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