1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

vircgroup: extract virCgroupV1(Set|Get)BlkioWeight

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:28:50 +02:00
parent dad061101d
commit c57b0be0cc
3 changed files with 51 additions and 12 deletions

View File

@ -1506,10 +1506,7 @@ virCgroupGetBlkioIoDeviceServiced(virCgroupPtr group,
int int
virCgroupSetBlkioWeight(virCgroupPtr group, unsigned int weight) virCgroupSetBlkioWeight(virCgroupPtr group, unsigned int weight)
{ {
return virCgroupSetValueU64(group, VIR_CGROUP_BACKEND_CALL(group, setBlkioWeight, -1, weight);
VIR_CGROUP_CONTROLLER_BLKIO,
"blkio.weight",
weight);
} }
@ -1524,14 +1521,7 @@ virCgroupSetBlkioWeight(virCgroupPtr group, unsigned int weight)
int int
virCgroupGetBlkioWeight(virCgroupPtr group, unsigned int *weight) virCgroupGetBlkioWeight(virCgroupPtr group, unsigned int *weight)
{ {
unsigned long long tmp; VIR_CGROUP_BACKEND_CALL(group, getBlkioWeight, -1, weight);
int ret;
ret = virCgroupGetValueU64(group,
VIR_CGROUP_CONTROLLER_BLKIO,
"blkio.weight", &tmp);
if (ret == 0)
*weight = tmp;
return ret;
} }
/** /**

View File

@ -137,6 +137,14 @@ typedef int
gid_t gid, gid_t gid,
int controllers); int controllers);
typedef int
(*virCgroupSetBlkioWeightCB)(virCgroupPtr group,
unsigned int weight);
typedef int
(*virCgroupGetBlkioWeightCB)(virCgroupPtr group,
unsigned int *weight);
struct _virCgroupBackend { struct _virCgroupBackend {
virCgroupBackendType type; virCgroupBackendType type;
@ -159,6 +167,10 @@ struct _virCgroupBackend {
virCgroupHasEmptyTasksCB hasEmptyTasks; virCgroupHasEmptyTasksCB hasEmptyTasks;
virCgroupBindMountCB bindMount; virCgroupBindMountCB bindMount;
virCgroupSetOwnerCB setOwner; virCgroupSetOwnerCB setOwner;
/* Optional cgroup controller specific callbacks. */
virCgroupSetBlkioWeightCB setBlkioWeight;
virCgroupGetBlkioWeightCB getBlkioWeight;
}; };
typedef struct _virCgroupBackend virCgroupBackend; typedef struct _virCgroupBackend virCgroupBackend;
typedef virCgroupBackend *virCgroupBackendPtr; typedef virCgroupBackend *virCgroupBackendPtr;
@ -169,4 +181,12 @@ virCgroupBackendRegister(virCgroupBackendPtr backend);
virCgroupBackendPtr * virCgroupBackendPtr *
virCgroupBackendGetAll(void); 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__ */ #endif /* __VIR_CGROUP_BACKEND_H__ */

View File

@ -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 = { virCgroupBackend virCgroupV1Backend = {
.type = VIR_CGROUP_BACKEND_TYPE_V1, .type = VIR_CGROUP_BACKEND_TYPE_V1,
@ -949,6 +975,9 @@ virCgroupBackend virCgroupV1Backend = {
.hasEmptyTasks = virCgroupV1HasEmptyTasks, .hasEmptyTasks = virCgroupV1HasEmptyTasks,
.bindMount = virCgroupV1BindMount, .bindMount = virCgroupV1BindMount,
.setOwner = virCgroupV1SetOwner, .setOwner = virCgroupV1SetOwner,
.setBlkioWeight = virCgroupV1SetBlkioWeight,
.getBlkioWeight = virCgroupV1GetBlkioWeight,
}; };