[libvirt] [PATCHv2 08/15] blockjob: expose qemu commands for mirrored storage migration

Eric Blake eblake at redhat.com
Fri Apr 6 15:15:24 UTC 2012


On 04/06/2012 01:13 AM, Paolo Bonzini wrote:
> Il 06/04/2012 06:36, Eric Blake ha scritto:
>> +int
>> +qemuMonitorJSONDriveMirror(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
>> +                           virJSONValuePtr actions,
>> +                           const char *device, const char *file,
>> +                           const char *format, int mode)
>> +{
>> +    int ret = -1;
>> +    virJSONValuePtr cmd;
>> +
>> +    cmd = qemuMonitorJSONMakeCommandRaw(true,
>> +                                        "drive-mirror",
>> +                                        "s:device", device,
>> +                                        "s:target", file,
>> +                                        "s:format", format,
>> +                                        "s:mode",
>> +                                        qemuMonitorDriveMirrorTypeToString(mode),
>> +                                        NULL);
>> +    if (!cmd)
>> +        return -1;
>> +
>> +    if (virJSONValueArrayAppend(actions, cmd) < 0) {
>> +        virReportOOMError();
>> +        goto cleanup;
>> +    }
> 
> Here it would be nice to invoke the command directly if actions is NULL.
>  Right now there is no certainty that drive-mirror will be
> transactionable in upstream QEMU, so it is safer to invoke it outside a
> transaction in patch 11.

Good idea; borrowing from qemuMonitorJSONDiskSnapshot, I'm going to
squash this in:

diff --git i/src/qemu/qemu_monitor_json.c w/src/qemu/qemu_monitor_json.c
index 3bbc664..ad9b8b8 100644
--- i/src/qemu/qemu_monitor_json.c
+++ w/src/qemu/qemu_monitor_json.c
@@ -3144,7 +3144,7 @@ qemuMonitorJSONDiskSnapshot(qemuMonitorPtr mon,
virJSONValuePtr actions,
                             const char *device, const char *file,
                             const char *format, bool reuse)
 {
-    int ret;
+    int ret = -1;
     virJSONValuePtr cmd;
     virJSONValuePtr reply = NULL;

@@ -3162,14 +3162,13 @@ qemuMonitorJSONDiskSnapshot(qemuMonitorPtr mon,
virJSONValuePtr actions,
     if (actions) {
         if (virJSONValueArrayAppend(actions, cmd) < 0) {
             virReportOOMError();
-            ret = -1;
         } else {
             ret = 0;
             cmd = NULL;
         }
     } else {
         if ((ret = qemuMonitorJSONCommand(mon, cmd, &reply)) < 0)
-        goto cleanup;
+            goto cleanup;

         if (qemuMonitorJSONHasError(reply, "CommandNotFound") &&
             qemuMonitorCheckHMP(mon, "snapshot_blkdev")) {
@@ -3199,8 +3198,9 @@ qemuMonitorJSONDriveMirror(qemuMonitorPtr mon
ATTRIBUTE_UNUSED,
 {
     int ret = -1;
     virJSONValuePtr cmd;
+    virJSONValuePtr reply = NULL;

-    cmd = qemuMonitorJSONMakeCommandRaw(true,
+    cmd = qemuMonitorJSONMakeCommandRaw(actions != NULL,
                                         "drive-mirror",
                                         "s:device", device,
                                         "s:target", file,
@@ -3211,16 +3211,22 @@ qemuMonitorJSONDriveMirror(qemuMonitorPtr mon
ATTRIBUTE_UNUSED,
     if (!cmd)
         return -1;

-    if (virJSONValueArrayAppend(actions, cmd) < 0) {
-        virReportOOMError();
-        goto cleanup;
+    if (actions) {
+        if (virJSONValueArrayAppend(actions, cmd) < 0) {
+            virReportOOMError();
+        } else {
+            cmd = NULL;
+            ret = 0;
+        }
+    } else {
+        if ((ret = qemuMonitorJSONCommand(mon, cmd, &reply)) < 0)
+            goto cleanup;
+        ret = qemuMonitorJSONCheckError(cmd, reply);
     }

-    cmd = NULL;
-    ret = 0;
-
 cleanup:
     virJSONValueFree(cmd);
+    virJSONValueFree(reply);
     return ret;
 }

-- 
Eric Blake   eblake at redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 620 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20120406/1811ba28/attachment-0001.sig>


More information about the libvir-list mailing list