addr.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262
  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 int offset,
  129. unsigned int length)
  130. {
  131. struct inode *inode;
  132. struct ceph_inode_info *ci;
  133. struct ceph_snap_context *snapc = page_snap_context(page);
  134. BUG_ON(!PageLocked(page));
  135. BUG_ON(!PagePrivate(page));
  136. BUG_ON(!page->mapping);
  137. inode = page->mapping->host;
  138. /*
  139. * We can get non-dirty pages here due to races between
  140. * set_page_dirty and truncate_complete_page; just spit out a
  141. * warning, in case we end up with accounting problems later.
  142. */
  143. if (!PageDirty(page))
  144. pr_err("%p invalidatepage %p page not dirty\n", inode, page);
  145. if (offset == 0 && length == PAGE_CACHE_SIZE)
  146. ClearPageChecked(page);
  147. ci = ceph_inode(inode);
  148. if (offset == 0 && length == PAGE_CACHE_SIZE) {
  149. dout("%p invalidatepage %p idx %lu full dirty page\n",
  150. inode, page, page->index);
  151. ceph_put_wrbuffer_cap_refs(ci, 1, snapc);
  152. ceph_put_snap_context(snapc);
  153. page->private = 0;
  154. ClearPagePrivate(page);
  155. } else {
  156. dout("%p invalidatepage %p idx %lu partial dirty page %u(%u)\n",
  157. inode, page, page->index, offset, length);
  158. }
  159. }
  160. /* just a sanity check */
  161. static int ceph_releasepage(struct page *page, gfp_t g)
  162. {
  163. struct inode *inode = page->mapping ? page->mapping->host : NULL;
  164. dout("%p releasepage %p idx %lu\n", inode, page, page->index);
  165. WARN_ON(PageDirty(page));
  166. WARN_ON(PagePrivate(page));
  167. return 0;
  168. }
  169. /*
  170. * read a single page, without unlocking it.
  171. */
  172. static int readpage_nounlock(struct file *filp, struct page *page)
  173. {
  174. struct inode *inode = file_inode(filp);
  175. struct ceph_inode_info *ci = ceph_inode(inode);
  176. struct ceph_osd_client *osdc =
  177. &ceph_inode_to_client(inode)->client->osdc;
  178. int err = 0;
  179. u64 len = PAGE_CACHE_SIZE;
  180. dout("readpage inode %p file %p page %p index %lu\n",
  181. inode, filp, page, page->index);
  182. err = ceph_osdc_readpages(osdc, ceph_vino(inode), &ci->i_layout,
  183. (u64) page_offset(page), &len,
  184. ci->i_truncate_seq, ci->i_truncate_size,
  185. &page, 1, 0);
  186. if (err == -ENOENT)
  187. err = 0;
  188. if (err < 0) {
  189. SetPageError(page);
  190. goto out;
  191. } else if (err < PAGE_CACHE_SIZE) {
  192. /* zero fill remainder of page */
  193. zero_user_segment(page, err, PAGE_CACHE_SIZE);
  194. }
  195. SetPageUptodate(page);
  196. out:
  197. return err < 0 ? err : 0;
  198. }
  199. static int ceph_readpage(struct file *filp, struct page *page)
  200. {
  201. int r = readpage_nounlock(filp, page);
  202. unlock_page(page);
  203. return r;
  204. }
  205. /*
  206. * Finish an async read(ahead) op.
  207. */
  208. static void finish_read(struct ceph_osd_request *req, struct ceph_msg *msg)
  209. {
  210. struct inode *inode = req->r_inode;
  211. struct ceph_osd_data *osd_data;
  212. int rc = req->r_result;
  213. int bytes = le32_to_cpu(msg->hdr.data_len);
  214. int num_pages;
  215. int i;
  216. dout("finish_read %p req %p rc %d bytes %d\n", inode, req, rc, bytes);
  217. /* unlock all pages, zeroing any data we didn't read */
  218. osd_data = osd_req_op_extent_osd_data(req, 0);
  219. BUG_ON(osd_data->type != CEPH_OSD_DATA_TYPE_PAGES);
  220. num_pages = calc_pages_for((u64)osd_data->alignment,
  221. (u64)osd_data->length);
  222. for (i = 0; i < num_pages; i++) {
  223. struct page *page = osd_data->pages[i];
  224. if (bytes < (int)PAGE_CACHE_SIZE) {
  225. /* zero (remainder of) page */
  226. int s = bytes < 0 ? 0 : bytes;
  227. zero_user_segment(page, s, PAGE_CACHE_SIZE);
  228. }
  229. dout("finish_read %p uptodate %p idx %lu\n", inode, page,
  230. page->index);
  231. flush_dcache_page(page);
  232. SetPageUptodate(page);
  233. unlock_page(page);
  234. page_cache_release(page);
  235. bytes -= PAGE_CACHE_SIZE;
  236. }
  237. kfree(osd_data->pages);
  238. }
  239. static void ceph_unlock_page_vector(struct page **pages, int num_pages)
  240. {
  241. int i;
  242. for (i = 0; i < num_pages; i++)
  243. unlock_page(pages[i]);
  244. }
  245. /*
  246. * start an async read(ahead) operation. return nr_pages we submitted
  247. * a read for on success, or negative error code.
  248. */
  249. static int start_read(struct inode *inode, struct list_head *page_list, int max)
  250. {
  251. struct ceph_osd_client *osdc =
  252. &ceph_inode_to_client(inode)->client->osdc;
  253. struct ceph_inode_info *ci = ceph_inode(inode);
  254. struct page *page = list_entry(page_list->prev, struct page, lru);
  255. struct ceph_vino vino;
  256. struct ceph_osd_request *req;
  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, 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. osd_req_op_extent_osd_data_pages(req, 0, pages, len, 0, 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. struct ceph_snap_context *snapc, *oldest;
  394. loff_t page_off = page_offset(page);
  395. long writeback_stat;
  396. u64 truncate_size, snap_size = 0;
  397. u32 truncate_seq;
  398. int err = 0, len = PAGE_CACHE_SIZE;
  399. dout("writepage %p idx %lu\n", page, page->index);
  400. if (!page->mapping || !page->mapping->host) {
  401. dout("writepage %p - no mapping\n", page);
  402. return -EFAULT;
  403. }
  404. inode = page->mapping->host;
  405. ci = ceph_inode(inode);
  406. fsc = ceph_inode_to_client(inode);
  407. osdc = &fsc->client->osdc;
  408. /* verify this is a writeable snap context */
  409. snapc = page_snap_context(page);
  410. if (snapc == NULL) {
  411. dout("writepage %p page %p not dirty?\n", inode, page);
  412. goto out;
  413. }
  414. oldest = get_oldest_context(inode, &snap_size);
  415. if (snapc->seq > oldest->seq) {
  416. dout("writepage %p page %p snapc %p not writeable - noop\n",
  417. inode, page, snapc);
  418. /* we should only noop if called by kswapd */
  419. WARN_ON((current->flags & PF_MEMALLOC) == 0);
  420. ceph_put_snap_context(oldest);
  421. goto out;
  422. }
  423. ceph_put_snap_context(oldest);
  424. spin_lock(&ci->i_ceph_lock);
  425. truncate_seq = ci->i_truncate_seq;
  426. truncate_size = ci->i_truncate_size;
  427. if (!snap_size)
  428. snap_size = i_size_read(inode);
  429. spin_unlock(&ci->i_ceph_lock);
  430. /* is this a partial page at end of file? */
  431. if (page_off >= snap_size) {
  432. dout("%p page eof %llu\n", page, snap_size);
  433. goto out;
  434. }
  435. if (snap_size < page_off + len)
  436. len = snap_size - page_off;
  437. dout("writepage %p page %p index %lu on %llu~%u snapc %p\n",
  438. inode, page, page->index, page_off, len, snapc);
  439. writeback_stat = atomic_long_inc_return(&fsc->writeback_count);
  440. if (writeback_stat >
  441. CONGESTION_ON_THRESH(fsc->mount_options->congestion_kb))
  442. set_bdi_congested(&fsc->backing_dev_info, BLK_RW_ASYNC);
  443. set_page_writeback(page);
  444. err = ceph_osdc_writepages(osdc, ceph_vino(inode),
  445. &ci->i_layout, snapc,
  446. page_off, len,
  447. truncate_seq, truncate_size,
  448. &inode->i_mtime, &page, 1);
  449. if (err < 0) {
  450. dout("writepage setting page/mapping error %d %p\n", err, page);
  451. SetPageError(page);
  452. mapping_set_error(&inode->i_data, err);
  453. if (wbc)
  454. wbc->pages_skipped++;
  455. } else {
  456. dout("writepage cleaned page %p\n", page);
  457. err = 0; /* vfs expects us to return 0 */
  458. }
  459. page->private = 0;
  460. ClearPagePrivate(page);
  461. end_page_writeback(page);
  462. ceph_put_wrbuffer_cap_refs(ci, 1, snapc);
  463. ceph_put_snap_context(snapc); /* page's reference */
  464. out:
  465. return err;
  466. }
  467. static int ceph_writepage(struct page *page, struct writeback_control *wbc)
  468. {
  469. int err;
  470. struct inode *inode = page->mapping->host;
  471. BUG_ON(!inode);
  472. ihold(inode);
  473. err = writepage_nounlock(page, wbc);
  474. unlock_page(page);
  475. iput(inode);
  476. return err;
  477. }
  478. /*
  479. * lame release_pages helper. release_pages() isn't exported to
  480. * modules.
  481. */
  482. static void ceph_release_pages(struct page **pages, int num)
  483. {
  484. struct pagevec pvec;
  485. int i;
  486. pagevec_init(&pvec, 0);
  487. for (i = 0; i < num; i++) {
  488. if (pagevec_add(&pvec, pages[i]) == 0)
  489. pagevec_release(&pvec);
  490. }
  491. pagevec_release(&pvec);
  492. }
  493. /*
  494. * async writeback completion handler.
  495. *
  496. * If we get an error, set the mapping error bit, but not the individual
  497. * page error bits.
  498. */
  499. static void writepages_finish(struct ceph_osd_request *req,
  500. struct ceph_msg *msg)
  501. {
  502. struct inode *inode = req->r_inode;
  503. struct ceph_inode_info *ci = ceph_inode(inode);
  504. struct ceph_osd_data *osd_data;
  505. unsigned wrote;
  506. struct page *page;
  507. int num_pages;
  508. int i;
  509. struct ceph_snap_context *snapc = req->r_snapc;
  510. struct address_space *mapping = inode->i_mapping;
  511. int rc = req->r_result;
  512. u64 bytes = req->r_ops[0].extent.length;
  513. struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
  514. long writeback_stat;
  515. unsigned issued = ceph_caps_issued(ci);
  516. osd_data = osd_req_op_extent_osd_data(req, 0);
  517. BUG_ON(osd_data->type != CEPH_OSD_DATA_TYPE_PAGES);
  518. num_pages = calc_pages_for((u64)osd_data->alignment,
  519. (u64)osd_data->length);
  520. if (rc >= 0) {
  521. /*
  522. * Assume we wrote the pages we originally sent. The
  523. * osd might reply with fewer pages if our writeback
  524. * raced with a truncation and was adjusted at the osd,
  525. * so don't believe the reply.
  526. */
  527. wrote = num_pages;
  528. } else {
  529. wrote = 0;
  530. mapping_set_error(mapping, rc);
  531. }
  532. dout("writepages_finish %p rc %d bytes %llu wrote %d (pages)\n",
  533. inode, rc, bytes, wrote);
  534. /* clean all pages */
  535. for (i = 0; i < num_pages; i++) {
  536. page = osd_data->pages[i];
  537. BUG_ON(!page);
  538. WARN_ON(!PageUptodate(page));
  539. writeback_stat =
  540. atomic_long_dec_return(&fsc->writeback_count);
  541. if (writeback_stat <
  542. CONGESTION_OFF_THRESH(fsc->mount_options->congestion_kb))
  543. clear_bdi_congested(&fsc->backing_dev_info,
  544. BLK_RW_ASYNC);
  545. ceph_put_snap_context(page_snap_context(page));
  546. page->private = 0;
  547. ClearPagePrivate(page);
  548. dout("unlocking %d %p\n", i, page);
  549. end_page_writeback(page);
  550. /*
  551. * We lost the cache cap, need to truncate the page before
  552. * it is unlocked, otherwise we'd truncate it later in the
  553. * page truncation thread, possibly losing some data that
  554. * raced its way in
  555. */
  556. if ((issued & (CEPH_CAP_FILE_CACHE|CEPH_CAP_FILE_LAZYIO)) == 0)
  557. generic_error_remove_page(inode->i_mapping, page);
  558. unlock_page(page);
  559. }
  560. dout("%p wrote+cleaned %d pages\n", inode, wrote);
  561. ceph_put_wrbuffer_cap_refs(ci, num_pages, snapc);
  562. ceph_release_pages(osd_data->pages, num_pages);
  563. if (osd_data->pages_from_pool)
  564. mempool_free(osd_data->pages,
  565. ceph_sb_to_client(inode->i_sb)->wb_pagevec_pool);
  566. else
  567. kfree(osd_data->pages);
  568. ceph_osdc_put_request(req);
  569. }
  570. /*
  571. * initiate async writeback
  572. */
  573. static int ceph_writepages_start(struct address_space *mapping,
  574. struct writeback_control *wbc)
  575. {
  576. struct inode *inode = mapping->host;
  577. struct ceph_inode_info *ci = ceph_inode(inode);
  578. struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
  579. struct ceph_vino vino = ceph_vino(inode);
  580. pgoff_t index, start, end;
  581. int range_whole = 0;
  582. int should_loop = 1;
  583. pgoff_t max_pages = 0, max_pages_ever = 0;
  584. struct ceph_snap_context *snapc = NULL, *last_snapc = NULL, *pgsnapc;
  585. struct pagevec pvec;
  586. int done = 0;
  587. int rc = 0;
  588. unsigned wsize = 1 << inode->i_blkbits;
  589. struct ceph_osd_request *req = NULL;
  590. int do_sync;
  591. u64 truncate_size, snap_size;
  592. u32 truncate_seq;
  593. /*
  594. * Include a 'sync' in the OSD request if this is a data
  595. * integrity write (e.g., O_SYNC write or fsync()), or if our
  596. * cap is being revoked.
  597. */
  598. if ((wbc->sync_mode == WB_SYNC_ALL) ||
  599. ceph_caps_revoking(ci, CEPH_CAP_FILE_BUFFER))
  600. do_sync = 1;
  601. dout("writepages_start %p dosync=%d (mode=%s)\n",
  602. inode, do_sync,
  603. wbc->sync_mode == WB_SYNC_NONE ? "NONE" :
  604. (wbc->sync_mode == WB_SYNC_ALL ? "ALL" : "HOLD"));
  605. if (fsc->mount_state == CEPH_MOUNT_SHUTDOWN) {
  606. pr_warning("writepage_start %p on forced umount\n", inode);
  607. return -EIO; /* we're in a forced umount, don't write! */
  608. }
  609. if (fsc->mount_options->wsize && fsc->mount_options->wsize < wsize)
  610. wsize = fsc->mount_options->wsize;
  611. if (wsize < PAGE_CACHE_SIZE)
  612. wsize = PAGE_CACHE_SIZE;
  613. max_pages_ever = wsize >> PAGE_CACHE_SHIFT;
  614. pagevec_init(&pvec, 0);
  615. /* where to start/end? */
  616. if (wbc->range_cyclic) {
  617. start = mapping->writeback_index; /* Start from prev offset */
  618. end = -1;
  619. dout(" cyclic, start at %lu\n", start);
  620. } else {
  621. start = wbc->range_start >> PAGE_CACHE_SHIFT;
  622. end = wbc->range_end >> PAGE_CACHE_SHIFT;
  623. if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
  624. range_whole = 1;
  625. should_loop = 0;
  626. dout(" not cyclic, %lu to %lu\n", start, end);
  627. }
  628. index = start;
  629. retry:
  630. /* find oldest snap context with dirty data */
  631. ceph_put_snap_context(snapc);
  632. snap_size = 0;
  633. snapc = get_oldest_context(inode, &snap_size);
  634. if (!snapc) {
  635. /* hmm, why does writepages get called when there
  636. is no dirty data? */
  637. dout(" no snap context with dirty data?\n");
  638. goto out;
  639. }
  640. if (snap_size == 0)
  641. snap_size = i_size_read(inode);
  642. dout(" oldest snapc is %p seq %lld (%d snaps)\n",
  643. snapc, snapc->seq, snapc->num_snaps);
  644. spin_lock(&ci->i_ceph_lock);
  645. truncate_seq = ci->i_truncate_seq;
  646. truncate_size = ci->i_truncate_size;
  647. if (!snap_size)
  648. snap_size = i_size_read(inode);
  649. spin_unlock(&ci->i_ceph_lock);
  650. if (last_snapc && snapc != last_snapc) {
  651. /* if we switched to a newer snapc, restart our scan at the
  652. * start of the original file range. */
  653. dout(" snapc differs from last pass, restarting at %lu\n",
  654. index);
  655. index = start;
  656. }
  657. last_snapc = snapc;
  658. while (!done && index <= end) {
  659. int num_ops = do_sync ? 2 : 1;
  660. unsigned i;
  661. int first;
  662. pgoff_t next;
  663. int pvec_pages, locked_pages;
  664. struct page **pages = NULL;
  665. mempool_t *pool = NULL; /* Becomes non-null if mempool used */
  666. struct page *page;
  667. int want;
  668. u64 offset, len;
  669. long writeback_stat;
  670. next = 0;
  671. locked_pages = 0;
  672. max_pages = max_pages_ever;
  673. get_more_pages:
  674. first = -1;
  675. want = min(end - index,
  676. min((pgoff_t)PAGEVEC_SIZE,
  677. max_pages - (pgoff_t)locked_pages) - 1)
  678. + 1;
  679. pvec_pages = pagevec_lookup_tag(&pvec, mapping, &index,
  680. PAGECACHE_TAG_DIRTY,
  681. want);
  682. dout("pagevec_lookup_tag got %d\n", pvec_pages);
  683. if (!pvec_pages && !locked_pages)
  684. break;
  685. for (i = 0; i < pvec_pages && locked_pages < max_pages; i++) {
  686. page = pvec.pages[i];
  687. dout("? %p idx %lu\n", page, page->index);
  688. if (locked_pages == 0)
  689. lock_page(page); /* first page */
  690. else if (!trylock_page(page))
  691. break;
  692. /* only dirty pages, or our accounting breaks */
  693. if (unlikely(!PageDirty(page)) ||
  694. unlikely(page->mapping != mapping)) {
  695. dout("!dirty or !mapping %p\n", page);
  696. unlock_page(page);
  697. break;
  698. }
  699. if (!wbc->range_cyclic && page->index > end) {
  700. dout("end of range %p\n", page);
  701. done = 1;
  702. unlock_page(page);
  703. break;
  704. }
  705. if (next && (page->index != next)) {
  706. dout("not consecutive %p\n", page);
  707. unlock_page(page);
  708. break;
  709. }
  710. if (wbc->sync_mode != WB_SYNC_NONE) {
  711. dout("waiting on writeback %p\n", page);
  712. wait_on_page_writeback(page);
  713. }
  714. if (page_offset(page) >= snap_size) {
  715. dout("%p page eof %llu\n", page, snap_size);
  716. done = 1;
  717. unlock_page(page);
  718. break;
  719. }
  720. if (PageWriteback(page)) {
  721. dout("%p under writeback\n", page);
  722. unlock_page(page);
  723. break;
  724. }
  725. /* only if matching snap context */
  726. pgsnapc = page_snap_context(page);
  727. if (pgsnapc->seq > snapc->seq) {
  728. dout("page snapc %p %lld > oldest %p %lld\n",
  729. pgsnapc, pgsnapc->seq, snapc, snapc->seq);
  730. unlock_page(page);
  731. if (!locked_pages)
  732. continue; /* keep looking for snap */
  733. break;
  734. }
  735. if (!clear_page_dirty_for_io(page)) {
  736. dout("%p !clear_page_dirty_for_io\n", page);
  737. unlock_page(page);
  738. break;
  739. }
  740. /*
  741. * We have something to write. If this is
  742. * the first locked page this time through,
  743. * allocate an osd request and a page array
  744. * that it will use.
  745. */
  746. if (locked_pages == 0) {
  747. BUG_ON(pages);
  748. /* prepare async write request */
  749. offset = (u64)page_offset(page);
  750. len = wsize;
  751. req = ceph_osdc_new_request(&fsc->client->osdc,
  752. &ci->i_layout, vino,
  753. offset, &len, num_ops,
  754. CEPH_OSD_OP_WRITE,
  755. CEPH_OSD_FLAG_WRITE |
  756. CEPH_OSD_FLAG_ONDISK,
  757. snapc, truncate_seq,
  758. truncate_size, true);
  759. if (IS_ERR(req)) {
  760. rc = PTR_ERR(req);
  761. unlock_page(page);
  762. break;
  763. }
  764. req->r_callback = writepages_finish;
  765. req->r_inode = inode;
  766. max_pages = calc_pages_for(0, (u64)len);
  767. pages = kmalloc(max_pages * sizeof (*pages),
  768. GFP_NOFS);
  769. if (!pages) {
  770. pool = fsc->wb_pagevec_pool;
  771. pages = mempool_alloc(pool, GFP_NOFS);
  772. BUG_ON(!pages);
  773. }
  774. }
  775. /* note position of first page in pvec */
  776. if (first < 0)
  777. first = i;
  778. dout("%p will write page %p idx %lu\n",
  779. inode, page, page->index);
  780. writeback_stat =
  781. atomic_long_inc_return(&fsc->writeback_count);
  782. if (writeback_stat > CONGESTION_ON_THRESH(
  783. fsc->mount_options->congestion_kb)) {
  784. set_bdi_congested(&fsc->backing_dev_info,
  785. BLK_RW_ASYNC);
  786. }
  787. set_page_writeback(page);
  788. pages[locked_pages] = page;
  789. locked_pages++;
  790. next = page->index + 1;
  791. }
  792. /* did we get anything? */
  793. if (!locked_pages)
  794. goto release_pvec_pages;
  795. if (i) {
  796. int j;
  797. BUG_ON(!locked_pages || first < 0);
  798. if (pvec_pages && i == pvec_pages &&
  799. locked_pages < max_pages) {
  800. dout("reached end pvec, trying for more\n");
  801. pagevec_reinit(&pvec);
  802. goto get_more_pages;
  803. }
  804. /* shift unused pages over in the pvec... we
  805. * will need to release them below. */
  806. for (j = i; j < pvec_pages; j++) {
  807. dout(" pvec leftover page %p\n",
  808. pvec.pages[j]);
  809. pvec.pages[j-i+first] = pvec.pages[j];
  810. }
  811. pvec.nr -= i-first;
  812. }
  813. /* Format the osd request message and submit the write */
  814. offset = page_offset(pages[0]);
  815. len = min(snap_size - offset,
  816. (u64)locked_pages << PAGE_CACHE_SHIFT);
  817. dout("writepages got %d pages at %llu~%llu\n",
  818. locked_pages, offset, len);
  819. osd_req_op_extent_osd_data_pages(req, 0, pages, len, 0,
  820. !!pool, false);
  821. pages = NULL; /* request message now owns the pages array */
  822. pool = NULL;
  823. /* Update the write op length in case we changed it */
  824. osd_req_op_extent_update(req, 0, len);
  825. vino = ceph_vino(inode);
  826. ceph_osdc_build_request(req, offset, snapc, vino.snap,
  827. &inode->i_mtime);
  828. rc = ceph_osdc_start_request(&fsc->client->osdc, req, true);
  829. BUG_ON(rc);
  830. req = NULL;
  831. /* continue? */
  832. index = next;
  833. wbc->nr_to_write -= locked_pages;
  834. if (wbc->nr_to_write <= 0)
  835. done = 1;
  836. release_pvec_pages:
  837. dout("pagevec_release on %d pages (%p)\n", (int)pvec.nr,
  838. pvec.nr ? pvec.pages[0] : NULL);
  839. pagevec_release(&pvec);
  840. if (locked_pages && !done)
  841. goto retry;
  842. }
  843. if (should_loop && !done) {
  844. /* more to do; loop back to beginning of file */
  845. dout("writepages looping back to beginning of file\n");
  846. should_loop = 0;
  847. index = 0;
  848. goto retry;
  849. }
  850. if (wbc->range_cyclic || (range_whole && wbc->nr_to_write > 0))
  851. mapping->writeback_index = index;
  852. out:
  853. if (req)
  854. ceph_osdc_put_request(req);
  855. ceph_put_snap_context(snapc);
  856. dout("writepages done, rc = %d\n", rc);
  857. return rc;
  858. }
  859. /*
  860. * See if a given @snapc is either writeable, or already written.
  861. */
  862. static int context_is_writeable_or_written(struct inode *inode,
  863. struct ceph_snap_context *snapc)
  864. {
  865. struct ceph_snap_context *oldest = get_oldest_context(inode, NULL);
  866. int ret = !oldest || snapc->seq <= oldest->seq;
  867. ceph_put_snap_context(oldest);
  868. return ret;
  869. }
  870. /*
  871. * We are only allowed to write into/dirty the page if the page is
  872. * clean, or already dirty within the same snap context.
  873. *
  874. * called with page locked.
  875. * return success with page locked,
  876. * or any failure (incl -EAGAIN) with page unlocked.
  877. */
  878. static int ceph_update_writeable_page(struct file *file,
  879. loff_t pos, unsigned len,
  880. struct page *page)
  881. {
  882. struct inode *inode = file_inode(file);
  883. struct ceph_inode_info *ci = ceph_inode(inode);
  884. struct ceph_mds_client *mdsc = ceph_inode_to_client(inode)->mdsc;
  885. loff_t page_off = pos & PAGE_CACHE_MASK;
  886. int pos_in_page = pos & ~PAGE_CACHE_MASK;
  887. int end_in_page = pos_in_page + len;
  888. loff_t i_size;
  889. int r;
  890. struct ceph_snap_context *snapc, *oldest;
  891. retry_locked:
  892. /* writepages currently holds page lock, but if we change that later, */
  893. wait_on_page_writeback(page);
  894. /* check snap context */
  895. BUG_ON(!ci->i_snap_realm);
  896. down_read(&mdsc->snap_rwsem);
  897. BUG_ON(!ci->i_snap_realm->cached_context);
  898. snapc = page_snap_context(page);
  899. if (snapc && snapc != ci->i_head_snapc) {
  900. /*
  901. * this page is already dirty in another (older) snap
  902. * context! is it writeable now?
  903. */
  904. oldest = get_oldest_context(inode, NULL);
  905. up_read(&mdsc->snap_rwsem);
  906. if (snapc->seq > oldest->seq) {
  907. ceph_put_snap_context(oldest);
  908. dout(" page %p snapc %p not current or oldest\n",
  909. page, snapc);
  910. /*
  911. * queue for writeback, and wait for snapc to
  912. * be writeable or written
  913. */
  914. snapc = ceph_get_snap_context(snapc);
  915. unlock_page(page);
  916. ceph_queue_writeback(inode);
  917. r = wait_event_interruptible(ci->i_cap_wq,
  918. context_is_writeable_or_written(inode, snapc));
  919. ceph_put_snap_context(snapc);
  920. if (r == -ERESTARTSYS)
  921. return r;
  922. return -EAGAIN;
  923. }
  924. ceph_put_snap_context(oldest);
  925. /* yay, writeable, do it now (without dropping page lock) */
  926. dout(" page %p snapc %p not current, but oldest\n",
  927. page, snapc);
  928. if (!clear_page_dirty_for_io(page))
  929. goto retry_locked;
  930. r = writepage_nounlock(page, NULL);
  931. if (r < 0)
  932. goto fail_nosnap;
  933. goto retry_locked;
  934. }
  935. if (PageUptodate(page)) {
  936. dout(" page %p already uptodate\n", page);
  937. return 0;
  938. }
  939. /* full page? */
  940. if (pos_in_page == 0 && len == PAGE_CACHE_SIZE)
  941. return 0;
  942. /* past end of file? */
  943. i_size = inode->i_size; /* caller holds i_mutex */
  944. if (i_size + len > inode->i_sb->s_maxbytes) {
  945. /* file is too big */
  946. r = -EINVAL;
  947. goto fail;
  948. }
  949. if (page_off >= i_size ||
  950. (pos_in_page == 0 && (pos+len) >= i_size &&
  951. end_in_page - pos_in_page != PAGE_CACHE_SIZE)) {
  952. dout(" zeroing %p 0 - %d and %d - %d\n",
  953. page, pos_in_page, end_in_page, (int)PAGE_CACHE_SIZE);
  954. zero_user_segments(page,
  955. 0, pos_in_page,
  956. end_in_page, PAGE_CACHE_SIZE);
  957. return 0;
  958. }
  959. /* we need to read it. */
  960. up_read(&mdsc->snap_rwsem);
  961. r = readpage_nounlock(file, page);
  962. if (r < 0)
  963. goto fail_nosnap;
  964. goto retry_locked;
  965. fail:
  966. up_read(&mdsc->snap_rwsem);
  967. fail_nosnap:
  968. unlock_page(page);
  969. return r;
  970. }
  971. /*
  972. * We are only allowed to write into/dirty the page if the page is
  973. * clean, or already dirty within the same snap context.
  974. */
  975. static int ceph_write_begin(struct file *file, struct address_space *mapping,
  976. loff_t pos, unsigned len, unsigned flags,
  977. struct page **pagep, void **fsdata)
  978. {
  979. struct inode *inode = file_inode(file);
  980. struct page *page;
  981. pgoff_t index = pos >> PAGE_CACHE_SHIFT;
  982. int r;
  983. do {
  984. /* get a page */
  985. page = grab_cache_page_write_begin(mapping, index, 0);
  986. if (!page)
  987. return -ENOMEM;
  988. *pagep = page;
  989. dout("write_begin file %p inode %p page %p %d~%d\n", file,
  990. inode, page, (int)pos, (int)len);
  991. r = ceph_update_writeable_page(file, pos, len, page);
  992. } while (r == -EAGAIN);
  993. return r;
  994. }
  995. /*
  996. * we don't do anything in here that simple_write_end doesn't do
  997. * except adjust dirty page accounting and drop read lock on
  998. * mdsc->snap_rwsem.
  999. */
  1000. static int ceph_write_end(struct file *file, struct address_space *mapping,
  1001. loff_t pos, unsigned len, unsigned copied,
  1002. struct page *page, void *fsdata)
  1003. {
  1004. struct inode *inode = file_inode(file);
  1005. struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
  1006. struct ceph_mds_client *mdsc = fsc->mdsc;
  1007. unsigned from = pos & (PAGE_CACHE_SIZE - 1);
  1008. int check_cap = 0;
  1009. dout("write_end file %p inode %p page %p %d~%d (%d)\n", file,
  1010. inode, page, (int)pos, (int)copied, (int)len);
  1011. /* zero the stale part of the page if we did a short copy */
  1012. if (copied < len)
  1013. zero_user_segment(page, from+copied, len);
  1014. /* did file size increase? */
  1015. /* (no need for i_size_read(); we caller holds i_mutex */
  1016. if (pos+copied > inode->i_size)
  1017. check_cap = ceph_inode_set_size(inode, pos+copied);
  1018. if (!PageUptodate(page))
  1019. SetPageUptodate(page);
  1020. set_page_dirty(page);
  1021. unlock_page(page);
  1022. up_read(&mdsc->snap_rwsem);
  1023. page_cache_release(page);
  1024. if (check_cap)
  1025. ceph_check_caps(ceph_inode(inode), CHECK_CAPS_AUTHONLY, NULL);
  1026. return copied;
  1027. }
  1028. /*
  1029. * we set .direct_IO to indicate direct io is supported, but since we
  1030. * intercept O_DIRECT reads and writes early, this function should
  1031. * never get called.
  1032. */
  1033. static ssize_t ceph_direct_io(int rw, struct kiocb *iocb,
  1034. const struct iovec *iov,
  1035. loff_t pos, unsigned long nr_segs)
  1036. {
  1037. WARN_ON(1);
  1038. return -EINVAL;
  1039. }
  1040. const struct address_space_operations ceph_aops = {
  1041. .readpage = ceph_readpage,
  1042. .readpages = ceph_readpages,
  1043. .writepage = ceph_writepage,
  1044. .writepages = ceph_writepages_start,
  1045. .write_begin = ceph_write_begin,
  1046. .write_end = ceph_write_end,
  1047. .set_page_dirty = ceph_set_page_dirty,
  1048. .invalidatepage = ceph_invalidatepage,
  1049. .releasepage = ceph_releasepage,
  1050. .direct_IO = ceph_direct_io,
  1051. };
  1052. /*
  1053. * vm ops
  1054. */
  1055. /*
  1056. * Reuse write_begin here for simplicity.
  1057. */
  1058. static int ceph_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
  1059. {
  1060. struct inode *inode = file_inode(vma->vm_file);
  1061. struct page *page = vmf->page;
  1062. struct ceph_mds_client *mdsc = ceph_inode_to_client(inode)->mdsc;
  1063. loff_t off = page_offset(page);
  1064. loff_t size, len;
  1065. int ret;
  1066. /* Update time before taking page lock */
  1067. file_update_time(vma->vm_file);
  1068. size = i_size_read(inode);
  1069. if (off + PAGE_CACHE_SIZE <= size)
  1070. len = PAGE_CACHE_SIZE;
  1071. else
  1072. len = size & ~PAGE_CACHE_MASK;
  1073. dout("page_mkwrite %p %llu~%llu page %p idx %lu\n", inode,
  1074. off, len, page, page->index);
  1075. lock_page(page);
  1076. ret = VM_FAULT_NOPAGE;
  1077. if ((off > size) ||
  1078. (page->mapping != inode->i_mapping))
  1079. goto out;
  1080. ret = ceph_update_writeable_page(vma->vm_file, off, len, page);
  1081. if (ret == 0) {
  1082. /* success. we'll keep the page locked. */
  1083. set_page_dirty(page);
  1084. up_read(&mdsc->snap_rwsem);
  1085. ret = VM_FAULT_LOCKED;
  1086. } else {
  1087. if (ret == -ENOMEM)
  1088. ret = VM_FAULT_OOM;
  1089. else
  1090. ret = VM_FAULT_SIGBUS;
  1091. }
  1092. out:
  1093. dout("page_mkwrite %p %llu~%llu = %d\n", inode, off, len, ret);
  1094. if (ret != VM_FAULT_LOCKED)
  1095. unlock_page(page);
  1096. return ret;
  1097. }
  1098. static struct vm_operations_struct ceph_vmops = {
  1099. .fault = filemap_fault,
  1100. .page_mkwrite = ceph_page_mkwrite,
  1101. .remap_pages = generic_file_remap_pages,
  1102. };
  1103. int ceph_mmap(struct file *file, struct vm_area_struct *vma)
  1104. {
  1105. struct address_space *mapping = file->f_mapping;
  1106. if (!mapping->a_ops->readpage)
  1107. return -ENOEXEC;
  1108. file_accessed(file);
  1109. vma->vm_ops = &ceph_vmops;
  1110. return 0;
  1111. }