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 1347735730dSChao Yu err = f2fs_get_node_info(fio.sbi, dn->nid, &ni); 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); 1762049d4fcSJaegeuk Kim clear_inline_node(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 195300e129cSJaegeuk Kim page = f2fs_grab_cache_page(inode->i_mapping, 0, false); 196b3d208f9SJaegeuk Kim if (!page) 1979e09fc85SJaegeuk Kim return -ENOMEM; 198b3d208f9SJaegeuk Kim 199b3d208f9SJaegeuk Kim f2fs_lock_op(sbi); 200b3d208f9SJaegeuk Kim 2014d57b86dSChao Yu ipage = f2fs_get_node_page(sbi, inode->i_ino); 202b3d208f9SJaegeuk Kim if (IS_ERR(ipage)) { 2036d20aff8SJaegeuk Kim err = PTR_ERR(ipage); 2046d20aff8SJaegeuk Kim goto out; 205b067ba1fSJaegeuk Kim } 206e18c65b2SHuajun Li 207b3d208f9SJaegeuk Kim set_new_dnode(&dn, inode, ipage, ipage, 0); 208b3d208f9SJaegeuk Kim 209b3d208f9SJaegeuk Kim if (f2fs_has_inline_data(inode)) 210b3d208f9SJaegeuk Kim err = f2fs_convert_inline_page(&dn, page); 211b3d208f9SJaegeuk Kim 212b3d208f9SJaegeuk Kim f2fs_put_dnode(&dn); 2136d20aff8SJaegeuk Kim out: 214b3d208f9SJaegeuk Kim f2fs_unlock_op(sbi); 215b3d208f9SJaegeuk Kim 216b3d208f9SJaegeuk Kim f2fs_put_page(page, 1); 2172a340760SJaegeuk Kim 2182c4db1a6SJaegeuk Kim f2fs_balance_fs(sbi, dn.node_changed); 2192a340760SJaegeuk Kim 220e18c65b2SHuajun Li return err; 221e18c65b2SHuajun Li } 222e18c65b2SHuajun Li 223b3d208f9SJaegeuk Kim int f2fs_write_inline_data(struct inode *inode, struct page *page) 224e18c65b2SHuajun Li { 225e18c65b2SHuajun Li void *src_addr, *dst_addr; 226e18c65b2SHuajun Li struct dnode_of_data dn; 227e18c65b2SHuajun Li int err; 228e18c65b2SHuajun Li 229e18c65b2SHuajun Li set_new_dnode(&dn, inode, NULL, NULL, 0); 2304d57b86dSChao Yu err = f2fs_get_dnode_of_data(&dn, 0, LOOKUP_NODE); 231e18c65b2SHuajun Li if (err) 232e18c65b2SHuajun Li return err; 233e18c65b2SHuajun Li 234c08a690bSJaegeuk Kim if (!f2fs_has_inline_data(inode)) { 235b3d208f9SJaegeuk Kim f2fs_put_dnode(&dn); 236b3d208f9SJaegeuk Kim return -EAGAIN; 237c08a690bSJaegeuk Kim } 238c08a690bSJaegeuk Kim 239b3d208f9SJaegeuk Kim f2fs_bug_on(F2FS_I_SB(inode), page->index); 240b3d208f9SJaegeuk Kim 241bae0ee7aSChao Yu f2fs_wait_on_page_writeback(dn.inode_page, NODE, true, true); 242f1e33a04SJaegeuk Kim src_addr = kmap_atomic(page); 243f2470371SChao Yu dst_addr = inline_data_addr(inode, dn.inode_page); 244f2470371SChao Yu memcpy(dst_addr, src_addr, MAX_INLINE_DATA(inode)); 245f1e33a04SJaegeuk Kim kunmap_atomic(src_addr); 246ee6d182fSJaegeuk Kim set_page_dirty(dn.inode_page); 247e18c65b2SHuajun Li 2485ec2d99dSMatthew Wilcox f2fs_clear_page_cache_dirty_tag(page); 2490abd8e70SDaeho Jeong 25091942321SJaegeuk Kim set_inode_flag(inode, FI_APPEND_WRITE); 25191942321SJaegeuk Kim set_inode_flag(inode, FI_DATA_EXIST); 252b3d208f9SJaegeuk Kim 2532049d4fcSJaegeuk Kim clear_inline_node(dn.inode_page); 254e18c65b2SHuajun Li f2fs_put_dnode(&dn); 255e18c65b2SHuajun Li return 0; 256e18c65b2SHuajun Li } 2571e1bb4baSJaegeuk Kim 2589627a7b3SChao Yu int f2fs_recover_inline_data(struct inode *inode, struct page *npage) 2591e1bb4baSJaegeuk Kim { 2604081363fSJaegeuk Kim struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 2611e1bb4baSJaegeuk Kim struct f2fs_inode *ri = NULL; 2621e1bb4baSJaegeuk Kim void *src_addr, *dst_addr; 2631e1bb4baSJaegeuk Kim struct page *ipage; 2641e1bb4baSJaegeuk Kim 2651e1bb4baSJaegeuk Kim /* 2661e1bb4baSJaegeuk Kim * The inline_data recovery policy is as follows. 2671e1bb4baSJaegeuk Kim * [prev.] [next] of inline_data flag 2681e1bb4baSJaegeuk Kim * o o -> recover inline_data 2691e1bb4baSJaegeuk Kim * o x -> remove inline_data, and then recover data blocks 270*6e5ca4fcSJack Qiu * x o -> remove data blocks, and then recover inline_data 2711e1bb4baSJaegeuk Kim * x x -> recover data blocks 2721e1bb4baSJaegeuk Kim */ 2731e1bb4baSJaegeuk Kim if (IS_INODE(npage)) 2741e1bb4baSJaegeuk Kim ri = F2FS_INODE(npage); 2751e1bb4baSJaegeuk Kim 2761e1bb4baSJaegeuk Kim if (f2fs_has_inline_data(inode) && 2770342fd30SJaegeuk Kim ri && (ri->i_inline & F2FS_INLINE_DATA)) { 2781e1bb4baSJaegeuk Kim process_inline: 2794d57b86dSChao Yu ipage = f2fs_get_node_page(sbi, inode->i_ino); 2809627a7b3SChao Yu if (IS_ERR(ipage)) 2819627a7b3SChao Yu return PTR_ERR(ipage); 2821e1bb4baSJaegeuk Kim 283bae0ee7aSChao Yu f2fs_wait_on_page_writeback(ipage, NODE, true, true); 28454b591dfSJaegeuk Kim 285f2470371SChao Yu src_addr = inline_data_addr(inode, npage); 286f2470371SChao Yu dst_addr = inline_data_addr(inode, ipage); 287f2470371SChao Yu memcpy(dst_addr, src_addr, MAX_INLINE_DATA(inode)); 288b3d208f9SJaegeuk Kim 28991942321SJaegeuk Kim set_inode_flag(inode, FI_INLINE_DATA); 29091942321SJaegeuk Kim set_inode_flag(inode, FI_DATA_EXIST); 291b3d208f9SJaegeuk Kim 292ee6d182fSJaegeuk Kim set_page_dirty(ipage); 2931e1bb4baSJaegeuk Kim f2fs_put_page(ipage, 1); 2949627a7b3SChao Yu return 1; 2951e1bb4baSJaegeuk Kim } 2961e1bb4baSJaegeuk Kim 2971e1bb4baSJaegeuk Kim if (f2fs_has_inline_data(inode)) { 2984d57b86dSChao Yu ipage = f2fs_get_node_page(sbi, inode->i_ino); 2999627a7b3SChao Yu if (IS_ERR(ipage)) 3009627a7b3SChao Yu return PTR_ERR(ipage); 3014d57b86dSChao Yu f2fs_truncate_inline_inode(inode, ipage, 0); 302bd4667cbSKinglong Mee clear_inode_flag(inode, FI_INLINE_DATA); 3031e1bb4baSJaegeuk Kim f2fs_put_page(ipage, 1); 3040342fd30SJaegeuk Kim } else if (ri && (ri->i_inline & F2FS_INLINE_DATA)) { 3059627a7b3SChao Yu int ret; 3069627a7b3SChao Yu 3079627a7b3SChao Yu ret = f2fs_truncate_blocks(inode, 0, false); 3089627a7b3SChao Yu if (ret) 3099627a7b3SChao Yu return ret; 3101e1bb4baSJaegeuk Kim goto process_inline; 3111e1bb4baSJaegeuk Kim } 3129627a7b3SChao Yu return 0; 3131e1bb4baSJaegeuk Kim } 314201a05beSChao Yu 3154d57b86dSChao Yu struct f2fs_dir_entry *f2fs_find_in_inline_dir(struct inode *dir, 31643c780baSEric Biggers const struct f2fs_filename *fname, 31743c780baSEric Biggers struct page **res_page) 318201a05beSChao Yu { 319201a05beSChao Yu struct f2fs_sb_info *sbi = F2FS_SB(dir->i_sb); 320201a05beSChao Yu struct f2fs_dir_entry *de; 3217b3cd7d6SJaegeuk Kim struct f2fs_dentry_ptr d; 3224e6ebf6dSJaegeuk Kim struct page *ipage; 323f2470371SChao Yu void *inline_dentry; 324201a05beSChao Yu 3254d57b86dSChao Yu ipage = f2fs_get_node_page(sbi, dir->i_ino); 32642d96401SJaegeuk Kim if (IS_ERR(ipage)) { 32742d96401SJaegeuk Kim *res_page = ipage; 328201a05beSChao Yu return NULL; 32942d96401SJaegeuk Kim } 330201a05beSChao Yu 331f2470371SChao Yu inline_dentry = inline_data_addr(dir, ipage); 332201a05beSChao Yu 333f2470371SChao Yu make_dentry_ptr_inline(dir, &d, inline_dentry); 33443c780baSEric Biggers de = f2fs_find_target_dentry(&d, fname, NULL); 3354e6ebf6dSJaegeuk Kim unlock_page(ipage); 3367ad08a58SDaniel Rosenberg if (IS_ERR(de)) { 3377ad08a58SDaniel Rosenberg *res_page = ERR_CAST(de); 3387ad08a58SDaniel Rosenberg de = NULL; 3397ad08a58SDaniel Rosenberg } 3404e6ebf6dSJaegeuk Kim if (de) 341201a05beSChao Yu *res_page = ipage; 3424e6ebf6dSJaegeuk Kim else 3434e6ebf6dSJaegeuk Kim f2fs_put_page(ipage, 0); 344201a05beSChao Yu 345201a05beSChao Yu return de; 346201a05beSChao Yu } 347201a05beSChao Yu 3484d57b86dSChao Yu int f2fs_make_empty_inline_dir(struct inode *inode, struct inode *parent, 349201a05beSChao Yu struct page *ipage) 350201a05beSChao Yu { 351062a3e7bSJaegeuk Kim struct f2fs_dentry_ptr d; 352f2470371SChao Yu void *inline_dentry; 353201a05beSChao Yu 354f2470371SChao Yu inline_dentry = inline_data_addr(inode, ipage); 355201a05beSChao Yu 356f2470371SChao Yu make_dentry_ptr_inline(inode, &d, inline_dentry); 3574d57b86dSChao Yu f2fs_do_make_empty_dir(inode, parent, &d); 358201a05beSChao Yu 359201a05beSChao Yu set_page_dirty(ipage); 360201a05beSChao Yu 361201a05beSChao Yu /* update i_size to MAX_INLINE_DATA */ 362f2470371SChao Yu if (i_size_read(inode) < MAX_INLINE_DATA(inode)) 363f2470371SChao Yu f2fs_i_size_write(inode, MAX_INLINE_DATA(inode)); 364201a05beSChao Yu return 0; 365201a05beSChao Yu } 366201a05beSChao Yu 367470f00e9SChao Yu /* 368470f00e9SChao Yu * NOTE: ipage is grabbed by caller, but if any error occurs, we should 369470f00e9SChao Yu * release ipage in this function. 370470f00e9SChao Yu */ 371675f10bdSChao Yu static int f2fs_move_inline_dirents(struct inode *dir, struct page *ipage, 372f2470371SChao Yu void *inline_dentry) 373201a05beSChao Yu { 374201a05beSChao Yu struct page *page; 375201a05beSChao Yu struct dnode_of_data dn; 376201a05beSChao Yu struct f2fs_dentry_block *dentry_blk; 37776a9dd85SChao Yu struct f2fs_dentry_ptr src, dst; 378201a05beSChao Yu int err; 379201a05beSChao Yu 380dd973007SJaegeuk Kim page = f2fs_grab_cache_page(dir->i_mapping, 0, true); 381470f00e9SChao Yu if (!page) { 382470f00e9SChao Yu f2fs_put_page(ipage, 1); 383201a05beSChao Yu return -ENOMEM; 384470f00e9SChao Yu } 385201a05beSChao Yu 386201a05beSChao Yu set_new_dnode(&dn, dir, ipage, NULL, 0); 387201a05beSChao Yu err = f2fs_reserve_block(&dn, 0); 388201a05beSChao Yu if (err) 389201a05beSChao Yu goto out; 390201a05beSChao Yu 3914dbe38dcSChao Yu if (unlikely(dn.data_blkaddr != NEW_ADDR)) { 3924dbe38dcSChao Yu f2fs_put_dnode(&dn); 3934dbe38dcSChao Yu set_sbi_flag(F2FS_P_SB(page), SBI_NEED_FSCK); 394dcbb4c10SJoe Perches f2fs_warn(F2FS_P_SB(page), "%s: corrupted inline inode ino=%lx, i_addr[0]:0x%x, run fsck to fix.", 3954dbe38dcSChao Yu __func__, dir->i_ino, dn.data_blkaddr); 39610f966bbSChao Yu err = -EFSCORRUPTED; 3974dbe38dcSChao Yu goto out; 3984dbe38dcSChao Yu } 3994dbe38dcSChao Yu 400bae0ee7aSChao Yu f2fs_wait_on_page_writeback(page, DATA, true, true); 401201a05beSChao Yu 402bdbc90faSYunlong Song dentry_blk = page_address(page); 403201a05beSChao Yu 404f2470371SChao Yu make_dentry_ptr_inline(dir, &src, inline_dentry); 405f2470371SChao Yu make_dentry_ptr_block(dir, &dst, dentry_blk); 40676a9dd85SChao Yu 407201a05beSChao Yu /* copy data from inline dentry block to new dentry block */ 40876a9dd85SChao Yu memcpy(dst.bitmap, src.bitmap, src.nr_bitmap); 40976a9dd85SChao Yu memset(dst.bitmap + src.nr_bitmap, 0, dst.nr_bitmap - src.nr_bitmap); 4104ec17d68SChao Yu /* 4114ec17d68SChao Yu * we do not need to zero out remainder part of dentry and filename 4124ec17d68SChao Yu * field, since we have used bitmap for marking the usage status of 4134ec17d68SChao Yu * them, besides, we can also ignore copying/zeroing reserved space 4144ec17d68SChao Yu * of dentry block, because them haven't been used so far. 4154ec17d68SChao Yu */ 41676a9dd85SChao Yu memcpy(dst.dentry, src.dentry, SIZE_OF_DIR_ENTRY * src.max); 41776a9dd85SChao Yu memcpy(dst.filename, src.filename, src.max * F2FS_SLOT_LEN); 418201a05beSChao Yu 419237c0790SJaegeuk Kim if (!PageUptodate(page)) 420201a05beSChao Yu SetPageUptodate(page); 421201a05beSChao Yu set_page_dirty(page); 422201a05beSChao Yu 423201a05beSChao Yu /* clear inline dir and flag after data writeback */ 4244d57b86dSChao Yu f2fs_truncate_inline_inode(dir, ipage, 0); 425b3d208f9SJaegeuk Kim 4263289c061SJaegeuk Kim stat_dec_inline_dir(dir); 42791942321SJaegeuk Kim clear_inode_flag(dir, FI_INLINE_DENTRY); 428201a05beSChao Yu 42945a74688SChao Yu /* 43045a74688SChao Yu * should retrieve reserved space which was used to keep 43145a74688SChao Yu * inline_dentry's structure for backward compatibility. 43245a74688SChao Yu */ 43345a74688SChao Yu if (!f2fs_sb_has_flexible_inline_xattr(F2FS_I_SB(dir)) && 43445a74688SChao Yu !f2fs_has_inline_xattr(dir)) 43545a74688SChao Yu F2FS_I(dir)->i_inline_xattr_size = 0; 43645a74688SChao Yu 437205b9822SJaegeuk Kim f2fs_i_depth_write(dir, 1); 438ee6d182fSJaegeuk Kim if (i_size_read(dir) < PAGE_SIZE) 439fc9581c8SJaegeuk Kim f2fs_i_size_write(dir, PAGE_SIZE); 440201a05beSChao Yu out: 441201a05beSChao Yu f2fs_put_page(page, 1); 442201a05beSChao Yu return err; 443201a05beSChao Yu } 444201a05beSChao Yu 445f2470371SChao Yu static int f2fs_add_inline_entries(struct inode *dir, void *inline_dentry) 446675f10bdSChao Yu { 447675f10bdSChao Yu struct f2fs_dentry_ptr d; 448675f10bdSChao Yu unsigned long bit_pos = 0; 449675f10bdSChao Yu int err = 0; 450675f10bdSChao Yu 451f2470371SChao Yu make_dentry_ptr_inline(dir, &d, inline_dentry); 452675f10bdSChao Yu 453675f10bdSChao Yu while (bit_pos < d.max) { 454675f10bdSChao Yu struct f2fs_dir_entry *de; 45543c780baSEric Biggers struct f2fs_filename fname; 456675f10bdSChao Yu nid_t ino; 457675f10bdSChao Yu umode_t fake_mode; 458675f10bdSChao Yu 459675f10bdSChao Yu if (!test_bit_le(bit_pos, d.bitmap)) { 460675f10bdSChao Yu bit_pos++; 461675f10bdSChao Yu continue; 462675f10bdSChao Yu } 463675f10bdSChao Yu 464675f10bdSChao Yu de = &d.dentry[bit_pos]; 465a4a13f58SChao Yu 466a4a13f58SChao Yu if (unlikely(!de->name_len)) { 467a4a13f58SChao Yu bit_pos++; 468a4a13f58SChao Yu continue; 469a4a13f58SChao Yu } 470a4a13f58SChao Yu 47143c780baSEric Biggers /* 47243c780baSEric Biggers * We only need the disk_name and hash to move the dentry. 47343c780baSEric Biggers * We don't need the original or casefolded filenames. 47443c780baSEric Biggers */ 47543c780baSEric Biggers memset(&fname, 0, sizeof(fname)); 47643c780baSEric Biggers fname.disk_name.name = d.filename[bit_pos]; 47743c780baSEric Biggers fname.disk_name.len = le16_to_cpu(de->name_len); 47843c780baSEric Biggers fname.hash = de->hash_code; 479675f10bdSChao Yu 480675f10bdSChao Yu ino = le32_to_cpu(de->ino); 4814d57b86dSChao Yu fake_mode = f2fs_get_de_type(de) << S_SHIFT; 482675f10bdSChao Yu 48343c780baSEric Biggers err = f2fs_add_regular_entry(dir, &fname, NULL, ino, fake_mode); 484675f10bdSChao Yu if (err) 485675f10bdSChao Yu goto punch_dentry_pages; 486675f10bdSChao Yu 487675f10bdSChao Yu bit_pos += GET_DENTRY_SLOTS(le16_to_cpu(de->name_len)); 488675f10bdSChao Yu } 489675f10bdSChao Yu return 0; 490675f10bdSChao Yu punch_dentry_pages: 491675f10bdSChao Yu truncate_inode_pages(&dir->i_data, 0); 492c42d28ceSChao Yu f2fs_truncate_blocks(dir, 0, false); 4934d57b86dSChao Yu f2fs_remove_dirty_inode(dir); 494675f10bdSChao Yu return err; 495675f10bdSChao Yu } 496675f10bdSChao Yu 497675f10bdSChao Yu static int f2fs_move_rehashed_dirents(struct inode *dir, struct page *ipage, 498f2470371SChao Yu void *inline_dentry) 499675f10bdSChao Yu { 500f2470371SChao Yu void *backup_dentry; 501675f10bdSChao Yu int err; 502675f10bdSChao Yu 5031ecc0c5cSChao Yu backup_dentry = f2fs_kmalloc(F2FS_I_SB(dir), 504f2470371SChao Yu MAX_INLINE_DATA(dir), GFP_F2FS_ZERO); 5058975bdf4SChao Yu if (!backup_dentry) { 5068975bdf4SChao Yu f2fs_put_page(ipage, 1); 507675f10bdSChao Yu return -ENOMEM; 5088975bdf4SChao Yu } 509675f10bdSChao Yu 510f2470371SChao Yu memcpy(backup_dentry, inline_dentry, MAX_INLINE_DATA(dir)); 5114d57b86dSChao Yu f2fs_truncate_inline_inode(dir, ipage, 0); 512675f10bdSChao Yu 513675f10bdSChao Yu unlock_page(ipage); 514675f10bdSChao Yu 515675f10bdSChao Yu err = f2fs_add_inline_entries(dir, backup_dentry); 516675f10bdSChao Yu if (err) 517675f10bdSChao Yu goto recover; 518675f10bdSChao Yu 519675f10bdSChao Yu lock_page(ipage); 520675f10bdSChao Yu 521675f10bdSChao Yu stat_dec_inline_dir(dir); 52291942321SJaegeuk Kim clear_inode_flag(dir, FI_INLINE_DENTRY); 52345a74688SChao Yu 52445a74688SChao Yu /* 52545a74688SChao Yu * should retrieve reserved space which was used to keep 52645a74688SChao Yu * inline_dentry's structure for backward compatibility. 52745a74688SChao Yu */ 52845a74688SChao Yu if (!f2fs_sb_has_flexible_inline_xattr(F2FS_I_SB(dir)) && 52945a74688SChao Yu !f2fs_has_inline_xattr(dir)) 53045a74688SChao Yu F2FS_I(dir)->i_inline_xattr_size = 0; 53145a74688SChao Yu 532c8eb7024SChao Yu kfree(backup_dentry); 533675f10bdSChao Yu return 0; 534675f10bdSChao Yu recover: 535675f10bdSChao Yu lock_page(ipage); 536bae0ee7aSChao Yu f2fs_wait_on_page_writeback(ipage, NODE, true, true); 537f2470371SChao Yu memcpy(inline_dentry, backup_dentry, MAX_INLINE_DATA(dir)); 538205b9822SJaegeuk Kim f2fs_i_depth_write(dir, 0); 539f2470371SChao Yu f2fs_i_size_write(dir, MAX_INLINE_DATA(dir)); 540ee6d182fSJaegeuk Kim set_page_dirty(ipage); 541675f10bdSChao Yu f2fs_put_page(ipage, 1); 542675f10bdSChao Yu 543c8eb7024SChao Yu kfree(backup_dentry); 544675f10bdSChao Yu return err; 545675f10bdSChao Yu } 546675f10bdSChao Yu 547b06af2afSJaegeuk Kim static int do_convert_inline_dir(struct inode *dir, struct page *ipage, 548f2470371SChao Yu void *inline_dentry) 549675f10bdSChao Yu { 550675f10bdSChao Yu if (!F2FS_I(dir)->i_dir_level) 551675f10bdSChao Yu return f2fs_move_inline_dirents(dir, ipage, inline_dentry); 552675f10bdSChao Yu else 553675f10bdSChao Yu return f2fs_move_rehashed_dirents(dir, ipage, inline_dentry); 554675f10bdSChao Yu } 555675f10bdSChao Yu 556b06af2afSJaegeuk Kim int f2fs_try_convert_inline_dir(struct inode *dir, struct dentry *dentry) 557b06af2afSJaegeuk Kim { 558b06af2afSJaegeuk Kim struct f2fs_sb_info *sbi = F2FS_I_SB(dir); 559b06af2afSJaegeuk Kim struct page *ipage; 56043c780baSEric Biggers struct f2fs_filename fname; 561b06af2afSJaegeuk Kim void *inline_dentry = NULL; 562b06af2afSJaegeuk Kim int err = 0; 563b06af2afSJaegeuk Kim 564b06af2afSJaegeuk Kim if (!f2fs_has_inline_dentry(dir)) 565b06af2afSJaegeuk Kim return 0; 566b06af2afSJaegeuk Kim 567b06af2afSJaegeuk Kim f2fs_lock_op(sbi); 568b06af2afSJaegeuk Kim 56943c780baSEric Biggers err = f2fs_setup_filename(dir, &dentry->d_name, 0, &fname); 570b06af2afSJaegeuk Kim if (err) 571b06af2afSJaegeuk Kim goto out; 572b06af2afSJaegeuk Kim 573b06af2afSJaegeuk Kim ipage = f2fs_get_node_page(sbi, dir->i_ino); 574b06af2afSJaegeuk Kim if (IS_ERR(ipage)) { 575b06af2afSJaegeuk Kim err = PTR_ERR(ipage); 576ff5f85c8SEric Biggers goto out_fname; 577b06af2afSJaegeuk Kim } 578b06af2afSJaegeuk Kim 579b06af2afSJaegeuk Kim if (f2fs_has_enough_room(dir, ipage, &fname)) { 580b06af2afSJaegeuk Kim f2fs_put_page(ipage, 1); 581ff5f85c8SEric Biggers goto out_fname; 582b06af2afSJaegeuk Kim } 583b06af2afSJaegeuk Kim 584b06af2afSJaegeuk Kim inline_dentry = inline_data_addr(dir, ipage); 585b06af2afSJaegeuk Kim 586b06af2afSJaegeuk Kim err = do_convert_inline_dir(dir, ipage, inline_dentry); 587b06af2afSJaegeuk Kim if (!err) 588b06af2afSJaegeuk Kim f2fs_put_page(ipage, 1); 589ff5f85c8SEric Biggers out_fname: 59043c780baSEric Biggers f2fs_free_filename(&fname); 591b06af2afSJaegeuk Kim out: 592b06af2afSJaegeuk Kim f2fs_unlock_op(sbi); 593b06af2afSJaegeuk Kim return err; 594b06af2afSJaegeuk Kim } 595b06af2afSJaegeuk Kim 59643c780baSEric Biggers int f2fs_add_inline_entry(struct inode *dir, const struct f2fs_filename *fname, 597510022a8SJaegeuk Kim struct inode *inode, nid_t ino, umode_t mode) 598201a05beSChao Yu { 599201a05beSChao Yu struct f2fs_sb_info *sbi = F2FS_I_SB(dir); 600201a05beSChao Yu struct page *ipage; 601201a05beSChao Yu unsigned int bit_pos; 602f2470371SChao Yu void *inline_dentry = NULL; 6033b4d732aSChao Yu struct f2fs_dentry_ptr d; 60443c780baSEric Biggers int slots = GET_DENTRY_SLOTS(fname->disk_name.len); 605510022a8SJaegeuk Kim struct page *page = NULL; 606201a05beSChao Yu int err = 0; 607201a05beSChao Yu 6084d57b86dSChao Yu ipage = f2fs_get_node_page(sbi, dir->i_ino); 609201a05beSChao Yu if (IS_ERR(ipage)) 610201a05beSChao Yu return PTR_ERR(ipage); 611201a05beSChao Yu 612f2470371SChao Yu inline_dentry = inline_data_addr(dir, ipage); 613f2470371SChao Yu make_dentry_ptr_inline(dir, &d, inline_dentry); 61476a9dd85SChao Yu 6154d57b86dSChao Yu bit_pos = f2fs_room_for_filename(d.bitmap, slots, d.max); 61676a9dd85SChao Yu if (bit_pos >= d.max) { 617b06af2afSJaegeuk Kim err = do_convert_inline_dir(dir, ipage, inline_dentry); 618470f00e9SChao Yu if (err) 619470f00e9SChao Yu return err; 620201a05beSChao Yu err = -EAGAIN; 621201a05beSChao Yu goto out; 622201a05beSChao Yu } 623201a05beSChao Yu 624510022a8SJaegeuk Kim if (inode) { 625201a05beSChao Yu down_write(&F2FS_I(inode)->i_sem); 62643c780baSEric Biggers page = f2fs_init_inode_metadata(inode, dir, fname, ipage); 627201a05beSChao Yu if (IS_ERR(page)) { 628201a05beSChao Yu err = PTR_ERR(page); 629201a05beSChao Yu goto fail; 630201a05beSChao Yu } 631510022a8SJaegeuk Kim } 632bce8d112SJaegeuk Kim 633bae0ee7aSChao Yu f2fs_wait_on_page_writeback(ipage, NODE, true, true); 6343b4d732aSChao Yu 63543c780baSEric Biggers f2fs_update_dentry(ino, mode, &d, &fname->disk_name, fname->hash, 63643c780baSEric Biggers bit_pos); 6373b4d732aSChao Yu 638201a05beSChao Yu set_page_dirty(ipage); 639201a05beSChao Yu 640201a05beSChao Yu /* we don't need to mark_inode_dirty now */ 641510022a8SJaegeuk Kim if (inode) { 642205b9822SJaegeuk Kim f2fs_i_pino_write(inode, dir->i_ino); 64398194030SChao Yu 64498194030SChao Yu /* synchronize inode page's data from inode cache */ 64598194030SChao Yu if (is_inode_flag_set(inode, FI_NEW_INODE)) 64698194030SChao Yu f2fs_update_inode(inode, page); 64798194030SChao Yu 648201a05beSChao Yu f2fs_put_page(page, 1); 649510022a8SJaegeuk Kim } 650201a05beSChao Yu 6514d57b86dSChao Yu f2fs_update_parent_metadata(dir, inode, 0); 652201a05beSChao Yu fail: 653510022a8SJaegeuk Kim if (inode) 654201a05beSChao Yu up_write(&F2FS_I(inode)->i_sem); 655201a05beSChao Yu out: 656201a05beSChao Yu f2fs_put_page(ipage, 1); 657201a05beSChao Yu return err; 658201a05beSChao Yu } 659201a05beSChao Yu 660201a05beSChao Yu void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry, struct page *page, 661201a05beSChao Yu struct inode *dir, struct inode *inode) 662201a05beSChao Yu { 66376a9dd85SChao Yu struct f2fs_dentry_ptr d; 664f2470371SChao Yu void *inline_dentry; 665201a05beSChao Yu int slots = GET_DENTRY_SLOTS(le16_to_cpu(dentry->name_len)); 666201a05beSChao Yu unsigned int bit_pos; 667201a05beSChao Yu int i; 668201a05beSChao Yu 669201a05beSChao Yu lock_page(page); 670bae0ee7aSChao Yu f2fs_wait_on_page_writeback(page, NODE, true, true); 671201a05beSChao Yu 672f2470371SChao Yu inline_dentry = inline_data_addr(dir, page); 673f2470371SChao Yu make_dentry_ptr_inline(dir, &d, inline_dentry); 67476a9dd85SChao Yu 67576a9dd85SChao Yu bit_pos = dentry - d.dentry; 676201a05beSChao Yu for (i = 0; i < slots; i++) 67776a9dd85SChao Yu __clear_bit_le(bit_pos + i, d.bitmap); 678201a05beSChao Yu 679201a05beSChao Yu set_page_dirty(page); 6809f7c45ccSJaegeuk Kim f2fs_put_page(page, 1); 681201a05beSChao Yu 682078cd827SDeepa Dinamani dir->i_ctime = dir->i_mtime = current_time(dir); 6837c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(dir, false); 684201a05beSChao Yu 685201a05beSChao Yu if (inode) 6869f7c45ccSJaegeuk Kim f2fs_drop_nlink(dir, inode); 687201a05beSChao Yu } 688201a05beSChao Yu 689201a05beSChao Yu bool f2fs_empty_inline_dir(struct inode *dir) 690201a05beSChao Yu { 691201a05beSChao Yu struct f2fs_sb_info *sbi = F2FS_I_SB(dir); 692201a05beSChao Yu struct page *ipage; 693201a05beSChao Yu unsigned int bit_pos = 2; 694f2470371SChao Yu void *inline_dentry; 69576a9dd85SChao Yu struct f2fs_dentry_ptr d; 696201a05beSChao Yu 6974d57b86dSChao Yu ipage = f2fs_get_node_page(sbi, dir->i_ino); 698201a05beSChao Yu if (IS_ERR(ipage)) 699201a05beSChao Yu return false; 700201a05beSChao Yu 701f2470371SChao Yu inline_dentry = inline_data_addr(dir, ipage); 702f2470371SChao Yu make_dentry_ptr_inline(dir, &d, inline_dentry); 70376a9dd85SChao Yu 70476a9dd85SChao Yu bit_pos = find_next_bit_le(d.bitmap, d.max, bit_pos); 705201a05beSChao Yu 706201a05beSChao Yu f2fs_put_page(ipage, 1); 707201a05beSChao Yu 70876a9dd85SChao Yu if (bit_pos < d.max) 709201a05beSChao Yu return false; 710201a05beSChao Yu 711201a05beSChao Yu return true; 712201a05beSChao Yu } 713201a05beSChao Yu 714d8c6822aSJaegeuk Kim int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx, 7150b81d077SJaegeuk Kim struct fscrypt_str *fstr) 716201a05beSChao Yu { 717201a05beSChao Yu struct inode *inode = file_inode(file); 718201a05beSChao Yu struct page *ipage = NULL; 7197b3cd7d6SJaegeuk Kim struct f2fs_dentry_ptr d; 720f2470371SChao Yu void *inline_dentry = NULL; 721ed6bd4b1SChao Yu int err; 722201a05beSChao Yu 72376a9dd85SChao Yu make_dentry_ptr_inline(inode, &d, inline_dentry); 72476a9dd85SChao Yu 72576a9dd85SChao Yu if (ctx->pos == d.max) 726201a05beSChao Yu return 0; 727201a05beSChao Yu 7284d57b86dSChao Yu ipage = f2fs_get_node_page(F2FS_I_SB(inode), inode->i_ino); 729201a05beSChao Yu if (IS_ERR(ipage)) 730201a05beSChao Yu return PTR_ERR(ipage); 731201a05beSChao Yu 732aadcef64SChao Yu /* 733aadcef64SChao Yu * f2fs_readdir was protected by inode.i_rwsem, it is safe to access 734aadcef64SChao Yu * ipage without page's lock held. 735aadcef64SChao Yu */ 736aadcef64SChao Yu unlock_page(ipage); 737aadcef64SChao Yu 738f2470371SChao Yu inline_dentry = inline_data_addr(inode, ipage); 739201a05beSChao Yu 74064c24ecbSTomohiro Kusumi make_dentry_ptr_inline(inode, &d, inline_dentry); 7417b3cd7d6SJaegeuk Kim 742ed6bd4b1SChao Yu err = f2fs_fill_dentries(ctx, &d, 0, fstr); 743ed6bd4b1SChao Yu if (!err) 74476a9dd85SChao Yu ctx->pos = d.max; 745201a05beSChao Yu 746aadcef64SChao Yu f2fs_put_page(ipage, 0); 747ed6bd4b1SChao Yu return err < 0 ? err : 0; 748201a05beSChao Yu } 74967f8cf3cSJaegeuk Kim 75067f8cf3cSJaegeuk Kim int f2fs_inline_data_fiemap(struct inode *inode, 75167f8cf3cSJaegeuk Kim struct fiemap_extent_info *fieinfo, __u64 start, __u64 len) 75267f8cf3cSJaegeuk Kim { 75367f8cf3cSJaegeuk Kim __u64 byteaddr, ilen; 75467f8cf3cSJaegeuk Kim __u32 flags = FIEMAP_EXTENT_DATA_INLINE | FIEMAP_EXTENT_NOT_ALIGNED | 75567f8cf3cSJaegeuk Kim FIEMAP_EXTENT_LAST; 75667f8cf3cSJaegeuk Kim struct node_info ni; 75767f8cf3cSJaegeuk Kim struct page *ipage; 75867f8cf3cSJaegeuk Kim int err = 0; 75967f8cf3cSJaegeuk Kim 7604d57b86dSChao Yu ipage = f2fs_get_node_page(F2FS_I_SB(inode), inode->i_ino); 76167f8cf3cSJaegeuk Kim if (IS_ERR(ipage)) 76267f8cf3cSJaegeuk Kim return PTR_ERR(ipage); 76367f8cf3cSJaegeuk Kim 7647975f349SChao Yu if ((S_ISREG(inode->i_mode) || S_ISLNK(inode->i_mode)) && 7657975f349SChao Yu !f2fs_has_inline_data(inode)) { 7667975f349SChao Yu err = -EAGAIN; 7677975f349SChao Yu goto out; 7687975f349SChao Yu } 7697975f349SChao Yu 7707975f349SChao Yu if (S_ISDIR(inode->i_mode) && !f2fs_has_inline_dentry(inode)) { 77167f8cf3cSJaegeuk Kim err = -EAGAIN; 77267f8cf3cSJaegeuk Kim goto out; 77367f8cf3cSJaegeuk Kim } 77467f8cf3cSJaegeuk Kim 775f2470371SChao Yu ilen = min_t(size_t, MAX_INLINE_DATA(inode), i_size_read(inode)); 77667f8cf3cSJaegeuk Kim if (start >= ilen) 77767f8cf3cSJaegeuk Kim goto out; 77867f8cf3cSJaegeuk Kim if (start + len < ilen) 77967f8cf3cSJaegeuk Kim ilen = start + len; 78067f8cf3cSJaegeuk Kim ilen -= start; 78167f8cf3cSJaegeuk Kim 7827735730dSChao Yu err = f2fs_get_node_info(F2FS_I_SB(inode), inode->i_ino, &ni); 7837735730dSChao Yu if (err) 7847735730dSChao Yu goto out; 7857735730dSChao Yu 78667f8cf3cSJaegeuk Kim byteaddr = (__u64)ni.blk_addr << inode->i_sb->s_blocksize_bits; 787f2470371SChao Yu byteaddr += (char *)inline_data_addr(inode, ipage) - 788f2470371SChao Yu (char *)F2FS_INODE(ipage); 78967f8cf3cSJaegeuk Kim err = fiemap_fill_next_extent(fieinfo, start, byteaddr, ilen, flags); 790dd5a09bdSChao Yu trace_f2fs_fiemap(inode, start, byteaddr, ilen, flags, err); 79167f8cf3cSJaegeuk Kim out: 79267f8cf3cSJaegeuk Kim f2fs_put_page(ipage, 1); 79367f8cf3cSJaegeuk Kim return err; 79467f8cf3cSJaegeuk Kim } 795