addr.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266
  1. #include <linux/ceph/ceph_debug.h>
  2. #include <linux/backing-dev.h>
  3. #include <linux/fs.h>
  4. #include <linux/mm.h>
  5. #include <linux/pagemap.h>
  6. #include <linux/writeback.h> /* generic_writepages */
  7. #include <linux/slab.h>
  8. #include <linux/pagevec.h>
  9. #include <linux/task_io_accounting_ops.h>
  10. #include "super.h"
  11. #include "mds_client.h"
  12. #include <linux/ceph/osd_client.h>
  13. /*
  14. * Ceph address space ops.
  15. *
  16. * There are a few funny things going on here.
  17. *
  18. * The page->private field is used to reference a struct
  19. * ceph_snap_context for _every_ dirty page. This indicates which
  20. * snapshot the page was logically dirtied in, and thus which snap
  21. * context needs to be associated with the osd write during writeback.
  22. *
  23. * Similarly, struct ceph_inode_info maintains a set of counters to
  24. * count dirty pages on the inode. In the absence of snapshots,
  25. * i_wrbuffer_ref == i_wrbuffer_ref_head == the dirty page count.
  26. *
  27. * When a snapshot is taken (that is, when the client receives
  28. * notification that a snapshot was taken), each inode with caps and
  29. * with dirty pages (dirty pages implies there is a cap) gets a new
  30. * ceph_cap_snap in the i_cap_snaps list (which is sorted in ascending
  31. * order, new snaps go to the tail). The i_wrbuffer_ref_head count is
  32. * moved to capsnap->dirty. (Unless a sync write is currently in
  33. * progress. In that case, the capsnap is said to be "pending", new
  34. * writes cannot start, and the capsnap isn't "finalized" until the
  35. * write completes (or fails) and a final size/mtime for the inode for
  36. * that snap can be settled upon.) i_wrbuffer_ref_head is reset to 0.
  37. *
  38. * On writeback, we must submit writes to the osd IN SNAP ORDER. So,
  39. * we look for the first capsnap in i_cap_snaps and write out pages in
  40. * that snap context _only_. Then we move on to the next capsnap,
  41. * eventually reaching the "live" or "head" context (i.e., pages that
  42. * are not yet snapped) and are writing the most recently dirtied
  43. * pages.
  44. *
  45. * Invalidate and so forth must take care to ensure the dirty page
  46. * accounting is preserved.
  47. */
  48. #define CONGESTION_ON_THRESH(congestion_kb) (congestion_kb >> (PAGE_SHIFT-10))
  49. #define CONGESTION_OFF_THRESH(congestion_kb) \
  50. (CONGESTION_ON_THRESH(congestion_kb) - \
  51. (CONGESTION_ON_THRESH(congestion_kb) >> 2))
  52. static inline struct ceph_snap_context *page_snap_context(struct page *page)
  53. {
  54. if (PagePrivate(page))
  55. return (void *)page->private;
  56. return NULL;
  57. }
  58. /*
  59. * Dirty a page. Optimistically adjust accounting, on the assumption
  60. * that we won't race with invalidate. If we do, readjust.
  61. */
  62. static int ceph_set_page_dirty(struct page *page)
  63. {
  64. struct address_space *mapping = page->mapping;
  65. struct inode *inode;
  66. struct ceph_inode_info *ci;
  67. int undo = 0;
  68. struct ceph_snap_context *snapc;
  69. if (unlikely(!mapping))
  70. return !TestSetPageDirty(page);
  71. if (TestSetPageDirty(page)) {
  72. dout("%p set_page_dirty %p idx %lu -- already dirty\n",
  73. mapping->host, page, page->index);
  74. return 0;
  75. }
  76. inode = mapping->host;
  77. ci = ceph_inode(inode);
  78. /*
  79. * Note that we're grabbing a snapc ref here without holding
  80. * any locks!
  81. */
  82. snapc = ceph_get_snap_context(ci->i_snap_realm->cached_context);
  83. /* dirty the head */
  84. spin_lock(&ci->i_ceph_lock);
  85. if (ci->i_head_snapc == NULL)
  86. ci->i_head_snapc = ceph_get_snap_context(snapc);
  87. ++ci->i_wrbuffer_ref_head;
  88. if (ci->i_wrbuffer_ref == 0)
  89. ihold(inode);
  90. ++ci->i_wrbuffer_ref;
  91. dout("%p set_page_dirty %p idx %lu head %d/%d -> %d/%d "
  92. "snapc %p seq %lld (%d snaps)\n",
  93. mapping->host, page, page->index,
  94. ci->i_wrbuffer_ref-1, ci->i_wrbuffer_ref_head-1,
  95. ci->i_wrbuffer_ref, ci->i_wrbuffer_ref_head,
  96. snapc, snapc->seq, snapc->num_snaps);
  97. spin_unlock(&ci->i_ceph_lock);
  98. /* now adjust page */
  99. spin_lock_irq(&mapping->tree_lock);
  100. if (page->mapping) { /* Race with truncate? */
  101. WARN_ON_ONCE(!PageUptodate(page));
  102. account_page_dirtied(page, page->mapping);
  103. radix_tree_tag_set(&mapping->page_tree,
  104. page_index(page), PAGECACHE_TAG_DIRTY);
  105. /*
  106. * Reference snap context in page->private. Also set
  107. * PagePrivate so that we get invalidatepage callback.
  108. */
  109. page->private = (unsigned long)snapc;
  110. SetPagePrivate(page);
  111. } else {
  112. dout("ANON set_page_dirty %p (raced truncate?)\n", page);
  113. undo = 1;
  114. }
  115. spin_unlock_irq(&mapping->tree_lock);
  116. if (undo)
  117. /* whoops, we failed to dirty the page */
  118. ceph_put_wrbuffer_cap_refs(ci, 1, snapc);
  119. __mark_inode_dirty(mapping->host, I_DIRTY_PAGES);
  120. BUG_ON(!PageDirty(page));
  121. return 1;
  122. }
  123. /*
  124. * If we are truncating the full page (i.e. offset == 0), adjust the
  125. * dirty page counters appropriately. Only called if there is private
  126. * data on the page.
  127. */
  128. static void ceph_invalidatepage(struct page *page, unsigned long offset)
  129. {
  130. struct inode *inode;
  131. struct ceph_inode_info *ci;
  132. struct ceph_snap_context *snapc = page_snap_context(page);
  133. BUG_ON(!PageLocked(page));
  134. BUG_ON(!PagePrivate(page));
  135. BUG_ON(!page->mapping);
  136. inode = page->mapping->host;
  137. /*
  138. * We can get non-dirty pages here due to races between
  139. * set_page_dirty and truncate_complete_page; just spit out a
  140. * warning, in case we end up with accounting problems later.
  141. */
  142. if (!PageDirty(page))
  143. pr_err("%p invalidatepage %p page not dirty\n", inode, page);
  144. if (offset == 0)
  145. ClearPageChecked(page);
  146. ci = ceph_inode(inode);
  147. if (offset == 0) {
  148. dout("%p invalidatepage %p idx %lu full dirty page %lu\n",
  149. inode, page, page->index, offset);
  150. ceph_put_wrbuffer_cap_refs(ci, 1, snapc);
  151. ceph_put_snap_context(snapc);
  152. page->private = 0;
  153. ClearPagePrivate(page);
  154. } else {
  155. dout("%p invalidatepage %p idx %lu partial dirty page\n",
  156. inode, page, page->index);
  157. }
  158. }
  159. /* just a sanity check */
  160. static int ceph_releasepage(struct page *page, gfp_t g)
  161. {
  162. struct inode *inode = page->mapping ? page->mapping->host : NULL;
  163. dout("%p releasepage %p idx %lu\n", inode, page, page->index);
  164. WARN_ON(PageDirty(page));
  165. WARN_ON(PagePrivate(page));
  166. return 0;
  167. }
  168. /*
  169. * read a single page, without unlocking it.
  170. */
  171. static int readpage_nounlock(struct file *filp, struct page *page)
  172. {
  173. struct inode *inode = file_inode(filp);
  174. struct ceph_inode_info *ci = ceph_inode(inode);
  175. struct ceph_osd_client *osdc =
  176. &ceph_inode_to_client(inode)->client->osdc;
  177. int err = 0;
  178. u64 len = PAGE_CACHE_SIZE;
  179. dout("readpage inode %p file %p page %p index %lu\n",
  180. inode, filp, page, page->index);
  181. err = ceph_osdc_readpages(osdc, ceph_vino(inode), &ci->i_layout,
  182. (u64) page_offset(page), &len,
  183. ci->i_truncate_seq, ci->i_truncate_size,
  184. &page, 1, 0);
  185. if (err == -ENOENT)
  186. err = 0;
  187. if (err < 0) {
  188. SetPageError(page);
  189. goto out;
  190. } else if (err < PAGE_CACHE_SIZE) {
  191. /* zero fill remainder of page */
  192. zero_user_segment(page, err, PAGE_CACHE_SIZE);
  193. }
  194. SetPageUptodate(page);
  195. out:
  196. return err < 0 ? err : 0;
  197. }
  198. static int ceph_readpage(struct file *filp, struct page *page)
  199. {
  200. int r = readpage_nounlock(filp, page);
  201. unlock_page(page);
  202. return r;
  203. }
  204. /*
  205. * Finish an async read(ahead) op.
  206. */
  207. static void finish_read(struct ceph_osd_request *req, struct ceph_msg *msg)
  208. {
  209. struct inode *inode = req->r_inode;
  210. struct ceph_osd_data *osd_data;
  211. int rc = req->r_result;
  212. int bytes = le32_to_cpu(msg->hdr.data_len);
  213. int num_pages;
  214. int i;
  215. dout("finish_read %p req %p rc %d bytes %d\n", inode, req, rc, bytes);
  216. /* unlock all pages, zeroing any data we didn't read */
  217. osd_data = osd_req_op_extent_osd_data(req, 0, false);
  218. BUG_ON(osd_data->type != CEPH_OSD_DATA_TYPE_PAGES);
  219. num_pages = calc_pages_for((u64)osd_data->alignment,
  220. (u64)osd_data->length);
  221. for (i = 0; i < num_pages; i++) {
  222. struct page *page = osd_data->pages[i];
  223. if (bytes < (int)PAGE_CACHE_SIZE) {
  224. /* zero (remainder of) page */
  225. int s = bytes < 0 ? 0 : bytes;
  226. zero_user_segment(page, s, PAGE_CACHE_SIZE);
  227. }
  228. dout("finish_read %p uptodate %p idx %lu\n", inode, page,
  229. page->index);
  230. flush_dcache_page(page);
  231. SetPageUptodate(page);
  232. unlock_page(page);
  233. page_cache_release(page);
  234. bytes -= PAGE_CACHE_SIZE;
  235. }
  236. kfree(osd_data->pages);
  237. }
  238. static void ceph_unlock_page_vector(struct page **pages, int num_pages)
  239. {
  240. int i;
  241. for (i = 0; i < num_pages; i++)
  242. unlock_page(pages[i]);
  243. }
  244. /*
  245. * start an async read(ahead) operation. return nr_pages we submitted
  246. * a read for on success, or negative error code.
  247. */
  248. static int start_read(struct inode *inode, struct list_head *page_list, int max)
  249. {
  250. struct ceph_osd_client *osdc =
  251. &ceph_inode_to_client(inode)->client->osdc;
  252. struct ceph_inode_info *ci = ceph_inode(inode);
  253. struct page *page = list_entry(page_list->prev, struct page, lru);
  254. struct ceph_vino vino;
  255. struct ceph_osd_request *req;
  256. u64 off;
  257. u64 len;
  258. int i;
  259. struct page **pages;
  260. pgoff_t next_index;
  261. int nr_pages = 0;
  262. int ret;
  263. off = (u64) page_offset(page);
  264. /* count pages */
  265. next_index = page->index;
  266. list_for_each_entry_reverse(page, page_list, lru) {
  267. if (page->index != next_index)
  268. break;
  269. nr_pages++;
  270. next_index++;
  271. if (max && nr_pages == max)
  272. break;
  273. }
  274. len = nr_pages << PAGE_CACHE_SHIFT;
  275. dout("start_read %p nr_pages %d is %lld~%lld\n", inode, nr_pages,
  276. off, len);
  277. vino = ceph_vino(inode);
  278. req = ceph_osdc_new_request(osdc, &ci->i_layout, vino, off, &len,
  279. 1, CEPH_OSD_OP_READ,
  280. CEPH_OSD_FLAG_READ, NULL,
  281. ci->i_truncate_seq, ci->i_truncate_size,
  282. false);
  283. if (IS_ERR(req))
  284. return PTR_ERR(req);
  285. /* build page vector */
  286. nr_pages = calc_pages_for(0, len);
  287. pages = kmalloc(sizeof(*pages) * nr_pages, GFP_NOFS);
  288. ret = -ENOMEM;
  289. if (!pages)
  290. goto out;
  291. for (i = 0; i < nr_pages; ++i) {
  292. page = list_entry(page_list->prev, struct page, lru);
  293. BUG_ON(PageLocked(page));
  294. list_del(&page->lru);
  295. dout("start_read %p adding %p idx %lu\n", inode, page,
  296. page->index);
  297. if (add_to_page_cache_lru(page, &inode->i_data, page->index,
  298. GFP_NOFS)) {
  299. page_cache_release(page);
  300. dout("start_read %p add_to_page_cache failed %p\n",
  301. inode, page);
  302. nr_pages = i;
  303. goto out_pages;
  304. }
  305. pages[i] = page;
  306. }
  307. osd_req_op_extent_osd_data_pages(req, 0, false, pages, len, 0,
  308. false, false);
  309. req->r_callback = finish_read;
  310. req->r_inode = inode;
  311. ceph_osdc_build_request(req, off, NULL, vino.snap, NULL);
  312. dout("start_read %p starting %p %lld~%lld\n", inode, req, off, len);
  313. ret = ceph_osdc_start_request(osdc, req, false);
  314. if (ret < 0)
  315. goto out_pages;
  316. ceph_osdc_put_request(req);
  317. return nr_pages;
  318. out_pages:
  319. ceph_unlock_page_vector(pages, nr_pages);
  320. ceph_release_page_vector(pages, nr_pages);
  321. out:
  322. ceph_osdc_put_request(req);
  323. return ret;
  324. }
  325. /*
  326. * Read multiple pages. Leave pages we don't read + unlock in page_list;
  327. * the caller (VM) cleans them up.
  328. */
  329. static int ceph_readpages(struct file *file, struct address_space *mapping,
  330. struct list_head *page_list, unsigned nr_pages)
  331. {
  332. struct inode *inode = file_inode(file);
  333. struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
  334. int rc = 0;
  335. int max = 0;
  336. if (fsc->mount_options->rsize >= PAGE_CACHE_SIZE)
  337. max = (fsc->mount_options->rsize + PAGE_CACHE_SIZE - 1)
  338. >> PAGE_SHIFT;
  339. dout("readpages %p file %p nr_pages %d max %d\n", inode,
  340. file, nr_pages,
  341. max);
  342. while (!list_empty(page_list)) {
  343. rc = start_read(inode, page_list, max);
  344. if (rc < 0)
  345. goto out;
  346. BUG_ON(rc == 0);
  347. }
  348. out:
  349. dout("readpages %p file %p ret %d\n", inode, file, rc);
  350. return rc;
  351. }
  352. /*
  353. * Get ref for the oldest snapc for an inode with dirty data... that is, the
  354. * only snap context we are allowed to write back.
  355. */
  356. static struct ceph_snap_context *get_oldest_context(struct inode *inode,
  357. u64 *snap_size)
  358. {
  359. struct ceph_inode_info *ci = ceph_inode(inode);
  360. struct ceph_snap_context *snapc = NULL;
  361. struct ceph_cap_snap *capsnap = NULL;
  362. spin_lock(&ci->i_ceph_lock);
  363. list_for_each_entry(capsnap, &ci->i_cap_snaps, ci_item) {
  364. dout(" cap_snap %p snapc %p has %d dirty pages\n", capsnap,
  365. capsnap->context, capsnap->dirty_pages);
  366. if (capsnap->dirty_pages) {
  367. snapc = ceph_get_snap_context(capsnap->context);
  368. if (snap_size)
  369. *snap_size = capsnap->size;
  370. break;
  371. }
  372. }
  373. if (!snapc && ci->i_wrbuffer_ref_head) {
  374. snapc = ceph_get_snap_context(ci->i_head_snapc);
  375. dout(" head snapc %p has %d dirty pages\n",
  376. snapc, ci->i_wrbuffer_ref_head);
  377. }
  378. spin_unlock(&ci->i_ceph_lock);
  379. return snapc;
  380. }
  381. /*
  382. * Write a single page, but leave the page locked.
  383. *
  384. * If we get a write error, set the page error bit, but still adjust the
  385. * dirty page accounting (i.e., page is no longer dirty).
  386. */
  387. static int writepage_nounlock(struct page *page, struct writeback_control *wbc)
  388. {
  389. struct inode *inode;
  390. struct ceph_inode_info *ci;
  391. struct ceph_fs_client *fsc;
  392. struct ceph_osd_client *osdc;
  393. loff_t page_off = page_offset(page);
  394. int len = PAGE_CACHE_SIZE;
  395. loff_t i_size;
  396. int err = 0;
  397. struct ceph_snap_context *snapc, *oldest;
  398. u64 snap_size = 0;
  399. long writeback_stat;
  400. dout("writepage %p idx %lu\n", page, page->index);
  401. if (!page->mapping || !page->mapping->host) {
  402. dout("writepage %p - no mapping\n", page);
  403. return -EFAULT;
  404. }
  405. inode = page->mapping->host;
  406. ci = ceph_inode(inode);
  407. fsc = ceph_inode_to_client(inode);
  408. osdc = &fsc->client->osdc;
  409. /* verify this is a writeable snap context */
  410. snapc = page_snap_context(page);
  411. if (snapc == NULL) {
  412. dout("writepage %p page %p not dirty?\n", inode, page);
  413. goto out;
  414. }
  415. oldest = get_oldest_context(inode, &snap_size);
  416. if (snapc->seq > oldest->seq) {
  417. dout("writepage %p page %p snapc %p not writeable - noop\n",
  418. inode, page, snapc);
  419. /* we should only noop if called by kswapd */
  420. WARN_ON((current->flags & PF_MEMALLOC) == 0);
  421. ceph_put_snap_context(oldest);
  422. goto out;
  423. }
  424. ceph_put_snap_context(oldest);
  425. /* is this a partial page at end of file? */
  426. if (snap_size)
  427. i_size = snap_size;
  428. else
  429. i_size = i_size_read(inode);
  430. if (i_size < page_off + len)
  431. len = i_size - page_off;
  432. dout("writepage %p page %p index %lu on %llu~%u snapc %p\n",
  433. inode, page, page->index, page_off, len, snapc);
  434. writeback_stat = atomic_long_inc_return(&fsc->writeback_count);
  435. if (writeback_stat >
  436. CONGESTION_ON_THRESH(fsc->mount_options->congestion_kb))
  437. set_bdi_congested(&fsc->backing_dev_info, BLK_RW_ASYNC);
  438. set_page_writeback(page);
  439. err = ceph_osdc_writepages(osdc, ceph_vino(inode),
  440. &ci->i_layout, snapc,
  441. page_off, len,
  442. ci->i_truncate_seq, ci->i_truncate_size,
  443. &inode->i_mtime, &page, 1);
  444. if (err < 0) {
  445. dout("writepage setting page/mapping error %d %p\n", err, page);
  446. SetPageError(page);
  447. mapping_set_error(&inode->i_data, err);
  448. if (wbc)
  449. wbc->pages_skipped++;
  450. } else {
  451. dout("writepage cleaned page %p\n", page);
  452. err = 0; /* vfs expects us to return 0 */
  453. }
  454. page->private = 0;
  455. ClearPagePrivate(page);
  456. end_page_writeback(page);
  457. ceph_put_wrbuffer_cap_refs(ci, 1, snapc);
  458. ceph_put_snap_context(snapc); /* page's reference */
  459. out:
  460. return err;
  461. }
  462. static int ceph_writepage(struct page *page, struct writeback_control *wbc)
  463. {
  464. int err;
  465. struct inode *inode = page->mapping->host;
  466. BUG_ON(!inode);
  467. ihold(inode);
  468. err = writepage_nounlock(page, wbc);
  469. unlock_page(page);
  470. iput(inode);
  471. return err;
  472. }
  473. /*
  474. * lame release_pages helper. release_pages() isn't exported to
  475. * modules.
  476. */
  477. static void ceph_release_pages(struct page **pages, int num)
  478. {
  479. struct pagevec pvec;
  480. int i;
  481. pagevec_init(&pvec, 0);
  482. for (i = 0; i < num; i++) {
  483. if (pagevec_add(&pvec, pages[i]) == 0)
  484. pagevec_release(&pvec);
  485. }
  486. pagevec_release(&pvec);
  487. }
  488. /*
  489. * async writeback completion handler.
  490. *
  491. * If we get an error, set the mapping error bit, but not the individual
  492. * page error bits.
  493. */
  494. static void writepages_finish(struct ceph_osd_request *req,
  495. struct ceph_msg *msg)
  496. {
  497. struct inode *inode = req->r_inode;
  498. struct ceph_inode_info *ci = ceph_inode(inode);
  499. struct ceph_osd_data *osd_data;
  500. unsigned wrote;
  501. struct page *page;
  502. int num_pages;
  503. int i;
  504. struct ceph_snap_context *snapc = req->r_snapc;
  505. struct address_space *mapping = inode->i_mapping;
  506. int rc = req->r_result;
  507. u64 bytes = req->r_ops[0].extent.length;
  508. struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
  509. long writeback_stat;
  510. unsigned issued = ceph_caps_issued(ci);
  511. osd_data = osd_req_op_extent_osd_data(req, 0, true);
  512. BUG_ON(osd_data->type != CEPH_OSD_DATA_TYPE_PAGES);
  513. num_pages = calc_pages_for((u64)osd_data->alignment,
  514. (u64)osd_data->length);
  515. if (rc >= 0) {
  516. /*
  517. * Assume we wrote the pages we originally sent. The
  518. * osd might reply with fewer pages if our writeback
  519. * raced with a truncation and was adjusted at the osd,
  520. * so don't believe the reply.
  521. */
  522. wrote = num_pages;
  523. } else {
  524. wrote = 0;
  525. mapping_set_error(mapping, rc);
  526. }
  527. dout("writepages_finish %p rc %d bytes %llu wrote %d (pages)\n",
  528. inode, rc, bytes, wrote);
  529. /* clean all pages */
  530. for (i = 0; i < num_pages; i++) {
  531. page = osd_data->pages[i];
  532. BUG_ON(!page);
  533. WARN_ON(!PageUptodate(page));
  534. writeback_stat =
  535. atomic_long_dec_return(&fsc->writeback_count);
  536. if (writeback_stat <
  537. CONGESTION_OFF_THRESH(fsc->mount_options->congestion_kb))
  538. clear_bdi_congested(&fsc->backing_dev_info,
  539. BLK_RW_ASYNC);
  540. ceph_put_snap_context(page_snap_context(page));
  541. page->private = 0;
  542. ClearPagePrivate(page);
  543. dout("unlocking %d %p\n", i, page);
  544. end_page_writeback(page);
  545. /*
  546. * We lost the cache cap, need to truncate the page before
  547. * it is unlocked, otherwise we'd truncate it later in the
  548. * page truncation thread, possibly losing some data that
  549. * raced its way in
  550. */
  551. if ((issued & (CEPH_CAP_FILE_CACHE|CEPH_CAP_FILE_LAZYIO)) == 0)
  552. generic_error_remove_page(inode->i_mapping, page);
  553. unlock_page(page);
  554. }
  555. dout("%p wrote+cleaned %d pages\n", inode, wrote);
  556. ceph_put_wrbuffer_cap_refs(ci, num_pages, snapc);
  557. ceph_release_pages(osd_data->pages, num_pages);
  558. if (osd_data->pages_from_pool)
  559. mempool_free(osd_data->pages,
  560. ceph_sb_to_client(inode->i_sb)->wb_pagevec_pool);
  561. else
  562. kfree(osd_data->pages);
  563. ceph_osdc_put_request(req);
  564. }
  565. static struct ceph_osd_request *
  566. ceph_writepages_osd_request(struct inode *inode, u64 offset, u64 *len,
  567. struct ceph_snap_context *snapc, int num_ops)
  568. {
  569. struct ceph_fs_client *fsc;
  570. struct ceph_inode_info *ci;
  571. struct ceph_vino vino;
  572. fsc = ceph_inode_to_client(inode);
  573. ci = ceph_inode(inode);
  574. vino = ceph_vino(inode);
  575. /* BUG_ON(vino.snap != CEPH_NOSNAP); */
  576. return ceph_osdc_new_request(&fsc->client->osdc, &ci->i_layout,
  577. vino, offset, len, num_ops, CEPH_OSD_OP_WRITE,
  578. CEPH_OSD_FLAG_WRITE|CEPH_OSD_FLAG_ONDISK,
  579. snapc, ci->i_truncate_seq, ci->i_truncate_size, true);
  580. }
  581. /*
  582. * initiate async writeback
  583. */
  584. static int ceph_writepages_start(struct address_space *mapping,
  585. struct writeback_control *wbc)
  586. {
  587. struct inode *inode = mapping->host;
  588. struct ceph_inode_info *ci = ceph_inode(inode);
  589. struct ceph_fs_client *fsc;
  590. pgoff_t index, start, end;
  591. int range_whole = 0;
  592. int should_loop = 1;
  593. pgoff_t max_pages = 0, max_pages_ever = 0;
  594. struct ceph_snap_context *snapc = NULL, *last_snapc = NULL, *pgsnapc;
  595. struct pagevec pvec;
  596. int done = 0;
  597. int rc = 0;
  598. unsigned wsize = 1 << inode->i_blkbits;
  599. struct ceph_osd_request *req = NULL;
  600. int do_sync;
  601. u64 snap_size;
  602. /*
  603. * Include a 'sync' in the OSD request if this is a data
  604. * integrity write (e.g., O_SYNC write or fsync()), or if our
  605. * cap is being revoked.
  606. */
  607. do_sync = wbc->sync_mode == WB_SYNC_ALL;
  608. if (ceph_caps_revoking(ci, CEPH_CAP_FILE_BUFFER))
  609. do_sync = 1;
  610. dout("writepages_start %p dosync=%d (mode=%s)\n",
  611. inode, do_sync,
  612. wbc->sync_mode == WB_SYNC_NONE ? "NONE" :
  613. (wbc->sync_mode == WB_SYNC_ALL ? "ALL" : "HOLD"));
  614. fsc = ceph_inode_to_client(inode);
  615. if (fsc->mount_state == CEPH_MOUNT_SHUTDOWN) {
  616. pr_warning("writepage_start %p on forced umount\n", inode);
  617. return -EIO; /* we're in a forced umount, don't write! */
  618. }
  619. if (fsc->mount_options->wsize && fsc->mount_options->wsize < wsize)
  620. wsize = fsc->mount_options->wsize;
  621. if (wsize < PAGE_CACHE_SIZE)
  622. wsize = PAGE_CACHE_SIZE;
  623. max_pages_ever = wsize >> PAGE_CACHE_SHIFT;
  624. pagevec_init(&pvec, 0);
  625. /* where to start/end? */
  626. if (wbc->range_cyclic) {
  627. start = mapping->writeback_index; /* Start from prev offset */
  628. end = -1;
  629. dout(" cyclic, start at %lu\n", start);
  630. } else {
  631. start = wbc->range_start >> PAGE_CACHE_SHIFT;
  632. end = wbc->range_end >> PAGE_CACHE_SHIFT;
  633. if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
  634. range_whole = 1;
  635. should_loop = 0;
  636. dout(" not cyclic, %lu to %lu\n", start, end);
  637. }
  638. index = start;
  639. retry:
  640. /* find oldest snap context with dirty data */
  641. ceph_put_snap_context(snapc);
  642. snap_size = 0;
  643. snapc = get_oldest_context(inode, &snap_size);
  644. if (!snapc) {
  645. /* hmm, why does writepages get called when there
  646. is no dirty data? */
  647. dout(" no snap context with dirty data?\n");
  648. goto out;
  649. }
  650. if (snap_size == 0)
  651. snap_size = i_size_read(inode);
  652. dout(" oldest snapc is %p seq %lld (%d snaps)\n",
  653. snapc, snapc->seq, snapc->num_snaps);
  654. if (last_snapc && snapc != last_snapc) {
  655. /* if we switched to a newer snapc, restart our scan at the
  656. * start of the original file range. */
  657. dout(" snapc differs from last pass, restarting at %lu\n",
  658. index);
  659. index = start;
  660. }
  661. last_snapc = snapc;
  662. while (!done && index <= end) {
  663. int num_ops = do_sync ? 2 : 1;
  664. struct ceph_vino vino;
  665. unsigned i;
  666. int first;
  667. pgoff_t next;
  668. int pvec_pages, locked_pages;
  669. struct page **pages = NULL;
  670. mempool_t *pool = NULL; /* Becomes non-null if mempool used */
  671. struct page *page;
  672. int want;
  673. u64 offset, len;
  674. long writeback_stat;
  675. next = 0;
  676. locked_pages = 0;
  677. max_pages = max_pages_ever;
  678. get_more_pages:
  679. first = -1;
  680. want = min(end - index,
  681. min((pgoff_t)PAGEVEC_SIZE,
  682. max_pages - (pgoff_t)locked_pages) - 1)
  683. + 1;
  684. pvec_pages = pagevec_lookup_tag(&pvec, mapping, &index,
  685. PAGECACHE_TAG_DIRTY,
  686. want);
  687. dout("pagevec_lookup_tag got %d\n", pvec_pages);
  688. if (!pvec_pages && !locked_pages)
  689. break;
  690. for (i = 0; i < pvec_pages && locked_pages < max_pages; i++) {
  691. page = pvec.pages[i];
  692. dout("? %p idx %lu\n", page, page->index);
  693. if (locked_pages == 0)
  694. lock_page(page); /* first page */
  695. else if (!trylock_page(page))
  696. break;
  697. /* only dirty pages, or our accounting breaks */
  698. if (unlikely(!PageDirty(page)) ||
  699. unlikely(page->mapping != mapping)) {
  700. dout("!dirty or !mapping %p\n", page);
  701. unlock_page(page);
  702. break;
  703. }
  704. if (!wbc->range_cyclic && page->index > end) {
  705. dout("end of range %p\n", page);
  706. done = 1;
  707. unlock_page(page);
  708. break;
  709. }
  710. if (next && (page->index != next)) {
  711. dout("not consecutive %p\n", page);
  712. unlock_page(page);
  713. break;
  714. }
  715. if (wbc->sync_mode != WB_SYNC_NONE) {
  716. dout("waiting on writeback %p\n", page);
  717. wait_on_page_writeback(page);
  718. }
  719. if (page_offset(page) >= snap_size) {
  720. dout("%p page eof %llu\n", page, snap_size);
  721. done = 1;
  722. unlock_page(page);
  723. break;
  724. }
  725. if (PageWriteback(page)) {
  726. dout("%p under writeback\n", page);
  727. unlock_page(page);
  728. break;
  729. }
  730. /* only if matching snap context */
  731. pgsnapc = page_snap_context(page);
  732. if (pgsnapc->seq > snapc->seq) {
  733. dout("page snapc %p %lld > oldest %p %lld\n",
  734. pgsnapc, pgsnapc->seq, snapc, snapc->seq);
  735. unlock_page(page);
  736. if (!locked_pages)
  737. continue; /* keep looking for snap */
  738. break;
  739. }
  740. if (!clear_page_dirty_for_io(page)) {
  741. dout("%p !clear_page_dirty_for_io\n", page);
  742. unlock_page(page);
  743. break;
  744. }
  745. /*
  746. * We have something to write. If this is
  747. * the first locked page this time through,
  748. * allocate an osd request and a page array
  749. * that it will use.
  750. */
  751. if (locked_pages == 0) {
  752. size_t size;
  753. BUG_ON(pages);
  754. /* prepare async write request */
  755. offset = (u64)page_offset(page);
  756. len = wsize;
  757. req = ceph_writepages_osd_request(inode,
  758. offset, &len, snapc,
  759. num_ops);
  760. if (IS_ERR(req)) {
  761. rc = PTR_ERR(req);
  762. unlock_page(page);
  763. break;
  764. }
  765. req->r_callback = writepages_finish;
  766. req->r_inode = inode;
  767. max_pages = calc_pages_for(0, (u64)len);
  768. size = max_pages * sizeof (*pages);
  769. pages = kmalloc(size, GFP_NOFS);
  770. if (!pages) {
  771. pool = fsc->wb_pagevec_pool;
  772. pages = mempool_alloc(pool, GFP_NOFS);
  773. BUG_ON(!pages);
  774. }
  775. }
  776. /* note position of first page in pvec */
  777. if (first < 0)
  778. first = i;
  779. dout("%p will write page %p idx %lu\n",
  780. inode, page, page->index);
  781. writeback_stat =
  782. atomic_long_inc_return(&fsc->writeback_count);
  783. if (writeback_stat > CONGESTION_ON_THRESH(
  784. fsc->mount_options->congestion_kb)) {
  785. set_bdi_congested(&fsc->backing_dev_info,
  786. BLK_RW_ASYNC);
  787. }
  788. set_page_writeback(page);
  789. pages[locked_pages] = page;
  790. locked_pages++;
  791. next = page->index + 1;
  792. }
  793. /* did we get anything? */
  794. if (!locked_pages)
  795. goto release_pvec_pages;
  796. if (i) {
  797. int j;
  798. BUG_ON(!locked_pages || first < 0);
  799. if (pvec_pages && i == pvec_pages &&
  800. locked_pages < max_pages) {
  801. dout("reached end pvec, trying for more\n");
  802. pagevec_reinit(&pvec);
  803. goto get_more_pages;
  804. }
  805. /* shift unused pages over in the pvec... we
  806. * will need to release them below. */
  807. for (j = i; j < pvec_pages; j++) {
  808. dout(" pvec leftover page %p\n",
  809. pvec.pages[j]);
  810. pvec.pages[j-i+first] = pvec.pages[j];
  811. }
  812. pvec.nr -= i-first;
  813. }
  814. /* Format the osd request message and submit the write */
  815. offset = page_offset(pages[0]);
  816. len = min(snap_size - offset,
  817. (u64)locked_pages << PAGE_CACHE_SHIFT);
  818. dout("writepages got %d pages at %llu~%llu\n",
  819. locked_pages, offset, len);
  820. osd_req_op_extent_osd_data_pages(req, 0, true, pages, len, 0,
  821. !!pool, false);
  822. pages = NULL; /* request message now owns the pages array */
  823. pool = NULL;
  824. /* Update the write op length in case we changed it */
  825. osd_req_op_extent_update(req, 0, len);
  826. vino = ceph_vino(inode);
  827. ceph_osdc_build_request(req, offset, snapc, vino.snap,
  828. &inode->i_mtime);
  829. rc = ceph_osdc_start_request(&fsc->client->osdc, req, true);
  830. BUG_ON(rc);
  831. req = NULL;
  832. /* continue? */
  833. index = next;
  834. wbc->nr_to_write -= locked_pages;
  835. if (wbc->nr_to_write <= 0)
  836. done = 1;
  837. release_pvec_pages:
  838. dout("pagevec_release on %d pages (%p)\n", (int)pvec.nr,
  839. pvec.nr ? pvec.pages[0] : NULL);
  840. pagevec_release(&pvec);
  841. if (locked_pages && !done)
  842. goto retry;
  843. }
  844. if (should_loop && !done) {
  845. /* more to do; loop back to beginning of file */
  846. dout("writepages looping back to beginning of file\n");
  847. should_loop = 0;
  848. index = 0;
  849. goto retry;
  850. }
  851. if (wbc->range_cyclic || (range_whole && wbc->nr_to_write > 0))
  852. mapping->writeback_index = index;
  853. out:
  854. if (req)
  855. ceph_osdc_put_request(req);
  856. ceph_put_snap_context(snapc);
  857. dout("writepages done, rc = %d\n", rc);
  858. return rc;
  859. }
  860. /*
  861. * See if a given @snapc is either writeable, or already written.
  862. */
  863. static int context_is_writeable_or_written(struct inode *inode,
  864. struct ceph_snap_context *snapc)
  865. {
  866. struct ceph_snap_context *oldest = get_oldest_context(inode, NULL);
  867. int ret = !oldest || snapc->seq <= oldest->seq;
  868. ceph_put_snap_context(oldest);
  869. return ret;
  870. }
  871. /*
  872. * We are only allowed to write into/dirty the page if the page is
  873. * clean, or already dirty within the same snap context.
  874. *
  875. * called with page locked.
  876. * return success with page locked,
  877. * or any failure (incl -EAGAIN) with page unlocked.
  878. */
  879. static int ceph_update_writeable_page(struct file *file,
  880. loff_t pos, unsigned len,
  881. struct page *page)
  882. {
  883. struct inode *inode = file_inode(file);
  884. struct ceph_inode_info *ci = ceph_inode(inode);
  885. struct ceph_mds_client *mdsc = ceph_inode_to_client(inode)->mdsc;
  886. loff_t page_off = pos & PAGE_CACHE_MASK;
  887. int pos_in_page = pos & ~PAGE_CACHE_MASK;
  888. int end_in_page = pos_in_page + len;
  889. loff_t i_size;
  890. int r;
  891. struct ceph_snap_context *snapc, *oldest;
  892. retry_locked:
  893. /* writepages currently holds page lock, but if we change that later, */
  894. wait_on_page_writeback(page);
  895. /* check snap context */
  896. BUG_ON(!ci->i_snap_realm);
  897. down_read(&mdsc->snap_rwsem);
  898. BUG_ON(!ci->i_snap_realm->cached_context);
  899. snapc = page_snap_context(page);
  900. if (snapc && snapc != ci->i_head_snapc) {
  901. /*
  902. * this page is already dirty in another (older) snap
  903. * context! is it writeable now?
  904. */
  905. oldest = get_oldest_context(inode, NULL);
  906. up_read(&mdsc->snap_rwsem);
  907. if (snapc->seq > oldest->seq) {
  908. ceph_put_snap_context(oldest);
  909. dout(" page %p snapc %p not current or oldest\n",
  910. page, snapc);
  911. /*
  912. * queue for writeback, and wait for snapc to
  913. * be writeable or written
  914. */
  915. snapc = ceph_get_snap_context(snapc);
  916. unlock_page(page);
  917. ceph_queue_writeback(inode);
  918. r = wait_event_interruptible(ci->i_cap_wq,
  919. context_is_writeable_or_written(inode, snapc));
  920. ceph_put_snap_context(snapc);
  921. if (r == -ERESTARTSYS)
  922. return r;
  923. return -EAGAIN;
  924. }
  925. ceph_put_snap_context(oldest);
  926. /* yay, writeable, do it now (without dropping page lock) */
  927. dout(" page %p snapc %p not current, but oldest\n",
  928. page, snapc);
  929. if (!clear_page_dirty_for_io(page))
  930. goto retry_locked;
  931. r = writepage_nounlock(page, NULL);
  932. if (r < 0)
  933. goto fail_nosnap;
  934. goto retry_locked;
  935. }
  936. if (PageUptodate(page)) {
  937. dout(" page %p already uptodate\n", page);
  938. return 0;
  939. }
  940. /* full page? */
  941. if (pos_in_page == 0 && len == PAGE_CACHE_SIZE)
  942. return 0;
  943. /* past end of file? */
  944. i_size = inode->i_size; /* caller holds i_mutex */
  945. if (i_size + len > inode->i_sb->s_maxbytes) {
  946. /* file is too big */
  947. r = -EINVAL;
  948. goto fail;
  949. }
  950. if (page_off >= i_size ||
  951. (pos_in_page == 0 && (pos+len) >= i_size &&
  952. end_in_page - pos_in_page != PAGE_CACHE_SIZE)) {
  953. dout(" zeroing %p 0 - %d and %d - %d\n",
  954. page, pos_in_page, end_in_page, (int)PAGE_CACHE_SIZE);
  955. zero_user_segments(page,
  956. 0, pos_in_page,
  957. end_in_page, PAGE_CACHE_SIZE);
  958. return 0;
  959. }
  960. /* we need to read it. */
  961. up_read(&mdsc->snap_rwsem);
  962. r = readpage_nounlock(file, page);
  963. if (r < 0)
  964. goto fail_nosnap;
  965. goto retry_locked;
  966. fail:
  967. up_read(&mdsc->snap_rwsem);
  968. fail_nosnap:
  969. unlock_page(page);
  970. return r;
  971. }
  972. /*
  973. * We are only allowed to write into/dirty the page if the page is
  974. * clean, or already dirty within the same snap context.
  975. */
  976. static int ceph_write_begin(struct file *file, struct address_space *mapping,
  977. loff_t pos, unsigned len, unsigned flags,
  978. struct page **pagep, void **fsdata)
  979. {
  980. struct inode *inode = file_inode(file);
  981. struct page *page;
  982. pgoff_t index = pos >> PAGE_CACHE_SHIFT;
  983. int r;
  984. do {
  985. /* get a page */
  986. page = grab_cache_page_write_begin(mapping, index, 0);
  987. if (!page)
  988. return -ENOMEM;
  989. *pagep = page;
  990. dout("write_begin file %p inode %p page %p %d~%d\n", file,
  991. inode, page, (int)pos, (int)len);
  992. r = ceph_update_writeable_page(file, pos, len, page);
  993. } while (r == -EAGAIN);
  994. return r;
  995. }
  996. /*
  997. * we don't do anything in here that simple_write_end doesn't do
  998. * except adjust dirty page accounting and drop read lock on
  999. * mdsc->snap_rwsem.
  1000. */
  1001. static int ceph_write_end(struct file *file, struct address_space *mapping,
  1002. loff_t pos, unsigned len, unsigned copied,
  1003. struct page *page, void *fsdata)
  1004. {
  1005. struct inode *inode = file_inode(file);
  1006. struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
  1007. struct ceph_mds_client *mdsc = fsc->mdsc;
  1008. unsigned from = pos & (PAGE_CACHE_SIZE - 1);
  1009. int check_cap = 0;
  1010. dout("write_end file %p inode %p page %p %d~%d (%d)\n", file,
  1011. inode, page, (int)pos, (int)copied, (int)len);
  1012. /* zero the stale part of the page if we did a short copy */
  1013. if (copied < len)
  1014. zero_user_segment(page, from+copied, len);
  1015. /* did file size increase? */
  1016. /* (no need for i_size_read(); we caller holds i_mutex */
  1017. if (pos+copied > inode->i_size)
  1018. check_cap = ceph_inode_set_size(inode, pos+copied);
  1019. if (!PageUptodate(page))
  1020. SetPageUptodate(page);
  1021. set_page_dirty(page);
  1022. unlock_page(page);
  1023. up_read(&mdsc->snap_rwsem);
  1024. page_cache_release(page);
  1025. if (check_cap)
  1026. ceph_check_caps(ceph_inode(inode), CHECK_CAPS_AUTHONLY, NULL);
  1027. return copied;
  1028. }
  1029. /*
  1030. * we set .direct_IO to indicate direct io is supported, but since we
  1031. * intercept O_DIRECT reads and writes early, this function should
  1032. * never get called.
  1033. */
  1034. static ssize_t ceph_direct_io(int rw, struct kiocb *iocb,
  1035. const struct iovec *iov,
  1036. loff_t pos, unsigned long nr_segs)
  1037. {
  1038. WARN_ON(1);
  1039. return -EINVAL;
  1040. }
  1041. const struct address_space_operations ceph_aops = {
  1042. .readpage = ceph_readpage,
  1043. .readpages = ceph_readpages,
  1044. .writepage = ceph_writepage,
  1045. .writepages = ceph_writepages_start,
  1046. .write_begin = ceph_write_begin,
  1047. .write_end = ceph_write_end,
  1048. .set_page_dirty = ceph_set_page_dirty,
  1049. .invalidatepage = ceph_invalidatepage,
  1050. .releasepage = ceph_releasepage,
  1051. .direct_IO = ceph_direct_io,
  1052. };
  1053. /*
  1054. * vm ops
  1055. */
  1056. /*
  1057. * Reuse write_begin here for simplicity.
  1058. */
  1059. static int ceph_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
  1060. {
  1061. struct inode *inode = file_inode(vma->vm_file);
  1062. struct page *page = vmf->page;
  1063. struct ceph_mds_client *mdsc = ceph_inode_to_client(inode)->mdsc;
  1064. loff_t off = page_offset(page);
  1065. loff_t size, len;
  1066. int ret;
  1067. /* Update time before taking page lock */
  1068. file_update_time(vma->vm_file);
  1069. size = i_size_read(inode);
  1070. if (off + PAGE_CACHE_SIZE <= size)
  1071. len = PAGE_CACHE_SIZE;
  1072. else
  1073. len = size & ~PAGE_CACHE_MASK;
  1074. dout("page_mkwrite %p %llu~%llu page %p idx %lu\n", inode,
  1075. off, len, page, page->index);
  1076. lock_page(page);
  1077. ret = VM_FAULT_NOPAGE;
  1078. if ((off > size) ||
  1079. (page->mapping != inode->i_mapping))
  1080. goto out;
  1081. ret = ceph_update_writeable_page(vma->vm_file, off, len, page);
  1082. if (ret == 0) {
  1083. /* success. we'll keep the page locked. */
  1084. set_page_dirty(page);
  1085. up_read(&mdsc->snap_rwsem);
  1086. ret = VM_FAULT_LOCKED;
  1087. } else {
  1088. if (ret == -ENOMEM)
  1089. ret = VM_FAULT_OOM;
  1090. else
  1091. ret = VM_FAULT_SIGBUS;
  1092. }
  1093. out:
  1094. dout("page_mkwrite %p %llu~%llu = %d\n", inode, off, len, ret);
  1095. if (ret != VM_FAULT_LOCKED)
  1096. unlock_page(page);
  1097. return ret;
  1098. }
  1099. static struct vm_operations_struct ceph_vmops = {
  1100. .fault = filemap_fault,
  1101. .page_mkwrite = ceph_page_mkwrite,
  1102. .remap_pages = generic_file_remap_pages,
  1103. };
  1104. int ceph_mmap(struct file *file, struct vm_area_struct *vma)
  1105. {
  1106. struct address_space *mapping = file->f_mapping;
  1107. if (!mapping->a_ops->readpage)
  1108. return -ENOEXEC;
  1109. file_accessed(file);
  1110. vma->vm_ops = &ceph_vmops;
  1111. return 0;
  1112. }