>>> Andreas Kurz <[email protected]> schrieb am 19.06.2012 um 10:48 in 
>>> Nachricht
<[email protected]>:
> On 06/19/2012 04:00 AM, Martin Marji Cermak wrote:
> > Hello guys,
> > I have 3 questions if you please.
> > 
> > I have a HA NFS cluster - Centos 6.2, pacemaker, corosync, two NFS nodes
> > plus 1 quorum node, in semi Active-Active configuration.
> > By "semi", I mean that both NFS nodes are active and each of them is under
> > normal circumstances exclusively responsible for one (out of two) Volume
> > Group - using the ocf:heartbeat:LVM RA.
> > Each LVM volume group lives on a dedicated multipath iscsi device, exported
> > from a shared SAN.
> > 
> > I'm exporting a NFSv3/v4 export (/srv/nfs/software_repos directory). I need
> > to make it available for 2 separate /21 networks as read-only, and for 3
> > different servers as read-write.
> > I'm using the ocf:heartbeat:exportfs RA and it seems to me I have to use
> > the ocf:heartbeat:exportfs RA 5 times.
> 
> If you want to use NFSv4 you also need to export the virtual nfs
> file-system root with fsid=0.
> 
> In its current incarnation, the exportfs RA does not allow to summarize
> different clients with the same export options in one primitive
> configuration, though the exportfs command would support it ... patches
> are welcome ;-)

The problem is: What to do if "1 out of n" exports fails: Is the resource 
"started" or "stopped" then. Likewise for unexporting and monitoring.

Actually I have modified the resource to allow multiple hosts, but the 
described problem made me wonder what to do. My patch looks like this (based on 
SLES 11 SP1 resource-agents-3.9.2-0.4.2.1):
>From f6a50995d82971da8a582b8862a5fdf1b1c19eb5 Mon Sep 17 00:00:00 2001
From: Ulrich Windl <[email protected]>
Date: Thu, 12 Apr 2012 15:42:21 +0200
Subject: [PATCH] exportfs: allow multiple clients in clientspec

Changed exportfs to allow a list of space-separated clients for parameter
"clientspec".

Fixed some obvious problems:
(1) Correctly match entries for long directories in exportfs_monitor().

(2) Actually allow a uuid (not just a number) for the "fsid=" option.

Other changes:
Consistently use "directory" instead of file system" for messages.
Announce when writing an rmtab backup in backup_rmtab().
---
 exportfs |   86 ++++++++++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 61 insertions(+), 25 deletions(-)

diff --git a/exportfs b/exportfs
index bc8e341..dfe4fe8 100755
--- a/exportfs
+++ b/exportfs
@@ -46,10 +46,10 @@ Manages NFS exports
 <parameter name="clientspec" unique="0" required="1">
 <longdesc lang="en">
 The client specification allowing remote machines to mount the directory
-over NFS.
+over NFS.  A list of clients separated by a space is allowed.
 </longdesc>
 <shortdesc lang="en">
-Client ACL.
+Client specification
 </shortdesc>
 <content type="string" />
 </parameter>
@@ -155,6 +155,7 @@ return $OCF_SUCCESS
 backup_rmtab() {
     local rmtab_backup
     if [ ${OCF_RESKEY_rmtab_backup} != "none" ]; then
+       ocf_log info "backup_rmtab(): Writing ${rmtab_backup}"
        rmtab_backup="${OCF_RESKEY_directory}/${OCF_RESKEY_rmtab_backup}"
        grep ":${OCF_RESKEY_directory}:" /var/lib/nfs/rmtab > ${rmtab_backup}
     fi
@@ -181,35 +182,60 @@ END

 exportfs_monitor ()
 {
-       # "grep -z" matches across newlines, which is necessary as
-       # exportfs output wraps lines for long export directory names
-       exportfs | grep -zqs 
"${OCF_RESKEY_directory}[[:space:]]*${OCF_RESKEY_clientspec}"
-
-#Adapt grep status code to OCF return code
-       case $? in
-       0)
+       local nclient=0 nmatch=0 rc client
+       for client in $OCF_RESKEY_clientspec
+       do
+               (( ++nclient ))
+               # exportfs uses TAB to continue wrapped entries for long
+               # directory names
+               #<DIR>
+               #<TAB><TAB><HOST>
+               # instead of
+               #<DIR><SPACE>*<HOST>
+               exportfs | grep -qs 
"^${OCF_RESKEY_directory}[[:space:]][[:space:]]*${client}\$" ||
+               exportfs | sed -n -e '\:^'"$OCF_RESKEY_directory"'$:,+1p' |
+               grep -qs "[[:space:]][[:space:]]*${client}\$"
+               rc=$?
+               if [ "$rc" -eq 0 ]
+               then
+                   (( ++nmatch ))
+               elif [ "$rc" -ne 1 ]
+               then
+                   ocf_log err "Unable to determine export status for 
$client:${OCF_RESKEY_directory}"
+                   break
+               else
+                   ocf_log info "Directory ${OCF_RESKEY_directory} is not 
exported to $client"
+               fi
+       done
+       #Adapt grep status code and match count to OCF return code
+       if [ "$rc" -gt 1 ]
+       then
+               return $OCF_ERR_GENERIC
+       elif [ "$nclient" -eq "$nmatch" ]
+       then
                ocf_log info "Directory ${OCF_RESKEY_directory} is exported to 
${OCF_RESKEY_clientspec} (started)."
                # Backup the rmtab to ensure smooth NFS-over-TCP failover
                backup_rmtab
                return $OCF_SUCCESS
-               ;;
-       1)
+       elif [ "$nmatch" -eq 0 ]
+       then
                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
