Skip site navigation (1)Skip section navigation (2)
Date:      Thu,  8 Sep 2011 19:07:14 +0400 (MSD)
From:      Lev Serebryakov <lev@FreeBSD.org>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   kern/160562: [geom][patch] Allow to insert new component to geom_raid3 without specifying number.
Message-ID:  <20110908150714.C5CA74AC60@onlyone.friendlyhosting.spb.ru>
Resent-Message-ID: <201109081510.p88FA7ZD000633@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         160562
>Category:       kern
>Synopsis:       [geom][patch] Allow to insert new component to geom_raid3 without specifying number.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu Sep 08 15:10:07 UTC 2011
>Closed-Date:
>Last-Modified:
>Originator:     Lev Serebryakov <lev@FreeBSD.org>
>Release:        FreeBSD 9.0-BETA2 i386
>Organization:
>Environment:
System: FreeBSD vmware-9-32.home.serebryakov.spb.ru 9.0-BETA2 FreeBSD 9.0-BETA2 #1: Wed Sep 7 22:08:28 MSK 2011 lev@vmware-9-32.home.serebryakov.spb.ru:/usr/obj/usr/src/sys/VMWARE i386


>Description:
  Now "geom_raid3" requires "-n <number>" argument for "insert" command, which insert new component instead of removed (or failed) one.
  It is not convient in most cases (one lost component).
  This patch allows not to specify component number. In such case new component is added instead of first missed component.

>How-To-Repeat:

  Try to add new component to geom_raid3 without "-n" argument.
  
>Fix:
Index: sbin/geom/class/raid3/graid3.8
===================================================================
--- sbin/geom/class/raid3/graid3.8	(revision 225448)
+++ sbin/geom/class/raid3/graid3.8	(working copy)
@@ -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 beaaded instead of first missed
+component.
 .Pp
 Additional options include:
 .Bl -tag -width ".Fl h"
Index: sbin/geom/class/raid3/geom_raid3.c
===================================================================
--- sbin/geom/class/raid3/geom_raid3.c	(revision 225448)
+++ sbin/geom/class/raid3/geom_raid3.c	(working copy)
@@ -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"
Index: sys/geom/raid3/g_raid3_ctl.c
===================================================================
--- sys/geom/raid3/g_raid3_ctl.c	(revision 225448)
+++ sys/geom/raid3/g_raid3_ctl.c	(working copy)
@@ -404,7 +404,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) {
@@ -425,11 +425,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();
@@ -465,17 +464,30 @@
 		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 >= 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 unconnected 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,
>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20110908150714.C5CA74AC60>