file.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252
  1. #include <linux/ceph/ceph_debug.h>
  2. #include <linux/module.h>
  3. #include <linux/sched.h>
  4. #include <linux/slab.h>
  5. #include <linux/file.h>
  6. #include <linux/mount.h>
  7. #include <linux/namei.h>
  8. #include <linux/writeback.h>
  9. #include <linux/aio.h>
  10. #include <linux/falloc.h>
  11. #include "super.h"
  12. #include "mds_client.h"
  13. #include "cache.h"
  14. /*
  15. * Ceph file operations
  16. *
  17. * Implement basic open/close functionality, and implement
  18. * read/write.
  19. *
  20. * We implement three modes of file I/O:
  21. * - buffered uses the generic_file_aio_{read,write} helpers
  22. *
  23. * - synchronous is used when there is multi-client read/write
  24. * sharing, avoids the page cache, and synchronously waits for an
  25. * ack from the OSD.
  26. *
  27. * - direct io takes the variant of the sync path that references
  28. * user pages directly.
  29. *
  30. * fsync() flushes and waits on dirty pages, but just queues metadata
  31. * for writeback: since the MDS can recover size and mtime there is no
  32. * need to wait for MDS acknowledgement.
  33. */
  34. /*
  35. * Prepare an open request. Preallocate ceph_cap to avoid an
  36. * inopportune ENOMEM later.
  37. */
  38. static struct ceph_mds_request *
  39. prepare_open_request(struct super_block *sb, int flags, int create_mode)
  40. {
  41. struct ceph_fs_client *fsc = ceph_sb_to_client(sb);
  42. struct ceph_mds_client *mdsc = fsc->mdsc;
  43. struct ceph_mds_request *req;
  44. int want_auth = USE_ANY_MDS;
  45. int op = (flags & O_CREAT) ? CEPH_MDS_OP_CREATE : CEPH_MDS_OP_OPEN;
  46. if (flags & (O_WRONLY|O_RDWR|O_CREAT|O_TRUNC))
  47. want_auth = USE_AUTH_MDS;
  48. req = ceph_mdsc_create_request(mdsc, op, want_auth);
  49. if (IS_ERR(req))
  50. goto out;
  51. req->r_fmode = ceph_flags_to_mode(flags);
  52. req->r_args.open.flags = cpu_to_le32(flags);
  53. req->r_args.open.mode = cpu_to_le32(create_mode);
  54. out:
  55. return req;
  56. }
  57. /*
  58. * initialize private struct file data.
  59. * if we fail, clean up by dropping fmode reference on the ceph_inode
  60. */
  61. static int ceph_init_file(struct inode *inode, struct file *file, int fmode)
  62. {
  63. struct ceph_file_info *cf;
  64. int ret = 0;
  65. struct ceph_inode_info *ci = ceph_inode(inode);
  66. struct ceph_fs_client *fsc = ceph_sb_to_client(inode->i_sb);
  67. struct ceph_mds_client *mdsc = fsc->mdsc;
  68. switch (inode->i_mode & S_IFMT) {
  69. case S_IFREG:
  70. /* First file open request creates the cookie, we want to keep
  71. * this cookie around for the filetime of the inode as not to
  72. * have to worry about fscache register / revoke / operation
  73. * races.
  74. *
  75. * Also, if we know the operation is going to invalidate data
  76. * (non readonly) just nuke the cache right away.
  77. */
  78. ceph_fscache_register_inode_cookie(mdsc->fsc, ci);
  79. if ((fmode & CEPH_FILE_MODE_WR))
  80. ceph_fscache_invalidate(inode);
  81. case S_IFDIR:
  82. dout("init_file %p %p 0%o (regular)\n", inode, file,
  83. inode->i_mode);
  84. cf = kmem_cache_alloc(ceph_file_cachep, GFP_NOFS | __GFP_ZERO);
  85. if (cf == NULL) {
  86. ceph_put_fmode(ceph_inode(inode), fmode); /* clean up */
  87. return -ENOMEM;
  88. }
  89. cf->fmode = fmode;
  90. cf->next_offset = 2;
  91. file->private_data = cf;
  92. BUG_ON(inode->i_fop->release != ceph_release);
  93. break;
  94. case S_IFLNK:
  95. dout("init_file %p %p 0%o (symlink)\n", inode, file,
  96. inode->i_mode);
  97. ceph_put_fmode(ceph_inode(inode), fmode); /* clean up */
  98. break;
  99. default:
  100. dout("init_file %p %p 0%o (special)\n", inode, file,
  101. inode->i_mode);
  102. /*
  103. * we need to drop the open ref now, since we don't
  104. * have .release set to ceph_release.
  105. */
  106. ceph_put_fmode(ceph_inode(inode), fmode); /* clean up */
  107. BUG_ON(inode->i_fop->release == ceph_release);
  108. /* call the proper open fop */
  109. ret = inode->i_fop->open(inode, file);
  110. }
  111. return ret;
  112. }
  113. /*
  114. * If we already have the requisite capabilities, we can satisfy
  115. * the open request locally (no need to request new caps from the
  116. * MDS). We do, however, need to inform the MDS (asynchronously)
  117. * if our wanted caps set expands.
  118. */
  119. int ceph_open(struct inode *inode, struct file *file)
  120. {
  121. struct ceph_inode_info *ci = ceph_inode(inode);
  122. struct ceph_fs_client *fsc = ceph_sb_to_client(inode->i_sb);
  123. struct ceph_mds_client *mdsc = fsc->mdsc;
  124. struct ceph_mds_request *req;
  125. struct ceph_file_info *cf = file->private_data;
  126. struct inode *parent_inode = NULL;
  127. int err;
  128. int flags, fmode, wanted;
  129. if (cf) {
  130. dout("open file %p is already opened\n", file);
  131. return 0;
  132. }
  133. /* filter out O_CREAT|O_EXCL; vfs did that already. yuck. */
  134. flags = file->f_flags & ~(O_CREAT|O_EXCL);
  135. if (S_ISDIR(inode->i_mode))
  136. flags = O_DIRECTORY; /* mds likes to know */
  137. dout("open inode %p ino %llx.%llx file %p flags %d (%d)\n", inode,
  138. ceph_vinop(inode), file, flags, file->f_flags);
  139. fmode = ceph_flags_to_mode(flags);
  140. wanted = ceph_caps_for_mode(fmode);
  141. /* snapped files are read-only */
  142. if (ceph_snap(inode) != CEPH_NOSNAP && (file->f_mode & FMODE_WRITE))
  143. return -EROFS;
  144. /* trivially open snapdir */
  145. if (ceph_snap(inode) == CEPH_SNAPDIR) {
  146. spin_lock(&ci->i_ceph_lock);
  147. __ceph_get_fmode(ci, fmode);
  148. spin_unlock(&ci->i_ceph_lock);
  149. return ceph_init_file(inode, file, fmode);
  150. }
  151. /*
  152. * No need to block if we have caps on the auth MDS (for
  153. * write) or any MDS (for read). Update wanted set
  154. * asynchronously.
  155. */
  156. spin_lock(&ci->i_ceph_lock);
  157. if (__ceph_is_any_real_caps(ci) &&
  158. (((fmode & CEPH_FILE_MODE_WR) == 0) || ci->i_auth_cap)) {
  159. int mds_wanted = __ceph_caps_mds_wanted(ci);
  160. int issued = __ceph_caps_issued(ci, NULL);
  161. dout("open %p fmode %d want %s issued %s using existing\n",
  162. inode, fmode, ceph_cap_string(wanted),
  163. ceph_cap_string(issued));
  164. __ceph_get_fmode(ci, fmode);
  165. spin_unlock(&ci->i_ceph_lock);
  166. /* adjust wanted? */
  167. if ((issued & wanted) != wanted &&
  168. (mds_wanted & wanted) != wanted &&
  169. ceph_snap(inode) != CEPH_SNAPDIR)
  170. ceph_check_caps(ci, 0, NULL);
  171. return ceph_init_file(inode, file, fmode);
  172. } else if (ceph_snap(inode) != CEPH_NOSNAP &&
  173. (ci->i_snap_caps & wanted) == wanted) {
  174. __ceph_get_fmode(ci, fmode);
  175. spin_unlock(&ci->i_ceph_lock);
  176. return ceph_init_file(inode, file, fmode);
  177. }
  178. spin_unlock(&ci->i_ceph_lock);
  179. dout("open fmode %d wants %s\n", fmode, ceph_cap_string(wanted));
  180. req = prepare_open_request(inode->i_sb, flags, 0);
  181. if (IS_ERR(req)) {
  182. err = PTR_ERR(req);
  183. goto out;
  184. }
  185. req->r_inode = inode;
  186. ihold(inode);
  187. req->r_num_caps = 1;
  188. if (flags & O_CREAT)
  189. parent_inode = ceph_get_dentry_parent_inode(file->f_dentry);
  190. err = ceph_mdsc_do_request(mdsc, parent_inode, req);
  191. iput(parent_inode);
  192. if (!err)
  193. err = ceph_init_file(inode, file, req->r_fmode);
  194. ceph_mdsc_put_request(req);
  195. dout("open result=%d on %llx.%llx\n", err, ceph_vinop(inode));
  196. out:
  197. return err;
  198. }
  199. /*
  200. * Do a lookup + open with a single request. If we get a non-existent
  201. * file or symlink, return 1 so the VFS can retry.
  202. */
  203. int ceph_atomic_open(struct inode *dir, struct dentry *dentry,
  204. struct file *file, unsigned flags, umode_t mode,
  205. int *opened)
  206. {
  207. struct ceph_fs_client *fsc = ceph_sb_to_client(dir->i_sb);
  208. struct ceph_mds_client *mdsc = fsc->mdsc;
  209. struct ceph_mds_request *req;
  210. struct dentry *dn;
  211. int err;
  212. dout("atomic_open %p dentry %p '%.*s' %s flags %d mode 0%o\n",
  213. dir, dentry, dentry->d_name.len, dentry->d_name.name,
  214. d_unhashed(dentry) ? "unhashed" : "hashed", flags, mode);
  215. if (dentry->d_name.len > NAME_MAX)
  216. return -ENAMETOOLONG;
  217. err = ceph_init_dentry(dentry);
  218. if (err < 0)
  219. return err;
  220. /* do the open */
  221. req = prepare_open_request(dir->i_sb, flags, mode);
  222. if (IS_ERR(req))
  223. return PTR_ERR(req);
  224. req->r_dentry = dget(dentry);
  225. req->r_num_caps = 2;
  226. if (flags & O_CREAT) {
  227. req->r_dentry_drop = CEPH_CAP_FILE_SHARED;
  228. req->r_dentry_unless = CEPH_CAP_FILE_EXCL;
  229. }
  230. req->r_locked_dir = dir; /* caller holds dir->i_mutex */
  231. err = ceph_mdsc_do_request(mdsc,
  232. (flags & (O_CREAT|O_TRUNC)) ? dir : NULL,
  233. req);
  234. if (err)
  235. goto out_err;
  236. err = ceph_handle_snapdir(req, dentry, err);
  237. if (err == 0 && (flags & O_CREAT) && !req->r_reply_info.head->is_dentry)
  238. err = ceph_handle_notrace_create(dir, dentry);
  239. if (d_unhashed(dentry)) {
  240. dn = ceph_finish_lookup(req, dentry, err);
  241. if (IS_ERR(dn))
  242. err = PTR_ERR(dn);
  243. } else {
  244. /* we were given a hashed negative dentry */
  245. dn = NULL;
  246. }
  247. if (err)
  248. goto out_err;
  249. if (dn || dentry->d_inode == NULL || S_ISLNK(dentry->d_inode->i_mode)) {
  250. /* make vfs retry on splice, ENOENT, or symlink */
  251. dout("atomic_open finish_no_open on dn %p\n", dn);
  252. err = finish_no_open(file, dn);
  253. } else {
  254. dout("atomic_open finish_open on dn %p\n", dn);
  255. if (req->r_op == CEPH_MDS_OP_CREATE && req->r_reply_info.has_create_ino) {
  256. ceph_init_acl(dentry, dentry->d_inode, dir);
  257. *opened |= FILE_CREATED;
  258. }
  259. err = finish_open(file, dentry, ceph_open, opened);
  260. }
  261. out_err:
  262. if (!req->r_err && req->r_target_inode)
  263. ceph_put_fmode(ceph_inode(req->r_target_inode), req->r_fmode);
  264. ceph_mdsc_put_request(req);
  265. dout("atomic_open result=%d\n", err);
  266. return err;
  267. }
  268. int ceph_release(struct inode *inode, struct file *file)
  269. {
  270. struct ceph_inode_info *ci = ceph_inode(inode);
  271. struct ceph_file_info *cf = file->private_data;
  272. dout("release inode %p file %p\n", inode, file);
  273. ceph_put_fmode(ci, cf->fmode);
  274. if (cf->last_readdir)
  275. ceph_mdsc_put_request(cf->last_readdir);
  276. kfree(cf->last_name);
  277. kfree(cf->dir_info);
  278. dput(cf->dentry);
  279. kmem_cache_free(ceph_file_cachep, cf);
  280. /* wake up anyone waiting for caps on this inode */
  281. wake_up_all(&ci->i_cap_wq);
  282. return 0;
  283. }
  284. /*
  285. * Read a range of bytes striped over one or more objects. Iterate over
  286. * objects we stripe over. (That's not atomic, but good enough for now.)
  287. *
  288. * If we get a short result from the OSD, check against i_size; we need to
  289. * only return a short read to the caller if we hit EOF.
  290. */
  291. static int striped_read(struct inode *inode,
  292. u64 off, u64 len,
  293. struct page **pages, int num_pages,
  294. int *checkeof, bool o_direct,
  295. unsigned long buf_align)
  296. {
  297. struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
  298. struct ceph_inode_info *ci = ceph_inode(inode);
  299. u64 pos, this_len, left;
  300. int io_align, page_align;
  301. int pages_left;
  302. int read;
  303. struct page **page_pos;
  304. int ret;
  305. bool hit_stripe, was_short;
  306. /*
  307. * we may need to do multiple reads. not atomic, unfortunately.
  308. */
  309. pos = off;
  310. left = len;
  311. page_pos = pages;
  312. pages_left = num_pages;
  313. read = 0;
  314. io_align = off & ~PAGE_MASK;
  315. more:
  316. if (o_direct)
  317. page_align = (pos - io_align + buf_align) & ~PAGE_MASK;
  318. else
  319. page_align = pos & ~PAGE_MASK;
  320. this_len = left;
  321. ret = ceph_osdc_readpages(&fsc->client->osdc, ceph_vino(inode),
  322. &ci->i_layout, pos, &this_len,
  323. ci->i_truncate_seq,
  324. ci->i_truncate_size,
  325. page_pos, pages_left, page_align);
  326. if (ret == -ENOENT)
  327. ret = 0;
  328. hit_stripe = this_len < left;
  329. was_short = ret >= 0 && ret < this_len;
  330. dout("striped_read %llu~%llu (read %u) got %d%s%s\n", pos, left, read,
  331. ret, hit_stripe ? " HITSTRIPE" : "", was_short ? " SHORT" : "");
  332. if (ret >= 0) {
  333. int didpages;
  334. if (was_short && (pos + ret < inode->i_size)) {
  335. u64 tmp = min(this_len - ret,
  336. inode->i_size - pos - ret);
  337. dout(" zero gap %llu to %llu\n",
  338. pos + ret, pos + ret + tmp);
  339. ceph_zero_page_vector_range(page_align + read + ret,
  340. tmp, pages);
  341. ret += tmp;
  342. }
  343. didpages = (page_align + ret) >> PAGE_CACHE_SHIFT;
  344. pos += ret;
  345. read = pos - off;
  346. left -= ret;
  347. page_pos += didpages;
  348. pages_left -= didpages;
  349. /* hit stripe and need continue*/
  350. if (left && hit_stripe && pos < inode->i_size)
  351. goto more;
  352. }
  353. if (read > 0) {
  354. ret = read;
  355. /* did we bounce off eof? */
  356. if (pos + left > inode->i_size)
  357. *checkeof = 1;
  358. }
  359. dout("striped_read returns %d\n", ret);
  360. return ret;
  361. }
  362. /*
  363. * Completely synchronous read and write methods. Direct from __user
  364. * buffer to osd, or directly to user pages (if O_DIRECT).
  365. *
  366. * If the read spans object boundary, just do multiple reads.
  367. */
  368. static ssize_t ceph_sync_read(struct kiocb *iocb, struct iov_iter *i,
  369. int *checkeof)
  370. {
  371. struct file *file = iocb->ki_filp;
  372. struct inode *inode = file_inode(file);
  373. struct page **pages;
  374. u64 off = iocb->ki_pos;
  375. int num_pages, ret;
  376. size_t len = iov_iter_count(i);
  377. dout("sync_read on file %p %llu~%u %s\n", file, off,
  378. (unsigned)len,
  379. (file->f_flags & O_DIRECT) ? "O_DIRECT" : "");
  380. /*
  381. * flush any page cache pages in this range. this
  382. * will make concurrent normal and sync io slow,
  383. * but it will at least behave sensibly when they are
  384. * in sequence.
  385. */
  386. ret = filemap_write_and_wait_range(inode->i_mapping, off,
  387. off + len);
  388. if (ret < 0)
  389. return ret;
  390. if (file->f_flags & O_DIRECT) {
  391. while (iov_iter_count(i)) {
  392. size_t start;
  393. ssize_t n;
  394. n = iov_iter_get_pages_alloc(i, &pages, INT_MAX, &start);
  395. if (n < 0)
  396. return n;
  397. num_pages = (n + start + PAGE_SIZE - 1) / PAGE_SIZE;
  398. ret = striped_read(inode, off, n,
  399. pages, num_pages, checkeof,
  400. 1, start);
  401. ceph_put_page_vector(pages, num_pages, true);
  402. if (ret <= 0)
  403. break;
  404. off += ret;
  405. iov_iter_advance(i, ret);
  406. if (ret < n)
  407. break;
  408. }
  409. } else {
  410. num_pages = calc_pages_for(off, len);
  411. pages = ceph_alloc_page_vector(num_pages, GFP_NOFS);
  412. if (IS_ERR(pages))
  413. return PTR_ERR(pages);
  414. ret = striped_read(inode, off, len, pages,
  415. num_pages, checkeof, 0, 0);
  416. if (ret > 0) {
  417. int l, k = 0;
  418. size_t left = ret;
  419. while (left) {
  420. int copy = min_t(size_t, PAGE_SIZE, left);
  421. l = copy_page_to_iter(pages[k++], 0, copy, i);
  422. off += l;
  423. left -= l;
  424. if (l < copy)
  425. break;
  426. }
  427. }
  428. ceph_release_page_vector(pages, num_pages);
  429. }
  430. if (off > iocb->ki_pos) {
  431. ret = off - iocb->ki_pos;
  432. iocb->ki_pos = off;
  433. }
  434. dout("sync_read result %d\n", ret);
  435. return ret;
  436. }
  437. /*
  438. * Write commit request unsafe callback, called to tell us when a
  439. * request is unsafe (that is, in flight--has been handed to the
  440. * messenger to send to its target osd). It is called again when
  441. * we've received a response message indicating the request is
  442. * "safe" (its CEPH_OSD_FLAG_ONDISK flag is set), or when a request
  443. * is completed early (and unsuccessfully) due to a timeout or
  444. * interrupt.
  445. *
  446. * This is used if we requested both an ACK and ONDISK commit reply
  447. * from the OSD.
  448. */
  449. static void ceph_sync_write_unsafe(struct ceph_osd_request *req, bool unsafe)
  450. {
  451. struct ceph_inode_info *ci = ceph_inode(req->r_inode);
  452. dout("%s %p tid %llu %ssafe\n", __func__, req, req->r_tid,
  453. unsafe ? "un" : "");
  454. if (unsafe) {
  455. ceph_get_cap_refs(ci, CEPH_CAP_FILE_WR);
  456. spin_lock(&ci->i_unsafe_lock);
  457. list_add_tail(&req->r_unsafe_item,
  458. &ci->i_unsafe_writes);
  459. spin_unlock(&ci->i_unsafe_lock);
  460. } else {
  461. spin_lock(&ci->i_unsafe_lock);
  462. list_del_init(&req->r_unsafe_item);
  463. spin_unlock(&ci->i_unsafe_lock);
  464. ceph_put_cap_refs(ci, CEPH_CAP_FILE_WR);
  465. }
  466. }
  467. /*
  468. * Synchronous write, straight from __user pointer or user pages.
  469. *
  470. * If write spans object boundary, just do multiple writes. (For a
  471. * correct atomic write, we should e.g. take write locks on all
  472. * objects, rollback on failure, etc.)
  473. */
  474. static ssize_t
  475. ceph_sync_direct_write(struct kiocb *iocb, struct iov_iter *from)
  476. {
  477. struct file *file = iocb->ki_filp;
  478. struct inode *inode = file_inode(file);
  479. struct ceph_inode_info *ci = ceph_inode(inode);
  480. struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
  481. struct ceph_snap_context *snapc;
  482. struct ceph_vino vino;
  483. struct ceph_osd_request *req;
  484. struct page **pages;
  485. int num_pages;
  486. int written = 0;
  487. int flags;
  488. int check_caps = 0;
  489. int ret;
  490. struct timespec mtime = CURRENT_TIME;
  491. loff_t pos = iocb->ki_pos;
  492. size_t count = iov_iter_count(from);
  493. if (ceph_snap(file_inode(file)) != CEPH_NOSNAP)
  494. return -EROFS;
  495. dout("sync_direct_write on file %p %lld~%u\n", file, pos,
  496. (unsigned)count);
  497. ret = filemap_write_and_wait_range(inode->i_mapping, pos, pos + count);
  498. if (ret < 0)
  499. return ret;
  500. ret = invalidate_inode_pages2_range(inode->i_mapping,
  501. pos >> PAGE_CACHE_SHIFT,
  502. (pos + count) >> PAGE_CACHE_SHIFT);
  503. if (ret < 0)
  504. dout("invalidate_inode_pages2_range returned %d\n", ret);
  505. flags = CEPH_OSD_FLAG_ORDERSNAP |
  506. CEPH_OSD_FLAG_ONDISK |
  507. CEPH_OSD_FLAG_WRITE;
  508. while (iov_iter_count(from) > 0) {
  509. u64 len = iov_iter_single_seg_count(from);
  510. size_t start;
  511. ssize_t n;
  512. snapc = ci->i_snap_realm->cached_context;
  513. vino = ceph_vino(inode);
  514. req = ceph_osdc_new_request(&fsc->client->osdc, &ci->i_layout,
  515. vino, pos, &len,
  516. 2,/*include a 'startsync' command*/
  517. CEPH_OSD_OP_WRITE, flags, snapc,
  518. ci->i_truncate_seq,
  519. ci->i_truncate_size,
  520. false);
  521. if (IS_ERR(req)) {
  522. ret = PTR_ERR(req);
  523. break;
  524. }
  525. n = iov_iter_get_pages_alloc(from, &pages, len, &start);
  526. if (unlikely(n < 0)) {
  527. ret = n;
  528. ceph_osdc_put_request(req);
  529. break;
  530. }
  531. num_pages = (n + start + PAGE_SIZE - 1) / PAGE_SIZE;
  532. /*
  533. * throw out any page cache pages in this range. this
  534. * may block.
  535. */
  536. truncate_inode_pages_range(inode->i_mapping, pos,
  537. (pos+n) | (PAGE_CACHE_SIZE-1));
  538. osd_req_op_extent_osd_data_pages(req, 0, pages, n, start,
  539. false, false);
  540. /* BUG_ON(vino.snap != CEPH_NOSNAP); */
  541. ceph_osdc_build_request(req, pos, snapc, vino.snap, &mtime);
  542. ret = ceph_osdc_start_request(&fsc->client->osdc, req, false);
  543. if (!ret)
  544. ret = ceph_osdc_wait_request(&fsc->client->osdc, req);
  545. ceph_put_page_vector(pages, num_pages, false);
  546. ceph_osdc_put_request(req);
  547. if (ret)
  548. break;
  549. pos += n;
  550. written += n;
  551. iov_iter_advance(from, n);
  552. if (pos > i_size_read(inode)) {
  553. check_caps = ceph_inode_set_size(inode, pos);
  554. if (check_caps)
  555. ceph_check_caps(ceph_inode(inode),
  556. CHECK_CAPS_AUTHONLY,
  557. NULL);
  558. }
  559. }
  560. if (ret != -EOLDSNAPC && written > 0) {
  561. iocb->ki_pos = pos;
  562. ret = written;
  563. }
  564. return ret;
  565. }
  566. /*
  567. * Synchronous write, straight from __user pointer or user pages.
  568. *
  569. * If write spans object boundary, just do multiple writes. (For a
  570. * correct atomic write, we should e.g. take write locks on all
  571. * objects, rollback on failure, etc.)
  572. */
  573. static ssize_t ceph_sync_write(struct kiocb *iocb, struct iov_iter *from)
  574. {
  575. struct file *file = iocb->ki_filp;
  576. struct inode *inode = file_inode(file);
  577. struct ceph_inode_info *ci = ceph_inode(inode);
  578. struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
  579. struct ceph_snap_context *snapc;
  580. struct ceph_vino vino;
  581. struct ceph_osd_request *req;
  582. struct page **pages;
  583. u64 len;
  584. int num_pages;
  585. int written = 0;
  586. int flags;
  587. int check_caps = 0;
  588. int ret;
  589. struct timespec mtime = CURRENT_TIME;
  590. loff_t pos = iocb->ki_pos;
  591. size_t count = iov_iter_count(from);
  592. if (ceph_snap(file_inode(file)) != CEPH_NOSNAP)
  593. return -EROFS;
  594. dout("sync_write on file %p %lld~%u\n", file, pos, (unsigned)count);
  595. ret = filemap_write_and_wait_range(inode->i_mapping, pos, pos + count);
  596. if (ret < 0)
  597. return ret;
  598. ret = invalidate_inode_pages2_range(inode->i_mapping,
  599. pos >> PAGE_CACHE_SHIFT,
  600. (pos + count) >> PAGE_CACHE_SHIFT);
  601. if (ret < 0)
  602. dout("invalidate_inode_pages2_range returned %d\n", ret);
  603. flags = CEPH_OSD_FLAG_ORDERSNAP |
  604. CEPH_OSD_FLAG_ONDISK |
  605. CEPH_OSD_FLAG_WRITE |
  606. CEPH_OSD_FLAG_ACK;
  607. while ((len = iov_iter_count(from)) > 0) {
  608. size_t left;
  609. int n;
  610. snapc = ci->i_snap_realm->cached_context;
  611. vino = ceph_vino(inode);
  612. req = ceph_osdc_new_request(&fsc->client->osdc, &ci->i_layout,
  613. vino, pos, &len, 1,
  614. CEPH_OSD_OP_WRITE, flags, snapc,
  615. ci->i_truncate_seq,
  616. ci->i_truncate_size,
  617. false);
  618. if (IS_ERR(req)) {
  619. ret = PTR_ERR(req);
  620. break;
  621. }
  622. /*
  623. * write from beginning of first page,
  624. * regardless of io alignment
  625. */
  626. num_pages = (len + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
  627. pages = ceph_alloc_page_vector(num_pages, GFP_NOFS);
  628. if (IS_ERR(pages)) {
  629. ret = PTR_ERR(pages);
  630. goto out;
  631. }
  632. left = len;
  633. for (n = 0; n < num_pages; n++) {
  634. size_t plen = min_t(size_t, left, PAGE_SIZE);
  635. ret = copy_page_from_iter(pages[n], 0, plen, from);
  636. if (ret != plen) {
  637. ret = -EFAULT;
  638. break;
  639. }
  640. left -= ret;
  641. }
  642. if (ret < 0) {
  643. ceph_release_page_vector(pages, num_pages);
  644. goto out;
  645. }
  646. /* get a second commit callback */
  647. req->r_unsafe_callback = ceph_sync_write_unsafe;
  648. req->r_inode = inode;
  649. osd_req_op_extent_osd_data_pages(req, 0, pages, len, 0,
  650. false, true);
  651. /* BUG_ON(vino.snap != CEPH_NOSNAP); */
  652. ceph_osdc_build_request(req, pos, snapc, vino.snap, &mtime);
  653. ret = ceph_osdc_start_request(&fsc->client->osdc, req, false);
  654. if (!ret)
  655. ret = ceph_osdc_wait_request(&fsc->client->osdc, req);
  656. out:
  657. ceph_osdc_put_request(req);
  658. if (ret == 0) {
  659. pos += len;
  660. written += len;
  661. if (pos > i_size_read(inode)) {
  662. check_caps = ceph_inode_set_size(inode, pos);
  663. if (check_caps)
  664. ceph_check_caps(ceph_inode(inode),
  665. CHECK_CAPS_AUTHONLY,
  666. NULL);
  667. }
  668. } else
  669. break;
  670. }
  671. if (ret != -EOLDSNAPC && written > 0) {
  672. ret = written;
  673. iocb->ki_pos = pos;
  674. }
  675. return ret;
  676. }
  677. /*
  678. * Wrap generic_file_aio_read with checks for cap bits on the inode.
  679. * Atomically grab references, so that those bits are not released
  680. * back to the MDS mid-read.
  681. *
  682. * Hmm, the sync read case isn't actually async... should it be?
  683. */
  684. static ssize_t ceph_read_iter(struct kiocb *iocb, struct iov_iter *to)
  685. {
  686. struct file *filp = iocb->ki_filp;
  687. struct ceph_file_info *fi = filp->private_data;
  688. size_t len = iocb->ki_nbytes;
  689. struct inode *inode = file_inode(filp);
  690. struct ceph_inode_info *ci = ceph_inode(inode);
  691. ssize_t ret;
  692. int want, got = 0;
  693. int checkeof = 0, read = 0;
  694. again:
  695. dout("aio_read %p %llx.%llx %llu~%u trying to get caps on %p\n",
  696. inode, ceph_vinop(inode), iocb->ki_pos, (unsigned)len, inode);
  697. if (fi->fmode & CEPH_FILE_MODE_LAZY)
  698. want = CEPH_CAP_FILE_CACHE | CEPH_CAP_FILE_LAZYIO;
  699. else
  700. want = CEPH_CAP_FILE_CACHE;
  701. ret = ceph_get_caps(ci, CEPH_CAP_FILE_RD, want, &got, -1);
  702. if (ret < 0)
  703. return ret;
  704. if ((got & (CEPH_CAP_FILE_CACHE|CEPH_CAP_FILE_LAZYIO)) == 0 ||
  705. (iocb->ki_filp->f_flags & O_DIRECT) ||
  706. (fi->flags & CEPH_F_SYNC)) {
  707. dout("aio_sync_read %p %llx.%llx %llu~%u got cap refs on %s\n",
  708. inode, ceph_vinop(inode), iocb->ki_pos, (unsigned)len,
  709. ceph_cap_string(got));
  710. /* hmm, this isn't really async... */
  711. ret = ceph_sync_read(iocb, to, &checkeof);
  712. } else {
  713. dout("aio_read %p %llx.%llx %llu~%u got cap refs on %s\n",
  714. inode, ceph_vinop(inode), iocb->ki_pos, (unsigned)len,
  715. ceph_cap_string(got));
  716. ret = generic_file_read_iter(iocb, to);
  717. }
  718. dout("aio_read %p %llx.%llx dropping cap refs on %s = %d\n",
  719. inode, ceph_vinop(inode), ceph_cap_string(got), (int)ret);
  720. ceph_put_cap_refs(ci, got);
  721. if (checkeof && ret >= 0) {
  722. int statret = ceph_do_getattr(inode,
  723. CEPH_STAT_CAP_SIZE);
  724. /* hit EOF or hole? */
  725. if (statret == 0 && iocb->ki_pos < inode->i_size &&
  726. ret < len) {
  727. dout("sync_read hit hole, ppos %lld < size %lld"
  728. ", reading more\n", iocb->ki_pos,
  729. inode->i_size);
  730. iov_iter_advance(to, ret);
  731. read += ret;
  732. len -= ret;
  733. checkeof = 0;
  734. goto again;
  735. }
  736. }
  737. if (ret >= 0)
  738. ret += read;
  739. return ret;
  740. }
  741. /*
  742. * Take cap references to avoid releasing caps to MDS mid-write.
  743. *
  744. * If we are synchronous, and write with an old snap context, the OSD
  745. * may return EOLDSNAPC. In that case, retry the write.. _after_
  746. * dropping our cap refs and allowing the pending snap to logically
  747. * complete _before_ this write occurs.
  748. *
  749. * If we are near ENOSPC, write synchronously.
  750. */
  751. static ssize_t ceph_write_iter(struct kiocb *iocb, struct iov_iter *from)
  752. {
  753. struct file *file = iocb->ki_filp;
  754. struct ceph_file_info *fi = file->private_data;
  755. struct inode *inode = file_inode(file);
  756. struct ceph_inode_info *ci = ceph_inode(inode);
  757. struct ceph_osd_client *osdc =
  758. &ceph_sb_to_client(inode->i_sb)->client->osdc;
  759. ssize_t count = iov_iter_count(from), written = 0;
  760. int err, want, got;
  761. loff_t pos = iocb->ki_pos;
  762. if (ceph_snap(inode) != CEPH_NOSNAP)
  763. return -EROFS;
  764. mutex_lock(&inode->i_mutex);
  765. /* We can write back this queue in page reclaim */
  766. current->backing_dev_info = file->f_mapping->backing_dev_info;
  767. err = generic_write_checks(file, &pos, &count, S_ISBLK(inode->i_mode));
  768. if (err)
  769. goto out;
  770. if (count == 0)
  771. goto out;
  772. iov_iter_truncate(from, count);
  773. err = file_remove_suid(file);
  774. if (err)
  775. goto out;
  776. err = file_update_time(file);
  777. if (err)
  778. goto out;
  779. retry_snap:
  780. if (ceph_osdmap_flag(osdc->osdmap, CEPH_OSDMAP_FULL)) {
  781. err = -ENOSPC;
  782. goto out;
  783. }
  784. dout("aio_write %p %llx.%llx %llu~%zd getting caps. i_size %llu\n",
  785. inode, ceph_vinop(inode), pos, count, inode->i_size);
  786. if (fi->fmode & CEPH_FILE_MODE_LAZY)
  787. want = CEPH_CAP_FILE_BUFFER | CEPH_CAP_FILE_LAZYIO;
  788. else
  789. want = CEPH_CAP_FILE_BUFFER;
  790. got = 0;
  791. err = ceph_get_caps(ci, CEPH_CAP_FILE_WR, want, &got, pos + count);
  792. if (err < 0)
  793. goto out;
  794. dout("aio_write %p %llx.%llx %llu~%zd got cap refs on %s\n",
  795. inode, ceph_vinop(inode), pos, count, ceph_cap_string(got));
  796. if ((got & (CEPH_CAP_FILE_BUFFER|CEPH_CAP_FILE_LAZYIO)) == 0 ||
  797. (file->f_flags & O_DIRECT) || (fi->flags & CEPH_F_SYNC)) {
  798. struct iov_iter data;
  799. mutex_unlock(&inode->i_mutex);
  800. /* we might need to revert back to that point */
  801. data = *from;
  802. if (file->f_flags & O_DIRECT)
  803. written = ceph_sync_direct_write(iocb, &data);
  804. else
  805. written = ceph_sync_write(iocb, &data);
  806. if (written == -EOLDSNAPC) {
  807. dout("aio_write %p %llx.%llx %llu~%u"
  808. "got EOLDSNAPC, retrying\n",
  809. inode, ceph_vinop(inode),
  810. pos, (unsigned)count);
  811. mutex_lock(&inode->i_mutex);
  812. goto retry_snap;
  813. }
  814. if (written > 0)
  815. iov_iter_advance(from, written);
  816. } else {
  817. loff_t old_size = inode->i_size;
  818. /*
  819. * No need to acquire the i_truncate_mutex. Because
  820. * the MDS revokes Fwb caps before sending truncate
  821. * message to us. We can't get Fwb cap while there
  822. * are pending vmtruncate. So write and vmtruncate
  823. * can not run at the same time
  824. */
  825. written = generic_perform_write(file, from, pos);
  826. if (likely(written >= 0))
  827. iocb->ki_pos = pos + written;
  828. if (inode->i_size > old_size)
  829. ceph_fscache_update_objectsize(inode);
  830. mutex_unlock(&inode->i_mutex);
  831. }
  832. if (written >= 0) {
  833. int dirty;
  834. spin_lock(&ci->i_ceph_lock);
  835. dirty = __ceph_mark_dirty_caps(ci, CEPH_CAP_FILE_WR);
  836. spin_unlock(&ci->i_ceph_lock);
  837. if (dirty)
  838. __mark_inode_dirty(inode, dirty);
  839. }
  840. dout("aio_write %p %llx.%llx %llu~%u dropping cap refs on %s\n",
  841. inode, ceph_vinop(inode), pos, (unsigned)count,
  842. ceph_cap_string(got));
  843. ceph_put_cap_refs(ci, got);
  844. if (written >= 0 &&
  845. ((file->f_flags & O_SYNC) || IS_SYNC(file->f_mapping->host) ||
  846. ceph_osdmap_flag(osdc->osdmap, CEPH_OSDMAP_NEARFULL))) {
  847. err = vfs_fsync_range(file, pos, pos + written - 1, 1);
  848. if (err < 0)
  849. written = err;
  850. }
  851. goto out_unlocked;
  852. out:
  853. mutex_unlock(&inode->i_mutex);
  854. out_unlocked:
  855. current->backing_dev_info = NULL;
  856. return written ? written : err;
  857. }
  858. /*
  859. * llseek. be sure to verify file size on SEEK_END.
  860. */
  861. static loff_t ceph_llseek(struct file *file, loff_t offset, int whence)
  862. {
  863. struct inode *inode = file->f_mapping->host;
  864. int ret;
  865. mutex_lock(&inode->i_mutex);
  866. if (whence == SEEK_END || whence == SEEK_DATA || whence == SEEK_HOLE) {
  867. ret = ceph_do_getattr(inode, CEPH_STAT_CAP_SIZE);
  868. if (ret < 0) {
  869. offset = ret;
  870. goto out;
  871. }
  872. }
  873. switch (whence) {
  874. case SEEK_END:
  875. offset += inode->i_size;
  876. break;
  877. case SEEK_CUR:
  878. /*
  879. * Here we special-case the lseek(fd, 0, SEEK_CUR)
  880. * position-querying operation. Avoid rewriting the "same"
  881. * f_pos value back to the file because a concurrent read(),
  882. * write() or lseek() might have altered it
  883. */
  884. if (offset == 0) {
  885. offset = file->f_pos;
  886. goto out;
  887. }
  888. offset += file->f_pos;
  889. break;
  890. case SEEK_DATA:
  891. if (offset >= inode->i_size) {
  892. ret = -ENXIO;
  893. goto out;
  894. }
  895. break;
  896. case SEEK_HOLE:
  897. if (offset >= inode->i_size) {
  898. ret = -ENXIO;
  899. goto out;
  900. }
  901. offset = inode->i_size;
  902. break;
  903. }
  904. offset = vfs_setpos(file, offset, inode->i_sb->s_maxbytes);
  905. out:
  906. mutex_unlock(&inode->i_mutex);
  907. return offset;
  908. }
  909. static inline void ceph_zero_partial_page(
  910. struct inode *inode, loff_t offset, unsigned size)
  911. {
  912. struct page *page;
  913. pgoff_t index = offset >> PAGE_CACHE_SHIFT;
  914. page = find_lock_page(inode->i_mapping, index);
  915. if (page) {
  916. wait_on_page_writeback(page);
  917. zero_user(page, offset & (PAGE_CACHE_SIZE - 1), size);
  918. unlock_page(page);
  919. page_cache_release(page);
  920. }
  921. }
  922. static void ceph_zero_pagecache_range(struct inode *inode, loff_t offset,
  923. loff_t length)
  924. {
  925. loff_t nearly = round_up(offset, PAGE_CACHE_SIZE);
  926. if (offset < nearly) {
  927. loff_t size = nearly - offset;
  928. if (length < size)
  929. size = length;
  930. ceph_zero_partial_page(inode, offset, size);
  931. offset += size;
  932. length -= size;
  933. }
  934. if (length >= PAGE_CACHE_SIZE) {
  935. loff_t size = round_down(length, PAGE_CACHE_SIZE);
  936. truncate_pagecache_range(inode, offset, offset + size - 1);
  937. offset += size;
  938. length -= size;
  939. }
  940. if (length)
  941. ceph_zero_partial_page(inode, offset, length);
  942. }
  943. static int ceph_zero_partial_object(struct inode *inode,
  944. loff_t offset, loff_t *length)
  945. {
  946. struct ceph_inode_info *ci = ceph_inode(inode);
  947. struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
  948. struct ceph_osd_request *req;
  949. int ret = 0;
  950. loff_t zero = 0;
  951. int op;
  952. if (!length) {
  953. op = offset ? CEPH_OSD_OP_DELETE : CEPH_OSD_OP_TRUNCATE;
  954. length = &zero;
  955. } else {
  956. op = CEPH_OSD_OP_ZERO;
  957. }
  958. req = ceph_osdc_new_request(&fsc->client->osdc, &ci->i_layout,
  959. ceph_vino(inode),
  960. offset, length,
  961. 1, op,
  962. CEPH_OSD_FLAG_WRITE |
  963. CEPH_OSD_FLAG_ONDISK,
  964. NULL, 0, 0, false);
  965. if (IS_ERR(req)) {
  966. ret = PTR_ERR(req);
  967. goto out;
  968. }
  969. ceph_osdc_build_request(req, offset, NULL, ceph_vino(inode).snap,
  970. &inode->i_mtime);
  971. ret = ceph_osdc_start_request(&fsc->client->osdc, req, false);
  972. if (!ret) {
  973. ret = ceph_osdc_wait_request(&fsc->client->osdc, req);
  974. if (ret == -ENOENT)
  975. ret = 0;
  976. }
  977. ceph_osdc_put_request(req);
  978. out:
  979. return ret;
  980. }
  981. static int ceph_zero_objects(struct inode *inode, loff_t offset, loff_t length)
  982. {
  983. int ret = 0;
  984. struct ceph_inode_info *ci = ceph_inode(inode);
  985. s32 stripe_unit = ceph_file_layout_su(ci->i_layout);
  986. s32 stripe_count = ceph_file_layout_stripe_count(ci->i_layout);
  987. s32 object_size = ceph_file_layout_object_size(ci->i_layout);
  988. u64 object_set_size = object_size * stripe_count;
  989. u64 nearly, t;
  990. /* round offset up to next period boundary */
  991. nearly = offset + object_set_size - 1;
  992. t = nearly;
  993. nearly -= do_div(t, object_set_size);
  994. while (length && offset < nearly) {
  995. loff_t size = length;
  996. ret = ceph_zero_partial_object(inode, offset, &size);
  997. if (ret < 0)
  998. return ret;
  999. offset += size;
  1000. length -= size;
  1001. }
  1002. while (length >= object_set_size) {
  1003. int i;
  1004. loff_t pos = offset;
  1005. for (i = 0; i < stripe_count; ++i) {
  1006. ret = ceph_zero_partial_object(inode, pos, NULL);
  1007. if (ret < 0)
  1008. return ret;
  1009. pos += stripe_unit;
  1010. }
  1011. offset += object_set_size;
  1012. length -= object_set_size;
  1013. }
  1014. while (length) {
  1015. loff_t size = length;
  1016. ret = ceph_zero_partial_object(inode, offset, &size);
  1017. if (ret < 0)
  1018. return ret;
  1019. offset += size;
  1020. length -= size;
  1021. }
  1022. return ret;
  1023. }
  1024. static long ceph_fallocate(struct file *file, int mode,
  1025. loff_t offset, loff_t length)
  1026. {
  1027. struct ceph_file_info *fi = file->private_data;
  1028. struct inode *inode = file_inode(file);
  1029. struct ceph_inode_info *ci = ceph_inode(inode);
  1030. struct ceph_osd_client *osdc =
  1031. &ceph_inode_to_client(inode)->client->osdc;
  1032. int want, got = 0;
  1033. int dirty;
  1034. int ret = 0;
  1035. loff_t endoff = 0;
  1036. loff_t size;
  1037. if (!S_ISREG(inode->i_mode))
  1038. return -EOPNOTSUPP;
  1039. mutex_lock(&inode->i_mutex);
  1040. if (ceph_snap(inode) != CEPH_NOSNAP) {
  1041. ret = -EROFS;
  1042. goto unlock;
  1043. }
  1044. if (ceph_osdmap_flag(osdc->osdmap, CEPH_OSDMAP_FULL) &&
  1045. !(mode & FALLOC_FL_PUNCH_HOLE)) {
  1046. ret = -ENOSPC;
  1047. goto unlock;
  1048. }
  1049. size = i_size_read(inode);
  1050. if (!(mode & FALLOC_FL_KEEP_SIZE))
  1051. endoff = offset + length;
  1052. if (fi->fmode & CEPH_FILE_MODE_LAZY)
  1053. want = CEPH_CAP_FILE_BUFFER | CEPH_CAP_FILE_LAZYIO;
  1054. else
  1055. want = CEPH_CAP_FILE_BUFFER;
  1056. ret = ceph_get_caps(ci, CEPH_CAP_FILE_WR, want, &got, endoff);
  1057. if (ret < 0)
  1058. goto unlock;
  1059. if (mode & FALLOC_FL_PUNCH_HOLE) {
  1060. if (offset < size)
  1061. ceph_zero_pagecache_range(inode, offset, length);
  1062. ret = ceph_zero_objects(inode, offset, length);
  1063. } else if (endoff > size) {
  1064. truncate_pagecache_range(inode, size, -1);
  1065. if (ceph_inode_set_size(inode, endoff))
  1066. ceph_check_caps(ceph_inode(inode),
  1067. CHECK_CAPS_AUTHONLY, NULL);
  1068. }
  1069. if (!ret) {
  1070. spin_lock(&ci->i_ceph_lock);
  1071. dirty = __ceph_mark_dirty_caps(ci, CEPH_CAP_FILE_WR);
  1072. spin_unlock(&ci->i_ceph_lock);
  1073. if (dirty)
  1074. __mark_inode_dirty(inode, dirty);
  1075. }
  1076. ceph_put_cap_refs(ci, got);
  1077. unlock:
  1078. mutex_unlock(&inode->i_mutex);
  1079. return ret;
  1080. }
  1081. const struct file_operations ceph_file_fops = {
  1082. .open = ceph_open,
  1083. .release = ceph_release,
  1084. .llseek = ceph_llseek,
  1085. .read = new_sync_read,
  1086. .write = new_sync_write,
  1087. .read_iter = ceph_read_iter,
  1088. .write_iter = ceph_write_iter,
  1089. .mmap = ceph_mmap,
  1090. .fsync = ceph_fsync,
  1091. .lock = ceph_lock,
  1092. .flock = ceph_flock,
  1093. .splice_read = generic_file_splice_read,
  1094. .splice_write = iter_file_splice_write,
  1095. .unlocked_ioctl = ceph_ioctl,
  1096. .compat_ioctl = ceph_ioctl,
  1097. .fallocate = ceph_fallocate,
  1098. };