Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3220719imu; Sun, 23 Dec 2018 19:49:38 -0800 (PST) X-Google-Smtp-Source: ALg8bN5Qr5JWnOscchRnSPFXI43Sx/HfQXmw6r7JCEW3X/c3BZuvZ0auxdO8s4m5l+Cx7ujT3oTM X-Received: by 2002:a62:7a8b:: with SMTP id v133mr12029358pfc.159.1545623378662; Sun, 23 Dec 2018 19:49:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545623378; cv=none; d=google.com; s=arc-20160816; b=xMIyivINiDT4sAUsKbedNdR/Mjqar5XK03gc6RJnhTiDA/VtkpUkCr5/rtOgIDj9Yz EjYWaYZOttzk9b3Cuoi7UfGGO6o/7O2nrASeFQHiL/CZdb3WWjlbvq1/0lcZcZUZY8Qi 23hA8ijKz4cNpI+CR3EfQkKyqdELtNBJjYfC3zF337RfMmp/AFK8IamAV8HSfDxAg31+ yRR6DBF1ARWiAkkTEC9ywjn0nM8ocOIkVSV6XrFWKCC1VRGmesK+mPJbDWyD5J6FPn0m BoKLTOL+IpDhi+AmA9nBm1Bd4E3xQ+bLtU8iMVFYDJjqo7RWL7mEgaGq+Uiz3/SCSSy6 RK2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=QRyqeswnT1/d8WKv7wWjffgDFOzSwDmkqz6PFreo1Po=; b=rKBMSmGN2YLxDifdvVXSaY1a60iz8AJbIxT+5G0ZyzX9ca7J6RtXLwh3H228ulh/1q U0GxGXGNH1Gx6MtsByuIM6/6utlY/LmCVMJEL5DPYKdPV5ydbNIO84PThn5ow7ejurN/ Wq0JeYpDHzdHriu6InP9dVYhwfIIX/A4pxXGwuxCmIR1CNcHt7GBLNtv224YDlefIBa2 /iPuTTSmo3bzLryYMq5qyJt169vwy+a5wDGrbdGUuQ2Jm3IllA/7FEC4X1MgA4BAUNae gaW8x7OVljUBJGX1pUkplTkmp33voCFgLQ+KD9wFdQ6xKtNICqanJQVRxCUOntvbdAFO xmlg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a19si2065961pgj.429.2018.12.23.19.49.23; Sun, 23 Dec 2018 19:49:38 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726702AbeLXDr6 (ORCPT + 99 others); Sun, 23 Dec 2018 22:47:58 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:41800 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726361AbeLXDr6 (ORCPT ); Sun, 23 Dec 2018 22:47:58 -0500 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 75D819909DF77; Mon, 24 Dec 2018 11:47:55 +0800 (CST) Received: from [127.0.0.1] (10.177.33.43) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.408.0; Mon, 24 Dec 2018 11:47:51 +0800 Subject: Re: [PATCH] debugfs: remove inc_nlink in debugfs_create_automount To: Greg KH , Al Viro CC: , References: <20181222084536.21305-1-yangerkun@huawei.com> <20181222112512.GA27683@kroah.com> From: yangerkun Message-ID: Date: Mon, 24 Dec 2018 11:47:41 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <20181222112512.GA27683@kroah.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.177.33.43] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 >> --- >> 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 #include #include 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.