Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit afcdd129 authored by Josef Bacik's avatar Josef Bacik Committed by David Sterba
Browse files

Btrfs: add a flags field to btrfs_fs_info



We have a lot of random ints in btrfs_fs_info that can be put into flags.  This
is mostly equivalent with the exception of how we deal with quota going on or
off, now instead we set a flag when we are turning it on or off and deal with
that appropriately, rather than just having a pending state that the current
quota_enabled gets set to.  Thanks,

Signed-off-by: default avatarJosef Bacik <jbacik@fb.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent ba8b04c1
Loading
Loading
Loading
Loading
+0 −11
Original line number Diff line number Diff line
@@ -44,17 +44,6 @@
#define BTRFS_INODE_IN_DELALLOC_LIST		9
#define BTRFS_INODE_READDIO_NEED_LOCK		10
#define BTRFS_INODE_HAS_PROPS		        11
/*
 * The following 3 bits are meant only for the btree inode.
 * When any of them is set, it means an error happened while writing an
 * extent buffer belonging to:
 * 1) a non-log btree
 * 2) a log btree and first log sub-transaction
 * 3) a log btree and second log sub-transaction
 */
#define BTRFS_INODE_BTREE_ERR		        12
#define BTRFS_INODE_BTREE_LOG1_ERR		13
#define BTRFS_INODE_BTREE_LOG2_ERR		14

