addr.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269
  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 = &req->r_data_in;
  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. struct ceph_osd_req_op op;
  257. u64 off;
  258. u64 len;
  259. int i;
  260. struct page **pages;
  261. pgoff_t next_index;
  262. int nr_pages = 0;
  263. int ret;
  264. off = (u64) page_offset(page);
  265. /* count pages */
  266. next_index = page->index;
  267. list_for_each_entry_reverse(page, page_list, lru) {
  268. if (page->index != next_index)
  269. break;
  270. nr_pages++;
  271. next_index++;
  272. if (max && nr_pages == max)
  273. break;
  274. }
  275. len = nr_pages << PAGE_CACHE_SHIFT;
  276. dout("start_read %p nr_pages %d is %lld~%lld\n", inode, nr_pages,
  277. off, len);
  278. vino = ceph_vino(inode);
  279. req = ceph_osdc_new_request(osdc, &ci->i_layout, vino, off, &len,
  280. 1, &op, CEPH_OSD_OP_READ,
  281. CEPH_OSD_FLAG_READ, NULL,
  282. ci->i_truncate_seq, ci->i_truncate_size,
  283. false);
  284. if (IS_ERR(req))
  285. return PTR_ERR(req);
  286. /* build page vector */
  287. nr_pages = calc_pages_for(0, len);
  288. pages = kmalloc(sizeof(*pages) * nr_pages, GFP_NOFS);
  289. ret = -ENOMEM;
  290. if (!pages)
  291. goto out;
  292. for (i = 0; i < nr_pages; ++i) {
  293. page = list_entry(page_list->prev, struct page, lru);
  294. BUG_ON(PageLocked(page));
  295. list_del(&page->lru);
  296. dout("start_read %p adding %p idx %lu\n", inode, page,
  297. page->index);
  298. if (add_to_page_cache_lru(page, &inode->i_data, page->index,
  299. GFP_NOFS)) {
  300. page_cache_release(page);
  301. dout("start_read %p add_to_page_cache failed %p\n",
  302. inode, page);
  303. nr_pages = i;
  304. goto out_pages;
  305. }
  306. pages[i] = page;
  307. }
  308. ceph_osd_data_pages_init(&req->r_data_in, pages, len, 0,
  309. false, false);
  310. req->r_callback = finish_read;
  311. req->r_inode = inode;
  312. ceph_osdc_build_request(req, off, 1, &op, NULL, vino.snap, NULL);
  313. dout("start_read %p starting %p %lld~%lld\n", inode, req, off, len);
  314. ret = ceph_osdc_start_request(osdc, req, false);
  315. if (ret < 0)
  316. goto out_pages;
  317. ceph_osdc_put_request(req);
  318. return nr_pages;
  319. out_pages:
  320. ceph_unlock_page_vector(pages, nr_pages);
  321. ceph_release_page_vector(pages, nr_pages);
  322. out:
  323. ceph_osdc_put_request(req);
  324. return ret;
  325. }
  326. /*
  327. * Read multiple pages. Leave pages we don't read + unlock in page_list;
  328. * the caller (VM) cleans them up.
  329. */
  330. static int ceph_readpages(struct file *file, struct address_space *mapping,
  331. struct list_head *page_list, unsigned nr_pages)
  332. {
  333. struct inode *inode = file_inode(file);
  334. struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
  335. int rc = 0;
  336. int max = 0;
  337. if (fsc->mount_options->rsize >= PAGE_CACHE_SIZE)
  338. max = (fsc->mount_options->rsize + PAGE_CACHE_SIZE - 1)
  339. >> PAGE_SHIFT;
  340. dout("readpages %p file %p nr_pages %d max %d\n", inode,
  341. file, nr_pages,
  342. max);
  343. while (!list_empty(page_list)) {
  344. rc = start_read(inode, page_list, max);
  345. if (rc < 0)
  346. goto out;
  347. BUG_ON(rc == 0);
  348. }
  349. out:
  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. loff_t page_off = page_offset(page);
  395. int len = PAGE_CACHE_SIZE;
  396. loff_t i_size;
  397. int err = 0;
  398. struct ceph_snap_context *snapc, *oldest;
  399. u64 snap_size = 0;
  400. long writeback_stat;
  401. dout("writepage %p idx %lu\n", page, page->index);
  402. if (!page->mapping || !page->mapping->host) {
  403. dout("writepage %p - no mapping\n", page);
  404. return -EFAULT;
  405. }
  406. inode = page->mapping->host;
  407. ci = ceph_inode(inode);
  408. fsc = ceph_inode_to_client(inode);
  409. osdc = &fsc->client->osdc;
  410. /* verify this is a writeable snap context */
  411. snapc = page_snap_context(page);
  412. if (snapc == NULL) {
  413. dout("writepage %p page %p not dirty?\n", inode, page);
  414. goto out;
  415. }
  416. oldest = get_oldest_context(inode, &snap_size);
  417. if (snapc->seq > oldest->seq) {
  418. dout("writepage %p page %p snapc %p not writeable - noop\n",
  419. inode, page, snapc);
  420. /* we should only noop if called by kswapd */
  421. WARN_ON((current->flags & PF_MEMALLOC) == 0);
  422. ceph_put_snap_context(oldest);
  423. goto out;
  424. }
  425. ceph_put_snap_context(oldest);
  426. /* is this a partial page at end of file? */
  427. if (snap_size)
  428. i_size = snap_size;
  429. else
  430. i_size = i_size_read(inode);
  431. if (i_size < page_off + len)
  432. len = i_size - page_off;
  433. dout("writepage %p page %p index %lu on %llu~%u snapc %p\n",
  434. inode, page, page->index, page_off, len, snapc);
  435. writeback_stat = atomic_long_inc_return(&fsc->writeback_count);
  436. if (writeback_stat >
  437. CONGESTION_ON_THRESH(fsc->mount_options->congestion_kb))
  438. set_bdi_congested(&fsc->backing_dev_info, BLK_RW_ASYNC);
  439. set_page_writeback(page);
  440. err = ceph_osdc_writepages(osdc, ceph_vino(inode),
  441. &ci->i_layout, snapc,
  442. page_off, len,
  443. ci->i_truncate_seq, ci->i_truncate_size,
  444. &inode->i_mtime, &page, 1);
  445. if (err < 0) {
  446. dout("writepage setting page/mapping error %d %p\n", err, page);
  447. SetPageError(page);
  448. mapping_set_error(&inode->i_data, err);
  449. if (wbc)
  450. wbc->pages_skipped++;
  451. } else {
  452. dout("writepage cleaned page %p\n", page);
  453. err = 0; /* vfs expects us to return 0 */
  454. }
  455. page->private = 0;
  456. ClearPagePrivate(page);
  457. end_page_writeback(page);
  458. ceph_put_wrbuffer_cap_refs(ci, 1, snapc);
  459. ceph_put_snap_context(snapc); /* page's reference */
  460. out:
  461. return err;
  462. }
  463. static int ceph_writepage(struct page *page, struct writeback_control *wbc)
  464. {
  465. int err;
  466. struct inode *inode = page->mapping->host;
  467. BUG_ON(!inode);
  468. ihold(inode);
  469. err = writepage_nounlock(page, wbc);
  470. unlock_page(page);
  471. iput(inode);
  472. return err;
  473. }
  474. /*
  475. * lame release_pages helper. release_pages() isn't exported to
  476. * modules.
  477. */
  478. static void ceph_release_pages(struct page **pages, int num)
  479. {
  480. struct pagevec pvec;
  481. int i;
  482. pagevec_init(&pvec, 0);
  483. for (i = 0; i < num; i++) {
  484. if (pagevec_add(&pvec, pages[i]) == 0)
  485. pagevec_release(&pvec);
  486. }
  487. pagevec_release(&pvec);
  488. }
  489. /*
  490. * async writeback completion handler.
  491. *
  492. * If we get an error, set the mapping error bit, but not the individual
  493. * page error bits.
  494. */
  495. static void writepages_finish(struct ceph_osd_request *req,
  496. struct ceph_msg *msg)
  497. {
  498. struct inode *inode = req->r_inode;
  499. struct ceph_inode_info *ci = ceph_inode(inode);
  500. struct ceph_osd_data *osd_data;
  501. unsigned wrote;
  502. struct page *page;
  503. int num_pages;
  504. int i;
  505. struct ceph_snap_context *snapc = req->r_snapc;
  506. struct address_space *mapping = inode->i_mapping;
  507. int rc = req->r_result;
  508. u64 bytes = le64_to_cpu(req->r_request_ops[0].extent.length);
  509. struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
  510. long writeback_stat;
  511. unsigned issued = ceph_caps_issued(ci);
  512. osd_data = &req->r_data_out;
  513. BUG_ON(osd_data->type != CEPH_OSD_DATA_TYPE_PAGES);
  514. num_pages = calc_pages_for((u64)osd_data->alignment,
  515. (u64)osd_data->length);
  516. if (rc >= 0) {
  517. /*
  518. * Assume we wrote the pages we originally sent. The
  519. * osd might reply with fewer pages if our writeback
  520. * raced with a truncation and was adjusted at the osd,
  521. * so don't believe the reply.
  522. */
  523. wrote = num_pages;
  524. } else {
  525. wrote = 0;
  526. mapping_set_error(mapping, rc);
  527. }
  528. dout("writepages_finish %p rc %d bytes %llu wrote %d (pages)\n",
  529. inode, rc, bytes, wrote);
  530. /* clean all pages */
  531. for (i = 0; i < num_pages; i++) {
  532. page = osd_data->pages[i];
  533. BUG_ON(!page);
  534. WARN_ON(!PageUptodate(page));
  535. writeback_stat =
  536. atomic_long_dec_return(&fsc->writeback_count);
  537. if (writeback_stat <
  538. CONGESTION_OFF_THRESH(fsc->mount_options->congestion_kb))
  539. clear_bdi_congested(&fsc->backing_dev_info,
  540. BLK_RW_ASYNC);
  541. ceph_put_snap_context(page_snap_context(page));
  542. page->private = 0;
  543. ClearPagePrivate(page);
  544. dout("unlocking %d %p\n", i, page);
  545. end_page_writeback(page);
  546. /*
  547. * We lost the cache cap, need to truncate the page before
  548. * it is unlocked, otherwise we'd truncate it later in the
  549. * page truncation thread, possibly losing some data that
  550. * raced its way in
  551. */
  552. if ((issued & (CEPH_CAP_FILE_CACHE|CEPH_CAP_FILE_LAZYIO)) == 0)
  553. generic_error_remove_page(inode->i_mapping, page);
  554. unlock_page(page);
  555. }
  556. dout("%p wrote+cleaned %d pages\n", inode, wrote);
  557. ceph_put_wrbuffer_cap_refs(ci, num_pages, snapc);
  558. ceph_release_pages(osd_data->pages, num_pages);
  559. if (osd_data->pages_from_pool)
  560. mempool_free(osd_data->pages,
  561. ceph_sb_to_client(inode->i_sb)->wb_pagevec_pool);
  562. else
  563. kfree(osd_data->pages);
  564. ceph_osdc_put_request(req);
  565. }
  566. static struct ceph_osd_request *
  567. ceph_writepages_osd_request(struct inode *inode, u64 offset, u64 *len,
  568. struct ceph_snap_context *snapc,
  569. int num_ops, struct ceph_osd_req_op *ops)
  570. {
  571. struct ceph_fs_client *fsc;
  572. struct ceph_inode_info *ci;
  573. struct ceph_vino vino;
  574. fsc = ceph_inode_to_client(inode);
  575. ci = ceph_inode(inode);
  576. vino = ceph_vino(inode);
  577. /* BUG_ON(vino.snap != CEPH_NOSNAP); */
  578. return ceph_osdc_new_request(&fsc->client->osdc, &ci->i_layout,
  579. vino, offset, len, num_ops, ops, CEPH_OSD_OP_WRITE,
  580. CEPH_OSD_FLAG_WRITE|CEPH_OSD_FLAG_ONDISK,
  581. snapc, ci->i_truncate_seq, ci->i_truncate_size, true);
  582. }
  583. /*
  584. * initiate async writeback
  585. */
  586. static int ceph_writepages_start(struct address_space *mapping,
  587. struct writeback_control *wbc)
  588. {
  589. struct inode *inode = mapping->host;
  590. struct ceph_inode_info *ci = ceph_inode(inode);
  591. struct ceph_fs_client *fsc;
  592. pgoff_t index, start, end;
  593. int range_whole = 0;
  594. int should_loop = 1;
  595. pgoff_t max_pages = 0, max_pages_ever = 0;
  596. struct ceph_snap_context *snapc = NULL, *last_snapc = NULL, *pgsnapc;
  597. struct pagevec pvec;
  598. int done = 0;
  599. int rc = 0;
  600. unsigned wsize = 1 << inode->i_blkbits;
  601. struct ceph_osd_request *req = NULL;
  602. int do_sync;
  603. u64 snap_size = 0;
  604. /*
  605. * Include a 'sync' in the OSD request if this is a data
  606. * integrity write (e.g., O_SYNC write or fsync()), or if our
  607. * cap is being revoked.
  608. */
  609. do_sync = wbc->sync_mode == WB_SYNC_ALL;
  610. if (ceph_caps_revoking(ci, CEPH_CAP_FILE_BUFFER))
  611. do_sync = 1;
  612. dout("writepages_start %p dosync=%d (mode=%s)\n",
  613. inode, do_sync,
  614. wbc->sync_mode == WB_SYNC_NONE ? "NONE" :
  615. (wbc->sync_mode == WB_SYNC_ALL ? "ALL" : "HOLD"));
  616. fsc = ceph_inode_to_client(inode);
  617. if (fsc->mount_state == CEPH_MOUNT_SHUTDOWN) {
  618. pr_warning("writepage_start %p on forced umount\n", inode);
  619. return -EIO; /* we're in a forced umount, don't write! */
  620. }
  621. if (fsc->mount_options->wsize && fsc->mount_options->wsize < wsize)
  622. wsize = fsc->mount_options->wsize;
  623. if (wsize < PAGE_CACHE_SIZE)
  624. wsize = PAGE_CACHE_SIZE;
  625. max_pages_ever = wsize >> PAGE_CACHE_SHIFT;
  626. pagevec_init(&pvec, 0);
  627. /* where to start/end? */
  628. if (wbc->range_cyclic) {
  629. start = mapping->writeback_index; /* Start from prev offset */
  630. end = -1;
  631. dout(" cyclic, start at %lu\n", start);
  632. } else {
  633. start = wbc->range_start >> PAGE_CACHE_SHIFT;
  634. end = wbc->range_end >> PAGE_CACHE_SHIFT;
  635. if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
  636. range_whole = 1;
  637. should_loop = 0;
  638. dout(" not cyclic, %lu to %lu\n", start, end);
  639. }
  640. index = start;
  641. retry:
  642. /* find oldest snap context with dirty data */
  643. ceph_put_snap_context(snapc);
  644. snapc = get_oldest_context(inode, &snap_size);
  645. if (!snapc) {
  646. /* hmm, why does writepages get called when there
  647. is no dirty data? */
  648. dout(" no snap context with dirty data?\n");
  649. goto out;
  650. }
  651. dout(" oldest snapc is %p seq %lld (%d snaps)\n",
  652. snapc, snapc->seq, snapc->num_snaps);
  653. if (last_snapc && snapc != last_snapc) {
  654. /* if we switched to a newer snapc, restart our scan at the
  655. * start of the original file range. */
  656. dout(" snapc differs from last pass, restarting at %lu\n",
  657. index);
  658. index = start;
  659. }
  660. last_snapc = snapc;
  661. while (!done && index <= end) {
  662. struct ceph_osd_req_op ops[2];
  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 ((snap_size && page_offset(page) > snap_size) ||
  720. (!snap_size &&
  721. page_offset(page) > i_size_read(inode))) {
  722. dout("%p page eof %llu\n", page, snap_size ?
  723. snap_size : i_size_read(inode));
  724. done = 1;
  725. unlock_page(page);
  726. break;
  727. }
  728. if (PageWriteback(page)) {
  729. dout("%p under writeback\n", page);
  730. unlock_page(page);
  731. break;
  732. }
  733. /* only if matching snap context */
  734. pgsnapc = page_snap_context(page);
  735. if (pgsnapc->seq > snapc->seq) {
  736. dout("page snapc %p %lld > oldest %p %lld\n",
  737. pgsnapc, pgsnapc->seq, snapc, snapc->seq);
  738. unlock_page(page);
  739. if (!locked_pages)
  740. continue; /* keep looking for snap */
  741. break;
  742. }
  743. if (!clear_page_dirty_for_io(page)) {
  744. dout("%p !clear_page_dirty_for_io\n", page);
  745. unlock_page(page);
  746. break;
  747. }
  748. /*
  749. * We have something to write. If this is
  750. * the first locked page this time through,
  751. * allocate an osd request and a page array
  752. * that it will use.
  753. */
  754. if (locked_pages == 0) {
  755. size_t size;
  756. BUG_ON(pages);
  757. /* prepare async write request */
  758. offset = (u64)page_offset(page);
  759. len = wsize;
  760. req = ceph_writepages_osd_request(inode,
  761. offset, &len, snapc,
  762. num_ops, ops);
  763. if (IS_ERR(req)) {
  764. rc = PTR_ERR(req);
  765. unlock_page(page);
  766. break;
  767. }
  768. req->r_callback = writepages_finish;
  769. req->r_inode = inode;
  770. max_pages = calc_pages_for(0, (u64)len);
  771. size = max_pages * sizeof (*pages);
  772. pages = kmalloc(size, GFP_NOFS);
  773. if (!pages) {
  774. pool = fsc->wb_pagevec_pool;
  775. pages = mempool_alloc(pool, GFP_NOFS);
  776. BUG_ON(!pages);
  777. }
  778. }
  779. /* note position of first page in pvec */
  780. if (first < 0)
  781. first = i;
  782. dout("%p will write page %p idx %lu\n",
  783. inode, page, page->index);
  784. writeback_stat =
  785. atomic_long_inc_return(&fsc->writeback_count);
  786. if (writeback_stat > CONGESTION_ON_THRESH(
  787. fsc->mount_options->congestion_kb)) {
  788. set_bdi_congested(&fsc->backing_dev_info,
  789. BLK_RW_ASYNC);
  790. }
  791. set_page_writeback(page);
  792. pages[locked_pages] = page;
  793. locked_pages++;
  794. next = page->index + 1;
  795. }
  796. /* did we get anything? */
  797. if (!locked_pages)
  798. goto release_pvec_pages;
  799. if (i) {
  800. int j;
  801. BUG_ON(!locked_pages || first < 0);
  802. if (pvec_pages && i == pvec_pages &&
  803. locked_pages < max_pages) {
  804. dout("reached end pvec, trying for more\n");
  805. pagevec_reinit(&pvec);
  806. goto get_more_pages;
  807. }
  808. /* shift unused pages over in the pvec... we
  809. * will need to release them below. */
  810. for (j = i; j < pvec_pages; j++) {
  811. dout(" pvec leftover page %p\n",
  812. pvec.pages[j]);
  813. pvec.pages[j-i+first] = pvec.pages[j];
  814. }
  815. pvec.nr -= i-first;
  816. }
  817. /* Format the osd request message and submit the write */
  818. offset = page_offset(pages[0]);
  819. len = min((snap_size ? snap_size : i_size_read(inode)) - offset,
  820. (u64)locked_pages << PAGE_CACHE_SHIFT);
  821. dout("writepages got %d pages at %llu~%llu\n",
  822. locked_pages, offset, len);
  823. ceph_osd_data_pages_init(&req->r_data_out, pages, len, 0,
  824. !!pool, false);
  825. pages = NULL; /* request message now owns the pages array */
  826. pool = NULL;
  827. /* Update the write op length in case we changed it */
  828. osd_req_op_extent_update(&ops[0], len);
  829. vino = ceph_vino(inode);
  830. ceph_osdc_build_request(req, offset, num_ops, ops,
  831. snapc, vino.snap, &inode->i_mtime);
  832. rc = ceph_osdc_start_request(&fsc->client->osdc, req, true);
  833. BUG_ON(rc);
  834. req = NULL;
  835. /* continue? */
  836. index = next;
  837. wbc->nr_to_write -= locked_pages;
  838. if (wbc->nr_to_write <= 0)
  839. done = 1;
  840. release_pvec_pages:
  841. dout("pagevec_release on %d pages (%p)\n", (int)pvec.nr,
  842. pvec.nr ? pvec.pages[0] : NULL);
  843. pagevec_release(&pvec);
  844. if (locked_pages && !done)
  845. goto retry;
  846. }
  847. if (should_loop && !done) {
  848. /* more to do; loop back to beginning of file */
  849. dout("writepages looping back to beginning of file\n");
  850. should_loop = 0;
  851. index = 0;
  852. goto retry;
  853. }
  854. if (wbc->range_cyclic || (range_whole && wbc->nr_to_write > 0))
  855. mapping->writeback_index = index;
  856. out:
  857. if (req)
  858. ceph_osdc_put_request(req);
  859. ceph_put_snap_context(snapc);
  860. dout("writepages done, rc = %d\n", rc);
  861. return rc;
  862. }
  863. /*
  864. * See if a given @snapc is either writeable, or already written.
  865. */
  866. static int context_is_writeable_or_written(struct inode *inode,
  867. struct ceph_snap_context *snapc)
  868. {
  869. struct ceph_snap_context *oldest = get_oldest_context(inode, NULL);
  870. int ret = !oldest || snapc->seq <= oldest->seq;
  871. ceph_put_snap_context(oldest);
  872. return ret;
  873. }
  874. /*
  875. * We are only allowed to write into/dirty the page if the page is
  876. * clean, or already dirty within the same snap context.
  877. *
  878. * called with page locked.
  879. * return success with page locked,
  880. * or any failure (incl -EAGAIN) with page unlocked.
  881. */
  882. static int ceph_update_writeable_page(struct file *file,
  883. loff_t pos, unsigned len,
  884. struct page *page)
  885. {
  886. struct inode *inode = file_inode(file);
  887. struct ceph_inode_info *ci = ceph_inode(inode);
  888. struct ceph_mds_client *mdsc = ceph_inode_to_client(inode)->mdsc;
  889. loff_t page_off = pos & PAGE_CACHE_MASK;
  890. int pos_in_page = pos & ~PAGE_CACHE_MASK;
  891. int end_in_page = pos_in_page + len;
  892. loff_t i_size;
  893. int r;
  894. struct ceph_snap_context *snapc, *oldest;
  895. retry_locked:
  896. /* writepages currently holds page lock, but if we change that later, */
  897. wait_on_page_writeback(page);
  898. /* check snap context */
  899. BUG_ON(!ci->i_snap_realm);
  900. down_read(&mdsc->snap_rwsem);
  901. BUG_ON(!ci->i_snap_realm->cached_context);
  902. snapc = page_snap_context(page);
  903. if (snapc && snapc != ci->i_head_snapc) {
  904. /*
  905. * this page is already dirty in another (older) snap
  906. * context! is it writeable now?
  907. */
  908. oldest = get_oldest_context(inode, NULL);
  909. up_read(&mdsc->snap_rwsem);
  910. if (snapc->seq > oldest->seq) {
  911. ceph_put_snap_context(oldest);
  912. dout(" page %p snapc %p not current or oldest\n",
  913. page, snapc);
  914. /*
  915. * queue for writeback, and wait for snapc to
  916. * be writeable or written
  917. */
  918. snapc = ceph_get_snap_context(snapc);
  919. unlock_page(page);
  920. ceph_queue_writeback(inode);
  921. r = wait_event_interruptible(ci->i_cap_wq,
  922. context_is_writeable_or_written(inode, snapc));
  923. ceph_put_snap_context(snapc);
  924. if (r == -ERESTARTSYS)
  925. return r;
  926. return -EAGAIN;
  927. }
  928. ceph_put_snap_context(oldest);
  929. /* yay, writeable, do it now (without dropping page lock) */
  930. dout(" page %p snapc %p not current, but oldest\n",
  931. page, snapc);
  932. if (!clear_page_dirty_for_io(page))
  933. goto retry_locked;
  934. r = writepage_nounlock(page, NULL);
  935. if (r < 0)
  936. goto fail_nosnap;
  937. goto retry_locked;
  938. }
  939. if (PageUptodate(page)) {
  940. dout(" page %p already uptodate\n", page);
  941. return 0;
  942. }
  943. /* full page? */
  944. if (pos_in_page == 0 && len == PAGE_CACHE_SIZE)
  945. return 0;
  946. /* past end of file? */
  947. i_size = inode->i_size; /* caller holds i_mutex */
  948. if (i_size + len > inode->i_sb->s_maxbytes) {
  949. /* file is too big */
  950. r = -EINVAL;
  951. goto fail;
  952. }
  953. if (page_off >= i_size ||
  954. (pos_in_page == 0 && (pos+len) >= i_size &&
  955. end_in_page - pos_in_page != PAGE_CACHE_SIZE)) {
  956. dout(" zeroing %p 0 - %d and %d - %d\n",
  957. page, pos_in_page, end_in_page, (int)PAGE_CACHE_SIZE);
  958. zero_user_segments(page,
  959. 0, pos_in_page,
  960. end_in_page, PAGE_CACHE_SIZE);
  961. return 0;
  962. }
  963. /* we need to read it. */
  964. up_read(&mdsc->snap_rwsem);
  965. r = readpage_nounlock(file, page);
  966. if (r < 0)
  967. goto fail_nosnap;
  968. goto retry_locked;
  969. fail:
  970. up_read(&mdsc->snap_rwsem);
  971. fail_nosnap:
  972. unlock_page(page);
  973. return r;
  974. }
  975. /*
  976. * We are only allowed to write into/dirty the page if the page is
  977. * clean, or already dirty within the same snap context.
  978. */
  979. static int ceph_write_begin(struct file *file, struct address_space *mapping,
  980. loff_t pos, unsigned len, unsigned flags,
  981. struct page **pagep, void **fsdata)
  982. {
  983. struct inode *inode = file_inode(file);
  984. struct page *page;
  985. pgoff_t index = pos >> PAGE_CACHE_SHIFT;
  986. int r;
  987. do {
  988. /* get a page */
  989. page = grab_cache_page_write_begin(mapping, index, 0);
  990. if (!page)
  991. return -ENOMEM;
  992. *pagep = page;
  993. dout("write_begin file %p inode %p page %p %d~%d\n", file,
  994. inode, page, (int)pos, (int)len);
  995. r = ceph_update_writeable_page(file, pos, len, page);
  996. } while (r == -EAGAIN);
  997. return r;
  998. }
  999. /*
  1000. * we don't do anything in here that simple_write_end doesn't do
  1001. * except adjust dirty page accounting and drop read lock on
  1002. * mdsc->snap_rwsem.
  1003. */
  1004. static int ceph_write_end(struct file *file, struct address_space *mapping,
  1005. loff_t pos, unsigned len, unsigned copied,
  1006. struct page *page, void *fsdata)
  1007. {
  1008. struct inode *inode = file_inode(file);
  1009. struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
  1010. struct ceph_mds_client *mdsc = fsc->mdsc;
  1011. unsigned from = pos & (PAGE_CACHE_SIZE - 1);
  1012. int check_cap = 0;
  1013. dout("write_end file %p inode %p page %p %d~%d (%d)\n", file,
  1014. inode, page, (int)pos, (int)copied, (int)len);
  1015. /* zero the stale part of the page if we did a short copy */
  1016. if (copied < len)
  1017. zero_user_segment(page, from+copied, len);
  1018. /* did file size increase? */
  1019. /* (no need for i_size_read(); we caller holds i_mutex */
  1020. if (pos+copied > inode->i_size)
  1021. check_cap = ceph_inode_set_size(inode, pos+copied);
  1022. if (!PageUptodate(page))
  1023. SetPageUptodate(page);
  1024. set_page_dirty(page);
  1025. unlock_page(page);
  1026. up_read(&mdsc->snap_rwsem);
  1027. page_cache_release(page);
  1028. if (check_cap)
  1029. ceph_check_caps(ceph_inode(inode), CHECK_CAPS_AUTHONLY, NULL);
  1030. return copied;
  1031. }
  1032. /*
  1033. * we set .direct_IO to indicate direct io is supported, but since we
  1034. * intercept O_DIRECT reads and writes early, this function should
  1035. * never get called.
  1036. */
  1037. static ssize_t ceph_direct_io(int rw, struct kiocb *iocb,
  1038. const struct iovec *iov,
  1039. loff_t pos, unsigned long nr_segs)
  1040. {
  1041. WARN_ON(1);
  1042. return -EINVAL;
  1043. }
  1044. const struct address_space_operations ceph_aops = {
  1045. .readpage = ceph_readpage,
  1046. .readpages = ceph_readpages,
  1047. .writepage = ceph_writepage,
  1048. .writepages = ceph_writepages_start,
  1049. .write_begin = ceph_write_begin,
  1050. .write_end = ceph_write_end,
  1051. .set_page_dirty = ceph_set_page_dirty,
  1052. .invalidatepage = ceph_invalidatepage,
  1053. .releasepage = ceph_releasepage,
  1054. .direct_IO = ceph_direct_io,
  1055. };
  1056. /*
  1057. * vm ops
  1058. */
  1059. /*
  1060. * Reuse write_begin here for simplicity.
  1061. */
  1062. static int ceph_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
  1063. {
  1064. struct inode *inode = file_inode(vma->vm_file);
  1065. struct page *page = vmf->page;
  1066. struct ceph_mds_client *mdsc = ceph_inode_to_client(inode)->mdsc;
  1067. loff_t off = page_offset(page);
  1068. loff_t size, len;
  1069. int ret;
  1070. /* Update time before taking page lock */
  1071. file_update_time(vma->vm_file);
  1072. size = i_size_read(inode);
  1073. if (off + PAGE_CACHE_SIZE <= size)
  1074. len = PAGE_CACHE_SIZE;
  1075. else
  1076. len = size & ~PAGE_CACHE_MASK;
  1077. dout("page_mkwrite %p %llu~%llu page %p idx %lu\n", inode,
  1078. off, len, page, page->index);
  1079. lock_page(page);
  1080. ret = VM_FAULT_NOPAGE;
  1081. if ((off > size) ||
  1082. (page->mapping != inode->i_mapping))
  1083. goto out;
  1084. ret = ceph_update_writeable_page(vma->vm_file, off, len, page);
  1085. if (ret == 0) {
  1086. /* success. we'll keep the page locked. */
  1087. set_page_dirty(page);
  1088. up_read(&mdsc->snap_rwsem);
  1089. ret = VM_FAULT_LOCKED;
  1090. } else {
  1091. if (ret == -ENOMEM)
  1092. ret = VM_FAULT_OOM;
  1093. else
  1094. ret = VM_FAULT_SIGBUS;
  1095. }
  1096. out:
  1097. dout("page_mkwrite %p %llu~%llu = %d\n", inode, off, len, ret);
  1098. if (ret != VM_FAULT_LOCKED)
  1099. unlock_page(page);
  1100. return ret;
  1101. }
  1102. static struct vm_operations_struct ceph_vmops = {
  1103. .fault = filemap_fault,
  1104. .page_mkwrite = ceph_page_mkwrite,
  1105. .remap_pages = generic_file_remap_pages,
  1106. };
  1107. int ceph_mmap(struct file *file, struct vm_area_struct *vma)
  1108. {
  1109. struct address_space *mapping = file->f_mapping;
  1110. if (!mapping->a_ops->readpage)
  1111. return -ENOEXEC;
  1112. file_accessed(file);
  1113. vma->vm_ops = &ceph_vmops;
  1114. return 0;
  1115. }