performing test on loop device if noatime or relatime specified
PATCH 1/1 performing test on loop device if noatime or relatime specified
Hi,
The noatime test of open12 fails on a distribution which doesn't use tmpfs for /tmp. I have composed a patch to fix it. Please have a look, thanks.
After 2.6.30, kernel specifies relatime option by default. If so then try to mount a loop device using strictatime option to do the noatime test.
--- testcases/kernel/syscalls/open/open12.c | 41 +++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-)
testcases/kernel/syscalls/open/open12.c +37 -4
@@ -24,6 +24,7 @@#include <stdio.h> #include <sys/types.h> #include <sys/wait.h> +#include <sys/mount.h> #include <unistd.h> #include <mntent.h> #include <errno.h>
@@ -34,8 +35,16 @@#define TEST_FILE "test_file"#define LARGE_FILE "large_file" +#define DIR_MODE 0755 +#define MNTPOINT "mntpoint" +char *TCID ="open12" ; +static const char *device; +static const char *fs_type; +static unsigned int mount_flag =0 ; +static unsigned int cd_flag =0 ; +static void setup (void );static void cleanup (void );static void test_append (void );
@@ -114,10 +123,21 @@ static void test_noatime(void) }if (tst_path_has_mnt_flags (cleanup,NULL , flags)) { -tst_resm (TCONF , -"test O_NOATIME flag for open needs filesystems which " -"is mounted without noatime and relatime" ); -return ; + + fs_type =tst_dev_fs_type (); + device =tst_acquire_device (cleanup); + +if (!device) +tst_brkm (TCONF , cleanup,"Failed to obtain block device" ); + +tst_mkfs (cleanup, device, fs_type,NULL ); + +SAFE_MKDIR (cleanup,MNTPOINT ,DIR_MODE ); +SAFE_MOUNT (cleanup, device,MNTPOINT , fs_type,MS_STRICTATIME ,NULL ); + mount_flag =1 ; +SAFE_FILE_PRINTF (cleanup,MNTPOINT "/" TEST_FILE ,TEST_FILE ); +SAFE_CHDIR (cleanup,MNTPOINT ); + cd_flag =1 ; }SAFE_STAT (cleanup,TEST_FILE , &old_stat);
@@ -221,5 +241,18 @@ static void test_largefile(void)static void cleanup (void ) { +if (cd_flag) { +char *tmp_dir =tst_get_tmpdir (); +SAFE_CHDIR (NULL , tmp_dir); +free (tmp_dir); + } + +if (mount_flag &&tst_umount (MNTPOINT ) ==-1 ) { +tst_brkm (TBROK |TERRNO ,NULL ,"umount(2) failed" ); + } + +if (device) +tst_release_device (NULL , device); +tst_rmdir (); }
Signature · 13 lines
1.9.3 ------------------------------------------------------------------------------ One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight. http://ad.doubleclick.net/ddm/clk/290420510;117567292;y _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
Hi!
Quoted 37 lines
testcases/kernel/syscalls/open/open12.c +9
-4@@ -24,6 +24,7 @@#include <stdio.h> #include <sys/types.h> #include <sys/wait.h> +#include <sys/mount.h> #include <unistd.h> #include <mntent.h> #include <errno.h> @@ -34,8 +35,16 @@#define TEST_FILE "test_file"#define LARGE_FILE "large_file" +#define DIR_MODE 0755 +#define MNTPOINT "mntpoint" +char *TCID ="open12" ; +static const char *device; +static const char *fs_type; +static unsigned int mount_flag =0 ; +static unsigned int cd_flag =0 ; +static void setup (void );static void cleanup (void );static void test_append (void );@@ -114,10 +123,21 @@ static void test_noatime(void) }if (tst_path_has_mnt_flags (cleanup,NULL , flags)) { -tst_resm (TCONF , -"test O_NOATIME flag for open needs filesystems which " -"is mounted without noatime and relatime" ); -return ;
testcases/kernel/syscalls/open/open12.c static void test_noatime(void) · line 135
Quoted 10 lines
testcases/kernel/syscalls/open/open12.c +10
-0+ + fs_type =tst_dev_fs_type (); + device =tst_acquire_device (cleanup); + +if (!device) +tst_brkm (TCONF , cleanup,"Failed to obtain block device" ); + +tst_mkfs (cleanup, device, fs_type,NULL ); + +SAFE_MKDIR (cleanup,MNTPOINT ,DIR_MODE );
What about creating a test directory in test temporary directory unconditionally and change the TEST_FILE to point to a file in it? That way we can just mount the loop device over the directory if needed and avoid the ugly chdir here and in the cleanup.
Quoted 10 lines
testcases/kernel/syscalls/open/open12.c +5
-0+SAFE_MOUNT (cleanup, device,MNTPOINT , fs_type,MS_STRICTATIME ,NULL ); + mount_flag =1 ; +SAFE_FILE_PRINTF (cleanup,MNTPOINT "/" TEST_FILE ,TEST_FILE ); +SAFE_CHDIR (cleanup,MNTPOINT ); + cd_flag =1 ; }SAFE_STAT (cleanup,TEST_FILE , &old_stat);@@ -221,5 +241,18 @@ static void test_largefile(void)
testcases/kernel/syscalls/open/open12.c static void test_largefile(void) · line 251
Quoted 10 lines
testcases/kernel/syscalls/open/open12.c +8
-0static void cleanup (void ) { +if (cd_flag) { +char *tmp_dir =tst_get_tmpdir (); +SAFE_CHDIR (NULL , tmp_dir); +free (tmp_dir); + } + +if (mount_flag &&tst_umount (MNTPOINT ) ==-1 ) { +tst_brkm (TBROK |TERRNO ,NULL ,"umount(2) failed" );
This should rather be tst_resm(TWARN | TERRNO, ...) so that we at least attempt to continue the cleanup.
Quoted 6 lines
testcases/kernel/syscalls/open/open12.c +5
-0+ } + +if (device) +tst_release_device (NULL , device); +tst_rmdir ();
Signature · 13 lines
Cyril Hrubis [email protected] ------------------------------------------------------------------------------ One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight. http://ad.doubleclick.net/ddm/clk/290420510;117567292;y _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
Quoted 8 lines · Cyril Hrubis
What about creating a test directory in test temporary directory unconditionally and change the
TEST_FILEto point to a file in it? That way we can just mount the loop device over the directory if needed and avoid the ugly chdir here and in the cleanup.This should rather be
tst_resm(TWARN | TERRNO, ...)so that we at least attempt to continue the cleanup.
Thanks. I have revised the patch according to your suggestions.
From 1cdaff6a5658a544f0968ec3e336ffff191ebc30 Mon Sep 17 00:00:00 2001
From: Han Pingtian <[email protected]>
Date: Mon, 4 May 2015 13:44:51 +0800
Subject: [PATCH] performing test on loop device if noatime or relatime
specified
After 2.6.30, kernel specifies relatime option by default. If so then try to mount a loop device using strictatime option to do the noatime test.
--- testcases/kernel/syscalls/open/open12.c | 40 ++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-)
testcases/kernel/syscalls/open/open12.c +35 -5
@@ -24,6 +24,7 @@#include <stdio.h> #include <sys/types.h> #include <sys/wait.h> +#include <sys/mount.h> #include <unistd.h> #include <mntent.h> #include <errno.h>
@@ -31,11 +32,17 @@#include "safe_macros.h" #include "lapi/fcntl.h" -#define TEST_FILE "test_file" +#define MNTPOINT "mntpoint" +#define TEST_FILE MNTPOINT"/test_file"#define LARGE_FILE "large_file" +#define DIR_MODE 0755 +char *TCID ="open12" ; +static const char *device; +static unsigned int mount_flag =0 ; +static void setup (void );static void cleanup (void );static void test_append (void );
@@ -75,6 +82,8 @@ static void setup(void)tst_tmpdir (); +SAFE_MKDIR (cleanup,MNTPOINT ,DIR_MODE ); +SAFE_FILE_PRINTF (cleanup,TEST_FILE ,TEST_FILE ); }
@@ -114,10 +123,18 @@ static void test_noatime(void) }if (tst_path_has_mnt_flags (cleanup,NULL , flags)) { -tst_resm (TCONF , -"test O_NOATIME flag for open needs filesystems which " -"is mounted without noatime and relatime" ); -return ; + +const char *fs_type =tst_dev_fs_type (); + device =tst_acquire_device (cleanup); + +if (!device) +tst_brkm (TCONF , cleanup,"Failed to obtain block device" ); + +tst_mkfs (cleanup, device, fs_type,NULL ); + +SAFE_MOUNT (cleanup, device,MNTPOINT , fs_type,MS_STRICTATIME ,NULL ); + mount_flag =1 ; +SAFE_FILE_PRINTF (cleanup,TEST_FILE ,TEST_FILE ); }SAFE_STAT (cleanup,TEST_FILE , &old_stat);
@@ -138,6 +155,13 @@ static void test_noatime(void)tst_resm (TPASS ,"test O_NOATIME for open success" ); else tst_resm(TFAIL, "test O_NOATIME for open failed"); + +if (mount_flag) { + mount_flag =0 ; + +if (tst_umount (MNTPOINT ) ==-1 ) +tst_brkm (TBROK |TERRNO , cleanup,"umount(2) failed" ); + } }static void test_cloexec (void )
@@ -221,5 +245,11 @@ static void test_largefile(void)static void cleanup (void ) { +if (mount_flag &&tst_umount (MNTPOINT ) ==-1 ) +tst_brkm (TWARN |TERRNO ,NULL ,"umount(2) failed" ); + +if (device) +tst_release_device (NULL , device); +tst_rmdir (); }
Signature · 13 lines
1.9.3 ------------------------------------------------------------------------------ One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight. http://ad.doubleclick.net/ddm/clk/290420510;117567292;y _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
Hi!
Quoted 1 line
Thanks. I have revised the patch according to your suggestions.
Pushed with following modifications, thanks.
* The device preparation must be done only once in setup() otherwise the testcase fails with -i 2
* The testcase was previously working fine when executed as non-root user, I've made some changes so that this continues to work as well
Signature · 13 lines
Cyril Hrubis [email protected] ------------------------------------------------------------------------------ One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight. http://ad.doubleclick.net/ddm/clk/290420510;117567292;y _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
Quoted 12 lines · Cyril Hrubis
Hi!
Quoted 1 line
Thanks. I have revised the patch according to your suggestions.
Pushed with following modifications, thanks.
* The device preparation must be done only once in
setup()otherwise the testcase fails with -i 2* The testcase was previously working fine when executed as non-root user, I've made some changes so that this continues to work as well
Thanks!
------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
testcases/kernel/syscalls/open/open12.c static void test_noatime(void) · line 138
Quoted 6 lines
testcases/kernel/syscalls/open/open12.c +4
-0+ +SAFE_MOUNT (cleanup, device,MNTPOINT , fs_type,MS_STRICTATIME ,NULL ); + mount_flag =1 ; +SAFE_FILE_PRINTF (cleanup,TEST_FILE ,TEST_FILE ); }
Hi,
I run the LTP today:
.configure
make
then compile error:
gcc -g -O2 -g -O2 -fno-strict-aliasing -pipe -Wall -W -g -O2 -Wold-style-definition -D_FORTIFY_SOURCE=2 -I/home/cuibixuan/home/git/ltp/ltp/testcases/kernel/include -I../../../../include -I../../../../include -L../../../../lib open12.c -lltp -o open12open12.c: In function ‘setup’:
open12.c:103: error: ‘MS_STRICTATIME’ undeclared (first use in this function) open12.c:103: error: (Each undeclared identifier is reported only once open12.c:103: error: for each function it appears in.)
make[4]: *** [open12] Error 1
make[4]: Leaving directory `/home/cuibixuan/home/git/ltp/ltp/testcases/kernel/syscalls/open'
Do 'man mount' and can not find 'MS_STRICTATIME'.
I get from man-pages of linux:MS_STRICTATIME (since Linux 2.6.30)
Always update the last access time (atime) when files on this filesystem are accessed. (This was the default behavior before Linux 2.6.30.) Specifying this flag overrides the effect of setting the MS_NOATIME and MS_RELATIME flags.
If not support 'MS_STRICTATIME'?
My system is SUSE11-SP2, linux 3.0.13, and gcc version 4.3.4.
------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
Hi!
Quoted 18 lines
then compile error:
gcc -g -O2 -g -O2 -fno-strict-aliasing -pipe -Wall -W -g -O2 -Wold-style-definition -D_FORTIFY_SOURCE=2 -I/home/cuibixuan/home/git/ltp/ltp/testcases/kernel/include -I../../../../include -I../../../../include -L../../../../libopen12.c-lltp -o open12open12.c: In function ?setup?:
open12.c:103: error: ?MS_STRICTATIME? undeclared (first use in this function) open12.c:103: error: (Each undeclared identifier is reported only once open12.c:103: error: for each function it appears in.)
make[4]: *** [open12] Error 1
make[4]: Leaving directory `/home/cuibixuan/home/git/ltp/ltp/testcases/kernel/syscalls/open'Do 'man mount' and can not find '
MS_STRICTATIME'.I get from man-pages of linux:
MS_STRICTATIME(since Linux 2.6.30)
Always update the last access time (atime) when files on this filesystem are accessed. (This was the default behavior before Linux 2.6.30.) Specifying this flag overrides the effect of setting theMS_NOATIMEandMS_RELATIMEflags.
Quoted 2 lines
If not support '
MS_STRICTATIME'?
My system is SUSE11-SP2, linux 3.0.13, and gcc version 4.3.4.
Solution to compilation failures is to add fallback definition into ltp/include/lapi/mount.h (have a look at ltp/include/lapi/fcntl.h) and include it in the testcase source. That would make the testcase compile, but it may still fail when executed. To fix the execution we would need to do a runtime check if the kernel supports this flag, I guess that we would need to pass it only on newer kernels (we use tst_kvercmp() for that).
Signature · 13 lines
Cyril Hrubis [email protected] ------------------------------------------------------------------------------ One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight. http://ad.doubleclick.net/ddm/clk/290420510;117567292;y _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
A message that is not in the archive (sent off-list or not yet received): [email protected]
Hi!
Quoted 10 lines
Quoted 7 lines
Quoted 7 lines
then compile error:
gcc -g -O2 -g -O2 -fno-strict-aliasing -pipe -Wall -W -g -O2 -Wold-style-definition -D_FORTIFY_SOURCE=2 -I/home/cuibixuan/home/git/ltp/ltp/testcases/kernel/include -I../../../../include -I../../../../include -L../../../../libopen12.c-lltp -o open12open12.c: In function ?setup?:
open12.c:103: error: ?MS_STRICTATIME? undeclared (first use in this function) open12.c:103: error: (Each undeclared identifier is reported only once open12.c:103: error: for each function it appears in.)
make[4]: *** [open12] Error 1Compile error '
MS_STRICTATIMEundeclared' because my glibc version(2.11) is too old. I upgrade it then compile succeed.
That is not a solution. The solution is to create a fallback declaration in LTP as I said.
Signature · 13 lines
Cyril Hrubis [email protected] ------------------------------------------------------------------------------ One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight. http://ad.doubleclick.net/ddm/clk/290420510;117567292;y _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [LTP] [PATCH] open/open12: compile error
Hi!
Quoted 1 line
The '
MS_STRICTATIME' flag is not defined in old kernel.Now add
^ libc
The system headers are supplied by glibc.
Quoted 22 lines
it into
include/lapi/mount.hand include it in testcase source.Signed-off-by Cui Bixuan <[email protected]>---
Cat/usr/include/x86_64-linux-gnu/sys/mount.hin Ubuntu14 and find 'MS_STRICTATIME' flag:MS_STRICTATIME= 1 << 24, /* Always perform atime updates. */So add it into
include/lapi/mount.h
And thank you for your advice,My idea is wrong.include/lapi/mount.h | 26 ++++++++++++++++++++++++++ testcases/kernel/syscalls/open/open12.c | 1 + 2 files changed, 27 insertions(+), 0 deletions(-) create mode 100644 include/lapi/mount.hinclude/lapi/mount.h new file +0
-0
include/lapi/mount.h line 2
Quoted 2 lines
include/lapi/mount.h new file +2
-0@@ -0,0 +1,26 @@ +/* +* Copyright (c) 2014 Cyril Hrubis <[email protected]>
^
Should be your name and current year. :)
Quoted 37 lines
include/lapi/mount.h new file +23
-0+* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License, or (at your option) any later version. +* +* This program is distributed in the hope that it would be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write the Free Software Foundation, +* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef __MOUNT_H__ +#define __MOUNT_H__ + +#ifndef MS_STRICTATIME +#define MS_STRICTATIME 1 << 24 +#endif + +#endif /* __MOUNT_H__ */ testcases/kernel/syscalls/open/open12.c +1
-0@@ -31,6 +31,7 @@#include "test.h" #include "safe_macros.h" #include "lapi/fcntl.h" +#include "lapi/mount.h" #define MNTPOINT "mntpoint"#define TEST_FILE MNTPOINT"/test_file"Signature · 1 line
1.6.0.2
Signature · 13 lines
Cyril Hrubis [email protected] ------------------------------------------------------------------------------ One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight. http://ad.doubleclick.net/ddm/clk/290420510;117567292;y _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [LTP] [PATCH] open/open12: Check the kernel version for 'MS_STRICTATIME'
Hi!
Quoted 13 lines
Call
tst_kvercmp()to check the kernel version(newer than 2.6.30) before callingSAFE_MOUNT( MS_STRICTATIME ).Signed-off-by Cui Bixuan <[email protected]>--- testcases/kernel/syscalls/open/open12.c | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)testcases/kernel/syscalls/open/open12.c +0
-0
testcases/kernel/syscalls/open/open12.c static void setup(void) · line 88
Quoted 9 lines
testcases/kernel/syscalls/open/open12.c +6
-0@@ -80,6 +80,13 @@ static void setup(void)TEST_PAUSE ; +if ((tst_kvercmp (2 ,6 ,30 )) <0 ) { +tst_resm (TCONF , +"MS_STRICTATIME flags for mount(2) needs kernel 2.6.30 " +"or higher" ); +return ; + }
This is not right place to do it. The flag is used only when we need to mount the loop device so the check should be done only if we are about to acquire the device. And we should set the skip_noatime flag there as well.
Signature · 13 lines
Cyril Hrubis [email protected] ------------------------------------------------------------------------------ One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight. http://ad.doubleclick.net/ddm/clk/290420510;117567292;y _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [LTP] [PATCH] open/open12: Check the kernel version for 'MS_STRICTATIME'
Hi!
Quoted 7 lines
Quoted 5 lines
This is not right place to do it. The flag is used only when we need to mount the loop device so the check should be done only if we are about to acquire the device. And we should set the
skip_noatimeflag there as well.Your opinion is to add the check after
if (tst_path_has_mnt_flags(cleanup, NULL, mount_flags))and then set theskip_noatimeflag to 1 ?
Yes, because there is no need to skip the test if we are not even going to mount the loop device.
Signature · 13 lines
Cyril Hrubis [email protected] ------------------------------------------------------------------------------ One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight. http://ad.doubleclick.net/ddm/clk/290420510;117567292;y _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [LTP] [PATCH 2/2 v2] open/open12: Check the kernel version for 'MS_STRICTATIME'
Hi!
Both patches pushed with a minor commit message formatting change, thanks.
Signature · 8 lines
Cyril Hrubis [email protected] ------------------------------------------------------------------------------ _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list