[Midnightbsd-cvs] src [8681] trunk: allow to insert new component to geom_raid3

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sun Sep 25 18:01:25 EDT 2016


Revision: 8681
          http://svnweb.midnightbsd.org/src/?rev=8681
Author:   laffer1
Date:     2016-09-25 18:01:24 -0400 (Sun, 25 Sep 2016)
Log Message:
-----------
allow to insert new component to geom_raid3

Modified Paths:
--------------
    trunk/sbin/geom/class/raid3/geom_raid3.c
    trunk/sbin/geom/class/raid3/graid3.8
    trunk/sys/geom/raid3/g_raid3_ctl.c

Modified: trunk/sbin/geom/class/raid3/geom_raid3.c
===================================================================
--- trunk/sbin/geom/class/raid3/geom_raid3.c	2016-09-25 22:00:57 UTC (rev 8680)
+++ trunk/sbin/geom/class/raid3/geom_raid3.c	2016-09-25 22:01:24 UTC (rev 8681)
@@ -76,7 +76,7 @@
 	{ "insert", G_FLAG_VERBOSE, NULL,
 	    {
 		{ 'h', "hardcode", NULL, G_TYPE_BOOL },
-		{ 'n', "number", NULL, G_TYPE_NUMBER },
+		{ 'n', "number", G_VAL_OPTIONAL, G_TYPE_NUMBER },
 		G_OPT_SENTINEL
 	    },
 	    "[-hv] <-n number> name prov"

Modified: trunk/sbin/geom/class/raid3/graid3.8
===================================================================
--- trunk/sbin/geom/class/raid3/graid3.8	2016-09-25 22:00:57 UTC (rev 8680)
+++ trunk/sbin/geom/class/raid3/graid3.8	2016-09-25 22:01:24 UTC (rev 8681)
@@ -24,7 +24,7 @@
 .\"
 .\" $MidnightBSD$
 .\"
-.Dd January 5, 2010
+.Dd January 15, 2012
 .Dt GRAID3 8
 .Os
 .Sh NAME
@@ -53,7 +53,7 @@
 .Nm
 .Cm insert
 .Op Fl hv
-.Fl n Ar number
+.Op Fl n Ar number
 .Ar name
 .Ar prov
 .Nm
@@ -171,6 +171,8 @@
 removed previously with the
 .Cm remove
 command or if one component is missing and will not be connected again.
+If no number is given, new component will be added instead of first missed
+component.
 .Pp
 Additional options include:
 .Bl -tag -width ".Fl h"

Modified: trunk/sys/geom/raid3/g_raid3_ctl.c
===================================================================
--- trunk/sys/geom/raid3/g_raid3_ctl.c	2016-09-25 22:00:57 UTC (rev 8680)
+++ trunk/sys/geom/raid3/g_raid3_ctl.c	2016-09-25 22:01:24 UTC (rev 8681)
@@ -1,4 +1,4 @@
-/* $MidnightBSD: src/sys/geom/raid3/g_raid3_ctl.c,v 1.4 2008/12/03 00:25:50 laffer1 Exp $ */
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2004-2006 Pawel Jakub Dawidek <pjd at FreeBSD.org>
  * All rights reserved.
@@ -405,7 +405,7 @@
 	u_char *sector;
 	off_t compsize;
 	intmax_t *no;
-	int *hardcode, *nargs, error;
+	int *hardcode, *nargs, error, autono;
 
 	nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs));
 	if (nargs == NULL) {
@@ -426,11 +426,10 @@
 		gctl_error(req, "No 'arg%u' argument.", 1);
 		return;
 	}
-	no = gctl_get_paraml(req, "number", sizeof(*no));
-	if (no == NULL) {
-		gctl_error(req, "No '%s' argument.", "no");
-		return;
-	}
+	if (gctl_get_param(req, "number", NULL) != NULL)
+		no = gctl_get_paraml(req, "number", sizeof(*no));
+	else
+		no = NULL;
 	if (strncmp(name, "/dev/", 5) == 0)
 		name += 5;
 	g_topology_lock();
@@ -466,17 +465,31 @@
 		gctl_error(req, "No such device: %s.", name);
 		goto end;
 	}
-	if (*no >= sc->sc_ndisks) {
-		sx_xunlock(&sc->sc_lock);
-		gctl_error(req, "Invalid component number.");
-		goto end;
+	if (no != NULL) {
+		if (*no < 0 || *no >= sc->sc_ndisks) {
+			sx_xunlock(&sc->sc_lock);
+			gctl_error(req, "Invalid component number.");
+			goto end;
+		}
+		disk = &sc->sc_disks[*no];
+		if (disk->d_state != G_RAID3_DISK_STATE_NODISK) {
+			sx_xunlock(&sc->sc_lock);
+			gctl_error(req, "Component %jd is already connected.",
+			    *no);
+			goto end;
+		}
+	} else {
+		disk = NULL;
+		for (autono = 0; autono < sc->sc_ndisks && disk == NULL; autono++)
+			if (sc->sc_disks[autono].d_state ==
+			    G_RAID3_DISK_STATE_NODISK)
+				disk = &sc->sc_disks[autono];
+		if (disk == NULL) {
+			sx_xunlock(&sc->sc_lock);
+			gctl_error(req, "No disconnected components.");
+			goto end;
+		}
 	}
-	disk = &sc->sc_disks[*no];
-	if (disk->d_state != G_RAID3_DISK_STATE_NODISK) {
-		sx_xunlock(&sc->sc_lock);
-		gctl_error(req, "Component %jd is already connected.", *no);
-		goto end;
-	}
 	if (((sc->sc_sectorsize / (sc->sc_ndisks - 1)) % pp->sectorsize) != 0) {
 		sx_xunlock(&sc->sc_lock);
 		gctl_error(req,



More information about the Midnightbsd-cvs mailing list