Module Name:    src
Committed By:   mlelstv
Date:           Sat Jun  9 06:20:45 UTC 2012

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

Log Message:
autodiscover wedges


To generate a diff of this commit:
cvs rdiff -u -r1.220 -r1.221 src/sys/dev/vnd.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/vnd.c
diff -u src/sys/dev/vnd.c:1.220 src/sys/dev/vnd.c:1.221
--- src/sys/dev/vnd.c:1.220	Mon Mar 26 16:28:08 2012
+++ src/sys/dev/vnd.c	Sat Jun  9 06:20:45 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: vnd.c,v 1.220 2012/03/26 16:28:08 hannken Exp $	*/
+/*	$NetBSD: vnd.c,v 1.221 2012/06/09 06:20:45 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2008 The NetBSD Foundation, Inc.
@@ -91,7 +91,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vnd.c,v 1.220 2012/03/26 16:28:08 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vnd.c,v 1.221 2012/06/09 06:20:45 mlelstv Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_vnd.h"
@@ -332,15 +332,31 @@ vndopen(dev_t dev, int flags, int mode, 
 	part = DISKPART(dev);
 	pmask = (1 << part);
 
-	/*
-	 * If we're initialized, check to see if there are any other
-	 * open partitions.  If not, then it's safe to update the
-	 * in-core disklabel.  Only read the disklabel if it is
-	 * not already valid.
-	 */
-	if ((sc->sc_flags & (VNF_INITED|VNF_VLABEL)) == VNF_INITED &&
-	    sc->sc_dkdev.dk_openmask == 0)
-		vndgetdisklabel(dev, sc);
+	if (sc->sc_dkdev.dk_nwedges != 0 && part != RAW_PART) {
+		error = EBUSY;
+		goto done;
+	}
+
+	if (sc->sc_flags & VNF_INITED) {
+		if ((sc->sc_dkdev.dk_openmask & ~(1<<RAW_PART)) != 0) {
+			/*
+			 * If any non-raw partition is open, but the disk
+			 * has been invalidated, disallow further opens.
+			 */
+			if ((sc->sc_flags & VNF_VLABEL) == 0) {
+				error = EIO;
+				goto done;
+			}
+		} else {
+			/*
+			 * Load the partition info if not already loaded.
+			 */
+			if ((sc->sc_flags & VNF_VLABEL) == 0) {
+				sc->sc_flags |= VNF_VLABEL;
+				vndgetdisklabel(dev, sc);
+			}
+		}
+	}
 
 	/* Check that the partitions exists. */
 	if (part != RAW_PART) {
@@ -968,6 +984,9 @@ vnddoclear(struct vnd_softc *vnd, int pm
 		return EBUSY;
 	}
 
+	/* Delete all of our wedges */
+	dkwedge_delall(&vnd->sc_dkdev);
+
 	/*
 	 * XXX vndclear() might call vndclose() implicitly;
 	 * release lock to avoid recursion
@@ -1320,12 +1339,13 @@ vndioctl(dev_t dev, u_long cmd, void *da
 		pool_init(&vnd->sc_vxpool, sizeof(struct vndxfer), 0,
 		    0, 0, "vndxpl", NULL, IPL_BIO);
 
-		/* Try and read the disklabel. */
-		vndgetdisklabel(dev, vnd);
-
 		vndunlock(vnd);
 
 		pathbuf_destroy(pb);
+
+		/* Discover wedges on this disk */
+		dkwedge_discover(&vnd->sc_dkdev);
+
 		break;
 
 close_and_exit:
@@ -1827,9 +1847,6 @@ vndgetdisklabel(dev_t dev, struct vnd_so
 		lp->d_npartitions = MAXPARTITIONS;
 		lp->d_checksum = dkcksum(lp);
 	}
-
-	/* In-core label now valid. */
-	sc->sc_flags |= VNF_VLABEL;
 }
 
 /*

Reply via email to