zio: refactor zio_flush()

zio_ioctl() is the only user of zio_flush(), and its structure and flag
use is fairly specific to flushing. So here we bring the guts of
zio_ioctl() into zio_flush(), allowing some light reorganising (mostly
around how zio_nowait() is called) and a better signature.

This will help in the future when changing the way flush works, as its
clear where the change should be made and no wondering if zio_ioctl() is
being used somewhere else.

Signed-off-by: Rob Norris <rob.norris@klarasystems.com>
This commit is contained in:
Rob Norris 2023-08-24 10:43:05 +10:00 committed by Geoff Amey
parent 97b5e0bbbd
commit 1a160e3b08
4 changed files with 33 additions and 35 deletions

View File

@ -563,9 +563,6 @@ extern zio_t *zio_claim(zio_t *pio, spa_t *spa, uint64_t txg,
const blkptr_t *bp, const blkptr_t *bp,
zio_done_func_t *done, void *priv, enum zio_flag flags); zio_done_func_t *done, void *priv, enum zio_flag flags);
extern zio_t *zio_ioctl(zio_t *pio, spa_t *spa, vdev_t *vd, int cmd,
zio_done_func_t *done, void *priv, enum zio_flag flags);
extern zio_t *zio_trim(zio_t *pio, vdev_t *vd, uint64_t offset, uint64_t size, extern zio_t *zio_trim(zio_t *pio, vdev_t *vd, uint64_t offset, uint64_t size,
zio_done_func_t *done, void *priv, zio_priority_t priority, zio_done_func_t *done, void *priv, zio_priority_t priority,
enum zio_flag flags, enum trim_flag trim_flags); enum zio_flag flags, enum trim_flag trim_flags);
@ -585,7 +582,7 @@ extern zio_t *zio_free_sync(zio_t *pio, spa_t *spa, uint64_t txg,
extern int zio_alloc_zil(spa_t *spa, objset_t *os, uint64_t txg, extern int zio_alloc_zil(spa_t *spa, objset_t *os, uint64_t txg,
blkptr_t *new_bp, uint64_t size, boolean_t *slog); blkptr_t *new_bp, uint64_t size, boolean_t *slog);
extern void zio_flush(zio_t *zio, vdev_t *vd, enum zio_flag flags); extern void zio_flush(zio_t *zio, vdev_t *vd, boolean_t propagate);
extern void zio_shrink(zio_t *zio, uint64_t size); extern void zio_shrink(zio_t *zio, uint64_t size);
extern int zio_wait(zio_t *zio); extern int zio_wait(zio_t *zio);

View File

@ -1711,7 +1711,7 @@ vdev_uberblock_sync_list(vdev_t **svd, int svdcount, uberblock_t *ub, int flags)
for (int v = 0; v < svdcount; v++) { for (int v = 0; v < svdcount; v++) {
if (vdev_writeable(svd[v])) { if (vdev_writeable(svd[v])) {
zio_flush(zio, svd[v], ZIO_FLAG_DONT_PROPAGATE); zio_flush(zio, svd[v], B_FALSE);
} }
} }
@ -1848,7 +1848,7 @@ vdev_label_sync_list(spa_t *spa, int l, uint64_t txg, int flags)
zio = zio_root(spa, NULL, NULL, flags); zio = zio_root(spa, NULL, NULL, flags);
for (vd = list_head(dl); vd != NULL; vd = list_next(dl, vd)) for (vd = list_head(dl); vd != NULL; vd = list_next(dl, vd))
zio_flush(zio, vd, ZIO_FLAG_DONT_PROPAGATE); zio_flush(zio, vd, B_FALSE);
(void) zio_wait(zio); (void) zio_wait(zio);
@ -1921,7 +1921,7 @@ retry:
for (vdev_t *vd = for (vdev_t *vd =
txg_list_head(&spa->spa_vdev_txg_list, TXG_CLEAN(txg)); vd != NULL; txg_list_head(&spa->spa_vdev_txg_list, TXG_CLEAN(txg)); vd != NULL;
vd = txg_list_next(&spa->spa_vdev_txg_list, vd, TXG_CLEAN(txg))) vd = txg_list_next(&spa->spa_vdev_txg_list, vd, TXG_CLEAN(txg)))
zio_flush(zio, vd, ZIO_FLAG_DONT_PROPAGATE); zio_flush(zio, vd, B_FALSE);
(void) zio_wait(zio); (void) zio_wait(zio);

View File

@ -1706,7 +1706,7 @@ zil_lwb_write_done(zio_t *zio)
* that had their flushes deferred. Flush errors will * that had their flushes deferred. Flush errors will
* be delivered to zil_lwb_flush_vdevs_done(). * be delivered to zil_lwb_flush_vdevs_done().
*/ */
zio_flush(lwb->lwb_root_zio, vd, 0); zio_flush(lwb->lwb_root_zio, vd, B_TRUE);
} }
kmem_free(zv, sizeof (*zv)); kmem_free(zv, sizeof (*zv));
} }

