From patchwork Fri Nov 18 00:07:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 9435547 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 E82EC6047D for ; Fri, 18 Nov 2016 00:08:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D953C296F5 for ; Fri, 18 Nov 2016 00:08:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CE3432970A; Fri, 18 Nov 2016 00:08:12 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, 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 6A6802970B for ; Fri, 18 Nov 2016 00:08:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753104AbcKRAIH (ORCPT ); Thu, 17 Nov 2016 19:08:07 -0500 Received: from mail-pg0-f51.google.com ([74.125.83.51]:36363 "EHLO mail-pg0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753087AbcKRAIC (ORCPT ); Thu, 17 Nov 2016 19:08:02 -0500 Received: by mail-pg0-f51.google.com with SMTP id f188so96137243pgc.3 for ; Thu, 17 Nov 2016 16:08:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=NDSlKG/jn8qVjkhbnLKTgInCzX3W3CExofd7B/6z/Ec=; b=QyrWnEsEO4dXhLDuf0QGqhQkbdHa1C+FzN9qWqSt9+6nUJAglFeVE+ivRDr0kKrhAz DFWzT9+dqNPGaBFu1CZMxEs++uV9DXwLc7R+j8uempb+mjhY1diKCvuYzHFWgMXWVMpn 3TcRE/WwHZQ3CcwQupCgmCF1tpFicGTtguhwR9JvzgrJkFd4BBLgsTxCJYl0tFfufmmA VZ37mLBmfR4G80/HNLaiCY6CzULX3WZv6C3nXZF3BT/Om46l/EH4sEgWQCZl+sTHn5Zu 8frf/15bmd8BaA9blcWaowzuzVVT8adLYxXRYsQ971UvEpy02BYsfUWVkoUaEd8EUAbF N5AQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=NDSlKG/jn8qVjkhbnLKTgInCzX3W3CExofd7B/6z/Ec=; b=cMbGOx1H5zbc59OUhpZC0cEcxxSF66XyWaN3Jf3qD6kZNM499DBh8aSXWvXUUJgUOl 6dgBQfNmv0XR4puLBUTAyL4yfJxwFRxeDP/wTQBJHfbSATc/lSmsVHGUeXCzO9AM9K0B 4CUGr/HVwjqO9M/Xw++2NQirPnfKRs+leohBrvvD/pTJe4pCREaRDY8JESEDBv9+frzG D5m48VYX4KSQFMsEMkdbGwq2lpKjQe65xnQj1PVy9OHjmjjU4KAYvE/ICE5FIQkZRdct Qm1HtL5vszO2cTG+Ke9vt/Ho6sYK1Z5Jyg8W1eUpcGnGc3xICHEL7d6C38L70p4jtT9M YkaA== X-Gm-Message-State: ABUngvfmYdYZkvLIhB3yHfM2Sl6RkFpxktrsc/6BGybbNCVh3Ee2jcdKZu45xGBxuATyuKj+ X-Received: by 10.98.58.132 with SMTP id v4mr7807085pfj.7.1479427681783; Thu, 17 Nov 2016 16:08:01 -0800 (PST) Received: from vader.thefacebook.com ([2620:10d:c090:200::8:4aae]) by smtp.gmail.com with ESMTPSA id c128sm11054226pfc.39.2016.11.17.16.08.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Nov 2016 16:08:01 -0800 (PST) From: Omar Sandoval To: linux-btrfs@vger.kernel.org, linux-xfs@vger.kernel.org Cc: "Darrick J. Wong" , Qu Wenruo , Christoph Hellwig , kernel-team@fb.com Subject: [RFC PATCH 2/2] Btrfs: make a source length of 0 imply EOF for dedupe Date: Thu, 17 Nov 2016 16:07:50 -0800 Message-Id: <42687716155fb892c55b56f22a995b39e543f906.1479427384.git.osandov@fb.com> X-Mailer: git-send-email 2.10.2 In-Reply-To: References: In-Reply-To: References: 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 From: Omar Sandoval This makes us consistent with both reflink and the XFS implementation of dedupe. Signed-off-by: Omar Sandoval --- fs/btrfs/ioctl.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index e23f945..320fb35 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -3121,21 +3121,25 @@ static int extent_same_check_offsets(struct inode *inode, u64 off, u64 *plen, static int btrfs_extent_same(struct inode *src, u64 loff, u64 olen, struct inode *dst, u64 dst_loff) { - int ret; - u64 len = olen; + int ret = 0; + u64 len; struct cmp_pages cmp; bool same_inode = (src == dst); u64 same_lock_start = 0; u64 same_lock_len = 0; - if (len == 0) - return 0; - if (same_inode) inode_lock(src); else btrfs_double_inode_lock(src, dst); + if (olen == 0) { + olen = i_size_read(src) - loff; + if (olen == 0) + goto out_unlock; + } + len = olen; + ret = extent_same_check_offsets(src, loff, &len, olen); if (ret) goto out_unlock;