LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Fedora (https://www.linuxquestions.org/questions/fedora-35/)
-   -   A work-around for reboot/shutdown problems when cifs shares are open (https://www.linuxquestions.org/questions/fedora-35/a-work-around-for-reboot-shutdown-problems-when-cifs-shares-are-open-524383/)

PTrenholme 01-31-2007 10:14 AM

A work-around for reboot/shutdown problems when cifs shares are open
 
In Fedora, when a reboot or shutdown is done, and if a cifs share is open, the network access may be terminated before the CIFS filesystems are unmounted. This produces an inordinate delay as each share must wait for it's umount request to time out.

Since I set up my cifs shares for automount with no timeout, I needed an automatic way to unmount them at the start of a reboot or shutdown.

The solution I took was to patch the stop function in /etc/init.d/dhcdbd to include the following code:
Code:

# Un-mount CIFS shares if there are any CIFS processes running
        if ! [ -z $(/sbin/pidof cifsd) ];
        then
            echo -n Umounting SMB shares;
            umount -a -t cifs
            if [ $? -eq 0 ];
            then
                success;
            else
                failure;
            fi
            echo
        fi
#

This is, of course, a "hack." A better solution might be to create a cifs program in in /etc/init.d/ and link to it from /etc/rc.d/rc5.d/ so that it's run before dhcdbd at shutdown. Something like this (which I've not tested):
Code:

$ cat tmp/cifs
#!/bin/bash
#
#  cifs:        Make sure that all cifs shares are unmounted before INIT 0
#
#  description: This is a pseudo init process that umounts any cifs shares
#              that are open when it's called
#
#  processname: cifs
#
. /etc/rc.d/init.d/functions
[ -e /etc/sysconfig/network ] && . /etc/sysconfig/network
[ "${NETWORKING}" = "no" ] && exit 0
prog=cifs

stop () {
# Un-mount CIFS shares if there are any CIFS processes running
        RETVAL=0
        if ! [ -z $(/sbin/pidof cifsd) ];
        then
            echo -n Umounting cifs shares:
            umount -a -t cifs
            RETVAL=$?
            if [ $RETVAL -eq 0 ];
            then
                success;
            else
                failure;
            fi
            echo
        fi
        return $RETVAL
}

status() {
# Report if any CIFS processes is running
        RETVAL=0
        if ! [ -z $(/sbin/pidof cifsd) ];
        then
          echo The CIFS process is running.
        else
          echo The CIFS process is not running.
        fi
        return $RETVAL
}

case "$1" in
    stop)
        stop;
        RETVAL=$?;
        ;;
    status)
        status;
        RETVAL=$?;
        ;;
    *)
# Just ignore any other arguments
        RETVAL=0;
        ;;
esac;

exit $RETVAL;

As an aside, for those who want to use automount for their cifs shares, here's my /etc/auto.master and /etc/auto.cifs:
Code:

$ cat /etc/auto.master
/smb    /etc/auto.cifs --timeout=0
+auto.master
$ cat /etc/auto.cifs
#!/bin/bash
credfile="/etc/auto.smb.$key"
mountopts="-fstype=cifs,file_mode=0775,dir_mode=0775,uid=$USER,gid=smb"
smbclientopts=""
SMBCLIENT=$(whereis -b smbclient | cut -d " " -f 2)
if ! [ -x $SMBCLIENT ]
then
    echo No smbclient executable found. Have you installed samba? >2
    exit 1
fi
if [ -r "$credfile" ]
then
        mountopts=$mountopts",credentials=$credfile"
        smbclientopts="-A "$credfile
else
        smbclientopts="-N"
fi
$SMBCLIENT $smbclientopts -gL $key\
  | awk -v key="$key" -v opts="$mountopts" -F'|' -- '
        BEGIN  { ORS=""; first=1 }
        /^Disk[^$]*$/  { if (first) { print opts; first=0 };
                  sub(/ /, "\\ ", $2);
                  if (length($2)==1) sub(/ ^/, "", $2);
                  print " \\\n\t /" tolower($2), "://" key "/" $2 }
        END    { if (!first) print "\n"; else exit 1 }
        '



All times are GMT -5. The time now is 11:22 AM.