}
mon->ballooninit = true;
- flp_ret = qemuMonitorJSONFindLinkPath(mon, "virtio-balloon-pci", &path);
+ flp_ret = qemuMonitorJSONFindLinkPath(mon, "virtio-balloon-pci", NULL, &path);
if (flp_ret == -2) {
/* pci object was not found retry search for ccw object */
- if (qemuMonitorJSONFindLinkPath(mon, "virtio-balloon-ccw", &path) < 0)
+ if (qemuMonitorJSONFindLinkPath(mon, "virtio-balloon-ccw",
+ NULL, &path) < 0)
return;
} else if (flp_ret < 0) {
return;
QEMU_CHECK_MONITOR(mon);
if (mon->json) {
- ret = qemuMonitorJSONFindLinkPath(mon, videoName, &path);
+ ret = qemuMonitorJSONFindLinkPath(mon, videoName,
+ video->info.alias, &path);
if (ret < 0) {
if (ret == -2)
virReportError(VIR_ERR_INTERNAL_ERROR,
QEMU_CHECK_MONITOR(mon);
if (mon->json) {
- ret = qemuMonitorJSONFindLinkPath(mon, videoName, &path);
+ ret = qemuMonitorJSONFindLinkPath(mon, videoName,
+ video->info.alias, &path);
if (ret < 0) {
if (ret == -2)
virReportError(VIR_ERR_INTERNAL_ERROR,
/**
- * Recursively search for a QOM object link.
+ * Search for a QOM object link by alias and name.
+ *
+ * For @alias and @name, this function tries to find QOM object named @name
+ * with id @alias in /machine/peripheral.
+ *
+ * Returns:
+ * 0 - Found
+ * -1 - Error - bail out
+ * -2 - Not found
+ */
+static int
+qemuMonitorJSONFindObjectPathByAlias(qemuMonitorPtr mon,
+ const char *name,
+ const char *alias,
+ char **path)
+{
+ qemuMonitorJSONListPathPtr *paths = NULL;
+ char *child = NULL;
+ int npaths;
+ int ret = -1;
+ size_t i;
+
+ npaths = qemuMonitorJSONGetObjectListPaths(mon, "/machine/peripheral", &paths);
+ if (npaths < 0)
+ return -1;
+
+ if (virAsprintf(&child, "child<%s>", name) < 0)
+ goto cleanup;
+
+ for (i = 0; i < npaths; i++) {
+ if (STREQ(paths[i]->name, alias) && STREQ(paths[i]->type, child)) {
+ if (virAsprintf(path, "/machine/peripheral/%s", alias) < 0)
+ goto cleanup;
+
+ ret = 0;
+ goto cleanup;
+ }
+ }
+
+ ret = -2;
+
+ cleanup:
+ for (i = 0; i < npaths; i++)
+ qemuMonitorJSONListPathFree(paths[i]);
+ VIR_FREE(paths);
+ VIR_FREE(child);
+ return ret;
+}
+
+
+/**
+ * Recursively search for a QOM object link only by name.
*
* For @name, this function finds the first QOM object
* named @name, recursively going through all the "child<>"
* -2 - Not found
*/
static int
-qemuMonitorJSONFindObjectPath(qemuMonitorPtr mon,
- const char *curpath,
- const char *name,
- char **path)
+qemuMonitorJSONFindObjectPathByName(qemuMonitorPtr mon,
+ const char *curpath,
+ const char *name,
+ char **path)
{
ssize_t i, npaths = 0;
int ret = -2;
goto cleanup;
}
- ret = qemuMonitorJSONFindObjectPath(mon, nextpath, name, path);
+ ret = qemuMonitorJSONFindObjectPathByName(mon, nextpath, name, path);
VIR_FREE(nextpath);
}
}
/**
* Recursively search for a QOM object link.
*
- * For @name, this function finds the first QOM object
- * pointed to by a link in the form of 'link<@name>'
+ * For @name and @alias, this function finds the first QOM object.
+ * The search is done at first by @alias and @name and if nothing was found
+ * it continues recursively only with @name.
*
* Returns:
* 0 - Found
int
qemuMonitorJSONFindLinkPath(qemuMonitorPtr mon,
const char *name,
+ const char *alias,
char **path)
{
char *linkname = NULL;
int ret = -1;
+ if (alias) {
+ ret = qemuMonitorJSONFindObjectPathByAlias(mon, name, alias, path);
+ if (ret == -1 || ret == 0)
+ return ret;
+ }
+
if (virAsprintf(&linkname, "link<%s>", name) < 0)
return -1;
- ret = qemuMonitorJSONFindObjectPath(mon, "/", linkname, path);
+ ret = qemuMonitorJSONFindObjectPathByName(mon, "/", linkname, path);
VIR_FREE(linkname);
return ret;
}