Skip to content

Commit

Permalink
Fix racy assignment of zcb.zcb_haderrors
Browse files Browse the repository at this point in the history
zcb_haderrors will be modified in zdb_blkptr_done, which is
asynchronous. So we must move this assignment after zio_wait.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: loli10K <ezomori.nozomu@gmail.com>
Signed-off-by: Chunwei Chen <david.chen@nutanix.com>
Closes openzfs#7099
  • Loading branch information
davidchenntnx authored and tonyhutter committed Mar 8, 2018
1 parent 2a59c28 commit ffcef3f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions cmd/zdb/zdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -3313,7 +3313,7 @@ dump_block_stats(spa_t *spa)
uint64_t norm_alloc, norm_space, total_alloc, total_found;
int flags = TRAVERSE_PRE | TRAVERSE_PREFETCH_METADATA | TRAVERSE_HARD;
boolean_t leaks = B_FALSE;
int e, c;
int e, c, err;
bp_embedded_type_t i;

(void) printf("\nTraversing all blocks %s%s%s%s%s...\n\n",
Expand Down Expand Up @@ -3354,7 +3354,7 @@ dump_block_stats(spa_t *spa)

zcb.zcb_totalasize = metaslab_class_get_alloc(spa_normal_class(spa));
zcb.zcb_start = zcb.zcb_lastprint = gethrtime();
zcb.zcb_haderrors |= traverse_pool(spa, 0, flags, zdb_blkptr_cb, &zcb);
err = traverse_pool(spa, 0, flags, zdb_blkptr_cb, &zcb);

/*
* If we've traversed the data blocks then we need to wait for those
Expand All @@ -3370,6 +3370,12 @@ dump_block_stats(spa_t *spa)
}
}

/*
* Done after zio_wait() since zcb_haderrors is modified in
* zdb_blkptr_done()
*/
zcb.zcb_haderrors |= err;

if (zcb.zcb_haderrors) {
(void) printf("\nError counts:\n\n");
(void) printf("\t%5s %s\n", "errno", "count");
Expand Down

0 comments on commit ffcef3f

Please sign in to comment.