All of lore.kernel.org
 help / color / mirror / Atom feed
From: Emanuele Giuseppe Esposito <eesposit@redhat.com>
To: linux-nfs@vger.kernel.org
Cc: Song Liu <songliubraving@fb.com>,
	linux-usb@vger.kernel.org, bpf@vger.kernel.org,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	David Airlie <airlied@linux.ie>,
	Heiko Carstens <heiko.carstens@de.ibm.com>,
	Alexei Starovoitov <ast@kernel.org>,
	dri-devel@lists.freedesktop.org,
	"J. Bruce Fields" <bfields@fieldses.org>,
	Joseph Qi <joseph.qi@linux.alibaba.com>,
	Hugh Dickins <hughd@google.com>,
	Paul Mackerras <paulus@samba.org>,
	John Johansen <john.johansen@canonical.com>,
	netdev@vger.kernel.org, linux-s390@vger.kernel.org,
	Christoph Hellwig <hch@lst.de>,
	Andrew Donnellan <ajd@linux.ibm.com>,
	Emanuele Giuseppe Esposito <eesposit@redhat.com>,
	Matthew Garrett <matthew.garrett@nebula.com>,
	linux-efi@vger.kernel.org, Arnd Bergmann <arnd@arndb.de>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Christian Borntraeger <borntraeger@de.ibm.com>,
	linux-rdma@vger.kernel.org, Mark Fasheh <mark@fasheh.>
Subject: [PATCH 7/8] debugfs: switch to simplefs inode creation API
Date: Tue, 14 Apr 2020 14:43:01 +0200	[thread overview]
Message-ID: <20200414124304.4470-8-eesposit@redhat.com> (raw)
In-Reply-To: <20200414124304.4470-1-eesposit@redhat.com>

The only difference, compared to the pre-existing code, is that symlink
creation now triggers fsnotify_create.  This was a bug in the debugfs
code, since for example vfs_symlink does call fsnotify_create.

Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
---
 fs/debugfs/inode.c | 144 +++++----------------------------------------
 1 file changed, 15 insertions(+), 129 deletions(-)

diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
index 834b5872ca0d..7a2369373b85 100644
--- a/fs/debugfs/inode.c
+++ b/fs/debugfs/inode.c
@@ -294,68 +294,6 @@ struct dentry *debugfs_lookup(const char *name, struct dentry *parent)
 }
 EXPORT_SYMBOL_GPL(debugfs_lookup);
 
-static struct dentry *start_creating(const char *name, struct dentry *parent)
-{
-	struct dentry *dentry;
-	int error;
-
-	pr_debug("creating file '%s'\n", name);
-
-	if (IS_ERR(parent))
-		return parent;
-
-	error = simple_pin_fs(&debugfs, &debug_fs_type);
-	if (error) {
-		pr_err("Unable to pin filesystem for file '%s'\n", name);
-		return ERR_PTR(error);
-	}
-
-	/* If the parent is not specified, we create it in the root.
-	 * We need the root dentry to do this, which is in the super
-	 * block. A pointer to that is in the struct vfsmount that we
-	 * have around.
-	 */
-	if (!parent)
-		parent = debugfs.mount->mnt_root;
-
-	inode_lock(d_inode(parent));
-	if (unlikely(IS_DEADDIR(d_inode(parent))))
-		dentry = ERR_PTR(-ENOENT);
-	else
-		dentry = lookup_one_len(name, parent, strlen(name));
-	if (!IS_ERR(dentry) && d_really_is_positive(dentry)) {
-		if (d_is_dir(dentry))
-			pr_err("Directory '%s' with parent '%s' already present!\n",
-			       name, parent->d_name.name);
-		else
-			pr_err("File '%s' in directory '%s' already present!\n",
-			       name, parent->d_name.name);
-		dput(dentry);
-		dentry = ERR_PTR(-EEXIST);
-	}
-
-	if (IS_ERR(dentry)) {
-		inode_unlock(d_inode(parent));
-		simple_release_fs(&debugfs);
-	}
-
-	return dentry;
-}
-
-static struct dentry *failed_creating(struct dentry *dentry)
-{
-	inode_unlock(d_inode(dentry->d_parent));
-	dput(dentry);
-	simple_release_fs(&debugfs);
-	return ERR_PTR(-ENOMEM);
-}
-
-static struct dentry *end_creating(struct dentry *dentry)
-{
-	inode_unlock(d_inode(dentry->d_parent));
-	return dentry;
-}
-
 static struct dentry *__debugfs_create_file(const char *name, umode_t mode,
 				struct dentry *parent, void *data,
 				const struct file_operations *proxy_fops,
@@ -364,32 +302,17 @@ static struct dentry *__debugfs_create_file(const char *name, umode_t mode,
 	struct dentry *dentry;
 	struct inode *inode;
 
-	if (!(mode & S_IFMT))
-		mode |= S_IFREG;
-	BUG_ON(!S_ISREG(mode));
-	dentry = start_creating(name, parent);
-
+	dentry = simplefs_create_file(&debugfs, &debug_fs_type,
+				      name, mode, parent, data, &inode);
 	if (IS_ERR(dentry))
 		return dentry;
 
-	inode = simple_new_inode(dentry->d_sb);
-	if (unlikely(!inode)) {
-		pr_err("out of free dentries, can not create file '%s'\n",
-		       name);
-		return failed_creating(dentry);
-	}
-
-	inode->i_mode = mode;
-	inode->i_private = data;
-
 	inode->i_op = &debugfs_file_inode_operations;
 	inode->i_fop = proxy_fops;
 	dentry->d_fsdata = (void *)((unsigned long)real_fops |
 				DEBUGFS_FSDATA_IS_REAL_FOPS_BIT);
 
-	d_instantiate(dentry, inode);
-	fsnotify_create(d_inode(dentry->d_parent), dentry);
-	return end_creating(dentry);
+	return simplefs_finish_dentry(dentry, inode);
 }
 
 /**
@@ -522,29 +445,16 @@ EXPORT_SYMBOL_GPL(debugfs_create_file_size);
  */
 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
 {
-	struct dentry *dentry = start_creating(name, parent);
+	struct dentry *dentry;
 	struct inode *inode;
 
+	dentry = simplefs_create_dir(&debugfs, &debug_fs_type,
+				     name, 0755, parent, &inode);
 	if (IS_ERR(dentry))
 		return dentry;
 
-	inode = simple_new_inode(dentry->d_sb);
-	if (unlikely(!inode)) {
-		pr_err("out of free dentries, can not create directory '%s'\n",
-		       name);
-		return failed_creating(dentry);
-	}
-
-	inode->i_mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
 	inode->i_op = &debugfs_dir_inode_operations;
-	inode->i_fop = &simple_dir_operations;
-
-	/* directory inodes start off with i_nlink == 2 (for "." entry) */
-	inc_nlink(inode);
-	d_instantiate(dentry, inode);
-	inc_nlink(d_inode(dentry->d_parent));
-	fsnotify_mkdir(d_inode(dentry->d_parent), dentry);
-	return end_creating(dentry);
+	return simplefs_finish_dentry(dentry, inode);
 }
 EXPORT_SYMBOL_GPL(debugfs_create_dir);
 
@@ -564,29 +474,19 @@ struct dentry *debugfs_create_automount(const char *name,
 					debugfs_automount_t f,
 					void *data)
 {
-	struct dentry *dentry = start_creating(name, parent);
+	struct dentry *dentry;
 	struct inode *inode;
 
+	dentry = simplefs_create_dentry(&debugfs, &debug_fs_type, name, parent,
+					&inode);
 	if (IS_ERR(dentry))
 		return dentry;
 
-	inode = simple_new_inode(dentry->d_sb);
-	if (unlikely(!inode)) {
-		pr_err("out of free dentries, can not create automount '%s'\n",
-		       name);
-		return failed_creating(dentry);
-	}
-
 	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);
-	d_instantiate(dentry, inode);
-	inc_nlink(d_inode(dentry->d_parent));
-	fsnotify_mkdir(d_inode(dentry->d_parent), dentry);
-	return end_creating(dentry);
+	return simplefs_finish_dentry(dentry, inode);
 }
 EXPORT_SYMBOL(debugfs_create_automount);
 
