From patchwork Fri Nov 18 00:07:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 9486431 X-Mozilla-Keys: nonjunk Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on sandeen.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, RP_MATCHES_RCVD, T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.0 X-Spam-HP: BAYES_00=-1.9, DKIM_SIGNED=0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.001, RP_MATCHES_RCVD=-0.1,T_DKIM_INVALID=0.01 X-Original-To: sandeen@sandeen.net Delivered-To: sandeen@sandeen.net Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by sandeen.net (Postfix) with ESMTP id C31086F7BC7 for ; Thu, 17 Nov 2016 18:07:56 -0600 (CST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753229AbcKRAIE (ORCPT ); Thu, 17 Nov 2016 19:08:04 -0500 Received: from mail-pf0-f178.google.com ([209.85.192.178]:32998 "EHLO mail-pf0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753050AbcKRAIB (ORCPT ); Thu, 17 Nov 2016 19:08:01 -0500 Received: by mail-pf0-f178.google.com with SMTP id d2so51369633pfd.0 for ; Thu, 17 Nov 2016 16:08:01 -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=ZDsPYOOi/4Abe2wmReYZ/PkwjJvxbA2R+S7FjvnDYWA=; b=q7ssBLVOz/0ltpq++hxKhbm17aExQSuXdlBG1GFez0ngTvq2YHTGOKRRhyeLHIaw0U vnL45xs6p7Tn1OZBuE5NcLZYcMf5krQfwpcae1oPKjAbS9/qEAop1iG0xqa45ml4KZLA hhXwxfB59xJ0MKsFZQM1uhGZcem9uQatt2URms5zV/sjlkakPH3gBR+A4ldbLgiVClKx 6lVmVvBQYEc3bW30gwLoFx+wOJYPV+xrifLZrM+JAbrTGiWx9YyLwpHM16UPbXjrkDcr D5McLJavnn+ES5axMoGufVhYrRwsL6h9vYTaLElKEJ5Saj/E4KZJxZGEtIBp8klqsvhv WFVg== 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=ZDsPYOOi/4Abe2wmReYZ/PkwjJvxbA2R+S7FjvnDYWA=; b=QiCQ7qCbdTGfqlQuqEL2mzUWSqs2VzWlIbdBXSivOU6obK0m4OgXNqfDlBr6srA+dJ rvmPHEOh/cvRmRr7rrvxQww+lNjP9tTceGmEQDCbF9s0NuDEJASyTO4b+I5oYODr0Obq BV4v0pSAInqqyEGBo6Z881SYwh0hDHxTBhnE6p9UG9y1qf6iGMXXNP3fD2ff2iOkeD0C EWjyTrhCzlHDE1VFulRHsHuJQfBk79pW+/zXwTEBYaxudi/wYw2ryiwIsRm3i/guupbE bC8qliaFyFMf0mW3R6pmRuqfb9j7VJTAkRCkQSefUvcu8BPRKCVpx30wV0DlAsoXaRLC j3fw== X-Gm-Message-State: ABUngveaxWbaU+8w1uR5qCyYGa68gryd41Czhr5U2YYOYLeU5P+mGI3mGKQTNgybDHEWpD6t X-Received: by 10.99.227.81 with SMTP id o17mr12686611pgj.69.1479427680730; Thu, 17 Nov 2016 16:08:00 -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.07.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Nov 2016 16:08:00 -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 1/2] Btrfs: refactor btrfs_extent_same() slightly Date: Thu, 17 Nov 2016 16:07:49 -0800 Message-Id: <35c668f0a23e0424569f812523c76a1828219f76.1479427384.git.osandov@fb.com> X-Mailer: git-send-email 2.10.2 In-Reply-To: References: In-Reply-To: References: Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Omar Sandoval This just makes the following patch cleaner. Signed-off-by: Omar Sandoval --- 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 7acbd2c..e23f945 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -3124,26 +3124,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 @@ -3171,16 +3172,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 */