This number of max sub-directories depends on the filesystem. For current
kernel, subdir limit is not availiable for all filesystems (availiable for
ext2, ext3, minix, sysv etc). If the test runs on some other filesystems,
like ramfs, tmpfs, it will always fail.

So we check the fs type in tst_fs_fill_subdirs(), and only try to reach the
limit on filesystems which have subdir limit. Otherwise, give an information
tells that subdir limit is not avaliable, and returns -1 to let the testcase
know that EMLINK test can be skipped safely.

Signed-off-by: Sheng Yong <shengyo...@huawei.com>
---
 doc/test-writing-guidelines.txt |  5 ++++-
 lib/tst_fs_link_count.c         | 35 +++++++++++++++++++++++++++++++++--
 2 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/doc/test-writing-guidelines.txt b/doc/test-writing-guidelines.txt
index a59fdd9..8f690f7 100644
--- a/doc/test-writing-guidelines.txt
+++ b/doc/test-writing-guidelines.txt
@@ -892,7 +892,10 @@ int tst_fs_fill_subdirs(void (*cleanup)(void), const char 
*dir);
 
 Try to get maximum number of subdirectories in directory.
 
-NOTE: This number depends on the filesystem 'dir' is on.
+NOTE: This number depends on the filesystem 'dir' is on. For current kernel,
+subdir limit is not availiable for all filesystems (availiable for ext2, ext3,
+minix, sysv and more). If the test runs on some other filesystems, like ramfs,
+tmpfs, it will always fail.
 
 This function uses 'mkdir(2)' to create directories in 'dir' until it gets
 'EMLINK' or creates 65535 directories. If the limit is hit, the maximum number
diff --git a/lib/tst_fs_link_count.c b/lib/tst_fs_link_count.c
index 1b45f79..4a691bb 100644
--- a/lib/tst_fs_link_count.c
+++ b/lib/tst_fs_link_count.c
@@ -24,9 +24,24 @@
 #include "test.h"
 #include "usctest.h"
 #include "safe_macros.h"
+#include "tst_fs_type.h"
 
 #define MAX_SANE_HARD_LINKS    65535
 
+/*
+ * filesystems whose subdir limit is less than MAX_SANE_HARD_LINKS
+ * XXX: we cannot filter ext4 out, because ext2/ext3/ext4 have the
+ * same magic number
+ */
+const long subdir_limit_whitelist[] = {
+       TST_EXT2_OLD_MAGIC, TST_EXT2_MAGIC,    TST_EXT3_MAGIC,
+       TST_MINIX_MAGIC,    TST_MINIX_MAGIC2, TST_MINIX2_MAGIC,
+       TST_MINIX2_MAGIC2,  TST_MINIX3_MAGIC,  TST_UDF_MAGIC,
+       TST_SYSV2_MAGIC,    TST_SYSV4_MAGIC,   TST_UFS_MAGIC,
+       TST_UFS2_MAGIC,     TST_F2FS_MAGIC,    TST_NILFS_MAGIC,
+       TST_EXOFS_MAGIC
+};
+
 int tst_fs_fill_hardlinks(void (*cleanup) (void), const char *dir)
 {
        unsigned int i, j;
@@ -88,9 +103,10 @@ max_hardlinks_cleanup:
 
 int tst_fs_fill_subdirs(void (*cleanup) (void), const char *dir)
 {
-       unsigned int i, j;
+       unsigned int i, j, whitelist_size;
        char dirname[PATH_MAX];
        struct stat s;
+       long fs_type;
 
        if (stat(dir, &s) == -1 && errno == ENOENT)
                SAFE_MKDIR(cleanup, dir, 0744);
@@ -99,6 +115,20 @@ int tst_fs_fill_subdirs(void (*cleanup) (void), const char 
*dir)
        if (!S_ISDIR(s.st_mode))
                tst_brkm(TBROK, cleanup, "%s is not directory", dir);
 
+       /* for current kernel, subdir limit is not availiable for all fs */
+       fs_type = tst_fs_type(cleanup, dir);
+
+       whitelist_size = ARRAY_SIZE(subdir_limit_whitelist);
+       for (i = 0; i < whitelist_size; i++) {
+               if (fs_type == subdir_limit_whitelist[i])
+                       break;
+       }
+       if (i == whitelist_size) {
+               tst_resm(TINFO, "subdir limit is not availiable for "
+                        "filesystem %s", tst_fs_type_name(fs_type));
+               return -1;
+       }
+
        for (i = 0; i < MAX_SANE_HARD_LINKS; i++) {
                sprintf(dirname, "%s/testdir%d", dir, i);
 
@@ -134,7 +164,8 @@ int tst_fs_fill_subdirs(void (*cleanup) (void), const char 
*dir)
 
        }
 
-       tst_resm(TINFO, "Failed reach the subdirs limit");
+       tst_resm(TINFO, "Failed reach the subdirs limit on filesystem %s",
+                tst_fs_type_name(fs_type));
 
 max_subdirs_cleanup:
        for (j = 0; j < i; j++) {
-- 
1.8.3.4


------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to