From: Joel Becker <Joel.Becker@oracle.com>
To: ocfs2-devel@oss.oracle.com
Subject: [Ocfs2-devel] [PATCH 1/4] ocfs2: turn __ocfs2_remove_inode_range() into ocfs2_remove_btree_range()
Date: Wed, 12 Nov 2008 18:53:47 -0800 [thread overview]
Message-ID: <20081113025347.GB27602@mail.oracle.com> (raw)
In-Reply-To: <1226543048-911-2-git-send-email-mfasheh@suse.com>
On Wed, Nov 12, 2008 at 06:24:05PM -0800, Mark Fasheh wrote:
> This patch genericizes the high level handling of extent removal.
> ocfs2_remove_btree_range() is nearly identical to
> __ocfs2_remove_inode_range(), except that extent tree operations have been
> used where necessary. We update ocfs2_remove_inode_range() to use the
> generic helper. Now extent tree based structures have an easy way to
> truncate ranges.
>
> Signed-off-by: Mark Fasheh <mfasheh@suse.com>
I like it!
Signed-off-by: Joel Becker <joel.becker@oracle.com>
> ---
> fs/ocfs2/alloc.c | 72 +++++++++++++++++++++++++++++++++++++++++++++
> fs/ocfs2/alloc.h | 5 +++
> fs/ocfs2/file.c | 85 +++--------------------------------------------------
> 3 files changed, 82 insertions(+), 80 deletions(-)
>
> diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c
> index 4614614..5592a2f 100644
> --- a/fs/ocfs2/alloc.c
> +++ b/fs/ocfs2/alloc.c
> @@ -5255,6 +5255,78 @@ out:
> return ret;
> }
>
> +int ocfs2_remove_btree_range(struct inode *inode,
> + struct ocfs2_extent_tree *et,
> + u32 cpos, u32 phys_cpos, u32 len,
> + struct ocfs2_cached_dealloc_ctxt *dealloc)
> +{
> + int ret;
> + u64 phys_blkno = ocfs2_clusters_to_blocks(inode->i_sb, phys_cpos);
> + struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
> + struct inode *tl_inode = osb->osb_tl_inode;
> + handle_t *handle;
> + struct ocfs2_alloc_context *meta_ac = NULL;
> +
> + ret = ocfs2_lock_allocators(inode, et, 0, 1, NULL, &meta_ac);
> + if (ret) {
> + mlog_errno(ret);
> + return ret;
> + }
> +
> + mutex_lock(&tl_inode->i_mutex);
> +
> + if (ocfs2_truncate_log_needs_flush(osb)) {
> + ret = __ocfs2_flush_truncate_log(osb);
> + if (ret < 0) {
> + mlog_errno(ret);
> + goto out;
> + }
> + }
> +
> + handle = ocfs2_start_trans(osb, OCFS2_REMOVE_EXTENT_CREDITS);
> + if (IS_ERR(handle)) {
> + ret = PTR_ERR(handle);
> + mlog_errno(ret);
> + goto out;
> + }
> +
> + ret = ocfs2_journal_access(handle, inode, et->et_root_bh,
> + OCFS2_JOURNAL_ACCESS_WRITE);
> + if (ret) {
> + mlog_errno(ret);
> + goto out;
> + }
> +
> + ret = ocfs2_remove_extent(inode, et, cpos, len, handle, meta_ac,
> + dealloc);
> + if (ret) {
> + mlog_errno(ret);
> + goto out_commit;
> + }
> +
> + ocfs2_et_update_clusters(inode, et, -len);
> +
> + ret = ocfs2_journal_dirty(handle, et->et_root_bh);
> + if (ret) {
> + mlog_errno(ret);
> + goto out_commit;
> + }
> +
> + ret = ocfs2_truncate_log_append(osb, handle, phys_blkno, len);
> + if (ret)
> + mlog_errno(ret);
> +
> +out_commit:
> + ocfs2_commit_trans(osb, handle);
> +out:
> + mutex_unlock(&tl_inode->i_mutex);
> +
> + if (meta_ac)
> + ocfs2_free_alloc_context(meta_ac);
> +
> + return ret;
> +}
> +
> int ocfs2_truncate_log_needs_flush(struct ocfs2_super *osb)
> {
> struct buffer_head *tl_bh = osb->osb_tl_bh;
> diff --git a/fs/ocfs2/alloc.h b/fs/ocfs2/alloc.h
> index 3eb735e..0fbf8fc 100644
> --- a/fs/ocfs2/alloc.h
> +++ b/fs/ocfs2/alloc.h
> @@ -110,6 +110,11 @@ int ocfs2_remove_extent(struct inode *inode,
> u32 cpos, u32 len, handle_t *handle,
> struct ocfs2_alloc_context *meta_ac,
> struct ocfs2_cached_dealloc_ctxt *dealloc);
> +int ocfs2_remove_btree_range(struct inode *inode,
> + struct ocfs2_extent_tree *et,
> + u32 cpos, u32 phys_cpos, u32 len,
> + struct ocfs2_cached_dealloc_ctxt *dealloc);
> +
> int ocfs2_num_free_extents(struct ocfs2_super *osb,
> struct inode *inode,
> struct ocfs2_extent_tree *et);
> diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c
> index e2570a3..3605491 100644
> --- a/fs/ocfs2/file.c
> +++ b/fs/ocfs2/file.c
> @@ -1226,83 +1226,6 @@ out:
> return ret;
> }
>
> -static int __ocfs2_remove_inode_range(struct inode *inode,
> - struct buffer_head *di_bh,
> - u32 cpos, u32 phys_cpos, u32 len,
> - struct ocfs2_cached_dealloc_ctxt *dealloc)
> -{
> - int ret;
> - u64 phys_blkno = ocfs2_clusters_to_blocks(inode->i_sb, phys_cpos);
> - struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
> - struct inode *tl_inode = osb->osb_tl_inode;
> - handle_t *handle;
> - struct ocfs2_alloc_context *meta_ac = NULL;
> - struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data;
> - struct ocfs2_extent_tree et;
> -
> - ocfs2_init_dinode_extent_tree(&et, inode, di_bh);
> -
> - ret = ocfs2_lock_allocators(inode, &et, 0, 1, NULL, &meta_ac);
> - if (ret) {
> - mlog_errno(ret);
> - return ret;
> - }
> -
> - mutex_lock(&tl_inode->i_mutex);
> -
> - if (ocfs2_truncate_log_needs_flush(osb)) {
> - ret = __ocfs2_flush_truncate_log(osb);
> - if (ret < 0) {
> - mlog_errno(ret);
> - goto out;
> - }
> - }
> -
> - handle = ocfs2_start_trans(osb, OCFS2_REMOVE_EXTENT_CREDITS);
> - if (IS_ERR(handle)) {
> - ret = PTR_ERR(handle);
> - mlog_errno(ret);
> - goto out;
> - }
> -
> - ret = ocfs2_journal_access(handle, inode, di_bh,
> - OCFS2_JOURNAL_ACCESS_WRITE);
> - if (ret) {
> - mlog_errno(ret);
> - goto out;
> - }
> -
> - ret = ocfs2_remove_extent(inode, &et, cpos, len, handle, meta_ac,
> - dealloc);
> - if (ret) {
> - mlog_errno(ret);
> - goto out_commit;
> - }
> -
> - OCFS2_I(inode)->ip_clusters -= len;
> - di->i_clusters = cpu_to_le32(OCFS2_I(inode)->ip_clusters);
> -
> - ret = ocfs2_journal_dirty(handle, di_bh);
> - if (ret) {
> - mlog_errno(ret);
> - goto out_commit;
> - }
> -
> - ret = ocfs2_truncate_log_append(osb, handle, phys_blkno, len);
> - if (ret)
> - mlog_errno(ret);
> -
> -out_commit:
> - ocfs2_commit_trans(osb, handle);
> -out:
> - mutex_unlock(&tl_inode->i_mutex);
> -
> - if (meta_ac)
> - ocfs2_free_alloc_context(meta_ac);
> -
> - return ret;
> -}
> -
> /*
> * Truncate a byte range, avoiding pages within partial clusters. This
> * preserves those pages for the zeroing code to write to.
> @@ -1402,7 +1325,9 @@ static int ocfs2_remove_inode_range(struct inode *inode,
> struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
> struct ocfs2_cached_dealloc_ctxt dealloc;
> struct address_space *mapping = inode->i_mapping;
> + struct ocfs2_extent_tree et;
>
> + ocfs2_init_dinode_extent_tree(&et, inode, di_bh);
> ocfs2_init_dealloc_ctxt(&dealloc);
>
> if (byte_len == 0)
> @@ -1458,9 +1383,9 @@ static int ocfs2_remove_inode_range(struct inode *inode,
>
> /* Only do work for non-holes */
> if (phys_cpos != 0) {
> - ret = __ocfs2_remove_inode_range(inode, di_bh, cpos,
> - phys_cpos, alloc_size,
> - &dealloc);
> + ret = ocfs2_remove_btree_range(inode, &et, cpos,
> + phys_cpos, alloc_size,
> + &dealloc);
> if (ret) {
> mlog_errno(ret);
> goto out;
> --
> 1.5.4.1
>
--
Life's Little Instruction Book #451
"Don't be afraid to say, 'I'm sorry.'"
Joel Becker
Principal Software Developer
Oracle
E-mail: joel.becker at oracle.com
Phone: (650) 506-8127
next prev parent reply other threads:[~2008-11-13 2:53 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-13 2:24 [Ocfs2-devel] [RFC][PATCH 0/4] ocfs2: Directory indexing support Mark Fasheh
2008-11-13 2:24 ` [Ocfs2-devel] [PATCH 1/4] ocfs2: turn __ocfs2_remove_inode_range() into ocfs2_remove_btree_range() Mark Fasheh
2008-11-13 2:53 ` Joel Becker [this message]
2008-11-13 2:24 ` [Ocfs2-devel] [PATCH 2/4] ocfs2: Introduce dir lookup helper struct Mark Fasheh
2008-11-13 2:59 ` Joel Becker
2008-11-13 2:24 ` [Ocfs2-devel] [PATCH 3/4] ocfs2: Add a name indexed b-tree to directory inodes Mark Fasheh
2008-11-13 3:28 ` Joel Becker
2008-11-13 2:24 ` [Ocfs2-devel] [PATCH 4/4] ocfs2: Introduce dir free space list Mark Fasheh
2008-11-13 3:48 ` Joel Becker
2008-11-13 3:59 ` [Ocfs2-devel] [RFC][PATCH 0/4] ocfs2: Directory indexing support Joel Becker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20081113025347.GB27602@mail.oracle.com \
--to=joel.becker@oracle.com \
--cc=ocfs2-devel@oss.oracle.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.