@@ -618,28 +518,14 @@ struct dentry *debugfs_create_symlink(const char *name, struct dentry *parent,
 {
 	struct dentry *dentry;
 	struct inode *inode;
-	char *link = kstrdup(target, GFP_KERNEL);
-	if (!link)
-		return ERR_PTR(-ENOMEM);
 
-	dentry = start_creating(name, parent);
-	if (IS_ERR(dentry)) {
-		kfree(link);
+	dentry = simplefs_create_symlink(&debugfs, &debug_fs_type,
+					 name, parent, target, &inode);
+	if (IS_ERR(dentry))
 		return dentry;
-	}
 
-	inode = simple_new_inode(dentry->d_sb);
-	if (unlikely(!inode)) {
-		pr_err("out of free dentries, can not create symlink '%s'\n",
-		       name);
-		kfree(link);
-		return failed_creating(dentry);
-	}
-	inode->i_mode = S_IFLNK | S_IRWXUGO;
 	inode->i_op = &debugfs_symlink_inode_operations;
-	inode->i_link = link;
-	d_instantiate(dentry, inode);
-	return end_creating(dentry);
+	return simplefs_finish_dentry(dentry, inode);
 }
 EXPORT_SYMBOL_GPL(debugfs_create_symlink);
 
-- 
2.25.2


WARNING: multiple messages have this Message-ID (diff)
From: Emanuele Giuseppe Esposito <eesposit@redhat.com>
To: linux-nfs@vger.kernel.org
Cc: Song Liu <songliubraving@fb.com>,
	linux-usb@vger.kernel.org, bpf@vger.kernel.org,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	David Airlie <airlied@linux.ie>,
	Heiko Carstens <heiko.carstens@de.ibm.com>,
	Alexei Starovoitov <ast@kernel.org>,
	dri-devel@lists.freedesktop.org,
	"J. Bruce Fields" <bfields@fieldses.org>,
	Joseph Qi <joseph.qi@linux.alibaba.com>,
	Hugh Dickins <hughd@google.com>,
	Paul Mackerras <paulus@samba.org>,
	John Johansen <john.johansen@canonical.com>,
	linux-s390@vger.kernel.org, Christoph Hellwig <hch@lst.de>,
	Andrew Donnellan <ajd@linux.ibm.com>,
	Emanuele Giuseppe Esposito <eesposit@redhat.com>,
	Matthew Garrett <matthew.garrett@nebula.com>,
	linux-efi@vger.kernel.org, Arnd Bergmann <arnd@arndb.de>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Christian Borntraeger <borntraeger@de.ibm.com>,
	linux-rdma@vger.kernel.org, Michael Ellerman <mpe@ellerman.id.au>,
	Mark Fasheh <mark@fasheh.com>, Anton Vorontsov <anton@enomsg.org>,
	John Fastabend <john.fastabend@gmail.com>,
	James Morris <jmorris@namei.org>,
	Ard Biesheuvel <ardb@kernel.org>, Jason Gunthorpe <jgg@ziepe.ca>,
	Doug Ledford <dledford@redhat.com>,
	oprofile-list@lists.sf.net, Yonghong Song <yhs@fb.com>,
	Ian Kent <raven@themaw.net>, Andrii Nakryiko <andriin@fb.com>,
	Alexey Dobriyan <adobriyan@gmail.com>,
	"Serge E. Hallyn" <serge@hallyn.com>,
	netdev@vger.kernel.org, Robert Richter <rric@kernel.org>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	Vasily Gorbik <gor@linux.ibm.com>,
	Tony Luck <tony.luck@intel.com>,
	Kees Cook <keescook@chromium.org>,
	"James E.J. Bottomley" <jejb@linux.ibm.com>,
	autofs@vger.kernel.org, Uma Krishnan <ukrishn@linux.ibm.com>,
	linux-fsdevel@vger.kernel.org,
	"Manoj N. Kumar" <manoj@linux.ibm.com>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	Jakub Kicinski <kuba@kernel.org>, KP Singh <kpsingh@chromium.org>,
	Trond Myklebust <trond.myklebust@hammerspace.com>,
	"Matthew R. Ochs" <mrochs@linux.ibm.com>,
	"David S. Miller" <davem@davemloft.net>,
	Felipe Balbi <balbi@kernel.org>,
	Mike Marciniszyn <mike.marciniszyn@intel.com>,
	Iurii Zaikin <yzaikin@google.com>,
	linux-scsi@vger.kernel.org,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	linux-mm@kvack.org,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Dennis Dalessandro <dennis.dalessandro@intel.com>,
	Miklos Szeredi <miklos@szeredi.hu>,
	linux-security-module@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Anna Schumaker <anna.schumaker@netapp.com>,
	Luis Chamberlain <mcgrof@kernel.org>,
	Chuck Lever <chuck.lever@oracle.com>, Jeremy Kerr <jk@ozlabs.org>,
	Colin Cross <ccross@android.com>,
	Frederic Barrat <fbarrat@linux.ibm.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Mike Kravetz <mike.kravetz@oracle.com>,
	linuxppc-dev@lists.ozlabs.org, Martin KaFai Lau <kafai@fb.com>,
	ocfs2-devel@oss.oracle.com, Joel Becker <jlbec@evilplan.org>
Subject: [Ocfs2-devel] [PATCH 7/8] debugfs: switch to simplefs inode creation API
Date: Tue, 14 Apr 2020 14:43:01 +0200	[thread overview]
Message-ID: <20200414124304.4470-8-eesposit@redhat.com> (raw)
In-Reply-To: <20200414124304.4470-1-eesposit@redhat.com>

The only difference, compared to the pre-existing code, is that symlink
creation now triggers fsnotify_create.  This was a bug in the debugfs
code, since for example vfs_symlink does call fsnotify_create.

Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
---
 fs/debugfs/inode.c | 144 +++++----------------------------------------
 1 file changed, 15 insertions(+), 129 deletions(-)

diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
index 834b5872ca0d..7a2369373b85 100644
--- a/fs/debugfs/inode.c
+++ b/fs/debugfs/inode.c
@@ -294,68 +294,6 @@ struct dentry *debugfs_lookup(const char *name, struct dentry *parent)
 }
 EXPORT_SYMBOL_GPL(debugfs_lookup);
 
