PERFORCE change 81638 for review
soc-cjones
soc-cjones at FreeBSD.org
Mon Aug 8 08:15:46 GMT 2005
http://perforce.freebsd.org/chv.cgi?CH=81638
Change 81638 by soc-cjones at soc-cjones_ishtar on 2005/08/08 08:15:21
Renaming now works for drives, volumes, plexes, and subdisks, in both recursive and non-recursive modes. Plenty of debugging crud in this check-in; removing some of the excess in the next.
Affected files ...
.. //depot/projects/soc2005/gvinum/src/sys/geom/vinum/geom_vinum_rename.c#4 edit
Differences ...
==== //depot/projects/soc2005/gvinum/src/sys/geom/vinum/geom_vinum_rename.c#4 (text+ko) ====
@@ -57,9 +57,8 @@
struct gv_drive *d;
int *argc, *flags;
- char *argv, buf[20];
char *object, *newname;
- int i, type, err;
+ int type, err;
sc = gp->softc;
@@ -71,12 +70,6 @@
gctl_error(req, "no new name given");
return;
}
- type = gv_object_type(sc, newname);
- printf("gv_object_type(sc, \"%s\") = %d\n", newname, type);
- if (-1 != type) {
- gctl_error(req, "new name is already in use");
- return;
- }
object = gctl_get_param(req, "object", NULL);
if (NULL == object) {
@@ -102,8 +95,6 @@
gctl_error(req, "unknown plex '%s'", object);
return;
}
- gctl_error(req, "calling gv_rename_plex(,, %s, %s,)", p, newname);
- return;
err = gv_rename_plex(sc, req, p, newname, *flags);
if (err)
return;
@@ -114,8 +105,6 @@
gctl_error(req, "unknown subdisk '%s'", object);
return;
}
- gctl_error(req, "calling gv_rename_sd(,, %s, %s,)", s, newname);
- return;
err = gv_rename_sd(sc, req, s, newname, *flags);
if (err)
return;
@@ -126,8 +115,6 @@
gctl_error(req, "unknown drive '%s'", object);
return;
}
- gctl_error(req, "calling gv_rename_drive(,, %s, %s,)", d, newname);
- return;
err = gv_rename_drive(sc, req, d, newname, *flags);
if (err)
return;
@@ -143,11 +130,26 @@
static int
gv_rename_drive(struct gv_softc *sc, struct gctl_req *req, struct gv_drive *d, char *newname, int flags)
{
- int err;
+ char olddrivename[GV_MAXDRIVENAME];
+ struct gv_sd *s;
g_topology_assert();
KASSERT(d != NULL, ("gv_rename_drive: NULL d"));
+ if (-1 != gv_object_type(sc, newname)) {
+ gctl_error(req, "drive name %s already in use", newname);
+ return 2;
+ }
+
+ strncpy(olddrivename, d->name, GV_MAXDRIVENAME);
+ strncpy(d->name, newname, GV_MAXDRIVENAME);
+
+ LIST_FOREACH(s, &sc->subdisks, sd) {
+ if (!strncmp(s->drive, olddrivename, GV_MAXDRIVENAME)) {
+ strncpy(s->drive, d->name, GV_MAXDRIVENAME);
+ }
+ }
+
return (0);
}
@@ -156,21 +158,90 @@
gv_rename_plex(struct gv_softc *sc, struct gctl_req *req, struct gv_plex *p, char *newname, int flags)
{
int err;
+ char plexnumber[GV_MAXPLEXNAME];
+ char *pplexnumber = plexnumber;
+ char oldplexname[GV_MAXPLEXNAME];
+ char *poldplexname = oldplexname;
+ struct gv_sd *s;
g_topology_assert();
KASSERT(d != NULL, ("gv_rename_plex: NULL p"));
+ if (-1 != gv_object_type(sc, newname)) {
+ gctl_error(req, "plex name %s already in use", newname);
+ return 2;
+ }
+
+ strncpy(oldplexname, p->name, GV_MAXPLEXNAME);
+ strsep(&poldplexname, ".");
+ strncpy(plexnumber, p->name, GV_MAXPLEXNAME);
+ strsep(&pplexnumber, ".");
+ if (strcmp(poldplexname, pplexnumber)) {
+ gctl_error(req, "current and proposed plex numbers (%s, %s) do not match", pplexnumber, poldplexname);
+ return 1;
+ }
+
+ printf("oldplexname = %s\n", oldplexname);
+ strncpy(oldplexname, p->name, GV_MAXPLEXNAME);
+ strncpy(p->name, newname, GV_MAXPLEXNAME);
+
+ /* Fix up references and potentially rename subdisks. */
+ LIST_FOREACH(s, &sc->subdisks, sd) {
+ if (!strncmp(s->plex, oldplexname, GV_MAXPLEXNAME)) {
+ printf("Fixing plex reference for subdisk %s from %s to %s\n", s->name, s->plex, p->name);
+ strncpy(s->plex, p->name, GV_MAXPLEXNAME);
+ if (flags && GV_FLAG_R) {
+ char newsdname[GV_MAXSDNAME];
+ char oldsdname[GV_MAXSDNAME];
+ char *poldsdname = oldsdname;
+ printf("Modifying subdisk %s, s->plex = %s\n", s->name, s->plex);
+ strncpy(oldsdname, s->name, GV_MAXSDNAME);
+ strsep(&poldsdname, ".");
+ strsep(&poldsdname, ".");
+ snprintf(newsdname, GV_MAXSDNAME, "%s.%s", p->name, poldsdname);
+ if ((err = gv_rename_sd(sc, req, s, newsdname, flags)))
+ return err;
+ }
+ } else {
+ printf("Ignoring subdisk %s\n", s->name);
+ }
+ }
return (0);
}
+/* gv_rename_sd: renames a subdisk. Note that the 'flags' argument is ignored, since
+ there are no structures below a subdisk. Similarly, we don't have
+ to clean up any references elsewhere to the subdisk's name. */
static int
gv_rename_sd(struct gv_softc *sc, struct gctl_req *req, struct gv_sd *s, char * newname, int flags)
{
- int err;
+ char newsdnumber[GV_MAXSDNAME];
+ char *pnewsdnumber = newsdnumber;
+ char oldsdnumber[GV_MAXSDNAME];
+ char *poldsdnumber = oldsdnumber;
g_topology_assert();
KASSERT(d != NULL, ("gv_rename_sd: NULL s"));
+ if (-1 != gv_object_type(sc, newname)) {
+ gctl_error(req, "subdrive name %s already in use", newname);
+ return 2;
+ }
+
+ strncpy(oldsdnumber, s->name, GV_MAXSDNAME);
+ strsep(&poldsdnumber, ".");
+ strsep(&poldsdnumber, ".");
+ strncpy(newsdnumber, newname, GV_MAXSDNAME);
+ strsep(&pnewsdnumber, ".");
+ strsep(&pnewsdnumber, ".");
+ if (strcmp(pnewsdnumber, poldsdnumber)) {
+ gctl_error(req, "current and proposed sd numbers (%s, %s) do not match", poldsdnumber, pnewsdnumber);
+ return 1;
+ }
+
+ printf("Renaming subdisk %s to %s\n", s->name, newname);
+ strncpy(s->name, newname, GV_MAXSDNAME);
+
return (0);
}
@@ -179,13 +250,17 @@
{
int err;
struct gv_plex *p;
- struct gv_sd *s;
+ /* struct gv_sd *s; */
char oldvolname[GV_MAXVOLNAME];
- char oldplexname[GV_MAXPLEXNAME];
g_topology_assert();
KASSERT(d != NULL, ("gv_rename_vol: NULL v"));
+ if (-1 != gv_object_type(sc, newname)) {
+ gctl_error(req, "volume name %s already in use", newname);
+ return 2;
+ }
+
printf("gv_rename_vol: flags = %x\n", flags);
/* Rename the volume. We need to hold on to the old volume name. */
@@ -200,37 +275,51 @@
LIST_FOREACH(p, &sc->plexes, plex) {
if (!strncmp(p->volume, oldvolname, GV_MAXVOLNAME)) {
+ printf("Fixing volume reference for plex %s from %s to %s\n", p->name, p->volume, v->name);
strncpy(p->volume, v->name, GV_MAXVOLNAME);
if (flags && GV_FLAG_R) {
- char plexnumber[GV_MAXPLEXNAME];
- char *pplexnumber = plexnumber;
+ char newplexname[GV_MAXPLEXNAME];
+ char oldplexname[GV_MAXPLEXNAME];
+ char *poldplexname = oldplexname;
printf("Modifying plex %s, p->volume = %s\n", p->name, p->volume);
strncpy(oldplexname, p->name, GV_MAXPLEXNAME);
- strncpy(plexnumber, p->name, GV_MAXPLEXNAME);
- strsep(&pplexnumber, ".");
- printf("Renaming plex %s to %s.%s\n", p->name, v->name, pplexnumber);
- snprintf(p->name, GV_MAXPLEXNAME, "%s.%s", v->name, pplexnumber);
- LIST_FOREACH(s, &sc->subdisks, sd) {
+ strsep(&poldplexname, ".");
+ snprintf(newplexname, GV_MAXPLEXNAME, "%s.%s", v->name, poldplexname);
+ if ((err = gv_rename_plex(sc, req, p, newplexname, flags)))
+ return err;
+
+ /*
+ char plexnumber[GV_MAXPLEXNAME];
+ char *pplexnumber = plexnumber;
+ printf("Modifying plex %s, p->volume = %s\n", p->name, p->volume);
+ strncpy(oldplexname, p->name, GV_MAXPLEXNAME);
+ strncpy(plexnumber, p->name, GV_MAXPLEXNAME);
+ strsep(&pplexnumber, ".");
+ printf("Renaming plex %s to %s.%s\n", p->name, v->name, pplexnumber);
+ snprintf(p->name, GV_MAXPLEXNAME, "%s.%s", v->name, pplexnumber);
+ LIST_FOREACH(s, &sc->subdisks, sd) {
if (!strncmp(s->plex, oldplexname, GV_MAXPLEXNAME)) {
- char sdnumber[GV_MAXSDNAME];
- char *psdnumber = sdnumber;
- printf("Modifying subdisk %s, s->plex = %s\n", s->name, s->plex);
- strncpy(sdnumber, s->name, GV_MAXSDNAME);
- strsep(&psdnumber, ".");
- strsep(&psdnumber, ".");
- printf("Renaming subdisk %s to %s.%s\n", s->name, p->name, psdnumber);
- snprintf(s->name, GV_MAXSDNAME, "%s.%s", p->name, psdnumber);
- strncpy(s->plex, p->name, GV_MAXPLEXNAME);
+ char sdnumber[GV_MAXSDNAME];
+ char *psdnumber = sdnumber;
+ printf("Modifying subdisk %s, s->plex = %s\n", s->name, s->plex);
+ strncpy(sdnumber, s->name, GV_MAXSDNAME);
+ strsep(&psdnumber, ".");
+ strsep(&psdnumber, ".");
+ printf("Renaming subdisk %s to %s.%s\n", s->name, p->name, psdnumber);
+ snprintf(s->name, GV_MAXSDNAME, "%s.%s", p->name, psdnumber);
+ strncpy(s->plex, p->name, GV_MAXPLEXNAME);
} else {
- printf("Ignoring subdisk %s, s->plex = %s\n", s->name, s->plex);
+ printf("Ignoring subdisk %s, s->plex = %s\n", s->name, s->plex);
+ }
}
- }
+ */
}
- } else {
+ } else {
printf("Ignoring plex %s, p->volume = %s\n", p->name, p->volume);
}
}
+ /*
printf("Debugging output:\n");
printf("\tsc = %p\n", sc);
printf("\treq = %p\n", req);
@@ -259,6 +348,7 @@
}
}
printf("\n\n");
+ */
return (0);
}
More information about the p4-projects
mailing list