提交 c23829f1 编写于 作者: P Pavel Hrdina

util: vircgroup: move virCgroupGetValueStr out of virCgroupGetValueForBlkDev

If we need to get a path of specific file and we need to check its
existence before we use it then we can reuse that path to get value
for specific device.  This way we will not build the path again in
virCgroupGetValueForBlkDev.
Signed-off-by: NPavel Hrdina <phrdina@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 3f741f9a
...@@ -533,20 +533,14 @@ virCgroupGetValueStr(virCgroupPtr group, ...@@ -533,20 +533,14 @@ virCgroupGetValueStr(virCgroupPtr group,
int int
virCgroupGetValueForBlkDev(virCgroupPtr group, virCgroupGetValueForBlkDev(const char *str,
int controller,
const char *key,
const char *path, const char *path,
char **value) char **value)
{ {
VIR_AUTOFREE(char *) prefix = NULL; VIR_AUTOFREE(char *) prefix = NULL;
VIR_AUTOFREE(char *) str = NULL;
char **lines = NULL; char **lines = NULL;
int ret = -1; int ret = -1;
if (virCgroupGetValueStr(group, controller, key, &str) < 0)
goto error;
if (!(prefix = virCgroupGetBlockDevString(path))) if (!(prefix = virCgroupGetBlockDevString(path)))
goto error; goto error;
......
...@@ -98,10 +98,8 @@ int virCgroupPartitionEscape(char **path); ...@@ -98,10 +98,8 @@ int virCgroupPartitionEscape(char **path);
char *virCgroupGetBlockDevString(const char *path); char *virCgroupGetBlockDevString(const char *path);
int virCgroupGetValueForBlkDev(virCgroupPtr group, int virCgroupGetValueForBlkDev(const char *str,
int controller, const char *devPath,
const char *key,
const char *path,
char **value); char **value);
int virCgroupNew(pid_t pid, int virCgroupNew(pid_t pid,
......
...@@ -1181,12 +1181,16 @@ virCgroupV1GetBlkioDeviceWeight(virCgroupPtr group, ...@@ -1181,12 +1181,16 @@ virCgroupV1GetBlkioDeviceWeight(virCgroupPtr group,
unsigned int *weight) unsigned int *weight)
{ {
VIR_AUTOFREE(char *) str = NULL; VIR_AUTOFREE(char *) str = NULL;
VIR_AUTOFREE(char *) value = NULL;
if (virCgroupGetValueForBlkDev(group, if (virCgroupGetValueStr(group,
VIR_CGROUP_CONTROLLER_BLKIO, VIR_CGROUP_CONTROLLER_BLKIO,
"blkio.weight_device", "blkio.weight_device",
path, &value) < 0) {
&str) < 0) return -1;
}
if (virCgroupGetValueForBlkDev(value, path, &str) < 0)
return -1; return -1;
if (!str) { if (!str) {
...@@ -1229,12 +1233,16 @@ virCgroupV1GetBlkioDeviceReadIops(virCgroupPtr group, ...@@ -1229,12 +1233,16 @@ virCgroupV1GetBlkioDeviceReadIops(virCgroupPtr group,
unsigned int *riops) unsigned int *riops)
{ {
VIR_AUTOFREE(char *) str = NULL; VIR_AUTOFREE(char *) str = NULL;
VIR_AUTOFREE(char *) value = NULL;
if (virCgroupGetValueForBlkDev(group, if (virCgroupGetValueStr(group,
VIR_CGROUP_CONTROLLER_BLKIO, VIR_CGROUP_CONTROLLER_BLKIO,
"blkio.throttle.read_iops_device", "blkio.throttle.read_iops_device",
path, &value) < 0) {
&str) < 0) return -1;
}
if (virCgroupGetValueForBlkDev(value, path, &str) < 0)
return -1; return -1;
if (!str) { if (!str) {
...@@ -1277,12 +1285,16 @@ virCgroupV1GetBlkioDeviceWriteIops(virCgroupPtr group, ...@@ -1277,12 +1285,16 @@ virCgroupV1GetBlkioDeviceWriteIops(virCgroupPtr group,
unsigned int *wiops) unsigned int *wiops)
{ {
VIR_AUTOFREE(char *) str = NULL; VIR_AUTOFREE(char *) str = NULL;
VIR_AUTOFREE(char *) value = NULL;
if (virCgroupGetValueForBlkDev(group, if (virCgroupGetValueStr(group,
VIR_CGROUP_CONTROLLER_BLKIO, VIR_CGROUP_CONTROLLER_BLKIO,
"blkio.throttle.write_iops_device", "blkio.throttle.write_iops_device",
path, &value) < 0) {
&str) < 0) return -1;
}
if (virCgroupGetValueForBlkDev(value, path, &str) < 0)
return -1; return -1;
if (!str) { if (!str) {
...@@ -1325,12 +1337,16 @@ virCgroupV1GetBlkioDeviceReadBps(virCgroupPtr group, ...@@ -1325,12 +1337,16 @@ virCgroupV1GetBlkioDeviceReadBps(virCgroupPtr group,
unsigned long long *rbps) unsigned long long *rbps)
{ {
VIR_AUTOFREE(char *) str = NULL; VIR_AUTOFREE(char *) str = NULL;
VIR_AUTOFREE(char *) value = NULL;
if (virCgroupGetValueForBlkDev(group, if (virCgroupGetValueStr(group,
VIR_CGROUP_CONTROLLER_BLKIO, VIR_CGROUP_CONTROLLER_BLKIO,
"blkio.throttle.read_bps_device", "blkio.throttle.read_bps_device",
path, &value) < 0) {
&str) < 0) return -1;
}
if (virCgroupGetValueForBlkDev(value, path, &str) < 0)
return -1; return -1;
if (!str) { if (!str) {
...@@ -1373,12 +1389,16 @@ virCgroupV1GetBlkioDeviceWriteBps(virCgroupPtr group, ...@@ -1373,12 +1389,16 @@ virCgroupV1GetBlkioDeviceWriteBps(virCgroupPtr group,
unsigned long long *wbps) unsigned long long *wbps)
{ {
VIR_AUTOFREE(char *) str = NULL; VIR_AUTOFREE(char *) str = NULL;
VIR_AUTOFREE(char *) value = NULL;
if (virCgroupGetValueForBlkDev(group, if (virCgroupGetValueStr(group,
VIR_CGROUP_CONTROLLER_BLKIO, VIR_CGROUP_CONTROLLER_BLKIO,
"blkio.throttle.write_bps_device", "blkio.throttle.write_bps_device",
path, &value) < 0) {
&str) < 0) return -1;
}
if (virCgroupGetValueForBlkDev(value, path, &str) < 0)
return -1; return -1;
if (!str) { if (!str) {
......
...@@ -750,15 +750,18 @@ virCgroupV2GetBlkioDeviceWeight(virCgroupPtr group, ...@@ -750,15 +750,18 @@ virCgroupV2GetBlkioDeviceWeight(virCgroupPtr group,
unsigned int *weight) unsigned int *weight)
{ {
VIR_AUTOFREE(char *) str = NULL; VIR_AUTOFREE(char *) str = NULL;
VIR_AUTOFREE(char *) value = NULL;
if (virCgroupGetValueForBlkDev(group, if (virCgroupGetValueStr(group,
VIR_CGROUP_CONTROLLER_BLKIO, VIR_CGROUP_CONTROLLER_BLKIO,
"io.weight", "io.weight",
path, &value) < 0) {
&str) < 0) {
return -1; return -1;
} }
if (virCgroupGetValueForBlkDev(value, path, &str) < 0)
return -1;
if (!str) { if (!str) {
*weight = 0; *weight = 0;
} else if (virStrToLong_ui(str, NULL, 10, weight) < 0) { } else if (virStrToLong_ui(str, NULL, 10, weight) < 0) {
...@@ -804,17 +807,20 @@ virCgroupV2GetBlkioDeviceReadIops(virCgroupPtr group, ...@@ -804,17 +807,20 @@ virCgroupV2GetBlkioDeviceReadIops(virCgroupPtr group,
unsigned int *riops) unsigned int *riops)
{ {
VIR_AUTOFREE(char *) str = NULL; VIR_AUTOFREE(char *) str = NULL;
VIR_AUTOFREE(char *) value = NULL;
const char *name = "riops="; const char *name = "riops=";
char *tmp; char *tmp;
if (virCgroupGetValueForBlkDev(group, if (virCgroupGetValueStr(group,
VIR_CGROUP_CONTROLLER_BLKIO, VIR_CGROUP_CONTROLLER_BLKIO,
"io.max", "io.max",
path, &value) < 0) {
&str) < 0) {
return -1; return -1;
} }
if (virCgroupGetValueForBlkDev(value, path, &str) < 0)
return -1;
if (!str) { if (!str) {
*riops = 0; *riops = 0;
} else { } else {
...@@ -872,17 +878,20 @@ virCgroupV2GetBlkioDeviceWriteIops(virCgroupPtr group, ...@@ -872,17 +878,20 @@ virCgroupV2GetBlkioDeviceWriteIops(virCgroupPtr group,
unsigned int *wiops) unsigned int *wiops)
{ {
VIR_AUTOFREE(char *) str = NULL; VIR_AUTOFREE(char *) str = NULL;
VIR_AUTOFREE(char *) value = NULL;
const char *name = "wiops="; const char *name = "wiops=";
char *tmp; char *tmp;
if (virCgroupGetValueForBlkDev(group, if (virCgroupGetValueStr(group,
VIR_CGROUP_CONTROLLER_BLKIO, VIR_CGROUP_CONTROLLER_BLKIO,
"io.max", "io.max",
path, &value) < 0) {
&str) < 0) {
return -1; return -1;
} }
if (virCgroupGetValueForBlkDev(value, path, &str) < 0)
return -1;
if (!str) { if (!str) {
*wiops = 0; *wiops = 0;
} else { } else {
...@@ -940,17 +949,20 @@ virCgroupV2GetBlkioDeviceReadBps(virCgroupPtr group, ...@@ -940,17 +949,20 @@ virCgroupV2GetBlkioDeviceReadBps(virCgroupPtr group,
unsigned long long *rbps) unsigned long long *rbps)
{ {
VIR_AUTOFREE(char *) str = NULL; VIR_AUTOFREE(char *) str = NULL;
VIR_AUTOFREE(char *) value = NULL;
const char *name = "rbps="; const char *name = "rbps=";
char *tmp; char *tmp;
if (virCgroupGetValueForBlkDev(group, if (virCgroupGetValueStr(group,
VIR_CGROUP_CONTROLLER_BLKIO, VIR_CGROUP_CONTROLLER_BLKIO,
"io.max", "io.max",
path, &value) < 0) {
&str) < 0) {
return -1; return -1;
} }
if (virCgroupGetValueForBlkDev(value, path, &str) < 0)
return -1;
if (!str) { if (!str) {
*rbps = 0; *rbps = 0;
} else { } else {
...@@ -1008,17 +1020,20 @@ virCgroupV2GetBlkioDeviceWriteBps(virCgroupPtr group, ...@@ -1008,17 +1020,20 @@ virCgroupV2GetBlkioDeviceWriteBps(virCgroupPtr group,
unsigned long long *wbps) unsigned long long *wbps)
{ {
VIR_AUTOFREE(char *) str = NULL; VIR_AUTOFREE(char *) str = NULL;
VIR_AUTOFREE(char *) value = NULL;
const char *name = "wbps="; const char *name = "wbps=";
char *tmp; char *tmp;
if (virCgroupGetValueForBlkDev(group, if (virCgroupGetValueStr(group,
VIR_CGROUP_CONTROLLER_BLKIO, VIR_CGROUP_CONTROLLER_BLKIO,
"io.max", "io.max",
path, &value) < 0) {
&str) < 0) {
return -1; return -1;
} }
if (virCgroupGetValueForBlkDev(value, path, &str) < 0)
return -1;
if (!str) { if (!str) {
*wbps = 0; *wbps = 0;
} else { } else {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册