Print this page
8890 ipfilter and nfs/server are locked in death race


  15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16 # If applicable, add the following below this CDDL HEADER, with the
  17 # fields enclosed by brackets "[]" replaced with your own identifying
  18 # information: Portions Copyright [yyyy] [name of copyright owner]
  19 #
  20 # CDDL HEADER END
  21 #
  22 
  23 #
  24 # Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
  25 # Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
  26 # Copyright 2016 Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org>
  27 #
  28 
  29 # Start/stop processes required for server NFS
  30 
  31 . /lib/svc/share/smf_include.sh
  32 . /lib/svc/share/ipf_include.sh
  33 zone=`smf_zonename`
  34 
  35 #
  36 # Handling a corner case here. If we were in offline state due to an
  37 # unsatisfied dependency, the ipf_method process wouldn't have generated
  38 # the ipfilter configuration. When we transition to online because the
  39 # dependency is satisfied, the start method will have to generate the
  40 # ipfilter configuration. To avoid all possible deadlock scenarios,
  41 # we restart ipfilter which will regenerate the ipfilter configuration
  42 # for the entire system.
  43 #
  44 # The ipf_method process signals that it didn't generate ipf rules by
  45 # removing the service's ipf file. Thus we only restart network/ipfilter
  46 # when the file is missing.
  47 #
  48 configure_ipfilter()
  49 {
  50         ipfile=`fmri_to_file $SMF_FMRI $IPF_SUFFIX`
  51         ip6file=`fmri_to_file $SMF_FMRI $IPF6_SUFFIX`
  52         [ -f "$ipfile" -a -f "$ip6file" ] && return 0
  53 
  54         #
  55         # Nothing to do if:
  56         # - ipfilter isn't online 
  57         # - global policy is 'custom'
  58         # - service's policy is 'use_global'
  59         #
  60         service_check_state $IPF_FMRI $SMF_ONLINE || return 0
  61         [ "`get_global_def_policy`" = "custom" ] && return 0
  62         [ "`get_policy $SMF_FMRI`" = "use_global" ] && return 0
  63 
  64         svcadm restart $IPF_FMRI
  65 }
  66 
  67 case "$1" in
  68 'start')
  69         # The NFS server is not supported in a local zone
  70         if smf_is_nonglobalzone; then
  71                 /usr/sbin/svcadm disable -t svc:/network/nfs/server
  72                 echo "The NFS server is not supported in a local zone"
  73                 sleep 5 &
  74                 exit $SMF_EXIT_OK
  75         fi
  76 
  77         # Share all file systems enabled for sharing. sharemgr understands
  78         # regular shares and ZFS shares and will handle both. Technically,
  79         # the shares would have been started long before getting here since
  80         # nfsd has a dependency on them.
  81 
  82         # restart stopped shares from the repository
  83         /usr/sbin/sharemgr start -P nfs -a
  84 
  85         # Options for nfsd are now set in SMF
  86 
  87         /usr/lib/nfs/mountd
  88         rc=$?
  89         if [ $rc != 0 ]; then
  90                 /usr/sbin/svcadm mark -t maintenance svc:/network/nfs/server
  91                 echo "$0: mountd failed with $rc"
  92                 sleep 5 &
  93                 exit $SMF_EXIT_ERR_FATAL
  94         fi
  95 
  96         /usr/lib/nfs/nfsd
  97         rc=$?
  98         if [ $rc != 0 ]; then
  99                 /usr/sbin/svcadm mark -t maintenance svc:/network/nfs/server
 100                 echo "$0: nfsd failed with $rc"
 101                 sleep 5 &
 102                 exit $SMF_EXIT_ERR_FATAL
 103         fi
 104 
 105         configure_ipfilter
 106         ;;
 107 
 108 'refresh')
 109         /usr/sbin/sharemgr start -P nfs -a
 110         ;;
 111 
 112 'stop')
 113         /usr/bin/pkill -x -u 0,1 -z $zone '(nfsd|mountd)'
 114 
 115         # Unshare all shared file systems using NFS
 116 
 117         /usr/sbin/sharemgr stop -P nfs -a
 118 
 119         # Kill any processes left in service contract
 120         smf_kill_contract $2 TERM 1
 121         [ $? -ne 0 ] && exit 1
 122         ;;
 123 
 124 'ipfilter')
 125         #




  15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16 # If applicable, add the following below this CDDL HEADER, with the
  17 # fields enclosed by brackets "[]" replaced with your own identifying
  18 # information: Portions Copyright [yyyy] [name of copyright owner]
  19 #
  20 # CDDL HEADER END
  21 #
  22 
  23 #
  24 # Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
  25 # Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
  26 # Copyright 2016 Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org>
  27 #
  28 
  29 # Start/stop processes required for server NFS
  30 
  31 . /lib/svc/share/smf_include.sh
  32 . /lib/svc/share/ipf_include.sh
  33 zone=`smf_zonename`
  34 
































  35 case "$1" in
  36 'start')
  37         # The NFS server is not supported in a local zone
  38         if smf_is_nonglobalzone; then
  39                 /usr/sbin/svcadm disable -t svc:/network/nfs/server
  40                 echo "The NFS server is not supported in a local zone"
  41                 sleep 5 &
  42                 exit $SMF_EXIT_OK
  43         fi
  44 
  45         # Share all file systems enabled for sharing. sharemgr understands
  46         # regular shares and ZFS shares and will handle both. Technically,
  47         # the shares would have been started long before getting here since
  48         # nfsd has a dependency on them.
  49 
  50         # restart stopped shares from the repository
  51         /usr/sbin/sharemgr start -P nfs -a
  52 
  53         # Options for nfsd are now set in SMF
  54 
  55         /usr/lib/nfs/mountd
  56         rc=$?
  57         if [ $rc != 0 ]; then
  58                 /usr/sbin/svcadm mark -t maintenance svc:/network/nfs/server
  59                 echo "$0: mountd failed with $rc"
  60                 sleep 5 &
  61                 exit $SMF_EXIT_ERR_FATAL
  62         fi
  63 
  64         /usr/lib/nfs/nfsd
  65         rc=$?
  66         if [ $rc != 0 ]; then
  67                 /usr/sbin/svcadm mark -t maintenance svc:/network/nfs/server
  68                 echo "$0: nfsd failed with $rc"
  69                 sleep 5 &
  70                 exit $SMF_EXIT_ERR_FATAL
  71         fi


  72         ;;
  73 
  74 'refresh')
  75         /usr/sbin/sharemgr start -P nfs -a
  76         ;;
  77 
  78 'stop')
  79         /usr/bin/pkill -x -u 0,1 -z $zone '(nfsd|mountd)'
  80 
  81         # Unshare all shared file systems using NFS
  82 
  83         /usr/sbin/sharemgr stop -P nfs -a
  84 
  85         # Kill any processes left in service contract
  86         smf_kill_contract $2 TERM 1
  87         [ $? -ne 0 ] && exit 1
  88         ;;
  89 
  90 'ipfilter')
  91         #