geom->access problem and workaround

Andriy Gapon avg at FreeBSD.org
Mon Mar 12 13:17:53 UTC 2018


According to Poul-Henning (phk@), the principal author of GEOM, a GEOM class's
access method was intended to be a light-weight operation involving mostly
access counts.  That is, it should be (have been) close in spirit to what
g_access() function does.  The method is only called from g_access and it is
always done under the GEOM topology lock (like with most GEOM "control plane"
methods).  The lock ensures that the method and the function operate on a
consistent state of the topology and all geoms in it.

In reality, many classes have their access method do a lot more than just
checking and modifying access bits.  And often, what the method does is
incompatible with the topology lock.

Some examples.
g_mirror_access() has to drop and reacquire the topology lock to avoid a LOR
(deadlock) because the method needs to use the class's internal sc_lock.

zvol_geom_access() also has to drop and reacquire the topology lock when it
interacts with ZFS internals involving many locks.  The main issue here is that
ZFS is both above the GEOM when ZFS uses GEOM for the storage access and it is
"below" the GEOM when ZFS is accessed through the ZVOL provider.

g_disk_access() -> daopen().  In this case the topology lock is never dropped,
but the operation issues multiple SCSI commands and waits for their completion.
So, if something goes wrong and takes a long time to complete then the whole
topology will be frozen for all that time.
[Perhaps doing the lock dance would be a better alternative]

But, of course, dropping the lock does not come free.
It opens races where two (at least) sets of incompatible access counts may get
granted.  Or a special action, that should be done only on a first access to a
geom, could be executed more than once.

Bringing everything to conformance with the original design would be an ideal
solution, but it will take a lot of work both in the individual nonconforming
classes and in at least some of their consumers.  It seems to require moving all
the complex operations from access methods to the GEOM "data plane".  E.g, doing
those things upon the first I/O operation.  Or having a new special BIO_GETATTR
(kind of) operation that could be executed after g_access() but before the
actual I/O is allowed.

I am proposing an interim solution, so really a workaround, for the problem of
dropping the topology lock:

https://reviews.freebsd.org/D14533

That workaround cannot guarantee, of course, the complete stability of the
topology, but it prevents concurrent calls to access methods.
The idea is very simple.  Before calling a geom's access method the geom is
marked with a special flag unless the flag is already set in which case the code
waits until the flag is cleared.  The flag is cleared after the call, of course.
The topology lock is released while waiting for the flag.

I think that having this new flag may help to get more visibility into the problem.

P.S.
The workaround does not help daopen() at all.

-- 
Andriy Gapon


More information about the freebsd-arch mailing list