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:
parent
dad061101d
commit
c57b0be0cc
@ -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,
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user