mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Josef 'Jeff' Sipek" <jsipek@cs.sunysb.edu>
To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org
Cc: akpm@linux-foundation.org, "Josef 'Jeff' Sipek" <jsipek@cs.sunysb.edu>
Subject: [PATCH 12/16] Unionfs: Cleanup new_dentry_private_data
Date: Sun, 17 Jun 2007 15:09:19 -0400	[thread overview]
Message-ID: <11821073643856-git-send-email-jsipek@cs.sunysb.edu> (raw)
In-Reply-To: <11821073632989-git-send-email-jsipek@cs.sunysb.edu>

Signed-off-by: Josef 'Jeff' Sipek <jsipek@cs.sunysb.edu>
---
 fs/unionfs/lookup.c |   96 +++++++++++++++++++++++++++++++-------------------
 fs/unionfs/union.h  |    1 +
 2 files changed, 60 insertions(+), 37 deletions(-)

diff --git a/fs/unionfs/lookup.c b/fs/unionfs/lookup.c
index 758c813..246a67a 100644
--- a/fs/unionfs/lookup.c
+++ b/fs/unionfs/lookup.c
@@ -106,11 +106,22 @@ struct dentry *unionfs_lookup_backend(struct dentry *dentry,
 		BUG_ON(UNIONFS_D(dentry) != NULL);
 		locked_child = 1;
 	}
-	if (lookupmode != INTERPOSE_PARTIAL) {
-		if ((err = new_dentry_private_data(dentry)))
-			goto out;
-		allocated_new_info = 1;
+
+	switch(lookupmode) {
+		case INTERPOSE_PARTIAL:
+			break;
+		case INTERPOSE_LOOKUP:
+			if ((err = new_dentry_private_data(dentry)))
+				goto out;
+			allocated_new_info = 1;
+			break;
+		default:
+			if ((err = realloc_dentry_private_data(dentry)))
+				goto out;
+			allocated_new_info = 1;
+			break;
 	}
+
 	/* must initialize dentry operations */
 	dentry->d_op = &unionfs_dops;
 
@@ -448,58 +459,69 @@ void free_dentry_private_data(struct unionfs_dentry_info *udi)
 	kmem_cache_free(unionfs_dentry_cachep, udi);
 }
 
-/* allocate new dentry private data, free old one if necessary */
-int new_dentry_private_data(struct dentry *dentry)
+static inline int __realloc_dentry_private_data(struct dentry *dentry)
 {
-	int size;
 	struct unionfs_dentry_info *info = UNIONFS_D(dentry);
 	void *p;
-	int unlock_on_err = 0;
-
-	spin_lock(&dentry->d_lock);
-	if (!info) {
-		dentry->d_fsdata = kmem_cache_alloc(unionfs_dentry_cachep,
-						    GFP_ATOMIC);
-		
-		info = UNIONFS_D(dentry);
-		if (!info)
-			goto out;
+	int size;
 
-		mutex_init(&info->lock);
-		mutex_lock(&info->lock);
-		unlock_on_err = 1;
+	BUG_ON(!info);
 
-		info->lower_paths = NULL;
-	}
+	size = sizeof(struct path) * sbmax(dentry->d_sb);
+	p = krealloc(info->lower_paths, size, GFP_ATOMIC);
+	if (!p)
+		return -ENOMEM;
+
+	info->lower_paths = p;
 
 	info->bstart = -1;
 	info->bend = -1;
 	info->bopaque = -1;
 	info->bcount = sbmax(dentry->d_sb);
 	atomic_set(&info->generation,
-		   atomic_read(&UNIONFS_SB(dentry->d_sb)->generation));
-
-	size = sizeof(struct path) * sbmax(dentry->d_sb);
-
-	p = krealloc(info->lower_paths, size, GFP_ATOMIC);
-	if (!p)
-		goto out_free;
+			atomic_read(&UNIONFS_SB(dentry->d_sb)->generation));
 
-	info->lower_paths = p;
 	memset(info->lower_paths, 0, size);
 
-	spin_unlock(&dentry->d_lock);
 	return 0;
+}
 
