From patchwork Fri Dec 7 06:24:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 10717543 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BE9C917D5 for ; Fri, 7 Dec 2018 06:24:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A97182EB67 for ; Fri, 7 Dec 2018 06:24:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9D47E2EB78; Fri, 7 Dec 2018 06:24:46 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham 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 DE28C2EB67 for ; Fri, 7 Dec 2018 06:24:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726036AbeLGGYp (ORCPT ); Fri, 7 Dec 2018 01:24:45 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:34536 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725952AbeLGGYp (ORCPT ); Fri, 7 Dec 2018 01:24:45 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id wB76OJ8G118815; Fri, 7 Dec 2018 06:24:41 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : from : to : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2018-07-02; bh=dJZwAw+JAmQr8ozxwMvo7+HO0JhdNxPiB+/dxNwQYNU=; b=BPNOsIUWkpc0SSKGa9MWQWRs66emKBhx3pW/4aRUv4FcK0hKRF8wnaIUYjKL1GDXGu4p fanhdtCcU6XEoSbngZK5KM6bLD2jkqkBh0nZ6XVhyCz0qzVq3PhQplWb0QOLZoLAR3Ws /YJDRoO+zNBVuGgp/7LI7XS4YN04hwjpAhBO68VAYODZoDA5JfSk5YiixqspDOl2WGET ge8/YbbSfNiw/V4Ovev1hi4MEHsoUsvL8rj8OBT0XKMSjgLbPBv4EJiwZVDrQLIVe7M+ +5/Bf/hw77iJoN6tLRVR3x7q90TO8PgrlRcfVgGpVyc8ywdeBMZvslpu5Rt1s0XT/hbQ Rg== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp2130.oracle.com with ESMTP id 2p3ftfg1ry-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 07 Dec 2018 06:24:40 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id wB76OZqr019081 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 7 Dec 2018 06:24:35 GMT Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id wB76OYtg016500; Fri, 7 Dec 2018 06:24:34 GMT Received: from localhost (/10.159.153.113) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 06 Dec 2018 22:24:34 -0800 Subject: [PATCH 10/12] fsx: add copy_file_range support From: "Darrick J. Wong" To: guaneryu@gmail.com, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org, fstests@vger.kernel.org, Dave Chinner Date: Thu, 06 Dec 2018 22:24:33 -0800 Message-ID: <154416387314.15344.2165201747424065702.stgit@magnolia> In-Reply-To: <154416379233.15344.4377231692638417530.stgit@magnolia> References: <154416379233.15344.4377231692638417530.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9099 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1812070055 Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Darrick J. Wong Add support for the copy_file_range system call to fsx. Signed-off-by: Darrick J. Wong [dchinner: copy_file_range() needs to obey read/write constraints otherwise is blows up when direct IO is used] Signed-off-by: Dave Chinner --- ltp/fsx.c | 165 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 163 insertions(+), 2 deletions(-) diff --git a/ltp/fsx.c b/ltp/fsx.c index e7a88c04..316f08eb 100644 --- a/ltp/fsx.c +++ b/ltp/fsx.c @@ -34,6 +34,7 @@ #ifdef AIO #include #endif +#include #ifndef MAP_FILE # define MAP_FILE 0 @@ -106,6 +107,7 @@ enum { OP_INSERT_RANGE, OP_CLONE_RANGE, OP_DEDUPE_RANGE, + OP_COPY_RANGE, OP_MAX_FULL, /* integrity operations */ @@ -169,6 +171,7 @@ int mapped_reads = 1; /* -R flag disables it */ int check_file = 0; /* -X flag enables */ int clone_range_calls = 1; /* -J flag disables */ int dedupe_range_calls = 1; /* -B flag disables */ +int copy_range_calls = 1; /* -E flag disables */ int integrity = 0; /* -i flag */ int fsxgoodfd = 0; int o_direct; /* -Z */ @@ -264,6 +267,7 @@ static const char *op_names[] = { [OP_INSERT_RANGE] = "insert_range", [OP_CLONE_RANGE] = "clone_range", [OP_DEDUPE_RANGE] = "dedupe_range", + [OP_COPY_RANGE] = "copy_range", [OP_FSYNC] = "fsync", }; @@ -477,6 +481,20 @@ logdump(void) else if (overlap2) prt("\t******BBBB"); break; + case OP_COPY_RANGE: + prt("COPY 0x%x thru 0x%x\t(0x%x bytes) to 0x%x thru 0x%x", + lp->args[0], lp->args[0] + lp->args[1] - 1, + lp->args[1], + lp->args[2], lp->args[2] + lp->args[1] - 1); + overlap2 = badoff >= lp->args[2] && + badoff < lp->args[2] + lp->args[1]; + if (overlap && overlap2) + prt("\tEEEE**EEEE"); + else if (overlap) + prt("\tEEEE******"); + else if (overlap2) + prt("\t******EEEE"); + break; case OP_FSYNC: prt("FSYNC"); break; @@ -1558,6 +1576,110 @@ do_dedupe_range(unsigned offset, unsigned length, unsigned dest) } #endif +#ifdef HAVE_COPY_FILE_RANGE +int +test_copy_range(void) +{ + loff_t o1 = 0, o2 = 0; + + if (syscall(__NR_copy_file_range, fd, &o1, fd, &o2, 0, 0) == -1 && + (errno == EOPNOTSUPP || errno == ENOTTY)) { + if (!quiet) + fprintf(stderr, + "main: filesystem does not support " + "copy range, disabling!\n"); + return 0; + } + + return 1; +} + +void +do_copy_range(unsigned offset, unsigned length, unsigned dest) +{ + loff_t o1, o2; + size_t olen; + ssize_t nr; + int tries = 0; + + if (length == 0) { + if (!quiet && testcalls > simulatedopcount) + prt("skipping zero length copy range\n"); + log5(OP_COPY_RANGE, offset, length, dest, FL_SKIPPED); + return; + } + + if ((loff_t)offset >= file_size) { + if (!quiet && testcalls > simulatedopcount) + prt("skipping copy range behind EOF\n"); + log5(OP_COPY_RANGE, offset, length, dest, FL_SKIPPED); + return; + } + + if (dest + length > biggest) { + biggest = dest + length; + if (!quiet && testcalls > simulatedopcount) + prt("copying to largest ever: 0x%x\n", dest + length); + } + + log5(OP_COPY_RANGE, offset, length, dest, FL_NONE); + + if (testcalls <= simulatedopcount) + return; + + if ((progressinterval && testcalls % progressinterval == 0) || + (debug && (monitorstart == -1 || monitorend == -1 || + dest <= monitorstart || dest + length <= monitorend))) { + prt("%lu copy\tfrom 0x%x to 0x%x, (0x%x bytes) at 0x%x\n", + testcalls, offset, offset+length, length, dest); + } + + o1 = offset; + o2 = dest; + olen = length; + + while (olen > 0) { + nr = syscall(__NR_copy_file_range, fd, &o1, fd, &o2, olen, 0); + if (nr < 0) { + if (errno != EAGAIN || tries++ >= 300) + break; + } else if (nr > olen) { + prt("copy range: 0x%x to 0x%x at 0x%x\n", offset, + offset + length, dest); + prt("do_copy_range: asked %u, copied %u??\n", + nr, olen); + report_failure(161); + } else if (nr > 0) + olen -= nr; + } + if (nr < 0) { + prt("copy range: 0x%x to 0x%x at 0x%x\n", offset, + offset + length, dest); + prterr("do_copy_range:"); + report_failure(161); + } + + memcpy(good_buf + dest, good_buf + offset, length); + if (dest > file_size) + memset(good_buf + file_size, '\0', dest - file_size); + if (dest + length > file_size) + file_size = dest + length; +} + +#else +int +test_copy_range(void) +{ + return 0; +} + +void +do_copy_range(unsigned offset, unsigned length, unsigned dest) +{ + return; +} +#endif + #ifdef HAVE_LINUX_FALLOC_H /* fallocate is basically a no-op unless extending, then a lot like a truncate */ void @@ -1717,6 +1839,7 @@ op_args_count(int operation) switch (operation) { case OP_CLONE_RANGE: case OP_DEDUPE_RANGE: + case OP_COPY_RANGE: return 4; default: return 3; @@ -1891,6 +2014,18 @@ test(void) offset2 + size > file_size); break; } + case OP_COPY_RANGE: + TRIM_OFF_LEN(offset, size, file_size); + offset -= offset % readbdy; + if (o_direct) + size -= size % readbdy; + do { + offset2 = random(); + TRIM_OFF(offset2, maxfilelen); + offset2 -= offset2 % writebdy; + } while (llabs(offset2 - offset) < size || + offset2 + size > maxfilelen); + break; } have_op: @@ -1946,6 +2081,12 @@ test(void) goto out; } break; + case OP_COPY_RANGE: + if (!copy_range_calls) { + log5(op, offset, size, offset2, FL_SKIPPED); + goto out; + } + break; } switch (op) { @@ -2036,6 +2177,18 @@ test(void) do_dedupe_range(offset, size, offset2); break; + case OP_COPY_RANGE: + if (size == 0) { + log5(OP_COPY_RANGE, offset, size, offset2, FL_SKIPPED); + goto out; + } + if (offset2 + size > maxfilelen) { + log5(OP_COPY_RANGE, offset, size, offset2, FL_SKIPPED); + goto out; + } + + do_copy_range(offset, size, offset2); + break; case OP_FSYNC: dofsync(); break; @@ -2061,7 +2214,7 @@ void usage(void) { fprintf(stdout, "usage: %s", - "fsx [-dknqxABFJLOWZ] [-b opnum] [-c Prob] [-g filldata] [-i logdev] [-j logid] [-l flen] [-m start:end] [-o oplen] [-p progressinterval] [-r readbdy] [-s style] [-t truncbdy] [-w writebdy] [-D startingop] [-N numops] [-P dirpath] [-S seed] fname\n\ + "fsx [-dknqxABEFJLOWZ] [-b opnum] [-c Prob] [-g filldata] [-i logdev] [-j logid] [-l flen] [-m start:end] [-o oplen] [-p progressinterval] [-r readbdy] [-s style] [-t truncbdy] [-w writebdy] [-D startingop] [-N numops] [-P dirpath] [-S seed] fname\n\ -b opnum: beginning operation number (default 1)\n\ -c P: 1 in P chance of file close+open at each op (default infinity)\n\ -d: debug output for all operations\n\ @@ -2108,6 +2261,9 @@ usage(void) #ifdef FIDEDUPERANGE " -B: Do not use dedupe range calls\n" #endif +#ifdef HAVE_COPY_FILE_RANGE +" -E: Do not use copy range calls\n" +#endif " -L: fsxLite - no file creations & no file size changes\n\ -N numops: total # operations to do (default infinity)\n\ -O: use oplen (see -o flag) for every op (default random)\n\ @@ -2311,7 +2467,7 @@ main(int argc, char **argv) setvbuf(stdout, (char *)0, _IOLBF, 0); /* line buffered stdout */ while ((ch = getopt_long(argc, argv, - "b:c:dfg:i:j:kl:m:no:p:qr:s:t:w:xyABD:FJKHzCILN:OP:RS:WXZ", + "b:c:dfg:i:j:kl:m:no:p:qr:s:t:w:xyABD:EFJKHzCILN:OP:RS:WXZ", longopts, NULL)) != EOF) switch (ch) { case 'b': @@ -2447,6 +2603,9 @@ main(int argc, char **argv) case 'B': dedupe_range_calls = 0; break; + case 'E': + copy_range_calls = 0; + break; case 'L': lite = 1; o_flags &= ~(O_CREAT|O_TRUNC); @@ -2669,6 +2828,8 @@ main(int argc, char **argv) clone_range_calls = test_clone_range(); if (dedupe_range_calls) dedupe_range_calls = test_dedupe_range(); + if (copy_range_calls) + copy_range_calls = test_copy_range(); while (numops == -1 || numops--) if (!test())