[PATCH v2 8/9] selftests/mm: Skip map_populate on weird filesystems

Brendan Jackman posted 9 patches 9 months, 4 weeks ago
There is a newer version of this series
[PATCH v2 8/9] selftests/mm: Skip map_populate on weird filesystems
Posted by Brendan Jackman 9 months, 4 weeks ago
It seems that 9pfs does not allow truncating unlinked files, Mark Brown
has noted that NFS may also behave this way.

It doesn't seem quite right to call this a "bug" but it's probably a
special enough case that it makes sense for the test to just SKIP if it
happens.

Signed-off-by: Brendan Jackman <jackmanb@google.com>
---
 tools/testing/selftests/mm/map_populate.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/tools/testing/selftests/mm/map_populate.c b/tools/testing/selftests/mm/map_populate.c
index 5c8a53869b1bd287b09a250edf628a66c25c2439..cdd88531dd9fe98f2d25edf4878659767c919e8e 100644
--- a/tools/testing/selftests/mm/map_populate.c
+++ b/tools/testing/selftests/mm/map_populate.c
@@ -87,6 +87,13 @@ int main(int argc, char **argv)
 	BUG_ON(!ftmp, "tmpfile()");
 
 	ret = ftruncate(fileno(ftmp), MMAP_SZ);
+	if (ret < 0 && errno == ENOENT) {
+		/*
+		 * This probably means tmpfile() made a file on a filesystem
+		 * that doesn't handle temporary files the way we want.
+		 */
+		ksft_exit_skip("ftruncate(fileno(tmpfile())) gave ENOENT, weird filesystem?");
+	}
 	BUG_ON(ret, "ftruncate()");
 
 	smap = mmap(0, MMAP_SZ, PROT_READ | PROT_WRITE,

-- 
2.48.1.601.g30ceb7b040-goog
Re: [PATCH v2 8/9] selftests/mm: Skip map_populate on weird filesystems
Posted by Brendan Jackman 9 months, 3 weeks ago
On Fri, 21 Feb 2025 at 19:26, Brendan Jackman <jackmanb@google.com> wrote:
>
> It seems that 9pfs does not allow truncating unlinked files, Mark Brown
> has noted that NFS may also behave this way.

I have not investigated at all but I _think_ over the weekend I saw
ftruncate() failure on a QEMU guest where /tmp was tmpfs.

Most likely explanation is user probably error (like /tmp wasn't
actually tmpfs or the tmpfile() did not actually come from /tmp). But
still, maybe just waving my hands and going "buggy filesystem, ignore"
wasn't so smart. I should actually understand the problem before
switching off tests.

So, I think this and the other "ignore on weird filesystem" patch 9/9
should be ignored for the moment.
Re: [PATCH v2 8/9] selftests/mm: Skip map_populate on weird filesystems
Posted by Brendan Jackman 9 months, 3 weeks ago
On Mon, 24 Feb 2025 at 11:25, Brendan Jackman <jackmanb@google.com> wrote:
>
> On Fri, 21 Feb 2025 at 19:26, Brendan Jackman <jackmanb@google.com> wrote:
> >
> > It seems that 9pfs does not allow truncating unlinked files, Mark Brown
> > has noted that NFS may also behave this way.
>
> I have not investigated at all but I _think_ over the weekend I saw
> ftruncate() failure on a QEMU guest where /tmp was tmpfs.
>
> Most likely explanation is user probably error (like /tmp wasn't
> actually tmpfs or the tmpfile() did not actually come from /tmp).

OK I double checked. It was in fact a 9p filesystem, turns out
virtme-ng uses that unconditionally for its --rwdir/--rodir mounts
even if the root is virtiofsd, and the tests operate on files in the
CWD as well as in /tmp.

I am still pondering ways to tackle this kinda problem more
systematically but for now I think just skipping these tests is fine.

> +               ksft_exit_skip("ftruncate(fileno(tmpfile())) gave ENOENT, weird filesystem?");

This is missing a newline though, ditto in the subsequent patch. I
will wait and see if any reviews come in before I send a fixup.