From patchwork Tue Oct 3 14:38:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 9983009 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id F13D8602B8 for ; Tue, 3 Oct 2017 14:38:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D1B35289AC for ; Tue, 3 Oct 2017 14:38:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C6495289AE; Tue, 3 Oct 2017 14:38:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B71EA289AC for ; Tue, 3 Oct 2017 14:38:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751545AbdJCOiE (ORCPT ); Tue, 3 Oct 2017 10:38:04 -0400 Received: from verein.lst.de ([213.95.11.211]:44340 "EHLO newverein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751238AbdJCOiE (ORCPT ); Tue, 3 Oct 2017 10:38:04 -0400 Received: by newverein.lst.de (Postfix, from userid 2407) id 85BC668CEE; Tue, 3 Oct 2017 16:38:02 +0200 (CEST) Date: Tue, 3 Oct 2017 16:38:02 +0200 From: Christoph Hellwig To: fstests@vger.kernel.org Cc: linux-xfs@vger.kernel.org Subject: add a new test for racing AIO COW writes Message-ID: <20171003143802.GA3964@lst.de> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.17 (2007-11-01) Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This can be used to trigger an assert in the current XFS code because it can't handle the case where there are COW extents on a file, but none at or below the range converted by the AIO completion handler. Note that it doesn't trigger the assert 100% but fairly reliably. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- To unsubscribe from this list: send the line "unsubscribe linux-xfs" 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/aio-dio-regress/aio-dio-cow-race.c b/src/aio-dio-regress/aio-dio-cow-race.c new file mode 100755 index 0000000..c7f8e89 --- /dev/null +++ b/src/aio-dio-regress/aio-dio-cow-race.c @@ -0,0 +1,119 @@ +/* + * Copyright (c) Christoph Hellwig. 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 + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#ifndef FICLONE +#define FICLONE _IOW(0x94, 9, int) +#endif + +#define IO_PATTERN 0xab + +int main(int argc, char *argv[]) +{ + struct io_context *ctx = NULL; + struct io_event evs[4]; + struct iocb iocb1, iocb2, iocb3, iocb4; + struct iocb *iocbs[] = { &iocb1, &iocb2, &iocb3, &iocb4 }; + void *buf; + int fd, clone, err = 0; + unsigned long buf_size = getpagesize() * 2; + char *filename, *clonename; + + if (argc != 3) { + fprintf(stderr, "usage: %s filename clonename\n", argv[0]); + exit(1); + } + + err = posix_memalign(&buf, getpagesize(), buf_size); + if (err) { + fprintf(stderr, "error %s during %s\n", + strerror(err), "posix_memalign"); + return 1; + } + memset(buf, IO_PATTERN, buf_size); + + filename = argv[1]; + fd = open(filename, O_DIRECT | O_CREAT | O_TRUNC | O_RDWR, 0600); + if (fd == -1) { + perror("open"); + return 1; + } + + if (write(fd, buf, buf_size) != buf_size) { + perror("write"); + return 1; + } + + clonename = argv[2]; + clone = open(clonename, O_DIRECT | O_CREAT | O_TRUNC | O_RDWR, 0600); + if (clone == -1) { + perror("open clone"); + return 1; + } + + if (ioctl(clone, FICLONE, fd)) { + perror("FICLONE"); + return 1; + } + + err = io_setup(4, &ctx); + if (err) { + fprintf(stderr, "error %s during %s\n", + strerror(err), + "io_setup"); + return 1; + } + + /* + * Test overlapping aio writes, where an earlier one clears the whole + * range of a later aio, thus leaving nothing to do for the I/O + * completion to do. To make things harder also make sure there is + * other outstanding COW I/O. + */ + io_prep_pwrite(&iocb1, fd, buf, buf_size, 0); + io_prep_pwrite(&iocb2, fd, buf, buf_size / 2, 0); + io_prep_pwrite(&iocb3, fd, buf, buf_size / 2, buf_size); + io_prep_pwrite(&iocb4, fd, buf, buf_size, 0); + + err = io_submit(ctx, 4, iocbs); + if (err != 4) { + fprintf(stderr, "error %s during %s\n", + strerror(err), "io_submit"); + return 1; + } + + err = io_getevents(ctx, 4, 4, evs, NULL); + if (err != 4) { + fprintf(stderr, "error %s during %s\n", + strerror(err), "io_getevents"); + return 1; + } + + return 0; +} diff --git a/tests/generic/463 b/tests/generic/463 new file mode 100755 index 0000000..b3afbb0 --- /dev/null +++ b/tests/generic/463 @@ -0,0 +1,60 @@ +#! /bin/bash +# FS QA Test 463 +# +# Test racy COW AIO write completions. +# +#----------------------------------------------------------------------- +# Copyright (c) 2017 Christoph Hellwig. 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 +#----------------------------------------------------------------------- +# + +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 -f $TEST_DIR/file $TEST_DIR/clone +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter +. ./common/reflink + +# remove previous $seqres.full before test +rm -f $seqres.full + +_supported_fs generic +_supported_os Linux + +_require_test +_require_test_reflink +_require_aio +_require_odirect + +$here/src/aio-dio-regress/aio-dio-cow-race $TEST_DIR/file $TEST_DIR/clone + +echo "Silence is golden" +status=0 +exit diff --git a/tests/generic/group b/tests/generic/group index f2a6cda..014d6ea 100644 --- a/tests/generic/group +++ b/tests/generic/group @@ -465,3 +465,4 @@ 460 auto quick rw 461 auto shutdown stress 462 auto quick dax +463 auto quick reflink dangerous