mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 03:25:20 +00:00
util: Produce friendlier error message to user
Commit id '1c24cfe9' added error messages for virNumaSetPagePoolSize; however, virNumaGetHugePageInfo also uses virNumaGetHugePageInfoPath in order to build the path, but it never checked upon return if the built path exists which could lead to an error message as follows: $ virsh freepages 0 1 error: Failed to open file '/sys/devices/system/node/node0/hugepages/hugepages-1kB/free_hugepages': No such file or directory Rather than add the same message for the other two callers, adjust the virNumaGetHugePageInfoPath in order not only build the path, but also check if the built path exists. If the path does not exist, then generate the error message and return failure. Signed-off-by: Luyao Huang <lhuang@redhat.com>
This commit is contained in:
parent
e802d7efb4
commit
4f9e61f648
@ -493,18 +493,41 @@ virNumaGetHugePageInfoPath(char **path,
|
||||
unsigned int page_size,
|
||||
const char *suffix)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (node == -1) {
|
||||
/* We are aiming at overall system info */
|
||||
return virAsprintf(path,
|
||||
HUGEPAGES_SYSTEM_PREFIX HUGEPAGES_PREFIX "%ukB/%s",
|
||||
page_size, suffix ? suffix : "");
|
||||
ret = virAsprintf(path,
|
||||
HUGEPAGES_SYSTEM_PREFIX HUGEPAGES_PREFIX "%ukB/%s",
|
||||
page_size, suffix ? suffix : "");
|
||||
} else {
|
||||
/* We are aiming on specific NUMA node */
|
||||
return virAsprintf(path,
|
||||
HUGEPAGES_NUMA_PREFIX "node%d/hugepages/"
|
||||
HUGEPAGES_PREFIX "%ukB/%s",
|
||||
node, page_size, suffix ? suffix : "");
|
||||
ret = virAsprintf(path,
|
||||
HUGEPAGES_NUMA_PREFIX "node%d/hugepages/"
|
||||
HUGEPAGES_PREFIX "%ukB/%s",
|
||||
node, page_size, suffix ? suffix : "");
|
||||
}
|
||||
|
||||
if (ret >= 0 && !virFileExists(*path)) {
|
||||
ret = -1;
|
||||
if (node != -1) {
|
||||
if (!virNumaNodeIsAvailable(node)) {
|
||||
virReportError(VIR_ERR_OPERATION_FAILED,
|
||||
_("NUMA node %d is not available"),
|
||||
node);
|
||||
} else {
|
||||
virReportError(VIR_ERR_OPERATION_FAILED,
|
||||
_("page size %u is not available on node %d"),
|
||||
page_size, node);
|
||||
}
|
||||
} else {
|
||||
virReportError(VIR_ERR_OPERATION_FAILED,
|
||||
_("page size %u is not available"),
|
||||
page_size);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
@ -839,25 +862,6 @@ virNumaSetPagePoolSize(int node,
|
||||
if (virNumaGetHugePageInfoPath(&nr_path, node, page_size, "nr_hugepages") < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (!virFileExists(nr_path)) {
|
||||
if (node != -1) {
|
||||
if (!virNumaNodeIsAvailable(node)) {
|
||||
virReportError(VIR_ERR_OPERATION_FAILED,
|
||||
_("NUMA node %d is not available"),
|
||||
node);
|
||||
} else {
|
||||
virReportError(VIR_ERR_OPERATION_FAILED,
|
||||
_("page size %u is not available on node %d"),
|
||||
page_size, node);
|
||||
}
|
||||
} else {
|
||||
virReportError(VIR_ERR_OPERATION_FAILED,
|
||||
_("page size %u is not available"),
|
||||
page_size);
|
||||
}
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* Firstly check, if there's anything for us to do */
|
||||
if (virFileReadAll(nr_path, 1024, &nr_buf) < 0)
|
||||
goto cleanup;
|
||||
|
Loading…
Reference in New Issue
Block a user