Unverified Commit 21432f9b authored by Christian Brauner's avatar Christian Brauner
Browse files

Merge patch series "Change inode_operations.mkdir to return struct dentry *"

NeilBrown <neilb@suse.de> says:

This revised series contains a few clean-ups as requested by various
people but no substantial changes.

I reviewed the mkdir functions in many (all?) filesystems and found a
few that use d_instantiate() on an unlocked inode (after
unlock_new_inode()) and also support export_operations. These could
potentially call d_instantiate() on a directory inode which is already
attached to a dentry, though making that happen would usually require
guessing the filehandle correctly. I haven't tried to address those
here, (this patch set doesn't make that situation any worse) but I may
in the future.

* patches from https://lore.kernel.org/r/20250227013949.536172-2-neilb@suse.de:
  VFS: Change vfs_mkdir() to return the dentry.
  nfs: change mkdir inode_operation to return alternate dentry if needed.
  fuse: return correct dentry for ->mkdir
  ceph: return the correct dentry on mkdir
  hostfs: store inode in dentry after mkdir if possible.
  Change inode_operations.mkdir to return struct dentry *

Link: https://lore.kernel.org/r/20250227013949.536172-2-neilb@suse.de


Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
parents 71628584 c54b3869
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -66,7 +66,7 @@ prototypes::
	int (*link) (struct dentry *,struct inode *,struct dentry *);
	int (*unlink) (struct inode *,struct dentry *);
	int (*symlink) (struct mnt_idmap *, struct inode *,struct dentry *,const char *);
	int (*mkdir) (struct mnt_idmap *, struct inode *,struct dentry *,umode_t);
	struct dentry *(*mkdir) (struct mnt_idmap *, struct inode *,struct dentry *,umode_t);
	int (*rmdir) (struct inode *,struct dentry *);
	int (*mknod) (struct mnt_idmap *, struct inode *,struct dentry *,umode_t,dev_t);
	int (*rename) (struct mnt_idmap *, struct inode *, struct dentry *,
+19 −0
Original line number Diff line number Diff line
@@ -1178,3 +1178,22 @@ these conditions don't require explicit checks:

LOOKUP_EXCL now means "target must not exist".  It can be combined with
LOOK_CREATE or LOOKUP_RENAME_TARGET.

---

** mandatory**

->mkdir() now returns a 'struct dentry *'.  If the created inode is
found to already be in cache and have a dentry (often IS_ROOT()), it will
need to be spliced into the given name in place of the given dentry.
That dentry now needs to be returned.  If the original dentry is used,
NULL should be returned.  Any error should be returned with
ERR_PTR().

In general, filesystems which use d_instantiate_new() to install the new
inode can safely return NULL.  Filesystems which may not have an I_NEW inode
should use d_drop();d_splice_alias() and return the result of the latter.

If a positive dentry cannot be returned for some reason, in-kernel
clients such as cachefiles, nfsd, smb/server may not perform ideally but
will fail-safe.
+21 −2
Original line number Diff line number Diff line
@@ -495,7 +495,7 @@ As of kernel 2.6.22, the following members are defined:
		int (*link) (struct dentry *,struct inode *,struct dentry *);
		int (*unlink) (struct inode *,struct dentry *);
		int (*symlink) (struct mnt_idmap *, struct inode *,struct dentry *,const char *);
		int (*mkdir) (struct mnt_idmap *, struct inode *,struct dentry *,umode_t);
		struct dentry *(*mkdir) (struct mnt_idmap *, struct inode *,struct dentry *,umode_t);
		int (*rmdir) (struct inode *,struct dentry *);
		int (*mknod) (struct mnt_idmap *, struct inode *,struct dentry *,umode_t,dev_t);
		int (*rename) (struct mnt_idmap *, struct inode *, struct dentry *,
@@ -562,7 +562,26 @@ otherwise noted.
``mkdir``
	called by the mkdir(2) system call.  Only required if you want
	to support creating subdirectories.  You will probably need to
	call d_instantiate() just as you would in the create() method
	call d_instantiate_new() just as you would in the create() method.

	If d_instantiate_new() is not used and if the fh_to_dentry()
	export operation is provided, or if the storage might be
	accessible by another path (e.g. with a network filesystem)
	then more care may be needed.  Importantly d_instantate()
	should not be used with an inode that is no longer I_NEW if there
	any chance that the inode could already be attached to a dentry.
	This is because of a hard rule in the VFS that a directory must
	only ever have one dentry.

	For example, if an NFS filesystem is mounted twice the new directory
	could be visible on the other mount before it is on the original
	mount, and a pair of name_to_handle_at(), open_by_handle_at()
	calls could instantiate the directory inode with an IS_ROOT()
	dentry before the first mkdir returns.

	If there is any chance this could happen, then the new inode
	should be d_drop()ed and attached with d_splice_alias().  The
	returned dentry (if any) should be returned by ->mkdir().

``rmdir``
	called by the rmdir(2) system call.  Only required if you want
+3 −4
Original line number Diff line number Diff line
@@ -160,18 +160,17 @@ static int dev_mkdir(const char *name, umode_t mode)
{
	struct dentry *dentry;
	struct path path;
	int err;

	dentry = kern_path_create(AT_FDCWD, name, &path, LOOKUP_DIRECTORY);
	if (IS_ERR(dentry))
		return PTR_ERR(dentry);

	err = vfs_mkdir(&nop_mnt_idmap, d_inode(path.dentry), dentry, mode);
	if (!err)
	dentry = vfs_mkdir(&nop_mnt_idmap, d_inode(path.dentry), dentry, mode);
	if (!IS_ERR(dentry))
		/* mark as kernel-created inode */
		d_inode(dentry)->i_private = &thread;
	done_path_create(&path, dentry);
	return err;
	return PTR_ERR_OR_ZERO(dentry);
}

static int create_path(const char *nodepath)
+3 −4
Original line number Diff line number Diff line
@@ -669,7 +669,7 @@ v9fs_vfs_create(struct mnt_idmap *idmap, struct inode *dir,
 *
 */

static int v9fs_vfs_mkdir(struct mnt_idmap *idmap, struct inode *dir,
static struct dentry *v9fs_vfs_mkdir(struct mnt_idmap *idmap, struct inode *dir,
				     struct dentry *dentry, umode_t mode)
{
	int err;
@@ -692,8 +692,7 @@ static int v9fs_vfs_mkdir(struct mnt_idmap *idmap, struct inode *dir,

	if (fid)
		p9_fid_put(fid);

	return err;
	return ERR_PTR(err);
}

/**
Loading