Skip to content

Commit

Permalink
Create unique partition labels
Browse files Browse the repository at this point in the history
When partitioning a device a name may be specified for each partion.
Internally zfs doesn't use this partition name for anything so it
has always just been set to "zfs".

However this isn't optimal because udev will create symlinks using
this name in /dev/disk/by-partlabel/.  If the name isn't unique
then all the links cannot be created.

Therefore a random 64-bit value has been added to the partition
label, i.e "zfs-1234567890abcdef".  Additional information could
be encoded here since partitions may be reused that could result
in confusion and was decided against.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Issue #4517
  • Loading branch information
behlendorf committed Apr 13, 2016
1 parent edd770e commit fea901b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions cmd/zpool/zpool_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6055,6 +6055,7 @@ main(int argc, char **argv)

(void) setlocale(LC_ALL, "");
(void) textdomain(TEXT_DOMAIN);
srand(time(NULL));

dprintf_setup(&argc, argv);

Expand Down
25 changes: 24 additions & 1 deletion lib/libzfs/libzfs_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -4170,6 +4170,23 @@ zpool_label_disk_check(char *path)
return (0);
}

static void
zpool_label_name(char *label_name, int label_size)
{
uint64_t id = 0;
int fd;

fd = open("/dev/urandom", O_RDONLY);
if (fd > 0) {
read(fd, &id, sizeof (id));
close(fd);
} else {
id = (((uint64_t)rand()) << 32) | (uint64_t)rand();
}

sprintf(label_name, "zfs-%016llx", (u_longlong_t) id);
}

/*
* Label an individual disk. The name provided is the short name,
* stripped of any leading /dev path.
Expand Down Expand Up @@ -4260,7 +4277,13 @@ zpool_label_disk(libzfs_handle_t *hdl, zpool_handle_t *zhp, char *name)
* can get, in the absence of V_OTHER.
*/
vtoc->efi_parts[0].p_tag = V_USR;
(void) strcpy(vtoc->efi_parts[0].p_name, "zfs");

/*
* Partions must have unique names so udev will be able to create
* symlinks under /dev/disk/by-partlabel/ for all pool devices.
* The partition names are of the form <pool>-<unique-id>.
*/
zpool_label_name(vtoc->efi_parts[0].p_name, EFI_PART_NAME_LEN);

vtoc->efi_parts[8].p_start = slice_size + start_block;
vtoc->efi_parts[8].p_size = resv;
Expand Down

0 comments on commit fea901b

Please sign in to comment.