[PATCH 5/8] util: Extract path formatting into virResctrlAllocDeterminePath

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

 



We can use this from more places later, so just a future code de-duplication.

Signed-off-by: Martin Kletzander <mkletzan@xxxxxxxxxx>
---
 src/libvirt_private.syms |  1 +
 src/util/virresctrl.c    | 29 ++++++++++++++++++++---------
 src/util/virresctrl.h    |  4 ++++
 3 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 792fb60568bd..9339c2c3259d 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2560,6 +2560,7 @@ virCacheTypeFromString;
 virCacheTypeToString;
 virResctrlAllocAddPID;
 virResctrlAllocCreate;
+virResctrlAllocDeterminePath;
 virResctrlAllocForeachSize;
 virResctrlAllocFormat;
 virResctrlAllocGetID;
diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c
index 14a3c459ffd3..fefca32a6710 100644
--- a/src/util/virresctrl.c
+++ b/src/util/virresctrl.c
@@ -1503,6 +1503,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
@@ -1524,15 +1543,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)) {
diff --git a/src/util/virresctrl.h b/src/util/virresctrl.h
index 63a954feaad1..5368ba211924 100644
--- a/src/util/virresctrl.h
+++ b/src/util/virresctrl.h
@@ -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,
-- 
2.16.1

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