提交 8cbb0c76 编写于 作者: P Pavel Hrdina

vircgroup: extract virCgroupV1(Allow|Deny)Device

Reviewed-by: NFabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
Signed-off-by: NPavel Hrdina <phrdina@redhat.com>
上级 87d9fc5b
...@@ -1871,29 +1871,7 @@ int ...@@ -1871,29 +1871,7 @@ int
virCgroupAllowDevice(virCgroupPtr group, char type, int major, int minor, virCgroupAllowDevice(virCgroupPtr group, char type, int major, int minor,
int perms) int perms)
{ {
VIR_AUTOFREE(char *) devstr = NULL; VIR_CGROUP_BACKEND_CALL(group, allowDevice, -1, type, major, minor, perms);
VIR_AUTOFREE(char *) majorstr = NULL;
VIR_AUTOFREE(char *) minorstr = NULL;
if ((major < 0 && VIR_STRDUP(majorstr, "*") < 0) ||
(major >= 0 && virAsprintf(&majorstr, "%i", major) < 0))
return -1;
if ((minor < 0 && VIR_STRDUP(minorstr, "*") < 0) ||
(minor >= 0 && virAsprintf(&minorstr, "%i", minor) < 0))
return -1;
if (virAsprintf(&devstr, "%c %s:%s %s", type, majorstr, minorstr,
virCgroupGetDevicePermsString(perms)) < 0)
return -1;
if (virCgroupSetValueStr(group,
VIR_CGROUP_CONTROLLER_DEVICES,
"devices.allow",
devstr) < 0)
return -1;
return 0;
} }
...@@ -1932,11 +1910,11 @@ virCgroupAllowDevicePath(virCgroupPtr group, ...@@ -1932,11 +1910,11 @@ virCgroupAllowDevicePath(virCgroupPtr group,
if (!S_ISCHR(sb.st_mode) && !S_ISBLK(sb.st_mode)) if (!S_ISCHR(sb.st_mode) && !S_ISBLK(sb.st_mode))
return 1; return 1;
return virCgroupAllowDevice(group, VIR_CGROUP_BACKEND_CALL(group, allowDevice, -1,
S_ISCHR(sb.st_mode) ? 'c' : 'b', S_ISCHR(sb.st_mode) ? 'c' : 'b',
major(sb.st_rdev), major(sb.st_rdev),
minor(sb.st_rdev), minor(sb.st_rdev),
perms); perms);
} }
...@@ -1955,29 +1933,7 @@ int ...@@ -1955,29 +1933,7 @@ int
virCgroupDenyDevice(virCgroupPtr group, char type, int major, int minor, virCgroupDenyDevice(virCgroupPtr group, char type, int major, int minor,
int perms) int perms)
{ {
VIR_AUTOFREE(char *) devstr = NULL; VIR_CGROUP_BACKEND_CALL(group, denyDevice, -1, type, major, minor, perms);
VIR_AUTOFREE(char *) majorstr = NULL;
VIR_AUTOFREE(char *) minorstr = NULL;
if ((major < 0 && VIR_STRDUP(majorstr, "*") < 0) ||
(major >= 0 && virAsprintf(&majorstr, "%i", major) < 0))
return -1;
if ((minor < 0 && VIR_STRDUP(minorstr, "*") < 0) ||
(minor >= 0 && virAsprintf(&minorstr, "%i", minor) < 0))
return -1;
if (virAsprintf(&devstr, "%c %s:%s %s", type, majorstr, minorstr,
virCgroupGetDevicePermsString(perms)) < 0)
return -1;
if (virCgroupSetValueStr(group,
VIR_CGROUP_CONTROLLER_DEVICES,
"devices.deny",
devstr) < 0)
return -1;
return 0;
} }
...@@ -2016,11 +1972,11 @@ virCgroupDenyDevicePath(virCgroupPtr group, ...@@ -2016,11 +1972,11 @@ virCgroupDenyDevicePath(virCgroupPtr group,
if (!S_ISCHR(sb.st_mode) && !S_ISBLK(sb.st_mode)) if (!S_ISCHR(sb.st_mode) && !S_ISBLK(sb.st_mode))
return 1; return 1;
return virCgroupDenyDevice(group, VIR_CGROUP_BACKEND_CALL(group, denyDevice, -1,
S_ISCHR(sb.st_mode) ? 'c' : 'b', S_ISCHR(sb.st_mode) ? 'c' : 'b',
major(sb.st_rdev), major(sb.st_rdev),
minor(sb.st_rdev), minor(sb.st_rdev),
perms); perms);
} }
......
...@@ -255,6 +255,20 @@ typedef int ...@@ -255,6 +255,20 @@ typedef int
(*virCgroupGetMemSwapUsageCB)(virCgroupPtr group, (*virCgroupGetMemSwapUsageCB)(virCgroupPtr group,
unsigned long long *kb); unsigned long long *kb);
typedef int
(*virCgroupAllowDeviceCB)(virCgroupPtr group,
char type,
int major,
int minor,
int perms);
typedef int
(*virCgroupDenyDeviceCB)(virCgroupPtr group,
char type,
int major,
int minor,
int perms);
struct _virCgroupBackend { struct _virCgroupBackend {
virCgroupBackendType type; virCgroupBackendType type;
...@@ -304,6 +318,9 @@ struct _virCgroupBackend { ...@@ -304,6 +318,9 @@ struct _virCgroupBackend {
virCgroupSetMemSwapHardLimitCB setMemSwapHardLimit; virCgroupSetMemSwapHardLimitCB setMemSwapHardLimit;
virCgroupGetMemSwapHardLimitCB getMemSwapHardLimit; virCgroupGetMemSwapHardLimitCB getMemSwapHardLimit;
virCgroupGetMemSwapUsageCB getMemSwapUsage; virCgroupGetMemSwapUsageCB getMemSwapUsage;
virCgroupAllowDeviceCB allowDevice;
virCgroupDenyDeviceCB denyDevice;
}; };
typedef struct _virCgroupBackend virCgroupBackend; typedef struct _virCgroupBackend virCgroupBackend;
typedef virCgroupBackend *virCgroupBackendPtr; typedef virCgroupBackend *virCgroupBackendPtr;
......
...@@ -1670,6 +1670,72 @@ virCgroupV1GetMemSwapUsage(virCgroupPtr group, ...@@ -1670,6 +1670,72 @@ virCgroupV1GetMemSwapUsage(virCgroupPtr group,
} }
static int
virCgroupV1AllowDevice(virCgroupPtr group,
char type,
int major,
int minor,
int perms)
{
VIR_AUTOFREE(char *) devstr = NULL;
VIR_AUTOFREE(char *) majorstr = NULL;
VIR_AUTOFREE(char *) minorstr = NULL;
if ((major < 0 && VIR_STRDUP(majorstr, "*") < 0) ||
(major >= 0 && virAsprintf(&majorstr, "%i", major) < 0))
return -1;
if ((minor < 0 && VIR_STRDUP(minorstr, "*") < 0) ||
(minor >= 0 && virAsprintf(&minorstr, "%i", minor) < 0))
return -1;
if (virAsprintf(&devstr, "%c %s:%s %s", type, majorstr, minorstr,
virCgroupGetDevicePermsString(perms)) < 0)
return -1;
if (virCgroupSetValueStr(group,
VIR_CGROUP_CONTROLLER_DEVICES,
"devices.allow",
devstr) < 0)
return -1;
return 0;
}
static int
virCgroupV1DenyDevice(virCgroupPtr group,
char type,
int major,
int minor,
int perms)
{
VIR_AUTOFREE(char *) devstr = NULL;
VIR_AUTOFREE(char *) majorstr = NULL;
VIR_AUTOFREE(char *) minorstr = NULL;
if ((major < 0 && VIR_STRDUP(majorstr, "*") < 0) ||
(major >= 0 && virAsprintf(&majorstr, "%i", major) < 0))
return -1;
if ((minor < 0 && VIR_STRDUP(minorstr, "*") < 0) ||
(minor >= 0 && virAsprintf(&minorstr, "%i", minor) < 0))
return -1;
if (virAsprintf(&devstr, "%c %s:%s %s", type, majorstr, minorstr,
virCgroupGetDevicePermsString(perms)) < 0)
return -1;
if (virCgroupSetValueStr(group,
VIR_CGROUP_CONTROLLER_DEVICES,
"devices.deny",
devstr) < 0)
return -1;
return 0;
}
virCgroupBackend virCgroupV1Backend = { virCgroupBackend virCgroupV1Backend = {
.type = VIR_CGROUP_BACKEND_TYPE_V1, .type = VIR_CGROUP_BACKEND_TYPE_V1,
...@@ -1717,6 +1783,9 @@ virCgroupBackend virCgroupV1Backend = { ...@@ -1717,6 +1783,9 @@ virCgroupBackend virCgroupV1Backend = {
.setMemSwapHardLimit = virCgroupV1SetMemSwapHardLimit, .setMemSwapHardLimit = virCgroupV1SetMemSwapHardLimit,
.getMemSwapHardLimit = virCgroupV1GetMemSwapHardLimit, .getMemSwapHardLimit = virCgroupV1GetMemSwapHardLimit,
.getMemSwapUsage = virCgroupV1GetMemSwapUsage, .getMemSwapUsage = virCgroupV1GetMemSwapUsage,
.allowDevice = virCgroupV1AllowDevice,
.denyDevice = virCgroupV1DenyDevice,
}; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册