Skip to contentSkip to conversation

mmap21: Check for free space before mapping the file

PATCH In review Victor Cheng-Yen Yang via ltp 3 participants 4 messages Sep 8 – Sep 14

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mmap21: Check for free space before mapping the file

From: Victor Cheng-Yen Yang <[email protected]>

The test creates a sparse file with lseek() and a one byte write, so mmap() allocates no blocks. The child then touches every byte and ext4 fills the holes inside ext4_page_mkwrite(). A store instruction has no error return, so an ENOSPC there becomes VM_FAULT_SIGBUS and the test reports only

tst_test.c:536: TBROK: Child (13042) killed by signal SIGBUS

which says nothing about the full filesystem. The information is available before the mapping and gone after it, so check it in setup and report TCONF earlier as convention.

---
 testcases/kernel/syscalls/mmap/mmap21.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
testcases/kernel/syscalls/mmap/mmap21.c +14 -0
index ea3ae835a..3d6e8bd46 100644
@@ -10,6 +10,7 @@
  * access, and read back the data from the file.
  */
 
+#include <sys/vfs.h>
 #include "tst_test.h"
 
 #define FILE_NAME "testfile"
@@ -71,11 +72,24 @@ exit:
 
 static void setup(void)
 {
+	struct statfs sf;
+	unsigned long long needed, avail;
+
 	if (tst_parse_filesize(str_pages, &pages, 1, LLONG_MAX))
 		tst_brk(TBROK, "Invalid number of pages: %s", str_pages);
 
 	memory_size = pages * getpagesize();
 
+	/* the byte written past the mapping costs a whole block */
+	SAFE_STATFS(".", &sf);
+	needed = memory_size + sf.f_bsize;
+	avail = (unsigned long long)sf.f_bavail * sf.f_bsize;
+
+	if (!tst_fs_has_free(".", needed, TST_BYTES)) {
+		tst_brk(TCONF, "Not enough free space, test needs %llu bytes, %llu available",
+			needed, avail);
+	}
+
 	buff = SAFE_MALLOC(memory_size);
 }
 
Signature · 5 lines
2.55.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi Victor,

Quoted 1 line · Victor Cheng-Yen Yang

mmap21: Check for free space before mapping the file

Verdict - Reviewed

---
Note:

The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw
In reply to Victor Cheng-Yen Yang via ltp

Hi!

Quoted 11 lines

The test creates a sparse file with lseek() and a one byte write, so mmap() allocates no blocks. The child then touches every byte and ext4 fills the holes inside ext4_page_mkwrite(). A store instruction has no error return, so an ENOSPC there becomes VM_FAULT_SIGBUS and the test reports only

tst_test.c:536: TBROK: Child (13042) killed by signal SIGBUS

which says nothing about the full filesystem. The information is available before the mapping and gone after it, so check it in setup and report TCONF earlier as convention.

Depending on the page size this is either 4MB or 64MB, I would say that if you run LTP on a machine with less than 4MB of free space many tests would fail.

Maybe it would make sense to print a warning from the test library for any tests that has needs_tmpdir == 1 and the free space at the test temporary directory is less than a few megabytes.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

Hi Cyril,

Quoted 3 lines

Depending on the page size this is either 4MB or 64MB, I would say that if you run LTP on a machine with less than 4MB of free space many tests would fail.

I agree with you. In our test environment, we did provide mmap21 with sufficient space. mmap21 was the victim because certain shell test did not clean up properly and filled up the disk.

Quoted 3 lines

Maybe it would make sense to print a warning from the test library for any tests that has needs_tmpdir == 1 and the free space at the test temporary directory is less than a few megabytes.

I'll work on this in the near future. Printing warning messages from the test library is indeed an elegant way. Thanks for your idea!

Best Regards,
Victor

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp