Date: Thu, 28 Jun 2007 12:50:28 GMT From: Ulf Lilleengen <lulf@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 122482 for review Message-ID: <200706281250.l5SCoSHh063077@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=122482 Change 122482 by lulf@lulf_carrot on 2007/06/28 12:50:06 - Add support for 'move' command in the new event system. - Rework the move code to use the new event system, error codes, and other small fixes. - Add a move event. Affected files ... .. //depot/projects/soc2007/lulf/gvinum_fixup/sys/geom/vinum/geom_vinum.c#23 edit .. //depot/projects/soc2007/lulf/gvinum_fixup/sys/geom/vinum/geom_vinum.h#18 edit .. //depot/projects/soc2007/lulf/gvinum_fixup/sys/geom/vinum/geom_vinum_move.c#2 edit .. //depot/projects/soc2007/lulf/gvinum_fixup/sys/geom/vinum/geom_vinum_var.h#19 edit Differences ... ==== //depot/projects/soc2007/lulf/gvinum_fixup/sys/geom/vinum/geom_vinum.c#23 (text+ko) ==== @@ -433,10 +433,8 @@ } else if (!strcmp(verb, "create")) { gv_create(gp, req); -#if 0 } else if (!strcmp(verb, "move")) { gv_move(gp, req); -#endif } else if (!strcmp(verb, "rebuildparity") || !strcmp(verb, "checkparity")) { @@ -799,6 +797,18 @@ g_free(newname); break; + case GV_EVENT_MOVE_SD: + printf("VINUM: event 'move'\n"); + s = ev->arg1; + d = ev->arg2; + flags = ev->arg3; + err = gv_move_sd(sc, s, d, flags); + if (err) + printf("VINUM: error moving %s to %s: " + " error code %d\n", s->name, + d->name, err); + break; + case GV_EVENT_THREAD_EXIT: printf("VINUM: event 'thread exit'\n"); g_free(ev); ==== //depot/projects/soc2007/lulf/gvinum_fixup/sys/geom/vinum/geom_vinum.h#18 (text+ko) ==== @@ -46,6 +46,7 @@ /* geom_vinum_move.c */ void gv_move(struct g_geom *, struct gctl_req *); +int gv_move_sd(struct gv_softc *, struct gv_sd *, struct gv_drive *, int); /* geom_vinum_rename.c */ void gv_rename(struct g_geom *, struct gctl_req *); ==== //depot/projects/soc2007/lulf/gvinum_fixup/sys/geom/vinum/geom_vinum_move.c#2 (text+ko) ==== @@ -42,17 +42,15 @@ #include <geom/vinum/geom_vinum.h> #include <geom/vinum/geom_vinum_share.h> -#if 0 -static int gv_move_sd(struct gv_softc *, struct gctl_req *, - struct gv_sd *, char *, int); void gv_move(struct g_geom *gp, struct gctl_req *req) { struct gv_softc *sc; struct gv_sd *s; + struct gv_drive *d; char buf[20], *destination, *object; - int *argc, err, *flags, i, type; + int *argc, *flags, i, type; sc = gp->softc; @@ -67,6 +65,7 @@ gctl_error(req, "destination '%s' is not a drive", destination); return; } + d = gv_find_drive(sc, destination); /* * We start with 1 here, because argv[0] on the command line is the @@ -90,68 +89,58 @@ gctl_error(req, "unknown subdisk '%s'", object); return; } - err = gv_move_sd(sc, req, s, destination, *flags); - if (err) - return; + gv_post_event(sc, GV_EVENT_MOVE_SD, s, d, *flags, 0); } - - gv_save_config_all(sc); } /* Move a subdisk. */ -static int -gv_move_sd(struct gv_softc *sc, struct gctl_req *req, struct gv_sd *cursd, char *destination, int flags) +int +gv_move_sd(struct gv_softc *sc, struct gv_sd *cursd, + struct gv_drive *destination, int flags) { struct gv_drive *d; struct gv_sd *newsd, *s, *s2; struct gv_plex *p; - struct g_consumer *cp; - char errstr[ERRBUFSIZ]; int err; g_topology_assert(); KASSERT(cursd != NULL, ("gv_move_sd: NULL cursd")); + KASSERT(destination != NULL, ("gv_move_sd: NULL destination")); - cp = cursd->consumer; + d = cursd->drive_sc; - if (cp != NULL && (cp->acr || cp->acw || cp->ace)) { - gctl_error(req, "subdisk '%s' is busy", cursd->name); - return (-1); + if (gv_consumer_is_open(d->consumer) || + gv_consumer_is_open(destination->consumer)) { + printf("VINUM: consumers on current and destination drive " + " still open"); + return (GV_ERR_ISOPEN); } - if (!(flags && GV_FLAG_F)) { - gctl_error(req, "-f flag not passed; move would be " - "destructive"); - return (-1); + printf("VINUM: -f flag not passed; move would be " + "destructive\n"); + return (GV_ERR_INVFLAG); } - d = gv_find_drive(sc, destination); - if (d == NULL) { - gctl_error(req, "destination drive '%s' not found", - destination); - return (-1); + if (destination == cursd->drive_sc) { + printf("VINUM: subdisk '%s' already on drive '%s'\n", + cursd->name, destination->name); + return (GV_ERR_ISATTACHED); } - if (d == cursd->drive_sc) { - gctl_error(req, "subdisk '%s' already on drive '%s'", - cursd->name, destination); - return (-1); - } - /* XXX: Does it have to be part of a plex? */ p = gv_find_plex(sc, cursd->plex); if (p == NULL) { - gctl_error(req, "subdisk '%s' is not part of a plex", + printf("VINUM: subdisk '%s' is not part of a plex\n", cursd->name); - return (-1); + return (GV_ERR_NOTFOUND); } - + /* Stale the old subdisk. */ err = gv_set_sd_state(cursd, GV_SD_STALE, GV_SETSTATE_FORCE | GV_SETSTATE_CONFIG); if (err) { - gctl_error(req, "could not set the subdisk '%s' to state " - "'stale'", cursd->name); + printf("VINUM: could not set the subdisk '%s' to state " + "'stale'\n", cursd->name); return (err); } @@ -164,55 +153,27 @@ newsd->plex_offset = cursd->plex_offset; newsd->size = cursd->size; newsd->drive_offset = -1; - strncpy(newsd->name, cursd->name, GV_MAXSDNAME); - strncpy(newsd->drive, destination, GV_MAXDRIVENAME); - strncpy(newsd->plex, cursd->plex, GV_MAXPLEXNAME); + strlcpy(newsd->name, cursd->name, GV_MAXSDNAME); + strlcpy(newsd->drive, destination->name, GV_MAXDRIVENAME); + strlcpy(newsd->plex, cursd->plex, GV_MAXPLEXNAME); newsd->state = GV_SD_STALE; newsd->vinumconf = cursd->vinumconf; - err = gv_sd_to_drive(sc, d, newsd, errstr, ERRBUFSIZ); + err = gv_sd_to_drive(newsd, destination); if (err) { /* XXX not enough free space? */ - gctl_error(req, errstr); g_free(newsd); return (err); } /* Replace the old sd by the new one. */ - if (cp != NULL) - g_detach(cp); LIST_FOREACH_SAFE(s, &p->subdisks, in_plex, s2) { if (s == cursd) { - p->sdcount--; - p->size -= s->size; - err = gv_rm_sd(sc, req, s, 0); - if (err) - return (err); - + gv_rm_sd(sc, s); } } - - gv_sd_to_plex(p, newsd, 1); - - /* Creates the new providers.... */ - gv_drive_modify(d); - - /* And reconnect the consumer ... */ - if (cp != NULL) { - newsd->consumer = cp; - err = g_attach(cp, newsd->provider); - if (err) { - g_destroy_consumer(cp); - gctl_error(req, "proposed move would create a loop " - "in GEOM config"); - return (err); - } - } - + gv_sd_to_plex(newsd, p); LIST_INSERT_HEAD(&sc->subdisks, newsd, sd); - gv_save_config_all(sc); - return (0); } -#endif ==== //depot/projects/soc2007/lulf/gvinum_fixup/sys/geom/vinum/geom_vinum_var.h#19 (text+ko) ==== @@ -204,6 +204,7 @@ #define GV_EVENT_RENAME_PLEX 27 #define GV_EVENT_RENAME_SD 28 #define GV_EVENT_RENAME_DRIVE 29 +#define GV_EVENT_MOVE_SD 30 struct gv_event { int type;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200706281250.l5SCoSHh063077>