aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Johnston <markj@FreeBSD.org>2023-03-26 18:14:53 +0000
committerMark Johnston <markj@FreeBSD.org>2023-03-30 17:38:15 +0000
commitfd02d0bc14b5c8d7109a180575b565fa7427b93e (patch)
treeeb4b925f36eeed9b1e2887306b9524cb86cb56a9
parentefe6a1574ec0a1b41a5729a478c6243002da60c9 (diff)
downloadsrc-fd02d0bc14b5c8d7109a180575b565fa7427b93e.tar.gz
src-fd02d0bc14b5c8d7109a180575b565fa7427b93e.zip
graid3: Pre-allocate the timeout event structure
As in commit 2f1cfb7f63ca ("gmirror: Pre-allocate the timeout event structure"), graid3 must avoid M_WAITOK allocations in callout handlers. Reported by: graid3 regression tests MFC after 2 weeks
-rw-r--r--sys/geom/raid3/g_raid3.c40
-rw-r--r--sys/geom/raid3/g_raid3.h1
2 files changed, 33 insertions, 8 deletions
diff --git a/sys/geom/raid3/g_raid3.c b/sys/geom/raid3/g_raid3.c
index 22e833c25f5d..1b425ba66f5f 100644
--- a/sys/geom/raid3/g_raid3.c
+++ b/sys/geom/raid3/g_raid3.c
@@ -125,6 +125,7 @@ static void g_raid3_dumpconf(struct sbuf *sb, const char *indent,
static void g_raid3_sync_stop(struct g_raid3_softc *sc, int type);
static int g_raid3_register_request(struct bio *pbp);
static void g_raid3_sync_release(struct g_raid3_softc *sc);
+static void g_raid3_timeout_drain(struct g_raid3_softc *sc);
static const char *
g_raid3_disk_state2str(int state)
@@ -285,15 +286,14 @@ g_raid3_event_free(struct g_raid3_event *ep)
free(ep, M_RAID3);
}
-int
-g_raid3_event_send(void *arg, int state, int flags)
+static int
+g_raid3_event_dispatch(struct g_raid3_event *ep, void *arg, int state,
+ int flags)
{
struct g_raid3_softc *sc;
struct g_raid3_disk *disk;
- struct g_raid3_event *ep;
int error;
- ep = malloc(sizeof(*ep), M_RAID3, M_WAITOK);
G_RAID3_DEBUG(4, "%s: Sending event %p.", __func__, ep);
if ((flags & G_RAID3_EVENT_DEVICE) != 0) {
disk = NULL;
@@ -330,6 +330,15 @@ g_raid3_event_send(void *arg, int state, int flags)
return (error);
}
+int
+g_raid3_event_send(void *arg, int state, int flags)
+{
+ struct g_raid3_event *ep;
+
+ ep = malloc(sizeof(*ep), M_RAID3, M_WAITOK);
+ return (g_raid3_event_dispatch(ep, arg, state, flags));
+}
+
static struct g_raid3_event *
g_raid3_event_get(struct g_raid3_softc *sc)
{
@@ -634,7 +643,7 @@ g_raid3_destroy_device(struct g_raid3_softc *sc)
mtx_unlock(&sc->sc_events_mtx);
}
}
- callout_drain(&sc->sc_callout);
+ g_raid3_timeout_drain(sc);
cp = LIST_FIRST(&sc->sc_sync.ds_geom->consumer);
g_topology_lock();
if (cp != NULL)
@@ -2377,13 +2386,26 @@ static void
g_raid3_go(void *arg)
{
struct g_raid3_softc *sc;
+ struct g_raid3_event *ep;
sc = arg;
G_RAID3_DEBUG(0, "Force device %s start due to timeout.", sc->sc_name);
- g_raid3_event_send(sc, 0,
+ ep = sc->sc_timeout_event;
+ sc->sc_timeout_event = NULL;
+ g_raid3_event_dispatch(ep, sc, 0,
G_RAID3_EVENT_DONTWAIT | G_RAID3_EVENT_DEVICE);
}
+static void
+g_raid3_timeout_drain(struct g_raid3_softc *sc)
+{
+ sx_assert(&sc->sc_lock, SX_XLOCKED);
+
+ callout_drain(&sc->sc_callout);
+ g_raid3_event_free(sc->sc_timeout_event);
+ sc->sc_timeout_event = NULL;
+}
+
static u_int
g_raid3_determine_state(struct g_raid3_disk *disk)
{
@@ -2473,7 +2495,7 @@ g_raid3_update_device(struct g_raid3_softc *sc, boolean_t force)
*/
if (g_raid3_ndisks(sc, -1) + force == sc->sc_ndisks) {
if (!force)
- callout_drain(&sc->sc_callout);
+ g_raid3_timeout_drain(sc);
} else {
if (force) {
/*
@@ -3217,9 +3239,11 @@ g_raid3_create(struct g_class *mp, const struct g_raid3_metadata *md)
G_RAID3_DEBUG(1, "root_mount_hold %p", sc->sc_rootmount);
/*
- * Run timeout.
+ * Schedule startup timeout.
*/
timeout = atomic_load_acq_int(&g_raid3_timeout);
+ sc->sc_timeout_event = malloc(sizeof(struct g_raid3_event), M_RAID3,
+ M_WAITOK);
callout_reset(&sc->sc_callout, timeout * hz, g_raid3_go, sc);
return (sc->sc_geom);
}
diff --git a/sys/geom/raid3/g_raid3.h b/sys/geom/raid3/g_raid3.h
index 8f0d92dee7ef..edfc036809c8 100644
--- a/sys/geom/raid3/g_raid3.h
+++ b/sys/geom/raid3/g_raid3.h
@@ -224,6 +224,7 @@ struct g_raid3_softc {
TAILQ_HEAD(, g_raid3_event) sc_events;
struct mtx sc_events_mtx;
+ struct g_raid3_event *sc_timeout_event;
struct callout sc_callout;