summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorJoel Sing <jsing@cvs.openbsd.org>2010-09-23 13:20:37 +0000
committerJoel Sing <jsing@cvs.openbsd.org>2010-09-23 13:20:37 +0000
commit2a8b624950fde478a9b81a7a9cee5ddefe4aa7b5 (patch)
tree5dcb12e164ebef9c47db6b3b6d2560bb5c33367c /sys
parent9ff999e5b9b73ca6f102ddb22fc7d68f22e0edd9 (diff)
When a disk is attached create a workq task to read the disklabel,
providing the DKF_NOLABELREAD flag is not set. This provides the kernel with the actual disklabel which includes the disklabel UID. ok deraadt@ miod@ krw@
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/subr_disk.c36
1 files changed, 35 insertions, 1 deletions
diff --git a/sys/kern/subr_disk.c b/sys/kern/subr_disk.c
index fbdf1a78d30..f6f47712473 100644
--- a/sys/kern/subr_disk.c
+++ b/sys/kern/subr_disk.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: subr_disk.c,v 1.109 2010/09/08 15:16:22 jsing Exp $ */
+/* $OpenBSD: subr_disk.c,v 1.110 2010/09/23 13:20:36 jsing Exp $ */
/* $NetBSD: subr_disk.c,v 1.17 1996/03/16 23:17:08 christos Exp $ */
/*
@@ -57,6 +57,7 @@
#include <sys/dkstat.h> /* XXX */
#include <sys/proc.h>
#include <sys/vnode.h>
+#include <sys/workq.h>
#include <uvm/uvm_extern.h>
#include <sys/socket.h>
@@ -82,6 +83,7 @@ int disk_change; /* set if a disk has been attached/detached
void (*softraid_disk_attach)(struct disk *, int);
char *disk_readlabel(struct disklabel *, dev_t);
+void disk_attach_callback(void *, void *);
/*
* Seek sort for disks. We depend on the driver which calls us using b_resid
@@ -793,6 +795,7 @@ void
disk_attach(struct device *dv, struct disk *diskp)
{
int majdev;
+ dev_t *dev;
if (!ISSET(diskp->dk_flags, DKF_CONSTRUCTED))
disk_construct(diskp, diskp->dk_name);
@@ -830,11 +833,42 @@ disk_attach(struct device *dv, struct disk *diskp)
diskp->dk_devno =
MAKEDISKDEV(majdev, dv->dv_unit, RAW_PART);
}
+ if (diskp->dk_devno != NODEV) {
+ dev = malloc(sizeof(dev_t), M_DEVBUF, M_NOWAIT);
+ if (dev == NULL)
+ panic("failed to allocate memory for dev no");
+ *dev = diskp->dk_devno;
+ if (workq_add_task(NULL, 0, disk_attach_callback, dev, NULL))
+ free(dev, M_DEVBUF);
+ }
if (softraid_disk_attach)
softraid_disk_attach(diskp, 1);
}
+void
+disk_attach_callback(void *arg1, void *arg2)
+{
+ struct disklabel dl;
+ struct disk *dk;
+ dev_t dev = *((dev_t *)arg1);
+
+ /* Locate disk associated with device no. */
+ TAILQ_FOREACH(dk, &disklist, dk_link) {
+ if (dk->dk_devno == dev)
+ break;
+ }
+ if (dk == NULL || (dk->dk_flags & (DKF_OPENED | DKF_NOLABELREAD)))
+ goto done;
+
+ /* Read disklabel. */
+ disk_readlabel(&dl, dev);
+ dk->dk_flags |= DKF_OPENED;
+
+done:
+ free(arg1, M_DEVBUF);
+}
+
/*
* Detach a disk.
*/