mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
daemon: Convert do_set_uuid_random to table-driven dispatch
Signed-off-by: Susant Sahani <ssahani@redhat.com>
This commit is contained in:
@@ -92,8 +92,6 @@ do_set_uuid (const char *device, const char *uuid)
|
||||
int
|
||||
do_set_uuid_random (const char *device)
|
||||
{
|
||||
int r;
|
||||
|
||||
/* How we set the UUID depends on the filesystem type. */
|
||||
CLEANUP_FREE char *vfs_type = get_blkid_tag (device, "TYPE");
|
||||
if (vfs_type == NULL)
|
||||
@@ -103,20 +101,30 @@ do_set_uuid_random (const char *device)
|
||||
if (uuid_random == NULL)
|
||||
return -1;
|
||||
|
||||
/* Fast path: ext2/3/4 family */
|
||||
if (fstype_is_extfs (vfs_type))
|
||||
r = ext_set_uuid_random (device);
|
||||
return ext_set_uuid_random (device);
|
||||
|
||||
else if (STREQ (vfs_type, "xfs"))
|
||||
r = xfs_set_uuid_random (device);
|
||||
static const struct {
|
||||
const char *fs_name;
|
||||
int (*setter)(const char *device); /* most take device only */
|
||||
} handlers[] = {
|
||||
{ "xfs", xfs_set_uuid_random },
|
||||
{ "btrfs", btrfs_set_uuid_random },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
else if (STREQ (vfs_type, "swap"))
|
||||
r = swap_set_uuid (device, uuid_random);
|
||||
/* Special case: swap uses the generated UUID string */
|
||||
if (STREQ (vfs_type, "swap"))
|
||||
return swap_set_uuid (device, uuid_random);
|
||||
|
||||
else if (STREQ (vfs_type, "btrfs"))
|
||||
r = btrfs_set_uuid_random (device);
|
||||
/* Table lookup for the rest */
|
||||
for (size_t i = 0; handlers[i].fs_name; ++i) {
|
||||
if (STREQ (vfs_type, handlers[i].fs_name))
|
||||
return handlers[i].setter (device);
|
||||
}
|
||||
|
||||
else
|
||||
NOT_SUPPORTED (-1, "don't know how to set the random UUID for '%s' filesystems",
|
||||
vfs_type);
|
||||
return r;
|
||||
NOT_SUPPORTED (-1,
|
||||
"don't know how to set random UUID for '%s' filesystems",
|
||||
vfs_type);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user