]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: Refactor virResctrlAllocSetID to set allocation ID
authorWang Huaqiang <huaqiang.wang@intel.com>
Mon, 12 Nov 2018 13:31:40 +0000 (21:31 +0800)
committerJohn Ferlan <jferlan@redhat.com>
Wed, 14 Nov 2018 17:18:46 +0000 (12:18 -0500)
Refactor virResctrlAllocSetID generating an error if an attempt
is made to overwrite the existing value.

Signed-off-by: Wang Huaqiang <huaqiang.wang@intel.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
src/util/virresctrl.c

index 3a8b6e2cf0071f3e24f5fd62abca70fa5b340275..90eda726f87c84706fd7dbc51e0167d1fdcfb998 100644 (file)
@@ -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);
 }