diff options
author | mav <mav@FreeBSD.org> | 2012-07-29 11:51:48 +0000 |
---|---|---|
committer | mav <mav@FreeBSD.org> | 2012-07-29 11:51:48 +0000 |
commit | 24017b5387054ebed0abcea2a144f0db7f108d51 (patch) | |
tree | 07c23269365b3097a0872aa1a4fe569caf1995e1 /sys/geom/geom_vfs.c | |
parent | 6009a2eb434a1c413557b4d2bc90c32da1b6e1d4 (diff) | |
download | FreeBSD-src-24017b5387054ebed0abcea2a144f0db7f108d51.zip FreeBSD-src-24017b5387054ebed0abcea2a144f0db7f108d51.tar.gz |
Implement media change notification for DA and CD removable media devices.
It includes three parts:
1) Modifications to CAM to detect media media changes and report them to
disk(9) layer. For modern SATA (and potentially UAS) devices it utilizes
Asynchronous Notification mechanism to receive events from hardware.
Active polling with TEST UNIT READY commands with 3 seconds period is used
for incapable hardware. After that both CD and DA drivers work the same way,
detecting two conditions: "NOT READY: Medium not present" after medium was
detected previously, and "UNIT ATTENTION: Not ready to ready change, medium
may have changed". First one reported to disk(9) as media removal, second
as media insert/change. To reliably receive second event new
AC_UNIT_ATTENTION async added to make UAs broadcasted to all periphs by
generic error handling code in cam_periph_error().
2) Modifications to GEOM core to handle media remove and change events.
Media removal handled by spoiling all consumers attached to the provider.
Media change event also schedules provider retaste after spoiling to probe
new media. New flag G_CF_ORPHAN was added to consumers to reflect that
consumer is in process of destruction. It allows retaste to create new
geom instance of the same class, while previous one is still dying.
3) Modifications to some GEOM classes: DEV -- to report media change
events to devd; VFS -- to handle spoiling same as orphan to prevent
accessing replaced media. PART class already handles spoiling alike to
orphan.
Reviewed by: silence on geom@ and scsi@
Tested by: avg
Sponsored by: iXsystems, Inc. / PC-BSD
MFC after: 2 months
Diffstat (limited to 'sys/geom/geom_vfs.c')
-rw-r--r-- | sys/geom/geom_vfs.c | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/sys/geom/geom_vfs.c b/sys/geom/geom_vfs.c index ade1790..86d0b55 100644 --- a/sys/geom/geom_vfs.c +++ b/sys/geom/geom_vfs.c @@ -65,11 +65,13 @@ static struct buf_ops __g_vfs_bufops = { struct buf_ops *g_vfs_bufops = &__g_vfs_bufops; static g_orphan_t g_vfs_orphan; +static g_spoiled_t g_vfs_spoiled; static struct g_class g_vfs_class = { .name = "VFS", .version = G_VERSION, .orphan = g_vfs_orphan, + .spoiled = g_vfs_spoiled, }; DECLARE_GEOM_CLASS(g_vfs_class, g_vfs); @@ -215,8 +217,35 @@ g_vfs_orphan(struct g_consumer *cp) if (sc == NULL) return; mtx_lock(&sc->sc_mtx); + destroy = (sc->sc_active == 0 && sc->sc_orphaned == 0); + sc->sc_orphaned = 1; + mtx_unlock(&sc->sc_mtx); + if (destroy) + g_vfs_destroy(cp, 0); + + /* + * Do not destroy the geom. Filesystem will do that during unmount. + */ +} + +static void +g_vfs_spoiled(struct g_consumer *cp) +{ + struct g_geom *gp; + struct g_vfs_softc *sc; + int destroy; + + g_topology_assert(); + + gp = cp->geom; + g_trace(G_T_TOPOLOGY, "g_vfs_spoiled(%p(%s))", cp, gp->name); + cp->flags |= G_CF_ORPHAN; + sc = gp->softc; + if (sc == NULL) + return; + mtx_lock(&sc->sc_mtx); + destroy = (sc->sc_active == 0 && sc->sc_orphaned == 0); sc->sc_orphaned = 1; - destroy = (sc->sc_active == 0); mtx_unlock(&sc->sc_mtx); if (destroy) g_vfs_destroy(cp, 0); |