Skip to content

Commit 5272eaf

Browse files
braunerMiklos Szeredi
authored andcommitted
ovl: pass ofs to setattr operations
Pass down struct ovl_fs to setattr operations so we can ultimately retrieve the relevant upper mount and take the mount's idmapping into account when creating new filesystem objects. This is needed to support idmapped base layers with overlay. Cc: <linux-unionfs@vger.kernel.org> Tested-by: Giuseppe Scrivano <gscrivan@redhat.com> Reviewed-by: Amir Goldstein <amir73il@gmail.com> Signed-off-by: Christian Brauner (Microsoft) <brauner@kernel.org> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
1 parent c67cf65 commit 5272eaf

3 files changed

Lines changed: 13 additions & 10 deletions

File tree

fs/overlayfs/copy_up.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,8 @@ static int ovl_copy_up_data(struct ovl_fs *ofs, struct path *old,
292292
return error;
293293
}
294294

295-
static int ovl_set_size(struct dentry *upperdentry, struct kstat *stat)
295+
static int ovl_set_size(struct ovl_fs *ofs,
296+
struct dentry *upperdentry, struct kstat *stat)
296297
{
297298
struct iattr attr = {
298299
.ia_valid = ATTR_SIZE,
@@ -302,7 +303,8 @@ static int ovl_set_size(struct dentry *upperdentry, struct kstat *stat)
302303
return notify_change(&init_user_ns, upperdentry, &attr, NULL);
303304
}
304305

305-
static int ovl_set_timestamps(struct dentry *upperdentry, struct kstat *stat)
306+
static int ovl_set_timestamps(struct ovl_fs *ofs, struct dentry *upperdentry,
307+
struct kstat *stat)
306308
{
307309
struct iattr attr = {
308310
.ia_valid =
@@ -314,7 +316,8 @@ static int ovl_set_timestamps(struct dentry *upperdentry, struct kstat *stat)
314316
return notify_change(&init_user_ns, upperdentry, &attr, NULL);
315317
}
316318

317-
int ovl_set_attr(struct dentry *upperdentry, struct kstat *stat)
319+
int ovl_set_attr(struct ovl_fs *ofs, struct dentry *upperdentry,
320+
struct kstat *stat)
318321
{
319322
int err = 0;
320323

@@ -334,7 +337,7 @@ int ovl_set_attr(struct dentry *upperdentry, struct kstat *stat)
334337
err = notify_change(&init_user_ns, upperdentry, &attr, NULL);
335338
}
336339
if (!err)
337-
ovl_set_timestamps(upperdentry, stat);
340+
ovl_set_timestamps(ofs, upperdentry, stat);
338341

339342
return err;
340343
}
@@ -541,7 +544,7 @@ static int ovl_link_up(struct ovl_copy_up_ctx *c)
541544

542545
if (!err) {
543546
/* Restore timestamps on parent (best effort) */
544-
ovl_set_timestamps(upperdir, &c->pstat);
547+
ovl_set_timestamps(ofs, upperdir, &c->pstat);
545548
ovl_dentry_set_upper_alias(c->dentry);
546549
}
547550
}
@@ -615,9 +618,9 @@ static int ovl_copy_up_inode(struct ovl_copy_up_ctx *c, struct dentry *temp)
615618

616619
inode_lock(temp->d_inode);
617620
if (S_ISREG(c->stat.mode))
618-
err = ovl_set_size(temp, &c->stat);
621+
err = ovl_set_size(ofs, temp, &c->stat);
619622
if (!err)
620-
err = ovl_set_attr(temp, &c->stat);
623+
err = ovl_set_attr(ofs, temp, &c->stat);
621624
inode_unlock(temp->d_inode);
622625

623626
return err;
@@ -839,7 +842,7 @@ static int ovl_do_copy_up(struct ovl_copy_up_ctx *c)
839842

840843
/* Restore timestamps on parent (best effort) */
841844
inode_lock(udir);
842-
ovl_set_timestamps(c->destdir, &c->pstat);
845+
ovl_set_timestamps(ofs, c->destdir, &c->pstat);
843846
inode_unlock(udir);
844847

845848
ovl_dentry_set_upper_alias(c->dentry);

fs/overlayfs/dir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ static struct dentry *ovl_clear_empty(struct dentry *dentry,
408408
goto out_cleanup;
409409

410410
inode_lock(opaquedir->d_inode);
411-
err = ovl_set_attr(opaquedir, &stat);
411+
err = ovl_set_attr(ofs, opaquedir, &stat);
412412
inode_unlock(opaquedir->d_inode);
413413
if (err)
414414
goto out_cleanup;

fs/overlayfs/overlayfs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ int ovl_copy_up_with_data(struct dentry *dentry);
623623
int ovl_maybe_copy_up(struct dentry *dentry, int flags);
624624
int ovl_copy_xattr(struct super_block *sb, struct dentry *old,
625625
struct dentry *new);
626-
int ovl_set_attr(struct dentry *upper, struct kstat *stat);
626+
int ovl_set_attr(struct ovl_fs *ofs, struct dentry *upper, struct kstat *stat);
627627
struct ovl_fh *ovl_encode_real_fh(struct ovl_fs *ofs, struct dentry *real,
628628
bool is_upper);
629629
int ovl_set_origin(struct ovl_fs *ofs, struct dentry *lower,

0 commit comments

Comments
 (0)