render / rpms / libvirt

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