[PATCHv8 09/17] util: Refactor virResctrlAllocSetID to set allocation ID

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

 



Refactor virResctrlAllocSetID.
In new code the error of id overwriting is reported promptly.

Signed-off-by: Wang Huaqiang <huaqiang.wang@xxxxxxxxx>
---
 src/util/virresctrl.c | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c
index 3216abe..4e4831c 100644
--- a/src/util/virresctrl.c
+++ b/src/util/virresctrl.c
@@ -1361,17 +1361,32 @@ virResctrlAllocForeachMemory(virResctrlAllocPtr alloc,
 }
 
 
-int
-virResctrlAllocSetID(virResctrlAllocPtr alloc,
-                     const char *id)
+static int
+virResctrlSetID(char **resctrlid,
+                const char *id)
 {
     if (!id) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("Resctrl allocation 'id' cannot be NULL"));
+                       _("New resctrl 'id' cannot be NULL"));
+        return -1;
+    }
+
+    if (*resctrlid) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Attempt to overwrite resctrlid='%s' with id='%s'"),
+                       *resctrlid, id);
         return -1;
     }
 
-    return VIR_STRDUP(alloc->id, id);
+    return VIR_STRDUP(*resctrlid, id);
+}
+
+
+int
+virResctrlAllocSetID(virResctrlAllocPtr alloc,
+                     const char *id)
+{
+    return virResctrlSetID(&alloc->id, id);
 }
 
 
-- 
2.7.4

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