--- /usr/lib/ocf/resource.d/heartbeat/nfsserver_orig 2011-12-27 10:07:32.591996016 +0100 +++ /usr/lib/ocf/resource.d/heartbeat/nfsserver 2011-12-27 11:33:44.538524680 +0100 @@ -3,6 +3,7 @@ # # Description: Manages nfs server as OCF resource # by hxinwei@gmail.com +# edited for NFSv4 by josef.vogt@telecom.li # License: GNU General Public License v2 (GPLv2) and later if [ -n "$OCF_DEBUG_LIBRARY" ]; then @@ -47,6 +48,7 @@ Init script for nfsserver The tool to send out NSM reboot notification. Failover of nfsserver can be considered as rebooting to different machines. The nfsserver resource agent use this command to notify all clients about the happening of failover. +This is not needed when using NFSv4. The tool to send out notification. @@ -65,7 +67,7 @@ Directory to store nfs server related in - + The floating IP address used to access the nfs service @@ -75,6 +77,47 @@ IP address. + + +The gracetime is the time a server has to wait after a failover until it is safe to give out new locks. Min value is 10 sec. A shorter time means faster failover time but a higher load. + + +nfsv4gracetime in seconds. + + + + + + +The leasetime is the time a during which a lock is valid. A client has to check in after this time to get a new lock. Min value is 10 sec. A shorter time means faster failover time but a higher load. + + +nfsv4leasetime in seconds. + + + + + + +The graceperiod is only needed for NFSv2/NFSv3. It can be set to 0 when using NFSv4. + + +nlm_timeout in seconds. + + + + + + +Select, which version to use: NFSv3 or NFSv4 +When using NFSv4, set this value to: NFSv4 + + +NFS version. + + + + @@ -115,6 +158,11 @@ esac fp="$OCF_RESKEY_nfs_shared_infodir" : ${OCF_RESKEY_nfs_init_script="$DEFAULT_INIT_SCRIPT"} : ${OCF_RESKEY_nfs_notify_cmd="$DEFAULT_NOTIFY_CMD"} +: ${OCF_RESKEY_nfs_gracetime="10"} +: ${OCF_RESKEY_nfs_leasetime="10"} +: ${OCF_RESKEY_nfs_graceperiod="90"} +: ${OCF_RESKEY_nfs_version="NFSv3"} + nfsserver_monitor () { @@ -134,6 +182,30 @@ nfsserver_monitor () fi } +prepare_nfsd () +{ + # mount /proc/fs/nfsd + lsmod | grep -q nfsd + if [ $? -ne 0 ]; then + ocf_log debug "Running modprobe for nfsd..." + modprobe nfsd + fi + + # Here we set gracetime, leasetime and graceperiod so that failover is faster + ocf_log info "Setting gracetime, leasetime and grace_period... " + ocf_log debug "gracetime: ${OCF_RESKEY_nfs_gracetime}" + ocf_log debug "leasetime: ${OCF_RESKEY_nfs_leasetime} " + ocf_log debug "graceperiod: ${OCF_RESKEY_nfs_graceperiod} " + + echo ${OCF_RESKEY_nfs_gracetime} > /proc/fs/nfsd/nfsv4gracetime + echo ${OCF_RESKEY_nfs_leasetime} > /proc/fs/nfsd/nfsv4leasetime + echo ${OCF_RESKEY_nfs_graceperiod} > /proc/sys/fs/nfs/nlm_grace_period + + ocf_log info "gracetime is now: `cat /proc/fs/nfsd/nfsv4gracetime`" + ocf_log info "leasetime is now: `cat /proc/fs/nfsd/nfsv4leasetime`" + ocf_log info "graceperiod is now: `cat /proc/sys/fs/nfs/nlm_grace_period`" +} + prepare_directory () { [ -d "$fp" ] || mkdir -p $fp @@ -171,6 +243,9 @@ unbind_tree () nfsserver_start () { + if [ $OCF_RESKEY_nfs_version = "NFSv4" ]; then + prepare_nfsd + fi prepare_directory bind_tree @@ -190,14 +265,17 @@ nfsserver_start () return $rc fi - #Notify the nfs server has been moved or rebooted - #The init script do that already, but with the hostname, which may be ignored by client - #we have to do it again with the nfs_ip - local opts="-v" - echo $OCF_RESKEY_nfs_notify_cmd | grep -qws rpc.statd && - opts="" - ${OCF_RESKEY_nfs_notify_cmd} $opts $OCF_RESKEY_nfs_ip -P /var/lib/nfs/sm.ha - + # Only needed for NFSv2/NFSv3 + if [ $OCF_RESKEY_nfs_version != "NFSv4" ]; then + #Notify the nfs server has been moved or rebooted + #The init script do that already, but with the hostname, which may be ignored by client + #we have to do it again with the nfs_ip + local opts="-v" + echo $OCF_RESKEY_nfs_notify_cmd | grep -qws rpc.statd && + opts="" + ${OCF_RESKEY_nfs_notify_cmd} $opts $OCF_RESKEY_nfs_ip -P /var/lib/nfs/sm.ha + fi + ocf_log info "NFS server started" return $OCF_SUCCESS } @@ -224,11 +302,15 @@ nfsserver_stop () nfsserver_validate () { check_binary ${OCF_RESKEY_nfs_init_script} - check_binary ${OCF_RESKEY_nfs_notify_cmd} - if [ -z ${OCF_RESKEY_nfs_ip} ]; then - ocf_log err "nfs_ip not set" - exit $OCF_ERR_CONFIGURED + # Not needed for NFSv4 + if [ $OCF_RESKEY_nfs_version != "NFSv4" ]; then + check_binary ${OCF_RESKEY_nfs_notify_cmd} + + if [ -z ${OCF_RESKEY_nfs_ip} ]; then + ocf_log err "nfs_ip not set" + exit $OCF_ERR_CONFIGURED + fi fi if [ x = "x$OCF_RESKEY_nfs_shared_infodir" ]; then