Module Name:    src
Committed By:   dyoung
Date:           Thu Jul 23 21:38:33 UTC 2009

Modified Files:
        src/sys/dev: ld.c

Log Message:
Extract ldlastclose() and use it in ldclose().  At the top of
ldbegindetach(), call disk_begindetach(..., ldlastclose, ...).

Compiles.  Not tested.


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/sys/dev/ld.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/ld.c
diff -u src/sys/dev/ld.c:1.65 src/sys/dev/ld.c:1.66
--- src/sys/dev/ld.c:1.65	Thu May  7 09:11:42 2009
+++ src/sys/dev/ld.c	Thu Jul 23 21:38:33 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: ld.c,v 1.65 2009/05/07 09:11:42 cegger Exp $	*/
+/*	$NetBSD: ld.c,v 1.66 2009/07/23 21:38:33 dyoung Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ld.c,v 1.65 2009/05/07 09:11:42 cegger Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ld.c,v 1.66 2009/07/23 21:38:33 dyoung Exp $");
 
 #include "rnd.h"
 
@@ -71,6 +71,7 @@
 static void	ldstart(struct ld_softc *, struct buf *);
 static void	ld_set_properties(struct ld_softc *);
 static void	ld_config_interrupts (device_t);
+static int	ldlastclose(device_t);
 
 extern struct	cfdriver ld_cd;
 
@@ -183,8 +184,10 @@
 	if ((sc->sc_flags & LDF_ENABLED) == 0)
 		return (0);
 
-	if ((flags & DETACH_FORCE) == 0 && sc->sc_dk.dk_openmask != 0)
-		return (EBUSY);
+	rv = disk_begindetach(&sc->sc_dk, ldlastclose, sc->sc_dv, flags);
+
+	if (rv != 0)
+		return rv;
 
 	s = splbio();
 	sc->sc_maxqueuecnt = 0;
@@ -321,6 +324,19 @@
 	return (error);
 }
 
+static int
+ldlastclose(device_t self)
+{
+	struct ld_softc *sc = device_private(self);
+
+	if (sc->sc_flush != NULL && (*sc->sc_flush)(sc, 0) != 0)
+		aprint_error_dev(self, "unable to flush cache\n");
+	if ((sc->sc_flags & LDF_KLABEL) == 0)
+		sc->sc_flags &= ~LDF_VLABEL;
+
+	return 0;
+}
+
 /* ARGSUSED */
 static int
 ldclose(dev_t dev, int flags, int fmt, struct lwp *l)
@@ -345,12 +361,8 @@
 	sc->sc_dk.dk_openmask =
 	    sc->sc_dk.dk_copenmask | sc->sc_dk.dk_bopenmask;
 
-	if (sc->sc_dk.dk_openmask == 0) {
-		if (sc->sc_flush != NULL && (*sc->sc_flush)(sc, 0) != 0)
-			aprint_error_dev(sc->sc_dv, "unable to flush cache\n");
-		if ((sc->sc_flags & LDF_KLABEL) == 0)
-			sc->sc_flags &= ~LDF_VLABEL;
-	}
+	if (sc->sc_dk.dk_openmask == 0)
+		ldlastclose(sc->sc_dv);
 
 	mutex_exit(&sc->sc_dk.dk_openlock);
 	return (0);

Reply via email to