[libvirt] [PATCHv7 07/18] util: Refactor code for creating resctrl group

Wang Huaqiang posted 18 patches 5 years, 4 months ago
[libvirt] [PATCHv7 07/18] util: Refactor code for creating resctrl group
Posted by Wang Huaqiang 5 years, 4 months ago
The code for creating resctrl allocation group could be reused
for monitoring group, refactor it for reuse in the later patch.

Signed-off-by: Wang Huaqiang <huaqiang.wang@intel.com>
---
 src/util/virresctrl.c | 37 +++++++++++++++++++++++--------------
 1 file changed, 23 insertions(+), 14 deletions(-)

diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c
index 93b5e70..5b984d9 100644
--- a/src/util/virresctrl.c
+++ b/src/util/virresctrl.c
@@ -2315,6 +2315,26 @@ virResctrlAllocDeterminePath(virResctrlAllocPtr alloc,
 }
 
 
+/* This function creates a resctrl directory in resource control file system,
+ * and the directory path is specified by @path. */
+static int
+virResctrlCreateGroupPath(const char *path)
+{
+    /* Directory exists, return */
+    if (virFileExists(path))
+        return 0;
+
+    if (virFileMakePath(path) < 0) {
+        virReportSystemError(errno,
+                             _("Cannot create resctrl directory '%s'"),
+                             path);
+        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
@@ -2344,13 +2364,6 @@ virResctrlAllocCreate(virResctrlInfoPtr resctrl,
     if (virResctrlAllocIsEmpty(alloc))
         return 0;
 
-    if (virFileExists(alloc->path)) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("Path '%s' for resctrl allocation exists"),
-                       alloc->path);
-        goto cleanup;
-    }
-
     lockfd = virResctrlLockWrite();
     if (lockfd < 0)
         goto cleanup;
@@ -2358,6 +2371,9 @@ virResctrlAllocCreate(virResctrlInfoPtr resctrl,
     if (virResctrlAllocAssign(resctrl, alloc) < 0)
         goto cleanup;
 
+    if (virResctrlCreateGroupPath(alloc->path) < 0)
+        goto cleanup;
+
     alloc_str = virResctrlAllocFormat(alloc);
     if (!alloc_str)
         goto cleanup;
@@ -2365,13 +2381,6 @@ virResctrlAllocCreate(virResctrlInfoPtr resctrl,
     if (virAsprintf(&schemata_path, "%s/schemata", alloc->path) < 0)
         goto cleanup;
 
-    if (virFileMakePath(alloc->path) < 0) {
-        virReportSystemError(errno,
-                             _("Cannot create resctrl directory '%s'"),
-                             alloc->path);
-        goto cleanup;
-    }
-
     VIR_DEBUG("Writing resctrl schemata '%s' into '%s'", alloc_str, schemata_path);
     if (virFileWriteStr(schemata_path, alloc_str, 0) < 0) {
         rmdir(alloc->path);
-- 
2.7.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCHv7 07/18] util: Refactor code for creating resctrl group
Posted by John Ferlan 5 years, 3 months ago

On 10/22/18 4:01 AM, Wang Huaqiang wrote:
> The code for creating resctrl allocation group could be reused
> for monitoring group, refactor it for reuse in the later patch.
> 
> Signed-off-by: Wang Huaqiang <huaqiang.wang@intel.com>
> ---
>  src/util/virresctrl.c | 37 +++++++++++++++++++++++--------------
>  1 file changed, 23 insertions(+), 14 deletions(-)
> 

Reviewed-by: John Ferlan <jferlan@redhat.com>

John

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list