svn commit: r218321 - in projects/graid/head: sbin/geom/class/raid sys/geom/raid

Alexander Motin mav at FreeBSD.org
Sat Feb 5 12:56:29 UTC 2011


Author: mav
Date: Sat Feb  5 12:56:29 2011
New Revision: 218321
URL: http://svn.freebsd.org/changeset/base/218321

Log:
  Add -f argument to `graid delete` to specify whether open volume should be
  destroyed.

Modified:
  projects/graid/head/sbin/geom/class/raid/geom_raid.c
  projects/graid/head/sbin/geom/class/raid/graid.8
  projects/graid/head/sys/geom/raid/g_raid.c
  projects/graid/head/sys/geom/raid/g_raid.h
  projects/graid/head/sys/geom/raid/md_intel.c

Modified: projects/graid/head/sbin/geom/class/raid/geom_raid.c
==============================================================================
--- projects/graid/head/sbin/geom/class/raid/geom_raid.c	Sat Feb  5 12:54:59 2011	(r218320)
+++ projects/graid/head/sbin/geom/class/raid/geom_raid.c	Sat Feb  5 12:56:29 2011	(r218321)
@@ -61,8 +61,12 @@ struct g_command class_commands[] = {
 	    },
 	    "[-S size] [-s stripsize] name label level"
 	},
