[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 07/19] vircgroup: introduce virCgroupV2DeviceReallocMap



This function will create a new BPF map and copy all existing rules from
old BPF map.  There is no way how to reallocate existing BPF map so we
need to create a new copy if we run out of space in current BPF map.

Signed-off-by: Pavel Hrdina <phrdina redhat com>
---
 src/util/vircgroupv2.c | 43 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
index ae9aafd9a4..d70eefd92f 100644
--- a/src/util/vircgroupv2.c
+++ b/src/util/vircgroupv2.c
@@ -1846,6 +1846,49 @@ virCgroupV2DeviceCreateMap(size_t size)
 }
 
 
+static int
+virCgroupV2DeviceReallocMap(int mapfd,
+                            size_t size)
+{
+    __u64 key = 0;
+    __u64 prevKey = 0;
+    int rc;
+    int newmapfd = virCgroupV2DeviceCreateMap(size);
+
+    VIR_DEBUG("realloc devices map mapfd:%d, size:%lu", mapfd, size);
+
+    if (newmapfd < 0)
+        return -1;
+
+    while ((rc = virBPFGetNextElem(mapfd, &prevKey, &key)) == 0) {
+        __u32 val = 0;
+
+        if (virBPFLookupElem(mapfd, &key, &val) < 0) {
+            virReportSystemError(errno, "%s",
+                                 _("failed to lookup device in old map"));
+            goto error;
+        }
+
+        if (virBPFUpdateElem(newmapfd, &key, &val) < 0) {
+            virReportSystemError(errno, "%s",
+                                 _("failed to add device into new map"));
+            goto error;
+        }
+
+        prevKey = key;
+    }
+
+    if (rc < 0)
+        goto error;
+
+    return newmapfd;
+
+ error:
+    VIR_FORCE_CLOSE(newmapfd);
+    return -1;
+}
+
+
 static int
 virCgroupV2DeviceCreateProg(virCgroupPtr group)
 {
-- 
2.20.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]