[PATCH v4 12/14] qemu: Introduce qemuDomainChardevPrivatePtr

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

 



Modeled after the qemuDomainHostdevPrivatePtr (commit id '27726d8c'),
create a privateData pointer in the _virDomainChardevDef to allow storage
of private data for a hypervisor in order to at least temporarily store
secret data for usage during qemuBuildCommandLine.

NB: Since the qemu_parse_command (qemuParseCommandLine) code is not
expecting to restore the secret data, there's no need to add code
code to handle this new structure there.

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/conf/domain_conf.c        | 27 ++++++++++++++++++--------
 src/conf/domain_conf.h        |  4 +++-
 src/libxl/libxl_domain.c      |  2 +-
 src/lxc/lxc_native.c          |  2 +-
 src/qemu/qemu_domain.c        | 44 +++++++++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_domain.h        | 14 ++++++++++++++
 src/qemu/qemu_parse_command.c |  4 ++--
 src/vz/vz_sdk.c               |  2 +-
 src/xenconfig/xen_sxpr.c      |  2 +-
 9 files changed, 86 insertions(+), 15 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index f614ff9..18dfc1c 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -10208,7 +10208,7 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDefPtr def,
  * default port.
  */
 virDomainChrDefPtr
-virDomainChrDefNew(void)
+virDomainChrDefNew(virDomainXMLOptionPtr xmlopt)
 {
     virDomainChrDefPtr def = NULL;
 
@@ -10216,6 +10216,11 @@ virDomainChrDefNew(void)
         return NULL;
 
     def->target.port = -1;
+
+    if (xmlopt && xmlopt->privateData.chardevNew &&
+        !(def->privateData = xmlopt->privateData.chardevNew()))
+        VIR_FREE(def);
+
     return def;
 }
 
@@ -10263,7 +10268,8 @@ virDomainChrDefNew(void)
  *
  */
 static virDomainChrDefPtr
