summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorle <le@FreeBSD.org>2006-03-23 19:58:43 +0000
committerle <le@FreeBSD.org>2006-03-23 19:58:43 +0000
commit80efd8a6c8402b6ec3055526640e188d257ad82d (patch)
treeebf356ea4a6858242ffdfeb11c641e7b4306871d
parent925eb76ba3564d403af4210dfa40dde20fa1726c (diff)
downloadFreeBSD-src-80efd8a6c8402b6ec3055526640e188d257ad82d.zip
FreeBSD-src-80efd8a6c8402b6ec3055526640e188d257ad82d.tar.gz
Implement the 'resetconfig' command.
PR: kern/94835 Submitted by: Ulf Lilleengen <lulf@stud.ntnu.no>
-rw-r--r--sbin/gvinum/gvinum.88
-rw-r--r--sbin/gvinum/gvinum.c41
-rw-r--r--sys/geom/vinum/geom_vinum.c3
-rw-r--r--sys/geom/vinum/geom_vinum.h1
-rw-r--r--sys/geom/vinum/geom_vinum_rm.c39
5 files changed, 88 insertions, 4 deletions
diff --git a/sbin/gvinum/gvinum.8 b/sbin/gvinum/gvinum.8
index 582e509..0da4af1 100644
--- a/sbin/gvinum/gvinum.8
+++ b/sbin/gvinum/gvinum.8
@@ -165,6 +165,10 @@ the beginning of the plex if the
.Fl f
flag is specified, or otherwise at the location of the parity check pointer.
All subdisks in the plex must be up for a parity check.
+.It Ic resetconfig
+Reset the complete
+.Nm
+configuration.
.It Xo
.Ic rm
.Op Fl r
@@ -365,10 +369,6 @@ Create a volume label.
.Ar drives
.Xc
Create a mirrored volume from the specified drives.
-.It Ic resetconfig
-Reset the complete
-.Nm
-configuration.
.It Xo
.Ic resetstats
.Op Fl r
diff --git a/sbin/gvinum/gvinum.c b/sbin/gvinum/gvinum.c
index 23a21b9..ea33b75 100644
--- a/sbin/gvinum/gvinum.c
+++ b/sbin/gvinum/gvinum.c
@@ -61,6 +61,7 @@ void gvinum_move(int, char **);
void gvinum_parityop(int, char **, int);
void gvinum_printconfig(int, char **);
void gvinum_rename(int, char **);
+void gvinum_resetconfig(void);
void gvinum_rm(int, char **);
void gvinum_saveconfig(void);
void gvinum_setstate(int, char **);
@@ -349,6 +350,8 @@ gvinum_help(void)
" 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 @@ gvinum_rm(int argc, char **argv)
}
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 = gctl_get_handle();
+ gctl_ro_param(req, "class", -1, "VINUM");
+ gctl_ro_param(req, "verb", -1, "resetconfig");
+ errstr = gctl_issue(req);
+ if (errstr != 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;
@@ -846,6 +885,8 @@ parseline(int argc, char **argv)
gvinum_printconfig(argc, argv);
else if (!strcmp(argv[0], "rename"))
gvinum_rename(argc, argv);
+ else if (!strcmp(argv[0], "resetconfig"))
+ gvinum_resetconfig();
else if (!strcmp(argv[0], "rm"))
gvinum_rm(argc, argv);
else if (!strcmp(argv[0], "saveconfig"))
diff --git a/sys/geom/vinum/geom_vinum.c b/sys/geom/vinum/geom_vinum.c
index dfb0452..7e045d9 100644
--- a/sys/geom/vinum/geom_vinum.c
+++ b/sys/geom/vinum/geom_vinum.c
@@ -396,6 +396,9 @@ gv_config(struct gctl_req *req, struct g_class *mp, char const *verb)
} else if (!strcmp(verb, "rename")) {
gv_rename(gp, req);
+
+ } else if (!strcmp(verb, "resetconfig")) {
+ gv_resetconfig(gp, req);
} else if (!strcmp(verb, "start")) {
gv_start_obj(gp, req);
diff --git a/sys/geom/vinum/geom_vinum.h b/sys/geom/vinum/geom_vinum.h
index 1a31b3b..0e272ce 100644
--- a/sys/geom/vinum/geom_vinum.h
+++ b/sys/geom/vinum/geom_vinum.h
@@ -57,6 +57,7 @@ void gv_rename(struct g_geom *, struct gctl_req *);
/* 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);
diff --git a/sys/geom/vinum/geom_vinum_rm.c b/sys/geom/vinum/geom_vinum_rm.c
index eb188b7..7d25b82 100644
--- a/sys/geom/vinum/geom_vinum_rm.c
+++ b/sys/geom/vinum/geom_vinum_rm.c
@@ -125,6 +125,45 @@ gv_remove(struct g_geom *gp, struct gctl_req *req)
gv_save_config_all(sc);
}
+/* 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 = NULL;
+ d2 = NULL;
+ p = NULL;
+ p2 = NULL;
+ s = NULL;
+ s2 = NULL;
+ flags = GV_FLAG_R;
+ sc = 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)
OpenPOWER on IntegriCloud