mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
util: split the virNumaGetHugePageInfoPath into separate function
https://bugzilla.redhat.com/show_bug.cgi?id=1265114 Refactor helper virNumaGetHugePageInfoPath to handle returning a directory path when passed a page_size of 0 and suffix == NULL into a new helper virNumaGetHugePageInfoDir which will only be called when a directory path is expected to be returned. This solves the issue where the helper was called with page_size == 0 expecting a file path in return, but instead got a directory path and failed in virFileReadAll with: error : virFileReadAll:1358 : Failed to read file '/sys/devices/system/node/node0/hugepages/': Is a directory Since virNumaGetPages API expects to return a directory by passing page_size == 0 and suffix == NULL, it will now call the new helper. Callers to virNumaGetHugePageInfoPath expect to return a file path which could then be used in the call to virFileReadAll. Signed-off-by: Luyao Huang <lhuang@redhat.com>
This commit is contained in:
parent
32cee5b2f0
commit
deb8c66d44
@ -493,44 +493,31 @@ virNumaGetHugePageInfoPath(char **path,
|
|||||||
unsigned int page_size,
|
unsigned int page_size,
|
||||||
const char *suffix)
|
const char *suffix)
|
||||||
{
|
{
|
||||||
|
|
||||||
int ret = -1;
|
|
||||||
|
|
||||||
if (node == -1) {
|
if (node == -1) {
|
||||||
/* We are aiming at overall system info */
|
/* We are aiming at overall system info */
|
||||||
if (page_size) {
|
return virAsprintf(path,
|
||||||
/* And even on specific huge page size */
|
HUGEPAGES_SYSTEM_PREFIX HUGEPAGES_PREFIX "%ukB/%s",
|
||||||
if (virAsprintf(path,
|
page_size, suffix ? suffix : "");
|
||||||
HUGEPAGES_SYSTEM_PREFIX HUGEPAGES_PREFIX "%ukB/%s",
|
|
||||||
page_size, suffix ? suffix : "") < 0)
|
|
||||||
goto cleanup;
|
|
||||||
} else {
|
|
||||||
if (VIR_STRDUP(*path, HUGEPAGES_SYSTEM_PREFIX) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
/* We are aiming on specific NUMA node */
|
/* We are aiming on specific NUMA node */
|
||||||
if (page_size) {
|
return virAsprintf(path,
|
||||||
/* And even on specific huge page size */
|
HUGEPAGES_NUMA_PREFIX "node%d/hugepages/"
|
||||||
if (virAsprintf(path,
|
HUGEPAGES_PREFIX "%ukB/%s",
|
||||||
HUGEPAGES_NUMA_PREFIX "node%d/hugepages/"
|
node, page_size, suffix ? suffix : "");
|
||||||
HUGEPAGES_PREFIX "%ukB/%s",
|
|
||||||
node, page_size, suffix ? suffix : "") < 0)
|
|
||||||
goto cleanup;
|
|
||||||
} else {
|
|
||||||
if (virAsprintf(path,
|
|
||||||
HUGEPAGES_NUMA_PREFIX "node%d/hugepages/",
|
|
||||||
node) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
|
||||||
cleanup:
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
virNumaGetHugePageInfoDir(char **path, int node)
|
||||||
|
{
|
||||||
|
if (node == -1) {
|
||||||
|
return VIR_STRDUP(*path, HUGEPAGES_SYSTEM_PREFIX);
|
||||||
|
} else {
|
||||||
|
return virAsprintf(path,
|
||||||
|
HUGEPAGES_NUMA_PREFIX "node%d/hugepages/",
|
||||||
|
node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* virNumaGetHugePageInfo:
|
* virNumaGetHugePageInfo:
|
||||||
@ -724,7 +711,7 @@ virNumaGetPages(int node,
|
|||||||
* is always shown as used memory. Here, however, we want to report
|
* is always shown as used memory. Here, however, we want to report
|
||||||
* slightly different information. So we take the total memory on a node
|
* slightly different information. So we take the total memory on a node
|
||||||
* and subtract memory taken by the huge pages. */
|
* and subtract memory taken by the huge pages. */
|
||||||
if (virNumaGetHugePageInfoPath(&path, node, 0, NULL) < 0)
|
if (virNumaGetHugePageInfoDir(&path, node) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (!(dir = opendir(path))) {
|
if (!(dir = opendir(path))) {
|
||||||
|
Loading…
Reference in New Issue
Block a user