1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-12 09:17:44 +03:00

v3: Properly parsing SCSI Hyperv devices (#8509)

Since 2016, Hyperv devices moved to using standard way to expose UUID to sysfs. Fix the parsing function to work with the newer format.

Change log:
v2: changed code to work with both old and new path format
v3: changed guid_str_len type to size_t, fixed length in char guid[] in handle_scsi_hyperv()
This commit is contained in:
Long Li 2018-03-21 03:51:28 -07:00 committed by Lennart Poettering
parent ed1738a24a
commit cf3fabacaa

View File

@ -397,16 +397,17 @@ static struct udev_device *handle_scsi_default(struct udev_device *parent, char
return hostdev;
}
static struct udev_device *handle_scsi_hyperv(struct udev_device *parent, char **path) {
static struct udev_device *handle_scsi_hyperv(struct udev_device *parent, char **path, size_t guid_str_len) {
struct udev_device *hostdev;
struct udev_device *vmbusdev;
const char *guid_str;
_cleanup_free_ char *lun = NULL;
char guid[38];
char guid[39];
size_t i, k;
assert(parent);
assert(path);
assert(guid_str_len < sizeof(guid));
hostdev = udev_device_get_parent_with_subsystem_devtype(parent, "scsi", "scsi_host");
if (!hostdev)
@ -420,10 +421,10 @@ static struct udev_device *handle_scsi_hyperv(struct udev_device *parent, char *
if (!guid_str)
return NULL;
if (strlen(guid_str) < 37 || guid_str[0] != '{' || guid_str[36] != '}')
if (strlen(guid_str) < guid_str_len || guid_str[0] != '{' || guid_str[guid_str_len-1] != '}')
return NULL;
for (i = 1, k = 0; i < 36; i++) {
for (i = 1, k = 0; i < guid_str_len-1; i++) {
if (guid_str[i] == '-')
continue;
guid[k++] = guid_str[i];
@ -472,7 +473,9 @@ static struct udev_device *handle_scsi(struct udev_device *parent, char **path,
return handle_scsi_ata(parent, path);
if (strstr(name, "/vmbus_"))
return handle_scsi_hyperv(parent, path);
return handle_scsi_hyperv(parent, path, 37);
else if (strstr(name, "/VMBUS"))
return handle_scsi_hyperv(parent, path, 38);
return handle_scsi_default(parent, path);
}