[libvirt] [PATCHv7 09/18] util: Add more interfaces for resctrl monitor

Wang Huaqiang posted 18 patches 5 years, 7 months ago
[libvirt] [PATCHv7 09/18] util: Add more interfaces for resctrl monitor
Posted by Wang Huaqiang 5 years, 7 months ago
Add interfaces monitor group to support operations such
as add PID, set ID, remove group ... etc.

Signed-off-by: Wang Huaqiang <huaqiang.wang@intel.com>
---
 src/libvirt_private.syms |  5 +++++
 src/util/virresctrl.c    | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 src/util/virresctrl.h    | 14 ++++++++++++++
 3 files changed, 66 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index a878083..d59ac86 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2683,7 +2683,12 @@ virResctrlInfoNew;
 virResctrlMonitorAddPID;
 virResctrlMonitorCreate;
 virResctrlMonitorDeterminePath;
+virResctrlMonitorGetID;
 virResctrlMonitorNew;
+virResctrlMonitorRemove;
+virResctrlMonitorSetAlloc;
+virResctrlMonitorSetID;
+
 
 
 # util/virrotatingfile.h
diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c
index 9f42065..b0205bc 100644
--- a/src/util/virresctrl.c
+++ b/src/util/virresctrl.c
@@ -2566,3 +2566,50 @@ virResctrlMonitorCreate(virResctrlMonitorPtr monitor,
     virResctrlUnlock(lockfd);
     return ret;
 }
+
+
+int
+virResctrlMonitorSetID(virResctrlMonitorPtr monitor,
+                       const char *id)
+{
+    if (!id) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("Resctrl monitor 'id' cannot be NULL"));
+        return -1;
+    }
+
+    return VIR_STRDUP(monitor->id, id);
+}
+
+
+const char *
+virResctrlMonitorGetID(virResctrlMonitorPtr monitor)
+{
+    return monitor->id;
+}
+
+
+void
+virResctrlMonitorSetAlloc(virResctrlMonitorPtr monitor,
+                          virResctrlAllocPtr alloc)
+{
+    monitor->alloc = virObjectRef(alloc);
+}
+
+
+int
+virResctrlMonitorRemove(virResctrlMonitorPtr monitor)
+{
+    int ret = 0;
+
+    if (!monitor->path)
+        return 0;
+
+    VIR_DEBUG("Removing resctrl monitor%s", monitor->path);
+    if (rmdir(monitor->path) != 0 && errno != ENOENT) {
+        ret = -errno;
+        VIR_ERROR(_("Unable to remove %s (%d)"), monitor->path, errno);
+    }
+
+    return ret;
+}
diff --git a/src/util/virresctrl.h b/src/util/virresctrl.h
index 76e40a2..804d6f5 100644
--- a/src/util/virresctrl.h
+++ b/src/util/virresctrl.h
@@ -205,4 +205,18 @@ virResctrlMonitorAddPID(virResctrlMonitorPtr monitor,
 int
 virResctrlMonitorCreate(virResctrlMonitorPtr monitor,
                         const char *machinename);
+
+int
+virResctrlMonitorSetID(virResctrlMonitorPtr monitor,
+                       const char *id);
+
+const char *
+virResctrlMonitorGetID(virResctrlMonitorPtr monitor);
+
+void
+virResctrlMonitorSetAlloc(virResctrlMonitorPtr monitor,
+                          virResctrlAllocPtr alloc);
+
+int
+virResctrlMonitorRemove(virResctrlMonitorPtr monitor);
 #endif /*  __VIR_RESCTRL_H__ */
-- 
2.7.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCHv7 09/18] util: Add more interfaces for resctrl monitor
Posted by John Ferlan 5 years, 6 months ago

On 10/22/18 4:01 AM, Wang Huaqiang wrote:
> Add interfaces monitor group to support operations such
> as add PID, set ID, remove group ... etc.
> 
> Signed-off-by: Wang Huaqiang <huaqiang.wang@intel.com>
> ---
>  src/libvirt_private.syms |  5 +++++
>  src/util/virresctrl.c    | 47 +++++++++++++++++++++++++++++++++++++++++++++++
>  src/util/virresctrl.h    | 14 ++++++++++++++
>  3 files changed, 66 insertions(+)
> 

[...]

> +int
> +virResctrlMonitorRemove(virResctrlMonitorPtr monitor)
> +{
> +    int ret = 0;
> +
> +    if (!monitor->path)
> +        return 0;

Similar to patch1 - if we are using a default path, then we don't want
to removed even if it exists, so I *think* (but you need to confirm for
me) that the following should be done:

    if (STREQ(monitor->path, monitor->alloc->path))
        return 0;

Although I wonder if a !monitor->alloc guard should be used as well.
Whether it's part of a || !monitor->path return 0 or this check should
be "if (monitor->alloc && STREQ(...))"... Thoughts?

> +
> +    VIR_DEBUG("Removing resctrl monitor%s", monitor->path);

s/monitor%s/monitor path='%s'

> +    if (rmdir(monitor->path) != 0 && errno != ENOENT) {
> +        ret = -errno;
> +        VIR_ERROR(_("Unable to remove %s (%d)"), monitor->path, errno);
> +    }
> +
> +    return ret;
> +}

I can make the changes - just let me know your preferred way to proceed...

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

John

[...]

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