提交 32f19925 编写于 作者: P Pavel Hrdina

vircgroup: extract virCgroupV1(Set|Get)BlkioDeviceReadBps

Reviewed-by: NFabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
Signed-off-by: NPavel Hrdina <phrdina@redhat.com>
上级 2edd0bcd
......@@ -1415,19 +1415,7 @@ virCgroupSetBlkioDeviceReadBps(virCgroupPtr group,
const char *path,
unsigned long long rbps)
{
VIR_AUTOFREE(char *) str = NULL;
VIR_AUTOFREE(char *) blkstr = NULL;
if (!(blkstr = virCgroupGetBlockDevString(path)))
return -1;
if (virAsprintf(&str, "%s%llu", blkstr, rbps) < 0)
return -1;
return virCgroupSetValueStr(group,
VIR_CGROUP_CONTROLLER_BLKIO,
"blkio.throttle.read_bps_device",
str);
VIR_CGROUP_BACKEND_CALL(group, setBlkioDeviceReadBps, -1, path, rbps);
}
/**
......@@ -1521,25 +1509,7 @@ virCgroupGetBlkioDeviceReadBps(virCgroupPtr group,
const char *path,
unsigned long long *rbps)
{
VIR_AUTOFREE(char *) str = NULL;
if (virCgroupGetValueForBlkDev(group,
VIR_CGROUP_CONTROLLER_BLKIO,
"blkio.throttle.read_bps_device",
path,
&str) < 0)
return -1;
if (!str) {
*rbps = 0;
} else if (virStrToLong_ull(str, NULL, 10, rbps) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Unable to parse '%s' as an integer"),
str);
return -1;
}
return 0;
VIR_CGROUP_BACKEND_CALL(group, getBlkioDeviceReadBps, -1, path, rbps);
}
/**
......
......@@ -190,6 +190,16 @@ typedef int
const char *path,
unsigned int *wiops);
typedef int
(*virCgroupSetBlkioDeviceReadBpsCB)(virCgroupPtr group,
const char *path,
unsigned long long rbps);
typedef int
(*virCgroupGetBlkioDeviceReadBpsCB)(virCgroupPtr group,
const char *path,
unsigned long long *rbps);
struct _virCgroupBackend {
virCgroupBackendType type;
......@@ -224,6 +234,8 @@ struct _virCgroupBackend {
virCgroupGetBlkioDeviceReadIopsCB getBlkioDeviceReadIops;
virCgroupSetBlkioDeviceWriteIopsCB setBlkioDeviceWriteIops;
virCgroupGetBlkioDeviceWriteIopsCB getBlkioDeviceWriteIops;
virCgroupSetBlkioDeviceReadBpsCB setBlkioDeviceReadBps;
virCgroupGetBlkioDeviceReadBpsCB getBlkioDeviceReadBps;
};
typedef struct _virCgroupBackend virCgroupBackend;
typedef virCgroupBackend *virCgroupBackendPtr;
......
......@@ -1281,6 +1281,54 @@ virCgroupV1GetBlkioDeviceWriteIops(virCgroupPtr group,
}
static int
virCgroupV1SetBlkioDeviceReadBps(virCgroupPtr group,
const char *path,
unsigned long long rbps)
{
VIR_AUTOFREE(char *) str = NULL;
VIR_AUTOFREE(char *) blkstr = NULL;
if (!(blkstr = virCgroupGetBlockDevString(path)))
return -1;
if (virAsprintf(&str, "%s%llu", blkstr, rbps) < 0)
return -1;
return virCgroupSetValueStr(group,
VIR_CGROUP_CONTROLLER_BLKIO,
"blkio.throttle.read_bps_device",
str);
}
static int
virCgroupV1GetBlkioDeviceReadBps(virCgroupPtr group,
const char *path,
unsigned long long *rbps)
{
VIR_AUTOFREE(char *) str = NULL;
if (virCgroupGetValueForBlkDev(group,
VIR_CGROUP_CONTROLLER_BLKIO,
"blkio.throttle.read_bps_device",
path,
&str) < 0)
return -1;
if (!str) {
*rbps = 0;
} else if (virStrToLong_ull(str, NULL, 10, rbps) < 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,
......@@ -1313,6 +1361,8 @@ virCgroupBackend virCgroupV1Backend = {
.getBlkioDeviceReadIops = virCgroupV1GetBlkioDeviceReadIops,
.setBlkioDeviceWriteIops = virCgroupV1SetBlkioDeviceWriteIops,
.getBlkioDeviceWriteIops = virCgroupV1GetBlkioDeviceWriteIops,
.setBlkioDeviceReadBps = virCgroupV1SetBlkioDeviceReadBps,
.getBlkioDeviceReadBps = virCgroupV1GetBlkioDeviceReadBps,
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册