Skip to content

Commit c496f6f

Browse files
committed
zio_add_child: collapse into a single function
The child locking difference is simple enough to handle with a boolean. The actual work is more involved, and it's easy to forget to change things in both places when experimenting. Just collapse them. Sponsored-by: Klara, Inc. Sponsored-by: Wasabi Technology, Inc. Signed-off-by: Rob Norris <[email protected]>
1 parent b048bfa commit c496f6f

File tree

2 files changed

+17
-36
lines changed

2 files changed

+17
-36
lines changed

include/sys/zio.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,6 @@ extern zio_t *zio_walk_parents(zio_t *cio, zio_link_t **);
621621
extern zio_t *zio_walk_children(zio_t *pio, zio_link_t **);
622622
extern zio_t *zio_unique_parent(zio_t *cio);
623623
extern void zio_add_child(zio_t *pio, zio_t *cio);
624-
extern void zio_add_child_first(zio_t *pio, zio_t *cio);
625624

626625
extern void *zio_buf_alloc(size_t size);
627626
extern void zio_buf_free(void *buf, size_t size);

module/zfs/zio.c

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -744,8 +744,8 @@ zio_unique_parent(zio_t *cio)
744744
return (pio);
745745
}
746746

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

767767
mutex_enter(&pio->io_lock);
768-
mutex_enter(&cio->io_lock);
768+
769+
if (first)
770+
ASSERT(list_is_empty(&cio->io_parent_list));
771+
else
772+
mutex_enter(&cio->io_lock);
769773

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

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

779-
mutex_exit(&cio->io_lock);
783+
if (!first)
784+
mutex_exit(&cio->io_lock);
785+
780786
mutex_exit(&pio->io_lock);
781787
}
782788

783789
void
784-
zio_add_child_first(zio_t *pio, zio_t *cio)
790+
zio_add_child(zio_t *pio, zio_t *cio)
785791
{
786-
/*
787-
* Logical I/Os can have logical, gang, or vdev children.
788-
* Gang I/Os can have gang or vdev children.
789-
* Vdev I/Os can only have vdev children.
790-
* The following ASSERT captures all of these constraints.
791-
*/
792-
ASSERT3S(cio->io_child_type, <=, pio->io_child_type);
793-
794-
/* Parent should not have READY stage if child doesn't have it. */
795-
IMPLY((cio->io_pipeline & ZIO_STAGE_READY) == 0 &&
796-
(cio->io_child_type != ZIO_CHILD_VDEV),
797-
(pio->io_pipeline & ZIO_STAGE_READY) == 0);
798-
799-
zio_link_t *zl = kmem_cache_alloc(zio_link_cache, KM_SLEEP);
800-
zl->zl_parent = pio;
801-
zl->zl_child = cio;
802-
803-
ASSERT(list_is_empty(&cio->io_parent_list));
804-
list_insert_head(&cio->io_parent_list, zl);
805-
806-
mutex_enter(&pio->io_lock);
807-
808-
ASSERT(pio->io_state[ZIO_WAIT_DONE] == 0);
809-
810-
uint64_t *countp = pio->io_children[cio->io_child_type];
811-
for (int w = 0; w < ZIO_WAIT_TYPES; w++)
812-
countp[w] += !cio->io_state[w];
813-
814-
list_insert_head(&pio->io_child_list, zl);
792+
zio_add_child_impl(pio, cio, B_FALSE);
793+
}
815794

816-
mutex_exit(&pio->io_lock);
795+
static void
796+
zio_add_child_first(zio_t *pio, zio_t *cio)
797+
{
798+
zio_add_child_impl(pio, cio, B_TRUE);
817799
}
818800

819801
static void

0 commit comments

Comments
 (0)