From patchwork Wed Apr 3 06:09:10 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Hongjiang X-Patchwork-Id: 233276 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id BD9E42C0125 for ; Wed, 3 Apr 2013 17:09:40 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1761503Ab3DCGJi (ORCPT ); Wed, 3 Apr 2013 02:09:38 -0400 Received: from mail-pb0-f52.google.com ([209.85.160.52]:40142 "EHLO mail-pb0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758889Ab3DCGJh (ORCPT ); Wed, 3 Apr 2013 02:09:37 -0400 Received: by mail-pb0-f52.google.com with SMTP id mc8so665116pbc.39 for ; Tue, 02 Apr 2013 23:09:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:message-id:date:from:user-agent:mime-version:to:cc :subject:content-type:content-transfer-encoding; bh=5CmWAkSkKyisQwmXj+SGMupTHnsq6on/Onx5EkGEShY=; b=wofzNLGcOgqJCWiW4N4KVJOIRG8Ox9L6f5Q5qSLJqwDuFrjL8AL4oNCuBRUaPcsR9u 7p9CMfsyR9ITBIVmD/Hztw7WXvPQxCxun15If4OEM/kGTCUMXe0FBKa60sX1p5U7ZzCQ o3irHg7dCfryT6rAXbMBEROD6PIlEeAr5JzD8bwFC4m5LK0izeVaJvOt26hbgTHM90Cu 3A/Y1sqCp4/owH+du81R3areXtPkCyHSLVifO7LPpVazATEpdeisOI997Y9m9QpfrJ+r 4JyDiikJqGC3dpE4o4bm/3BykxkFrDSLZa1h04Wl3bQdPRWUZYoJ1lq6AgeNYQijuudn bRnw== X-Received: by 10.68.143.197 with SMTP id sg5mr597626pbb.101.1364969377256; Tue, 02 Apr 2013 23:09:37 -0700 (PDT) Received: from [192.168.204.180] ([218.17.215.175]) by mx.google.com with ESMTPS id tm1sm4675359pbc.11.2013.04.02.23.09.16 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 02 Apr 2013 23:09:36 -0700 (PDT) Message-ID: <515BC786.3070102@gmail.com> Date: Wed, 03 Apr 2013 14:09:10 +0800 From: Zhao Hongjiang User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130107 Thunderbird/17.0.2 MIME-Version: 1.0 To: david@fromorbit.com CC: xfs@oss.sgi.com, linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH] xfstests: Check concurrently of readdir and read on the same directory fd Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Zhao Hongjiang 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 . http://marc.info/?l=linux-kernel&m=136123703211869&w=2 Signed-off-by: Zhao Hongjiang Reviewed-by: Rich Johnston --- src/Makefile | 2 +- src/t_readdir_1.c | 46 +++++++++++++++++++++++++++++ src/t_readdir_2.c | 57 ++++++++++++++++++++++++++++++++++++ tests/generic/308 | 76 +++++++++++++++++++++++++++++++++++++++++++++++++ tests/generic/308.out | 2 + tests/generic/group | 1 + 6 files changed, 183 insertions(+), 1 deletions(-) create mode 100644 src/t_readdir_1.c create mode 100644 src/t_readdir_2.c create mode 100755 tests/generic/308 create mode 100644 tests/generic/308.out -- 1.7.1 -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/src/Makefile b/src/Makefile index f7362a2..8d8e97f 100644 --- a/src/Makefile +++ b/src/Makefile @@ -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 \ - seek_copy_test + seek_copy_test t_readdir_1 t_readdir_2 SUBDIRS = diff --git a/src/t_readdir_1.c b/src/t_readdir_1.c new file mode 100644 index 0000000..2d46b29 --- /dev/null +++ b/src/t_readdir_1.c @@ -0,0 +1,46 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +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 index 0000000..7ec3a50 --- /dev/null +++ b/src/t_readdir_2.c @@ -0,0 +1,57 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +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/308 b/tests/generic/308 new file mode 100755 index 0000000..38d4903 --- /dev/null +++ b/tests/generic/308 @@ -0,0 +1,76 @@ +#! /bin/bash +# FS QA Test No. 308 +# +#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 . +# +# 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/308.out b/tests/generic/308.out new file mode 100644 index 0000000..904ad4d --- /dev/null +++ b/tests/generic/308.out @@ -0,0 +1,2 @@ +QA output created by 308 +*** done diff --git a/tests/generic/group b/tests/generic/group index 450e942..a924086 100644 --- a/tests/generic/group +++ b/tests/generic/group @@ -109,3 +109,4 @@ 299 auto aio enospc rw stress 300 auto aio enospc preallocrw stress 306 auto quick rw +308 auto