vircgroup: extract virCgroupV1GetMemoryUsage

Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
Pavel Hrdina 2018-08-17 15:56:33 +02:00
parent 64bfbd7ceb
commit e92f8bad66
3 changed files with 22 additions and 8 deletions

View File

@ -1633,14 +1633,7 @@ virCgroupGetMemoryStat(virCgroupPtr group,
int
virCgroupGetMemoryUsage(virCgroupPtr group, unsigned long *kb)
{
long long unsigned int usage_in_bytes;
int ret;
ret = virCgroupGetValueU64(group,
VIR_CGROUP_CONTROLLER_MEMORY,
"memory.usage_in_bytes", &usage_in_bytes);
if (ret == 0)
*kb = (unsigned long) usage_in_bytes >> 10;
return ret;
VIR_CGROUP_BACKEND_CALL(group, getMemoryUsage, -1, kb);
}

View File

@ -223,6 +223,10 @@ typedef int
unsigned long long *inactiveFile,
unsigned long long *unevictable);
typedef int
(*virCgroupGetMemoryUsageCB)(virCgroupPtr group,
unsigned long *kb);
struct _virCgroupBackend {
virCgroupBackendType type;
@ -264,6 +268,7 @@ struct _virCgroupBackend {
virCgroupSetMemoryCB setMemory;
virCgroupGetMemoryStatCB getMemoryStat;
virCgroupGetMemoryUsageCB getMemoryUsage;
};
typedef struct _virCgroupBackend virCgroupBackend;
typedef virCgroupBackend *virCgroupBackendPtr;

View File

@ -1478,6 +1478,21 @@ virCgroupV1GetMemoryStat(virCgroupPtr group,
}
static int
virCgroupV1GetMemoryUsage(virCgroupPtr group,
unsigned long *kb)
{
long long unsigned int usage_in_bytes;
int ret;
ret = virCgroupGetValueU64(group,
VIR_CGROUP_CONTROLLER_MEMORY,
"memory.usage_in_bytes", &usage_in_bytes);
if (ret == 0)
*kb = (unsigned long) usage_in_bytes >> 10;
return ret;
}
virCgroupBackend virCgroupV1Backend = {
.type = VIR_CGROUP_BACKEND_TYPE_V1,
@ -1517,6 +1532,7 @@ virCgroupBackend virCgroupV1Backend = {
.setMemory = virCgroupV1SetMemory,
.getMemoryStat = virCgroupV1GetMemoryStat,
.getMemoryUsage = virCgroupV1GetMemoryUsage,
};