mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: yangerkun <yangerkun@huawei.com>
To: Greg KH <gregkh@linuxfoundation.org>, Al Viro <viro@zeniv.linux.org.uk>
Cc: <rafael@kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] debugfs: remove inc_nlink in debugfs_create_automount
Date: Mon, 24 Dec 2018 11:47:41 +0800	[thread overview]
Message-ID: <c97fd5c9-c9aa-7f27-30fb-115e59f17389@huawei.com> (raw)
In-Reply-To: <20181222112512.GA27683@kroah.com>



Greg KH wrote on 2018/12/22 19:25:
> On Sat, Dec 22, 2018 at 04:45:36PM +0800, yangerkun wrote:
>> Remove inc_nlink in debugfs_create_automount, or this inode will never
>> be free.
>>
>> Signed-off-by: yangerkun <yangerkun@huawei.com>
>> ---
>>   fs/debugfs/inode.c | 3 +--
>>   1 file changed, 1 insertion(+), 2 deletions(-)
>>
>> diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
>> index 13b01351dd1c..9294238e364f 100644
>> --- a/fs/debugfs/inode.c
>> +++ b/fs/debugfs/inode.c
>> @@ -551,12 +551,11 @@ struct dentry *debugfs_create_automount(const char *name,
>>   	if (unlikely(!inode))
>>   		return failed_creating(dentry);
>>   
>> +	/* directory inodes start off with i_nlink == 2 (for "." entry) */
>>   	make_empty_dir_inode(inode);
>>   	inode->i_flags |= S_AUTOMOUNT;
>>   	inode->i_private = data;
>>   	dentry->d_fsdata = (void *)f;
>> -	/* directory inodes start off with i_nlink == 2 (for "." entry) */
>> -	inc_nlink(inode);
> 
> Again, have you tested this and how?  How did you find this issue?
> 
> thanks,
> 
> greg k-h
> 
> .
> 
Thanks a lot for Al Viro's explain.

I was confusing about i_nlink and i_count before, so after insert and 
remove module show as below, i think the inode can still exist with 
nlink will be 1.

So the only problem is that the nlink should be 2 for a empty dir, and 
for debugfs,the influence is that the stat for the dir. Right?

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/debugfs.h>

static char *name = "test-dir";
module_param(name, charp, 0644);
MODULE_PARM_DESC(name, "Get an string(char *) value from user...\n");

struct inode *inode;

int init_module(void)
{
     struct dentry *dentry;

     dentry = debugfs_create_automount(name, NULL, NULL, NULL);
     inode = dentry->d_inode;
     debugfs_remove(dentry);
     return 0;
}

void cleanup_module(void)
{
     printk("%d\n", inode->i_nlink);
}

MODULE_LICENSE("GPL");

Thanks,
Kun.


  reply	other threads:[~2018-12-24  3:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-22  8:45 yangerkun
2018-12-22 11:25 ` Greg KH
2018-12-24  3:47   ` yangerkun [this message]
2018-12-23  1:13 ` Al Viro

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=c97fd5c9-c9aa-7f27-30fb-115e59f17389@huawei.com \
    --to=yangerkun@huawei.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rafael@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

all inboxes | Powered by JetHome®