[PATCH 9/9] qemu: monitor: Add APIs for 'blockdev-create'

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The 'blockdev-create' starts a job which creates a storage volume using
the given protocol or formats an existing (added) volume with one of the
supported storage formats.

This patch adds the monitor interaction bits.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/qemu/qemu_monitor.c      | 30 ++++++++++++++++++++++++++++++
 src/qemu/qemu_monitor.h      |  4 ++++
 src/qemu/qemu_monitor_json.c | 26 ++++++++++++++++++++++++++
 src/qemu/qemu_monitor_json.h |  5 +++++
 4 files changed, 65 insertions(+)

diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 9358d0b1e2..90cd5ea9bd 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -4418,6 +4418,36 @@ qemuMonitorSetWatchdogAction(qemuMonitorPtr mon,
 }


+/**
+ * qemuMonitorBlockdevCreate:
+ * @mon: monitor object
+ * @jobname: name of the job
+ * @props: JSON object describing the blockdev to add
+ *
+ * Instructs qemu to create/format a new stroage or format layer. Note that
+ * the job does not add the created/formatted image into qemu and
+ * qemuMonitorBlockdevAdd needs to be called separately with corresponding
+ * arguments. Note that the argumetns for creating and adding are different.
+ *
+ * Note that @props is always consumed by this function and should not be
+ * accessed after calling this function.
+ */
+int
+qemuMonitorBlockdevCreate(qemuMonitorPtr mon,
+                          const char *jobname,
+                          virJSONValuePtr props)
+{
+    VIR_DEBUG("jobname=%s props=%p", jobname, props);
+
+    QEMU_CHECK_MONITOR_GOTO(mon, error);
+
+    return qemuMonitorJSONBlockdevCreate(mon, jobname, props);
+
+ error:
+    virJSONValueFree(props);
+    return -1;
+}
+
 /**
  * qemuMonitorBlockdevAdd:
  * @mon: monitor object
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index c6dddd1e9e..aafea6350c 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -1289,6 +1289,10 @@ virJSONValuePtr qemuMonitorQueryNamedBlockNodes(qemuMonitorPtr mon);
 int qemuMonitorSetWatchdogAction(qemuMonitorPtr mon,
                                  const char *action);

+int qemuMonitorBlockdevCreate(qemuMonitorPtr mon,
+                              const char *jobname,
+                              virJSONValuePtr props);
+
 int qemuMonitorBlockdevAdd(qemuMonitorPtr mon,
                            virJSONValuePtr props);

diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 04538bc46c..22fbd84e90 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -8616,6 +8616,32 @@ qemuMonitorJSONSetWatchdogAction(qemuMonitorPtr mon,
 }


+int
+qemuMonitorJSONBlockdevCreate(qemuMonitorPtr mon,
+                              const char *jobname,
+                              virJSONValuePtr props)
+{
+    VIR_AUTOPTR(virJSONValue) cmd = NULL;
+    VIR_AUTOPTR(virJSONValue) reply = NULL;
+
+    cmd = qemuMonitorJSONMakeCommand("blockdev-create",
+                                     "s:job-id", jobname,
+                                     "a:options", &props,
+                                     NULL);
+    virJSONValueFree(props);
+    if (!cmd)
+        return -1;
+
+    if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+        return -1;
+
+    if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+        return -1;
+
+    return 0;
+}
+
+
 int
 qemuMonitorJSONBlockdevAdd(qemuMonitorPtr mon,
                            virJSONValuePtr props)
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
index a50d4d7b23..00e6b3d68f 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -580,6 +580,11 @@ int qemuMonitorJSONSetWatchdogAction(qemuMonitorPtr mon,
                                      const char *action)
     ATTRIBUTE_NONNULL(1);

+int qemuMonitorJSONBlockdevCreate(qemuMonitorPtr mon,
+                                  const char *jobname,
+                                  virJSONValuePtr props)
+    ATTRIBUTE_NONNULL(1);
+
 int qemuMonitorJSONBlockdevAdd(qemuMonitorPtr mon,
                                virJSONValuePtr props)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
-- 
2.21.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux