]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: Extract path formatting into virResctrlAllocDeterminePath
authorMartin Kletzander <mkletzan@redhat.com>
Tue, 30 Jan 2018 22:57:42 +0000 (23:57 +0100)
committerMartin Kletzander <mkletzan@redhat.com>
Wed, 31 Jan 2018 13:51:34 +0000 (14:51 +0100)
We can use this from more places later, so just a future code de-duplication.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
src/libvirt_private.syms
src/util/virresctrl.c
src/util/virresctrl.h

index 792fb60568bd7d7187d9f55625819e709ff1b89e..9339c2c3259da6912f11caf958ddc6cfa86edbce 100644 (file)
@@ -2560,6 +2560,7 @@ virCacheTypeFromString;
 virCacheTypeToString;
 virResctrlAllocAddPID;
 virResctrlAllocCreate;
+virResctrlAllocDeterminePath;
 virResctrlAllocForeachSize;
 virResctrlAllocFormat;
 virResctrlAllocGetID;
index fdd1ded6f76fe69f6a9bc79406b76c109e3b33e4..e1c4998f715171e309a13dad2bf52d2071bef03f 100644 (file)
@@ -1501,6 +1501,25 @@ virResctrlAllocMasksAssign(virResctrlInfoPtr resctrl,
 }
 
 
+int
+virResctrlAllocDeterminePath(virResctrlAllocPtr alloc,
+                             const char *machinename)
+{
+    if (!alloc->id) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("Resctrl Allocation ID must be set before creation"));
+        return -1;
+    }
+
+    if (!alloc->path &&
+        virAsprintf(&alloc->path, "%s/%s-%s",
+                    SYSFS_RESCTRL_PATH, machinename, alloc->id) < 0)
+        return -1;
+
+    return 0;
+}
+
+
 /* This checks if the directory for the alloc exists.  If not it tries to create
  * it and apply appropriate alloc settings. */
 int
@@ -1522,15 +1541,7 @@ virResctrlAllocCreate(virResctrlInfoPtr resctrl,
         return -1;
     }
 
-    if (!alloc->id) {
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("Resctrl Allocation ID must be set before creation"));
-        return -1;
-    }
-
-    if (!alloc->path &&
-        virAsprintf(&alloc->path, "%s/%s-%s",
-                    SYSFS_RESCTRL_PATH, machinename, alloc->id) < 0)
+    if (virResctrlAllocDeterminePath(alloc, machinename) < 0)
         return -1;
 
     if (virFileExists(alloc->path)) {
index 63a954feaad1facecf34e1444257bea3595409a2..5368ba211924acf7c49dea4aa9c118db7f856568 100644 (file)
@@ -102,6 +102,10 @@ virResctrlAllocGetID(virResctrlAllocPtr alloc);
 char *
 virResctrlAllocFormat(virResctrlAllocPtr alloc);
 
+int
+virResctrlAllocDeterminePath(virResctrlAllocPtr alloc,
+                             const char *machinename);
+
 int
 virResctrlAllocCreate(virResctrlInfoPtr r_info,
                       virResctrlAllocPtr alloc,