file.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/ceph/ceph_debug.h>
  3. #include <linux/module.h>
  4. #include <linux/sched.h>
  5. #include <linux/slab.h>
  6. #include <linux/file.h>
  7. #include <linux/mount.h>
  8. #include <linux/namei.h>
  9. #include <linux/writeback.h>
  10. #include <linux/falloc.h>
  11. #include "super.h"
  12. #include "mds_client.h"
  13. #include "cache.h"
  14. static __le32 ceph_flags_sys2wire(u32 flags)
  15. {
  16. u32 wire_flags = 0;
  17. switch (flags & O_ACCMODE) {
  18. case O_RDONLY:
  19. wire_flags |= CEPH_O_RDONLY;
  20. break;
  21. case O_WRONLY:
  22. wire_flags |= CEPH_O_WRONLY;
  23. break;
  24. case O_RDWR:
  25. wire_flags |= CEPH_O_RDWR;
  26. break;
  27. }
  28. flags &= ~O_ACCMODE;
  29. #define ceph_sys2wire(a) if (flags & a) { wire_flags |= CEPH_##a; flags &= ~a; }
  30. ceph_sys2wire(O_CREAT);
  31. ceph_sys2wire(O_EXCL);
  32. ceph_sys2wire(O_TRUNC);
  33. ceph_sys2wire(O_DIRECTORY);
  34. ceph_sys2wire(O_NOFOLLOW);
  35. #undef ceph_sys2wire
  36. if (flags)
  37. dout("unused open flags: %x\n", flags);
  38. return cpu_to_le32(wire_flags);
  39. }
  40. /*
  41. * Ceph file operations
  42. *
  43. * Implement basic open/close functionality, and implement
  44. * read/write.
  45. *
  46. * We implement three modes of file I/O:
  47. * - buffered uses the generic_file_aio_{read,write} helpers
  48. *
  49. * - synchronous is used when there is multi-client read/write
  50. * sharing, avoids the page cache, and synchronously waits for an
  51. * ack from the OSD.
  52. *
  53. * - direct io takes the variant of the sync path that references
  54. * user pages directly.
  55. *
  56. * fsync() flushes and waits on dirty pages, but just queues metadata
  57. * for writeback: since the MDS can recover size and mtime there is no
  58. * need to wait for MDS acknowledgement.
  59. */
  60. /*
  61. * How many pages to get in one call to iov_iter_get_pages(). This
  62. * determines the size of the on-stack array used as a buffer.
  63. */
  64. #define ITER_GET_BVECS_PAGES 64
  65. static ssize_t __iter_get_bvecs(struct iov_iter *iter, size_t maxsize,
  66. struct bio_vec *bvecs)
  67. {
  68. size_t size = 0;
  69. int bvec_idx = 0;
  70. if (maxsize > iov_iter_count(iter))
  71. maxsize = iov_iter_count(iter);
  72. while (size < maxsize) {
  73. struct page *pages[ITER_GET_BVECS_PAGES];
  74. ssize_t bytes;
  75. size_t start;
  76. int idx = 0;
  77. bytes = iov_iter_get_pages(iter, pages, maxsize - size,
  78. ITER_GET_BVECS_PAGES, &start);
  79. if (bytes < 0)
  80. return size ?: bytes;
  81. iov_iter_advance(iter, bytes);
  82. size += bytes;
  83. for ( ; bytes; idx++, bvec_idx++) {
  84. struct bio_vec bv = {
  85. .bv_page = pages[idx],
  86. .bv_len = min_t(int, bytes, PAGE_SIZE - start),
  87. .bv_offset = start,
  88. };
  89. bvecs[bvec_idx] = bv;
  90. bytes -= bv.bv_len;
  91. start = 0;
  92. }
  93. }
  94. return size;
  95. }
  96. /*
  97. * iov_iter_get_pages() only considers one iov_iter segment, no matter
  98. * what maxsize or maxpages are given. For ITER_BVEC that is a single
  99. * page.
  100. *
  101. * Attempt to get up to @maxsize bytes worth of pages from @iter.
  102. * Return the number of bytes in the created bio_vec array, or an error.
  103. */
  104. static ssize_t iter_get_bvecs_alloc(struct iov_iter *iter, size_t maxsize,
  105. struct bio_vec **bvecs, int *num_bvecs)
  106. {
  107. struct bio_vec *bv;
  108. size_t orig_count = iov_iter_count(iter);
  109. ssize_t bytes;
  110. int npages;
  111. iov_iter_truncate(iter, maxsize);
  112. npages = iov_iter_npages(iter, INT_MAX);
  113. iov_iter_reexpand(iter, orig_count);
  114. /*
  115. * __iter_get_bvecs() may populate only part of the array -- zero it
  116. * out.
  117. */
  118. bv = kvmalloc_array(npages, sizeof(*bv), GFP_KERNEL | __GFP_ZERO);
  119. if (!bv)
  120. return -ENOMEM;
  121. bytes = __iter_get_bvecs(iter, maxsize, bv);
  122. if (bytes < 0) {
  123. /*
  124. * No pages were pinned -- just free the array.
  125. */
  126. kvfree(bv);
  127. return bytes;
  128. }
  129. *bvecs = bv;
  130. *num_bvecs = npages;
  131. return bytes;
  132. }
  133. static void put_bvecs(struct bio_vec *bvecs, int num_bvecs, bool should_dirty)
  134. {
  135. int i;
  136. for (i = 0; i < num_bvecs; i++) {
  137. if (bvecs[i].bv_page) {
  138. if (should_dirty)
  139. set_page_dirty_lock(bvecs[i].bv_page);
  140. put_page(bvecs[i].bv_page);
  141. }
  142. }
  143. kvfree(bvecs);
  144. }
  145. /*
  146. * Prepare an open request. Preallocate ceph_cap to avoid an
  147. * inopportune ENOMEM later.
  148. */
  149. static struct ceph_mds_request *
  150. prepare_open_request(struct super_block *sb, int flags, int create_mode)
  151. {
  152. struct ceph_fs_client *fsc = ceph_sb_to_client(sb);
  153. struct ceph_mds_client *mdsc = fsc->mdsc;
  154. struct ceph_mds_request *req;
  155. int want_auth = USE_ANY_MDS;
  156. int op = (flags & O_CREAT) ? CEPH_MDS_OP_CREATE : CEPH_MDS_OP_OPEN;
  157. if (flags & (O_WRONLY|O_RDWR|O_CREAT|O_TRUNC))
  158. want_auth = USE_AUTH_MDS;
  159. req = ceph_mdsc_create_request(mdsc, op, want_auth);
  160. if (IS_ERR(req))
  161. goto out;
  162. req->r_fmode = ceph_flags_to_mode(flags);
  163. req->r_args.open.flags = ceph_flags_sys2wire(flags);
  164. req->r_args.open.mode = cpu_to_le32(create_mode);
  165. out:
  166. return req;
  167. }
  168. static int ceph_init_file_info(struct inode *inode, struct file *file,
  169. int fmode, bool isdir)
  170. {
  171. struct ceph_file_info *fi;
  172. dout("%s %p %p 0%o (%s)\n", __func__, inode, file,
  173. inode->i_mode, isdir ? "dir" : "regular");
  174. BUG_ON(inode->i_fop->release != ceph_release);
  175. if (isdir) {
  176. struct ceph_dir_file_info *dfi =
  177. kmem_cache_zalloc(ceph_dir_file_cachep, GFP_KERNEL);
  178. if (!dfi) {
  179. ceph_put_fmode(ceph_inode(inode), fmode); /* clean up */
  180. return -ENOMEM;
  181. }
  182. file->private_data = dfi;
  183. fi = &dfi->file_info;
  184. dfi->next_offset = 2;
  185. dfi->readdir_cache_idx = -1;
  186. } else {
  187. fi = kmem_cache_zalloc(ceph_file_cachep, GFP_KERNEL);
  188. if (!fi) {
  189. ceph_put_fmode(ceph_inode(inode), fmode); /* clean up */
  190. return -ENOMEM;
  191. }
  192. file->private_data = fi;
  193. }
  194. fi->fmode = fmode;
  195. spin_lock_init(&fi->rw_contexts_lock);
  196. INIT_LIST_HEAD(&fi->rw_contexts);
  197. return 0;
  198. }
  199. /*
  200. * initialize private struct file data.
  201. * if we fail, clean up by dropping fmode reference on the ceph_inode
  202. */
  203. static int ceph_init_file(struct inode *inode, struct file *file, int fmode)
  204. {
  205. int ret = 0;
  206. switch (inode->i_mode & S_IFMT) {
  207. case S_IFREG:
  208. ceph_fscache_register_inode_cookie(inode);
  209. ceph_fscache_file_set_cookie(inode, file);
  210. case S_IFDIR:
  211. ret = ceph_init_file_info(inode, file, fmode,
  212. S_ISDIR(inode->i_mode));
  213. if (ret)
  214. return ret;
  215. break;
  216. case S_IFLNK:
  217. dout("init_file %p %p 0%o (symlink)\n", inode, file,
  218. inode->i_mode);
  219. ceph_put_fmode(ceph_inode(inode), fmode); /* clean up */
  220. break;
  221. default:
  222. dout("init_file %p %p 0%o (special)\n", inode, file,
  223. inode->i_mode);
  224. /*
  225. * we need to drop the open ref now, since we don't
  226. * have .release set to ceph_release.
  227. */
  228. ceph_put_fmode(ceph_inode(inode), fmode); /* clean up */
  229. BUG_ON(inode->i_fop->release == ceph_release);
  230. /* call the proper open fop */
  231. ret = inode->i_fop->open(inode, file);
  232. }
  233. return ret;
  234. }
  235. /*
  236. * try renew caps after session gets killed.
  237. */
  238. int ceph_renew_caps(struct inode *inode)
  239. {
  240. struct ceph_mds_client *mdsc = ceph_sb_to_client(inode->i_sb)->mdsc;
  241. struct ceph_inode_info *ci = ceph_inode(inode);
  242. struct ceph_mds_request *req;
  243. int err, flags, wanted;
  244. spin_lock(&ci->i_ceph_lock);
  245. wanted = __ceph_caps_file_wanted(ci);
  246. if (__ceph_is_any_real_caps(ci) &&
  247. (!(wanted & CEPH_CAP_ANY_WR) || ci->i_auth_cap)) {
  248. int issued = __ceph_caps_issued(ci, NULL);
  249. spin_unlock(&ci->i_ceph_lock);
  250. dout("renew caps %p want %s issued %s updating mds_wanted\n",
  251. inode, ceph_cap_string(wanted), ceph_cap_string(issued));
  252. ceph_check_caps(ci, 0, NULL);
  253. return 0;
  254. }
  255. spin_unlock(&ci->i_ceph_lock);
  256. flags = 0;
  257. if ((wanted & CEPH_CAP_FILE_RD) && (wanted & CEPH_CAP_FILE_WR))
  258. flags = O_RDWR;
  259. else if (wanted & CEPH_CAP_FILE_RD)
  260. flags = O_RDONLY;
  261. else if (wanted & CEPH_CAP_FILE_WR)
  262. flags = O_WRONLY;
  263. #ifdef O_LAZY
  264. if (wanted & CEPH_CAP_FILE_LAZYIO)
  265. flags |= O_LAZY;
  266. #endif
  267. req = prepare_open_request(inode->i_sb, flags, 0);
  268. if (IS_ERR(req)) {
  269. err = PTR_ERR(req);
  270. goto out;
  271. }
  272. req->r_inode = inode;
  273. ihold(inode);
  274. req->r_num_caps = 1;
  275. req->r_fmode = -1;
  276. err = ceph_mdsc_do_request(mdsc, NULL, req);
  277. ceph_mdsc_put_request(req);
  278. out:
  279. dout("renew caps %p open result=%d\n", inode, err);
  280. return err < 0 ? err : 0;
  281. }
  282. /*
  283. * If we already have the requisite capabilities, we can satisfy
  284. * the open request locally (no need to request new caps from the
  285. * MDS). We do, however, need to inform the MDS (asynchronously)
  286. * if our wanted caps set expands.
  287. */
  288. int ceph_open(struct inode *inode, struct file *file)
  289. {
  290. struct ceph_inode_info *ci = ceph_inode(inode);
  291. struct ceph_fs_client *fsc = ceph_sb_to_client(inode->i_sb);
  292. struct ceph_mds_client *mdsc = fsc->mdsc;
  293. struct ceph_mds_request *req;
  294. struct ceph_file_info *fi = file->private_data;
  295. int err;
  296. int flags, fmode, wanted;
  297. if (fi) {
  298. dout("open file %p is already opened\n", file);
  299. return 0;
  300. }
  301. /* filter out O_CREAT|O_EXCL; vfs did that already. yuck. */
  302. flags = file->f_flags & ~(O_CREAT|O_EXCL);
  303. if (S_ISDIR(inode->i_mode))
  304. flags = O_DIRECTORY; /* mds likes to know */
  305. dout("open inode %p ino %llx.%llx file %p flags %d (%d)\n", inode,
  306. ceph_vinop(inode), file, flags, file->f_flags);
  307. fmode = ceph_flags_to_mode(flags);
  308. wanted = ceph_caps_for_mode(fmode);
  309. /* snapped files are read-only */
  310. if (ceph_snap(inode) != CEPH_NOSNAP && (file->f_mode & FMODE_WRITE))
  311. return -EROFS;
  312. /* trivially open snapdir */
  313. if (ceph_snap(inode) == CEPH_SNAPDIR) {
  314. spin_lock(&ci->i_ceph_lock);
  315. __ceph_get_fmode(ci, fmode);
  316. spin_unlock(&ci->i_ceph_lock);
  317. return ceph_init_file(inode, file, fmode);
  318. }
  319. /*
  320. * No need to block if we have caps on the auth MDS (for
  321. * write) or any MDS (for read). Update wanted set
  322. * asynchronously.
  323. */
  324. spin_lock(&ci->i_ceph_lock);
  325. if (__ceph_is_any_real_caps(ci) &&
  326. (((fmode & CEPH_FILE_MODE_WR) == 0) || ci->i_auth_cap)) {
  327. int mds_wanted = __ceph_caps_mds_wanted(ci, true);
  328. int issued = __ceph_caps_issued(ci, NULL);
  329. dout("open %p fmode %d want %s issued %s using existing\n",
  330. inode, fmode, ceph_cap_string(wanted),
  331. ceph_cap_string(issued));
  332. __ceph_get_fmode(ci, fmode);
  333. spin_unlock(&ci->i_ceph_lock);
  334. /* adjust wanted? */
  335. if ((issued & wanted) != wanted &&
  336. (mds_wanted & wanted) != wanted &&
  337. ceph_snap(inode) != CEPH_SNAPDIR)
  338. ceph_check_caps(ci, 0, NULL);
  339. return ceph_init_file(inode, file, fmode);
  340. } else if (ceph_snap(inode) != CEPH_NOSNAP &&
  341. (ci->i_snap_caps & wanted) == wanted) {
  342. __ceph_get_fmode(ci, fmode);
  343. spin_unlock(&ci->i_ceph_lock);
  344. return ceph_init_file(inode, file, fmode);
  345. }
  346. spin_unlock(&ci->i_ceph_lock);
  347. dout("open fmode %d wants %s\n", fmode, ceph_cap_string(wanted));
  348. req = prepare_open_request(inode->i_sb, flags, 0);
  349. if (IS_ERR(req)) {
  350. err = PTR_ERR(req);
  351. goto out;
  352. }
  353. req->r_inode = inode;
  354. ihold(inode);
  355. req->r_num_caps = 1;
  356. err = ceph_mdsc_do_request(mdsc, NULL, req);
  357. if (!err)
  358. err = ceph_init_file(inode, file, req->r_fmode);
  359. ceph_mdsc_put_request(req);
  360. dout("open result=%d on %llx.%llx\n", err, ceph_vinop(inode));
  361. out:
  362. return err;
  363. }
  364. /*
  365. * Do a lookup + open with a single request. If we get a non-existent
  366. * file or symlink, return 1 so the VFS can retry.
  367. */
  368. int ceph_atomic_open(struct inode *dir, struct dentry *dentry,
  369. struct file *file, unsigned flags, umode_t mode,
  370. int *opened)
  371. {
  372. struct ceph_fs_client *fsc = ceph_sb_to_client(dir->i_sb);
  373. struct ceph_mds_client *mdsc = fsc->mdsc;
  374. struct ceph_mds_request *req;
  375. struct dentry *dn;
  376. struct ceph_acls_info acls = {};
  377. int mask;
  378. int err;
  379. dout("atomic_open %p dentry %p '%pd' %s flags %d mode 0%o\n",
  380. dir, dentry, dentry,
  381. d_unhashed(dentry) ? "unhashed" : "hashed", flags, mode);
  382. if (dentry->d_name.len > NAME_MAX)
  383. return -ENAMETOOLONG;
  384. if (flags & O_CREAT) {
  385. if (ceph_quota_is_max_files_exceeded(dir))
  386. return -EDQUOT;
  387. err = ceph_pre_init_acls(dir, &mode, &acls);
  388. if (err < 0)
  389. return err;
  390. }
  391. /* do the open */
  392. req = prepare_open_request(dir->i_sb, flags, mode);
  393. if (IS_ERR(req)) {
  394. err = PTR_ERR(req);
  395. goto out_acl;
  396. }
  397. req->r_dentry = dget(dentry);
  398. req->r_num_caps = 2;
  399. if (flags & O_CREAT) {
  400. req->r_dentry_drop = CEPH_CAP_FILE_SHARED | CEPH_CAP_AUTH_EXCL;
  401. req->r_dentry_unless = CEPH_CAP_FILE_EXCL;
  402. if (acls.pagelist) {
  403. req->r_pagelist = acls.pagelist;
  404. acls.pagelist = NULL;
  405. }
  406. }
  407. mask = CEPH_STAT_CAP_INODE | CEPH_CAP_AUTH_SHARED;
  408. if (ceph_security_xattr_wanted(dir))
  409. mask |= CEPH_CAP_XATTR_SHARED;
  410. req->r_args.open.mask = cpu_to_le32(mask);
  411. req->r_parent = dir;
  412. set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags);
  413. err = ceph_mdsc_do_request(mdsc,
  414. (flags & (O_CREAT|O_TRUNC)) ? dir : NULL,
  415. req);
  416. err = ceph_handle_snapdir(req, dentry, err);
  417. if (err)
  418. goto out_req;
  419. if ((flags & O_CREAT) && !req->r_reply_info.head->is_dentry)
  420. err = ceph_handle_notrace_create(dir, dentry);
  421. if (d_in_lookup(dentry)) {
  422. dn = ceph_finish_lookup(req, dentry, err);
  423. if (IS_ERR(dn))
  424. err = PTR_ERR(dn);
  425. } else {
  426. /* we were given a hashed negative dentry */
  427. dn = NULL;
  428. }
  429. if (err)
  430. goto out_req;
  431. if (dn || d_really_is_negative(dentry) || d_is_symlink(dentry)) {
  432. /* make vfs retry on splice, ENOENT, or symlink */
  433. dout("atomic_open finish_no_open on dn %p\n", dn);
  434. err = finish_no_open(file, dn);
  435. } else {
  436. dout("atomic_open finish_open on dn %p\n", dn);
  437. if (req->r_op == CEPH_MDS_OP_CREATE && req->r_reply_info.has_create_ino) {
  438. ceph_init_inode_acls(d_inode(dentry), &acls);
  439. *opened |= FILE_CREATED;
  440. }
  441. err = finish_open(file, dentry, ceph_open, opened);
  442. }
  443. out_req:
  444. if (!req->r_err && req->r_target_inode)
  445. ceph_put_fmode(ceph_inode(req->r_target_inode), req->r_fmode);
  446. ceph_mdsc_put_request(req);
  447. out_acl:
  448. ceph_release_acls_info(&acls);
  449. dout("atomic_open result=%d\n", err);
  450. return err;
  451. }
  452. int ceph_release(struct inode *inode, struct file *file)
  453. {
  454. struct ceph_inode_info *ci = ceph_inode(inode);
  455. if (S_ISDIR(inode->i_mode)) {
  456. struct ceph_dir_file_info *dfi = file->private_data;
  457. dout("release inode %p dir file %p\n", inode, file);
  458. WARN_ON(!list_empty(&dfi->file_info.rw_contexts));
  459. ceph_put_fmode(ci, dfi->file_info.fmode);
  460. if (dfi->last_readdir)
  461. ceph_mdsc_put_request(dfi->last_readdir);
  462. kfree(dfi->last_name);
  463. kfree(dfi->dir_info);
  464. kmem_cache_free(ceph_dir_file_cachep, dfi);
  465. } else {
  466. struct ceph_file_info *fi = file->private_data;
  467. dout("release inode %p regular file %p\n", inode, file);
  468. WARN_ON(!list_empty(&fi->rw_contexts));
  469. ceph_put_fmode(ci, fi->fmode);
  470. kmem_cache_free(ceph_file_cachep, fi);
  471. }
  472. /* wake up anyone waiting for caps on this inode */
  473. wake_up_all(&ci->i_cap_wq);
  474. return 0;
  475. }
  476. enum {
  477. HAVE_RETRIED = 1,
  478. CHECK_EOF = 2,
  479. READ_INLINE = 3,
  480. };
  481. /*
  482. * Read a range of bytes striped over one or more objects. Iterate over
  483. * objects we stripe over. (That's not atomic, but good enough for now.)
  484. *
  485. * If we get a short result from the OSD, check against i_size; we need to
  486. * only return a short read to the caller if we hit EOF.
  487. */
  488. static int striped_read(struct inode *inode,
  489. u64 pos, u64 len,
  490. struct page **pages, int num_pages,
  491. int page_align, int *checkeof)
  492. {
  493. struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
  494. struct ceph_inode_info *ci = ceph_inode(inode);
  495. u64 this_len;
  496. loff_t i_size;
  497. int page_idx;
  498. int ret, read = 0;
  499. bool hit_stripe, was_short;
  500. /*
  501. * we may need to do multiple reads. not atomic, unfortunately.
  502. */
  503. more:
  504. this_len = len;
  505. page_idx = (page_align + read) >> PAGE_SHIFT;
  506. ret = ceph_osdc_readpages(&fsc->client->osdc, ceph_vino(inode),
  507. &ci->i_layout, pos, &this_len,
  508. ci->i_truncate_seq, ci->i_truncate_size,
  509. pages + page_idx, num_pages - page_idx,
  510. ((page_align + read) & ~PAGE_MASK));
  511. if (ret == -ENOENT)
  512. ret = 0;
  513. hit_stripe = this_len < len;
  514. was_short = ret >= 0 && ret < this_len;
  515. dout("striped_read %llu~%llu (read %u) got %d%s%s\n", pos, len, read,
  516. ret, hit_stripe ? " HITSTRIPE" : "", was_short ? " SHORT" : "");
  517. i_size = i_size_read(inode);
  518. if (ret >= 0) {
  519. if (was_short && (pos + ret < i_size)) {
  520. int zlen = min(this_len - ret, i_size - pos - ret);
  521. int zoff = page_align + read + ret;
  522. dout(" zero gap %llu to %llu\n",
  523. pos + ret, pos + ret + zlen);
  524. ceph_zero_page_vector_range(zoff, zlen, pages);
  525. ret += zlen;
  526. }
  527. read += ret;
  528. pos += ret;
  529. len -= ret;
  530. /* hit stripe and need continue*/
  531. if (len && hit_stripe && pos < i_size)
  532. goto more;
  533. }
  534. if (read > 0) {
  535. ret = read;
  536. /* did we bounce off eof? */
  537. if (pos + len > i_size)
  538. *checkeof = CHECK_EOF;
  539. }
  540. dout("striped_read returns %d\n", ret);
  541. return ret;
  542. }
  543. /*
  544. * Completely synchronous read and write methods. Direct from __user
  545. * buffer to osd, or directly to user pages (if O_DIRECT).
  546. *
  547. * If the read spans object boundary, just do multiple reads.
  548. */
  549. static ssize_t ceph_sync_read(struct kiocb *iocb, struct iov_iter *to,
  550. int *checkeof)
  551. {
  552. struct file *file = iocb->ki_filp;
  553. struct inode *inode = file_inode(file);
  554. struct page **pages;
  555. u64 off = iocb->ki_pos;
  556. int num_pages;
  557. ssize_t ret;
  558. size_t len = iov_iter_count(to);
  559. dout("sync_read on file %p %llu~%u %s\n", file, off, (unsigned)len,
  560. (file->f_flags & O_DIRECT) ? "O_DIRECT" : "");
  561. if (!len)
  562. return 0;
  563. /*
  564. * flush any page cache pages in this range. this
  565. * will make concurrent normal and sync io slow,
  566. * but it will at least behave sensibly when they are
  567. * in sequence.
  568. */
  569. ret = filemap_write_and_wait_range(inode->i_mapping, off,
  570. off + len);
  571. if (ret < 0)
  572. return ret;
  573. if (unlikely(to->type & ITER_PIPE)) {
  574. size_t page_off;
  575. ret = iov_iter_get_pages_alloc(to, &pages, len,
  576. &page_off);
  577. if (ret <= 0)
  578. return -ENOMEM;
  579. num_pages = DIV_ROUND_UP(ret + page_off, PAGE_SIZE);
  580. ret = striped_read(inode, off, ret, pages, num_pages,
  581. page_off, checkeof);
  582. if (ret > 0) {
  583. iov_iter_advance(to, ret);
  584. off += ret;
  585. } else {
  586. iov_iter_advance(to, 0);
  587. }
  588. ceph_put_page_vector(pages, num_pages, false);
  589. } else {
  590. num_pages = calc_pages_for(off, len);
  591. pages = ceph_alloc_page_vector(num_pages, GFP_KERNEL);
  592. if (IS_ERR(pages))
  593. return PTR_ERR(pages);
  594. ret = striped_read(inode, off, len, pages, num_pages,
  595. (off & ~PAGE_MASK), checkeof);
  596. if (ret > 0) {
  597. int l, k = 0;
  598. size_t left = ret;
  599. while (left) {
  600. size_t page_off = off & ~PAGE_MASK;
  601. size_t copy = min_t(size_t, left,
  602. PAGE_SIZE - page_off);
  603. l = copy_page_to_iter(pages[k++], page_off,
  604. copy, to);
  605. off += l;
  606. left -= l;
  607. if (l < copy)
  608. break;
  609. }
  610. }
  611. ceph_release_page_vector(pages, num_pages);
  612. }
  613. if (off > iocb->ki_pos) {
  614. ret = off - iocb->ki_pos;
  615. iocb->ki_pos = off;
  616. }
  617. dout("sync_read result %zd\n", ret);
  618. return ret;
  619. }
  620. struct ceph_aio_request {
  621. struct kiocb *iocb;
  622. size_t total_len;
  623. bool write;
  624. bool should_dirty;
  625. int error;
  626. struct list_head osd_reqs;
  627. unsigned num_reqs;
  628. atomic_t pending_reqs;
  629. struct timespec mtime;
  630. struct ceph_cap_flush *prealloc_cf;
  631. };
  632. struct ceph_aio_work {
  633. struct work_struct work;
  634. struct ceph_osd_request *req;
  635. };
  636. static void ceph_aio_retry_work(struct work_struct *work);
  637. static void ceph_aio_complete(struct inode *inode,
  638. struct ceph_aio_request *aio_req)
  639. {
  640. struct ceph_inode_info *ci = ceph_inode(inode);
  641. int ret;
  642. if (!atomic_dec_and_test(&aio_req->pending_reqs))
  643. return;
  644. ret = aio_req->error;
  645. if (!ret)
  646. ret = aio_req->total_len;
  647. dout("ceph_aio_complete %p rc %d\n", inode, ret);
  648. if (ret >= 0 && aio_req->write) {
  649. int dirty;
  650. loff_t endoff = aio_req->iocb->ki_pos + aio_req->total_len;
  651. if (endoff > i_size_read(inode)) {
  652. if (ceph_inode_set_size(inode, endoff))
  653. ceph_check_caps(ci, CHECK_CAPS_AUTHONLY, NULL);
  654. }
  655. spin_lock(&ci->i_ceph_lock);
  656. ci->i_inline_version = CEPH_INLINE_NONE;
  657. dirty = __ceph_mark_dirty_caps(ci, CEPH_CAP_FILE_WR,
  658. &aio_req->prealloc_cf);
  659. spin_unlock(&ci->i_ceph_lock);
  660. if (dirty)
  661. __mark_inode_dirty(inode, dirty);
  662. }
  663. ceph_put_cap_refs(ci, (aio_req->write ? CEPH_CAP_FILE_WR :
  664. CEPH_CAP_FILE_RD));
  665. aio_req->iocb->ki_complete(aio_req->iocb, ret, 0);
  666. ceph_free_cap_flush(aio_req->prealloc_cf);
  667. kfree(aio_req);
  668. }
  669. static void ceph_aio_complete_req(struct ceph_osd_request *req)
  670. {
  671. int rc = req->r_result;
  672. struct inode *inode = req->r_inode;
  673. struct ceph_aio_request *aio_req = req->r_priv;
  674. struct ceph_osd_data *osd_data = osd_req_op_extent_osd_data(req, 0);
  675. BUG_ON(osd_data->type != CEPH_OSD_DATA_TYPE_BVECS);
  676. BUG_ON(!osd_data->num_bvecs);
  677. dout("ceph_aio_complete_req %p rc %d bytes %u\n",
  678. inode, rc, osd_data->bvec_pos.iter.bi_size);
  679. if (rc == -EOLDSNAPC) {
  680. struct ceph_aio_work *aio_work;
  681. BUG_ON(!aio_req->write);
  682. aio_work = kmalloc(sizeof(*aio_work), GFP_NOFS);
  683. if (aio_work) {
  684. INIT_WORK(&aio_work->work, ceph_aio_retry_work);
  685. aio_work->req = req;
  686. queue_work(ceph_inode_to_client(inode)->wb_wq,
  687. &aio_work->work);
  688. return;
  689. }
  690. rc = -ENOMEM;
  691. } else if (!aio_req->write) {
  692. if (rc == -ENOENT)
  693. rc = 0;
  694. if (rc >= 0 && osd_data->bvec_pos.iter.bi_size > rc) {
  695. struct iov_iter i;
  696. int zlen = osd_data->bvec_pos.iter.bi_size - rc;
  697. /*
  698. * If read is satisfied by single OSD request,
  699. * it can pass EOF. Otherwise read is within
  700. * i_size.
  701. */
  702. if (aio_req->num_reqs == 1) {
  703. loff_t i_size = i_size_read(inode);
  704. loff_t endoff = aio_req->iocb->ki_pos + rc;
  705. if (endoff < i_size)
  706. zlen = min_t(size_t, zlen,
  707. i_size - endoff);
  708. aio_req->total_len = rc + zlen;
  709. }
  710. iov_iter_bvec(&i, ITER_BVEC, osd_data->bvec_pos.bvecs,
  711. osd_data->num_bvecs,
  712. osd_data->bvec_pos.iter.bi_size);
  713. iov_iter_advance(&i, rc);
  714. iov_iter_zero(zlen, &i);
  715. }
  716. }
  717. put_bvecs(osd_data->bvec_pos.bvecs, osd_data->num_bvecs,
  718. aio_req->should_dirty);
  719. ceph_osdc_put_request(req);
  720. if (rc < 0)
  721. cmpxchg(&aio_req->error, 0, rc);
  722. ceph_aio_complete(inode, aio_req);
  723. return;
  724. }
  725. static void ceph_aio_retry_work(struct work_struct *work)
  726. {
  727. struct ceph_aio_work *aio_work =
  728. container_of(work, struct ceph_aio_work, work);
  729. struct ceph_osd_request *orig_req = aio_work->req;
  730. struct ceph_aio_request *aio_req = orig_req->r_priv;
  731. struct inode *inode = orig_req->r_inode;
  732. struct ceph_inode_info *ci = ceph_inode(inode);
  733. struct ceph_snap_context *snapc;
  734. struct ceph_osd_request *req;
  735. int ret;
  736. spin_lock(&ci->i_ceph_lock);
  737. if (__ceph_have_pending_cap_snap(ci)) {
  738. struct ceph_cap_snap *capsnap =
  739. list_last_entry(&ci->i_cap_snaps,
  740. struct ceph_cap_snap,
  741. ci_item);
  742. snapc = ceph_get_snap_context(capsnap->context);
  743. } else {
  744. BUG_ON(!ci->i_head_snapc);
  745. snapc = ceph_get_snap_context(ci->i_head_snapc);
  746. }
  747. spin_unlock(&ci->i_ceph_lock);
  748. req = ceph_osdc_alloc_request(orig_req->r_osdc, snapc, 2,
  749. false, GFP_NOFS);
  750. if (!req) {
  751. ret = -ENOMEM;
  752. req = orig_req;
  753. goto out;
  754. }
  755. req->r_flags = /* CEPH_OSD_FLAG_ORDERSNAP | */ CEPH_OSD_FLAG_WRITE;
  756. ceph_oloc_copy(&req->r_base_oloc, &orig_req->r_base_oloc);
  757. ceph_oid_copy(&req->r_base_oid, &orig_req->r_base_oid);
  758. ret = ceph_osdc_alloc_messages(req, GFP_NOFS);
  759. if (ret) {
  760. ceph_osdc_put_request(req);
  761. req = orig_req;
  762. goto out;
  763. }
  764. req->r_ops[0] = orig_req->r_ops[0];
  765. req->r_mtime = aio_req->mtime;
  766. req->r_data_offset = req->r_ops[0].extent.offset;
  767. ceph_osdc_put_request(orig_req);
  768. req->r_callback = ceph_aio_complete_req;
  769. req->r_inode = inode;
  770. req->r_priv = aio_req;
  771. ret = ceph_osdc_start_request(req->r_osdc, req, false);
  772. out:
  773. if (ret < 0) {
  774. req->r_result = ret;
  775. ceph_aio_complete_req(req);
  776. }
  777. ceph_put_snap_context(snapc);
  778. kfree(aio_work);
  779. }
  780. static ssize_t
  781. ceph_direct_read_write(struct kiocb *iocb, struct iov_iter *iter,
  782. struct ceph_snap_context *snapc,
  783. struct ceph_cap_flush **pcf)
  784. {
  785. struct file *file = iocb->ki_filp;
  786. struct inode *inode = file_inode(file);
  787. struct ceph_inode_info *ci = ceph_inode(inode);
  788. struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
  789. struct ceph_vino vino;
  790. struct ceph_osd_request *req;
  791. struct bio_vec *bvecs;
  792. struct ceph_aio_request *aio_req = NULL;
  793. int num_pages = 0;
  794. int flags;
  795. int ret;
  796. struct timespec mtime = current_time(inode);
  797. size_t count = iov_iter_count(iter);
  798. loff_t pos = iocb->ki_pos;
  799. bool write = iov_iter_rw(iter) == WRITE;
  800. bool should_dirty = !write && iter_is_iovec(iter);
  801. if (write && ceph_snap(file_inode(file)) != CEPH_NOSNAP)
  802. return -EROFS;
  803. dout("sync_direct_%s on file %p %lld~%u snapc %p seq %lld\n",
  804. (write ? "write" : "read"), file, pos, (unsigned)count,
  805. snapc, snapc->seq);
  806. ret = filemap_write_and_wait_range(inode->i_mapping, pos, pos + count);
  807. if (ret < 0)
  808. return ret;
  809. if (write) {
  810. int ret2 = invalidate_inode_pages2_range(inode->i_mapping,
  811. pos >> PAGE_SHIFT,
  812. (pos + count) >> PAGE_SHIFT);
  813. if (ret2 < 0)
  814. dout("invalidate_inode_pages2_range returned %d\n", ret2);
  815. flags = /* CEPH_OSD_FLAG_ORDERSNAP | */ CEPH_OSD_FLAG_WRITE;
  816. } else {
  817. flags = CEPH_OSD_FLAG_READ;
  818. }
  819. while (iov_iter_count(iter) > 0) {
  820. u64 size = iov_iter_count(iter);
  821. ssize_t len;
  822. if (write)
  823. size = min_t(u64, size, fsc->mount_options->wsize);
  824. else
  825. size = min_t(u64, size, fsc->mount_options->rsize);
  826. vino = ceph_vino(inode);
  827. req = ceph_osdc_new_request(&fsc->client->osdc, &ci->i_layout,
  828. vino, pos, &size, 0,
  829. 1,
  830. write ? CEPH_OSD_OP_WRITE :
  831. CEPH_OSD_OP_READ,
  832. flags, snapc,
  833. ci->i_truncate_seq,
  834. ci->i_truncate_size,
  835. false);
  836. if (IS_ERR(req)) {
  837. ret = PTR_ERR(req);
  838. break;
  839. }
  840. len = iter_get_bvecs_alloc(iter, size, &bvecs, &num_pages);
  841. if (len < 0) {
  842. ceph_osdc_put_request(req);
  843. ret = len;
  844. break;
  845. }
  846. if (len != size)
  847. osd_req_op_extent_update(req, 0, len);
  848. /*
  849. * To simplify error handling, allow AIO when IO within i_size
  850. * or IO can be satisfied by single OSD request.
  851. */
  852. if (pos == iocb->ki_pos && !is_sync_kiocb(iocb) &&
  853. (len == count || pos + count <= i_size_read(inode))) {
  854. aio_req = kzalloc(sizeof(*aio_req), GFP_KERNEL);
  855. if (aio_req) {
  856. aio_req->iocb = iocb;
  857. aio_req->write = write;
  858. aio_req->should_dirty = should_dirty;
  859. INIT_LIST_HEAD(&aio_req->osd_reqs);
  860. if (write) {
  861. aio_req->mtime = mtime;
  862. swap(aio_req->prealloc_cf, *pcf);
  863. }
  864. }
  865. /* ignore error */
  866. }
  867. if (write) {
  868. /*
  869. * throw out any page cache pages in this range. this
  870. * may block.
  871. */
  872. truncate_inode_pages_range(inode->i_mapping, pos,
  873. (pos+len) | (PAGE_SIZE - 1));
  874. req->r_mtime = mtime;
  875. }
  876. osd_req_op_extent_osd_data_bvecs(req, 0, bvecs, num_pages, len);
  877. if (aio_req) {
  878. aio_req->total_len += len;
  879. aio_req->num_reqs++;
  880. atomic_inc(&aio_req->pending_reqs);
  881. req->r_callback = ceph_aio_complete_req;
  882. req->r_inode = inode;
  883. req->r_priv = aio_req;
  884. list_add_tail(&req->r_unsafe_item, &aio_req->osd_reqs);
  885. pos += len;
  886. continue;
  887. }
  888. ret = ceph_osdc_start_request(req->r_osdc, req, false);
  889. if (!ret)
  890. ret = ceph_osdc_wait_request(&fsc->client->osdc, req);
  891. size = i_size_read(inode);
  892. if (!write) {
  893. if (ret == -ENOENT)
  894. ret = 0;
  895. if (ret >= 0 && ret < len && pos + ret < size) {
  896. struct iov_iter i;
  897. int zlen = min_t(size_t, len - ret,
  898. size - pos - ret);
  899. iov_iter_bvec(&i, ITER_BVEC, bvecs, num_pages,
  900. len);
  901. iov_iter_advance(&i, ret);
  902. iov_iter_zero(zlen, &i);
  903. ret += zlen;
  904. }
  905. if (ret >= 0)
  906. len = ret;
  907. }
  908. put_bvecs(bvecs, num_pages, should_dirty);
  909. ceph_osdc_put_request(req);
  910. if (ret < 0)
  911. break;
  912. pos += len;
  913. if (!write && pos >= size)
  914. break;
  915. if (write && pos > size) {
  916. if (ceph_inode_set_size(inode, pos))
  917. ceph_check_caps(ceph_inode(inode),
  918. CHECK_CAPS_AUTHONLY,
  919. NULL);
  920. }
  921. }
  922. if (aio_req) {
  923. LIST_HEAD(osd_reqs);
  924. if (aio_req->num_reqs == 0) {
  925. kfree(aio_req);
  926. return ret;
  927. }
  928. ceph_get_cap_refs(ci, write ? CEPH_CAP_FILE_WR :
  929. CEPH_CAP_FILE_RD);
  930. list_splice(&aio_req->osd_reqs, &osd_reqs);
  931. while (!list_empty(&osd_reqs)) {
  932. req = list_first_entry(&osd_reqs,
  933. struct ceph_osd_request,
  934. r_unsafe_item);
  935. list_del_init(&req->r_unsafe_item);
  936. if (ret >= 0)
  937. ret = ceph_osdc_start_request(req->r_osdc,
  938. req, false);
  939. if (ret < 0) {
  940. req->r_result = ret;
  941. ceph_aio_complete_req(req);
  942. }
  943. }
  944. return -EIOCBQUEUED;
  945. }
  946. if (ret != -EOLDSNAPC && pos > iocb->ki_pos) {
  947. ret = pos - iocb->ki_pos;
  948. iocb->ki_pos = pos;
  949. }
  950. return ret;
  951. }
  952. /*
  953. * Synchronous write, straight from __user pointer or user pages.
  954. *
  955. * If write spans object boundary, just do multiple writes. (For a
  956. * correct atomic write, we should e.g. take write locks on all
  957. * objects, rollback on failure, etc.)
  958. */
  959. static ssize_t
  960. ceph_sync_write(struct kiocb *iocb, struct iov_iter *from, loff_t pos,
  961. struct ceph_snap_context *snapc)
  962. {
  963. struct file *file = iocb->ki_filp;
  964. struct inode *inode = file_inode(file);
  965. struct ceph_inode_info *ci = ceph_inode(inode);
  966. struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
  967. struct ceph_vino vino;
  968. struct ceph_osd_request *req;
  969. struct page **pages;
  970. u64 len;
  971. int num_pages;
  972. int written = 0;
  973. int flags;
  974. int ret;
  975. bool check_caps = false;
  976. struct timespec mtime = current_time(inode);
  977. size_t count = iov_iter_count(from);
  978. if (ceph_snap(file_inode(file)) != CEPH_NOSNAP)
  979. return -EROFS;
  980. dout("sync_write on file %p %lld~%u snapc %p seq %lld\n",
  981. file, pos, (unsigned)count, snapc, snapc->seq);
  982. ret = filemap_write_and_wait_range(inode->i_mapping, pos, pos + count);
  983. if (ret < 0)
  984. return ret;
  985. ret = invalidate_inode_pages2_range(inode->i_mapping,
  986. pos >> PAGE_SHIFT,
  987. (pos + count) >> PAGE_SHIFT);
  988. if (ret < 0)
  989. dout("invalidate_inode_pages2_range returned %d\n", ret);
  990. flags = /* CEPH_OSD_FLAG_ORDERSNAP | */ CEPH_OSD_FLAG_WRITE;
  991. while ((len = iov_iter_count(from)) > 0) {
  992. size_t left;
  993. int n;
  994. vino = ceph_vino(inode);
  995. req = ceph_osdc_new_request(&fsc->client->osdc, &ci->i_layout,
  996. vino, pos, &len, 0, 1,
  997. CEPH_OSD_OP_WRITE, flags, snapc,
  998. ci->i_truncate_seq,
  999. ci->i_truncate_size,
  1000. false);
  1001. if (IS_ERR(req)) {
  1002. ret = PTR_ERR(req);
  1003. break;
  1004. }
  1005. /*
  1006. * write from beginning of first page,
  1007. * regardless of io alignment
  1008. */
  1009. num_pages = (len + PAGE_SIZE - 1) >> PAGE_SHIFT;
  1010. pages = ceph_alloc_page_vector(num_pages, GFP_KERNEL);
  1011. if (IS_ERR(pages)) {
  1012. ret = PTR_ERR(pages);
  1013. goto out;
  1014. }
  1015. left = len;
  1016. for (n = 0; n < num_pages; n++) {
  1017. size_t plen = min_t(size_t, left, PAGE_SIZE);
  1018. ret = copy_page_from_iter(pages[n], 0, plen, from);
  1019. if (ret != plen) {
  1020. ret = -EFAULT;
  1021. break;
  1022. }
  1023. left -= ret;
  1024. }
  1025. if (ret < 0) {
  1026. ceph_release_page_vector(pages, num_pages);
  1027. goto out;
  1028. }
  1029. req->r_inode = inode;
  1030. osd_req_op_extent_osd_data_pages(req, 0, pages, len, 0,
  1031. false, true);
  1032. req->r_mtime = mtime;
  1033. ret = ceph_osdc_start_request(&fsc->client->osdc, req, false);
  1034. if (!ret)
  1035. ret = ceph_osdc_wait_request(&fsc->client->osdc, req);
  1036. out:
  1037. ceph_osdc_put_request(req);
  1038. if (ret != 0) {
  1039. ceph_set_error_write(ci);
  1040. break;
  1041. }
  1042. ceph_clear_error_write(ci);
  1043. pos += len;
  1044. written += len;
  1045. if (pos > i_size_read(inode)) {
  1046. check_caps = ceph_inode_set_size(inode, pos);
  1047. if (check_caps)
  1048. ceph_check_caps(ceph_inode(inode),
  1049. CHECK_CAPS_AUTHONLY,
  1050. NULL);
  1051. }
  1052. }
  1053. if (ret != -EOLDSNAPC && written > 0) {
  1054. ret = written;
  1055. iocb->ki_pos = pos;
  1056. }
  1057. return ret;
  1058. }
  1059. /*
  1060. * Wrap generic_file_aio_read with checks for cap bits on the inode.
  1061. * Atomically grab references, so that those bits are not released
  1062. * back to the MDS mid-read.
  1063. *
  1064. * Hmm, the sync read case isn't actually async... should it be?
  1065. */
  1066. static ssize_t ceph_read_iter(struct kiocb *iocb, struct iov_iter *to)
  1067. {
  1068. struct file *filp = iocb->ki_filp;
  1069. struct ceph_file_info *fi = filp->private_data;
  1070. size_t len = iov_iter_count(to);
  1071. struct inode *inode = file_inode(filp);
  1072. struct ceph_inode_info *ci = ceph_inode(inode);
  1073. struct page *pinned_page = NULL;
  1074. ssize_t ret;
  1075. int want, got = 0;
  1076. int retry_op = 0, read = 0;
  1077. again:
  1078. dout("aio_read %p %llx.%llx %llu~%u trying to get caps on %p\n",
  1079. inode, ceph_vinop(inode), iocb->ki_pos, (unsigned)len, inode);
  1080. if (fi->fmode & CEPH_FILE_MODE_LAZY)
  1081. want = CEPH_CAP_FILE_CACHE | CEPH_CAP_FILE_LAZYIO;
  1082. else
  1083. want = CEPH_CAP_FILE_CACHE;
  1084. ret = ceph_get_caps(ci, CEPH_CAP_FILE_RD, want, -1, &got, &pinned_page);
  1085. if (ret < 0)
  1086. return ret;
  1087. if ((got & (CEPH_CAP_FILE_CACHE|CEPH_CAP_FILE_LAZYIO)) == 0 ||
  1088. (iocb->ki_flags & IOCB_DIRECT) ||
  1089. (fi->flags & CEPH_F_SYNC)) {
  1090. dout("aio_sync_read %p %llx.%llx %llu~%u got cap refs on %s\n",
  1091. inode, ceph_vinop(inode), iocb->ki_pos, (unsigned)len,
  1092. ceph_cap_string(got));
  1093. if (ci->i_inline_version == CEPH_INLINE_NONE) {
  1094. if (!retry_op && (iocb->ki_flags & IOCB_DIRECT)) {
  1095. ret = ceph_direct_read_write(iocb, to,
  1096. NULL, NULL);
  1097. if (ret >= 0 && ret < len)
  1098. retry_op = CHECK_EOF;
  1099. } else {
  1100. ret = ceph_sync_read(iocb, to, &retry_op);
  1101. }
  1102. } else {
  1103. retry_op = READ_INLINE;
  1104. }
  1105. } else {
  1106. CEPH_DEFINE_RW_CONTEXT(rw_ctx, got);
  1107. dout("aio_read %p %llx.%llx %llu~%u got cap refs on %s\n",
  1108. inode, ceph_vinop(inode), iocb->ki_pos, (unsigned)len,
  1109. ceph_cap_string(got));
  1110. ceph_add_rw_context(fi, &rw_ctx);
  1111. ret = generic_file_read_iter(iocb, to);
  1112. ceph_del_rw_context(fi, &rw_ctx);
  1113. }
  1114. dout("aio_read %p %llx.%llx dropping cap refs on %s = %d\n",
  1115. inode, ceph_vinop(inode), ceph_cap_string(got), (int)ret);
  1116. if (pinned_page) {
  1117. put_page(pinned_page);
  1118. pinned_page = NULL;
  1119. }
  1120. ceph_put_cap_refs(ci, got);
  1121. if (retry_op > HAVE_RETRIED && ret >= 0) {
  1122. int statret;
  1123. struct page *page = NULL;
  1124. loff_t i_size;
  1125. if (retry_op == READ_INLINE) {
  1126. page = __page_cache_alloc(GFP_KERNEL);
  1127. if (!page)
  1128. return -ENOMEM;
  1129. }
  1130. statret = __ceph_do_getattr(inode, page,
  1131. CEPH_STAT_CAP_INLINE_DATA, !!page);
  1132. if (statret < 0) {
  1133. if (page)
  1134. __free_page(page);
  1135. if (statret == -ENODATA) {
  1136. BUG_ON(retry_op != READ_INLINE);
  1137. goto again;
  1138. }
  1139. return statret;
  1140. }
  1141. i_size = i_size_read(inode);
  1142. if (retry_op == READ_INLINE) {
  1143. BUG_ON(ret > 0 || read > 0);
  1144. if (iocb->ki_pos < i_size &&
  1145. iocb->ki_pos < PAGE_SIZE) {
  1146. loff_t end = min_t(loff_t, i_size,
  1147. iocb->ki_pos + len);
  1148. end = min_t(loff_t, end, PAGE_SIZE);
  1149. if (statret < end)
  1150. zero_user_segment(page, statret, end);
  1151. ret = copy_page_to_iter(page,
  1152. iocb->ki_pos & ~PAGE_MASK,
  1153. end - iocb->ki_pos, to);
  1154. iocb->ki_pos += ret;
  1155. read += ret;
  1156. }
  1157. if (iocb->ki_pos < i_size && read < len) {
  1158. size_t zlen = min_t(size_t, len - read,
  1159. i_size - iocb->ki_pos);
  1160. ret = iov_iter_zero(zlen, to);
  1161. iocb->ki_pos += ret;
  1162. read += ret;
  1163. }
  1164. __free_pages(page, 0);
  1165. return read;
  1166. }
  1167. /* hit EOF or hole? */
  1168. if (retry_op == CHECK_EOF && iocb->ki_pos < i_size &&
  1169. ret < len) {
  1170. dout("sync_read hit hole, ppos %lld < size %lld"
  1171. ", reading more\n", iocb->ki_pos, i_size);
  1172. read += ret;
  1173. len -= ret;
  1174. retry_op = HAVE_RETRIED;
  1175. goto again;
  1176. }
  1177. }
  1178. if (ret >= 0)
  1179. ret += read;
  1180. return ret;
  1181. }
  1182. /*
  1183. * Take cap references to avoid releasing caps to MDS mid-write.
  1184. *
  1185. * If we are synchronous, and write with an old snap context, the OSD
  1186. * may return EOLDSNAPC. In that case, retry the write.. _after_
  1187. * dropping our cap refs and allowing the pending snap to logically
  1188. * complete _before_ this write occurs.
  1189. *
  1190. * If we are near ENOSPC, write synchronously.
  1191. */
  1192. static ssize_t ceph_write_iter(struct kiocb *iocb, struct iov_iter *from)
  1193. {
  1194. struct file *file = iocb->ki_filp;
  1195. struct ceph_file_info *fi = file->private_data;
  1196. struct inode *inode = file_inode(file);
  1197. struct ceph_inode_info *ci = ceph_inode(inode);
  1198. struct ceph_osd_client *osdc =
  1199. &ceph_sb_to_client(inode->i_sb)->client->osdc;
  1200. struct ceph_cap_flush *prealloc_cf;
  1201. ssize_t count, written = 0;
  1202. int err, want, got;
  1203. loff_t pos;
  1204. if (ceph_snap(inode) != CEPH_NOSNAP)
  1205. return -EROFS;
  1206. prealloc_cf = ceph_alloc_cap_flush();
  1207. if (!prealloc_cf)
  1208. return -ENOMEM;
  1209. retry_snap:
  1210. inode_lock(inode);
  1211. /* We can write back this queue in page reclaim */
  1212. current->backing_dev_info = inode_to_bdi(inode);
  1213. if (iocb->ki_flags & IOCB_APPEND) {
  1214. err = ceph_do_getattr(inode, CEPH_STAT_CAP_SIZE, false);
  1215. if (err < 0)
  1216. goto out;
  1217. }
  1218. err = generic_write_checks(iocb, from);
  1219. if (err <= 0)
  1220. goto out;
  1221. pos = iocb->ki_pos;
  1222. count = iov_iter_count(from);
  1223. if (ceph_quota_is_max_bytes_exceeded(inode, pos + count)) {
  1224. err = -EDQUOT;
  1225. goto out;
  1226. }
  1227. err = file_remove_privs(file);
  1228. if (err)
  1229. goto out;
  1230. err = file_update_time(file);
  1231. if (err)
  1232. goto out;
  1233. if (ci->i_inline_version != CEPH_INLINE_NONE) {
  1234. err = ceph_uninline_data(file, NULL);
  1235. if (err < 0)
  1236. goto out;
  1237. }
  1238. /* FIXME: not complete since it doesn't account for being at quota */
  1239. if (ceph_osdmap_flag(osdc, CEPH_OSDMAP_FULL)) {
  1240. err = -ENOSPC;
  1241. goto out;
  1242. }
  1243. dout("aio_write %p %llx.%llx %llu~%zd getting caps. i_size %llu\n",
  1244. inode, ceph_vinop(inode), pos, count, i_size_read(inode));
  1245. if (fi->fmode & CEPH_FILE_MODE_LAZY)
  1246. want = CEPH_CAP_FILE_BUFFER | CEPH_CAP_FILE_LAZYIO;
  1247. else
  1248. want = CEPH_CAP_FILE_BUFFER;
  1249. got = 0;
  1250. err = ceph_get_caps(ci, CEPH_CAP_FILE_WR, want, pos + count,
  1251. &got, NULL);
  1252. if (err < 0)
  1253. goto out;
  1254. dout("aio_write %p %llx.%llx %llu~%zd got cap refs on %s\n",
  1255. inode, ceph_vinop(inode), pos, count, ceph_cap_string(got));
  1256. if ((got & (CEPH_CAP_FILE_BUFFER|CEPH_CAP_FILE_LAZYIO)) == 0 ||
  1257. (iocb->ki_flags & IOCB_DIRECT) || (fi->flags & CEPH_F_SYNC) ||
  1258. (ci->i_ceph_flags & CEPH_I_ERROR_WRITE)) {
  1259. struct ceph_snap_context *snapc;
  1260. struct iov_iter data;
  1261. inode_unlock(inode);
  1262. spin_lock(&ci->i_ceph_lock);
  1263. if (__ceph_have_pending_cap_snap(ci)) {
  1264. struct ceph_cap_snap *capsnap =
  1265. list_last_entry(&ci->i_cap_snaps,
  1266. struct ceph_cap_snap,
  1267. ci_item);
  1268. snapc = ceph_get_snap_context(capsnap->context);
  1269. } else {
  1270. BUG_ON(!ci->i_head_snapc);
  1271. snapc = ceph_get_snap_context(ci->i_head_snapc);
  1272. }
  1273. spin_unlock(&ci->i_ceph_lock);
  1274. /* we might need to revert back to that point */
  1275. data = *from;
  1276. if (iocb->ki_flags & IOCB_DIRECT)
  1277. written = ceph_direct_read_write(iocb, &data, snapc,
  1278. &prealloc_cf);
  1279. else
  1280. written = ceph_sync_write(iocb, &data, pos, snapc);
  1281. if (written > 0)
  1282. iov_iter_advance(from, written);
  1283. ceph_put_snap_context(snapc);
  1284. } else {
  1285. /*
  1286. * No need to acquire the i_truncate_mutex. Because
  1287. * the MDS revokes Fwb caps before sending truncate
  1288. * message to us. We can't get Fwb cap while there
  1289. * are pending vmtruncate. So write and vmtruncate
  1290. * can not run at the same time
  1291. */
  1292. written = generic_perform_write(file, from, pos);
  1293. if (likely(written >= 0))
  1294. iocb->ki_pos = pos + written;
  1295. inode_unlock(inode);
  1296. }
  1297. if (written >= 0) {
  1298. int dirty;
  1299. spin_lock(&ci->i_ceph_lock);
  1300. ci->i_inline_version = CEPH_INLINE_NONE;
  1301. dirty = __ceph_mark_dirty_caps(ci, CEPH_CAP_FILE_WR,
  1302. &prealloc_cf);
  1303. spin_unlock(&ci->i_ceph_lock);
  1304. if (dirty)
  1305. __mark_inode_dirty(inode, dirty);
  1306. if (ceph_quota_is_max_bytes_approaching(inode, iocb->ki_pos))
  1307. ceph_check_caps(ci, CHECK_CAPS_NODELAY, NULL);
  1308. }
  1309. dout("aio_write %p %llx.%llx %llu~%u dropping cap refs on %s\n",
  1310. inode, ceph_vinop(inode), pos, (unsigned)count,
  1311. ceph_cap_string(got));
  1312. ceph_put_cap_refs(ci, got);
  1313. if (written == -EOLDSNAPC) {
  1314. dout("aio_write %p %llx.%llx %llu~%u" "got EOLDSNAPC, retrying\n",
  1315. inode, ceph_vinop(inode), pos, (unsigned)count);
  1316. goto retry_snap;
  1317. }
  1318. if (written >= 0) {
  1319. if (ceph_osdmap_flag(osdc, CEPH_OSDMAP_NEARFULL))
  1320. iocb->ki_flags |= IOCB_DSYNC;
  1321. written = generic_write_sync(iocb, written);
  1322. }
  1323. goto out_unlocked;
  1324. out:
  1325. inode_unlock(inode);
  1326. out_unlocked:
  1327. ceph_free_cap_flush(prealloc_cf);
  1328. current->backing_dev_info = NULL;
  1329. return written ? written : err;
  1330. }
  1331. /*
  1332. * llseek. be sure to verify file size on SEEK_END.
  1333. */
  1334. static loff_t ceph_llseek(struct file *file, loff_t offset, int whence)
  1335. {
  1336. struct inode *inode = file->f_mapping->host;
  1337. loff_t i_size;
  1338. loff_t ret;
  1339. inode_lock(inode);
  1340. if (whence == SEEK_END || whence == SEEK_DATA || whence == SEEK_HOLE) {
  1341. ret = ceph_do_getattr(inode, CEPH_STAT_CAP_SIZE, false);
  1342. if (ret < 0)
  1343. goto out;
  1344. }
  1345. i_size = i_size_read(inode);
  1346. switch (whence) {
  1347. case SEEK_END:
  1348. offset += i_size;
  1349. break;
  1350. case SEEK_CUR:
  1351. /*
  1352. * Here we special-case the lseek(fd, 0, SEEK_CUR)
  1353. * position-querying operation. Avoid rewriting the "same"
  1354. * f_pos value back to the file because a concurrent read(),
  1355. * write() or lseek() might have altered it
  1356. */
  1357. if (offset == 0) {
  1358. ret = file->f_pos;
  1359. goto out;
  1360. }
  1361. offset += file->f_pos;
  1362. break;
  1363. case SEEK_DATA:
  1364. if (offset < 0 || offset >= i_size) {
  1365. ret = -ENXIO;
  1366. goto out;
  1367. }
  1368. break;
  1369. case SEEK_HOLE:
  1370. if (offset < 0 || offset >= i_size) {
  1371. ret = -ENXIO;
  1372. goto out;
  1373. }
  1374. offset = i_size;
  1375. break;
  1376. }
  1377. ret = vfs_setpos(file, offset, inode->i_sb->s_maxbytes);
  1378. out:
  1379. inode_unlock(inode);
  1380. return ret;
  1381. }
  1382. static inline void ceph_zero_partial_page(
  1383. struct inode *inode, loff_t offset, unsigned size)
  1384. {
  1385. struct page *page;
  1386. pgoff_t index = offset >> PAGE_SHIFT;
  1387. page = find_lock_page(inode->i_mapping, index);
  1388. if (page) {
  1389. wait_on_page_writeback(page);
  1390. zero_user(page, offset & (PAGE_SIZE - 1), size);
  1391. unlock_page(page);
  1392. put_page(page);
  1393. }
  1394. }
  1395. static void ceph_zero_pagecache_range(struct inode *inode, loff_t offset,
  1396. loff_t length)
  1397. {
  1398. loff_t nearly = round_up(offset, PAGE_SIZE);
  1399. if (offset < nearly) {
  1400. loff_t size = nearly - offset;
  1401. if (length < size)
  1402. size = length;
  1403. ceph_zero_partial_page(inode, offset, size);
  1404. offset += size;
  1405. length -= size;
  1406. }
  1407. if (length >= PAGE_SIZE) {
  1408. loff_t size = round_down(length, PAGE_SIZE);
  1409. truncate_pagecache_range(inode, offset, offset + size - 1);
  1410. offset += size;
  1411. length -= size;
  1412. }
  1413. if (length)
  1414. ceph_zero_partial_page(inode, offset, length);
  1415. }
  1416. static int ceph_zero_partial_object(struct inode *inode,
  1417. loff_t offset, loff_t *length)
  1418. {
  1419. struct ceph_inode_info *ci = ceph_inode(inode);
  1420. struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
  1421. struct ceph_osd_request *req;
  1422. int ret = 0;
  1423. loff_t zero = 0;
  1424. int op;
  1425. if (!length) {
  1426. op = offset ? CEPH_OSD_OP_DELETE : CEPH_OSD_OP_TRUNCATE;
  1427. length = &zero;
  1428. } else {
  1429. op = CEPH_OSD_OP_ZERO;
  1430. }
  1431. req = ceph_osdc_new_request(&fsc->client->osdc, &ci->i_layout,
  1432. ceph_vino(inode),
  1433. offset, length,
  1434. 0, 1, op,
  1435. CEPH_OSD_FLAG_WRITE,
  1436. NULL, 0, 0, false);
  1437. if (IS_ERR(req)) {
  1438. ret = PTR_ERR(req);
  1439. goto out;
  1440. }
  1441. req->r_mtime = inode->i_mtime;
  1442. ret = ceph_osdc_start_request(&fsc->client->osdc, req, false);
  1443. if (!ret) {
  1444. ret = ceph_osdc_wait_request(&fsc->client->osdc, req);
  1445. if (ret == -ENOENT)
  1446. ret = 0;
  1447. }
  1448. ceph_osdc_put_request(req);
  1449. out:
  1450. return ret;
  1451. }
  1452. static int ceph_zero_objects(struct inode *inode, loff_t offset, loff_t length)
  1453. {
  1454. int ret = 0;
  1455. struct ceph_inode_info *ci = ceph_inode(inode);
  1456. s32 stripe_unit = ci->i_layout.stripe_unit;
  1457. s32 stripe_count = ci->i_layout.stripe_count;
  1458. s32 object_size = ci->i_layout.object_size;
  1459. u64 object_set_size = object_size * stripe_count;
  1460. u64 nearly, t;
  1461. /* round offset up to next period boundary */
  1462. nearly = offset + object_set_size - 1;
  1463. t = nearly;
  1464. nearly -= do_div(t, object_set_size);
  1465. while (length && offset < nearly) {
  1466. loff_t size = length;
  1467. ret = ceph_zero_partial_object(inode, offset, &size);
  1468. if (ret < 0)
  1469. return ret;
  1470. offset += size;
  1471. length -= size;
  1472. }
  1473. while (length >= object_set_size) {
  1474. int i;
  1475. loff_t pos = offset;
  1476. for (i = 0; i < stripe_count; ++i) {
  1477. ret = ceph_zero_partial_object(inode, pos, NULL);
  1478. if (ret < 0)
  1479. return ret;
  1480. pos += stripe_unit;
  1481. }
  1482. offset += object_set_size;
  1483. length -= object_set_size;
  1484. }
  1485. while (length) {
  1486. loff_t size = length;
  1487. ret = ceph_zero_partial_object(inode, offset, &size);
  1488. if (ret < 0)
  1489. return ret;
  1490. offset += size;
  1491. length -= size;
  1492. }
  1493. return ret;
  1494. }
  1495. static long ceph_fallocate(struct file *file, int mode,
  1496. loff_t offset, loff_t length)
  1497. {
  1498. struct ceph_file_info *fi = file->private_data;
  1499. struct inode *inode = file_inode(file);
  1500. struct ceph_inode_info *ci = ceph_inode(inode);
  1501. struct ceph_osd_client *osdc =
  1502. &ceph_inode_to_client(inode)->client->osdc;
  1503. struct ceph_cap_flush *prealloc_cf;
  1504. int want, got = 0;
  1505. int dirty;
  1506. int ret = 0;
  1507. loff_t endoff = 0;
  1508. loff_t size;
  1509. if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE))
  1510. return -EOPNOTSUPP;
  1511. if (!S_ISREG(inode->i_mode))
  1512. return -EOPNOTSUPP;
  1513. prealloc_cf = ceph_alloc_cap_flush();
  1514. if (!prealloc_cf)
  1515. return -ENOMEM;
  1516. inode_lock(inode);
  1517. if (ceph_snap(inode) != CEPH_NOSNAP) {
  1518. ret = -EROFS;
  1519. goto unlock;
  1520. }
  1521. if (!(mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE)) &&
  1522. ceph_quota_is_max_bytes_exceeded(inode, offset + length)) {
  1523. ret = -EDQUOT;
  1524. goto unlock;
  1525. }
  1526. if (ceph_osdmap_flag(osdc, CEPH_OSDMAP_FULL) &&
  1527. !(mode & FALLOC_FL_PUNCH_HOLE)) {
  1528. ret = -ENOSPC;
  1529. goto unlock;
  1530. }
  1531. if (ci->i_inline_version != CEPH_INLINE_NONE) {
  1532. ret = ceph_uninline_data(file, NULL);
  1533. if (ret < 0)
  1534. goto unlock;
  1535. }
  1536. size = i_size_read(inode);
  1537. if (!(mode & FALLOC_FL_KEEP_SIZE)) {
  1538. endoff = offset + length;
  1539. ret = inode_newsize_ok(inode, endoff);
  1540. if (ret)
  1541. goto unlock;
  1542. }
  1543. if (fi->fmode & CEPH_FILE_MODE_LAZY)
  1544. want = CEPH_CAP_FILE_BUFFER | CEPH_CAP_FILE_LAZYIO;
  1545. else
  1546. want = CEPH_CAP_FILE_BUFFER;
  1547. ret = ceph_get_caps(ci, CEPH_CAP_FILE_WR, want, endoff, &got, NULL);
  1548. if (ret < 0)
  1549. goto unlock;
  1550. if (mode & FALLOC_FL_PUNCH_HOLE) {
  1551. if (offset < size)
  1552. ceph_zero_pagecache_range(inode, offset, length);
  1553. ret = ceph_zero_objects(inode, offset, length);
  1554. } else if (endoff > size) {
  1555. truncate_pagecache_range(inode, size, -1);
  1556. if (ceph_inode_set_size(inode, endoff))
  1557. ceph_check_caps(ceph_inode(inode),
  1558. CHECK_CAPS_AUTHONLY, NULL);
  1559. }
  1560. if (!ret) {
  1561. spin_lock(&ci->i_ceph_lock);
  1562. ci->i_inline_version = CEPH_INLINE_NONE;
  1563. dirty = __ceph_mark_dirty_caps(ci, CEPH_CAP_FILE_WR,
  1564. &prealloc_cf);
  1565. spin_unlock(&ci->i_ceph_lock);
  1566. if (dirty)
  1567. __mark_inode_dirty(inode, dirty);
  1568. if ((endoff > size) &&
  1569. ceph_quota_is_max_bytes_approaching(inode, endoff))
  1570. ceph_check_caps(ci, CHECK_CAPS_NODELAY, NULL);
  1571. }
  1572. ceph_put_cap_refs(ci, got);
  1573. unlock:
  1574. inode_unlock(inode);
  1575. ceph_free_cap_flush(prealloc_cf);
  1576. return ret;
  1577. }
  1578. const struct file_operations ceph_file_fops = {
  1579. .open = ceph_open,
  1580. .release = ceph_release,
  1581. .llseek = ceph_llseek,
  1582. .read_iter = ceph_read_iter,
  1583. .write_iter = ceph_write_iter,
  1584. .mmap = ceph_mmap,
  1585. .fsync = ceph_fsync,
  1586. .lock = ceph_lock,
  1587. .flock = ceph_flock,
  1588. .splice_read = generic_file_splice_read,
  1589. .splice_write = iter_file_splice_write,
  1590. .unlocked_ioctl = ceph_ioctl,
  1591. .compat_ioctl = ceph_ioctl,
  1592. .fallocate = ceph_fallocate,
  1593. };