Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 12 Mar 2018 15:17:48 +0200
From:      Andriy Gapon <avg@FreeBSD.org>
To:        freebsd-geom@FreeBSD.org, freebsd-arch@FreeBSD.ORG
Subject:   geom->access problem and workaround
Message-ID:  <809d9254-ee56-59d8-69a4-08838e985cea@FreeBSD.org>

next in thread | raw e-mail | index | archive | help

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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?809d9254-ee56-59d8-69a4-08838e985cea>