提交 b38da584 编写于 作者: D Daniel P. Berrange

Make tests independant of system page size

Some code paths have special logic depending on the page size
reported by sysconf, which in turn affects the test results.
We must mock this so tests always have a consistent page size.
上级 df2cc650
......@@ -997,6 +997,11 @@ sc_prohibit_virXXXFree:
halt='avoid using 'virXXXFree', use 'virObjectUnref' instead' \
$(_sc_search_regexp)
sc_prohibit_sysconf_pagesize:
@prohibit='sysconf\(_SC_PAGESIZE' \
halt='use virGetSystemPageSize[KB] instead of sysconf(_SC_PAGESIZE)' \
$(_sc_search_regexp)
# We don't use this feature of maint.mk.
prev_version_file = /dev/null
......@@ -1187,3 +1192,6 @@ exclude_file_name_regexp--sc_prohibit_devname = \
exclude_file_name_regexp--sc_prohibit_virXXXFree = \
^(docs/|tests/|examples/|tools/|cfg.mk|src/test/test_driver.c|src/libvirt_public.syms|include/libvirt/libvirt-(domain|network|nodedev|storage|stream|secret|nwfilter|interface|domain-snapshot).h|src/libvirt-(domain|qemu|network|nodedev|storage|stream|secret|nwfilter|interface|domain-snapshot).c$$)
exclude_file_name_regexp--sc_prohibit_sysconf_pagesize = \
^(cfg\.mk|src/util/virutil\.c)$$
......@@ -2228,6 +2228,8 @@ virGetListenFDs;
virGetSCSIHostNameByParentaddr;
virGetSCSIHostNumber;
virGetSelfLastChanged;
virGetSystemPageSize;
virGetSystemPageSizeKB;
virGetUnprivSGIOSysfsPath;
virGetUserCacheDirectory;
virGetUserConfigDirectory;
......
......@@ -42,10 +42,7 @@ openvzKBPerPages(void)
static long kb_per_pages;
if (kb_per_pages == 0) {
kb_per_pages = sysconf(_SC_PAGESIZE);
if (kb_per_pages > 0) {
kb_per_pages /= 1024;
} else {
if ((kb_per_pages = virGetSystemPageSizeKB()) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Can't determine page size"));
kb_per_pages = 0;
......
......@@ -4540,7 +4540,7 @@ qemuBuildMemoryBackendStr(unsigned long long size,
virDomainHugePagePtr master_hugepage = NULL;
virDomainHugePagePtr hugepage = NULL;
virDomainNumatuneMemMode mode;
const long system_page_size = sysconf(_SC_PAGESIZE) / 1024;
const long system_page_size = virGetSystemPageSizeKB();
virMemAccess memAccess = def->cpu->cells[guestNode].memAccess;
size_t i;
char *mem_path = NULL;
......@@ -7051,7 +7051,7 @@ qemuBuildNumaArgStr(virQEMUDriverConfigPtr cfg,
bool needBackend = false;
int rc;
int ret = -1;
const long system_page_size = sysconf(_SC_PAGESIZE) / 1024;
const long system_page_size = virGetSystemPageSizeKB();
if (virDomainNumatuneHasPerNodeBinding(def->numatune) &&
!(virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_MEMORY_RAM) ||
......@@ -8239,7 +8239,7 @@ qemuBuildCommandLine(virConnectPtr conn,
def->mem.max_balloon = VIR_DIV_UP(def->mem.max_balloon, 1024) * 1024;
virCommandAddArgFormat(cmd, "%llu", def->mem.max_balloon / 1024);
if (def->mem.nhugepages && (!def->cpu || !def->cpu->ncells)) {
const long system_page_size = sysconf(_SC_PAGESIZE) / 1024;
const long system_page_size = virGetSystemPageSizeKB();
char *mem_path = NULL;
if (def->mem.hugepages[0].size == system_page_size) {
......
......@@ -1352,12 +1352,8 @@ qemuGetProcessInfo(unsigned long long *cpuTime, int *lastCpu, long *vm_rss,
if (lastCpu)
*lastCpu = cpu;
/* We got pages
* We want kiloBytes
* _SC_PAGESIZE is page size in Bytes
* So calculate, but first lower the pagesize so we don't get overflow */
if (vm_rss)
*vm_rss = rss * (sysconf(_SC_PAGESIZE) >> 10);
*vm_rss = rss * virGetSystemPageSizeKB();
VIR_DEBUG("Got status for %d/%d user=%llu sys=%llu cpu=%d rss=%ld",
......
......@@ -1086,7 +1086,7 @@ safezero_mmap(int fd, off_t offset, off_t len)
/* align offset and length, rounding offset down and length up */
if (pagemask == 0)
pagemask = ~(sysconf(_SC_PAGESIZE) - 1);
pagemask = ~(virGetSystemPageSize() - 1);
map_skip = offset - (offset & pagemask);
/* memset wants the mmap'ed file to be present on disk so create a
......
......@@ -639,7 +639,7 @@ virNumaGetPageInfo(int node,
unsigned int *page_free)
{
int ret = -1;
long system_page_size = sysconf(_SC_PAGESIZE);
long system_page_size = virGetSystemPageSize();
/* sysconf() returns page size in bytes,
* the @page_size is however in kibibytes */
......@@ -717,7 +717,7 @@ virNumaGetPages(int node,
/* sysconf() returns page size in bytes,
* but we are storing the page size in kibibytes. */
system_page_size = sysconf(_SC_PAGESIZE) / 1024;
system_page_size = virGetSystemPageSizeKB();
/* Query huge pages at first.
* On Linux systems, the huge pages pool cuts off the available memory and
......@@ -841,7 +841,7 @@ virNumaSetPagePoolSize(int node,
char *end;
unsigned long long nr_count;
if (page_size == sysconf(_SC_PAGESIZE) / 1024) {
if (page_size == virGetSystemPageSizeKB()) {
/* Special case as kernel handles system pages
* differently to huge pages. */
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
......
......@@ -2577,3 +2577,16 @@ virGetListenFDs(void)
}
#endif /* WIN32 */
long virGetSystemPageSize(void)
{
return sysconf(_SC_PAGESIZE);
}
long virGetSystemPageSizeKB(void)
{
long val = virGetSystemPageSize();
if (val < 0)
return val;
return val / 1024;
}
......@@ -244,4 +244,7 @@ VIR_ENUM_DECL(virTristateSwitch)
unsigned int virGetListenFDs(void);
long virGetSystemPageSize(void);
long virGetSystemPageSizeKB(void);
#endif /* __VIR_UTIL_H__ */
......@@ -2736,7 +2736,7 @@ xenHypervisorGetMaxMemory(virConnectPtr conn,
int ret;
if (kb_per_pages == 0) {
kb_per_pages = sysconf(_SC_PAGESIZE) / 1024;
kb_per_pages = virGetSystemPageSizeKB();
if (kb_per_pages <= 0)
kb_per_pages = 4;
}
......@@ -2771,7 +2771,7 @@ xenHypervisorGetDomInfo(virConnectPtr conn, int id, virDomainInfoPtr info)
uint32_t domain_flags, domain_state, domain_shutdown_cause;
if (kb_per_pages == 0) {
kb_per_pages = sysconf(_SC_PAGESIZE) / 1024;
kb_per_pages = virGetSystemPageSizeKB();
if (kb_per_pages <= 0)
kb_per_pages = 4;
}
......
......@@ -22,7 +22,15 @@
#include "internal.h"
#include "virnuma.h"
#include "virmock.h"
#include "virutil.h"
#include <time.h>
#include <unistd.h>
long virGetSystemPageSize(void)
{
return 4096;
}
time_t time(time_t *t)
{
......
......@@ -22,6 +22,7 @@
# include "cpu/cpu_map.h"
# include "virstring.h"
# include "storage/storage_driver.h"
# include "virmock.h"
# include "testutilsqemu.h"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册