tst_mkfs: add new parameter extra_opts to tst_mkfs function
PATCH 1/2 tst_mkfs: add new parameter extra_opts to tst_mkfs function
mmap16 always hit ETIMEDOUT error, if the test device is too large. mkfs on the device will take lots of time. So I want to make ext4 with an appointed size. But the [fs_size] need behind the device name, e.g. "mkfs -t ext4 dev [fs_size]".
Due to above reason, add a new parameter extra_opts to tst_mkfs. extra_opts store the options need to behind the device name of mkfs. Then mmap16 can make ext4 with an appointed (small) size.
Because of tst_mkfs be changed, all testcases which use tst_mkfs add NULL parameter for extra_opts.
---
Hi Cyril,
As we talked, I make this V3 patch for mmap16 ETIMEDOUT problem. This patch follow your suggestion, and I have tested it simply.
Thanks,
Zorro
doc/test-writing-guidelines.txt | 10 ++++++-- include/test.h | 6 +++-- lib/tests/tst_device.c | 2 +- lib/tst_mkfs.c | 30 +++++++++++++++++++--- testcases/kernel/io/direct_io/dma_thread_diotest.c | 2 +- testcases/kernel/syscalls/access/access06.c | 2 +- testcases/kernel/syscalls/acct/acct01.c | 2 +- testcases/kernel/syscalls/chmod/chmod06.c | 2 +- testcases/kernel/syscalls/chown/chown04.c | 2 +- testcases/kernel/syscalls/creat/creat06.c | 2 +- testcases/kernel/syscalls/fchmod/fchmod06.c | 2 +- testcases/kernel/syscalls/fchown/fchown04.c | 2 +- testcases/kernel/syscalls/ftruncate/ftruncate04.c | 2 +- testcases/kernel/syscalls/inotify/inotify03.c | 2 +- testcases/kernel/syscalls/lchown/lchown03.c | 2 +- testcases/kernel/syscalls/link/link08.c | 2 +- testcases/kernel/syscalls/linkat/linkat02.c | 2 +- testcases/kernel/syscalls/mkdir/mkdir03.c | 2 +- testcases/kernel/syscalls/mkdirat/mkdirat02.c | 2 +- testcases/kernel/syscalls/mknod/mknod07.c | 2 +- testcases/kernel/syscalls/mknodat/mknodat02.c | 2 +- testcases/kernel/syscalls/mmap/mmap16.c | 2 +- testcases/kernel/syscalls/mount/mount01.c | 2 +- testcases/kernel/syscalls/mount/mount02.c | 2 +- testcases/kernel/syscalls/mount/mount03.c | 2 +- testcases/kernel/syscalls/mount/mount04.c | 2 +- testcases/kernel/syscalls/mount/mount05.c | 2 +- testcases/kernel/syscalls/mount/mount06.c | 2 +- testcases/kernel/syscalls/open/open12.c | 2 +- testcases/kernel/syscalls/quotactl/quotactl02.c | 2 +- testcases/kernel/syscalls/rename/rename11.c | 2 +- testcases/kernel/syscalls/renameat/renameat01.c | 2 +- testcases/kernel/syscalls/rmdir/rmdir02.c | 2 +- testcases/kernel/syscalls/umount/umount01.c | 2 +- testcases/kernel/syscalls/umount/umount02.c | 2 +- testcases/kernel/syscalls/umount/umount03.c | 2 +- testcases/kernel/syscalls/umount2/umount2_01.c | 2 +- testcases/kernel/syscalls/umount2/umount2_02.c | 2 +- testcases/kernel/syscalls/umount2/umount2_03.c | 2 +- testcases/kernel/syscalls/utime/utime06.c | 2 +- testcases/kernel/syscalls/utimes/utimes01.c | 2 +- 41 files changed, 77 insertions(+), 45 deletions(-)
doc/test-writing-guidelines.txt +8 -2
@@ -906,15 +906,21 @@ NOTE: The default filesytem is hardcoded to 'ext2' in the sources and can be #include "test.h" void tst_mkfs(void (cleanup_fn)(void), const char *dev, - const char *fs_type, const char *const fs_opts[]); + const char *fs_type, const char *const fs_opts[] + const char *extra_opts); ------------------------------------------------------------------------------- This function takes a path to a device, filesystem type and an array of extra options passed to mkfs. -The extra options 'fs_opts' should either be 'NULL' if there are none, or a +The fs options 'fs_opts' should either be 'NULL' if there are none, or a 'NULL' terminated array of strings such as '{"-b", "1024", NULL}'. +The extra options 'extra_opts' should either be 'NULL' if there are none, or +a string such as "102400". 'extra_opts' will be used behind device name. e.g: +mkfs -t ext4 -b 1024 /dev/sda1 102400 + ^^^^^^ + 2.2.16 Verifying a filesystem's free space ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
include/test.h +4 -2
@@ -316,10 +316,12 @@ int tst_system(const char *command);* * @dev: path to a device * @fs_type: filesystem type -* @fs_opts: NULL or NULL terminated array of extra mkfs options +* @fs_opts: NULL or NULL terminated array of mkfs options +* @extra_opts: extranal mkfs options which need to behind the device name */ void tst_mkfs (void (cleanup_fn )(void ),const char *dev, -const char *fs_type,const char *const fs_opts[]); +const char *fs_type,const char *const fs_opts[], +const char *extra_opts);/* * Returns filesystem type to be used for the testing. Unless your test is
lib/tests/tst_device.c +1 -1
@@ -46,7 +46,7 @@ int main(void)printf ("Test device='%s'\n" , dev); -tst_mkfs (cleanup, dev,"ext2" ,NULL ); +tst_mkfs (cleanup, dev,"ext2" ,NULL ,NULL );cleanup ();tst_exit ();
lib/tst_mkfs.c +27 -3
@@ -21,12 +21,24 @@#define OPTS_MAX 32 +/* +* tst_mkfs: mkfs.$fs_type on $dev with options $fs_opts and $extra_opts +* cleanup_fn - run it when exit with error. +* dev - device path name +* fs_opts - store the options for mkfs (except -t fs_type). Set +* NULL if don't need options. +* extra_opts - extranal mkfs options for mkfs, these options need +* behind the device name, e.g. [fs_size] for ext4. +* Set NULL, if don't need options behind device name. +*/ void tst_mkfs (void (cleanup_fn )(void ),const char *dev, -const char *fs_type,const char *const fs_opts[]) +const char *fs_type,const char *const fs_opts[], +const char *extra_opts) {int i, pos =3 ;const char *argv[OPTS_MAX ] = {"mkfs" ,"-t" , fs_type};char fs_opts_str[1024 ] ="" ; +const char *fs_extra_opts = extra_opts;if (!fs_type)tst_brkm (TBROK , cleanup_fn,"No fs_type specified" );
@@ -68,10 +80,22 @@ void tst_mkfs(void (cleanup_fn)(void), const char *dev, } argv[pos++] = dev; + +if (fs_extra_opts) { + argv[pos++] = extra_opts; + +if (pos +1 >OPTS_MAX ) { +tst_brkm (TBROK , cleanup_fn, +"Too much mkfs options" ); + } + }else { + fs_extra_opts ="None" ; + } + argv[pos] =NULL ; -tst_resm (TINFO ,"Formatting %s with %s extra opts='%s'" , - dev, fs_type, fs_opts_str); +tst_resm (TINFO ,"Formatting %s with %s opts='%s' extra opts='%s'" , + dev, fs_type, fs_opts_str, fs_extra_opts);tst_run_cmd (cleanup_fn, argv,"/dev/null" ,NULL ,0 ); }
testcases/kernel/io/direct_io/dma_thread_diotest.c +1 -1
@@ -397,7 +397,7 @@ static void setup(void)tst_brkm (TCONF ,NULL ,"you must specify a big blockdevice(>1.3G)" ); }else { -tst_mkfs (NULL , device,"ext3" ,NULL ); +tst_mkfs (NULL , device,"ext3" ,NULL ,NULL ); }if (mount (device,MNT_POINT ,"ext3" ,0 ,NULL ) <0 ) {
testcases/kernel/syscalls/access/access06.c +1 -1
@@ -93,7 +93,7 @@ static void setup(void)if (!device)tst_brkm (TCONF , cleanup,"Failed to obtain block device" ); -tst_mkfs (cleanup, device, fs_type,NULL ); +tst_mkfs (cleanup, device, fs_type,NULL ,NULL );SAFE_MKDIR (cleanup,MNT_POINT ,DIR_MODE );TEST_PAUSE ;
testcases/kernel/syscalls/acct/acct01.c +1 -1
@@ -150,7 +150,7 @@ static void setup(void)if (!device)tst_brkm (TCONF , cleanup,"Failed to obtain block device" ); -tst_mkfs (cleanup, device, fs_type,NULL ); +tst_mkfs (cleanup, device, fs_type,NULL ,NULL );SAFE_MKDIR (cleanup,"mntpoint" ,DIR_MODE );if (mount (device,"mntpoint" , fs_type,0 ,NULL ) <0 ) { tst_brkm(TBROK | TERRNO, cleanup,
testcases/kernel/syscalls/chmod/chmod06.c +1 -1
@@ -192,7 +192,7 @@ void setup(void)SAFE_CHMOD (cleanup,DIR_TEMP ,FILE_MODE );SAFE_TOUCH (cleanup,"t_file" ,MODE_RWX ,NULL ); -tst_mkfs (cleanup, device, fs_type,NULL ); +tst_mkfs (cleanup, device, fs_type,NULL ,NULL );SAFE_MKDIR (cleanup,MNT_POINT ,DIR_MODE );
testcases/kernel/syscalls/chown/chown04.c +1 -1
@@ -149,7 +149,7 @@ static void setup(void)if (!device)tst_brkm (TCONF , cleanup,"Failed to obtain block device" ); -tst_mkfs (cleanup, device, fs_type,NULL ); +tst_mkfs (cleanup, device, fs_type,NULL ,NULL );TEST_PAUSE ;
testcases/kernel/syscalls/creat/creat06.c +1 -1
@@ -179,7 +179,7 @@ static void setup(void)SAFE_SYMLINK (cleanup,TEST7_FILE ,"test_file_eloop2" );SAFE_SYMLINK (cleanup,"test_file_eloop2" ,TEST7_FILE ); -tst_mkfs (cleanup, device, fs_type,NULL ); +tst_mkfs (cleanup, device, fs_type,NULL ,NULL );SAFE_MKDIR (cleanup,"mntpoint" ,0777 );if (mount (device,"mntpoint" , fs_type,MS_RDONLY ,NULL ) <0 ) { tst_brkm(TBROK | TERRNO, cleanup,
testcases/kernel/syscalls/fchmod/fchmod06.c +1 -1
@@ -127,7 +127,7 @@ static void setup(void)if (!device)tst_brkm (TCONF , cleanup,"Failed to obtain block device" ); -tst_mkfs (cleanup, device, fs_type,NULL ); +tst_mkfs (cleanup, device, fs_type,NULL ,NULL );SAFE_MKDIR (cleanup,"mntpoint" ,0755 );
testcases/kernel/syscalls/fchown/fchown04.c +1 -1
@@ -113,7 +113,7 @@ static void setup(void) fd1 =SAFE_OPEN (cleanup,"tfile_1" ,O_RDWR |O_CREAT ,0666 ); -tst_mkfs (cleanup, device, fs_type,NULL ); +tst_mkfs (cleanup, device, fs_type,NULL ,NULL );SAFE_MKDIR (cleanup,"mntpoint" ,DIR_MODE );if (mount (device,"mntpoint" , fs_type,0 ,NULL ) <0 ) { tst_brkm(TBROK | TERRNO, cleanup,
testcases/kernel/syscalls/ftruncate/ftruncate04.c +1 -1
@@ -240,7 +240,7 @@ static void setup(void)if (!device)tst_brkm (TCONF , cleanup,"Failed to obtain block device" ); -tst_mkfs (cleanup, device, fs_type,NULL ); +tst_mkfs (cleanup, device, fs_type,NULL ,NULL );SAFE_MOUNT (NULL , device,MOUNT_DIR , fs_type,MS_MANDLOCK ,NULL ); mount_flag =1 ;
testcases/kernel/syscalls/inotify/inotify03.c +1 -1
@@ -178,7 +178,7 @@ static void setup(void)if (!device)tst_brkm (TCONF , cleanup,"Failed to obtain block device" ); -tst_mkfs (cleanup, device, fs_type,NULL ); +tst_mkfs (cleanup, device, fs_type,NULL ,NULL );if (mkdir (mntpoint,DIR_MODE ) <0 ) { tst_brkm(TBROK | TERRNO, cleanup, "mkdir(%s, %#o) failed",
testcases/kernel/syscalls/lchown/lchown03.c +1 -1
@@ -107,7 +107,7 @@ static void setup(void)for (i =0 ; i <43 ; i++)strcat (test_eloop,"/test_eloop" ); -tst_mkfs (cleanup, device, fs_type,NULL ); +tst_mkfs (cleanup, device, fs_type,NULL ,NULL );SAFE_MKDIR (cleanup,TEST_EROFS ,DIR_MODE );if (mount (device,TEST_EROFS , fs_type,MS_RDONLY ,NULL ) <0 ) { tst_brkm(TBROK | TERRNO, cleanup,
testcases/kernel/syscalls/link/link08.c +1 -1
@@ -143,7 +143,7 @@ static void setup(void)for (i =0 ; i <43 ; i++)strcat (test_file4,"/test_eloop" ); -tst_mkfs (cleanup, device, fs_type,NULL ); +tst_mkfs (cleanup, device, fs_type,NULL ,NULL );SAFE_MKDIR (cleanup,MNT_POINT ,DIR_MODE );if (mount (device,MNT_POINT , fs_type,0 ,NULL ) <0 ) { tst_brkm(TBROK | TERRNO, cleanup,
testcases/kernel/syscalls/linkat/linkat02.c +1 -1
@@ -171,7 +171,7 @@ static void setup(void)SAFE_MKDIR (cleanup,"./tmp" ,DIR_MODE );SAFE_TOUCH (cleanup,TEST_EACCES ,0666 ,NULL ); -tst_mkfs (cleanup, device, fs_type,NULL ); +tst_mkfs (cleanup, device, fs_type,NULL ,NULL );SAFE_MKDIR (cleanup,"mntpoint" ,DIR_MODE );if (mount (device,"mntpoint" , fs_type,0 ,NULL ) <0 ) {
testcases/kernel/syscalls/mkdir/mkdir03.c +1 -1
@@ -122,7 +122,7 @@ static void setup(void)for (i =0 ; i <43 ; i++)strcat (loop_dir,"/test_eloop" ); -tst_mkfs (cleanup, device, fs_type,NULL ); +tst_mkfs (cleanup, device, fs_type,NULL ,NULL );SAFE_MKDIR (cleanup,MNT_POINT ,DIR_MODE );if (mount (device,MNT_POINT , fs_type,MS_RDONLY ,NULL ) <0 ) { tst_brkm(TBROK | TERRNO, cleanup,
testcases/kernel/syscalls/mkdirat/mkdirat02.c +1 -1
@@ -116,7 +116,7 @@ static void setup(void)for (i =0 ; i <43 ; i++)strcat (test_file2,"/test_eloop" ); -tst_mkfs (cleanup, device, fs_type,NULL ); +tst_mkfs (cleanup, device, fs_type,NULL ,NULL );SAFE_MKDIR (cleanup,"test_dir/mntpoint" ,DIR_MODE );if (mount (device,"test_dir/mntpoint" , fs_type,MS_RDONLY ,NULL ) <0 ) {
testcases/kernel/syscalls/mknod/mknod07.c +1 -1
@@ -123,7 +123,7 @@ static void setup(void)if (!device)tst_brkm (TCONF , cleanup,"Failed to acquire device" ); -tst_mkfs (cleanup, device, fs_type,NULL ); +tst_mkfs (cleanup, device, fs_type,NULL ,NULL );TEST_PAUSE ;
testcases/kernel/syscalls/mknodat/mknodat02.c +1 -1
@@ -124,7 +124,7 @@ static void setup(void)if (!device)tst_brkm (TCONF , cleanup,"Failed to acquire device" ); -tst_mkfs (cleanup, device, fs_type,NULL ); +tst_mkfs (cleanup, device, fs_type,NULL ,NULL );TEST_PAUSE ;
testcases/kernel/syscalls/mmap/mmap16.c +1 -1
@@ -158,7 +158,7 @@ static void setup(void) device =tst_acquire_device (cleanup);if (!device)tst_brkm (TCONF , cleanup,"Failed to obtain block device" ); -tst_mkfs (cleanup, device, fs_type, fs_opts); +tst_mkfs (cleanup, device, fs_type, fs_opts,"102400" );SAFE_MKDIR (cleanup,MNTPOINT ,0755 );/*
testcases/kernel/syscalls/mount/mount01.c +1 -1
@@ -83,7 +83,7 @@ static void setup(void)if (!device)tst_brkm (TCONF , cleanup,"Failed to obtain block device" ); -tst_mkfs (cleanup, device, fs_type,NULL ); +tst_mkfs (cleanup, device, fs_type,NULL ,NULL );SAFE_MKDIR (cleanup,MNTPOINT ,DIR_MODE );
testcases/kernel/syscalls/mount/mount02.c +1 -1
@@ -186,7 +186,7 @@ static void setup(void)if (!device)tst_brkm (TCONF , cleanup,"Failed to obtain block device" ); -tst_mkfs (cleanup, device, fs_type,NULL ); +tst_mkfs (cleanup, device, fs_type,NULL ,NULL );SAFE_MKDIR (cleanup, mntpoint,DIR_MODE );
testcases/kernel/syscalls/mount/mount03.c +1 -1
@@ -355,7 +355,7 @@ static void setup(void)if (!device)tst_brkm (TCONF , cleanup,"Failed to obtain block device" ); -tst_mkfs (cleanup, device, fs_type,NULL ); +tst_mkfs (cleanup, device, fs_type,NULL ,NULL );SAFE_MKDIR (cleanup, mntpoint,DIR_MODE );
testcases/kernel/syscalls/mount/mount04.c +1 -1
@@ -98,7 +98,7 @@ static void setup(void)if (!device)tst_brkm (TCONF , cleanup,"Failed to obtain block device" ); -tst_mkfs (cleanup, device, fs_type,NULL ); +tst_mkfs (cleanup, device, fs_type,NULL ,NULL ); ltpuser =SAFE_GETPWNAM (cleanup, nobody_uid);SAFE_SETEUID (cleanup, ltpuser->pw_uid);
testcases/kernel/syscalls/mount/mount05.c +1 -1
@@ -104,7 +104,7 @@ void setup(void)SAFE_MKDIR (cleanup, mntpoint_des,DIR_MODE );if (dflag) { -tst_mkfs (NULL , device, fstype,NULL ); +tst_mkfs (NULL , device, fstype,NULL ,NULL );if (mount (device, mntpoint_src, fstype,0 ,NULL ) ==-1 )tst_brkm (TBROK |TERRNO , cleanup,"mount failed" );
testcases/kernel/syscalls/mount/mount06.c +1 -1
@@ -129,7 +129,7 @@ static void setup(void)if (!device)tst_brkm (TCONF , cleanup,"Failed to obtain block device" ); -tst_mkfs (cleanup, device, fs_type,NULL ); +tst_mkfs (cleanup, device, fs_type,NULL ,NULL );if (getcwd (path_name,sizeof (path_name)) ==NULL )tst_brkm (TBROK , cleanup,"getcwd failed" );
testcases/kernel/syscalls/open/open12.c +1 -1
@@ -107,7 +107,7 @@ static void setup(void) goto end; } -tst_mkfs (cleanup, device, fs_type,NULL ); +tst_mkfs (cleanup, device, fs_type,NULL ,NULL );SAFE_MOUNT (cleanup, device,MNTPOINT , fs_type,MS_STRICTATIME ,NULL ); mount_flag =1 ;
testcases/kernel/syscalls/quotactl/quotactl02.c +1 -1
@@ -207,7 +207,7 @@ static void setup(void)if (!block_dev)tst_brkm (TCONF , cleanup,"Failed to obtain block device" ); -tst_mkfs (cleanup, block_dev,"xfs" ,NULL ); +tst_mkfs (cleanup, block_dev,"xfs" ,NULL ,NULL );if (mount (block_dev, mntpoint,"xfs" ,0 ,"uquota" ) <0 )tst_brkm (TFAIL |TERRNO ,NULL ,"mount(2) fail" );
testcases/kernel/syscalls/rename/rename11.c +1 -1
@@ -104,7 +104,7 @@ static void setup(void)if (!device)tst_brkm (TCONF , cleanup,"Failed to obtain block device" ); -tst_mkfs (cleanup, device, fs_type,NULL ); +tst_mkfs (cleanup, device, fs_type,NULL ,NULL );SAFE_MKDIR (cleanup,MNTPOINT ,0755 );if (mount (device,MNTPOINT , fs_type,0 ,NULL ) <0 ) {
testcases/kernel/syscalls/renameat/renameat01.c +1 -1
@@ -183,7 +183,7 @@ static void setup(void)for (i =0 ; i <43 ; i++)strcat (looppathname,TESTDIR2 ); -tst_mkfs (cleanup, device, fs_type,NULL ); +tst_mkfs (cleanup, device, fs_type,NULL ,NULL );SAFE_MKDIR (cleanup,MNTPOINT ,DIRMODE );if (mount (device,MNTPOINT , fs_type,0 ,NULL ) <0 ) { tst_brkm(TBROK | TERRNO, cleanup,
testcases/kernel/syscalls/rmdir/rmdir02.c +1 -1
@@ -137,7 +137,7 @@ static void setup(void)if (!device)tst_brkm (TCONF , cleanup,"Failed to acquire device" ); -tst_mkfs (cleanup, device, fs_type,NULL ); +tst_mkfs (cleanup, device, fs_type,NULL ,NULL );SAFE_MKDIR (cleanup,MNTPOINT ,DIR_MODE );if (mount (device,MNTPOINT , fs_type,0 ,NULL ) ==-1 ) { tst_brkm(TBROK | TERRNO, cleanup,
testcases/kernel/syscalls/umount/umount01.c +1 -1
@@ -93,7 +93,7 @@ static void setup(void)if (!device)tst_brkm (TCONF , cleanup,"Failed to obtain block device" ); -tst_mkfs (cleanup, device, fs_type,NULL ); +tst_mkfs (cleanup, device, fs_type,NULL ,NULL );if (mkdir (mntpoint,DIR_MODE ) <0 ) { tst_brkm(TBROK, cleanup, "mkdir(%s, %#o) failed; "
testcases/kernel/syscalls/umount/umount02.c +1 -1
@@ -117,7 +117,7 @@ static void setup(void)if (!device)tst_brkm (TCONF , cleanup,"Failed to obtain block device" ); -tst_mkfs (cleanup, device, fs_type,NULL ); +tst_mkfs (cleanup, device, fs_type,NULL ,NULL );memset (long_path,'a' ,PATH_MAX +1 );
testcases/kernel/syscalls/umount/umount03.c +1 -1
@@ -99,7 +99,7 @@ static void setup(void)if (!device)tst_brkm (TCONF , cleanup,"Failed to obtain block device" ); -tst_mkfs (cleanup, device, fs_type,NULL ); +tst_mkfs (cleanup, device, fs_type,NULL ,NULL );SAFE_MKDIR (cleanup,MNTPOINT ,DIR_MODE );
testcases/kernel/syscalls/umount2/umount2_01.c +1 -1
@@ -78,7 +78,7 @@ static void setup(void)if (!device)tst_brkm (TCONF , cleanup,"Failed to obtain block device" ); -tst_mkfs (cleanup, device, fs_type,NULL ); +tst_mkfs (cleanup, device, fs_type,NULL ,NULL );SAFE_MKDIR (cleanup,MNTPOINT ,DIR_MODE );
testcases/kernel/syscalls/umount2/umount2_02.c +1 -1
@@ -115,7 +115,7 @@ static void setup(void)if (!device)tst_brkm (TCONF , cleanup,"Failed to obtain block device" ); -tst_mkfs (cleanup, device, fs_type,NULL ); +tst_mkfs (cleanup, device, fs_type,NULL ,NULL );SAFE_MKDIR (cleanup,MNTPOINT ,DIR_MODE );
testcases/kernel/syscalls/umount2/umount2_03.c +1 -1
@@ -96,7 +96,7 @@ static void setup(void)if (!device)tst_brkm (TCONF , cleanup,"Failed to obtain block device" ); -tst_mkfs (cleanup, device, fs_type,NULL ); +tst_mkfs (cleanup, device, fs_type,NULL ,NULL );SAFE_MKDIR (cleanup,MNTPOINT ,DIR_MODE );
testcases/kernel/syscalls/utime/utime06.c +1 -1
@@ -119,7 +119,7 @@ static void setup(void)if (!dev)tst_brkm (TCONF , cleanup,"Failed to acquire test device" ); -tst_mkfs (cleanup, dev, fs_type,NULL ); +tst_mkfs (cleanup, dev, fs_type,NULL ,NULL );SAFE_MKDIR (cleanup,MNT_POINT ,0644 );if (mount (dev,MNT_POINT , fs_type,MS_RDONLY ,NULL ) <0 ) {
testcases/kernel/syscalls/utimes/utimes01.c +1 -1
@@ -139,7 +139,7 @@ static void setup(void)SAFE_CHOWN (cleanup,TESTFILE2 , ltpuser->pw_uid, ltpuser->pw_gid); -tst_mkfs (cleanup, device, fs_type,NULL ); +tst_mkfs (cleanup, device, fs_type,NULL ,NULL );SAFE_MKDIR (cleanup,MNTPOINT ,DIR_MODE );if (mount (device,MNTPOINT , fs_type,0 ,NULL ) ==-1 ) { tst_brkm(TBROK | TERRNO, cleanup,
Signature · 1 line
2.5.0
PATCH 2/2 tst_mkfs: add new function tst_mkfs_sized
The new function as below:
void tst_mkfs_sized(void (cleanup_fn)(void), const char *dev,
const char *fs_type, const char *fs_size, const char *blk_size);
This is an extensional function of tst_mkfs(), This function is only used to make fs with an appointed fs size or block size or both. For some filesystems(e.g. ext2/3/4), if you set 'fs_size', then you need to give blk_size at the same time, the reason please check the manual of mke2fs.
Generally we can use tst_mkfs() function to make an appointed size fs, by use its fs_opts and extra_opts option. But if a testcase maybe mkfs different filesystem type, due to different fs need different options, so we need to check the fs_type and do different operations. tst_mkfs_sized() function is used for that.
---
Hi Cyril,
I still think tst_mkfs_sized() function is needed, even I haven't use it in any testcase.
tst_mkfs() can make an appointed size fs for someone pointed fs. But if the fs_type can't be sure before call tst_mkfs(), for example:
for fs_type in "xfs ext4 btrfs"
do
tst_mkfs(....);
done
In this condition, we can't use tst_mkfs directly. So I think this tst_mkfs_sized is needed. For fs test, fs size and block size always be used, maybe this function is useful in the future:)
In xfstests, we alway use scratch_mkfs_sized() function, I just try to copy it to here. You can merge this if you feel it's helpful, or wait for LTP really need it. I just sent this patch as I already did it.
Thanks,
Zorro
doc/test-writing-guidelines.txt | 20 +++++++++++ include/test.h | 13 +++++++ lib/tst_mkfs.c | 76 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+)
doc/test-writing-guidelines.txt +20 -0
@@ -921,6 +921,26 @@ a string such as "102400". 'extra_opts' will be used behind device name. e.g: mkfs -t ext4 -b 1024 /dev/sda1 102400 ^^^^^^ +[source,c] +------------------------------------------------------------------------------- +#include "test.h" + +void tst_mkfs_sized(void (cleanup_fn)(void), const char *dev, + const char *fs_type, const char *fs_size, + const char *blk_size); +------------------------------------------------------------------------------- + +This is an extensional function of tst_mkfs(), This function is only used to +make fs with an appointed fs size or block size or both. For some filesystems +(e.g. ext2/3/4), if you set 'fs_size', then you need to give blk_size +at the same time, the reason please check the manual of mke2fs. + +Generally we can use tst_mkfs() function to make an appointed size fs, by use +its fs_opts and extra_opts option. But if a testcase maybe mkfs different file- +system type, due to different fs need different options, so we need to check +the fs_type and do different operations. tst_mkfs_sized() function is used for +that. + 2.2.16 Verifying a filesystem's free space ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
include/test.h +13 -0
@@ -323,6 +323,19 @@ void tst_mkfs(void (cleanup_fn)(void), const char *dev, const char *fs_type, const char *const fs_opts[], const char *extra_opts); +/* lib/tst_mkfs.c +* +* @dev: path to a device +* @fs_type: filesystem type +* @fs_size: filesystem size, e.g. "512m", "2g", "1024000" +* @blk_size: filesystem block size, e.g. "512", "1024", "4096" +* If both @fs_size and @blk_size aren NULL, it will same as +* tst_mkfs(cleanup_fn, dev, fs_type, NULL, NULL); +*/ +void tst_mkfs_sized (void (cleanup_fn )(void ),const char *dev, +const char *fs_type,const char *fs_size, +const char *blk_size); +/* * Returns filesystem type to be used for the testing. Unless your test is * designed for specific filesystem you should use this function to the tested
lib/tst_mkfs.c +76 -0
88 lines not on this page · raw message
Signature · 1 line
2.5.0
PATCH 1/2 tst_mkfs: add new parameter extra_opts to tst_mkfs function
In reply to Zorro Lang----- 原始邮件 -----
Quoted 192 lines
发件人: "Zorro Lang" <[email protected]>
收件人: [email protected]
抄送: [email protected], "Zorro Lang" <[email protected]>
发送时间: 星期四, 2016年 3 月 10日 下午 5:07:35
主题: [PATCH 1/2]tst_mkfs: add new parameterextra_optstotst_mkfsfunctionmmap16 always hit ETIMEDOUT error, if the test device is too large. mkfs on the device will take lots of time. So I want to make ext4 with an appointed size. But the [
fs_size] need behind the device name, e.g. "mkfs -t ext4 dev [fs_size]".Due to above reason, add a new parameter
extra_optstotst_mkfs.extra_optsstore the options need to behind the device name of mkfs. Then mmap16 can make ext4 with an appointed (small) size.Because of
tst_mkfsbe changed, all testcases which usetst_mkfsadd NULL parameter forextra_opts.Signed-off-by Zorro Lang <[email protected]>---
Hi Cyril,
As we talked, I make this V3 patch for mmap16 ETIMEDOUT problem. This patch follow your suggestion, and I have tested it simply.
Thanks,
Zorrodoc/test-writing-guidelines.txt | 10 ++++++-- include/test.h | 6 +++-- lib/tests/tst_device.c | 2 +- lib/tst_mkfs.c | 30 +++++++++++++++++++--- testcases/kernel/io/direct_io/dma_thread_diotest.c | 2 +- testcases/kernel/syscalls/access/access06.c | 2 +- testcases/kernel/syscalls/acct/acct01.c | 2 +- testcases/kernel/syscalls/chmod/chmod06.c | 2 +- testcases/kernel/syscalls/chown/chown04.c | 2 +- testcases/kernel/syscalls/creat/creat06.c | 2 +- testcases/kernel/syscalls/fchmod/fchmod06.c | 2 +- testcases/kernel/syscalls/fchown/fchown04.c | 2 +- testcases/kernel/syscalls/ftruncate/ftruncate04.c | 2 +- testcases/kernel/syscalls/inotify/inotify03.c | 2 +- testcases/kernel/syscalls/lchown/lchown03.c | 2 +- testcases/kernel/syscalls/link/link08.c | 2 +- testcases/kernel/syscalls/linkat/linkat02.c | 2 +- testcases/kernel/syscalls/mkdir/mkdir03.c | 2 +- testcases/kernel/syscalls/mkdirat/mkdirat02.c | 2 +- testcases/kernel/syscalls/mknod/mknod07.c | 2 +- testcases/kernel/syscalls/mknodat/mknodat02.c | 2 +- testcases/kernel/syscalls/mmap/mmap16.c | 2 +- testcases/kernel/syscalls/mount/mount01.c | 2 +- testcases/kernel/syscalls/mount/mount02.c | 2 +- testcases/kernel/syscalls/mount/mount03.c | 2 +- testcases/kernel/syscalls/mount/mount04.c | 2 +- testcases/kernel/syscalls/mount/mount05.c | 2 +- testcases/kernel/syscalls/mount/mount06.c | 2 +- testcases/kernel/syscalls/open/open12.c | 2 +- testcases/kernel/syscalls/quotactl/quotactl02.c | 2 +- testcases/kernel/syscalls/rename/rename11.c | 2 +- testcases/kernel/syscalls/renameat/renameat01.c | 2 +- testcases/kernel/syscalls/rmdir/rmdir02.c | 2 +- testcases/kernel/syscalls/umount/umount01.c | 2 +- testcases/kernel/syscalls/umount/umount02.c | 2 +- testcases/kernel/syscalls/umount/umount03.c | 2 +- testcases/kernel/syscalls/umount2/umount2_01.c | 2 +- testcases/kernel/syscalls/umount2/umount2_02.c | 2 +- testcases/kernel/syscalls/umount2/umount2_03.c | 2 +- testcases/kernel/syscalls/utime/utime06.c | 2 +- testcases/kernel/syscalls/utimes/utimes01.c | 2 +- 41 files changed, 77 insertions(+), 45 deletions(-)doc/test-writing-guidelines.txt +0
-0@@ -906,15 +906,21 @@ NOTE: The default filesytem is hardcoded to 'ext2' inthe sources and can be
#include "test.h"void tst_mkfs(void (cleanup_fn)(void), const char *dev,
doc/test-writing-guidelines.txt +5
-2- const char *fs_type, const char *const fs_opts[]); + const char *fs_type, const char *const fs_opts[] + const char *extra_opts); ------------------------------------------------------------------------------- This function takes a path to a device, filesystem type and an array of extra options passed to mkfs. -The extra options 'fs_opts' should either be 'NULL' if there are none, or a +The fs options 'fs_opts' should either be 'NULL' if there are none, or a 'NULL' terminated array of strings such as '{"-b", "1024", NULL}'. +The extra options 'extra_opts' should either be 'NULL' if there are none, or +a string such as "102400". 'extra_opts' will be used behind device name.e.g:
doc/test-writing-guidelines.txt +3
-0+mkfs -t ext4 -b 1024 /dev/sda1 102400 + ^^^^^^ + 2.2.16 Verifying a filesystem's free space ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^include/test.h +4
-2@@ -316,10 +316,12 @@ int tst_system(const char *command);* * @dev: path to a device * @fs_type: filesystem type -* @fs_opts: NULL or NULL terminated array of extra mkfs options +* @fs_opts: NULL or NULL terminated array of mkfs options +* @extra_opts: extranal mkfs options which need to behind the device name */ void tst_mkfs (void (cleanup_fn )(void ),const char *dev, -const char *fs_type,const char *const fs_opts[]); +const char *fs_type,const char *const fs_opts[], +const char *extra_opts);/* * Returns filesystem type to be used for the testing. Unless your test is lib/tests/tst_device.c +1
-1@@ -46,7 +46,7 @@ int main(void)printf ("Test device='%s'\n" , dev); -tst_mkfs (cleanup, dev,"ext2" ,NULL ); +tst_mkfs (cleanup, dev,"ext2" ,NULL ,NULL );cleanup ();tst_exit ();lib/tst_mkfs.c +27
-3@@ -21,12 +21,24 @@#define OPTS_MAX 32 +/* +* tst_mkfs: mkfs.$fs_type on $dev with options $fs_opts and $extra_opts +* cleanup_fn - run it when exit with error. +* dev - device path name +* fs_opts - store the options for mkfs (except -t fs_type). Set +* NULL if don't need options. +* extra_opts - extranal mkfs options for mkfs, these options need +* behind the device name, e.g. [fs_size] for ext4. +* Set NULL, if don't need options behind device name. +*/ void tst_mkfs (void (cleanup_fn )(void ),const char *dev, -const char *fs_type,const char *const fs_opts[]) +const char *fs_type,const char *const fs_opts[], +const char *extra_opts) {int i, pos =3 ;const char *argv[OPTS_MAX ] = {"mkfs" ,"-t" , fs_type};char fs_opts_str[1024 ] ="" ; +const char *fs_extra_opts = extra_opts;if (!fs_type)tst_brkm (TBROK , cleanup_fn,"No fs_type specified" );@@ -68,10 +80,22 @@ void tst_mkfs(void (cleanup_fn)(void), const char *dev, } argv[pos++] = dev; + +if (fs_extra_opts) { + argv[pos++] = extra_opts; + +if (pos +1 >OPTS_MAX ) { +tst_brkm (TBROK , cleanup_fn, +"Too much mkfs options" ); + } + }else { + fs_extra_opts ="None" ; + } + argv[pos] =NULL ; -tst_resm (TINFO ,"Formatting %s with %s extra opts='%s'" , - dev, fs_type, fs_opts_str); +tst_resm (TINFO ,"Formatting %s with %s opts='%s' extra opts='%s'" , + dev, fs_type, fs_opts_str, fs_extra_opts);tst_run_cmd (cleanup_fn, argv,"/dev/null" ,NULL ,0 ); }
<skip>
testcases/kernel/syscalls/mmap/mmap16.c static void setup(void) · line 161
Quoted 12 lines
testcases/kernel/syscalls/mmap/mmap16.c +1
-1@@ -158,7 +158,7 @@ static void setup(void) device =tst_acquire_device (cleanup);if (!device)tst_brkm (TCONF , cleanup,"Failed to obtain block device" ); -tst_mkfs (cleanup, device, fs_type, fs_opts); +tst_mkfs (cleanup, device, fs_type, fs_opts,"102400" );
Sorry, the 100M size is bigger than the default ltp loop device(if no -b option used). I will change this size to smaller and send another version patch.
Thanks,
Zorro