Skip to content

Commit c826229

Browse files
jtlaytonbrauner
authored andcommitted
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>
1 parent 85bbffc commit c826229

8 files changed

Lines changed: 21 additions & 9 deletions

File tree

fs/ecryptfs/inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ ecryptfs_do_create(struct inode *directory_inode,
188188

189189
rc = lock_parent(ecryptfs_dentry, &lower_dentry, &lower_dir);
190190
if (!rc)
191-
rc = vfs_create(&nop_mnt_idmap, lower_dentry, mode);
191+
rc = vfs_create(&nop_mnt_idmap, lower_dentry, mode, NULL);
192192
if (rc) {
193193
printk(KERN_ERR "%s: Failure to create dentry in lower fs; "
194194
"rc = [%d]\n", __func__, rc);

fs/namei.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3463,6 +3463,7 @@ static inline umode_t vfs_prepare_mode(struct mnt_idmap *idmap,
34633463
* @idmap: idmap of the mount the inode was found from
34643464
* @dentry: dentry of the child file
34653465
* @mode: mode of the child file
3466+
* @di: returns parent inode, if the inode is delegated.
34663467
*
34673468
* Create a new file.
34683469
*
@@ -3472,7 +3473,8 @@ static inline umode_t vfs_prepare_mode(struct mnt_idmap *idmap,
34723473
* On non-idmapped mounts or if permission checking is to be performed on the
34733474
* raw inode simply pass @nop_mnt_idmap.
34743475
*/
3475-
int vfs_create(struct mnt_idmap *idmap, struct dentry *dentry, umode_t mode)
3476+
int vfs_create(struct mnt_idmap *idmap, struct dentry *dentry, umode_t mode,
3477+
struct delegated_inode *di)
34763478
{
34773479
struct inode *dir = d_inode(dentry->d_parent);
34783480
int error;
@@ -3486,6 +3488,9 @@ int vfs_create(struct mnt_idmap *idmap, struct dentry *dentry, umode_t mode)
34863488

34873489
mode = vfs_prepare_mode(idmap, dir, mode, S_IALLUGO, S_IFREG);
34883490
error = security_inode_create(dir, dentry, mode);
3491+
if (error)
3492+
return error;
3493+
error = try_break_deleg(dir, di);
34893494
if (error)
34903495
return error;
34913496
error = dir->i_op->create(idmap, dir, dentry, mode, true);
@@ -4358,6 +4363,7 @@ static int may_mknod(umode_t mode)
43584363
static int do_mknodat(int dfd, struct filename *name, umode_t mode,
43594364
unsigned int dev)
43604365
{
4366+
struct delegated_inode di = { };
43614367
struct mnt_idmap *idmap;
43624368
struct dentry *dentry;
43634369
struct path path;
@@ -4381,7 +4387,7 @@ static int do_mknodat(int dfd, struct filename *name, umode_t mode,
43814387
idmap = mnt_idmap(path.mnt);
43824388
switch (mode & S_IFMT) {
43834389
case 0: case S_IFREG:
4384-
error = vfs_create(idmap, dentry, mode);
4390+
error = vfs_create(idmap, dentry, mode, &di);
43854391
if (!error)
43864392
security_path_post_mknod(idmap, dentry);
43874393
break;
@@ -4396,6 +4402,11 @@ static int do_mknodat(int dfd, struct filename *name, umode_t mode,
43964402
}
43974403
out2:
43984404
end_creating_path(&path, dentry);
4405+
if (is_delegated(&di)) {
4406+
error = break_deleg_wait(&di);
4407+
if (!error)
4408+
goto retry;
4409+
}
43994410
if (retry_estale(error, lookup_flags)) {
44004411
lookup_flags |= LOOKUP_REVAL;
44014412
goto retry;

fs/nfsd/nfs3proc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ nfsd3_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp,
344344
status = fh_fill_pre_attrs(fhp);
345345
if (status != nfs_ok)
346346
goto out;
347-
host_err = vfs_create(&nop_mnt_idmap, child, iap->ia_mode);
347+
host_err = vfs_create(&nop_mnt_idmap, child, iap->ia_mode, NULL);
348348
if (host_err < 0) {
349349
status = nfserrno(host_err);
350350
goto out;

fs/nfsd/vfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1552,7 +1552,7 @@ nfsd_create_locked(struct svc_rqst *rqstp, struct svc_fh *fhp,
15521552
err = 0;
15531553
switch (type) {
15541554
case S_IFREG:
1555-
host_err = vfs_create(&nop_mnt_idmap, dchild, iap->ia_mode);
1555+
host_err = vfs_create(&nop_mnt_idmap, dchild, iap->ia_mode, NULL);
15561556
if (!host_err)
15571557
nfsd_check_ignore_resizing(iap);
15581558
break;

fs/open.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,7 @@ struct file *dentry_create(const struct path *path, int flags, umode_t mode,
11711171
if (IS_ERR(f))
11721172
return f;
11731173

1174-
error = vfs_create(mnt_idmap(path->mnt), path->dentry, mode);
1174+
error = vfs_create(mnt_idmap(path->mnt), path->dentry, mode, NULL);
11751175
if (!error)
11761176
error = vfs_open(path, f);
11771177

fs/overlayfs/overlayfs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ static inline int ovl_do_create(struct ovl_fs *ofs,
235235
struct inode *dir, struct dentry *dentry,
236236
umode_t mode)
237237
{
238-
int err = vfs_create(ovl_upper_mnt_idmap(ofs), dentry, mode);
238+
int err = vfs_create(ovl_upper_mnt_idmap(ofs), dentry, mode, NULL);
239239

240240
pr_debug("create(%pd2, 0%o) = %i\n", dentry, mode, err);
241241
return err;

fs/smb/server/vfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ int ksmbd_vfs_create(struct ksmbd_work *work, const char *name, umode_t mode)
188188
}
189189

190190
mode |= S_IFREG;
191-
err = vfs_create(mnt_idmap(path.mnt), dentry, mode);
191+
err = vfs_create(mnt_idmap(path.mnt), dentry, mode, NULL);
192192
if (!err) {
193193
ksmbd_vfs_inherit_owner(work, d_inode(path.dentry),
194194
d_inode(dentry));

include/linux/fs.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2111,7 +2111,8 @@ bool inode_owner_or_capable(struct mnt_idmap *idmap,
21112111
/*
21122112
* VFS helper functions..
21132113
*/
2114-
int vfs_create(struct mnt_idmap *, struct dentry *, umode_t);
2114+
int vfs_create(struct mnt_idmap *, struct dentry *, umode_t,
2115+
struct delegated_inode *);
21152116
struct dentry *vfs_mkdir(struct mnt_idmap *, struct inode *,
21162117
struct dentry *, umode_t, struct delegated_inode *);
21172118
int vfs_mknod(struct mnt_idmap *, struct inode *, struct dentry *,

0 commit comments

Comments
 (0)