From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, NICE_REPLY_A,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5DDA2C433E7 for ; Wed, 2 Sep 2020 15:30:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3008620767 for ; Wed, 2 Sep 2020 15:30:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20150623.gappssmtp.com header.i=@toxicpanda-com.20150623.gappssmtp.com header.b="IEpT4YXg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728274AbgIBPaB (ORCPT ); Wed, 2 Sep 2020 11:30:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728306AbgIBP3z (ORCPT ); Wed, 2 Sep 2020 11:29:55 -0400 Received: from mail-qv1-xf44.google.com (mail-qv1-xf44.google.com [IPv6:2607:f8b0:4864:20::f44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1CE86C061245 for ; Wed, 2 Sep 2020 08:29:55 -0700 (PDT) Received: by mail-qv1-xf44.google.com with SMTP id m14so2394232qvt.1 for ; Wed, 02 Sep 2020 08:29:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=NDGtHV3+xZ+QgHAPo/ikKnk1UyAjOinZA/yddNp58eo=; b=IEpT4YXgeD3Ril/IndxdyXZOz8FjUL/o7Fvgf2p6tr2TlXS3m+4d4LiZ+ww/6Fg6KQ yYqsISvKzEL8nZSb+/jrm6vsL0bMouLGcb3BeQVMp3yPyPwVXwqmHCuMU/0mq7sbToa+ iAfOHyP61gg3OiYxowgey5qFLKRIKNsliQebtLg800JXYcnt0Ezh/dj7WndLis2zXVP1 vqQgGAjaxWKem5AFk/ymMULj3aCCk9acdN4iLKfPcZAe60+N/pYV+aV39i7Xe49Y3p8O KP5EXzmB9ZXlmFkXKj9I5dP9toHd5YFEW1o3GQv27+c8oOD8GzXiFJk0wsAInsGx+kgH wCYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=NDGtHV3+xZ+QgHAPo/ikKnk1UyAjOinZA/yddNp58eo=; b=DmDO7Za7mYFxQyt3Rgr+QQpwiVSrXbqQtWenD8L2H5dIx++upVAvQuWGwrxhYK03Cf 7HbfxiyVAOtM53qi31ILuse2y6kfIeMrmOhhiy2vyoJJTTcfqtTPXBEQubFMtlE9pQEl pqKVoNXLBgucXBjswlDAe8CNz+/aZ+EuTQMr82q0i1CmZBAiBXE9bz3UwkUaRrKi3Cul zGtwEU1J5JEnxR9K9pSrdFla0pOHMHLzyTuiKg2YfpF9eX3lHFGzWAEW+h92tFL1DY7G +WfD3VQmMct7KZENDeyaPf8uwYgp2UWMneyHv7cEtK0hOFJec9jDvlq1N1pDmSQm8z22 pG9A== X-Gm-Message-State: AOAM531R3gK1m29I0/6LlE+AEmBEh3+OVSqjKX/tWVHzrEbt1mbROJPP yCz5yxLbyJcKvuhQAG4XbURE/jHB3lx2QEG4bEg= X-Google-Smtp-Source: ABdhPJwkIHT5mNGTbhNPgD4xPNTrA7+U4P37ua0k7LDtQjVL6ftn4oXayMpgzlgWHKjaDp5WpJfAJw== X-Received: by 2002:a0c:c3cb:: with SMTP id p11mr3067961qvi.101.1599060593704; Wed, 02 Sep 2020 08:29:53 -0700 (PDT) Received: from [192.168.1.45] (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id i65sm4756556qkf.126.2020.09.02.08.29.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 02 Sep 2020 08:29:52 -0700 (PDT) Subject: Re: [PATCH] fstests: add generic/609 to test O_DIRECT|O_DSYNC To: fdmanana@gmail.com Cc: linux-btrfs , fstests References: From: Josef Bacik Message-ID: <3a696ffa-905f-fd28-1d25-790ac450ec0f@toxicpanda.com> Date: Wed, 2 Sep 2020 11:29:51 -0400 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org On 9/2/20 11:18 AM, Filipe Manana wrote: > On Wed, Sep 2, 2020 at 4:03 PM Josef Bacik wrote: >> >> We had a problem recently where btrfs would deadlock with >> O_DIRECT|O_DSYNC because of an unexpected dependency on ->fsync in >> iomap. This was only caught by chance with aiostress, because weirdly >> we don't actually test this particular configuration anywhere in >> xfstests. Fix this by adding a basic test that just does >> O_DIRECT|O_DSYNC writes. With this test the box deadlocks right away >> with Btrfs, which would have been helpful in finding this issue before >> the patches were merged. >> >> Signed-off-by: Josef Bacik >> --- >> .gitignore | 1 + >> src/aio-dio-regress/dio-dsync.c | 61 +++++++++++++++++++++++++++++++++ >> tests/generic/609 | 44 ++++++++++++++++++++++++ >> tests/generic/group | 1 + >> 4 files changed, 107 insertions(+) >> create mode 100644 src/aio-dio-regress/dio-dsync.c >> create mode 100755 tests/generic/609 >> >> diff --git a/.gitignore b/.gitignore >> index 5f5c4a0f..07c8014b 100644 >> --- a/.gitignore >> +++ b/.gitignore >> @@ -175,6 +175,7 @@ >> /src/aio-dio-regress/aio-last-ref-held-by-io >> /src/aio-dio-regress/aiocp >> /src/aio-dio-regress/aiodio_sparse2 >> +/src/aio-dio-regress/dio-dsync >> /src/log-writes/replay-log >> /src/perf/*.pyc >> >> diff --git a/src/aio-dio-regress/dio-dsync.c b/src/aio-dio-regress/dio-dsync.c >> new file mode 100644 >> index 00000000..53cda9ac >> --- /dev/null >> +++ b/src/aio-dio-regress/dio-dsync.c >> @@ -0,0 +1,61 @@ >> +// SPDX-License-Identifier: GPL-2.0-or-newer >> +/* >> + * Copyright (c) 2020 Facebook. >> + * All Rights Reserved. >> + * >> + * Do some O_DIRECT writes with O_DSYNC to exercise this path. >> + */ >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> + >> +int main(int argc, char **argv) >> +{ >> + struct stat st; >> + char *buf; >> + ssize_t ret; >> + int fd, i; >> + int bufsize; >> + >> + if (argc != 2) { >> + printf("Usage: %s filename\n", argv[0]); >> + return 1; >> + } >> + >> + fd = open(argv[1], O_DIRECT | O_RDWR | O_TRUNC | O_CREAT | O_DSYNC, >> + 0644); >> + if (fd < 0) { >> + perror(argv[1]); >> + return 1; >> + } >> + >> + if (fstat(fd, &st)) { >> + perror(argv[1]); >> + return 1; >> + } >> + bufsize = st.st_blksize * 10; >> + >> + ret = posix_memalign((void **)&buf, st.st_blksize, bufsize); >> + if (ret) { >> + errno = ret; >> + perror("allocating buffer"); >> + return 1; >> + } >> + >> + memset(buf, 'a', bufsize); >> + for (i = 0; i < 10; i++) { >> + ret = write(fd, buf, bufsize); >> + if (ret < 0) { >> + perror("writing"); >> + return 1; >> + } >> + } >> + free(buf); >> + close(fd); >> + return 0; >> +} >> diff --git a/tests/generic/609 b/tests/generic/609 >> new file mode 100755 >> index 00000000..8a888eb9 >> --- /dev/null >> +++ b/tests/generic/609 >> @@ -0,0 +1,44 @@ >> +#! /bin/bash >> +# SPDX-License-Identifier: GPL-2.0 >> +# Copyright (c) 2020 Josef Bacik. All Rights Reserved. >> +# >> +# FS QA Test 609 >> +# >> +# iomap can call generic_write_sync() if we're O_DSYNC, so write a basic test to >> +# exercise O_DSYNC so any unsuspecting file systems will get lockdep warnings if >> +# they're locking isn't compatible. >> +# >> +seq=`basename $0` >> +seqres=$RESULT_DIR/$seq >> +echo "QA output created by $seq" >> + >> +here=`pwd` >> +tmp=/tmp/$$ >> +status=1 # failure is the default! >> +trap "_cleanup; exit \$status" 0 1 2 3 15 >> + >> +_cleanup() >> +{ >> + cd / >> + rm -f $tmp.* >> + rm -rf $TEST_DIR/file >> +} >> + >> +# get standard environment, filters and checks >> +. ./common/rc >> +. ./common/filter >> + >> +# remove previous $seqres.full before test >> +rm -f $seqres.full >> + >> +# Modify as appropriate. >> +_supported_fs generic >> +_supported_os Linux >> +_require_test >> +_require_aiodio dio-dsync >> + >> +$AIO_TEST $TEST_DIR/file > > This can be triggered with xfs_io and without adding a new test program: > > #!/bin/bash > > mkfs.btrfs -f /dev/sdj > mount /dev/sdj /mnt/sdj > > xfs_io -f -d -c "pwrite -D -V 1 0 4K" /mnt/sdj/foobar > > Ah that's how you do it, I didn't realize I could pass the open flags on the command line, so I had done something wonkey like xfs_io -c "open -fds FILE" -c "pwrite" and it hadn't worked, I really didn't want to write a bunch of code. Thanks, I'll fix that, Josef