From patchwork Sun Aug 27 20:06:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timofey Titovets X-Patchwork-Id: 9924013 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 61FEF6022E for ; Sun, 27 Aug 2017 20:07:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 437C028632 for ; Sun, 27 Aug 2017 20:07:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 35DC028641; Sun, 27 Aug 2017 20:07:35 +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 C471B28632 for ; Sun, 27 Aug 2017 20:07:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751326AbdH0UGb (ORCPT ); Sun, 27 Aug 2017 16:06:31 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:35775 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751294AbdH0UGa (ORCPT ); Sun, 27 Aug 2017 16:06:30 -0400 Received: by mail-wm0-f66.google.com with SMTP id r187so5074397wma.2 for ; Sun, 27 Aug 2017 13:06:29 -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; bh=NUFS2oWCmdC+BBC09Dek8UZyGUgfFULPq408Y42d9RE=; b=mpRxFaFHpCPtpmls44NG8EWncbzzt7uquG6044fgtYpznx8Fu2sBZf9Cd7NwguFpXv fPfXwkgvfQ3mleU3fbTMduw9y+2x9g7LfHYWOzInIEIUSTOqLV4LeZUz0aCissYLhdZm mZ9hpU1RI5fOshq9Sq44w0NA88foeORQTVorYlO2g1QzfA8XjxozKUyCUGdzQ0sN4qvX VvtgajR6kF7HYhWcFkjH2eNr5DH1OajPjoXKO89OSa38rUzHKmenLVRjralYeVJ/HsHW hJw8wYNSaDlr723Yb+7z/NpSli4EtOVeBwfOnJDczl82yNNbnalrTZAPiTBDmeQGZS2r jAPw== 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; bh=NUFS2oWCmdC+BBC09Dek8UZyGUgfFULPq408Y42d9RE=; b=Zz6CPgHNYDUajDrg8zgO2Cp1B5pXjB/eUTYOFEVv+Cl9ZyP72ip3N1w9cFz6KS2Mcn PBVIertd2I1IaCaROZMkGuDOb2/xyi/yKWtN1kYRt2Xvk+cKQgkJeOMVtBqTWk/G4pzd 5IPa8TE4fjfWyfELAE6YJ1pw6sfiMAekmPoazuR5CdzWdT5Mc/4u57ne3o+0cXDFeW// nSg9ViZdBDzOsqq7u/gdg1S6k+9osM53cabhwjAUQI2/yPvEVMOlg8mnu+P9jwEBjy0m XXH/0XhKGF2BpL732o5fyDRiS+Ent+82NWj2aEsVUIAyXrntbs1ofVGUr/PdLhYNZ7M7 prpg== X-Gm-Message-State: AHYfb5ghX2ADsxzSTF5+VxVxPR6do4dEgZZUJp5dTD4sctqq9InauV1H k2TFtQ4gGkCboPTc X-Received: by 10.28.179.85 with SMTP id c82mr3221923wmf.186.1503864388718; Sun, 27 Aug 2017 13:06:28 -0700 (PDT) Received: from titovetst-l.itransition.corp (nat3-minsk-pool-46-53-180-190.telecom.by. [46.53.180.190]) by smtp.gmail.com with ESMTPSA id 6sm7128459wrn.52.2017.08.27.13.06.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 27 Aug 2017 13:06:27 -0700 (PDT) From: Timofey Titovets To: linux-btrfs@vger.kernel.org Cc: Timofey Titovets Subject: [RFC PATCH] Btrfs: btrfs_dedupe_file_range() ioctl, remove 16MiB restriction Date: Sun, 27 Aug 2017 23:06:16 +0300 Message-Id: <20170827200616.17799-1-nefelim4ag@gmail.com> X-Mailer: git-send-email 2.14.1 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.1 -- 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 ae8fbf9d3de2..7e77d192776f 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -3226,11 +3226,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 @@ -3240,7 +3238,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;