-static struct dentry *start_creating(const char *name, struct dentry *parent)
-{
-	struct dentry *dentry;
-	int error;
-
-	pr_debug("creating file '%s'\n", name);
-
-	if (IS_ERR(parent))
-		return parent;
-
-	error = simple_pin_fs(&debugfs, &debug_fs_type);
-	if (error) {
-		pr_err("Unable to pin filesystem for file '%s'\n", name);
-		return ERR_PTR(error);
-	}
-
-	/* If the parent is not specified, we create it in the root.
-	 * We need the root dentry to do this, which is in the super
-	 * block. A pointer to that is in the struct vfsmount that we
-	 * have around.
-	 */
-	if (!parent)
-		parent = debugfs.mount->mnt_root;
-
-	inode_lock(d_inode(parent));
-	if (unlikely(IS_DEADDIR(d_inode(parent))))
-		dentry = ERR_PTR(-ENOENT);
-	else
-		dentry = lookup_one_len(name, parent, strlen(name));
-	if (!IS_ERR(dentry) && d_really_is_positive(dentry)) {
-		if (d_is_dir(dentry))
-			pr_err("Directory '%s' with parent '%s' already present!\n",
-			       name, parent->d_name.name);
-		else
-			pr_err("File '%s' in directory '%s' already present!\n",
-			       name, parent->d_name.name);
-		dput(dentry);
-		dentry = ERR_PTR(-EEXIST);
-	}
-
-	if (IS_ERR(dentry)) {
-		inode_unlock(d_inode(parent));
-		simple_release_fs(&debugfs);
-	}
-
-	return dentry;
-}
-
-static struct dentry *failed_creating(struct dentry *dentry)
-{
-	inode_unlock(d_inode(dentry->d_parent));
-	dput(dentry);
-	simple_release_fs(&debugfs);
-	return ERR_PTR(-ENOMEM);
-}
-
-static struct dentry *end_creating(struct dentry *dentry)
-{
-	inode_unlock(d_inode(dentry->d_parent));
-	return dentry;
-}
-
 static struct dentry *__debugfs_create_file(const char *name, umode_t mode,
 				struct dentry *parent, void *data,
 				const struct file_operations *proxy_fops,
@@ -364,32 +302,17 @@ static struct dentry *__debugfs_create_file(const char *name, umode_t mode,
 	struct dentry *dentry;
 	struct inode *inode;
 
-	if (!(mode & S_IFMT))
-		mode |= S_IFREG;
-	BUG_ON(!S_ISREG(mode));
-	dentry = start_creating(name, parent);
-
+	dentry = simplefs_create_file(&debugfs, &debug_fs_type,
+				      name, mode, parent, data, &inode);
 	if (IS_ERR(dentry))
 		return dentry;
 
-	inode = simple_new_inode(dentry->d_sb);
-	if (unlikely(!inode)) {
-		pr_err("out of free dentries, can not create file '%s'\n",
-		       name);
-		return failed_creating(dentry);
-	}
-
-	inode->i_mode = mode;
-	inode->i_private = data;
-
 	inode->i_op = &debugfs_file_inode_operations;
 	inode->i_fop = proxy_fops;
 	dentry->d_fsdata = (void *)((unsigned long)real_fops |
 				DEBUGFS_FSDATA_IS_REAL_FOPS_BIT);
 
-	d_instantiate(dentry, inode);
-	fsnotify_create(d_inode(dentry->d_parent), dentry);
-	return end_creating(dentry);
+	return simplefs_finish_dentry(dentry, inode);
 }
 
 /**
@@ -522,29 +445,16 @@ EXPORT_SYMBOL_GPL(debugfs_create_file_size);
  */
 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
 {
-	struct dentry *dentry = start_creating(name, parent);
+	struct dentry *dentry;
 	struct inode *inode;
 
+	dentry = simplefs_create_dir(&debugfs, &debug_fs_type,
+				     name, 0755, parent, &inode);
 	if (IS_ERR(dentry))
 		return dentry;
 
-	inode = simple_new_inode(dentry->d_sb);
-	if (unlikely(!inode)) {
-		pr_err("out of free dentries, can not create directory '%s'\n",
-		       name);
-		return failed_creating(dentry);
-	}
-
-	inode->i_mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
 	inode->i_op = &debugfs_dir_inode_operations;
-	inode->i_fop = &simple_dir_operations;
-
-	/* directory inodes start off with i_nlink == 2 (for "." entry) */
-	inc_nlink(inode);
-	d_instantiate(dentry, inode);
-	inc_nlink(d_inode(dentry->d_parent));
-	fsnotify_mkdir(d_inode(dentry->d_parent), dentry);
-	return end_creating(dentry);
+	return simplefs_finish_dentry(dentry, inode);
 }
 EXPORT_SYMBOL_GPL(debugfs_create_dir);
 
@@ -564,29 +474,19 @@ struct dentry *debugfs_create_automount(const char *name,
 					debugfs_automount_t f,
 					void *data)
 {
-	struct dentry *dentry = start_creating(name, parent);
+	struct dentry *dentry;
 	struct inode *inode;
 
+	dentry = simplefs_create_dentry(&debugfs, &debug_fs_type, name, parent,
+					&inode);
 	if (IS_ERR(dentry))
 		return dentry;
 
-	inode = simple_new_inode(dentry->d_sb);
-	if (unlikely(!inode)) {
-		pr_err("out of free dentries, can not create automount '%s'\n",
-		       name);
-		return failed_creating(dentry);
-	}
-
 	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);
-	d_instantiate(dentry, inode);
-	inc_nlink(d_inode(dentry->d_parent));
-	fsnotify_mkdir(d_inode(dentry->d_parent), dentry);
-	return end_creating(dentry);
+	return simplefs_finish_dentry(dentry, inode);
 }
 EXPORT_SYMBOL(debugfs_create_automount);
 
@@ -618,28 +518,14 @@ struct dentry *debugfs_create_symlink(const char *name, struct dentry *parent,
 {
 	struct dentry *dentry;
 	struct inode *inode;
-	char *link = kstrdup(target, GFP_KERNEL);
-	if (!link)
-		return ERR_PTR(-ENOMEM);
 
-	dentry = start_creating(name, parent);
-	if (IS_ERR(dentry)) {
-		kfree(link);
+	dentry = simplefs_create_symlink(&debugfs, &debug_fs_type,
+					 name, parent, target, &inode);
+	if (IS_ERR(dentry))
 		return dentry;
-	}
 
-	inode = simple_new_inode(dentry->d_sb);
-	if (unlikely(!inode)) {
-		pr_err("out of free dentries, can not create symlink '%s'\n",
-		       name);
-		kfree(link);
-		return failed_creating(dentry);
-	}
-	inode->i_mode = S_IFLNK | S_IRWXUGO;
 	inode->i_op = &debugfs_symlink_inode_operations;
-	inode->i_link = link;
-	d_instantiate(dentry, inode);
-	return end_creating(dentry);
+	return simplefs_finish_dentry(dentry, inode);
 }
 EXPORT_SYMBOL_GPL(debugfs_create_symlink);
 
-- 
2.25.2

WARNING: multiple messages have this Message-ID (diff)
From: Emanuele Giuseppe Esposito <eesposit@redhat.com>
To: linux-nfs@vger.kernel.org
Cc: Song Liu <songliubraving@fb.com>,
	linux-usb@vger.kernel.org, bpf@vger.kernel.org,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	David Airlie <airlied@linux.ie>,
	Heiko Carstens <heiko.carstens@de.ibm.com>,
	Alexei Starovoitov <ast@kernel.org>,
	dri-devel@lists.freedesktop.org,
	"J. Bruce Fields" <bfields@fieldses.org>,
	Joseph Qi <joseph.qi@linux.alibaba.com>,
	Hugh Dickins <hughd@google.com>,
	Paul Mackerras <paulus@samba.org>,
	John Johansen <john.johansen@canonical.com>,
	netdev@vger.kernel.org, linux-s390@vger.kernel.org,
	Christoph Hellwig <hch@lst.de>,
	Andrew Donnellan <ajd@linux.ibm.com>,
	Emanuele Giuseppe Esposito <eesposit@redhat.com>,
	Matthew Garrett <matthew.garrett@nebula.com>,
	linux-efi@vger.kernel.org, Arnd Bergmann <arnd@arndb.de>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Christian Borntraeger <borntraeger@de.ibm.com>,
	linux-rdma@vger.kernel.org, Mark Fasheh <mark@fasheh.com>,
	Anton Vorontsov <anton@enomsg.org>,
	John Fastabend <john.fastabend@gmail.com>,
	James Morris <jmorris@namei.org>,
	Ard Biesheuvel <ardb@kernel.org>, Jason Gunthorpe <jgg@ziepe.ca>,
	Doug Ledford <dledford@redhat.com>,
	oprofile-list@lists.sf.net, Yonghong Song <yhs@fb.com>,
	Ian Kent <raven@themaw.net>, Andrii Nakryiko <andriin@fb.com>,
	Alexey Dobriyan <adobriyan@gmail.com>,
	"Serge E. Hallyn" <serge@hallyn.com>,
	Robert Richter <rric@kernel.org>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	Vasily Gorbik <gor@linux.ibm.com>,
	Tony Luck <tony.luck@intel.com>,
	Kees Cook <keescook@chromium.org>,
	"James E.J. Bottomley" <jejb@linux.ibm.com>,
	autofs@vger.kernel.org,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Uma Krishnan <ukrishn@linux.ibm.com>,
	Maxime Ripard <mripard@kernel.org>,
	linux-fsdevel@vger.kernel.org,
	"Manoj N. Kumar" <manoj@linux.ibm.com>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	Jakub Kicinski <kuba@kernel.org>, KP Singh <kpsingh@chromium.org>,
	Trond Myklebust <trond.myklebust@hammerspace.com>,
	"Matthew R. Ochs" <mrochs@linux.ibm.com>,
	"David S. Miller" <davem@davemloft.net>,
	Felipe Balbi <balbi@kernel.org>,
	Mike Marciniszyn <mike.marciniszyn@intel.com>,
	Iurii Zaikin <yzaikin@google.com>,
	linux-scsi@vger.kernel.org,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	linux-mm@kvack.org,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Dennis Dalessandro <dennis.dalessandro@intel.com>,
	Miklos Szeredi <miklos@szeredi.hu>,
	linux-security-module@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Anna Schumaker <anna.schumaker@netapp.com>,
	Luis Chamberlain <mcgrof@kernel.org>,
	Chuck Lever <chuck.lever@oracle.com>, Jeremy Kerr <jk@ozlabs.org>,
	Daniel Vetter <daniel@ffwll.ch>, Colin Cross <ccross@android.com>,
	Frederic Barrat <fbarrat@linux.ibm.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Mike Kravetz <mike.kravetz@oracle.com>,
	linuxppc-dev@lists.ozlabs.org, Martin KaFai Lau <kafai@fb.com>,
	ocfs2-devel@oss.oracle.com, Joel Becker <jlbec@evilplan.org>
Subject: [PATCH 7/8] debugfs: switch to simplefs inode creation API
Date: Tue, 14 Apr 2020 14:43:01 +0200	[thread overview]
Message-ID: <20200414124304.4470-8-eesposit@redhat.com> (raw)
In-Reply-To: <20200414124304.4470-1-eesposit@redhat.com>

The only difference, compared to the pre-existing code, is that symlink
creation now triggers fsnotify_create.  This was a bug in the debugfs
code, since for example vfs_symlink does call fsnotify_create.

Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
---
 fs/debugfs/inode.c | 144 +++++----------------------------------------
 1 file changed, 15 insertions(+), 129 deletions(-)

diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
index 834b5872ca0d..7a2369373b85 100644
--- a/fs/debugfs/inode.c
+++ b/fs/debugfs/inode.c
@@ -294,68 +294,6 @@ struct dentry *debugfs_lookup(const char *name, struct dentry *parent)
 }
 EXPORT_SYMBOL_GPL(debugfs_lookup);
 
