mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 06:05:27 +00:00
util: virresctrl: Use g_strsplit instead of virStringSplitCount
In 3 of 4 instances the code didn't even need the count of the elements. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
3fa15af8e1
commit
02a0d2e08c
@ -697,8 +697,6 @@ virResctrlGetMonitorInfo(virResctrlInfoPtr resctrl)
|
|||||||
{
|
{
|
||||||
int rv = -1;
|
int rv = -1;
|
||||||
g_autofree char *featurestr = NULL;
|
g_autofree char *featurestr = NULL;
|
||||||
g_auto(GStrv) features = NULL;
|
|
||||||
size_t nfeatures = 0;
|
|
||||||
g_autofree virResctrlInfoMongrpPtr info_monitor = NULL;
|
g_autofree virResctrlInfoMongrpPtr info_monitor = NULL;
|
||||||
|
|
||||||
info_monitor = g_new0(virResctrlInfoMongrp, 1);
|
info_monitor = g_new0(virResctrlInfoMongrp, 1);
|
||||||
@ -748,11 +746,10 @@ virResctrlGetMonitorInfo(virResctrlInfoPtr resctrl)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
features = virStringSplitCount(featurestr, "\n", 0, &nfeatures);
|
info_monitor->features = g_strsplit(featurestr, "\n", 0);
|
||||||
VIR_DEBUG("Resctrl supported %zd monitoring features", nfeatures);
|
info_monitor->nfeatures = g_strv_length(info_monitor->features);
|
||||||
|
VIR_DEBUG("Resctrl supported %zd monitoring features", info_monitor->nfeatures);
|
||||||
|
|
||||||
info_monitor->nfeatures = nfeatures;
|
|
||||||
info_monitor->features = g_steal_pointer(&features);
|
|
||||||
resctrl->monitor_info = g_steal_pointer(&info_monitor);
|
resctrl->monitor_info = g_steal_pointer(&info_monitor);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -1466,9 +1463,8 @@ virResctrlAllocParseMemoryBandwidthLine(virResctrlInfoPtr resctrl,
|
|||||||
char *line)
|
char *line)
|
||||||
{
|
{
|
||||||
g_auto(GStrv) mbs = NULL;
|
g_auto(GStrv) mbs = NULL;
|
||||||
|
GStrv next;
|
||||||
char *tmp = NULL;
|
char *tmp = NULL;
|
||||||
size_t nmbs = 0;
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
/* For no reason there can be spaces */
|
/* For no reason there can be spaces */
|
||||||
virSkipSpaces((const char **) &line);
|
virSkipSpaces((const char **) &line);
|
||||||
@ -1493,9 +1489,9 @@ virResctrlAllocParseMemoryBandwidthLine(virResctrlInfoPtr resctrl,
|
|||||||
return 0;
|
return 0;
|
||||||
tmp++;
|
tmp++;
|
||||||
|
|
||||||
mbs = virStringSplitCount(tmp, ";", 0, &nmbs);
|
mbs = g_strsplit(tmp, ";", 0);
|
||||||
for (i = 0; i < nmbs; i++) {
|
for (next = mbs; *next; next++) {
|
||||||
if (virResctrlAllocParseProcessMemoryBandwidth(resctrl, alloc, mbs[i]) < 0)
|
if (virResctrlAllocParseProcessMemoryBandwidth(resctrl, alloc, *next) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1620,11 +1616,10 @@ virResctrlAllocParseCacheLine(virResctrlInfoPtr resctrl,
|
|||||||
char *line)
|
char *line)
|
||||||
{
|
{
|
||||||
g_auto(GStrv) caches = NULL;
|
g_auto(GStrv) caches = NULL;
|
||||||
|
GStrv next;
|
||||||
char *tmp = NULL;
|
char *tmp = NULL;
|
||||||
unsigned int level = 0;
|
unsigned int level = 0;
|
||||||
int type = -1;
|
int type = -1;
|
||||||
size_t ncaches = 0;
|
|
||||||
size_t i = 0;
|
|
||||||
|
|
||||||
/* For no reason there can be spaces */
|
/* For no reason there can be spaces */
|
||||||
virSkipSpaces((const char **) &line);
|
virSkipSpaces((const char **) &line);
|
||||||
@ -1656,12 +1651,12 @@ virResctrlAllocParseCacheLine(virResctrlInfoPtr resctrl,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
caches = virStringSplitCount(tmp, ";", 0, &ncaches);
|
caches = g_strsplit(tmp, ";", 0);
|
||||||
if (!caches)
|
if (!caches)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
for (i = 0; i < ncaches; i++) {
|
for (next = caches; *next; next++) {
|
||||||
if (virResctrlAllocParseProcessCache(resctrl, alloc, level, type, caches[i]) < 0)
|
if (virResctrlAllocParseProcessCache(resctrl, alloc, level, type, *next) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1675,14 +1670,13 @@ virResctrlAllocParse(virResctrlInfoPtr resctrl,
|
|||||||
const char *schemata)
|
const char *schemata)
|
||||||
{
|
{
|
||||||
g_auto(GStrv) lines = NULL;
|
g_auto(GStrv) lines = NULL;
|
||||||
size_t nlines = 0;
|
GStrv next;
|
||||||
size_t i = 0;
|
|
||||||
|
|
||||||
lines = virStringSplitCount(schemata, "\n", 0, &nlines);
|
lines = g_strsplit(schemata, "\n", 0);
|
||||||
for (i = 0; i < nlines; i++) {
|
for (next = lines; *next; next++) {
|
||||||
if (virResctrlAllocParseCacheLine(resctrl, alloc, lines[i]) < 0)
|
if (virResctrlAllocParseCacheLine(resctrl, alloc, *next) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
if (virResctrlAllocParseMemoryBandwidthLine(resctrl, alloc, lines[i]) < 0)
|
if (virResctrlAllocParseMemoryBandwidthLine(resctrl, alloc, *next) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user