Skip to content

Commit f40c32f

Browse files
amir73ilgregkh
authored andcommitted
ovl: support stacked SEEK_HOLE/SEEK_DATA
commit 9e46b84 upstream. 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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 289e5e0 commit f40c32f

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
@@ -146,11 +146,47 @@ static int ovl_release(struct inode *inode, struct file *file)
146146

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

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

156192
static void ovl_file_accessed(struct file *file)

0 commit comments

Comments
 (0)