From patchwork Wed May 2 05:15:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timofey Titovets X-Patchwork-Id: 10374939 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 EE0DA60384 for ; Wed, 2 May 2018 05:16:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DE88328A43 for ; Wed, 2 May 2018 05:16:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D38FA28B0A; Wed, 2 May 2018 05:16:00 +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=-7.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 78E5F28A43 for ; Wed, 2 May 2018 05:16:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751074AbeEBFP5 (ORCPT ); Wed, 2 May 2018 01:15:57 -0400 Received: from mail-lf0-f68.google.com ([209.85.215.68]:43557 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750954AbeEBFPw (ORCPT ); Wed, 2 May 2018 01:15:52 -0400 Received: by mail-lf0-f68.google.com with SMTP id g12-v6so18975891lfb.10 for ; Tue, 01 May 2018 22:15:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=WoO2tCdAFZuM8971ZZuIOK89+vN6XoVxvu7E9NsBbKc=; b=t58Lnso0xCQZkB0itmecOHSRjasfYMehhQYhtACXqeTTAMA/UGZxUym38dHNS7B4fS 5s443iqBDNGQ7bIXJw6XThrhLj2joDWoiK5DGLDwwQM4+AN5EMuvvVlgN5uojR1uh+Nf 8IV3TsV+B2E57aYMwkig7QpHPp38LUxmBLbcWY21uF0D/09USiA0eErWlxeH+vqK+UCY l9xou/q6TIBuAJI5dSBqxik8DfdNjwRh2nYO9y9nsuKsNTPl/1zQFD2dYEO+FUuJLWki ap3JlhJh0HNzqPokyrDqG3diT8G8dJ8pzuBy6/R2Ov6gfNummNtpzzpylYVSRfxbC2PL 07lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=WoO2tCdAFZuM8971ZZuIOK89+vN6XoVxvu7E9NsBbKc=; b=b8TB8A/q4LAbRii5W4rfPEK766d1lZZuk4Gui9grEkQc4QTT6buaKex9WG91l8LaWe 7ZnjQEsBwQUflBEi+W+2AixMBzEXJKh2Wg4qurGc6qyYUlOuylCuVKRFDEjB+t1gy4s9 ZGsQiEVYblQw7ll4wMuBX99yeaK5ine31pBnWEJ2T25P2pN+Cro7K6PVuHTpbe/BQitS 00tFFEMcBeahBOKlK1fvqwHnidlS36W9scBmeQt46OHfIfUpFJ8Nl7MjqfXK5XEkAIMG UAO35jruhd2qKuXwZUT85+T8vLrTclkmX26LFzKi50XoPlwxQmGDBF2oxEeBVk32K37W hv4g== X-Gm-Message-State: ALQs6tAxivbp97gVXHIGO3Dc84vNMHky7RWWrrt1W4LXj6bQxpG8lNE5 +dftv94iTuHlSXNFokHn3wiJ2w== X-Google-Smtp-Source: AB8JxZrCaxUXQm0wC3XDi9AWi/NUpqWusF30Yox8LM5288FTRwAoRlY9gpyEMhDdKCGg5gsEZZho1w== X-Received: by 2002:a2e:82d6:: with SMTP id n22-v6mr11831176ljh.142.1525238151040; Tue, 01 May 2018 22:15:51 -0700 (PDT) Received: from TitovetsT.synesis.local ([86.57.155.118]) by smtp.gmail.com with ESMTPSA id w79-v6sm2274187lfi.49.2018.05.01.22.15.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 May 2018 22:15:50 -0700 (PDT) From: Timofey Titovets To: linux-btrfs@vger.kernel.org Cc: Timofey Titovets Subject: [PATCH V3 2/3] Btrfs: btrfs_dedupe_file_range() ioctl, remove 16MiB restriction Date: Wed, 2 May 2018 08:15:37 +0300 Message-Id: <20180502051538.26432-3-nefelim4ag@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180502051538.26432-1-nefelim4ag@gmail.com> References: <20180502051538.26432-1-nefelim4ag@gmail.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP At now btrfs_dedupe_file_range() restricted to 16MiB range for limit locking time and memory requirement for dedup ioctl() For too big input range code silently set range to 16MiB Let's remove that restriction by do iterating over dedup range. That's backward compatible and will not change anything for request less then 16MiB. Changes: v3: - Splited from one to 3 patches Signed-off-by: Timofey Titovets --- fs/btrfs/ioctl.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index fb8beedb0359..38ce990e9b4c 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -2983,11 +2983,14 @@ static int __btrfs_extent_same(struct inode *src, u64 loff, u64 olen, return ret; } +#define BTRFS_MAX_DEDUPE_LEN SZ_16M + static int btrfs_extent_same(struct inode *src, u64 loff, u64 olen, struct inode *dst, u64 dst_loff) { int ret; bool same_inode = (src == dst); + u64 i, tail_len, chunk_count; if (olen == 0) return 0; @@ -2998,13 +3001,28 @@ static int btrfs_extent_same(struct inode *src, u64 loff, u64 olen, return -EINVAL; } + tail_len = olen % BTRFS_MAX_DEDUPE_LEN; + chunk_count = div_u64(olen, BTRFS_MAX_DEDUPE_LEN); + if (same_inode) inode_lock(src); else btrfs_double_inode_lock(src, dst); - ret = __btrfs_extent_same(src, loff, olen, dst, dst_loff); + for (i = 0; i < chunk_count; i++) { + ret = __btrfs_extent_same(src, loff, BTRFS_MAX_DEDUPE_LEN, + dst, dst_loff); + if (ret) + goto out; + + loff += BTRFS_MAX_DEDUPE_LEN; + dst_loff += BTRFS_MAX_DEDUPE_LEN; + } + + if (tail_len > 0) + ret = __btrfs_extent_same(src, loff, tail_len, dst, dst_loff); +out: if (same_inode) inode_unlock(src); else @@ -3013,8 +3031,6 @@ static int btrfs_extent_same(struct inode *src, u64 loff, u64 olen, return ret; } -#define BTRFS_MAX_DEDUPE_LEN SZ_16M - ssize_t btrfs_dedupe_file_range(struct file *src_file, u64 loff, u64 olen, struct file *dst_file, u64 dst_loff) { @@ -3023,9 +3039,6 @@ ssize_t btrfs_dedupe_file_range(struct file *src_file, u64 loff, u64 olen, u64 bs = BTRFS_I(src)->root->fs_info->sb->s_blocksize; ssize_t res; - if (olen > BTRFS_MAX_DEDUPE_LEN) - olen = BTRFS_MAX_DEDUPE_LEN; - if (WARN_ON_ONCE(bs < PAGE_SIZE)) { /* * Btrfs does not support blocksize < page_size. As a