blob: 9d2eeed9e3232b11e65cb3831a7a76c47c148809 [file] [log] [blame]
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001#include <linux/ceph/ceph_debug.h>
Sage Weil124e68e2009-10-06 11:31:08 -07002
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07003#include <linux/module.h>
Sage Weil124e68e2009-10-06 11:31:08 -07004#include <linux/sched.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09005#include <linux/slab.h>
Sage Weil124e68e2009-10-06 11:31:08 -07006#include <linux/file.h>
Sage Weil5ef50c32012-07-31 11:27:36 -07007#include <linux/mount.h>
Sage Weil124e68e2009-10-06 11:31:08 -07008#include <linux/namei.h>
9#include <linux/writeback.h>
Li Wangad7a60d2013-08-15 11:51:44 +080010#include <linux/falloc.h>
Sage Weil124e68e2009-10-06 11:31:08 -070011
12#include "super.h"
13#include "mds_client.h"
Milosz Tanski99ccbd22013-08-21 17:29:54 -040014#include "cache.h"
Sage Weil124e68e2009-10-06 11:31:08 -070015
Alexander Graff775ff72017-04-27 18:34:00 +020016static __le32 ceph_flags_sys2wire(u32 flags)
17{
18 u32 wire_flags = 0;
19
20 switch (flags & O_ACCMODE) {
21 case O_RDONLY:
22 wire_flags |= CEPH_O_RDONLY;
23 break;
24 case O_WRONLY:
25 wire_flags |= CEPH_O_WRONLY;
26 break;
27 case O_RDWR:
28 wire_flags |= CEPH_O_RDWR;
29 break;
30 }
31
32#define ceph_sys2wire(a) if (flags & a) { wire_flags |= CEPH_##a; flags &= ~a; }
33
34 ceph_sys2wire(O_CREAT);
35 ceph_sys2wire(O_EXCL);
36 ceph_sys2wire(O_TRUNC);
37 ceph_sys2wire(O_DIRECTORY);
38 ceph_sys2wire(O_NOFOLLOW);
39
40#undef ceph_sys2wire
41
42 if (flags)
43 dout("unused open flags: %x", flags);
44
45 return cpu_to_le32(wire_flags);
46}
47
Sage Weil124e68e2009-10-06 11:31:08 -070048/*
49 * Ceph file operations
50 *
51 * Implement basic open/close functionality, and implement
52 * read/write.
53 *
54 * We implement three modes of file I/O:
55 * - buffered uses the generic_file_aio_{read,write} helpers
56 *
57 * - synchronous is used when there is multi-client read/write
58 * sharing, avoids the page cache, and synchronously waits for an
59 * ack from the OSD.
60 *
61 * - direct io takes the variant of the sync path that references
62 * user pages directly.
63 *
64 * fsync() flushes and waits on dirty pages, but just queues metadata
65 * for writeback: since the MDS can recover size and mtime there is no
66 * need to wait for MDS acknowledgement.
67 */
68
Zhu, Caifengb5b98989d2015-10-08 15:26:15 +080069/*
70 * Calculate the length sum of direct io vectors that can
71 * be combined into one page vector.
72 */
73static size_t dio_get_pagev_size(const struct iov_iter *it)
74{
75 const struct iovec *iov = it->iov;
76 const struct iovec *iovend = iov + it->nr_segs;
77 size_t size;
78
79 size = iov->iov_len - it->iov_offset;
80 /*
81 * An iov can be page vectored when both the current tail
82 * and the next base are page aligned.
83 */
84 while (PAGE_ALIGNED((iov->iov_base + iov->iov_len)) &&
85 (++iov < iovend && PAGE_ALIGNED((iov->iov_base)))) {
86 size += iov->iov_len;
87 }
88 dout("dio_get_pagevlen len = %zu\n", size);
89 return size;
90}
91
92/*
93 * Allocate a page vector based on (@it, @nbytes).
94 * The return value is the tuple describing a page vector,
95 * that is (@pages, @page_align, @num_pages).
96 */
97static struct page **
98dio_get_pages_alloc(const struct iov_iter *it, size_t nbytes,
99 size_t *page_align, int *num_pages)
100{
101 struct iov_iter tmp_it = *it;
102 size_t align;
103 struct page **pages;
104 int ret = 0, idx, npages;
105
106 align = (unsigned long)(it->iov->iov_base + it->iov_offset) &
107 (PAGE_SIZE - 1);
108 npages = calc_pages_for(align, nbytes);
109 pages = kmalloc(sizeof(*pages) * npages, GFP_KERNEL);
110 if (!pages) {
111 pages = vmalloc(sizeof(*pages) * npages);
112 if (!pages)
113 return ERR_PTR(-ENOMEM);
114 }
115
116 for (idx = 0; idx < npages; ) {
117 size_t start;
118 ret = iov_iter_get_pages(&tmp_it, pages + idx, nbytes,
119 npages - idx, &start);
120 if (ret < 0)
121 goto fail;
122
123 iov_iter_advance(&tmp_it, ret);
124 nbytes -= ret;
125 idx += (ret + start + PAGE_SIZE - 1) / PAGE_SIZE;
126 }
127
128 BUG_ON(nbytes != 0);
129 *num_pages = npages;
130 *page_align = align;
131 dout("dio_get_pages_alloc: got %d pages align %zu\n", npages, align);
132 return pages;
133fail:
134 ceph_put_page_vector(pages, idx, false);
135 return ERR_PTR(ret);
136}
Sage Weil124e68e2009-10-06 11:31:08 -0700137
138/*
139 * Prepare an open request. Preallocate ceph_cap to avoid an
140 * inopportune ENOMEM later.
141 */
142static struct ceph_mds_request *
143prepare_open_request(struct super_block *sb, int flags, int create_mode)
144{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700145 struct ceph_fs_client *fsc = ceph_sb_to_client(sb);
146 struct ceph_mds_client *mdsc = fsc->mdsc;
Sage Weil124e68e2009-10-06 11:31:08 -0700147 struct ceph_mds_request *req;
148 int want_auth = USE_ANY_MDS;
149 int op = (flags & O_CREAT) ? CEPH_MDS_OP_CREATE : CEPH_MDS_OP_OPEN;
150
151 if (flags & (O_WRONLY|O_RDWR|O_CREAT|O_TRUNC))
152 want_auth = USE_AUTH_MDS;
153
154 req = ceph_mdsc_create_request(mdsc, op, want_auth);
155 if (IS_ERR(req))
156 goto out;
157 req->r_fmode = ceph_flags_to_mode(flags);
Alexander Graff775ff72017-04-27 18:34:00 +0200158 req->r_args.open.flags = ceph_flags_sys2wire(flags);
Sage Weil124e68e2009-10-06 11:31:08 -0700159 req->r_args.open.mode = cpu_to_le32(create_mode);
Sage Weil124e68e2009-10-06 11:31:08 -0700160out:
161 return req;
162}
163
164/*
165 * initialize private struct file data.
166 * if we fail, clean up by dropping fmode reference on the ceph_inode
167 */
168static int ceph_init_file(struct inode *inode, struct file *file, int fmode)
169{
170 struct ceph_file_info *cf;
171 int ret = 0;
172
173 switch (inode->i_mode & S_IFMT) {
174 case S_IFREG:
Yan, Zheng46b59b22016-05-18 15:25:03 +0800175 ceph_fscache_register_inode_cookie(inode);
176 ceph_fscache_file_set_cookie(inode, file);
Sage Weil124e68e2009-10-06 11:31:08 -0700177 case S_IFDIR:
178 dout("init_file %p %p 0%o (regular)\n", inode, file,
179 inode->i_mode);
Geliang Tang99ec2692016-03-13 15:26:29 +0800180 cf = kmem_cache_zalloc(ceph_file_cachep, GFP_KERNEL);
Sage Weil124e68e2009-10-06 11:31:08 -0700181 if (cf == NULL) {
182 ceph_put_fmode(ceph_inode(inode), fmode); /* clean up */
183 return -ENOMEM;
184 }
185 cf->fmode = fmode;
186 cf->next_offset = 2;
Yan, Zhengfdd4e152015-06-16 20:48:56 +0800187 cf->readdir_cache_idx = -1;
Sage Weil124e68e2009-10-06 11:31:08 -0700188 file->private_data = cf;
189 BUG_ON(inode->i_fop->release != ceph_release);
190 break;
191
192 case S_IFLNK:
193 dout("init_file %p %p 0%o (symlink)\n", inode, file,
194 inode->i_mode);
195 ceph_put_fmode(ceph_inode(inode), fmode); /* clean up */
196 break;
197
198 default:
199 dout("init_file %p %p 0%o (special)\n", inode, file,
200 inode->i_mode);
201 /*
202 * we need to drop the open ref now, since we don't
203 * have .release set to ceph_release.
204 */
205 ceph_put_fmode(ceph_inode(inode), fmode); /* clean up */
206 BUG_ON(inode->i_fop->release == ceph_release);
207
208 /* call the proper open fop */
209 ret = inode->i_fop->open(inode, file);
210 }
211 return ret;
212}
213
214/*
Yan, Zheng77310322016-04-08 15:27:16 +0800215 * try renew caps after session gets killed.
216 */
217int ceph_renew_caps(struct inode *inode)
218{
219 struct ceph_mds_client *mdsc = ceph_sb_to_client(inode->i_sb)->mdsc;
220 struct ceph_inode_info *ci = ceph_inode(inode);
221 struct ceph_mds_request *req;
222 int err, flags, wanted;
223
224 spin_lock(&ci->i_ceph_lock);
225 wanted = __ceph_caps_file_wanted(ci);
226 if (__ceph_is_any_real_caps(ci) &&
Yan, Zheng8242c9f2017-03-25 17:28:10 +0800227 (!(wanted & CEPH_CAP_ANY_WR) || ci->i_auth_cap)) {
Yan, Zheng77310322016-04-08 15:27:16 +0800228 int issued = __ceph_caps_issued(ci, NULL);
229 spin_unlock(&ci->i_ceph_lock);
230 dout("renew caps %p want %s issued %s updating mds_wanted\n",
231 inode, ceph_cap_string(wanted), ceph_cap_string(issued));
232 ceph_check_caps(ci, 0, NULL);
233 return 0;
234 }
235 spin_unlock(&ci->i_ceph_lock);
236
237 flags = 0;
238 if ((wanted & CEPH_CAP_FILE_RD) && (wanted & CEPH_CAP_FILE_WR))
239 flags = O_RDWR;
240 else if (wanted & CEPH_CAP_FILE_RD)
241 flags = O_RDONLY;
242 else if (wanted & CEPH_CAP_FILE_WR)
243 flags = O_WRONLY;
244#ifdef O_LAZY
245 if (wanted & CEPH_CAP_FILE_LAZYIO)
246 flags |= O_LAZY;
247#endif
248
249 req = prepare_open_request(inode->i_sb, flags, 0);
250 if (IS_ERR(req)) {
251 err = PTR_ERR(req);
252 goto out;
253 }
254
255 req->r_inode = inode;
256 ihold(inode);
257 req->r_num_caps = 1;
258 req->r_fmode = -1;
259
260 err = ceph_mdsc_do_request(mdsc, NULL, req);
261 ceph_mdsc_put_request(req);
262out:
263 dout("renew caps %p open result=%d\n", inode, err);
264 return err < 0 ? err : 0;
265}
266
267/*
Sage Weil124e68e2009-10-06 11:31:08 -0700268 * If we already have the requisite capabilities, we can satisfy
269 * the open request locally (no need to request new caps from the
270 * MDS). We do, however, need to inform the MDS (asynchronously)
271 * if our wanted caps set expands.
272 */
273int ceph_open(struct inode *inode, struct file *file)
274{
275 struct ceph_inode_info *ci = ceph_inode(inode);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700276 struct ceph_fs_client *fsc = ceph_sb_to_client(inode->i_sb);
277 struct ceph_mds_client *mdsc = fsc->mdsc;
Sage Weil124e68e2009-10-06 11:31:08 -0700278 struct ceph_mds_request *req;
279 struct ceph_file_info *cf = file->private_data;
Sage Weil124e68e2009-10-06 11:31:08 -0700280 int err;
281 int flags, fmode, wanted;
282
283 if (cf) {
284 dout("open file %p is already opened\n", file);
285 return 0;
286 }
287
288 /* filter out O_CREAT|O_EXCL; vfs did that already. yuck. */
289 flags = file->f_flags & ~(O_CREAT|O_EXCL);
290 if (S_ISDIR(inode->i_mode))
291 flags = O_DIRECTORY; /* mds likes to know */
292
293 dout("open inode %p ino %llx.%llx file %p flags %d (%d)\n", inode,
294 ceph_vinop(inode), file, flags, file->f_flags);
295 fmode = ceph_flags_to_mode(flags);
296 wanted = ceph_caps_for_mode(fmode);
297
298 /* snapped files are read-only */
299 if (ceph_snap(inode) != CEPH_NOSNAP && (file->f_mode & FMODE_WRITE))
300 return -EROFS;
301
302 /* trivially open snapdir */
303 if (ceph_snap(inode) == CEPH_SNAPDIR) {
Sage Weilbe655592011-11-30 09:47:09 -0800304 spin_lock(&ci->i_ceph_lock);
Sage Weil124e68e2009-10-06 11:31:08 -0700305 __ceph_get_fmode(ci, fmode);
Sage Weilbe655592011-11-30 09:47:09 -0800306 spin_unlock(&ci->i_ceph_lock);
Sage Weil124e68e2009-10-06 11:31:08 -0700307 return ceph_init_file(inode, file, fmode);
308 }
309
310 /*
Sage Weil7421ab82010-11-07 09:07:15 -0800311 * No need to block if we have caps on the auth MDS (for
312 * write) or any MDS (for read). Update wanted set
Sage Weil124e68e2009-10-06 11:31:08 -0700313 * asynchronously.
314 */
Sage Weilbe655592011-11-30 09:47:09 -0800315 spin_lock(&ci->i_ceph_lock);
Sage Weil7421ab82010-11-07 09:07:15 -0800316 if (__ceph_is_any_real_caps(ci) &&
317 (((fmode & CEPH_FILE_MODE_WR) == 0) || ci->i_auth_cap)) {
Yan, Zhengc1944fe2017-01-29 22:15:47 +0800318 int mds_wanted = __ceph_caps_mds_wanted(ci, true);
Sage Weil124e68e2009-10-06 11:31:08 -0700319 int issued = __ceph_caps_issued(ci, NULL);
320
321 dout("open %p fmode %d want %s issued %s using existing\n",
322 inode, fmode, ceph_cap_string(wanted),
323 ceph_cap_string(issued));
324 __ceph_get_fmode(ci, fmode);
Sage Weilbe655592011-11-30 09:47:09 -0800325 spin_unlock(&ci->i_ceph_lock);
Sage Weil124e68e2009-10-06 11:31:08 -0700326
327 /* adjust wanted? */
328 if ((issued & wanted) != wanted &&
329 (mds_wanted & wanted) != wanted &&
330 ceph_snap(inode) != CEPH_SNAPDIR)
331 ceph_check_caps(ci, 0, NULL);
332
333 return ceph_init_file(inode, file, fmode);
334 } else if (ceph_snap(inode) != CEPH_NOSNAP &&
335 (ci->i_snap_caps & wanted) == wanted) {
336 __ceph_get_fmode(ci, fmode);
Sage Weilbe655592011-11-30 09:47:09 -0800337 spin_unlock(&ci->i_ceph_lock);
Sage Weil124e68e2009-10-06 11:31:08 -0700338 return ceph_init_file(inode, file, fmode);
339 }
Milosz Tanski99ccbd22013-08-21 17:29:54 -0400340
Sage Weilbe655592011-11-30 09:47:09 -0800341 spin_unlock(&ci->i_ceph_lock);
Sage Weil124e68e2009-10-06 11:31:08 -0700342
343 dout("open fmode %d wants %s\n", fmode, ceph_cap_string(wanted));
344 req = prepare_open_request(inode->i_sb, flags, 0);
345 if (IS_ERR(req)) {
346 err = PTR_ERR(req);
347 goto out;
348 }
Sage Weil70b666c2011-05-27 09:24:26 -0700349 req->r_inode = inode;
350 ihold(inode);
Milosz Tanski99ccbd22013-08-21 17:29:54 -0400351
Sage Weil124e68e2009-10-06 11:31:08 -0700352 req->r_num_caps = 1;
Jianpeng Mae36d5712015-08-18 10:25:35 +0800353 err = ceph_mdsc_do_request(mdsc, NULL, req);
Sage Weil124e68e2009-10-06 11:31:08 -0700354 if (!err)
355 err = ceph_init_file(inode, file, req->r_fmode);
356 ceph_mdsc_put_request(req);
357 dout("open result=%d on %llx.%llx\n", err, ceph_vinop(inode));
358out:
359 return err;
360}
361
362
363/*
Sage Weil5ef50c32012-07-31 11:27:36 -0700364 * Do a lookup + open with a single request. If we get a non-existent
365 * file or symlink, return 1 so the VFS can retry.
Sage Weil124e68e2009-10-06 11:31:08 -0700366 */
Sage Weil5ef50c32012-07-31 11:27:36 -0700367int ceph_atomic_open(struct inode *dir, struct dentry *dentry,
Al Viro30d90492012-06-22 12:40:19 +0400368 struct file *file, unsigned flags, umode_t mode,
Al Virod9585272012-06-22 12:39:14 +0400369 int *opened)
Sage Weil124e68e2009-10-06 11:31:08 -0700370{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700371 struct ceph_fs_client *fsc = ceph_sb_to_client(dir->i_sb);
372 struct ceph_mds_client *mdsc = fsc->mdsc;
Sage Weil124e68e2009-10-06 11:31:08 -0700373 struct ceph_mds_request *req;
Sage Weil5ef50c32012-07-31 11:27:36 -0700374 struct dentry *dn;
Yan, Zhengb1ee94a2014-09-16 20:35:17 +0800375 struct ceph_acls_info acls = {};
Yan, Zheng315f2402016-03-07 10:34:50 +0800376 int mask;
Sage Weil124e68e2009-10-06 11:31:08 -0700377 int err;
Sage Weil124e68e2009-10-06 11:31:08 -0700378
Al Viroa4555892014-10-21 20:11:25 -0400379 dout("atomic_open %p dentry %p '%pd' %s flags %d mode 0%o\n",
380 dir, dentry, dentry,
Sage Weil5ef50c32012-07-31 11:27:36 -0700381 d_unhashed(dentry) ? "unhashed" : "hashed", flags, mode);
382
383 if (dentry->d_name.len > NAME_MAX)
384 return -ENAMETOOLONG;
385
Yan, Zhengb1ee94a2014-09-16 20:35:17 +0800386 if (flags & O_CREAT) {
387 err = ceph_pre_init_acls(dir, &mode, &acls);
388 if (err < 0)
389 return err;
390 }
391
Sage Weil124e68e2009-10-06 11:31:08 -0700392 /* do the open */
393 req = prepare_open_request(dir->i_sb, flags, mode);
Yan, Zhengb1ee94a2014-09-16 20:35:17 +0800394 if (IS_ERR(req)) {
395 err = PTR_ERR(req);
396 goto out_acl;
397 }
Sage Weil124e68e2009-10-06 11:31:08 -0700398 req->r_dentry = dget(dentry);
399 req->r_num_caps = 2;
400 if (flags & O_CREAT) {
401 req->r_dentry_drop = CEPH_CAP_FILE_SHARED;
402 req->r_dentry_unless = CEPH_CAP_FILE_EXCL;
Yan, Zhengb1ee94a2014-09-16 20:35:17 +0800403 if (acls.pagelist) {
404 req->r_pagelist = acls.pagelist;
405 acls.pagelist = NULL;
406 }
Sage Weil124e68e2009-10-06 11:31:08 -0700407 }
Yan, Zheng315f2402016-03-07 10:34:50 +0800408
409 mask = CEPH_STAT_CAP_INODE | CEPH_CAP_AUTH_SHARED;
410 if (ceph_security_xattr_wanted(dir))
411 mask |= CEPH_CAP_XATTR_SHARED;
412 req->r_args.open.mask = cpu_to_le32(mask);
413
Jeff Layton3dd69aa2017-01-31 10:28:26 -0500414 req->r_parent = dir;
415 set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags);
Sage Weilacda7652011-07-26 11:27:48 -0700416 err = ceph_mdsc_do_request(mdsc,
417 (flags & (O_CREAT|O_TRUNC)) ? dir : NULL,
418 req);
Yan, Zhengbf91c312015-01-19 13:23:20 +0800419 err = ceph_handle_snapdir(req, dentry, err);
Sam Lang79aec9842012-12-19 09:44:23 -1000420 if (err)
Yan, Zhengb1ee94a2014-09-16 20:35:17 +0800421 goto out_req;
Sam Lang79aec9842012-12-19 09:44:23 -1000422
Jianpeng Maa43137f2015-08-18 10:23:50 +0800423 if ((flags & O_CREAT) && !req->r_reply_info.head->is_dentry)
Sage Weil124e68e2009-10-06 11:31:08 -0700424 err = ceph_handle_notrace_create(dir, dentry);
Sage Weil5ef50c32012-07-31 11:27:36 -0700425
Al Viro00699ad2016-07-05 09:44:53 -0400426 if (d_in_lookup(dentry)) {
Sage Weil5ef50c32012-07-31 11:27:36 -0700427 dn = ceph_finish_lookup(req, dentry, err);
428 if (IS_ERR(dn))
429 err = PTR_ERR(dn);
430 } else {
431 /* we were given a hashed negative dentry */
432 dn = NULL;
433 }
Sage Weil468640e2011-07-26 11:28:11 -0700434 if (err)
Yan, Zhengb1ee94a2014-09-16 20:35:17 +0800435 goto out_req;
David Howells2b0143b2015-03-17 22:25:59 +0000436 if (dn || d_really_is_negative(dentry) || d_is_symlink(dentry)) {
Sage Weil5ef50c32012-07-31 11:27:36 -0700437 /* make vfs retry on splice, ENOENT, or symlink */
438 dout("atomic_open finish_no_open on dn %p\n", dn);
439 err = finish_no_open(file, dn);
440 } else {
441 dout("atomic_open finish_open on dn %p\n", dn);
Sam Lang6e8575f2012-12-28 09:56:46 -0800442 if (req->r_op == CEPH_MDS_OP_CREATE && req->r_reply_info.has_create_ino) {
David Howells2b0143b2015-03-17 22:25:59 +0000443 ceph_init_inode_acls(d_inode(dentry), &acls);
Sam Lang6e8575f2012-12-28 09:56:46 -0800444 *opened |= FILE_CREATED;
445 }
Sage Weil5ef50c32012-07-31 11:27:36 -0700446 err = finish_open(file, dentry, ceph_open, opened);
447 }
Yan, Zhengb1ee94a2014-09-16 20:35:17 +0800448out_req:
Yan, Zhengab866542014-04-01 20:20:17 +0800449 if (!req->r_err && req->r_target_inode)
450 ceph_put_fmode(ceph_inode(req->r_target_inode), req->r_fmode);
Sage Weil124e68e2009-10-06 11:31:08 -0700451 ceph_mdsc_put_request(req);
Yan, Zhengb1ee94a2014-09-16 20:35:17 +0800452out_acl:
453 ceph_release_acls_info(&acls);
Sage Weil5ef50c32012-07-31 11:27:36 -0700454 dout("atomic_open result=%d\n", err);
Al Virod9585272012-06-22 12:39:14 +0400455 return err;
Sage Weil124e68e2009-10-06 11:31:08 -0700456}
457
458int ceph_release(struct inode *inode, struct file *file)
459{
460 struct ceph_inode_info *ci = ceph_inode(inode);
461 struct ceph_file_info *cf = file->private_data;
462
463 dout("release inode %p file %p\n", inode, file);
464 ceph_put_fmode(ci, cf->fmode);
465 if (cf->last_readdir)
466 ceph_mdsc_put_request(cf->last_readdir);
467 kfree(cf->last_name);
468 kfree(cf->dir_info);
Sage Weil124e68e2009-10-06 11:31:08 -0700469 kmem_cache_free(ceph_file_cachep, cf);
Sage Weil195d3ce2010-03-01 09:57:54 -0800470
471 /* wake up anyone waiting for caps on this inode */
Yehuda Sadeh03066f22010-07-27 13:11:08 -0700472 wake_up_all(&ci->i_cap_wq);
Sage Weil124e68e2009-10-06 11:31:08 -0700473 return 0;
474}
475
Yan, Zheng83701242014-11-14 22:36:18 +0800476enum {
Yan, Zhengc8fe9b12015-12-23 21:23:38 +0800477 HAVE_RETRIED = 1,
478 CHECK_EOF = 2,
479 READ_INLINE = 3,
Yan, Zheng83701242014-11-14 22:36:18 +0800480};
481
Sage Weil124e68e2009-10-06 11:31:08 -0700482/*
Sage Weil124e68e2009-10-06 11:31:08 -0700483 * Read a range of bytes striped over one or more objects. Iterate over
484 * objects we stripe over. (That's not atomic, but good enough for now.)
485 *
486 * If we get a short result from the OSD, check against i_size; we need to
487 * only return a short read to the caller if we hit EOF.
488 */
489static int striped_read(struct inode *inode,
Yan, Zheng7ce469a2016-11-08 21:54:34 +0800490 u64 pos, u64 len,
Sage Weil6a026582010-02-09 14:04:02 -0800491 struct page **pages, int num_pages,
Yan, Zheng7ce469a2016-11-08 21:54:34 +0800492 int page_align, int *checkeof)
Sage Weil124e68e2009-10-06 11:31:08 -0700493{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700494 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
Sage Weil124e68e2009-10-06 11:31:08 -0700495 struct ceph_inode_info *ci = ceph_inode(inode);
Yan, Zheng7ce469a2016-11-08 21:54:34 +0800496 u64 this_len;
Yan, Zheng99c88e62015-12-30 11:32:46 +0800497 loff_t i_size;
Yan, Zheng7ce469a2016-11-08 21:54:34 +0800498 int page_idx;
499 int ret, read = 0;
Sage Weil124e68e2009-10-06 11:31:08 -0700500 bool hit_stripe, was_short;
501
502 /*
503 * we may need to do multiple reads. not atomic, unfortunately.
504 */
Sage Weil124e68e2009-10-06 11:31:08 -0700505more:
Yan, Zheng7ce469a2016-11-08 21:54:34 +0800506 this_len = len;
507 page_idx = (page_align + read) >> PAGE_SHIFT;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700508 ret = ceph_osdc_readpages(&fsc->client->osdc, ceph_vino(inode),
Sage Weil124e68e2009-10-06 11:31:08 -0700509 &ci->i_layout, pos, &this_len,
Yan, Zheng7ce469a2016-11-08 21:54:34 +0800510 ci->i_truncate_seq, ci->i_truncate_size,
511 pages + page_idx, num_pages - page_idx,
512 ((page_align + read) & ~PAGE_MASK));
Sage Weil124e68e2009-10-06 11:31:08 -0700513 if (ret == -ENOENT)
514 ret = 0;
Yan, Zheng7ce469a2016-11-08 21:54:34 +0800515 hit_stripe = this_len < len;
Sage Weil0e987282011-06-07 20:40:35 -0700516 was_short = ret >= 0 && ret < this_len;
Yan, Zheng7ce469a2016-11-08 21:54:34 +0800517 dout("striped_read %llu~%llu (read %u) got %d%s%s\n", pos, len, read,
Sage Weil124e68e2009-10-06 11:31:08 -0700518 ret, hit_stripe ? " HITSTRIPE" : "", was_short ? " SHORT" : "");
519
Yan, Zheng99c88e62015-12-30 11:32:46 +0800520 i_size = i_size_read(inode);
majianpeng02ae66d2013-08-06 16:20:38 +0800521 if (ret >= 0) {
Yan, Zheng99c88e62015-12-30 11:32:46 +0800522 if (was_short && (pos + ret < i_size)) {
523 int zlen = min(this_len - ret, i_size - pos - ret);
Yan, Zheng7ce469a2016-11-08 21:54:34 +0800524 int zoff = page_align + read + ret;
majianpeng02ae66d2013-08-06 16:20:38 +0800525 dout(" zero gap %llu to %llu\n",
Yan, Zheng7ce469a2016-11-08 21:54:34 +0800526 pos + ret, pos + ret + zlen);
Yan, Zheng1487a682015-01-06 15:29:14 +0800527 ceph_zero_page_vector_range(zoff, zlen, pages);
528 ret += zlen;
Sage Weil124e68e2009-10-06 11:31:08 -0700529 }
majianpeng02ae66d2013-08-06 16:20:38 +0800530
Yan, Zheng7ce469a2016-11-08 21:54:34 +0800531 read += ret;
Sage Weil124e68e2009-10-06 11:31:08 -0700532 pos += ret;
Yan, Zheng7ce469a2016-11-08 21:54:34 +0800533 len -= ret;
Sage Weil124e68e2009-10-06 11:31:08 -0700534
majianpeng02ae66d2013-08-06 16:20:38 +0800535 /* hit stripe and need continue*/
Yan, Zheng7ce469a2016-11-08 21:54:34 +0800536 if (len && hit_stripe && pos < i_size)
Sage Weil124e68e2009-10-06 11:31:08 -0700537 goto more;
538 }
539
majianpengee7289b2013-08-21 15:02:51 +0800540 if (read > 0) {
majianpeng02ae66d2013-08-06 16:20:38 +0800541 ret = read;
Sage Weilc3cd6282011-06-01 16:08:44 -0700542 /* did we bounce off eof? */
Yan, Zheng7ce469a2016-11-08 21:54:34 +0800543 if (pos + len > i_size)
Yan, Zheng83701242014-11-14 22:36:18 +0800544 *checkeof = CHECK_EOF;
Sage Weil124e68e2009-10-06 11:31:08 -0700545 }
546
Sage Weil124e68e2009-10-06 11:31:08 -0700547 dout("striped_read returns %d\n", ret);
548 return ret;
549}
550
551/*
552 * Completely synchronous read and write methods. Direct from __user
553 * buffer to osd, or directly to user pages (if O_DIRECT).
554 *
555 * If the read spans object boundary, just do multiple reads.
556 */
Yan, Zheng7ce469a2016-11-08 21:54:34 +0800557static ssize_t ceph_sync_read(struct kiocb *iocb, struct iov_iter *to,
558 int *checkeof)
Sage Weil124e68e2009-10-06 11:31:08 -0700559{
majianpeng8eb4efb2013-09-26 14:42:17 +0800560 struct file *file = iocb->ki_filp;
Al Viro496ad9a2013-01-23 17:07:38 -0500561 struct inode *inode = file_inode(file);
Sage Weil124e68e2009-10-06 11:31:08 -0700562 struct page **pages;
majianpeng8eb4efb2013-09-26 14:42:17 +0800563 u64 off = iocb->ki_pos;
Yan, Zheng7ce469a2016-11-08 21:54:34 +0800564 int num_pages;
565 ssize_t ret;
566 size_t len = iov_iter_count(to);
Sage Weil124e68e2009-10-06 11:31:08 -0700567
majianpeng8eb4efb2013-09-26 14:42:17 +0800568 dout("sync_read on file %p %llu~%u %s\n", file, off,
569 (unsigned)len,
Sage Weil124e68e2009-10-06 11:31:08 -0700570 (file->f_flags & O_DIRECT) ? "O_DIRECT" : "");
Yan, Zhengd0d0db22014-07-21 10:15:48 +0800571
572 if (!len)
573 return 0;
Sage Weile98b6fe2010-11-09 12:24:53 -0800574 /*
575 * flush any page cache pages in this range. this
576 * will make concurrent normal and sync io slow,
577 * but it will at least behave sensibly when they are
578 * in sequence.
579 */
majianpeng8eb4efb2013-09-26 14:42:17 +0800580 ret = filemap_write_and_wait_range(inode->i_mapping, off,
581 off + len);
Yehuda Sadeh29065a52010-02-09 11:14:41 -0800582 if (ret < 0)
majianpeng8eb4efb2013-09-26 14:42:17 +0800583 return ret;
Yehuda Sadeh29065a52010-02-09 11:14:41 -0800584
Yan, Zheng7ce469a2016-11-08 21:54:34 +0800585 if (unlikely(to->type & ITER_PIPE)) {
586 size_t page_off;
587 ret = iov_iter_get_pages_alloc(to, &pages, len,
588 &page_off);
589 if (ret <= 0)
590 return -ENOMEM;
591 num_pages = DIV_ROUND_UP(ret + page_off, PAGE_SIZE);
Sage Weil124e68e2009-10-06 11:31:08 -0700592
Yan, Zheng7ce469a2016-11-08 21:54:34 +0800593 ret = striped_read(inode, off, ret, pages, num_pages,
594 page_off, checkeof);
595 if (ret > 0) {
596 iov_iter_advance(to, ret);
597 off += ret;
598 } else {
599 iov_iter_advance(to, 0);
majianpeng8eb4efb2013-09-26 14:42:17 +0800600 }
Yan, Zheng7ce469a2016-11-08 21:54:34 +0800601 ceph_put_page_vector(pages, num_pages, false);
602 } else {
603 num_pages = calc_pages_for(off, len);
604 pages = ceph_alloc_page_vector(num_pages, GFP_KERNEL);
605 if (IS_ERR(pages))
606 return PTR_ERR(pages);
607
608 ret = striped_read(inode, off, len, pages, num_pages,
609 (off & ~PAGE_MASK), checkeof);
610 if (ret > 0) {
611 int l, k = 0;
612 size_t left = ret;
613
614 while (left) {
615 size_t page_off = off & ~PAGE_MASK;
616 size_t copy = min_t(size_t, left,
617 PAGE_SIZE - page_off);
618 l = copy_page_to_iter(pages[k++], page_off,
619 copy, to);
620 off += l;
621 left -= l;
622 if (l < copy)
623 break;
624 }
625 }
626 ceph_release_page_vector(pages, num_pages);
majianpeng8eb4efb2013-09-26 14:42:17 +0800627 }
628
629 if (off > iocb->ki_pos) {
630 ret = off - iocb->ki_pos;
631 iocb->ki_pos = off;
632 }
633
Yan, Zheng7ce469a2016-11-08 21:54:34 +0800634 dout("sync_read result %zd\n", ret);
Sage Weil124e68e2009-10-06 11:31:08 -0700635 return ret;
636}
637
Yan, Zhengc8fe9b12015-12-23 21:23:38 +0800638struct ceph_aio_request {
639 struct kiocb *iocb;
640 size_t total_len;
641 int write;
642 int error;
643 struct list_head osd_reqs;
644 unsigned num_reqs;
645 atomic_t pending_reqs;
Yan, Zheng5be03892015-12-24 08:44:20 +0800646 struct timespec mtime;
Yan, Zhengc8fe9b12015-12-23 21:23:38 +0800647 struct ceph_cap_flush *prealloc_cf;
648};
649
Yan, Zheng5be03892015-12-24 08:44:20 +0800650struct ceph_aio_work {
651 struct work_struct work;
652 struct ceph_osd_request *req;
653};
654
655static void ceph_aio_retry_work(struct work_struct *work);
656
Yan, Zhengc8fe9b12015-12-23 21:23:38 +0800657static void ceph_aio_complete(struct inode *inode,
658 struct ceph_aio_request *aio_req)
659{
660 struct ceph_inode_info *ci = ceph_inode(inode);
661 int ret;
662
663 if (!atomic_dec_and_test(&aio_req->pending_reqs))
664 return;
665
666 ret = aio_req->error;
667 if (!ret)
668 ret = aio_req->total_len;
669
670 dout("ceph_aio_complete %p rc %d\n", inode, ret);
671
672 if (ret >= 0 && aio_req->write) {
673 int dirty;
674
675 loff_t endoff = aio_req->iocb->ki_pos + aio_req->total_len;
676 if (endoff > i_size_read(inode)) {
677 if (ceph_inode_set_size(inode, endoff))
678 ceph_check_caps(ci, CHECK_CAPS_AUTHONLY, NULL);
679 }
680
681 spin_lock(&ci->i_ceph_lock);
682 ci->i_inline_version = CEPH_INLINE_NONE;
683 dirty = __ceph_mark_dirty_caps(ci, CEPH_CAP_FILE_WR,
684 &aio_req->prealloc_cf);
685 spin_unlock(&ci->i_ceph_lock);
686 if (dirty)
687 __mark_inode_dirty(inode, dirty);
688
689 }
690
691 ceph_put_cap_refs(ci, (aio_req->write ? CEPH_CAP_FILE_WR :
692 CEPH_CAP_FILE_RD));
693
694 aio_req->iocb->ki_complete(aio_req->iocb, ret, 0);
695
696 ceph_free_cap_flush(aio_req->prealloc_cf);
697 kfree(aio_req);
698}
699
Ilya Dryomov85e084f2016-04-28 16:07:24 +0200700static void ceph_aio_complete_req(struct ceph_osd_request *req)
Yan, Zhengc8fe9b12015-12-23 21:23:38 +0800701{
702 int rc = req->r_result;
703 struct inode *inode = req->r_inode;
704 struct ceph_aio_request *aio_req = req->r_priv;
705 struct ceph_osd_data *osd_data = osd_req_op_extent_osd_data(req, 0);
706 int num_pages = calc_pages_for((u64)osd_data->alignment,
707 osd_data->length);
708
709 dout("ceph_aio_complete_req %p rc %d bytes %llu\n",
710 inode, rc, osd_data->length);
711
712 if (rc == -EOLDSNAPC) {
Yan, Zheng5be03892015-12-24 08:44:20 +0800713 struct ceph_aio_work *aio_work;
714 BUG_ON(!aio_req->write);
Yan, Zhengc8fe9b12015-12-23 21:23:38 +0800715
Yan, Zheng5be03892015-12-24 08:44:20 +0800716 aio_work = kmalloc(sizeof(*aio_work), GFP_NOFS);
717 if (aio_work) {
718 INIT_WORK(&aio_work->work, ceph_aio_retry_work);
719 aio_work->req = req;
720 queue_work(ceph_inode_to_client(inode)->wb_wq,
721 &aio_work->work);
722 return;
723 }
724 rc = -ENOMEM;
725 } else if (!aio_req->write) {
Yan, Zhengc8fe9b12015-12-23 21:23:38 +0800726 if (rc == -ENOENT)
727 rc = 0;
728 if (rc >= 0 && osd_data->length > rc) {
729 int zoff = osd_data->alignment + rc;
730 int zlen = osd_data->length - rc;
731 /*
732 * If read is satisfied by single OSD request,
733 * it can pass EOF. Otherwise read is within
734 * i_size.
735 */
736 if (aio_req->num_reqs == 1) {
737 loff_t i_size = i_size_read(inode);
738 loff_t endoff = aio_req->iocb->ki_pos + rc;
739 if (endoff < i_size)
740 zlen = min_t(size_t, zlen,
741 i_size - endoff);
742 aio_req->total_len = rc + zlen;
743 }
744
745 if (zlen > 0)
746 ceph_zero_page_vector_range(zoff, zlen,
747 osd_data->pages);
748 }
749 }
750
Yan, Zhenga22bd5f2016-05-26 10:30:13 +0800751 ceph_put_page_vector(osd_data->pages, num_pages, !aio_req->write);
Yan, Zhengc8fe9b12015-12-23 21:23:38 +0800752 ceph_osdc_put_request(req);
753
754 if (rc < 0)
755 cmpxchg(&aio_req->error, 0, rc);
756
757 ceph_aio_complete(inode, aio_req);
758 return;
759}
760
Yan, Zheng5be03892015-12-24 08:44:20 +0800761static void ceph_aio_retry_work(struct work_struct *work)
762{
763 struct ceph_aio_work *aio_work =
764 container_of(work, struct ceph_aio_work, work);
765 struct ceph_osd_request *orig_req = aio_work->req;
766 struct ceph_aio_request *aio_req = orig_req->r_priv;
767 struct inode *inode = orig_req->r_inode;
768 struct ceph_inode_info *ci = ceph_inode(inode);
769 struct ceph_snap_context *snapc;
770 struct ceph_osd_request *req;
771 int ret;
772
773 spin_lock(&ci->i_ceph_lock);
774 if (__ceph_have_pending_cap_snap(ci)) {
775 struct ceph_cap_snap *capsnap =
776 list_last_entry(&ci->i_cap_snaps,
777 struct ceph_cap_snap,
778 ci_item);
779 snapc = ceph_get_snap_context(capsnap->context);
780 } else {
781 BUG_ON(!ci->i_head_snapc);
782 snapc = ceph_get_snap_context(ci->i_head_snapc);
783 }
784 spin_unlock(&ci->i_ceph_lock);
785
786 req = ceph_osdc_alloc_request(orig_req->r_osdc, snapc, 2,
787 false, GFP_NOFS);
Dan Carpenter1418bf02016-01-26 12:24:44 +0300788 if (!req) {
789 ret = -ENOMEM;
Yan, Zheng5be03892015-12-24 08:44:20 +0800790 req = orig_req;
791 goto out;
792 }
793
Ilya Dryomov54ea0042017-02-11 18:48:41 +0100794 req->r_flags = CEPH_OSD_FLAG_ORDERSNAP | CEPH_OSD_FLAG_WRITE;
Ilya Dryomov63244fa2016-04-28 16:07:23 +0200795 ceph_oloc_copy(&req->r_base_oloc, &orig_req->r_base_oloc);
Ilya Dryomovd30291b2016-04-29 19:54:20 +0200796 ceph_oid_copy(&req->r_base_oid, &orig_req->r_base_oid);
Yan, Zheng5be03892015-12-24 08:44:20 +0800797
Ilya Dryomov13d1ad12016-04-27 14:15:51 +0200798 ret = ceph_osdc_alloc_messages(req, GFP_NOFS);
799 if (ret) {
800 ceph_osdc_put_request(req);
801 req = orig_req;
802 goto out;
803 }
Yan, Zheng5be03892015-12-24 08:44:20 +0800804
805 req->r_ops[0] = orig_req->r_ops[0];
806 osd_req_op_init(req, 1, CEPH_OSD_OP_STARTSYNC, 0);
807
Ilya Dryomovbb873b52016-05-26 00:29:52 +0200808 req->r_mtime = aio_req->mtime;
809 req->r_data_offset = req->r_ops[0].extent.offset;
Yan, Zheng5be03892015-12-24 08:44:20 +0800810
Yan, Zheng5be03892015-12-24 08:44:20 +0800811 ceph_osdc_put_request(orig_req);
812
813 req->r_callback = ceph_aio_complete_req;
814 req->r_inode = inode;
815 req->r_priv = aio_req;
Jeff Laytona1f40202017-04-04 08:39:37 -0400816 req->r_abort_on_full = true;
Yan, Zheng5be03892015-12-24 08:44:20 +0800817
818 ret = ceph_osdc_start_request(req->r_osdc, req, false);
819out:
820 if (ret < 0) {
Yan, Zheng5be03892015-12-24 08:44:20 +0800821 req->r_result = ret;
Ilya Dryomov85e084f2016-04-28 16:07:24 +0200822 ceph_aio_complete_req(req);
Yan, Zheng5be03892015-12-24 08:44:20 +0800823 }
824
Yan, Zhengdb6aed72016-01-26 23:05:37 +0800825 ceph_put_snap_context(snapc);
Yan, Zheng5be03892015-12-24 08:44:20 +0800826 kfree(aio_work);
827}
828
majianpenge8344e62013-09-12 13:54:26 +0800829static ssize_t
Yan, Zhengc8fe9b12015-12-23 21:23:38 +0800830ceph_direct_read_write(struct kiocb *iocb, struct iov_iter *iter,
831 struct ceph_snap_context *snapc,
832 struct ceph_cap_flush **pcf)
Sage Weil124e68e2009-10-06 11:31:08 -0700833{
majianpenge8344e62013-09-12 13:54:26 +0800834 struct file *file = iocb->ki_filp;
Al Viro496ad9a2013-01-23 17:07:38 -0500835 struct inode *inode = file_inode(file);
Sage Weil124e68e2009-10-06 11:31:08 -0700836 struct ceph_inode_info *ci = ceph_inode(inode);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700837 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
Alex Elderacead002013-03-14 14:09:05 -0500838 struct ceph_vino vino;
Sage Weil124e68e2009-10-06 11:31:08 -0700839 struct ceph_osd_request *req;
840 struct page **pages;
Yan, Zhengc8fe9b12015-12-23 21:23:38 +0800841 struct ceph_aio_request *aio_req = NULL;
842 int num_pages = 0;
Sage Weil124e68e2009-10-06 11:31:08 -0700843 int flags;
Sage Weil124e68e2009-10-06 11:31:08 -0700844 int ret;
Deepa Dinamanic2050a42016-09-14 07:48:06 -0700845 struct timespec mtime = current_time(inode);
Yan, Zhengc8fe9b12015-12-23 21:23:38 +0800846 size_t count = iov_iter_count(iter);
847 loff_t pos = iocb->ki_pos;
848 bool write = iov_iter_rw(iter) == WRITE;
Sage Weil124e68e2009-10-06 11:31:08 -0700849
Yan, Zhengc8fe9b12015-12-23 21:23:38 +0800850 if (write && ceph_snap(file_inode(file)) != CEPH_NOSNAP)
Sage Weil124e68e2009-10-06 11:31:08 -0700851 return -EROFS;
852
Yan, Zhengc8fe9b12015-12-23 21:23:38 +0800853 dout("sync_direct_read_write (%s) on file %p %lld~%u\n",
854 (write ? "write" : "read"), file, pos, (unsigned)count);
Sage Weil124e68e2009-10-06 11:31:08 -0700855
majianpenge8344e62013-09-12 13:54:26 +0800856 ret = filemap_write_and_wait_range(inode->i_mapping, pos, pos + count);
Yehuda Sadeh29065a52010-02-09 11:14:41 -0800857 if (ret < 0)
858 return ret;
859
Yan, Zhengc8fe9b12015-12-23 21:23:38 +0800860 if (write) {
NeilBrown5d7eb1a2016-09-01 22:26:23 +0800861 int ret2 = invalidate_inode_pages2_range(inode->i_mapping,
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +0300862 pos >> PAGE_SHIFT,
863 (pos + count) >> PAGE_SHIFT);
NeilBrown5d7eb1a2016-09-01 22:26:23 +0800864 if (ret2 < 0)
Zhi Zhanga380a032016-11-08 14:35:59 +0100865 dout("invalidate_inode_pages2_range returned %d\n", ret2);
Yehuda Sadeh29065a52010-02-09 11:14:41 -0800866
Ilya Dryomov54ea0042017-02-11 18:48:41 +0100867 flags = CEPH_OSD_FLAG_ORDERSNAP | CEPH_OSD_FLAG_WRITE;
Yan, Zhengc8fe9b12015-12-23 21:23:38 +0800868 } else {
869 flags = CEPH_OSD_FLAG_READ;
870 }
Sage Weil124e68e2009-10-06 11:31:08 -0700871
Yan, Zhengc8fe9b12015-12-23 21:23:38 +0800872 while (iov_iter_count(iter) > 0) {
873 u64 size = dio_get_pagev_size(iter);
874 size_t start = 0;
875 ssize_t len;
majianpenge8344e62013-09-12 13:54:26 +0800876
majianpenge8344e62013-09-12 13:54:26 +0800877 vino = ceph_vino(inode);
878 req = ceph_osdc_new_request(&fsc->client->osdc, &ci->i_layout,
Yan, Zhengc8fe9b12015-12-23 21:23:38 +0800879 vino, pos, &size, 0,
880 /*include a 'startsync' command*/
881 write ? 2 : 1,
882 write ? CEPH_OSD_OP_WRITE :
883 CEPH_OSD_OP_READ,
884 flags, snapc,
majianpenge8344e62013-09-12 13:54:26 +0800885 ci->i_truncate_seq,
886 ci->i_truncate_size,
887 false);
888 if (IS_ERR(req)) {
889 ret = PTR_ERR(req);
Al Viroeab87232014-04-03 22:44:19 -0400890 break;
majianpenge8344e62013-09-12 13:54:26 +0800891 }
892
Yan, Zhengc8fe9b12015-12-23 21:23:38 +0800893 len = size;
894 pages = dio_get_pages_alloc(iter, len, &start, &num_pages);
Zhu, Caifengb5b98989d2015-10-08 15:26:15 +0800895 if (IS_ERR(pages)) {
Al Viro64c31312014-04-03 22:58:25 -0400896 ceph_osdc_put_request(req);
Zhu, Caifengb5b98989d2015-10-08 15:26:15 +0800897 ret = PTR_ERR(pages);
Al Viro64c31312014-04-03 22:58:25 -0400898 break;
Sage Weil124e68e2009-10-06 11:31:08 -0700899 }
900
901 /*
Yan, Zhengc8fe9b12015-12-23 21:23:38 +0800902 * To simplify error handling, allow AIO when IO within i_size
903 * or IO can be satisfied by single OSD request.
Sage Weil124e68e2009-10-06 11:31:08 -0700904 */
Yan, Zhengc8fe9b12015-12-23 21:23:38 +0800905 if (pos == iocb->ki_pos && !is_sync_kiocb(iocb) &&
906 (len == count || pos + count <= i_size_read(inode))) {
907 aio_req = kzalloc(sizeof(*aio_req), GFP_KERNEL);
908 if (aio_req) {
909 aio_req->iocb = iocb;
910 aio_req->write = write;
911 INIT_LIST_HEAD(&aio_req->osd_reqs);
912 if (write) {
Yan, Zheng5be03892015-12-24 08:44:20 +0800913 aio_req->mtime = mtime;
Yan, Zhengc8fe9b12015-12-23 21:23:38 +0800914 swap(aio_req->prealloc_cf, *pcf);
915 }
916 }
917 /* ignore error */
918 }
majianpenge8344e62013-09-12 13:54:26 +0800919
Yan, Zhengc8fe9b12015-12-23 21:23:38 +0800920 if (write) {
921 /*
922 * throw out any page cache pages in this range. this
923 * may block.
924 */
925 truncate_inode_pages_range(inode->i_mapping, pos,
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +0300926 (pos+len) | (PAGE_SIZE - 1));
Yan, Zhengc8fe9b12015-12-23 21:23:38 +0800927
928 osd_req_op_init(req, 1, CEPH_OSD_OP_STARTSYNC, 0);
Ilya Dryomovbb873b52016-05-26 00:29:52 +0200929 req->r_mtime = mtime;
Yan, Zhengc8fe9b12015-12-23 21:23:38 +0800930 }
931
Yan, Zhengc8fe9b12015-12-23 21:23:38 +0800932 osd_req_op_extent_osd_data_pages(req, 0, pages, len, start,
933 false, false);
934
Yan, Zhengc8fe9b12015-12-23 21:23:38 +0800935 if (aio_req) {
936 aio_req->total_len += len;
937 aio_req->num_reqs++;
938 atomic_inc(&aio_req->pending_reqs);
939
940 req->r_callback = ceph_aio_complete_req;
941 req->r_inode = inode;
942 req->r_priv = aio_req;
943 list_add_tail(&req->r_unsafe_item, &aio_req->osd_reqs);
944
945 pos += len;
946 iov_iter_advance(iter, len);
947 continue;
948 }
949
950 ret = ceph_osdc_start_request(req->r_osdc, req, false);
majianpenge8344e62013-09-12 13:54:26 +0800951 if (!ret)
952 ret = ceph_osdc_wait_request(&fsc->client->osdc, req);
953
Yan, Zhengc8fe9b12015-12-23 21:23:38 +0800954 size = i_size_read(inode);
955 if (!write) {
956 if (ret == -ENOENT)
957 ret = 0;
958 if (ret >= 0 && ret < len && pos + ret < size) {
959 int zlen = min_t(size_t, len - ret,
960 size - pos - ret);
961 ceph_zero_page_vector_range(start + ret, zlen,
962 pages);
963 ret += zlen;
964 }
965 if (ret >= 0)
966 len = ret;
967 }
968
Yan, Zhenga22bd5f2016-05-26 10:30:13 +0800969 ceph_put_page_vector(pages, num_pages, !write);
majianpenge8344e62013-09-12 13:54:26 +0800970
majianpenge8344e62013-09-12 13:54:26 +0800971 ceph_osdc_put_request(req);
Yan, Zhengc8fe9b12015-12-23 21:23:38 +0800972 if (ret < 0)
majianpenge8344e62013-09-12 13:54:26 +0800973 break;
Al Viro64c31312014-04-03 22:58:25 -0400974
Yan, Zhengc8fe9b12015-12-23 21:23:38 +0800975 pos += len;
976 iov_iter_advance(iter, len);
977
978 if (!write && pos >= size)
979 break;
980
981 if (write && pos > size) {
982 if (ceph_inode_set_size(inode, pos))
Al Viro64c31312014-04-03 22:58:25 -0400983 ceph_check_caps(ceph_inode(inode),
984 CHECK_CAPS_AUTHONLY,
985 NULL);
986 }
majianpenge8344e62013-09-12 13:54:26 +0800987 }
988
Yan, Zhengc8fe9b12015-12-23 21:23:38 +0800989 if (aio_req) {
Yan, Zhengfc8c3892016-06-14 11:13:59 +0800990 LIST_HEAD(osd_reqs);
991
Yan, Zhengc8fe9b12015-12-23 21:23:38 +0800992 if (aio_req->num_reqs == 0) {
993 kfree(aio_req);
994 return ret;
995 }
996
997 ceph_get_cap_refs(ci, write ? CEPH_CAP_FILE_WR :
998 CEPH_CAP_FILE_RD);
999
Yan, Zhengfc8c3892016-06-14 11:13:59 +08001000 list_splice(&aio_req->osd_reqs, &osd_reqs);
1001 while (!list_empty(&osd_reqs)) {
1002 req = list_first_entry(&osd_reqs,
Yan, Zhengc8fe9b12015-12-23 21:23:38 +08001003 struct ceph_osd_request,
1004 r_unsafe_item);
1005 list_del_init(&req->r_unsafe_item);
1006 if (ret >= 0)
1007 ret = ceph_osdc_start_request(req->r_osdc,
1008 req, false);
1009 if (ret < 0) {
1010 req->r_result = ret;
Ilya Dryomov85e084f2016-04-28 16:07:24 +02001011 ceph_aio_complete_req(req);
Yan, Zhengc8fe9b12015-12-23 21:23:38 +08001012 }
1013 }
1014 return -EIOCBQUEUED;
1015 }
1016
1017 if (ret != -EOLDSNAPC && pos > iocb->ki_pos) {
1018 ret = pos - iocb->ki_pos;
majianpenge8344e62013-09-12 13:54:26 +08001019 iocb->ki_pos = pos;
majianpenge8344e62013-09-12 13:54:26 +08001020 }
1021 return ret;
1022}
1023
majianpenge8344e62013-09-12 13:54:26 +08001024/*
1025 * Synchronous write, straight from __user pointer or user pages.
1026 *
1027 * If write spans object boundary, just do multiple writes. (For a
1028 * correct atomic write, we should e.g. take write locks on all
1029 * objects, rollback on failure, etc.)
1030 */
Yan, Zheng06fee302014-07-28 14:33:46 +08001031static ssize_t
Yan, Zheng5dda377c2015-04-30 14:40:54 +08001032ceph_sync_write(struct kiocb *iocb, struct iov_iter *from, loff_t pos,
1033 struct ceph_snap_context *snapc)
majianpenge8344e62013-09-12 13:54:26 +08001034{
1035 struct file *file = iocb->ki_filp;
1036 struct inode *inode = file_inode(file);
1037 struct ceph_inode_info *ci = ceph_inode(inode);
1038 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
majianpenge8344e62013-09-12 13:54:26 +08001039 struct ceph_vino vino;
1040 struct ceph_osd_request *req;
1041 struct page **pages;
1042 u64 len;
1043 int num_pages;
1044 int written = 0;
1045 int flags;
1046 int check_caps = 0;
1047 int ret;
Deepa Dinamanic2050a42016-09-14 07:48:06 -07001048 struct timespec mtime = current_time(inode);
Al Viro4908b822014-04-03 23:09:01 -04001049 size_t count = iov_iter_count(from);
majianpenge8344e62013-09-12 13:54:26 +08001050
1051 if (ceph_snap(file_inode(file)) != CEPH_NOSNAP)
1052 return -EROFS;
1053
1054 dout("sync_write on file %p %lld~%u\n", file, pos, (unsigned)count);
1055
1056 ret = filemap_write_and_wait_range(inode->i_mapping, pos, pos + count);
1057 if (ret < 0)
1058 return ret;
1059
1060 ret = invalidate_inode_pages2_range(inode->i_mapping,
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +03001061 pos >> PAGE_SHIFT,
1062 (pos + count) >> PAGE_SHIFT);
majianpenge8344e62013-09-12 13:54:26 +08001063 if (ret < 0)
1064 dout("invalidate_inode_pages2_range returned %d\n", ret);
1065
Ilya Dryomov54ea0042017-02-11 18:48:41 +01001066 flags = CEPH_OSD_FLAG_ORDERSNAP | CEPH_OSD_FLAG_WRITE;
majianpenge8344e62013-09-12 13:54:26 +08001067
Al Viro4908b822014-04-03 23:09:01 -04001068 while ((len = iov_iter_count(from)) > 0) {
majianpenge8344e62013-09-12 13:54:26 +08001069 size_t left;
1070 int n;
1071
majianpenge8344e62013-09-12 13:54:26 +08001072 vino = ceph_vino(inode);
1073 req = ceph_osdc_new_request(&fsc->client->osdc, &ci->i_layout,
Yan, Zheng715e4cd2014-11-13 14:40:37 +08001074 vino, pos, &len, 0, 1,
majianpenge8344e62013-09-12 13:54:26 +08001075 CEPH_OSD_OP_WRITE, flags, snapc,
1076 ci->i_truncate_seq,
1077 ci->i_truncate_size,
1078 false);
1079 if (IS_ERR(req)) {
1080 ret = PTR_ERR(req);
Al Viroeab87232014-04-03 22:44:19 -04001081 break;
majianpenge8344e62013-09-12 13:54:26 +08001082 }
1083
1084 /*
1085 * write from beginning of first page,
1086 * regardless of io alignment
1087 */
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +03001088 num_pages = (len + PAGE_SIZE - 1) >> PAGE_SHIFT;
majianpenge8344e62013-09-12 13:54:26 +08001089
Yan, Zheng687265e2015-06-13 17:27:05 +08001090 pages = ceph_alloc_page_vector(num_pages, GFP_KERNEL);
Sage Weil124e68e2009-10-06 11:31:08 -07001091 if (IS_ERR(pages)) {
1092 ret = PTR_ERR(pages);
1093 goto out;
1094 }
majianpenge8344e62013-09-12 13:54:26 +08001095
1096 left = len;
1097 for (n = 0; n < num_pages; n++) {
Ilya Dryomov125d7252014-01-28 19:16:18 +02001098 size_t plen = min_t(size_t, left, PAGE_SIZE);
Al Viro4908b822014-04-03 23:09:01 -04001099 ret = copy_page_from_iter(pages[n], 0, plen, from);
majianpenge8344e62013-09-12 13:54:26 +08001100 if (ret != plen) {
1101 ret = -EFAULT;
1102 break;
1103 }
1104 left -= ret;
majianpenge8344e62013-09-12 13:54:26 +08001105 }
1106
Sage Weil124e68e2009-10-06 11:31:08 -07001107 if (ret < 0) {
1108 ceph_release_page_vector(pages, num_pages);
1109 goto out;
1110 }
1111
majianpenge8344e62013-09-12 13:54:26 +08001112 req->r_inode = inode;
Sage Weil124e68e2009-10-06 11:31:08 -07001113
majianpenge8344e62013-09-12 13:54:26 +08001114 osd_req_op_extent_osd_data_pages(req, 0, pages, len, 0,
1115 false, true);
Alex Elder02ee07d2013-03-14 14:09:06 -05001116
Ilya Dryomovbb873b52016-05-26 00:29:52 +02001117 req->r_mtime = mtime;
majianpenge8344e62013-09-12 13:54:26 +08001118 ret = ceph_osdc_start_request(&fsc->client->osdc, req, false);
1119 if (!ret)
1120 ret = ceph_osdc_wait_request(&fsc->client->osdc, req);
Sage Weil124e68e2009-10-06 11:31:08 -07001121
1122out:
majianpenge8344e62013-09-12 13:54:26 +08001123 ceph_osdc_put_request(req);
Jeff Layton26544c622017-04-04 08:39:46 -04001124 if (ret != 0) {
1125 ceph_set_error_write(ci);
majianpenge8344e62013-09-12 13:54:26 +08001126 break;
Jeff Layton26544c622017-04-04 08:39:46 -04001127 }
1128
1129 ceph_clear_error_write(ci);
1130 pos += len;
1131 written += len;
1132 if (pos > i_size_read(inode)) {
1133 check_caps = ceph_inode_set_size(inode, pos);
1134 if (check_caps)
1135 ceph_check_caps(ceph_inode(inode),
1136 CHECK_CAPS_AUTHONLY,
1137 NULL);
1138 }
1139
majianpenge8344e62013-09-12 13:54:26 +08001140 }
1141
1142 if (ret != -EOLDSNAPC && written > 0) {
Sage Weil124e68e2009-10-06 11:31:08 -07001143 ret = written;
majianpenge8344e62013-09-12 13:54:26 +08001144 iocb->ki_pos = pos;
Sage Weil124e68e2009-10-06 11:31:08 -07001145 }
1146 return ret;
1147}
1148
1149/*
1150 * Wrap generic_file_aio_read with checks for cap bits on the inode.
1151 * Atomically grab references, so that those bits are not released
1152 * back to the MDS mid-read.
1153 *
1154 * Hmm, the sync read case isn't actually async... should it be?
1155 */
Al Viro36444242014-04-02 20:28:01 -04001156static ssize_t ceph_read_iter(struct kiocb *iocb, struct iov_iter *to)
Sage Weil124e68e2009-10-06 11:31:08 -07001157{
1158 struct file *filp = iocb->ki_filp;
Sage Weil29625072010-05-27 10:40:43 -07001159 struct ceph_file_info *fi = filp->private_data;
Christoph Hellwig66ee59a2015-02-11 19:56:46 +01001160 size_t len = iov_iter_count(to);
Al Viro496ad9a2013-01-23 17:07:38 -05001161 struct inode *inode = file_inode(filp);
Sage Weil124e68e2009-10-06 11:31:08 -07001162 struct ceph_inode_info *ci = ceph_inode(inode);
Yan, Zheng3738daa2014-11-14 22:10:07 +08001163 struct page *pinned_page = NULL;
Sage Weil124e68e2009-10-06 11:31:08 -07001164 ssize_t ret;
Sage Weil29625072010-05-27 10:40:43 -07001165 int want, got = 0;
Yan, Zheng83701242014-11-14 22:36:18 +08001166 int retry_op = 0, read = 0;
Sage Weil124e68e2009-10-06 11:31:08 -07001167
Sage Weil6a026582010-02-09 14:04:02 -08001168again:
majianpeng8eb4efb2013-09-26 14:42:17 +08001169 dout("aio_read %p %llx.%llx %llu~%u trying to get caps on %p\n",
1170 inode, ceph_vinop(inode), iocb->ki_pos, (unsigned)len, inode);
1171
Sage Weil29625072010-05-27 10:40:43 -07001172 if (fi->fmode & CEPH_FILE_MODE_LAZY)
1173 want = CEPH_CAP_FILE_CACHE | CEPH_CAP_FILE_LAZYIO;
1174 else
1175 want = CEPH_CAP_FILE_CACHE;
Yan, Zheng3738daa2014-11-14 22:10:07 +08001176 ret = ceph_get_caps(ci, CEPH_CAP_FILE_RD, want, -1, &got, &pinned_page);
Sage Weil124e68e2009-10-06 11:31:08 -07001177 if (ret < 0)
majianpeng8eb4efb2013-09-26 14:42:17 +08001178 return ret;
Sage Weil124e68e2009-10-06 11:31:08 -07001179
Sage Weil29625072010-05-27 10:40:43 -07001180 if ((got & (CEPH_CAP_FILE_CACHE|CEPH_CAP_FILE_LAZYIO)) == 0 ||
Al Viro2ba48ce2015-04-09 13:52:01 -04001181 (iocb->ki_flags & IOCB_DIRECT) ||
majianpeng8eb4efb2013-09-26 14:42:17 +08001182 (fi->flags & CEPH_F_SYNC)) {
Sage Weil124e68e2009-10-06 11:31:08 -07001183
majianpeng8eb4efb2013-09-26 14:42:17 +08001184 dout("aio_sync_read %p %llx.%llx %llu~%u got cap refs on %s\n",
1185 inode, ceph_vinop(inode), iocb->ki_pos, (unsigned)len,
1186 ceph_cap_string(got));
1187
Yan, Zheng83701242014-11-14 22:36:18 +08001188 if (ci->i_inline_version == CEPH_INLINE_NONE) {
Yan, Zhengc8fe9b12015-12-23 21:23:38 +08001189 if (!retry_op && (iocb->ki_flags & IOCB_DIRECT)) {
1190 ret = ceph_direct_read_write(iocb, to,
1191 NULL, NULL);
1192 if (ret >= 0 && ret < len)
1193 retry_op = CHECK_EOF;
1194 } else {
1195 ret = ceph_sync_read(iocb, to, &retry_op);
1196 }
Yan, Zheng83701242014-11-14 22:36:18 +08001197 } else {
1198 retry_op = READ_INLINE;
1199 }
majianpeng8eb4efb2013-09-26 14:42:17 +08001200 } else {
majianpeng8eb4efb2013-09-26 14:42:17 +08001201 dout("aio_read %p %llx.%llx %llu~%u got cap refs on %s\n",
Al Viro36444242014-04-02 20:28:01 -04001202 inode, ceph_vinop(inode), iocb->ki_pos, (unsigned)len,
majianpeng8eb4efb2013-09-26 14:42:17 +08001203 ceph_cap_string(got));
Yan, Zheng2b1ac852016-10-25 10:51:55 +08001204 current->journal_info = filp;
Al Viro36444242014-04-02 20:28:01 -04001205 ret = generic_file_read_iter(iocb, to);
Yan, Zheng2b1ac852016-10-25 10:51:55 +08001206 current->journal_info = NULL;
majianpeng8eb4efb2013-09-26 14:42:17 +08001207 }
Sage Weil124e68e2009-10-06 11:31:08 -07001208 dout("aio_read %p %llx.%llx dropping cap refs on %s = %d\n",
1209 inode, ceph_vinop(inode), ceph_cap_string(got), (int)ret);
Yan, Zheng3738daa2014-11-14 22:10:07 +08001210 if (pinned_page) {
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +03001211 put_page(pinned_page);
Yan, Zheng3738daa2014-11-14 22:10:07 +08001212 pinned_page = NULL;
1213 }
Sage Weil124e68e2009-10-06 11:31:08 -07001214 ceph_put_cap_refs(ci, got);
Yan, Zhengc8fe9b12015-12-23 21:23:38 +08001215 if (retry_op > HAVE_RETRIED && ret >= 0) {
Yan, Zheng83701242014-11-14 22:36:18 +08001216 int statret;
1217 struct page *page = NULL;
1218 loff_t i_size;
1219 if (retry_op == READ_INLINE) {
Yan, Zheng687265e2015-06-13 17:27:05 +08001220 page = __page_cache_alloc(GFP_KERNEL);
Yan, Zheng83701242014-11-14 22:36:18 +08001221 if (!page)
1222 return -ENOMEM;
1223 }
Sage Weil6a026582010-02-09 14:04:02 -08001224
Yan, Zheng83701242014-11-14 22:36:18 +08001225 statret = __ceph_do_getattr(inode, page,
1226 CEPH_STAT_CAP_INLINE_DATA, !!page);
1227 if (statret < 0) {
Nikolay Borisov0d7718f62016-10-10 15:38:18 +03001228 if (page)
1229 __free_page(page);
Yan, Zheng83701242014-11-14 22:36:18 +08001230 if (statret == -ENODATA) {
1231 BUG_ON(retry_op != READ_INLINE);
1232 goto again;
1233 }
1234 return statret;
1235 }
1236
1237 i_size = i_size_read(inode);
1238 if (retry_op == READ_INLINE) {
Yan, Zhengfcc02d22015-01-10 11:43:12 +08001239 BUG_ON(ret > 0 || read > 0);
1240 if (iocb->ki_pos < i_size &&
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +03001241 iocb->ki_pos < PAGE_SIZE) {
Yan, Zheng83701242014-11-14 22:36:18 +08001242 loff_t end = min_t(loff_t, i_size,
1243 iocb->ki_pos + len);
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +03001244 end = min_t(loff_t, end, PAGE_SIZE);
Yan, Zheng83701242014-11-14 22:36:18 +08001245 if (statret < end)
1246 zero_user_segment(page, statret, end);
1247 ret = copy_page_to_iter(page,
1248 iocb->ki_pos & ~PAGE_MASK,
1249 end - iocb->ki_pos, to);
1250 iocb->ki_pos += ret;
Yan, Zhengfcc02d22015-01-10 11:43:12 +08001251 read += ret;
1252 }
1253 if (iocb->ki_pos < i_size && read < len) {
1254 size_t zlen = min_t(size_t, len - read,
1255 i_size - iocb->ki_pos);
1256 ret = iov_iter_zero(zlen, to);
1257 iocb->ki_pos += ret;
1258 read += ret;
Yan, Zheng83701242014-11-14 22:36:18 +08001259 }
1260 __free_pages(page, 0);
Yan, Zhengfcc02d22015-01-10 11:43:12 +08001261 return read;
Yan, Zheng83701242014-11-14 22:36:18 +08001262 }
Sage Weil6a026582010-02-09 14:04:02 -08001263
1264 /* hit EOF or hole? */
Yan, Zheng83701242014-11-14 22:36:18 +08001265 if (retry_op == CHECK_EOF && iocb->ki_pos < i_size &&
Yan, Zhengfcc02d22015-01-10 11:43:12 +08001266 ret < len) {
majianpeng8eb4efb2013-09-26 14:42:17 +08001267 dout("sync_read hit hole, ppos %lld < size %lld"
Yan, Zheng99c88e62015-12-30 11:32:46 +08001268 ", reading more\n", iocb->ki_pos, i_size);
majianpeng8eb4efb2013-09-26 14:42:17 +08001269
Sage Weil6a026582010-02-09 14:04:02 -08001270 read += ret;
Sage Weil6a026582010-02-09 14:04:02 -08001271 len -= ret;
Yan, Zhengc8fe9b12015-12-23 21:23:38 +08001272 retry_op = HAVE_RETRIED;
Sage Weil6a026582010-02-09 14:04:02 -08001273 goto again;
1274 }
1275 }
majianpeng8eb4efb2013-09-26 14:42:17 +08001276
Sage Weil6a026582010-02-09 14:04:02 -08001277 if (ret >= 0)
1278 ret += read;
1279
Sage Weil124e68e2009-10-06 11:31:08 -07001280 return ret;
1281}
1282
1283/*
1284 * Take cap references to avoid releasing caps to MDS mid-write.
1285 *
1286 * If we are synchronous, and write with an old snap context, the OSD
1287 * may return EOLDSNAPC. In that case, retry the write.. _after_
1288 * dropping our cap refs and allowing the pending snap to logically
1289 * complete _before_ this write occurs.
1290 *
1291 * If we are near ENOSPC, write synchronously.
1292 */
Al Viro4908b822014-04-03 23:09:01 -04001293static ssize_t ceph_write_iter(struct kiocb *iocb, struct iov_iter *from)
Sage Weil124e68e2009-10-06 11:31:08 -07001294{
1295 struct file *file = iocb->ki_filp;
Sage Weil33caad32010-05-26 14:31:27 -07001296 struct ceph_file_info *fi = file->private_data;
Al Viro496ad9a2013-01-23 17:07:38 -05001297 struct inode *inode = file_inode(file);
Sage Weil124e68e2009-10-06 11:31:08 -07001298 struct ceph_inode_info *ci = ceph_inode(inode);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001299 struct ceph_osd_client *osdc =
1300 &ceph_sb_to_client(inode->i_sb)->client->osdc;
Yan, Zhengf66fd9f2015-06-10 17:26:13 +08001301 struct ceph_cap_flush *prealloc_cf;
Al Viro3309dd02015-04-09 12:55:47 -04001302 ssize_t count, written = 0;
Yan, Zheng03d254e2013-04-12 16:11:13 +08001303 int err, want, got;
Al Viro3309dd02015-04-09 12:55:47 -04001304 loff_t pos;
Sage Weil124e68e2009-10-06 11:31:08 -07001305
1306 if (ceph_snap(inode) != CEPH_NOSNAP)
1307 return -EROFS;
1308
Yan, Zhengf66fd9f2015-06-10 17:26:13 +08001309 prealloc_cf = ceph_alloc_cap_flush();
1310 if (!prealloc_cf)
1311 return -ENOMEM;
1312
Al Viro59551022016-01-22 15:40:57 -05001313 inode_lock(inode);
Yan, Zheng03d254e2013-04-12 16:11:13 +08001314
Yan, Zheng03d254e2013-04-12 16:11:13 +08001315 /* We can write back this queue in page reclaim */
Christoph Hellwigde1414a2015-01-14 10:42:36 +01001316 current->backing_dev_info = inode_to_bdi(inode);
Yan, Zheng03d254e2013-04-12 16:11:13 +08001317
Yan, Zheng55b0b312015-09-07 11:35:01 +08001318 if (iocb->ki_flags & IOCB_APPEND) {
1319 err = ceph_do_getattr(inode, CEPH_STAT_CAP_SIZE, false);
1320 if (err < 0)
1321 goto out;
1322 }
1323
Al Viro3309dd02015-04-09 12:55:47 -04001324 err = generic_write_checks(iocb, from);
1325 if (err <= 0)
Yan, Zheng03d254e2013-04-12 16:11:13 +08001326 goto out;
1327
Al Viro3309dd02015-04-09 12:55:47 -04001328 pos = iocb->ki_pos;
1329 count = iov_iter_count(from);
Jan Kara5fa8e0a2015-05-21 16:05:53 +02001330 err = file_remove_privs(file);
Yan, Zheng03d254e2013-04-12 16:11:13 +08001331 if (err)
1332 goto out;
1333
1334 err = file_update_time(file);
1335 if (err)
1336 goto out;
1337
Yan, Zheng28127bd2014-11-14 22:38:29 +08001338 if (ci->i_inline_version != CEPH_INLINE_NONE) {
1339 err = ceph_uninline_data(file, NULL);
1340 if (err < 0)
1341 goto out;
1342 }
1343
Sage Weil124e68e2009-10-06 11:31:08 -07001344retry_snap:
Jeff Layton26544c622017-04-04 08:39:46 -04001345 /* FIXME: not complete since it doesn't account for being at quota */
Ilya Dryomovb7ec35b2016-04-28 16:07:25 +02001346 if (ceph_osdmap_flag(osdc, CEPH_OSDMAP_FULL)) {
Yan, Zheng03d254e2013-04-12 16:11:13 +08001347 err = -ENOSPC;
Yan, Zheng6070e0c2013-03-01 10:55:39 +08001348 goto out;
1349 }
Yan, Zheng03d254e2013-04-12 16:11:13 +08001350
Randy Dunlapac7f29b2013-04-19 14:20:07 -07001351 dout("aio_write %p %llx.%llx %llu~%zd getting caps. i_size %llu\n",
Yan, Zheng99c88e62015-12-30 11:32:46 +08001352 inode, ceph_vinop(inode), pos, count, i_size_read(inode));
Sage Weil7971bd92013-05-01 21:15:58 -07001353 if (fi->fmode & CEPH_FILE_MODE_LAZY)
1354 want = CEPH_CAP_FILE_BUFFER | CEPH_CAP_FILE_LAZYIO;
1355 else
1356 want = CEPH_CAP_FILE_BUFFER;
Yan, Zheng03d254e2013-04-12 16:11:13 +08001357 got = 0;
Yan, Zheng3738daa2014-11-14 22:10:07 +08001358 err = ceph_get_caps(ci, CEPH_CAP_FILE_WR, want, pos + count,
1359 &got, NULL);
Yan, Zheng03d254e2013-04-12 16:11:13 +08001360 if (err < 0)
Yan, Zheng37505d52013-04-12 16:11:10 +08001361 goto out;
Sage Weil124e68e2009-10-06 11:31:08 -07001362
Randy Dunlapac7f29b2013-04-19 14:20:07 -07001363 dout("aio_write %p %llx.%llx %llu~%zd got cap refs on %s\n",
Yan, Zheng03d254e2013-04-12 16:11:13 +08001364 inode, ceph_vinop(inode), pos, count, ceph_cap_string(got));
Sage Weil7971bd92013-05-01 21:15:58 -07001365
1366 if ((got & (CEPH_CAP_FILE_BUFFER|CEPH_CAP_FILE_LAZYIO)) == 0 ||
Jeff Layton26544c622017-04-04 08:39:46 -04001367 (iocb->ki_flags & IOCB_DIRECT) || (fi->flags & CEPH_F_SYNC) ||
1368 (ci->i_ceph_flags & CEPH_I_ERROR_WRITE)) {
Yan, Zheng5dda377c2015-04-30 14:40:54 +08001369 struct ceph_snap_context *snapc;
Al Viro4908b822014-04-03 23:09:01 -04001370 struct iov_iter data;
Al Viro59551022016-01-22 15:40:57 -05001371 inode_unlock(inode);
Yan, Zheng5dda377c2015-04-30 14:40:54 +08001372
1373 spin_lock(&ci->i_ceph_lock);
1374 if (__ceph_have_pending_cap_snap(ci)) {
1375 struct ceph_cap_snap *capsnap =
1376 list_last_entry(&ci->i_cap_snaps,
1377 struct ceph_cap_snap,
1378 ci_item);
1379 snapc = ceph_get_snap_context(capsnap->context);
1380 } else {
1381 BUG_ON(!ci->i_head_snapc);
1382 snapc = ceph_get_snap_context(ci->i_head_snapc);
1383 }
1384 spin_unlock(&ci->i_ceph_lock);
1385
Al Viro4908b822014-04-03 23:09:01 -04001386 /* we might need to revert back to that point */
1387 data = *from;
Al Viro2ba48ce2015-04-09 13:52:01 -04001388 if (iocb->ki_flags & IOCB_DIRECT)
Yan, Zhengc8fe9b12015-12-23 21:23:38 +08001389 written = ceph_direct_read_write(iocb, &data, snapc,
1390 &prealloc_cf);
majianpenge8344e62013-09-12 13:54:26 +08001391 else
Yan, Zheng5dda377c2015-04-30 14:40:54 +08001392 written = ceph_sync_write(iocb, &data, pos, snapc);
majianpeng0e5dd452013-08-08 15:32:19 +08001393 if (written == -EOLDSNAPC) {
1394 dout("aio_write %p %llx.%llx %llu~%u"
1395 "got EOLDSNAPC, retrying\n",
1396 inode, ceph_vinop(inode),
Al Viro4908b822014-04-03 23:09:01 -04001397 pos, (unsigned)count);
Al Viro59551022016-01-22 15:40:57 -05001398 inode_lock(inode);
majianpeng0e5dd452013-08-08 15:32:19 +08001399 goto retry_snap;
1400 }
Al Viro4908b822014-04-03 23:09:01 -04001401 if (written > 0)
1402 iov_iter_advance(from, written);
Yan, Zheng5dda377c2015-04-30 14:40:54 +08001403 ceph_put_snap_context(snapc);
Sage Weil7971bd92013-05-01 21:15:58 -07001404 } else {
Yan, Zhengb0d7c222013-08-12 21:42:15 -07001405 /*
1406 * No need to acquire the i_truncate_mutex. Because
1407 * the MDS revokes Fwb caps before sending truncate
1408 * message to us. We can't get Fwb cap while there
1409 * are pending vmtruncate. So write and vmtruncate
1410 * can not run at the same time
1411 */
Al Viro4908b822014-04-03 23:09:01 -04001412 written = generic_perform_write(file, from, pos);
Al Viroaec605f42014-02-11 22:28:43 -05001413 if (likely(written >= 0))
1414 iocb->ki_pos = pos + written;
Al Viro59551022016-01-22 15:40:57 -05001415 inode_unlock(inode);
Sage Weil124e68e2009-10-06 11:31:08 -07001416 }
Sage Weild8de9ab2011-07-26 11:27:34 -07001417
Yan, Zheng03d254e2013-04-12 16:11:13 +08001418 if (written >= 0) {
Sage Weilfca65b42011-05-04 11:33:47 -07001419 int dirty;
Sage Weilbe655592011-11-30 09:47:09 -08001420 spin_lock(&ci->i_ceph_lock);
Yan, Zheng28127bd2014-11-14 22:38:29 +08001421 ci->i_inline_version = CEPH_INLINE_NONE;
Yan, Zhengf66fd9f2015-06-10 17:26:13 +08001422 dirty = __ceph_mark_dirty_caps(ci, CEPH_CAP_FILE_WR,
1423 &prealloc_cf);
Sage Weilbe655592011-11-30 09:47:09 -08001424 spin_unlock(&ci->i_ceph_lock);
Sage Weilfca65b42011-05-04 11:33:47 -07001425 if (dirty)
1426 __mark_inode_dirty(inode, dirty);
Sage Weil124e68e2009-10-06 11:31:08 -07001427 }
Sage Weil7971bd92013-05-01 21:15:58 -07001428
Sage Weil124e68e2009-10-06 11:31:08 -07001429 dout("aio_write %p %llx.%llx %llu~%u dropping cap refs on %s\n",
Al Viro4908b822014-04-03 23:09:01 -04001430 inode, ceph_vinop(inode), pos, (unsigned)count,
Sage Weil7971bd92013-05-01 21:15:58 -07001431 ceph_cap_string(got));
Sage Weil124e68e2009-10-06 11:31:08 -07001432 ceph_put_cap_refs(ci, got);
Sage Weil7971bd92013-05-01 21:15:58 -07001433
Christoph Hellwig6aa657c2016-04-07 08:52:02 -07001434 if (written >= 0) {
Ilya Dryomovb7ec35b2016-04-28 16:07:25 +02001435 if (ceph_osdmap_flag(osdc, CEPH_OSDMAP_NEARFULL))
Christoph Hellwig6aa657c2016-04-07 08:52:02 -07001436 iocb->ki_flags |= IOCB_DSYNC;
1437
1438 written = generic_write_sync(iocb, written);
Yan, Zheng6070e0c2013-03-01 10:55:39 +08001439 }
Yan, Zheng03d254e2013-04-12 16:11:13 +08001440
Sage Weil2f75e9e2013-08-09 09:57:58 -07001441 goto out_unlocked;
Sage Weil124e68e2009-10-06 11:31:08 -07001442
Sage Weil2f75e9e2013-08-09 09:57:58 -07001443out:
Al Viro59551022016-01-22 15:40:57 -05001444 inode_unlock(inode);
Sage Weil2f75e9e2013-08-09 09:57:58 -07001445out_unlocked:
Yan, Zhengf66fd9f2015-06-10 17:26:13 +08001446 ceph_free_cap_flush(prealloc_cf);
Sage Weil2f75e9e2013-08-09 09:57:58 -07001447 current->backing_dev_info = NULL;
Yan, Zheng03d254e2013-04-12 16:11:13 +08001448 return written ? written : err;
Sage Weil124e68e2009-10-06 11:31:08 -07001449}
1450
1451/*
1452 * llseek. be sure to verify file size on SEEK_END.
1453 */
Andrew Morton965c8e52012-12-17 15:59:39 -08001454static loff_t ceph_llseek(struct file *file, loff_t offset, int whence)
Sage Weil124e68e2009-10-06 11:31:08 -07001455{
1456 struct inode *inode = file->f_mapping->host;
Yan, Zheng99c88e62015-12-30 11:32:46 +08001457 loff_t i_size;
Phil Turnbull955818c2016-07-21 13:43:09 -04001458 loff_t ret;
Sage Weil124e68e2009-10-06 11:31:08 -07001459
Al Viro59551022016-01-22 15:40:57 -05001460 inode_lock(inode);
Sage Weil6a82c472011-12-13 09:19:26 -08001461
Andrew Morton965c8e52012-12-17 15:59:39 -08001462 if (whence == SEEK_END || whence == SEEK_DATA || whence == SEEK_HOLE) {
Yan, Zheng508b32d2014-09-16 21:46:17 +08001463 ret = ceph_do_getattr(inode, CEPH_STAT_CAP_SIZE, false);
Phil Turnbull955818c2016-07-21 13:43:09 -04001464 if (ret < 0)
Sage Weil124e68e2009-10-06 11:31:08 -07001465 goto out;
Josef Bacik06222e42011-07-18 13:21:38 -04001466 }
1467
Yan, Zheng99c88e62015-12-30 11:32:46 +08001468 i_size = i_size_read(inode);
Andrew Morton965c8e52012-12-17 15:59:39 -08001469 switch (whence) {
Josef Bacik06222e42011-07-18 13:21:38 -04001470 case SEEK_END:
Yan, Zheng99c88e62015-12-30 11:32:46 +08001471 offset += i_size;
Sage Weil124e68e2009-10-06 11:31:08 -07001472 break;
1473 case SEEK_CUR:
1474 /*
1475 * Here we special-case the lseek(fd, 0, SEEK_CUR)
1476 * position-querying operation. Avoid rewriting the "same"
1477 * f_pos value back to the file because a concurrent read(),
1478 * write() or lseek() might have altered it
1479 */
1480 if (offset == 0) {
Phil Turnbull955818c2016-07-21 13:43:09 -04001481 ret = file->f_pos;
Sage Weil124e68e2009-10-06 11:31:08 -07001482 goto out;
1483 }
1484 offset += file->f_pos;
1485 break;
Josef Bacik06222e42011-07-18 13:21:38 -04001486 case SEEK_DATA:
Yan, Zheng99c88e62015-12-30 11:32:46 +08001487 if (offset >= i_size) {
Josef Bacik06222e42011-07-18 13:21:38 -04001488 ret = -ENXIO;
1489 goto out;
1490 }
1491 break;
1492 case SEEK_HOLE:
Yan, Zheng99c88e62015-12-30 11:32:46 +08001493 if (offset >= i_size) {
Josef Bacik06222e42011-07-18 13:21:38 -04001494 ret = -ENXIO;
1495 goto out;
1496 }
Yan, Zheng99c88e62015-12-30 11:32:46 +08001497 offset = i_size;
Josef Bacik06222e42011-07-18 13:21:38 -04001498 break;
Sage Weil124e68e2009-10-06 11:31:08 -07001499 }
1500
Phil Turnbull955818c2016-07-21 13:43:09 -04001501 ret = vfs_setpos(file, offset, inode->i_sb->s_maxbytes);
Sage Weil124e68e2009-10-06 11:31:08 -07001502
1503out:
Al Viro59551022016-01-22 15:40:57 -05001504 inode_unlock(inode);
Phil Turnbull955818c2016-07-21 13:43:09 -04001505 return ret;
Sage Weil124e68e2009-10-06 11:31:08 -07001506}
1507
Li Wangad7a60d2013-08-15 11:51:44 +08001508static inline void ceph_zero_partial_page(
1509 struct inode *inode, loff_t offset, unsigned size)
1510{
1511 struct page *page;
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +03001512 pgoff_t index = offset >> PAGE_SHIFT;
Li Wangad7a60d2013-08-15 11:51:44 +08001513
1514 page = find_lock_page(inode->i_mapping, index);
1515 if (page) {
1516 wait_on_page_writeback(page);
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +03001517 zero_user(page, offset & (PAGE_SIZE - 1), size);
Li Wangad7a60d2013-08-15 11:51:44 +08001518 unlock_page(page);
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +03001519 put_page(page);
Li Wangad7a60d2013-08-15 11:51:44 +08001520 }
1521}
1522
1523static void ceph_zero_pagecache_range(struct inode *inode, loff_t offset,
1524 loff_t length)
1525{
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +03001526 loff_t nearly = round_up(offset, PAGE_SIZE);
Li Wangad7a60d2013-08-15 11:51:44 +08001527 if (offset < nearly) {
1528 loff_t size = nearly - offset;
1529 if (length < size)
1530 size = length;
1531 ceph_zero_partial_page(inode, offset, size);
1532 offset += size;
1533 length -= size;
1534 }
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +03001535 if (length >= PAGE_SIZE) {
1536 loff_t size = round_down(length, PAGE_SIZE);
Li Wangad7a60d2013-08-15 11:51:44 +08001537 truncate_pagecache_range(inode, offset, offset + size - 1);
1538 offset += size;
1539 length -= size;
1540 }
1541 if (length)
1542 ceph_zero_partial_page(inode, offset, length);
1543}
1544
1545static int ceph_zero_partial_object(struct inode *inode,
1546 loff_t offset, loff_t *length)
1547{
1548 struct ceph_inode_info *ci = ceph_inode(inode);
1549 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
1550 struct ceph_osd_request *req;
1551 int ret = 0;
1552 loff_t zero = 0;
1553 int op;
1554
1555 if (!length) {
1556 op = offset ? CEPH_OSD_OP_DELETE : CEPH_OSD_OP_TRUNCATE;
1557 length = &zero;
1558 } else {
1559 op = CEPH_OSD_OP_ZERO;
1560 }
1561
1562 req = ceph_osdc_new_request(&fsc->client->osdc, &ci->i_layout,
1563 ceph_vino(inode),
1564 offset, length,
Yan, Zheng715e4cd2014-11-13 14:40:37 +08001565 0, 1, op,
Ilya Dryomov54ea0042017-02-11 18:48:41 +01001566 CEPH_OSD_FLAG_WRITE,
Li Wangad7a60d2013-08-15 11:51:44 +08001567 NULL, 0, 0, false);
1568 if (IS_ERR(req)) {
1569 ret = PTR_ERR(req);
1570 goto out;
1571 }
1572
Ilya Dryomovbb873b52016-05-26 00:29:52 +02001573 req->r_mtime = inode->i_mtime;
Li Wangad7a60d2013-08-15 11:51:44 +08001574 ret = ceph_osdc_start_request(&fsc->client->osdc, req, false);
1575 if (!ret) {
1576 ret = ceph_osdc_wait_request(&fsc->client->osdc, req);
1577 if (ret == -ENOENT)
1578 ret = 0;
1579 }
1580 ceph_osdc_put_request(req);
1581
1582out:
1583 return ret;
1584}
1585
1586static int ceph_zero_objects(struct inode *inode, loff_t offset, loff_t length)
1587{
1588 int ret = 0;
1589 struct ceph_inode_info *ci = ceph_inode(inode);
Yan, Zheng76271512016-02-03 21:24:49 +08001590 s32 stripe_unit = ci->i_layout.stripe_unit;
1591 s32 stripe_count = ci->i_layout.stripe_count;
1592 s32 object_size = ci->i_layout.object_size;
Sage Weilb314a902013-08-27 12:15:16 -07001593 u64 object_set_size = object_size * stripe_count;
1594 u64 nearly, t;
Li Wangad7a60d2013-08-15 11:51:44 +08001595
Sage Weilb314a902013-08-27 12:15:16 -07001596 /* round offset up to next period boundary */
1597 nearly = offset + object_set_size - 1;
1598 t = nearly;
1599 nearly -= do_div(t, object_set_size);
1600
Li Wangad7a60d2013-08-15 11:51:44 +08001601 while (length && offset < nearly) {
1602 loff_t size = length;
1603 ret = ceph_zero_partial_object(inode, offset, &size);
1604 if (ret < 0)
1605 return ret;
1606 offset += size;
1607 length -= size;
1608 }
1609 while (length >= object_set_size) {
1610 int i;
1611 loff_t pos = offset;
1612 for (i = 0; i < stripe_count; ++i) {
1613 ret = ceph_zero_partial_object(inode, pos, NULL);
1614 if (ret < 0)
1615 return ret;
1616 pos += stripe_unit;
1617 }
1618 offset += object_set_size;
1619 length -= object_set_size;
1620 }
1621 while (length) {
1622 loff_t size = length;
1623 ret = ceph_zero_partial_object(inode, offset, &size);
1624 if (ret < 0)
1625 return ret;
1626 offset += size;
1627 length -= size;
1628 }
1629 return ret;
1630}
1631
1632static long ceph_fallocate(struct file *file, int mode,
1633 loff_t offset, loff_t length)
1634{
1635 struct ceph_file_info *fi = file->private_data;
Libo Chenaa8b60e2013-12-11 13:49:11 +08001636 struct inode *inode = file_inode(file);
Li Wangad7a60d2013-08-15 11:51:44 +08001637 struct ceph_inode_info *ci = ceph_inode(inode);
1638 struct ceph_osd_client *osdc =
1639 &ceph_inode_to_client(inode)->client->osdc;
Yan, Zhengf66fd9f2015-06-10 17:26:13 +08001640 struct ceph_cap_flush *prealloc_cf;
Li Wangad7a60d2013-08-15 11:51:44 +08001641 int want, got = 0;
1642 int dirty;
1643 int ret = 0;
1644 loff_t endoff = 0;
1645 loff_t size;
1646
Yan, Zheng494d77b2014-06-26 15:25:17 +08001647 if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE))
1648 return -EOPNOTSUPP;
1649
Li Wangad7a60d2013-08-15 11:51:44 +08001650 if (!S_ISREG(inode->i_mode))
1651 return -EOPNOTSUPP;
1652
Yan, Zhengf66fd9f2015-06-10 17:26:13 +08001653 prealloc_cf = ceph_alloc_cap_flush();
1654 if (!prealloc_cf)
1655 return -ENOMEM;
1656
Al Viro59551022016-01-22 15:40:57 -05001657 inode_lock(inode);
Li Wangad7a60d2013-08-15 11:51:44 +08001658
1659 if (ceph_snap(inode) != CEPH_NOSNAP) {
1660 ret = -EROFS;
1661 goto unlock;
1662 }
1663
Ilya Dryomovb7ec35b2016-04-28 16:07:25 +02001664 if (ceph_osdmap_flag(osdc, CEPH_OSDMAP_FULL) &&
1665 !(mode & FALLOC_FL_PUNCH_HOLE)) {
Li Wangad7a60d2013-08-15 11:51:44 +08001666 ret = -ENOSPC;
1667 goto unlock;
1668 }
1669
Yan, Zheng28127bd2014-11-14 22:38:29 +08001670 if (ci->i_inline_version != CEPH_INLINE_NONE) {
1671 ret = ceph_uninline_data(file, NULL);
1672 if (ret < 0)
1673 goto unlock;
1674 }
1675
Li Wangad7a60d2013-08-15 11:51:44 +08001676 size = i_size_read(inode);
1677 if (!(mode & FALLOC_FL_KEEP_SIZE))
1678 endoff = offset + length;
1679
1680 if (fi->fmode & CEPH_FILE_MODE_LAZY)
1681 want = CEPH_CAP_FILE_BUFFER | CEPH_CAP_FILE_LAZYIO;
1682 else
1683 want = CEPH_CAP_FILE_BUFFER;
1684
Yan, Zheng3738daa2014-11-14 22:10:07 +08001685 ret = ceph_get_caps(ci, CEPH_CAP_FILE_WR, want, endoff, &got, NULL);
Li Wangad7a60d2013-08-15 11:51:44 +08001686 if (ret < 0)
1687 goto unlock;
1688
1689 if (mode & FALLOC_FL_PUNCH_HOLE) {
1690 if (offset < size)
1691 ceph_zero_pagecache_range(inode, offset, length);
1692 ret = ceph_zero_objects(inode, offset, length);
1693 } else if (endoff > size) {
1694 truncate_pagecache_range(inode, size, -1);
1695 if (ceph_inode_set_size(inode, endoff))
1696 ceph_check_caps(ceph_inode(inode),
1697 CHECK_CAPS_AUTHONLY, NULL);
1698 }
1699
1700 if (!ret) {
1701 spin_lock(&ci->i_ceph_lock);
Yan, Zheng28127bd2014-11-14 22:38:29 +08001702 ci->i_inline_version = CEPH_INLINE_NONE;
Yan, Zhengf66fd9f2015-06-10 17:26:13 +08001703 dirty = __ceph_mark_dirty_caps(ci, CEPH_CAP_FILE_WR,
1704 &prealloc_cf);
Li Wangad7a60d2013-08-15 11:51:44 +08001705 spin_unlock(&ci->i_ceph_lock);
1706 if (dirty)
1707 __mark_inode_dirty(inode, dirty);
1708 }
1709
1710 ceph_put_cap_refs(ci, got);
1711unlock:
Al Viro59551022016-01-22 15:40:57 -05001712 inode_unlock(inode);
Yan, Zhengf66fd9f2015-06-10 17:26:13 +08001713 ceph_free_cap_flush(prealloc_cf);
Li Wangad7a60d2013-08-15 11:51:44 +08001714 return ret;
1715}
1716
Sage Weil124e68e2009-10-06 11:31:08 -07001717const struct file_operations ceph_file_fops = {
1718 .open = ceph_open,
1719 .release = ceph_release,
1720 .llseek = ceph_llseek,
Al Viro36444242014-04-02 20:28:01 -04001721 .read_iter = ceph_read_iter,
Al Viro4908b822014-04-03 23:09:01 -04001722 .write_iter = ceph_write_iter,
Sage Weil124e68e2009-10-06 11:31:08 -07001723 .mmap = ceph_mmap,
1724 .fsync = ceph_fsync,
Greg Farnum40819f62010-08-02 15:34:23 -07001725 .lock = ceph_lock,
1726 .flock = ceph_flock,
Yan, Zheng7ce469a2016-11-08 21:54:34 +08001727 .splice_read = generic_file_splice_read,
Al Viro3551dd72014-04-05 04:40:12 -04001728 .splice_write = iter_file_splice_write,
Sage Weil124e68e2009-10-06 11:31:08 -07001729 .unlocked_ioctl = ceph_ioctl,
1730 .compat_ioctl = ceph_ioctl,
Li Wangad7a60d2013-08-15 11:51:44 +08001731 .fallocate = ceph_fallocate,
Sage Weil124e68e2009-10-06 11:31:08 -07001732};
1733