mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 22:25:25 +00:00
vircgroup: extract virCgroupV1(Set|Get)BlkioDeviceWriteIops
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
dfaf5c6de1
commit
2edd0bcda6
@ -1398,19 +1398,7 @@ virCgroupSetBlkioDeviceWriteIops(virCgroupPtr group,
|
||||
const char *path,
|
||||
unsigned int wiops)
|
||||
{
|
||||
VIR_AUTOFREE(char *) str = NULL;
|
||||
VIR_AUTOFREE(char *) blkstr = NULL;
|
||||
|
||||
if (!(blkstr = virCgroupGetBlockDevString(path)))
|
||||
return -1;
|
||||
|
||||
if (virAsprintf(&str, "%s%u", blkstr, wiops) < 0)
|
||||
return -1;
|
||||
|
||||
return virCgroupSetValueStr(group,
|
||||
VIR_CGROUP_CONTROLLER_BLKIO,
|
||||
"blkio.throttle.write_iops_device",
|
||||
str);
|
||||
VIR_CGROUP_BACKEND_CALL(group, setBlkioDeviceWriteIops, -1, path, wiops);
|
||||
}
|
||||
|
||||
|
||||
@ -1517,25 +1505,7 @@ virCgroupGetBlkioDeviceWriteIops(virCgroupPtr group,
|
||||
const char *path,
|
||||
unsigned int *wiops)
|
||||
{
|
||||
VIR_AUTOFREE(char *) str = NULL;
|
||||
|
||||
if (virCgroupGetValueForBlkDev(group,
|
||||
VIR_CGROUP_CONTROLLER_BLKIO,
|
||||
"blkio.throttle.write_iops_device",
|
||||
path,
|
||||
&str) < 0)
|
||||
return -1;
|
||||
|
||||
if (!str) {
|
||||
*wiops = 0;
|
||||
} else if (virStrToLong_ui(str, NULL, 10, wiops) < 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Unable to parse '%s' as an integer"),
|
||||
str);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
VIR_CGROUP_BACKEND_CALL(group, getBlkioDeviceWriteIops, -1, path, wiops);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -180,6 +180,16 @@ typedef int
|
||||
const char *path,
|
||||
unsigned int *riops);
|
||||
|
||||
typedef int
|
||||
(*virCgroupSetBlkioDeviceWriteIopsCB)(virCgroupPtr group,
|
||||
const char *path,
|
||||
unsigned int wiops);
|
||||
|
||||
typedef int
|
||||
(*virCgroupGetBlkioDeviceWriteIopsCB)(virCgroupPtr group,
|
||||
const char *path,
|
||||
unsigned int *wiops);
|
||||
|
||||
struct _virCgroupBackend {
|
||||
virCgroupBackendType type;
|
||||
|
||||
@ -212,6 +222,8 @@ struct _virCgroupBackend {
|
||||
virCgroupGetBlkioDeviceWeightCB getBlkioDeviceWeight;
|
||||
virCgroupSetBlkioDeviceReadIopsCB setBlkioDeviceReadIops;
|
||||
virCgroupGetBlkioDeviceReadIopsCB getBlkioDeviceReadIops;
|
||||
virCgroupSetBlkioDeviceWriteIopsCB setBlkioDeviceWriteIops;
|
||||
virCgroupGetBlkioDeviceWriteIopsCB getBlkioDeviceWriteIops;
|
||||
};
|
||||
typedef struct _virCgroupBackend virCgroupBackend;
|
||||
typedef virCgroupBackend *virCgroupBackendPtr;
|
||||
|
@ -1233,6 +1233,54 @@ virCgroupV1GetBlkioDeviceReadIops(virCgroupPtr group,
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
virCgroupV1SetBlkioDeviceWriteIops(virCgroupPtr group,
|
||||
const char *path,
|
||||
unsigned int wiops)
|
||||
{
|
||||
VIR_AUTOFREE(char *) str = NULL;
|
||||
VIR_AUTOFREE(char *) blkstr = NULL;
|
||||
|
||||
if (!(blkstr = virCgroupGetBlockDevString(path)))
|
||||
return -1;
|
||||
|
||||
if (virAsprintf(&str, "%s%u", blkstr, wiops) < 0)
|
||||
return -1;
|
||||
|
||||
return virCgroupSetValueStr(group,
|
||||
VIR_CGROUP_CONTROLLER_BLKIO,
|
||||
"blkio.throttle.write_iops_device",
|
||||
str);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
virCgroupV1GetBlkioDeviceWriteIops(virCgroupPtr group,
|
||||
const char *path,
|
||||
unsigned int *wiops)
|
||||
{
|
||||
VIR_AUTOFREE(char *) str = NULL;
|
||||
|
||||
if (virCgroupGetValueForBlkDev(group,
|
||||
VIR_CGROUP_CONTROLLER_BLKIO,
|
||||
"blkio.throttle.write_iops_device",
|
||||
path,
|
||||
&str) < 0)
|
||||
return -1;
|
||||
|
||||
if (!str) {
|
||||
*wiops = 0;
|
||||
} else if (virStrToLong_ui(str, NULL, 10, wiops) < 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Unable to parse '%s' as an integer"),
|
||||
str);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
virCgroupBackend virCgroupV1Backend = {
|
||||
.type = VIR_CGROUP_BACKEND_TYPE_V1,
|
||||
|
||||
@ -1263,6 +1311,8 @@ virCgroupBackend virCgroupV1Backend = {
|
||||
.getBlkioDeviceWeight = virCgroupV1GetBlkioDeviceWeight,
|
||||
.setBlkioDeviceReadIops = virCgroupV1SetBlkioDeviceReadIops,
|
||||
.getBlkioDeviceReadIops = virCgroupV1GetBlkioDeviceReadIops,
|
||||
.setBlkioDeviceWriteIops = virCgroupV1SetBlkioDeviceWriteIops,
|
||||
.getBlkioDeviceWriteIops = virCgroupV1GetBlkioDeviceWriteIops,
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user