[PATCH v2 01/14] vircgroup.c: adding virCgroupSetupBlkioDevice* helpers

Daniel Henrique Barboza posted 14 patches 4 years, 9 months ago
[PATCH v2 01/14] vircgroup.c: adding virCgroupSetupBlkioDevice* helpers
Posted by Daniel Henrique Barboza 4 years, 9 months ago
The current use of the functions that sets and gets
BlkioDevice attributes is doing a set(), following by
a get() of the same parameter right after. This is done
because there is no guarantee that the kernel will accept
the desired value given by the set() call, thus we need to
execute a get() right after to get the actual value.

This patch adds helpers inside vircgroup.c to execute these
operations. Next patch will use these helpers to reduce
code repetition in LXC and QEMU files.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
---
 src/libvirt_private.syms |  5 +++
 src/util/vircgroup.c     | 85 ++++++++++++++++++++++++++++++++++++++++
 src/util/vircgroup.h     | 20 ++++++++++
 3 files changed, 110 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 125d1836dd..e26bfab101 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1730,6 +1730,11 @@ virCgroupSetMemoryHardLimit;
 virCgroupSetMemorySoftLimit;
 virCgroupSetMemSwapHardLimit;
 virCgroupSetOwner;
+virCgroupSetupBlkioDeviceReadBps;
+virCgroupSetupBlkioDeviceReadIops;
+virCgroupSetupBlkioDeviceWeight;
+virCgroupSetupBlkioDeviceWriteBps;
+virCgroupSetupBlkioDeviceWriteIops;
 virCgroupSupportsCpuBW;
 virCgroupTerminateMachine;
 
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index 0680ff7c24..302352aca3 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -3581,3 +3581,88 @@ virCgroupDelThread(virCgroupPtr cgroup,
 
     return 0;
 }
+
+
+/**
+ * Calls virCgroupSetBlkioDeviceWeight() to set up blkio device weight,
+ * then retrieves the actual value set by the kernel with
+ * virCgroupGetBlkioDeviceWeight() in the same @weight pointer.
+ */
+int
+virCgroupSetupBlkioDeviceWeight(virCgroupPtr cgroup, const char *path,
+                                unsigned int *weight)
+{
+    if (virCgroupSetBlkioDeviceWeight(cgroup, path, *weight) < 0 ||
+        virCgroupGetBlkioDeviceWeight(cgroup, path, weight) < 0)
+        return -1;
+
+    return 0;
+}
+
+
+/**
+ * Calls virCgroupSetBlkioDeviceReadIops() to set up blkio device riops,
+ * then retrieves the actual value set by the kernel with
+ * virCgroupGetBlkioDeviceReadIops() in the same @riops pointer.
+ */
+int
+virCgroupSetupBlkioDeviceReadIops(virCgroupPtr cgroup, const char *path,
+                                  unsigned int *riops)
+{
+    if (virCgroupSetBlkioDeviceReadIops(cgroup, path, *riops) < 0 ||
+        virCgroupGetBlkioDeviceReadIops(cgroup, path, riops) < 0)
+        return -1;
+
+    return 0;
+}
+
+
+/**
+ * Calls virCgroupSetBlkioDeviceWriteIops() to set up blkio device wiops,
+ * then retrieves the actual value set by the kernel with
+ * virCgroupGetBlkioDeviceWriteIops() in the same @wiops pointer.
+ */
+int
+virCgroupSetupBlkioDeviceWriteIops(virCgroupPtr cgroup, const char *path,
+                                   unsigned int *wiops)
+{
+    if (virCgroupSetBlkioDeviceWriteIops(cgroup, path, *wiops) < 0 ||
+        virCgroupGetBlkioDeviceWriteIops(cgroup, path, wiops) < 0)
+        return -1;
+
+    return 0;
+}
+
+
+/**
+ * Calls virCgroupSetBlkioDeviceReadBps() to set up blkio device rbps,
+ * then retrieves the actual value set by the kernel with
+ * virCgroupGetBlkioDeviceReadBps() in the same @rbps pointer.
+ */
+int
+virCgroupSetupBlkioDeviceReadBps(virCgroupPtr cgroup, const char *path,
+                                 unsigned long long *rbps)
+{
+    if (virCgroupSetBlkioDeviceReadBps(cgroup, path, *rbps) < 0 ||
+        virCgroupGetBlkioDeviceReadBps(cgroup, path, rbps) < 0)
+        return -1;
+
+    return 0;
+}
+
+
+/**
+ * Calls virCgroupSetBlkioDeviceWriteBps() to set up blkio device wbps,
+ * then retrieves the actual value set by the kernel with
+ * virCgroupGetBlkioDeviceWriteBps() in the same @wbps pointer.
+ */
+int
+virCgroupSetupBlkioDeviceWriteBps(virCgroupPtr cgroup, const char *path,
+                                  unsigned long long *wbps)
+{
+    if (virCgroupSetBlkioDeviceWriteBps(cgroup, path, *wbps) < 0 ||
+        virCgroupGetBlkioDeviceWriteBps(cgroup, path, wbps) < 0)
+        return -1;
+
+    return 0;
+}
diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h
index 15263f534a..6bd3f4fe9d 100644
--- a/src/util/vircgroup.h
+++ b/src/util/vircgroup.h
@@ -175,6 +175,26 @@ int virCgroupGetBlkioDeviceWriteBps(virCgroupPtr group,
                                     const char *path,
                                     unsigned long long *wbps);
 
+int virCgroupSetupBlkioDeviceWeight(virCgroupPtr cgroup,
+                                    const char *path,
+                                    unsigned int *weight);
+
+int virCgroupSetupBlkioDeviceReadIops(virCgroupPtr cgroup,
+                                      const char *path,
+                                      unsigned int *riops);
+
+int virCgroupSetupBlkioDeviceWriteIops(virCgroupPtr cgroup,
+                                       const char *path,
+                                       unsigned int *wiops);
+
+int virCgroupSetupBlkioDeviceReadBps(virCgroupPtr cgroup,
+                                     const char *path,
+                                     unsigned long long *rbps);
+
+int virCgroupSetupBlkioDeviceWriteBps(virCgroupPtr cgroup,
+                                      const char *path,
+                                      unsigned long long *wbps);
+
 int virCgroupSetMemory(virCgroupPtr group, unsigned long long kb);
 int virCgroupGetMemoryStat(virCgroupPtr group,
                            unsigned long long *cache,
-- 
2.24.1


Re: [PATCH v2 01/14] vircgroup.c: adding virCgroupSetupBlkioDevice* helpers
Posted by Ján Tomko 4 years, 9 months ago
s/adding/add/

On Mon, Feb 17, 2020 at 04:29:08PM -0500, Daniel Henrique Barboza wrote:
>The current use of the functions that sets and gets

*set, *get

>BlkioDevice attributes is doing a set(), following by
>a get() of the same parameter right after. This is done
>because there is no guarantee that the kernel will accept
>the desired value given by the set() call, thus we need to
>execute a get() right after to get the actual value.
>
>This patch adds helpers inside vircgroup.c to execute these
>operations. Next patch will use these helpers to reduce
>code repetition in LXC and QEMU files.
>
>Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
>---
> src/libvirt_private.syms |  5 +++
> src/util/vircgroup.c     | 85 ++++++++++++++++++++++++++++++++++++++++
> src/util/vircgroup.h     | 20 ++++++++++
> 3 files changed, 110 insertions(+)
>

Reviewed-by: Ján Tomko <jtomko@redhat.com>

Jano