PERFORCE change 118219 for review

Ulf Lilleengen lulf at FreeBSD.org
Mon Apr 16 09:37:58 UTC 2007


http://perforce.freebsd.org/chv.cgi?CH=118219

Change 118219 by lulf at lulf_vimes on 2007/04/16 09:37:40

	- Edit TODO.
	- Import more of lukas' work.
	- Change event structure to contain one more argument.
	- Change all functions using gv_post_event to add extra argument.
	- Enable setstate, and make it use the new EVENT system. Also create
	  EVENT types for this.

Affected files ...

.. //depot/projects/soc2007/lulf/TODO#2 edit
.. //depot/projects/soc2007/lulf/gvinum_fixup/sbin/gvinum/gvinum.c#2 integrate
.. //depot/projects/soc2007/lulf/gvinum_fixup/sys/geom/vinum/geom_vinum.c#2 edit
.. //depot/projects/soc2007/lulf/gvinum_fixup/sys/geom/vinum/geom_vinum.h#2 edit
.. //depot/projects/soc2007/lulf/gvinum_fixup/sys/geom/vinum/geom_vinum_events.c#2 edit
.. //depot/projects/soc2007/lulf/gvinum_fixup/sys/geom/vinum/geom_vinum_plex.c#2 integrate
.. //depot/projects/soc2007/lulf/gvinum_fixup/sys/geom/vinum/geom_vinum_raid5.h#2 integrate
.. //depot/projects/soc2007/lulf/gvinum_fixup/sys/geom/vinum/geom_vinum_rm.c#2 edit
.. //depot/projects/soc2007/lulf/gvinum_fixup/sys/geom/vinum/geom_vinum_state.c#2 edit
.. //depot/projects/soc2007/lulf/gvinum_fixup/sys/geom/vinum/geom_vinum_var.h#2 edit

Differences ...

==== //depot/projects/soc2007/lulf/TODO#2 (text+ko) ====

@@ -5,4 +5,6 @@
 3. Integrate concat/stripe/mirror routines
 4. Implement working RAID5 to the new gvinum.
 5. Implementing routines for syncing raid 5 (in the 'start' command).
-6. Run some tests to make sure the new gvinum code-base is good enough.
+6. Make sure other parts is function correctly, and implement what perhaps is
+not implemented yet.
+7. Run some tests to make sure the new gvinum code-base is good enough.

==== //depot/projects/soc2007/lulf/gvinum_fixup/sbin/gvinum/gvinum.c#2 (text+ko) ====

@@ -854,16 +854,19 @@
 	 * event thread will be free for the g_wither_geom() call from
 	 * gv_unload().  It's silly, but it works.
 	 */
+	printf("unloading " GVINUMMOD " kernel module... ");
+	fflush(stdout);
 	if ((err = kldunload(fileid)) != 0 && (errno == EAGAIN)) {
 		sleep(1);
 		err = kldunload(fileid);
 	}
 	if (err != 0) {
+		printf(" failed!\n");
 		warn("cannot unload " GVINUMMOD);
 		return;
 	}
 
-	warnx(GVINUMMOD " unloaded");
+	printf("done\n");
 	exit(0);
 }
 

==== //depot/projects/soc2007/lulf/gvinum_fixup/sys/geom/vinum/geom_vinum.c#2 (text+ko) ====

@@ -71,7 +71,7 @@
 
 	g_trace(G_T_TOPOLOGY, "gv_orphan(%s)", gp->name);
 
-	gv_post_event(sc, GV_EVENT_DRIVE_LOST, d, NULL);
+	gv_post_event(sc, GV_EVENT_DRIVE_LOST, d, NULL, NULL);
 }
 
 static void
@@ -184,7 +184,7 @@
 	sc = gp->softc;
 
 	if (sc != NULL) {
-		gv_post_event(sc, GV_EVENT_THREAD_EXIT, NULL, NULL);
+		gv_post_event(sc, GV_EVENT_THREAD_EXIT, NULL, NULL, NULL);
 		gp->softc = NULL;
 		g_wither_geom(gp, ENXIO);
 		return (EAGAIN);
@@ -238,7 +238,7 @@
 		d = g_malloc(sizeof(*d), M_WAITOK | M_ZERO);
 		bcopy(d2, d, sizeof(*d));
 
-		gv_post_event(sc, GV_EVENT_CREATE_DRIVE, d, NULL);
+		gv_post_event(sc, GV_EVENT_CREATE_DRIVE, d, NULL, NULL);
 	}
 
 	/* ... then volume definitions ... */
