Skip to content

Commit 4166564

Browse files
committed
ovl: prepare for lazy lookup of lowerdata inode
Make the code handle the case of numlower > 1 and missing lowerdata dentry gracefully. Missing lowerdata dentry is an indication for lazy lookup of lowerdata and in that case the lowerdata_redirect path is stored in ovl_inode. Following commits will defer lookup and perform the lazy lookup on access. Reviewed-by: Alexander Larsson <alexl@redhat.com> Signed-off-by: Amir Goldstein <amir73il@gmail.com> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
1 parent 2b21da9 commit 4166564

4 files changed

Lines changed: 33 additions & 5 deletions

File tree

fs/overlayfs/file.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ static int ovl_real_fdget_meta(const struct file *file, struct fd *real,
115115
ovl_path_real(dentry, &realpath);
116116
else
117117
ovl_path_realdata(dentry, &realpath);
118+
/* TODO: lazy lookup of lowerdata */
119+
if (!realpath.dentry)
120+
return -EIO;
118121

119122
/* Has it been copied up since we'd opened it? */
120123
if (unlikely(file_inode(real->file) != d_inode(realpath.dentry))) {
@@ -158,6 +161,10 @@ static int ovl_open(struct inode *inode, struct file *file)
158161
file->f_flags &= ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC);
159162

160163
ovl_path_realdata(dentry, &realpath);
164+
/* TODO: lazy lookup of lowerdata */
165+
if (!realpath.dentry)
166+
return -EIO;
167+
161168
realfile = ovl_open_realfile(file, &realpath);
162169
if (IS_ERR(realfile))
163170
return PTR_ERR(realfile);

fs/overlayfs/inode.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,15 +240,22 @@ int ovl_getattr(struct mnt_idmap *idmap, const struct path *path,
240240
/*
241241
* If lower is not same as lowerdata or if there was
242242
* no origin on upper, we can end up here.
243+
* With lazy lowerdata lookup, guess lowerdata blocks
244+
* from size to avoid lowerdata lookup on stat(2).
243245
*/
244246
struct kstat lowerdatastat;
245247
u32 lowermask = STATX_BLOCKS;
246248

247249
ovl_path_lowerdata(dentry, &realpath);
248-
err = vfs_getattr(&realpath, &lowerdatastat,
249-
lowermask, flags);
250-
if (err)
251-
goto out;
250+
if (realpath.dentry) {
251+
err = vfs_getattr(&realpath, &lowerdatastat,
252+
lowermask, flags);
253+
if (err)
254+
goto out;
255+
} else {
256+
lowerdatastat.blocks =
257+
round_up(stat->size, stat->blksize) >> 9;
258+
}
252259
stat->blocks = lowerdatastat.blocks;
253260
}
254261
}
@@ -709,6 +716,9 @@ static int ovl_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
709716
struct inode *realinode = ovl_inode_realdata(inode);
710717
const struct cred *old_cred;
711718

719+
if (!realinode)
720+
return -EIO;
721+
712722
if (!realinode->i_op->fiemap)
713723
return -EOPNOTSUPP;
714724

fs/overlayfs/super.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ static struct dentry *ovl_d_real(struct dentry *dentry,
8181
if (real && !inode && ovl_has_upperdata(d_inode(dentry)))
8282
return real;
8383

84+
/*
85+
* XXX: We may need lazy lookup of lowerdata for !inode case to return
86+
* the real lowerdata dentry. The only current caller of d_real() with
87+
* NULL inode is d_real_inode() from trace_uprobe and this caller is
88+
* likely going to be followed reading from the file, before placing
89+
* uprobes on offset within the file, so lowerdata should be available
90+
* when setting the uprobe.
91+
*/
8492
lower = ovl_dentry_lowerdata(dentry);
8593
if (!lower)
8694
goto bug;
@@ -103,6 +111,9 @@ static int ovl_revalidate_real(struct dentry *d, unsigned int flags, bool weak)
103111
{
104112
int ret = 1;
105113

114+
if (!d)
115+
return 1;
116+
106117
if (weak) {
107118
if (d->d_flags & DCACHE_OP_WEAK_REVALIDATE)
108119
ret = d->d_op->d_weak_revalidate(d, flags);

fs/overlayfs/util.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ void ovl_dentry_init_flags(struct dentry *dentry, struct dentry *upperdentry,
159159

160160
if (upperdentry)
161161
flags |= upperdentry->d_flags;
162-
for (i = 0; i < ovl_numlower(oe); i++)
162+
for (i = 0; i < ovl_numlower(oe) && lowerstack[i].dentry; i++)
163163
flags |= lowerstack[i].dentry->d_flags;
164164

165165
spin_lock(&dentry->d_lock);

0 commit comments

Comments
 (0)