mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Maxim Patlasov <mpatlasov@parallels.com>
To: viro@zeniv.linux.org.uk
Cc: linux-kernel@vger.kernel.org, dhowells@redhat.com,
	ebiederm@xmission.com, akpm@linux-foundation.org,
	fengguang.wu@intel.com, devel@openvz.org
Subject: Re: [PATCH] proc: avoid extra pde_put() in proc_fill_super()
Date: Thu, 24 Jan 2013 16:08:28 +0400	[thread overview]
Message-ID: <20130124113842.19298.15835.stgit@maximpc.sw.ru> (raw)
In-Reply-To: <20130123161715.GX4939@ZenIV.linux.org.uk>

Hi Al,

01/23/2013 08:17 PM, Al Viro wrote:
> On Tue, Jan 22, 2013 at 09:03:26PM +0400, Maxim Patlasov wrote:
>> If proc_get_inode() succeeded, but d_make_root() failed, pde_put() for
>> proc_root will be called twice: the first time due to iput() called from
>> d_make_root() and the second time directly in the end of proc_fill_super().
>
> I don't like that solution, TBH.  How about making proc_get_inode() call
> pde_put() on failure instead?  Note that it already does so if inode had
> been found in icache, so this will just make the refcounting consistent.
> Completely untested patch follows:

The patch looks correct and its idea is very reasonable. I agree, it makes
refcounting consistent. Also, proc_lookup_de() is simplified. But your patch
misses a few (minor) bits implemented in mine:

 * add KERN_ERR to printk
 * s/proc_read_super/proc_fill_super in message string(s)
 * avoid misleading user ("get root inode failed") if getting inode succeeded,
   but allocating dentry failed.

The thing I don't like in your patch is mixing one-line fix (removal pde_put()
from proc_fill_super()) with general cleanup of proc_get_inode() and friends.
I'd suggest to apply your cleanup patch on top of my bugfix patch. Below is
your patch (essentially unmodified, excepting very last hunk) in the form
to be applied on top of my patch.

Thanks,
Maxim

Suggested-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Maxim Patlasov <mpatlasov@parallels.com>
---
diff --git a/fs/proc/generic.c b/fs/proc/generic.c
index 76ddae8..8b487e5 100644
--- a/fs/proc/generic.c
+++ b/fs/proc/generic.c
@@ -413,31 +413,24 @@ struct dentry *proc_lookup_de(struct proc_dir_entry *de, struct inode *dir,
 		struct dentry *dentry)
 {
 	struct inode *inode = NULL;
-	int error = -ENOENT;
 
 	spin_lock(&proc_subdir_lock);
 	for (de = de->subdir; de ; de = de->next) {
 		if (de->namelen != dentry->d_name.len)
 			continue;
-		if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
-			pde_get(de);
-			spin_unlock(&proc_subdir_lock);
-			error = -ENOMEM;
-			inode = proc_get_inode(dir->i_sb, de);
-			goto out_unlock;
-		}
-	}
-	spin_unlock(&proc_subdir_lock);
-out_unlock:
-
-	if (inode) {
+		if (memcmp(dentry->d_name.name, de->name, de->namelen))
+			continue;
+		pde_get(de);
+		spin_unlock(&proc_subdir_lock);
+		inode = proc_get_inode(dir->i_sb, de);
+		if (!inode)
+			return ERR_PTR(-ENOMEM);
 		d_set_d_op(dentry, &proc_dentry_operations);
 		d_add(dentry, inode);
 		return NULL;
 	}
-	if (de)
-		pde_put(de);
-	return ERR_PTR(error);
+	spin_unlock(&proc_subdir_lock);
+	return ERR_PTR(-ENOENT);
 }
 
 struct dentry *proc_lookup(struct inode *dir, struct dentry *dentry,
diff --git a/fs/proc/inode.c b/fs/proc/inode.c
index c7f8b24..99a9eb7 100644
--- a/fs/proc/inode.c
+++ b/fs/proc/inode.c
@@ -448,9 +448,7 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
 	struct inode * inode;
 
 	inode = iget_locked(sb, de->low_ino);
-	if (!inode)
-		return NULL;
-	if (inode->i_state & I_NEW) {
+	if (inode && inode->i_state & I_NEW) {
 		inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
 		PROC_I(inode)->pde = de;
 
@@ -499,7 +497,6 @@ int proc_fill_super(struct super_block *s)
 	root_inode = proc_get_inode(s, &proc_root);
 	if (!root_inode) {
 		printk(KERN_ERR "proc_fill_super: get root inode failed\n");
-		pde_put(&proc_root);
 		return -ENOMEM;
 	}
 


      reply	other threads:[~2013-01-24 12:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-22 17:03 Maxim Patlasov
2013-01-23 16:17 ` Al Viro
2013-01-24 12:08   ` Maxim Patlasov [this message]

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=20130124113842.19298.15835.stgit@maximpc.sw.ru \
    --to=mpatlasov@parallels.com \
    --cc=akpm@linux-foundation.org \
    --cc=devel@openvz.org \
    --cc=dhowells@redhat.com \
    --cc=ebiederm@xmission.com \
    --cc=fengguang.wu@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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

Powered by JetHome