@@ -255,7 +255,7 @@
 		v = g_malloc(sizeof(*v), M_WAITOK | M_ZERO);
 		bcopy(v2, v, sizeof(*v));
 
-		gv_post_event(sc, GV_EVENT_CREATE_VOLUME, v, NULL);
+		gv_post_event(sc, GV_EVENT_CREATE_VOLUME, v, NULL, NULL);
 	}
 
 	/* ... then plex definitions ... */
@@ -272,7 +272,7 @@
 		p = g_malloc(sizeof(*p), M_WAITOK | M_ZERO);
 		bcopy(p2, p, sizeof(*p));
 
-		gv_post_event(sc, GV_EVENT_CREATE_PLEX, p, NULL);
+		gv_post_event(sc, GV_EVENT_CREATE_PLEX, p, NULL, NULL);
 	}
 
 	/* ... and, finally, subdisk definitions. */
@@ -289,10 +289,10 @@
 		s = g_malloc(sizeof(*s), M_WAITOK | M_ZERO);
 		bcopy(s2, s, sizeof(*s));
 
-		gv_post_event(sc, GV_EVENT_CREATE_SD, s, NULL);
+		gv_post_event(sc, GV_EVENT_CREATE_SD, s, NULL, NULL);
 	}
 
-	gv_post_event(sc, GV_EVENT_SAVE_CONFIG, sc, NULL);
+	gv_post_event(sc, GV_EVENT_SAVE_CONFIG, sc, NULL, NULL);
 
 	return (0);
 }
@@ -315,7 +315,7 @@
 
 	/* Save our configuration back to disk. */
 	} else if (!strcmp(verb, "saveconfig")) {
-		gv_post_event(sc, GV_EVENT_SAVE_CONFIG, sc, NULL);
+		gv_post_event(sc, GV_EVENT_SAVE_CONFIG, sc, NULL, NULL);
 
 	/* Return configuration in string form. */
 	} else if (!strcmp(verb, "getconfig")) {
@@ -351,9 +351,9 @@
 	} else if (!strcmp(verb, "start")) {
 		gv_start_obj(gp, req);
 
+#endif
 	} else if (!strcmp(verb, "setstate")) {
 		gv_setstate(gp, req);
-#endif
 	} else
 		gctl_error(req, "Unknown verb parameter");
 }
@@ -400,7 +400,7 @@
 	/* Check if what we've been given is a valid vinum drive. */
 	if (vhdr != NULL) {
 		if (vhdr->magic == GV_MAGIC)
-			gv_post_event(sc, GV_EVENT_DRIVE_TASTED, pp, NULL);
+			gv_post_event(sc, GV_EVENT_DRIVE_TASTED, pp, NULL, NULL);
 		g_free(vhdr);
 	}
 
@@ -418,6 +418,7 @@
 	struct gv_sd *s;
 	struct gv_drive *d;
 	struct bio *bp;
+	int newstate, flags, err;
 
 	sc = arg;
 	KASSERT(sc != NULL, ("NULL sc"));
@@ -503,6 +504,32 @@
 				gv_save_config(sc);
 				break;
 
+			case GV_EVENT_SET_SD_STATE:
+				printf("VINUM: event 'setstate sd'\n");
+				s = ev->arg1;
+				newstate = *(int *)ev->arg2;
+				flags = *(int *)ev->arg3;
+				err = gv_set_sd_state(s, newstate, flags);
+				if (err)
+					printf("VINUM: error setting subdisk "
+					    "state\n");
+				/* XXX: Handle these errors better, provide
+				 * ERROR CODES.*/
+				break;
+
+			case GV_EVENT_SET_DRIVE_STATE:
+				printf("VINUM: event 'setstate drive'\n");
+				d = ev->arg1;
+				newstate = *(int *)ev->arg2;
+				flags = *(int *)ev->arg3;
+				err = gv_set_drive_state(d, newstate, flags);
+				if (err)
+					printf("VINUM: error setting drive "
+					    "state");
+				/* XXX: Handle these errors better, provide
+				 * ERROR CODES.*/
+				break;
+
 			case GV_EVENT_THREAD_EXIT:
 				printf("VINUM: event 'thread exit'\n");
 				g_free(ev);
