17c1a000dSChao Yu // SPDX-License-Identifier: GPL-2.0 2e18c65b2SHuajun Li /* 3e18c65b2SHuajun Li * fs/f2fs/inline.c 4e18c65b2SHuajun Li * Copyright (c) 2013, Intel Corporation 5e18c65b2SHuajun Li * Authors: Huajun Li <huajun.li@intel.com> 6e18c65b2SHuajun Li * Haicheng Li <haicheng.li@intel.com> 7e18c65b2SHuajun Li */ 8e18c65b2SHuajun Li 9e18c65b2SHuajun Li #include <linux/fs.h> 10e18c65b2SHuajun Li #include <linux/f2fs_fs.h> 1110c5db28SChristoph Hellwig #include <linux/fiemap.h> 12e18c65b2SHuajun Li 13e18c65b2SHuajun Li #include "f2fs.h" 1467f8cf3cSJaegeuk Kim #include "node.h" 15dd5a09bdSChao Yu #include <trace/events/f2fs.h> 16e18c65b2SHuajun Li 1701b960e9SJaegeuk Kim bool f2fs_may_inline_data(struct inode *inode) 18e18c65b2SHuajun Li { 1988b88a66SJaegeuk Kim if (f2fs_is_atomic_file(inode)) 2088b88a66SJaegeuk Kim return false; 2188b88a66SJaegeuk Kim 22368a0e40SWanpeng Li if (!S_ISREG(inode->i_mode) && !S_ISLNK(inode->i_mode)) 23e18c65b2SHuajun Li return false; 24e18c65b2SHuajun Li 25f2470371SChao Yu if (i_size_read(inode) > MAX_INLINE_DATA(inode)) 2692dffd01SJaegeuk Kim return false; 2792dffd01SJaegeuk Kim 286dbb1796SEric Biggers if (f2fs_post_read_required(inode)) 29fcc85a4dSJaegeuk Kim return false; 30fcc85a4dSJaegeuk Kim 31e18c65b2SHuajun Li return true; 32e18c65b2SHuajun Li } 33e18c65b2SHuajun Li 3401b960e9SJaegeuk Kim bool f2fs_may_inline_dentry(struct inode *inode) 3501b960e9SJaegeuk Kim { 3601b960e9SJaegeuk Kim if (!test_opt(F2FS_I_SB(inode), INLINE_DENTRY)) 3701b960e9SJaegeuk Kim return false; 3801b960e9SJaegeuk Kim 3901b960e9SJaegeuk Kim if (!S_ISDIR(inode->i_mode)) 4001b960e9SJaegeuk Kim return false; 4101b960e9SJaegeuk Kim 4201b960e9SJaegeuk Kim return true; 4301b960e9SJaegeuk Kim } 4401b960e9SJaegeuk Kim 454d57b86dSChao Yu void f2fs_do_read_inline_data(struct page *page, struct page *ipage) 46e18c65b2SHuajun Li { 47f2470371SChao Yu struct inode *inode = page->mapping->host; 48e18c65b2SHuajun Li void *src_addr, *dst_addr; 49e18c65b2SHuajun Li 50b3d208f9SJaegeuk Kim if (PageUptodate(page)) 51b3d208f9SJaegeuk Kim return; 5204a17fb1SChao Yu 53b3d208f9SJaegeuk Kim f2fs_bug_on(F2FS_P_SB(page), page->index); 54e18c65b2SHuajun Li 55f2470371SChao Yu zero_user_segment(page, MAX_INLINE_DATA(inode), PAGE_SIZE); 56e18c65b2SHuajun Li 57e18c65b2SHuajun Li /* Copy the whole inline data block */ 58f2470371SChao Yu src_addr = inline_data_addr(inode, ipage); 59f1e33a04SJaegeuk Kim dst_addr = kmap_atomic(page); 60f2470371SChao Yu memcpy(dst_addr, src_addr, MAX_INLINE_DATA(inode)); 61427a45c8SJaegeuk Kim flush_dcache_page(page); 62f1e33a04SJaegeuk Kim kunmap_atomic(dst_addr); 63237c0790SJaegeuk Kim if (!PageUptodate(page)) 64e18c65b2SHuajun Li SetPageUptodate(page); 65b3d208f9SJaegeuk Kim } 66e18c65b2SHuajun Li 674d57b86dSChao Yu void f2fs_truncate_inline_inode(struct inode *inode, 684d57b86dSChao Yu struct page *ipage, u64 from) 69feeb0debSChao Yu { 700bfcfccaSChao Yu void *addr; 710bfcfccaSChao Yu 72f2470371SChao Yu if (from >= MAX_INLINE_DATA(inode)) 73bd4667cbSKinglong Mee return; 740bfcfccaSChao Yu 75f2470371SChao Yu addr = inline_data_addr(inode, ipage); 760bfcfccaSChao Yu 77bae0ee7aSChao Yu f2fs_wait_on_page_writeback(ipage, NODE, true, true); 78f2470371SChao Yu memset(addr + from, 0, MAX_INLINE_DATA(inode) - from); 79ee6d182fSJaegeuk Kim set_page_dirty(ipage); 80bd4667cbSKinglong Mee 81bd4667cbSKinglong Mee if (from == 0) 82bd4667cbSKinglong Mee clear_inode_flag(inode, FI_DATA_EXIST); 83feeb0debSChao Yu } 84feeb0debSChao Yu 85b3d208f9SJaegeuk Kim int f2fs_read_inline_data(struct inode *inode, struct page *page) 86b3d208f9SJaegeuk Kim { 87b3d208f9SJaegeuk Kim struct page *ipage; 88b3d208f9SJaegeuk Kim 894d57b86dSChao Yu ipage = f2fs_get_node_page(F2FS_I_SB(inode), inode->i_ino); 90b3d208f9SJaegeuk Kim if (IS_ERR(ipage)) { 91b3d208f9SJaegeuk Kim unlock_page(page); 92b3d208f9SJaegeuk Kim return PTR_ERR(ipage); 93b3d208f9SJaegeuk Kim } 94b3d208f9SJaegeuk Kim 95b3d208f9SJaegeuk Kim if (!f2fs_has_inline_data(inode)) { 96b3d208f9SJaegeuk Kim f2fs_put_page(ipage, 1); 97b3d208f9SJaegeuk Kim return -EAGAIN; 98b3d208f9SJaegeuk Kim } 99b3d208f9SJaegeuk Kim 100b3d208f9SJaegeuk Kim if (page->index) 10109cbfeafSKirill A. Shutemov zero_user_segment(page, 0, PAGE_SIZE); 102b3d208f9SJaegeuk Kim else 1034d57b86dSChao Yu f2fs_do_read_inline_data(page, ipage); 104b3d208f9SJaegeuk Kim 105237c0790SJaegeuk Kim if (!PageUptodate(page)) 106b3d208f9SJaegeuk Kim SetPageUptodate(page); 107b3d208f9SJaegeuk Kim f2fs_put_page(ipage, 1); 108b3d208f9SJaegeuk Kim unlock_page(page); 109e18c65b2SHuajun Li return 0; 110e18c65b2SHuajun Li } 111e18c65b2SHuajun Li 112b3d208f9SJaegeuk Kim int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page) 113e18c65b2SHuajun Li { 114e18c65b2SHuajun Li struct f2fs_io_info fio = { 11505ca3632SJaegeuk Kim .sbi = F2FS_I_SB(dn->inode), 11639d787beSChao Yu .ino = dn->inode->i_ino, 117e18c65b2SHuajun Li .type = DATA, 11804d328deSMike Christie .op = REQ_OP_WRITE, 11970fd7614SChristoph Hellwig .op_flags = REQ_SYNC | REQ_PRIO, 12005ca3632SJaegeuk Kim .page = page, 1214375a336SJaegeuk Kim .encrypted_page = NULL, 122b0af6d49SChao Yu .io_type = FS_DATA_IO, 123e18c65b2SHuajun Li }; 1247735730dSChao Yu struct node_info ni; 125158c194cSJaegeuk Kim int dirty, err; 126e18c65b2SHuajun Li 127b3d208f9SJaegeuk Kim if (!f2fs_exist_data(dn->inode)) 128b3d208f9SJaegeuk Kim goto clear_out; 129ec4e7af4SJaegeuk Kim 130b3d208f9SJaegeuk Kim err = f2fs_reserve_block(dn, 0); 13115c6e3aaSJaegeuk Kim if (err) 132b3d208f9SJaegeuk Kim return err; 133e18c65b2SHuajun Li 134a9419b63SJaegeuk Kim err = f2fs_get_node_info(fio.sbi, dn->nid, &ni, false); 1357735730dSChao Yu if (err) { 136e8c82c11SChao Yu f2fs_truncate_data_blocks_range(dn, 1); 1377735730dSChao Yu f2fs_put_dnode(dn); 1387735730dSChao Yu return err; 1397735730dSChao Yu } 1407735730dSChao Yu 1417735730dSChao Yu fio.version = ni.version; 1427735730dSChao Yu 1434dbe38dcSChao Yu if (unlikely(dn->data_blkaddr != NEW_ADDR)) { 1444dbe38dcSChao Yu f2fs_put_dnode(dn); 1454dbe38dcSChao Yu set_sbi_flag(fio.sbi, SBI_NEED_FSCK); 146dcbb4c10SJoe Perches f2fs_warn(fio.sbi, "%s: corrupted inline inode ino=%lx, i_addr[0]:0x%x, run fsck to fix.", 1474dbe38dcSChao Yu __func__, dn->inode->i_ino, dn->data_blkaddr); 14810f966bbSChao Yu return -EFSCORRUPTED; 1494dbe38dcSChao Yu } 1504dbe38dcSChao Yu 15185ead818SYunlei He f2fs_bug_on(F2FS_P_SB(page), PageWriteback(page)); 152b3d208f9SJaegeuk Kim 1534d57b86dSChao Yu f2fs_do_read_inline_data(page, dn->inode_page); 1546282adbfSJaegeuk Kim set_page_dirty(page); 1556282adbfSJaegeuk Kim 156158c194cSJaegeuk Kim /* clear dirty state */ 157158c194cSJaegeuk Kim dirty = clear_page_dirty_for_io(page); 158158c194cSJaegeuk Kim 159e18c65b2SHuajun Li /* write data page to try to make data consistent */ 160e18c65b2SHuajun Li set_page_writeback(page); 16117c50035SJaegeuk Kim ClearPageError(page); 1627a9d7548SChao Yu fio.old_blkaddr = dn->data_blkaddr; 163ef095d19SJaegeuk Kim set_inode_flag(dn->inode, FI_HOT_DATA); 1644d57b86dSChao Yu f2fs_outplace_write_data(dn, &fio); 165bae0ee7aSChao Yu f2fs_wait_on_page_writeback(page, DATA, true, true); 166933439c8SChao Yu if (dirty) { 167158c194cSJaegeuk Kim inode_dec_dirty_pages(dn->inode); 1684d57b86dSChao Yu f2fs_remove_dirty_inode(dn->inode); 169933439c8SChao Yu } 170e18c65b2SHuajun Li 17195f5b0fcSJaegeuk Kim /* this converted inline_data should be recovered. */ 17291942321SJaegeuk Kim set_inode_flag(dn->inode, FI_APPEND_WRITE); 17395f5b0fcSJaegeuk Kim 174e18c65b2SHuajun Li /* clear inline data and flag after data writeback */ 1754d57b86dSChao Yu f2fs_truncate_inline_inode(dn->inode, dn->inode_page, 0); 176b763f3beSChao Yu clear_page_private_inline(dn->inode_page); 177b3d208f9SJaegeuk Kim clear_out: 178b3d208f9SJaegeuk Kim stat_dec_inline_inode(dn->inode); 179bd4667cbSKinglong Mee clear_inode_flag(dn->inode, FI_INLINE_DATA); 180b3d208f9SJaegeuk Kim f2fs_put_dnode(dn); 181b3d208f9SJaegeuk Kim return 0; 182e18c65b2SHuajun Li } 183e18c65b2SHuajun Li 184b3d208f9SJaegeuk Kim int f2fs_convert_inline_inode(struct inode *inode) 185e18c65b2SHuajun Li { 186b3d208f9SJaegeuk Kim struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 187b3d208f9SJaegeuk Kim struct dnode_of_data dn; 188b3d208f9SJaegeuk Kim struct page *ipage, *page; 189b3d208f9SJaegeuk Kim int err = 0; 190e18c65b2SHuajun Li 191ec2ddf49SJaegeuk Kim if (!f2fs_has_inline_data(inode) || 192ec2ddf49SJaegeuk Kim f2fs_hw_is_readonly(sbi) || f2fs_readonly(sbi->sb)) 193b9d777b8SJaegeuk Kim return 0; 194b9d777b8SJaegeuk Kim 19510a26878SChao Yu err = f2fs_dquot_initialize(inode); 19625fb04dbSYi Chen if (err) 19725fb04dbSYi Chen return err; 19825fb04dbSYi Chen 199300e129cSJaegeuk Kim page = f2fs_grab_cache_page(inode->i_mapping, 0, false); 200b3d208f9SJaegeuk Kim if (!page) 2019e09fc85SJaegeuk Kim return -ENOMEM; 202b3d208f9SJaegeuk Kim 203b3d208f9SJaegeuk Kim f2fs_lock_op(sbi); 204b3d208f9SJaegeuk Kim 2054d57b86dSChao Yu ipage = f2fs_get_node_page(sbi, inode->i_ino); 206b3d208f9SJaegeuk Kim if (IS_ERR(ipage)) { 2076d20aff8SJaegeuk Kim err = PTR_ERR(ipage); 2086d20aff8SJaegeuk Kim goto out; 209b067ba1fSJaegeuk Kim } 210e18c65b2SHuajun Li 211b3d208f9SJaegeuk Kim set_new_dnode(&dn, inode, ipage, ipage, 0); 212b3d208f9SJaegeuk Kim 213b3d208f9SJaegeuk Kim if (f2fs_has_inline_data(inode)) 214b3d208f9SJaegeuk Kim err = f2fs_convert_inline_page(&dn, page); 215b3d208f9SJaegeuk Kim 216b3d208f9SJaegeuk Kim f2fs_put_dnode(&dn); 2176d20aff8SJaegeuk Kim out: 218b3d208f9SJaegeuk Kim f2fs_unlock_op(sbi); 219b3d208f9SJaegeuk Kim 220b3d208f9SJaegeuk Kim f2fs_put_page(page, 1); 2212a340760SJaegeuk Kim 22228e18ee6SColin Ian King if (!err) 2232c4db1a6SJaegeuk Kim f2fs_balance_fs(sbi, dn.node_changed); 2242a340760SJaegeuk Kim 225e18c65b2SHuajun Li return err; 226e18c65b2SHuajun Li } 227e18c65b2SHuajun Li 228b3d208f9SJaegeuk Kim int f2fs_write_inline_data(struct inode *inode, struct page *page) 229e18c65b2SHuajun Li { 230e18c65b2SHuajun Li void *src_addr, *dst_addr; 231e18c65b2SHuajun Li struct dnode_of_data dn; 232e18c65b2SHuajun Li int err; 233e18c65b2SHuajun Li 234e18c65b2SHuajun Li set_new_dnode(&dn, inode, NULL, NULL, 0); 2354d57b86dSChao Yu err = f2fs_get_dnode_of_data(&dn, 0, LOOKUP_NODE); 236e18c65b2SHuajun Li if (err) 237e18c65b2SHuajun Li return err; 238e18c65b2SHuajun Li 239c08a690bSJaegeuk Kim if (!f2fs_has_inline_data(inode)) { 240b3d208f9SJaegeuk Kim f2fs_put_dnode(&dn); 241b3d208f9SJaegeuk Kim return -EAGAIN; 242c08a690bSJaegeuk Kim } 243c08a690bSJaegeuk Kim 244b3d208f9SJaegeuk Kim f2fs_bug_on(F2FS_I_SB(inode), page->index); 245b3d208f9SJaegeuk Kim 246bae0ee7aSChao Yu f2fs_wait_on_page_writeback(dn.inode_page, NODE, true, true); 247f1e33a04SJaegeuk Kim src_addr = kmap_atomic(page); 248f2470371SChao Yu dst_addr = inline_data_addr(inode, dn.inode_page); 249f2470371SChao Yu memcpy(dst_addr, src_addr, MAX_INLINE_DATA(inode)); 250f1e33a04SJaegeuk Kim kunmap_atomic(src_addr); 251ee6d182fSJaegeuk Kim set_page_dirty(dn.inode_page); 252e18c65b2SHuajun Li 2535ec2d99dSMatthew Wilcox f2fs_clear_page_cache_dirty_tag(page); 2540abd8e70SDaeho Jeong 25591942321SJaegeuk Kim set_inode_flag(inode, FI_APPEND_WRITE); 25691942321SJaegeuk Kim set_inode_flag(inode, FI_DATA_EXIST); 257b3d208f9SJaegeuk Kim 258b763f3beSChao Yu clear_page_private_inline(dn.inode_page); 259e18c65b2SHuajun Li f2fs_put_dnode(&dn); 260e18c65b2SHuajun Li return 0; 261e18c65b2SHuajun Li } 2621e1bb4baSJaegeuk Kim 2639627a7b3SChao Yu int f2fs_recover_inline_data(struct inode *inode, struct page *npage) 2641e1bb4baSJaegeuk Kim { 2654081363fSJaegeuk Kim struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 2661e1bb4baSJaegeuk Kim struct f2fs_inode *ri = NULL; 2671e1bb4baSJaegeuk Kim void *src_addr, *dst_addr; 2681e1bb4baSJaegeuk Kim struct page *ipage; 2691e1bb4baSJaegeuk Kim 2701e1bb4baSJaegeuk Kim /* 2711e1bb4baSJaegeuk Kim * The inline_data recovery policy is as follows. 2721e1bb4baSJaegeuk Kim * [prev.] [next] of inline_data flag 2731e1bb4baSJaegeuk Kim * o o -> recover inline_data 2741e1bb4baSJaegeuk Kim * o x -> remove inline_data, and then recover data blocks 2756e5ca4fcSJack Qiu * x o -> remove data blocks, and then recover inline_data 2761e1bb4baSJaegeuk Kim * x x -> recover data blocks 2771e1bb4baSJaegeuk Kim */ 2781e1bb4baSJaegeuk Kim if (IS_INODE(npage)) 2791e1bb4baSJaegeuk Kim ri = F2FS_INODE(npage); 2801e1bb4baSJaegeuk Kim 2811e1bb4baSJaegeuk Kim if (f2fs_has_inline_data(inode) && 2820342fd30SJaegeuk Kim ri && (ri->i_inline & F2FS_INLINE_DATA)) { 2831e1bb4baSJaegeuk Kim process_inline: 2844d57b86dSChao Yu ipage = f2fs_get_node_page(sbi, inode->i_ino); 2859627a7b3SChao Yu if (IS_ERR(ipage)) 2869627a7b3SChao Yu return PTR_ERR(ipage); 2871e1bb4baSJaegeuk Kim 288bae0ee7aSChao Yu f2fs_wait_on_page_writeback(ipage, NODE, true, true); 28954b591dfSJaegeuk Kim 290f2470371SChao Yu src_addr = inline_data_addr(inode, npage); 291f2470371SChao Yu dst_addr = inline_data_addr(inode, ipage); 292f2470371SChao Yu memcpy(dst_addr, src_addr, MAX_INLINE_DATA(inode)); 293b3d208f9SJaegeuk Kim 29491942321SJaegeuk Kim set_inode_flag(inode, FI_INLINE_DATA); 29591942321SJaegeuk Kim set_inode_flag(inode, FI_DATA_EXIST); 296b3d208f9SJaegeuk Kim 297ee6d182fSJaegeuk Kim set_page_dirty(ipage); 2981e1bb4baSJaegeuk Kim f2fs_put_page(ipage, 1); 2999627a7b3SChao Yu return 1; 3001e1bb4baSJaegeuk Kim } 3011e1bb4baSJaegeuk Kim 3021e1bb4baSJaegeuk Kim if (f2fs_has_inline_data(inode)) { 3034d57b86dSChao Yu ipage = f2fs_get_node_page(sbi, inode->i_ino); 3049627a7b3SChao Yu if (IS_ERR(ipage)) 3059627a7b3SChao Yu return PTR_ERR(ipage); 3064d57b86dSChao Yu f2fs_truncate_inline_inode(inode, ipage, 0); 30784921561SJack Qiu stat_dec_inline_inode(inode); 308bd4667cbSKinglong Mee clear_inode_flag(inode, FI_INLINE_DATA); 3091e1bb4baSJaegeuk Kim f2fs_put_page(ipage, 1); 3100342fd30SJaegeuk Kim } else if (ri && (ri->i_inline & F2FS_INLINE_DATA)) { 3119627a7b3SChao Yu int ret; 3129627a7b3SChao Yu 3139627a7b3SChao Yu ret = f2fs_truncate_blocks(inode, 0, false); 3149627a7b3SChao Yu if (ret) 3159627a7b3SChao Yu return ret; 31684921561SJack Qiu stat_inc_inline_inode(inode); 3171e1bb4baSJaegeuk Kim goto process_inline; 3181e1bb4baSJaegeuk Kim } 3199627a7b3SChao Yu return 0; 3201e1bb4baSJaegeuk Kim } 321201a05beSChao Yu 3224d57b86dSChao Yu struct f2fs_dir_entry *f2fs_find_in_inline_dir(struct inode *dir, 32343c780baSEric Biggers const struct f2fs_filename *fname, 32443c780baSEric Biggers struct page **res_page) 325201a05beSChao Yu { 326201a05beSChao Yu struct f2fs_sb_info *sbi = F2FS_SB(dir->i_sb); 327201a05beSChao Yu struct f2fs_dir_entry *de; 3287b3cd7d6SJaegeuk Kim struct f2fs_dentry_ptr d; 3294e6ebf6dSJaegeuk Kim struct page *ipage; 330f2470371SChao Yu void *inline_dentry; 331201a05beSChao Yu 3324d57b86dSChao Yu ipage = f2fs_get_node_page(sbi, dir->i_ino); 33342d96401SJaegeuk Kim if (IS_ERR(ipage)) { 33442d96401SJaegeuk Kim *res_page = ipage; 335201a05beSChao Yu return NULL; 33642d96401SJaegeuk Kim } 337201a05beSChao Yu 338f2470371SChao Yu inline_dentry = inline_data_addr(dir, ipage); 339201a05beSChao Yu 340f2470371SChao Yu make_dentry_ptr_inline(dir, &d, inline_dentry); 34143c780baSEric Biggers de = f2fs_find_target_dentry(&d, fname, NULL); 3424e6ebf6dSJaegeuk Kim unlock_page(ipage); 3437ad08a58SDaniel Rosenberg if (IS_ERR(de)) { 3447ad08a58SDaniel Rosenberg *res_page = ERR_CAST(de); 3457ad08a58SDaniel Rosenberg de = NULL; 3467ad08a58SDaniel Rosenberg } 3474e6ebf6dSJaegeuk Kim if (de) 348201a05beSChao Yu *res_page = ipage; 3494e6ebf6dSJaegeuk Kim else 3504e6ebf6dSJaegeuk Kim f2fs_put_page(ipage, 0); 351201a05beSChao Yu 352201a05beSChao Yu return de; 353201a05beSChao Yu } 354201a05beSChao Yu 3554d57b86dSChao Yu int f2fs_make_empty_inline_dir(struct inode *inode, struct inode *parent, 356201a05beSChao Yu struct page *ipage) 357201a05beSChao Yu { 358062a3e7bSJaegeuk Kim struct f2fs_dentry_ptr d; 359f2470371SChao Yu void *inline_dentry; 360201a05beSChao Yu 361f2470371SChao Yu inline_dentry = inline_data_addr(inode, ipage); 362201a05beSChao Yu 363f2470371SChao Yu make_dentry_ptr_inline(inode, &d, inline_dentry); 3644d57b86dSChao Yu f2fs_do_make_empty_dir(inode, parent, &d); 365201a05beSChao Yu 366201a05beSChao Yu set_page_dirty(ipage); 367201a05beSChao Yu 368201a05beSChao Yu /* update i_size to MAX_INLINE_DATA */ 369f2470371SChao Yu if (i_size_read(inode) < MAX_INLINE_DATA(inode)) 370f2470371SChao Yu f2fs_i_size_write(inode, MAX_INLINE_DATA(inode)); 371201a05beSChao Yu return 0; 372201a05beSChao Yu } 373201a05beSChao Yu 374470f00e9SChao Yu /* 375470f00e9SChao Yu * NOTE: ipage is grabbed by caller, but if any error occurs, we should 376470f00e9SChao Yu * release ipage in this function. 377470f00e9SChao Yu */ 378675f10bdSChao Yu static int f2fs_move_inline_dirents(struct inode *dir, struct page *ipage, 379f2470371SChao Yu void *inline_dentry) 380201a05beSChao Yu { 381201a05beSChao Yu struct page *page; 382201a05beSChao Yu struct dnode_of_data dn; 383201a05beSChao Yu struct f2fs_dentry_block *dentry_blk; 38476a9dd85SChao Yu struct f2fs_dentry_ptr src, dst; 385201a05beSChao Yu int err; 386201a05beSChao Yu 387dd973007SJaegeuk Kim page = f2fs_grab_cache_page(dir->i_mapping, 0, true); 388470f00e9SChao Yu if (!page) { 389470f00e9SChao Yu f2fs_put_page(ipage, 1); 390201a05beSChao Yu return -ENOMEM; 391470f00e9SChao Yu } 392201a05beSChao Yu 393201a05beSChao Yu set_new_dnode(&dn, dir, ipage, NULL, 0); 394201a05beSChao Yu err = f2fs_reserve_block(&dn, 0); 395201a05beSChao Yu if (err) 396201a05beSChao Yu goto out; 397201a05beSChao Yu 3984dbe38dcSChao Yu if (unlikely(dn.data_blkaddr != NEW_ADDR)) { 3994dbe38dcSChao Yu f2fs_put_dnode(&dn); 4004dbe38dcSChao Yu set_sbi_flag(F2FS_P_SB(page), SBI_NEED_FSCK); 401dcbb4c10SJoe Perches f2fs_warn(F2FS_P_SB(page), "%s: corrupted inline inode ino=%lx, i_addr[0]:0x%x, run fsck to fix.", 4024dbe38dcSChao Yu __func__, dir->i_ino, dn.data_blkaddr); 40310f966bbSChao Yu err = -EFSCORRUPTED; 4044dbe38dcSChao Yu goto out; 4054dbe38dcSChao Yu } 4064dbe38dcSChao Yu 407bae0ee7aSChao Yu f2fs_wait_on_page_writeback(page, DATA, true, true); 408201a05beSChao Yu 409bdbc90faSYunlong Song dentry_blk = page_address(page); 410201a05beSChao Yu 411f2470371SChao Yu make_dentry_ptr_inline(dir, &src, inline_dentry); 412f2470371SChao Yu make_dentry_ptr_block(dir, &dst, dentry_blk); 41376a9dd85SChao Yu 414201a05beSChao Yu /* copy data from inline dentry block to new dentry block */ 41576a9dd85SChao Yu memcpy(dst.bitmap, src.bitmap, src.nr_bitmap); 41676a9dd85SChao Yu memset(dst.bitmap + src.nr_bitmap, 0, dst.nr_bitmap - src.nr_bitmap); 4174ec17d68SChao Yu /* 4184ec17d68SChao Yu * we do not need to zero out remainder part of dentry and filename 4194ec17d68SChao Yu * field, since we have used bitmap for marking the usage status of 4204ec17d68SChao Yu * them, besides, we can also ignore copying/zeroing reserved space 4214ec17d68SChao Yu * of dentry block, because them haven't been used so far. 4224ec17d68SChao Yu */ 42376a9dd85SChao Yu memcpy(dst.dentry, src.dentry, SIZE_OF_DIR_ENTRY * src.max); 42476a9dd85SChao Yu memcpy(dst.filename, src.filename, src.max * F2FS_SLOT_LEN); 425201a05beSChao Yu 426237c0790SJaegeuk Kim if (!PageUptodate(page)) 427201a05beSChao Yu SetPageUptodate(page); 428201a05beSChao Yu set_page_dirty(page); 429201a05beSChao Yu 430201a05beSChao Yu /* clear inline dir and flag after data writeback */ 4314d57b86dSChao Yu f2fs_truncate_inline_inode(dir, ipage, 0); 432b3d208f9SJaegeuk Kim 4333289c061SJaegeuk Kim stat_dec_inline_dir(dir); 43491942321SJaegeuk Kim clear_inode_flag(dir, FI_INLINE_DENTRY); 435201a05beSChao Yu 43645a74688SChao Yu /* 43745a74688SChao Yu * should retrieve reserved space which was used to keep 43845a74688SChao Yu * inline_dentry's structure for backward compatibility. 43945a74688SChao Yu */ 44045a74688SChao Yu if (!f2fs_sb_has_flexible_inline_xattr(F2FS_I_SB(dir)) && 44145a74688SChao Yu !f2fs_has_inline_xattr(dir)) 44245a74688SChao Yu F2FS_I(dir)->i_inline_xattr_size = 0; 44345a74688SChao Yu 444205b9822SJaegeuk Kim f2fs_i_depth_write(dir, 1); 445ee6d182fSJaegeuk Kim if (i_size_read(dir) < PAGE_SIZE) 446fc9581c8SJaegeuk Kim f2fs_i_size_write(dir, PAGE_SIZE); 447201a05beSChao Yu out: 448201a05beSChao Yu f2fs_put_page(page, 1); 449201a05beSChao Yu return err; 450201a05beSChao Yu } 451201a05beSChao Yu 452f2470371SChao Yu static int f2fs_add_inline_entries(struct inode *dir, void *inline_dentry) 453675f10bdSChao Yu { 454675f10bdSChao Yu struct f2fs_dentry_ptr d; 455675f10bdSChao Yu unsigned long bit_pos = 0; 456675f10bdSChao Yu int err = 0; 457675f10bdSChao Yu 458f2470371SChao Yu make_dentry_ptr_inline(dir, &d, inline_dentry); 459675f10bdSChao Yu 460675f10bdSChao Yu while (bit_pos < d.max) { 461675f10bdSChao Yu struct f2fs_dir_entry *de; 46243c780baSEric Biggers struct f2fs_filename fname; 463675f10bdSChao Yu nid_t ino; 464675f10bdSChao Yu umode_t fake_mode; 465675f10bdSChao Yu 466675f10bdSChao Yu if (!test_bit_le(bit_pos, d.bitmap)) { 467675f10bdSChao Yu bit_pos++; 468675f10bdSChao Yu continue; 469675f10bdSChao Yu } 470675f10bdSChao Yu 471675f10bdSChao Yu de = &d.dentry[bit_pos]; 472a4a13f58SChao Yu 473a4a13f58SChao Yu if (unlikely(!de->name_len)) { 474a4a13f58SChao Yu bit_pos++; 475a4a13f58SChao Yu continue; 476a4a13f58SChao Yu } 477a4a13f58SChao Yu 47843c780baSEric Biggers /* 47943c780baSEric Biggers * We only need the disk_name and hash to move the dentry. 48043c780baSEric Biggers * We don't need the original or casefolded filenames. 48143c780baSEric Biggers */ 48243c780baSEric Biggers memset(&fname, 0, sizeof(fname)); 48343c780baSEric Biggers fname.disk_name.name = d.filename[bit_pos]; 48443c780baSEric Biggers fname.disk_name.len = le16_to_cpu(de->name_len); 48543c780baSEric Biggers fname.hash = de->hash_code; 486675f10bdSChao Yu 487675f10bdSChao Yu ino = le32_to_cpu(de->ino); 4884d57b86dSChao Yu fake_mode = f2fs_get_de_type(de) << S_SHIFT; 489675f10bdSChao Yu 49043c780baSEric Biggers err = f2fs_add_regular_entry(dir, &fname, NULL, ino, fake_mode); 491675f10bdSChao Yu if (err) 492675f10bdSChao Yu goto punch_dentry_pages; 493675f10bdSChao Yu 494675f10bdSChao Yu bit_pos += GET_DENTRY_SLOTS(le16_to_cpu(de->name_len)); 495675f10bdSChao Yu } 496675f10bdSChao Yu return 0; 497675f10bdSChao Yu punch_dentry_pages: 498675f10bdSChao Yu truncate_inode_pages(&dir->i_data, 0); 499c42d28ceSChao Yu f2fs_truncate_blocks(dir, 0, false); 5004d57b86dSChao Yu f2fs_remove_dirty_inode(dir); 501675f10bdSChao Yu return err; 502675f10bdSChao Yu } 503675f10bdSChao Yu 504675f10bdSChao Yu static int f2fs_move_rehashed_dirents(struct inode *dir, struct page *ipage, 505f2470371SChao Yu void *inline_dentry) 506675f10bdSChao Yu { 507f2470371SChao Yu void *backup_dentry; 508675f10bdSChao Yu int err; 509675f10bdSChao Yu 5101ecc0c5cSChao Yu backup_dentry = f2fs_kmalloc(F2FS_I_SB(dir), 511f2470371SChao Yu MAX_INLINE_DATA(dir), GFP_F2FS_ZERO); 5128975bdf4SChao Yu if (!backup_dentry) { 5138975bdf4SChao Yu f2fs_put_page(ipage, 1); 514675f10bdSChao Yu return -ENOMEM; 5158975bdf4SChao Yu } 516675f10bdSChao Yu 517f2470371SChao Yu memcpy(backup_dentry, inline_dentry, MAX_INLINE_DATA(dir)); 5184d57b86dSChao Yu f2fs_truncate_inline_inode(dir, ipage, 0); 519675f10bdSChao Yu 520675f10bdSChao Yu unlock_page(ipage); 521675f10bdSChao Yu 522675f10bdSChao Yu err = f2fs_add_inline_entries(dir, backup_dentry); 523675f10bdSChao Yu if (err) 524675f10bdSChao Yu goto recover; 525675f10bdSChao Yu 526675f10bdSChao Yu lock_page(ipage); 527675f10bdSChao Yu 528675f10bdSChao Yu stat_dec_inline_dir(dir); 52991942321SJaegeuk Kim clear_inode_flag(dir, FI_INLINE_DENTRY); 53045a74688SChao Yu 53145a74688SChao Yu /* 53245a74688SChao Yu * should retrieve reserved space which was used to keep 53345a74688SChao Yu * inline_dentry's structure for backward compatibility. 53445a74688SChao Yu */ 53545a74688SChao Yu if (!f2fs_sb_has_flexible_inline_xattr(F2FS_I_SB(dir)) && 53645a74688SChao Yu !f2fs_has_inline_xattr(dir)) 53745a74688SChao Yu F2FS_I(dir)->i_inline_xattr_size = 0; 53845a74688SChao Yu 539c8eb7024SChao Yu kfree(backup_dentry); 540675f10bdSChao Yu return 0; 541675f10bdSChao Yu recover: 542675f10bdSChao Yu lock_page(ipage); 543bae0ee7aSChao Yu f2fs_wait_on_page_writeback(ipage, NODE, true, true); 544f2470371SChao Yu memcpy(inline_dentry, backup_dentry, MAX_INLINE_DATA(dir)); 545205b9822SJaegeuk Kim f2fs_i_depth_write(dir, 0); 546f2470371SChao Yu f2fs_i_size_write(dir, MAX_INLINE_DATA(dir)); 547ee6d182fSJaegeuk Kim set_page_dirty(ipage); 548675f10bdSChao Yu f2fs_put_page(ipage, 1); 549675f10bdSChao Yu 550c8eb7024SChao Yu kfree(backup_dentry); 551675f10bdSChao Yu return err; 552675f10bdSChao Yu } 553675f10bdSChao Yu 554b06af2afSJaegeuk Kim static int do_convert_inline_dir(struct inode *dir, struct page *ipage, 555f2470371SChao Yu void *inline_dentry) 556675f10bdSChao Yu { 557675f10bdSChao Yu if (!F2FS_I(dir)->i_dir_level) 558675f10bdSChao Yu return f2fs_move_inline_dirents(dir, ipage, inline_dentry); 559675f10bdSChao Yu else 560675f10bdSChao Yu return f2fs_move_rehashed_dirents(dir, ipage, inline_dentry); 561675f10bdSChao Yu } 562675f10bdSChao Yu 563b06af2afSJaegeuk Kim int f2fs_try_convert_inline_dir(struct inode *dir, struct dentry *dentry) 564b06af2afSJaegeuk Kim { 565b06af2afSJaegeuk Kim struct f2fs_sb_info *sbi = F2FS_I_SB(dir); 566b06af2afSJaegeuk Kim struct page *ipage; 56743c780baSEric Biggers struct f2fs_filename fname; 568b06af2afSJaegeuk Kim void *inline_dentry = NULL; 569b06af2afSJaegeuk Kim int err = 0; 570b06af2afSJaegeuk Kim 571b06af2afSJaegeuk Kim if (!f2fs_has_inline_dentry(dir)) 572b06af2afSJaegeuk Kim return 0; 573b06af2afSJaegeuk Kim 574b06af2afSJaegeuk Kim f2fs_lock_op(sbi); 575b06af2afSJaegeuk Kim 57643c780baSEric Biggers err = f2fs_setup_filename(dir, &dentry->d_name, 0, &fname); 577b06af2afSJaegeuk Kim if (err) 578b06af2afSJaegeuk Kim goto out; 579b06af2afSJaegeuk Kim 580b06af2afSJaegeuk Kim ipage = f2fs_get_node_page(sbi, dir->i_ino); 581b06af2afSJaegeuk Kim if (IS_ERR(ipage)) { 582b06af2afSJaegeuk Kim err = PTR_ERR(ipage); 583ff5f85c8SEric Biggers goto out_fname; 584b06af2afSJaegeuk Kim } 585b06af2afSJaegeuk Kim 586b06af2afSJaegeuk Kim if (f2fs_has_enough_room(dir, ipage, &fname)) { 587b06af2afSJaegeuk Kim f2fs_put_page(ipage, 1); 588ff5f85c8SEric Biggers goto out_fname; 589b06af2afSJaegeuk Kim } 590b06af2afSJaegeuk Kim 591b06af2afSJaegeuk Kim inline_dentry = inline_data_addr(dir, ipage); 592b06af2afSJaegeuk Kim 593b06af2afSJaegeuk Kim err = do_convert_inline_dir(dir, ipage, inline_dentry); 594b06af2afSJaegeuk Kim if (!err) 595b06af2afSJaegeuk Kim f2fs_put_page(ipage, 1); 596ff5f85c8SEric Biggers out_fname: 59743c780baSEric Biggers f2fs_free_filename(&fname); 598b06af2afSJaegeuk Kim out: 599b06af2afSJaegeuk Kim f2fs_unlock_op(sbi); 600b06af2afSJaegeuk Kim return err; 601b06af2afSJaegeuk Kim } 602b06af2afSJaegeuk Kim 60343c780baSEric Biggers int f2fs_add_inline_entry(struct inode *dir, const struct f2fs_filename *fname, 604510022a8SJaegeuk Kim struct inode *inode, nid_t ino, umode_t mode) 605201a05beSChao Yu { 606201a05beSChao Yu struct f2fs_sb_info *sbi = F2FS_I_SB(dir); 607201a05beSChao Yu struct page *ipage; 608201a05beSChao Yu unsigned int bit_pos; 609f2470371SChao Yu void *inline_dentry = NULL; 6103b4d732aSChao Yu struct f2fs_dentry_ptr d; 61143c780baSEric Biggers int slots = GET_DENTRY_SLOTS(fname->disk_name.len); 612510022a8SJaegeuk Kim struct page *page = NULL; 613201a05beSChao Yu int err = 0; 614201a05beSChao Yu 6154d57b86dSChao Yu ipage = f2fs_get_node_page(sbi, dir->i_ino); 616201a05beSChao Yu if (IS_ERR(ipage)) 617201a05beSChao Yu return PTR_ERR(ipage); 618201a05beSChao Yu 619f2470371SChao Yu inline_dentry = inline_data_addr(dir, ipage); 620f2470371SChao Yu make_dentry_ptr_inline(dir, &d, inline_dentry); 62176a9dd85SChao Yu 6224d57b86dSChao Yu bit_pos = f2fs_room_for_filename(d.bitmap, slots, d.max); 62376a9dd85SChao Yu if (bit_pos >= d.max) { 624b06af2afSJaegeuk Kim err = do_convert_inline_dir(dir, ipage, inline_dentry); 625470f00e9SChao Yu if (err) 626470f00e9SChao Yu return err; 627201a05beSChao Yu err = -EAGAIN; 628201a05beSChao Yu goto out; 629201a05beSChao Yu } 630201a05beSChao Yu 631510022a8SJaegeuk Kim if (inode) { 632*e4544b63STim Murray f2fs_down_write(&F2FS_I(inode)->i_sem); 63343c780baSEric Biggers page = f2fs_init_inode_metadata(inode, dir, fname, ipage); 634201a05beSChao Yu if (IS_ERR(page)) { 635201a05beSChao Yu err = PTR_ERR(page); 636201a05beSChao Yu goto fail; 637201a05beSChao Yu } 638510022a8SJaegeuk Kim } 639bce8d112SJaegeuk Kim 640bae0ee7aSChao Yu f2fs_wait_on_page_writeback(ipage, NODE, true, true); 6413b4d732aSChao Yu 64243c780baSEric Biggers f2fs_update_dentry(ino, mode, &d, &fname->disk_name, fname->hash, 64343c780baSEric Biggers bit_pos); 6443b4d732aSChao Yu 645201a05beSChao Yu set_page_dirty(ipage); 646201a05beSChao Yu 647201a05beSChao Yu /* we don't need to mark_inode_dirty now */ 648510022a8SJaegeuk Kim if (inode) { 649205b9822SJaegeuk Kim f2fs_i_pino_write(inode, dir->i_ino); 65098194030SChao Yu 65198194030SChao Yu /* synchronize inode page's data from inode cache */ 65298194030SChao Yu if (is_inode_flag_set(inode, FI_NEW_INODE)) 65398194030SChao Yu f2fs_update_inode(inode, page); 65498194030SChao Yu 655201a05beSChao Yu f2fs_put_page(page, 1); 656510022a8SJaegeuk Kim } 657201a05beSChao Yu 6584d57b86dSChao Yu f2fs_update_parent_metadata(dir, inode, 0); 659201a05beSChao Yu fail: 660510022a8SJaegeuk Kim if (inode) 661*e4544b63STim Murray f2fs_up_write(&F2FS_I(inode)->i_sem); 662201a05beSChao Yu out: 663201a05beSChao Yu f2fs_put_page(ipage, 1); 664201a05beSChao Yu return err; 665201a05beSChao Yu } 666201a05beSChao Yu 667201a05beSChao Yu void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry, struct page *page, 668201a05beSChao Yu struct inode *dir, struct inode *inode) 669201a05beSChao Yu { 67076a9dd85SChao Yu struct f2fs_dentry_ptr d; 671f2470371SChao Yu void *inline_dentry; 672201a05beSChao Yu int slots = GET_DENTRY_SLOTS(le16_to_cpu(dentry->name_len)); 673201a05beSChao Yu unsigned int bit_pos; 674201a05beSChao Yu int i; 675201a05beSChao Yu 676201a05beSChao Yu lock_page(page); 677bae0ee7aSChao Yu f2fs_wait_on_page_writeback(page, NODE, true, true); 678201a05beSChao Yu 679f2470371SChao Yu inline_dentry = inline_data_addr(dir, page); 680f2470371SChao Yu make_dentry_ptr_inline(dir, &d, inline_dentry); 68176a9dd85SChao Yu 68276a9dd85SChao Yu bit_pos = dentry - d.dentry; 683201a05beSChao Yu for (i = 0; i < slots; i++) 68476a9dd85SChao Yu __clear_bit_le(bit_pos + i, d.bitmap); 685201a05beSChao Yu 686201a05beSChao Yu set_page_dirty(page); 6879f7c45ccSJaegeuk Kim f2fs_put_page(page, 1); 688201a05beSChao Yu 689078cd827SDeepa Dinamani dir->i_ctime = dir->i_mtime = current_time(dir); 6907c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(dir, false); 691201a05beSChao Yu 692201a05beSChao Yu if (inode) 6939f7c45ccSJaegeuk Kim f2fs_drop_nlink(dir, inode); 694201a05beSChao Yu } 695201a05beSChao Yu 696201a05beSChao Yu bool f2fs_empty_inline_dir(struct inode *dir) 697201a05beSChao Yu { 698201a05beSChao Yu struct f2fs_sb_info *sbi = F2FS_I_SB(dir); 699201a05beSChao Yu struct page *ipage; 700201a05beSChao Yu unsigned int bit_pos = 2; 701f2470371SChao Yu void *inline_dentry; 70276a9dd85SChao Yu struct f2fs_dentry_ptr d; 703201a05beSChao Yu 7044d57b86dSChao Yu ipage = f2fs_get_node_page(sbi, dir->i_ino); 705201a05beSChao Yu if (IS_ERR(ipage)) 706201a05beSChao Yu return false; 707201a05beSChao Yu 708f2470371SChao Yu inline_dentry = inline_data_addr(dir, ipage); 709f2470371SChao Yu make_dentry_ptr_inline(dir, &d, inline_dentry); 71076a9dd85SChao Yu 71176a9dd85SChao Yu bit_pos = find_next_bit_le(d.bitmap, d.max, bit_pos); 712201a05beSChao Yu 713201a05beSChao Yu f2fs_put_page(ipage, 1); 714201a05beSChao Yu 71576a9dd85SChao Yu if (bit_pos < d.max) 716201a05beSChao Yu return false; 717201a05beSChao Yu 718201a05beSChao Yu return true; 719201a05beSChao Yu } 720201a05beSChao Yu 721d8c6822aSJaegeuk Kim int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx, 7220b81d077SJaegeuk Kim struct fscrypt_str *fstr) 723201a05beSChao Yu { 724201a05beSChao Yu struct inode *inode = file_inode(file); 725201a05beSChao Yu struct page *ipage = NULL; 7267b3cd7d6SJaegeuk Kim struct f2fs_dentry_ptr d; 727f2470371SChao Yu void *inline_dentry = NULL; 728ed6bd4b1SChao Yu int err; 729201a05beSChao Yu 73076a9dd85SChao Yu make_dentry_ptr_inline(inode, &d, inline_dentry); 73176a9dd85SChao Yu 73276a9dd85SChao Yu if (ctx->pos == d.max) 733201a05beSChao Yu return 0; 734201a05beSChao Yu 7354d57b86dSChao Yu ipage = f2fs_get_node_page(F2FS_I_SB(inode), inode->i_ino); 736201a05beSChao Yu if (IS_ERR(ipage)) 737201a05beSChao Yu return PTR_ERR(ipage); 738201a05beSChao Yu 739aadcef64SChao Yu /* 740aadcef64SChao Yu * f2fs_readdir was protected by inode.i_rwsem, it is safe to access 741aadcef64SChao Yu * ipage without page's lock held. 742aadcef64SChao Yu */ 743aadcef64SChao Yu unlock_page(ipage); 744aadcef64SChao Yu 745f2470371SChao Yu inline_dentry = inline_data_addr(inode, ipage); 746201a05beSChao Yu 74764c24ecbSTomohiro Kusumi make_dentry_ptr_inline(inode, &d, inline_dentry); 7487b3cd7d6SJaegeuk Kim 749ed6bd4b1SChao Yu err = f2fs_fill_dentries(ctx, &d, 0, fstr); 750ed6bd4b1SChao Yu if (!err) 75176a9dd85SChao Yu ctx->pos = d.max; 752201a05beSChao Yu 753aadcef64SChao Yu f2fs_put_page(ipage, 0); 754ed6bd4b1SChao Yu return err < 0 ? err : 0; 755201a05beSChao Yu } 75667f8cf3cSJaegeuk Kim 75767f8cf3cSJaegeuk Kim int f2fs_inline_data_fiemap(struct inode *inode, 75867f8cf3cSJaegeuk Kim struct fiemap_extent_info *fieinfo, __u64 start, __u64 len) 75967f8cf3cSJaegeuk Kim { 76067f8cf3cSJaegeuk Kim __u64 byteaddr, ilen; 76167f8cf3cSJaegeuk Kim __u32 flags = FIEMAP_EXTENT_DATA_INLINE | FIEMAP_EXTENT_NOT_ALIGNED | 76267f8cf3cSJaegeuk Kim FIEMAP_EXTENT_LAST; 76367f8cf3cSJaegeuk Kim struct node_info ni; 76467f8cf3cSJaegeuk Kim struct page *ipage; 76567f8cf3cSJaegeuk Kim int err = 0; 76667f8cf3cSJaegeuk Kim 7674d57b86dSChao Yu ipage = f2fs_get_node_page(F2FS_I_SB(inode), inode->i_ino); 76867f8cf3cSJaegeuk Kim if (IS_ERR(ipage)) 76967f8cf3cSJaegeuk Kim return PTR_ERR(ipage); 77067f8cf3cSJaegeuk Kim 7717975f349SChao Yu if ((S_ISREG(inode->i_mode) || S_ISLNK(inode->i_mode)) && 7727975f349SChao Yu !f2fs_has_inline_data(inode)) { 7737975f349SChao Yu err = -EAGAIN; 7747975f349SChao Yu goto out; 7757975f349SChao Yu } 7767975f349SChao Yu 7777975f349SChao Yu if (S_ISDIR(inode->i_mode) && !f2fs_has_inline_dentry(inode)) { 77867f8cf3cSJaegeuk Kim err = -EAGAIN; 77967f8cf3cSJaegeuk Kim goto out; 78067f8cf3cSJaegeuk Kim } 78167f8cf3cSJaegeuk Kim 782f2470371SChao Yu ilen = min_t(size_t, MAX_INLINE_DATA(inode), i_size_read(inode)); 78367f8cf3cSJaegeuk Kim if (start >= ilen) 78467f8cf3cSJaegeuk Kim goto out; 78567f8cf3cSJaegeuk Kim if (start + len < ilen) 78667f8cf3cSJaegeuk Kim ilen = start + len; 78767f8cf3cSJaegeuk Kim ilen -= start; 78867f8cf3cSJaegeuk Kim 789a9419b63SJaegeuk Kim err = f2fs_get_node_info(F2FS_I_SB(inode), inode->i_ino, &ni, false); 7907735730dSChao Yu if (err) 7917735730dSChao Yu goto out; 7927735730dSChao Yu 79367f8cf3cSJaegeuk Kim byteaddr = (__u64)ni.blk_addr << inode->i_sb->s_blocksize_bits; 794f2470371SChao Yu byteaddr += (char *)inline_data_addr(inode, ipage) - 795f2470371SChao Yu (char *)F2FS_INODE(ipage); 79667f8cf3cSJaegeuk Kim err = fiemap_fill_next_extent(fieinfo, start, byteaddr, ilen, flags); 797dd5a09bdSChao Yu trace_f2fs_fiemap(inode, start, byteaddr, ilen, flags, err); 79867f8cf3cSJaegeuk Kim out: 79967f8cf3cSJaegeuk Kim f2fs_put_page(ipage, 1); 80067f8cf3cSJaegeuk Kim return err; 80167f8cf3cSJaegeuk Kim } 802