summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/subr_disk.c40
-rw-r--r--sys/sys/disk.h10
2 files changed, 48 insertions, 2 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().
diff --git a/sys/sys/disk.h b/sys/sys/disk.h
index 1fc3da62527..3802fc6243d 100644
--- a/sys/sys/disk.h
+++ b/sys/sys/disk.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: disk.h,v 1.4 1996/05/02 13:13:21 deraadt Exp $ */
+/* $OpenBSD: disk.h,v 1.5 2000/04/09 19:26:35 csapuntz Exp $ */
/* $NetBSD: disk.h,v 1.11 1996/04/28 20:22:50 thorpej Exp $ */
/*
@@ -54,6 +54,7 @@
#include <sys/time.h>
#include <sys/queue.h>
+#include <sys/lock.h>
struct buf;
struct disklabel;
@@ -61,7 +62,10 @@ struct cpu_disklabel;
struct disk {
TAILQ_ENTRY(disk) dk_link; /* link in global disklist */
+ struct lock dk_lock; /* disk lock */
char *dk_name; /* disk name */
+ int dk_flags; /* disk flags */
+#define DKF_CONSTRUCTED 0x0001
int dk_bopenmask; /* block devices open */
int dk_copenmask; /* character devices open */
int dk_openmask; /* composite (bopen|copen) */
@@ -138,6 +142,7 @@ TAILQ_HEAD(disklist_head, disk); /* the disklist is a TAILQ */
extern int disk_count; /* number of disks in global disklist */
void disk_init __P((void));
+int disk_construct __P((struct disk *, char *));
void disk_attach __P((struct disk *));
void disk_detach __P((struct disk *));
void disk_busy __P((struct disk *));
@@ -145,6 +150,9 @@ void disk_unbusy __P((struct disk *, long));
void disk_resetstat __P((struct disk *));
struct disk *disk_find __P((char *));
+int disk_lock __P((struct disk *));
+void disk_unlock __P((struct disk *));
+
struct device;
void dk_establish __P((struct disk *, struct device *));
#endif