-static struct dentry *start_creating(const char *name, struct dentry *parent)
-{
-	struct dentry *dentry;
-	int error;
-
-	pr_debug("creating file '%s'\n", name);
-
-	if (IS_ERR(parent))
-		return parent;
-
-	error = simple_pin_fs(&debugfs, &debug_fs_type);
-	if (error) {
-		pr_err("Unable to pin filesystem for file '%s'\n", name);
-		return ERR_PTR(error);
-	}
-
-	/* If the parent is not specified, we create it in the root.
-	 * We need the root dentry to do this, which is in the super
-	 * block. A pointer to that is in the struct vfsmount that we
-	 * have around.
-	 */
-	if (!parent)
-		parent = debugfs.mount->mnt_root;
-
-	inode_lock(d_inode(parent));
-	if (unlikely(IS_DEADDIR(d_inode(parent))))
-		dentry = ERR_PTR(-ENOENT);
-	else
-		dentry = lookup_one_len(name, parent, strlen(name));
-	if (!IS_ERR(dentry) && d_really_is_positive(dentry)) {
-		if (d_is_dir(dentry))
-			pr_err("Directory '%s' with parent '%s' already present!\n",
-			       name, parent->d_name.name);
-		else
-			pr_err("File '%s' in directory '%s' already present!\n",
-			       name, parent->d_name.name);
-		dput(dentry);
-		dentry = ERR_PTR(-EEXIST);
-	}
-
-	if (IS_ERR(dentry)) {
-		inode_unlock(d_inode(parent));
-		simple_release_fs(&debugfs);
-	}
-
-	return dentry;
-}
-
-static struct dentry *failed_creating(struct dentry *dentry)
-{
-	inode_unlock(d_inode(dentry->d_parent));
-	dput(dentry);
-	simple_release_fs(&debugfs);
-	return ERR_PTR(-ENOMEM);
-}
-
-static struct dentry *end_creating(struct dentry *dentry)
-{
-	inode_unlock(d_inode(dentry->d_parent));
-	return dentry;
-}
-
 static struct dentry *__debugfs_create_file(const char *name, umode_t mode,
 				struct dentry *parent, void *data,
 				const struct file_operations *proxy_fops,
@@ -364,32 +302,17 @@ static struct dentry *__debugfs_create_file(const char *name, umode_t mode,
 	struct dentry *dentry;
 	struct inode *inode;
 
-	if (!(mode & S_IFMT))
-		mode |= S_IFREG;
-	BUG_ON(!S_ISREG(mode));
-	dentry = start_creating(name, parent);
-
+	dentry = simplefs_create_file(&debugfs, &debug_fs_type,
+				      name, mode, parent, data, &inode);
 	if (IS_ERR(dentry))
 		return dentry;
 
-	inode = simple_new_inode(dentry->d_sb);
-	if (unlikely(!inode)) {
-		pr_err("out of free dentries, can not create file '%s'\n",
-		       name);
-		return failed_creating(dentry);
-	}
-
-	inode->i_mode = mode;
-	inode->i_private = data;
-
 	inode->i_op = &debugfs_file_inode_operations;
 	inode->i_fop = proxy_fops;
 	dentry->d_fsdata = (void *)((unsigned long)real_fops |
 				DEBUGFS_FSDATA_IS_REAL_FOPS_BIT);
 
-	d_instantiate(dentry, inode);
-	fsnotify_create(d_inode(dentry->d_parent), dentry);
-	return end_creating(dentry);
+	return simplefs_finish_dentry(dentry, inode);
 }
 
 /**
@@ -522,29 +445,16 @@ EXPORT_SYMBOL_GPL(debugfs_create_file_size);
  */
 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
 {
-	struct dentry *dentry = start_creating(name, parent);
+	struct dentry *dentry;
 	struct inode *inode;
 
+	dentry = simplefs_create_dir(&debugfs, &debug_fs_type,
+				     name, 0755, parent, &inode);
 	if (IS_ERR(dentry))
 		return dentry;
 
-	inode = simple_new_inode(dentry->d_sb);
-	if (unlikely(!inode)) {
-		pr_err("out of free dentries, can not create directory '%s'\n",
-		       name);
-		return failed_creating(dentry);
-	}
-
-	inode->i_mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
 	inode->i_op = &debugfs_dir_inode_operations;
-	inode->i_fop = &simple_dir_operations;
-
-	/* directory inodes start off with i_nlink == 2 (for "." entry) */
-	inc_nlink(inode);
-	d_instantiate(dentry, inode);
-	inc_nlink(d_inode(dentry->d_parent));
-	fsnotify_mkdir(d_inode(dentry->d_parent), dentry);
-	return end_creating(dentry);
+	return simplefs_finish_dentry(dentry, inode);
 }
 EXPORT_SYMBOL_GPL(debugfs_create_dir);
 
@@ -564,29 +474,19 @@ struct dentry *debugfs_create_automount(const char *name,
 					debugfs_automount_t f,
 					void *data)
 {
-	struct dentry *dentry = start_creating(name, parent);
+	struct dentry *dentry;
 	struct inode *inode;
 
+	dentry = simplefs_create_dentry(&debugfs, &debug_fs_type, name, parent,
+					&inode);
 	if (IS_ERR(dentry))
 		return dentry;
 
-	inode = simple_new_inode(dentry->d_sb);
-	if (unlikely(!inode)) {
-		pr_err("out of free dentries, can not create automount '%s'\n",
-		       name);
-		return failed_creating(dentry);
-	}
-
 	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);
-	d_instantiate(dentry, inode);
-	inc_nlink(d_inode(dentry->d_parent));
-	fsnotify_mkdir(d_inode(dentry->d_parent), dentry);
-	return end_creating(dentry);
+	return simplefs_finish_dentry(dentry, inode);
 }
 EXPORT_SYMBOL(debugfs_create_automount);
 
