data.c 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934
  1. /*
  2. * fs/f2fs/data.c
  3. *
  4. * Copyright (c) 2012 Samsung Electronics Co., Ltd.
  5. * http://www.samsung.com/
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/fs.h>
  12. #include <linux/f2fs_fs.h>
  13. #include <linux/buffer_head.h>
  14. #include <linux/mpage.h>
  15. #include <linux/aio.h>
  16. #include <linux/writeback.h>
  17. #include <linux/backing-dev.h>
  18. #include <linux/pagevec.h>
  19. #include <linux/blkdev.h>
  20. #include <linux/bio.h>
  21. #include <linux/prefetch.h>
  22. #include <linux/uio.h>
  23. #include <linux/mm.h>
  24. #include <linux/memcontrol.h>
  25. #include <linux/cleancache.h>
  26. #include "f2fs.h"
  27. #include "node.h"
  28. #include "segment.h"
  29. #include "trace.h"
  30. #include <trace/events/f2fs.h>
  31. static bool __is_cp_guaranteed(struct page *page)
  32. {
  33. struct address_space *mapping = page->mapping;
  34. struct inode *inode;
  35. struct f2fs_sb_info *sbi;
  36. if (!mapping)
  37. return false;
  38. inode = mapping->host;
  39. sbi = F2FS_I_SB(inode);
  40. if (inode->i_ino == F2FS_META_INO(sbi) ||
  41. inode->i_ino == F2FS_NODE_INO(sbi) ||
  42. S_ISDIR(inode->i_mode) ||
  43. is_cold_data(page))
  44. return true;
  45. return false;
  46. }
  47. static void f2fs_read_end_io(struct bio *bio, int err)
  48. {
  49. struct bio_vec *bvec;
  50. int i;
  51. #ifdef CONFIG_F2FS_FAULT_INJECTION
  52. if (time_to_inject(F2FS_P_SB(bio->bi_io_vec->bv_page), FAULT_IO))
  53. err = -EIO;
  54. #endif
  55. if (f2fs_bio_encrypted(bio)) {
  56. if (err) {
  57. fscrypt_release_ctx(bio->bi_private);
  58. } else {
  59. fscrypt_decrypt_bio_pages(bio->bi_private, bio);
  60. return;
  61. }
  62. }
  63. __bio_for_each_segment(bvec, bio, i, 0) {
  64. struct page *page = bvec->bv_page;
  65. if (!err) {
  66. if (!PageUptodate(page))
  67. SetPageUptodate(page);
  68. } else {
  69. ClearPageUptodate(page);
  70. SetPageError(page);
  71. }
  72. unlock_page(page);
  73. }
  74. bio_put(bio);
  75. }
  76. static void f2fs_write_end_io(struct bio *bio, int err)
  77. {
  78. struct f2fs_sb_info *sbi = bio->bi_private;
  79. struct bio_vec *bvec;
  80. int i;
  81. __bio_for_each_segment(bvec, bio, i, 0) {
  82. struct page *page = bvec->bv_page;
  83. enum count_type type = WB_DATA_TYPE(page);
  84. fscrypt_pullback_bio_page(&page, true);
  85. if (unlikely(err)) {
  86. set_bit(AS_EIO, &page->mapping->flags);
  87. f2fs_stop_checkpoint(sbi, true);
  88. }
  89. dec_page_count(sbi, type);
  90. clear_cold_data(page);
  91. end_page_writeback(page);
  92. }
  93. if (!get_pages(sbi, F2FS_WB_CP_DATA) &&
  94. wq_has_sleeper(&sbi->cp_wait))
  95. wake_up(&sbi->cp_wait);
  96. bio_put(bio);
  97. }
  98. /*
  99. * Low-level block read/write IO operations.
  100. */
  101. static struct bio *__bio_alloc(struct f2fs_sb_info *sbi, block_t blk_addr,
  102. int npages, bool is_read)
  103. {
  104. struct bio *bio;
  105. bio = f2fs_bio_alloc(npages);
  106. bio->bi_bdev = sbi->sb->s_bdev;
  107. bio->bi_sector = SECTOR_FROM_BLOCK(blk_addr);
  108. bio->bi_end_io = is_read ? f2fs_read_end_io : f2fs_write_end_io;
  109. bio->bi_private = is_read ? NULL : sbi;
  110. return bio;
  111. }
  112. static inline void __submit_bio(struct f2fs_sb_info *sbi, int rw,
  113. struct bio *bio, enum page_type type)
  114. {
  115. if (!is_read_io(rw)) {
  116. if (f2fs_sb_mounted_blkzoned(sbi->sb) &&
  117. current->plug && (type == DATA || type == NODE))
  118. blk_finish_plug(current->plug);
  119. }
  120. submit_bio(rw, bio);
  121. }
  122. static void __submit_merged_bio(struct f2fs_bio_info *io)
  123. {
  124. struct f2fs_io_info *fio = &io->fio;
  125. if (!io->bio)
  126. return;
  127. if (is_read_io(fio->rw))
  128. trace_f2fs_submit_read_bio(io->sbi->sb, fio, io->bio);
  129. else
  130. trace_f2fs_submit_write_bio(io->sbi->sb, fio, io->bio);
  131. __submit_bio(io->sbi, fio->rw, io->bio, fio->type);
  132. io->bio = NULL;
  133. }
  134. static bool __has_merged_page(struct f2fs_bio_info *io, struct inode *inode,
  135. struct page *page, nid_t ino)
  136. {
  137. struct bio_vec *bvec;
  138. struct page *target;
  139. int i;
  140. if (!io->bio)
  141. return false;
  142. if (!inode && !page && !ino)
  143. return true;
  144. __bio_for_each_segment(bvec, io->bio, i, 0) {
  145. if (bvec->bv_page->mapping)
  146. target = bvec->bv_page;
  147. else
  148. target = fscrypt_control_page(bvec->bv_page);
  149. if (inode && inode == target->mapping->host)
  150. return true;
  151. if (page && page == target)
  152. return true;
  153. if (ino && ino == ino_of_node(target))
  154. return true;
  155. }
  156. return false;
  157. }
  158. static bool has_merged_page(struct f2fs_sb_info *sbi, struct inode *inode,
  159. struct page *page, nid_t ino,
  160. enum page_type type)
  161. {
  162. enum page_type btype = PAGE_TYPE_OF_BIO(type);
  163. struct f2fs_bio_info *io = &sbi->write_io[btype];
  164. bool ret;
  165. down_read(&io->io_rwsem);
  166. ret = __has_merged_page(io, inode, page, ino);
  167. up_read(&io->io_rwsem);
  168. return ret;
  169. }
  170. static void __f2fs_submit_merged_bio(struct f2fs_sb_info *sbi,
  171. struct inode *inode, struct page *page,
  172. nid_t ino, enum page_type type, int rw)
  173. {
  174. enum page_type btype = PAGE_TYPE_OF_BIO(type);
  175. struct f2fs_bio_info *io;
  176. io = is_read_io(rw) ? &sbi->read_io : &sbi->write_io[btype];
  177. down_write(&io->io_rwsem);
  178. if (!__has_merged_page(io, inode, page, ino))
  179. goto out;
  180. /* change META to META_FLUSH in the checkpoint procedure */
  181. if (type >= META_FLUSH) {
  182. io->fio.type = META_FLUSH;
  183. if (test_opt(sbi, NOBARRIER))
  184. io->fio.rw = WRITE_FLUSH | REQ_META | REQ_PRIO;
  185. else
  186. io->fio.rw = WRITE_FLUSH_FUA | REQ_META | REQ_PRIO;
  187. }
  188. __submit_merged_bio(io);
  189. out:
  190. up_write(&io->io_rwsem);
  191. }
  192. void f2fs_submit_merged_bio(struct f2fs_sb_info *sbi, enum page_type type,
  193. int rw)
  194. {
  195. __f2fs_submit_merged_bio(sbi, NULL, NULL, 0, type, rw);
  196. }
  197. void f2fs_submit_merged_bio_cond(struct f2fs_sb_info *sbi,
  198. struct inode *inode, struct page *page,
  199. nid_t ino, enum page_type type, int rw)
  200. {
  201. if (has_merged_page(sbi, inode, page, ino, type))
  202. __f2fs_submit_merged_bio(sbi, inode, page, ino, type, rw);
  203. }
  204. void f2fs_flush_merged_bios(struct f2fs_sb_info *sbi)
  205. {
  206. f2fs_submit_merged_bio(sbi, DATA, WRITE);
  207. f2fs_submit_merged_bio(sbi, NODE, WRITE);
  208. f2fs_submit_merged_bio(sbi, META, WRITE);
  209. }
  210. /*
  211. * Fill the locked page with data located in the block address.
  212. * Return unlocked page.
  213. */
  214. int f2fs_submit_page_bio(struct f2fs_io_info *fio)
  215. {
  216. struct bio *bio;
  217. struct page *page = fio->encrypted_page ?
  218. fio->encrypted_page : fio->page;
  219. trace_f2fs_submit_page_bio(page, fio);
  220. f2fs_trace_ios(fio, 0);
  221. /* Allocate a new bio */
  222. bio = __bio_alloc(fio->sbi, fio->new_blkaddr, 1, is_read_io(fio->rw));
  223. if (bio_add_page(bio, page, PAGE_SIZE, 0) < PAGE_SIZE) {
  224. bio_put(bio);
  225. return -EFAULT;
  226. }
  227. __submit_bio(fio->sbi, fio->rw, bio, fio->type);
  228. return 0;
  229. }
  230. void f2fs_submit_page_mbio(struct f2fs_io_info *fio)
  231. {
  232. struct f2fs_sb_info *sbi = fio->sbi;
  233. enum page_type btype = PAGE_TYPE_OF_BIO(fio->type);
  234. struct f2fs_bio_info *io;
  235. bool is_read = is_read_io(fio->rw);
  236. struct page *bio_page;
  237. io = is_read ? &sbi->read_io : &sbi->write_io[btype];
  238. if (fio->old_blkaddr != NEW_ADDR)
  239. verify_block_addr(sbi, fio->old_blkaddr);
  240. verify_block_addr(sbi, fio->new_blkaddr);
  241. bio_page = fio->encrypted_page ? fio->encrypted_page : fio->page;
  242. if (!is_read)
  243. inc_page_count(sbi, WB_DATA_TYPE(bio_page));
  244. down_write(&io->io_rwsem);
  245. if (io->bio && (io->last_block_in_bio != fio->new_blkaddr - 1 ||
  246. io->fio.rw != fio->rw))
  247. __submit_merged_bio(io);
  248. alloc_new:
  249. if (io->bio == NULL) {
  250. io->bio = __bio_alloc(sbi, fio->new_blkaddr,
  251. BIO_MAX_PAGES, is_read);
  252. io->fio = *fio;
  253. }
  254. if (bio_add_page(io->bio, bio_page, PAGE_SIZE, 0) <
  255. PAGE_SIZE) {
  256. __submit_merged_bio(io);
  257. goto alloc_new;
  258. }
  259. io->last_block_in_bio = fio->new_blkaddr;
  260. f2fs_trace_ios(fio, 0);
  261. up_write(&io->io_rwsem);
  262. trace_f2fs_submit_page_mbio(fio->page, fio);
  263. }
  264. static void __set_data_blkaddr(struct dnode_of_data *dn)
  265. {
  266. struct f2fs_node *rn = F2FS_NODE(dn->node_page);
  267. __le32 *addr_array;
  268. /* Get physical address of data block */
  269. addr_array = blkaddr_in_node(rn);
  270. addr_array[dn->ofs_in_node] = cpu_to_le32(dn->data_blkaddr);
  271. }
  272. /*
  273. * Lock ordering for the change of data block address:
  274. * ->data_page
  275. * ->node_page
  276. * update block addresses in the node page
  277. */
  278. void set_data_blkaddr(struct dnode_of_data *dn)
  279. {
  280. f2fs_wait_on_page_writeback(dn->node_page, NODE, true);
  281. __set_data_blkaddr(dn);
  282. if (set_page_dirty(dn->node_page))
  283. dn->node_changed = true;
  284. }
  285. void f2fs_update_data_blkaddr(struct dnode_of_data *dn, block_t blkaddr)
  286. {
  287. dn->data_blkaddr = blkaddr;
  288. set_data_blkaddr(dn);
  289. f2fs_update_extent_cache(dn);
  290. }
  291. /* dn->ofs_in_node will be returned with up-to-date last block pointer */
  292. int reserve_new_blocks(struct dnode_of_data *dn, blkcnt_t count)
  293. {
  294. struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode);
  295. if (!count)
  296. return 0;
  297. if (unlikely(is_inode_flag_set(dn->inode, FI_NO_ALLOC)))
  298. return -EPERM;
  299. if (unlikely(!inc_valid_block_count(sbi, dn->inode, &count)))
  300. return -ENOSPC;
  301. trace_f2fs_reserve_new_blocks(dn->inode, dn->nid,
  302. dn->ofs_in_node, count);
  303. f2fs_wait_on_page_writeback(dn->node_page, NODE, true);
  304. for (; count > 0; dn->ofs_in_node++) {
  305. block_t blkaddr =
  306. datablock_addr(dn->node_page, dn->ofs_in_node);
  307. if (blkaddr == NULL_ADDR) {
  308. dn->data_blkaddr = NEW_ADDR;
  309. __set_data_blkaddr(dn);
  310. count--;
  311. }
  312. }
  313. if (set_page_dirty(dn->node_page))
  314. dn->node_changed = true;
  315. return 0;
  316. }
  317. /* Should keep dn->ofs_in_node unchanged */
  318. int reserve_new_block(struct dnode_of_data *dn)
  319. {
  320. unsigned int ofs_in_node = dn->ofs_in_node;
  321. int ret;
  322. ret = reserve_new_blocks(dn, 1);
  323. dn->ofs_in_node = ofs_in_node;
  324. return ret;
  325. }
  326. int f2fs_reserve_block(struct dnode_of_data *dn, pgoff_t index)
  327. {
  328. bool need_put = dn->inode_page ? false : true;
  329. int err;
  330. err = get_dnode_of_data(dn, index, ALLOC_NODE);
  331. if (err)
  332. return err;
  333. if (dn->data_blkaddr == NULL_ADDR)
  334. err = reserve_new_block(dn);
  335. if (err || need_put)
  336. f2fs_put_dnode(dn);
  337. return err;
  338. }
  339. int f2fs_get_block(struct dnode_of_data *dn, pgoff_t index)
  340. {
  341. struct extent_info ei;
  342. struct inode *inode = dn->inode;
  343. if (f2fs_lookup_extent_cache(inode, index, &ei)) {
  344. dn->data_blkaddr = ei.blk + index - ei.fofs;
  345. return 0;
  346. }
  347. return f2fs_reserve_block(dn, index);
  348. }
  349. struct page *get_read_data_page(struct inode *inode, pgoff_t index,
  350. int rw, bool for_write)
  351. {
  352. struct address_space *mapping = inode->i_mapping;
  353. struct dnode_of_data dn;
  354. struct page *page;
  355. struct extent_info ei;
  356. int err;
  357. struct f2fs_io_info fio = {
  358. .sbi = F2FS_I_SB(inode),
  359. .type = DATA,
  360. .rw = rw,
  361. .encrypted_page = NULL,
  362. };
  363. if (f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode))
  364. return read_mapping_page(mapping, index, NULL);
  365. page = f2fs_grab_cache_page(mapping, index, for_write);
  366. if (!page)
  367. return ERR_PTR(-ENOMEM);
  368. if (f2fs_lookup_extent_cache(inode, index, &ei)) {
  369. dn.data_blkaddr = ei.blk + index - ei.fofs;
  370. goto got_it;
  371. }
  372. set_new_dnode(&dn, inode, NULL, NULL, 0);
  373. err = get_dnode_of_data(&dn, index, LOOKUP_NODE);
  374. if (err)
  375. goto put_err;
  376. f2fs_put_dnode(&dn);
  377. if (unlikely(dn.data_blkaddr == NULL_ADDR)) {
  378. err = -ENOENT;
  379. goto put_err;
  380. }
  381. got_it:
  382. if (PageUptodate(page)) {
  383. unlock_page(page);
  384. return page;
  385. }
  386. /*
  387. * A new dentry page is allocated but not able to be written, since its
  388. * new inode page couldn't be allocated due to -ENOSPC.
  389. * In such the case, its blkaddr can be remained as NEW_ADDR.
  390. * see, f2fs_add_link -> get_new_data_page -> init_inode_metadata.
  391. */
  392. if (dn.data_blkaddr == NEW_ADDR) {
  393. zero_user_segment(page, 0, PAGE_SIZE);
  394. if (!PageUptodate(page))
  395. SetPageUptodate(page);
  396. unlock_page(page);
  397. return page;
  398. }
  399. fio.new_blkaddr = fio.old_blkaddr = dn.data_blkaddr;
  400. fio.page = page;
  401. err = f2fs_submit_page_bio(&fio);
  402. if (err)
  403. goto put_err;
  404. return page;
  405. put_err:
  406. f2fs_put_page(page, 1);
  407. return ERR_PTR(err);
  408. }
  409. struct page *find_data_page(struct inode *inode, pgoff_t index)
  410. {
  411. struct address_space *mapping = inode->i_mapping;
  412. struct page *page;
  413. page = find_get_page(mapping, index);
  414. if (page && PageUptodate(page))
  415. return page;
  416. f2fs_put_page(page, 0);
  417. page = get_read_data_page(inode, index, READ_SYNC, false);
  418. if (IS_ERR(page))
  419. return page;
  420. if (PageUptodate(page))
  421. return page;
  422. wait_on_page_locked(page);
  423. if (unlikely(!PageUptodate(page))) {
  424. f2fs_put_page(page, 0);
  425. return ERR_PTR(-EIO);
  426. }
  427. return page;
  428. }
  429. /*
  430. * If it tries to access a hole, return an error.
  431. * Because, the callers, functions in dir.c and GC, should be able to know
  432. * whether this page exists or not.
  433. */
  434. struct page *get_lock_data_page(struct inode *inode, pgoff_t index,
  435. bool for_write)
  436. {
  437. struct address_space *mapping = inode->i_mapping;
  438. struct page *page;
  439. repeat:
  440. page = get_read_data_page(inode, index, READ_SYNC, for_write);
  441. if (IS_ERR(page))
  442. return page;
  443. /* wait for read completion */
  444. lock_page(page);
  445. if (unlikely(page->mapping != mapping)) {
  446. f2fs_put_page(page, 1);
  447. goto repeat;
  448. }
  449. if (unlikely(!PageUptodate(page))) {
  450. f2fs_put_page(page, 1);
  451. return ERR_PTR(-EIO);
  452. }
  453. return page;
  454. }
  455. /*
  456. * Caller ensures that this data page is never allocated.
  457. * A new zero-filled data page is allocated in the page cache.
  458. *
  459. * Also, caller should grab and release a rwsem by calling f2fs_lock_op() and
  460. * f2fs_unlock_op().
  461. * Note that, ipage is set only by make_empty_dir, and if any error occur,
  462. * ipage should be released by this function.
  463. */
  464. struct page *get_new_data_page(struct inode *inode,
  465. struct page *ipage, pgoff_t index, bool new_i_size)
  466. {
  467. struct address_space *mapping = inode->i_mapping;
  468. struct page *page;
  469. struct dnode_of_data dn;
  470. int err;
  471. page = f2fs_grab_cache_page(mapping, index, true);
  472. if (!page) {
  473. /*
  474. * before exiting, we should make sure ipage will be released
  475. * if any error occur.
  476. */
  477. f2fs_put_page(ipage, 1);
  478. return ERR_PTR(-ENOMEM);
  479. }
  480. set_new_dnode(&dn, inode, ipage, NULL, 0);
  481. err = f2fs_reserve_block(&dn, index);
  482. if (err) {
  483. f2fs_put_page(page, 1);
  484. return ERR_PTR(err);
  485. }
  486. if (!ipage)
  487. f2fs_put_dnode(&dn);
  488. if (PageUptodate(page))
  489. goto got_it;
  490. if (dn.data_blkaddr == NEW_ADDR) {
  491. zero_user_segment(page, 0, PAGE_SIZE);
  492. if (!PageUptodate(page))
  493. SetPageUptodate(page);
  494. } else {
  495. f2fs_put_page(page, 1);
  496. /* if ipage exists, blkaddr should be NEW_ADDR */
  497. f2fs_bug_on(F2FS_I_SB(inode), ipage);
  498. page = get_lock_data_page(inode, index, true);
  499. if (IS_ERR(page))
  500. return page;
  501. }
  502. got_it:
  503. if (new_i_size && i_size_read(inode) <
  504. ((loff_t)(index + 1) << PAGE_SHIFT))
  505. f2fs_i_size_write(inode, ((loff_t)(index + 1) << PAGE_SHIFT));
  506. return page;
  507. }
  508. static int __allocate_data_block(struct dnode_of_data *dn)
  509. {
  510. struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode);
  511. struct f2fs_summary sum;
  512. struct node_info ni;
  513. pgoff_t fofs;
  514. blkcnt_t count = 1;
  515. if (unlikely(is_inode_flag_set(dn->inode, FI_NO_ALLOC)))
  516. return -EPERM;
  517. dn->data_blkaddr = datablock_addr(dn->node_page, dn->ofs_in_node);
  518. if (dn->data_blkaddr == NEW_ADDR)
  519. goto alloc;
  520. if (unlikely(!inc_valid_block_count(sbi, dn->inode, &count)))
  521. return -ENOSPC;
  522. alloc:
  523. get_node_info(sbi, dn->nid, &ni);
  524. set_summary(&sum, dn->nid, dn->ofs_in_node, ni.version);
  525. allocate_data_block(sbi, NULL, dn->data_blkaddr, &dn->data_blkaddr,
  526. &sum, CURSEG_WARM_DATA);
  527. set_data_blkaddr(dn);
  528. /* update i_size */
  529. fofs = start_bidx_of_node(ofs_of_node(dn->node_page), dn->inode) +
  530. dn->ofs_in_node;
  531. if (i_size_read(dn->inode) < ((loff_t)(fofs + 1) << PAGE_SHIFT))
  532. f2fs_i_size_write(dn->inode,
  533. ((loff_t)(fofs + 1) << PAGE_SHIFT));
  534. return 0;
  535. }
  536. int f2fs_preallocate_blocks(struct inode *inode, loff_t pos,
  537. size_t count, bool dio)
  538. {
  539. struct f2fs_map_blocks map;
  540. int err = 0;
  541. map.m_lblk = F2FS_BLK_ALIGN(pos);
  542. map.m_len = F2FS_BYTES_TO_BLK(pos + count);
  543. if (map.m_len > map.m_lblk)
  544. map.m_len -= map.m_lblk;
  545. else
  546. map.m_len = 0;
  547. map.m_next_pgofs = NULL;
  548. if (dio) {
  549. err = f2fs_convert_inline_inode(inode);
  550. if (err)
  551. return err;
  552. return f2fs_map_blocks(inode, &map, 1, F2FS_GET_BLOCK_PRE_DIO);
  553. }
  554. if (pos + count > MAX_INLINE_DATA) {
  555. err = f2fs_convert_inline_inode(inode);
  556. if (err)
  557. return err;
  558. }
  559. if (!f2fs_has_inline_data(inode))
  560. return f2fs_map_blocks(inode, &map, 1, F2FS_GET_BLOCK_PRE_AIO);
  561. return err;
  562. }
  563. /*
  564. * f2fs_map_blocks() now supported readahead/bmap/rw direct_IO with
  565. * f2fs_map_blocks structure.
  566. * If original data blocks are allocated, then give them to blockdev.
  567. * Otherwise,
  568. * a. preallocate requested block addresses
  569. * b. do not use extent cache for better performance
  570. * c. give the block addresses to blockdev
  571. */
  572. int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map,
  573. int create, int flag)
  574. {
  575. unsigned int maxblocks = map->m_len;
  576. struct dnode_of_data dn;
  577. struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
  578. int mode = create ? ALLOC_NODE : LOOKUP_NODE;
  579. pgoff_t pgofs, end_offset, end;
  580. int err = 0, ofs = 1;
  581. unsigned int ofs_in_node, last_ofs_in_node;
  582. blkcnt_t prealloc;
  583. struct extent_info ei;
  584. block_t blkaddr;
  585. if (!maxblocks)
  586. return 0;
  587. map->m_len = 0;
  588. map->m_flags = 0;
  589. /* it only supports block size == page size */
  590. pgofs = (pgoff_t)map->m_lblk;
  591. end = pgofs + maxblocks;
  592. if (!create && f2fs_lookup_extent_cache(inode, pgofs, &ei)) {
  593. map->m_pblk = ei.blk + pgofs - ei.fofs;
  594. map->m_len = min((pgoff_t)maxblocks, ei.fofs + ei.len - pgofs);
  595. map->m_flags = F2FS_MAP_MAPPED;
  596. goto out;
  597. }
  598. next_dnode:
  599. if (create)
  600. f2fs_lock_op(sbi);
  601. /* When reading holes, we need its node page */
  602. set_new_dnode(&dn, inode, NULL, NULL, 0);
  603. err = get_dnode_of_data(&dn, pgofs, mode);
  604. if (err) {
  605. if (flag == F2FS_GET_BLOCK_BMAP)
  606. map->m_pblk = 0;
  607. if (err == -ENOENT) {
  608. err = 0;
  609. if (map->m_next_pgofs)
  610. *map->m_next_pgofs =
  611. get_next_page_offset(&dn, pgofs);
  612. }
  613. goto unlock_out;
  614. }
  615. prealloc = 0;
  616. last_ofs_in_node = ofs_in_node = dn.ofs_in_node;
  617. end_offset = ADDRS_PER_PAGE(dn.node_page, inode);
  618. next_block:
  619. blkaddr = datablock_addr(dn.node_page, dn.ofs_in_node);
  620. if (blkaddr == NEW_ADDR || blkaddr == NULL_ADDR) {
  621. if (create) {
  622. if (unlikely(f2fs_cp_error(sbi))) {
  623. err = -EIO;
  624. goto sync_out;
  625. }
  626. if (flag == F2FS_GET_BLOCK_PRE_AIO) {
  627. if (blkaddr == NULL_ADDR) {
  628. prealloc++;
  629. last_ofs_in_node = dn.ofs_in_node;
  630. }
  631. } else {
  632. err = __allocate_data_block(&dn);
  633. if (!err)
  634. set_inode_flag(inode, FI_APPEND_WRITE);
  635. }
  636. if (err)
  637. goto sync_out;
  638. map->m_flags = F2FS_MAP_NEW;
  639. blkaddr = dn.data_blkaddr;
  640. } else {
  641. if (flag == F2FS_GET_BLOCK_BMAP) {
  642. map->m_pblk = 0;
  643. goto sync_out;
  644. }
  645. if (flag == F2FS_GET_BLOCK_FIEMAP &&
  646. blkaddr == NULL_ADDR) {
  647. if (map->m_next_pgofs)
  648. *map->m_next_pgofs = pgofs + 1;
  649. }
  650. if (flag != F2FS_GET_BLOCK_FIEMAP ||
  651. blkaddr != NEW_ADDR)
  652. goto sync_out;
  653. }
  654. }
  655. if (flag == F2FS_GET_BLOCK_PRE_AIO)
  656. goto skip;
  657. if (map->m_len == 0) {
  658. /* preallocated unwritten block should be mapped for fiemap. */
  659. if (blkaddr == NEW_ADDR)
  660. map->m_flags |= F2FS_MAP_UNWRITTEN;
  661. map->m_flags |= F2FS_MAP_MAPPED;
  662. map->m_pblk = blkaddr;
  663. map->m_len = 1;
  664. } else if ((map->m_pblk != NEW_ADDR &&
  665. blkaddr == (map->m_pblk + ofs)) ||
  666. (map->m_pblk == NEW_ADDR && blkaddr == NEW_ADDR) ||
  667. flag == F2FS_GET_BLOCK_PRE_DIO) {
  668. ofs++;
  669. map->m_len++;
  670. } else {
  671. goto sync_out;
  672. }
  673. skip:
  674. dn.ofs_in_node++;
  675. pgofs++;
  676. /* preallocate blocks in batch for one dnode page */
  677. if (flag == F2FS_GET_BLOCK_PRE_AIO &&
  678. (pgofs == end || dn.ofs_in_node == end_offset)) {
  679. dn.ofs_in_node = ofs_in_node;
  680. err = reserve_new_blocks(&dn, prealloc);
  681. if (err)
  682. goto sync_out;
  683. map->m_len += dn.ofs_in_node - ofs_in_node;
  684. if (prealloc && dn.ofs_in_node != last_ofs_in_node + 1) {
  685. err = -ENOSPC;
  686. goto sync_out;
  687. }
  688. dn.ofs_in_node = end_offset;
  689. }
  690. if (pgofs >= end)
  691. goto sync_out;
  692. else if (dn.ofs_in_node < end_offset)
  693. goto next_block;
  694. f2fs_put_dnode(&dn);
  695. if (create) {
  696. f2fs_unlock_op(sbi);
  697. f2fs_balance_fs(sbi, dn.node_changed);
  698. }
  699. goto next_dnode;
  700. sync_out:
  701. f2fs_put_dnode(&dn);
  702. unlock_out:
  703. if (create) {
  704. f2fs_unlock_op(sbi);
  705. f2fs_balance_fs(sbi, dn.node_changed);
  706. }
  707. out:
  708. trace_f2fs_map_blocks(inode, map, err);
  709. return err;
  710. }
  711. static int __get_data_block(struct inode *inode, sector_t iblock,
  712. struct buffer_head *bh, int create, int flag,
  713. pgoff_t *next_pgofs)
  714. {
  715. struct f2fs_map_blocks map;
  716. int err;
  717. map.m_lblk = iblock;
  718. map.m_len = bh->b_size >> inode->i_blkbits;
  719. map.m_next_pgofs = next_pgofs;
  720. err = f2fs_map_blocks(inode, &map, create, flag);
  721. if (!err) {
  722. map_bh(bh, inode->i_sb, map.m_pblk);
  723. bh->b_state = (bh->b_state & ~F2FS_MAP_FLAGS) | map.m_flags;
  724. bh->b_size = map.m_len << inode->i_blkbits;
  725. }
  726. return err;
  727. }
  728. static int get_data_block(struct inode *inode, sector_t iblock,
  729. struct buffer_head *bh_result, int create, int flag,
  730. pgoff_t *next_pgofs)
  731. {
  732. return __get_data_block(inode, iblock, bh_result, create,
  733. flag, next_pgofs);
  734. }
  735. static int get_data_block_dio(struct inode *inode, sector_t iblock,
  736. struct buffer_head *bh_result, int create)
  737. {
  738. return __get_data_block(inode, iblock, bh_result, create,
  739. F2FS_GET_BLOCK_DIO, NULL);
  740. }
  741. static int get_data_block_bmap(struct inode *inode, sector_t iblock,
  742. struct buffer_head *bh_result, int create)
  743. {
  744. /* Block number less than F2FS MAX BLOCKS */
  745. if (unlikely(iblock >= F2FS_I_SB(inode)->max_file_blocks))
  746. return -EFBIG;
  747. return __get_data_block(inode, iblock, bh_result, create,
  748. F2FS_GET_BLOCK_BMAP, NULL);
  749. }
  750. static inline sector_t logical_to_blk(struct inode *inode, loff_t offset)
  751. {
  752. return (offset >> inode->i_blkbits);
  753. }
  754. static inline loff_t blk_to_logical(struct inode *inode, sector_t blk)
  755. {
  756. return (blk << inode->i_blkbits);
  757. }
  758. int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
  759. u64 start, u64 len)
  760. {
  761. struct buffer_head map_bh;
  762. sector_t start_blk, last_blk;
  763. pgoff_t next_pgofs;
  764. u64 logical = 0, phys = 0, size = 0;
  765. u32 flags = 0;
  766. int ret = 0;
  767. ret = fiemap_check_flags(fieinfo, FIEMAP_FLAG_SYNC);
  768. if (ret)
  769. return ret;
  770. if (f2fs_has_inline_data(inode)) {
  771. ret = f2fs_inline_data_fiemap(inode, fieinfo, start, len);
  772. if (ret != -EAGAIN)
  773. return ret;
  774. }
  775. inode_lock(inode);
  776. if (logical_to_blk(inode, len) == 0)
  777. len = blk_to_logical(inode, 1);
  778. start_blk = logical_to_blk(inode, start);
  779. last_blk = logical_to_blk(inode, start + len - 1);
  780. next:
  781. memset(&map_bh, 0, sizeof(struct buffer_head));
  782. map_bh.b_size = len;
  783. ret = get_data_block(inode, start_blk, &map_bh, 0,
  784. F2FS_GET_BLOCK_FIEMAP, &next_pgofs);
  785. if (ret)
  786. goto out;
  787. /* HOLE */
  788. if (!buffer_mapped(&map_bh)) {
  789. start_blk = next_pgofs;
  790. if (blk_to_logical(inode, start_blk) < blk_to_logical(inode,
  791. F2FS_I_SB(inode)->max_file_blocks))
  792. goto prep_next;
  793. flags |= FIEMAP_EXTENT_LAST;
  794. }
  795. if (size) {
  796. if (f2fs_encrypted_inode(inode))
  797. flags |= FIEMAP_EXTENT_DATA_ENCRYPTED;
  798. ret = fiemap_fill_next_extent(fieinfo, logical,
  799. phys, size, flags);
  800. }
  801. if (start_blk > last_blk || ret)
  802. goto out;
  803. logical = blk_to_logical(inode, start_blk);
  804. phys = blk_to_logical(inode, map_bh.b_blocknr);
  805. size = map_bh.b_size;
  806. flags = 0;
  807. if (buffer_unwritten(&map_bh))
  808. flags = FIEMAP_EXTENT_UNWRITTEN;
  809. start_blk += logical_to_blk(inode, size);
  810. prep_next:
  811. cond_resched();
  812. if (fatal_signal_pending(current))
  813. ret = -EINTR;
  814. else
  815. goto next;
  816. out:
  817. if (ret == 1)
  818. ret = 0;
  819. inode_unlock(inode);
  820. return ret;
  821. }
  822. static struct bio *f2fs_grab_bio(struct inode *inode, block_t blkaddr,
  823. unsigned nr_pages)
  824. {
  825. struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
  826. struct fscrypt_ctx *ctx = NULL;
  827. struct block_device *bdev = sbi->sb->s_bdev;
  828. struct bio *bio;
  829. if (f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode)) {
  830. ctx = fscrypt_get_ctx(inode, GFP_NOFS);
  831. if (IS_ERR(ctx))
  832. return ERR_CAST(ctx);
  833. /* wait the page to be moved by cleaning */
  834. f2fs_wait_on_encrypted_page_writeback(sbi, blkaddr);
  835. }
  836. bio = bio_alloc(GFP_KERNEL, min_t(int, nr_pages, BIO_MAX_PAGES));
  837. if (!bio) {
  838. if (ctx)
  839. fscrypt_release_ctx(ctx);
  840. return ERR_PTR(-ENOMEM);
  841. }
  842. bio->bi_bdev = bdev;
  843. bio->bi_sector = SECTOR_FROM_BLOCK(blkaddr);
  844. bio->bi_end_io = f2fs_read_end_io;
  845. bio->bi_private = ctx;
  846. return bio;
  847. }
  848. /*
  849. * This function was originally taken from fs/mpage.c, and customized for f2fs.
  850. * Major change was from block_size == page_size in f2fs by default.
  851. */
  852. static int f2fs_mpage_readpages(struct address_space *mapping,
  853. struct list_head *pages, struct page *page,
  854. unsigned nr_pages)
  855. {
  856. struct bio *bio = NULL;
  857. unsigned page_idx;
  858. sector_t last_block_in_bio = 0;
  859. struct inode *inode = mapping->host;
  860. const unsigned blkbits = inode->i_blkbits;
  861. const unsigned blocksize = 1 << blkbits;
  862. sector_t block_in_file;
  863. sector_t last_block;
  864. sector_t last_block_in_file;
  865. sector_t block_nr;
  866. struct f2fs_map_blocks map;
  867. map.m_pblk = 0;
  868. map.m_lblk = 0;
  869. map.m_len = 0;
  870. map.m_flags = 0;
  871. map.m_next_pgofs = NULL;
  872. for (page_idx = 0; nr_pages; page_idx++, nr_pages--) {
  873. prefetchw(&page->flags);
  874. if (pages) {
  875. page = list_entry(pages->prev, struct page, lru);
  876. list_del(&page->lru);
  877. if (add_to_page_cache_lru(page, mapping,
  878. page->index, GFP_KERNEL))
  879. goto next_page;
  880. }
  881. block_in_file = (sector_t)page->index;
  882. last_block = block_in_file + nr_pages;
  883. last_block_in_file = (i_size_read(inode) + blocksize - 1) >>
  884. blkbits;
  885. if (last_block > last_block_in_file)
  886. last_block = last_block_in_file;
  887. /*
  888. * Map blocks using the previous result first.
  889. */
  890. if ((map.m_flags & F2FS_MAP_MAPPED) &&
  891. block_in_file > map.m_lblk &&
  892. block_in_file < (map.m_lblk + map.m_len))
  893. goto got_it;
  894. /*
  895. * Then do more f2fs_map_blocks() calls until we are
  896. * done with this page.
  897. */
  898. map.m_flags = 0;
  899. if (block_in_file < last_block) {
  900. map.m_lblk = block_in_file;
  901. map.m_len = last_block - block_in_file;
  902. if (f2fs_map_blocks(inode, &map, 0,
  903. F2FS_GET_BLOCK_READ))
  904. goto set_error_page;
  905. }
  906. got_it:
  907. if ((map.m_flags & F2FS_MAP_MAPPED)) {
  908. block_nr = map.m_pblk + block_in_file - map.m_lblk;
  909. SetPageMappedToDisk(page);
  910. if (!PageUptodate(page) && !cleancache_get_page(page)) {
  911. SetPageUptodate(page);
  912. goto confused;
  913. }
  914. } else {
  915. zero_user_segment(page, 0, PAGE_SIZE);
  916. if (!PageUptodate(page))
  917. SetPageUptodate(page);
  918. unlock_page(page);
  919. goto next_page;
  920. }
  921. /*
  922. * This page will go to BIO. Do we need to send this
  923. * BIO off first?
  924. */
  925. if (bio && (last_block_in_bio != block_nr - 1)) {
  926. submit_and_realloc:
  927. __submit_bio(F2FS_I_SB(inode), READ, bio, DATA);
  928. bio = NULL;
  929. }
  930. if (bio == NULL) {
  931. bio = f2fs_grab_bio(inode, block_nr, nr_pages);
  932. if (IS_ERR(bio)) {
  933. bio = NULL;
  934. goto set_error_page;
  935. }
  936. }
  937. if (bio_add_page(bio, page, blocksize, 0) < blocksize)
  938. goto submit_and_realloc;
  939. last_block_in_bio = block_nr;
  940. goto next_page;
  941. set_error_page:
  942. SetPageError(page);
  943. zero_user_segment(page, 0, PAGE_SIZE);
  944. unlock_page(page);
  945. goto next_page;
  946. confused:
  947. if (bio) {
  948. __submit_bio(F2FS_I_SB(inode), READ, bio, DATA);
  949. bio = NULL;
  950. }
  951. unlock_page(page);
  952. next_page:
  953. if (pages)
  954. put_page(page);
  955. }
  956. BUG_ON(pages && !list_empty(pages));
  957. if (bio)
  958. __submit_bio(F2FS_I_SB(inode), READ, bio, DATA);
  959. return 0;
  960. }
  961. static int f2fs_read_data_page(struct file *file, struct page *page)
  962. {
  963. struct inode *inode = page->mapping->host;
  964. int ret = -EAGAIN;
  965. trace_f2fs_readpage(page, DATA);
  966. /* If the file has inline data, try to read it directly */
  967. if (f2fs_has_inline_data(inode))
  968. ret = f2fs_read_inline_data(inode, page);
  969. if (ret == -EAGAIN)
  970. ret = f2fs_mpage_readpages(page->mapping, NULL, page, 1);
  971. return ret;
  972. }
  973. static int f2fs_read_data_pages(struct file *file,
  974. struct address_space *mapping,
  975. struct list_head *pages, unsigned nr_pages)
  976. {
  977. struct inode *inode = file->f_mapping->host;
  978. struct page *page = list_entry(pages->prev, struct page, lru);
  979. trace_f2fs_readpages(inode, page, nr_pages);
  980. /* If the file has inline data, skip readpages */
  981. if (f2fs_has_inline_data(inode))
  982. return 0;
  983. return f2fs_mpage_readpages(mapping, pages, NULL, nr_pages);
  984. }
  985. int do_write_data_page(struct f2fs_io_info *fio)
  986. {
  987. struct page *page = fio->page;
  988. struct inode *inode = page->mapping->host;
  989. struct dnode_of_data dn;
  990. int err = 0;
  991. set_new_dnode(&dn, inode, NULL, NULL, 0);
  992. err = get_dnode_of_data(&dn, page->index, LOOKUP_NODE);
  993. if (err)
  994. return err;
  995. fio->old_blkaddr = dn.data_blkaddr;
  996. /* This page is already truncated */
  997. if (fio->old_blkaddr == NULL_ADDR) {
  998. ClearPageUptodate(page);
  999. goto out_writepage;
  1000. }
  1001. if (f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode)) {
  1002. gfp_t gfp_flags = GFP_NOFS;
  1003. /* wait for GCed encrypted page writeback */
  1004. f2fs_wait_on_encrypted_page_writeback(F2FS_I_SB(inode),
  1005. fio->old_blkaddr);
  1006. retry_encrypt:
  1007. fio->encrypted_page = fscrypt_encrypt_page(inode, fio->page,
  1008. gfp_flags);
  1009. if (IS_ERR(fio->encrypted_page)) {
  1010. err = PTR_ERR(fio->encrypted_page);
  1011. if (err == -ENOMEM) {
  1012. /* flush pending ios and wait for a while */
  1013. f2fs_flush_merged_bios(F2FS_I_SB(inode));
  1014. congestion_wait(BLK_RW_ASYNC, HZ/50);
  1015. gfp_flags |= __GFP_NOFAIL;
  1016. err = 0;
  1017. goto retry_encrypt;
  1018. }
  1019. goto out_writepage;
  1020. }
  1021. }
  1022. set_page_writeback(page);
  1023. /*
  1024. * If current allocation needs SSR,
  1025. * it had better in-place writes for updated data.
  1026. */
  1027. if (unlikely(fio->old_blkaddr != NEW_ADDR &&
  1028. !is_cold_data(page) &&
  1029. !IS_ATOMIC_WRITTEN_PAGE(page) &&
  1030. need_inplace_update(inode))) {
  1031. rewrite_data_page(fio);
  1032. set_inode_flag(inode, FI_UPDATE_WRITE);
  1033. trace_f2fs_do_write_data_page(page, IPU);
  1034. } else {
  1035. write_data_page(&dn, fio);
  1036. trace_f2fs_do_write_data_page(page, OPU);
  1037. set_inode_flag(inode, FI_APPEND_WRITE);
  1038. if (page->index == 0)
  1039. set_inode_flag(inode, FI_FIRST_BLOCK_WRITTEN);
  1040. }
  1041. out_writepage:
  1042. f2fs_put_dnode(&dn);
  1043. return err;
  1044. }
  1045. static int f2fs_write_data_page(struct page *page,
  1046. struct writeback_control *wbc)
  1047. {
  1048. struct inode *inode = page->mapping->host;
  1049. struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
  1050. loff_t i_size = i_size_read(inode);
  1051. const pgoff_t end_index = ((unsigned long long) i_size)
  1052. >> PAGE_SHIFT;
  1053. loff_t psize = (page->index + 1) << PAGE_SHIFT;
  1054. unsigned offset = 0;
  1055. bool need_balance_fs = false;
  1056. int err = 0;
  1057. struct f2fs_io_info fio = {
  1058. .sbi = sbi,
  1059. .type = DATA,
  1060. .rw = (wbc->sync_mode == WB_SYNC_ALL) ? WRITE_SYNC : WRITE,
  1061. .page = page,
  1062. .encrypted_page = NULL,
  1063. };
  1064. trace_f2fs_writepage(page, DATA);
  1065. if (page->index < end_index)
  1066. goto write;
  1067. /*
  1068. * If the offset is out-of-range of file size,
  1069. * this page does not have to be written to disk.
  1070. */
  1071. offset = i_size & (PAGE_SIZE - 1);
  1072. if ((page->index >= end_index + 1) || !offset)
  1073. goto out;
  1074. zero_user_segment(page, offset, PAGE_SIZE);
  1075. write:
  1076. if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING)))
  1077. goto redirty_out;
  1078. if (f2fs_is_drop_cache(inode))
  1079. goto out;
  1080. /* we should not write 0'th page having journal header */
  1081. if (f2fs_is_volatile_file(inode) && (!page->index ||
  1082. (!wbc->for_reclaim &&
  1083. available_free_memory(sbi, BASE_CHECK))))
  1084. goto redirty_out;
  1085. /* we should bypass data pages to proceed the kworkder jobs */
  1086. if (unlikely(f2fs_cp_error(sbi))) {
  1087. mapping_set_error(page->mapping, -EIO);
  1088. goto out;
  1089. }
  1090. /* Dentry blocks are controlled by checkpoint */
  1091. if (S_ISDIR(inode->i_mode)) {
  1092. err = do_write_data_page(&fio);
  1093. goto done;
  1094. }
  1095. if (!wbc->for_reclaim)
  1096. need_balance_fs = true;
  1097. else if (has_not_enough_free_secs(sbi, 0, 0))
  1098. goto redirty_out;
  1099. err = -EAGAIN;
  1100. f2fs_lock_op(sbi);
  1101. if (f2fs_has_inline_data(inode))
  1102. err = f2fs_write_inline_data(inode, page);
  1103. if (err == -EAGAIN)
  1104. err = do_write_data_page(&fio);
  1105. if (F2FS_I(inode)->last_disk_size < psize)
  1106. F2FS_I(inode)->last_disk_size = psize;
  1107. f2fs_unlock_op(sbi);
  1108. done:
  1109. if (err && err != -ENOENT)
  1110. goto redirty_out;
  1111. out:
  1112. inode_dec_dirty_pages(inode);
  1113. if (err)
  1114. ClearPageUptodate(page);
  1115. if (wbc->for_reclaim) {
  1116. f2fs_submit_merged_bio_cond(sbi, NULL, page, 0, DATA, WRITE);
  1117. remove_dirty_inode(inode);
  1118. }
  1119. unlock_page(page);
  1120. f2fs_balance_fs(sbi, need_balance_fs);
  1121. if (unlikely(f2fs_cp_error(sbi)))
  1122. f2fs_submit_merged_bio(sbi, DATA, WRITE);
  1123. return 0;
  1124. redirty_out:
  1125. redirty_page_for_writepage(wbc, page);
  1126. if (!err)
  1127. return AOP_WRITEPAGE_ACTIVATE;
  1128. unlock_page(page);
  1129. return err;
  1130. }
  1131. /*
  1132. * This function was copied from write_cche_pages from mm/page-writeback.c.
  1133. * The major change is making write step of cold data page separately from
  1134. * warm/hot data page.
  1135. */
  1136. static int f2fs_write_cache_pages(struct address_space *mapping,
  1137. struct writeback_control *wbc)
  1138. {
  1139. int ret = 0;
  1140. int done = 0;
  1141. struct pagevec pvec;
  1142. int nr_pages;
  1143. pgoff_t uninitialized_var(writeback_index);
  1144. pgoff_t index;
  1145. pgoff_t end; /* Inclusive */
  1146. pgoff_t done_index;
  1147. int cycled;
  1148. int range_whole = 0;
  1149. int tag;
  1150. int nwritten = 0;
  1151. pagevec_init(&pvec, 0);
  1152. if (wbc->range_cyclic) {
  1153. writeback_index = mapping->writeback_index; /* prev offset */
  1154. index = writeback_index;
  1155. if (index == 0)
  1156. cycled = 1;
  1157. else
  1158. cycled = 0;
  1159. end = -1;
  1160. } else {
  1161. index = wbc->range_start >> PAGE_SHIFT;
  1162. end = wbc->range_end >> PAGE_SHIFT;
  1163. if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
  1164. range_whole = 1;
  1165. cycled = 1; /* ignore range_cyclic tests */
  1166. }
  1167. if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages)
  1168. tag = PAGECACHE_TAG_TOWRITE;
  1169. else
  1170. tag = PAGECACHE_TAG_DIRTY;
  1171. retry:
  1172. if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages)
  1173. tag_pages_for_writeback(mapping, index, end);
  1174. done_index = index;
  1175. while (!done && (index <= end)) {
  1176. int i;
  1177. nr_pages = pagevec_lookup_tag(&pvec, mapping, &index, tag,
  1178. min(end - index, (pgoff_t)PAGEVEC_SIZE - 1) + 1);
  1179. if (nr_pages == 0)
  1180. break;
  1181. for (i = 0; i < nr_pages; i++) {
  1182. struct page *page = pvec.pages[i];
  1183. if (page->index > end) {
  1184. done = 1;
  1185. break;
  1186. }
  1187. done_index = page->index;
  1188. lock_page(page);
  1189. if (unlikely(page->mapping != mapping)) {
  1190. continue_unlock:
  1191. unlock_page(page);
  1192. continue;
  1193. }
  1194. if (!PageDirty(page)) {
  1195. /* someone wrote it for us */
  1196. goto continue_unlock;
  1197. }
  1198. if (PageWriteback(page)) {
  1199. if (wbc->sync_mode != WB_SYNC_NONE)
  1200. f2fs_wait_on_page_writeback(page,
  1201. DATA, true);
  1202. else
  1203. goto continue_unlock;
  1204. }
  1205. BUG_ON(PageWriteback(page));
  1206. if (!clear_page_dirty_for_io(page))
  1207. goto continue_unlock;
  1208. ret = mapping->a_ops->writepage(page, wbc);
  1209. if (unlikely(ret)) {
  1210. /*
  1211. * keep nr_to_write, since vfs uses this to
  1212. * get # of written pages.
  1213. */
  1214. if (ret == AOP_WRITEPAGE_ACTIVATE) {
  1215. unlock_page(page);
  1216. ret = 0;
  1217. continue;
  1218. }
  1219. done_index = page->index + 1;
  1220. done = 1;
  1221. break;
  1222. } else {
  1223. nwritten++;
  1224. }
  1225. if (--wbc->nr_to_write <= 0 &&
  1226. wbc->sync_mode == WB_SYNC_NONE) {
  1227. done = 1;
  1228. break;
  1229. }
  1230. }
  1231. pagevec_release(&pvec);
  1232. cond_resched();
  1233. }
  1234. if (!cycled && !done) {
  1235. cycled = 1;
  1236. index = 0;
  1237. end = writeback_index - 1;
  1238. goto retry;
  1239. }
  1240. if (wbc->range_cyclic || (range_whole && wbc->nr_to_write > 0))
  1241. mapping->writeback_index = done_index;
  1242. if (nwritten)
  1243. f2fs_submit_merged_bio_cond(F2FS_M_SB(mapping), mapping->host,
  1244. NULL, 0, DATA, WRITE);
  1245. return ret;
  1246. }
  1247. static int f2fs_write_data_pages(struct address_space *mapping,
  1248. struct writeback_control *wbc)
  1249. {
  1250. struct inode *inode = mapping->host;
  1251. struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
  1252. struct blk_plug plug;
  1253. int ret;
  1254. /* deal with chardevs and other special file */
  1255. if (!mapping->a_ops->writepage)
  1256. return 0;
  1257. /* skip writing if there is no dirty page in this inode */
  1258. if (!get_dirty_pages(inode) && wbc->sync_mode == WB_SYNC_NONE)
  1259. return 0;
  1260. if (S_ISDIR(inode->i_mode) && wbc->sync_mode == WB_SYNC_NONE &&
  1261. get_dirty_pages(inode) < nr_pages_to_skip(sbi, DATA) &&
  1262. available_free_memory(sbi, DIRTY_DENTS))
  1263. goto skip_write;
  1264. /* skip writing during file defragment */
  1265. if (is_inode_flag_set(inode, FI_DO_DEFRAG))
  1266. goto skip_write;
  1267. /* during POR, we don't need to trigger writepage at all. */
  1268. if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING)))
  1269. goto skip_write;
  1270. trace_f2fs_writepages(mapping->host, wbc, DATA);
  1271. blk_start_plug(&plug);
  1272. ret = f2fs_write_cache_pages(mapping, wbc);
  1273. blk_finish_plug(&plug);
  1274. /*
  1275. * if some pages were truncated, we cannot guarantee its mapping->host
  1276. * to detect pending bios.
  1277. */
  1278. remove_dirty_inode(inode);
  1279. return ret;
  1280. skip_write:
  1281. wbc->pages_skipped += get_dirty_pages(inode);
  1282. trace_f2fs_writepages(mapping->host, wbc, DATA);
  1283. return 0;
  1284. }
  1285. static void f2fs_write_failed(struct address_space *mapping, loff_t to)
  1286. {
  1287. struct inode *inode = mapping->host;
  1288. loff_t i_size = i_size_read(inode);
  1289. if (to > i_size) {
  1290. truncate_pagecache(inode, 0, i_size);
  1291. truncate_blocks(inode, i_size, true);
  1292. }
  1293. }
  1294. static int prepare_write_begin(struct f2fs_sb_info *sbi,
  1295. struct page *page, loff_t pos, unsigned len,
  1296. block_t *blk_addr, bool *node_changed)
  1297. {
  1298. struct inode *inode = page->mapping->host;
  1299. pgoff_t index = page->index;
  1300. struct dnode_of_data dn;
  1301. struct page *ipage;
  1302. bool locked = false;
  1303. struct extent_info ei;
  1304. int err = 0;
  1305. /*
  1306. * we already allocated all the blocks, so we don't need to get
  1307. * the block addresses when there is no need to fill the page.
  1308. */
  1309. if (!f2fs_has_inline_data(inode) && len == PAGE_SIZE)
  1310. return 0;
  1311. if (f2fs_has_inline_data(inode) ||
  1312. (pos & PAGE_MASK) >= i_size_read(inode)) {
  1313. f2fs_lock_op(sbi);
  1314. locked = true;
  1315. }
  1316. restart:
  1317. /* check inline_data */
  1318. ipage = get_node_page(sbi, inode->i_ino);
  1319. if (IS_ERR(ipage)) {
  1320. err = PTR_ERR(ipage);
  1321. goto unlock_out;
  1322. }
  1323. set_new_dnode(&dn, inode, ipage, ipage, 0);
  1324. if (f2fs_has_inline_data(inode)) {
  1325. if (pos + len <= MAX_INLINE_DATA) {
  1326. read_inline_data(page, ipage);
  1327. set_inode_flag(inode, FI_DATA_EXIST);
  1328. if (inode->i_nlink)
  1329. set_inline_node(ipage);
  1330. } else {
  1331. err = f2fs_convert_inline_page(&dn, page);
  1332. if (err)
  1333. goto out;
  1334. if (dn.data_blkaddr == NULL_ADDR)
  1335. err = f2fs_get_block(&dn, index);
  1336. }
  1337. } else if (locked) {
  1338. err = f2fs_get_block(&dn, index);
  1339. } else {
  1340. if (f2fs_lookup_extent_cache(inode, index, &ei)) {
  1341. dn.data_blkaddr = ei.blk + index - ei.fofs;
  1342. } else {
  1343. /* hole case */
  1344. err = get_dnode_of_data(&dn, index, LOOKUP_NODE);
  1345. if (err || dn.data_blkaddr == NULL_ADDR) {
  1346. f2fs_put_dnode(&dn);
  1347. f2fs_lock_op(sbi);
  1348. locked = true;
  1349. goto restart;
  1350. }
  1351. }
  1352. }
  1353. /* convert_inline_page can make node_changed */
  1354. *blk_addr = dn.data_blkaddr;
  1355. *node_changed = dn.node_changed;
  1356. out:
  1357. f2fs_put_dnode(&dn);
  1358. unlock_out:
  1359. if (locked)
  1360. f2fs_unlock_op(sbi);
  1361. return err;
  1362. }
  1363. static int f2fs_write_begin(struct file *file, struct address_space *mapping,
  1364. loff_t pos, unsigned len, unsigned flags,
  1365. struct page **pagep, void **fsdata)
  1366. {
  1367. struct inode *inode = mapping->host;
  1368. struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
  1369. struct page *page = NULL;
  1370. pgoff_t index = ((unsigned long long) pos) >> PAGE_SHIFT;
  1371. bool need_balance = false;
  1372. block_t blkaddr = NULL_ADDR;
  1373. int err = 0;
  1374. trace_f2fs_write_begin(inode, pos, len, flags);
  1375. /*
  1376. * We should check this at this moment to avoid deadlock on inode page
  1377. * and #0 page. The locking rule for inline_data conversion should be:
  1378. * lock_page(page #0) -> lock_page(inode_page)
  1379. */
  1380. if (index != 0) {
  1381. err = f2fs_convert_inline_inode(inode);
  1382. if (err)
  1383. goto fail;
  1384. }
  1385. repeat:
  1386. page = grab_cache_page_write_begin(mapping, index, flags);
  1387. if (!page) {
  1388. err = -ENOMEM;
  1389. goto fail;
  1390. }
  1391. *pagep = page;
  1392. err = prepare_write_begin(sbi, page, pos, len,
  1393. &blkaddr, &need_balance);
  1394. if (err)
  1395. goto fail;
  1396. if (need_balance && has_not_enough_free_secs(sbi, 0, 0)) {
  1397. unlock_page(page);
  1398. f2fs_balance_fs(sbi, true);
  1399. lock_page(page);
  1400. if (page->mapping != mapping) {
  1401. /* The page got truncated from under us */
  1402. f2fs_put_page(page, 1);
  1403. goto repeat;
  1404. }
  1405. }
  1406. f2fs_wait_on_page_writeback(page, DATA, false);
  1407. /* wait for GCed encrypted page writeback */
  1408. if (f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode))
  1409. f2fs_wait_on_encrypted_page_writeback(sbi, blkaddr);
  1410. if (len == PAGE_SIZE || PageUptodate(page))
  1411. return 0;
  1412. if (blkaddr == NEW_ADDR) {
  1413. zero_user_segment(page, 0, PAGE_SIZE);
  1414. SetPageUptodate(page);
  1415. } else {
  1416. struct bio *bio;
  1417. bio = f2fs_grab_bio(inode, blkaddr, 1);
  1418. if (IS_ERR(bio)) {
  1419. err = PTR_ERR(bio);
  1420. goto fail;
  1421. }
  1422. if (bio_add_page(bio, page, PAGE_SIZE, 0) < PAGE_SIZE) {
  1423. bio_put(bio);
  1424. err = -EFAULT;
  1425. goto fail;
  1426. }
  1427. __submit_bio(sbi, READ_SYNC, bio, DATA);
  1428. lock_page(page);
  1429. if (unlikely(page->mapping != mapping)) {
  1430. f2fs_put_page(page, 1);
  1431. goto repeat;
  1432. }
  1433. if (unlikely(!PageUptodate(page))) {
  1434. err = -EIO;
  1435. goto fail;
  1436. }
  1437. }
  1438. return 0;
  1439. fail:
  1440. f2fs_put_page(page, 1);
  1441. f2fs_write_failed(mapping, pos + len);
  1442. return err;
  1443. }
  1444. static int f2fs_write_end(struct file *file,
  1445. struct address_space *mapping,
  1446. loff_t pos, unsigned len, unsigned copied,
  1447. struct page *page, void *fsdata)
  1448. {
  1449. struct inode *inode = page->mapping->host;
  1450. trace_f2fs_write_end(inode, pos, len, copied);
  1451. /*
  1452. * This should be come from len == PAGE_SIZE, and we expect copied
  1453. * should be PAGE_SIZE. Otherwise, we treat it with zero copied and
  1454. * let generic_perform_write() try to copy data again through copied=0.
  1455. */
  1456. if (!PageUptodate(page)) {
  1457. if (unlikely(copied != PAGE_SIZE))
  1458. copied = 0;
  1459. else
  1460. SetPageUptodate(page);
  1461. }
  1462. if (!copied)
  1463. goto unlock_out;
  1464. set_page_dirty(page);
  1465. if (pos + copied > i_size_read(inode))
  1466. f2fs_i_size_write(inode, pos + copied);
  1467. unlock_out:
  1468. f2fs_put_page(page, 1);
  1469. f2fs_update_time(F2FS_I_SB(inode), REQ_TIME);
  1470. return copied;
  1471. }
  1472. static ssize_t check_direct_IO(struct inode *inode, int rw,
  1473. const struct iovec *iov, loff_t offset, unsigned long nr_segs)
  1474. {
  1475. unsigned blocksize_mask = inode->i_sb->s_blocksize - 1;
  1476. int seg, i;
  1477. size_t size;
  1478. unsigned long addr;
  1479. ssize_t retval = -EINVAL;
  1480. loff_t end = offset;
  1481. if (offset & blocksize_mask)
  1482. return -EINVAL;
  1483. /* Check the memory alignment. Blocks cannot straddle pages */
  1484. for (seg = 0; seg < nr_segs; seg++) {
  1485. addr = (unsigned long)iov[seg].iov_base;
  1486. size = iov[seg].iov_len;
  1487. end += size;
  1488. if ((addr & blocksize_mask) || (size & blocksize_mask))
  1489. goto out;
  1490. /* If this is a write we don't need to check anymore */
  1491. if (rw & WRITE)
  1492. continue;
  1493. /*
  1494. * Check to make sure we don't have duplicate iov_base's in this
  1495. * iovec, if so return EINVAL, otherwise we'll get csum errors
  1496. * when reading back.
  1497. */
  1498. for (i = seg + 1; i < nr_segs; i++) {
  1499. if (iov[seg].iov_base == iov[i].iov_base)
  1500. goto out;
  1501. }
  1502. }
  1503. retval = 0;
  1504. out:
  1505. return retval;
  1506. }
  1507. static ssize_t f2fs_direct_IO(int rw, struct kiocb *iocb,
  1508. const struct iovec *iov, loff_t offset,
  1509. unsigned long nr_segs)
  1510. {
  1511. struct address_space *mapping = iocb->ki_filp->f_mapping;
  1512. struct inode *inode = mapping->host;
  1513. size_t count = iov_length(iov, nr_segs);
  1514. int err;
  1515. err = check_direct_IO(inode, rw, iov, offset, nr_segs);
  1516. if (err)
  1517. return err;
  1518. if (f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode))
  1519. return 0;
  1520. if (rw == WRITE && test_opt(F2FS_I_SB(inode), LFS))
  1521. return 0;
  1522. trace_f2fs_direct_IO_enter(inode, offset, count, rw);
  1523. down_read(&F2FS_I(inode)->dio_rwsem[rw]);
  1524. err = blockdev_direct_IO(rw, iocb, inode, iov, offset, nr_segs,
  1525. get_data_block_dio);
  1526. up_read(&F2FS_I(inode)->dio_rwsem[rw]);
  1527. if (err < 0 && (rw & WRITE)) {
  1528. if (err > 0)
  1529. set_inode_flag(inode, FI_UPDATE_WRITE);
  1530. else if (err < 0)
  1531. f2fs_write_failed(mapping, offset + count);
  1532. }
  1533. trace_f2fs_direct_IO_exit(inode, offset, count, rw, err);
  1534. return err;
  1535. }
  1536. void f2fs_invalidate_page(struct page *page, unsigned long offset)
  1537. {
  1538. struct inode *inode = page->mapping->host;
  1539. struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
  1540. if (inode->i_ino >= F2FS_ROOT_INO(sbi) && (offset % PAGE_SIZE))
  1541. return;
  1542. if (PageDirty(page)) {
  1543. if (inode->i_ino == F2FS_META_INO(sbi)) {
  1544. dec_page_count(sbi, F2FS_DIRTY_META);
  1545. } else if (inode->i_ino == F2FS_NODE_INO(sbi)) {
  1546. dec_page_count(sbi, F2FS_DIRTY_NODES);
  1547. } else {
  1548. inode_dec_dirty_pages(inode);
  1549. remove_dirty_inode(inode);
  1550. }
  1551. }
  1552. /* This is atomic written page, keep Private */
  1553. if (IS_ATOMIC_WRITTEN_PAGE(page))
  1554. return;
  1555. set_page_private(page, 0);
  1556. ClearPagePrivate(page);
  1557. }
  1558. int f2fs_release_page(struct page *page, gfp_t wait)
  1559. {
  1560. /* If this is dirty page, keep PagePrivate */
  1561. if (PageDirty(page))
  1562. return 0;
  1563. /* This is atomic written page, keep Private */
  1564. if (IS_ATOMIC_WRITTEN_PAGE(page))
  1565. return 0;
  1566. set_page_private(page, 0);
  1567. ClearPagePrivate(page);
  1568. return 1;
  1569. }
  1570. /*
  1571. * This was copied from __set_page_dirty_buffers which gives higher performance
  1572. * in very high speed storages. (e.g., pmem)
  1573. */
  1574. void f2fs_set_page_dirty_nobuffers(struct page *page)
  1575. {
  1576. struct address_space *mapping = page->mapping;
  1577. unsigned long flags;
  1578. if (unlikely(!mapping))
  1579. return;
  1580. spin_lock(&mapping->private_lock);
  1581. SetPageDirty(page);
  1582. spin_unlock(&mapping->private_lock);
  1583. spin_lock_irqsave(&mapping->tree_lock, flags);
  1584. WARN_ON_ONCE(!PageUptodate(page));
  1585. account_page_dirtied(page, mapping);
  1586. radix_tree_tag_set(&mapping->page_tree,
  1587. page_index(page), PAGECACHE_TAG_DIRTY);
  1588. spin_unlock_irqrestore(&mapping->tree_lock, flags);
  1589. __mark_inode_dirty(mapping->host, I_DIRTY_PAGES);
  1590. return;
  1591. }
  1592. static int f2fs_set_data_page_dirty(struct page *page)
  1593. {
  1594. struct address_space *mapping = page->mapping;
  1595. struct inode *inode = mapping->host;
  1596. trace_f2fs_set_page_dirty(page, DATA);
  1597. if (!PageUptodate(page))
  1598. SetPageUptodate(page);
  1599. if (f2fs_is_atomic_file(inode)) {
  1600. if (!IS_ATOMIC_WRITTEN_PAGE(page)) {
  1601. register_inmem_page(inode, page);
  1602. return 1;
  1603. }
  1604. /*
  1605. * Previously, this page has been registered, we just
  1606. * return here.
  1607. */
  1608. return 0;
  1609. }
  1610. if (!PageDirty(page)) {
  1611. f2fs_set_page_dirty_nobuffers(page);
  1612. update_dirty_page(inode, page);
  1613. return 1;
  1614. }
  1615. return 0;
  1616. }
  1617. static sector_t f2fs_bmap(struct address_space *mapping, sector_t block)
  1618. {
  1619. struct inode *inode = mapping->host;
  1620. if (f2fs_has_inline_data(inode))
  1621. return 0;
  1622. /* make sure allocating whole blocks */
  1623. if (mapping_tagged(mapping, PAGECACHE_TAG_DIRTY))
  1624. filemap_write_and_wait(mapping);
  1625. return generic_block_bmap(mapping, block, get_data_block_bmap);
  1626. }
  1627. const struct address_space_operations f2fs_dblock_aops = {
  1628. .readpage = f2fs_read_data_page,
  1629. .readpages = f2fs_read_data_pages,
  1630. .writepage = f2fs_write_data_page,
  1631. .writepages = f2fs_write_data_pages,
  1632. .write_begin = f2fs_write_begin,
  1633. .write_end = f2fs_write_end,
  1634. .set_page_dirty = f2fs_set_data_page_dirty,
  1635. .invalidatepage = f2fs_invalidate_page,
  1636. .releasepage = f2fs_release_page,
  1637. .direct_IO = f2fs_direct_IO,
  1638. .bmap = f2fs_bmap,
  1639. };