Liu Bo
2012-Jul-10 11:28 UTC
[PATCH 1/2] Btrfs: fix btrfs_is_free_space_inode to recognize btree inode
For btree inode, its root is also ''tree root'', so btree inode can be misunderstood as a free space inode. We should add one more check for btree inode. Signed-off-by: Liu Bo <liubo2009@cn.fujitsu.com> --- fs/btrfs/btrfs_inode.h | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/btrfs_inode.h b/fs/btrfs/btrfs_inode.h index 12394a9..b168238 100644 --- a/fs/btrfs/btrfs_inode.h +++ b/fs/btrfs/btrfs_inode.h @@ -194,8 +194,10 @@ static inline void btrfs_i_size_write(struct inode *inode, u64 size) static inline bool btrfs_is_free_space_inode(struct btrfs_root *root, struct inode *inode) { - if (root == root->fs_info->tree_root || - BTRFS_I(inode)->location.objectid == BTRFS_FREE_INO_OBJECTID) + if (root == root->fs_info->tree_root && + btrfs_ino(inode) != BTRFS_BTREE_INODE_OBJECTID) + return true; + if (BTRFS_I(inode)->location.objectid == BTRFS_FREE_INO_OBJECTID) return true; return false; } -- 1.6.5.2 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Since root can be fetched via BTRFS_I macro directly, we can save an args for btrfs_is_free_space_inode(). Signed-off-by: Liu Bo <liubo2009@cn.fujitsu.com> --- fs/btrfs/btrfs_inode.h | 5 +++-- fs/btrfs/extent-tree.c | 2 +- fs/btrfs/file-item.c | 2 +- fs/btrfs/inode.c | 22 +++++++++++----------- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/fs/btrfs/btrfs_inode.h b/fs/btrfs/btrfs_inode.h index b168238..21b8cfe 100644 --- a/fs/btrfs/btrfs_inode.h +++ b/fs/btrfs/btrfs_inode.h @@ -191,9 +191,10 @@ static inline void btrfs_i_size_write(struct inode *inode, u64 size) BTRFS_I(inode)->disk_i_size = size; } -static inline bool btrfs_is_free_space_inode(struct btrfs_root *root, - struct inode *inode) +static inline bool btrfs_is_free_space_inode(struct inode *inode) { + struct btrfs_root *root = BTRFS_I(inode)->root; + if (root == root->fs_info->tree_root && btrfs_ino(inode) != BTRFS_BTREE_INODE_OBJECTID) return true; diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 6e1d367..07087f6 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -4444,7 +4444,7 @@ int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes) int ret; /* Need to be holding the i_mutex here if we aren''t free space cache */ - if (btrfs_is_free_space_inode(root, inode)) + if (btrfs_is_free_space_inode(inode)) flush = 0; if (flush && btrfs_transaction_in_commit(root->fs_info)) diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c index 5d158d3..af87025 100644 --- a/fs/btrfs/file-item.c +++ b/fs/btrfs/file-item.c @@ -183,7 +183,7 @@ static int __btrfs_lookup_bio_sums(struct btrfs_root *root, * read from the commit root and sidestep a nasty deadlock * between reading the free space cache and updating the csum tree. */ - if (btrfs_is_free_space_inode(root, inode)) { + if (btrfs_is_free_space_inode(inode)) { path->search_commit_root = 1; path->skip_locking = 1; } diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index a7d1921..5d463d4 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -825,7 +825,7 @@ static noinline int cow_file_range(struct inode *inode, struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree; int ret = 0; - BUG_ON(btrfs_is_free_space_inode(root, inode)); + BUG_ON(btrfs_is_free_space_inode(inode)); trans = btrfs_join_transaction(root); if (IS_ERR(trans)) { extent_clear_unlock_delalloc(inode, @@ -1153,7 +1153,7 @@ static noinline int run_delalloc_nocow(struct inode *inode, return -ENOMEM; } - nolock = btrfs_is_free_space_inode(root, inode); + nolock = btrfs_is_free_space_inode(inode); if (nolock) trans = btrfs_join_transaction_nolock(root); @@ -1466,7 +1466,7 @@ static void btrfs_set_bit_hook(struct inode *inode, if (!(state->state & EXTENT_DELALLOC) && (*bits & EXTENT_DELALLOC)) { struct btrfs_root *root = BTRFS_I(inode)->root; u64 len = state->end + 1 - state->start; - bool do_list = !btrfs_is_free_space_inode(root, inode); + bool do_list = !btrfs_is_free_space_inode(inode); if (*bits & EXTENT_FIRST_DELALLOC) { *bits &= ~EXTENT_FIRST_DELALLOC; @@ -1501,7 +1501,7 @@ static void btrfs_clear_bit_hook(struct inode *inode, if ((state->state & EXTENT_DELALLOC) && (*bits & EXTENT_DELALLOC)) { struct btrfs_root *root = BTRFS_I(inode)->root; u64 len = state->end + 1 - state->start; - bool do_list = !btrfs_is_free_space_inode(root, inode); + bool do_list = !btrfs_is_free_space_inode(inode); if (*bits & EXTENT_FIRST_DELALLOC) { *bits &= ~EXTENT_FIRST_DELALLOC; @@ -1612,7 +1612,7 @@ static int btrfs_submit_bio_hook(struct inode *inode, int rw, struct bio *bio, skip_sum = BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM; - if (btrfs_is_free_space_inode(root, inode)) + if (btrfs_is_free_space_inode(inode)) metadata = 2; if (!(rw & REQ_WRITE)) { @@ -1869,7 +1869,7 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent) int ret; bool nolock; - nolock = btrfs_is_free_space_inode(root, inode); + nolock = btrfs_is_free_space_inode(inode); if (test_bit(BTRFS_ORDERED_IOERR, &ordered_extent->flags)) { ret = -EIO; @@ -2007,7 +2007,7 @@ static int btrfs_writepage_end_io_hook(struct page *page, u64 start, u64 end, ordered_extent->work.func = finish_ordered_fn; ordered_extent->work.flags = 0; - if (btrfs_is_free_space_inode(root, inode)) + if (btrfs_is_free_space_inode(inode)) workers = &root->fs_info->endio_freespace_worker; else workers = &root->fs_info->endio_write_workers; @@ -2732,7 +2732,7 @@ noinline int btrfs_update_inode(struct btrfs_trans_handle *trans, * The data relocation inode should also be directly updated * without delay */ - if (!btrfs_is_free_space_inode(root, inode) + if (!btrfs_is_free_space_inode(inode) && root->root_key.objectid != BTRFS_DATA_RELOC_TREE_OBJECTID) { ret = btrfs_delayed_update_inode(trans, root, inode); if (!ret) @@ -3743,7 +3743,7 @@ void btrfs_evict_inode(struct inode *inode) truncate_inode_pages(&inode->i_data, 0); if (inode->i_nlink && (btrfs_root_refs(&root->root_item) != 0 || - btrfs_is_free_space_inode(root, inode))) + btrfs_is_free_space_inode(inode))) goto no_delete; if (is_bad_inode(inode)) { @@ -4457,7 +4457,7 @@ int btrfs_write_inode(struct inode *inode, struct writeback_control *wbc) if (test_bit(BTRFS_INODE_DUMMY, &BTRFS_I(inode)->runtime_flags)) return 0; - if (btrfs_fs_closing(root->fs_info) && btrfs_is_free_space_inode(root, inode)) + if (btrfs_fs_closing(root->fs_info) && btrfs_is_free_space_inode(inode)) nolock = true; if (wbc->sync_mode == WB_SYNC_ALL) { @@ -7046,7 +7046,7 @@ int btrfs_drop_inode(struct inode *inode) struct btrfs_root *root = BTRFS_I(inode)->root; if (btrfs_root_refs(&root->root_item) == 0 && - !btrfs_is_free_space_inode(root, inode)) + !btrfs_is_free_space_inode(inode)) return 1; else return generic_drop_inode(inode); -- 1.6.5.2 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
David Sterba
2012-Jul-17 13:43 UTC
Re: [PATCH 2/2] Btrfs: kill root from btrfs_is_free_space_inode
On Tue, Jul 10, 2012 at 07:28:39PM +0800, Liu Bo wrote:> Since root can be fetched via BTRFS_I macro directly, we can save an args > for btrfs_is_free_space_inode().I see a great opportunity to rename the function :) It does not cover just the free space inode anymore and it''ll be more confusing with the btree inode case. I don''t have a better name than btrfs_is_special_inode, but am not completely satisfied. david -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Liu Bo
2012-Jul-18 01:03 UTC
Re: [PATCH 2/2] Btrfs: kill root from btrfs_is_free_space_inode
On 07/17/2012 09:43 PM, David Sterba wrote:> On Tue, Jul 10, 2012 at 07:28:39PM +0800, Liu Bo wrote: >> Since root can be fetched via BTRFS_I macro directly, we can save an args >> for btrfs_is_free_space_inode(). > > I see a great opportunity to rename the function :) It does not cover > just the free space inode anymore and it''ll be more confusing with the > btree inode case. > > I don''t have a better name than btrfs_is_special_inode, but am not > completely satisfied. >Hi David, Seems that my patch''s title is confusing you... I made these patches to make this function return true if the inode is a free space inode or an inode cache inode, but not the btree inode. Or am I missing something? :) thanks, liubo> > david > -- > To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html >-- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Alex Lyakas
2012-Jul-18 10:02 UTC
Re: [PATCH 1/2] Btrfs: fix btrfs_is_free_space_inode to recognize btree inode
Hi Liu, can you pls explain this a bit more to me. I see in my fs that there are (FREE_SPACE,0, offset) items in the root tree. It seems that offset here is the objectid of the appropriate BLOCK_GROUP_ITEM. Also, I see that each FREE_SPACE points at some INODE_ITEM within the root tree, and this INODE_ITEM also has extents. I presume that these extents contain the free space cache in some format, is that correct? However, I don''t see any FREE_INO entries, what are they? Are they perhaps used only when "inode_cache" mount option is used, so inode numbers are not always incremented in btrfs_find_free_ino(), but smaller unused numbers are reused? Also, I don''t see anywhere BTRFS_BTREE_INODE_OBJECTID in the tree root tree. So what is this "btree inode" that you mention? Thanks, Alex. On Tue, Jul 10, 2012 at 2:28 PM, Liu Bo <liubo2009@cn.fujitsu.com> wrote:> For btree inode, its root is also ''tree root'', so btree inode can be > misunderstood as a free space inode. > > We should add one more check for btree inode. > > Signed-off-by: Liu Bo <liubo2009@cn.fujitsu.com> > --- > fs/btrfs/btrfs_inode.h | 6 ++++-- > 1 files changed, 4 insertions(+), 2 deletions(-) > > diff --git a/fs/btrfs/btrfs_inode.h b/fs/btrfs/btrfs_inode.h > index 12394a9..b168238 100644 > --- a/fs/btrfs/btrfs_inode.h > +++ b/fs/btrfs/btrfs_inode.h > @@ -194,8 +194,10 @@ static inline void btrfs_i_size_write(struct inode *inode, u64 size) > static inline bool btrfs_is_free_space_inode(struct btrfs_root *root, > struct inode *inode) > { > - if (root == root->fs_info->tree_root || > - BTRFS_I(inode)->location.objectid == BTRFS_FREE_INO_OBJECTID) > + if (root == root->fs_info->tree_root && > + btrfs_ino(inode) != BTRFS_BTREE_INODE_OBJECTID) > + return true; > + if (BTRFS_I(inode)->location.objectid == BTRFS_FREE_INO_OBJECTID) > return true; > return false; > } > -- > 1.6.5.2 > > -- > To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html-- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Liu Bo
2012-Jul-18 12:02 UTC
Re: [PATCH 1/2] Btrfs: fix btrfs_is_free_space_inode to recognize btree inode
On 07/18/2012 06:02 PM, Alex Lyakas wrote:> Hi Liu, > can you pls explain this a bit more to me. > I see in my fs that there are (FREE_SPACE,0, offset) items in the root > tree. It seems that offset here is the objectid of the appropriate > BLOCK_GROUP_ITEM. Also, I see that each FREE_SPACE points at some > INODE_ITEM within the root tree, and this INODE_ITEM also has extents. > I presume that these extents contain the free space cache in some > format, is that correct? >More or less. As its name shows, a free space inode''s data (you name it extents) consists of free space info, meanwhile, a free space inode is issued to a block group, so the free space info actually stands for free space in the block group: |<- a block group len ->| |----vvv----vvv-------vvv-----| ''v'' : occupied. ''-'' : available. (free space) these free space info are indexed in a rbtree in memory, and each entry has [start, len].> However, I don''t see any FREE_INO entries, what are they? Are they > perhaps used only when "inode_cache" mount option is used, so inode > numbers are not always incremented in btrfs_find_free_ino(), but > smaller unused numbers are reused? >Yes, that''s what it is used for.> Also, I don''t see anywhere BTRFS_BTREE_INODE_OBJECTID in the tree root > tree. So what is this "btree inode" that you mention? >The code refers to disk_io.c, in the function ''open_ctree()'' you can see the definition. Basically btree inode''s data stands for btrfs''s metadata, I think you can find something in btrfs''s wiki page? And thanks for your energy on btrfs! :) thanks, liubo> Thanks, > Alex. > > > On Tue, Jul 10, 2012 at 2:28 PM, Liu Bo <liubo2009@cn.fujitsu.com> wrote: >> For btree inode, its root is also ''tree root'', so btree inode can be >> misunderstood as a free space inode. >> >> We should add one more check for btree inode. >> >> Signed-off-by: Liu Bo <liubo2009@cn.fujitsu.com> >> --- >> fs/btrfs/btrfs_inode.h | 6 ++++-- >> 1 files changed, 4 insertions(+), 2 deletions(-) >> >> diff --git a/fs/btrfs/btrfs_inode.h b/fs/btrfs/btrfs_inode.h >> index 12394a9..b168238 100644 >> --- a/fs/btrfs/btrfs_inode.h >> +++ b/fs/btrfs/btrfs_inode.h >> @@ -194,8 +194,10 @@ static inline void btrfs_i_size_write(struct inode *inode, u64 size) >> static inline bool btrfs_is_free_space_inode(struct btrfs_root *root, >> struct inode *inode) >> { >> - if (root == root->fs_info->tree_root || >> - BTRFS_I(inode)->location.objectid == BTRFS_FREE_INO_OBJECTID) >> + if (root == root->fs_info->tree_root && >> + btrfs_ino(inode) != BTRFS_BTREE_INODE_OBJECTID) >> + return true; >> + if (BTRFS_I(inode)->location.objectid == BTRFS_FREE_INO_OBJECTID) >> return true; >> return false; >> } >> -- >> 1.6.5.2 >> >> -- >> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in >> the body of a message to majordomo@vger.kernel.org >> More majordomo info at http://vger.kernel.org/majordomo-info.html > -- > To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html >-- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Alex Lyakas
2012-Jul-18 12:39 UTC
Re: [PATCH 1/2] Btrfs: fix btrfs_is_free_space_inode to recognize btree inode
On Wed, Jul 18, 2012 at 3:02 PM, Liu Bo <liubo2009@cn.fujitsu.com> wrote:> On 07/18/2012 06:02 PM, Alex Lyakas wrote: > > More or less. > > As its name shows, a free space inode''s data (you name it extents) consists of > free space info, meanwhile, a free space inode is issued to a block group, > so the free space info actually stands for free space in the block group: > > |<- a block group len ->| > |----vvv----vvv-------vvv-----| > > ''v'' : occupied. > ''-'' : available. (free space) > > these free space info are indexed in a rbtree in memory, and each entry has [start, len].Thanks, it makes sense with what I saw in the code, just could not figure how this free-space inode''s data is being read into memory.> >> Also, I don''t see anywhere BTRFS_BTREE_INODE_OBJECTID in the tree root >> tree. So what is this "btree inode" that you mention? >> > > > The code refers to disk_io.c, in the function ''open_ctree()'' you can see the definition. >I saw it there, but not on disk. So now I see that it''s kind of a special "top" inode, used for ... something, and this inode is not stored anywhere on-disk. Thanks, now I understand your patch. Also, I understand now that FREE_INO items sit in the subvolume file tree (and perhaps also in the root tree), because they need to track free inos for distinct ino spaces.> Basically btree inode''s data stands for btrfs''s metadata, I think you can find something > in btrfs''s wiki page?> > > And thanks for your energy on btrfs! :)Thanks for helping. Alex. -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html