Skip to contentSkip to conversation

libltp: add support to mount tmpfs for EROFS testing

PATCH New Sandeep Patil 2 participants 3 messages Sep 19, 2017 – Sep 25, 2017 Library code

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/2 libltp: add support to mount tmpfs for EROFS testing

Some tests go through losetup, create, format and mount filesystems only to test for 'EROFS' return value from system calls. The tests end up being flaky depending on the tools available on the platform. e.g. mkfs.<filesystem> tool is required for mounting a device with filesystem.

If the test is only to check for EROFS, this can be achieved by simply by the bind mounting (MS_BIND) for '/' on 'mntpoint' and then remount the same as 'read-only'.

Example of tests that can benefit from this are:
access04, mkdirat02, mknodat02, acct01, fchown04, mknod07 etc.

This also allows for these tests to successfully run on Android.

---

v3->v4
------
- s/mntpoint_active/mntpoint_mounted
- removed duplicate check for tst_test->mntpoint
- added TERRNO to the message about unsuccessful tmpfs mount

v2->v3
------
- Added Tested-by from Jan Stancek

v1->v2
------
- Changed the interface to be at a higher level, i.e. instead of making tests specify that they need a read-only tmpfs mount, we do that automatically in the library as a preference and fallback to the old way if that doesn't succeed.

- The read-only bind mount of "/" option was tried and it worked just fine with an Android system, but broke my ubuntu instance badly (I lost root). I could never find out why, since hte patch worked fine on Android and it correctly did the bind mount. However, I figured if there is any chance of possible breakage, we should simply avoid that path for now.

 include/tst_test.h |  1 +
 lib/tst_test.c     | 41 ++++++++++++++++++++++++++++++-----------
 2 files changed, 31 insertions(+), 11 deletions(-)
include/tst_test.h +1 -0
index e90312ae3..ad468e8cf 100644
@@ -124,6 +124,7 @@ struct tst_test {
 	int needs_checkpoints:1;
 	int format_device:1;
 	int mount_device:1;
+	int needs_rofs:1;
 
 	/* Minimal device size in megabytes */
 	unsigned int dev_min_size;
lib/tst_test.c +30 -11

73 lines not on this page · raw message

Signature · 1 line
2.14.1.690.gbb1197296e-goog
#1 lore raw

PATCH v4 2/2 syscalls/access04: use .needs_rofs flag for EROFS testing

Prefer to use the read-only bind mount of '/' over create, format and mount a filesystem image for testing 'EROFS' return value from access()

---
 testcases/kernel/syscalls/access/access04.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
testcases/kernel/syscalls/access/access04.c +1 -2
index dbb6d271a..626e6df2c 100644
@@ -125,9 +125,8 @@ static struct tst_test test = {
 	.needs_tmpdir = 1,
 	.needs_root = 1,
 	.forks_child = 1,
-	.mount_device = 1,
+	.needs_rofs = 1,
 	.mntpoint = MNT_POINT,
-	.mnt_flags = MS_RDONLY,
 	.setup = setup,
 	.test = verify_access,
 };
Signature · 1 line
2.14.1.690.gbb1197296e-goog
#2 lore raw

PATCH v4 1/2 libltp: add support to mount tmpfs for EROFS testing

In reply to Sandeep Patil

Hi!

Quoted 3 lines

If the test is only to check for EROFS, this can be achieved by simply by the bind mounting (MS_BIND) for '/' on 'mntpoint' and then remount the same as 'read-only'.

I've fixed this part of the changelog since we use tmpfs instead of bind mount.

Quoted 7 lines

Example of tests that can benefit from this are:
access04, mkdirat02, mknodat02, acct01, fchown04, mknod07 etc.

This also allows for these tests to successfully run on Android.

...

lib/tst_test.c static void do_setup(int argc, char *argv[]) · line 716

Quoted 4 lines
lib/tst_test.c +4 -0
+	if (tst_test->needs_rofs) {
+		/* If we failed to do read-only bind mount for '/'. Fallback to
+		 * using a device with empty read-only filesystem.
+		 */

And this comment as well.

And pushed, thanks.

Signature · 2 lines
Cyril Hrubis
[email protected]