[PATCH RFC v3 04/16] config: Introduce ThrottleFilter and corresponding XML parsing

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

 



From: Chun Feng Wu <wucf@xxxxxxxxxxxxx>

* Define new struct 'virDomainThrottleFilterDef' and corresponding destructor
* Update _virDomainDiskDef to include virDomainThrottleFilterDef
* Support new resource "Parse" and "Format" for operations between DOM XML and structs

Signed-off-by: Chun Feng Wu <wucf@xxxxxxxxxxxxx>
---
 src/conf/domain_conf.c  | 95 +++++++++++++++++++++++++++++++++++++++++
 src/conf/domain_conf.h  | 20 +++++++++
 src/conf/virconftypes.h |  2 +
 3 files changed, 117 insertions(+)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 05d6f7ad3a..0f6979091b 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -3776,6 +3776,16 @@ virDomainThrottleGroupDefArrayFree(virDomainThrottleGroupDef **def,
 }
 
 
+void
+virDomainThrottleFilterDefFree(virDomainThrottleFilterDef *def)
+{
+    if (!def)
+        return;
+    g_free(def->group_name);
+    g_free(def->nodename);
+}
+
+
 void
 virDomainResourceDefFree(virDomainResourceDef *resource)
 {
@@ -7832,6 +7842,53 @@ virDomainDefThrottleGroupsParse(virDomainDef *def,
 }
 
 
+static virDomainThrottleFilterDef *
+virDomainDiskThrottleFilterDefParse(xmlNodePtr node)
+{
+    g_autoptr(virDomainThrottleFilterDef) filter =  g_new0(virDomainThrottleFilterDef, 1);
+
+    filter->group_name = virXMLPropString(node, "group");
+
+    if (!filter->group_name)
+        return NULL;
+
+    return g_steal_pointer(&filter);
+}
+
+
+static int
+virDomainDiskDefThrottleFiltersParse(virDomainDiskDef *def,
+                                     xmlXPathContextPtr ctxt)
+{
+    size_t i;
+    int n = 0;
+    g_autofree xmlNodePtr *nodes = NULL;
+
+    if ((n = virXPathNodeSet("./throttlefilters/throttlefilter", ctxt, &nodes)) < 0)
+        return -1;
+
+    if (n)
+        def->throttlefilters = g_new0(virDomainThrottleFilterDef *, n);
+
+    for (i = 0; i < n; i++) {
+        g_autoptr(virDomainThrottleFilterDef) filter = NULL;
+
+        if (!(filter = virDomainDiskThrottleFilterDefParse(nodes[i]))) {
+            return -1;
+        }
+
+        if (virDomainThrottleFilterFind(def, filter->group_name)) {
+            virReportError(VIR_ERR_XML_ERROR,
+                           _("duplicate filter name '%1$s' found"),
+                           filter->group_name);
+            return -1;
+        }
+        def->throttlefilters[def->nthrottlefilters++] = g_steal_pointer(&filter);
+    }
+    return 0;
+}
+
+
 static int
 virDomainDiskDefMirrorParse(virDomainDiskDef *def,
                             xmlNodePtr cur,
@@ -8322,6 +8379,9 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt,
     if (virDomainDiskDefIotuneParse(def, ctxt) < 0)
         return NULL;
 
+    if (virDomainDiskDefThrottleFiltersParse(def, ctxt) < 0)
+        return NULL;
+
     def->domain_name = virXPathString("string(./backenddomain/@name)", ctxt);
     def->serial = virXPathString("string(./serial)", ctxt);
     def->wwn = virXPathString("string(./wwn)", ctxt);
@@ -22310,6 +22370,24 @@ virDomainThrottleGroupDel(virDomainDef *def,
 }
 
 
+virDomainThrottleFilterDef *
+virDomainThrottleFilterFind(const virDomainDiskDef *def,
+                            const char *name)
+{
+    size_t i;
+
+    if (!def->throttlefilters || def->nthrottlefilters == 0)
+        return NULL;
+
+    for (i = 0; i < def->nthrottlefilters; i++) {
+        if (STREQ(name, def->throttlefilters[i]->group_name))
+            return def->throttlefilters[i];
+    }
+
+    return NULL;
+}
+
+
 static int
 virDomainEventActionDefFormat(virBuffer *buf,
                               int type,
@@ -22926,6 +23004,21 @@ virDomainDiskDefFormatIotune(virBuffer *buf,
 #undef FORMAT_IOTUNE
 
 
+static void
+virDomainDiskDefFormatThrottleFilters(virBuffer *buf,
+                                      virDomainDiskDef *disk)
+{
+    size_t i;
+    g_auto(virBuffer) throttleChildBuf = VIR_BUFFER_INIT_CHILD(buf);
+    for (i = 0; i < disk->nthrottlefilters; i++) {
+        g_auto(virBuffer) throttleAttrBuf = VIR_BUFFER_INITIALIZER;
+        virBufferEscapeString(&throttleAttrBuf, " group='%s'", disk->throttlefilters[i]->group_name);
+        virXMLFormatElement(&throttleChildBuf, "throttlefilter", &throttleAttrBuf, NULL);
+    }
+    virXMLFormatElement(buf, "throttlefilters", NULL, &throttleChildBuf);
+}
+
+
 static void
 virDomainDiskDefFormatDriver(virBuffer *buf,
                              virDomainDiskDef *disk)
@@ -23212,6 +23305,8 @@ virDomainDiskDefFormat(virBuffer *buf,
 
     virDomainDiskDefFormatIotune(&childBuf, def);
 
+    virDomainDiskDefFormatThrottleFilters(&childBuf, def);
+
     if (def->src->readonly)
         virBufferAddLit(&childBuf, "<readonly/>\n");
     if (def->src->shared)
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index c9e3fcd924..952fe7f567 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -518,6 +518,15 @@ void virDomainDiskIothreadDefFree(virDomainDiskIothreadDef *def);
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainDiskIothreadDef, virDomainDiskIothreadDefFree);
 
 
+/* Stores information related to a ThrottleFilter resource. */
+struct _virDomainThrottleFilterDef {
+    char *group_name;
+    /* those below are internal fields used for runtime by qemu */
+    unsigned int id; /* throttle filter identifier, 0 is unset */
+    char *nodename;  /* node name of throttle filter object */
+};
+
+
 /* Stores the virtual disk configuration */
 struct _virDomainDiskDef {
     virStorageSource *src; /* non-NULL.  XXX Allow NULL for empty cdrom? */
@@ -550,6 +559,9 @@ struct _virDomainDiskDef {
 
     virDomainBlockIoTuneInfo blkdeviotune;
 
+    size_t nthrottlefilters;
+    virDomainThrottleFilterDef **throttlefilters;
+
     char *driverName;
 
     char *serial;
@@ -4543,3 +4555,11 @@ virDomainThrottleGroupByName(virDomainDef *def,
 void
 virDomainThrottleGroupDefCopy(const virDomainThrottleGroupDef *src,
                               virDomainThrottleGroupDef *dst);
+
+void
+virDomainThrottleFilterDefFree(virDomainThrottleFilterDef *def);
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainThrottleFilterDef, virDomainThrottleFilterDefFree);
+
+virDomainThrottleFilterDef *
+virDomainThrottleFilterFind(const virDomainDiskDef *def,
+                            const char *name);
diff --git a/src/conf/virconftypes.h b/src/conf/virconftypes.h
index d51e8f5f40..1cf68b2814 100644
--- a/src/conf/virconftypes.h
+++ b/src/conf/virconftypes.h
@@ -82,6 +82,8 @@ typedef struct _virDomainBlockIoTuneInfo virDomainBlockIoTuneInfo;
 
 typedef struct _virDomainBlockIoTuneInfo  virDomainThrottleGroupDef;
 
+typedef struct _virDomainThrottleFilterDef  virDomainThrottleFilterDef;
+
 typedef struct _virDomainCheckpointDef virDomainCheckpointDef;
 
 typedef struct _virDomainCheckpointObj virDomainCheckpointObj;
-- 
2.34.1



[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