PERFORCE change 123227 for review
Sonja Milicic
smilicic at FreeBSD.org
Mon Jul 9 20:45:45 UTC 2007
http://perforce.freebsd.org/chv.cgi?CH=123227
Change 123227 by smilicic at tanarri_marilith on 2007/07/09 20:45:26
repaired and tested worker thread. also added a function to empty event queue before the geom is stopped.
Affected files ...
.. //depot/projects/soc2007/smilicic_glog/sys/geom/log/glog.c#6 edit
Differences ...
==== //depot/projects/soc2007/smilicic_glog/sys/geom/log/glog.c#6 (text+ko) ====
@@ -71,7 +71,6 @@
static int g_log_post_event(struct g_log_event_sink *es, u_int type,
u_int flags, void* data1, int data2);
static struct g_log_event* g_log_get_event(struct g_log_event_sink *es);
-static int g_log_no_events(struct g_log_event_sink *es);
static void g_log_write(struct bio *bp);
static void g_log_read(struct bio *bp);
static void g_log_dumpconf(struct sbuf *sb, const char *indent,
@@ -168,7 +167,6 @@
/*create geom for log*/
gp = g_new_geomf(mp, "%s.log", prov);
- G_LOG_DEBUG(0, "Creating geom %s", gp->name);
gp->start = g_log_start;
gp->spoiled = g_log_orphan;
@@ -205,7 +203,8 @@
sc->sc_vn = glog_open_file(file, FWRITE | O_TRUNC | O_CREAT);
sc->sc_geom_log = gp;
gp->softc = sc;
-
+ G_LOG_DEBUG(0, "Created geom %s", gp->name);
+
return gp;
}
@@ -255,6 +254,7 @@
prov = gctl_get_asciiparam(req, "arg0");
file = gctl_get_asciiparam(req, "arg1");
gp = g_log_create_geom(prov, file, mp, &err);
+
if (err != 0){
switch (err){
case 1:
@@ -278,7 +278,7 @@
case GCTL_COMMIT:
if (*num_arg == 1) {
prov = gctl_get_asciiparam(req, "arg0");
- g_log_stop(gp,0);
+
} else
gctl_error(req, "Wrong number of parameters.");
@@ -294,6 +294,7 @@
default:
panic("Unknown verb!");
}
+ G_LOG_DEBUG(0, "ctlreq done");
}
/*start geom*/
@@ -307,7 +308,8 @@
bp->bio_to->error, bp->bio_to->name));
G_LOG_LOGREQ(DBG_NOTICE, bp, "Request received.");
-
+ g_io_deliver(bp, ENXIO);
+ return;
switch(bp->bio_cmd) {
case BIO_WRITE:
g_log_post_event(&sc->sc_events, GLOG_EVWRITE, GLOG_FLAG_WAKEUP_SC, bp, 0);
@@ -411,6 +413,26 @@
return err;
}
+/* Empty the worker queue */
+static void
+g_log_empty_event_queue(struct g_log_event_sink *es) {
+ struct g_log_softc *sc;
+ struct g_log_event *ev;
+
+ KASSERT(es != NULL, ("%s: event_sink is null", __func__));
+ sc = es->sc;
+ KASSERT(sc != NULL, ("%s: softc is null", __func__));
+
+ mtx_lock(&es->eventq_mtx);
+ while (!TAILQ_EMPTY(&es->eventq)) {
+ ev = TAILQ_FIRST(&es->eventq);
+ TAILQ_REMOVE(&es->eventq, ev, linkage);
+ free(ev, M_GLOG);
+ }
+ mtx_unlock(&es->eventq_mtx);
+
+}
+
/*worker thread*/
static void
g_log_worker(void *args)
@@ -426,8 +448,7 @@
KASSERT(sc != NULL, ("%s: softc is null", __func__));
while (1){
- G_LOG_DEBUG(0, "working...");
- if (!g_log_no_events(es))
+ if (!TAILQ_EMPTY(&es->eventq))
ev = g_log_get_event(es);
else
goto sleep;
@@ -445,15 +466,18 @@
g_log_write(bp);
break;
case GLOG_EVSTOP:
+ G_LOG_DEBUG(DBG_DEBUG, "Worker thread exiting");
+ g_log_empty_event_queue(es);
+ es->worker_thread = NULL;
+ kthread_exit(0);
break;
default:
G_LOG_DEBUG(0, "unhandled event %d", ev->type);
}
free(ev,M_GLOG);
+sleep: tsleep(es, PRIBIO, "glogidle", 1000);
}
-sleep: G_LOG_DEBUG(0, "putting worker to sleep");
- tsleep(es, PRIBIO, "glogidle", hz);
-
+
}
/* adds event to event queue */
static int
@@ -480,11 +504,8 @@
TAILQ_INSERT_TAIL(&es->eventq, ev, linkage);
mtx_unlock(&es->eventq_mtx);
G_LOG_DEBUG (0, "posted event %d", ev->type);
- if ( (flags & GLOG_FLAG_WAKEUP_SC) != 0){
- G_LOG_DEBUG(0, "waking worker");
+ if ( (flags & GLOG_FLAG_WAKEUP_SC) != 0)
wakeup(es);
- }
-
return 0;
}
@@ -499,8 +520,7 @@
KASSERT(es != NULL, ("%s: event_sink is null", __func__));
sc = es->sc;
KASSERT(sc != NULL, ("%s: softc is null", __func__));
- if (g_log_no_events(es))
- G_LOG_DEBUG(0, "no events");
+
mtx_lock(&es->eventq_mtx);
ev = TAILQ_FIRST(&es->eventq);
if (ev != NULL)
@@ -510,13 +530,6 @@
return ev;
}
-/*is the event queue empty?*/
-static int
-g_log_no_events(struct g_log_event_sink *es)
-{
- return TAILQ_EMPTY(&es->eventq);
-}
-
/*writes data to log file*/
static void
g_log_write(struct bio *bp)
@@ -581,15 +594,15 @@
struct g_log_softc *sc;
int *num_args, *force;
const char *prov;
+
g_topology_assert();
-
num_args = gctl_get_paraml(req, "nargs", sizeof(int));
if (*num_args != 1){
gctl_error(req, "Wrong number of arguments.");
return;
}
prov = gctl_get_asciiparam(req, "arg0");
-
+
force = gctl_get_paraml(req, "force", sizeof(int));
sc = g_log_find(mp, prov);
@@ -624,7 +637,6 @@
sbuf_printf(sb, "</State>\n");
}
- G_LOG_DEBUG(0, "xmldump");
}
/* Convert verb to number */
More information about the p4-projects
mailing list