From patchwork Mon May 14 11:13:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Borisov X-Patchwork-Id: 10397963 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 1F85A6038F for ; Mon, 14 May 2018 11:13:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1001229109 for ; Mon, 14 May 2018 11:13:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 048FD2910B; Mon, 14 May 2018 11:13:54 +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 A08ED29109 for ; Mon, 14 May 2018 11:13:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752381AbeENLNw (ORCPT ); Mon, 14 May 2018 07:13:52 -0400 Received: from mx2.suse.de ([195.135.220.15]:41123 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752207AbeENLNm (ORCPT ); Mon, 14 May 2018 07:13:42 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 1390CAD97 for ; Mon, 14 May 2018 11:13:41 +0000 (UTC) From: Nikolay Borisov To: linux-btrfs@vger.kernel.org Cc: Nikolay Borisov Subject: [PATCH 6/9] btrfs-progs: btrfs-corrupt-block: Factor out common "-r" handling code Date: Mon, 14 May 2018 14:13:31 +0300 Message-Id: <1526296414-27638-7-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 Since more and more of the "corrupt XXX" options are going to support combination with -r option, let's extract the common code needed for this. No functional changes. Signed-off-by: Nikolay Borisov --- btrfs-corrupt-block.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/btrfs-corrupt-block.c b/btrfs-corrupt-block.c index 7a5513c455e6..8bbfe1cdb855 100644 --- a/btrfs-corrupt-block.c +++ b/btrfs-corrupt-block.c @@ -1114,7 +1114,7 @@ int main(int argc, char **argv) { struct cache_tree root_cache; struct btrfs_key key; - struct btrfs_root *root; + struct btrfs_root *root, *target_root; char *dev; /* chunk offset can be 0,so change to (u64)-1 */ u64 logical = (u64)-1; @@ -1245,6 +1245,10 @@ int main(int argc, char **argv) fprintf(stderr, "Open ctree failed\n"); exit(1); } + target_root = root; + if (root_objectid) + target_root = open_root(root->fs_info, root_objectid); + if (extent_rec) { struct btrfs_trans_handle *trans; @@ -1342,26 +1346,19 @@ int main(int argc, char **argv) goto out_close; } if (corrupt_item) { - struct btrfs_root *target; if (!key.objectid) print_usage(1); if (!root_objectid) print_usage(1); - target = open_root(root->fs_info, root_objectid); - - ret = corrupt_btrfs_item(target, &key, field); + ret = corrupt_btrfs_item(target_root, &key, field); goto out_close; } if (delete) { - struct btrfs_root *target = root; - if (!key.objectid) print_usage(1); - if (root_objectid) - target = open_root(root->fs_info, root_objectid); - ret = delete_item(target, &key); + ret = delete_item(target_root, &key); goto out_close; } if (should_corrupt_key) {