]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
VLockFile: Do not close fd on lock failure
authorAndrew Deason <adeason@sinenomine.net>
Thu, 18 Feb 2010 17:42:27 +0000 (11:42 -0600)
committerDerrick Brashear <shadow@dementia.org>
Wed, 24 Feb 2010 06:28:16 +0000 (22:28 -0800)
When we fail to acquire a lock in _VLockFd, do not close the fd if we
fail to acquire the lock for any reason, since VLockFile does that for
us already. There also may be other locks on that file, and we clearly
do not want to release them when just one lock fails. VLockFile takes
care of the necessary refcounting and fd closing, so don't do it in
_VLockFd too.

Change-Id: I65f27837dad033e0e84faf4aa0fb71ff26feda83
Reviewed-on: http://gerrit.openafs.org/1344
Tested-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Tested-by: Derrick Brashear <shadow@dementia.org>
src/vol/vutil.c

index 09360e80f0216bbcb5b7e41adce78a19096c16e1..8b28f9c95d9f55535fe9382d7de950f3ac1b6737 100644 (file)
@@ -892,10 +892,8 @@ _VLockFd(FD_t handle, afs_uint32 offset, int locktype, int nonblock)
 
     if (!LockFileEx(handle, flags, 0, 1, 0, &lap)) {
        if (GetLastError() == ERROR_LOCK_VIOLATION) {
-           CloseHandle(handle);
            return EBUSY;
        }
-       CloseHandle(handle);
        return EIO;
     }
 
@@ -977,12 +975,10 @@ _VLockFd(int fd, afs_uint32 offset, int locktype, int nonblock)
     if (fcntl(fd, cmd, &sf)) {
        if (nonblock && (errno == EACCES || errno == EAGAIN)) {
            /* We asked for a nonblocking lock, and it was already locked */
-           close(fd);
            return EBUSY;
        }
        Log("_VLockFd: fcntl failed with error %d when trying to lock "
            "fd %d (locktype=%d)\n", errno, fd, locktype);
-       close(fd);
        return EIO;
     }