-virDomainChrDefParseXML(xmlXPathContextPtr ctxt,
+virDomainChrDefParseXML(virDomainXMLOptionPtr xmlopt,
+                        xmlXPathContextPtr ctxt,
                         xmlNodePtr node,
                         virSecurityLabelDefPtr* vmSeclabels,
                         int nvmSeclabels,
@@ -10275,7 +10281,7 @@ virDomainChrDefParseXML(xmlXPathContextPtr ctxt,
     virDomainChrDefPtr def;
     bool seenTarget = false;
 
-    if (!(def = virDomainChrDefNew()))
+    if (!(def = virDomainChrDefNew(xmlopt)))
         return NULL;
 
     type = virXMLPropString(node, "type");
@@ -13424,7 +13430,8 @@ virDomainDeviceDefParse(const char *xmlStr,
             goto error;
         break;
     case VIR_DOMAIN_DEVICE_CHR:
-        if (!(dev->data.chr = virDomainChrDefParseXML(ctxt,
+        if (!(dev->data.chr = virDomainChrDefParseXML(xmlopt,
+                                                      ctxt,
                                                       node,
                                                       def->seclabels,
                                                       def->nseclabels,
@@ -16859,7 +16866,8 @@ virDomainDefParseXML(xmlDocPtr xml,
         goto error;
 
     for (i = 0; i < n; i++) {
-        virDomainChrDefPtr chr = virDomainChrDefParseXML(ctxt,
+        virDomainChrDefPtr chr = virDomainChrDefParseXML(xmlopt,
+                                                         ctxt,
                                                          nodes[i],
                                                          def->seclabels,
                                                          def->nseclabels,
@@ -16886,7 +16894,8 @@ virDomainDefParseXML(xmlDocPtr xml,
         goto error;
 
     for (i = 0; i < n; i++) {
-        virDomainChrDefPtr chr = virDomainChrDefParseXML(ctxt,
+        virDomainChrDefPtr chr = virDomainChrDefParseXML(xmlopt,
+                                                         ctxt,
                                                          nodes[i],
                                                          def->seclabels,
                                                          def->nseclabels,
@@ -16915,7 +16924,8 @@ virDomainDefParseXML(xmlDocPtr xml,
         goto error;
 
     for (i = 0; i < n; i++) {
-        virDomainChrDefPtr chr = virDomainChrDefParseXML(ctxt,
+        virDomainChrDefPtr chr = virDomainChrDefParseXML(xmlopt,
+                                                         ctxt,
                                                          nodes[i],
                                                          def->seclabels,
                                                          def->nseclabels,
@@ -16934,7 +16944,8 @@ virDomainDefParseXML(xmlDocPtr xml,
         goto error;
 
     for (i = 0; i < n; i++) {
-        virDomainChrDefPtr chr = virDomainChrDefParseXML(ctxt,
+        virDomainChrDefPtr chr = virDomainChrDefParseXML(xmlopt,
+                                                         ctxt,
                                                          nodes[i],
                                                          def->seclabels,
                                                          def->nseclabels,
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 8d4a9ec..f1d38fa 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1124,6 +1124,7 @@ struct _virDomainChrSourceDef {
 /* A complete character device, both host and domain views.  */
 struct _virDomainChrDef {
     int deviceType; /* enum virDomainChrDeviceType */
+    virObjectPtr privateData;
 
     bool targetTypeAttr;
     int targetType; /* enum virDomainChrConsoleTargetType ||
@@ -2424,6 +2425,7 @@ struct _virDomainXMLPrivateDataCallbacks {
     virDomainXMLPrivateDataFreeFunc   free;
     virDomainXMLPrivateDataNewFunc    diskNew;
     virDomainXMLPrivateDataNewFunc    hostdevNew;
+    virDomainXMLPrivateDataNewFunc    chardevNew;
     virDomainXMLPrivateDataFormatFunc format;
     virDomainXMLPrivateDataParseFunc  parse;
 };
@@ -2546,7 +2548,7 @@ bool virDomainDefHasDeviceAddress(virDomainDefPtr def,
 
 void virDomainDefFree(virDomainDefPtr vm);
 
-virDomainChrDefPtr virDomainChrDefNew(void);
+virDomainChrDefPtr virDomainChrDefNew(virDomainXMLOptionPtr xmlopt);
 
 virDomainDefPtr virDomainDefNew(void);
 virDomainDefPtr virDomainDefNewFull(const char *name,
diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
index 6bcb4d9..f264c89 100644
--- a/src/libxl/libxl_domain.c
+++ b/src/libxl/libxl_domain.c
@@ -386,7 +386,7 @@ libxlDomainDefPostParse(virDomainDefPtr def,
     if (def->os.type != VIR_DOMAIN_OSTYPE_HVM && def->nconsoles == 0) {
         virDomainChrDefPtr chrdef;
 
-        if (!(chrdef = virDomainChrDefNew()))
+        if (!(chrdef = virDomainChrDefNew(NULL)))
             return -1;
 
         chrdef->source.type = VIR_DOMAIN_CHR_TYPE_PTY;
diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c
index 7f8e904..b7db904 100644
--- a/src/lxc/lxc_native.c
+++ b/src/lxc/lxc_native.c
@@ -702,7 +702,7 @@ lxcCreateConsoles(virDomainDefPtr def, virConfPtr properties)
 
     def->nconsoles = nbttys;
     for (i = 0; i < nbttys; i++) {
-        if (!(console = virDomainChrDefNew()))
+        if (!(console = virDomainChrDefNew(NULL)))
             goto error;
 
         console->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE;
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index dca8970..72fe5ca 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -811,6 +811,49 @@ qemuDomainHostdevPrivateDispose(void *obj)
 }
 
 
+static virClassPtr qemuDomainChardevPrivateClass;
+static void qemuDomainChardevPrivateDispose(void *obj);
+
+static int
+qemuDomainChardevPrivateOnceInit(void)
+{
+    qemuDomainChardevPrivateClass =
+        virClassNew(virClassForObject(),
+                    "qemuDomainChardevPrivate",
+                    sizeof(qemuDomainChardevPrivate),
+                    qemuDomainChardevPrivateDispose);
+    if (!qemuDomainChardevPrivateClass)
+        return -1;
+    else
+        return 0;
+}
+
+VIR_ONCE_GLOBAL_INIT(qemuDomainChardevPrivate)
+
+static virObjectPtr
+qemuDomainChardevPrivateNew(void)
+{
+    qemuDomainChardevPrivatePtr priv;
+
+    if (qemuDomainChardevPrivateInitialize() < 0)
+        return NULL;
+
+    if (!(priv = virObjectNew(qemuDomainChardevPrivateClass)))
+        return NULL;
+
+    return (virObjectPtr) priv;
+}
+
+
+static void
+qemuDomainChardevPrivateDispose(void *obj)
+{
+    qemuDomainChardevPrivatePtr priv = obj;
+
+    qemuDomainSecretInfoFree(&priv->secinfo);
+}
+
+
 /* qemuDomainSecretPlainSetup:
  * @conn: Pointer to connection
  * @secinfo: Pointer to secret info
@@ -1627,6 +1670,7 @@ virDomainXMLPrivateDataCallbacks virQEMUDriverPrivateDataCallbacks = {
     .free = qemuDomainObjPrivateFree,
     .diskNew = qemuDomainDiskPrivateNew,
     .hostdevNew = qemuDomainHostdevPrivateNew,
+    .chardevNew = qemuDomainChardevPrivateNew,
     .parse = qemuDomainObjPrivateXMLParse,
     .format = qemuDomainObjPrivateXMLFormat,
 };
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index fa536e0..d718917 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -331,6 +331,20 @@ struct _qemuDomainHostdevPrivate {
     qemuDomainSecretInfoPtr secinfo;
 };
 
+# define QEMU_DOMAIN_CHARDEV_PRIVATE(chardev)	\
+    ((qemuDomainChardevPrivatePtr) (chardev)->privateData)
+
+typedef struct _qemuDomainChardevPrivate qemuDomainChardevPrivate;
+typedef qemuDomainChardevPrivate *qemuDomainChardevPrivatePtr;
+struct _qemuDomainChardevPrivate {
+    virObject parent;
+
+    /* for char devices using secret
+     * NB: *not* to be written to qemu domain object XML */
+    qemuDomainSecretInfoPtr secinfo;
+};
+
+
 typedef enum {
     QEMU_PROCESS_EVENT_WATCHDOG = 0,
     QEMU_PROCESS_EVENT_GUESTPANIC,
diff --git a/src/qemu/qemu_parse_command.c b/src/qemu/qemu_parse_command.c
index 1d54a68..083b6f7 100644
--- a/src/qemu/qemu_parse_command.c
+++ b/src/qemu/qemu_parse_command.c
@@ -2187,7 +2187,7 @@ qemuParseCommandLine(virCapsPtr caps,
             if (STRNEQ(val, "none")) {
                 virDomainChrDefPtr chr;
 
-                if (!(chr = virDomainChrDefNew()))
+                if (!(chr = virDomainChrDefNew(NULL)))
                     goto error;
 
                 if (qemuParseCommandLineChr(&chr->source, val) < 0) {
@@ -2206,7 +2206,7 @@ qemuParseCommandLine(virCapsPtr caps,
             if (STRNEQ(val, "none")) {
                 virDomainChrDefPtr chr;
 
-                if (!(chr = virDomainChrDefNew()))
+                if (!(chr = virDomainChrDefNew(NULL)))
                     goto error;
 
                 if (qemuParseCommandLineChr(&chr->source, val) < 0) {
diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c
index cb06240..5e82545 100644
--- a/src/vz/vz_sdk.c
+++ b/src/vz/vz_sdk.c
@@ -944,7 +944,7 @@ prlsdkAddSerialInfo(PRL_HANDLE sdkdom,
         ret = PrlVmCfg_GetSerialPort(sdkdom, i, &serialPort);
         prlsdkCheckRetGoto(ret, cleanup);
 
-        if (!(chr = virDomainChrDefNew()))
+        if (!(chr = virDomainChrDefNew(NULL)))
             goto cleanup;
 
         if (prlsdkGetSerialInfo(serialPort, chr))
diff --git a/src/xenconfig/xen_sxpr.c b/src/xenconfig/xen_sxpr.c
index 653b7b3..5732b15 100644
--- a/src/xenconfig/xen_sxpr.c
+++ b/src/xenconfig/xen_sxpr.c
@@ -190,7 +190,7 @@ xenParseSxprChar(const char *value,
     char *tmp;
     virDomainChrDefPtr def;
 
-    if (!(def = virDomainChrDefNew()))
+    if (!(def = virDomainChrDefNew(NULL)))
         return NULL;
 
     prefix = value;
-- 
2.5.5

--
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]