Skip to content

Commit 9e46b84

Browse files
amir73ilMiklos Szeredi
authored andcommitted
ovl: support stacked SEEK_HOLE/SEEK_DATA
Overlay file f_pos is the master copy that is preserved through copy up and modified on read/write, but only real fs knows how to SEEK_HOLE/SEEK_DATA and real fs may impose limitations that are more strict than ->s_maxbytes for specific files, so we use the real file to perform seeks. We do not call real fs for SEEK_CUR:0 query and for SEEK_SET:0 requests. Fixes: d1d04ef ("ovl: stack file ops") Reported-by: Eddie Horng <eddiehorng.tw@gmail.com> Signed-off-by: Amir Goldstein <amir73il@gmail.com> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
1 parent 3428030 commit 9e46b84

1 file changed

Lines changed: 40 additions & 4 deletions

File tree

‎fs/overlayfs/file.c‎

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,47 @@ static int ovl_release(struct inode *inode, struct file *file)
144144

145145
static loff_t ovl_llseek(struct file *file, loff_t offset, int whence)
146146
{
147-
struct inode *realinode = ovl_inode_real(file_inode(file));
147+
struct inode *inode = file_inode(file);
148+
struct fd real;
149+
const struct cred *old_cred;
150+
ssize_t ret;
151+
152+
/*
153+
* The two special cases below do not need to involve real fs,
154+
* so we can optimizing concurrent callers.
155+
*/
156+
if (offset == 0) {
157+
if (whence == SEEK_CUR)
158+
return file->f_pos;
159+
160+
if (whence == SEEK_SET)
161+
return vfs_setpos(file, 0, 0);
162+
}
163+
164+
ret = ovl_real_fdget(file, &real);
165+
if (ret)
166+
return ret;
148167

149-
return generic_file_llseek_size(file, offset, whence,
150-
realinode->i_sb->s_maxbytes,
151-
i_size_read(realinode));
168+
/*
169+
* Overlay file f_pos is the master copy that is preserved
170+
* through copy up and modified on read/write, but only real
171+
* fs knows how to SEEK_HOLE/SEEK_DATA and real fs may impose
172+
* limitations that are more strict than ->s_maxbytes for specific
173+
* files, so we use the real file to perform seeks.
174+
*/
175+
inode_lock(inode);
176+
real.file->f_pos = file->f_pos;
177+
178+
old_cred = ovl_override_creds(inode->i_sb);
179+
ret = vfs_llseek(real.file, offset, whence);
180+
revert_creds(old_cred);
181+
182+
file->f_pos = real.file->f_pos;
183+
inode_unlock(inode);
184+
185+
fdput(real);
186+
187+
return ret;
152188
}
153189

154190
static void ovl_file_accessed(struct file *file)

0 commit comments

Comments
 (0)