Skip to content

Commit 134796f

Browse files
jtlaytonbrauner
authored andcommitted
vfs: break parent dir delegations in open(..., O_CREAT) codepath
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 lookup_open and have it break the delegation. Then, open_last_lookups can wait for the delegation break and retry the call to lookup_open once it's done. 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-8-52f3feebb2f2@kernel.org Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 4fa7631 commit 134796f

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

fs/namei.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3697,7 +3697,7 @@ static struct dentry *atomic_open(struct nameidata *nd, struct dentry *dentry,
36973697
*/
36983698
static struct dentry *lookup_open(struct nameidata *nd, struct file *file,
36993699
const struct open_flags *op,
3700-
bool got_write)
3700+
bool got_write, struct delegated_inode *delegated_inode)
37013701
{
37023702
struct mnt_idmap *idmap;
37033703
struct dentry *dir = nd->path.dentry;
@@ -3786,6 +3786,11 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file,
37863786

37873787
/* Negative dentry, just create the file */
37883788
if (!dentry->d_inode && (open_flag & O_CREAT)) {
3789+
/* but break the directory lease first! */
3790+
error = try_break_deleg(dir_inode, delegated_inode);
3791+
if (error)
3792+
goto out_dput;
3793+
37893794
file->f_mode |= FMODE_CREATED;
37903795
audit_inode_child(dir_inode, dentry, AUDIT_TYPE_CHILD_CREATE);
37913796
if (!dir_inode->i_op->create) {
@@ -3848,6 +3853,7 @@ static struct dentry *lookup_fast_for_open(struct nameidata *nd, int open_flag)
38483853
static const char *open_last_lookups(struct nameidata *nd,
38493854
struct file *file, const struct open_flags *op)
38503855
{
3856+
struct delegated_inode delegated_inode = { };
38513857
struct dentry *dir = nd->path.dentry;
38523858
int open_flag = op->open_flag;
38533859
bool got_write = false;
@@ -3879,7 +3885,7 @@ static const char *open_last_lookups(struct nameidata *nd,
38793885
return ERR_PTR(-ECHILD);
38803886
}
38813887
}
3882-
3888+
retry:
38833889
if (open_flag & (O_CREAT | O_TRUNC | O_WRONLY | O_RDWR)) {
38843890
got_write = !mnt_want_write(nd->path.mnt);
38853891
/*
@@ -3892,7 +3898,7 @@ static const char *open_last_lookups(struct nameidata *nd,
38923898
inode_lock(dir->d_inode);
38933899
else
38943900
inode_lock_shared(dir->d_inode);
3895-
dentry = lookup_open(nd, file, op, got_write);
3901+
dentry = lookup_open(nd, file, op, got_write, &delegated_inode);
38963902
if (!IS_ERR(dentry)) {
38973903
if (file->f_mode & FMODE_CREATED)
38983904
fsnotify_create(dir->d_inode, dentry);
@@ -3907,8 +3913,16 @@ static const char *open_last_lookups(struct nameidata *nd,
39073913
if (got_write)
39083914
mnt_drop_write(nd->path.mnt);
39093915

3910-
if (IS_ERR(dentry))
3916+
if (IS_ERR(dentry)) {
3917+
if (is_delegated(&delegated_inode)) {
3918+
int error = break_deleg_wait(&delegated_inode);
3919+
3920+
if (!error)
3921+
goto retry;
3922+
return ERR_PTR(error);
3923+
}
39113924
return ERR_CAST(dentry);
3925+
}
39123926

39133927
if (file->f_mode & (FMODE_OPENED | FMODE_CREATED)) {
39143928
dput(nd->path.dentry);

0 commit comments

Comments
 (0)