From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35B9DC43603 for ; Fri, 6 Dec 2019 14:46:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 032A621835 for ; Fri, 6 Dec 2019 14:46:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20150623.gappssmtp.com header.i=@toxicpanda-com.20150623.gappssmtp.com header.b="LqLWZwR7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726761AbfLFOq4 (ORCPT ); Fri, 6 Dec 2019 09:46:56 -0500 Received: from mail-qk1-f193.google.com ([209.85.222.193]:42070 "EHLO mail-qk1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726688AbfLFOqz (ORCPT ); Fri, 6 Dec 2019 09:46:55 -0500 Received: by mail-qk1-f193.google.com with SMTP id a10so6643831qko.9 for ; Fri, 06 Dec 2019 06:46:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=WX62XFGdRTFAYg+p96wiK+WMiqaGhA7AxwyBRxGzd6Y=; b=LqLWZwR7MCjxf1lAlb2XsNQeqK6RLKAf6uzdq3vvjudktYf+YSSpOXLKDZZxv2dMWt Fjy79tKhCDMaZ1JIqJTyIXrLNY/5mjvJ0F/LvLxcv6ck/He3CLGLsl7kN1XiYWQJDJ76 lI2tYiPRdZaBJ3+Zz89cgU1XB7Q730waQV94WYdZo/ozOphJ2BJgQFAVinL77N5tA/yH bsMOJ/E0EUjECg8kPWexYDMP7V05N4Q0dK+CNpAY6KS+dFJqxURwmiBXjoHbpnwd1vJ2 kqYssLoI9o/PipXGBCNq5MsDMldIko/X3Qg2Xg5xcTbrqP+siH+U7b3OMTh7Mv95M5G7 Ji4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WX62XFGdRTFAYg+p96wiK+WMiqaGhA7AxwyBRxGzd6Y=; b=ETxHUoCO6l3uabX8hBfPukssBF6wm59u5BhzBEIS7BNwiQtsYREbYwW2Q5th9UFlGQ nUu7TEiH4xSo6pOqumOW0HrMDbcfEf4NRndRayr/rfQJABhmbIaIRfLSkYHLBbrlVY9+ i4wlDedoPgIhOPEVRlSimjknHSMjjL/KcZt9/MsklxzIH/X5JftuYpf4qEemk+CEYdGJ 8kmXs6mmCJWVEjKjRKbUItNiYS8yux4Tjlnuw09C8f8csDol2UOo9O8cyWe/nXJeDZg2 Bimm4qyxo/d0TqJxfJEif5z+pjrEKMjhhla3aDPs3wqjUVPNiO0BVVWKOXvzBCGgD5l1 iY8w== X-Gm-Message-State: APjAAAVa/MPJZzHy+As7FFptv+n3NXFOEV1x1QQ/Q8MtBR9rJQYH8qja vQkADPA9jae0o+C/MP5YCDfBKfsyxmk//A== X-Google-Smtp-Source: APXvYqxckKjVj146KkIaBAsqiKMjSd0JdXypQj6TPr6738Ri+XJRlg6oxFz8M/2juMy6nnngzb7xLQ== X-Received: by 2002:a05:620a:10b8:: with SMTP id h24mr14395345qkk.332.1575643614069; Fri, 06 Dec 2019 06:46:54 -0800 (PST) Received: from localhost ([107.15.81.208]) by smtp.gmail.com with ESMTPSA id d143sm526564qke.123.2019.12.06.06.46.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Dec 2019 06:46:53 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 42/44] btrfs: move fs_info init work into it's own helper function Date: Fri, 6 Dec 2019 09:45:36 -0500 Message-Id: <20191206144538.168112-43-josef@toxicpanda.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191206144538.168112-1-josef@toxicpanda.com> References: <20191206144538.168112-1-josef@toxicpanda.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org open_ctree mixes initialization of fs stuff and fs_info stuff, which makes it confusing when doing things like adding the root leak detection. Make a separate function that init's all the static structures inside of the fs_info needed for the fs to operate, and then call that before we start setting up the fs_info to be mounted. Signed-off-by: Josef Bacik --- fs/btrfs/disk-io.c | 164 +++++++++++++++++++++++---------------------- 1 file changed, 83 insertions(+), 81 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index c7163229effc..6151c828a311 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2649,68 +2649,9 @@ static int __cold init_tree_roots(struct btrfs_fs_info *fs_info) return ret; } -int __cold open_ctree(struct super_block *sb, - struct btrfs_fs_devices *fs_devices, - char *options) +static int init_fs_info(struct btrfs_fs_info *fs_info, struct super_block *sb) { - u32 sectorsize; - u32 nodesize; - u32 stripesize; - u64 generation; - u64 features; - u16 csum_type; - struct btrfs_key location; - struct buffer_head *bh; - struct btrfs_super_block *disk_super; - struct btrfs_fs_info *fs_info = btrfs_sb(sb); - struct btrfs_root *tree_root; - struct btrfs_root *chunk_root; int ret; - int err = -EINVAL; - int clear_free_space_tree = 0; - int level; - - tree_root = fs_info->tree_root = btrfs_alloc_root(fs_info, - BTRFS_ROOT_TREE_OBJECTID, GFP_KERNEL); - chunk_root = fs_info->chunk_root = btrfs_alloc_root(fs_info, - BTRFS_CHUNK_TREE_OBJECTID, GFP_KERNEL); - if (!tree_root || !chunk_root) { - err = -ENOMEM; - goto fail; - } - - ret = init_srcu_struct(&fs_info->subvol_srcu); - if (ret) { - err = ret; - goto fail; - } - - ret = percpu_counter_init(&fs_info->dio_bytes, 0, GFP_KERNEL); - if (ret) { - err = ret; - goto fail_srcu; - } - - ret = percpu_counter_init(&fs_info->dirty_metadata_bytes, 0, GFP_KERNEL); - if (ret) { - err = ret; - goto fail_srcu; - } - fs_info->dirty_metadata_batch = PAGE_SIZE * - (1 + ilog2(nr_cpu_ids)); - - ret = percpu_counter_init(&fs_info->delalloc_bytes, 0, GFP_KERNEL); - if (ret) { - err = ret; - goto fail_srcu; - } - - ret = percpu_counter_init(&fs_info->dev_replace.bio_counter, 0, - GFP_KERNEL); - if (ret) { - err = ret; - goto fail_srcu; - } INIT_RADIX_TREE(&fs_info->fs_roots_radix, GFP_ATOMIC); INIT_RADIX_TREE(&fs_info->buffer_radix, GFP_ATOMIC); @@ -2774,21 +2715,6 @@ int __cold open_ctree(struct super_block *sb, INIT_LIST_HEAD(&fs_info->ordered_roots); spin_lock_init(&fs_info->ordered_root_lock); - fs_info->btree_inode = new_inode(sb); - if (!fs_info->btree_inode) { - err = -ENOMEM; - goto fail_srcu; - } - mapping_set_gfp_mask(fs_info->btree_inode->i_mapping, GFP_NOFS); - - fs_info->delayed_root = kmalloc(sizeof(struct btrfs_delayed_root), - GFP_KERNEL); - if (!fs_info->delayed_root) { - err = -ENOMEM; - goto fail_iput; - } - btrfs_init_delayed_root(fs_info->delayed_root); - btrfs_init_scrub(fs_info); #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY fs_info->check_integrity_print_mask = 0; @@ -2799,8 +2725,6 @@ int __cold open_ctree(struct super_block *sb, sb->s_blocksize = BTRFS_BDEV_BLOCKSIZE; sb->s_blocksize_bits = blksize_bits(BTRFS_BDEV_BLOCKSIZE); - btrfs_init_btree_inode(fs_info); - spin_lock_init(&fs_info->block_group_cache_lock); fs_info->block_group_cache_tree = RB_ROOT; fs_info->first_logical_byte = (u64)-1; @@ -2845,12 +2769,91 @@ int __cold open_ctree(struct super_block *sb, fs_info->send_in_progress = 0; + ret = init_srcu_struct(&fs_info->subvol_srcu); + if (ret) + return ret; + + ret = percpu_counter_init(&fs_info->dio_bytes, 0, GFP_KERNEL); + if (ret) + goto fail; + + ret = percpu_counter_init(&fs_info->dirty_metadata_bytes, 0, GFP_KERNEL); + if (ret) + goto fail; + + fs_info->dirty_metadata_batch = PAGE_SIZE * + (1 + ilog2(nr_cpu_ids)); + + ret = percpu_counter_init(&fs_info->delalloc_bytes, 0, GFP_KERNEL); + if (ret) + goto fail; + + ret = percpu_counter_init(&fs_info->dev_replace.bio_counter, 0, + GFP_KERNEL); + if (ret) + goto fail; + + fs_info->delayed_root = kmalloc(sizeof(struct btrfs_delayed_root), + GFP_KERNEL); + if (!fs_info->delayed_root) { + ret = -ENOMEM; + goto fail; + } + btrfs_init_delayed_root(fs_info->delayed_root); + ret = btrfs_alloc_stripe_hash_table(fs_info); - if (ret) { - err = ret; - goto fail_alloc; + if (ret) + goto fail; + + return 0; +fail: + cleanup_srcu_struct(&fs_info->subvol_srcu); + return ret; +} + +int __cold open_ctree(struct super_block *sb, + struct btrfs_fs_devices *fs_devices, + char *options) +{ + u32 sectorsize; + u32 nodesize; + u32 stripesize; + u64 generation; + u64 features; + u16 csum_type; + struct btrfs_key location; + struct buffer_head *bh; + struct btrfs_super_block *disk_super; + struct btrfs_fs_info *fs_info = btrfs_sb(sb); + struct btrfs_root *tree_root; + struct btrfs_root *chunk_root; + int ret; + int err = -EINVAL; + int clear_free_space_tree = 0; + int level; + + err = init_fs_info(fs_info, sb); + if (err) + goto fail; + + /* These need to be init'ed before we start creating inodes and such. */ + tree_root = fs_info->tree_root = btrfs_alloc_root(fs_info, + BTRFS_ROOT_TREE_OBJECTID, GFP_KERNEL); + chunk_root = fs_info->chunk_root = btrfs_alloc_root(fs_info, + BTRFS_CHUNK_TREE_OBJECTID, GFP_KERNEL); + if (!tree_root || !chunk_root) { + err = -ENOMEM; + goto fail_srcu; } + fs_info->btree_inode = new_inode(sb); + if (!fs_info->btree_inode) { + err = -ENOMEM; + goto fail_srcu; + } + mapping_set_gfp_mask(fs_info->btree_inode->i_mapping, GFP_NOFS); + btrfs_init_btree_inode(fs_info); + invalidate_bdev(fs_devices->latest_bdev); /* @@ -3357,7 +3360,6 @@ int __cold open_ctree(struct super_block *sb, btrfs_stop_all_workers(fs_info); btrfs_free_block_groups(fs_info); fail_alloc: -fail_iput: btrfs_mapping_tree_free(&fs_info->mapping_tree); iput(fs_info->btree_inode); -- 2.23.0