@@ -618,28 +518,14 @@ struct dentry *debugfs_create_symlink(const char *name, struct dentry *parent,
 {
 	struct dentry *dentry;
 	struct inode *inode;
-	char *link = kstrdup(target, GFP_KERNEL);
-	if (!link)
-		return ERR_PTR(-ENOMEM);
 
-	dentry = start_creating(name, parent);
-	if (IS_ERR(dentry)) {
-		kfree(link);
+	dentry = simplefs_create_symlink(&debugfs, &debug_fs_type,
+					 name, parent, target, &inode);
+	if (IS_ERR(dentry))
 		return dentry;
-	}
 
-	inode = simple_new_inode(dentry->d_sb);
-	if (unlikely(!inode)) {
-		pr_err("out of free dentries, can not create symlink '%s'\n",
-		       name);
-		kfree(link);
-		return failed_creating(dentry);
-	}
-	inode->i_mode = S_IFLNK | S_IRWXUGO;
 	inode->i_op = &debugfs_symlink_inode_operations;
-	inode->i_link = link;
-	d_instantiate(dentry, inode);
-	return end_creating(dentry);
+	return simplefs_finish_dentry(dentry, inode);
 }
 EXPORT_SYMBOL_GPL(debugfs_create_symlink);
 
-- 
2.25.2


WARNING: multiple messages have this Message-ID (diff)
From: Emanuele Giuseppe Esposito <eesposit@redhat.com>
To: linux-nfs@vger.kernel.org
Cc: Song Liu <songliubraving@fb.com>,
	linux-usb@vger.kernel.org, bpf@vger.kernel.org,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	David Airlie <airlied@linux.ie>,
	Heiko Carstens <heiko.carstens@de.ibm.com>,
	Alexei Starovoitov <ast@kernel.org>,
	dri-devel@lists.freedesktop.org,
	"J. Bruce Fields" <bfields@fieldses.org>,
	Joseph Qi <joseph.qi@linux.alibaba.com>,
	Hugh Dickins <hughd@google.com>,
	Paul Mackerras <paulus@samba.org>,
	John Johansen <john.johansen@canonical.com>,
	linux-s390@vger.kernel.org, Christoph Hellwig <hch@lst.de>,
	Andrew Donnellan <ajd@linux.ibm.com>,
	Emanuele Giuseppe Esposito <eesposit@redhat.com>,
	Matthew Garrett <matthew.garrett@nebula.com>,
	linux-efi@vger.kernel.org, Arnd Bergmann <arnd@arndb.de>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Christian Borntraeger <borntraeger@de.ibm.com>,
	linux-rdma@vger.kernel.org, Michael Ellerman <mpe@ellerman.id.au>,
	Mark Fasheh <mark@fasheh.com>, Anton Vorontsov <anton@enomsg.org>,
	John Fastabend <john.fastabend@gmail.com>,
	James Morris <jmorris@namei.org>,
	Ard Biesheuvel <ardb@kernel.org>, Jason Gunthorpe <jgg@ziepe.ca>,
	Doug Ledford <dledford@redhat.com>,
	oprofile-list@lists.sf.net, Yonghong Song <yhs@fb.com>,
	Ian Kent <raven@themaw.net>, Andrii Nakryiko <andriin@fb.com>,
	Alexey Dobriyan <adobriyan@gmail.com>,
	"Serge E. Hallyn" <serge@hallyn.com>,
	netdev@vger.kernel.org, Robert Richter <rric@kernel.org>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	Vasily Gorbik <gor@linux.ibm.com>,
	Tony Luck <tony.luck@intel.com>,
	Kees Cook <keescook@chromium.org>,
	"James E.J. Bottomley" <jejb@linux.ibm.com>,
	autofs@vger.kernel.org, Uma Krishnan <ukrishn@linux.ibm.com>,
	linux-fsdevel@vger.kernel.org,
	"Manoj N. Kumar" <manoj@linux.ibm.com>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	Jakub Kicinski <kuba@kernel.org>, KP Singh <kpsingh@chromium.org>,
	Trond Myklebust <trond.myklebust@hammerspace.com>,
	"Matthew R. Ochs" <mrochs@linux.ibm.com>,
	"David S. Miller" <davem@davemloft.net>,
	Felipe Balbi <balbi@kernel.org>,
	Mike Marciniszyn <mike.marciniszyn@intel.com>,
	Iurii Zaikin <yzaikin@google.com>,
	linux-scsi@vger.kernel.org,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	linux-mm@kvack.org,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Dennis Dalessandro <dennis.dalessandro@intel.com>,
	Miklos Szeredi <miklos@szeredi.hu>,
	linux-security-module@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Anna Schumaker <anna.schumaker@netapp.com>,
	Luis Chamberlain <mcgrof@kernel.org>,
	Chuck Lever <chuck.lever@oracle.com>, Jeremy Kerr <jk@ozlabs.org>,
	Colin Cross <ccross@android.com>,
	Frederic Barrat <fbarrat@linux.ibm.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Mike Kravetz <mike.kravetz@oracle.com>,
	linuxppc-dev@lists.ozlabs.org, Martin KaFai Lau <kafai@fb.com>,
	ocfs2-devel@oss.oracle.com, Joel Becker <jlbec@evilplan.org>
Subject: [PATCH 7/8] debugfs: switch to simplefs inode creation API
Date: Tue, 14 Apr 2020 14:43:01 +0200	[thread overview]
Message-ID: <20200414124304.4470-8-eesposit@redhat.com> (raw)
In-Reply-To: <20200414124304.4470-1-eesposit@redhat.com>

The only difference, compared to the pre-existing code, is that symlink
creation now triggers fsnotify_create.  This was a bug in the debugfs
code, since for example vfs_symlink does call fsnotify_create.

Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
---
 fs/debugfs/inode.c | 144 +++++----------------------------------------
 1 file changed, 15 insertions(+), 129 deletions(-)

diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
index 834b5872ca0d..7a2369373b85 100644
--- a/fs/debugfs/inode.c
+++ b/fs/debugfs/inode.c
@@ -294,68 +294,6 @@ struct dentry *debugfs_lookup(const char *name, struct dentry *parent)
 }
 EXPORT_SYMBOL_GPL(debugfs_lookup);
 
-static struct dentry *start_creating(const char *name, struct dentry *parent)
-{
-	struct dentry *dentry;
-	int error;
-
-	pr_debug("creating file '%s'\n", name);
-
-	if (IS_ERR(parent))
-		return parent;
-
-	error = simple_pin_fs(&debugfs, &debug_fs_type);
-	if (error) {
-		pr_err("Unable to pin filesystem for file '%s'\n", name);
-		return ERR_PTR(error);
-	}
-
-	/* If the parent is not specified, we create it in the root.
-	 * We need the root dentry to do this, which is in the super
-	 * block. A pointer to that is in the struct vfsmount that we
-	 * have around.
-	 */
-	if (!parent)
-		parent = debugfs.mount->mnt_root;
-
-	inode_lock(d_inode(parent));
-	if (unlikely(IS_DEADDIR(d_inode(parent))))
-		dentry = ERR_PTR(-ENOENT);
-	else
-		dentry = lookup_one_len(name, parent, strlen(name));
-	if (!IS_ERR(dentry) && d_really_is_positive(dentry)) {
-		if (d_is_dir(dentry))
-			pr_err("Directory '%s' with parent '%s' already present!\n",
-			       name, parent->d_name.name);
-		else
-			pr_err("File '%s' in directory '%s' already present!\n",
-			       name, parent->d_name.name);
-		dput(dentry);
-		dentry = ERR_PTR(-EEXIST);
-	}
-
-	if (IS_ERR(dentry)) {
-		inode_unlock(d_inode(parent));
-		simple_release_fs(&debugfs);
-	}
-
-	return dentry;
-}
-
-static struct dentry *failed_creating(struct dentry *dentry)
-{
-	inode_unlock(d_inode(dentry->d_parent));
-	dput(dentry);
-	simple_release_fs(&debugfs);
-	return ERR_PTR(-ENOMEM);
-}
-
-static struct dentry *end_creating(struct dentry *dentry)
-{
-	inode_unlock(d_inode(dentry->d_parent));
-	return dentry;
-}
-
 static struct dentry *__debugfs_create_file(const char *name, umode_t mode,
 				struct dentry *parent, void *data,
 				const struct file_operations *proxy_fops,
@@ -364,32 +302,17 @@ static struct dentry *__debugfs_create_file(const char *name, umode_t mode,
 	struct dentry *dentry;
 	struct inode *inode;
 
-	if (!(mode & S_IFMT))
-		mode |= S_IFREG;
-	BUG_ON(!S_ISREG(mode));
-	dentry = start_creating(name, parent);
-
+	dentry = simplefs_create_file(&debugfs, &debug_fs_type,
+				      name, mode, parent, data, &inode);
 	if (IS_ERR(dentry))
 		return dentry;
 
-	inode = simple_new_inode(dentry->d_sb);
-	if (unlikely(!inode)) {
-		pr_err("out of free dentries, can not create file '%s'\n",
-		       name);
-		return failed_creating(dentry);
-	}
-
-	inode->i_mode = mode;
-	inode->i_private = data;
-
 	inode->i_op = &debugfs_file_inode_operations;
 	inode->i_fop = proxy_fops;
 	dentry->d_fsdata = (void *)((unsigned long)real_fops |
 				DEBUGFS_FSDATA_IS_REAL_FOPS_BIT);
 
-	d_instantiate(dentry, inode);
-	fsnotify_create(d_inode(dentry->d_parent), dentry);
-	return end_creating(dentry);
+	return simplefs_finish_dentry(dentry, inode);
 }
 
 /**
@@ -522,29 +445,16 @@ EXPORT_SYMBOL_GPL(debugfs_create_file_size);
  */
 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
 {
-	struct dentry *dentry = start_creating(name, parent);
+	struct dentry *dentry;
 	struct inode *inode;
 
+	dentry = simplefs_create_dir(&debugfs, &debug_fs_type,
+				     name, 0755, parent, &inode);
 	if (IS_ERR(dentry))
 		return dentry;
 
-	inode = simple_new_inode(dentry->d_sb);
-	if (unlikely(!inode)) {
-		pr_err("out of free dentries, can not create directory '%s'\n",
-		       name);
-		return failed_creating(dentry);
-	}
-
-	inode->i_mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
 	inode->i_op = &debugfs_dir_inode_operations;
-	inode->i_fop = &simple_dir_operations;
-
-	/* directory inodes start off with i_nlink == 2 (for "." entry) */
-	inc_nlink(inode);
-	d_instantiate(dentry, inode);
-	inc_nlink(d_inode(dentry->d_parent));
-	fsnotify_mkdir(d_inode(dentry->d_parent), dentry);
-	return end_creating(dentry);
+	return simplefs_finish_dentry(dentry, inode);
 }
 EXPORT_SYMBOL_GPL(debugfs_create_dir);
 
@@ -564,29 +474,19 @@ struct dentry *debugfs_create_automount(const char *name,
 					debugfs_automount_t f,
 					void *data)
 {
-	struct dentry *dentry = start_creating(name, parent);
+	struct dentry *dentry;
 	struct inode *inode;
 
+	dentry = simplefs_create_dentry(&debugfs, &debug_fs_type, name, parent,
+					&inode);
 	if (IS_ERR(dentry))
 		return dentry;
 
-	inode = simple_new_inode(dentry->d_sb);
-	if (unlikely(!inode)) {
-		pr_err("out of free dentries, can not create automount '%s'\n",
-		       name);
-		return failed_creating(dentry);
-	}
-
 	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);
-	d_instantiate(dentry, inode);
-	inc_nlink(d_inode(dentry->d_parent));
-	fsnotify_mkdir(d_inode(dentry->d_parent), dentry);
-	return end_creating(dentry);
+	return simplefs_finish_dentry(dentry, inode);
 }
 EXPORT_SYMBOL(debugfs_create_automount);
 