@@ -532,8 +559,22 @@
 		}
 		mtx_unlock(&sc->queue_mtx);
 
+		/* A bio that is coming up from an underlying device. */
 		if (bp->bio_cflags & GV_BIO_DONE) {
 			gv_bio_done(sc, bp);
+		/* A bio that interfered with another bio. */
+		} else if (bp->bio_cflags & GV_BIO_ONHOLD) {
+			s = bp->bio_caller1;
+			p = s->plex_sc;
+			/* Is it still locked out? */
+			if (gv_stripe_active(p, bp)) {
+				/* Park the bio on the waiting queue. */
+				bioq_disksort(p->wqueue, bp);
+			} else {
+				bp->bio_cflags &= ~GV_BIO_ONHOLD;
+				g_io_request(bp, s->drive_sc->consumer);
+			}
+		/* A fresh bio, scheduled it down. */
 		} else {
 			gv_volume_start(sc, bp);
 		}

==== //depot/projects/soc2007/lulf/gvinum_fixup/sys/geom/vinum/geom_vinum.h#2 (text+ko) ====

@@ -87,7 +87,7 @@
 off_t	gv_plex_size(struct gv_plex *);
 
 void	gv_worker(void *);
-void	gv_post_event(struct gv_softc *, int, void *, void *);
+void	gv_post_event(struct gv_softc *, int, void *, void *, void *);
 void	gv_drive_tasted(struct gv_softc *, struct g_provider *);
 void	gv_drive_lost(struct gv_softc *, struct gv_drive *);
 void	gv_setup_objects(struct gv_softc *);

==== //depot/projects/soc2007/lulf/gvinum_fixup/sys/geom/vinum/geom_vinum_events.c#2 (text+ko) ====

@@ -42,7 +42,8 @@
 #include <geom/vinum/geom_vinum_share.h>
 
 void
