btrfs: Add noinode_cache mount option
authorQu Wenruo <quwenruo@cn.fujitsu.com>
Mon, 13 Jan 2014 05:36:06 +0000 (13:36 +0800)
committerChris Mason <clm@fb.com>
Tue, 28 Jan 2014 21:20:33 +0000 (13:20 -0800)
Add noinode_cache mount option for btrfs.

Since inode map cache involves all the btrfs_find_free_ino/return_ino
things and if just trigger the mount_opt,
an inode number get from inode map cache will not returned to inode map
cache.

To keep the find and return inode both in the same behavior,
a new bit in mount_opt, CHANGE_INODE_CACHE, is introduced for this idea.
CHANGE_INODE_CACHE is set/cleared in remounting, and the original
INODE_MAP_CACHE is set/cleared according to CHANGE_INODE_CACHE after a
success transaction.
Since find/return inode is all done between btrfs_start_transaction and
btrfs_commit_transaction, this will keep consistent behavior.

Also noinode_cache mount option will not stop the caching_kthread.

Cc: David Sterba <dsterba@suse.cz>
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: Chris Mason <clm@fb.com>
fs/btrfs/ctree.h
fs/btrfs/disk-io.c
fs/btrfs/super.c
fs/btrfs/transaction.c

index 3708fd7ee83a1c501574dbad85f650aee107121c..52c96db0ec0ab6cb98fab5c150537d48d9e1e165 100644 (file)
@@ -2023,6 +2023,7 @@ struct btrfs_ioctl_defrag_range_args {
 #define BTRFS_MOUNT_CHECK_INTEGRITY_INCLUDING_EXTENT_DATA (1 << 21)
 #define BTRFS_MOUNT_PANIC_ON_FATAL_ERROR       (1 << 22)
 #define BTRFS_MOUNT_RESCAN_UUID_TREE   (1 << 23)
+#define        BTRFS_MOUNT_CHANGE_INODE_CACHE  (1 << 24)
 
 #define BTRFS_DEFAULT_COMMIT_INTERVAL  (30)
 
index f0e7bbe148239188f528a3467330b51ba7c87113..4f142c986544856c052abd80310122eb79e14654 100644 (file)
@@ -2776,6 +2776,10 @@ retry_root_backup:
                btrfs_set_opt(fs_info->mount_opt, SSD);
        }
 
+       /* Set the real inode map cache flag */
+       if (btrfs_test_opt(tree_root, CHANGE_INODE_CACHE))
+               btrfs_set_opt(tree_root->fs_info->mount_opt, INODE_MAP_CACHE);
+
 #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
        if (btrfs_test_opt(tree_root, CHECK_INTEGRITY)) {
                ret = btrfsic_mount(tree_root, fs_devices,
index f44cc6a0eb27c312260912d604e5c3ef4a98111c..362aef44a17b536de18f7a5059928a247e43de8b 100644 (file)
@@ -327,7 +327,7 @@ enum {
        Opt_check_integrity_print_mask, Opt_fatal_errors, Opt_rescan_uuid_tree,
        Opt_commit_interval, Opt_barrier, Opt_nodefrag, Opt_nodiscard,
        Opt_noenospc_debug, Opt_noflushoncommit, Opt_acl, Opt_datacow,
-       Opt_datasum, Opt_treelog,
+       Opt_datasum, Opt_treelog, Opt_noinode_cache,
        Opt_err,
 };
 
@@ -370,6 +370,7 @@ static match_table_t tokens = {
        {Opt_defrag, "autodefrag"},
        {Opt_nodefrag, "noautodefrag"},
        {Opt_inode_cache, "inode_cache"},
+       {Opt_noinode_cache, "noinode_cache"},
        {Opt_no_space_cache, "nospace_cache"},
        {Opt_recovery, "recovery"},
        {Opt_skip_balance, "skip_balance"},
@@ -627,7 +628,12 @@ int btrfs_parse_options(struct btrfs_root *root, char *options)
                        break;
                case Opt_inode_cache:
                        btrfs_info(root->fs_info, "enabling inode map caching");
-                       btrfs_set_opt(info->mount_opt, INODE_MAP_CACHE);
+                       btrfs_set_opt(info->mount_opt, CHANGE_INODE_CACHE);
+                       break;
+               case Opt_noinode_cache:
+                       if (btrfs_test_opt(root, CHANGE_INODE_CACHE))
+                               btrfs_info(root->fs_info, "disabling inode map caching");
+                       btrfs_clear_opt(info->mount_opt, CHANGE_INODE_CACHE);
                        break;
                case Opt_clear_cache:
                        btrfs_info(root->fs_info, "force clearing of disk cache");
index 5e2bfdaf8d14bc0c69e8330255454cf284b7d01b..34cd83184c4ad2ff7ce85bb13fea48dfb61198b4 100644 (file)
@@ -1826,6 +1826,15 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans,
                goto cleanup_transaction;
        }
 
+       /*
+        * Since the transaction is done, we should set the inode map cache flag
+        * before any other comming transaction.
+        */
+       if (btrfs_test_opt(root, CHANGE_INODE_CACHE))
+               btrfs_set_opt(root->fs_info->mount_opt, INODE_MAP_CACHE);
+       else
+               btrfs_clear_opt(root->fs_info->mount_opt, INODE_MAP_CACHE);
+
        /* commit_fs_roots gets rid of all the tree log roots, it is now
         * safe to free the root of tree log roots
         */
This page took 0.071952 seconds and 5 git commands to generate.