Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1230886pxu; Fri, 27 Nov 2020 02:55:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJzSLglpXUhahurwiYiZiVKbWig/uWqTrRV/FUZcGQY5FxUkTgw7Le2wXo+Zcq1hALZxmMhI X-Received: by 2002:a17:906:c826:: with SMTP id dd6mr7469101ejb.191.1606474530126; Fri, 27 Nov 2020 02:55:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606474530; cv=none; d=google.com; s=arc-20160816; b=UXR1c0DCoJSDyu7xWA0nPbfxYRISSgFm5SCQdZM/rYlrvWXSltWEdSOU6PZJwONyQR kJ1Jmu2kVHxCuC8lIWKrusCrLTT5mqjjUy8d/ZhsdlafR2d3K72LiGzSnCfIgzXN7iyL kh4Ijd/DvnvTGxKzKLJmTjTLnldodY5dSbfvmNW4AorXL57v3Izf5LK1L3/Lz5BjaMnG D7tK5rIdztc0z6bL4ixWEzqQeu1TXfmKGdqn9xzFTlIXycLAfewQNgmm6X3sgF13t1y8 /UXdgtsOflS6wWNQedspYy7H2/hbxACNkH9AA8HcWUcLNGtSkidaFNphQ7+bgOjEHqfE 9USg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:to:from:dkim-signature; bh=DbOeu0nupaHpMrFspv7A8PwdzpkOFyVZUcMa4iz6ghU=; b=ipNpBLFI4dfTgpoffcIPpsJcgcl42f5yyW7HJ6PGwISTp/srzcyNwzu/Pv+KzpRqqm i8yCptPqL9ZR91BsXJdXEansD7kYXTPpVfSt/F5PDX2JaXL1FMeII9PI+YeAlVPq0JaB DagZARcI4Sm+TcC1VMF0fUXqvISeRKoRUQTwLNnNKKmimTDAeMkL99mm1N9goKtfqz9X qQh3gejSCFmjjWqhLccBXtKFN+4Dvg5ijBa0POeJld0ARu9fAUdhTamqSvtyy6/FpX0o D2fqMSB+3LqC2K9CZbEzFv6SWzS2OWIAArI4RDHu22z7G7CqrmhquA4ilWWG+0SX+OVs TcUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=ruI6WavJ; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y23si2461658ejr.725.2020.11.27.02.54.51; Fri, 27 Nov 2020 02:55:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=ruI6WavJ; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726178AbgK0KyY (ORCPT + 99 others); Fri, 27 Nov 2020 05:54:24 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:47278 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725985AbgK0KyY (ORCPT ); Fri, 27 Nov 2020 05:54:24 -0500 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0ARAWLgh071524; Fri, 27 Nov 2020 05:54:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : subject : date : message-id : mime-version : content-transfer-encoding; s=pp1; bh=DbOeu0nupaHpMrFspv7A8PwdzpkOFyVZUcMa4iz6ghU=; b=ruI6WavJk/MS/HJywasrp3R4KwZGdqgyCFYM1NW7ouSP2S5YfwUwl84VWktM5F8tVKvI tp+DnMPv44PXYqKSzJ4x7dGNOtrim8C0+kWZTCynC1oy8JCYSsD9r8FlS/l8GBNJUhwq GJMC4gVb5PgE3HZs7WW9hFY2PjqzBlHYmtNCt3D+ULZ7iCZlifcNzY+xHfitXtpPXPjH yxif/eaUk3gYdFn6KPp3eFizGCn/V+VAnj7n99QaJtpeDHPiCBkEl/BPUyBvtlQB6e+O oKnmCgPhL0FHl4z8k9O79ChDoo7v3SviGos6ypigSm6lKyhmIAJcE+H44ypiVWU6KEal Hg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 352xru2aej-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Nov 2020 05:54:23 -0500 Received: from m0098399.ppops.net (m0098399.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 0ARAWc6o072219; Fri, 27 Nov 2020 05:54:23 -0500 Received: from ppma05fra.de.ibm.com (6c.4a.5195.ip4.static.sl-reverse.com [149.81.74.108]) by mx0a-001b2d01.pphosted.com with ESMTP id 352xru2adx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Nov 2020 05:54:22 -0500 Received: from pps.filterd (ppma05fra.de.ibm.com [127.0.0.1]) by ppma05fra.de.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 0ARArN7J019074; Fri, 27 Nov 2020 10:54:20 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma05fra.de.ibm.com with ESMTP id 352ww601yc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Nov 2020 10:54:20 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 0ARAsHU122020398 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Nov 2020 10:54:17 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8C7CA4C046; Fri, 27 Nov 2020 10:54:17 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5E3404C040; Fri, 27 Nov 2020 10:54:16 +0000 (GMT) Received: from pratiks-thinkpad.ibmuc.com (unknown [9.102.25.109]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 27 Nov 2020 10:54:16 +0000 (GMT) From: Pratik Rajesh Sampat To: fstests@vger.kernel.org, linux-ext4@vger.kernel.org, riteshh@linux.ibm.com, sourabhjain@linux.ibm.com, psampat@linux.ibm.com, pratik.r.sampat@gmail.com Subject: [PATCH] generic: ENOSPC regression test in a multi-threaded scenario Date: Fri, 27 Nov 2020 16:24:15 +0530 Message-Id: <20201127105415.41831-1-psampat@linux.ibm.com> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312,18.0.737 definitions=2020-11-27_05:2020-11-26,2020-11-27 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 clxscore=1011 spamscore=0 mlxlogscore=999 impostorscore=0 mlxscore=0 bulkscore=0 phishscore=0 lowpriorityscore=0 malwarescore=0 priorityscore=1501 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2011270061 Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Test allocation strategies of the file system and validate space anomalies as reported by the system versus the allocated by the program. The test is motivated by a bug in ext4 systems where-in ENOSPC is reported by the file system even though enough space for allocations is available[1]. [1]: https://patchwork.ozlabs.org/patch/1294003 Suggested-by: Ritesh Harjani Co-authored-by: Sourabh Jain Signed-off-by: Sourabh Jain Signed-off-by: Pratik Rajesh Sampat --- src/Makefile | 2 +- src/t_enospc.c | 186 ++++++++++++++++++++++++++++++++++++++++++ tests/generic/618 | 168 ++++++++++++++++++++++++++++++++++++++ tests/generic/618.out | 2 + tests/generic/group | 1 + 5 files changed, 358 insertions(+), 1 deletion(-) create mode 100644 src/t_enospc.c create mode 100755 tests/generic/618 create mode 100644 tests/generic/618.out diff --git a/src/Makefile b/src/Makefile index 919d77c4..32940142 100644 --- a/src/Makefile +++ b/src/Makefile @@ -17,7 +17,7 @@ TARGETS = dirstress fill fill2 getpagesize holes lstat64 \ t_mmap_cow_race t_mmap_fallocate fsync-err t_mmap_write_ro \ t_ext4_dax_journal_corruption t_ext4_dax_inline_corruption \ t_ofd_locks t_mmap_collision mmap-write-concurrent \ - t_get_file_time t_create_short_dirs t_create_long_dirs + t_get_file_time t_create_short_dirs t_create_long_dirs t_enospc LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \ preallo_rw_pattern_writer ftrunc trunc fs_perms testx looptest \ diff --git a/src/t_enospc.c b/src/t_enospc.c new file mode 100644 index 00000000..a0a8c783 --- /dev/null +++ b/src/t_enospc.c @@ -0,0 +1,186 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2020 IBM. + * All Rights Reserved. + * + * simple mmap write multithreaded test + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define pr_debug(fmt, ...) do { \ + if (verbose) { \ + printf (fmt, ##__VA_ARGS__); \ + } \ +} while (0) + +struct thread_s { + int id; +}; + +static float file_ratio[2] = {0.5, 0.5}; +static unsigned long fsize = 0; +static char *base_dir = "."; +static char *ratio = "1"; + +static bool use_fallocate = false; +static bool verbose = false; + +pthread_barrier_t bar; + +void handle_sigbus(int sig) +{ + pr_debug("Enospc test failed with SIGBUS\n"); + exit(7); +} + +void enospc_test(int id) +{ + int fd; + char fpath[255] = {0}; + char *addr; + unsigned long size = 0; + + if (id % 2 == 0) + size = fsize * file_ratio[0]; + else + size = fsize * file_ratio[1]; + + pthread_barrier_wait(&bar); + + sprintf(fpath, "%s/mmap-file-%d", base_dir, id); + pr_debug("Test write phase starting file %s fsize %lu, id %d\n", fpath, size, id); + + signal(SIGBUS, handle_sigbus); + + fd = open(fpath, O_RDWR | O_CREAT, 0644); + if (fd < 0) { + pr_debug("Open failed\n"); + exit(1); + } + + if (use_fallocate) + assert(fallocate(fd, 0, 0, fsize) == 0); + else + assert(ftruncate(fd, size) == 0); + + addr = mmap(NULL, size, PROT_WRITE, MAP_SHARED, fd, 0); + assert(addr != MAP_FAILED); + + for (int i = 0; i < size; i++) { + addr[i] = 0xAB; + } + + assert(munmap(addr, size) != -1); + close(fd); + pr_debug("Test write phase completed...file %s, fsize %lu, id %d\n", fpath, size, id); +} + +void *spawn_test_thread(void *arg) +{ + struct thread_s *thread_info = (struct thread_s *)arg; + pthread_t tid; + + tid = pthread_self(); + pr_debug("Inside thread %lu %d\n", tid, thread_info->id); + enospc_test(thread_info->id); + return NULL; +} + +void _run_test(int threads) +{ + pthread_t tid[threads]; + + pthread_barrier_init(&bar, NULL, threads+1); + for (int i = 0; i < threads; i++) { + struct thread_s *thread_info = (struct thread_s *) malloc(sizeof(struct thread_s)); + thread_info->id = i; + assert(pthread_create(&tid[i], NULL, spawn_test_thread, thread_info) == 0); + } + + pthread_barrier_wait(&bar); + + for (int i = 0; i &2 "func->${FUNCNAME[1]}: $1" + fi +} + +# Calculate the number of threads needed to fill the disk space +calc_thread_cnt() +{ + local file_ratio_unit=$1 + local file_ratio=$2 + local disk_saturation=$3 + local tot_avail_size + local avail_size + local thread_cnt + + IFS=',' read -ra fratio <<< $file_ratio + file_ratio_cnt=${#fratio[@]} + + tot_avail_size=$(df --block-size=1 $SCRATCH_DEV | awk 'FNR == 2 { print $4 }') + avail_size=$(echo $tot_avail_size*$disk_saturation | bc) + thread_cnt=$(echo "$file_ratio_cnt*($avail_size/$file_ratio_unit)" | bc) + + debug "Total available size: $tot_avail_size" + debug "Available size: $avail_size" + debug "Thread count: $thread_cnt" + + echo ${thread_cnt} +} + +run_testcase() +{ + IFS=':' read -ra args <<< $1 + local test_name=${args[0]} + local file_ratio_unit=${args[1]} + local file_ratio=${args[2]} + local disk_saturation=${args[3]} + local disk_alloc_method=${args[4]} + local test_iteration_cnt=${args[5]} + local extra_args="" + local thread_cnt + + if [ "$disk_alloc_method" == "$FTRUNCATE" ]; then + extra_args="$extra_args -f" + fi + + # enable the debug statements in c program + if [ "$DEBUG" -eq 1 ]; then + extra_args="$extra_args -v" + fi + + for i in $(eval echo "{1..$test_iteration_cnt}") + do + # Setup the device + _scratch_mkfs_sized $FS_SIZE >> $seqres.full 2>&1 + _scratch_mount + + thread_cnt=$(calc_thread_cnt $file_ratio_unit $file_ratio $disk_saturation) + + debug "====== Test details starts ======" + debug "Test name: $test_name" + debug "File ratio unit: $file_ratio_unit" + debug "File ratio: $file_ratio" + debug "Disk saturation $disk_saturation" + debug "Disk alloc method $disk_alloc_method" + debug "Test iteration count: $test_iteration_cnt" + debug "Extra arg: $extra_args" + debug "Thread count: $thread_cnt" + debug "============ end ===============" + + # Start the test + $here/src/t_enospc -t $thread_cnt -s $file_ratio_unit -r $file_ratio -p $SCRATCH_MNT $extra_args + + status=$(echo $?) + if [ $status -ne 0 ]; then + use_per=$(df -h | grep $SCRATCH_MNT | awk '{print substr($5, 1, length($5)-1)}' | bc) + alloc_per=$(echo "$FACT * 100" | bc) + # We are here since t_nospc failed with an error code. + # If the used filesystem space is still < available space - that means + # the test failed due to FS wrongly reported ENOSPC. + if [ $(echo "$use_per < $alloc_per" | bc) -ne 0 ]; then + if [ $status -eq 134 ]; then + echo "FAIL: Aborted assertion faliure" + elif [ $status -eq 7 ]; then + echo "FAIL: ENOSPC BUS faliure" + fi + echo "$test_name failed at iteration count: $i" + echo "$(df -h $SCRATCH_MNT)" + echo "Allocated: $alloc_per% Used: $use_per%" + exit + fi + fi + + # Make space for other tests + _scratch_unmount + done +} + +declare -a TEST_VECTORS=( +# test-name:file-ratio-unit:file-ratio:disk-saturation:disk-alloc-method:test-iteration-cnt +"Small-file-test:$SMALL_FILE_SIZE:1:$FACT:$FALLOCATE:3" +"Big-file-test:$BIG_FILE_SIZE:1:$FACT:$FALLOCATE:3" +"Mix-file-test:$MIX_FILE_SIZE:0.75,0.25:$FACT:$FALLOCATE:3" +) + +# real QA test starts here +for i in "${TEST_VECTORS[@]}"; do + run_testcase $i +done + +echo "Silence is golden" +status=0 +exit diff --git a/tests/generic/618.out b/tests/generic/618.out new file mode 100644 index 00000000..8940b72f --- /dev/null +++ b/tests/generic/618.out @@ -0,0 +1,2 @@ +QA output created by 618 +Silence is golden diff --git a/tests/generic/group b/tests/generic/group index 94e860b8..dc668c06 100644 --- a/tests/generic/group +++ b/tests/generic/group @@ -620,3 +620,4 @@ 615 auto rw 616 auto rw io_uring stress 617 auto rw io_uring stress +618 auto rw stress -- 2.28.0