]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Introduce nbd-server-start command
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 22 Nov 2012 15:08:52 +0000 (16:08 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Sat, 23 Feb 2013 06:58:13 +0000 (07:58 +0100)
This will be used with new migration scheme.
This patch creates basically just monitor stub
functions. Wiring them into something useful
is done in later patches.

src/qemu/qemu_monitor.c
src/qemu/qemu_monitor.h
src/qemu/qemu_monitor_json.c
src/qemu/qemu_monitor_json.h

index 7f4a7a017ab6b57a37469dae9c37018bfb143ccf..6160ad97777b221fa1d13cab2009d0a4119e45dd 100644 (file)
@@ -3463,3 +3463,25 @@ int qemuMonitorSetMigrationCapability(qemuMonitorPtr mon,
 
     return qemuMonitorJSONSetMigrationCapability(mon, capability);
 }
+
+int qemuMonitorNBDServerStart(qemuMonitorPtr mon,
+                              const char *host,
+                              unsigned int port)
+{
+    VIR_DEBUG("mon=%p host=%s port=%u",
+              mon, host, port);
+
+    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 qemuMonitorJSONNBDServerStart(mon, host, port);
+}
index ffb17c207a12d986fef61a38cd23c729347ff86c..26d4d947ccbaa32275f0a39407574e0c6e178366 100644 (file)
@@ -676,6 +676,9 @@ int qemuMonitorGetObjectProps(qemuMonitorPtr mon,
                               char ***props);
 char *qemuMonitorGetTargetArch(qemuMonitorPtr mon);
 
+int qemuMonitorNBDServerStart(qemuMonitorPtr mon,
+                              const char *host,
+                              unsigned int port);
 /**
  * When running two dd process and using <> redirection, we need a
  * shell that will not truncate files.  These two strings serve that
index f7123212238383807b420b8aeee5887d59825546..c91d22609ca71323b83f3b4fa12d15fde6ae25a2 100644 (file)
@@ -4607,3 +4607,59 @@ no_memory:
     virReportOOMError();
     goto cleanup;
 }
+
+int
+qemuMonitorJSONNBDServerStart(qemuMonitorPtr mon,
+                              const char *host,
+                              unsigned int port)
+{
+    int ret = -1;
+    virJSONValuePtr cmd = NULL;
+    virJSONValuePtr reply = NULL;
+    virJSONValuePtr data = NULL;
+    virJSONValuePtr addr = NULL;
+    char *port_str = NULL;
+
+    if (!(data = virJSONValueNewObject()) ||
+        !(addr = virJSONValueNewObject()) ||
+        (virAsprintf(&port_str, "%u", port) < 0)) {
+        virReportOOMError();
+        goto cleanup;
+    }
+
+    /* port is really expected as a string here by qemu */
+    if (virJSONValueObjectAppendString(data, "host", host) < 0 ||
+        virJSONValueObjectAppendString(data, "port", port_str) < 0 ||
+        virJSONValueObjectAppendString(addr, "type", "inet") < 0 ||
+        virJSONValueObjectAppend(addr, "data", data) < 0) {
+        virReportOOMError();
+        goto cleanup;
+    }
+
+    /* From now on, @data is part of @addr */
+    data = NULL;
+
+    if (!(cmd = qemuMonitorJSONMakeCommand("nbd-server-start",
+                                           "a:addr", addr,
+                                           NULL)))
+        goto cleanup;
+
+    /* From now on, @addr is part of @cmd */
+    addr = NULL;
+
+    if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+        goto cleanup;
+
+    if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+        goto cleanup;
+
+    ret = 0;
+
+cleanup:
+    VIR_FREE(port_str);
+    virJSONValueFree(reply);
+    virJSONValueFree(cmd);
+    virJSONValueFree(addr);
+    virJSONValueFree(data);
+    return ret;
+}
index cfe9c1926ee883f367361484bcbb6a9371e216ba..5d6372638b5366be50fb416cd0a8f7c3edb5b526 100644 (file)
@@ -334,4 +334,7 @@ int qemuMonitorJSONGetObjectProps(qemuMonitorPtr mon,
     ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
 char *qemuMonitorJSONGetTargetArch(qemuMonitorPtr mon);
 
+int qemuMonitorJSONNBDServerStart(qemuMonitorPtr mon,
+                                  const char *host,
+                                  unsigned int port);
 #endif /* QEMU_MONITOR_JSON_H */