Source-Changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

CVS commit: src/sys/dev



Module Name:    src
Committed By:   riastradh
Date:           Mon Dec 27 22:57:20 UTC 2021

Modified Files:
        src/sys/dev: cgd.c

Log Message:
cgd(4): Fix criterion for detach when wedgies are held.

The somewhat confusingly named DK_BUSY(dksc, pmask) answers the
following question:

        Suppose I hold either the character or the block device (but
        not both) of all of the partitions in pmask.  Is anyone else
        using the disk, rendering it unsafe to detach?

This is useful for ioctls like CGDIOCCLR and VNDIOCCLR, which must be
issued on open file descriptors for the disk, so the question cannot
simply be answered by testing whether dk_openmask != 0.

Instead, DK_BUSY breaks the question into the following criteria:

        1. Are there any _other_ partitions than those in pmask open
           at all?  If so, it must be someone else, since I only hold
           partitions in pmask -- hence the disk is busy.

        2. Are any of the partitions in pmask open _both_ as a block
           device _and_ as a character device?  If so, it must be
           someone else, since I only hold _either_ the character
           _or_ the block device open but not both -- hence the disk
           is busy.

When config_detach_all runs at shutdown time, it tries to detach
cgd(4), which has DVF_DETACH_SHUTDOWN; this is important so we submit
queued writes to the underlying disk and wait for them to complete
with dk_drain.

If cgd(4) has any dk wedges with file systems mounted still
configured on it, it isn't ready to detach yet.  But asking
DK_BUSY(dksc, 1 << RAW_PART) returns false, because the dk wedges
only hold RAW_PART open as a block device -- so if nobody has
RAW_PART open as a character device, or any other partitions open,
cgd_detach blithely goes on its way to forcibly detach the wedges.

Instead, ask DK_BUSY(dksc, 0), because the caller -- cgd_detach
issued by config_detach_all -- does not, in fact, hold any partitions
open, so it doesn't need to work around them like ioctl(CGDIOCCLR)
does.  Fixes hang in zfs on dk on cgd during shutdown (and probably
also zfs on cgd without any intervening dk but I haven't tested).

(This change might have the side effect that `drvctl -d cgdN' doesn't
work, but I don't care.)

XXX pullup-9
XXX pullup-8 (...-7, -6, -5...)


To generate a diff of this commit:
cvs rdiff -u -r1.141 -r1.142 src/sys/dev/cgd.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.




Home | Main Index | Thread Index | Old Index