}
-/* Determine the name that qemu is using for tracking the backing
- * element TARGET within the chain starting at TOP. */
-char *
-qemuMonitorDiskNameLookup(qemuMonitor *mon,
- const char *device,
- virStorageSource *top,
- virStorageSource *target)
-{
- QEMU_CHECK_MONITOR_NULL(mon);
-
- return qemuMonitorJSONDiskNameLookup(mon, device, top, target);
-}
-
-
/* Use the block-job-complete monitor command to pivot a block copy job. */
int
qemuMonitorDrivePivot(qemuMonitor *mon,
return 0;
}
-
-static char *
-qemuMonitorJSONDiskNameLookupOne(virJSONValue *image,
- virStorageSource *top,
- virStorageSource *target)
-{
- virJSONValue *backing;
- char *ret;
-
- /* The caller will report a generic message if we return NULL
- * without an error; but in some cases we can improve by reporting
- * a more specific message. */
- if (!top || !image)
- return NULL;
- if (top != target) {
- backing = virJSONValueObjectGetObject(image, "backing-image");
- return qemuMonitorJSONDiskNameLookupOne(backing, top->backingStore,
- target);
- }
- ret = g_strdup(virJSONValueObjectGetString(image, "filename"));
- /* Sanity check - the name qemu gave us should resolve to the same
- file tracked by our target description. */
- if (virStorageSourceIsLocalStorage(target) &&
- STRNEQ(ret, target->path) &&
- !virFileLinkPointsTo(ret, target->path)) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("qemu block name '%s' doesn't match expected '%s'"),
- ret, target->path);
- VIR_FREE(ret);
- }
- return ret;
-}
-
-
-char *
-qemuMonitorJSONDiskNameLookup(qemuMonitor *mon,
- const char *device,
- virStorageSource *top,
- virStorageSource *target)
-{
- g_autoptr(virJSONValue) devices = NULL;
- size_t i;
-
- if (!(devices = qemuMonitorJSONQueryBlock(mon)))
- return NULL;
-
- for (i = 0; i < virJSONValueArraySize(devices); i++) {
- virJSONValue *dev;
- virJSONValue *inserted;
- virJSONValue *image;
- const char *thisdev;
-
- if (!(dev = qemuMonitorJSONGetBlockDev(devices, i)))
- return NULL;
-
- if (!(thisdev = qemuMonitorJSONGetBlockDevDevice(dev)))
- return NULL;
-
- if (STREQ(thisdev, device)) {
- if ((inserted = virJSONValueObjectGetObject(dev, "inserted")) &&
- (image = virJSONValueObjectGetObject(inserted, "image"))) {
- return qemuMonitorJSONDiskNameLookupOne(image, top, target);
- }
- }
- }
- /* Guarantee an error when returning NULL, but don't override a
- * more specific error if one was already generated. */
- if (virGetLastErrorCode() == VIR_ERR_OK) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("unable to find backing name for device %s"),
- device);
- }
-
- return NULL;
-}
-
-
int qemuMonitorJSONArbitraryCommand(qemuMonitor *mon,
const char *cmd_str,
int fd,