syscalls/ftruncate04: TCONF on kernels without MANDLOCK
PATCH 1/1 syscalls/ftruncate04: TCONF on kernels without MANDLOCK
Upstream kernel commit
9e8925b67a809bb27ce4b7d352d67f25cf1d7fc5
locks: Allow disabling mandatory locking at compile time
added a config option to remove support for mandatory locking (mount -o mand, MS_MANDLOCK), which went into v4.5.
Some distributions (like Fedora) already disable it, causing ftruncate04 to fail:
ftruncate04 1 TBROK : safe_macros.c:728: ftruncate04.c:247:mount(/dev/loop0, dir/, ext2, 64, (nil)) failed: errno=EPERM(1):
Operation not permitted
As the kernel returns EPERM in this case, there's no easy reliable way of checking whether MANDLOCK is supported - instead, we perform "regular" mount, to catch EPERM due to other causes early, and then remount with MS_MANDLOCK.
If the remount triggers EPERM, the kernel was likely compiled without CONFIG_MANDATORY_FILE_LOCKING.
--- testcases/kernel/syscalls/ftruncate/ftruncate04.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/ftruncate/ftruncate04.c +16 -2
@@ -240,10 +240,24 @@ static void setup(void)if (!device)tst_brkm (TCONF , cleanup,"Failed to obtain block device" ); -tst_mkfs (cleanup, device, fs_type,NULL ,NULL ); +/* the kernel returns EPERM when CONFIG_MANDATORY_FILE_LOCKING is not +* supported - to avoid false negatives, mount the fs first without +* flags and then remount it as MS_MANDLOCK */ -SAFE_MOUNT (NULL , device,MOUNT_DIR , fs_type,MS_MANDLOCK ,NULL ); +tst_mkfs (cleanup, device, fs_type,NULL ,NULL ); +SAFE_MOUNT (cleanup, device,MOUNT_DIR , fs_type,0 ,NULL ); mount_flag =1 ; + +if (mount (NULL ,MOUNT_DIR ,NULL ,MS_REMOUNT |MS_MANDLOCK ,NULL ) ==-1 ) { +if (errno ==EPERM ) { +tst_brkm (TCONF , cleanup,"Mandatory locking (likely) " +"not supported by this system" ); + }else { +tst_brkm (TBROK , cleanup, +"Remount with MS_MANDLOCK failed: %s" , +strerror (errno)); + } + } }static void cleanup (void )
Signature · 1 line
2.4.3
PATCH 1/1 syscalls/ftruncate04: TCONF on kernels without MANDLOCK
Hi!
Pushed with following change:
testcases/kernel/syscalls/ftruncate/ftruncate04.c +2 -3
@@ -253,9 +253,8 @@ static void setup(void)tst_brkm (TCONF , cleanup,"Mandatory locking (likely) " "not supported by this system" ); }else { -tst_brkm (TBROK , cleanup, -"Remount with MS_MANDLOCK failed: %s" , -strerror (errno)); +tst_brkm (TBROK |TERRNO , cleanup, +"Remount with MS_MANDLOCK failed" ); } } }
Since in LTP we prefer TERRNO flag over strerror().
Thanks.
Signature · 2 lines
Cyril Hrubis [email protected]