aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs
diff options
context:
space:
mode:
authorJosef Bacik <josef@redhat.com>2011-10-03 14:07:49 -0400
committerJosef Bacik <josef@redhat.com>2011-10-19 15:12:51 -0400
commit73bc187680f94bed498f8a669103cad290e41180 (patch)
treee4e8c9a6baa656dbeb470032956657b294610c61 /fs/btrfs
parente27425d614d68daa08f60735982a7c3a0230e855 (diff)
Btrfs: introduce mount option no_space_cache
Some users have requested this and I've found I needed a way to disable cache loading without actually clearing the cache, so introduce the no_space_cache option. Before we check the super blocks cache generation field and if it was populated we always turned space caching on. Now we check this and set the space cache option on, and then parse the mount options so that if we want it off it get's turned off. Then we check the mount option all the places we do the caching work instead of checking the super's cache generation. This makes things more consistent and lets us turn space caching off. Thanks, Signed-off-by: Josef Bacik <josef@redhat.com>
Diffstat (limited to 'fs/btrfs')
-rw-r--r--fs/btrfs/extent-tree.c9
-rw-r--r--fs/btrfs/super.c21
-rw-r--r--fs/btrfs/transaction.c2
3 files changed, 22 insertions, 10 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 25b69d0f9135..f9711a82fc54 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -481,7 +481,8 @@ static int cache_block_group(struct btrfs_block_group_cache *cache,
481 * we likely hold important locks. 481 * we likely hold important locks.
482 */ 482 */
483 if (trans && (!trans->transaction->in_commit) && 483 if (trans && (!trans->transaction->in_commit) &&
484 (root && root != root->fs_info->tree_root)) { 484 (root && root != root->fs_info->tree_root) &&
485 btrfs_test_opt(root, SPACE_CACHE)) {
485 spin_lock(&cache->lock); 486 spin_lock(&cache->lock);
486 if (cache->cached != BTRFS_CACHE_NO) { 487 if (cache->cached != BTRFS_CACHE_NO) {
487 spin_unlock(&cache->lock); 488 spin_unlock(&cache->lock);
@@ -4223,7 +4224,7 @@ static int update_block_group(struct btrfs_trans_handle *trans,
4223 spin_lock(&cache->space_info->lock); 4224 spin_lock(&cache->space_info->lock);
4224 spin_lock(&cache->lock); 4225 spin_lock(&cache->lock);
4225 4226
4226 if (btrfs_super_cache_generation(&info->super_copy) != 0 && 4227 if (btrfs_test_opt(root, SPACE_CACHE) &&
4227 cache->disk_cache_state < BTRFS_DC_CLEAR) 4228 cache->disk_cache_state < BTRFS_DC_CLEAR)
4228 cache->disk_cache_state = BTRFS_DC_CLEAR; 4229 cache->disk_cache_state = BTRFS_DC_CLEAR;
4229 4230
@@ -7038,13 +7039,11 @@ int btrfs_read_block_groups(struct btrfs_root *root)
7038 path->reada = 1; 7039 path->reada = 1;
7039 7040
7040 cache_gen = btrfs_super_cache_generation(&root->fs_info->super_copy); 7041 cache_gen = btrfs_super_cache_generation(&root->fs_info->super_copy);
7041 if (cache_gen != 0 && 7042 if (btrfs_test_opt(root, SPACE_CACHE) &&
7042 btrfs_super_generation(&root->fs_info->super_copy) != cache_gen) 7043 btrfs_super_generation(&root->fs_info->super_copy) != cache_gen)
7043 need_clear = 1; 7044 need_clear = 1;
7044 if (btrfs_test_opt(root, CLEAR_CACHE)) 7045 if (btrfs_test_opt(root, CLEAR_CACHE))
7045 need_clear = 1; 7046 need_clear = 1;
7046 if (!btrfs_test_opt(root, SPACE_CACHE) && cache_gen)
7047 printk(KERN_INFO "btrfs: disk space caching is enabled\n");
7048 7047
7049 while (1) { 7048 while (1) {
7050 ret = find_first_block_group(root, path, &key); 7049 ret = find_first_block_group(root, path, &key);
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 934789f7fd33..266d1f35465d 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -164,7 +164,7 @@ enum {
164 Opt_notreelog, Opt_ratio, Opt_flushoncommit, Opt_discard, 164 Opt_notreelog, Opt_ratio, Opt_flushoncommit, Opt_discard,
165 Opt_space_cache, Opt_clear_cache, Opt_user_subvol_rm_allowed, 165 Opt_space_cache, Opt_clear_cache, Opt_user_subvol_rm_allowed,
166 Opt_enospc_debug, Opt_subvolrootid, Opt_defrag, 166 Opt_enospc_debug, Opt_subvolrootid, Opt_defrag,
167 Opt_inode_cache, Opt_err, 167 Opt_inode_cache, Opt_no_space_cache, Opt_err,
168}; 168};
169 169
170static match_table_t tokens = { 170static match_table_t tokens = {
@@ -197,6 +197,7 @@ static match_table_t tokens = {
197 {Opt_subvolrootid, "subvolrootid=%d"}, 197 {Opt_subvolrootid, "subvolrootid=%d"},
198 {Opt_defrag, "autodefrag"}, 198 {Opt_defrag, "autodefrag"},
199 {Opt_inode_cache, "inode_cache"}, 199 {Opt_inode_cache, "inode_cache"},
200 {Opt_no_space_cache, "no_space_cache"},
200 {Opt_err, NULL}, 201 {Opt_err, NULL},
201}; 202};
202 203
@@ -208,14 +209,19 @@ int btrfs_parse_options(struct btrfs_root *root, char *options)
208{ 209{
209 struct btrfs_fs_info *info = root->fs_info; 210 struct btrfs_fs_info *info = root->fs_info;
210 substring_t args[MAX_OPT_ARGS]; 211 substring_t args[MAX_OPT_ARGS];
211 char *p, *num, *orig; 212 char *p, *num, *orig = NULL;
213 u64 cache_gen;
212 int intarg; 214 int intarg;
213 int ret = 0; 215 int ret = 0;
214 char *compress_type; 216 char *compress_type;
215 bool compress_force = false; 217 bool compress_force = false;
216 218
219 cache_gen = btrfs_super_cache_generation(&root->fs_info->super_copy);
220 if (cache_gen)
221 btrfs_set_opt(info->mount_opt, SPACE_CACHE);
222
217 if (!options) 223 if (!options)
218 return 0; 224 goto out;
219 225
220 /* 226 /*
221 * strsep changes the string, duplicate it because parse_options 227 * strsep changes the string, duplicate it because parse_options
@@ -362,9 +368,12 @@ int btrfs_parse_options(struct btrfs_root *root, char *options)
362 btrfs_set_opt(info->mount_opt, DISCARD); 368 btrfs_set_opt(info->mount_opt, DISCARD);
363 break; 369 break;
364 case Opt_space_cache: 370 case Opt_space_cache:
365 printk(KERN_INFO "btrfs: enabling disk space caching\n");
366 btrfs_set_opt(info->mount_opt, SPACE_CACHE); 371 btrfs_set_opt(info->mount_opt, SPACE_CACHE);
367 break; 372 break;
373 case Opt_no_space_cache:
374 printk(KERN_INFO "btrfs: disabling disk space caching\n");
375 btrfs_clear_opt(info->mount_opt, SPACE_CACHE);
376 break;
368 case Opt_inode_cache: 377 case Opt_inode_cache:
369 printk(KERN_INFO "btrfs: enabling inode map caching\n"); 378 printk(KERN_INFO "btrfs: enabling inode map caching\n");
370 btrfs_set_opt(info->mount_opt, INODE_MAP_CACHE); 379 btrfs_set_opt(info->mount_opt, INODE_MAP_CACHE);
@@ -393,6 +402,8 @@ int btrfs_parse_options(struct btrfs_root *root, char *options)
393 } 402 }
394 } 403 }
395out: 404out:
405 if (!ret && btrfs_test_opt(root, SPACE_CACHE))
406 printk(KERN_INFO "btrfs: disk space caching is enabled\n");
396 kfree(orig); 407 kfree(orig);
397 return ret; 408 return ret;
398} 409}
@@ -687,6 +698,8 @@ static int btrfs_show_options(struct seq_file *seq, struct vfsmount *vfs)
687 seq_puts(seq, ",noacl"); 698 seq_puts(seq, ",noacl");
688 if (btrfs_test_opt(root, SPACE_CACHE)) 699 if (btrfs_test_opt(root, SPACE_CACHE))
689 seq_puts(seq, ",space_cache"); 700 seq_puts(seq, ",space_cache");
701 else
702 seq_puts(seq, ",no_space_cache");
690 if (btrfs_test_opt(root, CLEAR_CACHE)) 703 if (btrfs_test_opt(root, CLEAR_CACHE))
691 seq_puts(seq, ",clear_cache"); 704 seq_puts(seq, ",clear_cache");
692 if (btrfs_test_opt(root, USER_SUBVOL_RM_ALLOWED)) 705 if (btrfs_test_opt(root, USER_SUBVOL_RM_ALLOWED))
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index 45655793a2c5..1e1a4816ccb0 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -1003,7 +1003,7 @@ static void update_super_roots(struct btrfs_root *root)
1003 super->root = root_item->bytenr; 1003 super->root = root_item->bytenr;
1004 super->generation = root_item->generation; 1004 super->generation = root_item->generation;
1005 super->root_level = root_item->level; 1005 super->root_level = root_item->level;
1006 if (super->cache_generation != 0 || btrfs_test_opt(root, SPACE_CACHE)) 1006 if (btrfs_test_opt(root, SPACE_CACHE))
1007 super->cache_generation = root_item->generation; 1007 super->cache_generation = root_item->generation;
1008} 1008}
1009 1009