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