-	{ "delete", G_FLAG_VERBOSE, NULL, G_NULL_OPTS,
-	    "[-v] name [label|num]"
+	{ "delete", G_FLAG_VERBOSE, NULL,
+	    {
+		{ 'f', "force", NULL, G_TYPE_BOOL },
+		G_OPT_SENTINEL
+	    },
+	    "[-fv] name [label|num]"
 	},
 	{ "insert", G_FLAG_VERBOSE, NULL, G_NULL_OPTS,
 	    "[-v] name prov ..."

Modified: projects/graid/head/sbin/geom/class/raid/graid.8
==============================================================================
--- projects/graid/head/sbin/geom/class/raid/graid.8	Sat Feb  5 12:54:59 2011	(r218320)
+++ projects/graid/head/sbin/geom/class/raid/graid.8	Sat Feb  5 12:56:29 2011	(r218321)
@@ -24,7 +24,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd February 3, 2011
+.Dd February 5, 2011
 .Dt GRAID 8
 .Os
 .Sh NAME
@@ -48,6 +48,7 @@
 .Ar level
 .Nm
 .Cm delete
+.Op Fl f
 .Ar name
 .Op Ar label | Ar num
 .Nm
@@ -142,6 +143,12 @@ Optional
 or
 .Ar num
 arguments allow specifying volume for deletion.
+.Pp
+Additional options include:
+.Bl -tag -width ".Fl f"
+.It Fl f
+Delete volume(s) even if it is still open.
+.El
 .It Cm insert
 Insert specified provider(s) into specified array instead of the first missing
 or failed components.

Modified: projects/graid/head/sys/geom/raid/g_raid.c
==============================================================================
--- projects/graid/head/sys/geom/raid/g_raid.c	Sat Feb  5 12:54:59 2011	(r218320)
+++ projects/graid/head/sys/geom/raid/g_raid.c	Sat Feb  5 12:56:29 2011	(r218321)
@@ -576,6 +576,20 @@ g_raid_nrequests(struct g_raid_softc *sc
 	return (nreqs);
 }
 
+u_int
+g_raid_nopens(struct g_raid_softc *sc)
+{
+	struct g_raid_volume *vol;
+	u_int opens;
+
+	opens = 0;
+	TAILQ_FOREACH(vol, &sc->sc_volumes, v_next) {
+		if (vol->v_provider_open != 0)
+			opens++;
+	}
+	return (opens);
+}
+
 static int
 g_raid_consumer_is_busy(struct g_raid_softc *sc, struct g_consumer *cp)
 {
@@ -1442,7 +1456,7 @@ g_raid_update_node(struct g_raid_softc *
 static int
 g_raid_access(struct g_provider *pp, int acr, int acw, int ace)
 {
-	struct g_raid_volume *vol, *vol1;
+	struct g_raid_volume *vol;
 	struct g_raid_softc *sc;
 	int dcr, dcw, dce, opens, error = 0;
 
@@ -1473,11 +1487,7 @@ g_raid_access(struct g_provider *pp, int
 	if (sc->sc_stopping == G_RAID_DESTROY_DELAYED &&
 	    vol->v_provider_open == 0) {
 		/* Count open volumes. */
-		opens = 0;
-		TAILQ_FOREACH(vol1, &sc->sc_volumes, v_next) {
-			if (vol1->v_provider_open != 0)
-				opens++;
-		}
+		opens = g_raid_nopens(sc);
 		if (opens == 0) {
 			sc->sc_stopping = G_RAID_DESTROY_HARD;
 			g_raid_event_send(sc, 0, 0);	/* Wake up worker. */
@@ -1752,7 +1762,6 @@ g_raid_destroy_disk(struct g_raid_disk *
 int
 g_raid_destroy(struct g_raid_softc *sc, int how)
 {
-	struct g_raid_volume *vol;
 	int opens;
 
 	g_topology_assert_not();
@@ -1761,11 +1770,7 @@ g_raid_destroy(struct g_raid_softc *sc, 
 	sx_assert(&sc->sc_lock, SX_XLOCKED);
 
 	/* Count open volumes. */
-	opens = 0;
-	TAILQ_FOREACH(vol, &sc->sc_volumes, v_next) {
-		if (vol->v_provider_open != 0)
-			opens++;
-	}
+	opens = g_raid_nopens(sc);
 
 	/* React on some opened volumes. */
 	if (opens > 0) {

Modified: projects/graid/head/sys/geom/raid/g_raid.h
==============================================================================
--- projects/graid/head/sys/geom/raid/g_raid.h	Sat Feb  5 12:54:59 2011	(r218320)
+++ projects/graid/head/sys/geom/raid/g_raid.h	Sat Feb  5 12:56:29 2011	(r218321)
@@ -356,6 +356,7 @@ int g_raid_tr_kerneldump_common(struct g
 
 u_int g_raid_ndisks(struct g_raid_softc *sc, int state);
 u_int g_raid_nsubdisks(struct g_raid_volume *vol, int state);
+u_int g_raid_nopens(struct g_raid_softc *sc);
 #define	G_RAID_DESTROY_SOFT		0
 #define	G_RAID_DESTROY_DELAYED	1
 #define	G_RAID_DESTROY_HARD		2

Modified: projects/graid/head/sys/geom/raid/md_intel.c
==============================================================================
--- projects/graid/head/sys/geom/raid/md_intel.c	Sat Feb  5 12:54:59 2011	(r218320)
+++ projects/graid/head/sys/geom/raid/md_intel.c	Sat Feb  5 12:56:29 2011	(r218321)
@@ -1227,7 +1227,7 @@ g_raid_md_ctl_intel(struct g_raid_md_obj
 	char arg[16], serial[INTEL_SERIAL_LEN];
 	const char *verb, *volname, *levelname, *diskname;
 	char *tmp;
-	int *nargs;
+	int *nargs, *force;
 	off_t off, size, sectorsize, strip;
 	intmax_t *sizearg, *striparg;
 	int numdisks, i, len, level, qual, update;
@@ -1632,6 +1632,14 @@ makedisk:
 
 		/* Full node destruction. */
 		if (*nargs == 1) {
+			/* Check if some volume is still open. */
+			force = gctl_get_paraml(req, "force", sizeof(*force));
+			if (force != NULL && *force == 0 &&
+			    g_raid_nopens(sc) != 0) {
+				gctl_error(req, "Some volume is still open.");
+				return (-4);
+			}
+
 			TAILQ_FOREACH(disk, &sc->sc_disks, d_next) {
 				if (disk->d_consumer)
 					intel_meta_erase(disk->d_consumer);
@@ -1670,6 +1678,14 @@ makedisk:
 			return (-3);
 		}
 
+		/* Check if volume is still open. */
+		force = gctl_get_paraml(req, "force", sizeof(*force));
+		if (force != NULL && *force == 0 &&
+		    vol->v_provider_open != 0) {
+			gctl_error(req, "Volume is still open.");
+			return (-4);
+		}
+
 		/* Destroy volume and potentially node. */
 		i = 0;
 		TAILQ_FOREACH(vol1, &sc->sc_volumes, v_next)


More information about the svn-src-projects mailing list