Skip to content

Commit a0a125b

Browse files
amotinandrewc12
authored andcommitted
Fix two abd_gang_add_gang() issues.
- There is no reason to assert that added gang is not empty. It may be weird to add an empty gang, but it is legal. - When moving chain list from the added gang clear its size, or it will trigger assertion in abd_verify() when that gang is freed. Reviewed-by: Brian Atkinson <[email protected]> Signed-off-by: Alexander Motin <[email protected]> Sponsored by: iXsystems, Inc. Closes openzfs#14816
1 parent aefb803 commit a0a125b

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

module/zfs/abd.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,20 @@ abd_gang_add_gang(abd_t *pabd, abd_t *cabd, boolean_t free_on_free)
370370
* will retain all the free_on_free settings after being
371371
* added to the parents list.
372372
*/
373+
#ifdef ZFS_DEBUG
374+
/*
375+
* If cabd had abd_parent, we have to drop it here. We can't
376+
* transfer it to pabd, nor we can clear abd_size leaving it.
377+
*/
378+
if (cabd->abd_parent != NULL) {
379+
(void) zfs_refcount_remove_many(
380+
&cabd->abd_parent->abd_children,
381+
cabd->abd_size, cabd);
382+
cabd->abd_parent = NULL;
383+
}
384+
#endif
373385
pabd->abd_size += cabd->abd_size;
386+
cabd->abd_size = 0;
374387
list_move_tail(&ABD_GANG(pabd).abd_gang_chain,
375388
&ABD_GANG(cabd).abd_gang_chain);
376389
ASSERT(list_is_empty(&ABD_GANG(cabd).abd_gang_chain));
@@ -408,7 +421,6 @@ abd_gang_add(abd_t *pabd, abd_t *cabd, boolean_t free_on_free)
408421
*/
409422
if (abd_is_gang(cabd)) {
410423
ASSERT(!list_link_active(&cabd->abd_gang_link));
411-
ASSERT(!list_is_empty(&ABD_GANG(cabd).abd_gang_chain));
412424
return (abd_gang_add_gang(pabd, cabd, free_on_free));
413425
}
414426
ASSERT(!abd_is_gang(cabd));

0 commit comments

Comments
 (0)