The multiple mounts patch introduces a slight semantic change that affects the quota test case. Prior to the patch, the hugetlbfs mount point was discovered when hugetlbfs_unlinked_fd() was called for the first time. Now the mount points are discovered by the library constructor. This means that the method of setting HUGETLB_PATH and then calling hugetlbfs_unlinked_fd() will not provide a fd from the desired mount point.
HUGETLB_PATH must be set before library initialization so change the quota test to operate in two stages. The first stage is to create the desired mount point and set HUGETLB_PATH to this mount. The second stage is entered by exec'ing the quota test again with an argument indicating that a mount point has been set up. In phase two, libhugetlbfs has been allowed to initialize with the desired mount point that was created in phase one and so the test can proceed as it always has. Additionally, if the libhugetlbfs default mount point has a page size that is not the kernel default page size, the pagesize= mount option must be specified when the quota test creates its mount point. Signed-off-by: Adam Litke <[EMAIL PROTECTED]> --- tests/quota.c | 56 ++++++++++++++++++++++++++++++++++++++------------------ 1 files changed, 38 insertions(+), 18 deletions(-) diff --git a/tests/quota.c b/tests/quota.c index 5a62d82..3dc9dcd 100644 --- a/tests/quota.c +++ b/tests/quota.c @@ -52,7 +52,7 @@ extern int errno; /* Global test configuration */ static long hpage_size; -static char mountpoint[17]; +char *mountpoint = NULL; /* map action flags */ #define ACTION_COW 0x0001 @@ -67,7 +67,7 @@ char result_str[3][10] = { "pass", "killed", "fail" }; void cleanup(void) { - if (umount(mountpoint) == 0) + if (mountpoint && (umount(mountpoint) == 0)) rmdir(mountpoint); } @@ -86,31 +86,47 @@ void _verify_stat(int line, long tot, long free, long avail) } #define verify_stat(t, f, a) _verify_stat(__LINE__, t, f, a) -void get_quota_fs(unsigned long size) +void get_quota_fs(unsigned long size, char *prog) { - char size_str[20]; + char mount_str[17]; + char mount_opts[50]; + int nr_written; - snprintf(size_str, 20, "size=%luK", size/1024); + nr_written = snprintf(mount_opts, 20, "size=%luK", size/1024); - sprintf(mountpoint, "/tmp/huge-XXXXXX"); - if (!mkdtemp(mountpoint)) + /* + * If the mount point now in use does not use the system default + * huge page size, specify the desired size when mounting. When + * the sizes do match, we avoid specifying the pagesize= option to + * preserve backwards compatibility with kernels that do not + * recognize that option. + */ + if (!using_system_hpage_size(hugetlbfs_find_path())) + snprintf(mount_opts + nr_written, 29, ",pagesize=%lu", + hpage_size); + + sprintf(mount_str, "/tmp/huge-XXXXXX"); + if (!mkdtemp(mount_str)) FAIL("Cannot create directory for mountpoint: %s", strerror(errno)); - if (mount("none", mountpoint, "hugetlbfs", 0, size_str)) { + if (mount("none", mount_str, "hugetlbfs", 0, mount_opts)) { perror("mount"); FAIL(); } + mountpoint = mount_str; /* - * Set HUGETLB_PATH so future calls to hugetlbfs_unlinked_fd() - * will use this mountpoint. + * Set HUGETLB_PATH and then exec the test again. This will cause + * libhugetlbfs to use this newly created mountpoint. */ - if (setenv("HUGETLB_PATH", mountpoint, 1)) + if (setenv("HUGETLB_PATH", mount_str, 1)) FAIL("Cannot set HUGETLB_PATH environment variable: %s", strerror(errno)); + verbose_printf("Using %s as temporary mount point.\n", mount_str); - verbose_printf("Using %s as temporary mount point.\n", mountpoint); + execlp(prog, prog, "-p", mount_str, NULL); + FAIL("execle failed: %s", strerror(errno)); } void map(unsigned long size, int mmap_flags, int action_flags) @@ -192,20 +208,24 @@ void _spawn(int l, int expected_result, unsigned long size, int mmap_flags, int main(int argc, char ** argv) { int fd, private_resv; + int bad_priv_resv; test_init(argc, argv); - check_must_be_root(); - mountpoint[0] = '\0'; hpage_size = check_hugepagesize(); - int bad_priv_resv; + if ((argc == 3) && !strcmp(argv[1], "-p")) + mountpoint = argv[2]; + else + get_quota_fs(hpage_size, argv[0]); + + check_must_be_root(); check_free_huge_pages(1); - get_quota_fs(hpage_size); fd = hugetlbfs_unlinked_fd(); - if ((private_resv = kernel_has_private_reservations(fd)) == -1) - FAIL("kernel_has_private_reservations() failed\n"); + private_resv = kernel_has_private_reservations(fd); close(fd); + if (private_resv == -1) + FAIL("kernel_has_private_reservations() failed\n"); bad_priv_resv = private_resv ? BAD_EXIT : BAD_SIG; /* ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Libhugetlbfs-devel mailing list Libhugetlbfs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel