Btrfs: Add a clear_cache mount option
authorJosef Bacik <josef@redhat.com>
Tue, 21 Sep 2010 18:21:34 +0000 (14:21 -0400)
committerChris Mason <chris.mason@oracle.com>
Fri, 29 Oct 2010 13:26:36 +0000 (09:26 -0400)
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>
fs/btrfs/ctree.h
fs/btrfs/extent-tree.c
fs/btrfs/free-space-cache.c
fs/btrfs/super.c

index b155a0e..633e559 100644 (file)
@@ -1229,6 +1229,7 @@ struct btrfs_root {
 #define BTRFS_MOUNT_DISCARD            (1 << 10)
 #define BTRFS_MOUNT_FORCE_COMPRESS      (1 << 11)
 #define BTRFS_MOUNT_SPACE_CACHE                (1 << 12)
+#define BTRFS_MOUNT_CLEAR_CACHE                (1 << 13)
 
 #define btrfs_clear_opt(o, opt)                ((o) &= ~BTRFS_MOUNT_##opt)
 #define btrfs_set_opt(o, opt)          ((o) |= BTRFS_MOUNT_##opt)
index 137833e..1a94ee4 100644 (file)
@@ -8198,6 +8198,8 @@ int btrfs_read_block_groups(struct btrfs_root *root)
        if (cache_gen != 0 &&
            btrfs_super_generation(&root->fs_info->super_copy) != cache_gen)
                need_clear = 1;
+       if (btrfs_test_opt(root, CLEAR_CACHE))
+               need_clear = 1;
 
        while (1) {
                ret = find_first_block_group(root, path, &key);
index baa1934..22ee0dc 100644 (file)
@@ -242,8 +242,6 @@ int load_free_space_cache(struct btrfs_fs_info *fs_info,
         */
        spin_lock(&block_group->lock);
        if (block_group->disk_cache_state != BTRFS_DC_WRITTEN) {
-               printk(KERN_ERR "not reading block group %llu, dcs is %d\n", block_group->key.objectid,
-                      block_group->disk_cache_state);
                spin_unlock(&block_group->lock);
                return 0;
        }
index 5c23eb8..5f56213 100644 (file)
@@ -68,7 +68,7 @@ enum {
        Opt_nodatacow, Opt_max_inline, Opt_alloc_start, Opt_nobarrier, Opt_ssd,
        Opt_nossd, Opt_ssd_spread, Opt_thread_pool, Opt_noacl, Opt_compress,
        Opt_compress_force, Opt_notreelog, Opt_ratio, Opt_flushoncommit,
-       Opt_discard, Opt_space_cache, Opt_err,
+       Opt_discard, Opt_space_cache, Opt_clear_cache, Opt_err,
 };
 
 static match_table_t tokens = {
@@ -93,6 +93,7 @@ static match_table_t tokens = {
        {Opt_ratio, "metadata_ratio=%d"},
        {Opt_discard, "discard"},
        {Opt_space_cache, "space_cache"},
+       {Opt_clear_cache, "clear_cache"},
        {Opt_err, NULL},
 };
 
@@ -239,6 +240,9 @@ int btrfs_parse_options(struct btrfs_root *root, char *options)
                case Opt_space_cache:
                        printk(KERN_INFO "btrfs: enabling disk space caching\n");
                        btrfs_set_opt(info->mount_opt, SPACE_CACHE);
+               case Opt_clear_cache:
+                       printk(KERN_INFO "btrfs: force clearing of disk cache\n");
+                       btrfs_set_opt(info->mount_opt, CLEAR_CACHE);
                        break;
                case Opt_err:
                        printk(KERN_INFO "btrfs: unrecognized mount option "