diff options
author | Brian Behlendorf <behlendorf1@llnl.gov> | 2024-02-16 17:07:32 +0000 |
---|---|---|
committer | Tony Hutter <hutter2@llnl.gov> | 2024-04-29 20:50:05 +0000 |
commit | 9f1d3db73035665b51270925d24974d9e34e3cb3 (patch) | |
tree | 6884a87388f1634121cb28fdb146df50d389a5a8 | |
parent | 5dda8c09102606449bffc42c3013a0500cf02578 (diff) | |
download | src-9f1d3db73035665b51270925d24974d9e34e3cb3.tar.gz src-9f1d3db73035665b51270925d24974d9e34e3cb3.zip |
Check for minimum partition size
On Linux block devices used for vdevs will by partitioned. The block
device must be large enough for an 64M partition starting at offset
of 2048 sectors (part1), and a second 64M reserved partition at the
end of the device (part9).
This commit adds a capacity check when creating the GPT label to
immediately detect a device which is too small. With the existing
code this would be caught slightly latter when attempting to use
the partition. Catching it sooner let's us print a more useful error.
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #15898
-rw-r--r-- | lib/libzfs/os/linux/libzfs_pool_os.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/libzfs/os/linux/libzfs_pool_os.c b/lib/libzfs/os/linux/libzfs_pool_os.c index 401151b1afb5..86eef3255bc2 100644 --- a/lib/libzfs/os/linux/libzfs_pool_os.c +++ b/lib/libzfs/os/linux/libzfs_pool_os.c @@ -273,6 +273,16 @@ zpool_label_disk(libzfs_handle_t *hdl, zpool_handle_t *zhp, const char *name) vtoc->efi_parts[0].p_start = start_block; vtoc->efi_parts[0].p_size = slice_size; + if (vtoc->efi_parts[0].p_size * vtoc->efi_lbasize < SPA_MINDEVSIZE) { + (void) close(fd); + efi_free(vtoc); + + zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "cannot " + "label '%s': partition would be less than the minimum " + "device size (64M)"), path); + return (zfs_error(hdl, EZFS_LABELFAILED, errbuf)); + } + /* * Why we use V_USR: V_BACKUP confuses users, and is considered * disposable by some EFI utilities (since EFI doesn't have a backup |