This change re-applies r273143. The original motivation for this change
was to fix callers of biowait(), all of which follow the pattern:
bp->bio_done = NULL; g_io_request(bp); biowait(bp); g_destroy_bio(bp);
(Note that the biowait() calls in ZFS are not compiled on FreeBSD.)
Because the g_disk optimization in r256880 introduced a trick where
the bio_done handler is overridden once the request is dispatched, it
was racy to set BIO_DONE before the g_disk bio_done handler completed.
This g_disk handler takes care to call biodone() with the original
bio_done handler, and this will wake up waiters in biowait(). However,
with r273638 there is no code to exercise this race.
Isilon's FS uses biowait() on BIOs with a non-NULL bio_done handler.
This is done e.g., to serialize updates to a superblock-like state
block. The bio_done handler is responsible for ensuring that waiters are
awoken. Right now it does so by setting bio_done = NULL and calling
biodone() again. With this use-case, it is also incorrect to set BIO_DONE
before calling the handler.
The cause of the corruption mentioned in r273638 is not clear to me, but
I believe that r273143 on its own cannot be the cause. It is
intrinsically racy to set BIO_DONE in common code when a bio_done handler
is provided.