mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
vfs: make vfs_create break delegations on parent directory
In order to add directory delegation support, we need to break delegations on the parent whenever there is going to be a change in the directory. Add a delegated_inode parameter to vfs_create. Most callers are converted to pass in NULL, but do_mknodat() is changed to wait for a delegation break if there is one. Reviewed-by: Jan Kara <jack@suse.cz> Reviewed-by: NeilBrown <neil@brown.name> Signed-off-by: Jeff Layton <jlayton@kernel.org> Link: https://patch.msgid.link/20251111-dir-deleg-ro-v6-10-52f3feebb2f2@kernel.org Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
parent
85bbffcad7
commit
c826229c6a
|
|
@ -188,7 +188,7 @@ ecryptfs_do_create(struct inode *directory_inode,
|
||||||
|
|
||||||
rc = lock_parent(ecryptfs_dentry, &lower_dentry, &lower_dir);
|
rc = lock_parent(ecryptfs_dentry, &lower_dentry, &lower_dir);
|
||||||
if (!rc)
|
if (!rc)
|
||||||
rc = vfs_create(&nop_mnt_idmap, lower_dentry, mode);
|
rc = vfs_create(&nop_mnt_idmap, lower_dentry, mode, NULL);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
printk(KERN_ERR "%s: Failure to create dentry in lower fs; "
|
printk(KERN_ERR "%s: Failure to create dentry in lower fs; "
|
||||||
"rc = [%d]\n", __func__, rc);
|
"rc = [%d]\n", __func__, rc);
|
||||||
|
|
|
||||||
15
fs/namei.c
15
fs/namei.c
|
|
@ -3463,6 +3463,7 @@ static inline umode_t vfs_prepare_mode(struct mnt_idmap *idmap,
|
||||||
* @idmap: idmap of the mount the inode was found from
|
* @idmap: idmap of the mount the inode was found from
|
||||||
* @dentry: dentry of the child file
|
* @dentry: dentry of the child file
|
||||||
* @mode: mode of the child file
|
* @mode: mode of the child file
|
||||||
|
* @di: returns parent inode, if the inode is delegated.
|
||||||
*
|
*
|
||||||
* Create a new file.
|
* Create a new file.
|
||||||
*
|
*
|
||||||
|
|
@ -3472,7 +3473,8 @@ static inline umode_t vfs_prepare_mode(struct mnt_idmap *idmap,
|
||||||
* On non-idmapped mounts or if permission checking is to be performed on the
|
* On non-idmapped mounts or if permission checking is to be performed on the
|
||||||
* raw inode simply pass @nop_mnt_idmap.
|
* raw inode simply pass @nop_mnt_idmap.
|
||||||
*/
|
*/
|
||||||
int vfs_create(struct mnt_idmap *idmap, struct dentry *dentry, umode_t mode)
|
int vfs_create(struct mnt_idmap *idmap, struct dentry *dentry, umode_t mode,
|
||||||
|
struct delegated_inode *di)
|
||||||
{
|
{
|
||||||
struct inode *dir = d_inode(dentry->d_parent);
|
struct inode *dir = d_inode(dentry->d_parent);
|
||||||
int error;
|
int error;
|
||||||
|
|
@ -3486,6 +3488,9 @@ int vfs_create(struct mnt_idmap *idmap, struct dentry *dentry, umode_t mode)
|
||||||
|
|
||||||
mode = vfs_prepare_mode(idmap, dir, mode, S_IALLUGO, S_IFREG);
|
mode = vfs_prepare_mode(idmap, dir, mode, S_IALLUGO, S_IFREG);
|
||||||
error = security_inode_create(dir, dentry, mode);
|
error = security_inode_create(dir, dentry, mode);
|
||||||
|
if (error)
|
||||||
|
return error;
|
||||||
|
error = try_break_deleg(dir, di);
|
||||||
if (error)
|
if (error)
|
||||||
return error;
|
return error;
|
||||||
error = dir->i_op->create(idmap, dir, dentry, mode, true);
|
error = dir->i_op->create(idmap, dir, dentry, mode, true);
|
||||||
|
|
@ -4358,6 +4363,7 @@ static int may_mknod(umode_t mode)
|
||||||
static int do_mknodat(int dfd, struct filename *name, umode_t mode,
|
static int do_mknodat(int dfd, struct filename *name, umode_t mode,
|
||||||
unsigned int dev)
|
unsigned int dev)
|
||||||
{
|
{
|
||||||
|
struct delegated_inode di = { };
|
||||||
struct mnt_idmap *idmap;
|
struct mnt_idmap *idmap;
|
||||||
struct dentry *dentry;
|
struct dentry *dentry;
|
||||||
struct path path;
|
struct path path;
|
||||||
|
|
@ -4381,7 +4387,7 @@ static int do_mknodat(int dfd, struct filename *name, umode_t mode,
|
||||||
idmap = mnt_idmap(path.mnt);
|
idmap = mnt_idmap(path.mnt);
|
||||||
switch (mode & S_IFMT) {
|
switch (mode & S_IFMT) {
|
||||||
case 0: case S_IFREG:
|
case 0: case S_IFREG:
|
||||||
error = vfs_create(idmap, dentry, mode);
|
error = vfs_create(idmap, dentry, mode, &di);
|
||||||
if (!error)
|
if (!error)
|
||||||
security_path_post_mknod(idmap, dentry);
|
security_path_post_mknod(idmap, dentry);
|
||||||
break;
|
break;
|
||||||
|
|
@ -4396,6 +4402,11 @@ static int do_mknodat(int dfd, struct filename *name, umode_t mode,
|
||||||
}
|
}
|
||||||
out2:
|
out2:
|
||||||
end_creating_path(&path, dentry);
|
end_creating_path(&path, dentry);
|
||||||
|
if (is_delegated(&di)) {
|
||||||
|
error = break_deleg_wait(&di);
|
||||||
|
if (!error)
|
||||||
|
goto retry;
|
||||||
|
}
|
||||||
if (retry_estale(error, lookup_flags)) {
|
if (retry_estale(error, lookup_flags)) {
|
||||||
lookup_flags |= LOOKUP_REVAL;
|
lookup_flags |= LOOKUP_REVAL;
|
||||||
goto retry;
|
goto retry;
|
||||||
|
|
|
||||||
|
|
@ -344,7 +344,7 @@ nfsd3_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp,
|
||||||
status = fh_fill_pre_attrs(fhp);
|
status = fh_fill_pre_attrs(fhp);
|
||||||
if (status != nfs_ok)
|
if (status != nfs_ok)
|
||||||
goto out;
|
goto out;
|
||||||
host_err = vfs_create(&nop_mnt_idmap, child, iap->ia_mode);
|
host_err = vfs_create(&nop_mnt_idmap, child, iap->ia_mode, NULL);
|
||||||
if (host_err < 0) {
|
if (host_err < 0) {
|
||||||
status = nfserrno(host_err);
|
status = nfserrno(host_err);
|
||||||
goto out;
|
goto out;
|
||||||
|
|
|
||||||
|
|
@ -1552,7 +1552,7 @@ nfsd_create_locked(struct svc_rqst *rqstp, struct svc_fh *fhp,
|
||||||
err = 0;
|
err = 0;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case S_IFREG:
|
case S_IFREG:
|
||||||
host_err = vfs_create(&nop_mnt_idmap, dchild, iap->ia_mode);
|
host_err = vfs_create(&nop_mnt_idmap, dchild, iap->ia_mode, NULL);
|
||||||
if (!host_err)
|
if (!host_err)
|
||||||
nfsd_check_ignore_resizing(iap);
|
nfsd_check_ignore_resizing(iap);
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -1171,7 +1171,7 @@ struct file *dentry_create(const struct path *path, int flags, umode_t mode,
|
||||||
if (IS_ERR(f))
|
if (IS_ERR(f))
|
||||||
return f;
|
return f;
|
||||||
|
|
||||||
error = vfs_create(mnt_idmap(path->mnt), path->dentry, mode);
|
error = vfs_create(mnt_idmap(path->mnt), path->dentry, mode, NULL);
|
||||||
if (!error)
|
if (!error)
|
||||||
error = vfs_open(path, f);
|
error = vfs_open(path, f);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -235,7 +235,7 @@ static inline int ovl_do_create(struct ovl_fs *ofs,
|
||||||
struct inode *dir, struct dentry *dentry,
|
struct inode *dir, struct dentry *dentry,
|
||||||
umode_t mode)
|
umode_t mode)
|
||||||
{
|
{
|
||||||
int err = vfs_create(ovl_upper_mnt_idmap(ofs), dentry, mode);
|
int err = vfs_create(ovl_upper_mnt_idmap(ofs), dentry, mode, NULL);
|
||||||
|
|
||||||
pr_debug("create(%pd2, 0%o) = %i\n", dentry, mode, err);
|
pr_debug("create(%pd2, 0%o) = %i\n", dentry, mode, err);
|
||||||
return err;
|
return err;
|
||||||
|
|
|
||||||
|
|
@ -188,7 +188,7 @@ int ksmbd_vfs_create(struct ksmbd_work *work, const char *name, umode_t mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
mode |= S_IFREG;
|
mode |= S_IFREG;
|
||||||
err = vfs_create(mnt_idmap(path.mnt), dentry, mode);
|
err = vfs_create(mnt_idmap(path.mnt), dentry, mode, NULL);
|
||||||
if (!err) {
|
if (!err) {
|
||||||
ksmbd_vfs_inherit_owner(work, d_inode(path.dentry),
|
ksmbd_vfs_inherit_owner(work, d_inode(path.dentry),
|
||||||
d_inode(dentry));
|
d_inode(dentry));
|
||||||
|
|
|
||||||
|
|
@ -2111,7 +2111,8 @@ bool inode_owner_or_capable(struct mnt_idmap *idmap,
|
||||||
/*
|
/*
|
||||||
* VFS helper functions..
|
* VFS helper functions..
|
||||||
*/
|
*/
|
||||||
int vfs_create(struct mnt_idmap *, struct dentry *, umode_t);
|
int vfs_create(struct mnt_idmap *, struct dentry *, umode_t,
|
||||||
|
struct delegated_inode *);
|
||||||
struct dentry *vfs_mkdir(struct mnt_idmap *, struct inode *,
|
struct dentry *vfs_mkdir(struct mnt_idmap *, struct inode *,
|
||||||
struct dentry *, umode_t, struct delegated_inode *);
|
struct dentry *, umode_t, struct delegated_inode *);
|
||||||
int vfs_mknod(struct mnt_idmap *, struct inode *, struct dentry *,
|
int vfs_mknod(struct mnt_idmap *, struct inode *, struct dentry *,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user