Loading fs/btrfs/TODO +0 −1 Original line number Diff line number Diff line Loading @@ -7,7 +7,6 @@ * Get rid of struct ctree_path, limiting tree levels held at one time * Add generation number to key pointer in nodes * Add generation number to inode * Add ability to switch a block group from data to metadata or vice versa * forbid cross subvolume renames and hardlinks * Release * Do real tree locking Loading fs/btrfs/ctree.h +3 −2 Original line number Diff line number Diff line Loading @@ -3,7 +3,7 @@ #include <linux/fs.h> #include <linux/buffer_head.h> #include <linux/kobject.h> #include <linux/workqueue.h> #include "bit-radix.h" struct btrfs_trans_handle; Loading Loading @@ -281,6 +281,7 @@ struct btrfs_block_group_cache { }; struct crypto_hash; struct btrfs_fs_info { struct btrfs_root *extent_root; struct btrfs_root *tree_root; Loading Loading @@ -308,9 +309,9 @@ struct btrfs_fs_info { struct mutex fs_mutex; struct list_head trans_list; struct crypto_hash *hash_tfm; struct delayed_work trans_work; spinlock_t hash_lock; int do_barriers; struct kobject kobj; }; /* Loading fs/btrfs/disk-io.c +2 −2 Original line number Diff line number Diff line Loading @@ -577,6 +577,7 @@ struct btrfs_root *open_ctree(struct super_block *sb) fs_info->do_barriers = 1; fs_info->extent_tree_insert_nr = 0; fs_info->extent_tree_prealloc_nr = 0; INIT_DELAYED_WORK(&fs_info->trans_work, btrfs_transaction_cleaner); BTRFS_I(fs_info->btree_inode)->root = tree_root; memset(&BTRFS_I(fs_info->btree_inode)->location, 0, sizeof(struct btrfs_key)); Loading Loading @@ -648,7 +649,6 @@ struct btrfs_root *open_ctree(struct super_block *sb) btrfs_read_block_groups(extent_root); fs_info->generation = btrfs_super_generation(disk_super) + 1; memset(&fs_info->kobj, 0, sizeof(fs_info->kobj)); mutex_unlock(&fs_info->fs_mutex); return tree_root; } Loading Loading @@ -746,6 +746,7 @@ int close_ctree(struct btrfs_root *root) struct btrfs_trans_handle *trans; struct btrfs_fs_info *fs_info = root->fs_info; btrfs_transaction_flush_work(root); mutex_lock(&fs_info->fs_mutex); trans = btrfs_start_transaction(root, 1); btrfs_commit_transaction(trans, root); Loading Loading @@ -776,7 +777,6 @@ int close_ctree(struct btrfs_root *root) del_fs_roots(fs_info); kfree(fs_info->extent_root); kfree(fs_info->tree_root); kobject_unregister(&fs_info->kobj); return 0; } Loading fs/btrfs/super.c +25 −2 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ #include <linux/swap.h> #include <linux/writeback.h> #include <linux/statfs.h> #include <linux/compat.h> #include "ctree.h" #include "disk-io.h" #include "transaction.h" Loading Loading @@ -950,7 +951,7 @@ static int btrfs_fill_super(struct super_block * sb, void * data, int silent) return -ENOMEM; } sb->s_root = root_dentry; btrfs_transaction_queue_work(tree_root, HZ * 30); return 0; } Loading Loading @@ -1452,7 +1453,7 @@ static int btrfs_prepare_write(struct file *file, struct page *page, static void btrfs_write_super(struct super_block *sb) { btrfs_sync_fs(sb, 1); sb->s_dirt = 0; } static int btrfs_readpage(struct file *file, struct page *page) Loading Loading @@ -2698,6 +2699,20 @@ static int btrfs_ioctl(struct inode *inode, struct file *filp, unsigned int return ret; } #ifdef CONFIG_COMPAT static long btrfs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { struct inode *inode = file->f_path.dentry->d_inode; int ret; lock_kernel(); ret = btrfs_ioctl(inode, file, cmd, (unsigned long) compat_ptr(arg)); unlock_kernel(); return ret; } #endif static struct kmem_cache *btrfs_inode_cachep; struct kmem_cache *btrfs_trans_handle_cachep; struct kmem_cache *btrfs_transaction_cachep; Loading Loading @@ -3042,6 +3057,9 @@ static struct file_operations btrfs_dir_file_operations = { .read = generic_read_dir, .readdir = btrfs_readdir, .ioctl = btrfs_ioctl, #ifdef CONFIG_COMPAT .compat_ioctl = btrfs_compat_ioctl, #endif }; static struct address_space_operations btrfs_aops = { Loading Loading @@ -3073,6 +3091,9 @@ static struct file_operations btrfs_file_operations = { .open = generic_file_open, .ioctl = btrfs_ioctl, .fsync = btrfs_sync_file, #ifdef CONFIG_COMPAT .compat_ioctl = btrfs_compat_ioctl, #endif }; static struct inode_operations btrfs_symlink_inode_operations = { Loading @@ -3085,6 +3106,7 @@ static int __init init_btrfs_fs(void) { int err; printk("btrfs loaded!\n"); btrfs_init_transaction_sys(); err = init_inodecache(); if (err) return err; Loading @@ -3095,6 +3117,7 @@ static int __init init_btrfs_fs(void) static void __exit exit_btrfs_fs(void) { btrfs_exit_transaction_sys(); destroy_inodecache(); unregister_filesystem(&btrfs_fs_type); printk("btrfs unloaded\n"); Loading fs/btrfs/transaction.c +60 −0 Original line number Diff line number Diff line Loading @@ -8,6 +8,8 @@ static int total_trans = 0; extern struct kmem_cache *btrfs_trans_handle_cachep; extern struct kmem_cache *btrfs_transaction_cachep; static struct workqueue_struct *trans_wq; #define BTRFS_ROOT_TRANS_TAG 0 #define TRANS_MAGIC 0xE1E10E Loading Loading @@ -44,6 +46,7 @@ static int join_transaction(struct btrfs_root *root) cur_trans->in_commit = 0; cur_trans->use_count = 1; cur_trans->commit_done = 0; cur_trans->start_time = get_seconds(); list_add_tail(&cur_trans->list, &root->fs_info->trans_list); init_bit_radix(&cur_trans->dirty_pages); } Loading Loading @@ -350,3 +353,60 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans, return ret; } void btrfs_transaction_cleaner(struct work_struct *work) { struct btrfs_fs_info *fs_info = container_of(work, struct btrfs_fs_info, trans_work.work); struct btrfs_root *root = fs_info->tree_root; struct btrfs_transaction *cur; struct btrfs_trans_handle *trans; unsigned long now; unsigned long delay = HZ * 30; int ret; printk("btrfs transaction cleaner\n"); mutex_lock(&root->fs_info->fs_mutex); mutex_lock(&root->fs_info->trans_mutex); cur = root->fs_info->running_transaction; if (!cur) { mutex_unlock(&root->fs_info->trans_mutex); goto out; } now = get_seconds(); if (now < cur->start_time || now - cur->start_time < 30) { mutex_unlock(&root->fs_info->trans_mutex); delay = HZ * 5; goto out; } mutex_unlock(&root->fs_info->trans_mutex); printk("forcing commit\n"); trans = btrfs_start_transaction(root, 1); ret = btrfs_commit_transaction(trans, root); out: mutex_unlock(&root->fs_info->fs_mutex); btrfs_transaction_queue_work(root, delay); } void btrfs_transaction_queue_work(struct btrfs_root *root, int delay) { queue_delayed_work(trans_wq, &root->fs_info->trans_work, delay); } void btrfs_transaction_flush_work(struct btrfs_root *root) { cancel_rearming_delayed_workqueue(trans_wq, &root->fs_info->trans_work); flush_workqueue(trans_wq); } void __init btrfs_init_transaction_sys(void) { trans_wq = create_workqueue("btrfs"); } void __exit btrfs_exit_transaction_sys(void) { destroy_workqueue(trans_wq); } Loading
fs/btrfs/TODO +0 −1 Original line number Diff line number Diff line Loading @@ -7,7 +7,6 @@ * Get rid of struct ctree_path, limiting tree levels held at one time * Add generation number to key pointer in nodes * Add generation number to inode * Add ability to switch a block group from data to metadata or vice versa * forbid cross subvolume renames and hardlinks * Release * Do real tree locking Loading
fs/btrfs/ctree.h +3 −2 Original line number Diff line number Diff line Loading @@ -3,7 +3,7 @@ #include <linux/fs.h> #include <linux/buffer_head.h> #include <linux/kobject.h> #include <linux/workqueue.h> #include "bit-radix.h" struct btrfs_trans_handle; Loading Loading @@ -281,6 +281,7 @@ struct btrfs_block_group_cache { }; struct crypto_hash; struct btrfs_fs_info { struct btrfs_root *extent_root; struct btrfs_root *tree_root; Loading Loading @@ -308,9 +309,9 @@ struct btrfs_fs_info { struct mutex fs_mutex; struct list_head trans_list; struct crypto_hash *hash_tfm; struct delayed_work trans_work; spinlock_t hash_lock; int do_barriers; struct kobject kobj; }; /* Loading
fs/btrfs/disk-io.c +2 −2 Original line number Diff line number Diff line Loading @@ -577,6 +577,7 @@ struct btrfs_root *open_ctree(struct super_block *sb) fs_info->do_barriers = 1; fs_info->extent_tree_insert_nr = 0; fs_info->extent_tree_prealloc_nr = 0; INIT_DELAYED_WORK(&fs_info->trans_work, btrfs_transaction_cleaner); BTRFS_I(fs_info->btree_inode)->root = tree_root; memset(&BTRFS_I(fs_info->btree_inode)->location, 0, sizeof(struct btrfs_key)); Loading Loading @@ -648,7 +649,6 @@ struct btrfs_root *open_ctree(struct super_block *sb) btrfs_read_block_groups(extent_root); fs_info->generation = btrfs_super_generation(disk_super) + 1; memset(&fs_info->kobj, 0, sizeof(fs_info->kobj)); mutex_unlock(&fs_info->fs_mutex); return tree_root; } Loading Loading @@ -746,6 +746,7 @@ int close_ctree(struct btrfs_root *root) struct btrfs_trans_handle *trans; struct btrfs_fs_info *fs_info = root->fs_info; btrfs_transaction_flush_work(root); mutex_lock(&fs_info->fs_mutex); trans = btrfs_start_transaction(root, 1); btrfs_commit_transaction(trans, root); Loading Loading @@ -776,7 +777,6 @@ int close_ctree(struct btrfs_root *root) del_fs_roots(fs_info); kfree(fs_info->extent_root); kfree(fs_info->tree_root); kobject_unregister(&fs_info->kobj); return 0; } Loading
fs/btrfs/super.c +25 −2 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ #include <linux/swap.h> #include <linux/writeback.h> #include <linux/statfs.h> #include <linux/compat.h> #include "ctree.h" #include "disk-io.h" #include "transaction.h" Loading Loading @@ -950,7 +951,7 @@ static int btrfs_fill_super(struct super_block * sb, void * data, int silent) return -ENOMEM; } sb->s_root = root_dentry; btrfs_transaction_queue_work(tree_root, HZ * 30); return 0; } Loading Loading @@ -1452,7 +1453,7 @@ static int btrfs_prepare_write(struct file *file, struct page *page, static void btrfs_write_super(struct super_block *sb) { btrfs_sync_fs(sb, 1); sb->s_dirt = 0; } static int btrfs_readpage(struct file *file, struct page *page) Loading Loading @@ -2698,6 +2699,20 @@ static int btrfs_ioctl(struct inode *inode, struct file *filp, unsigned int return ret; } #ifdef CONFIG_COMPAT static long btrfs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { struct inode *inode = file->f_path.dentry->d_inode; int ret; lock_kernel(); ret = btrfs_ioctl(inode, file, cmd, (unsigned long) compat_ptr(arg)); unlock_kernel(); return ret; } #endif static struct kmem_cache *btrfs_inode_cachep; struct kmem_cache *btrfs_trans_handle_cachep; struct kmem_cache *btrfs_transaction_cachep; Loading Loading @@ -3042,6 +3057,9 @@ static struct file_operations btrfs_dir_file_operations = { .read = generic_read_dir, .readdir = btrfs_readdir, .ioctl = btrfs_ioctl, #ifdef CONFIG_COMPAT .compat_ioctl = btrfs_compat_ioctl, #endif }; static struct address_space_operations btrfs_aops = { Loading Loading @@ -3073,6 +3091,9 @@ static struct file_operations btrfs_file_operations = { .open = generic_file_open, .ioctl = btrfs_ioctl, .fsync = btrfs_sync_file, #ifdef CONFIG_COMPAT .compat_ioctl = btrfs_compat_ioctl, #endif }; static struct inode_operations btrfs_symlink_inode_operations = { Loading @@ -3085,6 +3106,7 @@ static int __init init_btrfs_fs(void) { int err; printk("btrfs loaded!\n"); btrfs_init_transaction_sys(); err = init_inodecache(); if (err) return err; Loading @@ -3095,6 +3117,7 @@ static int __init init_btrfs_fs(void) static void __exit exit_btrfs_fs(void) { btrfs_exit_transaction_sys(); destroy_inodecache(); unregister_filesystem(&btrfs_fs_type); printk("btrfs unloaded\n"); Loading
fs/btrfs/transaction.c +60 −0 Original line number Diff line number Diff line Loading @@ -8,6 +8,8 @@ static int total_trans = 0; extern struct kmem_cache *btrfs_trans_handle_cachep; extern struct kmem_cache *btrfs_transaction_cachep; static struct workqueue_struct *trans_wq; #define BTRFS_ROOT_TRANS_TAG 0 #define TRANS_MAGIC 0xE1E10E Loading Loading @@ -44,6 +46,7 @@ static int join_transaction(struct btrfs_root *root) cur_trans->in_commit = 0; cur_trans->use_count = 1; cur_trans->commit_done = 0; cur_trans->start_time = get_seconds(); list_add_tail(&cur_trans->list, &root->fs_info->trans_list); init_bit_radix(&cur_trans->dirty_pages); } Loading Loading @@ -350,3 +353,60 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans, return ret; } void btrfs_transaction_cleaner(struct work_struct *work) { struct btrfs_fs_info *fs_info = container_of(work, struct btrfs_fs_info, trans_work.work); struct btrfs_root *root = fs_info->tree_root; struct btrfs_transaction *cur; struct btrfs_trans_handle *trans; unsigned long now; unsigned long delay = HZ * 30; int ret; printk("btrfs transaction cleaner\n"); mutex_lock(&root->fs_info->fs_mutex); mutex_lock(&root->fs_info->trans_mutex); cur = root->fs_info->running_transaction; if (!cur) { mutex_unlock(&root->fs_info->trans_mutex); goto out; } now = get_seconds(); if (now < cur->start_time || now - cur->start_time < 30) { mutex_unlock(&root->fs_info->trans_mutex); delay = HZ * 5; goto out; } mutex_unlock(&root->fs_info->trans_mutex); printk("forcing commit\n"); trans = btrfs_start_transaction(root, 1); ret = btrfs_commit_transaction(trans, root); out: mutex_unlock(&root->fs_info->fs_mutex); btrfs_transaction_queue_work(root, delay); } void btrfs_transaction_queue_work(struct btrfs_root *root, int delay) { queue_delayed_work(trans_wq, &root->fs_info->trans_work, delay); } void btrfs_transaction_flush_work(struct btrfs_root *root) { cancel_rearming_delayed_workqueue(trans_wq, &root->fs_info->trans_work); flush_workqueue(trans_wq); } void __init btrfs_init_transaction_sys(void) { trans_wq = create_workqueue("btrfs"); } void __exit btrfs_exit_transaction_sys(void) { destroy_workqueue(trans_wq); }