All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tao Ma <tao.ma@oracle.com>
To: ocfs2-devel@oss.oracle.com
Subject: [Ocfs2-devel] [PATCH 30/41] ocfs2: Call refcount tree remove process properly.
Date: Tue, 18 Aug 2009 14:19:31 +0800	[thread overview]
Message-ID: <1250576382-27080-30-git-send-email-tao.ma@oracle.com> (raw)
In-Reply-To: <4A8A47DF.8020707@oracle.com>

Now with xattr refcount support, we need to check whether
we have xattr refcounted before we remove the refcount tree.

Now the mechanism is:
1) Check whether i_clusters == 0, if no, exit.
2) check whether we have i_xattr_loc in dinode. if yes, exit.
2) Check whether we have inline xattr stored outside, if yes, exit.
4) Remove the tree.

Signed-off-by: Tao Ma <tao.ma@oracle.com>
---
 fs/ocfs2/file.c         |    2 ++
 fs/ocfs2/inode.c        |    7 +++++++
 fs/ocfs2/refcounttree.c |   36 ++++++++++++++++++++++++++++++++++++
 fs/ocfs2/refcounttree.h |    3 +++
 fs/ocfs2/xattr.c        |   23 +++++++++++++++++++++++
 fs/ocfs2/xattr.h        |    2 ++
 6 files changed, 73 insertions(+), 0 deletions(-)

diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c
index 1254d72..ccbcc82 100644
--- a/fs/ocfs2/file.c
+++ b/fs/ocfs2/file.c
@@ -531,6 +531,8 @@ bail_unlock_sem:
 	up_write(&OCFS2_I(inode)->ip_alloc_sem);
 
 bail:
+	if (!status && OCFS2_I(inode)->ip_clusters == 0)
+		status = ocfs2_try_remove_refcount_tree(inode, di_bh);
 
 	mlog_exit(status);
 	return status;
diff --git a/fs/ocfs2/inode.c b/fs/ocfs2/inode.c
index e82ceb3..0297fb8 100644
--- a/fs/ocfs2/inode.c
+++ b/fs/ocfs2/inode.c
@@ -53,6 +53,7 @@
 #include "sysfile.h"
 #include "uptodate.h"
 #include "xattr.h"
+#include "refcounttree.h"
 
 #include "buffer_head_io.h"
 
@@ -782,6 +783,12 @@ static int ocfs2_wipe_inode(struct inode *inode,
 		goto bail_unlock_dir;
 	}
 
+	status = ocfs2_remove_refcount_tree(inode, di_bh);
+	if (status < 0) {
+		mlog_errno(status);
+		goto bail_unlock_dir;
+	}
+
 	status = ocfs2_remove_inode(inode, di_bh, orphan_dir_inode,
 				    orphan_dir_bh);
 	if (status < 0)
diff --git a/fs/ocfs2/refcounttree.c b/fs/ocfs2/refcounttree.c
index 9638e46..aec8bf1 100644
--- a/fs/ocfs2/refcounttree.c
+++ b/fs/ocfs2/refcounttree.c
@@ -925,6 +925,42 @@ out:
 }
 
 /*
+ * Try to remove refcount tree. The mechanism is:
+ * 1) Check whether i_clusters == 0, if no, exit.
+ * 2) check whether we have i_xattr_loc in dinode. if yes, exit.
+ * 3) Check whether we have inline xattr stored outside, if yes, exit.
+ * 4) Remove the tree.
+ */
+int ocfs2_try_remove_refcount_tree(struct inode *inode,
+				   struct buffer_head *di_bh)
+{
+	int ret;
+	struct ocfs2_inode_info *oi = OCFS2_I(inode);
+	struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data;
+
+	down_write(&oi->ip_xattr_sem);
+	down_write(&oi->ip_alloc_sem);
+
+	if (oi->ip_clusters)
+		goto out;
+
+	if ((oi->ip_dyn_features & OCFS2_HAS_XATTR_FL) && di->i_xattr_loc)
+		goto out;
+
+	if (oi->ip_dyn_features & OCFS2_INLINE_XATTR_FL &&
+	    ocfs2_has_inline_xattr_value_outside(inode, di))
+		goto out;
+
+	ret = ocfs2_remove_refcount_tree(inode, di_bh);
+	if (ret)
+		mlog_errno(ret);
+out:
+	up_write(&oi->ip_alloc_sem);
+	up_write(&oi->ip_xattr_sem);
+	return 0;
+}
+
+/*
  * Given a cpos and len, try to find the refcount record which contains cpos.
  * 1. If cpos can be found in one refcount record, return the record.
  * 2. If cpos can't be found, return a fake record which start from cpos
diff --git a/fs/ocfs2/refcounttree.h b/fs/ocfs2/refcounttree.h
index 7796d1a..e46406a 100644
--- a/fs/ocfs2/refcounttree.h
+++ b/fs/ocfs2/refcounttree.h
@@ -90,4 +90,7 @@ int ocfs2_add_refcount_flag(struct inode *inode,
 			    u32 cpos, u32 p_cluster, u32 num_clusters,
 			    struct ocfs2_cached_dealloc_ctxt *dealloc,
 			    struct ocfs2_post_refcount *post);
+int ocfs2_remove_refcount_tree(struct inode *inode, struct buffer_head *di_bh);
+int ocfs2_try_remove_refcount_tree(struct inode *inode,
+				   struct buffer_head *di_bh);
 #endif /* OCFS2_REFCOUNTTREE_H */
diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c
index 9c3be01..7f9c3ac 100644
--- a/fs/ocfs2/xattr.c
+++ b/fs/ocfs2/xattr.c
@@ -840,6 +840,23 @@ static int ocfs2_xattr_list_entries(struct inode *inode,
 	return result;
 }
 
+int ocfs2_has_inline_xattr_value_outside(struct inode *inode,
+					 struct ocfs2_dinode *di)
+{
+	struct ocfs2_xattr_header *xh;
+	int i;
+
+	xh = (struct ocfs2_xattr_header *)
+		 ((void *)di + inode->i_sb->s_blocksize -
+		 le16_to_cpu(di->i_xattr_inline_size));
+
+	for (i = 0; i < le16_to_cpu(xh->xh_count); i++)
+		if (!ocfs2_xattr_is_local(&xh->xh_entries[i]))
+			return 1;
+
+	return 0;
+}
+
 static int ocfs2_xattr_ibody_list(struct inode *inode,
 				  struct ocfs2_dinode *di,
 				  char *buffer,
@@ -2898,10 +2915,16 @@ int ocfs2_xattr_set(struct inode *inode,
 	if (ocfs2_dealloc_has_cluster(&ctxt.dealloc))
 		ocfs2_schedule_truncate_log_flush(osb, 1);
 	ocfs2_run_deallocs(osb, &ctxt.dealloc);
+
 cleanup:
 	if (ref_tree)
 		ocfs2_unlock_refcount_tree(osb, ref_tree, 1);
 	up_write(&OCFS2_I(inode)->ip_xattr_sem);
+	if (!value && !ret) {
+		ret = ocfs2_try_remove_refcount_tree(inode, di_bh);
+		if (ret)
+			mlog_errno(ret);
+	}
 	ocfs2_inode_unlock(inode, 1);
 cleanup_nolock:
 	brelse(di_bh);
diff --git a/fs/ocfs2/xattr.h b/fs/ocfs2/xattr.h
index a3295d7..e74703f 100644
--- a/fs/ocfs2/xattr.h
+++ b/fs/ocfs2/xattr.h
@@ -55,6 +55,8 @@ int ocfs2_xattr_set_handle(handle_t *, struct inode *, struct buffer_head *,
 			   int, const char *, const void *, size_t, int,
 			   struct ocfs2_alloc_context *,
 			   struct ocfs2_alloc_context *);
+int ocfs2_has_inline_xattr_value_outside(struct inode *inode,
+					 struct ocfs2_dinode *di);
 int ocfs2_xattr_remove(struct inode *, struct buffer_head *);
 int ocfs2_init_security_get(struct inode *, struct inode *,
 			    struct ocfs2_security_xattr_info *);
-- 
1.6.2.rc2.16.gf474c

  parent reply	other threads:[~2009-08-18  6:19 UTC|newest]

Thread overview: 75+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-18  6:19 [Ocfs2-devel] [PATCH 00/41] ocfs2: Add reflink file support. V4 Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 01/41] ocfs2: Define refcount tree structure Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 02/41] ocfs2: Add metaecc for ocfs2_refcount_block Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 03/41] ocfs2: Add ocfs2_read_refcount_block Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 04/41] ocfs2: Abstract caching info checkpoint Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 05/41] ocfs2: Add new refcount tree lock resource in dlmglue Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 06/41] ocfs2: Add caching info for refcount tree Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 07/41] ocfs2: Add refcount tree lock mechanism Tao Ma
2009-08-19 23:25   ` Joel Becker
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 08/41] ocfs2: Basic tree root operation Tao Ma
2009-08-19 23:30   ` Joel Becker
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 09/41] ocfs2: Wrap ocfs2_extent_contig in ocfs2_extent_tree Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 10/41] ocfs2: Abstract extent split process Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 11/41] ocfs2: Add refcount b-tree as a new extent tree Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 12/41] ocfs2: move tree path functions to alloc.h Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 13/41] ocfs2: Add support for incrementing refcount in the tree Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 14/41] ocfs2: Add support of decrementing refcount for delete Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 15/41] ocfs2: Add functions for extents refcounted Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 16/41] ocfs2: Decrement refcount when truncating refcounted extents Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 17/41] ocfs2: Add CoW support Tao Ma
2009-08-21  0:59   ` Joel Becker
2009-08-21  2:04     ` Tao Ma
2009-08-21  2:51       ` Joel Becker
2009-08-21  3:04         ` Tao Ma
2009-08-21  7:10           ` Joel Becker
2009-08-21  3:55         ` Joel Becker
2009-08-21  6:25           ` Tao Ma
2009-08-21  7:07             ` Joel Becker
2009-08-21  8:24               ` Tao Ma
2009-08-21 18:39                 ` Joel Becker
2009-08-21 20:58                   ` Joel Becker
2009-08-24 15:04                     ` Tao Ma
2009-08-24 18:20                       ` Joel Becker
2009-08-25 19:30                       ` Joel Becker
2009-08-26  8:17                         ` TaoMa
2009-08-21 23:07                   ` Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 18/41] ocfs2: CoW refcount tree improvement Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 19/41] ocfs2: Integrate CoW in file write Tao Ma
2009-08-21  1:04   ` Joel Becker
2009-08-21  2:12     ` Tao Ma
2009-08-21 14:55       ` Tao Ma
2009-08-21 20:43         ` Joel Becker
2009-08-21 21:12   ` Joel Becker
2009-08-21 23:17     ` Tao Ma
2009-08-21 23:42       ` Joel Becker
2009-08-22  0:31         ` Tao Ma
2009-08-24 15:06         ` Tao Ma
2009-08-24 18:32           ` Joel Becker
2009-08-25  0:12             ` [Ocfs2-devel] [PATCH 19/41] ocfs2: Integrate CoW in file write(add refcount check) Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 20/41] ocfs2: CoW a reflinked cluster when it is truncated Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 21/41] ocfs2: Add normal functions for reflink a normal file's extents Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 22/41] ocfs2: handle file attributes issue for reflink Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 23/41] ocfs2: Return extent flags for xattr value tree Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 24/41] ocfs2: Abstract duplicate clusters process in CoW Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 25/41] ocfs2: Add CoW support for xattr Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 26/41] ocfs2: Remove inode from ocfs2_xattr_bucket_get_name_value Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 27/41] ocfs2: Abstract the creation of xattr block Tao Ma
2009-08-21  1:22   ` Joel Becker
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 28/41] ocfs2: Abstract ocfs2 xattr tree extend rec iteration process Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 29/41] ocfs2: Attach xattr clusters to refcount tree Tao Ma
2009-08-18  6:19 ` Tao Ma [this message]
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 31/41] ocfs2: Create an xattr indexed block if needed Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 32/41] ocfs2: Add reflink support for xattr Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 33/41] ocfs2: Modify removing xattr process for refcount Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 34/41] ocfs2: Don't merge in 1st refcount ops of reflink Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 35/41] ocfs2: Make transaction extend more efficient Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 36/41] ocfs2: Use proper parameter for some inode operation Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 37/41] ocfs2: Create reflinked file in orphan dir Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 38/41] ocfs2: Add preserve to reflink Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 39/41] ocfs2: Implement ocfs2_reflink Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 40/41] ocfs2: Enable refcount tree support Tao Ma
2009-08-18  6:19 ` [Ocfs2-devel] [PATCH 41/41] ocfs2: Add ioctl for reflink Tao Ma
2009-08-21  1:24 ` [Ocfs2-devel] [PATCH 00/41] ocfs2: Add reflink file support. V4 Joel Becker
2009-08-21  1:39   ` Tao Ma
2009-08-24 23:11   ` TaoMa

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=1250576382-27080-30-git-send-email-tao.ma@oracle.com \
    --to=tao.ma@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.