Blame SOURCES/libvirt-util-Extract-path-formatting-into-virResctrlAllocDeterminePath.patch

404507
From f2a6092c61d5ef0f2648529a8c141d5f85551da1 Mon Sep 17 00:00:00 2001
404507
Message-Id: <f2a6092c61d5ef0f2648529a8c141d5f85551da1@dist-git>
404507
From: Martin Kletzander <mkletzan@redhat.com>
404507
Date: Wed, 31 Jan 2018 16:32:44 +0100
404507
Subject: [PATCH] util: Extract path formatting into
404507
 virResctrlAllocDeterminePath
404507
404507
We can use this from more places later, so just a future code de-duplication.
404507
404507
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
404507
(cherry picked from commit b9ceacba7cd32eac55f383495319807430627b4c)
404507
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
404507
404507
https://bugzilla.redhat.com/show_bug.cgi?id=1289368
404507
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
404507
---
404507
 src/libvirt_private.syms |  1 +
404507
 src/util/virresctrl.c    | 29 ++++++++++++++++++++---------
404507
 src/util/virresctrl.h    |  4 ++++
404507
 3 files changed, 25 insertions(+), 9 deletions(-)
404507
404507
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
404507
index ee75e09767..9c64d0cb97 100644
404507
--- a/src/libvirt_private.syms
404507
+++ b/src/libvirt_private.syms
404507
@@ -2549,6 +2549,7 @@ virCacheTypeFromString;
404507
 virCacheTypeToString;
404507
 virResctrlAllocAddPID;
404507
 virResctrlAllocCreate;
404507
+virResctrlAllocDeterminePath;
404507
 virResctrlAllocForeachSize;
404507
 virResctrlAllocFormat;
404507
 virResctrlAllocGetID;
404507
diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c
404507
index fdd1ded6f7..e1c4998f71 100644
404507
--- a/src/util/virresctrl.c
404507
+++ b/src/util/virresctrl.c
404507
@@ -1501,6 +1501,25 @@ virResctrlAllocMasksAssign(virResctrlInfoPtr resctrl,
404507
 }
404507
 
404507
 
404507
+int
404507
+virResctrlAllocDeterminePath(virResctrlAllocPtr alloc,
404507
+                             const char *machinename)
404507
+{
404507
+    if (!alloc->id) {
404507
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
404507
+                       _("Resctrl Allocation ID must be set before creation"));
404507
+        return -1;
404507
+    }
404507
+
404507
+    if (!alloc->path &&
404507
+        virAsprintf(&alloc->path, "%s/%s-%s",
404507
+                    SYSFS_RESCTRL_PATH, machinename, alloc->id) < 0)
404507
+        return -1;
404507
+
404507
+    return 0;
404507
+}
404507
+
404507
+
404507
 /* This checks if the directory for the alloc exists.  If not it tries to create
404507
  * it and apply appropriate alloc settings. */
404507
 int
404507
@@ -1522,15 +1541,7 @@ virResctrlAllocCreate(virResctrlInfoPtr resctrl,
404507
         return -1;
404507
     }
404507
 
404507
-    if (!alloc->id) {
404507
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
404507
-                       _("Resctrl Allocation ID must be set before creation"));
404507
-        return -1;
404507
-    }
404507
-
404507
-    if (!alloc->path &&
404507
-        virAsprintf(&alloc->path, "%s/%s-%s",
404507
-                    SYSFS_RESCTRL_PATH, machinename, alloc->id) < 0)
404507
+    if (virResctrlAllocDeterminePath(alloc, machinename) < 0)
404507
         return -1;
404507
 
404507
     if (virFileExists(alloc->path)) {
404507
diff --git a/src/util/virresctrl.h b/src/util/virresctrl.h
404507
index 63a954feaa..5368ba2119 100644
404507
--- a/src/util/virresctrl.h
404507
+++ b/src/util/virresctrl.h
404507
@@ -102,6 +102,10 @@ virResctrlAllocGetID(virResctrlAllocPtr alloc);
404507
 char *
404507
 virResctrlAllocFormat(virResctrlAllocPtr alloc);
404507
 
404507
+int
404507
+virResctrlAllocDeterminePath(virResctrlAllocPtr alloc,
404507
+                             const char *machinename);
404507
+
404507
 int
404507
 virResctrlAllocCreate(virResctrlInfoPtr r_info,
404507
                       virResctrlAllocPtr alloc,
404507
-- 
404507
2.16.1
404507