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