mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 07:17:44 +00:00
vircgroup: extract virCgroupV1(Set|Get)BlkioDeviceWriteBps
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
32f199250b
commit
02fe32d3aa
@ -1431,19 +1431,7 @@ virCgroupSetBlkioDeviceWriteBps(virCgroupPtr group,
|
||||
const char *path,
|
||||
unsigned long long wbps)
|
||||
{
|
||||
VIR_AUTOFREE(char *) str = NULL;
|
||||
VIR_AUTOFREE(char *) blkstr = NULL;
|
||||
|
||||
if (!(blkstr = virCgroupGetBlockDevString(path)))
|
||||
return -1;
|
||||
|
||||
if (virAsprintf(&str, "%s%llu", blkstr, wbps) < 0)
|
||||
return -1;
|
||||
|
||||
return virCgroupSetValueStr(group,
|
||||
VIR_CGROUP_CONTROLLER_BLKIO,
|
||||
"blkio.throttle.write_bps_device",
|
||||
str);
|
||||
VIR_CGROUP_BACKEND_CALL(group, setBlkioDeviceWriteBps, -1, path, wbps);
|
||||
}
|
||||
|
||||
|
||||
@ -1525,25 +1513,7 @@ virCgroupGetBlkioDeviceWriteBps(virCgroupPtr group,
|
||||
const char *path,
|
||||
unsigned long long *wbps)
|
||||
{
|
||||
VIR_AUTOFREE(char *) str = NULL;
|
||||
|
||||
if (virCgroupGetValueForBlkDev(group,
|
||||
VIR_CGROUP_CONTROLLER_BLKIO,
|
||||
"blkio.throttle.write_bps_device",
|
||||
path,
|
||||
&str) < 0)
|
||||
return -1;
|
||||
|
||||
if (!str) {
|
||||
*wbps = 0;
|
||||
} else if (virStrToLong_ull(str, NULL, 10, wbps) < 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Unable to parse '%s' as an integer"),
|
||||
str);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
VIR_CGROUP_BACKEND_CALL(group, getBlkioDeviceWriteBps, -1, path, wbps);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -200,6 +200,16 @@ typedef int
|
||||
const char *path,
|
||||
unsigned long long *rbps);
|
||||
|
||||
typedef int
|
||||
(*virCgroupSetBlkioDeviceWriteBpsCB)(virCgroupPtr group,
|
||||
const char *path,
|
||||
unsigned long long wbps);
|
||||
|
||||
typedef int
|
||||
(*virCgroupGetBlkioDeviceWriteBpsCB)(virCgroupPtr group,
|
||||
const char *path,
|
||||
unsigned long long *wbps);
|
||||
|
||||
struct _virCgroupBackend {
|
||||
virCgroupBackendType type;
|
||||
|
||||
@ -236,6 +246,8 @@ struct _virCgroupBackend {
|
||||
virCgroupGetBlkioDeviceWriteIopsCB getBlkioDeviceWriteIops;
|
||||
virCgroupSetBlkioDeviceReadBpsCB setBlkioDeviceReadBps;
|
||||
virCgroupGetBlkioDeviceReadBpsCB getBlkioDeviceReadBps;
|
||||
virCgroupSetBlkioDeviceWriteBpsCB setBlkioDeviceWriteBps;
|
||||
virCgroupGetBlkioDeviceWriteBpsCB getBlkioDeviceWriteBps;
|
||||
};
|
||||
typedef struct _virCgroupBackend virCgroupBackend;
|
||||
typedef virCgroupBackend *virCgroupBackendPtr;
|
||||
|
@ -1329,6 +1329,54 @@ virCgroupV1GetBlkioDeviceReadBps(virCgroupPtr group,
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
virCgroupV1SetBlkioDeviceWriteBps(virCgroupPtr group,
|
||||
const char *path,
|
||||
unsigned long long wbps)
|
||||
{
|
||||
VIR_AUTOFREE(char *) str = NULL;
|
||||
VIR_AUTOFREE(char *) blkstr = NULL;
|
||||
|
||||
if (!(blkstr = virCgroupGetBlockDevString(path)))
|
||||
return -1;
|
||||
|
||||
if (virAsprintf(&str, "%s%llu", blkstr, wbps) < 0)
|
||||
return -1;
|
||||
|
||||
return virCgroupSetValueStr(group,
|
||||
VIR_CGROUP_CONTROLLER_BLKIO,
|
||||
"blkio.throttle.write_bps_device",
|
||||
str);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
virCgroupV1GetBlkioDeviceWriteBps(virCgroupPtr group,
|
||||
const char *path,
|
||||
unsigned long long *wbps)
|
||||
{
|
||||
VIR_AUTOFREE(char *) str = NULL;
|
||||
|
||||
if (virCgroupGetValueForBlkDev(group,
|
||||
VIR_CGROUP_CONTROLLER_BLKIO,
|
||||
"blkio.throttle.write_bps_device",
|
||||
path,
|
||||
&str) < 0)
|
||||
return -1;
|
||||
|
||||
if (!str) {
|
||||
*wbps = 0;
|
||||
} else if (virStrToLong_ull(str, NULL, 10, wbps) < 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,
|
||||
|
||||
@ -1363,6 +1411,8 @@ virCgroupBackend virCgroupV1Backend = {
|
||||
.getBlkioDeviceWriteIops = virCgroupV1GetBlkioDeviceWriteIops,
|
||||
.setBlkioDeviceReadBps = virCgroupV1SetBlkioDeviceReadBps,
|
||||
.getBlkioDeviceReadBps = virCgroupV1GetBlkioDeviceReadBps,
|
||||
.setBlkioDeviceWriteBps = virCgroupV1SetBlkioDeviceWriteBps,
|
||||
.getBlkioDeviceWriteBps = virCgroupV1GetBlkioDeviceWriteBps,
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user