Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 17 Mar 2006 19:52:26 +0100
From:      Ulf Lilleengen <lulf@pvv.ntnu.no>
To:        freebsd-geom@freebsd.org
Cc:        le@FreeBSD.org
Subject:   Implementation of gvinum resetconfig option
Message-ID:  <20060317185226.GA1469@stud.ntnu.no>

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

--OaZoDhBhXzo6bW1J
Content-Type: multipart/mixed; boundary="uXxzq0nDebZQVNAZ"
Content-Disposition: inline


--uXxzq0nDebZQVNAZ
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Hi,

I've been using gvinum for some time now, and I missed the 'resetconfig' op=
tion,
so I created an implementation of it to gvinum. I would love if people would
test this. It is currently tested on 7.0-Current. Diff attached.

--=20
Mvh Ulf Lilleengen

--uXxzq0nDebZQVNAZ
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="gvinum_resetconfig.diff"
Content-Transfer-Encoding: quoted-printable

Index: sbin/gvinum/gvinum.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/ncvs/src/sbin/gvinum/gvinum.c,v
retrieving revision 1.7
diff -u -r1.7 gvinum.c
--- sbin/gvinum/gvinum.c	20 Nov 2005 10:35:46 -0000	1.7
+++ sbin/gvinum/gvinum.c	17 Mar 2006 18:01:14 -0000
@@ -62,6 +62,7 @@
 void	gvinum_printconfig(int, char **);
 void	gvinum_rename(int, char **);
 void	gvinum_rm(int, char **);
+void	gvinum_resetconfig(void);
 void	gvinum_saveconfig(void);
 void	gvinum_setstate(int, char **);
 void	gvinum_start(int, char **);
@@ -349,6 +350,8 @@
 	    "        Change the name of the specified object.\n"
 	    "rebuildparity plex [-f]\n"
 	    "        Rebuild the parity blocks of a RAID-5 plex.\n"
+	    "resetconfig\n"
+	    "        Reset the complete gvinum configuration\n"
 	    "rm [-r] volume | plex | subdisk | drive\n"
 	    "        Remove an object.\n"
 	    "saveconfig\n"
@@ -729,6 +732,42 @@
 }
=20
 void
