From patchwork Mon May 14 11:13:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Borisov X-Patchwork-Id: 10397969 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 A8A5D60216 for ; Mon, 14 May 2018 11:14:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 993FF29109 for ; Mon, 14 May 2018 11:14:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8D9D72910B; Mon, 14 May 2018 11:14:04 +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.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 3810329109 for ; Mon, 14 May 2018 11:14:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752142AbeENLNk (ORCPT ); Mon, 14 May 2018 07:13:40 -0400 Received: from mx2.suse.de ([195.135.220.15]:41108 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752037AbeENLNk (ORCPT ); Mon, 14 May 2018 07:13:40 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 793F2ADB4 for ; Mon, 14 May 2018 11:13:39 +0000 (UTC) From: Nikolay Borisov To: linux-btrfs@vger.kernel.org Cc: Nikolay Borisov Subject: [PATCH 1/9] btrfs-progs: btrfs-corrupt-block: Factor out specific-root code Date: Mon, 14 May 2018 14:13:26 +0300 Message-Id: <1526296414-27638-2-git-send-email-nborisov@suse.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1526296414-27638-1-git-send-email-nborisov@suse.com> References: <1526296414-27638-1-git-send-email-nborisov@suse.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 Some options operate on a specific root so let's extract the code which deals with this. No functional change. Signed-off-by: Nikolay Borisov --- btrfs-corrupt-block.c | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/btrfs-corrupt-block.c b/btrfs-corrupt-block.c index da0ec8c51e5a..ab6ca0a1e90a 100644 --- a/btrfs-corrupt-block.c +++ b/btrfs-corrupt-block.c @@ -1080,6 +1080,26 @@ static int find_chunk_offset(struct btrfs_root *root, return ret; } + +static struct btrfs_root *open_root(struct btrfs_fs_info *fs_info, + u64 root_objectid) +{ + + struct btrfs_key root_key; + struct btrfs_root *root; + + root_key.objectid = root_objectid; + root_key.type = BTRFS_ROOT_ITEM_KEY; + root_key.offset = (u64)-1; + + root = btrfs_read_fs_root(fs_info, &root_key); + if (IS_ERR(root)) { + fprintf(stderr, "Couldn't find root %llu\n", root_objectid); + print_usage(1); + } + + return root; +} int main(int argc, char **argv) { struct cache_tree root_cache; @@ -1326,20 +1346,9 @@ int main(int argc, char **argv) if (!key.objectid) print_usage(1); - if (root_objectid) { - struct btrfs_key root_key; - - root_key.objectid = root_objectid; - root_key.type = BTRFS_ROOT_ITEM_KEY; - root_key.offset = (u64)-1; - - target = btrfs_read_fs_root(root->fs_info, &root_key); - if (IS_ERR(target)) { - fprintf(stderr, "Couldn't find root %llu\n", - (unsigned long long)root_objectid); - print_usage(1); - } - } + if (root_objectid) + target = open_root(root->fs_info, root_objectid); + ret = delete_item(target, &key); goto out_close; }