Commit 26d8e430 authored by Linus Torvalds's avatar Linus Torvalds
Browse files

Merge tag 'vfs-6.15-rc1.async.dir' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs

Pull vfs async dir updates from Christian Brauner:
 "This contains cleanups that fell out of the work from async directory
  handling:

   - Change kern_path_locked() and user_path_locked_at() to never return
     a negative dentry. This simplifies the usability of these helpers
     in various places

   - Drop d_exact_alias() from the remaining place in NFS where it is
     still used. This also allows us to drop the d_exact_alias() helper
     completely

   - Drop an unnecessary call to fh_update() from nfsd_create_locked()

   - Change i_op->mkdir() to return a struct dentry

     Change vfs_mkdir() to return a dentry provided by the filesystems
     which is hashed and positive. This allows us to reduce the number
     of cases where the resulting dentry is not positive to very few
     cases. The code in these places becomes simpler and easier to
     understand.

   - Repack DENTRY_* and LOOKUP_* flags"

* tag 'vfs-6.15-rc1.async.dir' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs:
  doc: fix inline emphasis warning
  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 *
  nfsd: drop fh_update() from S_IFDIR branch of nfsd_create_locked()
  nfs/vfs: discard d_exact_alias()
  VFS: add common error checks to lookup_one_qstr_excl()
  VFS: change kern_path_locked() and user_path_locked_at() to never return negative dentry
  VFS: repack LOOKUP_ bit flags.
  VFS: repack DENTRY_ flags.
parents 804382d5 be669019
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 *,
+43 −2
Original line number Diff line number Diff line
@@ -1160,5 +1160,46 @@ magic.

---

**recommended**

kern_path_locked() and user_path_locked() no longer return a negative
dentry so this doesn't need to be checked.  If the name cannot be found,
ERR_PTR(-ENOENT) is returned.

---

**recommended**

lookup_one_qstr_excl() is changed to return errors in more cases, so
these conditions don't require explicit checks:

 - if LOOKUP_CREATE is NOT given, then the dentry won't be negative,
   ERR_PTR(-ENOENT) is returned instead
 - if LOOKUP_EXCL IS given, then the dentry won't be positive,
   ERR_PTR(-EEXIST) is rreturned instread

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

---

**mandatory**
invalidate_inodes() is gone use evict_inodes() instead.

---

**mandatory**

->mkdir() now returns a 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
+33 −39
Original line number Diff line number Diff line
@@ -175,18 +175,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)
@@ -260,15 +259,12 @@ static int dev_rmdir(const char *name)
	dentry = kern_path_locked(name, &parent);
	if (IS_ERR(dentry))
		return PTR_ERR(dentry);
	if (d_really_is_positive(dentry)) {
	if (d_inode(dentry)->i_private == &thread)
		err = vfs_rmdir(&nop_mnt_idmap, d_inode(parent.dentry),
				dentry);
	else
		err = -EPERM;
	} else {
		err = -ENOENT;
	}

	dput(dentry);
	inode_unlock(d_inode(parent.dentry));
	path_put(&parent);
@@ -325,6 +321,8 @@ static int handle_remove(const char *nodename, struct device *dev)
{
	struct path parent;
	struct dentry *dentry;
	struct kstat stat;
	struct path p;
	int deleted = 0;
	int err;

@@ -332,9 +330,8 @@ static int handle_remove(const char *nodename, struct device *dev)
	if (IS_ERR(dentry))
		return PTR_ERR(dentry);

	if (d_really_is_positive(dentry)) {
		struct kstat stat;
		struct path p = {.mnt = parent.mnt, .dentry = dentry};
	p.mnt = parent.mnt;
	p.dentry = dentry;
	err = vfs_getattr(&p, &stat, STATX_TYPE | STATX_MODE,
			  AT_STATX_SYNC_AS_STAT);
	if (!err && dev_mynode(dev, d_inode(dentry), &stat)) {
@@ -356,9 +353,6 @@ static int handle_remove(const char *nodename, struct device *dev)
		if (!err || err == -ENOENT)
			deleted = 1;
	}
	} else {
		err = -ENOENT;
	}
	dput(dentry);
	inode_unlock(d_inode(parent.dentry));

+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