Skip to content

Commit

Permalink
Use a helper function to clarify gang block size
Browse files Browse the repository at this point in the history
For gang blocks, `DVA_GET_ASIZE()` is the total space allocated for the
gang DVA including its children BP's.  The space allocated at each DVA's
vdev/offset is `vdev_psize_to_asize(vd, SPA_GANGBLOCKSIZE)`.

This commit makes this relationship more clear by using a helper
function, `vdev_gang_header_asize()`, for the space allocated at the
gang block's vdev/offset.

Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Matthew Ahrens <[email protected]>
Closes openzfs#11744
  • Loading branch information
ahrens authored and Ryan Moeller committed May 10, 2021
1 parent edd5cd9 commit f2af4a3
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
6 changes: 6 additions & 0 deletions include/sys/spa.h
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,12 @@ typedef struct blkptr {
/*
* Macros to get and set fields in a bp or DVA.
*/

/*
* Note, for gang blocks, DVA_GET_ASIZE() is the total space allocated for
* this gang DVA including its children BP's. The space allocated at this
* DVA's vdev/offset is vdev_gang_header_asize(vdev).
*/
#define DVA_GET_ASIZE(dva) \
BF64_GET_SB((dva)->dva_word[0], 0, SPA_ASIZEBITS, SPA_MINBLOCKSHIFT, 0)
#define DVA_SET_ASIZE(dva, x) \
Expand Down
9 changes: 9 additions & 0 deletions include/sys/vdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ extern int64_t vdev_deflated_space(vdev_t *vd, int64_t space);

extern uint64_t vdev_psize_to_asize(vdev_t *vd, uint64_t psize);

/*
* Return the amount of space allocated for a gang block header.
*/
static inline uint64_t
vdev_gang_header_asize(vdev_t *vd)
{
return (vdev_psize_to_asize(vd, SPA_GANGBLOCKSIZE));
}

extern int vdev_fault(spa_t *spa, uint64_t guid, vdev_aux_t aux);
extern int vdev_degrade(spa_t *spa, uint64_t guid, vdev_aux_t aux);
extern int vdev_online(spa_t *spa, uint64_t guid, uint64_t flags,
Expand Down
8 changes: 4 additions & 4 deletions module/zfs/metaslab.c
Original file line number Diff line number Diff line change
Expand Up @@ -5536,7 +5536,7 @@ metaslab_unalloc_dva(spa_t *spa, const dva_t *dva, uint64_t txg)
ASSERT3P(vd->vdev_indirect_mapping, ==, NULL);

if (DVA_GET_GANG(dva))
size = vdev_psize_to_asize(vd, SPA_GANGBLOCKSIZE);
size = vdev_gang_header_asize(vd);

msp = vd->vdev_ms[offset >> vd->vdev_ms_shift];

Expand Down Expand Up @@ -5571,7 +5571,7 @@ metaslab_free_dva(spa_t *spa, const dva_t *dva, boolean_t checkpoint)
ASSERT3U(spa_config_held(spa, SCL_ALL, RW_READER), !=, 0);

if (DVA_GET_GANG(dva)) {
size = vdev_psize_to_asize(vd, SPA_GANGBLOCKSIZE);
size = vdev_gang_header_asize(vd);
}

metaslab_free_impl(vd, offset, size, checkpoint);
Expand Down Expand Up @@ -5763,7 +5763,7 @@ metaslab_claim_dva(spa_t *spa, const dva_t *dva, uint64_t txg)
ASSERT(DVA_IS_VALID(dva));

if (DVA_GET_GANG(dva))
size = vdev_psize_to_asize(vd, SPA_GANGBLOCKSIZE);
size = vdev_gang_header_asize(vd);

return (metaslab_claim_impl(vd, offset, size, txg));
}
Expand Down Expand Up @@ -6029,7 +6029,7 @@ metaslab_check_free(spa_t *spa, const blkptr_t *bp)
uint64_t size = DVA_GET_ASIZE(&bp->blk_dva[i]);

if (DVA_GET_GANG(&bp->blk_dva[i]))
size = vdev_psize_to_asize(vd, SPA_GANGBLOCKSIZE);
size = vdev_gang_header_asize(vd);

ASSERT3P(vd, !=, NULL);

Expand Down
18 changes: 11 additions & 7 deletions module/zfs/zio.c
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,8 @@ zfs_blkptr_verify(spa_t *spa, const blkptr_t *bp, boolean_t config_held,
* that are in the log) to be arbitrarily large.
*/
for (int i = 0; i < BP_GET_NDVAS(bp); i++) {
uint64_t vdevid = DVA_GET_VDEV(&bp->blk_dva[i]);
const dva_t *dva = &bp->blk_dva[i];
uint64_t vdevid = DVA_GET_VDEV(dva);

if (vdevid >= spa->spa_root_vdev->vdev_children) {
errors += zfs_blkptr_verify_log(spa, bp, blk_verify,
Expand Down Expand Up @@ -1024,10 +1025,10 @@ zfs_blkptr_verify(spa_t *spa, const blkptr_t *bp, boolean_t config_held,
*/
continue;
}
uint64_t offset = DVA_GET_OFFSET(&bp->blk_dva[i]);
uint64_t asize = DVA_GET_ASIZE(&bp->blk_dva[i]);
if (BP_IS_GANG(bp))
asize = vdev_psize_to_asize(vd, SPA_GANGBLOCKSIZE);
uint64_t offset = DVA_GET_OFFSET(dva);
uint64_t asize = DVA_GET_ASIZE(dva);
if (DVA_GET_GANG(dva))
asize = vdev_gang_header_asize(vd);
if (offset + asize > vd->vdev_asize) {
errors += zfs_blkptr_verify_log(spa, bp, blk_verify,
"blkptr at %p DVA %u has invalid OFFSET %llu",
Expand Down Expand Up @@ -1064,8 +1065,8 @@ zfs_dva_valid(spa_t *spa, const dva_t *dva, const blkptr_t *bp)
uint64_t offset = DVA_GET_OFFSET(dva);
uint64_t asize = DVA_GET_ASIZE(dva);

if (BP_IS_GANG(bp))
asize = vdev_psize_to_asize(vd, SPA_GANGBLOCKSIZE);
if (DVA_GET_GANG(dva))
asize = vdev_gang_header_asize(vd);
if (offset + asize > vd->vdev_asize)
return (B_FALSE);

Expand Down Expand Up @@ -3944,6 +3945,9 @@ zio_vdev_io_assess(zio_t *zio)
*/
if (zio->io_error == ENXIO && zio->io_type == ZIO_TYPE_WRITE &&
vd != NULL && !vd->vdev_ops->vdev_op_leaf) {
vdev_dbgmsg(vd, "zio_vdev_io_assess(zio=%px) setting "
"cant_write=TRUE due to write failure with ENXIO",
zio);
vd->vdev_cant_write = B_TRUE;
}

Expand Down

0 comments on commit f2af4a3

Please sign in to comment.