From patchwork Wed Jan 18 07:37:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 9522839 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 69D256043A for ; Wed, 18 Jan 2017 07:38:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5716928438 for ; Wed, 18 Jan 2017 07:38:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 495AA28534; Wed, 18 Jan 2017 07:38:22 +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_SIGNED, 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 BD46628438 for ; Wed, 18 Jan 2017 07:38:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751342AbdARHiJ (ORCPT ); Wed, 18 Jan 2017 02:38:09 -0500 Received: from mail-pf0-f171.google.com ([209.85.192.171]:36042 "EHLO mail-pf0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751323AbdARHiI (ORCPT ); Wed, 18 Jan 2017 02:38:08 -0500 Received: by mail-pf0-f171.google.com with SMTP id 189so2319762pfu.3 for ; Tue, 17 Jan 2017 23:38:08 -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; bh=o0N0Az9gFoi05XjM+O753F+Yc2u5tBFXNeyJp8/QEGA=; b=htYTzSTqOoHODVRgwMfZfGHb+EQKJOuPOuFphLrzANwe0WzJB3AlTbo/CbizRTQgC2 rmqesb+4ZJK2nEgLAxTY0xut3ZJc8rLLi+GJaIsH28wn8zhOMf82PpQVqe5jieHNFbWr O2hjW9igSrSy8DNDYgJ4KTxwnWwNSZCZNjzVmteEOOvsrPjkrGjzttMxBqN0s+R8fEc6 RztW2G5g7r/1XnjuGk1HMikPzqzNtgDlrZPs0ZB5kzzZ4tOJPduzExN58X/Pr9U9NRIo 0sr1dg6a/htmDnxHqEZDiwRUpAd3vU3CDRtWW/nuOrXo/7IBRMJbXxczcUUjHjvqi0dT pGaw== 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=o0N0Az9gFoi05XjM+O753F+Yc2u5tBFXNeyJp8/QEGA=; b=VH8npkGlRxwSkShtDsiT5wIY3GFmthuAdgXX/iGHMVhcIJZd+FmBfkWQ2rcRNKWaPa B3TvTV3WYLoitZY1yTD92Rvph3dM9CFWxr1VlcUNPSsDPKaneRl1wsT0v0B3Wrdv1XBO aVKWGAXS8lL08WyLiEESRQLMyIUx+wkjxWkh50An1/sm7h6TjSxurVi59sGge+sAvsV3 LyjTX0OUrUWD0q6mqMyawrbQqKfwyF4ysvokxgg57cjhWLpqeN3SrVSPewcHjUYayZmP +2XbMXf/UgKVq4/nbMw/wxAXjIHWLB/aHAz3mi3L3Now8pC9KNb+UvT84SCuUHAtMMEm k2SQ== X-Gm-Message-State: AIkVDXJzw+uYFtDP19GU+v0T5E+dNkObzY+IRScP4rtVjgwru0QeHYiCKpSvIOUeoQNa/xJX X-Received: by 10.84.196.131 with SMTP id l3mr1295666pld.150.1484725087685; Tue, 17 Jan 2017 23:38:07 -0800 (PST) Received: from localhost.localdomain (50-233-49-230-static.hfc.comcastbusiness.net. [50.233.49.230]) by smtp.gmail.com with ESMTPSA id o24sm60969679pfj.78.2017.01.17.23.38.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Jan 2017 23:38:07 -0800 (PST) From: Omar Sandoval To: linux-btrfs@vger.kernel.org, David Sterba , Chris Mason , Josef Bacik Cc: kernel-team@fb.com Subject: [PATCH] Btrfs: refactor btrfs_extent_same() slightly Date: Tue, 17 Jan 2017 23:37:38 -0800 Message-Id: <0e35cf0b96176e03494585709f5170dff94e1e55.1484724993.git.osandov@fb.com> X-Mailer: git-send-email 2.11.0 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 was originally a prep patch for changing the behavior on len=0, but we went another direction with that. This still makes the function slightly easier to follow. Reviewed-by: Qu Wenruo Signed-off-by: Omar Sandoval Reviewed-by: David Sterba --- Qu thought this would still be a worthwhile cleanup. I'm fine either way. Applies to Dave's for-next branch. fs/btrfs/ioctl.c | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index bf7227d43b5d..3542dddde3d2 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -3127,26 +3127,27 @@ static int btrfs_extent_same(struct inode *src, u64 loff, u64 olen, int ret; u64 len = olen; struct cmp_pages cmp; - int same_inode = 0; + bool same_inode = (src == dst); u64 same_lock_start = 0; u64 same_lock_len = 0; - if (src == dst) - same_inode = 1; - if (len == 0) return 0; - if (same_inode) { + if (same_inode) inode_lock(src); + else + btrfs_double_inode_lock(src, dst); - ret = extent_same_check_offsets(src, loff, &len, olen); - if (ret) - goto out_unlock; - ret = extent_same_check_offsets(src, dst_loff, &len, olen); - if (ret) - goto out_unlock; + ret = extent_same_check_offsets(src, loff, &len, olen); + if (ret) + goto out_unlock; + ret = extent_same_check_offsets(dst, dst_loff, &len, olen); + if (ret) + goto out_unlock; + + if (same_inode) { /* * Single inode case wants the same checks, except we * don't want our length pushed out past i_size as @@ -3174,16 +3175,6 @@ static int btrfs_extent_same(struct inode *src, u64 loff, u64 olen, same_lock_start = min_t(u64, loff, dst_loff); same_lock_len = max_t(u64, loff, dst_loff) + len - same_lock_start; - } else { - btrfs_double_inode_lock(src, dst); - - ret = extent_same_check_offsets(src, loff, &len, olen); - if (ret) - goto out_unlock; - - ret = extent_same_check_offsets(dst, dst_loff, &len, olen); - if (ret) - goto out_unlock; } /* don't make the dst file partly checksummed */