@@ -618,28 +518,14 @@ struct dentry *debugfs_create_symlink(const char *name, struct dentry *parent,
 {
 	struct dentry *dentry;
 	struct inode *inode;
-	char *link = kstrdup(target, GFP_KERNEL);
-	if (!link)
-		return ERR_PTR(-ENOMEM);
 
-	dentry = start_creating(name, parent);
-	if (IS_ERR(dentry)) {
-		kfree(link);
+	dentry = simplefs_create_symlink(&debugfs, &debug_fs_type,
+					 name, parent, target, &inode);
+	if (IS_ERR(dentry))
 		return dentry;
-	}
 
-	inode = simple_new_inode(dentry->d_sb);
-	if (unlikely(!inode)) {
-		pr_err("out of free dentries, can not create symlink '%s'\n",
-		       name);
-		kfree(link);
-		return failed_creating(dentry);
-	}
-	inode->i_mode = S_IFLNK | S_IRWXUGO;
 	inode->i_op = &debugfs_symlink_inode_operations;
-	inode->i_link = link;
-	d_instantiate(dentry, inode);
-	return end_creating(dentry);
+	return simplefs_finish_dentry(dentry, inode);
 }
 EXPORT_SYMBOL_GPL(debugfs_create_symlink);
 
-- 
2.25.2

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

WARNING: multiple messages have this Message-ID (diff)
From: Emanuele Giuseppe Esposito <eesposit@redhat.com>
To: linux-nfs@vger.kernel.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	Emanuele Giuseppe Esposito <eesposit@redhat.com>,
	Jeremy Kerr <jk@ozlabs.org>, Arnd Bergmann <arnd@arndb.de>,
	Michael Ellerman <mpe@ellerman.id.au>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Paul Mackerras <paulus@samba.org>,
	Heiko Carstens <heiko.carstens@de.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>,
	Christian Borntraeger <borntraeger@de.ibm.com>,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Maxime Ripard <mripard@kernel.org>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	David Airlie <airlied@linux.ie>, Daniel Vetter <daniel@ffwll.ch>,
	Dennis Dalessandro <dennis.dalessandro@intel.com>,
	Mike Marciniszyn <mike.marciniszyn@intel.com>,
	Doug Ledford <dledford@redhat.com>,
	Jason Gunthorpe <jgg@ziepe.ca>,
	Frederic Barrat <fbarrat@linux.ibm.com>,
	Andrew Donnellan <ajd@linux.ibm.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Robert Richter <rric@kernel.org>,
	"Manoj N. Kumar" <manoj@linux.ibm.com>,
	"Matthew R. Ochs" <mrochs@linux.ibm.com>,
	Uma Krishnan <ukrishn@linux.ibm.com>,
	"James E.J. Bottomley" <jejb@linux.ibm.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	Felipe Balbi <balbi@kernel.org>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	Ian Kent <raven@themaw.net>, Joel Becker <jlbec@evilplan.org>,
	Christoph Hellwig <hch@lst.de>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Matthew Garrett <matthew.garrett@nebula.com>,
	Ard Biesheuvel <ardb@kernel.org>,
	Miklos Szeredi <miklos@szeredi.hu>,
	Mike Kravetz <mike.kravetz@oracle.com>,
	Mark Fasheh <mark@fasheh.com>,
	Joseph Qi <joseph.qi@linux.alibaba.com>,
	Alexey Dobriyan <adobriyan@gmail.com>,
	Luis Chamberlain <mcgrof@kernel.org>,
	Kees Cook <keescook@chromium.org>,
	Iurii Zaikin <yzaikin@google.com>,
	Anton Vorontsov <anton@enomsg.org>,
	Colin Cross <ccross@android.com>, Tony Luck <tony.luck@intel.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Martin KaFai Lau <kafai@fb.com>, Song Liu <songliubraving@fb.com>,
	Yonghong Song <yhs@fb.com>, Andrii Nakryiko <andriin@fb.com>,
	John Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@chromium.org>, Hugh Dickins <hughd@google.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	"J. Bruce Fields" <bfields@fieldses.org>,
	Chuck Lever <chuck.lever@oracle.com>,
	Trond Myklebust <trond.myklebust@hammerspace.com>,
	Anna Schumaker <anna.schumaker@netapp.com>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	James Morris <jmorris@namei.org>,
	"Serge E. Hallyn" <serge@hallyn.com>,
	John Johansen <john.johansen@canonical.com>,
	linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org,
	linux-s390@vger.kernel.org, dri-devel@lists.freedesktop.org,
	linux-rdma@vger.kernel.org, oprofile-list@lists.sf.net,
	linux-scsi@vger.kernel.org, linux-usb@vger.kernel.org,
	linux-fsdevel@vger.kernel.org, autofs@vger.kernel.org,
	linux-efi@vger.kernel.org, linux-mm@kvack.org,
	ocfs2-devel@oss.oracle.com, netdev@vger.kernel.org,
	bpf@vger.kernel.org, linux-security-module@vger.kernel.org
Subject: [PATCH 7/8] debugfs: switch to simplefs inode creation API
Date: Tue, 14 Apr 2020 14:43:01 +0200	[thread overview]
Message-ID: <20200414124304.4470-8-eesposit@redhat.com> (raw)
In-Reply-To: <20200414124304.4470-1-eesposit@redhat.com>

The only difference, compared to the pre-existing code, is that symlink
creation now triggers fsnotify_create.  This was a bug in the debugfs
code, since for example vfs_symlink does call fsnotify_create.

Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
---
 fs/debugfs/inode.c | 144 +++++----------------------------------------
 1 file changed, 15 insertions(+), 129 deletions(-)

diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
index 834b5872ca0d..7a2369373b85 100644
--- a/fs/debugfs/inode.c
+++ b/fs/debugfs/inode.c
@@ -294,68 +294,6 @@ struct dentry *debugfs_lookup(const char *name, struct dentry *parent)
 }
 EXPORT_SYMBOL_GPL(debugfs_lookup);
 
