From: Ackerley Tng <[email protected]>

Verify that allocating folios in multiple guest_memfd instances sharing
the same tmpfs resource pool consumes blocks from the underlying pool as
reported by filesystem statistics.

Signed-off-by: Ackerley Tng <[email protected]>
---
 tools/testing/selftests/kvm/guest_memfd_test.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/kvm/guest_memfd_test.c 
b/tools/testing/selftests/kvm/guest_memfd_test.c
index 81311be059923..4610eeab39be6 100644
--- a/tools/testing/selftests/kvm/guest_memfd_test.c
+++ b/tools/testing/selftests/kvm/guest_memfd_test.c
@@ -19,6 +19,7 @@
 #include <sys/mount.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <sys/statvfs.h>
 
 #include "kvm_syscalls.h"
 #include "kvm_util.h"
@@ -545,7 +546,8 @@ static void test_resource_fd_tmpfs_huge(struct kvm_vm *vm)
 
 static void test_resource_fd_tmpfs_shared_pool(struct kvm_vm *vm)
 {
-       int pool_fd, fd1, fd2;
+       int pool_fd, fd1, fd2, ret;
+       struct statvfs svfs;
        struct stat st1, st2;
 
        pool_fd = create_tmpfs_pool_fd("never", true, page_size * 2);
@@ -573,6 +575,18 @@ static void test_resource_fd_tmpfs_shared_pool(struct 
kvm_vm *vm)
        TEST_ASSERT(st1.st_ino != st2.st_ino,
                    "different guest_memfd instances should have distinct 
inodes");
 
+       ret = fallocate(fd1, FALLOC_FL_KEEP_SIZE, 0, page_size);
+       TEST_ASSERT(!ret, "fallocate on fd1 should succeed");
+
+       TEST_ASSERT(!fstatvfs(pool_fd, &svfs), "fstatvfs on pool_fd should 
succeed");
+       TEST_ASSERT_EQ(svfs.f_blocks - svfs.f_bfree, 1);
+
+       ret = fallocate(fd2, FALLOC_FL_KEEP_SIZE, 0, page_size);
+       TEST_ASSERT(!ret, "fallocate on fd2 should succeed");
+
+       TEST_ASSERT(!fstatvfs(pool_fd, &svfs), "fstatvfs on pool_fd should 
succeed");
+       TEST_ASSERT_EQ(svfs.f_blocks - svfs.f_bfree, 2);
+
        close(fd2);
        close(fd1);
        close(pool_fd);

-- 
2.56.0.rc1.315.gc6ed9934b7-goog



Reply via email to