[RFC PATCH 04/11] domain_conf: introduce dimm def helpers

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

 



virDomainDimmDefFree - free memory allocated for dimm
virDomainDimmDefParseXML - parse job type
virDomainDimmDefFormat - output job type

Signed-off-by: Zhu Guihua <zhugh.fnst@xxxxxxxxxxxxxx>
---
 src/conf/domain_conf.c   | 196 +++++++++++++++++++++++++++++++++++++++++++++++
 src/conf/domain_conf.h   |   4 +
 src/libvirt_private.syms |   3 +
 3 files changed, 203 insertions(+)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index ea41cbd..d4da728 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -751,6 +751,10 @@ VIR_ENUM_IMPL(virDomainRNGBackend,
               "random",
               "egd");
 
+VIR_ENUM_IMPL(virDomainMemoryBackend, VIR_DOMAIN_MEMORY_BACKEND_LAST,
+              "ram",
+              "file");
+
 VIR_ENUM_IMPL(virDomainTPMModel, VIR_DOMAIN_TPM_MODEL_LAST,
               "tpm-tis")
 
@@ -1733,6 +1737,22 @@ void virDomainMemballoonDefFree(virDomainMemballoonDefPtr def)
     VIR_FREE(def);
 }
 
+void virDomainDimmDefFree(virDomainDimmDefPtr def)
+{
+    if (!def)
+        return;
+
+    if (def->driver)
+        VIR_FREE(def->driver);
+    if (def->backend.type == VIR_DOMAIN_MEMORY_BACKEND_FILE &&
+        def->backend.mem_path)
+        VIR_FREE(def->backend.mem_path);
+
+    virDomainDeviceInfoClear(&def->info);
+
+    VIR_FREE(def);
+}
+
 void virDomainNVRAMDefFree(virDomainNVRAMDefPtr def)
 {
     if (!def)
@@ -1983,6 +2003,8 @@ void virDomainDeviceDefFree(virDomainDeviceDefPtr def)
         virDomainPanicDefFree(def->data.panic);
         break;
     case VIR_DOMAIN_DEVICE_DIMM:
+        virDomainDimmDefFree(def->data.dimm);
+        break;
     case VIR_DOMAIN_DEVICE_LAST:
     case VIR_DOMAIN_DEVICE_NONE:
         break;
@@ -10203,6 +10225,132 @@ virDomainMemballoonDefParseXML(xmlNodePtr node,
     goto cleanup;
 }
 
+virDomainDimmDefPtr
+virDomainDimmDefNew(void)
+{
+    virDomainDimmDefPtr def = NULL;
+
+    if (VIR_ALLOC(def) < 0)
+        return NULL;
+
+    return def;
+}
+
+/* Parse the XML definition for a dimm
+ *
+ * The XML looks like this:
+ *
+ * <dimm driver='pc-dimm' addr='0' node='0' slot='1'>
+ *     <backend type='ram' size='128000'/>
+ * </dimm>
+ *
+ */
+static virDomainDimmDefPtr
+virDomainDimmDefParseXML(xmlNodePtr node,
+                         virDomainDefPtr def)
+{
+    virDomainDimmDefPtr dev;
+    xmlNodePtr cur;
+    char *driver = NULL;
+    char *addr = NULL;
+    char *nodeid = NULL;
+    char *slot = NULL;
+    char *type = NULL;
+    char *size = NULL;
+    char *mem_path = NULL;
+
+    if (!(dev = virDomainDimmDefNew()))
+        return NULL;
+
+    driver = virXMLPropString(node, "driver");
+    if (driver == NULL) {
+        virReportError(VIR_ERR_XML_ERROR, "%s",
+                       _("missing memory device driver"));
+        goto error;
+    }
+
+    addr = virXMLPropString(node, "addr");
+    nodeid = virXMLPropString(node, "node");
+    slot = virXMLPropString(node, "slot");
+
+    cur = node->children;
+    while (cur != NULL) {
+        if (cur->type == XML_ELEMENT_NODE) {
+            type = virXMLPropString(cur, "type");
+            if (type != NULL) {
+                if ((int)(dev->backend.type = virDomainMemoryBackendTypeFromString(type)) < 0) {
+                    virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                                   _("unknown memory backend type '%s'"), type);
+                    goto error;
+                }
+            } else {
+                virReportError(VIR_ERR_XML_ERROR, "%s",
+                               _("missing memory backend"));
+                goto error;
+            }
+
+            size = virXMLPropString(cur, "size");
+            if (size == NULL) {
+                virReportError(VIR_ERR_XML_ERROR, "%s",
+                               _("missing memory backend's size"));
+                goto error;
+            } else {
+                dev->backend.size = atoi (size);
+            }
+
+            if (dev->backend.type == VIR_DOMAIN_MEMORY_BACKEND_FILE) {
+                mem_path = virXMLPropString(cur, "mem_path");
+                if (mem_path == NULL) {
+                    virReportError(VIR_ERR_XML_ERROR, "%s",
+                                   _("mem_path property not set"));
+                    goto error;
+                } else {
+                    dev->backend.mem_path = mem_path;
+                }
+            }
+        }
+
+        cur = cur->next;
+    }
+
+    dev->driver = driver;
+    if (!addr)
+        dev->addr = 0;
+    else
+        dev->addr = atoi (addr);
+    if (!nodeid)
+        dev->node = 0;
+    else
+        dev->node = atoi (nodeid);
+    if (!slot)
+        dev->slot = virDomainDimmGetFreeSlot(def);
+    else
+        dev->slot = atoi (slot);
+ cleanup:
+    driver = NULL;
+    addr = NULL;
+    nodeid = NULL;
+    slot = NULL;
+    type = NULL;
+    size = NULL;
+    mem_path = NULL;
+
+    VIR_FREE(driver);
+    VIR_FREE(addr);
+    VIR_FREE(nodeid);
+    VIR_FREE(slot);
+    VIR_FREE(type);
+    VIR_FREE(size);
+    VIR_FREE(mem_path);
+
+    return dev;
+
+ error:
+    virDomainDimmDefFree(dev);
+    dev = NULL;
+    goto cleanup;
+}
+
 static virDomainNVRAMDefPtr
 virDomainNVRAMDefParseXML(xmlNodePtr node,
                           unsigned int flags)
