Re: [Cluster-devel] [PATCH] rgmanager: fix nfsrestart option to be effective

2012-06-21 Thread Lon Hohberger

On 06/21/2012 04:07 AM, Fabio M. Di Nitto wrote:

From: "Fabio M. Di Nitto"

The original patch e512a9ce367 was still racy in some conditions
as other rpc.* and nfs* processes were holding a lock on the filesystem.

stopping nfs in kernel is simply not enough in rhel5

this fixed version does stop nfs completely and re-instante nfs exports.

Resolves: rhbz#822066


This is okay; ideally we wouldn't have to do this in the first place, 
however.


-- Lon



[Cluster-devel] [PATCH v2] mkfs.gfs2: Check for symlinks before reporting device contents

2012-06-21 Thread Andrew Price
(Patch updated to report symlinks similar to Fabio's suggestion)

When using symlinks with mkfs.gfs2 it reports what the symlink points
to instead of the contents of the device, like so:

 # ./mkfs.gfs2 -p lock_nolock /dev/vg/test
 This will destroy any data on /dev/vg/test.
 It appears to contain: symbolic link to `../dm-3'

This patch resolves symlinks before checking the device contents to make
the output more informative:

 # ./mkfs.gfs2 -p lock_nolock /dev/vg/test
 /dev/vg/test is a symlink to /dev/dm-3
 This will destroy any data on /dev/dm-3.
 It appears to contain: GFS2 Filesystem (blocksize 4096, lockproto lock_nolock)

Signed-off-by: Andrew Price 
---
 gfs2/mkfs/main_mkfs.c |   35 ---
 1 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index e6b00a0..957b144 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -518,19 +518,46 @@ print_results(struct gfs2_sbd *sdp, uint64_t 
real_device_size,
printf("\n");
 }
 
+
+/**
+ * If path is a symlink, return 1 with *abspath pointing to the absolute path,
+ * otherwise return 0. Exit on errors. The caller must free the memory pointed
+ * to by *abspath.
+ */
+static int is_symlink(char *path, char **abspath)
+{
+   struct stat lnkstat;
+
+   if (lstat(path, &lnkstat) == -1) {
+   perror("Failed to lstat the device");
+   exit(EXIT_FAILURE);
+   }
+   if (!S_ISLNK(lnkstat.st_mode)) {
+   return 0;
+   }
+   *abspath = canonicalize_file_name(path);
+   if (*abspath == NULL) {
+   perror(_("Could not find the absolute path of the device"));
+   exit(EXIT_FAILURE);
+   }
+   printf( _("%s is a symlink to %s\n"), path, *abspath);
+   return 1;
+}
+
 /**
  * main_mkfs - do everything
  * @argc:
  * @argv:
  *
  */
-
 void main_mkfs(int argc, char *argv[])
 {
struct gfs2_sbd sbd, *sdp = &sbd;
int error;
int rgsize_specified = 0;
unsigned char uuid[16];
+   char *absname = NULL;
+   int islnk = 0;
 
memset(sdp, 0, sizeof(struct gfs2_sbd));
sdp->bsize = -1;
@@ -561,8 +588,10 @@ void main_mkfs(int argc, char *argv[])
}
 
if (!sdp->override) {
-   printf( _("This will destroy any data on %s.\n"), 
sdp->device_name);
-   check_dev_content(sdp->device_name);
+   islnk = is_symlink(sdp->device_name, &absname);
+   printf(_("This will destroy any data on %s.\n"), islnk ? 
absname : sdp->device_name);
+   check_dev_content(islnk ? absname : sdp->device_name);
+   free(absname);
are_you_sure();
}
 
-- 
1.7.7.6



Re: [Cluster-devel] [PATCH] rgmanager: fix nfsrestart option to be effective

2012-06-21 Thread Fabio M. Di Nitto
On 6/21/2012 3:26 PM, Lon Hohberger wrote:
> On 06/21/2012 04:07 AM, Fabio M. Di Nitto wrote:
>> From: "Fabio M. Di Nitto"
>>
>> The original patch e512a9ce367 was still racy in some conditions
>> as other rpc.* and nfs* processes were holding a lock on the filesystem.
>>
>> stopping nfs in kernel is simply not enough in rhel5
>>
>> this fixed version does stop nfs completely and re-instante nfs exports.
>>
>> Resolves: rhbz#822066
> 
> This is okay; ideally we wouldn't have to do this in the first place,
> however.

and I would like some ponies, rainbows and unicorns.. however.

Fabio



[Cluster-devel] [PATCH] rgmanager: fix nfsrestart option to be effective

2012-06-21 Thread Fabio M. Di Nitto
From: "Fabio M. Di Nitto" 

The original patch e512a9ce367 was still racy in some conditions
as other rpc.* and nfs* processes were holding a lock on the filesystem.

stopping nfs in kernel is simply not enough in rhel5

this fixed version does stop nfs completely and re-instante nfs exports.

Resolves: rhbz#822066

Signed-off-by: Fabio M. Di Nitto 
---
 rgmanager/src/resources/clusterfs.sh |   31 ---
 rgmanager/src/resources/fs.sh|   31 ---
 2 files changed, 40 insertions(+), 22 deletions(-)

diff --git a/rgmanager/src/resources/clusterfs.sh 
b/rgmanager/src/resources/clusterfs.sh
index 89b30a2..49eb724 100755
--- a/rgmanager/src/resources/clusterfs.sh
+++ b/rgmanager/src/resources/clusterfs.sh
@@ -681,7 +681,10 @@ stopFilesystem() {
typeset -i max_tries=3  # how many times to try umount
typeset -i sleep_time=2 # time between each umount failure
typeset -i refs=0
-   typeset nfsdthreads
+   typeset nfsexports=""
+   typeset nfsexp=""
+   typeset nfsopts=""
+   typeset nfsacl=""
typeset done=""
typeset umount_failed=""
typeset force_umount=""
@@ -804,16 +807,22 @@ stop: Could not match $OCF_RESKEY_device with a real 
device"
 
if [ "$OCF_RESKEY_nfsrestart" = "yes" ] 
|| \
   [ "$OCF_RESKEY_nfsrestart" = "1" ]; 
then
-   if [ -f /proc/fs/nfsd/threads 
]; then
-   ocf_log warning 
"Restarting nfsd/nfslock"
-   nfsdthreads="$(cat 
/proc/fs/nfsd/threads)"
-   service nfslock stop
-   echo 0 > 
/proc/fs/nfsd/threads
-   echo $nfsdthreads > 
/proc/fs/nfsd/threads
-   service nfslock start
-   else
-   ocf_log err "Unable to 
determin nfsd information. nfsd restart aborted"
-   fi
+   ocf_log warning "Restarting 
nfsd/nfslock"
+   nfsexports=$(cat 
/var/lib/nfs/etab)
+   service nfslock stop
+   service nfs stop
+   service nfs start
+   service nfslock start
+   echo "$nfsexports" | { while 
read line; do
+   nfsexp=$(echo $line | 
awk '{print $1}')
+   nfsopts=$(echo $line | 
sed -e 's#.*(##g' -e 's#).*##g')
+   nfsacl=$(echo $line | 
awk '{print $2}' | sed -e 's#(.*##g')
+   if [ -n "$nfsopts" ]; 
then
+   exportfs -i -o 
"$nfsopts" "$nfsacl":$nfsexp
+   else
+   exportfs -i 
"$nfsacl":$nfsexp
+   fi
+   done; }
fi
 
else
diff --git a/rgmanager/src/resources/fs.sh b/rgmanager/src/resources/fs.sh
index 5724352..a98cddc 100755
--- a/rgmanager/src/resources/fs.sh
+++ b/rgmanager/src/resources/fs.sh
@@ -1019,7 +1019,10 @@ stopFilesystem() {
typeset -i max_tries=3  # how many times to try umount
typeset -i sleep_time=5 # time between each umount failure
typeset -i nfslock_reclaim=0
-   typeset nfsdthreads
+   typeset nfsexports=""
+   typeset nfsexp=""
+   typeset nfsopts=""
+   typeset nfsacl=""
typeset done=""
typeset umount_failed=""
typeset force_umount=""
@@ -1126,16 +1129,22 @@ stop: Could not match $OCF_RESKEY_device with a real 
device"
 
  if [ "$OCF_RESKEY_nfsrestart" = "yes" ] || \
 [ "$OCF_RESKEY_nfsrestart" = "1" ]; then
-   if [ -f /proc/fs/nfsd/threads ]; then
-   ocf_log warning "Restarting 
nfsd/nfslock"
-   nfsdthreads="$(cat 
/proc/fs/nfsd/threads)"
-   service nfslock stop
-   echo 0 > /pr