-out_free:
-	kfree(info->lower_paths);
-	if (unlock_on_err)
-		mutex_unlock(&info->lock);
+/* UNIONFS_D(dentry)->lock must be locked */
+int realloc_dentry_private_data(struct dentry *dentry)
+{
+	if (!__realloc_dentry_private_data(dentry))
+		return 0;
 
-out:
+	kfree(UNIONFS_D(dentry)->lower_paths);
+	free_dentry_private_data(UNIONFS_D(dentry));
+	dentry->d_fsdata = NULL;
+	return -ENOMEM;
+}
+
+/* allocate new dentry private data */
+int new_dentry_private_data(struct dentry *dentry)
+{
+	struct unionfs_dentry_info *info = UNIONFS_D(dentry);
+
+	BUG_ON(info);
+
+	info = kmem_cache_alloc(unionfs_dentry_cachep, GFP_ATOMIC);
+	if (!info)
+		return -ENOMEM;
+
+	mutex_init(&info->lock);
+	mutex_lock(&info->lock);
+
+	info->lower_paths = NULL;
+
+	dentry->d_fsdata = info;
+
+	if (!__realloc_dentry_private_data(dentry))
+		return 0;
+
+	mutex_unlock(&info->lock);
 	free_dentry_private_data(info);
 	dentry->d_fsdata = NULL;
-	spin_unlock(&dentry->d_lock);
 	return -ENOMEM;
 }
 
diff --git a/fs/unionfs/union.h b/fs/unionfs/union.h
index 28eb622..7e0c318 100644
--- a/fs/unionfs/union.h
+++ b/fs/unionfs/union.h
@@ -233,6 +233,7 @@ static inline void unionfs_double_lock_dentry(struct dentry *d1,
 	unionfs_lock_dentry(d2);
 }
 
+extern int realloc_dentry_private_data(struct dentry *dentry);
 extern int new_dentry_private_data(struct dentry *dentry);
 extern void free_dentry_private_data(struct unionfs_dentry_info *udi);
 extern void update_bstart(struct dentry *dentry);
-- 
1.5.2.rc1.165.gaf9b


  parent reply	other threads:[~2007-06-17 19:10 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-17 19:09 [GIT PULL -mm] Unionfs cleanups, fixes, and mmap Josef 'Jeff' Sipek
2007-06-17 19:09 ` [PATCH 01/16] [PATCH] unionfs section mismatch Josef 'Jeff' Sipek
2007-06-17 19:09 ` [PATCH 02/16] Unionfs: Don't revalidate dropped dentries Josef 'Jeff' Sipek
2007-06-17 19:09 ` [PATCH 03/16] Unionfs: Retry lookup for different silly-renamed files Josef 'Jeff' Sipek
2007-06-17 19:09 ` [PATCH 04/16] Unionfs: Set lower inodes correctly after branch management succeeds Josef 'Jeff' Sipek
2007-06-17 19:09 ` [PATCH 05/16] Unionfs: call statfs on lower file system properly Josef 'Jeff' Sipek
2007-06-17 19:09 ` [PATCH 06/16] MAINTAINERS: Add Erez Zadok as a maintainer of Unionfs Josef 'Jeff' Sipek
2007-06-17 19:09 ` [PATCH 07/16] Unionfs: Add standard copyright comment to include/linux/union_fs.h Josef 'Jeff' Sipek
2007-06-17 19:09 ` [PATCH 08/16] Unionfs: Remove unnecessary #define Josef 'Jeff' Sipek
2007-06-17 19:09 ` [PATCH 09/16] Unionfs: mmap implementation Josef 'Jeff' Sipek
2007-06-17 19:09 ` [PATCH 10/16] Unionfs: merge find_new_branch_index and branch_id_to_idx into one function Josef 'Jeff' Sipek
2007-06-17 19:09 ` [PATCH 11/16] Unionfs: Revalidate dentries passed to all inode/super operations Josef 'Jeff' Sipek
2007-06-17 19:09 ` Josef 'Jeff' Sipek [this message]
2007-06-17 19:09 ` [PATCH 13/16] Unionfs: Change free_dentry_private_info to take a struct dentry Josef 'Jeff' Sipek
2007-06-17 19:09 ` [PATCH 14/16] Unionfs: Add BUG_ONs to unionfs_lower_* Josef 'Jeff' Sipek
2007-06-17 19:09 ` [PATCH 15/16] Unionfs: Change the semantics of sb info's rwsem Josef 'Jeff' Sipek
2007-06-17 19:09 ` [PATCH 16/16] Unionfs: Remove superfluous check for NULL pointer Josef 'Jeff' Sipek

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=11821073643856-git-send-email-jsipek@cs.sunysb.edu \
    --to=jsipek@cs.sunysb.edu \
    --cc=akpm@linux-foundation.org \
    --cc=linux-fsdevel@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®