@@ -11187,6 +11335,9 @@ virDomainDeviceDefParse(const char *xmlStr,
             goto error;
         break;
     case VIR_DOMAIN_DEVICE_DIMM:
+        if (!(dev->data.dimm = virDomainDimmDefParseXML(node, (virDomainDefPtr)def)))
+            goto error;
+        break;
     case VIR_DOMAIN_DEVICE_NONE:
     case VIR_DOMAIN_DEVICE_LAST:
         break;
@@ -18348,6 +18499,45 @@ virDomainMemballoonDefFormat(virBufferPtr buf,
 }
 
 static int
+virDomainDimmDefFormat(virBufferPtr buf,
+                       virDomainDimmDefPtr def,
+                       unsigned int flags)
+{
+    char *addr = NULL;
+    char *node = NULL;
+    char *slot = NULL;
+
+    ignore_value(virAsprintf(&addr, "%d", def->addr));
+    ignore_value(virAsprintf(&node, "%d", def->node));
+    ignore_value(virAsprintf(&slot, "%d", def->slot));
+
+    virBufferAsprintf(buf, "<dimm driver='%s'", def->driver);
+
+    virBufferEscapeString(buf, " addr='%s'", addr);
+    virBufferEscapeString(buf, " node='%s'", node);
+    virBufferEscapeString(buf, " slot='%s'", slot);
+    virBufferAddLit(buf, ">\n");
+    virBufferAdjustIndent(buf, 2);
+
+    if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0)
+        return -1;
+
+    virBufferAddLit(buf, "<backend");
+    virBufferEscapeString(buf, " type='%s'",
+                          virDomainMemoryBackendTypeToString(def->backend.type));
+    virBufferAsprintf(buf, " size='%llu' unit='KiB'", def->backend.size);
+    if (def->backend.type == VIR_DOMAIN_MEMORY_BACKEND_FILE) {
+        virBufferEscapeString(buf, " mem_path='%s'", def->backend.mem_path);
+    }
+    virBufferAddLit(buf, "/>\n");
+
+    virBufferAdjustIndent(buf, -2);
+    virBufferAddLit(buf, "</dimm>\n");
+
+    return 0;
+}
+
+static int
 virDomainNVRAMDefFormat(virBufferPtr buf,
                         virDomainNVRAMDefPtr def,
                         unsigned int flags)
