PERFORCE change 122892 for review

Sonja Milicic smilicic at FreeBSD.org
Thu Jul 5 00:01:42 UTC 2007


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

Change 122892 by smilicic at tanarri_marilith on 2007/07/05 00:01:06

	fixed a bug with log provider creation and added more details to dumpconf

Affected files ...

.. //depot/projects/soc2007/smilicic_glog/sys/geom/log/glog.c#4 edit

Differences ...

==== //depot/projects/soc2007/smilicic_glog/sys/geom/log/glog.c#4 (text+ko) ====

@@ -62,7 +62,7 @@
 static int g_log_destroy_geom(struct gctl_req *req __unused, 
 	    struct g_class *mp __unused, struct g_geom *gp);
 static void g_log_start(struct bio *bp); 
-static void g_log_stop(struct g_geom *gp, int force);
+static int g_log_stop(struct g_geom *gp, int force);
 static int g_log_access(struct g_provider *pp, int dr, int dw, int de);
 static int g_log_event_sink_init(struct g_log_softc *sc, 
 	    struct g_log_event_sink *es, void (*func)(void*), char* name);
@@ -159,15 +159,16 @@
 {
 	struct g_geom *gp;
 	struct g_provider *pp_log, *pp_disk;
+       	struct g_consumer *cp_disk;
 	struct g_log_softc *sc;
-	struct g_consumer *cp_disk;
 	
 	/*initialize softc*/
 	sc = malloc(sizeof(*sc), M_GLOG, M_WAITOK | M_ZERO);
 	
-	/*create geom and provider for log*/
+	/*create geom for log*/
 	gp = g_new_geomf(mp, "%s.log", prov);
-	gp->softc = sc;
+        G_LOG_DEBUG(0, "Creating geom %s", gp->name);
+
 	gp->start = g_log_start;
 	gp->spoiled = g_log_orphan;
 	gp->orphan = g_log_orphan;
@@ -175,14 +176,8 @@
 	gp->dumpconf = g_log_dumpconf;
 	if (gp == NULL)
 		*err=3;
-	pp_log = g_new_providerf(gp, "%s.log", prov);
-	sc->sc_geom_log = gp;
-	sc->sc_prov_log = pp_log;
 	
-	if (g_log_event_sink_init(sc, &sc->sc_events, g_log_worker, "events") !=0)
-		*err=4;
-	
-	/* create provider and consumer for disk*/
+	/* get provider and consumer for disk*/
 	if (strncmp(prov, "/dev/", strlen("/dev/")) == 0)
 		prov += strlen("/dev/");
 	pp_disk = g_provider_by_name(prov);
@@ -194,10 +189,20 @@
 	sc->sc_prov_disk = pp_disk;
 	sc->sc_cons_disk = cp_disk;
 	
+	/*create provider for log*/
+	pp_log = g_new_providerf(gp, "%s.log", prov);
+	pp_log->mediasize = (off_t) 1000;
+	pp_log->sectorsize = pp_disk->sectorsize;
+	g_error_provider(pp_log, 0);
+	sc->sc_prov_log = pp_log;
+	
+	if (g_log_event_sink_init(sc, &sc->sc_events, g_log_worker, "events") !=0)
+		*err=4;
 	/*open file*/
 	sc->sc_vn = glog_open_file(file, FWRITE | O_TRUNC | O_CREAT);
+	sc->sc_geom_log = gp;
+        gp->softc = sc;
 	
-	
 	return gp;
 }
 
@@ -301,24 +306,55 @@
 }
 
 /*stop geom*/
-static void
+static int
 g_log_stop(struct g_geom *gp, int force)
 {
 	struct g_log_softc *sc;
+        struct g_provider *pp_disk, *pp_log;
+	struct g_consumer *cp_disk;
 	sc=gp->softc;
+        
+       	g_topology_assert();
+
+	if (sc==NULL)
+                return (ENXIO);
+        
+        pp_log = sc->sc_prov_log;
+	pp_disk = sc->sc_prov_disk;
+	cp_disk = sc->sc_cons_disk;
 	
+        if (pp_log != NULL && (pp_log->acr != 0 || pp_log->acw !=0 || pp_log->ace != 0)){
+                if (force)
+                        G_LOG_DEBUG(0, "Device %s is still open.", pp_log->name);
+                else {
+                        G_LOG_DEBUG(1, "Device %s is still open(r%d, w%d, e%d)",
+                            pp_log->name,pp_log->acr,pp_log->acw,pp_log->ace);
+                        return (EBUSY);
+                }
+        }
 	/*close log file*/
+        G_LOG_DEBUG(0, "Closing log file.");
 	glog_close_file(sc->sc_vn, FWRITE);
 	
 	/*clean up memory*/
-	g_detach(sc->sc_cons_disk);
-	g_destroy_consumer(sc->sc_cons_disk);
+	G_LOG_DEBUG(0,"cleaning up mem.");
+	g_orphan_provider(pp_log, ENXIO);
+	if (cp_disk->acr > 0 ||cp_disk->acw > 0 ||cp_disk->ace > 0)
+		g_access(cp_disk, -cp_disk->acr, -cp_disk->acw, -cp_disk->ace);
+	
+	g_detach(cp_disk);
+	g_destroy_consumer(cp_disk);
 	gp->softc = NULL;
 	free(sc, M_GLOG);
 	
 	/*destroy geom*/
-	g_topology_assert();
+	if (pp_log == NULL || (pp_log->acr == 0 && pp_log->acw == 0 && pp_log->ace == 0))
+                G_LOG_DEBUG(0, "Device %s destroyed.", gp->name);
+        
 	g_wither_geom(gp, ENXIO);
+	
+        G_LOG_DEBUG(0, "Really destroyed %s.", gp->name);
+        return 0;
 }
 
 static int
