vol: Handle large volume IDs in VLockFile
authorAndrew Deason <adeason@sinenomine.net>
Thu, 10 Mar 2011 23:59:39 +0000 (17:59 -0600)
committerDerrick Brashear <shadow@dementia.org>
Mon, 21 Mar 2011 17:27:24 +0000 (10:27 -0700)
VLockVolumeByIdNB currently cannot handle volume IDs larger than
2^31-1. Fix this by using struct flock64, F_SETLKW64, and F_SETLK64 in
the VLockFile functions where possible.

Thanks to Simon Wilkinson for pointing out F_SETLK64.

Change-Id: I422c685aec035716e2f42d13bd97541425ead6a2
Reviewed-on: http://gerrit.openafs.org/4198
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@dementia.org>

src/vol/vutil.c

index 92aaad2..55e60a6 100644 (file)
 #include <strings.h>
 #endif
 
+#ifndef AFS_NT40_ENV
+# ifdef O_LARGEFILE
+#  define AFS_SETLKW   F_SETLKW64
+#  define AFS_SETLK    F_SETLK64
+#  define afs_st_flock flock64
+# else
+#  define AFS_SETLKW   F_SETLKW
+#  define AFS_SETLK    F_SETLK
+#  define afs_st_flock flock
+# endif
+#endif
+
 /* Note:  the volume creation functions herein leave the destroyMe flag in the
    volume header ON:  this means that the volumes will not be attached by the
    file server and WILL BE DESTROYED the next time a system salvage is performed */
@@ -968,14 +980,14 @@ static_inline int
 _VLockFd(FD_t fd, afs_uint32 offset, int locktype, int nonblock)
 {
     int l_type = F_WRLCK;
-    int cmd = F_SETLKW;
-    struct flock sf;
+    int cmd = AFS_SETLKW;
+    struct afs_st_flock sf;
 
     if (locktype == READ_LOCK) {
        l_type = F_RDLCK;
     }
     if (nonblock) {
-       cmd = F_SETLK;
+       cmd = AFS_SETLK;
     }
 
     sf.l_start = offset;
@@ -1032,14 +1044,14 @@ _VCloseFd(FD_t fd)
 static_inline void
 _VUnlockFd(FD_t fd, afs_uint32 offset)
 {
-    struct flock sf;
+    struct afs_st_flock sf;
 
     sf.l_start = offset;
     sf.l_len = 1;
     sf.l_type = F_UNLCK;
     sf.l_whence = SEEK_SET;
 
-    if (fcntl(fd, F_SETLK, &sf)) {
+    if (fcntl(fd, AFS_SETLK, &sf)) {
        Log("_VUnlockFd: fcntl failed with error %d when trying to unlock "
            "fd %d\n", errno, fd);
     }