lib/tst_supported_fs_types.c: Add tmpfs to filesystem whitelist
PATCH 1/1 lib/tst_supported_fs_types.c: Add tmpfs to filesystem whitelist
In many Embedded system, we need add tmpfs wo filesystem whitelist since there is only tmpfs can be used to test.
---------------v1->v2:
1)create a unique temporary directory under TMPDIR and use it as a mount point in the has_kernel_support() function.
2)add tst_umount after mount.
---------------
--- lib/tst_supported_fs_types.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-)
lib/tst_supported_fs_types.c +20 -2
@@ -22,6 +22,7 @@ static const char *const fs_type_whitelist[] = {"vfat" ,"exfat" ,"ntfs" , +"tmpfs" , NULL };
@@ -34,6 +35,10 @@ static int has_mkfs(const char *fs_type)sprintf (buf,"mkfs.%s >/dev/null 2>&1" , fs_type); +if (strstr (buf,"mkfs.tmpfs" )) { +return 1 ; + } + ret =tst_system (buf);if (WEXITSTATUS (ret) ==127 ) {
@@ -50,17 +55,30 @@ static int has_kernel_support(const char *fs_type, int flags)static int fuse_supported =-1 ;const char *tmpdir =getenv ("TMPDIR" );char buf[128 ]; +char template[PATH_MAX ];int ret;if (!tmpdir) tmpdir ="/tmp" ; -mount ("/dev/zero" , tmpdir, fs_type,0 ,NULL ); -if (errno !=ENODEV ) { +sprintf (template,"%s/mountXXXXXX" , tmpdir); +if (mkdtemp (template) ==NULL ) { +tst_res (TWARN |TERRNO ,"%s: mkdtemp(%s) failed" , __func__, template); + } + + ret =mount ("/dev/zero" , template, fs_type,0 ,NULL ); +if ((ret && errno !=ENODEV ) || !ret) { +if (!ret) +tst_umount (template);tst_res (TINFO ,"Kernel supports %s" , fs_type); +if (rmdir (template) ==-1 ) +tst_res (TWARN |TERRNO ,"rmdir %s failed" , template);return 1 ; } +if (rmdir (template) ==-1 ) +tst_res (TWARN |TERRNO ,"rmdir %s failed" , template); +/* Is FUSE supported by kernel? */ if (fuse_supported ==-1 ) { ret =open ("/dev/fuse" ,O_RDWR );
--
2.17.1
PATCH 1/1 lib/tst_supported_fs_types.c: Add tmpfs to filesystem whitelist
Hi!
lib/tst_supported_fs_types.c static int has_mkfs(const char *fs_type) · line 40
Quoted 7 lines
lib/tst_supported_fs_types.c +3
-0@@ -34,6 +35,10 @@ static int has_mkfs(const char *fs_type)sprintf (buf,"mkfs.%s >/dev/null 2>&1" , fs_type); +if (strstr (buf,"mkfs.tmpfs" )) { +return 1 ; + }
The curly braces around single line statement are useless here.
Also it would be cleaner if we checked before the sprintf and against the fs_type instead with if (!strcmp(fs_type, "tmpfs")).
We may also print a TINFO message something along the lines:
tst_res(TINFO, "mkfs is not needed for tmpfs");
Quoted 6 lines
lib/tst_supported_fs_types.c +0
-0ret =tst_system (buf);if (WEXITSTATUS (ret) ==127 ) {@@ -50,17 +55,30 @@ static int has_kernel_support(const char *fs_type, int flags)static int fuse_supported =-1 ;const char *tmpdir =getenv ("TMPDIR" );
lib/tst_supported_fs_types.c static int has_kernel_support(const char *fs_type, int flags) · line 64
Quoted 10 lines
lib/tst_supported_fs_types.c +2
-2char buf[128 ]; +char template[PATH_MAX ];int ret;if (!tmpdir) tmpdir ="/tmp" ; -mount ("/dev/zero" , tmpdir, fs_type,0 ,NULL ); -if (errno !=ENODEV ) { +sprintf (template,"%s/mountXXXXXX" , tmpdir);
We should at least use snprintf() with sizeof(template) in order not to overrun the buffer. Or we can use asprintf() instead and free the buffer later on.
lib/tst_supported_fs_types.c static int has_kernel_support(const char *fs_type, int flags) · line 67
Quoted 3 lines
lib/tst_supported_fs_types.c +3
-0+if (mkdtemp (template) ==NULL ) { +tst_res (TWARN |TERRNO ,"%s: mkdtemp(%s) failed" , __func__, template); + }
I guess that we can tst_brk(TBROK, ""); here if mkdtemp() failed, continuing here we would pass non-existing directory thte mount() syscall below.
Also please do not include the __func__ in the message here.
lib/tst_supported_fs_types.c static int has_kernel_support(const char *fs_type, int flags) · line 75
Quoted 7 lines
lib/tst_supported_fs_types.c +6
-0+ ret =mount ("/dev/zero" , template, fs_type,0 ,NULL ); +if ((ret && errno !=ENODEV ) || !ret) { +if (!ret) +tst_umount (template);tst_res (TINFO ,"Kernel supports %s" , fs_type); +if (rmdir (template) ==-1 ) +tst_res (TWARN |TERRNO ,"rmdir %s failed" , template);
We do have SAFE_RMDIR() please use that.
lib/tst_supported_fs_types.c static int has_kernel_support(const char *fs_type, int flags) · line 80
Quoted 5 lines
lib/tst_supported_fs_types.c +2
-0return 1 ; } +if (rmdir (template) ==-1 ) +tst_res (TWARN |TERRNO ,"rmdir %s failed" , template);
Here as well.
Quoted 9 lines
lib/tst_supported_fs_types.c +0
-1/* Is FUSE supported by kernel? */ if (fuse_supported ==-1 ) { ret =open ("/dev/fuse" ,O_RDWR ); --2.17.1
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis [email protected]