1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * fs/f2fs/inline.c 4 * Copyright (c) 2013, Intel Corporation 5 * Authors: Huajun Li <huajun.li@intel.com> 6 * Haicheng Li <haicheng.li@intel.com> 7 */ 8 9 #include <linux/fs.h> 10 #include <linux/f2fs_fs.h> 11 #include <linux/fiemap.h> 12 13 #include "f2fs.h" 14 #include "node.h" 15 #include <trace/events/f2fs.h> 16 17 bool f2fs_may_inline_data(struct inode *inode) 18 { 19 if (f2fs_is_atomic_file(inode)) 20 return false; 21 22 if (!S_ISREG(inode->i_mode) && !S_ISLNK(inode->i_mode)) 23 return false; 24 25 if (i_size_read(inode) > MAX_INLINE_DATA(inode)) 26 return false; 27 28 if (f2fs_post_read_required(inode)) 29 return false; 30 31 return true; 32 } 33 34 bool f2fs_may_inline_dentry(struct inode *inode) 35 { 36 if (!test_opt(F2FS_I_SB(inode), INLINE_DENTRY)) 37 return false; 38 39 if (!S_ISDIR(inode->i_mode)) 40 return false; 41 42 return true; 43 } 44 45 void f2fs_do_read_inline_data(struct page *page, struct page *ipage) 46 { 47 struct inode *inode = page->mapping->host; 48 void *src_addr, *dst_addr; 49 50 if (PageUptodate(page)) 51 return; 52 53 f2fs_bug_on(F2FS_P_SB(page), page->index); 54 55 zero_user_segment(page, MAX_INLINE_DATA(inode), PAGE_SIZE); 56 57 /* Copy the whole inline data block */ 58 src_addr = inline_data_addr(inode, ipage); 59 dst_addr = kmap_atomic(page); 60 memcpy(dst_addr, src_addr, MAX_INLINE_DATA(inode)); 61 flush_dcache_page(page); 62 kunmap_atomic(dst_addr); 63 if (!PageUptodate(page)) 64 SetPageUptodate(page); 65 } 66 67 void f2fs_truncate_inline_inode(struct inode *inode, 68 struct page *ipage, u64 from) 69 { 70 void *addr; 71 72 if (from >= MAX_INLINE_DATA(inode)) 73 return; 74 75 addr = inline_data_addr(inode, ipage); 76 77 f2fs_wait_on_page_writeback(ipage, NODE, true, true); 78 memset(addr + from, 0, MAX_INLINE_DATA(inode) - from); 79 set_page_dirty(ipage); 80 81 if (from == 0) 82 clear_inode_flag(inode, FI_DATA_EXIST); 83 } 84 85 int f2fs_read_inline_data(struct inode *inode, struct page *page) 86 { 87 struct page *ipage; 88 89 ipage = f2fs_get_node_page(F2FS_I_SB(inode), inode->i_ino); 90 if (IS_ERR(ipage)) { 91 unlock_page(page); 92 return PTR_ERR(ipage); 93 } 94 95 if (!f2fs_has_inline_data(inode)) { 96 f2fs_put_page(ipage, 1); 97 return -EAGAIN; 98 } 99 100 if (page->index) 101 zero_user_segment(page, 0, PAGE_SIZE); 102 else 103 f2fs_do_read_inline_data(page, ipage); 104 105 if (!PageUptodate(page)) 106 SetPageUptodate(page); 107 f2fs_put_page(ipage, 1); 108 unlock_page(page); 109 return 0; 110 } 111 112 int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page) 113 { 114 struct f2fs_io_info fio = { 115 .sbi = F2FS_I_SB(dn->inode), 116 .ino = dn->inode->i_ino, 117 .type = DATA, 118 .op = REQ_OP_WRITE, 119 .op_flags = REQ_SYNC | REQ_PRIO, 120 .page = page, 121 .encrypted_page = NULL, 122 .io_type = FS_DATA_IO, 123 }; 124 struct node_info ni; 125 int dirty, err; 126 127 if (!f2fs_exist_data(dn->inode)) 128 goto clear_out; 129 130 err = f2fs_reserve_block(dn, 0); 131 if (err) 132 return err; 133 134 err = f2fs_get_node_info(fio.sbi, dn->nid, &ni); 135 if (err) { 136 f2fs_truncate_data_blocks_range(dn, 1); 137 f2fs_put_dnode(dn); 138 return err; 139 } 140 141 fio.version = ni.version; 142 143 if (unlikely(dn->data_blkaddr != NEW_ADDR)) { 144 f2fs_put_dnode(dn); 145 set_sbi_flag(fio.sbi, SBI_NEED_FSCK); 146 f2fs_warn(fio.sbi, "%s: corrupted inline inode ino=%lx, i_addr[0]:0x%x, run fsck to fix.", 147 __func__, dn->inode->i_ino, dn->data_blkaddr); 148 return -EFSCORRUPTED; 149 } 150 151 f2fs_bug_on(F2FS_P_SB(page), PageWriteback(page)); 152 153 f2fs_do_read_inline_data(page, dn->inode_page); 154 set_page_dirty(page); 155 156 /* clear dirty state */ 157 dirty = clear_page_dirty_for_io(page); 158 159 /* write data page to try to make data consistent */ 160 set_page_writeback(page); 161 ClearPageError(page); 162 fio.old_blkaddr = dn->data_blkaddr; 163 set_inode_flag(dn->inode, FI_HOT_DATA); 164 f2fs_outplace_write_data(dn, &fio); 165 f2fs_wait_on_page_writeback(page, DATA, true, true); 166 if (dirty) { 167 inode_dec_dirty_pages(dn->inode); 168 f2fs_remove_dirty_inode(dn->inode); 169 } 170 171 /* this converted inline_data should be recovered. */ 172 set_inode_flag(dn->inode, FI_APPEND_WRITE); 173 174 /* clear inline data and flag after data writeback */ 175 f2fs_truncate_inline_inode(dn->inode, dn->inode_page, 0); 176 clear_inline_node(dn->inode_page); 177 clear_out: 178 stat_dec_inline_inode(dn->inode); 179 clear_inode_flag(dn->inode, FI_INLINE_DATA); 180 f2fs_put_dnode(dn); 181 return 0; 182 } 183 184 int f2fs_convert_inline_inode(struct inode *inode) 185 { 186 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 187 struct dnode_of_data dn; 188 struct page *ipage, *page; 189 int err = 0; 190 191 if (!f2fs_has_inline_data(inode) || 192 f2fs_hw_is_readonly(sbi) || f2fs_readonly(sbi->sb)) 193 return 0; 194 195 err = dquot_initialize(inode); 196 if (err) 197 return err; 198 199 page = f2fs_grab_cache_page(inode->i_mapping, 0, false); 200 if (!page) 201 return -ENOMEM; 202 203 f2fs_lock_op(sbi); 204 205 ipage = f2fs_get_node_page(sbi, inode->i_ino); 206 if (IS_ERR(ipage)) { 207 err = PTR_ERR(ipage); 208 goto out; 209 } 210 211 set_new_dnode(&dn, inode, ipage, ipage, 0); 212 213 if (f2fs_has_inline_data(inode)) 214 err = f2fs_convert_inline_page(&dn, page); 215 216 f2fs_put_dnode(&dn); 217 out: 218 f2fs_unlock_op(sbi); 219 220 f2fs_put_page(page, 1); 221 222 f2fs_balance_fs(sbi, dn.node_changed); 223 224 return err; 225 } 226 227 int f2fs_write_inline_data(struct inode *inode, struct page *page) 228 { 229 void *src_addr, *dst_addr; 230 struct dnode_of_data dn; 231 int err; 232 233 set_new_dnode(&dn, inode, NULL, NULL, 0); 234 err = f2fs_get_dnode_of_data(&dn, 0, LOOKUP_NODE); 235 if (err) 236 return err; 237 238 if (!f2fs_has_inline_data(inode)) { 239 f2fs_put_dnode(&dn); 240 return -EAGAIN; 241 } 242 243 f2fs_bug_on(F2FS_I_SB(inode), page->index); 244 245 f2fs_wait_on_page_writeback(dn.inode_page, NODE, true, true); 246 src_addr = kmap_atomic(page); 247 dst_addr = inline_data_addr(inode, dn.inode_page); 248 memcpy(dst_addr, src_addr, MAX_INLINE_DATA(inode)); 249 kunmap_atomic(src_addr); 250 set_page_dirty(dn.inode_page); 251 252 f2fs_clear_page_cache_dirty_tag(page); 253 254 set_inode_flag(inode, FI_APPEND_WRITE); 255 set_inode_flag(inode, FI_DATA_EXIST); 256 257 clear_inline_node(dn.inode_page); 258 f2fs_put_dnode(&dn); 259 return 0; 260 } 261 262 int f2fs_recover_inline_data(struct inode *inode, struct page *npage) 263 { 264 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 265 struct f2fs_inode *ri = NULL; 266 void *src_addr, *dst_addr; 267 struct page *ipage; 268 269 /* 270 * The inline_data recovery policy is as follows. 271 * [prev.] [next] of inline_data flag 272 * o o -> recover inline_data 273 * o x -> remove inline_data, and then recover data blocks 274 * x o -> remove data blocks, and then recover inline_data 275 * x x -> recover data blocks 276 */ 277 if (IS_INODE(npage)) 278 ri = F2FS_INODE(npage); 279 280 if (f2fs_has_inline_data(inode) && 281 ri && (ri->i_inline & F2FS_INLINE_DATA)) { 282 process_inline: 283 ipage = f2fs_get_node_page(sbi, inode->i_ino); 284 if (IS_ERR(ipage)) 285 return PTR_ERR(ipage); 286 287 f2fs_wait_on_page_writeback(ipage, NODE, true, true); 288 289 src_addr = inline_data_addr(inode, npage); 290 dst_addr = inline_data_addr(inode, ipage); 291 memcpy(dst_addr, src_addr, MAX_INLINE_DATA(inode)); 292 293 set_inode_flag(inode, FI_INLINE_DATA); 294 set_inode_flag(inode, FI_DATA_EXIST); 295 296 set_page_dirty(ipage); 297 f2fs_put_page(ipage, 1); 298 return 1; 299 } 300 301 if (f2fs_has_inline_data(inode)) { 302 ipage = f2fs_get_node_page(sbi, inode->i_ino); 303 if (IS_ERR(ipage)) 304 return PTR_ERR(ipage); 305 f2fs_truncate_inline_inode(inode, ipage, 0); 306 stat_dec_inline_inode(inode); 307 clear_inode_flag(inode, FI_INLINE_DATA); 308 f2fs_put_page(ipage, 1); 309 } else if (ri && (ri->i_inline & F2FS_INLINE_DATA)) { 310 int ret; 311 312 ret = f2fs_truncate_blocks(inode, 0, false); 313 if (ret) 314 return ret; 315 stat_inc_inline_inode(inode); 316 goto process_inline; 317 } 318 return 0; 319 } 320 321 struct f2fs_dir_entry *f2fs_find_in_inline_dir(struct inode *dir, 322 const struct f2fs_filename *fname, 323 struct page **res_page) 324 { 325 struct f2fs_sb_info *sbi = F2FS_SB(dir->i_sb); 326 struct f2fs_dir_entry *de; 327 struct f2fs_dentry_ptr d; 328 struct page *ipage; 329 void *inline_dentry; 330 331 ipage = f2fs_get_node_page(sbi, dir->i_ino); 332 if (IS_ERR(ipage)) { 333 *res_page = ipage; 334 return NULL; 335 } 336 337 inline_dentry = inline_data_addr(dir, ipage); 338 339 make_dentry_ptr_inline(dir, &d, inline_dentry); 340 de = f2fs_find_target_dentry(&d, fname, NULL); 341 unlock_page(ipage); 342 if (IS_ERR(de)) { 343 *res_page = ERR_CAST(de); 344 de = NULL; 345 } 346 if (de) 347 *res_page = ipage; 348 else 349 f2fs_put_page(ipage, 0); 350 351 return de; 352 } 353 354 int f2fs_make_empty_inline_dir(struct inode *inode, struct inode *parent, 355 struct page *ipage) 356 { 357 struct f2fs_dentry_ptr d; 358 void *inline_dentry; 359 360 inline_dentry = inline_data_addr(inode, ipage); 361 362 make_dentry_ptr_inline(inode, &d, inline_dentry); 363 f2fs_do_make_empty_dir(inode, parent, &d); 364 365 set_page_dirty(ipage); 366 367 /* update i_size to MAX_INLINE_DATA */ 368 if (i_size_read(inode) < MAX_INLINE_DATA(inode)) 369 f2fs_i_size_write(inode, MAX_INLINE_DATA(inode)); 370 return 0; 371 } 372 373 /* 374 * NOTE: ipage is grabbed by caller, but if any error occurs, we should 375 * release ipage in this function. 376 */ 377 static int f2fs_move_inline_dirents(struct inode *dir, struct page *ipage, 378 void *inline_dentry) 379 { 380 struct page *page; 381 struct dnode_of_data dn; 382 struct f2fs_dentry_block *dentry_blk; 383 struct f2fs_dentry_ptr src, dst; 384 int err; 385 386 page = f2fs_grab_cache_page(dir->i_mapping, 0, true); 387 if (!page) { 388 f2fs_put_page(ipage, 1); 389 return -ENOMEM; 390 } 391 392 set_new_dnode(&dn, dir, ipage, NULL, 0); 393 err = f2fs_reserve_block(&dn, 0); 394 if (err) 395 goto out; 396 397 if (unlikely(dn.data_blkaddr != NEW_ADDR)) { 398 f2fs_put_dnode(&dn); 399 set_sbi_flag(F2FS_P_SB(page), SBI_NEED_FSCK); 400 f2fs_warn(F2FS_P_SB(page), "%s: corrupted inline inode ino=%lx, i_addr[0]:0x%x, run fsck to fix.", 401 __func__, dir->i_ino, dn.data_blkaddr); 402 err = -EFSCORRUPTED; 403 goto out; 404 } 405 406 f2fs_wait_on_page_writeback(page, DATA, true, true); 407 408 dentry_blk = page_address(page); 409 410 make_dentry_ptr_inline(dir, &src, inline_dentry); 411 make_dentry_ptr_block(dir, &dst, dentry_blk); 412 413 /* copy data from inline dentry block to new dentry block */ 414 memcpy(dst.bitmap, src.bitmap, src.nr_bitmap); 415 memset(dst.bitmap + src.nr_bitmap, 0, dst.nr_bitmap - src.nr_bitmap); 416 /* 417 * we do not need to zero out remainder part of dentry and filename 418 * field, since we have used bitmap for marking the usage status of 419 * them, besides, we can also ignore copying/zeroing reserved space 420 * of dentry block, because them haven't been used so far. 421 */ 422 memcpy(dst.dentry, src.dentry, SIZE_OF_DIR_ENTRY * src.max); 423 memcpy(dst.filename, src.filename, src.max * F2FS_SLOT_LEN); 424 425 if (!PageUptodate(page)) 426 SetPageUptodate(page); 427 set_page_dirty(page); 428 429 /* clear inline dir and flag after data writeback */ 430 f2fs_truncate_inline_inode(dir, ipage, 0); 431 432 stat_dec_inline_dir(dir); 433 clear_inode_flag(dir, FI_INLINE_DENTRY); 434 435 /* 436 * should retrieve reserved space which was used to keep 437 * inline_dentry's structure for backward compatibility. 438 */ 439 if (!f2fs_sb_has_flexible_inline_xattr(F2FS_I_SB(dir)) && 440 !f2fs_has_inline_xattr(dir)) 441 F2FS_I(dir)->i_inline_xattr_size = 0; 442 443 f2fs_i_depth_write(dir, 1); 444 if (i_size_read(dir) < PAGE_SIZE) 445 f2fs_i_size_write(dir, PAGE_SIZE); 446 out: 447 f2fs_put_page(page, 1); 448 return err; 449 } 450 451 static int f2fs_add_inline_entries(struct inode *dir, void *inline_dentry) 452 { 453 struct f2fs_dentry_ptr d; 454 unsigned long bit_pos = 0; 455 int err = 0; 456 457 make_dentry_ptr_inline(dir, &d, inline_dentry); 458 459 while (bit_pos < d.max) { 460 struct f2fs_dir_entry *de; 461 struct f2fs_filename fname; 462 nid_t ino; 463 umode_t fake_mode; 464 465 if (!test_bit_le(bit_pos, d.bitmap)) { 466 bit_pos++; 467 continue; 468 } 469 470 de = &d.dentry[bit_pos]; 471 472 if (unlikely(!de->name_len)) { 473 bit_pos++; 474 continue; 475 } 476 477 /* 478 * We only need the disk_name and hash to move the dentry. 479 * We don't need the original or casefolded filenames. 480 */ 481 memset(&fname, 0, sizeof(fname)); 482 fname.disk_name.name = d.filename[bit_pos]; 483 fname.disk_name.len = le16_to_cpu(de->name_len); 484 fname.hash = de->hash_code; 485 486 ino = le32_to_cpu(de->ino); 487 fake_mode = f2fs_get_de_type(de) << S_SHIFT; 488 489 err = f2fs_add_regular_entry(dir, &fname, NULL, ino, fake_mode); 490 if (err) 491 goto punch_dentry_pages; 492 493 bit_pos += GET_DENTRY_SLOTS(le16_to_cpu(de->name_len)); 494 } 495 return 0; 496 punch_dentry_pages: 497 truncate_inode_pages(&dir->i_data, 0); 498 f2fs_truncate_blocks(dir, 0, false); 499 f2fs_remove_dirty_inode(dir); 500 return err; 501 } 502 503 static int f2fs_move_rehashed_dirents(struct inode *dir, struct page *ipage, 504 void *inline_dentry) 505 { 506 void *backup_dentry; 507 int err; 508 509 backup_dentry = f2fs_kmalloc(F2FS_I_SB(dir), 510 MAX_INLINE_DATA(dir), GFP_F2FS_ZERO); 511 if (!backup_dentry) { 512 f2fs_put_page(ipage, 1); 513 return -ENOMEM; 514 } 515 516 memcpy(backup_dentry, inline_dentry, MAX_INLINE_DATA(dir)); 517 f2fs_truncate_inline_inode(dir, ipage, 0); 518 519 unlock_page(ipage); 520 521 err = f2fs_add_inline_entries(dir, backup_dentry); 522 if (err) 523 goto recover; 524 525 lock_page(ipage); 526 527 stat_dec_inline_dir(dir); 528 clear_inode_flag(dir, FI_INLINE_DENTRY); 529 530 /* 531 * should retrieve reserved space which was used to keep 532 * inline_dentry's structure for backward compatibility. 533 */ 534 if (!f2fs_sb_has_flexible_inline_xattr(F2FS_I_SB(dir)) && 535 !f2fs_has_inline_xattr(dir)) 536 F2FS_I(dir)->i_inline_xattr_size = 0; 537 538 kfree(backup_dentry); 539 return 0; 540 recover: 541 lock_page(ipage); 542 f2fs_wait_on_page_writeback(ipage, NODE, true, true); 543 memcpy(inline_dentry, backup_dentry, MAX_INLINE_DATA(dir)); 544 f2fs_i_depth_write(dir, 0); 545 f2fs_i_size_write(dir, MAX_INLINE_DATA(dir)); 546 set_page_dirty(ipage); 547 f2fs_put_page(ipage, 1); 548 549 kfree(backup_dentry); 550 return err; 551 } 552 553 static int do_convert_inline_dir(struct inode *dir, struct page *ipage, 554 void *inline_dentry) 555 { 556 if (!F2FS_I(dir)->i_dir_level) 557 return f2fs_move_inline_dirents(dir, ipage, inline_dentry); 558 else 559 return f2fs_move_rehashed_dirents(dir, ipage, inline_dentry); 560 } 561 562 int f2fs_try_convert_inline_dir(struct inode *dir, struct dentry *dentry) 563 { 564 struct f2fs_sb_info *sbi = F2FS_I_SB(dir); 565 struct page *ipage; 566 struct f2fs_filename fname; 567 void *inline_dentry = NULL; 568 int err = 0; 569 570 if (!f2fs_has_inline_dentry(dir)) 571 return 0; 572 573 f2fs_lock_op(sbi); 574 575 err = f2fs_setup_filename(dir, &dentry->d_name, 0, &fname); 576 if (err) 577 goto out; 578 579 ipage = f2fs_get_node_page(sbi, dir->i_ino); 580 if (IS_ERR(ipage)) { 581 err = PTR_ERR(ipage); 582 goto out_fname; 583 } 584 585 if (f2fs_has_enough_room(dir, ipage, &fname)) { 586 f2fs_put_page(ipage, 1); 587 goto out_fname; 588 } 589 590 inline_dentry = inline_data_addr(dir, ipage); 591 592 err = do_convert_inline_dir(dir, ipage, inline_dentry); 593 if (!err) 594 f2fs_put_page(ipage, 1); 595 out_fname: 596 f2fs_free_filename(&fname); 597 out: 598 f2fs_unlock_op(sbi); 599 return err; 600 } 601 602 int f2fs_add_inline_entry(struct inode *dir, const struct f2fs_filename *fname, 603 struct inode *inode, nid_t ino, umode_t mode) 604 { 605 struct f2fs_sb_info *sbi = F2FS_I_SB(dir); 606 struct page *ipage; 607 unsigned int bit_pos; 608 void *inline_dentry = NULL; 609 struct f2fs_dentry_ptr d; 610 int slots = GET_DENTRY_SLOTS(fname->disk_name.len); 611 struct page *page = NULL; 612 int err = 0; 613 614 ipage = f2fs_get_node_page(sbi, dir->i_ino); 615 if (IS_ERR(ipage)) 616 return PTR_ERR(ipage); 617 618 inline_dentry = inline_data_addr(dir, ipage); 619 make_dentry_ptr_inline(dir, &d, inline_dentry); 620 621 bit_pos = f2fs_room_for_filename(d.bitmap, slots, d.max); 622 if (bit_pos >= d.max) { 623 err = do_convert_inline_dir(dir, ipage, inline_dentry); 624 if (err) 625 return err; 626 err = -EAGAIN; 627 goto out; 628 } 629 630 if (inode) { 631 down_write(&F2FS_I(inode)->i_sem); 632 page = f2fs_init_inode_metadata(inode, dir, fname, ipage); 633 if (IS_ERR(page)) { 634 err = PTR_ERR(page); 635 goto fail; 636 } 637 } 638 639 f2fs_wait_on_page_writeback(ipage, NODE, true, true); 640 641 f2fs_update_dentry(ino, mode, &d, &fname->disk_name, fname->hash, 642 bit_pos); 643 644 set_page_dirty(ipage); 645 646 /* we don't need to mark_inode_dirty now */ 647 if (inode) { 648 f2fs_i_pino_write(inode, dir->i_ino); 649 650 /* synchronize inode page's data from inode cache */ 651 if (is_inode_flag_set(inode, FI_NEW_INODE)) 652 f2fs_update_inode(inode, page); 653 654 f2fs_put_page(page, 1); 655 } 656 657 f2fs_update_parent_metadata(dir, inode, 0); 658 fail: 659 if (inode) 660 up_write(&F2FS_I(inode)->i_sem); 661 out: 662 f2fs_put_page(ipage, 1); 663 return err; 664 } 665 666 void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry, struct page *page, 667 struct inode *dir, struct inode *inode) 668 { 669 struct f2fs_dentry_ptr d; 670 void *inline_dentry; 671 int slots = GET_DENTRY_SLOTS(le16_to_cpu(dentry->name_len)); 672 unsigned int bit_pos; 673 int i; 674 675 lock_page(page); 676 f2fs_wait_on_page_writeback(page, NODE, true, true); 677 678 inline_dentry = inline_data_addr(dir, page); 679 make_dentry_ptr_inline(dir, &d, inline_dentry); 680 681 bit_pos = dentry - d.dentry; 682 for (i = 0; i < slots; i++) 683 __clear_bit_le(bit_pos + i, d.bitmap); 684 685 set_page_dirty(page); 686 f2fs_put_page(page, 1); 687 688 dir->i_ctime = dir->i_mtime = current_time(dir); 689 f2fs_mark_inode_dirty_sync(dir, false); 690 691 if (inode) 692 f2fs_drop_nlink(dir, inode); 693 } 694 695 bool f2fs_empty_inline_dir(struct inode *dir) 696 { 697 struct f2fs_sb_info *sbi = F2FS_I_SB(dir); 698 struct page *ipage; 699 unsigned int bit_pos = 2; 700 void *inline_dentry; 701 struct f2fs_dentry_ptr d; 702 703 ipage = f2fs_get_node_page(sbi, dir->i_ino); 704 if (IS_ERR(ipage)) 705 return false; 706 707 inline_dentry = inline_data_addr(dir, ipage); 708 make_dentry_ptr_inline(dir, &d, inline_dentry); 709 710 bit_pos = find_next_bit_le(d.bitmap, d.max, bit_pos); 711 712 f2fs_put_page(ipage, 1); 713 714 if (bit_pos < d.max) 715 return false; 716 717 return true; 718 } 719 720 int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx, 721 struct fscrypt_str *fstr) 722 { 723 struct inode *inode = file_inode(file); 724 struct page *ipage = NULL; 725 struct f2fs_dentry_ptr d; 726 void *inline_dentry = NULL; 727 int err; 728 729 make_dentry_ptr_inline(inode, &d, inline_dentry); 730 731 if (ctx->pos == d.max) 732 return 0; 733 734 ipage = f2fs_get_node_page(F2FS_I_SB(inode), inode->i_ino); 735 if (IS_ERR(ipage)) 736 return PTR_ERR(ipage); 737 738 /* 739 * f2fs_readdir was protected by inode.i_rwsem, it is safe to access 740 * ipage without page's lock held. 741 */ 742 unlock_page(ipage); 743 744 inline_dentry = inline_data_addr(inode, ipage); 745 746 make_dentry_ptr_inline(inode, &d, inline_dentry); 747 748 err = f2fs_fill_dentries(ctx, &d, 0, fstr); 749 if (!err) 750 ctx->pos = d.max; 751 752 f2fs_put_page(ipage, 0); 753 return err < 0 ? err : 0; 754 } 755 756 int f2fs_inline_data_fiemap(struct inode *inode, 757 struct fiemap_extent_info *fieinfo, __u64 start, __u64 len) 758 { 759 __u64 byteaddr, ilen; 760 __u32 flags = FIEMAP_EXTENT_DATA_INLINE | FIEMAP_EXTENT_NOT_ALIGNED | 761 FIEMAP_EXTENT_LAST; 762 struct node_info ni; 763 struct page *ipage; 764 int err = 0; 765 766 ipage = f2fs_get_node_page(F2FS_I_SB(inode), inode->i_ino); 767 if (IS_ERR(ipage)) 768 return PTR_ERR(ipage); 769 770 if ((S_ISREG(inode->i_mode) || S_ISLNK(inode->i_mode)) && 771 !f2fs_has_inline_data(inode)) { 772 err = -EAGAIN; 773 goto out; 774 } 775 776 if (S_ISDIR(inode->i_mode) && !f2fs_has_inline_dentry(inode)) { 777 err = -EAGAIN; 778 goto out; 779 } 780 781 ilen = min_t(size_t, MAX_INLINE_DATA(inode), i_size_read(inode)); 782 if (start >= ilen) 783 goto out; 784 if (start + len < ilen) 785 ilen = start + len; 786 ilen -= start; 787 788 err = f2fs_get_node_info(F2FS_I_SB(inode), inode->i_ino, &ni); 789 if (err) 790 goto out; 791 792 byteaddr = (__u64)ni.blk_addr << inode->i_sb->s_blocksize_bits; 793 byteaddr += (char *)inline_data_addr(inode, ipage) - 794 (char *)F2FS_INODE(ipage); 795 err = fiemap_fill_next_extent(fieinfo, start, byteaddr, ilen, flags); 796 trace_f2fs_fiemap(inode, start, byteaddr, ilen, flags, err); 797 out: 798 f2fs_put_page(ipage, 1); 799 return err; 800 } 801