Skip to content

Commit

Permalink
Check for minimum partition size
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Brian Behlendorf <[email protected]>
Closes #15898
behlendorf authored Feb 16, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent d6a3d3f commit af4da5c
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/libzfs/os/linux/libzfs_pool_os.c
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit af4da5c

Please sign in to comment.