addr.c 34 KB

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