Commit 07802534 authored by Qu Wenruo's avatar Qu Wenruo Committed by Chris Mason

btrfs: Cleanup the btrfs_parse_options for remount.

Since remount will pending the new mount options to the original mount
options, which will make btrfs_parse_options check the old options then
new options, causing some stupid output like "enabling XXX" following by
"disable XXX".

This patch will add extra check before every btrfs_info to skip the
output from old options checking.
Signed-off-by: default avatarQu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: default avatarJosef Bacik <jbacik@fb.com>
Signed-off-by: default avatarChris Mason <clm@fb.com>
parent 3818aea2
...@@ -383,6 +383,20 @@ static match_table_t tokens = { ...@@ -383,6 +383,20 @@ static match_table_t tokens = {
{Opt_err, NULL}, {Opt_err, NULL},
}; };
#define btrfs_set_and_info(root, opt, fmt, args...) \
{ \
if (!btrfs_test_opt(root, opt)) \
btrfs_info(root->fs_info, fmt, ##args); \
btrfs_set_opt(root->fs_info->mount_opt, opt); \
}
#define btrfs_clear_and_info(root, opt, fmt, args...) \
{ \
if (btrfs_test_opt(root, opt)) \
btrfs_info(root->fs_info, fmt, ##args); \
btrfs_clear_opt(root->fs_info->mount_opt, opt); \
}
/* /*
* Regular mount options parser. Everything that is needed only when * Regular mount options parser. Everything that is needed only when
* reading in a new superblock is parsed here. * reading in a new superblock is parsed here.
...@@ -398,6 +412,7 @@ int btrfs_parse_options(struct btrfs_root *root, char *options) ...@@ -398,6 +412,7 @@ int btrfs_parse_options(struct btrfs_root *root, char *options)
int ret = 0; int ret = 0;
char *compress_type; char *compress_type;
bool compress_force = false; bool compress_force = false;
bool compress = false;
cache_gen = btrfs_super_cache_generation(root->fs_info->super_copy); cache_gen = btrfs_super_cache_generation(root->fs_info->super_copy);
if (cache_gen) if (cache_gen)
...@@ -437,24 +452,28 @@ int btrfs_parse_options(struct btrfs_root *root, char *options) ...@@ -437,24 +452,28 @@ int btrfs_parse_options(struct btrfs_root *root, char *options)
*/ */
break; break;
case Opt_nodatasum: case Opt_nodatasum:
btrfs_info(root->fs_info, "setting nodatasum"); btrfs_set_and_info(root, NODATASUM,
btrfs_set_opt(info->mount_opt, NODATASUM); "setting nodatasum");
break; break;
case Opt_datasum: case Opt_datasum:
if (btrfs_test_opt(root, NODATACOW)) if (btrfs_test_opt(root, NODATASUM)) {
btrfs_info(root->fs_info, "setting datasum, datacow enabled"); if (btrfs_test_opt(root, NODATACOW))
else btrfs_info(root->fs_info, "setting datasum, datacow enabled");
btrfs_info(root->fs_info, "setting datasum"); else
btrfs_info(root->fs_info, "setting datasum");
}
btrfs_clear_opt(info->mount_opt, NODATACOW); btrfs_clear_opt(info->mount_opt, NODATACOW);
btrfs_clear_opt(info->mount_opt, NODATASUM); btrfs_clear_opt(info->mount_opt, NODATASUM);
break; break;
case Opt_nodatacow: case Opt_nodatacow:
if (!btrfs_test_opt(root, COMPRESS) || if (!btrfs_test_opt(root, NODATACOW)) {
!btrfs_test_opt(root, FORCE_COMPRESS)) { if (!btrfs_test_opt(root, COMPRESS) ||
!btrfs_test_opt(root, FORCE_COMPRESS)) {
btrfs_info(root->fs_info, btrfs_info(root->fs_info,
"setting nodatacow, compression disabled"); "setting nodatacow, compression disabled");
} else { } else {
btrfs_info(root->fs_info, "setting nodatacow"); btrfs_info(root->fs_info, "setting nodatacow");
}
} }
btrfs_clear_opt(info->mount_opt, COMPRESS); btrfs_clear_opt(info->mount_opt, COMPRESS);
btrfs_clear_opt(info->mount_opt, FORCE_COMPRESS); btrfs_clear_opt(info->mount_opt, FORCE_COMPRESS);
...@@ -462,9 +481,8 @@ int btrfs_parse_options(struct btrfs_root *root, char *options) ...@@ -462,9 +481,8 @@ int btrfs_parse_options(struct btrfs_root *root, char *options)
btrfs_set_opt(info->mount_opt, NODATASUM); btrfs_set_opt(info->mount_opt, NODATASUM);
break; break;
case Opt_datacow: case Opt_datacow:
if (btrfs_test_opt(root, NODATACOW)) btrfs_clear_and_info(root, NODATACOW,
btrfs_info(root->fs_info, "setting datacow"); "setting datacow");
btrfs_clear_opt(info->mount_opt, NODATACOW);
break; break;
case Opt_compress_force: case Opt_compress_force:
case Opt_compress_force_type: case Opt_compress_force_type:
...@@ -472,6 +490,7 @@ int btrfs_parse_options(struct btrfs_root *root, char *options) ...@@ -472,6 +490,7 @@ int btrfs_parse_options(struct btrfs_root *root, char *options)
/* Fallthrough */ /* Fallthrough */
case Opt_compress: case Opt_compress:
case Opt_compress_type: case Opt_compress_type:
compress = true;
if (token == Opt_compress || if (token == Opt_compress ||
token == Opt_compress_force || token == Opt_compress_force ||
strcmp(args[0].from, "zlib") == 0) { strcmp(args[0].from, "zlib") == 0) {
...@@ -498,37 +517,36 @@ int btrfs_parse_options(struct btrfs_root *root, char *options) ...@@ -498,37 +517,36 @@ int btrfs_parse_options(struct btrfs_root *root, char *options)
} }
if (compress_force) { if (compress_force) {
btrfs_set_opt(info->mount_opt, FORCE_COMPRESS); btrfs_set_and_info(root, FORCE_COMPRESS,
btrfs_info(root->fs_info, "force %s compression", "force %s compression",
compress_type); compress_type);
} else if (btrfs_test_opt(root, COMPRESS)) { } else if (compress) {
pr_info("btrfs: use %s compression\n", if (!btrfs_test_opt(root, COMPRESS))
compress_type); btrfs_info(root->fs_info,
"btrfs: use %s compression\n",
compress_type);
} }
break; break;
case Opt_ssd: case Opt_ssd:
btrfs_info(root->fs_info, "use ssd allocation scheme"); btrfs_set_and_info(root, SSD,
btrfs_set_opt(info->mount_opt, SSD); "use ssd allocation scheme");
break; break;
case Opt_ssd_spread: case Opt_ssd_spread:
btrfs_info(root->fs_info, "use spread ssd allocation scheme"); btrfs_set_and_info(root, SSD_SPREAD,
btrfs_set_opt(info->mount_opt, SSD); "use spread ssd allocation scheme");
btrfs_set_opt(info->mount_opt, SSD_SPREAD);
break; break;
case Opt_nossd: case Opt_nossd:
btrfs_info(root->fs_info, "not using ssd allocation scheme"); btrfs_clear_and_info(root, NOSSD,
btrfs_set_opt(info->mount_opt, NOSSD); "not using ssd allocation scheme");
btrfs_clear_opt(info->mount_opt, SSD); btrfs_clear_opt(info->mount_opt, SSD);
btrfs_clear_opt(info->mount_opt, SSD_SPREAD);
break; break;
case Opt_barrier: case Opt_barrier:
if (btrfs_test_opt(root, NOBARRIER)) btrfs_clear_and_info(root, NOBARRIER,
btrfs_info(root->fs_info, "turning on barriers"); "turning on barriers");
btrfs_clear_opt(info->mount_opt, NOBARRIER);
break; break;
case Opt_nobarrier: case Opt_nobarrier:
btrfs_info(root->fs_info, "turning off barriers"); btrfs_set_and_info(root, NOBARRIER,
btrfs_set_opt(info->mount_opt, NOBARRIER); "turning off barriers");
break; break;
case Opt_thread_pool: case Opt_thread_pool:
ret = match_int(&args[0], &intarg); ret = match_int(&args[0], &intarg);
...@@ -580,22 +598,20 @@ int btrfs_parse_options(struct btrfs_root *root, char *options) ...@@ -580,22 +598,20 @@ int btrfs_parse_options(struct btrfs_root *root, char *options)
root->fs_info->sb->s_flags &= ~MS_POSIXACL; root->fs_info->sb->s_flags &= ~MS_POSIXACL;
break; break;
case Opt_notreelog: case Opt_notreelog:
btrfs_info(root->fs_info, "disabling tree log"); btrfs_set_and_info(root, NOTREELOG,
btrfs_set_opt(info->mount_opt, NOTREELOG); "disabling tree log");
break; break;
case Opt_treelog: case Opt_treelog:
if (btrfs_test_opt(root, NOTREELOG)) btrfs_clear_and_info(root, NOTREELOG,
btrfs_info(root->fs_info, "enabling tree log"); "enabling tree log");
btrfs_clear_opt(info->mount_opt, NOTREELOG);
break; break;
case Opt_flushoncommit: case Opt_flushoncommit:
btrfs_info(root->fs_info, "turning on flush-on-commit"); btrfs_set_and_info(root, FLUSHONCOMMIT,
btrfs_set_opt(info->mount_opt, FLUSHONCOMMIT); "turning on flush-on-commit");
break; break;
case Opt_noflushoncommit: case Opt_noflushoncommit:
if (btrfs_test_opt(root, FLUSHONCOMMIT)) btrfs_clear_and_info(root, FLUSHONCOMMIT,
btrfs_info(root->fs_info, "turning off flush-on-commit"); "turning off flush-on-commit");
btrfs_clear_opt(info->mount_opt, FLUSHONCOMMIT);
break; break;
case Opt_ratio: case Opt_ratio:
ret = match_int(&args[0], &intarg); ret = match_int(&args[0], &intarg);
...@@ -611,33 +627,35 @@ int btrfs_parse_options(struct btrfs_root *root, char *options) ...@@ -611,33 +627,35 @@ int btrfs_parse_options(struct btrfs_root *root, char *options)
} }
break; break;
case Opt_discard: case Opt_discard:
btrfs_set_opt(info->mount_opt, DISCARD); btrfs_set_and_info(root, DISCARD,
"turning on discard");
break; break;
case Opt_nodiscard: case Opt_nodiscard:
btrfs_clear_opt(info->mount_opt, DISCARD); btrfs_clear_and_info(root, DISCARD,
"turning off discard");
break; break;
case Opt_space_cache: case Opt_space_cache:
btrfs_set_opt(info->mount_opt, SPACE_CACHE); btrfs_set_and_info(root, SPACE_CACHE,
"enabling disk space caching");
break; break;
case Opt_rescan_uuid_tree: case Opt_rescan_uuid_tree:
btrfs_set_opt(info->mount_opt, RESCAN_UUID_TREE); btrfs_set_opt(info->mount_opt, RESCAN_UUID_TREE);
break; break;
case Opt_no_space_cache: case Opt_no_space_cache:
btrfs_info(root->fs_info, "disabling disk space caching"); btrfs_clear_and_info(root, SPACE_CACHE,
btrfs_clear_opt(info->mount_opt, SPACE_CACHE); "disabling disk space caching");
break; break;
case Opt_inode_cache: case Opt_inode_cache:
btrfs_info(root->fs_info, "enabling inode map caching"); btrfs_set_and_info(root, CHANGE_INODE_CACHE,
btrfs_set_opt(info->mount_opt, CHANGE_INODE_CACHE); "enabling inode map caching");
break; break;
case Opt_noinode_cache: case Opt_noinode_cache:
if (btrfs_test_opt(root, CHANGE_INODE_CACHE)) btrfs_clear_and_info(root, CHANGE_INODE_CACHE,
btrfs_info(root->fs_info, "disabling inode map caching"); "disabling inode map caching");
btrfs_clear_opt(info->mount_opt, CHANGE_INODE_CACHE);
break; break;
case Opt_clear_cache: case Opt_clear_cache:
btrfs_info(root->fs_info, "force clearing of disk cache"); btrfs_set_and_info(root, CLEAR_CACHE,
btrfs_set_opt(info->mount_opt, CLEAR_CACHE); "force clearing of disk cache");
break; break;
case Opt_user_subvol_rm_allowed: case Opt_user_subvol_rm_allowed:
btrfs_set_opt(info->mount_opt, USER_SUBVOL_RM_ALLOWED); btrfs_set_opt(info->mount_opt, USER_SUBVOL_RM_ALLOWED);
...@@ -649,13 +667,12 @@ int btrfs_parse_options(struct btrfs_root *root, char *options) ...@@ -649,13 +667,12 @@ int btrfs_parse_options(struct btrfs_root *root, char *options)
btrfs_clear_opt(info->mount_opt, ENOSPC_DEBUG); btrfs_clear_opt(info->mount_opt, ENOSPC_DEBUG);
break; break;
case Opt_defrag: case Opt_defrag:
btrfs_info(root->fs_info, "enabling auto defrag"); btrfs_set_and_info(root, AUTO_DEFRAG,
btrfs_set_opt(info->mount_opt, AUTO_DEFRAG); "enabling auto defrag");
break; break;
case Opt_nodefrag: case Opt_nodefrag:
if (btrfs_test_opt(root, AUTO_DEFRAG)) btrfs_clear_and_info(root, AUTO_DEFRAG,
btrfs_info(root->fs_info, "disabling auto defrag"); "disabling auto defrag");
btrfs_clear_opt(info->mount_opt, AUTO_DEFRAG);
break; break;
case Opt_recovery: case Opt_recovery:
btrfs_info(root->fs_info, "enabling auto recovery"); btrfs_info(root->fs_info, "enabling auto recovery");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment