All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dave Hansen <haveblue@us.ibm.com>
To: akpm@osdl.org
Cc: linux-kernel@vger.kernel.org, hch@infradead.org,
	Dave Hansen <haveblue@us.ibm.com>
Subject: [PATCH 5/6] clean up OCFS2 nlink handling
Date: Wed, 09 Aug 2006 09:57:33 -0700	[thread overview]
Message-ID: <20060809165733.704AD0F5@localhost.localdomain> (raw)
In-Reply-To: <20060809165729.FE36B262@localhost.localdomain>


OCFS2 does some operations on i_nlink, then reverts them if some
of its operations fail to complete.  This does not fit in well
with the drop_nlink() logic where we expect i_nlink to stay at
zero once it gets there.

So, delay all of the nlink operations until we're sure that the
operations have completed.  Also, introduce a small helper to
check whether an inode has proper "unlinkable" i_nlink counts
no matter whether it is a directory or regular inode.

This patch is broken out from the others because it does contain
some logical changes.

Signed-off-by: Dave Hansen <haveblue@us.ibm.com>
Signed-off-by: Mark Fasheh <mark.fasheh@oracle.com>
---

 arch/i386/kernel/setup.c  |    0 
 lxc-dave/fs/ocfs2/namei.c |   45 ++++++++++++++++++++++++---------------------
 2 files changed, 24 insertions(+), 21 deletions(-)

diff -puN fs/ocfs2/namei.c~B5-clean_up_OCFS2_nlink_handling fs/ocfs2/namei.c
--- lxc/fs/ocfs2/namei.c~B5-clean_up_OCFS2_nlink_handling	2006-08-08 09:18:54.000000000 -0700
+++ lxc-dave/fs/ocfs2/namei.c	2006-08-08 09:18:56.000000000 -0700
@@ -744,11 +744,23 @@ bail:
 	return err;
 }
 
+static inline int inode_is_unlinkable(struct inode *inode)
+{
+	if (S_ISDIR(inode->i_mode)) {
+	       	if (inode->i_nlink == 2)
+			return 1;
+		return 0;
+	}
+
+	if (inode->i_nlink == 1)
+		return 1;
+	return 0;
+}
+
 static int ocfs2_unlink(struct inode *dir,
 			struct dentry *dentry)
 {
 	int status;
-	unsigned int saved_nlink = 0;
 	struct inode *inode = dentry->d_inode;
 	struct ocfs2_super *osb = OCFS2_SB(dir->i_sb);
 	u64 blkno;
@@ -760,6 +772,7 @@ static int ocfs2_unlink(struct inode *di
 	struct buffer_head *dirent_bh = NULL;
 	char orphan_name[OCFS2_ORPHAN_NAMELEN + 1];
 	struct buffer_head *orphan_entry_bh = NULL;
+	unsigned int future_nlink;
 
 	mlog_entry("(0x%p, 0x%p, '%.*s')\n", dir, dentry,
 		   dentry->d_name.len, dentry->d_name.name);
@@ -823,18 +836,11 @@ static int ocfs2_unlink(struct inode *di
 		}
 	}
 
-	/* There are still a few steps left until we can consider the
-	 * unlink to have succeeded. Save off nlink here before
-	 * modification so we can set it back in case we hit an issue
-	 * before commit. */
-	saved_nlink = inode->i_nlink;
-	if (S_ISDIR(inode->i_mode))
-		inode->i_nlink = 0;
+	if (S_ISDIR(inode->i_mode) && (inode->i_nlink == 2))
+		future_nlink = 0;
 	else
-		inode->i_nlink--;
-
-	status = ocfs2_request_unlink_vote(inode, dentry,
-					   (unsigned int) inode->i_nlink);
+		future_nlink = inode->i_nlink - 1;
+	status = ocfs2_request_unlink_vote(inode, dentry, future_nlink);
 	if (status < 0) {
 		/* This vote should succeed under all normal
 		 * circumstances. */
@@ -842,7 +848,7 @@ static int ocfs2_unlink(struct inode *di
 		goto leave;
 	}
 
-	if (!inode->i_nlink) {
+	if (inode_is_unlinkable(inode)) {
 		status = ocfs2_prepare_orphan_dir(osb, handle, inode,
 						  orphan_name,
 						  &orphan_entry_bh);
@@ -869,7 +875,7 @@ static int ocfs2_unlink(struct inode *di
 
 	fe = (struct ocfs2_dinode *) fe_bh->b_data;
 
-	if (!inode->i_nlink) {
+	if (inode_is_unlinkable(inode)) {
 		status = ocfs2_orphan_add(osb, handle, inode, fe, orphan_name,
 					  orphan_entry_bh);
 		if (status < 0) {
@@ -885,10 +891,10 @@ static int ocfs2_unlink(struct inode *di
 		goto leave;
 	}
 
-	/* We can set nlink on the dinode now. clear the saved version
-	 * so that it doesn't get set later. */
+	if (S_ISDIR(inode->i_mode))
+		drop_nlink(inode);
+	drop_nlink(inode);
 	fe->i_links_count = cpu_to_le16(inode->i_nlink);
-	saved_nlink = 0;
 
 	status = ocfs2_journal_dirty(handle, fe_bh);
 	if (status < 0) {
@@ -897,7 +903,7 @@ static int ocfs2_unlink(struct inode *di
 	}
 
 	if (S_ISDIR(inode->i_mode)) {
-		dir->i_nlink--;
+		drop_nlink(dir);
 		status = ocfs2_mark_inode_dirty(handle, dir,
 						parent_node_bh);
 		if (status < 0) {
@@ -907,9 +913,6 @@ static int ocfs2_unlink(struct inode *di
 	}
 
 leave:
-	if (status < 0 && saved_nlink)
-		inode->i_nlink = saved_nlink;
-
 	if (handle)
 		ocfs2_commit_trans(handle);
 
diff -puN arch/i386/kernel/setup.c~B5-clean_up_OCFS2_nlink_handling arch/i386/kernel/setup.c
_

  parent reply	other threads:[~2006-08-09 16:59 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-09 16:57 [PATCH 0/6] read-only bind mount prep work Dave Hansen
2006-08-09 16:57 ` [PATCH 1/6] prepare for write access checks: collapse if() Dave Hansen
2006-08-09 17:09   ` Christoph Hellwig
2006-08-09 17:18     ` Dave Hansen
2006-08-09 16:57 ` [PATCH 2/6] r/o bind mount prepwork: move open_namei()'s vfs_create() Dave Hansen
2006-08-09 17:09   ` Christoph Hellwig
2006-08-09 16:57 ` [PATCH 3/6] unlink: monitor i_nlink Dave Hansen
2006-08-09 17:11   ` Christoph Hellwig
2006-08-09 17:17     ` Dave Hansen
2006-08-09 18:27       ` Andrew Morton
2006-08-12 14:15         ` Arnd Bergmann
2006-08-09 16:57 ` [PATCH 4/6] r/o bind mount prepwork: inc_nlink() helper Dave Hansen
2006-08-09 17:11   ` Christoph Hellwig
2006-08-09 16:57 ` Dave Hansen [this message]
2006-08-09 17:12   ` [PATCH 5/6] clean up OCFS2 nlink handling Christoph Hellwig
2006-08-09 19:15     ` Dave Hansen
2006-08-10  8:07       ` Steven Whitehouse
2006-08-10 19:06         ` Dave Hansen
2006-08-11  9:38           ` Steven Whitehouse
2006-08-09 16:57 ` [PATCH 6/6] monitor zeroing of i_nlink Dave Hansen
2006-08-09 17:14   ` Christoph Hellwig

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=20060809165733.704AD0F5@localhost.localdomain \
    --to=haveblue@us.ibm.com \
    --cc=akpm@osdl.org \
    --cc=hch@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    /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.