1 /*
2 * fs/f2fs/inline.c
3 * Copyright (c) 2013, Intel Corporation
4 * Authors: Huajun Li <huajun.li@intel.com>
5 * Haicheng Li <haicheng.li@intel.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11 #include <linux/fs.h>
12 #include <linux/f2fs_fs.h>
13
14 #include "f2fs.h"
15 #include "node.h"
16
f2fs_may_inline_data(struct inode * inode)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
f2fs_may_inline_dentry(struct inode * inode)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
f2fs_do_read_inline_data(struct page * page,struct page * ipage)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
f2fs_truncate_inline_inode(struct inode * inode,struct page * ipage,u64 from)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);
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
f2fs_read_inline_data(struct inode * inode,struct page * page)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
f2fs_convert_inline_page(struct dnode_of_data * dn,struct page * page)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_put_dnode(dn);
137 return err;
138 }
139
140 fio.version = ni.version;
141
142 if (unlikely(dn->data_blkaddr != NEW_ADDR)) {
143 f2fs_put_dnode(dn);
144 set_sbi_flag(fio.sbi, SBI_NEED_FSCK);
145 f2fs_msg(fio.sbi->sb, KERN_WARNING,
146 "%s: corrupted inline inode ino=%lx, i_addr[0]:0x%x, "
147 "run fsck to fix.",
148 __func__, dn->inode->i_ino, dn->data_blkaddr);
149 return -EINVAL;
150 }
151
152 f2fs_bug_on(F2FS_P_SB(page), PageWriteback(page));
153
154 f2fs_do_read_inline_data(page, dn->inode_page);
155 set_page_dirty(page);
156
157 /* clear dirty state */
158 dirty = clear_page_dirty_for_io(page);
159
160 /* write data page to try to make data consistent */
161 set_page_writeback(page);
162 ClearPageError(page);
163 fio.old_blkaddr = dn->data_blkaddr;
164 set_inode_flag(dn->inode, FI_HOT_DATA);
165 f2fs_outplace_write_data(dn, &fio);
166 f2fs_wait_on_page_writeback(page, DATA, true);
167 if (dirty) {
168 inode_dec_dirty_pages(dn->inode);
169 f2fs_remove_dirty_inode(dn->inode);
170 }
171
172 /* this converted inline_data should be recovered. */
173 set_inode_flag(dn->inode, FI_APPEND_WRITE);
174
175 /* clear inline data and flag after data writeback */
176 f2fs_truncate_inline_inode(dn->inode, dn->inode_page, 0);
177 clear_inline_node(dn->inode_page);
178 clear_out:
179 stat_dec_inline_inode(dn->inode);
180 clear_inode_flag(dn->inode, FI_INLINE_DATA);
181 f2fs_put_dnode(dn);
182 return 0;
183 }
184
f2fs_convert_inline_inode(struct inode * inode)185 int f2fs_convert_inline_inode(struct inode *inode)
186 {
187 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
188 struct dnode_of_data dn;
189 struct page *ipage, *page;
190 int err = 0;
191
192 if (!f2fs_has_inline_data(inode))
193 return 0;
194
195 page = f2fs_grab_cache_page(inode->i_mapping, 0, false);
196 if (!page)
197 return -ENOMEM;
198
199 f2fs_lock_op(sbi);
200
201 ipage = f2fs_get_node_page(sbi, inode->i_ino);
202 if (IS_ERR(ipage)) {
203 err = PTR_ERR(ipage);
204 goto out;
205 }
206
207 set_new_dnode(&dn, inode, ipage, ipage, 0);
208
209 if (f2fs_has_inline_data(inode))
210 err = f2fs_convert_inline_page(&dn, page);
211
212 f2fs_put_dnode(&dn);
213 out:
214 f2fs_unlock_op(sbi);
215
216 f2fs_put_page(page, 1);
217
218 f2fs_balance_fs(sbi, dn.node_changed);
219
220 return err;
221 }
222
f2fs_write_inline_data(struct inode * inode,struct page * page)223 int f2fs_write_inline_data(struct inode *inode, struct page *page)
224 {
225 void *src_addr, *dst_addr;
226 struct dnode_of_data dn;
227 int err;
228
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;
233
234 if (!f2fs_has_inline_data(inode)) {
235 f2fs_put_dnode(&dn);
236 return -EAGAIN;
237 }
238
239 f2fs_bug_on(F2FS_I_SB(inode), page->index);
240
241 f2fs_wait_on_page_writeback(dn.inode_page, NODE, 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);
247
248 f2fs_clear_radix_tree_dirty_tag(page);
249
250 set_inode_flag(inode, FI_APPEND_WRITE);
251 set_inode_flag(inode, FI_DATA_EXIST);
252
253 clear_inline_node(dn.inode_page);
254 f2fs_put_dnode(&dn);
255 return 0;
256 }
257
f2fs_recover_inline_data(struct inode * inode,struct page * npage)258 bool f2fs_recover_inline_data(struct inode *inode, struct page *npage)
259 {
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;
264
265 /*
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 inline_data, and then recover inline_data
271 * x x -> recover data blocks
272 */
273 if (IS_INODE(npage))
274 ri = F2FS_INODE(npage);
275
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 f2fs_bug_on(sbi, IS_ERR(ipage));
281
282 f2fs_wait_on_page_writeback(ipage, NODE, true);
283
284 src_addr = inline_data_addr(inode, npage);
285 dst_addr = inline_data_addr(inode, ipage);
286 memcpy(dst_addr, src_addr, MAX_INLINE_DATA(inode));
287
288 set_inode_flag(inode, FI_INLINE_DATA);
289 set_inode_flag(inode, FI_DATA_EXIST);
290
291 set_page_dirty(ipage);
292 f2fs_put_page(ipage, 1);
293 return true;
294 }
295
296 if (f2fs_has_inline_data(inode)) {
297 ipage = f2fs_get_node_page(sbi, inode->i_ino);
298 f2fs_bug_on(sbi, IS_ERR(ipage));
299 f2fs_truncate_inline_inode(inode, ipage, 0);
300 clear_inode_flag(inode, FI_INLINE_DATA);
301 f2fs_put_page(ipage, 1);
302 } else if (ri && (ri->i_inline & F2FS_INLINE_DATA)) {
303 if (f2fs_truncate_blocks(inode, 0, false))
304 return false;
305 goto process_inline;
306 }
307 return false;
308 }
309
f2fs_find_in_inline_dir(struct inode * dir,struct fscrypt_name * fname,struct page ** res_page)310 struct f2fs_dir_entry *f2fs_find_in_inline_dir(struct inode *dir,
311 struct fscrypt_name *fname, struct page **res_page)
312 {
313 struct f2fs_sb_info *sbi = F2FS_SB(dir->i_sb);
314 struct qstr name = FSTR_TO_QSTR(&fname->disk_name);
315 struct f2fs_dir_entry *de;
316 struct f2fs_dentry_ptr d;
317 struct page *ipage;
318 void *inline_dentry;
319 f2fs_hash_t namehash;
320
321 ipage = f2fs_get_node_page(sbi, dir->i_ino);
322 if (IS_ERR(ipage)) {
323 *res_page = ipage;
324 return NULL;
325 }
326
327 namehash = f2fs_dentry_hash(&name, fname);
328
329 inline_dentry = inline_data_addr(dir, ipage);
330
331 make_dentry_ptr_inline(dir, &d, inline_dentry);
332 de = f2fs_find_target_dentry(fname, namehash, NULL, &d);
333 unlock_page(ipage);
334 if (de)
335 *res_page = ipage;
336 else
337 f2fs_put_page(ipage, 0);
338
339 return de;
340 }
341
f2fs_make_empty_inline_dir(struct inode * inode,struct inode * parent,struct page * ipage)342 int f2fs_make_empty_inline_dir(struct inode *inode, struct inode *parent,
343 struct page *ipage)
344 {
345 struct f2fs_dentry_ptr d;
346 void *inline_dentry;
347
348 inline_dentry = inline_data_addr(inode, ipage);
349
350 make_dentry_ptr_inline(inode, &d, inline_dentry);
351 f2fs_do_make_empty_dir(inode, parent, &d);
352
353 set_page_dirty(ipage);
354
355 /* update i_size to MAX_INLINE_DATA */
356 if (i_size_read(inode) < MAX_INLINE_DATA(inode))
357 f2fs_i_size_write(inode, MAX_INLINE_DATA(inode));
358 return 0;
359 }
360
361 /*
362 * NOTE: ipage is grabbed by caller, but if any error occurs, we should
363 * release ipage in this function.
364 */
f2fs_move_inline_dirents(struct inode * dir,struct page * ipage,void * inline_dentry)365 static int f2fs_move_inline_dirents(struct inode *dir, struct page *ipage,
366 void *inline_dentry)
367 {
368 struct page *page;
369 struct dnode_of_data dn;
370 struct f2fs_dentry_block *dentry_blk;
371 struct f2fs_dentry_ptr src, dst;
372 int err;
373
374 page = f2fs_grab_cache_page(dir->i_mapping, 0, false);
375 if (!page) {
376 f2fs_put_page(ipage, 1);
377 return -ENOMEM;
378 }
379
380 set_new_dnode(&dn, dir, ipage, NULL, 0);
381 err = f2fs_reserve_block(&dn, 0);
382 if (err)
383 goto out;
384
385 if (unlikely(dn.data_blkaddr != NEW_ADDR)) {
386 f2fs_put_dnode(&dn);
387 set_sbi_flag(F2FS_P_SB(page), SBI_NEED_FSCK);
388 f2fs_msg(F2FS_P_SB(page)->sb, KERN_WARNING,
389 "%s: corrupted inline inode ino=%lx, i_addr[0]:0x%x, "
390 "run fsck to fix.",
391 __func__, dir->i_ino, dn.data_blkaddr);
392 err = -EINVAL;
393 goto out;
394 }
395
396 f2fs_wait_on_page_writeback(page, DATA, true);
397
398 dentry_blk = page_address(page);
399
400 make_dentry_ptr_inline(dir, &src, inline_dentry);
401 make_dentry_ptr_block(dir, &dst, dentry_blk);
402
403 /* copy data from inline dentry block to new dentry block */
404 memcpy(dst.bitmap, src.bitmap, src.nr_bitmap);
405 memset(dst.bitmap + src.nr_bitmap, 0, dst.nr_bitmap - src.nr_bitmap);
406 /*
407 * we do not need to zero out remainder part of dentry and filename
408 * field, since we have used bitmap for marking the usage status of
409 * them, besides, we can also ignore copying/zeroing reserved space
410 * of dentry block, because them haven't been used so far.
411 */
412 memcpy(dst.dentry, src.dentry, SIZE_OF_DIR_ENTRY * src.max);
413 memcpy(dst.filename, src.filename, src.max * F2FS_SLOT_LEN);
414
415 if (!PageUptodate(page))
416 SetPageUptodate(page);
417 set_page_dirty(page);
418
419 /* clear inline dir and flag after data writeback */
420 f2fs_truncate_inline_inode(dir, ipage, 0);
421
422 stat_dec_inline_dir(dir);
423 clear_inode_flag(dir, FI_INLINE_DENTRY);
424
425 f2fs_i_depth_write(dir, 1);
426 if (i_size_read(dir) < PAGE_SIZE)
427 f2fs_i_size_write(dir, PAGE_SIZE);
428 out:
429 f2fs_put_page(page, 1);
430 return err;
431 }
432
f2fs_add_inline_entries(struct inode * dir,void * inline_dentry)433 static int f2fs_add_inline_entries(struct inode *dir, void *inline_dentry)
434 {
435 struct f2fs_dentry_ptr d;
436 unsigned long bit_pos = 0;
437 int err = 0;
438
439 make_dentry_ptr_inline(dir, &d, inline_dentry);
440
441 while (bit_pos < d.max) {
442 struct f2fs_dir_entry *de;
443 struct qstr new_name;
444 nid_t ino;
445 umode_t fake_mode;
446
447 if (!test_bit_le(bit_pos, d.bitmap)) {
448 bit_pos++;
449 continue;
450 }
451
452 de = &d.dentry[bit_pos];
453
454 if (unlikely(!de->name_len)) {
455 bit_pos++;
456 continue;
457 }
458
459 new_name.name = d.filename[bit_pos];
460 new_name.len = le16_to_cpu(de->name_len);
461
462 ino = le32_to_cpu(de->ino);
463 fake_mode = f2fs_get_de_type(de) << S_SHIFT;
464
465 err = f2fs_add_regular_entry(dir, &new_name, NULL, NULL,
466 ino, fake_mode);
467 if (err)
468 goto punch_dentry_pages;
469
470 bit_pos += GET_DENTRY_SLOTS(le16_to_cpu(de->name_len));
471 }
472 return 0;
473 punch_dentry_pages:
474 truncate_inode_pages(&dir->i_data, 0);
475 f2fs_truncate_blocks(dir, 0, false);
476 f2fs_remove_dirty_inode(dir);
477 return err;
478 }
479
f2fs_move_rehashed_dirents(struct inode * dir,struct page * ipage,void * inline_dentry)480 static int f2fs_move_rehashed_dirents(struct inode *dir, struct page *ipage,
481 void *inline_dentry)
482 {
483 void *backup_dentry;
484 int err;
485
486 backup_dentry = f2fs_kmalloc(F2FS_I_SB(dir),
487 MAX_INLINE_DATA(dir), GFP_F2FS_ZERO);
488 if (!backup_dentry) {
489 f2fs_put_page(ipage, 1);
490 return -ENOMEM;
491 }
492
493 memcpy(backup_dentry, inline_dentry, MAX_INLINE_DATA(dir));
494 f2fs_truncate_inline_inode(dir, ipage, 0);
495
496 unlock_page(ipage);
497
498 err = f2fs_add_inline_entries(dir, backup_dentry);
499 if (err)
500 goto recover;
501
502 lock_page(ipage);
503
504 stat_dec_inline_dir(dir);
505 clear_inode_flag(dir, FI_INLINE_DENTRY);
506 kfree(backup_dentry);
507 return 0;
508 recover:
509 lock_page(ipage);
510 f2fs_wait_on_page_writeback(ipage, NODE, true);
511 memcpy(inline_dentry, backup_dentry, MAX_INLINE_DATA(dir));
512 f2fs_i_depth_write(dir, 0);
513 f2fs_i_size_write(dir, MAX_INLINE_DATA(dir));
514 set_page_dirty(ipage);
515 f2fs_put_page(ipage, 1);
516
517 kfree(backup_dentry);
518 return err;
519 }
520
f2fs_convert_inline_dir(struct inode * dir,struct page * ipage,void * inline_dentry)521 static int f2fs_convert_inline_dir(struct inode *dir, struct page *ipage,
522 void *inline_dentry)
523 {
524 if (!F2FS_I(dir)->i_dir_level)
525 return f2fs_move_inline_dirents(dir, ipage, inline_dentry);
526 else
527 return f2fs_move_rehashed_dirents(dir, ipage, inline_dentry);
528 }
529
f2fs_add_inline_entry(struct inode * dir,const struct qstr * new_name,const struct qstr * orig_name,struct inode * inode,nid_t ino,umode_t mode)530 int f2fs_add_inline_entry(struct inode *dir, const struct qstr *new_name,
531 const struct qstr *orig_name,
532 struct inode *inode, nid_t ino, umode_t mode)
533 {
534 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
535 struct page *ipage;
536 unsigned int bit_pos;
537 f2fs_hash_t name_hash;
538 void *inline_dentry = NULL;
539 struct f2fs_dentry_ptr d;
540 int slots = GET_DENTRY_SLOTS(new_name->len);
541 struct page *page = NULL;
542 int err = 0;
543
544 ipage = f2fs_get_node_page(sbi, dir->i_ino);
545 if (IS_ERR(ipage))
546 return PTR_ERR(ipage);
547
548 inline_dentry = inline_data_addr(dir, ipage);
549 make_dentry_ptr_inline(dir, &d, inline_dentry);
550
551 bit_pos = f2fs_room_for_filename(d.bitmap, slots, d.max);
552 if (bit_pos >= d.max) {
553 err = f2fs_convert_inline_dir(dir, ipage, inline_dentry);
554 if (err)
555 return err;
556 err = -EAGAIN;
557 goto out;
558 }
559
560 if (inode) {
561 down_write(&F2FS_I(inode)->i_sem);
562 page = f2fs_init_inode_metadata(inode, dir, new_name,
563 orig_name, ipage);
564 if (IS_ERR(page)) {
565 err = PTR_ERR(page);
566 goto fail;
567 }
568 }
569
570 f2fs_wait_on_page_writeback(ipage, NODE, true);
571
572 name_hash = f2fs_dentry_hash(new_name, NULL);
573 f2fs_update_dentry(ino, mode, &d, new_name, name_hash, bit_pos);
574
575 set_page_dirty(ipage);
576
577 /* we don't need to mark_inode_dirty now */
578 if (inode) {
579 f2fs_i_pino_write(inode, dir->i_ino);
580 f2fs_put_page(page, 1);
581 }
582
583 f2fs_update_parent_metadata(dir, inode, 0);
584 fail:
585 if (inode)
586 up_write(&F2FS_I(inode)->i_sem);
587 out:
588 f2fs_put_page(ipage, 1);
589 return err;
590 }
591
f2fs_delete_inline_entry(struct f2fs_dir_entry * dentry,struct page * page,struct inode * dir,struct inode * inode)592 void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry, struct page *page,
593 struct inode *dir, struct inode *inode)
594 {
595 struct f2fs_dentry_ptr d;
596 void *inline_dentry;
597 int slots = GET_DENTRY_SLOTS(le16_to_cpu(dentry->name_len));
598 unsigned int bit_pos;
599 int i;
600
601 lock_page(page);
602 f2fs_wait_on_page_writeback(page, NODE, true);
603
604 inline_dentry = inline_data_addr(dir, page);
605 make_dentry_ptr_inline(dir, &d, inline_dentry);
606
607 bit_pos = dentry - d.dentry;
608 for (i = 0; i < slots; i++)
609 __clear_bit_le(bit_pos + i, d.bitmap);
610
611 set_page_dirty(page);
612 f2fs_put_page(page, 1);
613
614 dir->i_ctime = dir->i_mtime = current_time(dir);
615 f2fs_mark_inode_dirty_sync(dir, false);
616
617 if (inode)
618 f2fs_drop_nlink(dir, inode);
619 }
620
f2fs_empty_inline_dir(struct inode * dir)621 bool f2fs_empty_inline_dir(struct inode *dir)
622 {
623 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
624 struct page *ipage;
625 unsigned int bit_pos = 2;
626 void *inline_dentry;
627 struct f2fs_dentry_ptr d;
628
629 ipage = f2fs_get_node_page(sbi, dir->i_ino);
630 if (IS_ERR(ipage))
631 return false;
632
633 inline_dentry = inline_data_addr(dir, ipage);
634 make_dentry_ptr_inline(dir, &d, inline_dentry);
635
636 bit_pos = find_next_bit_le(d.bitmap, d.max, bit_pos);
637
638 f2fs_put_page(ipage, 1);
639
640 if (bit_pos < d.max)
641 return false;
642
643 return true;
644 }
645
f2fs_read_inline_dir(struct file * file,struct dir_context * ctx,struct fscrypt_str * fstr)646 int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx,
647 struct fscrypt_str *fstr)
648 {
649 struct inode *inode = file_inode(file);
650 struct page *ipage = NULL;
651 struct f2fs_dentry_ptr d;
652 void *inline_dentry = NULL;
653 int err;
654
655 make_dentry_ptr_inline(inode, &d, inline_dentry);
656
657 if (ctx->pos == d.max)
658 return 0;
659
660 ipage = f2fs_get_node_page(F2FS_I_SB(inode), inode->i_ino);
661 if (IS_ERR(ipage))
662 return PTR_ERR(ipage);
663
664 inline_dentry = inline_data_addr(inode, ipage);
665
666 make_dentry_ptr_inline(inode, &d, inline_dentry);
667
668 err = f2fs_fill_dentries(ctx, &d, 0, fstr);
669 if (!err)
670 ctx->pos = d.max;
671
672 f2fs_put_page(ipage, 1);
673 return err < 0 ? err : 0;
674 }
675
f2fs_inline_data_fiemap(struct inode * inode,struct fiemap_extent_info * fieinfo,__u64 start,__u64 len)676 int f2fs_inline_data_fiemap(struct inode *inode,
677 struct fiemap_extent_info *fieinfo, __u64 start, __u64 len)
678 {
679 __u64 byteaddr, ilen;
680 __u32 flags = FIEMAP_EXTENT_DATA_INLINE | FIEMAP_EXTENT_NOT_ALIGNED |
681 FIEMAP_EXTENT_LAST;
682 struct node_info ni;
683 struct page *ipage;
684 int err = 0;
685
686 ipage = f2fs_get_node_page(F2FS_I_SB(inode), inode->i_ino);
687 if (IS_ERR(ipage))
688 return PTR_ERR(ipage);
689
690 if (!f2fs_has_inline_data(inode)) {
691 err = -EAGAIN;
692 goto out;
693 }
694
695 ilen = min_t(size_t, MAX_INLINE_DATA(inode), i_size_read(inode));
696 if (start >= ilen)
697 goto out;
698 if (start + len < ilen)
699 ilen = start + len;
700 ilen -= start;
701
702 err = f2fs_get_node_info(F2FS_I_SB(inode), inode->i_ino, &ni);
703 if (err)
704 goto out;
705
706 byteaddr = (__u64)ni.blk_addr << inode->i_sb->s_blocksize_bits;
707 byteaddr += (char *)inline_data_addr(inode, ipage) -
708 (char *)F2FS_INODE(ipage);
709 err = fiemap_fill_next_extent(fieinfo, start, byteaddr, ilen, flags);
710 out:
711 f2fs_put_page(ipage, 1);
712 return err;
713 }
714