node_device: Rework udevKludgeStorageType()

The udevKludgeStorageType() function looks at devlink name
(/dev/XXX) and guesses the type of the (storage) device using a
series of STRPREFIX() calls. Well those can be turn into an array
and a for() loop, especially if we are about to add a new case
(in the next commit).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
Michal Privoznik 2022-01-26 14:00:13 +01:00
parent f9db6f3ab6
commit ec9e2adb96

View File

@ -890,32 +890,35 @@ udevProcessDASD(struct udev_device *device,
static int static int
udevKludgeStorageType(virNodeDeviceDef *def) udevKludgeStorageType(virNodeDeviceDef *def)
{ {
VIR_DEBUG("Could not find definitive storage type for device " size_t i;
"with sysfs path '%s', trying to guess it", const struct {
def->sysfs_path); const char *prefix;
const char *subst;
} fixups[] = {
/* virtio disk */ /* virtio disk */
if (STRPREFIX(def->caps->data.storage.block, "/dev/vd")) { { "/dev/vd", "disk" },
def->caps->data.storage.drive_type = g_strdup("disk");
VIR_DEBUG("Found storage type '%s' for device "
"with sysfs path '%s'",
def->caps->data.storage.drive_type,
def->sysfs_path);
return 0;
}
/* For Direct Access Storage Devices (DASDs) there are /* For Direct Access Storage Devices (DASDs) there are
* currently no identifiers in udev besides ID_PATH. Since * currently no identifiers in udev besides ID_PATH. Since
* ID_TYPE=disk does not exist on DASDs they fall through * ID_TYPE=disk does not exist on DASDs they fall through
* the udevProcessStorage detection logic. */ * the udevProcessStorage detection logic. */
if (STRPREFIX(def->caps->data.storage.block, "/dev/dasd")) { { "/dev/dasd", "dasd" },
def->caps->data.storage.drive_type = g_strdup("dasd"); };
VIR_DEBUG("Found storage type '%s' for device "
"with sysfs path '%s'", VIR_DEBUG("Could not find definitive storage type for device "
"with sysfs path '%s', trying to guess it",
def->sysfs_path);
for (i = 0; i < G_N_ELEMENTS(fixups); i++) {
if (STRPREFIX(def->caps->data.storage.block, fixups[i].prefix)) {
def->caps->data.storage.drive_type = g_strdup(fixups[i].subst);
VIR_DEBUG("Found storage type '%s' for device with sysfs path '%s'",
def->caps->data.storage.drive_type, def->caps->data.storage.drive_type,
def->sysfs_path); def->sysfs_path);
return 0; return 0;
} }
}
VIR_DEBUG("Could not determine storage type " VIR_DEBUG("Could not determine storage type "
"for device with sysfs path '%s'", def->sysfs_path); "for device with sysfs path '%s'", def->sysfs_path);
return -1; return -1;