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

Commit babbf170 authored by Miao Xie's avatar Miao Xie Committed by Josef Bacik
Browse files

Btrfs: make the snap/subv deletion end more early when the fs is R/O



The snapshot/subvolume deletion might spend lots of time, it would make
the remount task wait for a long time. This patch improve this problem,
we will break the deletion if the fs is remounted to be R/O. It will make
the users happy.

Cc: David Sterba <dsterba@suse.cz>
Signed-off-by: default avatarMiao Xie <miaox@cn.fujitsu.com>
Signed-off-by: default avatarJosef Bacik <jbacik@fusionio.com>
parent dc7f370c
Loading
Loading
Loading
Loading
+12 −0
Original line number Original line Diff line number Diff line
@@ -3318,6 +3318,18 @@ static inline int btrfs_fs_closing(struct btrfs_fs_info *fs_info)
	smp_mb();
	smp_mb();
	return fs_info->closing;
	return fs_info->closing;
}
}

/*
 * If we remount the fs to be R/O or umount the fs, the cleaner needn't do
 * anything except sleeping. This function is used to check the status of
 * the fs.
 */
static inline int btrfs_need_cleaner_sleep(struct btrfs_root *root)
{
	return (root->fs_info->sb->s_flags & MS_RDONLY ||
		btrfs_fs_closing(root->fs_info));
}

static inline void free_fs_info(struct btrfs_fs_info *fs_info)
static inline void free_fs_info(struct btrfs_fs_info *fs_info)
{
{
	kfree(fs_info->balance_ctl);
	kfree(fs_info->balance_ctl);
+2 −13
Original line number Original line Diff line number Diff line
@@ -1673,17 +1673,6 @@ static void end_workqueue_fn(struct btrfs_work *work)
	bio_endio(bio, error);
	bio_endio(bio, error);
}
}


/*
 * If we remount the fs to be R/O or umount the fs, the cleaner needn't do
 * anything except sleeping. This function is used to check the status of
 * the fs.
 */
static inline int need_cleaner_sleep(struct btrfs_root *root)
{
	return (root->fs_info->sb->s_flags & MS_RDONLY ||
		btrfs_fs_closing(root->fs_info));
}

static int cleaner_kthread(void *arg)
static int cleaner_kthread(void *arg)
{
{
	struct btrfs_root *root = arg;
	struct btrfs_root *root = arg;
@@ -1693,7 +1682,7 @@ static int cleaner_kthread(void *arg)
		again = 0;
		again = 0;


		/* Make the cleaner go to sleep early. */
		/* Make the cleaner go to sleep early. */
		if (need_cleaner_sleep(root))
		if (btrfs_need_cleaner_sleep(root))
			goto sleep;
			goto sleep;


		if (!mutex_trylock(&root->fs_info->cleaner_mutex))
		if (!mutex_trylock(&root->fs_info->cleaner_mutex))
@@ -1703,7 +1692,7 @@ static int cleaner_kthread(void *arg)
		 * Avoid the problem that we change the status of the fs
		 * Avoid the problem that we change the status of the fs
		 * during the above check and trylock.
		 * during the above check and trylock.
		 */
		 */
		if (need_cleaner_sleep(root)) {
		if (btrfs_need_cleaner_sleep(root)) {
			mutex_unlock(&root->fs_info->cleaner_mutex);
			mutex_unlock(&root->fs_info->cleaner_mutex);
			goto sleep;
			goto sleep;
		}
		}
+1 −1
Original line number Original line Diff line number Diff line
@@ -7384,7 +7384,7 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
	wc->reada_count = BTRFS_NODEPTRS_PER_BLOCK(root);
	wc->reada_count = BTRFS_NODEPTRS_PER_BLOCK(root);


	while (1) {
	while (1) {
		if (!for_reloc && btrfs_fs_closing(root->fs_info)) {
		if (!for_reloc && btrfs_need_cleaner_sleep(root)) {
			pr_debug("btrfs: drop snapshot early exit\n");
			pr_debug("btrfs: drop snapshot early exit\n");
			err = -EAGAIN;
			err = -EAGAIN;
			goto out_end_trans;
			goto out_end_trans;