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: 9435545 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 B1AF16047D for ; Fri, 18 Nov 2016 00:08:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A2B1D2970A for ; Fri, 18 Nov 2016 00:08:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 967B329720; Fri, 18 Nov 2016 00:08:11 +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 12A642970A for ; Fri, 18 Nov 2016 00:08:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753233AbcKRAIE (ORCPT ); Thu, 17 Nov 2016 19:08:04 -0500 Received: from mail-pg0-f45.google.com ([74.125.83.45]:35106 "EHLO mail-pg0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753058AbcKRAIB (ORCPT ); Thu, 17 Nov 2016 19:08:01 -0500 Received: by mail-pg0-f45.google.com with SMTP id p66so96412112pga.2 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=S8BMv+DIu10oYT8zM2JEIZSiNvVkn0klT/SOd3Tc+UBSqFd1JYJ8w0HWXlRI3NcxXY fVBynw9VBTYKvQXCeWmFeKEoUKWlbwxC5v4jqfk1V0tb2xrZENyLxnrZu8N0BkQiTWtf 9cjN3wpb/gB7bRJ7utRCwsAMTBZsIRXrsx4I7N18+ImQvewBN/uLwb1SFcy3V7p1Plyd /+2gan0zujtZX8JJUDCjlyDg8BAZzIohqfzXp+hbDpyIKACZJlpW8wgyhkHX31edSlr8 tlMlf9+MzLnAAvPYMDBu3PXPhyo/oYRqv/jZXbt2aXHmo3caq0Q26aP76Yz+kKqz/J7K Foug== X-Gm-Message-State: ABUngvdMKzTp5cnrczsQSLlgSKLe5VabAJA9af/fW2GoylNYdIEsUZAKORKSzeMNpBzFJqEa 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-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 just makes the following patch cleaner. Signed-off-by: Omar Sandoval Reviewed-by: Qu Wenruo --- 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 */