From patchwork Tue Oct 3 15:06:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timofey Titovets X-Patchwork-Id: 9983033 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 22FAD60375 for ; Tue, 3 Oct 2017 15:07:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1478C28801 for ; Tue, 3 Oct 2017 15:07:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0936928806; Tue, 3 Oct 2017 15:07:20 +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.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, 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 78EAA287D2 for ; Tue, 3 Oct 2017 15:07:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752179AbdJCPHQ (ORCPT ); Tue, 3 Oct 2017 11:07:16 -0400 Received: from mail-lf0-f67.google.com ([209.85.215.67]:50641 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752169AbdJCPHJ (ORCPT ); Tue, 3 Oct 2017 11:07:09 -0400 Received: by mail-lf0-f67.google.com with SMTP id a132so1956134lfa.7 for ; Tue, 03 Oct 2017 08:07:09 -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=9oACmPqAJ8l3H17ltG6H3kEE5ef2fwWen61NgddEyaM=; b=r9Kk8JbH6pCfEBr8zpPWvLpiaRNtFwmuB74v2uw/cKT2iLcMYU5R0OEef7GFq6ET6f DbucIHxoR5RPHex6X8lRutzOx8PM08cvudN8DzgXQuZmVLxD3zhCUGTPmSCF0U8oIUl3 kLUguivarhnKz9YedjJ2hjX3p2msVXNomDSSR46Bc/kPgLuSQk15IjyHi6OnQrIX8m8y VhGGP2NgUbrgOoC1YZPxYYpuMBcUU2si/XjPWUCYu/kI8axs0d4sY3VwcbjRiRxYvg0u gnJsAuSDQbEkgusVHQUFBQpyxGEvYB2in0Mj9dOXzmYWAt8L6MJTpOXA1nC34QoD1IYQ sUFg== 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=9oACmPqAJ8l3H17ltG6H3kEE5ef2fwWen61NgddEyaM=; b=G/n/lXGcSnjH3DRn4lQ+OYInJlbrw7Tjc1Os3PhBL5U2Rs8OjeB03l58Zc3rsmJ+js /s9jdTn7Oxm666Qfya+xwY4VD3O8xOWSJGVZx2sFa/lNMxK1jiKb340qb37z6YStT5r7 /L9nCIyfKxNWY/xfSp0iS119VJSW9uQZ4UDdwCYj+J4bOOUouJeRwtLubNdj2ApUiW+f Qs97KHm3iRW+wYnS0mc0yzRpwZWjWl+7E54hy7x8FSbfOPngL+UI8pHvksYV8GEpG21N QldKEO2qSZQ77gmCgYj+KCmdsKv8ouy69WXOONLPWuLbn8QjfU66jDJTiUeLVqOgeYhA pUJw== X-Gm-Message-State: AHPjjUj3sTmebbHAbVge8CgxWJOmRwESm7GLrtHZkif5drphTFNa5TiS 60qKsbAtyNGK9rg+yqH4BYPsQA== X-Google-Smtp-Source: AOwi7QD+6O0Y5G0ykUJMPgvXWSkwdWzS5icXcf04PXRXawuTVuORZ3Rplx0/GD3HUyW+5XuEtjA0lg== X-Received: by 10.25.198.66 with SMTP id w63mr5229213lff.182.1507043228164; Tue, 03 Oct 2017 08:07:08 -0700 (PDT) Received: from titovetst-l.itransition.corp ([93.171.6.182]) by smtp.gmail.com with ESMTPSA id t20sm2938498ljb.91.2017.10.03.08.07.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 Oct 2017 08:07:07 -0700 (PDT) From: Timofey Titovets To: linux-btrfs@vger.kernel.org Cc: Timofey Titovets Subject: [PATCH 4/4] Btrfs: btrfs_dedupe_file_range() ioctl, remove 16MiB restriction Date: Tue, 3 Oct 2017 18:06:04 +0300 Message-Id: <20171003150604.19596-5-nefelim4ag@gmail.com> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171003150604.19596-1-nefelim4ag@gmail.com> References: <20171003150604.19596-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 rage 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. Signed-off-by: Timofey Titovets Reviewed-by: Qu Wenruo --- fs/btrfs/ioctl.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) -- 2.14.2 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" 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/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 31407c62da63..4b468e5dfa11 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -3200,11 +3200,9 @@ ssize_t btrfs_dedupe_file_range(struct file *src_file, u64 loff, u64 olen, struct inode *src = file_inode(src_file); struct inode *dst = file_inode(dst_file); u64 bs = BTRFS_I(src)->root->fs_info->sb->s_blocksize; + u64 i, tail_len, chunk_count; 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 @@ -3214,7 +3212,23 @@ ssize_t btrfs_dedupe_file_range(struct file *src_file, u64 loff, u64 olen, return -EINVAL; } - res = btrfs_extent_same(src, loff, olen, dst, dst_loff); + tail_len = olen % BTRFS_MAX_DEDUPE_LEN; + chunk_count = div_u64(olen, BTRFS_MAX_DEDUPE_LEN); + + for (i = 0; i < chunk_count; i++) { + res = btrfs_extent_same(src, loff, BTRFS_MAX_DEDUPE_LEN, + dst, dst_loff); + if (res) + return res; + + loff += BTRFS_MAX_DEDUPE_LEN; + dst_loff += BTRFS_MAX_DEDUPE_LEN; + } + + if (tail_len > 0) + res = btrfs_extent_same(src, loff, tail_len, + dst, dst_loff); + if (res) return res; return olen;