diff options
author | alex <[email protected]> | 2020-04-25 10:04:34 +0800 |
---|---|---|
committer | GitHub <[email protected]> | 2020-04-24 19:04:34 -0700 |
commit | 47c9299fcc9e5fb91d0b1636bfacc03bd3e98439 (patch) | |
tree | 77fe869258d5884888eb1e10ce6acc82fd99ab89 /cmd | |
parent | aa646323dbb61a2c3224b03c17732bd19fc50758 (diff) |
zfs_create: round up volume size to multiple of bs
Round up the volume size requested in `zfs create -V size` to the next
higher multiple of the volblocksize. Updates the man page and adds a
test to verify the new behavior.
Reviewed-by: Brian Behlendorf <[email protected]>
Reported-by: puffi <[email protected]>
Signed-off-by: Alex John <[email protected]>
Closes #8541
Closes #10196
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/zfs/zfs_main.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/cmd/zfs/zfs_main.c b/cmd/zfs/zfs_main.c index 15e350313..27f34b9fd 100644 --- a/cmd/zfs/zfs_main.c +++ b/cmd/zfs/zfs_main.c @@ -1038,6 +1038,31 @@ zfs_do_create(int argc, char **argv) } } + /* + * if volsize is not a multiple of volblocksize, round it up to the + * nearest multiple of the volblocksize + */ + if (type == ZFS_TYPE_VOLUME) { + uint64_t volblocksize; + + if (nvlist_lookup_uint64(props, + zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE), + &volblocksize) != 0) + volblocksize = ZVOL_DEFAULT_BLOCKSIZE; + + if (volsize % volblocksize) { + volsize = P2ROUNDUP_TYPED(volsize, volblocksize, + uint64_t); + + if (nvlist_add_uint64(props, + zfs_prop_to_name(ZFS_PROP_VOLSIZE), volsize) != 0) { + nvlist_free(props); + nomem(); + } + } + } + + if (type == ZFS_TYPE_VOLUME && !noreserve) { uint64_t spa_version; zfs_prop_t resv_prop; |