@@ -351,6 +387,7 @@
 		err = g_access(cp, dr ,dw, de);
 		if (err == 0)
 			continue;
+                G_LOG_DEBUG(0, "loop access");
 	}
 	return err;
 }
@@ -359,8 +396,10 @@
 static void
 g_log_worker_sleep(struct g_log_softc *sc)
 {
-	if (g_log_no_events(&sc->sc_events))
-		tsleep(sc, PRIBIO, "glogidle", hz); 
+	if (g_log_no_events(&sc->sc_events)){
+		G_LOG_DEBUG(0, "putting worker to sleep");
+		tsleep(sc, PRIBIO, "glogidle", hz);
+	}
 }
 
 /*worker thread*/
@@ -380,6 +419,7 @@
 		panic("No softc!");
 	
 	while (1){
+                G_LOG_DEBUG(0,"working...");
 		ev = g_log_get_event(&sc->sc_events);
 		while (ev == NULL) 
 			g_log_worker_sleep(sc);
@@ -426,8 +466,10 @@
 	TAILQ_INSERT_TAIL(&es->eventq, ev, linkage);
 	mtx_unlock(&es->eventq_mtx);
 
-	if ( (flags & GLOG_FLAG_WAKEUP_SC) != 0)
+	if ( (flags & GLOG_FLAG_WAKEUP_SC) != 0){
+		G_LOG_DEBUG(0, "waking worker");
 		wakeup(es);
+	}
     
 	return 0;
 }
@@ -466,12 +508,13 @@
 	struct g_log_softc *sc;
 	void *data;
 	int err;
-	uprintf("Got a write request.");
+        G_LOG_DEBUG(0, "write request");
 	sc = bp->bio_to->geom->softc;
 	data = bp->bio_data;
 	err = glog_write_file(sc->sc_vn, data, sizeof(data), 0);
 	if (err != 0)
-		printf ("Error writing to file");
+                G_LOG_DEBUG(0, "write error");
+
 	
 }
 
@@ -504,13 +547,28 @@
 	return 0;	
 }
 
+/* Find the geom we handle */
+static struct g_log_softc *
+g_log_find(struct g_class *mp, const char *name)
+{
+    struct g_geom *gp;
+
+    G_LOG_DEBUG(DBG_DEBUG, "%s: %s", __func__, name);
+    LIST_FOREACH(gp, &mp->geom, geom) {
+        if (strcmp(gp->name, name) == 0)
+            return (gp->softc);
+	G_LOG_DEBUG(0, "loop log_find");
+
+    }
+    return (NULL);
+}
+
 static void
 g_log_ctl_destroy(struct gctl_req *req, struct g_class *mp)
 {
-	struct g_geom *gp;
+	struct g_log_softc *sc;
 	int *num_args, *force;
 	const char *prov;
-	
 	g_topology_assert();
 	
 	num_args = gctl_get_paraml(req, "nargs", sizeof(int));
@@ -521,10 +579,12 @@
 	prov = gctl_get_asciiparam(req, "arg0");
 
 	force = gctl_get_paraml(req, "force", sizeof(int));
-	gp = LIST_FIRST(&mp->geom);
-	g_log_stop(gp, *force);
 	
-	
+        sc = g_log_find(mp, prov);
+        if (sc != NULL)
+                g_log_stop(sc->sc_geom_log, *force);
+        else 
+                panic("Softc is null in ctl_destroy!");
 }
 /*XML*/
 static void
@@ -542,9 +602,18 @@
 		sbuf_printf(sb, "%s<Number>%u</Number>\n", indent,
 		    (u_int)cp->index);
 	} else {
-	       
-		
+		sbuf_printf(sb, "%s<Status>Total=%u, Online=%u</Status>\n",
+		    indent, 1, 1);
+		sbuf_printf(sb, "%s<State>", indent);
+		if (sc->sc_prov_log != NULL && sc->sc_prov_log->error == 0)
+			sbuf_printf(sb, "UP");
+		else
+			sbuf_printf(sb, "DOWN");
+		G_LOG_DEBUG(0, "error=%d", sc->sc_prov_log->error);
+		sbuf_printf(sb, "</State>\n");
 	}
+        
+        G_LOG_DEBUG(0, "xmldump");
 }
 		    
 /* Convert verb to number */
@@ -564,4 +633,3 @@
 };
 
 DECLARE_GEOM_CLASS(g_log_class, g_log);
-


More information about the p4-projects mailing list