From 626fc9fe3d995ec8666e92a1d01810f896e34ec1 Mon Sep 17 00:00:00 2001 From: Andrew Thompson Date: Fri, 3 Apr 2009 19:46:12 +0000 Subject: [PATCH] Add a how argument to root_mount_hold() so it can be passed NOWAIT and be called in situations where sleeping isnt allowed. --- .../contrib/opensolaris/uts/common/fs/zfs/zfs_ioctl.c | 2 +- sys/dev/pccbb/pccbb_pci.c | 2 +- sys/dev/usb/controller/usb_controller.c | 2 +- sys/geom/journal/g_journal.c | 2 +- sys/geom/mirror/g_mirror.c | 2 +- sys/geom/part/g_part.c | 2 +- sys/geom/raid3/g_raid3.c | 2 +- sys/kern/vfs_mount.c | 8 ++++++-- sys/sys/systm.h | 2 +- 9 files changed, 14 insertions(+), 10 deletions(-) diff --git a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ioctl.c b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ioctl.c index a6829eb1f12..e91695ba0c1 100644 --- a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ioctl.c +++ b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ioctl.c @@ -3087,7 +3087,7 @@ zfs_modevent(module_t mod, int type, void *unused __unused) error = EOPNOTSUPP; switch (type) { case MOD_LOAD: - zfs_root_token = root_mount_hold("ZFS"); + zfs_root_token = root_mount_hold("ZFS", M_WAITOK); printf("WARNING: ZFS is considered to be an experimental " "feature in FreeBSD.\n"); TASK_INIT(&zfs_start_task, 0, zfs_start, NULL); diff --git a/sys/dev/pccbb/pccbb_pci.c b/sys/dev/pccbb/pccbb_pci.c index c89e5ad1f45..4fcd7eafb5e 100644 --- a/sys/dev/pccbb/pccbb_pci.c +++ b/sys/dev/pccbb/pccbb_pci.c @@ -439,7 +439,7 @@ cbb_pci_attach(device_t brdev) device_printf(brdev, "unable to create event thread.\n"); panic("cbb_create_event_thread"); } - sc->sc_root_token = root_mount_hold(device_get_nameunit(sc->dev)); + sc->sc_root_token = root_mount_hold(device_get_nameunit(sc->dev), M_WAITOK); return (0); err: if (sc->irq_res) diff --git a/sys/dev/usb/controller/usb_controller.c b/sys/dev/usb/controller/usb_controller.c index fc31f15edaf..bea3e7770ee 100644 --- a/sys/dev/usb/controller/usb_controller.c +++ b/sys/dev/usb/controller/usb_controller.c @@ -115,7 +115,7 @@ usb2_attach(device_t dev) } /* delay vfs_mountroot until the bus is explored */ - bus->bus_roothold = root_mount_hold(device_get_nameunit(dev)); + bus->bus_roothold = root_mount_hold(device_get_nameunit(dev), M_WAITOK); if (usb2_post_init_called) { mtx_lock(&Giant); diff --git a/sys/geom/journal/g_journal.c b/sys/geom/journal/g_journal.c index 2db236440fc..d3274a2bba4 100644 --- a/sys/geom/journal/g_journal.c +++ b/sys/geom/journal/g_journal.c @@ -2310,7 +2310,7 @@ g_journal_create(struct g_class *mp, struct g_provider *pp, sc->sc_inactive.jj_queue = NULL; sc->sc_active.jj_queue = NULL; - sc->sc_rootmount = root_mount_hold("GJOURNAL"); + sc->sc_rootmount = root_mount_hold("GJOURNAL", M_WAITOK); GJ_DEBUG(1, "root_mount_hold %p", sc->sc_rootmount); callout_init(&sc->sc_callout, CALLOUT_MPSAFE); diff --git a/sys/geom/mirror/g_mirror.c b/sys/geom/mirror/g_mirror.c index 13ff6eaabb6..85b5b24399e 100644 --- a/sys/geom/mirror/g_mirror.c +++ b/sys/geom/mirror/g_mirror.c @@ -2907,7 +2907,7 @@ g_mirror_create(struct g_class *mp, const struct g_mirror_metadata *md) G_MIRROR_DEBUG(1, "Device %s created (%u components, id=%u).", sc->sc_name, sc->sc_ndisks, sc->sc_id); - sc->sc_rootmount = root_mount_hold("GMIRROR"); + sc->sc_rootmount = root_mount_hold("GMIRROR", M_WAITOK); G_MIRROR_DEBUG(1, "root_mount_hold %p", sc->sc_rootmount); /* * Run timeout. diff --git a/sys/geom/part/g_part.c b/sys/geom/part/g_part.c index 447221ac7b7..58fa7974ddc 100644 --- a/sys/geom/part/g_part.c +++ b/sys/geom/part/g_part.c @@ -1474,7 +1474,7 @@ g_part_taste(struct g_class *mp, struct g_provider *pp, int flags __unused) return (NULL); } - rht = root_mount_hold(mp->name); + rht = root_mount_hold(mp->name, M_WAITOK); g_topology_unlock(); /* diff --git a/sys/geom/raid3/g_raid3.c b/sys/geom/raid3/g_raid3.c index 1cbce257b59..cb19ef2a1fd 100644 --- a/sys/geom/raid3/g_raid3.c +++ b/sys/geom/raid3/g_raid3.c @@ -3193,7 +3193,7 @@ g_raid3_create(struct g_class *mp, const struct g_raid3_metadata *md) G_RAID3_DEBUG(1, "Device %s created (%u components, id=%u).", sc->sc_name, sc->sc_ndisks, sc->sc_id); - sc->sc_rootmount = root_mount_hold("GRAID3"); + sc->sc_rootmount = root_mount_hold("GRAID3", M_WAITOK); G_RAID3_DEBUG(1, "root_mount_hold %p", sc->sc_rootmount); /* diff --git a/sys/kern/vfs_mount.c b/sys/kern/vfs_mount.c index e4256c7f28e..164eb1217c0 100644 --- a/sys/kern/vfs_mount.c +++ b/sys/kern/vfs_mount.c @@ -1353,14 +1353,18 @@ static int root_mount_complete; * Hold root mount. */ struct root_hold_token * -root_mount_hold(const char *identifier) +root_mount_hold(const char *identifier, int how) { struct root_hold_token *h; if (root_mounted()) return (NULL); - h = malloc(sizeof *h, M_DEVBUF, M_ZERO | M_WAITOK); + h = malloc(sizeof *h, M_DEVBUF, M_ZERO | how); + if (h == NULL) { + printf("Unable to alloc root hold token for %s\n", identifier); + return (NULL); + } h->who = identifier; mtx_lock(&mountlist_mtx); LIST_INSERT_HEAD(&root_holds, h, list); diff --git a/sys/sys/systm.h b/sys/sys/systm.h index 31fb750a206..244d2181391 100644 --- a/sys/sys/systm.h +++ b/sys/sys/systm.h @@ -325,7 +325,7 @@ void DELAY(int usec); /* Root mount holdback API */ struct root_hold_token; -struct root_hold_token *root_mount_hold(const char *identifier); +struct root_hold_token *root_mount_hold(const char *identifier, int how); void root_mount_rel(struct root_hold_token *h); void root_mount_wait(void); int root_mounted(void);