summaryrefslogtreecommitdiffstats
path: root/sys/dev/vinum/vinumlock.c
diff options
context:
space:
mode:
authorgrog <grog@FreeBSD.org>1999-01-21 00:37:38 +0000
committergrog <grog@FreeBSD.org>1999-01-21 00:37:38 +0000
commit3b8d5388cd71d59ce7ccdc089dd3625f0e34ddbd (patch)
treebc1275a065b8182e25f6d5093b4d00c8e6f3242d /sys/dev/vinum/vinumlock.c
parent5708c2c7d7e828172fa62ff2da0dde97e168baa0 (diff)
downloadFreeBSD-src-3b8d5388cd71d59ce7ccdc089dd3625f0e34ddbd.zip
FreeBSD-src-3b8d5388cd71d59ce7ccdc089dd3625f0e34ddbd.tar.gz
Create functions lockdrive and unlockdrive to handle drive locking
Diffstat (limited to 'sys/dev/vinum/vinumlock.c')
-rw-r--r--sys/dev/vinum/vinumlock.c37
1 files changed, 35 insertions, 2 deletions
diff --git a/sys/dev/vinum/vinumlock.c b/sys/dev/vinum/vinumlock.c
index a979408..b367dc5 100644
--- a/sys/dev/vinum/vinumlock.c
+++ b/sys/dev/vinum/vinumlock.c
@@ -33,7 +33,7 @@
* otherwise) arising in any way out of the use of this software, even if
* advised of the possibility of such damage.
*
- * $Id: lock.c,v 1.3 1998/12/28 04:56:23 peter Exp $
+ * $Id: vinumlock.c,v 1.8 1999/01/14 02:52:13 grog Exp grog $
*/
#define REALLYKERNEL
@@ -44,6 +44,39 @@
* or the global configuration. I don't think tsleep and
* wakeup are SMP safe. FIXME XXX */
+/* Lock a drive, wait if it's in use */
+int
+lockdrive(struct drive *drive)
+{
+ int error;
+
+ /* XXX get rid of drive->flags |= VF_LOCKING; */
+ while ((drive->flags & VF_LOCKED) != 0) {
+ /* There are problems sleeping on a unique identifier,
+ * since the drive structure can move, and the unlock
+ * function can be called after killing the drive.
+ * Solve this by waiting on this function; the number
+ * of conflicts is negligible */
+ if ((error = tsleep(&lockdrive,
+ PRIBIO | PCATCH,
+ "vindrv",
+ 0)) != 0)
+ return error;
+ }
+ drive->flags |= VF_LOCKED;
+ drive->pid = curproc->p_pid; /* it's a panic error if curproc is null */
+ return 0;
+}
+
+/* Unlock a drive and let the next one at it */
+void
+unlockdrive(struct drive *drive)
+{
+ drive->flags &= ~VF_LOCKED;
+ /* we don't reset pid: it's of hysterical interest */
+ wakeup(&lockdrive);
+}
+
/* Lock a volume, wait if it's in use */
int
lockvol(struct volume *vol)
@@ -86,7 +119,7 @@ lockplex(struct plex *plex)
while ((plex->flags & VF_LOCKED) != 0) {
plex->flags |= VF_LOCKING;
/* It would seem to make more sense to sleep on
- * the address 'plex'. Unfortuntaly we can't
+ * the address 'plex'. Unfortunately we can't
* guarantee that this address won't change due to
* table expansion. The address we choose won't change. */
if ((error = tsleep(&vinum_conf.plex + plex->sdnos[0],
OpenPOWER on IntegriCloud