提交 53f43deb 编写于 作者: P Pavel Hrdina

vircgroup: extract virCgroupV1SetMemory

Reviewed-by: NFabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
Signed-off-by: NPavel Hrdina <phrdina@redhat.com>
上级 02fe32d3
...@@ -1589,25 +1589,7 @@ virCgroupGetMemoryUnlimitedKB(void) ...@@ -1589,25 +1589,7 @@ virCgroupGetMemoryUnlimitedKB(void)
int int
virCgroupSetMemory(virCgroupPtr group, unsigned long long kb) virCgroupSetMemory(virCgroupPtr group, unsigned long long kb)
{ {
unsigned long long maxkb = VIR_DOMAIN_MEMORY_PARAM_UNLIMITED; VIR_CGROUP_BACKEND_CALL(group, setMemory, -1, kb);
if (kb > maxkb) {
virReportError(VIR_ERR_INVALID_ARG,
_("Memory '%llu' must be less than %llu"),
kb, maxkb);
return -1;
}
if (kb == maxkb)
return virCgroupSetValueI64(group,
VIR_CGROUP_CONTROLLER_MEMORY,
"memory.limit_in_bytes",
-1);
else
return virCgroupSetValueU64(group,
VIR_CGROUP_CONTROLLER_MEMORY,
"memory.limit_in_bytes",
kb << 10);
} }
......
...@@ -210,6 +210,10 @@ typedef int ...@@ -210,6 +210,10 @@ typedef int
const char *path, const char *path,
unsigned long long *wbps); unsigned long long *wbps);
typedef int
(*virCgroupSetMemoryCB)(virCgroupPtr group,
unsigned long long kb);
struct _virCgroupBackend { struct _virCgroupBackend {
virCgroupBackendType type; virCgroupBackendType type;
...@@ -248,6 +252,8 @@ struct _virCgroupBackend { ...@@ -248,6 +252,8 @@ struct _virCgroupBackend {
virCgroupGetBlkioDeviceReadBpsCB getBlkioDeviceReadBps; virCgroupGetBlkioDeviceReadBpsCB getBlkioDeviceReadBps;
virCgroupSetBlkioDeviceWriteBpsCB setBlkioDeviceWriteBps; virCgroupSetBlkioDeviceWriteBpsCB setBlkioDeviceWriteBps;
virCgroupGetBlkioDeviceWriteBpsCB getBlkioDeviceWriteBps; virCgroupGetBlkioDeviceWriteBpsCB getBlkioDeviceWriteBps;
virCgroupSetMemoryCB setMemory;
}; };
typedef struct _virCgroupBackend virCgroupBackend; typedef struct _virCgroupBackend virCgroupBackend;
typedef virCgroupBackend *virCgroupBackendPtr; typedef virCgroupBackend *virCgroupBackendPtr;
......
...@@ -1377,6 +1377,32 @@ virCgroupV1GetBlkioDeviceWriteBps(virCgroupPtr group, ...@@ -1377,6 +1377,32 @@ virCgroupV1GetBlkioDeviceWriteBps(virCgroupPtr group,
} }
static int
virCgroupV1SetMemory(virCgroupPtr group,
unsigned long long kb)
{
unsigned long long maxkb = VIR_DOMAIN_MEMORY_PARAM_UNLIMITED;
if (kb > maxkb) {
virReportError(VIR_ERR_INVALID_ARG,
_("Memory '%llu' must be less than %llu"),
kb, maxkb);
return -1;
}
if (kb == maxkb)
return virCgroupSetValueI64(group,
VIR_CGROUP_CONTROLLER_MEMORY,
"memory.limit_in_bytes",
-1);
else
return virCgroupSetValueU64(group,
VIR_CGROUP_CONTROLLER_MEMORY,
"memory.limit_in_bytes",
kb << 10);
}
virCgroupBackend virCgroupV1Backend = { virCgroupBackend virCgroupV1Backend = {
.type = VIR_CGROUP_BACKEND_TYPE_V1, .type = VIR_CGROUP_BACKEND_TYPE_V1,
...@@ -1413,6 +1439,8 @@ virCgroupBackend virCgroupV1Backend = { ...@@ -1413,6 +1439,8 @@ virCgroupBackend virCgroupV1Backend = {
.getBlkioDeviceReadBps = virCgroupV1GetBlkioDeviceReadBps, .getBlkioDeviceReadBps = virCgroupV1GetBlkioDeviceReadBps,
.setBlkioDeviceWriteBps = virCgroupV1SetBlkioDeviceWriteBps, .setBlkioDeviceWriteBps = virCgroupV1SetBlkioDeviceWriteBps,
.getBlkioDeviceWriteBps = virCgroupV1GetBlkioDeviceWriteBps, .getBlkioDeviceWriteBps = virCgroupV1GetBlkioDeviceWriteBps,
.setMemory = virCgroupV1SetMemory,
}; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册