提交 c57b0be0 编写于 作者: P Pavel Hrdina

vircgroup: extract virCgroupV1(Set|Get)BlkioWeight

Reviewed-by: NFabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
Signed-off-by: NPavel Hrdina <phrdina@redhat.com>
上级 dad06110
......@@ -1506,10 +1506,7 @@ virCgroupGetBlkioIoDeviceServiced(virCgroupPtr group,
int
virCgroupSetBlkioWeight(virCgroupPtr group, unsigned int weight)
{
return virCgroupSetValueU64(group,
VIR_CGROUP_CONTROLLER_BLKIO,
"blkio.weight",
weight);
VIR_CGROUP_BACKEND_CALL(group, setBlkioWeight, -1, weight);
}
......@@ -1524,14 +1521,7 @@ virCgroupSetBlkioWeight(virCgroupPtr group, unsigned int weight)
int
virCgroupGetBlkioWeight(virCgroupPtr group, unsigned int *weight)
{
unsigned long long tmp;
int ret;
ret = virCgroupGetValueU64(group,
VIR_CGROUP_CONTROLLER_BLKIO,
"blkio.weight", &tmp);
if (ret == 0)
*weight = tmp;
return ret;
VIR_CGROUP_BACKEND_CALL(group, getBlkioWeight, -1, weight);
}
/**
......
......@@ -137,6 +137,14 @@ typedef int
gid_t gid,
int controllers);
typedef int
(*virCgroupSetBlkioWeightCB)(virCgroupPtr group,
unsigned int weight);
typedef int
(*virCgroupGetBlkioWeightCB)(virCgroupPtr group,
unsigned int *weight);
struct _virCgroupBackend {
virCgroupBackendType type;
......@@ -159,6 +167,10 @@ struct _virCgroupBackend {
virCgroupHasEmptyTasksCB hasEmptyTasks;
virCgroupBindMountCB bindMount;
virCgroupSetOwnerCB setOwner;
/* Optional cgroup controller specific callbacks. */
virCgroupSetBlkioWeightCB setBlkioWeight;
virCgroupGetBlkioWeightCB getBlkioWeight;
};
typedef struct _virCgroupBackend virCgroupBackend;
typedef virCgroupBackend *virCgroupBackendPtr;
......@@ -169,4 +181,12 @@ virCgroupBackendRegister(virCgroupBackendPtr backend);
virCgroupBackendPtr *
virCgroupBackendGetAll(void);
# define VIR_CGROUP_BACKEND_CALL(group, func, ret, ...) \
if (!group->backend->func) { \
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, \
_("operation '%s' not supported"), #func); \
return ret; \
} \
return group->backend->func(group, ##__VA_ARGS__);
#endif /* __VIR_CGROUP_BACKEND_H__ */
......@@ -928,6 +928,32 @@ virCgroupV1SetOwner(virCgroupPtr cgroup,
}
static int
virCgroupV1SetBlkioWeight(virCgroupPtr group,
unsigned int weight)
{
return virCgroupSetValueU64(group,
VIR_CGROUP_CONTROLLER_BLKIO,
"blkio.weight",
weight);
}
static int
virCgroupV1GetBlkioWeight(virCgroupPtr group,
unsigned int *weight)
{
unsigned long long tmp;
int ret;
ret = virCgroupGetValueU64(group,
VIR_CGROUP_CONTROLLER_BLKIO,
"blkio.weight", &tmp);
if (ret == 0)
*weight = tmp;
return ret;
}
virCgroupBackend virCgroupV1Backend = {
.type = VIR_CGROUP_BACKEND_TYPE_V1,
......@@ -949,6 +975,9 @@ virCgroupBackend virCgroupV1Backend = {
.hasEmptyTasks = virCgroupV1HasEmptyTasks,
.bindMount = virCgroupV1BindMount,
.setOwner = virCgroupV1SetOwner,
.setBlkioWeight = virCgroupV1SetBlkioWeight,
.getBlkioWeight = virCgroupV1GetBlkioWeight,
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册