mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-04-26 15:14:42 +00:00
Add API for issuing 'getfd' and 'closefd' monitor commands
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Add new qemuMonitorCloseFileHandle and qemuMonitorSendFileHandle APIs for processing file handles * src/qemu/qemu_driver.c: Convert NIC hotplug method over to use qemuMonitorCloseFileHandle and qemuMonitorSendFileHandle
This commit is contained in:
parent
85df93399c
commit
aadab51541
@ -4619,7 +4619,7 @@ static int qemudDomainAttachNetDevice(virConnectPtr conn,
|
|||||||
{
|
{
|
||||||
virDomainNetDefPtr net = dev->data.net;
|
virDomainNetDefPtr net = dev->data.net;
|
||||||
char *cmd = NULL, *reply = NULL, *remove_cmd = NULL;
|
char *cmd = NULL, *reply = NULL, *remove_cmd = NULL;
|
||||||
char *tapfd_name = NULL, *tapfd_close = NULL;
|
char *tapfd_name = NULL;
|
||||||
int i, tapfd = -1;
|
int i, tapfd = -1;
|
||||||
unsigned domain, bus, slot;
|
unsigned domain, bus, slot;
|
||||||
|
|
||||||
@ -4662,32 +4662,8 @@ static int qemudDomainAttachNetDevice(virConnectPtr conn,
|
|||||||
if (virAsprintf(&tapfd_name, "fd-%s", net->hostnet_name) < 0)
|
if (virAsprintf(&tapfd_name, "fd-%s", net->hostnet_name) < 0)
|
||||||
goto no_memory;
|
goto no_memory;
|
||||||
|
|
||||||
if (virAsprintf(&tapfd_close, "closefd %s", tapfd_name) < 0)
|
if (qemuMonitorSendFileHandle(vm, tapfd_name, tapfd) < 0)
|
||||||
goto no_memory;
|
|
||||||
|
|
||||||
if (virAsprintf(&cmd, "getfd %s", tapfd_name) < 0)
|
|
||||||
goto no_memory;
|
|
||||||
|
|
||||||
if (qemudMonitorCommandWithFd(vm, cmd, tapfd, &reply) < 0) {
|
|
||||||
qemudReportError(conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
|
|
||||||
_("failed to pass fd to qemu with '%s'"), cmd);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
DEBUG("%s: getfd reply: %s", vm->def->name, reply);
|
|
||||||
|
|
||||||
/* If the command isn't supported then qemu prints:
|
|
||||||
* unknown command: getfd" */
|
|
||||||
if (strstr(reply, "unknown command:")) {
|
|
||||||
qemudReportError(conn, dom, NULL, VIR_ERR_NO_SUPPORT,
|
|
||||||
"%s",
|
|
||||||
_("bridge/network interface attach not supported: "
|
|
||||||
"qemu 'getfd' monitor command not available"));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
VIR_FREE(reply);
|
|
||||||
VIR_FREE(cmd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qemuBuildHostNetStr(conn, net, "host_net_add ", ' ',
|
if (qemuBuildHostNetStr(conn, net, "host_net_add ", ' ',
|
||||||
@ -4713,7 +4689,6 @@ static int qemudDomainAttachNetDevice(virConnectPtr conn,
|
|||||||
VIR_FREE(reply);
|
VIR_FREE(reply);
|
||||||
VIR_FREE(cmd);
|
VIR_FREE(cmd);
|
||||||
VIR_FREE(tapfd_name);
|
VIR_FREE(tapfd_name);
|
||||||
VIR_FREE(tapfd_close);
|
|
||||||
if (tapfd != -1)
|
if (tapfd != -1)
|
||||||
close(tapfd);
|
close(tapfd);
|
||||||
tapfd = -1;
|
tapfd = -1;
|
||||||
@ -4760,12 +4735,10 @@ try_remove:
|
|||||||
try_tapfd_close:
|
try_tapfd_close:
|
||||||
VIR_FREE(reply);
|
VIR_FREE(reply);
|
||||||
|
|
||||||
if (tapfd_close) {
|
if (tapfd_name &&
|
||||||
if (qemudMonitorCommand(vm, tapfd_close, &reply) < 0)
|
qemuMonitorCloseFileHandle(vm, tapfd_name) < 0)
|
||||||
VIR_WARN(_("Failed to close tapfd with '%s'\n"), tapfd_close);
|
VIR_WARN(_("Failed to close tapfd with '%s'\n"), tapfd_name);
|
||||||
else
|
|
||||||
VIR_DEBUG("%s: closefd: %s\n", vm->def->name, reply);
|
|
||||||
}
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
no_memory:
|
no_memory:
|
||||||
@ -4774,7 +4747,6 @@ cleanup:
|
|||||||
VIR_FREE(cmd);
|
VIR_FREE(cmd);
|
||||||
VIR_FREE(reply);
|
VIR_FREE(reply);
|
||||||
VIR_FREE(remove_cmd);
|
VIR_FREE(remove_cmd);
|
||||||
VIR_FREE(tapfd_close);
|
|
||||||
VIR_FREE(tapfd_name);
|
VIR_FREE(tapfd_name);
|
||||||
if (tapfd != -1)
|
if (tapfd != -1)
|
||||||
close(tapfd);
|
close(tapfd);
|
||||||
|
@ -1552,3 +1552,81 @@ cleanup:
|
|||||||
VIR_FREE(reply);
|
VIR_FREE(reply);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int qemuMonitorSendFileHandle(const virDomainObjPtr vm,
|
||||||
|
const char *fdname,
|
||||||
|
int fd)
|
||||||
|
{
|
||||||
|
char *cmd;
|
||||||
|
char *reply = NULL;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
if (virAsprintf(&cmd, "getfd %s", fdname) < 0) {
|
||||||
|
virReportOOMError(NULL);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (qemudMonitorCommandWithFd(vm, cmd, fd, &reply) < 0) {
|
||||||
|
qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED,
|
||||||
|
_("failed to pass fd to qemu with '%s'"), cmd);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
DEBUG("%s: getfd reply: %s", vm->def->name, reply);
|
||||||
|
|
||||||
|
/* If the command isn't supported then qemu prints:
|
||||||
|
* unknown command: getfd" */
|
||||||
|
if (strstr(reply, "unknown command:")) {
|
||||||
|
qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_SUPPORT,
|
||||||
|
_("qemu does not support sending of file handles: %s"),
|
||||||
|
reply);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
VIR_FREE(cmd);
|
||||||
|
VIR_FREE(reply);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int qemuMonitorCloseFileHandle(const virDomainObjPtr vm,
|
||||||
|
const char *fdname)
|
||||||
|
{
|
||||||
|
char *cmd;
|
||||||
|
char *reply = NULL;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
if (virAsprintf(&cmd, "closefd %s", fdname) < 0) {
|
||||||
|
virReportOOMError(NULL);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (qemudMonitorCommand(vm, cmd, &reply) < 0) {
|
||||||
|
qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED,
|
||||||
|
_("failed to close fd in qemu with '%s'"), cmd);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
DEBUG("%s: closefd reply: %s", vm->def->name, reply);
|
||||||
|
|
||||||
|
/* If the command isn't supported then qemu prints:
|
||||||
|
* unknown command: getfd" */
|
||||||
|
if (strstr(reply, "unknown command:")) {
|
||||||
|
qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_SUPPORT,
|
||||||
|
_("qemu does not support closing of file handles: %s"),
|
||||||
|
reply);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
VIR_FREE(cmd);
|
||||||
|
VIR_FREE(reply);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -176,5 +176,11 @@ int qemuMonitorRemovePCIDevice(const virDomainObjPtr vm,
|
|||||||
unsigned guestSlot);
|
unsigned guestSlot);
|
||||||
|
|
||||||
|
|
||||||
|
int qemuMonitorSendFileHandle(const virDomainObjPtr vm,
|
||||||
|
const char *fdname,
|
||||||
|
int fd);
|
||||||
|
|
||||||
|
int qemuMonitorCloseFileHandle(const virDomainObjPtr vm,
|
||||||
|
const char *fdname);
|
||||||
|
|
||||||
#endif /* QEMU_MONITOR_TEXT_H */
|
#endif /* QEMU_MONITOR_TEXT_H */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user