-static struct dentry *start_creating(const char *name, struct dentry *parent)
-{
-	struct dentry *dentry;
-	int error;
-
-	pr_debug("creating file '%s'\n", name);
-
-	if (IS_ERR(parent))
-		return parent;
-
-	error = simple_pin_fs(&debugfs, &debug_fs_type);
-	if (error) {
-		pr_err("Unable to pin filesystem for file '%s'\n", name);
-		return ERR_PTR(error);
-	}
-
-	/* If the parent is not specified, we create it in the root.
-	 * We need the root dentry to do this, which is in the super
-	 * block. A pointer to that is in the struct vfsmount that we
-	 * have around.
-	 */
-	if (!parent)
-		parent = debugfs.mount->mnt_root;
-
-	inode_lock(d_inode(parent));
-	if (unlikely(IS_DEADDIR(d_inode(parent))))
-		dentry = ERR_PTR(-ENOENT);
-	else
-		dentry = lookup_one_len(name, parent, strlen(name));
-	if (!IS_ERR(dentry) && d_really_is_positive(dentry)) {
-		if (d_is_dir(dentry))
-			pr_err("Directory '%s' with parent '%s' already present!\n",
-			       name, parent->d_name.name);
-		else
-			pr_err("File '%s' in directory '%s' already present!\n",
-			       name, parent->d_name.name);
-		dput(dentry);
-		dentry = ERR_PTR(-EEXIST);
-	}
-
-	if (IS_ERR(dentry)) {
-		inode_unlock(d_inode(parent));
-		simple_release_fs(&debugfs);
-	}
-
-	return dentry;
-}
-
-static struct dentry *failed_creating(struct dentry *dentry)
-{
-	inode_unlock(d_inode(dentry->d_parent));
-	dput(dentry);
-	simple_release_fs(&debugfs);
-	return ERR_PTR(-ENOMEM);
-}
-
-static struct dentry *end_creating(struct dentry *dentry)
-{
-	inode_unlock(d_inode(dentry->d_parent));
-	return dentry;
-}
-
 static struct dentry *__debugfs_create_file(const char *name, umode_t mode,
 				struct dentry *parent, void *data,
 				const struct file_operations *proxy_fops,
@@ -364,32 +302,17 @@ static struct dentry *__debugfs_create_file(const char *name, umode_t mode,
 	struct dentry *dentry;
 	struct inode *inode;
 
-	if (!(mode & S_IFMT))
-		mode |= S_IFREG;
-	BUG_ON(!S_ISREG(mode));
-	dentry = start_creating(name, parent);
-
+	dentry = simplefs_create_file(&debugfs, &debug_fs_type,
+				      name, mode, parent, data, &inode);
 	if (IS_ERR(dentry))
 		return dentry;
 
-	inode = simple_new_inode(dentry->d_sb);
-	if (unlikely(!inode)) {
-		pr_err("out of free dentries, can not create file '%s'\n",
-		       name);
-		return failed_creating(dentry);
-	}
-
-	inode->i_mode = mode;
-	inode->i_private = data;
-
 	inode->i_op = &debugfs_file_inode_operations;
 	inode->i_fop = proxy_fops;
 	dentry->d_fsdata = (void *)((unsigned long)real_fops |
 				DEBUGFS_FSDATA_IS_REAL_FOPS_BIT);
 
-	d_instantiate(dentry, inode);
-	fsnotify_create(d_inode(dentry->d_parent), dentry);
-	return end_creating(dentry);
+	return simplefs_finish_dentry(dentry, inode);
 }
 
 /**
@@ -522,29 +445,16 @@ EXPORT_SYMBOL_GPL(debugfs_create_file_size);
  */
 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
 {
-	struct dentry *dentry = start_creating(name, parent);
+	struct dentry *dentry;
 	struct inode *inode;
 
+	dentry = simplefs_create_dir(&debugfs, &debug_fs_type,
+				     name, 0755, parent, &inode);
 	if (IS_ERR(dentry))
 		return dentry;
 
-	inode = simple_new_inode(dentry->d_sb);
-	if (unlikely(!inode)) {
-		pr_err("out of free dentries, can not create directory '%s'\n",
-		       name);
-		return failed_creating(dentry);
-	}
-
-	inode->i_mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
 	inode->i_op = &debugfs_dir_inode_operations;
-	inode->i_fop = &simple_dir_operations;
-
-	/* directory inodes start off with i_nlink == 2 (for "." entry) */
-	inc_nlink(inode);
-	d_instantiate(dentry, inode);
-	inc_nlink(d_inode(dentry->d_parent));
-	fsnotify_mkdir(d_inode(dentry->d_parent), dentry);
-	return end_creating(dentry);
+	return simplefs_finish_dentry(dentry, inode);
 }
 EXPORT_SYMBOL_GPL(debugfs_create_dir);
 
@@ -564,29 +474,19 @@ struct dentry *debugfs_create_automount(const char *name,
 					debugfs_automount_t f,
 					void *data)
 {
-	struct dentry *dentry = start_creating(name, parent);
+	struct dentry *dentry;
 	struct inode *inode;
 
+	dentry = simplefs_create_dentry(&debugfs, &debug_fs_type, name, parent,
+					&inode);
 	if (IS_ERR(dentry))
 		return dentry;
 
-	inode = simple_new_inode(dentry->d_sb);
-	if (unlikely(!inode)) {
-		pr_err("out of free dentries, can not create automount '%s'\n",
-		       name);
-		return failed_creating(dentry);
-	}
-
 	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);
-	d_instantiate(dentry, inode);
-	inc_nlink(d_inode(dentry->d_parent));
-	fsnotify_mkdir(d_inode(dentry->d_parent), dentry);
-	return end_creating(dentry);
+	return simplefs_finish_dentry(dentry, inode);
 }
 EXPORT_SYMBOL(debugfs_create_automount);
 