-gv_post_event(struct gv_softc *sc, int event, void *arg1, void *arg2)
+gv_post_event(struct gv_softc *sc, int event, void *arg1, void *arg2,
+    void *arg3)
 {
 	struct gv_event *ev;
 
@@ -50,6 +51,7 @@
 	ev->type = event;
 	ev->arg1 = arg1;
 	ev->arg2 = arg2;
+	ev->arg3 = arg3;
 
 	mtx_lock(&sc->queue_mtx);
 	TAILQ_INSERT_TAIL(&sc->equeue, ev, events);
@@ -172,7 +174,7 @@
 		if (cp->nstart != cp->nend) {
 			printf("VINUM: dead drive '%s' has still active "
 			    "requests, can't detach consumer\n", d->name);
-			gv_post_event(sc, GV_EVENT_DRIVE_LOST, d, NULL);
+			gv_post_event(sc, GV_EVENT_DRIVE_LOST, d, NULL, NULL);
 			return;
 		}
 		g_topology_lock();

==== //depot/projects/soc2007/lulf/gvinum_fixup/sys/geom/vinum/geom_vinum_plex.c#2 (text+ko) ====

@@ -330,15 +330,19 @@
 	struct bio *cbp, *pbp;
 	struct gv_bioq *bq, *bq2;
 	struct gv_raid5_packet *wp;
+	off_t completed;
 	int i;
 
+	completed = 0;
 	sc = p->vinumconf;
 	wp = bp->bio_caller2;
 
 	switch (bp->bio_parent->bio_cmd) {
 	case BIO_READ:
-		if (wp == NULL)
+		if (wp == NULL) {
+			completed = bp->bio_completed;
 			break;
+		}
 
 		TAILQ_FOREACH_SAFE(bq, &wp->bits, queue, bq2) {
 			if (bq->bp == bp) {
@@ -350,7 +354,7 @@
 			}
 		}
 		if (TAILQ_EMPTY(&wp->bits)) {
-			bp->bio_parent->bio_completed += wp->length;
+			completed = wp->length;
 			if (wp->lockbase != -1) {
 				TAILQ_REMOVE(&p->packets, wp, list);
 				/* Bring the waiting bios back into the game. */
@@ -368,8 +372,11 @@
 		break;
 
  	case BIO_WRITE:
-		if (wp == NULL)
+		/* XXX can this ever happen? */
+		if (wp == NULL) {
+			completed = bp->bio_completed;
 			break;
+		}
 
 		/* Check if we need to handle parity data. */
 		TAILQ_FOREACH_SAFE(bq, &wp->bits, queue, bq2) {
@@ -395,7 +402,7 @@
 
 			/* All of our sub-requests have finished. */
 			if (i) {
-				bp->bio_parent->bio_completed += wp->length;
+				completed = wp->length;
 				TAILQ_REMOVE(&p->packets, wp, list);
 				/* Bring the waiting bios back into the game. */
 				pbp = bioq_takefirst(p->wqueue);
@@ -415,6 +422,7 @@
 	pbp = bp->bio_parent;
 	if (pbp->bio_error == 0)
 		pbp->bio_error = bp->bio_error;
+	pbp->bio_completed += completed;
 
 	/* When the original request is finished, we deliver it. */
 	pbp->bio_inbed++;

==== //depot/projects/soc2007/lulf/gvinum_fixup/sys/geom/vinum/geom_vinum_raid5.h#2 (text+ko) ====

@@ -52,7 +52,6 @@
 	TAILQ_ENTRY(gv_raid5_packet)	list; /* Entry in plex's packet list. */
 };
 
-int	gv_stripe_active(struct gv_plex *, struct bio *);
 int	gv_raid5_request(struct gv_plex *, struct gv_raid5_packet *,
 	    struct bio *, caddr_t, off_t, off_t);
 int	gv_check_raid5(struct gv_plex *, struct gv_raid5_packet *,

==== //depot/projects/soc2007/lulf/gvinum_fixup/sys/geom/vinum/geom_vinum_rm.c#2 (text+ko) ====

@@ -83,7 +83,7 @@
 				return;
 			}
 
-			gv_post_event(sc, GV_EVENT_RM_VOLUME, v, NULL);
+			gv_post_event(sc, GV_EVENT_RM_VOLUME, v, NULL, NULL);
 			break;
 
 		case GV_TYPE_PLEX:
@@ -108,7 +108,7 @@
 				return;
 			}
 
-			gv_post_event(sc, GV_EVENT_RM_PLEX, p, NULL);
+			gv_post_event(sc, GV_EVENT_RM_PLEX, p, NULL, NULL);
 			break;
 
 		case GV_TYPE_SD:
@@ -121,7 +121,7 @@
 				return;
 			}
 
-			gv_post_event(sc, GV_EVENT_RM_SD, s, NULL);
+			gv_post_event(sc, GV_EVENT_RM_SD, s, NULL, NULL);
 			break;
 
 		case GV_TYPE_DRIVE:
@@ -140,7 +140,7 @@
 				return;
 			}
 
-			gv_post_event(sc, GV_EVENT_RM_DRIVE, d, NULL);
+			gv_post_event(sc, GV_EVENT_RM_DRIVE, d, NULL, NULL);
 			break;
 
 		default:
@@ -149,7 +149,7 @@
 		}
 	}
 
-	gv_post_event(sc, GV_EVENT_SAVE_CONFIG, sc, NULL);
+	gv_post_event(sc, GV_EVENT_SAVE_CONFIG, sc, NULL, NULL);
 }
 
 /* Resets configuration */
@@ -170,15 +170,15 @@
 	}
 	/* Then if not, we remove everything. */
 	LIST_FOREACH_SAFE(v, &sc->volumes, volume, v2)
-		gv_post_event(sc, GV_EVENT_RM_VOLUME, v, NULL);
+		gv_post_event(sc, GV_EVENT_RM_VOLUME, v, NULL, NULL);
 	LIST_FOREACH_SAFE(p, &sc->plexes, plex, p2)
