提交 876a5da0 编写于 作者: J Ján Tomko

Rewrite usage of StrToLong_ui in udevProcess{PCI,SCSI}

Use virStrToLong_ui instead of udevStrToLong_ui, reformat the code
and report a more specific error message.
上级 3775a2e1
...@@ -429,33 +429,14 @@ static int udevProcessPCI(struct udev_device *device, ...@@ -429,33 +429,14 @@ static int udevProcessPCI(struct udev_device *device,
goto out; goto out;
} }
p = strrchr(syspath, '/'); if ((p = strrchr(syspath, '/')) == NULL ||
virStrToLong_ui(p + 1, &p, 16, &data->pci_dev.domain) < 0 || p == NULL ||
if ((p == NULL) || (udevStrToLong_ui(p+1, virStrToLong_ui(p + 1, &p, 16, &data->pci_dev.bus) < 0 || p == NULL ||
&p, virStrToLong_ui(p + 1, &p, 16, &data->pci_dev.slot) < 0 || p == NULL ||
16, virStrToLong_ui(p + 1, &p, 16, &data->pci_dev.function) < 0) {
&data->pci_dev.domain) == -1)) { virReportError(VIR_ERR_INTERNAL_ERROR,
goto out; _("failed to parse the PCI address from sysfs path: '%s'"),
} syspath);
if ((p == NULL) || (udevStrToLong_ui(p+1,
&p,
16,
&data->pci_dev.bus) == -1)) {
goto out;
}
if ((p == NULL) || (udevStrToLong_ui(p+1,
&p,
16,
&data->pci_dev.slot) == -1)) {
goto out;
}
if ((p == NULL) || (udevStrToLong_ui(p+1,
&p,
16,
&data->pci_dev.function) == -1)) {
goto out; goto out;
} }
...@@ -716,16 +697,11 @@ static int udevProcessSCSIHost(struct udev_device *device ATTRIBUTE_UNUSED, ...@@ -716,16 +697,11 @@ static int udevProcessSCSIHost(struct udev_device *device ATTRIBUTE_UNUSED,
filename = last_component(def->sysfs_path); filename = last_component(def->sysfs_path);
if (!(str = STRSKIP(filename, "host"))) { if (!(str = STRSKIP(filename, "host")) ||
VIR_ERROR(_("SCSI host found, but its udev name '%s' does " virStrToLong_ui(str, NULL, 0, &data->scsi_host.host) < 0) {
"not begin with 'host'"), filename); virReportError(VIR_ERR_INTERNAL_ERROR,
goto out; _("failed to parse SCSI host '%s'"),
} filename);
if (udevStrToLong_ui(str,
NULL,
0,
&data->scsi_host.host) == -1) {
goto out; goto out;
} }
...@@ -831,28 +807,14 @@ static int udevProcessSCSIDevice(struct udev_device *device ATTRIBUTE_UNUSED, ...@@ -831,28 +807,14 @@ static int udevProcessSCSIDevice(struct udev_device *device ATTRIBUTE_UNUSED,
filename = last_component(def->sysfs_path); filename = last_component(def->sysfs_path);
if (udevStrToLong_ui(filename, &p, 10, &data->scsi.host) == -1) if (virStrToLong_ui(filename, &p, 10, &data->scsi.host) < 0 || p == NULL ||
goto out; virStrToLong_ui(p + 1, &p, 10, &data->scsi.bus) < 0 || p == NULL ||
virStrToLong_ui(p + 1, &p, 10, &data->scsi.target) < 0 || p == NULL ||
if ((p == NULL) || (udevStrToLong_ui(p+1, virStrToLong_ui(p + 1, &p, 10, &data->scsi.lun) < 0) {
&p, virReportError(VIR_ERR_INTERNAL_ERROR,
10, _("failed to parse the SCSI address from filename: '%s'"),
&data->scsi.bus) == -1)) { filename);
goto out; return -1;
}
if ((p == NULL) || (udevStrToLong_ui(p+1,
&p,
10,
&data->scsi.target) == -1)) {
goto out;
}
if ((p == NULL) || (udevStrToLong_ui(p+1,
&p,
10,
&data->scsi.lun) == -1)) {
goto out;
} }
switch (udevGetUintSysfsAttr(device, "type", &tmp, 0)) { switch (udevGetUintSysfsAttr(device, "type", &tmp, 0)) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册