From owner-freebsd-bugs@FreeBSD.ORG Thu Sep 8 15:10:08 2011 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 08A111065674 for ; Thu, 8 Sep 2011 15:10:08 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id DA5B28FC12 for ; Thu, 8 Sep 2011 15:10:07 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id p88FA7oP000634 for ; Thu, 8 Sep 2011 15:10:07 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id p88FA7ZD000633; Thu, 8 Sep 2011 15:10:07 GMT (envelope-from gnats) Resent-Date: Thu, 8 Sep 2011 15:10:07 GMT Resent-Message-Id: <201109081510.p88FA7ZD000633@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Lev Serebryakov Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 517CC106567A for ; Thu, 8 Sep 2011 15:07:16 +0000 (UTC) (envelope-from lev@onlyone.friendlyhosting.spb.ru) Received: from onlyone.friendlyhosting.spb.ru (onlyone.friendlyhosting.spb.ru [IPv6:2a01:4f8:131:60a2::2]) by mx1.freebsd.org (Postfix) with ESMTP id F2EF58FC18 for ; Thu, 8 Sep 2011 15:07:15 +0000 (UTC) Received: by onlyone.friendlyhosting.spb.ru (Postfix, from userid 1000) id C5CA74AC60; Thu, 8 Sep 2011 19:07:14 +0400 (MSD) Message-Id: <20110908150714.C5CA74AC60@onlyone.friendlyhosting.spb.ru> Date: Thu, 8 Sep 2011 19:07:14 +0400 (MSD) From: Lev Serebryakov To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Cc: Subject: kern/160562: [geom][patch] Allow to insert new component to geom_raid3 without specifying number. X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Lev Serebryakov List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 08 Sep 2011 15:10:08 -0000 >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 >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 " 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: