You need to sign in or sign up before continuing.
提交 5436fd75 编写于 作者: P Pavel Hrdina

vircgroup: extract virCgroupV1(Set|Get)CpuCfsQuota

Reviewed-by: NFabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
Signed-off-by: NPavel Hrdina <phrdina@redhat.com>
上级 c840448e
...@@ -555,7 +555,7 @@ virCgroupSetValueI64(virCgroupPtr group, ...@@ -555,7 +555,7 @@ virCgroupSetValueI64(virCgroupPtr group,
} }
static int int
virCgroupGetValueI64(virCgroupPtr group, virCgroupGetValueI64(virCgroupPtr group,
int controller, int controller,
const char *key, const char *key,
...@@ -2254,19 +2254,7 @@ virCgroupGetCpuCfsPeriod(virCgroupPtr group, unsigned long long *cfs_period) ...@@ -2254,19 +2254,7 @@ virCgroupGetCpuCfsPeriod(virCgroupPtr group, unsigned long long *cfs_period)
int int
virCgroupSetCpuCfsQuota(virCgroupPtr group, long long cfs_quota) virCgroupSetCpuCfsQuota(virCgroupPtr group, long long cfs_quota)
{ {
/* The cfs_quota should be greater or equal than 1ms */ VIR_CGROUP_BACKEND_CALL(group, setCpuCfsQuota, -1, cfs_quota);
if (cfs_quota >= 0 &&
(cfs_quota < 1000 ||
cfs_quota > ULLONG_MAX / 1000)) {
virReportError(VIR_ERR_INVALID_ARG,
_("cfs_quota '%lld' must be in range (1000, %llu)"),
cfs_quota, ULLONG_MAX / 1000);
return -1;
}
return virCgroupSetValueI64(group,
VIR_CGROUP_CONTROLLER_CPU,
"cpu.cfs_quota_us", cfs_quota);
} }
...@@ -2590,9 +2578,7 @@ virCgroupKillPainfully(virCgroupPtr group) ...@@ -2590,9 +2578,7 @@ virCgroupKillPainfully(virCgroupPtr group)
int int
virCgroupGetCpuCfsQuota(virCgroupPtr group, long long *cfs_quota) virCgroupGetCpuCfsQuota(virCgroupPtr group, long long *cfs_quota)
{ {
return virCgroupGetValueI64(group, VIR_CGROUP_BACKEND_CALL(group, getCpuCfsQuota, -1, cfs_quota);
VIR_CGROUP_CONTROLLER_CPU,
"cpu.cfs_quota_us", cfs_quota);
} }
......
...@@ -292,6 +292,14 @@ typedef int ...@@ -292,6 +292,14 @@ typedef int
(*virCgroupGetCpuCfsPeriodCB)(virCgroupPtr group, (*virCgroupGetCpuCfsPeriodCB)(virCgroupPtr group,
unsigned long long *cfs_period); unsigned long long *cfs_period);
typedef int
(*virCgroupSetCpuCfsQuotaCB)(virCgroupPtr group,
long long cfs_quota);
typedef int
(*virCgroupGetCpuCfsQuotaCB)(virCgroupPtr group,
long long *cfs_quota);
struct _virCgroupBackend { struct _virCgroupBackend {
virCgroupBackendType type; virCgroupBackendType type;
...@@ -351,6 +359,8 @@ struct _virCgroupBackend { ...@@ -351,6 +359,8 @@ struct _virCgroupBackend {
virCgroupGetCpuSharesCB getCpuShares; virCgroupGetCpuSharesCB getCpuShares;
virCgroupSetCpuCfsPeriodCB setCpuCfsPeriod; virCgroupSetCpuCfsPeriodCB setCpuCfsPeriod;
virCgroupGetCpuCfsPeriodCB getCpuCfsPeriod; virCgroupGetCpuCfsPeriodCB getCpuCfsPeriod;
virCgroupSetCpuCfsQuotaCB setCpuCfsQuota;
virCgroupGetCpuCfsQuotaCB getCpuCfsQuota;
}; };
typedef struct _virCgroupBackend virCgroupBackend; typedef struct _virCgroupBackend virCgroupBackend;
typedef virCgroupBackend *virCgroupBackendPtr; typedef virCgroupBackend *virCgroupBackendPtr;
......
...@@ -78,6 +78,11 @@ int virCgroupSetValueI64(virCgroupPtr group, ...@@ -78,6 +78,11 @@ int virCgroupSetValueI64(virCgroupPtr group,
const char *key, const char *key,
long long int value); long long int value);
int virCgroupGetValueI64(virCgroupPtr group,
int controller,
const char *key,
long long int *value);
int virCgroupPartitionEscape(char **path); int virCgroupPartitionEscape(char **path);
char *virCgroupGetBlockDevString(const char *path); char *virCgroupGetBlockDevString(const char *path);
......
...@@ -1815,6 +1815,36 @@ virCgroupV1GetCpuCfsPeriod(virCgroupPtr group, ...@@ -1815,6 +1815,36 @@ virCgroupV1GetCpuCfsPeriod(virCgroupPtr group,
} }
static int
virCgroupV1SetCpuCfsQuota(virCgroupPtr group,
long long cfs_quota)
{
/* The cfs_quota should be greater or equal than 1ms */
if (cfs_quota >= 0 &&
(cfs_quota < 1000 ||
cfs_quota > ULLONG_MAX / 1000)) {
virReportError(VIR_ERR_INVALID_ARG,
_("cfs_quota '%lld' must be in range (1000, %llu)"),
cfs_quota, ULLONG_MAX / 1000);
return -1;
}
return virCgroupSetValueI64(group,
VIR_CGROUP_CONTROLLER_CPU,
"cpu.cfs_quota_us", cfs_quota);
}
static int
virCgroupV1GetCpuCfsQuota(virCgroupPtr group,
long long *cfs_quota)
{
return virCgroupGetValueI64(group,
VIR_CGROUP_CONTROLLER_CPU,
"cpu.cfs_quota_us", cfs_quota);
}
virCgroupBackend virCgroupV1Backend = { virCgroupBackend virCgroupV1Backend = {
.type = VIR_CGROUP_BACKEND_TYPE_V1, .type = VIR_CGROUP_BACKEND_TYPE_V1,
...@@ -1872,6 +1902,8 @@ virCgroupBackend virCgroupV1Backend = { ...@@ -1872,6 +1902,8 @@ virCgroupBackend virCgroupV1Backend = {
.getCpuShares = virCgroupV1GetCpuShares, .getCpuShares = virCgroupV1GetCpuShares,
.setCpuCfsPeriod = virCgroupV1SetCpuCfsPeriod, .setCpuCfsPeriod = virCgroupV1SetCpuCfsPeriod,
.getCpuCfsPeriod = virCgroupV1GetCpuCfsPeriod, .getCpuCfsPeriod = virCgroupV1GetCpuCfsPeriod,
.setCpuCfsQuota = virCgroupV1SetCpuCfsQuota,
.getCpuCfsQuota = virCgroupV1GetCpuCfsQuota,
}; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册