Print this page
    
NEX-15891 Latest grep from illumos broke zvol_swap tests and swapadd
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
Reviewed by: Rob Gittins <rob.gittins@nexenta.com>
    
      
        | Split | 
	Close | 
      
      | Expand all | 
      | Collapse all | 
    
    
          --- old/usr/src/cmd/initpkg/swapadd.sh
          +++ new/usr/src/cmd/initpkg/swapadd.sh
   1    1  #!/sbin/sh
   2    2  #
   3    3  # CDDL HEADER START
   4    4  #
   5    5  # The contents of this file are subject to the terms of the
   6    6  # Common Development and Distribution License, Version 1.0 only
   7    7  # (the "License").  You may not use this file except in compliance
   8    8  # with the License.
   9    9  #
  10   10  # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  11   11  # or http://www.opensolaris.org/os/licensing.
  12   12  # See the License for the specific language governing permissions
  13   13  # and limitations under the License.
  14   14  #
  15   15  # When distributing Covered Code, include this CDDL HEADER in each
  16   16  # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  17   17  # If applicable, add the following below this CDDL HEADER, with the
  18   18  # fields enclosed by brackets "[]" replaced with your own identifying
  19   19  # information: Portions Copyright [yyyy] [name of copyright owner]
  20   20  #
  21   21  # CDDL HEADER END
  22   22  #
  23   23  #
  24   24  # Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
  25   25  # Use is subject to license terms.
  26   26  #
  27   27  # Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
  28   28  # All rights reserved.
  29   29  #
  30   30  #
  31   31  #ident  "%Z%%M% %I%     %E% SMI"
  32   32  
  33   33  # Set noinuse checking during boot. We want to disable device in use checking
  34   34  # so that normal swap use, such as specified in /etc/vfstab, will not cause
  35   35  # swap devices to fail to be configured during boot.
  36   36  NOINUSE_CHECK=1; export NOINUSE_CHECK
  37   37  
  38   38  PATH=/usr/sbin:/usr/bin; export PATH
  39   39  USAGE="Usage: swapadd [-12] [file_system_table]"
  40   40  
  41   41  VFSTAB=/etc/vfstab      # Default file system table
  42   42  PASS=2                  # Default to checking for existing swap
  43   43  
  44   44  #
  45   45  # Check to see if there is an entry in the fstab for a specified file and
  46   46  # mount it.  This allows swap files (e.g. nfs files) to be mounted before
  47   47  # being added for swap.
  48   48  #
  49   49  checkmount()
  50   50  {
  51   51          while read rspecial rfsckdev rmountp rfstype rfsckpass rautomnt rmntopts
  52   52          do
  53   53                  #
  54   54                  # Ignore comments, empty lines, and no-action lines
  55   55                  #
  56   56                  case "$rspecial" in
  57   57                  '#'* | '' | '-') continue ;;
  58   58                  esac
  59   59  
  60   60                  if [ "x$rmountp" = "x$1" ]; then
  61   61                          #
  62   62                          # If mount options are '-', default to 'rw'
  63   63                          #
  64   64                          [ "x$rmntopts" = x- ] && rmntopts=rw
  65   65  
  66   66                          if /sbin/mount -m -o $rmntopts $rspecial \
  67   67                              >/dev/null 2>&1; then
  68   68                                  echo "Mounting $rmountp for swap"
  69   69                          else
  70   70                                  echo "Mount of $rmountp for swap failed"
  71   71                          fi
  72   72                          return
  73   73                  fi
  74   74          done <$VFSTAB
  75   75  }
  76   76  
  77   77  die()
  78   78  {
  79   79          echo "$*" >& 2
  80   80          exit 1
  81   81  }
  82   82  
  83   83  while getopts 12 opt; do
  84   84          case "$opt" in
  85   85          1|2) PASS=$opt ;;
  86   86           \?) die "$USAGE" ;;
  87   87          esac
  88   88  done
  89   89  shift `expr $OPTIND - 1`
  90   90  
  91   91  [ $# -gt 1 ] && die "$USAGE"
  92   92  [ $# -gt 0 ] && VFSTAB="$1"
  93   93  
  94   94  #
  95   95  # If $VFSTAB is not "-" (stdin), re-open stdin as the specified file
  96   96  #
  97   97  if [ "x$VFSTAB" != x- ]; then
  98   98          [ -s "$VFSTAB" ] || die "swapadd: file system table ($VFSTAB) not found"
  99   99          exec <$VFSTAB
 100  100  fi
 101  101  
 102  102  #
 103  103  # Read the file system table to find entries of file system type "swap".
 104  104  # Add the swap device or file specified in the first column.
 105  105  #
 106  106  while read special t1 t2 fstype t3 t4 t5; do
 107  107          #
 108  108          # Ignore comments, empty lines, and no-action lines
 109  109          #
 110  110          case "$special" in
 111  111          '#'* | '' | '-') continue ;;
 112  112          esac
 113  113  
 114  114          #
 115  115          # Ignore non-swap fstypes
 116  116          #
 117  117          [ "$fstype" != swap ] && continue
 118  118  
 119  119          if [ $PASS = 1 ]; then
 120  120                  #
 121  121                  # Pass 1 should handle adding the swap files that
 122  122                  # are accessable immediately; block devices, files
 123  123                  # in / and /usr, and direct nfs mounted files.
 124  124                  #
 125  125                  if [ ! -b $special ]; then
 126  126                          #
 127  127                          # Read the file system table searching for mountpoints
 128  128                          # matching the swap file about to be added.
 129  129                          #
 130  130                          # NB: This won't work correctly if the file to added
 131  131                          # for swapping is a sub-directory of the mountpoint.
 132  132                          # e.g.  swapfile-> servername:/export/swap/clientname
 133  133                          #       mountpoint-> servername:/export/swap
 134  134                          #
 135  135                          checkmount $special
 136  136                  fi
 137  137                  if [ -f $special -a -w $special -o -b $special ]; then
  
    | 
      ↓ open down ↓ | 
    137 lines elided | 
    
      ↑ open up ↑ | 
  
 138  138                          swap -$PASS -a $special >/dev/null
 139  139                  fi
 140  140          else
 141  141                  #
 142  142                  # Pass 2 should skip all the swap already added.  If something
 143  143                  # added earlier uses the same name as something to be added
 144  144                  # later, the following test won't work. This should only happen
 145  145                  # if parts of a particular swap file are added or deleted by
 146  146                  # hand between invocations.
 147  147                  #
 148      -                swap -l 2>/dev/null | grep '\<'${special}'\>' >/dev/null 2>&1 \
      148 +                swap -l 2>/dev/null | grep -q "^$special " \
 149  149                      || swap -$PASS -a $special >/dev/null
 150  150          fi
 151  151  done
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX