提交 09831239 编写于 作者: E Eric Blake

qemu: simplify PCI configfd handling in monitor

This is also a bug fix - on the error path, qemu_hotplug would
leave the configfd file leaked into qemu.  At least the next
attempt to hotplug a PCI device would reuse the same fdname,
and when the qemu getfd monitor command gets a new fd by the
same name as an earlier one, it closes the earlier one, so there
is no risk of qemu running out of fds.

* src/qemu/qemu_monitor.h (qemuMonitorAddDeviceWithFd): New
prototype.
* src/qemu/qemu_monitor.c (qemuMonitorAddDevice): Move guts...
(qemuMonitorAddDeviceWithFd): ...to new function, and add support
for fd passing.
* src/qemu/qemu_hotplug.c (qemuDomainAttachHostPciDevice): Use it
to simplify code.
Suggested by Daniel P. Berrange.
上级 058d4efa
...@@ -820,14 +820,6 @@ int qemuDomainAttachHostPciDevice(struct qemud_driver *driver, ...@@ -820,14 +820,6 @@ int qemuDomainAttachHostPciDevice(struct qemud_driver *driver,
virReportOOMError(); virReportOOMError();
goto error; goto error;
} }
qemuDomainObjEnterMonitorWithDriver(driver, vm);
if (qemuMonitorSendFileHandle(priv->mon, configfd_name,
configfd) < 0) {
qemuDomainObjExitMonitorWithDriver(driver, vm);
goto error;
}
qemuDomainObjExitMonitorWithDriver(driver, vm);
} }
} }
...@@ -842,7 +834,8 @@ int qemuDomainAttachHostPciDevice(struct qemud_driver *driver, ...@@ -842,7 +834,8 @@ int qemuDomainAttachHostPciDevice(struct qemud_driver *driver,
goto error; goto error;
qemuDomainObjEnterMonitorWithDriver(driver, vm); qemuDomainObjEnterMonitorWithDriver(driver, vm);
ret = qemuMonitorAddDevice(priv->mon, devstr); ret = qemuMonitorAddDeviceWithFd(priv->mon, devstr,
configfd, configfd_name);
qemuDomainObjExitMonitorWithDriver(driver, vm); qemuDomainObjExitMonitorWithDriver(driver, vm);
} else { } else {
virDomainDevicePCIAddress guestAddr; virDomainDevicePCIAddress guestAddr;
......
...@@ -2030,10 +2030,13 @@ int qemuMonitorDelDevice(qemuMonitorPtr mon, ...@@ -2030,10 +2030,13 @@ int qemuMonitorDelDevice(qemuMonitorPtr mon,
} }
int qemuMonitorAddDevice(qemuMonitorPtr mon, int qemuMonitorAddDeviceWithFd(qemuMonitorPtr mon,
const char *devicestr) const char *devicestr,
int fd,
const char *fdname)
{ {
VIR_DEBUG("mon=%p device=%s", mon, devicestr); VIR_DEBUG("mon=%p device=%s fd=%d fdname=%s", mon, devicestr, fd,
NULLSTR(fdname));
int ret; int ret;
if (!mon) { if (!mon) {
...@@ -2042,13 +2045,28 @@ int qemuMonitorAddDevice(qemuMonitorPtr mon, ...@@ -2042,13 +2045,28 @@ int qemuMonitorAddDevice(qemuMonitorPtr mon,
return -1; return -1;
} }
if (fd >= 0 && qemuMonitorSendFileHandle(mon, fdname, fd) < 0)
return -1;
if (mon->json) if (mon->json)
ret = qemuMonitorJSONAddDevice(mon, devicestr); ret = qemuMonitorJSONAddDevice(mon, devicestr);
else else
ret = qemuMonitorTextAddDevice(mon, devicestr); ret = qemuMonitorTextAddDevice(mon, devicestr);
if (ret < 0 && fd >= 0) {
if (qemuMonitorCloseFileHandle(mon, fdname) < 0)
VIR_WARN("failed to close device handle '%s'", fdname);
}
return ret; return ret;
} }
int qemuMonitorAddDevice(qemuMonitorPtr mon,
const char *devicestr)
{
return qemuMonitorAddDeviceWithFd(mon, devicestr, -1, NULL);
}
int qemuMonitorAddDrive(qemuMonitorPtr mon, int qemuMonitorAddDrive(qemuMonitorPtr mon,
const char *drivestr) const char *drivestr)
{ {
......
...@@ -390,6 +390,11 @@ int qemuMonitorGetAllPCIAddresses(qemuMonitorPtr mon, ...@@ -390,6 +390,11 @@ int qemuMonitorGetAllPCIAddresses(qemuMonitorPtr mon,
int qemuMonitorAddDevice(qemuMonitorPtr mon, int qemuMonitorAddDevice(qemuMonitorPtr mon,
const char *devicestr); const char *devicestr);
int qemuMonitorAddDeviceWithFd(qemuMonitorPtr mon,
const char *devicestr,
int fd,
const char *fdname);
int qemuMonitorDelDevice(qemuMonitorPtr mon, int qemuMonitorDelDevice(qemuMonitorPtr mon,
const char *devalias); const char *devalias);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册