Skip to content

zio_add_child: collapse into a single function #17382

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion include/sys/zio.h
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,6 @@ extern zio_t *zio_walk_parents(zio_t *cio, zio_link_t **);
extern zio_t *zio_walk_children(zio_t *pio, zio_link_t **);
extern zio_t *zio_unique_parent(zio_t *cio);
extern void zio_add_child(zio_t *pio, zio_t *cio);
extern void zio_add_child_first(zio_t *pio, zio_t *cio);

extern void *zio_buf_alloc(size_t size);
extern void zio_buf_free(void *buf, size_t size);
Expand Down
52 changes: 17 additions & 35 deletions module/zfs/zio.c
Original file line number Diff line number Diff line change
Expand Up @@ -744,8 +744,8 @@ zio_unique_parent(zio_t *cio)
return (pio);
}

void
zio_add_child(zio_t *pio, zio_t *cio)
static void
zio_add_child_impl(zio_t *pio, zio_t *cio, boolean_t first)
{
/*
* Logical I/Os can have logical, gang, or vdev children.
Expand All @@ -765,7 +765,11 @@ zio_add_child(zio_t *pio, zio_t *cio)
zl->zl_child = cio;

mutex_enter(&pio->io_lock);
mutex_enter(&cio->io_lock);

if (first)
ASSERT(list_is_empty(&cio->io_parent_list));
else
mutex_enter(&cio->io_lock);

ASSERT(pio->io_state[ZIO_WAIT_DONE] == 0);

Expand All @@ -776,44 +780,22 @@ zio_add_child(zio_t *pio, zio_t *cio)
list_insert_head(&pio->io_child_list, zl);
list_insert_head(&cio->io_parent_list, zl);

mutex_exit(&cio->io_lock);
if (!first)
mutex_exit(&cio->io_lock);

mutex_exit(&pio->io_lock);
}

void
zio_add_child_first(zio_t *pio, zio_t *cio)
zio_add_child(zio_t *pio, zio_t *cio)
{
/*
* Logical I/Os can have logical, gang, or vdev children.
* Gang I/Os can have gang or vdev children.
* Vdev I/Os can only have vdev children.
* The following ASSERT captures all of these constraints.
*/
ASSERT3S(cio->io_child_type, <=, pio->io_child_type);

/* Parent should not have READY stage if child doesn't have it. */
IMPLY((cio->io_pipeline & ZIO_STAGE_READY) == 0 &&
(cio->io_child_type != ZIO_CHILD_VDEV),
(pio->io_pipeline & ZIO_STAGE_READY) == 0);

zio_link_t *zl = kmem_cache_alloc(zio_link_cache, KM_SLEEP);
zl->zl_parent = pio;
zl->zl_child = cio;

ASSERT(list_is_empty(&cio->io_parent_list));
list_insert_head(&cio->io_parent_list, zl);

mutex_enter(&pio->io_lock);

ASSERT(pio->io_state[ZIO_WAIT_DONE] == 0);

uint64_t *countp = pio->io_children[cio->io_child_type];
for (int w = 0; w < ZIO_WAIT_TYPES; w++)
countp[w] += !cio->io_state[w];

list_insert_head(&pio->io_child_list, zl);
zio_add_child_impl(pio, cio, B_FALSE);
}

mutex_exit(&pio->io_lock);
static void
zio_add_child_first(zio_t *pio, zio_t *cio)
{
zio_add_child_impl(pio, cio, B_TRUE);
}

static void
Expand Down
Loading