1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * Copyright (C) 2017 Red Hat, Inc.
4*4882a593Smuzhiyun */
5*4882a593Smuzhiyun
6*4882a593Smuzhiyun #include <linux/cred.h>
7*4882a593Smuzhiyun #include <linux/file.h>
8*4882a593Smuzhiyun #include <linux/mount.h>
9*4882a593Smuzhiyun #include <linux/xattr.h>
10*4882a593Smuzhiyun #include <linux/uio.h>
11*4882a593Smuzhiyun #include <linux/uaccess.h>
12*4882a593Smuzhiyun #include <linux/splice.h>
13*4882a593Smuzhiyun #include <linux/security.h>
14*4882a593Smuzhiyun #include <linux/mm.h>
15*4882a593Smuzhiyun #include <linux/fs.h>
16*4882a593Smuzhiyun #include "overlayfs.h"
17*4882a593Smuzhiyun
18*4882a593Smuzhiyun #define OVL_IOCB_MASK (IOCB_DSYNC | IOCB_HIPRI | IOCB_NOWAIT | IOCB_SYNC)
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun struct ovl_aio_req {
21*4882a593Smuzhiyun struct kiocb iocb;
22*4882a593Smuzhiyun refcount_t ref;
23*4882a593Smuzhiyun struct kiocb *orig_iocb;
24*4882a593Smuzhiyun struct fd fd;
25*4882a593Smuzhiyun };
26*4882a593Smuzhiyun
27*4882a593Smuzhiyun static struct kmem_cache *ovl_aio_request_cachep;
28*4882a593Smuzhiyun
ovl_whatisit(struct inode * inode,struct inode * realinode)29*4882a593Smuzhiyun static char ovl_whatisit(struct inode *inode, struct inode *realinode)
30*4882a593Smuzhiyun {
31*4882a593Smuzhiyun if (realinode != ovl_inode_upper(inode))
32*4882a593Smuzhiyun return 'l';
33*4882a593Smuzhiyun if (ovl_has_upperdata(inode))
34*4882a593Smuzhiyun return 'u';
35*4882a593Smuzhiyun else
36*4882a593Smuzhiyun return 'm';
37*4882a593Smuzhiyun }
38*4882a593Smuzhiyun
39*4882a593Smuzhiyun /* No atime modificaton nor notify on underlying */
40*4882a593Smuzhiyun #define OVL_OPEN_FLAGS (O_NOATIME | FMODE_NONOTIFY)
41*4882a593Smuzhiyun
ovl_open_realfile(const struct file * file,struct inode * realinode)42*4882a593Smuzhiyun static struct file *ovl_open_realfile(const struct file *file,
43*4882a593Smuzhiyun struct inode *realinode)
44*4882a593Smuzhiyun {
45*4882a593Smuzhiyun struct inode *inode = file_inode(file);
46*4882a593Smuzhiyun struct file *realfile;
47*4882a593Smuzhiyun const struct cred *old_cred;
48*4882a593Smuzhiyun int flags = file->f_flags | OVL_OPEN_FLAGS;
49*4882a593Smuzhiyun int acc_mode = ACC_MODE(flags);
50*4882a593Smuzhiyun int err;
51*4882a593Smuzhiyun
52*4882a593Smuzhiyun if (flags & O_APPEND)
53*4882a593Smuzhiyun acc_mode |= MAY_APPEND;
54*4882a593Smuzhiyun
55*4882a593Smuzhiyun old_cred = ovl_override_creds(inode->i_sb);
56*4882a593Smuzhiyun err = inode_permission(realinode, MAY_OPEN | acc_mode);
57*4882a593Smuzhiyun if (err) {
58*4882a593Smuzhiyun realfile = ERR_PTR(err);
59*4882a593Smuzhiyun } else if (old_cred && !inode_owner_or_capable(realinode)) {
60*4882a593Smuzhiyun realfile = ERR_PTR(-EPERM);
61*4882a593Smuzhiyun } else {
62*4882a593Smuzhiyun realfile = open_with_fake_path(&file->f_path, flags, realinode,
63*4882a593Smuzhiyun current_cred());
64*4882a593Smuzhiyun }
65*4882a593Smuzhiyun ovl_revert_creds(inode->i_sb, old_cred);
66*4882a593Smuzhiyun
67*4882a593Smuzhiyun pr_debug("open(%p[%pD2/%c], 0%o) -> (%p, 0%o)\n",
68*4882a593Smuzhiyun file, file, ovl_whatisit(inode, realinode), file->f_flags,
69*4882a593Smuzhiyun realfile, IS_ERR(realfile) ? 0 : realfile->f_flags);
70*4882a593Smuzhiyun
71*4882a593Smuzhiyun return realfile;
72*4882a593Smuzhiyun }
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun #define OVL_SETFL_MASK (O_APPEND | O_NONBLOCK | O_NDELAY | O_DIRECT)
75*4882a593Smuzhiyun
ovl_change_flags(struct file * file,unsigned int flags)76*4882a593Smuzhiyun static int ovl_change_flags(struct file *file, unsigned int flags)
77*4882a593Smuzhiyun {
78*4882a593Smuzhiyun struct inode *inode = file_inode(file);
79*4882a593Smuzhiyun int err;
80*4882a593Smuzhiyun
81*4882a593Smuzhiyun flags |= OVL_OPEN_FLAGS;
82*4882a593Smuzhiyun
83*4882a593Smuzhiyun /* If some flag changed that cannot be changed then something's amiss */
84*4882a593Smuzhiyun if (WARN_ON((file->f_flags ^ flags) & ~OVL_SETFL_MASK))
85*4882a593Smuzhiyun return -EIO;
86*4882a593Smuzhiyun
87*4882a593Smuzhiyun flags &= OVL_SETFL_MASK;
88*4882a593Smuzhiyun
89*4882a593Smuzhiyun if (((flags ^ file->f_flags) & O_APPEND) && IS_APPEND(inode))
90*4882a593Smuzhiyun return -EPERM;
91*4882a593Smuzhiyun
92*4882a593Smuzhiyun if (flags & O_DIRECT) {
93*4882a593Smuzhiyun if (!file->f_mapping->a_ops ||
94*4882a593Smuzhiyun !file->f_mapping->a_ops->direct_IO)
95*4882a593Smuzhiyun return -EINVAL;
96*4882a593Smuzhiyun }
97*4882a593Smuzhiyun
98*4882a593Smuzhiyun if (file->f_op->check_flags) {
99*4882a593Smuzhiyun err = file->f_op->check_flags(flags);
100*4882a593Smuzhiyun if (err)
101*4882a593Smuzhiyun return err;
102*4882a593Smuzhiyun }
103*4882a593Smuzhiyun
104*4882a593Smuzhiyun spin_lock(&file->f_lock);
105*4882a593Smuzhiyun file->f_flags = (file->f_flags & ~OVL_SETFL_MASK) | flags;
106*4882a593Smuzhiyun spin_unlock(&file->f_lock);
107*4882a593Smuzhiyun
108*4882a593Smuzhiyun return 0;
109*4882a593Smuzhiyun }
110*4882a593Smuzhiyun
ovl_real_fdget_meta(const struct file * file,struct fd * real,bool allow_meta)111*4882a593Smuzhiyun static int ovl_real_fdget_meta(const struct file *file, struct fd *real,
112*4882a593Smuzhiyun bool allow_meta)
113*4882a593Smuzhiyun {
114*4882a593Smuzhiyun struct inode *inode = file_inode(file);
115*4882a593Smuzhiyun struct inode *realinode;
116*4882a593Smuzhiyun
117*4882a593Smuzhiyun real->flags = 0;
118*4882a593Smuzhiyun real->file = file->private_data;
119*4882a593Smuzhiyun
120*4882a593Smuzhiyun if (allow_meta)
121*4882a593Smuzhiyun realinode = ovl_inode_real(inode);
122*4882a593Smuzhiyun else
123*4882a593Smuzhiyun realinode = ovl_inode_realdata(inode);
124*4882a593Smuzhiyun
125*4882a593Smuzhiyun /* Has it been copied up since we'd opened it? */
126*4882a593Smuzhiyun if (unlikely(file_inode(real->file) != realinode)) {
127*4882a593Smuzhiyun real->flags = FDPUT_FPUT;
128*4882a593Smuzhiyun real->file = ovl_open_realfile(file, realinode);
129*4882a593Smuzhiyun
130*4882a593Smuzhiyun return PTR_ERR_OR_ZERO(real->file);
131*4882a593Smuzhiyun }
132*4882a593Smuzhiyun
133*4882a593Smuzhiyun /* Did the flags change since open? */
134*4882a593Smuzhiyun if (unlikely((file->f_flags ^ real->file->f_flags) & ~OVL_OPEN_FLAGS))
135*4882a593Smuzhiyun return ovl_change_flags(real->file, file->f_flags);
136*4882a593Smuzhiyun
137*4882a593Smuzhiyun return 0;
138*4882a593Smuzhiyun }
139*4882a593Smuzhiyun
ovl_real_fdget(const struct file * file,struct fd * real)140*4882a593Smuzhiyun static int ovl_real_fdget(const struct file *file, struct fd *real)
141*4882a593Smuzhiyun {
142*4882a593Smuzhiyun if (d_is_dir(file_dentry(file))) {
143*4882a593Smuzhiyun real->flags = 0;
144*4882a593Smuzhiyun real->file = ovl_dir_real_file(file, false);
145*4882a593Smuzhiyun
146*4882a593Smuzhiyun return PTR_ERR_OR_ZERO(real->file);
147*4882a593Smuzhiyun }
148*4882a593Smuzhiyun
149*4882a593Smuzhiyun return ovl_real_fdget_meta(file, real, false);
150*4882a593Smuzhiyun }
151*4882a593Smuzhiyun
ovl_open(struct inode * inode,struct file * file)152*4882a593Smuzhiyun static int ovl_open(struct inode *inode, struct file *file)
153*4882a593Smuzhiyun {
154*4882a593Smuzhiyun struct file *realfile;
155*4882a593Smuzhiyun int err;
156*4882a593Smuzhiyun
157*4882a593Smuzhiyun err = ovl_maybe_copy_up(file_dentry(file), file->f_flags);
158*4882a593Smuzhiyun if (err)
159*4882a593Smuzhiyun return err;
160*4882a593Smuzhiyun
161*4882a593Smuzhiyun /* No longer need these flags, so don't pass them on to underlying fs */
162*4882a593Smuzhiyun file->f_flags &= ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC);
163*4882a593Smuzhiyun
164*4882a593Smuzhiyun realfile = ovl_open_realfile(file, ovl_inode_realdata(inode));
165*4882a593Smuzhiyun if (IS_ERR(realfile))
166*4882a593Smuzhiyun return PTR_ERR(realfile);
167*4882a593Smuzhiyun
168*4882a593Smuzhiyun file->private_data = realfile;
169*4882a593Smuzhiyun
170*4882a593Smuzhiyun return 0;
171*4882a593Smuzhiyun }
172*4882a593Smuzhiyun
ovl_release(struct inode * inode,struct file * file)173*4882a593Smuzhiyun static int ovl_release(struct inode *inode, struct file *file)
174*4882a593Smuzhiyun {
175*4882a593Smuzhiyun fput(file->private_data);
176*4882a593Smuzhiyun
177*4882a593Smuzhiyun return 0;
178*4882a593Smuzhiyun }
179*4882a593Smuzhiyun
ovl_llseek(struct file * file,loff_t offset,int whence)180*4882a593Smuzhiyun static loff_t ovl_llseek(struct file *file, loff_t offset, int whence)
181*4882a593Smuzhiyun {
182*4882a593Smuzhiyun struct inode *inode = file_inode(file);
183*4882a593Smuzhiyun struct fd real;
184*4882a593Smuzhiyun const struct cred *old_cred;
185*4882a593Smuzhiyun loff_t ret;
186*4882a593Smuzhiyun
187*4882a593Smuzhiyun /*
188*4882a593Smuzhiyun * The two special cases below do not need to involve real fs,
189*4882a593Smuzhiyun * so we can optimizing concurrent callers.
190*4882a593Smuzhiyun */
191*4882a593Smuzhiyun if (offset == 0) {
192*4882a593Smuzhiyun if (whence == SEEK_CUR)
193*4882a593Smuzhiyun return file->f_pos;
194*4882a593Smuzhiyun
195*4882a593Smuzhiyun if (whence == SEEK_SET)
196*4882a593Smuzhiyun return vfs_setpos(file, 0, 0);
197*4882a593Smuzhiyun }
198*4882a593Smuzhiyun
199*4882a593Smuzhiyun ret = ovl_real_fdget(file, &real);
200*4882a593Smuzhiyun if (ret)
201*4882a593Smuzhiyun return ret;
202*4882a593Smuzhiyun
203*4882a593Smuzhiyun /*
204*4882a593Smuzhiyun * Overlay file f_pos is the master copy that is preserved
205*4882a593Smuzhiyun * through copy up and modified on read/write, but only real
206*4882a593Smuzhiyun * fs knows how to SEEK_HOLE/SEEK_DATA and real fs may impose
207*4882a593Smuzhiyun * limitations that are more strict than ->s_maxbytes for specific
208*4882a593Smuzhiyun * files, so we use the real file to perform seeks.
209*4882a593Smuzhiyun */
210*4882a593Smuzhiyun ovl_inode_lock(inode);
211*4882a593Smuzhiyun real.file->f_pos = file->f_pos;
212*4882a593Smuzhiyun
213*4882a593Smuzhiyun old_cred = ovl_override_creds(inode->i_sb);
214*4882a593Smuzhiyun ret = vfs_llseek(real.file, offset, whence);
215*4882a593Smuzhiyun ovl_revert_creds(inode->i_sb, old_cred);
216*4882a593Smuzhiyun
217*4882a593Smuzhiyun file->f_pos = real.file->f_pos;
218*4882a593Smuzhiyun ovl_inode_unlock(inode);
219*4882a593Smuzhiyun
220*4882a593Smuzhiyun fdput(real);
221*4882a593Smuzhiyun
222*4882a593Smuzhiyun return ret;
223*4882a593Smuzhiyun }
224*4882a593Smuzhiyun
ovl_file_accessed(struct file * file)225*4882a593Smuzhiyun static void ovl_file_accessed(struct file *file)
226*4882a593Smuzhiyun {
227*4882a593Smuzhiyun struct inode *inode, *upperinode;
228*4882a593Smuzhiyun
229*4882a593Smuzhiyun if (file->f_flags & O_NOATIME)
230*4882a593Smuzhiyun return;
231*4882a593Smuzhiyun
232*4882a593Smuzhiyun inode = file_inode(file);
233*4882a593Smuzhiyun upperinode = ovl_inode_upper(inode);
234*4882a593Smuzhiyun
235*4882a593Smuzhiyun if (!upperinode)
236*4882a593Smuzhiyun return;
237*4882a593Smuzhiyun
238*4882a593Smuzhiyun if ((!timespec64_equal(&inode->i_mtime, &upperinode->i_mtime) ||
239*4882a593Smuzhiyun !timespec64_equal(&inode->i_ctime, &upperinode->i_ctime))) {
240*4882a593Smuzhiyun inode->i_mtime = upperinode->i_mtime;
241*4882a593Smuzhiyun inode->i_ctime = upperinode->i_ctime;
242*4882a593Smuzhiyun }
243*4882a593Smuzhiyun
244*4882a593Smuzhiyun touch_atime(&file->f_path);
245*4882a593Smuzhiyun }
246*4882a593Smuzhiyun
ovl_aio_put(struct ovl_aio_req * aio_req)247*4882a593Smuzhiyun static inline void ovl_aio_put(struct ovl_aio_req *aio_req)
248*4882a593Smuzhiyun {
249*4882a593Smuzhiyun if (refcount_dec_and_test(&aio_req->ref)) {
250*4882a593Smuzhiyun fdput(aio_req->fd);
251*4882a593Smuzhiyun kmem_cache_free(ovl_aio_request_cachep, aio_req);
252*4882a593Smuzhiyun }
253*4882a593Smuzhiyun }
254*4882a593Smuzhiyun
ovl_aio_cleanup_handler(struct ovl_aio_req * aio_req)255*4882a593Smuzhiyun static void ovl_aio_cleanup_handler(struct ovl_aio_req *aio_req)
256*4882a593Smuzhiyun {
257*4882a593Smuzhiyun struct kiocb *iocb = &aio_req->iocb;
258*4882a593Smuzhiyun struct kiocb *orig_iocb = aio_req->orig_iocb;
259*4882a593Smuzhiyun
260*4882a593Smuzhiyun if (iocb->ki_flags & IOCB_WRITE) {
261*4882a593Smuzhiyun struct inode *inode = file_inode(orig_iocb->ki_filp);
262*4882a593Smuzhiyun
263*4882a593Smuzhiyun /* Actually acquired in ovl_write_iter() */
264*4882a593Smuzhiyun __sb_writers_acquired(file_inode(iocb->ki_filp)->i_sb,
265*4882a593Smuzhiyun SB_FREEZE_WRITE);
266*4882a593Smuzhiyun file_end_write(iocb->ki_filp);
267*4882a593Smuzhiyun ovl_copyattr(ovl_inode_real(inode), inode);
268*4882a593Smuzhiyun }
269*4882a593Smuzhiyun
270*4882a593Smuzhiyun orig_iocb->ki_pos = iocb->ki_pos;
271*4882a593Smuzhiyun ovl_aio_put(aio_req);
272*4882a593Smuzhiyun }
273*4882a593Smuzhiyun
ovl_aio_rw_complete(struct kiocb * iocb,long res,long res2)274*4882a593Smuzhiyun static void ovl_aio_rw_complete(struct kiocb *iocb, long res, long res2)
275*4882a593Smuzhiyun {
276*4882a593Smuzhiyun struct ovl_aio_req *aio_req = container_of(iocb,
277*4882a593Smuzhiyun struct ovl_aio_req, iocb);
278*4882a593Smuzhiyun struct kiocb *orig_iocb = aio_req->orig_iocb;
279*4882a593Smuzhiyun
280*4882a593Smuzhiyun ovl_aio_cleanup_handler(aio_req);
281*4882a593Smuzhiyun orig_iocb->ki_complete(orig_iocb, res, res2);
282*4882a593Smuzhiyun }
283*4882a593Smuzhiyun
ovl_read_iter(struct kiocb * iocb,struct iov_iter * iter)284*4882a593Smuzhiyun static ssize_t ovl_read_iter(struct kiocb *iocb, struct iov_iter *iter)
285*4882a593Smuzhiyun {
286*4882a593Smuzhiyun struct file *file = iocb->ki_filp;
287*4882a593Smuzhiyun struct fd real;
288*4882a593Smuzhiyun const struct cred *old_cred;
289*4882a593Smuzhiyun ssize_t ret;
290*4882a593Smuzhiyun
291*4882a593Smuzhiyun if (!iov_iter_count(iter))
292*4882a593Smuzhiyun return 0;
293*4882a593Smuzhiyun
294*4882a593Smuzhiyun ret = ovl_real_fdget(file, &real);
295*4882a593Smuzhiyun if (ret)
296*4882a593Smuzhiyun return ret;
297*4882a593Smuzhiyun
298*4882a593Smuzhiyun ret = -EINVAL;
299*4882a593Smuzhiyun if (iocb->ki_flags & IOCB_DIRECT &&
300*4882a593Smuzhiyun (!real.file->f_mapping->a_ops ||
301*4882a593Smuzhiyun !real.file->f_mapping->a_ops->direct_IO))
302*4882a593Smuzhiyun goto out_fdput;
303*4882a593Smuzhiyun
304*4882a593Smuzhiyun old_cred = ovl_override_creds(file_inode(file)->i_sb);
305*4882a593Smuzhiyun if (is_sync_kiocb(iocb)) {
306*4882a593Smuzhiyun ret = vfs_iter_read(real.file, iter, &iocb->ki_pos,
307*4882a593Smuzhiyun iocb_to_rw_flags(iocb->ki_flags,
308*4882a593Smuzhiyun OVL_IOCB_MASK));
309*4882a593Smuzhiyun } else {
310*4882a593Smuzhiyun struct ovl_aio_req *aio_req;
311*4882a593Smuzhiyun
312*4882a593Smuzhiyun ret = -ENOMEM;
313*4882a593Smuzhiyun aio_req = kmem_cache_zalloc(ovl_aio_request_cachep, GFP_KERNEL);
314*4882a593Smuzhiyun if (!aio_req)
315*4882a593Smuzhiyun goto out;
316*4882a593Smuzhiyun
317*4882a593Smuzhiyun aio_req->fd = real;
318*4882a593Smuzhiyun real.flags = 0;
319*4882a593Smuzhiyun aio_req->orig_iocb = iocb;
320*4882a593Smuzhiyun kiocb_clone(&aio_req->iocb, iocb, real.file);
321*4882a593Smuzhiyun aio_req->iocb.ki_complete = ovl_aio_rw_complete;
322*4882a593Smuzhiyun refcount_set(&aio_req->ref, 2);
323*4882a593Smuzhiyun ret = vfs_iocb_iter_read(real.file, &aio_req->iocb, iter);
324*4882a593Smuzhiyun ovl_aio_put(aio_req);
325*4882a593Smuzhiyun if (ret != -EIOCBQUEUED)
326*4882a593Smuzhiyun ovl_aio_cleanup_handler(aio_req);
327*4882a593Smuzhiyun }
328*4882a593Smuzhiyun out:
329*4882a593Smuzhiyun ovl_revert_creds(file_inode(file)->i_sb, old_cred);
330*4882a593Smuzhiyun
331*4882a593Smuzhiyun ovl_file_accessed(file);
332*4882a593Smuzhiyun out_fdput:
333*4882a593Smuzhiyun fdput(real);
334*4882a593Smuzhiyun
335*4882a593Smuzhiyun return ret;
336*4882a593Smuzhiyun }
337*4882a593Smuzhiyun
ovl_write_iter(struct kiocb * iocb,struct iov_iter * iter)338*4882a593Smuzhiyun static ssize_t ovl_write_iter(struct kiocb *iocb, struct iov_iter *iter)
339*4882a593Smuzhiyun {
340*4882a593Smuzhiyun struct file *file = iocb->ki_filp;
341*4882a593Smuzhiyun struct inode *inode = file_inode(file);
342*4882a593Smuzhiyun struct fd real;
343*4882a593Smuzhiyun const struct cred *old_cred;
344*4882a593Smuzhiyun ssize_t ret;
345*4882a593Smuzhiyun int ifl = iocb->ki_flags;
346*4882a593Smuzhiyun
347*4882a593Smuzhiyun if (!iov_iter_count(iter))
348*4882a593Smuzhiyun return 0;
349*4882a593Smuzhiyun
350*4882a593Smuzhiyun inode_lock(inode);
351*4882a593Smuzhiyun /* Update mode */
352*4882a593Smuzhiyun ovl_copyattr(ovl_inode_real(inode), inode);
353*4882a593Smuzhiyun ret = file_remove_privs(file);
354*4882a593Smuzhiyun if (ret)
355*4882a593Smuzhiyun goto out_unlock;
356*4882a593Smuzhiyun
357*4882a593Smuzhiyun ret = ovl_real_fdget(file, &real);
358*4882a593Smuzhiyun if (ret)
359*4882a593Smuzhiyun goto out_unlock;
360*4882a593Smuzhiyun
361*4882a593Smuzhiyun ret = -EINVAL;
362*4882a593Smuzhiyun if (iocb->ki_flags & IOCB_DIRECT &&
363*4882a593Smuzhiyun (!real.file->f_mapping->a_ops ||
364*4882a593Smuzhiyun !real.file->f_mapping->a_ops->direct_IO))
365*4882a593Smuzhiyun goto out_fdput;
366*4882a593Smuzhiyun
367*4882a593Smuzhiyun if (!ovl_should_sync(OVL_FS(inode->i_sb)))
368*4882a593Smuzhiyun ifl &= ~(IOCB_DSYNC | IOCB_SYNC);
369*4882a593Smuzhiyun
370*4882a593Smuzhiyun old_cred = ovl_override_creds(file_inode(file)->i_sb);
371*4882a593Smuzhiyun if (is_sync_kiocb(iocb)) {
372*4882a593Smuzhiyun file_start_write(real.file);
373*4882a593Smuzhiyun ret = vfs_iter_write(real.file, iter, &iocb->ki_pos,
374*4882a593Smuzhiyun iocb_to_rw_flags(ifl, OVL_IOCB_MASK));
375*4882a593Smuzhiyun file_end_write(real.file);
376*4882a593Smuzhiyun /* Update size */
377*4882a593Smuzhiyun ovl_copyattr(ovl_inode_real(inode), inode);
378*4882a593Smuzhiyun } else {
379*4882a593Smuzhiyun struct ovl_aio_req *aio_req;
380*4882a593Smuzhiyun
381*4882a593Smuzhiyun ret = -ENOMEM;
382*4882a593Smuzhiyun aio_req = kmem_cache_zalloc(ovl_aio_request_cachep, GFP_KERNEL);
383*4882a593Smuzhiyun if (!aio_req)
384*4882a593Smuzhiyun goto out;
385*4882a593Smuzhiyun
386*4882a593Smuzhiyun file_start_write(real.file);
387*4882a593Smuzhiyun /* Pacify lockdep, same trick as done in aio_write() */
388*4882a593Smuzhiyun __sb_writers_release(file_inode(real.file)->i_sb,
389*4882a593Smuzhiyun SB_FREEZE_WRITE);
390*4882a593Smuzhiyun aio_req->fd = real;
391*4882a593Smuzhiyun real.flags = 0;
392*4882a593Smuzhiyun aio_req->orig_iocb = iocb;
393*4882a593Smuzhiyun kiocb_clone(&aio_req->iocb, iocb, real.file);
394*4882a593Smuzhiyun aio_req->iocb.ki_flags = ifl;
395*4882a593Smuzhiyun aio_req->iocb.ki_complete = ovl_aio_rw_complete;
396*4882a593Smuzhiyun refcount_set(&aio_req->ref, 2);
397*4882a593Smuzhiyun ret = vfs_iocb_iter_write(real.file, &aio_req->iocb, iter);
398*4882a593Smuzhiyun ovl_aio_put(aio_req);
399*4882a593Smuzhiyun if (ret != -EIOCBQUEUED)
400*4882a593Smuzhiyun ovl_aio_cleanup_handler(aio_req);
401*4882a593Smuzhiyun }
402*4882a593Smuzhiyun out:
403*4882a593Smuzhiyun ovl_revert_creds(file_inode(file)->i_sb, old_cred);
404*4882a593Smuzhiyun out_fdput:
405*4882a593Smuzhiyun fdput(real);
406*4882a593Smuzhiyun
407*4882a593Smuzhiyun out_unlock:
408*4882a593Smuzhiyun inode_unlock(inode);
409*4882a593Smuzhiyun
410*4882a593Smuzhiyun return ret;
411*4882a593Smuzhiyun }
412*4882a593Smuzhiyun
413*4882a593Smuzhiyun /*
414*4882a593Smuzhiyun * Calling iter_file_splice_write() directly from overlay's f_op may deadlock
415*4882a593Smuzhiyun * due to lock order inversion between pipe->mutex in iter_file_splice_write()
416*4882a593Smuzhiyun * and file_start_write(real.file) in ovl_write_iter().
417*4882a593Smuzhiyun *
418*4882a593Smuzhiyun * So do everything ovl_write_iter() does and call iter_file_splice_write() on
419*4882a593Smuzhiyun * the real file.
420*4882a593Smuzhiyun */
ovl_splice_write(struct pipe_inode_info * pipe,struct file * out,loff_t * ppos,size_t len,unsigned int flags)421*4882a593Smuzhiyun static ssize_t ovl_splice_write(struct pipe_inode_info *pipe, struct file *out,
422*4882a593Smuzhiyun loff_t *ppos, size_t len, unsigned int flags)
423*4882a593Smuzhiyun {
424*4882a593Smuzhiyun struct fd real;
425*4882a593Smuzhiyun const struct cred *old_cred;
426*4882a593Smuzhiyun struct inode *inode = file_inode(out);
427*4882a593Smuzhiyun struct inode *realinode = ovl_inode_real(inode);
428*4882a593Smuzhiyun ssize_t ret;
429*4882a593Smuzhiyun
430*4882a593Smuzhiyun inode_lock(inode);
431*4882a593Smuzhiyun /* Update mode */
432*4882a593Smuzhiyun ovl_copyattr(realinode, inode);
433*4882a593Smuzhiyun ret = file_remove_privs(out);
434*4882a593Smuzhiyun if (ret)
435*4882a593Smuzhiyun goto out_unlock;
436*4882a593Smuzhiyun
437*4882a593Smuzhiyun ret = ovl_real_fdget(out, &real);
438*4882a593Smuzhiyun if (ret)
439*4882a593Smuzhiyun goto out_unlock;
440*4882a593Smuzhiyun
441*4882a593Smuzhiyun old_cred = ovl_override_creds(inode->i_sb);
442*4882a593Smuzhiyun file_start_write(real.file);
443*4882a593Smuzhiyun
444*4882a593Smuzhiyun ret = iter_file_splice_write(pipe, real.file, ppos, len, flags);
445*4882a593Smuzhiyun
446*4882a593Smuzhiyun file_end_write(real.file);
447*4882a593Smuzhiyun /* Update size */
448*4882a593Smuzhiyun ovl_copyattr(realinode, inode);
449*4882a593Smuzhiyun ovl_revert_creds(inode->i_sb, old_cred);
450*4882a593Smuzhiyun fdput(real);
451*4882a593Smuzhiyun
452*4882a593Smuzhiyun out_unlock:
453*4882a593Smuzhiyun inode_unlock(inode);
454*4882a593Smuzhiyun
455*4882a593Smuzhiyun return ret;
456*4882a593Smuzhiyun }
457*4882a593Smuzhiyun
ovl_fsync(struct file * file,loff_t start,loff_t end,int datasync)458*4882a593Smuzhiyun static int ovl_fsync(struct file *file, loff_t start, loff_t end, int datasync)
459*4882a593Smuzhiyun {
460*4882a593Smuzhiyun struct fd real;
461*4882a593Smuzhiyun const struct cred *old_cred;
462*4882a593Smuzhiyun int ret;
463*4882a593Smuzhiyun
464*4882a593Smuzhiyun ret = ovl_sync_status(OVL_FS(file_inode(file)->i_sb));
465*4882a593Smuzhiyun if (ret <= 0)
466*4882a593Smuzhiyun return ret;
467*4882a593Smuzhiyun
468*4882a593Smuzhiyun ret = ovl_real_fdget_meta(file, &real, !datasync);
469*4882a593Smuzhiyun if (ret)
470*4882a593Smuzhiyun return ret;
471*4882a593Smuzhiyun
472*4882a593Smuzhiyun /* Don't sync lower file for fear of receiving EROFS error */
473*4882a593Smuzhiyun if (file_inode(real.file) == ovl_inode_upper(file_inode(file))) {
474*4882a593Smuzhiyun old_cred = ovl_override_creds(file_inode(file)->i_sb);
475*4882a593Smuzhiyun ret = vfs_fsync_range(real.file, start, end, datasync);
476*4882a593Smuzhiyun ovl_revert_creds(file_inode(file)->i_sb, old_cred);
477*4882a593Smuzhiyun }
478*4882a593Smuzhiyun
479*4882a593Smuzhiyun fdput(real);
480*4882a593Smuzhiyun
481*4882a593Smuzhiyun return ret;
482*4882a593Smuzhiyun }
483*4882a593Smuzhiyun
ovl_mmap(struct file * file,struct vm_area_struct * vma)484*4882a593Smuzhiyun static int ovl_mmap(struct file *file, struct vm_area_struct *vma)
485*4882a593Smuzhiyun {
486*4882a593Smuzhiyun struct file *realfile = file->private_data;
487*4882a593Smuzhiyun const struct cred *old_cred;
488*4882a593Smuzhiyun int ret;
489*4882a593Smuzhiyun
490*4882a593Smuzhiyun if (!realfile->f_op->mmap)
491*4882a593Smuzhiyun return -ENODEV;
492*4882a593Smuzhiyun
493*4882a593Smuzhiyun if (WARN_ON(file != vma->vm_file))
494*4882a593Smuzhiyun return -EIO;
495*4882a593Smuzhiyun
496*4882a593Smuzhiyun vma->vm_file = get_file(realfile);
497*4882a593Smuzhiyun
498*4882a593Smuzhiyun old_cred = ovl_override_creds(file_inode(file)->i_sb);
499*4882a593Smuzhiyun ret = call_mmap(vma->vm_file, vma);
500*4882a593Smuzhiyun ovl_revert_creds(file_inode(file)->i_sb, old_cred);
501*4882a593Smuzhiyun
502*4882a593Smuzhiyun if (ret) {
503*4882a593Smuzhiyun /* Drop reference count from new vm_file value */
504*4882a593Smuzhiyun fput(realfile);
505*4882a593Smuzhiyun } else {
506*4882a593Smuzhiyun /* Drop reference count from previous vm_file value */
507*4882a593Smuzhiyun fput(file);
508*4882a593Smuzhiyun }
509*4882a593Smuzhiyun
510*4882a593Smuzhiyun ovl_file_accessed(file);
511*4882a593Smuzhiyun
512*4882a593Smuzhiyun return ret;
513*4882a593Smuzhiyun }
514*4882a593Smuzhiyun
ovl_fallocate(struct file * file,int mode,loff_t offset,loff_t len)515*4882a593Smuzhiyun static long ovl_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
516*4882a593Smuzhiyun {
517*4882a593Smuzhiyun struct inode *inode = file_inode(file);
518*4882a593Smuzhiyun struct fd real;
519*4882a593Smuzhiyun const struct cred *old_cred;
520*4882a593Smuzhiyun int ret;
521*4882a593Smuzhiyun
522*4882a593Smuzhiyun ret = ovl_real_fdget(file, &real);
523*4882a593Smuzhiyun if (ret)
524*4882a593Smuzhiyun return ret;
525*4882a593Smuzhiyun
526*4882a593Smuzhiyun old_cred = ovl_override_creds(file_inode(file)->i_sb);
527*4882a593Smuzhiyun ret = vfs_fallocate(real.file, mode, offset, len);
528*4882a593Smuzhiyun ovl_revert_creds(file_inode(file)->i_sb, old_cred);
529*4882a593Smuzhiyun
530*4882a593Smuzhiyun /* Update size */
531*4882a593Smuzhiyun ovl_copyattr(ovl_inode_real(inode), inode);
532*4882a593Smuzhiyun
533*4882a593Smuzhiyun fdput(real);
534*4882a593Smuzhiyun
535*4882a593Smuzhiyun return ret;
536*4882a593Smuzhiyun }
537*4882a593Smuzhiyun
ovl_fadvise(struct file * file,loff_t offset,loff_t len,int advice)538*4882a593Smuzhiyun static int ovl_fadvise(struct file *file, loff_t offset, loff_t len, int advice)
539*4882a593Smuzhiyun {
540*4882a593Smuzhiyun struct fd real;
541*4882a593Smuzhiyun const struct cred *old_cred;
542*4882a593Smuzhiyun int ret;
543*4882a593Smuzhiyun
544*4882a593Smuzhiyun ret = ovl_real_fdget(file, &real);
545*4882a593Smuzhiyun if (ret)
546*4882a593Smuzhiyun return ret;
547*4882a593Smuzhiyun
548*4882a593Smuzhiyun old_cred = ovl_override_creds(file_inode(file)->i_sb);
549*4882a593Smuzhiyun ret = vfs_fadvise(real.file, offset, len, advice);
550*4882a593Smuzhiyun ovl_revert_creds(file_inode(file)->i_sb, old_cred);
551*4882a593Smuzhiyun
552*4882a593Smuzhiyun fdput(real);
553*4882a593Smuzhiyun
554*4882a593Smuzhiyun return ret;
555*4882a593Smuzhiyun }
556*4882a593Smuzhiyun
ovl_real_ioctl(struct file * file,unsigned int cmd,unsigned long arg)557*4882a593Smuzhiyun static long ovl_real_ioctl(struct file *file, unsigned int cmd,
558*4882a593Smuzhiyun unsigned long arg)
559*4882a593Smuzhiyun {
560*4882a593Smuzhiyun struct fd real;
561*4882a593Smuzhiyun long ret;
562*4882a593Smuzhiyun
563*4882a593Smuzhiyun ret = ovl_real_fdget(file, &real);
564*4882a593Smuzhiyun if (ret)
565*4882a593Smuzhiyun return ret;
566*4882a593Smuzhiyun
567*4882a593Smuzhiyun ret = security_file_ioctl(real.file, cmd, arg);
568*4882a593Smuzhiyun if (!ret) {
569*4882a593Smuzhiyun /*
570*4882a593Smuzhiyun * Don't override creds, since we currently can't safely check
571*4882a593Smuzhiyun * permissions before doing so.
572*4882a593Smuzhiyun */
573*4882a593Smuzhiyun ret = vfs_ioctl(real.file, cmd, arg);
574*4882a593Smuzhiyun }
575*4882a593Smuzhiyun
576*4882a593Smuzhiyun fdput(real);
577*4882a593Smuzhiyun
578*4882a593Smuzhiyun return ret;
579*4882a593Smuzhiyun }
580*4882a593Smuzhiyun
ovl_ioctl_set_flags(struct file * file,unsigned int cmd,unsigned long arg)581*4882a593Smuzhiyun static long ovl_ioctl_set_flags(struct file *file, unsigned int cmd,
582*4882a593Smuzhiyun unsigned long arg)
583*4882a593Smuzhiyun {
584*4882a593Smuzhiyun long ret;
585*4882a593Smuzhiyun struct inode *inode = file_inode(file);
586*4882a593Smuzhiyun
587*4882a593Smuzhiyun if (!inode_owner_or_capable(inode))
588*4882a593Smuzhiyun return -EACCES;
589*4882a593Smuzhiyun
590*4882a593Smuzhiyun ret = mnt_want_write_file(file);
591*4882a593Smuzhiyun if (ret)
592*4882a593Smuzhiyun return ret;
593*4882a593Smuzhiyun
594*4882a593Smuzhiyun inode_lock(inode);
595*4882a593Smuzhiyun
596*4882a593Smuzhiyun /*
597*4882a593Smuzhiyun * Prevent copy up if immutable and has no CAP_LINUX_IMMUTABLE
598*4882a593Smuzhiyun * capability.
599*4882a593Smuzhiyun */
600*4882a593Smuzhiyun ret = -EPERM;
601*4882a593Smuzhiyun if (!ovl_has_upperdata(inode) && IS_IMMUTABLE(inode) &&
602*4882a593Smuzhiyun !capable(CAP_LINUX_IMMUTABLE))
603*4882a593Smuzhiyun goto unlock;
604*4882a593Smuzhiyun
605*4882a593Smuzhiyun ret = ovl_maybe_copy_up(file_dentry(file), O_WRONLY);
606*4882a593Smuzhiyun if (ret)
607*4882a593Smuzhiyun goto unlock;
608*4882a593Smuzhiyun
609*4882a593Smuzhiyun ret = ovl_real_ioctl(file, cmd, arg);
610*4882a593Smuzhiyun
611*4882a593Smuzhiyun ovl_copyflags(ovl_inode_real(inode), inode);
612*4882a593Smuzhiyun unlock:
613*4882a593Smuzhiyun inode_unlock(inode);
614*4882a593Smuzhiyun
615*4882a593Smuzhiyun mnt_drop_write_file(file);
616*4882a593Smuzhiyun
617*4882a593Smuzhiyun return ret;
618*4882a593Smuzhiyun
619*4882a593Smuzhiyun }
620*4882a593Smuzhiyun
ovl_ioctl(struct file * file,unsigned int cmd,unsigned long arg)621*4882a593Smuzhiyun long ovl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
622*4882a593Smuzhiyun {
623*4882a593Smuzhiyun long ret;
624*4882a593Smuzhiyun
625*4882a593Smuzhiyun switch (cmd) {
626*4882a593Smuzhiyun case FS_IOC_GETFLAGS:
627*4882a593Smuzhiyun case FS_IOC_FSGETXATTR:
628*4882a593Smuzhiyun ret = ovl_real_ioctl(file, cmd, arg);
629*4882a593Smuzhiyun break;
630*4882a593Smuzhiyun
631*4882a593Smuzhiyun case FS_IOC_FSSETXATTR:
632*4882a593Smuzhiyun case FS_IOC_SETFLAGS:
633*4882a593Smuzhiyun ret = ovl_ioctl_set_flags(file, cmd, arg);
634*4882a593Smuzhiyun break;
635*4882a593Smuzhiyun
636*4882a593Smuzhiyun default:
637*4882a593Smuzhiyun ret = -ENOTTY;
638*4882a593Smuzhiyun }
639*4882a593Smuzhiyun
640*4882a593Smuzhiyun return ret;
641*4882a593Smuzhiyun }
642*4882a593Smuzhiyun
643*4882a593Smuzhiyun #ifdef CONFIG_COMPAT
ovl_compat_ioctl(struct file * file,unsigned int cmd,unsigned long arg)644*4882a593Smuzhiyun long ovl_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
645*4882a593Smuzhiyun {
646*4882a593Smuzhiyun switch (cmd) {
647*4882a593Smuzhiyun case FS_IOC32_GETFLAGS:
648*4882a593Smuzhiyun cmd = FS_IOC_GETFLAGS;
649*4882a593Smuzhiyun break;
650*4882a593Smuzhiyun
651*4882a593Smuzhiyun case FS_IOC32_SETFLAGS:
652*4882a593Smuzhiyun cmd = FS_IOC_SETFLAGS;
653*4882a593Smuzhiyun break;
654*4882a593Smuzhiyun
655*4882a593Smuzhiyun default:
656*4882a593Smuzhiyun return -ENOIOCTLCMD;
657*4882a593Smuzhiyun }
658*4882a593Smuzhiyun
659*4882a593Smuzhiyun return ovl_ioctl(file, cmd, arg);
660*4882a593Smuzhiyun }
661*4882a593Smuzhiyun #endif
662*4882a593Smuzhiyun
663*4882a593Smuzhiyun enum ovl_copyop {
664*4882a593Smuzhiyun OVL_COPY,
665*4882a593Smuzhiyun OVL_CLONE,
666*4882a593Smuzhiyun OVL_DEDUPE,
667*4882a593Smuzhiyun };
668*4882a593Smuzhiyun
ovl_copyfile(struct file * file_in,loff_t pos_in,struct file * file_out,loff_t pos_out,loff_t len,unsigned int flags,enum ovl_copyop op)669*4882a593Smuzhiyun static loff_t ovl_copyfile(struct file *file_in, loff_t pos_in,
670*4882a593Smuzhiyun struct file *file_out, loff_t pos_out,
671*4882a593Smuzhiyun loff_t len, unsigned int flags, enum ovl_copyop op)
672*4882a593Smuzhiyun {
673*4882a593Smuzhiyun struct inode *inode_out = file_inode(file_out);
674*4882a593Smuzhiyun struct fd real_in, real_out;
675*4882a593Smuzhiyun const struct cred *old_cred;
676*4882a593Smuzhiyun loff_t ret;
677*4882a593Smuzhiyun
678*4882a593Smuzhiyun ret = ovl_real_fdget(file_out, &real_out);
679*4882a593Smuzhiyun if (ret)
680*4882a593Smuzhiyun return ret;
681*4882a593Smuzhiyun
682*4882a593Smuzhiyun ret = ovl_real_fdget(file_in, &real_in);
683*4882a593Smuzhiyun if (ret) {
684*4882a593Smuzhiyun fdput(real_out);
685*4882a593Smuzhiyun return ret;
686*4882a593Smuzhiyun }
687*4882a593Smuzhiyun
688*4882a593Smuzhiyun old_cred = ovl_override_creds(file_inode(file_out)->i_sb);
689*4882a593Smuzhiyun switch (op) {
690*4882a593Smuzhiyun case OVL_COPY:
691*4882a593Smuzhiyun ret = vfs_copy_file_range(real_in.file, pos_in,
692*4882a593Smuzhiyun real_out.file, pos_out, len, flags);
693*4882a593Smuzhiyun break;
694*4882a593Smuzhiyun
695*4882a593Smuzhiyun case OVL_CLONE:
696*4882a593Smuzhiyun ret = vfs_clone_file_range(real_in.file, pos_in,
697*4882a593Smuzhiyun real_out.file, pos_out, len, flags);
698*4882a593Smuzhiyun break;
699*4882a593Smuzhiyun
700*4882a593Smuzhiyun case OVL_DEDUPE:
701*4882a593Smuzhiyun ret = vfs_dedupe_file_range_one(real_in.file, pos_in,
702*4882a593Smuzhiyun real_out.file, pos_out, len,
703*4882a593Smuzhiyun flags);
704*4882a593Smuzhiyun break;
705*4882a593Smuzhiyun }
706*4882a593Smuzhiyun ovl_revert_creds(file_inode(file_out)->i_sb, old_cred);
707*4882a593Smuzhiyun
708*4882a593Smuzhiyun /* Update size */
709*4882a593Smuzhiyun ovl_copyattr(ovl_inode_real(inode_out), inode_out);
710*4882a593Smuzhiyun
711*4882a593Smuzhiyun fdput(real_in);
712*4882a593Smuzhiyun fdput(real_out);
713*4882a593Smuzhiyun
714*4882a593Smuzhiyun return ret;
715*4882a593Smuzhiyun }
716*4882a593Smuzhiyun
ovl_copy_file_range(struct file * file_in,loff_t pos_in,struct file * file_out,loff_t pos_out,size_t len,unsigned int flags)717*4882a593Smuzhiyun static ssize_t ovl_copy_file_range(struct file *file_in, loff_t pos_in,
718*4882a593Smuzhiyun struct file *file_out, loff_t pos_out,
719*4882a593Smuzhiyun size_t len, unsigned int flags)
720*4882a593Smuzhiyun {
721*4882a593Smuzhiyun return ovl_copyfile(file_in, pos_in, file_out, pos_out, len, flags,
722*4882a593Smuzhiyun OVL_COPY);
723*4882a593Smuzhiyun }
724*4882a593Smuzhiyun
ovl_remap_file_range(struct file * file_in,loff_t pos_in,struct file * file_out,loff_t pos_out,loff_t len,unsigned int remap_flags)725*4882a593Smuzhiyun static loff_t ovl_remap_file_range(struct file *file_in, loff_t pos_in,
726*4882a593Smuzhiyun struct file *file_out, loff_t pos_out,
727*4882a593Smuzhiyun loff_t len, unsigned int remap_flags)
728*4882a593Smuzhiyun {
729*4882a593Smuzhiyun enum ovl_copyop op;
730*4882a593Smuzhiyun
731*4882a593Smuzhiyun if (remap_flags & ~(REMAP_FILE_DEDUP | REMAP_FILE_ADVISORY))
732*4882a593Smuzhiyun return -EINVAL;
733*4882a593Smuzhiyun
734*4882a593Smuzhiyun if (remap_flags & REMAP_FILE_DEDUP)
735*4882a593Smuzhiyun op = OVL_DEDUPE;
736*4882a593Smuzhiyun else
737*4882a593Smuzhiyun op = OVL_CLONE;
738*4882a593Smuzhiyun
739*4882a593Smuzhiyun /*
740*4882a593Smuzhiyun * Don't copy up because of a dedupe request, this wouldn't make sense
741*4882a593Smuzhiyun * most of the time (data would be duplicated instead of deduplicated).
742*4882a593Smuzhiyun */
743*4882a593Smuzhiyun if (op == OVL_DEDUPE &&
744*4882a593Smuzhiyun (!ovl_inode_upper(file_inode(file_in)) ||
745*4882a593Smuzhiyun !ovl_inode_upper(file_inode(file_out))))
746*4882a593Smuzhiyun return -EPERM;
747*4882a593Smuzhiyun
748*4882a593Smuzhiyun return ovl_copyfile(file_in, pos_in, file_out, pos_out, len,
749*4882a593Smuzhiyun remap_flags, op);
750*4882a593Smuzhiyun }
751*4882a593Smuzhiyun
752*4882a593Smuzhiyun const struct file_operations ovl_file_operations = {
753*4882a593Smuzhiyun .open = ovl_open,
754*4882a593Smuzhiyun .release = ovl_release,
755*4882a593Smuzhiyun .llseek = ovl_llseek,
756*4882a593Smuzhiyun .read_iter = ovl_read_iter,
757*4882a593Smuzhiyun .write_iter = ovl_write_iter,
758*4882a593Smuzhiyun .fsync = ovl_fsync,
759*4882a593Smuzhiyun .mmap = ovl_mmap,
760*4882a593Smuzhiyun .fallocate = ovl_fallocate,
761*4882a593Smuzhiyun .fadvise = ovl_fadvise,
762*4882a593Smuzhiyun .unlocked_ioctl = ovl_ioctl,
763*4882a593Smuzhiyun #ifdef CONFIG_COMPAT
764*4882a593Smuzhiyun .compat_ioctl = ovl_compat_ioctl,
765*4882a593Smuzhiyun #endif
766*4882a593Smuzhiyun .splice_read = generic_file_splice_read,
767*4882a593Smuzhiyun .splice_write = ovl_splice_write,
768*4882a593Smuzhiyun
769*4882a593Smuzhiyun .copy_file_range = ovl_copy_file_range,
770*4882a593Smuzhiyun .remap_file_range = ovl_remap_file_range,
771*4882a593Smuzhiyun };
772*4882a593Smuzhiyun
ovl_aio_request_cache_init(void)773*4882a593Smuzhiyun int __init ovl_aio_request_cache_init(void)
774*4882a593Smuzhiyun {
775*4882a593Smuzhiyun ovl_aio_request_cachep = kmem_cache_create("ovl_aio_req",
776*4882a593Smuzhiyun sizeof(struct ovl_aio_req),
777*4882a593Smuzhiyun 0, SLAB_HWCACHE_ALIGN, NULL);
778*4882a593Smuzhiyun if (!ovl_aio_request_cachep)
779*4882a593Smuzhiyun return -ENOMEM;
780*4882a593Smuzhiyun
781*4882a593Smuzhiyun return 0;
782*4882a593Smuzhiyun }
783*4882a593Smuzhiyun
ovl_aio_request_cache_destroy(void)784*4882a593Smuzhiyun void ovl_aio_request_cache_destroy(void)
785*4882a593Smuzhiyun {
786*4882a593Smuzhiyun kmem_cache_destroy(ovl_aio_request_cachep);
787*4882a593Smuzhiyun }
788