-		gv_post_event(sc, GV_EVENT_RM_PLEX, p, NULL);
+		gv_post_event(sc, GV_EVENT_RM_PLEX, p, NULL, NULL);
 	LIST_FOREACH_SAFE(s, &sc->subdisks, sd, s2)
-		gv_post_event(sc, GV_EVENT_RM_SD, s, NULL);
+		gv_post_event(sc, GV_EVENT_RM_SD, s, NULL, NULL);
 	LIST_FOREACH_SAFE(d, &sc->drives, drive, d2)
-		gv_post_event(sc, GV_EVENT_RM_DRIVE, d, NULL);
+		gv_post_event(sc, GV_EVENT_RM_DRIVE, d, NULL, NULL);
 
-	gv_post_event(sc, GV_EVENT_SAVE_CONFIG, sc, NULL);
+	gv_post_event(sc, GV_EVENT_SAVE_CONFIG, sc, NULL, NULL);
 
 	return (0);
 }

==== //depot/projects/soc2007/lulf/gvinum_fixup/sys/geom/vinum/geom_vinum_state.c#2 (text+ko) ====

@@ -44,7 +44,7 @@
 	struct gv_sd *s;
 	struct gv_drive *d;
 	char *obj, *state;
-	int err, f, *flags, newstate, type;
+	int f, *flags, newstate, type;
 
 	f = 0;
 	obj = gctl_get_param(req, "object", NULL);
@@ -83,9 +83,8 @@
 			break;
 		}
 		s = gv_find_sd(sc, obj);
-		err = gv_set_sd_state(s, newstate, f);
-		if (err)
-			gctl_error(req, "cannot set subdisk state");
+
+		gv_post_event(sc, GV_EVENT_SET_SD_STATE, s, &newstate, &f);
 		break;
 
 	case GV_TYPE_DRIVE:
@@ -95,9 +94,8 @@
 			break;
 		}
 		d = gv_find_drive(sc, obj);
-		err = gv_set_drive_state(d, newstate, f);
-		if (err)
-			gctl_error(req, "cannot set drive state");
+
+		gv_post_event(sc, GV_EVENT_SET_DRIVE_STATE, d, &newstate, &f);
 		break;
 
 	default:

==== //depot/projects/soc2007/lulf/gvinum_fixup/sys/geom/vinum/geom_vinum_var.h#2 (text+ko) ====

@@ -160,23 +160,26 @@
 	TAILQ_ENTRY(gv_bioq)	queue;
 };
 
-#define GV_EVENT_DRIVE_TASTED	1
-#define GV_EVENT_DRIVE_LOST	2
-#define GV_EVENT_THREAD_EXIT	3
-#define GV_EVENT_CREATE_DRIVE	4
-#define GV_EVENT_CREATE_VOLUME	5
-#define GV_EVENT_CREATE_PLEX	6
-#define GV_EVENT_CREATE_SD	7
-#define GV_EVENT_SAVE_CONFIG	8
-#define GV_EVENT_RM_VOLUME	9
-#define	GV_EVENT_RM_PLEX	10
-#define GV_EVENT_RM_SD		11
-#define	GV_EVENT_RM_DRIVE	12
+#define GV_EVENT_DRIVE_TASTED		1
+#define GV_EVENT_DRIVE_LOST		2
+#define GV_EVENT_THREAD_EXIT		3
+#define GV_EVENT_CREATE_DRIVE		4
+#define GV_EVENT_CREATE_VOLUME		5
+#define GV_EVENT_CREATE_PLEX		6
+#define GV_EVENT_CREATE_SD		7
+#define GV_EVENT_SAVE_CONFIG		8
+#define GV_EVENT_RM_VOLUME		9
+#define GV_EVENT_RM_PLEX		10
+#define GV_EVENT_RM_SD			11
+#define GV_EVENT_RM_DRIVE		12
+#define GV_EVENT_SET_SD_STATE		13
+#define GV_EVENT_SET_DRIVE_STATE	14
 
 struct gv_event {
 	int	type;
 	void	*arg1;
 	void	*arg2;
+	void	*arg3;
 	TAILQ_ENTRY(gv_event)	events;
 };
 


More information about the p4-projects mailing list