@@ -20092,6 +20282,10 @@ virDomainDefFormatInternal(virDomainDefPtr def,
         if (virDomainShmemDefFormat(buf, def->shmems[n], flags) < 0)
             goto error;
 
+    for (n = 0; n < def->ndimms; n++)
+        if (virDomainDimmDefFormat(buf, def->dimms[n], flags) < 0)
+            goto error;
+
     virBufferAdjustIndent(buf, -2);
     virBufferAddLit(buf, "</devices>\n");
 
@@ -21496,6 +21690,8 @@ virDomainDeviceDefCopy(virDomainDeviceDefPtr src,
         rc = virDomainPanicDefFormat(&buf, src->data.panic);
         break;
     case VIR_DOMAIN_DEVICE_DIMM:
+        rc = virDomainDimmDefFormat(&buf, src->data.dimm, flags);
+        break;
     case VIR_DOMAIN_DEVICE_NONE:
     case VIR_DOMAIN_DEVICE_SMARTCARD:
     case VIR_DOMAIN_DEVICE_MEMBALLOON:
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index c4ebbd4..4864dc3 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2382,6 +2382,8 @@ int virDomainChrSourceDefCopy(virDomainChrSourceDefPtr src,
 void virDomainSoundCodecDefFree(virDomainSoundCodecDefPtr def);
 void virDomainSoundDefFree(virDomainSoundDefPtr def);
 void virDomainMemballoonDefFree(virDomainMemballoonDefPtr def);
+virDomainDimmDefPtr virDomainDimmDefNew(void);
+void virDomainDimmDefFree(virDomainDimmDefPtr dimm);
 void virDomainNVRAMDefFree(virDomainNVRAMDefPtr def);
 void virDomainWatchdogDefFree(virDomainWatchdogDefPtr def);
 void virDomainVideoDefFree(virDomainVideoDefPtr def);
@@ -2845,6 +2847,8 @@ VIR_ENUM_DECL(virDomainChrSpicevmc)
 VIR_ENUM_DECL(virDomainSoundCodec)
 VIR_ENUM_DECL(virDomainSoundModel)
 VIR_ENUM_DECL(virDomainMemballoonModel)
+VIR_ENUM_DECL(virDomainMemoryBackend)
+VIR_ENUM_DECL(virDomainDimm)
 VIR_ENUM_DECL(virDomainSmbiosMode)
 VIR_ENUM_DECL(virDomainWatchdogModel)
 VIR_ENUM_DECL(virDomainWatchdogAction)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index a2eec83..c5daf5b 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -216,6 +216,7 @@ virDomainDeviceGetInfo;
 virDomainDeviceInfoCopy;
 virDomainDeviceInfoIterate;
 virDomainDeviceTypeToString;
+virDomainDimmDefFree;
 virDomainDiskBusTypeToString;
 virDomainDiskCacheTypeFromString;
 virDomainDiskCacheTypeToString;
@@ -323,6 +324,8 @@ virDomainLockFailureTypeFromString;
 virDomainLockFailureTypeToString;
 virDomainMemballoonModelTypeFromString;
 virDomainMemballoonModelTypeToString;
+virDomainMemoryBackendTypeFromString;
+virDomainMemoryBackendTypeToString;
 virDomainNetAppendIpAddress;
 virDomainNetDefFormat;
 virDomainNetDefFree;
-- 
1.9.3

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