xfstests generic 310: check concurrently of readdir and read on the same directory fd
authorZhao Hongjiang <zhaohongjiang@huawei.com>
Wed, 3 Apr 2013 06:09:10 +0000 (06:09 +0000)
committerRich Johnston <rjohnston@sgi.com>
Fri, 5 Apr 2013 17:25:29 +0000 (12:25 -0500)
Check if there are two threads,one keeps calling read() or lseek(), and
the other calling readdir(), both on the same directory fd.

Based on a testcase from Li Zefan <lizefan@huawei.com>.
http://marc.info/?l=linux-kernel&m=136123703211869&w=2

Signed-off-by: Zhao Hongjiang <zhaohongjiang@huawei.com>
Reviewed-by: Rich Johnston <rjohnston@sgi.com>
[rjohnston@sgi.com minor white space fixes and test renumbering]
Signed-off-by: Rich Johnston <rjohnston@sgi.com>
src/Makefile
src/t_readdir_1.c [new file with mode: 0644]
src/t_readdir_2.c [new file with mode: 0644]
tests/generic/310 [new file with mode: 0644]
tests/generic/310.out [new file with mode: 0644]
tests/generic/group

index f7362a25caba844bda76330671a6003aea169594..8d8e97fa03e0ac69542edaa3c547e609399ddd77 100644 (file)
@@ -18,7 +18,7 @@ LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \
        locktest unwritten_mmap bulkstat_unlink_test t_stripealign \
        bulkstat_unlink_test_modified t_dir_offset t_futimens t_immutable \
        stale_handle pwrite_mmap_blocked t_dir_offset2 seek_sanity_test \
        locktest unwritten_mmap bulkstat_unlink_test t_stripealign \
        bulkstat_unlink_test_modified t_dir_offset t_futimens t_immutable \
        stale_handle pwrite_mmap_blocked t_dir_offset2 seek_sanity_test \
-       seek_copy_test
+       seek_copy_test t_readdir_1 t_readdir_2
 
 SUBDIRS =
 
 
 SUBDIRS =
 
diff --git a/src/t_readdir_1.c b/src/t_readdir_1.c
new file mode 100644 (file)
index 0000000..37b37f0
--- /dev/null
@@ -0,0 +1,46 @@
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <dirent.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+int main(int argc, char *argv[])
+{
+       int fd;
+       int ret;
+       DIR *dir;
+       struct dirent *ptr;
+
+       dir = opendir(argv[1]);
+
+       fd = dirfd(dir);
+       if (fd < 0) {
+               perror("Failed to get dirfd!");
+               exit(EXIT_FAILURE);
+       }
+       ret = fork();
+
+       if (ret == 0) {
+               char buf[100];
+
+               while(1)
+                        read(fd, buf, 100);
+
+       } else {
+               while (1) {
+                       int ret2 = lseek(fd, 0, SEEK_SET);
+                       if (ret2 == -1) {
+                               perror("Seek failed!");
+                               exit(EXIT_FAILURE);
+                       }
+                       while ((ptr = readdir(dir)))
+                                       ;
+               }
+       }
+
+       closedir(dir);
+       exit(EXIT_SUCCESS);
+}
diff --git a/src/t_readdir_2.c b/src/t_readdir_2.c
new file mode 100644 (file)
index 0000000..2eef6e3
--- /dev/null
@@ -0,0 +1,57 @@
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <dirent.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+int main(int argc, char *argv[])
+{
+       int fd;
+       int ret;
+       DIR *dir;
+       struct dirent *ptr;
+
+       dir = opendir(argv[1]);
+
+       fd = dirfd(dir);
+       if (fd < 0) {
+               perror("Failed to get dirfd!");
+               exit(EXIT_FAILURE);
+       }
+       ret = fork();
+
+       if (ret == 0) {
+               int ret1, i;
+               static int array[11] = {0, 1, 2, 3, 1023, 1024, 1025, 4095,
+                                       4096, 4097, 0x7fffffff};
+
+               while(1) {
+                       for(i = 0; i < 11; i++) {
+                               ret1 = lseek(fd, array[i++], SEEK_SET);
+                               if (ret1 == -1) {
+                                       perror("Seek failed!");
+                                       exit(EXIT_FAILURE);
+                               }
+                       }
+
+                       off_t pos = lseek(fd, 0, SEEK_CUR);
+                       lseek(fd, pos, SEEK_SET);
+               }
+       } else {
+               while (1) {
+                       int ret2 = lseek(fd, 0, SEEK_SET);
+                       if (ret2 == -1) {
+                               perror("Seek failed!");
+                               exit(EXIT_FAILURE);
+                       }
+                       while ((ptr = readdir(dir)))
+                                       ;
+               }
+       }
+
+       closedir(dir);
+       exit(EXIT_SUCCESS);
+}
diff --git a/tests/generic/310 b/tests/generic/310
new file mode 100644 (file)
index 0000000..ef51422
--- /dev/null
@@ -0,0 +1,76 @@
+#! /bin/bash
+# FS QA Test No. 310
+#
+#Check if there are two threads,one keeps calling read() or lseek(), and
+#the other calling readdir(), both on the same directory fd.
+#
+# Based on a testcase from Li Zefan <lizefan@huawei.com>.
+#
+# http://marc.info/?l=linux-kernel&m=136123703211869&w=2
+#
+#-----------------------------------------------------------------------
+# Copyright (c) 2013 HuaWei. All Rights Reserved.
+#
+# 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.
+#
+# 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
+#-----------------------------------------------------------------------
+#
+# creator
+owner=zhaohongjiang@huawei.com
+
+seq=`basename $0`
+echo "QA output created by $seq"
+
+status=1       # failure is the default!
+
+_cleanup()
+{
+       rm -rf $TEST_DIR/tmp
+}
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+# get standard environment, filters and checks
+. ./common.rc
+. ./common.filter
+
+# real QA test starts here
+_supported_fs generic
+_supported_os Linux
+
+mkdir $TEST_DIR/tmp
+for n in {1..4096}; do
+       touch $TEST_DIR/tmp/$n
+done
+
+_test_read()
+{
+       src/t_readdir_1 $TEST_DIR/tmp &
+       sleep 100
+       killall src/t_readdir_1
+}
+
+_test_lseek()
+{
+       src/t_readdir_2 $TEST_DIR/tmp &
+       sleep 100
+       killall src/t_readdir_2
+}
+
+_test_read
+_test_lseek
+
+# success, all done
+echo "*** done"
+rm -f $seq.full
+status=0
+exit
diff --git a/tests/generic/310.out b/tests/generic/310.out
new file mode 100644 (file)
index 0000000..7d6c0fd
--- /dev/null
@@ -0,0 +1,2 @@
+QA output created by 310
+*** done
index a9fd0855f75aa646d32f1c3fec87f2f9b232c673..eb5283321e038cd21cd80bf7fa70a56228b6ec32 100644 (file)
 307 auto quick
 308 auto quick
 309 auto quick
 307 auto quick
 308 auto quick
 309 auto quick
+310 auto