/* in memory btrfs inode */
struct btrfs_inode {
+23 −20
Original line number Diff line number Diff line
@@ -677,9 +677,25 @@ struct btrfs_device;
struct btrfs_fs_devices;
struct btrfs_balance_control;
struct btrfs_delayed_root;

#define BTRFS_FS_BARRIER			1
#define BTRFS_FS_CLOSING_START			2
#define BTRFS_FS_CLOSING_DONE			3
#define BTRFS_FS_LOG_RECOVERING			4
#define BTRFS_FS_OPEN				5
#define BTRFS_FS_QUOTA_ENABLED			6
#define BTRFS_FS_QUOTA_ENABLING			7
#define BTRFS_FS_QUOTA_DISABLING		8
#define BTRFS_FS_UPDATE_UUID_TREE_GEN		9
#define BTRFS_FS_CREATING_FREE_SPACE_TREE	10
#define BTRFS_FS_BTREE_ERR			11
#define BTRFS_FS_LOG1_ERR			12
#define BTRFS_FS_LOG2_ERR			13

struct btrfs_fs_info {
	u8 fsid[BTRFS_FSID_SIZE];
	u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
	unsigned long flags;
	struct btrfs_root *extent_root;
	struct btrfs_root *tree_root;
	struct btrfs_root *chunk_root;
@@ -908,10 +924,6 @@ struct btrfs_fs_info {
	int thread_pool_size;

	struct kobject *space_info_kobj;
	int do_barriers;
	int closing;
	int log_root_recovering;
	int open;

	u64 total_pinned;

@@ -988,17 +1000,6 @@ struct btrfs_fs_info {
#ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
	u32 check_integrity_print_mask;
#endif
	/*
	 * quota information
	 */
	unsigned int quota_enabled:1;

	/*
	 * quota_enabled only changes state after a commit. This holds the
	 * next state.
	 */
	unsigned int pending_quota_state:1;

	/* is qgroup tracking in a consistent state? */
	u64 qgroup_flags;

@@ -1062,7 +1063,6 @@ struct btrfs_fs_info {
	wait_queue_head_t replace_wait;

	struct semaphore uuid_tree_rescan_sem;
	unsigned int update_uuid_tree_gen:1;

	/* Used to reclaim the metadata space in the background. */
	struct work_struct async_reclaim_work;
@@ -1081,7 +1081,6 @@ struct btrfs_fs_info {
	 */
	struct list_head pinned_chunks;

	int creating_free_space_tree;
	/* Used to record internally whether fs has been frozen */
	int fs_frozen;
};
@@ -2868,10 +2867,14 @@ int btrfs_drop_subtree(struct btrfs_trans_handle *trans,
static inline int btrfs_fs_closing(struct btrfs_fs_info *fs_info)
{
	/*
	 * Get synced with close_ctree()
	 * Do it this way so we only ever do one test_bit in the normal case.
	 */
	smp_mb();
	return fs_info->closing;
	if (test_bit(BTRFS_FS_CLOSING_START, &fs_info->flags)) {
		if (test_bit(BTRFS_FS_CLOSING_DONE, &fs_info->flags))
			return 2;
		return 1;
	}
	return 0;
}

/*
+2 −1
Original line number Diff line number Diff line
@@ -1874,7 +1874,8 @@ int btrfs_delayed_delete_inode_ref(struct inode *inode)
	 * leads to enospc problems.  This means we also can't do
	 * delayed inode refs
	 */
	if (BTRFS_I(inode)->root->fs_info->log_root_recovering)
	if (test_bit(BTRFS_FS_LOG_RECOVERING,
		     &BTRFS_I(inode)->root->fs_info->flags))
		return -EAGAIN;

	delayed_node = btrfs_get_or_create_delayed_node(inode);
+4 −2
Original line number Diff line number Diff line
@@ -770,7 +770,8 @@ int btrfs_add_delayed_tree_ref(struct btrfs_fs_info *fs_info,
	if (!head_ref)
		goto free_ref;

	if (fs_info->quota_enabled && is_fstree(ref_root)) {
	if (test_bit(BTRFS_FS_QUOTA_ENABLED, &fs_info->flags) &&
	    is_fstree(ref_root)) {
		record = kmalloc(sizeof(*record), GFP_NOFS);
		if (!record)
			goto free_head_ref;
@@ -828,7 +829,8 @@ int btrfs_add_delayed_data_ref(struct btrfs_fs_info *fs_info,
		return -ENOMEM;
	}

	if (fs_info->quota_enabled && is_fstree(ref_root)) {
	if (test_bit(BTRFS_FS_QUOTA_ENABLED, &fs_info->flags) &&
	    is_fstree(ref_root)) {
		record = kmalloc(sizeof(*record), GFP_NOFS);
		if (!record) {
			kmem_cache_free(btrfs_delayed_data_ref_cachep, ref);
+8 −15
Original line number Diff line number Diff line
@@ -1839,7 +1839,7 @@ static int cleaner_kthread(void *arg)
		 * Do not do anything if we might cause open_ctree() to block
		 * before we have finished mounting the filesystem.
		 */
		if (!root->fs_info->open)
		if (!test_bit(BTRFS_FS_OPEN, &root->fs_info->flags))
			goto sleep;

		if (!mutex_trylock(&root->fs_info->cleaner_mutex))
@@ -2332,8 +2332,6 @@ static void btrfs_init_qgroup(struct btrfs_fs_info *fs_info)
	fs_info->qgroup_op_tree = RB_ROOT;
	INIT_LIST_HEAD(&fs_info->dirty_qgroups);
	fs_info->qgroup_seq = 1;
	fs_info->quota_enabled = 0;
	fs_info->pending_quota_state = 0;
	fs_info->qgroup_ulist = NULL;
	fs_info->qgroup_rescan_running = false;
	mutex_init(&fs_info->qgroup_rescan_lock);
@@ -2518,8 +2516,7 @@ static int btrfs_read_roots(struct btrfs_fs_info *fs_info,
	root = btrfs_read_tree_root(tree_root, &location);
	if (!IS_ERR(root)) {
		set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state);
		fs_info->quota_enabled = 1;
		fs_info->pending_quota_state = 1;
		set_bit(BTRFS_FS_QUOTA_ENABLED, &fs_info->flags);
		fs_info->quota_root = root;
	}

@@ -2710,8 +2707,7 @@ int open_ctree(struct super_block *sb,
	extent_io_tree_init(&fs_info->freed_extents[1],
			     fs_info->btree_inode->i_mapping);
	fs_info->pinned_extents = &fs_info->freed_extents[0];
	fs_info->do_barriers = 1;

	set_bit(BTRFS_FS_BARRIER, &fs_info->flags);

	mutex_init(&fs_info->ordered_operations_mutex);
	mutex_init(&fs_info->tree_log_mutex);
@@ -3199,10 +3195,9 @@ int open_ctree(struct super_block *sb,
			return ret;
		}
	} else {
		fs_info->update_uuid_tree_gen = 1;
		set_bit(BTRFS_FS_UPDATE_UUID_TREE_GEN, &fs_info->flags);
	}

	fs_info->open = 1;
	set_bit(BTRFS_FS_OPEN, &fs_info->flags);

	/*
	 * backuproot only affect mount behavior, and if open_ctree succeeded,
@@ -3893,8 +3888,7 @@ void close_ctree(struct btrfs_root *root)
	struct btrfs_fs_info *fs_info = root->fs_info;
	int ret;

	fs_info->closing = 1;
	smp_mb();
	set_bit(BTRFS_FS_CLOSING_START, &fs_info->flags);

	/* wait for the qgroup rescan worker to stop */
	btrfs_qgroup_wait_for_completion(fs_info, false);
@@ -3939,8 +3933,7 @@ void close_ctree(struct btrfs_root *root)
	kthread_stop(fs_info->transaction_kthread);
	kthread_stop(fs_info->cleaner_kthread);

	fs_info->closing = 2;
	smp_mb();
	set_bit(BTRFS_FS_CLOSING_DONE, &fs_info->flags);

	btrfs_free_qgroup_config(fs_info);

@@ -3965,7 +3958,7 @@ void close_ctree(struct btrfs_root *root)
	invalidate_inode_pages2(fs_info->btree_inode->i_mapping);
	btrfs_stop_all_workers(fs_info);

	fs_info->open = 0;
	clear_bit(BTRFS_FS_OPEN, &fs_info->flags);
	free_root_pointers(fs_info, 1);

	iput(fs_info->btree_inode);
Loading