+gvinum_resetconfig(void)
+{
+	struct gctl_req *req;
+	const char *errstr;
+	char reply[32];
+
+	if (!isatty(STDIN_FILENO)) {
+		warn("Please enter this command from a tty device\n");
+		return;
+	}
+	printf(" WARNING!  This command will completely wipe out your gvinum"
+	    "configuration.\n"
+	    " All data will be lost.  If you really want to do this,"
+	    " enter the text\n\n"
+	    " NO FUTURE\n"
+	    " Enter text -> ");
+	fgets(reply, sizeof(reply), stdin);
+	if (strcmp(reply, "NO FUTURE\n")) {
+		printf("\n No change\n");
+		return;
+	}
+	req =3D gctl_get_handle();
+	gctl_ro_param(req, "class", -1, "VINUM");
+	gctl_ro_param(req, "verb", -1, "resetconfig");
+	errstr =3D gctl_issue(req);
+	if (errstr !=3D NULL) {
+		warnx("can't reset config: %s", errstr);
+		gctl_free(req);
+		return;
+	}
+	gctl_free(req);
+	gvinum_list(0, NULL);
+	printf("gvinum configuration obliterated\n");
+}
+
+void
 gvinum_saveconfig(void)
 {
 	struct gctl_req *req;
@@ -848,6 +887,8 @@
 		gvinum_rename(argc, argv);
 	else if (!strcmp(argv[0], "rm"))
 		gvinum_rm(argc, argv);
+	else if (!strcmp(argv[0], "resetconfig"))
+		gvinum_resetconfig();
 	else if (!strcmp(argv[0], "saveconfig"))
 		gvinum_saveconfig();
 	else if (!strcmp(argv[0], "setstate"))
Index: sys/geom/vinum/geom_vinum.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/ncvs/src/sys/geom/vinum/geom_vinum.c,v
retrieving revision 1.19
diff -u -r1.19 geom_vinum.c
--- sys/geom/vinum/geom_vinum.c	24 Nov 2005 15:11:41 -0000	1.19
+++ sys/geom/vinum/geom_vinum.c	17 Mar 2006 18:01:29 -0000
@@ -396,6 +396,9 @@
=20
 	} else if (!strcmp(verb, "rename")) {
 		gv_rename(gp, req);
+=09
+	} else if (!strcmp(verb, "resetconfig")) {
+		gv_resetconfig(gp, req);
=20
 	} else if (!strcmp(verb, "start")) {
 		gv_start_obj(gp, req);
Index: sys/geom/vinum/geom_vinum.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/ncvs/src/sys/geom/vinum/geom_vinum.h,v
retrieving revision 1.10
diff -u -r1.10 geom_vinum.h
--- sys/geom/vinum/geom_vinum.h	19 Nov 2005 20:25:18 -0000	1.10
+++ sys/geom/vinum/geom_vinum.h	17 Mar 2006 18:01:30 -0000
@@ -57,6 +57,7 @@
=20
 /* geom_vinum_rm.c */
 void	gv_remove(struct g_geom *, struct gctl_req *);
+int	gv_resetconfig(struct g_geom *, struct gctl_req *);
 int	gv_rm_sd(struct gv_softc *sc, struct gctl_req *req,
 	    struct gv_sd *s, int flags);
=20
Index: sys/geom/vinum/geom_vinum_rm.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/ncvs/src/sys/geom/vinum/geom_vinum_rm.c,v
retrieving revision 1.9
diff -u -r1.9 geom_vinum_rm.c
--- sys/geom/vinum/geom_vinum_rm.c	19 Nov 2005 20:25:18 -0000	1.9
+++ sys/geom/vinum/geom_vinum_rm.c	17 Mar 2006 18:01:30 -0000
@@ -125,6 +125,45 @@
 	gv_save_config_all(sc);
 }
=20
+/* Resets configuration */
+int
+gv_resetconfig(struct g_geom *gp, struct gctl_req *req)
+{
+        struct gv_softc *sc;
+        struct gv_drive *d, *d2;
+        struct gv_volume *v, *v2;
+	struct gv_plex *p, *p2;
+	struct gv_sd *s, *s2;
+	int flags;
+
+	d =3D NULL;
+	d2 =3D NULL;
+	p =3D NULL;
+	p2 =3D NULL;
+	s =3D NULL;
+	s2 =3D NULL;
+	flags =3D GV_FLAG_R;
+        sc =3D gp->softc;
+	/* First loop through to make sure no volumes are up */
+        LIST_FOREACH_SAFE(v, &sc->volumes, volume, v2) {
+		if (gv_is_open(v->geom)) {
+			gctl_error(req, "volume '%s' is busy", v->name);
+			return (-1);
+		}
+	}
+	/* Then if not, we remove everything. */
+	LIST_FOREACH_SAFE(v, &sc->volumes, volume, v2)
+                gv_rm_vol(sc, req, v, flags);
+	LIST_FOREACH_SAFE(p, &sc->plexes, plex, p2)
+		gv_rm_plex(sc, req, p, flags);
+	LIST_FOREACH_SAFE(s, &sc->subdisks, sd, s2)
+		gv_rm_sd(sc, req, s, flags);
+	LIST_FOREACH_SAFE(d, &sc->drives, drive, d2)
+		gv_rm_drive(sc, req, d, flags);
+	gv_save_config_all(sc);
+	return (0);
+}
+
 /* Remove a volume. */
 static int
 gv_rm_vol(struct gv_softc *sc, struct gctl_req *req, struct gv_volume *v, =
int flags)

--uXxzq0nDebZQVNAZ--

--OaZoDhBhXzo6bW1J
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFEGwVqCILg8nMIdCURApFuAJwK6cZ+8Ts8K8s5WR+8bB/ZeO6QkQCeOTzn
3G7WdWkwHXCoijFNk75/Kkk=
=CuGe
-----END PGP SIGNATURE-----

--OaZoDhBhXzo6bW1J--



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