From owner-p4-projects@FreeBSD.ORG Thu Jun 28 12:50:28 2007 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id BC51B16A469; Thu, 28 Jun 2007 12:50:28 +0000 (UTC) X-Original-To: perforce@FreeBSD.org Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 9095216A41F for ; Thu, 28 Jun 2007 12:50:28 +0000 (UTC) (envelope-from lulf@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [69.147.83.41]) by mx1.freebsd.org (Postfix) with ESMTP id 80AC713C448 for ; Thu, 28 Jun 2007 12:50:28 +0000 (UTC) (envelope-from lulf@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.8/8.13.8) with ESMTP id l5SCoSSZ063080 for ; Thu, 28 Jun 2007 12:50:28 GMT (envelope-from lulf@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.8/8.13.8/Submit) id l5SCoSHh063077 for perforce@freebsd.org; Thu, 28 Jun 2007 12:50:28 GMT (envelope-from lulf@FreeBSD.org) Date: Thu, 28 Jun 2007 12:50:28 GMT Message-Id: <200706281250.l5SCoSHh063077@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to lulf@FreeBSD.org using -f From: Ulf Lilleengen To: Perforce Change Reviews Cc: Subject: PERFORCE change 122482 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 28 Jun 2007 12:50:29 -0000 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 #include -#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;