From patchwork Wed May 2 05:15:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timofey Titovets X-Patchwork-Id: 10374937 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 CEF2C6037D for ; Wed, 2 May 2018 05:15:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF38F28A43 for ; Wed, 2 May 2018 05:15:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B3BB128A9C; Wed, 2 May 2018 05:15:57 +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=-7.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, MAILING_LIST_MULTI, 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 5205728B0A for ; Wed, 2 May 2018 05:15:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751055AbeEBFPx (ORCPT ); Wed, 2 May 2018 01:15:53 -0400 Received: from mail-lf0-f65.google.com ([209.85.215.65]:39731 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750932AbeEBFPv (ORCPT ); Wed, 2 May 2018 01:15:51 -0400 Received: by mail-lf0-f65.google.com with SMTP id j193-v6so18981123lfg.6 for ; Tue, 01 May 2018 22:15:51 -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:in-reply-to:references; bh=f/4pI4vMlUcT+AdAg7bWdE12Q4FgWZPbdETI5Gcto4Y=; b=OZmu/b3wgpyb2OhrMHrhddvBbizeugqJXij/2AJVLTLIlOvjHqtghILaTyMxKsuSUH 2F/Az5iL/OVKlVnqR+s+67xl0uodK8gcNR/osvN76ZxC1YHrJsEGOGPnkPu7V2e6N1gt r+eelnzkCN9Gr6UCwwVPCg3MVUP7Ort8Dv7Secn7+1CCJS2VlV5Nla+nIsVfoZAIcKGG EffndfjsM87fkUPKKcKWgRT6hu4JfzfQQ5HlmBZoKHHxlQcMw9ZvBWPY0/badppcKJBg GB+cIlJqJvD4G9sF0fnpWFIEsVmZm7jQKEPQUd4ZdhyR6t5uPgY/m5/fAu2m7R18bT3U 4aNA== 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:in-reply-to :references; bh=f/4pI4vMlUcT+AdAg7bWdE12Q4FgWZPbdETI5Gcto4Y=; b=H3yZYfZYOiMnyIMcZsFoqCBUs5IounfNGt5Ss+lMX1Psi1BDJpcLEncVl5ltw4+Mg9 Q3i1oG8mE8/ilB44YtIa1n39SLsM/0p5NQUEIDTyaXBTPIvg0R5UB7NzYc8v+G40bkqK 1npErpgRXwhlRj6yZH5Mk2CPGKMtn4tASFGLCGklXX6wkThCN6o0cAAa7AIFSC2YKWqZ ak3QAdoW0RNe5671oBlYMt9DhvqDhL7bcqolS30/ebtd+0sjPYsQ3GILINu+uMkxm4zt ISS6x5ai1bDUxByB2MLWE1YTCH+Fen31z3EGuTGOAXkBPiufbGGHleRn3em2zqdM4nT/ Ju1g== X-Gm-Message-State: ALQs6tDxPd+TyVJhR9c0bDPNBqtos9OOUV9Dipljf6ntYq0EpP+DYN91 KndnBZDqVJ/mptPlMI/VSBusjw== X-Google-Smtp-Source: AB8JxZoecMB4XxQdThF0YNt6xtLMy29EUQPGB1z/iny1Q8hY3I+JnhLNrW4PMWhKtno+DrCVIMTGmA== X-Received: by 2002:a2e:888b:: with SMTP id k11-v6mr10418311lji.54.1525238150009; Tue, 01 May 2018 22:15:50 -0700 (PDT) Received: from TitovetsT.synesis.local ([86.57.155.118]) by smtp.gmail.com with ESMTPSA id w79-v6sm2274187lfi.49.2018.05.01.22.15.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 May 2018 22:15:49 -0700 (PDT) From: Timofey Titovets To: linux-btrfs@vger.kernel.org Cc: Timofey Titovets Subject: [PATCH V3 1/3] Btrfs: split btrfs_extent_same() for simplification Date: Wed, 2 May 2018 08:15:36 +0300 Message-Id: <20180502051538.26432-2-nefelim4ag@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180502051538.26432-1-nefelim4ag@gmail.com> References: <20180502051538.26432-1-nefelim4ag@gmail.com> 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 Split btrfs_extent_same() for simplification and preparation for call several times over target files Move most logic to __btrfs_extent_same() And leave in btrfs_extent_same() things which must happens only once Changes: v3: - Splited from one to 3 patches Signed-off-by: Timofey Titovets --- fs/btrfs/ioctl.c | 64 ++++++++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index f0e62e4f8fe7..fb8beedb0359 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -2882,8 +2882,8 @@ static int extent_same_check_offsets(struct inode *inode, u64 off, u64 *plen, return 0; } -static int btrfs_extent_same(struct inode *src, u64 loff, u64 olen, - struct inode *dst, u64 dst_loff) +static int __btrfs_extent_same(struct inode *src, u64 loff, u64 olen, + struct inode *dst, u64 dst_loff) { int ret; u64 len = olen; @@ -2892,21 +2892,13 @@ static int btrfs_extent_same(struct inode *src, u64 loff, u64 olen, 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); - ret = extent_same_check_offsets(src, loff, &len, olen); if (ret) - goto out_unlock; + return ret; ret = extent_same_check_offsets(dst, dst_loff, &len, olen); if (ret) - goto out_unlock; + return ret; if (same_inode) { /* @@ -2923,32 +2915,21 @@ static int btrfs_extent_same(struct inode *src, u64 loff, u64 olen, * allow an unaligned length so long as it ends at * i_size. */ - if (len != olen) { - ret = -EINVAL; - goto out_unlock; - } + if (len != olen) + return -EINVAL; /* Check for overlapping ranges */ - if (dst_loff + len > loff && dst_loff < loff + len) { - ret = -EINVAL; - goto out_unlock; - } + if (dst_loff + len > loff && dst_loff < loff + len) + return -EINVAL; same_lock_start = min_t(u64, loff, dst_loff); same_lock_len = max_t(u64, loff, dst_loff) + len - same_lock_start; } - /* don't make the dst file partly checksummed */ - if ((BTRFS_I(src)->flags & BTRFS_INODE_NODATASUM) != - (BTRFS_I(dst)->flags & BTRFS_INODE_NODATASUM)) { - ret = -EINVAL; - goto out_unlock; - } - again: ret = btrfs_cmp_data_prepare(src, loff, dst, dst_loff, olen, &cmp); if (ret) - goto out_unlock; + return ret; if (same_inode) ret = lock_extent_range(src, same_lock_start, same_lock_len, @@ -2998,7 +2979,32 @@ static int btrfs_extent_same(struct inode *src, u64 loff, u64 olen, btrfs_double_extent_unlock(src, loff, dst, dst_loff, len); btrfs_cmp_data_free(&cmp); -out_unlock: + + return ret; +} + +static int btrfs_extent_same(struct inode *src, u64 loff, u64 olen, + struct inode *dst, u64 dst_loff) +{ + int ret; + bool same_inode = (src == dst); + + if (olen == 0) + return 0; + + /* don't make the dst file partly checksummed */ + if ((BTRFS_I(src)->flags & BTRFS_INODE_NODATASUM) != + (BTRFS_I(dst)->flags & BTRFS_INODE_NODATASUM)) { + return -EINVAL; + } + + if (same_inode) + inode_lock(src); + else + btrfs_double_inode_lock(src, dst); + + ret = __btrfs_extent_same(src, loff, olen, dst, dst_loff); + if (same_inode) inode_unlock(src); else