[OpenAFS-devel] [PATCH] fix file locking crash on linux

Christopher Allen Wing wingc@engin.umich.edu
Thu, 8 Feb 2007 16:04:43 -0500 (EST)


The following fixes the crash and seems ok on RHEL4 (2.6.9 kernel).  I 
haven't tried it on newer 2.6 kernels.  I might have an opportunity to try 
it out on RHEL5 tomorrow, which is 2.6.18 based and thus has the 'new' API 
for flock_lock_file*().

I believe it is safe to just clear FL_SLEEP in the structure handed to us, 
assuming that we want to retain the current semantics (tell the kernel 
never to wait when we ask it to perform a locking operation):


--- openafs-1.4.x/src/afs/LINUX/osi_vnodeops.c.orig	2007-02-08 14:22:27.000000000 -0500
+++ openafs-1.4.x/src/afs/LINUX/osi_vnodeops.c	2007-02-08 14:28:26.000000000 -0500
@@ -475,10 +475,8 @@
      if ((code == 0 || flp->fl_type == F_UNLCK) &&
          (cmd == F_SETLK || cmd == F_SETLKW)) {
  #ifdef AFS_LINUX26_ENV
-       struct file_lock flp2;
-       flp2 = *flp;
-       flp2.fl_flags &=~ FL_SLEEP;
-       code = posix_lock_file(fp, &flp2);
+       flp->fl_flags &=~ FL_SLEEP;
+       code = posix_lock_file(fp, flp);
  #else
         code = posix_lock_file(fp, flp, 0);
  #endif 
@@ -534,10 +532,8 @@

      if ((code == 0 || flp->fl_type == F_UNLCK) &&
          (cmd == F_SETLK || cmd == F_SETLKW)) {
-       struct file_lock flp2;
-       flp2 = *flp;
-       flp2.fl_flags &=~ FL_SLEEP;
-       code = flock_lock_file_wait(fp, &flp2);
+       flp->fl_flags &=~ FL_SLEEP;
+       code = flock_lock_file_wait(fp, flp);
         if (code && flp->fl_type != F_UNLCK) {
             struct AFS_FLOCK flock2;
             flock2 = flock;



Anyone interested in trying this on linux-2.4 or linux-2.6.17+?


-Chris
wingc@engin.umich.edu