From patchwork Tue Nov 13 23:39:49 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: 10681629 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 8B7DC3CF1 for ; Tue, 13 Nov 2018 23:39:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7A2782B458 for ; Tue, 13 Nov 2018 23:39:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6E2DD2B487; Tue, 13 Nov 2018 23:39:58 +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 F0DEC2B486 for ; Tue, 13 Nov 2018 23:39:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726659AbeKNJkd (ORCPT ); Wed, 14 Nov 2018 04:40:33 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:37100 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727770AbeKNJkc (ORCPT ); Wed, 14 Nov 2018 04:40:32 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id wADNd8J0098103; Tue, 13 Nov 2018 23:39:55 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=CCspqmgq6rcZ1jq4J5wVnBCehxGn1nlO3/9yyYIifpY=; b=txvjsDTEvPW5O2k3W0s3zq6AXdwyUR/3woBIJNBrR8EB3Urfc5iThOYTn2ByWyODJ9cp fTP9Rbsid7TEnqTspf6jgqLiHcluqX/2p88LuXzDP5/9/VCE9gZO0JjKBZRRQMb2RR9i AhbC9wynKZTCB8nfyB7LWHW7VaSo4EYxyKPkjSRkpEDPeobGSmD93OtxmP9gigF5OsmY C0Q8x2+936pJB0gKvPPjl66mV+GLw6XIl73dyydTggSMr9nPfXvJO/Fixz8NjLURavF5 GBeYgODfV0kR0luQVFvB+3EneSnfqti74nRWOjoCG0mJUtdRH8YyGm/+91zxvDppiBjk 4w== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2120.oracle.com with ESMTP id 2nr7cs092s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 13 Nov 2018 23:39:55 +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 wADNds6K023962 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 13 Nov 2018 23:39:54 GMT Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id wADNds6b024748; Tue, 13 Nov 2018 23:39:54 GMT Received: from localhost (/10.159.147.150) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 13 Nov 2018 15:39:53 -0800 Subject: [PATCH 2/6] fsx: add FIDEDUPERANGE support From: "Darrick J. Wong" To: guaneryu@gmail.com, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org, fstests@vger.kernel.org Date: Tue, 13 Nov 2018 15:39:49 -0800 Message-ID: <154215238968.21151.11312208246254421488.stgit@magnolia> In-Reply-To: <154215237717.21151.11976488103599724788.stgit@magnolia> References: <154215237717.21151.11976488103599724788.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9076 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 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-1811130211 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 Signed-off-by: Darrick J. Wong --- ltp/fsx.c | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) diff --git a/ltp/fsx.c b/ltp/fsx.c index 2b0a2b28..6f2b3364 100644 --- a/ltp/fsx.c +++ b/ltp/fsx.c @@ -104,6 +104,7 @@ enum { OP_COLLAPSE_RANGE, OP_INSERT_RANGE, OP_CLONE_RANGE, + OP_DEDUPE_RANGE, OP_MAX_FULL, /* integrity operations */ @@ -259,6 +260,7 @@ static const char *op_names[] = { [OP_COLLAPSE_RANGE] = "collapse_range", [OP_INSERT_RANGE] = "insert_range", [OP_CLONE_RANGE] = "clone_range", + [OP_DEDUPE_RANGE] = "dedupe_range", [OP_FSYNC] = "fsync", }; @@ -448,6 +450,13 @@ logdump(void) if (overlap) prt("\t******IIII"); break; + case OP_DEDUPE_RANGE: + prt("DEDUPE 0x%x thru 0x%x\t(0x%x bytes) to 0x%x", + lp->args[0], lp->args[0] + lp->args[1] - 1, + lp->args[1], lp->args[2]); + if (overlap) + prt("\t******IIII"); + break; case OP_FSYNC: prt("FSYNC"); break; @@ -1315,6 +1324,82 @@ do_clone_range(unsigned offset, unsigned length, unsigned dest) } #endif +#ifdef FIDEDUPERANGE +void +do_dedupe_range(unsigned offset, unsigned length, unsigned dest) +{ + struct file_dedupe_range *fdr; + + if (length == 0) { + if (!quiet && testcalls > simulatedopcount) + prt("skipping zero length dedupe range\n"); + log5(OP_DEDUPE_RANGE, offset, length, dest, FL_SKIPPED); + return; + } + + if ((loff_t)offset >= file_size) { + if (!quiet && testcalls > simulatedopcount) + prt("skipping dedupe range behind EOF\n"); + log5(OP_DEDUPE_RANGE, offset, length, dest, FL_SKIPPED); + return; + } + + log5(OP_DEDUPE_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 dedupe\tfrom 0x%x to 0x%x, (0x%x bytes) at 0x%x\n", + testcalls, offset, offset+length, length, dest); + } + + /* Alloc memory */ + fdr = malloc(sizeof(struct file_dedupe_range_info) + + sizeof(struct file_dedupe_range)); + if (!fdr) { + prterr("do_dedupe_range: malloc"); + report_failure(161); + } + memset(fdr, 0, (sizeof(struct file_dedupe_range_info) + + sizeof(struct file_dedupe_range))); + + /* Dedupe data blocks */ + fdr->src_offset = offset; + fdr->src_length = length; + fdr->dest_count = 1; + fdr->info[0].dest_fd = fd; + fdr->info[0].dest_offset = dest; + + if (ioctl(fd, FIDEDUPERANGE, fdr) == -1) { + if (errno == EOPNOTSUPP || errno == ENOTTY) { + if (!quiet && testcalls > simulatedopcount) + prt("skipping unsupported dedupe range\n"); + logptr--; + log5(OP_DEDUPE_RANGE, offset, length, dest, FL_SKIPPED); + free(fdr); + return; + } + + prt("dedupe range: 0x%x to 0x%x at 0x%x\n", offset, + offset + length, dest); + prterr("do_dedupe_range: FIDEDUPERANGE"); + report_failure(161); + } + + free(fdr); +} + +#else +void +do_dedupe_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 @@ -1615,6 +1700,25 @@ test(void) } while (llabs(offset2 - offset) < size || offset2 + size > maxfilelen); break; + case OP_DEDUPE_RANGE: + { + int tries = 0; + + TRIM_OFF_LEN(offset, size, file_size); + offset = offset & ~(block_size - 1); + size = size & ~(block_size - 1); + do { + if (tries++ >= 30) { + size = 0; + break; + } + offset2 = random(); + TRIM_OFF(offset2, file_size); + offset2 = offset2 & ~(block_size - 1); + } while (llabs(offset2 - offset) < size || + offset2 + size > file_size); + break; + } } have_op: @@ -1659,6 +1763,7 @@ test(void) } break; case OP_CLONE_RANGE: + case OP_DEDUPE_RANGE: if (!remap_calls) { log5(op, offset, size, offset2, FL_SKIPPED); goto out; @@ -1742,6 +1847,18 @@ test(void) do_clone_range(offset, size, offset2); break; + case OP_DEDUPE_RANGE: + if (size == 0) { + log5(OP_DEDUPE_RANGE, offset, size, offset2, FL_SKIPPED); + goto out; + } + if (offset2 + size > maxfilelen) { + log5(OP_DEDUPE_RANGE, offset, size, offset2, FL_SKIPPED); + goto out; + } + + do_dedupe_range(offset, size, offset2); + break; case OP_FSYNC: dofsync(); break;