Module Name: src
Committed By: dyoung
Date: Tue May 19 20:25:41 UTC 2009
Modified Files:
src/sys/dev: md.c
Log Message:
Add a detachment hook. Detach md(4) at shutdown.
To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 src/sys/dev/md.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/dev/md.c
diff -u src/sys/dev/md.c:1.58 src/sys/dev/md.c:1.59
--- src/sys/dev/md.c:1.58 Mon May 4 16:20:41 2009
+++ src/sys/dev/md.c Tue May 19 20:25:41 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: md.c,v 1.58 2009/05/04 16:20:41 manu Exp $ */
+/* $NetBSD: md.c,v 1.59 2009/05/19 20:25:41 dyoung Exp $ */
/*
* Copyright (c) 1995 Gordon W. Ross, Leo Weppelman.
@@ -46,7 +46,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: md.c,v 1.58 2009/05/04 16:20:41 manu Exp $");
+__KERNEL_RCSID(0, "$NetBSD: md.c,v 1.59 2009/05/19 20:25:41 dyoung Exp $");
#include "opt_md.h"
#include "opt_tftproot.h"
@@ -95,6 +95,7 @@
void mdattach(int);
static void md_attach(device_t, device_t, void *);
+static int md_detach(device_t, int);
static dev_type_open(mdopen);
static dev_type_close(mdclose);
@@ -116,8 +117,8 @@
static struct dkdriver mddkdriver = { mdstrategy, NULL };
extern struct cfdriver md_cd;
-CFATTACH_DECL_NEW(md, sizeof(struct md_softc),
- 0, md_attach, 0, NULL);
+CFATTACH_DECL3_NEW(md, sizeof(struct md_softc),
+ 0, md_attach, md_detach, NULL, NULL, NULL, DVF_DETACH_SHUTDOWN);
extern size_t md_root_size;
@@ -159,8 +160,7 @@
}
static void
-md_attach(device_t parent, device_t self,
- void *aux)
+md_attach(device_t parent, device_t self, void *aux)
{
struct md_softc *sc = device_private(self);
@@ -186,6 +186,30 @@
aprint_error_dev(self, "couldn't establish power handler\n");
}
+static int
+md_detach(device_t self, int flags)
+{
+ struct md_softc *sc = device_private(self);
+ int rc;
+
+ rc = 0;
+ mutex_enter(&sc->sc_dkdev.dk_openlock);
+ if (sc->sc_dkdev.dk_openmask == 0)
+ ; /* nothing to do */
+ else if ((flags & DETACH_FORCE) == 0)
+ rc = EBUSY;
+ mutex_exit(&sc->sc_dkdev.dk_openlock);
+
+ if (rc != 0)
+ return rc;
+
+ pmf_device_deregister(self);
+ disk_detach(&sc->sc_dkdev);
+ disk_destroy(&sc->sc_dkdev);
+ bufq_free(sc->sc_buflist);
+ return 0;
+}
+
/*
* operational routines:
* open, close, read, write, strategy,