Merge tag 'regmap-fix-v5.11-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux/fpc-iii.git] / fs / f2fs / inline.c
blob806ebabf58706c548c4b728e489741f4338dda3a
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 */
9 #include <linux/fs.h>
10 #include <linux/f2fs_fs.h>
11 #include <linux/fiemap.h>
13 #include "f2fs.h"
14 #include "node.h"
15 #include <trace/events/f2fs.h>
17 bool f2fs_may_inline_data(struct inode *inode)
19 if (f2fs_is_atomic_file(inode))
20 return false;
22 if (!S_ISREG(inode->i_mode) && !S_ISLNK(inode->i_mode))
23 return false;
25 if (i_size_read(inode) > MAX_INLINE_DATA(inode))
26 return false;
28 if (f2fs_post_read_required(inode))
29 return false;
31 return true;
34 bool f2fs_may_inline_dentry(struct inode *inode)
36 if (!test_opt(F2FS_I_SB(inode), INLINE_DENTRY))
37 return false;
39 if (!S_ISDIR(inode->i_mode))
40 return false;
42 return true;
45 void f2fs_do_read_inline_data(struct page *page, struct page *ipage)
47 struct inode *inode = page->mapping->host;
48 void *src_addr, *dst_addr;
50 if (PageUptodate(page))
51 return;
53 f2fs_bug_on(F2FS_P_SB(page), page->index);
55 zero_user_segment(page, MAX_INLINE_DATA(inode), PAGE_SIZE);
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);
67 void f2fs_truncate_inline_inode(struct inode *inode,
68 struct page *ipage, u64 from)
70 void *addr;
72 if (from >= MAX_INLINE_DATA(inode))
73 return;
75 addr = inline_data_addr(inode, ipage);
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);
81 if (from == 0)
82 clear_inode_flag(inode, FI_DATA_EXIST);
85 int f2fs_read_inline_data(struct inode *inode, struct page *page)
87 struct page *ipage;
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);
95 if (!f2fs_has_inline_data(inode)) {
96 f2fs_put_page(ipage, 1);
97 return -EAGAIN;
100 if (page->index)
101 zero_user_segment(page, 0, PAGE_SIZE);
102 else
103 f2fs_do_read_inline_data(page, ipage);
105 if (!PageUptodate(page))
106 SetPageUptodate(page);
107 f2fs_put_page(ipage, 1);
108 unlock_page(page);
109 return 0;
112 int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page)
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,
124 struct node_info ni;
125 int dirty, err;
127 if (!f2fs_exist_data(dn->inode))
128 goto clear_out;
130 err = f2fs_reserve_block(dn, 0);
131 if (err)
132 return err;
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;
141 fio.version = ni.version;
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;
151 f2fs_bug_on(F2FS_P_SB(page), PageWriteback(page));
153 f2fs_do_read_inline_data(page, dn->inode_page);
154 set_page_dirty(page);
156 /* clear dirty state */
157 dirty = clear_page_dirty_for_io(page);
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);
171 /* this converted inline_data should be recovered. */
172 set_inode_flag(dn->inode, FI_APPEND_WRITE);
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;
184 int f2fs_convert_inline_inode(struct inode *inode)
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;
191 if (!f2fs_has_inline_data(inode) ||
192 f2fs_hw_is_readonly(sbi) || f2fs_readonly(sbi->sb))
193 return 0;
195 page = f2fs_grab_cache_page(inode->i_mapping, 0, false);
196 if (!page)
197 return -ENOMEM;
199 f2fs_lock_op(sbi);
201 ipage = f2fs_get_node_page(sbi, inode->i_ino);
202 if (IS_ERR(ipage)) {
203 err = PTR_ERR(ipage);
204 goto out;
207 set_new_dnode(&dn, inode, ipage, ipage, 0);
209 if (f2fs_has_inline_data(inode))
210 err = f2fs_convert_inline_page(&dn, page);
212 f2fs_put_dnode(&dn);
213 out:
214 f2fs_unlock_op(sbi);
216 f2fs_put_page(page, 1);
218 f2fs_balance_fs(sbi, dn.node_changed);
220 return err;
223 int f2fs_write_inline_data(struct inode *inode, struct page *page)
225 void *src_addr, *dst_addr;
226 struct dnode_of_data dn;
227 int err;
229 set_new_dnode(&dn, inode, NULL, NULL, 0);
230 err = f2fs_get_dnode_of_data(&dn, 0, LOOKUP_NODE);
231 if (err)
232 return err;
234 if (!f2fs_has_inline_data(inode)) {
235 f2fs_put_dnode(&dn);
236 return -EAGAIN;
239 f2fs_bug_on(F2FS_I_SB(inode), page->index);
241 f2fs_wait_on_page_writeback(dn.inode_page, NODE, true, true);
242 src_addr = kmap_atomic(page);
243 dst_addr = inline_data_addr(inode, dn.inode_page);
244 memcpy(dst_addr, src_addr, MAX_INLINE_DATA(inode));
245 kunmap_atomic(src_addr);
246 set_page_dirty(dn.inode_page);
248 f2fs_clear_page_cache_dirty_tag(page);
250 set_inode_flag(inode, FI_APPEND_WRITE);
251 set_inode_flag(inode, FI_DATA_EXIST);
253 clear_inline_node(dn.inode_page);
254 f2fs_put_dnode(&dn);
255 return 0;
258 int f2fs_recover_inline_data(struct inode *inode, struct page *npage)
260 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
261 struct f2fs_inode *ri = NULL;
262 void *src_addr, *dst_addr;
263 struct page *ipage;
266 * The inline_data recovery policy is as follows.
267 * [prev.] [next] of inline_data flag
268 * o o -> recover inline_data
269 * o x -> remove inline_data, and then recover data blocks
270 * x o -> remove data blocks, and then recover inline_data
271 * x x -> recover data blocks
273 if (IS_INODE(npage))
274 ri = F2FS_INODE(npage);
276 if (f2fs_has_inline_data(inode) &&
277 ri && (ri->i_inline & F2FS_INLINE_DATA)) {
278 process_inline:
279 ipage = f2fs_get_node_page(sbi, inode->i_ino);
280 if (IS_ERR(ipage))
281 return PTR_ERR(ipage);
283 f2fs_wait_on_page_writeback(ipage, NODE, true, true);
285 src_addr = inline_data_addr(inode, npage);
286 dst_addr = inline_data_addr(inode, ipage);
287 memcpy(dst_addr, src_addr, MAX_INLINE_DATA(inode));
289 set_inode_flag(inode, FI_INLINE_DATA);
290 set_inode_flag(inode, FI_DATA_EXIST);
292 set_page_dirty(ipage);
293 f2fs_put_page(ipage, 1);
294 return 1;
297 if (f2fs_has_inline_data(inode)) {
298 ipage = f2fs_get_node_page(sbi, inode->i_ino);
299 if (IS_ERR(ipage))
300 return PTR_ERR(ipage);
301 f2fs_truncate_inline_inode(inode, ipage, 0);
302 stat_dec_inline_inode(inode);
303 clear_inode_flag(inode, FI_INLINE_DATA);
304 f2fs_put_page(ipage, 1);
305 } else if (ri && (ri->i_inline & F2FS_INLINE_DATA)) {
306 int ret;
308 ret = f2fs_truncate_blocks(inode, 0, false);
309 if (ret)
310 return ret;
311 stat_inc_inline_inode(inode);
312 goto process_inline;
314 return 0;
317 struct f2fs_dir_entry *f2fs_find_in_inline_dir(struct inode *dir,
318 const struct f2fs_filename *fname,
319 struct page **res_page)
321 struct f2fs_sb_info *sbi = F2FS_SB(dir->i_sb);
322 struct f2fs_dir_entry *de;
323 struct f2fs_dentry_ptr d;
324 struct page *ipage;
325 void *inline_dentry;
327 ipage = f2fs_get_node_page(sbi, dir->i_ino);
328 if (IS_ERR(ipage)) {
329 *res_page = ipage;
330 return NULL;
333 inline_dentry = inline_data_addr(dir, ipage);
335 make_dentry_ptr_inline(dir, &d, inline_dentry);
336 de = f2fs_find_target_dentry(&d, fname, NULL);
337 unlock_page(ipage);
338 if (IS_ERR(de)) {
339 *res_page = ERR_CAST(de);
340 de = NULL;
342 if (de)
343 *res_page = ipage;
344 else
345 f2fs_put_page(ipage, 0);
347 return de;
350 int f2fs_make_empty_inline_dir(struct inode *inode, struct inode *parent,
351 struct page *ipage)
353 struct f2fs_dentry_ptr d;
354 void *inline_dentry;
356 inline_dentry = inline_data_addr(inode, ipage);
358 make_dentry_ptr_inline(inode, &d, inline_dentry);
359 f2fs_do_make_empty_dir(inode, parent, &d);
361 set_page_dirty(ipage);
363 /* update i_size to MAX_INLINE_DATA */
364 if (i_size_read(inode) < MAX_INLINE_DATA(inode))
365 f2fs_i_size_write(inode, MAX_INLINE_DATA(inode));
366 return 0;
370 * NOTE: ipage is grabbed by caller, but if any error occurs, we should
371 * release ipage in this function.
373 static int f2fs_move_inline_dirents(struct inode *dir, struct page *ipage,
374 void *inline_dentry)
376 struct page *page;
377 struct dnode_of_data dn;
378 struct f2fs_dentry_block *dentry_blk;
379 struct f2fs_dentry_ptr src, dst;
380 int err;
382 page = f2fs_grab_cache_page(dir->i_mapping, 0, true);
383 if (!page) {
384 f2fs_put_page(ipage, 1);
385 return -ENOMEM;
388 set_new_dnode(&dn, dir, ipage, NULL, 0);
389 err = f2fs_reserve_block(&dn, 0);
390 if (err)
391 goto out;
393 if (unlikely(dn.data_blkaddr != NEW_ADDR)) {
394 f2fs_put_dnode(&dn);
395 set_sbi_flag(F2FS_P_SB(page), SBI_NEED_FSCK);
396 f2fs_warn(F2FS_P_SB(page), "%s: corrupted inline inode ino=%lx, i_addr[0]:0x%x, run fsck to fix.",
397 __func__, dir->i_ino, dn.data_blkaddr);
398 err = -EFSCORRUPTED;
399 goto out;
402 f2fs_wait_on_page_writeback(page, DATA, true, true);
404 dentry_blk = page_address(page);
406 make_dentry_ptr_inline(dir, &src, inline_dentry);
407 make_dentry_ptr_block(dir, &dst, dentry_blk);
409 /* copy data from inline dentry block to new dentry block */
410 memcpy(dst.bitmap, src.bitmap, src.nr_bitmap);
411 memset(dst.bitmap + src.nr_bitmap, 0, dst.nr_bitmap - src.nr_bitmap);
413 * we do not need to zero out remainder part of dentry and filename
414 * field, since we have used bitmap for marking the usage status of
415 * them, besides, we can also ignore copying/zeroing reserved space
416 * of dentry block, because them haven't been used so far.
418 memcpy(dst.dentry, src.dentry, SIZE_OF_DIR_ENTRY * src.max);
419 memcpy(dst.filename, src.filename, src.max * F2FS_SLOT_LEN);
421 if (!PageUptodate(page))
422 SetPageUptodate(page);
423 set_page_dirty(page);
425 /* clear inline dir and flag after data writeback */
426 f2fs_truncate_inline_inode(dir, ipage, 0);
428 stat_dec_inline_dir(dir);
429 clear_inode_flag(dir, FI_INLINE_DENTRY);
432 * should retrieve reserved space which was used to keep
433 * inline_dentry's structure for backward compatibility.
435 if (!f2fs_sb_has_flexible_inline_xattr(F2FS_I_SB(dir)) &&
436 !f2fs_has_inline_xattr(dir))
437 F2FS_I(dir)->i_inline_xattr_size = 0;
439 f2fs_i_depth_write(dir, 1);
440 if (i_size_read(dir) < PAGE_SIZE)
441 f2fs_i_size_write(dir, PAGE_SIZE);
442 out:
443 f2fs_put_page(page, 1);
444 return err;
447 static int f2fs_add_inline_entries(struct inode *dir, void *inline_dentry)
449 struct f2fs_dentry_ptr d;
450 unsigned long bit_pos = 0;
451 int err = 0;
453 make_dentry_ptr_inline(dir, &d, inline_dentry);
455 while (bit_pos < d.max) {
456 struct f2fs_dir_entry *de;
457 struct f2fs_filename fname;
458 nid_t ino;
459 umode_t fake_mode;
461 if (!test_bit_le(bit_pos, d.bitmap)) {
462 bit_pos++;
463 continue;
466 de = &d.dentry[bit_pos];
468 if (unlikely(!de->name_len)) {
469 bit_pos++;
470 continue;
474 * We only need the disk_name and hash to move the dentry.
475 * We don't need the original or casefolded filenames.
477 memset(&fname, 0, sizeof(fname));
478 fname.disk_name.name = d.filename[bit_pos];
479 fname.disk_name.len = le16_to_cpu(de->name_len);
480 fname.hash = de->hash_code;
482 ino = le32_to_cpu(de->ino);
483 fake_mode = f2fs_get_de_type(de) << S_SHIFT;
485 err = f2fs_add_regular_entry(dir, &fname, NULL, ino, fake_mode);
486 if (err)
487 goto punch_dentry_pages;
489 bit_pos += GET_DENTRY_SLOTS(le16_to_cpu(de->name_len));
491 return 0;
492 punch_dentry_pages:
493 truncate_inode_pages(&dir->i_data, 0);
494 f2fs_truncate_blocks(dir, 0, false);
495 f2fs_remove_dirty_inode(dir);
496 return err;
499 static int f2fs_move_rehashed_dirents(struct inode *dir, struct page *ipage,
500 void *inline_dentry)
502 void *backup_dentry;
503 int err;
505 backup_dentry = f2fs_kmalloc(F2FS_I_SB(dir),
506 MAX_INLINE_DATA(dir), GFP_F2FS_ZERO);
507 if (!backup_dentry) {
508 f2fs_put_page(ipage, 1);
509 return -ENOMEM;
512 memcpy(backup_dentry, inline_dentry, MAX_INLINE_DATA(dir));
513 f2fs_truncate_inline_inode(dir, ipage, 0);
515 unlock_page(ipage);
517 err = f2fs_add_inline_entries(dir, backup_dentry);
518 if (err)
519 goto recover;
521 lock_page(ipage);
523 stat_dec_inline_dir(dir);
524 clear_inode_flag(dir, FI_INLINE_DENTRY);
527 * should retrieve reserved space which was used to keep
528 * inline_dentry's structure for backward compatibility.
530 if (!f2fs_sb_has_flexible_inline_xattr(F2FS_I_SB(dir)) &&
531 !f2fs_has_inline_xattr(dir))
532 F2FS_I(dir)->i_inline_xattr_size = 0;
534 kfree(backup_dentry);
535 return 0;
536 recover:
537 lock_page(ipage);
538 f2fs_wait_on_page_writeback(ipage, NODE, true, true);
539 memcpy(inline_dentry, backup_dentry, MAX_INLINE_DATA(dir));
540 f2fs_i_depth_write(dir, 0);
541 f2fs_i_size_write(dir, MAX_INLINE_DATA(dir));
542 set_page_dirty(ipage);
543 f2fs_put_page(ipage, 1);
545 kfree(backup_dentry);
546 return err;
549 static int do_convert_inline_dir(struct inode *dir, struct page *ipage,
550 void *inline_dentry)
552 if (!F2FS_I(dir)->i_dir_level)
553 return f2fs_move_inline_dirents(dir, ipage, inline_dentry);
554 else
555 return f2fs_move_rehashed_dirents(dir, ipage, inline_dentry);
558 int f2fs_try_convert_inline_dir(struct inode *dir, struct dentry *dentry)
560 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
561 struct page *ipage;
562 struct f2fs_filename fname;
563 void *inline_dentry = NULL;
564 int err = 0;
566 if (!f2fs_has_inline_dentry(dir))
567 return 0;
569 f2fs_lock_op(sbi);
571 err = f2fs_setup_filename(dir, &dentry->d_name, 0, &fname);
572 if (err)
573 goto out;
575 ipage = f2fs_get_node_page(sbi, dir->i_ino);
576 if (IS_ERR(ipage)) {
577 err = PTR_ERR(ipage);
578 goto out_fname;
581 if (f2fs_has_enough_room(dir, ipage, &fname)) {
582 f2fs_put_page(ipage, 1);
583 goto out_fname;
586 inline_dentry = inline_data_addr(dir, ipage);
588 err = do_convert_inline_dir(dir, ipage, inline_dentry);
589 if (!err)
590 f2fs_put_page(ipage, 1);
591 out_fname:
592 f2fs_free_filename(&fname);
593 out:
594 f2fs_unlock_op(sbi);
595 return err;
598 int f2fs_add_inline_entry(struct inode *dir, const struct f2fs_filename *fname,
599 struct inode *inode, nid_t ino, umode_t mode)
601 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
602 struct page *ipage;
603 unsigned int bit_pos;
604 void *inline_dentry = NULL;
605 struct f2fs_dentry_ptr d;
606 int slots = GET_DENTRY_SLOTS(fname->disk_name.len);
607 struct page *page = NULL;
608 int err = 0;
610 ipage = f2fs_get_node_page(sbi, dir->i_ino);
611 if (IS_ERR(ipage))
612 return PTR_ERR(ipage);
614 inline_dentry = inline_data_addr(dir, ipage);
615 make_dentry_ptr_inline(dir, &d, inline_dentry);
617 bit_pos = f2fs_room_for_filename(d.bitmap, slots, d.max);
618 if (bit_pos >= d.max) {
619 err = do_convert_inline_dir(dir, ipage, inline_dentry);
620 if (err)
621 return err;
622 err = -EAGAIN;
623 goto out;
626 if (inode) {
627 down_write(&F2FS_I(inode)->i_sem);
628 page = f2fs_init_inode_metadata(inode, dir, fname, ipage);
629 if (IS_ERR(page)) {
630 err = PTR_ERR(page);
631 goto fail;
635 f2fs_wait_on_page_writeback(ipage, NODE, true, true);
637 f2fs_update_dentry(ino, mode, &d, &fname->disk_name, fname->hash,
638 bit_pos);
640 set_page_dirty(ipage);
642 /* we don't need to mark_inode_dirty now */
643 if (inode) {
644 f2fs_i_pino_write(inode, dir->i_ino);
646 /* synchronize inode page's data from inode cache */
647 if (is_inode_flag_set(inode, FI_NEW_INODE))
648 f2fs_update_inode(inode, page);
650 f2fs_put_page(page, 1);
653 f2fs_update_parent_metadata(dir, inode, 0);
654 fail:
655 if (inode)
656 up_write(&F2FS_I(inode)->i_sem);
657 out:
658 f2fs_put_page(ipage, 1);
659 return err;
662 void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry, struct page *page,
663 struct inode *dir, struct inode *inode)
665 struct f2fs_dentry_ptr d;
666 void *inline_dentry;
667 int slots = GET_DENTRY_SLOTS(le16_to_cpu(dentry->name_len));
668 unsigned int bit_pos;
669 int i;
671 lock_page(page);
672 f2fs_wait_on_page_writeback(page, NODE, true, true);
674 inline_dentry = inline_data_addr(dir, page);
675 make_dentry_ptr_inline(dir, &d, inline_dentry);
677 bit_pos = dentry - d.dentry;
678 for (i = 0; i < slots; i++)
679 __clear_bit_le(bit_pos + i, d.bitmap);
681 set_page_dirty(page);
682 f2fs_put_page(page, 1);
684 dir->i_ctime = dir->i_mtime = current_time(dir);
685 f2fs_mark_inode_dirty_sync(dir, false);
687 if (inode)
688 f2fs_drop_nlink(dir, inode);
691 bool f2fs_empty_inline_dir(struct inode *dir)
693 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
694 struct page *ipage;
695 unsigned int bit_pos = 2;
696 void *inline_dentry;
697 struct f2fs_dentry_ptr d;
699 ipage = f2fs_get_node_page(sbi, dir->i_ino);
700 if (IS_ERR(ipage))
701 return false;
703 inline_dentry = inline_data_addr(dir, ipage);
704 make_dentry_ptr_inline(dir, &d, inline_dentry);
706 bit_pos = find_next_bit_le(d.bitmap, d.max, bit_pos);
708 f2fs_put_page(ipage, 1);
710 if (bit_pos < d.max)
711 return false;
713 return true;
716 int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx,
717 struct fscrypt_str *fstr)
719 struct inode *inode = file_inode(file);
720 struct page *ipage = NULL;
721 struct f2fs_dentry_ptr d;
722 void *inline_dentry = NULL;
723 int err;
725 make_dentry_ptr_inline(inode, &d, inline_dentry);
727 if (ctx->pos == d.max)
728 return 0;
730 ipage = f2fs_get_node_page(F2FS_I_SB(inode), inode->i_ino);
731 if (IS_ERR(ipage))
732 return PTR_ERR(ipage);
735 * f2fs_readdir was protected by inode.i_rwsem, it is safe to access
736 * ipage without page's lock held.
738 unlock_page(ipage);
740 inline_dentry = inline_data_addr(inode, ipage);
742 make_dentry_ptr_inline(inode, &d, inline_dentry);
744 err = f2fs_fill_dentries(ctx, &d, 0, fstr);
745 if (!err)
746 ctx->pos = d.max;
748 f2fs_put_page(ipage, 0);
749 return err < 0 ? err : 0;
752 int f2fs_inline_data_fiemap(struct inode *inode,
753 struct fiemap_extent_info *fieinfo, __u64 start, __u64 len)
755 __u64 byteaddr, ilen;
756 __u32 flags = FIEMAP_EXTENT_DATA_INLINE | FIEMAP_EXTENT_NOT_ALIGNED |
757 FIEMAP_EXTENT_LAST;
758 struct node_info ni;
759 struct page *ipage;
760 int err = 0;
762 ipage = f2fs_get_node_page(F2FS_I_SB(inode), inode->i_ino);
763 if (IS_ERR(ipage))
764 return PTR_ERR(ipage);
766 if ((S_ISREG(inode->i_mode) || S_ISLNK(inode->i_mode)) &&
767 !f2fs_has_inline_data(inode)) {
768 err = -EAGAIN;
769 goto out;
772 if (S_ISDIR(inode->i_mode) && !f2fs_has_inline_dentry(inode)) {
773 err = -EAGAIN;
774 goto out;
777 ilen = min_t(size_t, MAX_INLINE_DATA(inode), i_size_read(inode));
778 if (start >= ilen)
779 goto out;
780 if (start + len < ilen)
781 ilen = start + len;
782 ilen -= start;
784 err = f2fs_get_node_info(F2FS_I_SB(inode), inode->i_ino, &ni);
785 if (err)
786 goto out;
788 byteaddr = (__u64)ni.blk_addr << inode->i_sb->s_blocksize_bits;
789 byteaddr += (char *)inline_data_addr(inode, ipage) -
790 (char *)F2FS_INODE(ipage);
791 err = fiemap_fill_next_extent(fieinfo, start, byteaddr, ilen, flags);
792 trace_f2fs_fiemap(inode, start, byteaddr, ilen, flags, err);
793 out:
794 f2fs_put_page(ipage, 1);
795 return err;