From patchwork Wed Oct 15 23:14:21 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zach Brown X-Patchwork-Id: 5087471 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D6350C11AC for ; Wed, 15 Oct 2014 23:15:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DEEAB20136 for ; Wed, 15 Oct 2014 23:14:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id ECDCA2012E for ; Wed, 15 Oct 2014 23:14:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750809AbaJOXOz (ORCPT ); Wed, 15 Oct 2014 19:14:55 -0400 Received: from mail-wi0-f170.google.com ([209.85.212.170]:36644 "EHLO mail-wi0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751178AbaJOXOx (ORCPT ); Wed, 15 Oct 2014 19:14:53 -0400 Received: by mail-wi0-f170.google.com with SMTP id hi2so42283wib.3 for ; Wed, 15 Oct 2014 16:14:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=EFRnEAHpDIsF+Jd3DQbUL2I/SdYlF120UtNSLrtXD1M=; b=HPWXeRo3inF9GCZg+9KkMtj3/Y2IPssDQ5U/HiDsM3AlzQbRSZxlNi+Av1c5PUhSfd PIpeSc6Y/OKHQ2L0cUIxJav3Jt76p14k6qSG3HqrJjFO7zttcPT7i0V2ZNrTSEZk8ChH 5NeeMO0YGlOpDryjGb8mjduaQukyXml9+15mXiKrdq3IPJ70VlJihPEXpTnqECMTzy0n LvuyquqWGyuNndpESBwdiAraPIrxWvEWlbCPllqGapUSPFmmDaInJAzgOeLxEq/PdLSb TEStRNC2fCWV0SWtkud6FO6chObxn0TUA1qyw/Wm8pzjCegWR2V3ZOhRJcbmDA3X7BZm 2jKA== X-Gm-Message-State: ALoCoQn6iBQnnxSXzCCdFZiXQxofbHqOZ4N1pQNsIycIdRlf2c6PCEhbqt3O51KiYyL06lu/aQKK X-Received: by 10.194.119.72 with SMTP id ks8mr15326554wjb.75.1413414892145; Wed, 15 Oct 2014 16:14:52 -0700 (PDT) Received: from lenny.home.zabbo.net (tetsuo.zabbo.net. [50.193.208.193]) by mx.google.com with ESMTPSA id o1sm25390716wja.25.2014.10.15.16.14.50 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Oct 2014 16:14:51 -0700 (PDT) From: Zach Brown To: linux-btrfs@vger.kernel.org, David Sterba Subject: [PATCH 4/4] btrfs-progs: fix csum root copy-n-paste error Date: Wed, 15 Oct 2014 16:14:21 -0700 Message-Id: <1413414861-28097-5-git-send-email-zab@zabbo.net> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1413414861-28097-1-git-send-email-zab@zabbo.net> References: <1413414861-28097-1-git-send-email-zab@zabbo.net> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-5.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY, URIBL_WS_SURBL autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP btrfs_setup_all_roots() had some copy and pasted code for trying to setup a root and then creating a blank node if that failed. The copy for the csum_root created the blank node in the extent_root. So we create a function to use a consistent root. Signed-off-by: Zach Brown --- disk-io.c | 66 ++++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 36 insertions(+), 30 deletions(-) diff --git a/disk-io.c b/disk-io.c index f9dbc85..b89bb29 100644 --- a/disk-io.c +++ b/disk-io.c @@ -831,6 +831,34 @@ static int find_best_backup_root(struct btrfs_super_block *super) return best_index; } +static int setup_root_or_create_block(struct btrfs_fs_info *fs_info, + enum btrfs_open_ctree_flags flags, + struct btrfs_root *info_root, + u64 objectid, char *str) +{ + struct btrfs_super_block *sb = fs_info->super_copy; + struct btrfs_root *root = fs_info->tree_root; + u32 leafsize = btrfs_super_leafsize(sb); + int ret; + + ret = find_and_setup_root(root, fs_info, objectid, info_root); + if (ret) { + printk("Couldn't setup %s tree\n", str); + if (!(flags & OPEN_CTREE_PARTIAL)) + return -EIO; + /* Need a blank node here just so we don't screw up in the + * million of places that assume a root has a valid ->node + */ + info_root->node = + btrfs_find_create_tree_block(info_root, 0, leafsize); + if (!info_root->node) + return -ENOMEM; + clear_extent_buffer_uptodate(NULL, info_root->node); + } + + return 0; +} + int btrfs_setup_all_roots(struct btrfs_fs_info *fs_info, u64 root_tree_bytenr, enum btrfs_open_ctree_flags flags) { @@ -877,22 +905,10 @@ int btrfs_setup_all_roots(struct btrfs_fs_info *fs_info, u64 root_tree_bytenr, return -EIO; } - ret = find_and_setup_root(root, fs_info, BTRFS_EXTENT_TREE_OBJECTID, - fs_info->extent_root); - if (ret) { - printk("Couldn't setup extent tree\n"); - if (!(flags & OPEN_CTREE_PARTIAL)) - return -EIO; - /* Need a blank node here just so we don't screw up in the - * million of places that assume a root has a valid ->node - */ - fs_info->extent_root->node = - btrfs_find_create_tree_block(fs_info->extent_root, 0, - leafsize); - if (!fs_info->extent_root->node) - return -ENOMEM; - clear_extent_buffer_uptodate(NULL, fs_info->extent_root->node); - } + ret = setup_root_or_create_block(fs_info, flags, fs_info->extent_root, + BTRFS_EXTENT_TREE_OBJECTID, "extent"); + if (ret) + return ret; fs_info->extent_root->track_dirty = 1; ret = find_and_setup_root(root, fs_info, BTRFS_DEV_TREE_OBJECTID, @@ -903,20 +919,10 @@ int btrfs_setup_all_roots(struct btrfs_fs_info *fs_info, u64 root_tree_bytenr, } fs_info->dev_root->track_dirty = 1; - ret = find_and_setup_root(root, fs_info, BTRFS_CSUM_TREE_OBJECTID, - fs_info->csum_root); - if (ret) { - printk("Couldn't setup csum tree\n"); - if (!(flags & OPEN_CTREE_PARTIAL)) - return -EIO; - /* do the same thing as extent tree rebuilding */ - fs_info->csum_root->node = - btrfs_find_create_tree_block(fs_info->extent_root, 0, - leafsize); - if (!fs_info->csum_root->node) - return -ENOMEM; - clear_extent_buffer_uptodate(NULL, fs_info->csum_root->node); - } + ret = setup_root_or_create_block(fs_info, flags, fs_info->csum_root, + BTRFS_CSUM_TREE_OBJECTID, "csum"); + if (ret) + return ret; fs_info->csum_root->track_dirty = 1; ret = find_and_setup_root(root, fs_info, BTRFS_QUOTA_TREE_OBJECTID,