lib/tst_fs_link_count.c: check fs type and do not fill subdir if no limit

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).

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 0 directly.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
diff --git a/lib/tst_fs_link_count.c b/lib/tst_fs_link_count.c
index 1b45f79..45a3a1b 100644
--- a/lib/tst_fs_link_count.c
+++ b/lib/tst_fs_link_count.c
@@ -24,9 +24,23 @@
 #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_EXT234_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 +102,10 @@
 
 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 +114,20 @@
 	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 "
+			 "%s filesystem", tst_fs_type_name(fs_type));
+		return 0;
+	}
+
 	for (i = 0; i < MAX_SANE_HARD_LINKS; i++) {
 		sprintf(dirname, "%s/testdir%d", dir, i);
 
@@ -134,7 +163,8 @@
 
 	}
 
-	tst_resm(TINFO, "Failed reach the subdirs limit");
+	tst_resm(TINFO, "Failed reach the subdirs limit on %s filesystem",
+		 tst_fs_type_name(fs_type));
 
 max_subdirs_cleanup:
 	for (j = 0; j < i; j++) {