addr.c 34 KB

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