Unverified Commit 3d18f80c authored by NeilBrown's avatar NeilBrown Committed by Christian Brauner
Browse files

VFS: rename kern_path_locked() and related functions.



kern_path_locked() is now only used to prepare for removing an object
from the filesystem (and that is the only credible reason for wanting a
positive locked dentry).  Thus it corresponds to kern_path_create() and
so should have a corresponding name.

Unfortunately the name "kern_path_create" is somewhat misleading as it
doesn't actually create anything.  The recently added
simple_start_creating() provides a better pattern I believe.  The
"start" can be matched with "end" to bracket the creating or removing.

So this patch changes names:

 kern_path_locked -> start_removing_path
 kern_path_create -> start_creating_path
 user_path_create -> start_creating_user_path
 user_path_locked_at -> start_removing_user_path_at
 done_path_create -> end_creating_path

and also introduces end_removing_path() which is identical to
end_creating_path().

__start_removing_path (which was __kern_path_locked) is enhanced to
call mnt_want_write() for consistency with the start_creating_path().

Reviewed-by: default avatarAmir Goldstein <amir73il@gmail.com>
Signed-off-by: default avatarNeilBrown <neil@brown.name>
Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
parent 76a53de6
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -1285,3 +1285,15 @@ rather than a VMA, as the VMA at this stage is not yet valid.
The vm_area_desc provides the minimum required information for a filesystem
to initialise state upon memory mapping of a file-backed region, and output
parameters for the file system to set this state.

---

**mandatory**

Several functions are renamed:

-  kern_path_locked -> start_removing_path
-  kern_path_create -> start_creating_path
-  user_path_create -> start_creating_user_path
-  user_path_locked_at -> start_removing_user_path_at
-  done_path_create -> end_creating_path
+2 −2
Original line number Diff line number Diff line
@@ -67,11 +67,11 @@ static long do_spu_create(const char __user *pathname, unsigned int flags,
	struct dentry *dentry;
	int ret;

	dentry = user_path_create(AT_FDCWD, pathname, &path, LOOKUP_DIRECTORY);
	dentry = start_creating_user_path(AT_FDCWD, pathname, &path, LOOKUP_DIRECTORY);
	ret = PTR_ERR(dentry);
	if (!IS_ERR(dentry)) {
		ret = spufs_create(&path, dentry, flags, mode, neighbor);
		done_path_create(&path, dentry);
		end_creating_path(&path, dentry);
	}

	return ret;
+9 −13
Original line number Diff line number Diff line
@@ -176,7 +176,7 @@ static int dev_mkdir(const char *name, umode_t mode)
	struct dentry *dentry;
	struct path path;

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

@@ -184,7 +184,7 @@ static int dev_mkdir(const char *name, umode_t mode)
	if (!IS_ERR(dentry))
		/* mark as kernel-created inode */
		d_inode(dentry)->i_private = &thread;
	done_path_create(&path, dentry);
	end_creating_path(&path, dentry);
	return PTR_ERR_OR_ZERO(dentry);
}

@@ -222,10 +222,10 @@ static int handle_create(const char *nodename, umode_t mode, kuid_t uid,
	struct path path;
	int err;

	dentry = kern_path_create(AT_FDCWD, nodename, &path, 0);
	dentry = start_creating_path(AT_FDCWD, nodename, &path, 0);
	if (dentry == ERR_PTR(-ENOENT)) {
		create_path(nodename);
		dentry = kern_path_create(AT_FDCWD, nodename, &path, 0);
		dentry = start_creating_path(AT_FDCWD, nodename, &path, 0);
	}
	if (IS_ERR(dentry))
		return PTR_ERR(dentry);
@@ -246,7 +246,7 @@ static int handle_create(const char *nodename, umode_t mode, kuid_t uid,
		/* mark as kernel-created inode */
		d_inode(dentry)->i_private = &thread;
	}
	done_path_create(&path, dentry);
	end_creating_path(&path, dentry);
	return err;
}

@@ -256,7 +256,7 @@ static int dev_rmdir(const char *name)
	struct dentry *dentry;
	int err;

	dentry = kern_path_locked(name, &parent);
	dentry = start_removing_path(name, &parent);
	if (IS_ERR(dentry))
		return PTR_ERR(dentry);
	if (d_inode(dentry)->i_private == &thread)
@@ -265,9 +265,7 @@ static int dev_rmdir(const char *name)
	else
		err = -EPERM;

	dput(dentry);
	inode_unlock(d_inode(parent.dentry));
	path_put(&parent);
	end_removing_path(&parent, dentry);
	return err;
}

@@ -325,7 +323,7 @@ static int handle_remove(const char *nodename, struct device *dev)
	int deleted = 0;
	int err = 0;

	dentry = kern_path_locked(nodename, &parent);
	dentry = start_removing_path(nodename, &parent);
	if (IS_ERR(dentry))
		return PTR_ERR(dentry);

