mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 19:32:19 +00:00
link-state: qemu: Add monitor handling for link state modification
This patch adds handlers for modification of guest's interface link state. Both HMP and QMP commands are supported, but as the link state functionality is from the beginning supported in QMP the HMP code will probably never be used.
This commit is contained in:
parent
edd1295e1d
commit
8277c15151
@ -1135,6 +1135,25 @@ int qemuMonitorGetCPUInfo(qemuMonitorPtr mon,
|
||||
return ret;
|
||||
}
|
||||
|
||||
int qemuMonitorSetLink(qemuMonitorPtr mon,
|
||||
const char *name,
|
||||
enum virDomainNetInterfaceLinkState state)
|
||||
{
|
||||
int ret;
|
||||
VIR_DEBUG("mon=%p, name=%p:%s, state=%u", mon, name, name, state);
|
||||
|
||||
if (!mon || !name) {
|
||||
qemuReportError(VIR_ERR_INVALID_ARG,
|
||||
_("monitor || name must not be NULL"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (mon->json)
|
||||
ret = qemuMonitorJSONSetLink(mon, name, state);
|
||||
else
|
||||
ret = qemuMonitorTextSetLink(mon, name, state);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int qemuMonitorGetVirtType(qemuMonitorPtr mon,
|
||||
int *virtType)
|
||||
|
@ -145,6 +145,10 @@ void qemuMonitorUnlock(qemuMonitorPtr mon);
|
||||
int qemuMonitorRef(qemuMonitorPtr mon);
|
||||
int qemuMonitorUnref(qemuMonitorPtr mon) ATTRIBUTE_RETURN_CHECK;
|
||||
|
||||
int qemuMonitorSetLink(qemuMonitorPtr mon,
|
||||
const char *name,
|
||||
enum virDomainNetInterfaceLinkState state) ;
|
||||
|
||||
/* These APIs are for use by the internal Text/JSON monitor impl code only */
|
||||
char *qemuMonitorNextCommandID(qemuMonitorPtr mon);
|
||||
int qemuMonitorSend(qemuMonitorPtr mon,
|
||||
|
@ -955,6 +955,29 @@ int qemuMonitorJSONSystemPowerdown(qemuMonitorPtr mon)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int qemuMonitorJSONSetLink(qemuMonitorPtr mon,
|
||||
const char *name,
|
||||
enum virDomainNetInterfaceLinkState state)
|
||||
{
|
||||
|
||||
int ret;
|
||||
virJSONValuePtr reply = NULL;
|
||||
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("set_link",
|
||||
"s:name", name,
|
||||
"b:up", state != VIR_DOMAIN_NET_INTERFACE_LINK_STATE_DOWN,
|
||||
NULL);
|
||||
|
||||
if (!cmd)
|
||||
return -1;
|
||||
|
||||
if ((ret = qemuMonitorJSONCommand(mon, cmd, &reply)) == 0)
|
||||
ret = qemuMonitorJSONCheckError(cmd, reply);
|
||||
|
||||
virJSONValueFree(cmd);
|
||||
virJSONValueFree(reply);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int qemuMonitorJSONSystemReset(qemuMonitorPtr mon)
|
||||
{
|
||||
|
@ -241,4 +241,8 @@ int qemuMonitorJSONBlockJob(qemuMonitorPtr mon,
|
||||
virDomainBlockJobInfoPtr info,
|
||||
int mode);
|
||||
|
||||
int qemuMonitorJSONSetLink(qemuMonitorPtr mon,
|
||||
const char *name,
|
||||
enum virDomainNetInterfaceLinkState state);
|
||||
|
||||
#endif /* QEMU_MONITOR_JSON_H */
|
||||
|
@ -433,6 +433,52 @@ int qemuMonitorTextSystemPowerdown(qemuMonitorPtr mon) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int qemuMonitorTextSetLink(qemuMonitorPtr mon, const char *name, enum virDomainNetInterfaceLinkState state) {
|
||||
char *info = NULL;
|
||||
char *cmd = NULL;
|
||||
const char *st_str = NULL;
|
||||
|
||||
/* determine state */
|
||||
if (state == VIR_DOMAIN_NET_INTERFACE_LINK_STATE_DOWN)
|
||||
st_str = "off";
|
||||
else
|
||||
st_str = "on";
|
||||
|
||||
if (virAsprintf(&cmd, "set_link %s %s", name, st_str) < 0) {
|
||||
virReportOOMError();
|
||||
goto error;
|
||||
}
|
||||
if (qemuMonitorHMPCommand(mon, cmd, &info) < 0) {
|
||||
qemuReportError(VIR_ERR_OPERATION_FAILED,
|
||||
"%s", _("set_link operation failed"));
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* check if set_link command is supported */
|
||||
if (strstr(info, "\nunknown ")) {
|
||||
qemuReportError(VIR_ERR_NO_SUPPORT,
|
||||
"%s",
|
||||
_("\'set_link\' not supported by this qemu"));
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* check if qemu didn't reject device name */
|
||||
if (strstr(info, "\nDevice ")) {
|
||||
qemuReportError(VIR_ERR_OPERATION_FAILED,
|
||||
"%s", _("device name rejected"));
|
||||
goto error;
|
||||
}
|
||||
|
||||
VIR_FREE(info);
|
||||
VIR_FREE(cmd);
|
||||
return 0;
|
||||
|
||||
error:
|
||||
VIR_FREE(info);
|
||||
VIR_FREE(cmd);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int qemuMonitorTextSystemReset(qemuMonitorPtr mon) {
|
||||
char *info;
|
||||
|
@ -234,4 +234,8 @@ int qemuMonitorTextBlockJob(qemuMonitorPtr mon,
|
||||
virDomainBlockJobInfoPtr info,
|
||||
int mode);
|
||||
|
||||
int qemuMonitorTextSetLink(qemuMonitorPtr mon,
|
||||
const char *name,
|
||||
enum virDomainNetInterfaceLinkState state);
|
||||
|
||||
#endif /* QEMU_MONITOR_TEXT_H */
|
||||
|
Loading…
x
Reference in New Issue
Block a user