mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-21 20:15:17 +00:00
qemu: Introduce qemuMonitorGetDeviceAliases
This API provides a NULL-terminated list of devices which are currently attached to a QEMU domain.
This commit is contained in:
parent
d327ac5328
commit
58b147ad07
@ -3818,3 +3818,24 @@ int qemuMonitorDetachCharDev(qemuMonitorPtr mon,
|
||||
|
||||
return qemuMonitorJSONDetachCharDev(mon, chrID);
|
||||
}
|
||||
|
||||
int
|
||||
qemuMonitorGetDeviceAliases(qemuMonitorPtr mon,
|
||||
char ***aliases)
|
||||
{
|
||||
VIR_DEBUG("mon=%p, aliases=%p", mon, aliases);
|
||||
|
||||
if (!mon) {
|
||||
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
||||
_("monitor must not be NULL"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!mon->json) {
|
||||
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
||||
_("JSON monitor is required"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
return qemuMonitorJSONGetDeviceAliases(mon, aliases);
|
||||
}
|
||||
|
@ -713,6 +713,10 @@ int qemuMonitorAttachCharDev(qemuMonitorPtr mon,
|
||||
virDomainChrSourceDefPtr chr);
|
||||
int qemuMonitorDetachCharDev(qemuMonitorPtr mon,
|
||||
const char *chrID);
|
||||
|
||||
int qemuMonitorGetDeviceAliases(qemuMonitorPtr mon,
|
||||
char ***aliases);
|
||||
|
||||
/**
|
||||
* When running two dd process and using <> redirection, we need a
|
||||
* shell that will not truncate files. These two strings serve that
|
||||
|
@ -5415,3 +5415,41 @@ qemuMonitorJSONDetachCharDev(qemuMonitorPtr mon,
|
||||
virJSONValueFree(reply);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
qemuMonitorJSONGetDeviceAliases(qemuMonitorPtr mon,
|
||||
char ***aliases)
|
||||
{
|
||||
qemuMonitorJSONListPathPtr *paths = NULL;
|
||||
char **alias;
|
||||
int ret = -1;
|
||||
size_t i;
|
||||
int n;
|
||||
|
||||
*aliases = NULL;
|
||||
|
||||
n = qemuMonitorJSONGetObjectListPaths(mon, "/machine/peripheral", &paths);
|
||||
if (n < 0)
|
||||
return -1;
|
||||
|
||||
if (VIR_ALLOC_N(*aliases, n + 1) < 0)
|
||||
goto cleanup;
|
||||
|
||||
alias = *aliases;
|
||||
for (i = 0; i < n; i++) {
|
||||
if (STRPREFIX(paths[i]->type, "child<")) {
|
||||
*alias = paths[i]->name;
|
||||
paths[i]->name = NULL;
|
||||
alias++;
|
||||
}
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
for (i = 0; i < n; i++)
|
||||
qemuMonitorJSONListPathFree(paths[i]);
|
||||
VIR_FREE(paths);
|
||||
return ret;
|
||||
}
|
||||
|
@ -422,4 +422,8 @@ int qemuMonitorJSONAttachCharDev(qemuMonitorPtr mon,
|
||||
virDomainChrSourceDefPtr chr);
|
||||
int qemuMonitorJSONDetachCharDev(qemuMonitorPtr mon,
|
||||
const char *chrID);
|
||||
|
||||
int qemuMonitorJSONGetDeviceAliases(qemuMonitorPtr mon,
|
||||
char ***aliases);
|
||||
|
||||
#endif /* QEMU_MONITOR_JSON_H */
|
||||
|
@ -882,6 +882,66 @@ cleanup:
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
testQemuMonitorJSONGetDeviceAliases(const void *data)
|
||||
{
|
||||
const virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
|
||||
qemuMonitorTestPtr test = qemuMonitorTestNew(true, xmlopt);
|
||||
int ret = -1;
|
||||
char **aliases = NULL;
|
||||
char **alias;
|
||||
const char *expected[] = {
|
||||
"virtio-disk25", "video0", "serial0", "ide0-0-0", "usb", NULL };
|
||||
|
||||
if (!test)
|
||||
return -1;
|
||||
|
||||
if (qemuMonitorTestAddItem(test,
|
||||
"qom-list",
|
||||
"{\"return\": ["
|
||||
" {\"name\": \"virtio-disk25\","
|
||||
" \"type\": \"child<virtio-blk-pci>\"},"
|
||||
" {\"name\": \"video0\","
|
||||
" \"type\": \"child<VGA>\"},"
|
||||
" {\"name\": \"serial0\","
|
||||
" \"type\": \"child<isa-serial>\"},"
|
||||
" {\"name\": \"ide0-0-0\","
|
||||
" \"type\": \"child<ide-cd>\"},"
|
||||
" {\"name\": \"usb\","
|
||||
" \"type\": \"child<piix3-usb-uhci>\"},"
|
||||
" {\"name\": \"type\", \"type\": \"string\"}"
|
||||
"]}") < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (qemuMonitorJSONGetDeviceAliases(qemuMonitorTestGetMonitor(test),
|
||||
&aliases) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (!aliases) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", "no aliases returned");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
for (alias = aliases; *alias; alias++) {
|
||||
if (!virStringArrayHasString((char **) expected, *alias)) {
|
||||
fprintf(stderr, "got unexpected device alias '%s'\n", *alias);
|
||||
ret = -1;
|
||||
}
|
||||
}
|
||||
for (alias = (char **) expected; *alias; alias++) {
|
||||
if (!virStringArrayHasString(aliases, *alias)) {
|
||||
fprintf(stderr, "missing expected alias '%s'\n", *alias);
|
||||
ret = -1;
|
||||
}
|
||||
}
|
||||
|
||||
cleanup:
|
||||
virStringFreeList(aliases);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
mymain(void)
|
||||
{
|
||||
@ -915,6 +975,7 @@ mymain(void)
|
||||
DO_TEST(GetListPaths);
|
||||
DO_TEST(GetObjectProperty);
|
||||
DO_TEST(SetObjectProperty);
|
||||
DO_TEST(GetDeviceAliases);
|
||||
|
||||
virObjectUnref(xmlopt);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user