aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosef Bacik <josef@redhat.com>2010-09-21 14:21:34 -0400
committerChris Mason <chris.mason@oracle.com>2010-10-29 09:26:36 -0400
commit88c2ba3b069f1e0f4694124d02985fa7620a19f1 (patch)
treee41859aca299e14e2658d75e2bf1ef2aea9ab077
parent67377734fd24c32cbdfeb697c2e2bd7fed519e75 (diff)
Btrfs: Add a clear_cache mount option
If something goes wrong with the free space cache we need a way to make sure it's not loaded on mount and that it's cleared for everybody. When you pass the clear_cache option it will make it so all block groups are setup to be cleared, which keeps them from being loaded and then they will be truncated when the transaction is committed. Thanks, Signed-off-by: Josef Bacik <josef@redhat.com>
-rw-r--r--fs/btrfs/ctree.h1
-rw-r--r--fs/btrfs/extent-tree.c2
-rw-r--r--fs/btrfs/free-space-cache.c2
-rw-r--r--fs/btrfs/super.c6
4 files changed, 8 insertions, 3 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index b155a0e49eeb..633e559e000e 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1229,6 +1229,7 @@ struct btrfs_root {
1229#define BTRFS_MOUNT_DISCARD (1 << 10) 1229#define BTRFS_MOUNT_DISCARD (1 << 10)
1230#define BTRFS_MOUNT_FORCE_COMPRESS (1 << 11) 1230#define BTRFS_MOUNT_FORCE_COMPRESS (1 << 11)
1231#define BTRFS_MOUNT_SPACE_CACHE (1 << 12) 1231#define BTRFS_MOUNT_SPACE_CACHE (1 << 12)
1232#define BTRFS_MOUNT_CLEAR_CACHE (1 << 13)
1232 1233
1233#define btrfs_clear_opt(o, opt) ((o) &= ~BTRFS_MOUNT_##opt) 1234#define btrfs_clear_opt(o, opt) ((o) &= ~BTRFS_MOUNT_##opt)
1234#define btrfs_set_opt(o, opt) ((o) |= BTRFS_MOUNT_##opt) 1235#define btrfs_set_opt(o, opt) ((o) |= BTRFS_MOUNT_##opt)
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 137833e1fc26..1a94ee4c4fbb 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -8198,6 +8198,8 @@ int btrfs_read_block_groups(struct btrfs_root *root)
8198 if (cache_gen != 0 && 8198 if (cache_gen != 0 &&
8199 btrfs_super_generation(&root->fs_info->super_copy) != cache_gen) 8199 btrfs_super_generation(&root->fs_info->super_copy) != cache_gen)
8200 need_clear = 1; 8200 need_clear = 1;
8201 if (btrfs_test_opt(root, CLEAR_CACHE))
8202 need_clear = 1;
8201 8203
8202 while (1) { 8204 while (1) {
8203 ret = find_first_block_group(root, path, &key); 8205 ret = find_first_block_group(root, path, &key);
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
index baa193423fb8..22ee0dc2e6b8 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
@@ -242,8 +242,6 @@ int load_free_space_cache(struct btrfs_fs_info *fs_info,
242 */ 242 */
243 spin_lock(&block_group->lock); 243 spin_lock(&block_group->lock);
244 if (block_group->disk_cache_state != BTRFS_DC_WRITTEN) { 244 if (block_group->disk_cache_state != BTRFS_DC_WRITTEN) {
245 printk(KERN_ERR "not reading block group %llu, dcs is %d\n", block_group->key.objectid,
246 block_group->disk_cache_state);
247 spin_unlock(&block_group->lock); 245 spin_unlock(&block_group->lock);
248 return 0; 246 return 0;
249 } 247 }
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 5c23eb8d6ba3..5f56213908e7 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -68,7 +68,7 @@ enum {
68 Opt_nodatacow, Opt_max_inline, Opt_alloc_start, Opt_nobarrier, Opt_ssd, 68 Opt_nodatacow, Opt_max_inline, Opt_alloc_start, Opt_nobarrier, Opt_ssd,
69 Opt_nossd, Opt_ssd_spread, Opt_thread_pool, Opt_noacl, Opt_compress, 69 Opt_nossd, Opt_ssd_spread, Opt_thread_pool, Opt_noacl, Opt_compress,
70 Opt_compress_force, Opt_notreelog, Opt_ratio, Opt_flushoncommit, 70 Opt_compress_force, Opt_notreelog, Opt_ratio, Opt_flushoncommit,
71 Opt_discard, Opt_space_cache, Opt_err, 71 Opt_discard, Opt_space_cache, Opt_clear_cache, Opt_err,
72}; 72};
73 73
74static match_table_t tokens = { 74static match_table_t tokens = {
@@ -93,6 +93,7 @@ static match_table_t tokens = {
93 {Opt_ratio, "metadata_ratio=%d"}, 93 {Opt_ratio, "metadata_ratio=%d"},
94 {Opt_discard, "discard"}, 94 {Opt_discard, "discard"},
95 {Opt_space_cache, "space_cache"}, 95 {Opt_space_cache, "space_cache"},
96 {Opt_clear_cache, "clear_cache"},
96 {Opt_err, NULL}, 97 {Opt_err, NULL},
97}; 98};
98 99
@@ -239,6 +240,9 @@ int btrfs_parse_options(struct btrfs_root *root, char *options)
239 case Opt_space_cache: 240 case Opt_space_cache:
240 printk(KERN_INFO "btrfs: enabling disk space caching\n"); 241 printk(KERN_INFO "btrfs: enabling disk space caching\n");
241 btrfs_set_opt(info->mount_opt, SPACE_CACHE); 242 btrfs_set_opt(info->mount_opt, SPACE_CACHE);
243 case Opt_clear_cache:
244 printk(KERN_INFO "btrfs: force clearing of disk cache\n");
245 btrfs_set_opt(info->mount_opt, CLEAR_CACHE);
242 break; 246 break;
243 case Opt_err: 247 case Opt_err:
244 printk(KERN_INFO "btrfs: unrecognized mount option " 248 printk(KERN_INFO "btrfs: unrecognized mount option "