]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
Add VLockFileReinit
authorAndrew Deason <adeason@sinenomine.net>
Fri, 19 Feb 2010 22:48:30 +0000 (16:48 -0600)
committerDerrick Brashear <shadow@dementia.org>
Tue, 9 Mar 2010 19:07:11 +0000 (11:07 -0800)
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 <shadow@dementia.org>
Tested-by: Derrick Brashear <shadow@dementia.org>
src/vol/volume.h
src/vol/vutil.c

index d34470b83ac5266c9f8c1431e04fa95266a95a85..e4fd89295f41bac78340a01f7ef513d17ccf7773 100644 (file)
@@ -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);
index 131039d2794264418c83703d144b067dacad2ba8..6fd42a22df847a527b65dd106cb5f4eac752164f 100644 (file)
@@ -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.
  *