mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
Rewrite disk type checking in udevProcessStorage
Error out on parsing errors and use a local const char pointer instead of chained ifs to check whether we found a match.
This commit is contained in:
parent
4ccf6886c8
commit
71cddab042
@ -1019,30 +1019,34 @@ static int udevProcessStorage(struct udev_device *device,
|
|||||||
"ID_TYPE",
|
"ID_TYPE",
|
||||||
&data->storage.drive_type) != PROPERTY_FOUND ||
|
&data->storage.drive_type) != PROPERTY_FOUND ||
|
||||||
STREQ(def->caps->data.storage.drive_type, "generic")) {
|
STREQ(def->caps->data.storage.drive_type, "generic")) {
|
||||||
int tmp_int = 0;
|
int val = 0;
|
||||||
|
const char *str = NULL;
|
||||||
|
|
||||||
/* All floppy drives have the ID_DRIVE_FLOPPY prop. This is
|
/* All floppy drives have the ID_DRIVE_FLOPPY prop. This is
|
||||||
* needed since legacy floppies don't have a drive_type */
|
* needed since legacy floppies don't have a drive_type */
|
||||||
if (udevGetIntProperty(device, "ID_DRIVE_FLOPPY",
|
if (udevGetIntProperty(device, "ID_DRIVE_FLOPPY", &val, 0) == PROPERTY_ERROR)
|
||||||
&tmp_int, 0) == PROPERTY_FOUND &&
|
|
||||||
tmp_int == 1) {
|
|
||||||
|
|
||||||
if (VIR_STRDUP(data->storage.drive_type, "floppy") < 0)
|
|
||||||
goto out;
|
goto out;
|
||||||
} else if (udevGetIntProperty(device, "ID_CDROM",
|
else if (val == 1)
|
||||||
&tmp_int, 0) == PROPERTY_FOUND &&
|
str = "floppy";
|
||||||
tmp_int == 1) {
|
|
||||||
|
|
||||||
if (VIR_STRDUP(data->storage.drive_type, "cd") < 0)
|
if (!str) {
|
||||||
|
if (udevGetIntProperty(device, "ID_CDROM", &val, 0) == PROPERTY_ERROR)
|
||||||
goto out;
|
goto out;
|
||||||
} else if (udevGetIntProperty(device, "ID_DRIVE_FLASH_SD",
|
else if (val == 1)
|
||||||
&tmp_int, 0) == PROPERTY_FOUND &&
|
str = "cd";
|
||||||
tmp_int == 1) {
|
}
|
||||||
|
|
||||||
if (VIR_STRDUP(data->storage.drive_type, "sd") < 0)
|
if (!str) {
|
||||||
|
if (udevGetIntProperty(device, "ID_DRIVE_FLASH_SD", &val, 0) == PROPERTY_ERROR)
|
||||||
|
goto out;
|
||||||
|
if (val == 1)
|
||||||
|
str = "sd";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (str) {
|
||||||
|
if (VIR_STRDUP(data->storage.drive_type, str) < 0)
|
||||||
goto out;
|
goto out;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
/* If udev doesn't have it, perhaps we can guess it. */
|
/* If udev doesn't have it, perhaps we can guess it. */
|
||||||
if (udevKludgeStorageType(def) != 0)
|
if (udevKludgeStorageType(def) != 0)
|
||||||
goto out;
|
goto out;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user