}
+/**
+ * virCgroupGetDevicePermsString:
+ *
+ * @perms: Bitwise or of VIR_CGROUP_DEVICE permission bits
+ *
+ * Returns string corresponding to the appropriate bits set.
+ */
+const char *
+virCgroupGetDevicePermsString(int perms)
+{
+ if (perms & VIR_CGROUP_DEVICE_READ) {
+ if (perms & VIR_CGROUP_DEVICE_WRITE) {
+ if (perms & VIR_CGROUP_DEVICE_MKNOD)
+ return "rwm";
+ else
+ return "rw";
+ } else {
+ if (perms & VIR_CGROUP_DEVICE_MKNOD)
+ return "rm";
+ else
+ return "r";
+ }
+ } else {
+ if (perms & VIR_CGROUP_DEVICE_WRITE) {
+ if (perms & VIR_CGROUP_DEVICE_MKNOD)
+ return "wm";
+ else
+ return "w";
+ } else {
+ if (perms & VIR_CGROUP_DEVICE_MKNOD)
+ return "m";
+ else
+ return "";
+ }
+ }
+}
+
+
/**
* virCgroupAllowDevice:
*
int ret = -1;
char *devstr = NULL;
- if (virAsprintf(&devstr, "%c %i:%i %s%s%s", type, major, minor,
- perms & VIR_CGROUP_DEVICE_READ ? "r" : "",
- perms & VIR_CGROUP_DEVICE_WRITE ? "w" : "",
- perms & VIR_CGROUP_DEVICE_MKNOD ? "m" : "") < 0)
+ if (virAsprintf(&devstr, "%c %i:%i %s", type, major, minor,
+ virCgroupGetDevicePermsString(perms)) < 0)
goto cleanup;
if (virCgroupSetValueStr(group,
int ret = -1;
char *devstr = NULL;
- if (virAsprintf(&devstr, "%c %i:* %s%s%s", type, major,
- perms & VIR_CGROUP_DEVICE_READ ? "r" : "",
- perms & VIR_CGROUP_DEVICE_WRITE ? "w" : "",
- perms & VIR_CGROUP_DEVICE_MKNOD ? "m" : "") < 0)
+ if (virAsprintf(&devstr, "%c %i:* %s", type, major,
+ virCgroupGetDevicePermsString(perms)) < 0)
goto cleanup;
if (virCgroupSetValueStr(group,
int ret = -1;
char *devstr = NULL;
- if (virAsprintf(&devstr, "%c %i:%i %s%s%s", type, major, minor,
- perms & VIR_CGROUP_DEVICE_READ ? "r" : "",
- perms & VIR_CGROUP_DEVICE_WRITE ? "w" : "",
- perms & VIR_CGROUP_DEVICE_MKNOD ? "m" : "") < 0)
+ if (virAsprintf(&devstr, "%c %i:%i %s", type, major, minor,
+ virCgroupGetDevicePermsString(perms)) < 0)
goto cleanup;
if (virCgroupSetValueStr(group,
int ret = -1;
char *devstr = NULL;
- if (virAsprintf(&devstr, "%c %i:* %s%s%s", type, major,
- perms & VIR_CGROUP_DEVICE_READ ? "r" : "",
- perms & VIR_CGROUP_DEVICE_WRITE ? "w" : "",
- perms & VIR_CGROUP_DEVICE_MKNOD ? "m" : "") < 0)
+ if (virAsprintf(&devstr, "%c %i:* %s", type, major,
+ virCgroupGetDevicePermsString(perms)) < 0)
goto cleanup;
if (virCgroupSetValueStr(group,