+               return $OCF_NOT_RUNNING
+       else
+               ocf_log err "${OCF_RESKEY_directory} is exported to $nmatch out 
of $nclient clients"
+               return $OCF_ERR_GENERIC
+       fi
 }

 exportfs_start ()
 {
+       local client
        if exportfs_monitor; then
                ocf_log debug "${OCF_RESKEY_directory} already exported"
                return $OCF_SUCCESS
        fi

-       ocf_log info "Exporting file system ..."
+       ocf_log info "Exporting directory ${OCF_RESKEY_directory} ..."

        if [ ${OCF_RESKEY_options} ]; then
                OPTIONS="${OCF_RESKEY_options}"
@@ -217,37 +243,47 @@ exportfs_start ()
        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"`
+               OPTIONS=`echo ${OPTIONS} | sed 
"s/fsid=[-0-9a-f]\+/fsid=${OCF_RESKEY_fsid}/g"`
        else
                #tack the fsid option onto our options list.
                OPTIONS="${OPTIONS}${OPTPREFIX}fsid=${OCF_RESKEY_fsid}"
        fi
        OPTIONS="-o ${OPTIONS}"

-       ocf_run exportfs -v ${OPTIONS} 
${OCF_RESKEY_clientspec}:${OCF_RESKEY_directory} || exit $OCF_ERR_GENERIC
+       for client in $OCF_RESKEY_clientspec
+       do
+           ocf_log debug "Exporting $OCF_RESKEY_directory to $client"
+           ocf_run exportfs -v ${OPTIONS} $client:${OCF_RESKEY_directory} || 
exit $OCF_ERR_GENERIC
+       done

        # Restore the rmtab to ensure smooth NFS-over-TCP failover
        restore_rmtab

-       ocf_log info "File system exported"
+       ocf_log info "Directory ${OCF_RESKEY_directory} exported"
        return $OCF_SUCCESS
 }

 exportfs_stop ()
 {
+       local client
        exportfs_monitor
        if [ $? -eq $OCF_NOT_RUNNING ]; then
                ocf_log debug "${OCF_RESKEY_directory} not exported"
                return $OCF_SUCCESS
        fi

-       ocf_log info "Un-exporting file system ..."
+       ocf_log info "Un-exporting directory ${OCF_RESKEY_directory} ..."

        # Backup the rmtab to ensure smooth NFS-over-TCP failover
        backup_rmtab

-       ocf_run exportfs -v -u ${OCF_RESKEY_clientspec}:${OCF_RESKEY_directory}
-       rc=$?
+       for client in $OCF_RESKEY_clientspec
+       do
+           ocf_log debug "Un-exporting $OCF_RESKEY_directory from $client"
+           ocf_run exportfs -v -u $client:${OCF_RESKEY_directory}
+           rc=$?
+           [ "$rc" -eq 0 ] || break
+       done

        if ocf_is_true ${OCF_RESKEY_unlock_on_stop}; then
                local unlockfile
@@ -274,11 +310,11 @@ exportfs_stop ()
        fi

        if [ $rc -eq 0 ]; then
-               ocf_log info "Un-exported file system"
+               ocf_log info "Un-exported directory ${OCF_RESKEY_directory}"
                return $OCF_SUCCESS
        fi

-       ocf_log err "Failed to un-export file system"
+       ocf_log err "Failed to un-export directory ${OCF_RESKEY_directory}"
        exit $OCF_ERR_GENERIC
 }

--
1.6.0.2

Note that the description of the "clientspec" parameter was so vague that I 
didn't even had to change the description. Sorry that I added some unrelated 
fixes also. Fix "(1)" could be improved most likely.

[...]

Regards,
Ulrich

_______________________________________________
Linux-HA mailing list
[email protected]
http://lists.linux-ha.org/mailman/listinfo/linux-ha
See also: http://linux-ha.org/ReportingProblems

Reply via email to