summaryrefslogtreecommitdiffstats
path: root/sys/kern/subr_disk.c
diff options
context:
space:
mode:
authorcsapuntz <csapuntz@openbsd.org>2000-04-09 19:26:35 +0000
committercsapuntz <csapuntz@openbsd.org>2000-04-09 19:26:35 +0000
commit501b64689d39b8491dc3beb65e0b3af882e305bd (patch)
treef65a502b39d210c2936bedbbf1ce3ea11d11fa82 /sys/kern/subr_disk.c
parentAdded config_detach_children, config_activate_children. (diff)
downloadwireguard-openbsd-501b64689d39b8491dc3beb65e0b3af882e305bd.tar.xz
wireguard-openbsd-501b64689d39b8491dc3beb65e0b3af882e305bd.zip
Move a locking function that was spread throughout disk device drivers into
the disk structure. The locking was mostly used in disk device drivers to prevent multiple disklabel operations from going on simultaneously against the device. Added disk_construct(), a constructor for the disk structure, that initializes the lock structure in disk. It is called by default in disk_attach() if it hasn't been called yet. Added disk_lock and disk_unlock
Diffstat (limited to 'sys/kern/subr_disk.c')
-rw-r--r--sys/kern/subr_disk.c40
1 files changed, 39 insertions, 1 deletions
diff --git a/sys/kern/subr_disk.c b/sys/kern/subr_disk.c
index 5d8f8fda806..a166a72c4a1 100644
--- a/sys/kern/subr_disk.c
+++ b/sys/kern/subr_disk.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: subr_disk.c,v 1.17 1999/11/17 04:31:22 d Exp $ */
+/* $OpenBSD: subr_disk.c,v 1.18 2000/04/09 19:26:35 csapuntz Exp $ */
/* $NetBSD: subr_disk.c,v 1.17 1996/03/16 23:17:08 christos Exp $ */
/*
@@ -53,9 +53,11 @@
#include <sys/time.h>
#include <sys/disklabel.h>
#include <sys/conf.h>
+#include <sys/lock.h>
#include <sys/disk.h>
#include <sys/dkio.h>
#include <sys/dkstat.h> /* XXX */
+#include <sys/proc.h>
#include <dev/rndvar.h>
@@ -266,6 +268,19 @@ disk_find(name)
return (NULL);
}
+int
+disk_construct(diskp, lockname)
+ struct disk *diskp;
+ char *lockname;
+{
+ lockinit(&diskp->dk_lock, PRIBIO | PCATCH, lockname,
+ 0, LK_CANRECURSE);
+
+ diskp->dk_flags |= DKF_CONSTRUCTED;
+
+ return (0);
+}
+
/*
* Attach a disk.
*/
@@ -275,6 +290,9 @@ disk_attach(diskp)
{
int s;
+ if (!diskp->dk_flags & DKF_CONSTRUCTED)
+ disk_construct(diskp, diskp->dk_name);
+
/*
* Allocate and initialize the disklabel structures. Note that
* it's not safe to sleep here, since we're probably going to be
@@ -378,6 +396,26 @@ disk_unbusy(diskp, bcount)
add_disk_randomness(bcount ^ diff_time.tv_usec);
}
+
+int
+disk_lock(dk)
+ struct disk *dk;
+{
+ int error;
+
+ error = lockmgr(&dk->dk_lock, LK_EXCLUSIVE, 0, curproc);
+
+ return (error);
+}
+
+void
+disk_unlock(dk)
+ struct disk *dk;
+{
+ lockmgr(&dk->dk_lock, LK_RELEASE, 0, curproc);
+}
+
+
/*
* Reset the metrics counters on the given disk. Note that we cannot
* reset the busy counter, as it may case a panic in disk_unbusy().