@@ -618,28 +518,14 @@ struct dentry *debugfs_create_symlink(const char *name, struct dentry *parent,
 {
 	struct dentry *dentry;
 	struct inode *inode;
-	char *link = kstrdup(target, GFP_KERNEL);
-	if (!link)
-		return ERR_PTR(-ENOMEM);
 
-	dentry = start_creating(name, parent);
-	if (IS_ERR(dentry)) {
-		kfree(link);
+	dentry = simplefs_create_symlink(&debugfs, &debug_fs_type,
+					 name, parent, target, &inode);
+	if (IS_ERR(dentry))
 		return dentry;
-	}
 
-	inode = simple_new_inode(dentry->d_sb);
-	if (unlikely(!inode)) {
-		pr_err("out of free dentries, can not create symlink '%s'\n",
-		       name);
-		kfree(link);
-		return failed_creating(dentry);
-	}
-	inode->i_mode = S_IFLNK | S_IRWXUGO;
 	inode->i_op = &debugfs_symlink_inode_operations;
-	inode->i_link = link;
-	d_instantiate(dentry, inode);
-	return end_creating(dentry);
+	return simplefs_finish_dentry(dentry, inode);
 }
 EXPORT_SYMBOL_GPL(debugfs_create_symlink);
 
-- 
2.25.2



  parent reply	other threads:[~2020-04-14 12:43 UTC|newest]

Thread overview: 130+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-14 12:42 [PATCH 0/8] Simplefs: group and simplify linux fs code Emanuele Giuseppe Esposito
2020-04-14 12:42 ` Emanuele Giuseppe Esposito
2020-04-14 12:42 ` Emanuele Giuseppe Esposito
2020-04-14 12:42 ` Emanuele Giuseppe Esposito
2020-04-14 12:42 ` [Ocfs2-devel] " Emanuele Giuseppe Esposito
2020-04-14 12:42 ` [PATCH 1/8] apparmor: just use vfs_kern_mount to make .null Emanuele Giuseppe Esposito
2020-04-14 12:42   ` Emanuele Giuseppe Esposito
2020-04-14 12:42   ` Emanuele Giuseppe Esposito
2020-04-14 12:42   ` Emanuele Giuseppe Esposito
2020-04-14 12:42   ` [Ocfs2-devel] " Emanuele Giuseppe Esposito
2020-04-15 12:52   ` kbuild test robot
2020-04-15 12:52     ` kbuild test robot
2020-04-16  6:44   ` Luis Chamberlain
2020-04-16  6:44     ` Luis Chamberlain
2020-04-16  6:44     ` Luis Chamberlain
2020-04-16  6:44     ` Luis Chamberlain
2020-04-16  6:44     ` [Ocfs2-devel] " Luis Chamberlain
2020-04-20 14:00     ` Emanuele Giuseppe Esposito
2020-04-20 14:00       ` Emanuele Giuseppe Esposito
2020-04-20 14:00       ` Emanuele Giuseppe Esposito
2020-04-20 14:00       ` Emanuele Giuseppe Esposito
2020-04-14 12:42 ` [PATCH 2/8] fs: extract simple_pin/release_fs to separate files Emanuele Giuseppe Esposito
2020-04-14 12:42   ` Emanuele Giuseppe Esposito
2020-04-14 12:42   ` Emanuele Giuseppe Esposito
2020-04-14 12:42   ` Emanuele Giuseppe Esposito
2020-04-14 12:42   ` [Ocfs2-devel] " Emanuele Giuseppe Esposito
2020-04-14 12:54   ` Greg Kroah-Hartman
2020-04-14 12:54     ` Greg Kroah-Hartman
2020-04-14 12:54     ` Greg Kroah-Hartman
2020-04-14 12:54     ` Greg Kroah-Hartman
2020-04-14 12:54     ` [Ocfs2-devel] " Greg Kroah-Hartman
2020-04-15  0:57   ` kbuild test robot
2020-04-15  0:57     ` kbuild test robot
2020-04-15  0:57     ` kbuild test robot
2020-04-16  6:52   ` Luis Chamberlain
2020-04-16  6:52     ` Luis Chamberlain
2020-04-16  6:52     ` Luis Chamberlain
2020-04-16  6:52     ` Luis Chamberlain
2020-04-16  6:52     ` [Ocfs2-devel] " Luis Chamberlain
2020-04-21 11:19   ` Frederic Barrat
2020-04-21 11:19     ` Frederic Barrat
2020-04-21 11:19     ` Frederic Barrat
2020-04-21 11:19     ` Frederic Barrat
2020-04-21 11:19     ` [Ocfs2-devel] " Frederic Barrat
2020-04-21 11:26     ` Emanuele Giuseppe Esposito
2020-04-21 11:26       ` Emanuele Giuseppe Esposito
2020-04-21 11:26       ` Emanuele Giuseppe Esposito
2020-04-21 11:26       ` Emanuele Giuseppe Esposito
2020-04-21 11:26       ` [Ocfs2-devel] " Emanuele Giuseppe Esposito
2020-04-14 12:42 ` [PATCH 3/8] fs: wrap simple_pin_fs/simple_release_fs arguments in a struct Emanuele Giuseppe Esposito
2020-04-14 12:42   ` Emanuele Giuseppe Esposito
2020-04-14 12:42   ` Emanuele Giuseppe Esposito
2020-04-14 12:42   ` Emanuele Giuseppe Esposito
2020-04-14 12:42   ` [Ocfs2-devel] " Emanuele Giuseppe Esposito
2020-04-14 13:03   ` Greg Kroah-Hartman
2020-04-14 13:03     ` Greg Kroah-Hartman
2020-04-14 13:03     ` Greg Kroah-Hartman
2020-04-14 13:03     ` Greg Kroah-Hartman
2020-04-14 13:03     ` [Ocfs2-devel] " Greg Kroah-Hartman
2020-04-14 23:24   ` kbuild test robot
2020-04-14 23:24     ` kbuild test robot
2020-04-14 12:42 ` [PATCH 4/8] fs: introduce simple_new_inode Emanuele Giuseppe Esposito
2020-04-14 12:42   ` Emanuele Giuseppe Esposito
2020-04-14 12:42   ` Emanuele Giuseppe Esposito
2020-04-14 12:42   ` Emanuele Giuseppe Esposito
2020-04-14 12:42   ` [Ocfs2-devel] " Emanuele Giuseppe Esposito
2020-04-14 13:01   ` Greg Kroah-Hartman
2020-04-14 13:01     ` Greg Kroah-Hartman
2020-04-14 13:01     ` Greg Kroah-Hartman
2020-04-14 13:01     ` Greg Kroah-Hartman
2020-04-14 13:01     ` [Ocfs2-devel] " Greg Kroah-Hartman
2020-04-20 13:58     ` Emanuele Giuseppe Esposito
2020-04-20 13:58       ` Emanuele Giuseppe Esposito
2020-04-20 13:58       ` Emanuele Giuseppe Esposito
2020-04-20 13:58       ` Emanuele Giuseppe Esposito
2020-04-20 13:58       ` [Ocfs2-devel] " Emanuele Giuseppe Esposito
2020-04-14 12:42 ` [PATCH 5/8] simplefs: add alloc_anon_inode wrapper Emanuele Giuseppe Esposito
2020-04-14 12:42   ` Emanuele Giuseppe Esposito
2020-04-14 12:42   ` Emanuele Giuseppe Esposito
2020-04-14 12:42   ` Emanuele Giuseppe Esposito
2020-04-14 12:42   ` [Ocfs2-devel] " Emanuele Giuseppe Esposito
2020-04-14 12:55   ` Greg Kroah-Hartman
2020-04-14 12:55     ` Greg Kroah-Hartman
2020-04-14 12:55     ` Greg Kroah-Hartman
2020-04-14 12:55     ` Greg Kroah-Hartman
2020-04-14 12:55     ` [Ocfs2-devel] " Greg Kroah-Hartman
2020-04-14 12:43 ` [PATCH 6/8] simplefs: add file creation functions Emanuele Giuseppe Esposito
2020-04-14 12:43   ` Emanuele Giuseppe Esposito
2020-04-14 12:43   ` Emanuele Giuseppe Esposito
2020-04-14 12:43   ` Emanuele Giuseppe Esposito
2020-04-14 12:43   ` [Ocfs2-devel] " Emanuele Giuseppe Esposito
2020-04-14 12:56   ` Greg Kroah-Hartman
2020-04-14 12:56     ` Greg Kroah-Hartman
2020-04-14 12:56     ` Greg Kroah-Hartman
2020-04-14 12:56     ` Greg Kroah-Hartman
2020-04-14 12:56     ` [Ocfs2-devel] " Greg Kroah-Hartman
2020-04-20 13:57     ` Emanuele Giuseppe Esposito
2020-04-20 13:57       ` Emanuele Giuseppe Esposito
2020-04-20 13:57       ` Emanuele Giuseppe Esposito
2020-04-20 13:57       ` Emanuele Giuseppe Esposito
2020-04-20 13:57       ` [Ocfs2-devel] " Emanuele Giuseppe Esposito
2020-04-20 14:28       ` Greg Kroah-Hartman
2020-04-20 14:28         ` Greg Kroah-Hartman
2020-04-20 14:28         ` Greg Kroah-Hartman
2020-04-20 14:28         ` Greg Kroah-Hartman
2020-04-20 14:28         ` [Ocfs2-devel] " Greg Kroah-Hartman
2020-04-20 14:33         ` Paolo Bonzini
2020-04-20 14:33           ` Paolo Bonzini
2020-04-20 14:33           ` Paolo Bonzini
2020-04-20 14:33           ` Paolo Bonzini
2020-04-20 14:33           ` [Ocfs2-devel] " Paolo Bonzini
2020-04-14 12:43 ` Emanuele Giuseppe Esposito [this message]
2020-04-14 12:43   ` [PATCH 7/8] debugfs: switch to simplefs inode creation API Emanuele Giuseppe Esposito
2020-04-14 12:43   ` Emanuele Giuseppe Esposito
2020-04-14 12:43   ` Emanuele Giuseppe Esposito
2020-04-14 12:43   ` [Ocfs2-devel] " Emanuele Giuseppe Esposito
2020-04-14 12:43 ` [PATCH 8/8] tracefs: " Emanuele Giuseppe Esposito
2020-04-14 12:43   ` Emanuele Giuseppe Esposito
2020-04-14 12:43   ` Emanuele Giuseppe Esposito
2020-04-14 12:43   ` Emanuele Giuseppe Esposito
2020-04-14 12:43   ` [Ocfs2-devel] " Emanuele Giuseppe Esposito
2020-04-16  6:59 ` [PATCH 0/8] Simplefs: group and simplify linux fs code Luis Chamberlain
2020-04-16  6:59   ` Luis Chamberlain
2020-04-16  6:59   ` Luis Chamberlain
2020-04-16  6:59   ` Luis Chamberlain
2020-04-16  6:59   ` [Ocfs2-devel] " Luis Chamberlain
2020-04-20 14:01   ` Emanuele Giuseppe Esposito
2020-04-20 14:01     ` Emanuele Giuseppe Esposito
2020-04-20 14:01     ` Emanuele Giuseppe Esposito
2020-04-20 14:01     ` Emanuele Giuseppe Esposito

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=20200414124304.4470-8-eesposit@redhat.com \
    --to=eesposit@redhat.com \
    --cc=airlied@linux.ie \
    --cc=ajd@linux.ibm.com \
    --cc=arnd@arndb.de \
    --cc=ast@kernel.org \
    --cc=bfields@fieldses.org \
    --cc=borntraeger@de.ibm.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=hch@lst.de \
    --cc=heiko.carstens@de.ibm.com \
    --cc=hughd@google.com \
    --cc=john.johansen@canonical.com \
    --cc=joseph.qi@linux.alibaba.com \
    --cc=linux-efi@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mark@fasheh. \
    --cc=matthew.garrett@nebula.com \
    --cc=netdev@vger.kernel.org \
    --cc=paulus@samba.org \
    --cc=rafael@kernel.org \
    --cc=songliubraving@fb.com \
    /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.