From 797fe86a8e6f7b6306e9dc2c3de1432e5fcbc0c2 Mon Sep 17 00:00:00 2001 From: Andrew Deason Date: Fri, 19 Feb 2010 16:48:30 -0600 Subject: [PATCH] Add VLockFileReinit Add a VLockFile function, VLockFileReinit, to close all locks on that particular lock file. Change-Id: Ie1e4af21a486fb0451b6d613117027a522c9bb5a Reviewed-on: http://gerrit.openafs.org/1358 Reviewed-by: Derrick Brashear Tested-by: Derrick Brashear --- src/vol/volume.h | 1 + src/vol/vutil.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/vol/volume.h b/src/vol/volume.h index d34470b83..e4fd89295 100644 --- a/src/vol/volume.h +++ b/src/vol/volume.h @@ -821,6 +821,7 @@ extern char *vol_DevName(dev_t adev, char *wpath); struct VLockFile; extern void VLockFileInit(struct VLockFile *lf, const char *path); +extern void VLockFileReinit(struct VLockFile *lf); extern int VLockFileLock(struct VLockFile *lf, afs_uint32 offset, int locktype, int nonblock); extern void VLockFileUnlock(struct VLockFile *lf, afs_uint32 offset); diff --git a/src/vol/vutil.c b/src/vol/vutil.c index 131039d27..6fd42a22d 100644 --- a/src/vol/vutil.c +++ b/src/vol/vutil.c @@ -1031,6 +1031,39 @@ _VUnlockFd(int fd, afs_uint32 offset) } #endif /* !AFS_NT40_ENV */ +/** + * reinitialize a struct VLockFile. + * + * Use this to close the lock file (unlocking any locks in it), and effectively + * restore lf to the state it was in when it was initialized. This is the same + * as unlocking all of the locks on the file, without having to remember what + * all of the locks were. Do not unlock previously held locks after calling + * this. + * + * @param[in] lf struct VLockFile to reinit + * + * @pre nobody is waiting for a lock on this lockfile or otherwise using + * this lockfile at all + */ +void +VLockFileReinit(struct VLockFile *lf) +{ +#ifdef AFS_PTHREAD_ENV + assert(pthread_mutex_lock(&lf->mutex) == 0); +#endif /* AFS_PTHREAD_ENV */ + + if (lf->fd != INVALID_FD) { + _VCloseFd(lf->fd); + lf->fd = INVALID_FD; + } + + lf->refcount = 0; + +#ifdef AFS_PTHREAD_ENV + assert(pthread_mutex_unlock(&lf->mutex) == 0); +#endif /* AFS_PTHREAD_ENV */ +} + /** * lock a file on disk for the process. * -- 2.39.5