Misc cleanups for 3.18
cover Misc cleanups for 3.18
Assorted cleanups. There's fix from Filipe mixed among my patches because I found it in the mailinglist but only after I had written my own patch of course.
You can pull from
git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux.git cleanup/misc-for-3.18
David Sterba (13):
btrfs: defrag, use unsigned type for extent thresh
btrfs: remove unused variable from btrfs_parse_options
btrfs: remove unused extent state bits
btrfs: use enum for wq endio metadata type
btrfs: fix error labels in init_btrfs_fs
btrfs: use slab for end_io_wq structures
btrfs: remove unused members from struct scrub_warning
btrfs: let merge_reloc_roots return void
btrfs: hide typecast to definition of BTRFS_SEND_TRANS_STUB
btrfs: drop constant param from btrfs_release_extent_buffer_page
btrfs: kill extent_buffer_page helper
btrfs: new define for the inline extent data start
btrfs: move checks for DUMMY_ROOT into a helper
Filipe David Borba Manana (1):
Btrfs: set default max_inline to 8KiB instead of 8MiB
fs/btrfs/compression.c | 11 +++++--- fs/btrfs/ctree.c | 8 +++--- fs/btrfs/ctree.h | 26 +++++++++++++------ fs/btrfs/disk-io.c | 61 ++++++++++++++++++++++++------------------- fs/btrfs/disk-io.h | 6 +++-- fs/btrfs/extent-tree.c | 16 +++++------- fs/btrfs/extent_io.c | 70 +++++++++++++++++++++++--------------------------- fs/btrfs/extent_io.h | 10 -------- fs/btrfs/inode.c | 3 ++- fs/btrfs/ioctl.c | 8 +++--- fs/btrfs/qgroup.c | 10 +++----- fs/btrfs/relocation.c | 3 +-- fs/btrfs/scrub.c | 17 ++---------- fs/btrfs/send.c | 2 +- fs/btrfs/super.c | 14 ++++++---- fs/btrfs/transaction.c | 2 +- fs/btrfs/transaction.h | 2 +- 17 files changed, 131 insertions(+), 138 deletions(-)
Signature · 1 line
1.8.4.5
PATCH 1/14 btrfs: defrag, use unsigned type for extent thresh
Signed type mismatches the ioctl structure, all extent calculations are done on unsigned types.
--- fs/btrfs/ioctl.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/btrfs/ioctl.c +4 -4
@@ -885,7 +885,7 @@ out_unlock:* file you want to defrag, we return 0 to let you know to skip this * part of the file */ -static int check_defrag_in_cache (struct inode *inode,u64 offset,int thresh) +static int check_defrag_in_cache (struct inode *inode,u64 offset,u32 thresh) {struct extent_io_tree *io_tree = &BTRFS_I (inode)->io_tree;struct extent_map *em =NULL ;
@@ -920,7 +920,7 @@ static int check_defrag_in_cache(struct inode *inode, u64 offset, int thresh)*/ static int find_new_extents (struct btrfs_root *root,struct inode *inode,u64 newer_than, -u64 *off,int thresh) +u64 *off,u32 thresh) {struct btrfs_path *path;struct btrfs_key min_key;
@@ -1029,7 +1029,7 @@ static bool defrag_check_next_extent(struct inode *inode, struct extent_map *em)return ret; } -static int should_defrag_range (struct inode *inode,u64 start,int thresh, +static int should_defrag_range (struct inode *inode,u64 start,u32 thresh,u64 *last_len,u64 *skip,u64 *defrag_end,int compress) {
@@ -1259,7 +1259,7 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,int ret;int defrag_count =0 ;int compress_type =BTRFS_COMPRESS_ZLIB ; -int extent_thresh = range->extent_thresh; +u32 extent_thresh = range->extent_thresh;unsigned long max_cluster = (256 *1024 ) >>PAGE_CACHE_SHIFT ;unsigned long cluster = max_cluster;u64 new_align = ~((u64 )128 *1024 -1 );
Signature · 1 line
1.8.4.5
PATCH 2/14 btrfs: remove unused variable from btrfs_parse_options
In reply to David Sterba--- fs/btrfs/super.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
fs/btrfs/super.c +1 -3
@@ -395,7 +395,6 @@ int btrfs_parse_options(struct btrfs_root *root, char *options)int ret =0 ;char *compress_type;bool compress_force = false; -bool compress = false; cache_gen =btrfs_super_cache_generation (root->fs_info->super_copy);if (cache_gen)
@@ -473,7 +472,6 @@ int btrfs_parse_options(struct btrfs_root *root, char *options)/* Fallthrough */ case Opt_compress:case Opt_compress_type: - compress = true;if (token == Opt_compress || token == Opt_compress_force ||strcmp (args[0 ].from,"zlib" ) ==0 ) {
@@ -503,7 +501,7 @@ int btrfs_parse_options(struct btrfs_root *root, char *options)btrfs_set_and_info (root,FORCE_COMPRESS ,"force %s compression" , compress_type); - }else if (compress) { + }else {if (!btrfs_test_opt (root,COMPRESS )) btrfs_info(root->fs_info, "btrfs: use %s compression",
Signature · 1 line
1.8.4.5
PATCH 3/14 Btrfs: set default max_inline to 8KiB instead of 8MiB
In reply to David SterbaFrom: Filipe David Borba Manana <[email protected]>
8MiB is way too large and likely set by mistake. This is not a significant issue as in practice the max amount of data added to an inline extent is also limited by the page cache and btree leaf sizes.
--- fs/btrfs/ctree.h | 1 + fs/btrfs/disk-io.c | 2 +- fs/btrfs/super.c | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-)
fs/btrfs/ctree.h +1 -0
@@ -2089,6 +2089,7 @@ struct btrfs_ioctl_defrag_range_args {#define BTRFS_MOUNT_CHANGE_INODE_CACHE (1 << 24)#define BTRFS_DEFAULT_COMMIT_INTERVAL (30) +#define BTRFS_DEFAULT_MAX_INLINE (8192)#define btrfs_clear_opt (o, opt) ((o) &= ~BTRFS_MOUNT_##opt)#define btrfs_set_opt (o, opt) ((o) |= BTRFS_MOUNT_##opt)
fs/btrfs/disk-io.c +1 -1
@@ -2260,7 +2260,7 @@ int open_ctree(struct super_block *sb,atomic_set (&fs_info->qgroup_op_seq,0 );atomic64_set (&fs_info->tree_mod_seq,0 ); fs_info->sb = sb; - fs_info->max_inline =8192 *1024 ; + fs_info->max_inline =BTRFS_DEFAULT_MAX_INLINE ; fs_info->metadata_ratio =0 ; fs_info->defrag_inodes =RB_ROOT ; fs_info->free_chunk_space =0 ;
fs/btrfs/super.c +1 -1
@@ -1014,7 +1014,7 @@ static int btrfs_show_options(struct seq_file *seq, struct dentry *dentry)seq_puts (seq,",nodatacow" );if (btrfs_test_opt (root,NOBARRIER ))seq_puts (seq,",nobarrier" ); -if (info->max_inline !=8192 *1024 ) +if (info->max_inline !=BTRFS_DEFAULT_MAX_INLINE )seq_printf (seq,",max_inline=%llu" , info->max_inline);if (info->alloc_start !=0 )seq_printf (seq,",alloc_start=%llu" , info->alloc_start);
Signature · 1 line
1.8.4.5
PATCH 4/14 btrfs: remove unused extent state bits
In reply to David SterbaThe last users are long gone.
--- fs/btrfs/extent_io.h | 4 ---- 1 file changed, 4 deletions(-)
fs/btrfs/extent_io.h +0 -4
@@ -11,8 +11,6 @@#define EXTENT_NEW (1 << 4)#define EXTENT_DELALLOC (1 << 5)#define EXTENT_DEFRAG (1 << 6) -#define EXTENT_DEFRAG_DONE (1 << 7) -#define EXTENT_BUFFER_FILLED (1 << 8)#define EXTENT_BOUNDARY (1 << 9)#define EXTENT_NODATASUM (1 << 10)#define EXTENT_DO_ACCOUNTING (1 << 11)
@@ -34,7 +32,6 @@/* these are bit numbers for test/set bit */ #define EXTENT_BUFFER_UPTODATE 0 -#define EXTENT_BUFFER_BLOCKING 1#define EXTENT_BUFFER_DIRTY 2#define EXTENT_BUFFER_CORRUPT 3#define EXTENT_BUFFER_READAHEAD 4/* this got triggered by readahead */
@@ -57,7 +54,6 @@* map has page->private set to one. */ #define EXTENT_PAGE_PRIVATE 1 -#define EXTENT_PAGE_PRIVATE_FIRST_PAGE 3struct extent_state ;struct btrfs_root ;
Signature · 1 line
1.8.4.5
PATCH 5/14 btrfs: use enum for wq endio metadata type
In reply to David SterbaThe enum exists but is not consistently used.
--- fs/btrfs/compression.c | 11 +++++++---- fs/btrfs/disk-io.c | 14 +++----------- fs/btrfs/disk-io.h | 4 ++-- fs/btrfs/inode.c | 3 ++- 4 files changed, 14 insertions(+), 18 deletions(-)
fs/btrfs/compression.c +7 -4
@@ -388,7 +388,8 @@ int btrfs_submit_compressed_write(struct inode *inode, u64 start,* freed before we're done setting it up */ atomic_inc (&cb->pending_bios); - ret =btrfs_bio_wq_end_io (root->fs_info, bio,0 ); + ret =btrfs_bio_wq_end_io (root->fs_info, bio, +BTRFS_WQ_ENDIO_DATA );BUG_ON (ret);/* -ENOMEM */ if (!skip_sum) {
@@ -419,7 +420,7 @@ int btrfs_submit_compressed_write(struct inode *inode, u64 start, }bio_get (bio); - ret =btrfs_bio_wq_end_io (root->fs_info, bio,0 ); + ret =btrfs_bio_wq_end_io (root->fs_info, bio,BTRFS_WQ_ENDIO_DATA );BUG_ON (ret);/* -ENOMEM */ if (!skip_sum) {
@@ -668,7 +669,8 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio, PAGE_CACHE_SIZE) {bio_get (comp_bio); - ret =btrfs_bio_wq_end_io (root->fs_info, comp_bio,0 ); + ret =btrfs_bio_wq_end_io (root->fs_info, comp_bio, +BTRFS_WQ_ENDIO_DATA );BUG_ON (ret);/* -ENOMEM */ /*
@@ -706,7 +708,8 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio, }bio_get (comp_bio); - ret =btrfs_bio_wq_end_io (root->fs_info, comp_bio,0 ); + ret =btrfs_bio_wq_end_io (root->fs_info, comp_bio, +BTRFS_WQ_ENDIO_DATA );BUG_ON (ret);/* -ENOMEM */ if (!(BTRFS_I (inode)->flags &BTRFS_INODE_NODATASUM )) {
fs/btrfs/disk-io.c +3 -11
@@ -82,7 +82,7 @@ struct end_io_wq {void *private;struct btrfs_fs_info *info;int error; -int metadata; +enum btrfs_wq_endio_type metadata;struct list_head list;struct btrfs_work work; };
@@ -733,16 +733,8 @@ static void end_workqueue_bio(struct bio *bio, int err)btrfs_queue_work (wq, &end_io_wq->work); } -/* -* For the metadata arg you want -* -* 0 - if data -* 1 - if normal metadta -* 2 - if writing to the free space cache area -* 3 - raid parity work -*/ int btrfs_bio_wq_end_io (struct btrfs_fs_info *info,struct bio *bio, -int metadata) +enum btrfs_wq_endio_type metadata) {struct end_io_wq *end_io_wq;
@@ -930,7 +922,7 @@ static int btree_submit_bio_hook(struct inode *inode, int rw, struct bio *bio,* can happen in the async kernel threads */ ret =btrfs_bio_wq_end_io (BTRFS_I (inode)->root->fs_info, - bio,1 ); + bio,BTRFS_WQ_ENDIO_METADATA );if (ret) goto out_w_error; ret = btrfs_map_bio(BTRFS_I(inode)->root, rw, bio,
fs/btrfs/disk-io.h +2 -2
@@ -25,7 +25,7 @@#define BTRFS_SUPER_MIRROR_MAX 3#define BTRFS_SUPER_MIRROR_SHIFT 12 -enum { +enum btrfs_wq_endio_type {BTRFS_WQ_ENDIO_DATA =0 ,BTRFS_WQ_ENDIO_METADATA =1 ,BTRFS_WQ_ENDIO_FREE_SPACE =2 ,
@@ -120,7 +120,7 @@ int btrfs_read_buffer(struct extent_buffer *buf, u64 parent_transid);u32 btrfs_csum_data (char *data,u32 seed,size_t len);void btrfs_csum_final (u32 crc,char *result);int btrfs_bio_wq_end_io (struct btrfs_fs_info *info,struct bio *bio, -int metadata); +enum btrfs_wq_endio_type metadata); int btrfs_wq_submit_bio(struct btrfs_fs_info *fs_info, struct inode *inode, int rw, struct bio *bio, int mirror_num, unsigned long bio_flags, u64 bio_offset,
fs/btrfs/inode.c +2 -1
@@ -7721,7 +7721,8 @@ static inline int __btrfs_submit_dio_bio(struct bio *bio, struct inode *inode,bio_get (bio);if (!write) { - ret =btrfs_bio_wq_end_io (root->fs_info, bio,0 ); + ret =btrfs_bio_wq_end_io (root->fs_info, bio, +BTRFS_WQ_ENDIO_DATA );if (ret) goto err; }
Signature · 1 line
1.8.4.5
PATCH 6/14 btrfs: fix error labels in init_btrfs_fs
In reply to David Sterbabtrfs_interface_init rarely fails but we could leak the prelim_ref slab.
--- fs/btrfs/super.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/btrfs/super.c +2 -2
@@ -1999,11 +1999,11 @@ static int __init init_btrfs_fs(void) err =btrfs_prelim_ref_init ();if (err) - goto free_prelim_ref; + goto free_delayed_ref; err =btrfs_interface_init ();if (err) - goto free_delayed_ref; + goto free_prelim_ref;btrfs_init_lockdep ();
Signature · 1 line
1.8.4.5
PATCH 7/14 btrfs: use slab for end_io_wq structures
In reply to David SterbaThe structure is frequently reused. Rename it according to the slab name.
--- fs/btrfs/disk-io.c | 38 +++++++++++++++++++++++++++++--------- fs/btrfs/disk-io.h | 2 ++ fs/btrfs/super.c | 8 +++++++- 3 files changed, 38 insertions(+), 10 deletions(-)
fs/btrfs/disk-io.c +29 -9
@@ -72,11 +72,11 @@ static int btrfs_cleanup_transaction(struct btrfs_root *root);static void btrfs_error_commit_super (struct btrfs_root *root);/* -* end_io_wq structs are used to do processing in task context when an IO is -* complete. This is used during reads to verify checksums, and it is used +* btrfs_end_io_wq structs are used to do processing in task context when an IO +* is complete. This is used during reads to verify checksums, and it is used * by writes to insert metadata for new file extents after IO is complete. */ -struct end_io_wq { +struct btrfs_end_io_wq {struct bio *bio;bio_end_io_t *end_io;void *private;
@@ -87,6 +87,26 @@ struct end_io_wq {struct btrfs_work work; }; +static struct kmem_cache *btrfs_end_io_wq_cache; + +int __init btrfs_end_io_wq_init (void ) +{ + btrfs_end_io_wq_cache =kmem_cache_create ("btrfs_end_io_wq" , +sizeof (struct btrfs_end_io_wq ), +0 , +SLAB_RECLAIM_ACCOUNT |SLAB_MEM_SPREAD , +NULL ); +if (!btrfs_end_io_wq_cache) +return -ENOMEM ; +return 0 ; +} + +void btrfs_end_io_wq_exit (void ) +{ +if (btrfs_end_io_wq_cache) +kmem_cache_destroy (btrfs_end_io_wq_cache); +} +/* * async submit bios are used to offload expensive checksumming * onto the worker threads. They checksum file and metadata bios
@@ -690,7 +710,7 @@ static int btree_io_failed_hook(struct page *page, int failed_mirror)static void end_workqueue_bio (struct bio *bio,int err) { -struct end_io_wq *end_io_wq = bio->bi_private; +struct btrfs_end_io_wq *end_io_wq = bio->bi_private;struct btrfs_fs_info *fs_info;struct btrfs_workqueue *wq;btrfs_work_func_t func;
@@ -736,9 +756,9 @@ static void end_workqueue_bio(struct bio *bio, int err)int btrfs_bio_wq_end_io (struct btrfs_fs_info *info,struct bio *bio,enum btrfs_wq_endio_type metadata) { -struct end_io_wq *end_io_wq; +struct btrfs_end_io_wq *end_io_wq; - end_io_wq =kmalloc (sizeof (*end_io_wq),GFP_NOFS ); + end_io_wq =kmem_cache_alloc (btrfs_end_io_wq_cache,GFP_NOFS );if (!end_io_wq)return -ENOMEM ;
@@ -1723,16 +1743,16 @@ static int setup_bdi(struct btrfs_fs_info *info, struct backing_dev_info *bdi)static void end_workqueue_fn (struct btrfs_work *work) {struct bio *bio; -struct end_io_wq *end_io_wq; +struct btrfs_end_io_wq *end_io_wq;int error; - end_io_wq = container_of(work, struct end_io_wq, work); + end_io_wq = container_of(work, struct btrfs_end_io_wq, work); bio = end_io_wq->bio; error = end_io_wq->error; bio->bi_private = end_io_wq->private; bio->bi_end_io = end_io_wq->end_io; -kfree (end_io_wq); +kmem_cache_free (btrfs_end_io_wq_cache, end_io_wq);bio_endio_nodec (bio, error); }
fs/btrfs/disk-io.h +2 -0
@@ -142,6 +142,8 @@ int btree_lock_page_hook(struct page *page, void *data, void (*flush_fn)(void *));int btrfs_calc_num_tolerated_disk_barrier_failures (struct btrfs_fs_info *fs_info); +int __init btrfs_end_io_wq_init (void ); +void btrfs_end_io_wq_exit (void );#ifdef CONFIG_DEBUG_LOCK_ALLOC void btrfs_init_lockdep (void );
fs/btrfs/super.c +7 -1
@@ -2001,10 +2001,14 @@ static int __init init_btrfs_fs(void)if (err) goto free_delayed_ref; - err =btrfs_interface_init (); + err =btrfs_end_io_wq_init ();if (err) goto free_prelim_ref; + err =btrfs_interface_init (); +if (err) + goto free_end_io_wq; +btrfs_init_lockdep ();btrfs_print_info ();
@@ -2021,6 +2025,8 @@ static int __init init_btrfs_fs(void) unregister_ioctl:btrfs_interface_exit (); +free_end_io_wq: +btrfs_end_io_wq_exit (); free_prelim_ref:btrfs_prelim_ref_exit (); free_delayed_ref:
Signature · 1 line
1.8.4.5
PATCH 8/14 btrfs: remove unused members from struct scrub_warning
In reply to David Sterba--- fs/btrfs/scrub.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-)
fs/btrfs/scrub.c +2 -15
@@ -177,17 +177,12 @@ struct scrub_copy_nocow_ctx {struct scrub_warning {struct btrfs_path *path;u64 extent_item_size; -char *scratch_buf; -char *msg_buf;const char *errstr;sector_t sector;u64 logical;struct btrfs_device *dev; -int msg_bufsize; -int scratch_bufsize; }; -static void scrub_pending_bio_inc (struct scrub_ctx *sctx);static void scrub_pending_bio_dec (struct scrub_ctx *sctx);static void scrub_pending_trans_workers_inc (struct scrub_ctx *sctx);
@@ -551,7 +546,6 @@ static void scrub_print_warning(const char *errstr, struct scrub_block *sblock)u64 ref_root;u32 item_size;u8 ref_level; -const int bufsize =4096 ;int ret;WARN_ON (sblock->page_count <1 );
@@ -559,18 +553,13 @@ static void scrub_print_warning(const char *errstr, struct scrub_block *sblock) fs_info = sblock->sctx->dev_root->fs_info; path =btrfs_alloc_path (); +if (!path) +return ; - swarn.scratch_buf =kmalloc (bufsize,GFP_NOFS ); - swarn.msg_buf =kmalloc (bufsize,GFP_NOFS ); swarn.sector = (sblock->pagev[0 ]->physical) >>9 ; swarn.logical = sblock->pagev[0 ]->logical; swarn.errstr = errstr; swarn.dev =NULL ; - swarn.msg_bufsize = bufsize; - swarn.scratch_bufsize = bufsize; - -if (!path || !swarn.scratch_buf || !swarn.msg_buf) - goto out; ret =extent_from_logical (fs_info, swarn.logical, path, &found_key, &flags);
@@ -611,8 +600,6 @@ static void scrub_print_warning(const char *errstr, struct scrub_block *sblock) out:btrfs_free_path (path); -kfree (swarn.scratch_buf); -kfree (swarn.msg_buf); }static int scrub_fixup_readpage (u64 inum,u64 offset,u64 root,void *fixup_ctx)
Signature · 1 line
1.8.4.5
PATCH 9/14 btrfs: let merge_reloc_roots return void
In reply to David Sterba--- fs/btrfs/relocation.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fs/btrfs/relocation.c +1 -2
@@ -2316,7 +2316,7 @@ void free_reloc_roots(struct list_head *list) }static noinline_for_stack -int merge_reloc_roots(struct reloc_control *rc) +void merge_reloc_roots(struct reloc_control *rc) {struct btrfs_root *root;struct btrfs_root *reloc_root;
@@ -2397,7 +2397,6 @@ out: }BUG_ON (!RB_EMPTY_ROOT (&rc->reloc_root_tree.rb_root)); -return ret; }static void free_block_list (struct rb_root *blocks)
Signature · 1 line
1.8.4.5
PATCH 10/14 btrfs: hide typecast to definition of BTRFS_SEND_TRANS_STUB
In reply to David Sterba--- fs/btrfs/disk-io.c | 3 +-- fs/btrfs/send.c | 2 +- fs/btrfs/transaction.c | 2 +- fs/btrfs/transaction.h | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-)
fs/btrfs/disk-io.c +1 -2
@@ -347,8 +347,7 @@ static int verify_parent_transid(struct extent_io_tree *io_tree, {struct extent_state *cached_state =NULL ;int ret; -bool need_lock = (current->journal_info == - (void *)BTRFS_SEND_TRANS_STUB ); +bool need_lock = (current->journal_info ==BTRFS_SEND_TRANS_STUB );if (!parent_transid ||btrfs_header_generation (eb) == parent_transid)return 0 ;
fs/btrfs/send.c +1 -1
@@ -5728,7 +5728,7 @@ long btrfs_ioctl_send(struct file *mnt_file, void __user *arg_) NULL); sort_clone_roots =1 ; - current->journal_info = (void *)BTRFS_SEND_TRANS_STUB ; + current->journal_info =BTRFS_SEND_TRANS_STUB ; ret =send_subvol (sctx); current->journal_info =NULL ;if (ret <0 )
fs/btrfs/transaction.c +1 -1
@@ -386,7 +386,7 @@ start_transaction(struct btrfs_root *root, u64 num_items, unsigned int type,int ret;/* Send isn't supposed to start transactions. */ -ASSERT (current->journal_info != (void *)BTRFS_SEND_TRANS_STUB ); +ASSERT (current->journal_info !=BTRFS_SEND_TRANS_STUB );if (test_bit (BTRFS_FS_STATE_ERROR , &root->fs_info->fs_state))return ERR_PTR (-EROFS );
fs/btrfs/transaction.h +1 -1
@@ -79,7 +79,7 @@ struct btrfs_transaction {#define TRANS_EXTWRITERS (__TRANS_USERSPACE | __TRANS_START | \ __TRANS_ATTACH) -#define BTRFS_SEND_TRANS_STUB 1 +#define BTRFS_SEND_TRANS_STUB ((void *)1)struct btrfs_trans_handle {u64 transid;
Signature · 1 line
1.8.4.5
PATCH 11/14 btrfs: drop constant param from btrfs_release_extent_buffer_page
In reply to David SterbaAll callers use the same value, simplify the function.
--- fs/btrfs/extent_io.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-)
fs/btrfs/extent_io.c +6 -9
@@ -4450,19 +4450,16 @@ int extent_buffer_under_io(struct extent_buffer *eb)/* * Helper for releasing extent buffer page. */ -static void btrfs_release_extent_buffer_page (struct extent_buffer *eb, -unsigned long start_idx) +static void btrfs_release_extent_buffer_page (struct extent_buffer *eb) {unsigned long index; -unsigned long num_pages;struct page *page;int mapped = !test_bit (EXTENT_BUFFER_DUMMY , &eb->bflags);BUG_ON (extent_buffer_under_io (eb)); - num_pages =num_extent_pages (eb->start, eb->len); - index = start_idx + num_pages; -if (start_idx >= index) + index =num_extent_pages (eb->start, eb->len); +if (index ==0 )return ; do {
@@ -4498,7 +4495,7 @@ static void btrfs_release_extent_buffer_page(struct extent_buffer *eb,/* One for when we alloced the page */ page_cache_release (page); } - }while (index != start_idx); + }while (index !=0 ); }/*
@@ -4506,7 +4503,7 @@ static void btrfs_release_extent_buffer_page(struct extent_buffer *eb,*/ static inline void btrfs_release_extent_buffer (struct extent_buffer *eb) { -btrfs_release_extent_buffer_page (eb,0 ); +btrfs_release_extent_buffer_page (eb);__free_extent_buffer (eb); }
@@ -4863,7 +4860,7 @@ static int release_extent_buffer(struct extent_buffer *eb) }/* Should be safe to release our pages at this point */ -btrfs_release_extent_buffer_page (eb,0 ); +btrfs_release_extent_buffer_page (eb);call_rcu (&eb->rcu_head, btrfs_release_extent_buffer_rcu);return 1 ; }
Signature · 1 line
1.8.4.5
PATCH 12/14 btrfs: kill extent_buffer_page helper
In reply to David SterbaIt used to be more complex but now it's just a simple array access.
--- fs/btrfs/extent_io.c | 55 +++++++++++++++++++++++++--------------------------- fs/btrfs/extent_io.h | 6 ------ 2 files changed, 26 insertions(+), 35 deletions(-)
fs/btrfs/extent_io.c +26 -29
@@ -2064,7 +2064,7 @@ int repair_eb_io_failure(struct btrfs_root *root, struct extent_buffer *eb,return -EROFS ;for (i =0 ; i < num_pages; i++) { -struct page *p =extent_buffer_page (eb, i); +struct page *p = eb->pages[i]; ret = repair_io_failure(root->fs_info->btree_inode, start, PAGE_CACHE_SIZE, start, p,
@@ -3580,7 +3580,7 @@ lock_extent_buffer_for_io(struct extent_buffer *eb, num_pages =num_extent_pages (eb->start, eb->len);for (i =0 ; i < num_pages; i++) { -struct page *p =extent_buffer_page (eb, i); +struct page *p = eb->pages[i];if (!trylock_page (p)) {if (!flush) {
@@ -3651,7 +3651,7 @@ static noinline_for_stack int write_one_eb(struct extent_buffer *eb, bio_flags =EXTENT_BIO_TREE_LOG ;for (i =0 ; i < num_pages; i++) { -struct page *p =extent_buffer_page (eb, i); +struct page *p = eb->pages[i];clear_page_dirty_for_io (p);set_page_writeback (p);
@@ -3674,10 +3674,8 @@ static noinline_for_stack int write_one_eb(struct extent_buffer *eb, }if (unlikely (ret)) { -for (; i < num_pages; i++) { -struct page *p =extent_buffer_page (eb, i); -unlock_page (p); - } +for (; i < num_pages; i++) +unlock_page (eb->pages[i]); }return ret;
@@ -4464,7 +4462,7 @@ static void btrfs_release_extent_buffer_page(struct extent_buffer *eb) do { index--; - page = extent_buffer_page(eb, index); + page = eb->pages[index]; if (page && mapped) { spin_lock(&page->mapping->private_lock); /*
@@ -4646,7 +4644,8 @@ static void mark_extent_buffer_accessed(struct extent_buffer *eb, num_pages =num_extent_pages (eb->start, eb->len);for (i =0 ; i < num_pages; i++) { -struct page *p =extent_buffer_page (eb, i); +struct page *p = eb->pages[i]; +if (p != accessed)mark_page_accessed (p); }
@@ -4815,7 +4814,7 @@ again:*/ SetPageChecked (eb->pages[0 ]);for (i =1 ; i < num_pages; i++) { - p =extent_buffer_page (eb, i); + p = eb->pages[i];ClearPageChecked (p);unlock_page (p); }
@@ -4926,7 +4925,7 @@ void clear_extent_buffer_dirty(struct extent_buffer *eb) num_pages =num_extent_pages (eb->start, eb->len);for (i =0 ; i < num_pages; i++) { - page =extent_buffer_page (eb, i); + page = eb->pages[i];if (!PageDirty (page))continue ;
@@ -4962,7 +4961,7 @@ int set_extent_buffer_dirty(struct extent_buffer *eb)WARN_ON (!test_bit (EXTENT_BUFFER_TREE_REF , &eb->bflags));for (i =0 ; i < num_pages; i++) -set_page_dirty (extent_buffer_page (eb, i)); +set_page_dirty (eb->pages[i]);return was_dirty; }
@@ -4975,7 +4974,7 @@ int clear_extent_buffer_uptodate(struct extent_buffer *eb)clear_bit (EXTENT_BUFFER_UPTODATE , &eb->bflags); num_pages =num_extent_pages (eb->start, eb->len);for (i =0 ; i < num_pages; i++) { - page =extent_buffer_page (eb, i); + page = eb->pages[i];if (page)ClearPageUptodate (page); }
@@ -4991,7 +4990,7 @@ int set_extent_buffer_uptodate(struct extent_buffer *eb)set_bit (EXTENT_BUFFER_UPTODATE , &eb->bflags); num_pages =num_extent_pages (eb->start, eb->len);for (i =0 ; i < num_pages; i++) { - page =extent_buffer_page (eb, i); + page = eb->pages[i];SetPageUptodate (page); }return 0 ;
@@ -5031,7 +5030,7 @@ int read_extent_buffer_pages(struct extent_io_tree *tree, num_pages =num_extent_pages (eb->start, eb->len);for (i = start_i; i < num_pages; i++) { - page =extent_buffer_page (eb, i); + page = eb->pages[i];if (wait ==WAIT_NONE ) {if (!trylock_page (page)) goto unlock_exit;
@@ -5054,7 +5053,7 @@ int read_extent_buffer_pages(struct extent_io_tree *tree, eb->read_mirror =0 ;atomic_set (&eb->io_pages, num_reads);for (i = start_i; i < num_pages; i++) { - page =extent_buffer_page (eb, i); + page = eb->pages[i];if (!PageUptodate (page)) {ClearPageError (page); err = __extent_read_full_page(tree, page,
@@ -5079,7 +5078,7 @@ int read_extent_buffer_pages(struct extent_io_tree *tree,return ret;for (i = start_i; i < num_pages; i++) { - page =extent_buffer_page (eb, i); + page = eb->pages[i];wait_on_page_locked (page);if (!PageUptodate (page)) ret = -EIO ;
@@ -5090,7 +5089,7 @@ int read_extent_buffer_pages(struct extent_io_tree *tree, unlock_exit: i = start_i;while (locked_pages >0 ) { - page =extent_buffer_page (eb, i); + page = eb->pages[i]; i++;unlock_page (page); locked_pages--;
@@ -5116,7 +5115,7 @@ void read_extent_buffer(struct extent_buffer *eb, void *dstv, offset = (start_offset + start) & (PAGE_CACHE_SIZE -1 );while (len >0 ) { - page =extent_buffer_page (eb, i); + page = eb->pages[i]; cur =min (len, (PAGE_CACHE_SIZE - offset)); kaddr =page_address (page);
@@ -5148,7 +5147,7 @@ int read_extent_buffer_to_user(struct extent_buffer *eb, void __user *dstv, offset = (start_offset + start) & (PAGE_CACHE_SIZE -1 );while (len >0 ) { - page =extent_buffer_page (eb, i); + page = eb->pages[i]; cur =min (len, (PAGE_CACHE_SIZE - offset)); kaddr =page_address (page);
@@ -5197,7 +5196,7 @@ int map_private_extent_buffer(struct extent_buffer *eb, unsigned long start,return -EINVAL ; } - p =extent_buffer_page (eb, i); + p = eb->pages[i]; kaddr =page_address (p); *map = kaddr + offset; *map_len =PAGE_CACHE_SIZE - offset;
@@ -5223,7 +5222,7 @@ int memcmp_extent_buffer(struct extent_buffer *eb, const void *ptrv, offset = (start_offset + start) & (PAGE_CACHE_SIZE -1 );while (len >0 ) { - page =extent_buffer_page (eb, i); + page = eb->pages[i]; cur =min (len, (PAGE_CACHE_SIZE - offset));
@@ -5257,7 +5256,7 @@ void write_extent_buffer(struct extent_buffer *eb, const void *srcv, offset = (start_offset + start) & (PAGE_CACHE_SIZE -1 );while (len >0 ) { - page =extent_buffer_page (eb, i); + page = eb->pages[i];WARN_ON (!PageUptodate (page)); cur =min (len,PAGE_CACHE_SIZE - offset);
@@ -5287,7 +5286,7 @@ void memset_extent_buffer(struct extent_buffer *eb, char c, offset = (start_offset + start) & (PAGE_CACHE_SIZE -1 );while (len >0 ) { - page =extent_buffer_page (eb, i); + page = eb->pages[i];WARN_ON (!PageUptodate (page)); cur =min (len,PAGE_CACHE_SIZE - offset);
@@ -5318,7 +5317,7 @@ void copy_extent_buffer(struct extent_buffer *dst, struct extent_buffer *src, (PAGE_CACHE_SIZE -1 );while (len >0 ) { - page =extent_buffer_page (dst, i); + page = dst->pages[i];WARN_ON (!PageUptodate (page)); cur =min (len, (unsigned long )(PAGE_CACHE_SIZE - offset));
@@ -5396,8 +5395,7 @@ void memcpy_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset, cur = min_t(unsigned long, cur, (unsigned long )(PAGE_CACHE_SIZE - dst_off_in_page)); -copy_pages (extent_buffer_page (dst, dst_i), -extent_buffer_page (dst, src_i), +copy_pages (dst->pages[dst_i], dst->pages[src_i], dst_off_in_page, src_off_in_page, cur); src_offset += cur;
@@ -5443,8 +5441,7 @@ void memmove_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset, cur = min_t(unsigned long, len, src_off_in_page + 1); cur =min (cur, dst_off_in_page +1 ); -copy_pages (extent_buffer_page (dst, dst_i), -extent_buffer_page (dst, src_i), +copy_pages (dst->pages[dst_i], dst->pages[src_i], dst_off_in_page - cur +1 , src_off_in_page - cur +1 , cur);
fs/btrfs/extent_io.h +0 -6
@@ -279,12 +279,6 @@ static inline unsigned long num_extent_pages(u64 start, u64 len) (start >>PAGE_CACHE_SHIFT ); } -static inline struct page *extent_buffer_page (struct extent_buffer *eb, -unsigned long i) -{ -return eb->pages[i]; -} -static inline void extent_buffer_get (struct extent_buffer *eb) {atomic_inc (&eb->refs);
Signature · 1 line
1.8.4.5
PATCH 13/14 btrfs: new define for the inline extent data start
In reply to David SterbaUse a common definition for the inline data start so we don't have to open-code it and introduce bugs like "Btrfs: fix wrong max inline data size limit" fixed.
--- fs/btrfs/ctree.c | 3 +-- fs/btrfs/ctree.h | 16 ++++++++-------- 2 files changed, 9 insertions(+), 10 deletions(-)
fs/btrfs/ctree.c +1 -2
@@ -4625,8 +4625,7 @@ void btrfs_truncate_item(struct btrfs_root *root, struct btrfs_path *path, ptr =btrfs_item_ptr_offset (leaf, slot);memmove_extent_buffer (leaf, ptr, (unsigned long )fi, - offsetof(struct btrfs_file_extent_item , - disk_bytenr)); +BTRFS_FILE_EXTENT_INLINE_DATA_START ); } }
fs/btrfs/ctree.h +8 -8
@@ -385,9 +385,11 @@ struct btrfs_header { sizeof(struct btrfs_key_ptr))#define __BTRFS_LEAF_DATA_SIZE (bs) ((bs) - sizeof(struct btrfs_header))#define BTRFS_LEAF_DATA_SIZE (r) (__BTRFS_LEAF_DATA_SIZE(r->nodesize)) +#define BTRFS_FILE_EXTENT_INLINE_DATA_START \ + (offsetof(struct btrfs_file_extent_item, disk_bytenr))#define BTRFS_MAX_INLINE_DATA_SIZE (r) (BTRFS_LEAF_DATA_SIZE(r) - \ sizeof(struct btrfs_item) - \ - offsetof(struct btrfs_file_extent_item, disk_bytenr)) + BTRFS_FILE_EXTENT_INLINE_DATA_START)#define BTRFS_MAX_XATTR_SIZE (r) (BTRFS_LEAF_DATA_SIZE(r) - \ sizeof(struct btrfs_item) -\ sizeof(struct btrfs_dir_item))
@@ -896,6 +898,8 @@ struct btrfs_file_extent_item {/* * disk space consumed by the extent, checksum blocks are included * in these numbers +* +* At this offset in the structure, the inline extent data start. */ __le64 disk_bytenr;__le64 disk_num_bytes;
@@ -3043,14 +3047,12 @@ BTRFS_SETGET_STACK_FUNCS(stack_file_extent_compression,static inline unsigned long btrfs_file_extent_inline_start (struct btrfs_file_extent_item *e) { -unsigned long offset = (unsigned long )e; - offset += offsetof(struct btrfs_file_extent_item , disk_bytenr); -return offset; +return (unsigned long )e +BTRFS_FILE_EXTENT_INLINE_DATA_START ; }static inline u32 btrfs_file_extent_calc_inline_size (u32 datasize) { -return offsetof(struct btrfs_file_extent_item , disk_bytenr) + datasize; +return BTRFS_FILE_EXTENT_INLINE_DATA_START + datasize; } BTRFS_SETGET_FUNCS(file_extent_disk_bytenr, struct btrfs_file_extent_item,
@@ -3080,9 +3082,7 @@ BTRFS_SETGET_FUNCS(file_extent_other_encoding, struct btrfs_file_extent_item,static inline u32 btrfs_file_extent_inline_item_len (struct extent_buffer *eb,struct btrfs_item *e) { -unsigned long offset; - offset = offsetof(struct btrfs_file_extent_item , disk_bytenr); -return btrfs_item_size (eb, e) - offset; +return btrfs_item_size (eb, e) -BTRFS_FILE_EXTENT_INLINE_DATA_START ; }/* this returns the number of file bytes represented by the inline item.
Signature · 1 line
1.8.4.5
PATCH 14/14 btrfs: move checks for DUMMY_ROOT into a helper
In reply to David Sterba--- fs/btrfs/ctree.c | 5 ++--- fs/btrfs/ctree.h | 9 +++++++++ fs/btrfs/disk-io.c | 4 +--- fs/btrfs/extent-tree.c | 16 +++++++--------- fs/btrfs/qgroup.c | 10 ++++------ 5 files changed, 23 insertions(+), 21 deletions(-)
fs/btrfs/ctree.c +2 -3
@@ -1506,10 +1506,9 @@ static inline int should_cow_block(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct extent_buffer *buf) { -#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS - if (unlikely(test_bit(BTRFS_ROOT_DUMMY_ROOT, &root->state))) + if (btrfs_test_is_dummy_root(root)) return 0; -#endif + /* ensure we can see the force_cow */ smp_rmb();
fs/btrfs/ctree.h +9 -0
@@ -4131,4 +4131,13 @@ int btrfs_verify_qgroup_counts(struct btrfs_fs_info *fs_info, u64 qgroupid, u64 rfer, u64 excl);#endif +static inline int btrfs_test_is_dummy_root (struct btrfs_root *root) +{ +#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS +if (unlikely (test_bit (BTRFS_ROOT_DUMMY_ROOT , &root->state))) +return 1 ; +#endif +return 0 ; +} +#endif
fs/btrfs/disk-io.c +1 -3
@@ -1130,11 +1130,9 @@ struct extent_buffer *btrfs_find_tree_block(struct btrfs_root *root,struct extent_buffer *btrfs_find_create_tree_block (struct btrfs_root *root,u64 bytenr,u32 blocksize) { -#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS -if (unlikely (test_bit (BTRFS_ROOT_DUMMY_ROOT , &root->state))) +if (btrfs_test_is_dummy_root (root))return alloc_test_extent_buffer (root->fs_info, bytenr, blocksize); -#endif return alloc_extent_buffer (root->fs_info, bytenr, blocksize); }
fs/btrfs/extent-tree.c +7 -9
@@ -3073,10 +3073,10 @@ static int __btrfs_mod_ref(struct btrfs_trans_handle *trans,int (*process_func)(struct btrfs_trans_handle *,struct btrfs_root *,u64 ,u64 ,u64 ,u64 ,u64 ,u64 ,int ); -#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS -if (unlikely (test_bit (BTRFS_ROOT_DUMMY_ROOT , &root->state))) + +if (btrfs_test_is_dummy_root (root))return 0 ; -#endif + ref_root =btrfs_header_owner (buf); nritems =btrfs_header_nritems (buf); level =btrfs_header_level (buf);
@@ -6264,10 +6264,9 @@ int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root *root,int ret;struct btrfs_fs_info *fs_info = root->fs_info; -#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS -if (unlikely (test_bit (BTRFS_ROOT_DUMMY_ROOT , &root->state))) +if (btrfs_test_is_dummy_root (root))return 0 ; -#endif +add_pinned_bytes (root->fs_info, num_bytes, owner, root_objectid);/*
@@ -7336,15 +7335,14 @@ struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,bool skinny_metadata =btrfs_fs_incompat (root->fs_info,SKINNY_METADATA ); -#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS -if (unlikely (test_bit (BTRFS_ROOT_DUMMY_ROOT , &root->state))) { +if (btrfs_test_is_dummy_root (root)) { buf =btrfs_init_new_buffer (trans, root, root->alloc_bytenr, blocksize, level);if (!IS_ERR (buf)) root->alloc_bytenr += blocksize;return buf; } -#endif + block_rsv =use_block_rsv (trans, root, blocksize);if (IS_ERR (block_rsv))return ERR_CAST (block_rsv);
fs/btrfs/qgroup.c +4 -6
@@ -539,10 +539,9 @@ static int add_qgroup_item(struct btrfs_trans_handle *trans,struct extent_buffer *leaf;struct btrfs_key key; -#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS -if (unlikely (test_bit (BTRFS_ROOT_DUMMY_ROOT , "a_root->state))) +if (btrfs_test_is_dummy_root (quota_root))return 0 ; -#endif + path =btrfs_alloc_path ();if (!path)return -ENOMEM ;
@@ -698,10 +697,9 @@ static int update_qgroup_info_item(struct btrfs_trans_handle *trans,int ret;int slot; -#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS -if (unlikely (test_bit (BTRFS_ROOT_DUMMY_ROOT , &root->state))) +if (btrfs_test_is_dummy_root (root))return 0 ; -#endif + key.objectid =0 ; key.type =BTRFS_QGROUP_INFO_KEY ; key.offset = qgroup->qgroupid;
Signature · 1 line
1.8.4.5