Page MenuHomeClusterLabs Projects

No OneTemporary

diff --git a/heartbeat/exportfs b/heartbeat/exportfs
index 095b732b6..14e70ae7a 100755
--- a/heartbeat/exportfs
+++ b/heartbeat/exportfs
@@ -1,367 +1,430 @@
#!/bin/sh
# exportfs
#
# Description: Manages nfs exported file system.
#
# (c) 2010 Ben Timby, Florian Haas, Dejan Muhamedagic,
# and Linux-HA contributors
#
# License: GNU General Public License v2 (GPLv2) and later
#######################################################################
# Initialization:
: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
# Defaults
OCF_RESKEY_unlock_on_stop_default=1
OCF_RESKEY_wait_for_leasetime_on_stop_default=0
OCF_RESKEY_rmtab_backup_default=".rmtab"
: ${OCF_RESKEY_unlock_on_stop=${OCF_RESKEY_unlock_on_stop_default}}
: ${OCF_RESKEY_wait_for_leasetime_on_stop=${OCF_RESKEY_wait_for_leasetime_on_stop_default}}
: ${OCF_RESKEY_rmtab_backup=${OCF_RESKEY_rmtab_backup_default}}
#######################################################################
exportfs_meta_data() {
cat <<END
<?xml version="1.0"?>
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
<resource-agent name="exportfs">
<version>1.0</version>
<longdesc lang="en">
Exportfs uses the exportfs command to add/remove nfs exports.
It does NOT manage the nfs server daemon.
It depends on Linux specific NFS implementation details,
so is considered not portable to other platforms yet.
</longdesc>
<shortdesc lang="en">
Manages NFS exports
</shortdesc>
<parameters>
<parameter name="clientspec" unique="0" required="1">
<longdesc lang="en">
The client specification allowing remote machines to mount the directory
-over NFS.
+(or directories) over NFS.
</longdesc>
<shortdesc lang="en">
Client ACL.
</shortdesc>
<content type="string" />
</parameter>
<parameter name="options" unique="0" required="0">
<longdesc lang="en">
-The options to pass to exportfs for the exported directory.
+The options to pass to exportfs for the exported directory
+or directories.
</longdesc>
<shortdesc lang="en">
Export options.
</shortdesc>
<content type="string" />
</parameter>
<parameter name="directory" unique="0" required="1">
<longdesc lang="en">
-The directory which you wish to export using NFS.
+The directory or directories to be exported using NFS. Multiple
+directories are separated by white space.
</longdesc>
<shortdesc lang="en">
-The directory to export.
+The directory or directories to export.
</shortdesc>
<content type="string" />
</parameter>
<parameter name="fsid" unique="1" required="1">
<longdesc lang="en">
The fsid option to pass to exportfs. This can be a unique positive
integer, a UUID, or the special string "root" which is functionally
identical to numeric fsid of 0.
+If multiple directories are being exported, then they are
+assigned ids sequentially starting with this fsid (fsid, fsid+1,
+fsid+2, ...). Obviously, in that case the fsid must be an
+integer.
0 (root) identifies the export as the root of an NFSv4
pseudofilesystem -- avoid this setting unless you understand its
special status.
This value will override any fsid provided via the options parameter.
</longdesc>
<shortdesc lang="en">
-Unique fsid within cluster.
+Unique fsid within cluster or starting fsid for multiple exports.
</shortdesc>
<content type="string" />
</parameter>
<parameter name="unlock_on_stop">
<longdesc lang="en">
Relinquish NFS locks associated with this filesystem when the resource
stops. Enabling this parameter is highly recommended unless the path exported
by this ${__SCRIPT_NAME} resource is also exported by a different resource.
Note: Unlocking is only possible on Linux systems where
/proc/fs/nfsd/unlock_filesystem exists and is writable. If your system does
not fulfill this requirement (on account of having an nonrecent kernel,
for example), you may set this parameter to 0 to silence the associated
warning.
</longdesc>
<shortdesc lang="en">
Unlock filesystem on stop?
</shortdesc>
<content type="boolean" default="${OCF_RESKEY_unlock_on_stop_default}" />
</parameter>
<parameter name="wait_for_leasetime_on_stop">
<longdesc lang="en">
When stopping (unexporting), wait out the NFSv4 lease time.
Only after all leases have expired does the NFS kernel server
relinquish all server-side handles on the exported filesystem.
If this ${__SCRIPT_NAME} resource manages an export that resides
on a mount point designed to fail over along with the NFS export
itself, then enabling this parameter will ensure such failover
is working properly. Note that when this parameter is set, your
stop timeout MUST accommodate for the wait period. This parameter
is safe to disable if none of your NFS clients are using NFS
version 4 or later.
</longdesc>
<shortdesc lang="en">
Ride out the NFSv4 lease time on resource stop?
</shortdesc>
<content type="boolean" default="${OCF_RESKEY_wait_for_leasetime_on_stop_default}" />
</parameter>
<parameter name="rmtab_backup">
<longdesc lang="en">
Back up those entries from the NFS rmtab that apply to the exported
directory, to the specified backup file. The filename is interpreted
as relative to the exported directory. This backup is required if
clients are connecting to the export via NFSv3 over TCP. Note that a
configured monitor operation is required for this functionality.
To disable rmtab backups, set this parameter to the special
string "none".
</longdesc>
<shortdesc lang="en">
Location of the rmtab backup, relative to directory.
</shortdesc>
<content type="string" default="${OCF_RESKEY_rmtab_backup_default}" />
</parameter>
</parameters>
<actions>
<action name="start" timeout="40" />
<action name="stop" timeout="120" />
<action name="monitor" depth="0" timeout="20" interval="10" />
<action name="meta-data" timeout="5" />
<action name="validate-all" timeout="30" />
</actions>
</resource-agent>
END
return $OCF_SUCCESS
}
exportfs_methods() {
cat <<-!
start
stop
status
monitor
validate-all
methods
meta-data
usage
!
}
+reset_fsid() {
+ CURRENT_FSID=$OCF_RESKEY_fsid
+}
+bump_fsid() {
+ let $((CURRENT_FSID++))
+}
+get_fsid() {
+ echo $CURRENT_FSID
+}
+
+# run a function on all directories
+forall() {
+ local func=$1
+ shift 1
+ local fast_exit=""
+ local dir rc=0
+ if [ "$2" = fast_exit ]; then
+ fast_exit=1
+ shift 1
+ fi
+ reset_fsid
+ for dir in $OCF_RESKEY_directory; do
+ $func $dir "$@"
+ rc=$(($rc | $?))
+ bump_fsid
+ [ "$fast_exit" ] && continue
+ [ $rc -ne 0 ] && return $rc
+ done
+ return $rc
+}
+
backup_rmtab() {
+ local dir=$1
local rmtab_backup
- if [ ${OCF_RESKEY_rmtab_backup} != "none" ]; then
- rmtab_backup="${OCF_RESKEY_directory}/${OCF_RESKEY_rmtab_backup}"
- grep ":${OCF_RESKEY_directory}:" /var/lib/nfs/rmtab > ${rmtab_backup}
- fi
+ rmtab_backup="$dir/${OCF_RESKEY_rmtab_backup}"
+ grep ":$dir:" /var/lib/nfs/rmtab > ${rmtab_backup}
}
restore_rmtab() {
+ local dir=$1
local rmtab_backup
- if [ ${OCF_RESKEY_rmtab_backup} != "none" ]; then
- rmtab_backup="${OCF_RESKEY_directory}/${OCF_RESKEY_rmtab_backup}"
+ rmtab_backup="$dir/${OCF_RESKEY_rmtab_backup}"
if [ -r ${rmtab_backup} ]; then
local tmpf=`mktemp`
sort -u ${rmtab_backup} /var/lib/nfs/rmtab > $tmpf &&
install -o root -m 644 $tmpf /var/lib/nfs/rmtab
rm -f $tmpf
ocf_log debug "Restored `wc -l ${rmtab_backup}` rmtab entries from ${rmtab_backup}."
else
ocf_log warn "rmtab backup ${rmtab_backup} not found or not readable."
fi
- fi
}
exportfs_usage() {
cat <<END
usage: $0 {start|stop|monitor|status|validate-all|meta-data}
END
}
+format_exports() {
+ # exportfs output wraps lines for long export directory names.
+ # We unwrap here with sed.
+ # We then do a literal match on the full line (grep -x -F)
+ exportfs |
+ sed -e '$! N; s/\n[[:space:]]\+/ /; t; s/[[:space:]]\+\([^[:space:]]\+\)\(\n\|$\)/ \1\2/g; P;D;'
+}
is_exported() {
local dir=$1
local spec=$2
- exportfs |
- sed -e '$! N; s/\n[[:space:]]\+/ /; t; s/[[:space:]]\+\([^[:space:]]\+\)\(\n\|$\)/ \1\2/g; P;D;' |
- grep -q -x -F "$dir $spec"
-}
-
-exportfs_monitor ()
-{
local rc
- # exportfs output wraps lines for long export directory names.
- # We unwrap here with sed.
- # We then do a literal match on the full line (grep -x -F)
- is_exported "${OCF_RESKEY_directory}" "${OCF_RESKEY_clientspec}"
+ format_exports | grep -q -x -F "$dir $spec"
rc=$?
-
- # on some platforms, exportfs may print "<world>" instead of
- # "*"
- if [ $rc -eq 1 -a "${OCF_RESKEY_clientspec}" = "*" ]; then
- is_exported "${OCF_RESKEY_directory}" "<world>"
+ if [ $rc -ne 0 -a "$spec" = "*" ]; then
+ # on some platforms, exportfs may print
+ # "<world>" instead of "*"
+ format_exports | grep -q -x -F "$dir <world>"
rc=$?
fi
-
-#Adapt grep status code to OCF return code
- case $rc in
- 0)
- if [ "$__OCF_ACTION" = "start" ]; then
- ocf_log info "Directory ${OCF_RESKEY_directory} is exported to ${OCF_RESKEY_clientspec} (started)."
- fi
- # Backup the rmtab to ensure smooth NFS-over-TCP failover
- backup_rmtab
- return $OCF_SUCCESS
- ;;
- 1)
- ocf_log info "Directory ${OCF_RESKEY_directory} is not exported to ${OCF_RESKEY_clientspec} (stopped)."
- return $OCF_NOT_RUNNING;;
- *)
- ocf_log err "Unable to determine export status for ${OCF_RESKEY_directory}."
- return $OCF_ERR_GENERIC;;
- esac
+ # log something only for monitors
+ if [ $rc -ne 0 -a "$__OCF_ACTION" = "monitor" ]; then
+ local sev="info"
+ ocf_is_probe || sev="err"
+ ocf_log $sev "$dir not exported to $spec (stopped)."
+ fi
+ return $rc
}
-exportfs_start ()
+exportfs_monitor ()
{
- if exportfs_monitor; then
- ocf_log debug "${OCF_RESKEY_directory} already exported"
+ if forall is_exported "${OCF_RESKEY_clientspec}"; then
+ if [ ${OCF_RESKEY_rmtab_backup} != "none" ]; then
+ forall backup_rmtab
+ fi
return $OCF_SUCCESS
+ else
+ return $OCF_NOT_RUNNING
fi
-
- ocf_log info "Exporting file system ..."
+}
- if [ ${OCF_RESKEY_options} ]; then
- OPTIONS="${OCF_RESKEY_options}"
- OPTPREFIX=','
+export_one() {
+ local dir=$1
+ local opts sep
+ sep=""
+ if [ -n "$OCF_RESKEY_options" ]; then
+ opts="$OCF_RESKEY_options"
+ sep=","
fi
- if [ `echo ${OPTIONS} | grep fsid` ]; then
- #replace fsid provided in options list with one provided in fsid param.
- OPTIONS=`echo ${OPTIONS} | sed "s/fsid=[0-9]\+/fsid=${OCF_RESKEY_fsid}/g"`
+ if echo "$opts" | grep fsid >/dev/null; then
+ #replace fsid in options list
+ opts=`echo "$opts" | sed "s/fsid=[0-9]\+/fsid=$(get_fsid)/g"`
else
#tack the fsid option onto our options list.
- OPTIONS="${OPTIONS}${OPTPREFIX}fsid=${OCF_RESKEY_fsid}"
+ opts="${opts}${sep}fsid=$(get_fsid)"
fi
- OPTIONS="-o ${OPTIONS}"
-
- ocf_run exportfs -v ${OPTIONS} ${OCF_RESKEY_clientspec}:${OCF_RESKEY_directory} || exit $OCF_ERR_GENERIC
+ opts="-o $opts"
- # Restore the rmtab to ensure smooth NFS-over-TCP failover
- restore_rmtab
+ # if any of directories fails to export we can exit
+ # immediately
+ ocf_run exportfs -v $opts "${OCF_RESKEY_clientspec}:$dir" ||
+ exit $OCF_ERR_GENERIC
- ocf_log info "File system exported"
+ ocf_log info "directory $dir exported"
return $OCF_SUCCESS
}
+exportfs_start ()
+{
+ if exportfs_monitor; then
+ ocf_log debug "already exported"
+ return $OCF_SUCCESS
+ fi
+ ocf_log info "Exporting file system(s) ..."
+ forall export_one
+
+ # Restore the rmtab to ensure smooth NFS-over-TCP failover
+ if [ ${OCF_RESKEY_rmtab_backup} != "none" ]; then
+ forall restore_rmtab
+ fi
+}
unlock_fs() {
+ local dir=$1
local unlockfile
unlockfile=/proc/fs/nfsd/unlock_filesystem
if [ -w ${unlockfile} ]; then
- echo "${OCF_RESKEY_directory}" > ${unlockfile}
- ocf_log info "Unlocked NFS export ${OCF_RESKEY_directory}"
+ echo "$dir" > ${unlockfile}
+ ocf_log info "Unlocked NFS export $dir"
else
- ocf_log warn "Unable to unlock NFS export ${OCF_RESKEY_directory}, ${unlockfile} not found or not writable"
+ ocf_log warn "Unable to unlock NFS export $dir, ${unlockfile} not found or not writable"
fi
}
wait_for_leasetime() {
local leasetimefile
local sleeptime
leasetimefile=/proc/fs/nfsd/nfsv4leasetime
if [ -r ${leasetimefile} ]; then
sleeptime=$((`cat ${leasetimefile}`+2))
ocf_log info "Sleeping ${sleeptime} seconds to accommodate for NFSv4 lease expiry"
sleep ${sleeptime}s
else
ocf_log warn "Unable to read NFSv4 lease time from ${leasetimefile}, file not found or not readable"
fi
}
cleanup_export_cache() {
# see if the cache is blocking unexport
local contentfile=/proc/net/rpc/nfsd.export/content
- local fsid_re="fsid=$OCF_RESKEY_fsid,"
+ local fsid_re
local i=1
+ fsid_re="fsid=(echo `forall get_fsid`|sed 's/ /|/g'),"
while :; do
- fgrep -q "$fsid_re" $contentfile ||
+ grep -E -q "$fsid_re" $contentfile ||
break
ocf_log info "Cleanup export cache ... (try $i)"
ocf_run exportfs -f
sleep 0.5
let i=$i+1
done
}
+unexport_one() {
+ local dir=$1
+ ocf_run exportfs -v -u ${OCF_RESKEY_clientspec}:$dir
+}
exportfs_stop ()
{
+ local rc
+
exportfs_monitor
if [ $? -eq $OCF_NOT_RUNNING ]; then
- ocf_log debug "${OCF_RESKEY_directory} not exported"
+ ocf_log debug "not exported"
return $OCF_SUCCESS
fi
ocf_log info "Un-exporting file system ..."
# Backup the rmtab to ensure smooth NFS-over-TCP failover
- backup_rmtab
+ if [ ${OCF_RESKEY_rmtab_backup} != "none" ]; then
+ forall backup_rmtab
+ fi
- ocf_run exportfs -v -u ${OCF_RESKEY_clientspec}:${OCF_RESKEY_directory}
+ forall unexport_one
rc=$?
if ocf_is_true ${OCF_RESKEY_unlock_on_stop}; then
- unlock_fs
+ forall unlock_fs
fi
if ocf_is_true ${OCF_RESKEY_wait_for_leasetime_on_stop}; then
wait_for_leasetime
fi
if [ $rc -eq 0 ]; then
cleanup_export_cache
- ocf_log info "Un-exported file system"
+ ocf_log info "Un-exported file system(s)"
return $OCF_SUCCESS
else
- ocf_log err "Failed to un-export file system"
- exit $OCF_ERR_GENERIC
+ ocf_log err "Failed to un-export file system(s)"
+ return $OCF_ERR_GENERIC
fi
}
+testdir() {
+ if [ ! -d $1 ]; then
+ ocf_is_probe ||
+ ocf_log err "$1 does not exist or is not a directory"
+ return 1
+ fi
+ return 0
+}
exportfs_validate_all ()
{
- if [ ! -d $OCF_RESKEY_directory ]; then
- ocf_log err "$OCF_RESKEY_directory does not exist or is not a directory"
+ if [ `echo "$OCF_RESKEY_directory" | wc -w` -gt 1 ] &&
+ ! ocf_is_decimal "$OCF_RESKEY_fsid"; then
+ ocf_log err "use integer fsid when exporting multiple directories"
+ return $OCF_ERR_CONFIGURED
+ fi
+ if ! forall testdir; then
return $OCF_ERR_INSTALLED
fi
}
# If someone puts a trailing slash at the end of the export directory,
# this agent is going to fail in some unexpected ways due to how
# export strings are matched. The simplest solution here is to strip off
# a trailing '/' in the directory before processing anything.
newdir=$(echo "$OCF_RESKEY_directory" | sed -n -e 's/^\(.*\)\/$/\1/p')
if [ -n "$newdir" ]; then
OCF_RESKEY_directory=$newdir
fi
OCF_REQUIRED_PARAMS="directory fsid clientspec"
OCF_REQUIRED_BINARIES="exportfs"
ocf_rarun $*
diff --git a/tools/ocft/Makefile.am b/tools/ocft/Makefile.am
index 2374531fe..b96d6d2e3 100644
--- a/tools/ocft/Makefile.am
+++ b/tools/ocft/Makefile.am
@@ -1,56 +1,57 @@
# Author: John Shi
# jshi@suse.de
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
MAINTAINERCLEANFILES = Makefile.in
EXTRA_DIST = $(ocftcfgs_DATA) $(ocft_DATA)
sbin_SCRIPTS = ocft
ocftcfgsdir = $(datadir)/$(PACKAGE_NAME)/ocft/configs
ocftcfgs_DATA = apache \
IPaddr2 \
IPaddr2v4 \
IPaddr2v6 \
IPv6addr \
Filesystem \
LVM \
Raid1 \
IPsrcaddr \
MailTo \
jboss \
mysql \
mysql-proxy \
pgsql \
db2 \
oracle \
drbd.linbit \
exportfs \
+ exportfs-multidir \
nfsserver \
portblock \
iscsi \
named \
postfix \
tomcat \
Xinetd \
SendArp
ocftdir = $(datadir)/$(PACKAGE_NAME)/ocft
ocft_DATA = README \
README.zh_CN \
caselib
diff --git a/tools/ocft/exportfs-multidir b/tools/ocft/exportfs-multidir
new file mode 100644
index 000000000..72551c669
--- /dev/null
+++ b/tools/ocft/exportfs-multidir
@@ -0,0 +1,79 @@
+# exportfs
+#
+#
+
+CONFIG
+ Agent exportfs
+ AgentRoot /usr/lib/ocf/resource.d/heartbeat
+ HangTimeout 40
+
+SETUP-AGENT
+ # nothing
+
+CASE-BLOCK set_testenv
+ Env OCF_RESKEY_directory="/usr /var"
+ Env OCF_RESKEY_fsid=105
+ Env OCF_RESKEY_clientspec="*"
+ Env OCF_RESKEY_CRM_meta_timeout=30000
+
+CASE-BLOCK default_status
+ AgentRun stop
+
+CASE-BLOCK prepare
+ Include set_testenv
+ Include default_status
+
+CASE "check base env"
+ Include prepare
+ AgentRun start OCF_SUCCESS
+
+CASE "check base env: no 'OCF_RESKEY_fsid'"
+ Include prepare
+ Env OCF_RESKEY_fsid=
+ AgentRun start OCF_ERR_CONFIGURED
+
+CASE "check base env: invalid 'OCF_RESKEY_directory'"
+ Include prepare
+ Env OCF_RESKEY_directory=/no_such
+ AgentRun start OCF_ERR_INSTALLED
+
+CASE "check base env: invalid 'OCF_RESKEY_fsid'"
+ Include prepare
+ Env OCF_RESKEY_fsid=root
+ AgentRun start OCF_ERR_CONFIGURED
+
+CASE "unimplemented command"
+ Include prepare
+ AgentRun no_cmd OCF_ERR_UNIMPLEMENTED
+
+CASE "normal start"
+ Include prepare
+ AgentRun start OCF_SUCCESS
+
+CASE "normal stop"
+ Include prepare
+ AgentRun start
+ AgentRun stop OCF_SUCCESS
+
+CASE "double start"
+ Include prepare
+ AgentRun start
+ AgentRun start OCF_SUCCESS
+
+CASE "double stop"
+ Include prepare
+ AgentRun stop OCF_SUCCESS
+
+CASE "stop with no env"
+ Include prepare
+ Env OCF_RESKEY_directory="/usr /no_such"
+ AgentRun stop OCF_SUCCESS
+
+CASE "started: monitor"
+ Include prepare
+ AgentRun start
+ AgentRun monitor OCF_SUCCESS
+
+CASE "not started: monitor"
+ Include prepare
+ AgentRun monitor OCF_NOT_RUNNING

File Metadata

Mime Type
text/x-diff
Expires
Mon, Apr 21, 7:23 PM (5 h, 48 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1665518
Default Alt Text
(18 KB)

Event Timeline