View File

@ -1306,30 +1306,6 @@ zio_claim(zio_t *pio, spa_t *spa, uint64_t txg, const blkptr_t *bp,
return (zio); return (zio);
} }
zio_t *
zio_ioctl(zio_t *pio, spa_t *spa, vdev_t *vd, int cmd,
zio_done_func_t *done, void *private, enum zio_flag flags)
{
zio_t *zio;
int c;
if (vd->vdev_children == 0) {
zio = zio_create(pio, spa, 0, NULL, NULL, 0, 0, done, private,
ZIO_TYPE_IOCTL, ZIO_PRIORITY_NOW, flags, vd, 0, NULL,
ZIO_STAGE_OPEN, ZIO_IOCTL_PIPELINE);
zio->io_cmd = cmd;
} else {
zio = zio_null(pio, spa, NULL, NULL, NULL, flags);
for (c = 0; c < vd->vdev_children; c++)
zio_nowait(zio_ioctl(zio, spa, vd->vdev_child[c], cmd,
done, private, flags));
}
return (zio);
}
zio_t * zio_t *
zio_trim(zio_t *pio, vdev_t *vd, uint64_t offset, uint64_t size, zio_trim(zio_t *pio, vdev_t *vd, uint64_t offset, uint64_t size,
zio_done_func_t *done, void *private, zio_priority_t priority, zio_done_func_t *done, void *private, zio_priority_t priority,
@ -1501,11 +1477,36 @@ zio_vdev_delegated_io(vdev_t *vd, uint64_t offset, abd_t *data, uint64_t size,
return (zio); return (zio);
} }
/*
* Send a flush command to the given vdev. Unlike most zio creation functions,
* the flush zios are issued immediately. You can wait on pio to pause until
* the flushes complete.
*
* Set propagate to true to have flush errors propagated to the parent.
* Otherwise, flush errors are ignored.
*/
void void
zio_flush(zio_t *zio, vdev_t *vd, enum zio_flag flags) zio_flush(zio_t *pio, vdev_t *vd, boolean_t propagate)
{ {
zio_nowait(zio_ioctl(zio, zio->io_spa, vd, DKIOCFLUSHWRITECACHE, const int cmd = DKIOCFLUSHWRITECACHE;
NULL, NULL, flags | ZIO_FLAG_CANFAIL | ZIO_FLAG_DONT_RETRY)); const enum zio_flag flags =
ZIO_FLAG_CANFAIL | ZIO_FLAG_DONT_RETRY |
(propagate ? 0 : ZIO_FLAG_DONT_PROPAGATE);
spa_t *spa = pio->io_spa;
zio_t *zio;
if (vd->vdev_children == 0) {
zio = zio_create(pio, spa, 0, NULL, NULL, 0, 0, NULL, NULL,
ZIO_TYPE_IOCTL, ZIO_PRIORITY_NOW, flags, vd, 0, NULL,
ZIO_STAGE_OPEN, ZIO_IOCTL_PIPELINE);
zio->io_cmd = cmd;
} else {
zio = zio_null(pio, spa, NULL, NULL, NULL, flags);
for (int c = 0; c < vd->vdev_children; c++)
zio_flush(zio, vd->vdev_child[c], propagate);
}
zio_nowait(zio);
} }
void void