@@ -349,10 +347,8 @@ static int handle_remove(const char *nodename, struct device *dev)
		if (!err || err == -ENOENT)
			deleted = 1;
	}
	dput(dentry);
	inode_unlock(d_inode(parent.dentry));
	end_removing_path(&parent, dentry);

	path_put(&parent);
	if (deleted && strchr(nodename, '/'))
		delete_path(nodename);
	return err;
+4 −6
Original line number Diff line number Diff line
@@ -255,7 +255,7 @@ static long bch2_ioctl_subvolume_create(struct bch_fs *c, struct file *filp,
		snapshot_src = inode_inum(to_bch_ei(src_path.dentry->d_inode));
	}

	dst_dentry = user_path_create(arg.dirfd,
	dst_dentry = start_creating_user_path(arg.dirfd,
			(const char __user *)(unsigned long)arg.dst_ptr,
			&dst_path, lookup_flags);
	error = PTR_ERR_OR_ZERO(dst_dentry);
@@ -314,7 +314,7 @@ static long bch2_ioctl_subvolume_create(struct bch_fs *c, struct file *filp,
	d_instantiate(dst_dentry, &inode->v);
	fsnotify_mkdir(dir, dst_dentry);
err3:
	done_path_create(&dst_path, dst_dentry);
	end_creating_path(&dst_path, dst_dentry);
err2:
	if (arg.src_ptr)
		path_put(&src_path);
@@ -334,7 +334,7 @@ static long bch2_ioctl_subvolume_destroy(struct bch_fs *c, struct file *filp,
	if (arg.flags)
		return -EINVAL;

	victim = user_path_locked_at(arg.dirfd, name, &path);
	victim = start_removing_user_path_at(arg.dirfd, name, &path);
	if (IS_ERR(victim))
		return PTR_ERR(victim);

@@ -351,9 +351,7 @@ static long bch2_ioctl_subvolume_destroy(struct bch_fs *c, struct file *filp,
		d_invalidate(victim);
	}
err:
	inode_unlock(dir);
	dput(victim);
	path_put(&path);
	end_removing_path(&path, victim);
	return ret;
}

+9 −8
Original line number Diff line number Diff line
@@ -149,7 +149,7 @@ int __init init_mknod(const char *filename, umode_t mode, unsigned int dev)
	else if (!(S_ISBLK(mode) || S_ISCHR(mode)))
		return -EINVAL;

	dentry = kern_path_create(AT_FDCWD, filename, &path, 0);
	dentry = start_creating_path(AT_FDCWD, filename, &path, 0);
	if (IS_ERR(dentry))
		return PTR_ERR(dentry);

@@ -158,7 +158,7 @@ int __init init_mknod(const char *filename, umode_t mode, unsigned int dev)
	if (!error)
		error = vfs_mknod(mnt_idmap(path.mnt), path.dentry->d_inode,
				  dentry, mode, new_decode_dev(dev));
	done_path_create(&path, dentry);
	end_creating_path(&path, dentry);
	return error;
}

@@ -173,7 +173,7 @@ int __init init_link(const char *oldname, const char *newname)
	if (error)
		return error;

	new_dentry = kern_path_create(AT_FDCWD, newname, &new_path, 0);
	new_dentry = start_creating_path(AT_FDCWD, newname, &new_path, 0);
	error = PTR_ERR(new_dentry);
	if (IS_ERR(new_dentry))
		goto out;
@@ -191,7 +191,7 @@ int __init init_link(const char *oldname, const char *newname)
	error = vfs_link(old_path.dentry, idmap, new_path.dentry->d_inode,
			 new_dentry, NULL);
out_dput:
	done_path_create(&new_path, new_dentry);
	end_creating_path(&new_path, new_dentry);
out:
	path_put(&old_path);
	return error;
@@ -203,14 +203,14 @@ int __init init_symlink(const char *oldname, const char *newname)
	struct path path;
	int error;

	dentry = kern_path_create(AT_FDCWD, newname, &path, 0);
	dentry = start_creating_path(AT_FDCWD, newname, &path, 0);
	if (IS_ERR(dentry))
		return PTR_ERR(dentry);
	error = security_path_symlink(&path, dentry, oldname);
	if (!error)
		error = vfs_symlink(mnt_idmap(path.mnt), path.dentry->d_inode,
				    dentry, oldname);
	done_path_create(&path, dentry);
	end_creating_path(&path, dentry);
	return error;
}

@@ -225,7 +225,8 @@ int __init init_mkdir(const char *pathname, umode_t mode)
	struct path path;
	int error;

	dentry = kern_path_create(AT_FDCWD, pathname, &path, LOOKUP_DIRECTORY);
	dentry = start_creating_path(AT_FDCWD, pathname, &path,
				     LOOKUP_DIRECTORY);
	if (IS_ERR(dentry))
		return PTR_ERR(dentry);
	mode = mode_strip_umask(d_inode(path.dentry), mode);
@@ -236,7 +237,7 @@ int __init init_mkdir(const char *pathname, umode_t mode)
		if (IS_ERR(dentry))
			error = PTR_ERR(dentry);
	}
	done_path_create(&path, dentry);
	end_creating_path(&path, dentry);
	return error;
}

Loading