Skip to content

Commit ffa5723

Browse files
amir73ilMiklos Szeredi
authored andcommitted
ovl: store lower path in ovl_inode
Create some ovl_i_* helpers to get real path from ovl inode. Instead of just stashing struct inode for the lower layer we stash struct path for the lower layer. The helpers allow to retrieve a struct path for the relevant upper or lower layer. This will be used when retrieving information based on struct inode when copying up inode attributes from upper or lower inodes to ovl inodes and when checking permissions in ovl_permission() in following patches. 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: Christian Brauner (Microsoft) <brauner@kernel.org> Signed-off-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 ba9ea77 commit ffa5723

5 files changed

Lines changed: 27 additions & 8 deletions

File tree

fs/overlayfs/inode.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -779,13 +779,16 @@ void ovl_inode_init(struct inode *inode, struct ovl_inode_params *oip,
779779
unsigned long ino, int fsid)
780780
{
781781
struct inode *realinode;
782+
struct ovl_inode *oi = OVL_I(inode);
782783

783784
if (oip->upperdentry)
784-
OVL_I(inode)->__upperdentry = oip->upperdentry;
785-
if (oip->lowerpath && oip->lowerpath->dentry)
786-
OVL_I(inode)->lower = igrab(d_inode(oip->lowerpath->dentry));
785+
oi->__upperdentry = oip->upperdentry;
786+
if (oip->lowerpath && oip->lowerpath->dentry) {
787+
oi->lowerpath.dentry = dget(oip->lowerpath->dentry);
788+
oi->lowerpath.layer = oip->lowerpath->layer;
789+
}
787790
if (oip->lowerdata)
788-
OVL_I(inode)->lowerdata = igrab(d_inode(oip->lowerdata));
791+
oi->lowerdata = igrab(d_inode(oip->lowerdata));
789792

790793
realinode = ovl_inode_real(inode);
791794
ovl_copyattr(realinode, inode);

fs/overlayfs/overlayfs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,11 +374,13 @@ enum ovl_path_type ovl_path_type(struct dentry *dentry);
374374
void ovl_path_upper(struct dentry *dentry, struct path *path);
375375
void ovl_path_lower(struct dentry *dentry, struct path *path);
376376
void ovl_path_lowerdata(struct dentry *dentry, struct path *path);
377+
void ovl_i_path_real(struct inode *inode, struct path *path);
377378
enum ovl_path_type ovl_path_real(struct dentry *dentry, struct path *path);
378379
enum ovl_path_type ovl_path_realdata(struct dentry *dentry, struct path *path);
379380
struct dentry *ovl_dentry_upper(struct dentry *dentry);
380381
struct dentry *ovl_dentry_lower(struct dentry *dentry);
381382
struct dentry *ovl_dentry_lowerdata(struct dentry *dentry);
383+
const struct ovl_layer *ovl_i_layer_lower(struct inode *inode);
382384
const struct ovl_layer *ovl_layer_lower(struct dentry *dentry);
383385
struct dentry *ovl_dentry_real(struct dentry *dentry);
384386
struct dentry *ovl_i_dentry_upper(struct inode *inode);

fs/overlayfs/ovl_entry.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ struct ovl_inode {
134134
unsigned long flags;
135135
struct inode vfs_inode;
136136
struct dentry *__upperdentry;
137-
struct inode *lower;
137+
struct ovl_path lowerpath;
138138

139139
/* synchronize copy up and more */
140140
struct mutex lock;

fs/overlayfs/super.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ static struct inode *ovl_alloc_inode(struct super_block *sb)
184184
oi->version = 0;
185185
oi->flags = 0;
186186
oi->__upperdentry = NULL;
187-
oi->lower = NULL;
187+
oi->lowerpath.dentry = NULL;
188+
oi->lowerpath.layer = NULL;
188189
oi->lowerdata = NULL;
189190
mutex_init(&oi->lock);
190191

@@ -205,7 +206,7 @@ static void ovl_destroy_inode(struct inode *inode)
205206
struct ovl_inode *oi = OVL_I(inode);
206207

207208
dput(oi->__upperdentry);
208-
iput(oi->lower);
209+
dput(oi->lowerpath.dentry);
209210
if (S_ISDIR(inode->i_mode))
210211
ovl_dir_cache_free(inode);
211212
else

fs/overlayfs/util.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,17 @@ struct dentry *ovl_i_dentry_upper(struct inode *inode)
250250
return ovl_upperdentry_dereference(OVL_I(inode));
251251
}
252252

253+
void ovl_i_path_real(struct inode *inode, struct path *path)
254+
{
255+
path->dentry = ovl_i_dentry_upper(inode);
256+
if (!path->dentry) {
257+
path->dentry = OVL_I(inode)->lowerpath.dentry;
258+
path->mnt = OVL_I(inode)->lowerpath.layer->mnt;
259+
} else {
260+
path->mnt = ovl_upper_mnt(OVL_FS(inode->i_sb));
261+
}
262+
}
263+
253264
struct inode *ovl_inode_upper(struct inode *inode)
254265
{
255266
struct dentry *upperdentry = ovl_i_dentry_upper(inode);
@@ -259,7 +270,9 @@ struct inode *ovl_inode_upper(struct inode *inode)
259270

260271
struct inode *ovl_inode_lower(struct inode *inode)
261272
{
262-
return OVL_I(inode)->lower;
273+
struct dentry *lowerdentry = OVL_I(inode)->lowerpath.dentry;
274+
275+
return lowerdentry ? d_inode(lowerdentry) : NULL;
263276
}
264277

265278
struct inode *ovl_inode_real(struct inode *inode)

0 commit comments

Comments
 (0)