inline.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  1. /*
  2. * fs/f2fs/inline.c
  3. * Copyright (c) 2013, Intel Corporation
  4. * Authors: Huajun Li <huajun.li@intel.com>
  5. * Haicheng Li <haicheng.li@intel.com>
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/fs.h>
  11. #include <linux/f2fs_fs.h>
  12. #include "f2fs.h"
  13. #include "node.h"
  14. bool f2fs_may_inline_data(struct inode *inode)
  15. {
  16. if (f2fs_is_atomic_file(inode))
  17. return false;
  18. if (!S_ISREG(inode->i_mode) && !S_ISLNK(inode->i_mode))
  19. return false;
  20. if (i_size_read(inode) > MAX_INLINE_DATA(inode))
  21. return false;
  22. if (f2fs_post_read_required(inode))
  23. return false;
  24. return true;
  25. }
  26. bool f2fs_may_inline_dentry(struct inode *inode)
  27. {
  28. if (!test_opt(F2FS_I_SB(inode), INLINE_DENTRY))
  29. return false;
  30. if (!S_ISDIR(inode->i_mode))
  31. return false;
  32. return true;
  33. }
  34. void f2fs_do_read_inline_data(struct page *page, struct page *ipage)
  35. {
  36. struct inode *inode = page->mapping->host;
  37. void *src_addr, *dst_addr;
  38. if (PageUptodate(page))
  39. return;
  40. f2fs_bug_on(F2FS_P_SB(page), page->index);
  41. zero_user_segment(page, MAX_INLINE_DATA(inode), PAGE_SIZE);
  42. /* Copy the whole inline data block */
  43. src_addr = inline_data_addr(inode, ipage);
  44. dst_addr = kmap_atomic(page);
  45. memcpy(dst_addr, src_addr, MAX_INLINE_DATA(inode));
  46. flush_dcache_page(page);
  47. kunmap_atomic(dst_addr);
  48. if (!PageUptodate(page))
  49. SetPageUptodate(page);
  50. }
  51. void f2fs_truncate_inline_inode(struct inode *inode,
  52. struct page *ipage, u64 from)
  53. {
  54. void *addr;
  55. if (from >= MAX_INLINE_DATA(inode))
  56. return;
  57. addr = inline_data_addr(inode, ipage);
  58. f2fs_wait_on_page_writeback(ipage, NODE, true);
  59. memset(addr + from, 0, MAX_INLINE_DATA(inode) - from);
  60. set_page_dirty(ipage);
  61. if (from == 0)
  62. clear_inode_flag(inode, FI_DATA_EXIST);
  63. }
  64. int f2fs_read_inline_data(struct inode *inode, struct page *page)
  65. {
  66. struct page *ipage;
  67. ipage = f2fs_get_node_page(F2FS_I_SB(inode), inode->i_ino);
  68. if (IS_ERR(ipage)) {
  69. unlock_page(page);
  70. return PTR_ERR(ipage);
  71. }
  72. if (!f2fs_has_inline_data(inode)) {
  73. f2fs_put_page(ipage, 1);
  74. return -EAGAIN;
  75. }
  76. if (page->index)
  77. zero_user_segment(page, 0, PAGE_SIZE);
  78. else
  79. f2fs_do_read_inline_data(page, ipage);
  80. if (!PageUptodate(page))
  81. SetPageUptodate(page);
  82. f2fs_put_page(ipage, 1);
  83. unlock_page(page);
  84. return 0;
  85. }
  86. int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page)
  87. {
  88. struct f2fs_io_info fio = {
  89. .sbi = F2FS_I_SB(dn->inode),
  90. .ino = dn->inode->i_ino,
  91. .type = DATA,
  92. .op = REQ_OP_WRITE,
  93. .op_flags = REQ_SYNC | REQ_PRIO,
  94. .page = page,
  95. .encrypted_page = NULL,
  96. .io_type = FS_DATA_IO,
  97. };
  98. struct node_info ni;
  99. int dirty, err;
  100. if (!f2fs_exist_data(dn->inode))
  101. goto clear_out;
  102. err = f2fs_reserve_block(dn, 0);
  103. if (err)
  104. return err;
  105. err = f2fs_get_node_info(fio.sbi, dn->nid, &ni);
  106. if (err) {
  107. f2fs_truncate_data_blocks_range(dn, 1);
  108. f2fs_put_dnode(dn);
  109. return err;
  110. }
  111. fio.version = ni.version;
  112. if (unlikely(dn->data_blkaddr != NEW_ADDR)) {
  113. f2fs_put_dnode(dn);
  114. set_sbi_flag(fio.sbi, SBI_NEED_FSCK);
  115. f2fs_msg(fio.sbi->sb, KERN_WARNING,
  116. "%s: corrupted inline inode ino=%lx, i_addr[0]:0x%x, "
  117. "run fsck to fix.",
  118. __func__, dn->inode->i_ino, dn->data_blkaddr);
  119. return -EFSCORRUPTED;
  120. }
  121. f2fs_bug_on(F2FS_P_SB(page), PageWriteback(page));
  122. f2fs_do_read_inline_data(page, dn->inode_page);
  123. set_page_dirty(page);
  124. /* clear dirty state */
  125. dirty = clear_page_dirty_for_io(page);
  126. /* write data page to try to make data consistent */
  127. set_page_writeback(page);
  128. ClearPageError(page);
  129. fio.old_blkaddr = dn->data_blkaddr;
  130. set_inode_flag(dn->inode, FI_HOT_DATA);
  131. f2fs_outplace_write_data(dn, &fio);
  132. f2fs_wait_on_page_writeback(page, DATA, true);
  133. if (dirty) {
  134. inode_dec_dirty_pages(dn->inode);
  135. f2fs_remove_dirty_inode(dn->inode);
  136. }
  137. /* this converted inline_data should be recovered. */
  138. set_inode_flag(dn->inode, FI_APPEND_WRITE);
  139. /* clear inline data and flag after data writeback */
  140. f2fs_truncate_inline_inode(dn->inode, dn->inode_page, 0);
  141. clear_inline_node(dn->inode_page);
  142. clear_out:
  143. stat_dec_inline_inode(dn->inode);
  144. clear_inode_flag(dn->inode, FI_INLINE_DATA);
  145. f2fs_put_dnode(dn);
  146. return 0;
  147. }
  148. int f2fs_convert_inline_inode(struct inode *inode)
  149. {
  150. struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
  151. struct dnode_of_data dn;
  152. struct page *ipage, *page;
  153. int err = 0;
  154. if (!f2fs_has_inline_data(inode))
  155. return 0;
  156. page = f2fs_grab_cache_page(inode->i_mapping, 0, false);
  157. if (!page)
  158. return -ENOMEM;
  159. f2fs_lock_op(sbi);
  160. ipage = f2fs_get_node_page(sbi, inode->i_ino);
  161. if (IS_ERR(ipage)) {
  162. err = PTR_ERR(ipage);
  163. goto out;
  164. }
  165. set_new_dnode(&dn, inode, ipage, ipage, 0);
  166. if (f2fs_has_inline_data(inode))
  167. err = f2fs_convert_inline_page(&dn, page);
  168. f2fs_put_dnode(&dn);
  169. out:
  170. f2fs_unlock_op(sbi);
  171. f2fs_put_page(page, 1);
  172. f2fs_balance_fs(sbi, dn.node_changed);
  173. return err;
  174. }
  175. int f2fs_write_inline_data(struct inode *inode, struct page *page)
  176. {
  177. void *src_addr, *dst_addr;
  178. struct dnode_of_data dn;
  179. int err;
  180. set_new_dnode(&dn, inode, NULL, NULL, 0);
  181. err = f2fs_get_dnode_of_data(&dn, 0, LOOKUP_NODE);
  182. if (err)
  183. return err;
  184. if (!f2fs_has_inline_data(inode)) {
  185. f2fs_put_dnode(&dn);
  186. return -EAGAIN;
  187. }
  188. f2fs_bug_on(F2FS_I_SB(inode), page->index);
  189. f2fs_wait_on_page_writeback(dn.inode_page, NODE, true);
  190. src_addr = kmap_atomic(page);
  191. dst_addr = inline_data_addr(inode, dn.inode_page);
  192. memcpy(dst_addr, src_addr, MAX_INLINE_DATA(inode));
  193. kunmap_atomic(src_addr);
  194. set_page_dirty(dn.inode_page);
  195. f2fs_clear_radix_tree_dirty_tag(page);
  196. set_inode_flag(inode, FI_APPEND_WRITE);
  197. set_inode_flag(inode, FI_DATA_EXIST);
  198. clear_inline_node(dn.inode_page);
  199. f2fs_put_dnode(&dn);
  200. return 0;
  201. }
  202. bool f2fs_recover_inline_data(struct inode *inode, struct page *npage)
  203. {
  204. struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
  205. struct f2fs_inode *ri = NULL;
  206. void *src_addr, *dst_addr;
  207. struct page *ipage;
  208. /*
  209. * The inline_data recovery policy is as follows.
  210. * [prev.] [next] of inline_data flag
  211. * o o -> recover inline_data
  212. * o x -> remove inline_data, and then recover data blocks
  213. * x o -> remove inline_data, and then recover inline_data
  214. * x x -> recover data blocks
  215. */
  216. if (IS_INODE(npage))
  217. ri = F2FS_INODE(npage);
  218. if (f2fs_has_inline_data(inode) &&
  219. ri && (ri->i_inline & F2FS_INLINE_DATA)) {
  220. process_inline:
  221. ipage = f2fs_get_node_page(sbi, inode->i_ino);
  222. f2fs_bug_on(sbi, IS_ERR(ipage));
  223. f2fs_wait_on_page_writeback(ipage, NODE, true);
  224. src_addr = inline_data_addr(inode, npage);
  225. dst_addr = inline_data_addr(inode, ipage);
  226. memcpy(dst_addr, src_addr, MAX_INLINE_DATA(inode));
  227. set_inode_flag(inode, FI_INLINE_DATA);
  228. set_inode_flag(inode, FI_DATA_EXIST);
  229. set_page_dirty(ipage);
  230. f2fs_put_page(ipage, 1);
  231. return true;
  232. }
  233. if (f2fs_has_inline_data(inode)) {
  234. ipage = f2fs_get_node_page(sbi, inode->i_ino);
  235. f2fs_bug_on(sbi, IS_ERR(ipage));
  236. f2fs_truncate_inline_inode(inode, ipage, 0);
  237. clear_inode_flag(inode, FI_INLINE_DATA);
  238. f2fs_put_page(ipage, 1);
  239. } else if (ri && (ri->i_inline & F2FS_INLINE_DATA)) {
  240. if (f2fs_truncate_blocks(inode, 0, false))
  241. return false;
  242. goto process_inline;
  243. }
  244. return false;
  245. }
  246. struct f2fs_dir_entry *f2fs_find_in_inline_dir(struct inode *dir,
  247. struct fscrypt_name *fname, struct page **res_page)
  248. {
  249. struct f2fs_sb_info *sbi = F2FS_SB(dir->i_sb);
  250. struct qstr name = FSTR_TO_QSTR(&fname->disk_name);
  251. struct f2fs_dir_entry *de;
  252. struct f2fs_dentry_ptr d;
  253. struct page *ipage;
  254. void *inline_dentry;
  255. f2fs_hash_t namehash;
  256. ipage = f2fs_get_node_page(sbi, dir->i_ino);
  257. if (IS_ERR(ipage)) {
  258. *res_page = ipage;
  259. return NULL;
  260. }
  261. namehash = f2fs_dentry_hash(&name, fname);
  262. inline_dentry = inline_data_addr(dir, ipage);
  263. make_dentry_ptr_inline(dir, &d, inline_dentry);
  264. de = f2fs_find_target_dentry(fname, namehash, NULL, &d);
  265. unlock_page(ipage);
  266. if (de)
  267. *res_page = ipage;
  268. else
  269. f2fs_put_page(ipage, 0);
  270. return de;
  271. }
  272. int f2fs_make_empty_inline_dir(struct inode *inode, struct inode *parent,
  273. struct page *ipage)
  274. {
  275. struct f2fs_dentry_ptr d;
  276. void *inline_dentry;
  277. inline_dentry = inline_data_addr(inode, ipage);
  278. make_dentry_ptr_inline(inode, &d, inline_dentry);
  279. f2fs_do_make_empty_dir(inode, parent, &d);
  280. set_page_dirty(ipage);
  281. /* update i_size to MAX_INLINE_DATA */
  282. if (i_size_read(inode) < MAX_INLINE_DATA(inode))
  283. f2fs_i_size_write(inode, MAX_INLINE_DATA(inode));
  284. return 0;
  285. }
  286. /*
  287. * NOTE: ipage is grabbed by caller, but if any error occurs, we should
  288. * release ipage in this function.
  289. */
  290. static int f2fs_move_inline_dirents(struct inode *dir, struct page *ipage,
  291. void *inline_dentry)
  292. {
  293. struct page *page;
  294. struct dnode_of_data dn;
  295. struct f2fs_dentry_block *dentry_blk;
  296. struct f2fs_dentry_ptr src, dst;
  297. int err;
  298. page = f2fs_grab_cache_page(dir->i_mapping, 0, false);
  299. if (!page) {
  300. f2fs_put_page(ipage, 1);
  301. return -ENOMEM;
  302. }
  303. set_new_dnode(&dn, dir, ipage, NULL, 0);
  304. err = f2fs_reserve_block(&dn, 0);
  305. if (err)
  306. goto out;
  307. if (unlikely(dn.data_blkaddr != NEW_ADDR)) {
  308. f2fs_put_dnode(&dn);
  309. set_sbi_flag(F2FS_P_SB(page), SBI_NEED_FSCK);
  310. f2fs_msg(F2FS_P_SB(page)->sb, KERN_WARNING,
  311. "%s: corrupted inline inode ino=%lx, i_addr[0]:0x%x, "
  312. "run fsck to fix.",
  313. __func__, dir->i_ino, dn.data_blkaddr);
  314. err = -EFSCORRUPTED;
  315. goto out;
  316. }
  317. f2fs_wait_on_page_writeback(page, DATA, true);
  318. dentry_blk = page_address(page);
  319. make_dentry_ptr_inline(dir, &src, inline_dentry);
  320. make_dentry_ptr_block(dir, &dst, dentry_blk);
  321. /* copy data from inline dentry block to new dentry block */
  322. memcpy(dst.bitmap, src.bitmap, src.nr_bitmap);
  323. memset(dst.bitmap + src.nr_bitmap, 0, dst.nr_bitmap - src.nr_bitmap);
  324. /*
  325. * we do not need to zero out remainder part of dentry and filename
  326. * field, since we have used bitmap for marking the usage status of
  327. * them, besides, we can also ignore copying/zeroing reserved space
  328. * of dentry block, because them haven't been used so far.
  329. */
  330. memcpy(dst.dentry, src.dentry, SIZE_OF_DIR_ENTRY * src.max);
  331. memcpy(dst.filename, src.filename, src.max * F2FS_SLOT_LEN);
  332. if (!PageUptodate(page))
  333. SetPageUptodate(page);
  334. set_page_dirty(page);
  335. /* clear inline dir and flag after data writeback */
  336. f2fs_truncate_inline_inode(dir, ipage, 0);
  337. stat_dec_inline_dir(dir);
  338. clear_inode_flag(dir, FI_INLINE_DENTRY);
  339. f2fs_i_depth_write(dir, 1);
  340. if (i_size_read(dir) < PAGE_SIZE)
  341. f2fs_i_size_write(dir, PAGE_SIZE);
  342. out:
  343. f2fs_put_page(page, 1);
  344. return err;
  345. }
  346. static int f2fs_add_inline_entries(struct inode *dir, void *inline_dentry)
  347. {
  348. struct f2fs_dentry_ptr d;
  349. unsigned long bit_pos = 0;
  350. int err = 0;
  351. make_dentry_ptr_inline(dir, &d, inline_dentry);
  352. while (bit_pos < d.max) {
  353. struct f2fs_dir_entry *de;
  354. struct qstr new_name;
  355. nid_t ino;
  356. umode_t fake_mode;
  357. if (!test_bit_le(bit_pos, d.bitmap)) {
  358. bit_pos++;
  359. continue;
  360. }
  361. de = &d.dentry[bit_pos];
  362. if (unlikely(!de->name_len)) {
  363. bit_pos++;
  364. continue;
  365. }
  366. new_name.name = d.filename[bit_pos];
  367. new_name.len = le16_to_cpu(de->name_len);
  368. ino = le32_to_cpu(de->ino);
  369. fake_mode = f2fs_get_de_type(de) << S_SHIFT;
  370. err = f2fs_add_regular_entry(dir, &new_name, NULL, NULL,
  371. ino, fake_mode);
  372. if (err)
  373. goto punch_dentry_pages;
  374. bit_pos += GET_DENTRY_SLOTS(le16_to_cpu(de->name_len));
  375. }
  376. return 0;
  377. punch_dentry_pages:
  378. truncate_inode_pages(&dir->i_data, 0);
  379. f2fs_truncate_blocks(dir, 0, false);
  380. f2fs_remove_dirty_inode(dir);
  381. return err;
  382. }
  383. static int f2fs_move_rehashed_dirents(struct inode *dir, struct page *ipage,
  384. void *inline_dentry)
  385. {
  386. void *backup_dentry;
  387. int err;
  388. backup_dentry = f2fs_kmalloc(F2FS_I_SB(dir),
  389. MAX_INLINE_DATA(dir), GFP_F2FS_ZERO);
  390. if (!backup_dentry) {
  391. f2fs_put_page(ipage, 1);
  392. return -ENOMEM;
  393. }
  394. memcpy(backup_dentry, inline_dentry, MAX_INLINE_DATA(dir));
  395. f2fs_truncate_inline_inode(dir, ipage, 0);
  396. unlock_page(ipage);
  397. err = f2fs_add_inline_entries(dir, backup_dentry);
  398. if (err)
  399. goto recover;
  400. lock_page(ipage);
  401. stat_dec_inline_dir(dir);
  402. clear_inode_flag(dir, FI_INLINE_DENTRY);
  403. kfree(backup_dentry);
  404. return 0;
  405. recover:
  406. lock_page(ipage);
  407. f2fs_wait_on_page_writeback(ipage, NODE, true);
  408. memcpy(inline_dentry, backup_dentry, MAX_INLINE_DATA(dir));
  409. f2fs_i_depth_write(dir, 0);
  410. f2fs_i_size_write(dir, MAX_INLINE_DATA(dir));
  411. set_page_dirty(ipage);
  412. f2fs_put_page(ipage, 1);
  413. kfree(backup_dentry);
  414. return err;
  415. }
  416. static int f2fs_convert_inline_dir(struct inode *dir, struct page *ipage,
  417. void *inline_dentry)
  418. {
  419. if (!F2FS_I(dir)->i_dir_level)
  420. return f2fs_move_inline_dirents(dir, ipage, inline_dentry);
  421. else
  422. return f2fs_move_rehashed_dirents(dir, ipage, inline_dentry);
  423. }
  424. int f2fs_add_inline_entry(struct inode *dir, const struct qstr *new_name,
  425. const struct qstr *orig_name,
  426. struct inode *inode, nid_t ino, umode_t mode)
  427. {
  428. struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
  429. struct page *ipage;
  430. unsigned int bit_pos;
  431. f2fs_hash_t name_hash;
  432. void *inline_dentry = NULL;
  433. struct f2fs_dentry_ptr d;
  434. int slots = GET_DENTRY_SLOTS(new_name->len);
  435. struct page *page = NULL;
  436. int err = 0;
  437. ipage = f2fs_get_node_page(sbi, dir->i_ino);
  438. if (IS_ERR(ipage))
  439. return PTR_ERR(ipage);
  440. inline_dentry = inline_data_addr(dir, ipage);
  441. make_dentry_ptr_inline(dir, &d, inline_dentry);
  442. bit_pos = f2fs_room_for_filename(d.bitmap, slots, d.max);
  443. if (bit_pos >= d.max) {
  444. err = f2fs_convert_inline_dir(dir, ipage, inline_dentry);
  445. if (err)
  446. return err;
  447. err = -EAGAIN;
  448. goto out;
  449. }
  450. if (inode) {
  451. down_write(&F2FS_I(inode)->i_sem);
  452. page = f2fs_init_inode_metadata(inode, dir, new_name,
  453. orig_name, ipage);
  454. if (IS_ERR(page)) {
  455. err = PTR_ERR(page);
  456. goto fail;
  457. }
  458. }
  459. f2fs_wait_on_page_writeback(ipage, NODE, true);
  460. name_hash = f2fs_dentry_hash(new_name, NULL);
  461. f2fs_update_dentry(ino, mode, &d, new_name, name_hash, bit_pos);
  462. set_page_dirty(ipage);
  463. /* we don't need to mark_inode_dirty now */
  464. if (inode) {
  465. f2fs_i_pino_write(inode, dir->i_ino);
  466. /* synchronize inode page's data from inode cache */
  467. if (is_inode_flag_set(inode, FI_NEW_INODE))
  468. f2fs_update_inode(inode, page);
  469. f2fs_put_page(page, 1);
  470. }
  471. f2fs_update_parent_metadata(dir, inode, 0);
  472. fail:
  473. if (inode)
  474. up_write(&F2FS_I(inode)->i_sem);
  475. out:
  476. f2fs_put_page(ipage, 1);
  477. return err;
  478. }
  479. void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry, struct page *page,
  480. struct inode *dir, struct inode *inode)
  481. {
  482. struct f2fs_dentry_ptr d;
  483. void *inline_dentry;
  484. int slots = GET_DENTRY_SLOTS(le16_to_cpu(dentry->name_len));
  485. unsigned int bit_pos;
  486. int i;
  487. lock_page(page);
  488. f2fs_wait_on_page_writeback(page, NODE, true);
  489. inline_dentry = inline_data_addr(dir, page);
  490. make_dentry_ptr_inline(dir, &d, inline_dentry);
  491. bit_pos = dentry - d.dentry;
  492. for (i = 0; i < slots; i++)
  493. __clear_bit_le(bit_pos + i, d.bitmap);
  494. set_page_dirty(page);
  495. f2fs_put_page(page, 1);
  496. dir->i_ctime = dir->i_mtime = current_time(dir);
  497. f2fs_mark_inode_dirty_sync(dir, false);
  498. if (inode)
  499. f2fs_drop_nlink(dir, inode);
  500. }
  501. bool f2fs_empty_inline_dir(struct inode *dir)
  502. {
  503. struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
  504. struct page *ipage;
  505. unsigned int bit_pos = 2;
  506. void *inline_dentry;
  507. struct f2fs_dentry_ptr d;
  508. ipage = f2fs_get_node_page(sbi, dir->i_ino);
  509. if (IS_ERR(ipage))
  510. return false;
  511. inline_dentry = inline_data_addr(dir, ipage);
  512. make_dentry_ptr_inline(dir, &d, inline_dentry);
  513. bit_pos = find_next_bit_le(d.bitmap, d.max, bit_pos);
  514. f2fs_put_page(ipage, 1);
  515. if (bit_pos < d.max)
  516. return false;
  517. return true;
  518. }
  519. int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx,
  520. struct fscrypt_str *fstr)
  521. {
  522. struct inode *inode = file_inode(file);
  523. struct page *ipage = NULL;
  524. struct f2fs_dentry_ptr d;
  525. void *inline_dentry = NULL;
  526. int err;
  527. make_dentry_ptr_inline(inode, &d, inline_dentry);
  528. if (ctx->pos == d.max)
  529. return 0;
  530. ipage = f2fs_get_node_page(F2FS_I_SB(inode), inode->i_ino);
  531. if (IS_ERR(ipage))
  532. return PTR_ERR(ipage);
  533. /*
  534. * f2fs_readdir was protected by inode.i_rwsem, it is safe to access
  535. * ipage without page's lock held.
  536. */
  537. unlock_page(ipage);
  538. inline_dentry = inline_data_addr(inode, ipage);
  539. make_dentry_ptr_inline(inode, &d, inline_dentry);
  540. err = f2fs_fill_dentries(ctx, &d, 0, fstr);
  541. if (!err)
  542. ctx->pos = d.max;
  543. f2fs_put_page(ipage, 0);
  544. return err < 0 ? err : 0;
  545. }
  546. int f2fs_inline_data_fiemap(struct inode *inode,
  547. struct fiemap_extent_info *fieinfo, __u64 start, __u64 len)
  548. {
  549. __u64 byteaddr, ilen;
  550. __u32 flags = FIEMAP_EXTENT_DATA_INLINE | FIEMAP_EXTENT_NOT_ALIGNED |
  551. FIEMAP_EXTENT_LAST;
  552. struct node_info ni;
  553. struct page *ipage;
  554. int err = 0;
  555. ipage = f2fs_get_node_page(F2FS_I_SB(inode), inode->i_ino);
  556. if (IS_ERR(ipage))
  557. return PTR_ERR(ipage);
  558. if (!f2fs_has_inline_data(inode)) {
  559. err = -EAGAIN;
  560. goto out;
  561. }
  562. ilen = min_t(size_t, MAX_INLINE_DATA(inode), i_size_read(inode));
  563. if (start >= ilen)
  564. goto out;
  565. if (start + len < ilen)
  566. ilen = start + len;
  567. ilen -= start;
  568. err = f2fs_get_node_info(F2FS_I_SB(inode), inode->i_ino, &ni);
  569. if (err)
  570. goto out;
  571. byteaddr = (__u64)ni.blk_addr << inode->i_sb->s_blocksize_bits;
  572. byteaddr += (char *)inline_data_addr(inode, ipage) -
  573. (char *)F2FS_INODE(ipage);
  574. err = fiemap_fill_next_extent(fieinfo, start, byteaddr, ilen, flags);
  575. out:
  576. f2fs_put_page(ipage, 1);
  577. return err;
  578. }