]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/blame - fs/f2fs/inline.c
f2fs: introduce f2fs_set_page_dirty_nobuffer
[mirror_ubuntu-eoan-kernel.git] / fs / f2fs / inline.c
CommitLineData
e18c65b2
HL
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"
67f8cf3c 15#include "node.h"
e18c65b2 16
01b960e9 17bool f2fs_may_inline_data(struct inode *inode)
e18c65b2 18{
88b88a66
JK
19 if (f2fs_is_atomic_file(inode))
20 return false;
21
368a0e40 22 if (!S_ISREG(inode->i_mode) && !S_ISLNK(inode->i_mode))
e18c65b2
HL
23 return false;
24
92dffd01
JK
25 if (i_size_read(inode) > MAX_INLINE_DATA)
26 return false;
27
fcc85a4d
JK
28 if (f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode))
29 return false;
30
e18c65b2
HL
31 return true;
32}
33
01b960e9
JK
34bool 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
b3d208f9 45void read_inline_data(struct page *page, struct page *ipage)
e18c65b2 46{
e18c65b2
HL
47 void *src_addr, *dst_addr;
48
b3d208f9
JK
49 if (PageUptodate(page))
50 return;
04a17fb1 51
b3d208f9 52 f2fs_bug_on(F2FS_P_SB(page), page->index);
e18c65b2 53
09cbfeaf 54 zero_user_segment(page, MAX_INLINE_DATA, PAGE_SIZE);
e18c65b2
HL
55
56 /* Copy the whole inline data block */
57 src_addr = inline_data_addr(ipage);
f1e33a04 58 dst_addr = kmap_atomic(page);
e18c65b2 59 memcpy(dst_addr, src_addr, MAX_INLINE_DATA);
427a45c8 60 flush_dcache_page(page);
f1e33a04 61 kunmap_atomic(dst_addr);
e18c65b2 62 SetPageUptodate(page);
b3d208f9
JK
63}
64
0bfcfcca 65bool truncate_inline_inode(struct page *ipage, u64 from)
feeb0deb 66{
0bfcfcca
CY
67 void *addr;
68
0bfcfcca
CY
69 if (from >= MAX_INLINE_DATA)
70 return false;
71
72 addr = inline_data_addr(ipage);
73
fec1d657 74 f2fs_wait_on_page_writeback(ipage, NODE, true);
0bfcfcca 75 memset(addr + from, 0, MAX_INLINE_DATA - from);
ee6d182f 76 set_page_dirty(ipage);
0bfcfcca 77 return true;
feeb0deb
CY
78}
79
b3d208f9
JK
80int f2fs_read_inline_data(struct inode *inode, struct page *page)
81{
82 struct page *ipage;
83
84 ipage = get_node_page(F2FS_I_SB(inode), inode->i_ino);
85 if (IS_ERR(ipage)) {
86 unlock_page(page);
87 return PTR_ERR(ipage);
88 }
e18c65b2 89
b3d208f9
JK
90 if (!f2fs_has_inline_data(inode)) {
91 f2fs_put_page(ipage, 1);
92 return -EAGAIN;
93 }
94
95 if (page->index)
09cbfeaf 96 zero_user_segment(page, 0, PAGE_SIZE);
b3d208f9
JK
97 else
98 read_inline_data(page, ipage);
99
100 SetPageUptodate(page);
101 f2fs_put_page(ipage, 1);
102 unlock_page(page);
e18c65b2
HL
103 return 0;
104}
105
b3d208f9 106int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page)
e18c65b2 107{
e18c65b2 108 struct f2fs_io_info fio = {
05ca3632 109 .sbi = F2FS_I_SB(dn->inode),
e18c65b2
HL
110 .type = DATA,
111 .rw = WRITE_SYNC | REQ_PRIO,
05ca3632 112 .page = page,
4375a336 113 .encrypted_page = NULL,
e18c65b2 114 };
158c194c 115 int dirty, err;
e18c65b2 116
b3d208f9
JK
117 if (!f2fs_exist_data(dn->inode))
118 goto clear_out;
ec4e7af4 119
b3d208f9 120 err = f2fs_reserve_block(dn, 0);
15c6e3aa 121 if (err)
b3d208f9 122 return err;
e18c65b2 123
85ead818 124 f2fs_bug_on(F2FS_P_SB(page), PageWriteback(page));
b3d208f9 125
8060656a 126 read_inline_data(page, dn->inode_page);
6282adbf
JK
127 set_page_dirty(page);
128
158c194c
JK
129 /* clear dirty state */
130 dirty = clear_page_dirty_for_io(page);
131
e18c65b2
HL
132 /* write data page to try to make data consistent */
133 set_page_writeback(page);
7a9d7548 134 fio.old_blkaddr = dn->data_blkaddr;
05ca3632 135 write_data_page(dn, &fio);
fec1d657 136 f2fs_wait_on_page_writeback(page, DATA, true);
158c194c
JK
137 if (dirty)
138 inode_dec_dirty_pages(dn->inode);
e18c65b2 139
95f5b0fc 140 /* this converted inline_data should be recovered. */
91942321 141 set_inode_flag(dn->inode, FI_APPEND_WRITE);
95f5b0fc 142
e18c65b2 143 /* clear inline data and flag after data writeback */
0bfcfcca 144 truncate_inline_inode(dn->inode_page, 0);
2049d4fc 145 clear_inline_node(dn->inode_page);
b3d208f9 146clear_out:
b3d208f9 147 stat_dec_inline_inode(dn->inode);
57e2a2c0 148 f2fs_clear_inline_inode(dn->inode);
b3d208f9
JK
149 f2fs_put_dnode(dn);
150 return 0;
e18c65b2
HL
151}
152
b3d208f9 153int f2fs_convert_inline_inode(struct inode *inode)
e18c65b2 154{
b3d208f9
JK
155 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
156 struct dnode_of_data dn;
157 struct page *ipage, *page;
158 int err = 0;
e18c65b2 159
b9d777b8
JK
160 if (!f2fs_has_inline_data(inode))
161 return 0;
162
300e129c 163 page = f2fs_grab_cache_page(inode->i_mapping, 0, false);
b3d208f9
JK
164 if (!page)
165 return -ENOMEM;
e18c65b2 166
b3d208f9
JK
167 f2fs_lock_op(sbi);
168
169 ipage = get_node_page(sbi, inode->i_ino);
170 if (IS_ERR(ipage)) {
6d20aff8
JK
171 err = PTR_ERR(ipage);
172 goto out;
b067ba1f 173 }
e18c65b2 174
b3d208f9
JK
175 set_new_dnode(&dn, inode, ipage, ipage, 0);
176
177 if (f2fs_has_inline_data(inode))
178 err = f2fs_convert_inline_page(&dn, page);
179
180 f2fs_put_dnode(&dn);
6d20aff8 181out:
b3d208f9
JK
182 f2fs_unlock_op(sbi);
183
184 f2fs_put_page(page, 1);
2a340760 185
2c4db1a6 186 f2fs_balance_fs(sbi, dn.node_changed);
2a340760 187
e18c65b2
HL
188 return err;
189}
190
b3d208f9 191int f2fs_write_inline_data(struct inode *inode, struct page *page)
e18c65b2
HL
192{
193 void *src_addr, *dst_addr;
e18c65b2
HL
194 struct dnode_of_data dn;
195 int err;
196
197 set_new_dnode(&dn, inode, NULL, NULL, 0);
198 err = get_dnode_of_data(&dn, 0, LOOKUP_NODE);
199 if (err)
200 return err;
e18c65b2 201
c08a690b 202 if (!f2fs_has_inline_data(inode)) {
b3d208f9
JK
203 f2fs_put_dnode(&dn);
204 return -EAGAIN;
c08a690b
JK
205 }
206
b3d208f9
JK
207 f2fs_bug_on(F2FS_I_SB(inode), page->index);
208
fec1d657 209 f2fs_wait_on_page_writeback(dn.inode_page, NODE, true);
f1e33a04 210 src_addr = kmap_atomic(page);
b3d208f9
JK
211 dst_addr = inline_data_addr(dn.inode_page);
212 memcpy(dst_addr, src_addr, MAX_INLINE_DATA);
f1e33a04 213 kunmap_atomic(src_addr);
ee6d182f 214 set_page_dirty(dn.inode_page);
e18c65b2 215
91942321
JK
216 set_inode_flag(inode, FI_APPEND_WRITE);
217 set_inode_flag(inode, FI_DATA_EXIST);
b3d208f9 218
2049d4fc 219 clear_inline_node(dn.inode_page);
e18c65b2 220 f2fs_put_dnode(&dn);
e18c65b2
HL
221 return 0;
222}
1e1bb4ba 223
0342fd30 224bool recover_inline_data(struct inode *inode, struct page *npage)
1e1bb4ba 225{
4081363f 226 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
1e1bb4ba
JK
227 struct f2fs_inode *ri = NULL;
228 void *src_addr, *dst_addr;
229 struct page *ipage;
230
231 /*
232 * The inline_data recovery policy is as follows.
233 * [prev.] [next] of inline_data flag
234 * o o -> recover inline_data
235 * o x -> remove inline_data, and then recover data blocks
236 * x o -> remove inline_data, and then recover inline_data
237 * x x -> recover data blocks
238 */
239 if (IS_INODE(npage))
240 ri = F2FS_INODE(npage);
241
242 if (f2fs_has_inline_data(inode) &&
0342fd30 243 ri && (ri->i_inline & F2FS_INLINE_DATA)) {
1e1bb4ba
JK
244process_inline:
245 ipage = get_node_page(sbi, inode->i_ino);
9850cf4a 246 f2fs_bug_on(sbi, IS_ERR(ipage));
1e1bb4ba 247
fec1d657 248 f2fs_wait_on_page_writeback(ipage, NODE, true);
54b591df 249
1e1bb4ba
JK
250 src_addr = inline_data_addr(npage);
251 dst_addr = inline_data_addr(ipage);
252 memcpy(dst_addr, src_addr, MAX_INLINE_DATA);
b3d208f9 253
91942321
JK
254 set_inode_flag(inode, FI_INLINE_DATA);
255 set_inode_flag(inode, FI_DATA_EXIST);
b3d208f9 256
ee6d182f 257 set_page_dirty(ipage);
1e1bb4ba 258 f2fs_put_page(ipage, 1);
0342fd30 259 return true;
1e1bb4ba
JK
260 }
261
262 if (f2fs_has_inline_data(inode)) {
263 ipage = get_node_page(sbi, inode->i_ino);
9850cf4a 264 f2fs_bug_on(sbi, IS_ERR(ipage));
545fe421
NK
265 if (!truncate_inline_inode(ipage, 0))
266 return false;
b3d208f9 267 f2fs_clear_inline_inode(inode);
1e1bb4ba 268 f2fs_put_page(ipage, 1);
0342fd30 269 } else if (ri && (ri->i_inline & F2FS_INLINE_DATA)) {
545fe421
NK
270 if (truncate_blocks(inode, 0, false))
271 return false;
1e1bb4ba
JK
272 goto process_inline;
273 }
0342fd30 274 return false;
1e1bb4ba 275}
201a05be
CY
276
277struct f2fs_dir_entry *find_in_inline_dir(struct inode *dir,
0b81d077 278 struct fscrypt_name *fname, struct page **res_page)
201a05be
CY
279{
280 struct f2fs_sb_info *sbi = F2FS_SB(dir->i_sb);
4e6ebf6d 281 struct f2fs_inline_dentry *inline_dentry;
6e22c691 282 struct qstr name = FSTR_TO_QSTR(&fname->disk_name);
201a05be 283 struct f2fs_dir_entry *de;
7b3cd7d6 284 struct f2fs_dentry_ptr d;
4e6ebf6d 285 struct page *ipage;
6e22c691 286 f2fs_hash_t namehash;
201a05be
CY
287
288 ipage = get_node_page(sbi, dir->i_ino);
42d96401
JK
289 if (IS_ERR(ipage)) {
290 *res_page = ipage;
201a05be 291 return NULL;
42d96401 292 }
201a05be 293
6e22c691
JK
294 namehash = f2fs_dentry_hash(&name);
295
4e6ebf6d 296 inline_dentry = inline_data_addr(ipage);
201a05be 297
d8c6822a 298 make_dentry_ptr(NULL, &d, (void *)inline_dentry, 2);
6e22c691 299 de = find_target_dentry(fname, namehash, NULL, &d);
201a05be 300 unlock_page(ipage);
4e6ebf6d
JK
301 if (de)
302 *res_page = ipage;
303 else
304 f2fs_put_page(ipage, 0);
305
201a05be
CY
306 return de;
307}
308
201a05be
CY
309int make_empty_inline_dir(struct inode *inode, struct inode *parent,
310 struct page *ipage)
311{
312 struct f2fs_inline_dentry *dentry_blk;
062a3e7b 313 struct f2fs_dentry_ptr d;
201a05be
CY
314
315 dentry_blk = inline_data_addr(ipage);
316
d8c6822a 317 make_dentry_ptr(NULL, &d, (void *)dentry_blk, 2);
062a3e7b 318 do_make_empty_dir(inode, parent, &d);
201a05be
CY
319
320 set_page_dirty(ipage);
321
322 /* update i_size to MAX_INLINE_DATA */
ee6d182f 323 if (i_size_read(inode) < MAX_INLINE_DATA)
fc9581c8 324 f2fs_i_size_write(inode, MAX_INLINE_DATA);
201a05be
CY
325 return 0;
326}
327
470f00e9
CY
328/*
329 * NOTE: ipage is grabbed by caller, but if any error occurs, we should
330 * release ipage in this function.
331 */
675f10bd 332static int f2fs_move_inline_dirents(struct inode *dir, struct page *ipage,
201a05be
CY
333 struct f2fs_inline_dentry *inline_dentry)
334{
335 struct page *page;
336 struct dnode_of_data dn;
337 struct f2fs_dentry_block *dentry_blk;
338 int err;
339
300e129c 340 page = f2fs_grab_cache_page(dir->i_mapping, 0, false);
470f00e9
CY
341 if (!page) {
342 f2fs_put_page(ipage, 1);
201a05be 343 return -ENOMEM;
470f00e9 344 }
201a05be
CY
345
346 set_new_dnode(&dn, dir, ipage, NULL, 0);
347 err = f2fs_reserve_block(&dn, 0);
348 if (err)
349 goto out;
350
fec1d657 351 f2fs_wait_on_page_writeback(page, DATA, true);
09cbfeaf 352 zero_user_segment(page, MAX_INLINE_DATA, PAGE_SIZE);
201a05be 353
f1e33a04 354 dentry_blk = kmap_atomic(page);
201a05be
CY
355
356 /* copy data from inline dentry block to new dentry block */
357 memcpy(dentry_blk->dentry_bitmap, inline_dentry->dentry_bitmap,
358 INLINE_DENTRY_BITMAP_SIZE);
4ec17d68
CY
359 memset(dentry_blk->dentry_bitmap + INLINE_DENTRY_BITMAP_SIZE, 0,
360 SIZE_OF_DENTRY_BITMAP - INLINE_DENTRY_BITMAP_SIZE);
361 /*
362 * we do not need to zero out remainder part of dentry and filename
363 * field, since we have used bitmap for marking the usage status of
364 * them, besides, we can also ignore copying/zeroing reserved space
365 * of dentry block, because them haven't been used so far.
366 */
201a05be
CY
367 memcpy(dentry_blk->dentry, inline_dentry->dentry,
368 sizeof(struct f2fs_dir_entry) * NR_INLINE_DENTRY);
369 memcpy(dentry_blk->filename, inline_dentry->filename,
370 NR_INLINE_DENTRY * F2FS_SLOT_LEN);
371
f1e33a04 372 kunmap_atomic(dentry_blk);
201a05be
CY
373 SetPageUptodate(page);
374 set_page_dirty(page);
375
376 /* clear inline dir and flag after data writeback */
0bfcfcca 377 truncate_inline_inode(ipage, 0);
b3d208f9 378
3289c061 379 stat_dec_inline_dir(dir);
91942321 380 clear_inode_flag(dir, FI_INLINE_DENTRY);
201a05be 381
205b9822 382 f2fs_i_depth_write(dir, 1);
ee6d182f 383 if (i_size_read(dir) < PAGE_SIZE)
fc9581c8 384 f2fs_i_size_write(dir, PAGE_SIZE);
201a05be
CY
385out:
386 f2fs_put_page(page, 1);
387 return err;
388}
389
675f10bd
CY
390static int f2fs_add_inline_entries(struct inode *dir,
391 struct f2fs_inline_dentry *inline_dentry)
392{
393 struct f2fs_dentry_ptr d;
394 unsigned long bit_pos = 0;
395 int err = 0;
396
397 make_dentry_ptr(NULL, &d, (void *)inline_dentry, 2);
398
399 while (bit_pos < d.max) {
400 struct f2fs_dir_entry *de;
401 struct qstr new_name;
402 nid_t ino;
403 umode_t fake_mode;
404
405 if (!test_bit_le(bit_pos, d.bitmap)) {
406 bit_pos++;
407 continue;
408 }
409
410 de = &d.dentry[bit_pos];
a4a13f58
CY
411
412 if (unlikely(!de->name_len)) {
413 bit_pos++;
414 continue;
415 }
416
675f10bd
CY
417 new_name.name = d.filename[bit_pos];
418 new_name.len = de->name_len;
419
420 ino = le32_to_cpu(de->ino);
421 fake_mode = get_de_type(de) << S_SHIFT;
422
423 err = f2fs_add_regular_entry(dir, &new_name, NULL,
424 ino, fake_mode);
425 if (err)
426 goto punch_dentry_pages;
427
675f10bd
CY
428 bit_pos += GET_DENTRY_SLOTS(le16_to_cpu(de->name_len));
429 }
430 return 0;
431punch_dentry_pages:
432 truncate_inode_pages(&dir->i_data, 0);
433 truncate_blocks(dir, 0, false);
434 remove_dirty_inode(dir);
435 return err;
436}
437
438static int f2fs_move_rehashed_dirents(struct inode *dir, struct page *ipage,
439 struct f2fs_inline_dentry *inline_dentry)
440{
441 struct f2fs_inline_dentry *backup_dentry;
442 int err;
443
0414b004 444 backup_dentry = f2fs_kmalloc(sizeof(struct f2fs_inline_dentry),
675f10bd 445 GFP_F2FS_ZERO);
8975bdf4
CY
446 if (!backup_dentry) {
447 f2fs_put_page(ipage, 1);
675f10bd 448 return -ENOMEM;
8975bdf4 449 }
675f10bd
CY
450
451 memcpy(backup_dentry, inline_dentry, MAX_INLINE_DATA);
452 truncate_inline_inode(ipage, 0);
453
454 unlock_page(ipage);
455
456 err = f2fs_add_inline_entries(dir, backup_dentry);
457 if (err)
458 goto recover;
459
460 lock_page(ipage);
461
462 stat_dec_inline_dir(dir);
91942321 463 clear_inode_flag(dir, FI_INLINE_DENTRY);
675f10bd
CY
464 kfree(backup_dentry);
465 return 0;
466recover:
467 lock_page(ipage);
468 memcpy(inline_dentry, backup_dentry, MAX_INLINE_DATA);
205b9822 469 f2fs_i_depth_write(dir, 0);
fc9581c8 470 f2fs_i_size_write(dir, MAX_INLINE_DATA);
ee6d182f 471 set_page_dirty(ipage);
675f10bd
CY
472 f2fs_put_page(ipage, 1);
473
474 kfree(backup_dentry);
475 return err;
476}
477
478static int f2fs_convert_inline_dir(struct inode *dir, struct page *ipage,
479 struct f2fs_inline_dentry *inline_dentry)
480{
481 if (!F2FS_I(dir)->i_dir_level)
482 return f2fs_move_inline_dirents(dir, ipage, inline_dentry);
483 else
484 return f2fs_move_rehashed_dirents(dir, ipage, inline_dentry);
485}
486
201a05be 487int f2fs_add_inline_entry(struct inode *dir, const struct qstr *name,
510022a8 488 struct inode *inode, nid_t ino, umode_t mode)
201a05be
CY
489{
490 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
491 struct page *ipage;
492 unsigned int bit_pos;
493 f2fs_hash_t name_hash;
201a05be
CY
494 size_t namelen = name->len;
495 struct f2fs_inline_dentry *dentry_blk = NULL;
3b4d732a 496 struct f2fs_dentry_ptr d;
201a05be 497 int slots = GET_DENTRY_SLOTS(namelen);
510022a8 498 struct page *page = NULL;
201a05be 499 int err = 0;
201a05be
CY
500
501 ipage = get_node_page(sbi, dir->i_ino);
502 if (IS_ERR(ipage))
503 return PTR_ERR(ipage);
504
505 dentry_blk = inline_data_addr(ipage);
a82afa20
JK
506 bit_pos = room_for_filename(&dentry_blk->dentry_bitmap,
507 slots, NR_INLINE_DENTRY);
201a05be
CY
508 if (bit_pos >= NR_INLINE_DENTRY) {
509 err = f2fs_convert_inline_dir(dir, ipage, dentry_blk);
470f00e9
CY
510 if (err)
511 return err;
512 err = -EAGAIN;
201a05be
CY
513 goto out;
514 }
515
510022a8
JK
516 if (inode) {
517 down_write(&F2FS_I(inode)->i_sem);
518 page = init_inode_metadata(inode, dir, name, ipage);
519 if (IS_ERR(page)) {
520 err = PTR_ERR(page);
521 goto fail;
522 }
201a05be 523 }
bce8d112 524
fec1d657 525 f2fs_wait_on_page_writeback(ipage, NODE, true);
3b4d732a
CY
526
527 name_hash = f2fs_dentry_hash(name);
d8c6822a 528 make_dentry_ptr(NULL, &d, (void *)dentry_blk, 2);
510022a8 529 f2fs_update_dentry(ino, mode, &d, name, name_hash, bit_pos);
3b4d732a 530
201a05be
CY
531 set_page_dirty(ipage);
532
533 /* we don't need to mark_inode_dirty now */
510022a8 534 if (inode) {
205b9822 535 f2fs_i_pino_write(inode, dir->i_ino);
510022a8
JK
536 f2fs_put_page(page, 1);
537 }
201a05be
CY
538
539 update_parent_metadata(dir, inode, 0);
540fail:
510022a8
JK
541 if (inode)
542 up_write(&F2FS_I(inode)->i_sem);
201a05be
CY
543out:
544 f2fs_put_page(ipage, 1);
545 return err;
546}
547
548void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry, struct page *page,
549 struct inode *dir, struct inode *inode)
550{
551 struct f2fs_inline_dentry *inline_dentry;
552 int slots = GET_DENTRY_SLOTS(le16_to_cpu(dentry->name_len));
553 unsigned int bit_pos;
554 int i;
555
556 lock_page(page);
fec1d657 557 f2fs_wait_on_page_writeback(page, NODE, true);
201a05be
CY
558
559 inline_dentry = inline_data_addr(page);
560 bit_pos = dentry - inline_dentry->dentry;
561 for (i = 0; i < slots; i++)
562 test_and_clear_bit_le(bit_pos + i,
563 &inline_dentry->dentry_bitmap);
564
565 set_page_dirty(page);
9f7c45cc 566 f2fs_put_page(page, 1);
201a05be
CY
567
568 dir->i_ctime = dir->i_mtime = CURRENT_TIME;
205b9822 569 mark_inode_dirty_sync(dir);
201a05be
CY
570
571 if (inode)
9f7c45cc 572 f2fs_drop_nlink(dir, inode);
201a05be
CY
573}
574
575bool f2fs_empty_inline_dir(struct inode *dir)
576{
577 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
578 struct page *ipage;
579 unsigned int bit_pos = 2;
580 struct f2fs_inline_dentry *dentry_blk;
581
582 ipage = get_node_page(sbi, dir->i_ino);
583 if (IS_ERR(ipage))
584 return false;
585
586 dentry_blk = inline_data_addr(ipage);
587 bit_pos = find_next_bit_le(&dentry_blk->dentry_bitmap,
588 NR_INLINE_DENTRY,
589 bit_pos);
590
591 f2fs_put_page(ipage, 1);
592
593 if (bit_pos < NR_INLINE_DENTRY)
594 return false;
595
596 return true;
597}
598
d8c6822a 599int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx,
0b81d077 600 struct fscrypt_str *fstr)
201a05be
CY
601{
602 struct inode *inode = file_inode(file);
201a05be 603 struct f2fs_inline_dentry *inline_dentry = NULL;
201a05be 604 struct page *ipage = NULL;
7b3cd7d6 605 struct f2fs_dentry_ptr d;
201a05be
CY
606
607 if (ctx->pos == NR_INLINE_DENTRY)
608 return 0;
609
38594de7 610 ipage = get_node_page(F2FS_I_SB(inode), inode->i_ino);
201a05be
CY
611 if (IS_ERR(ipage))
612 return PTR_ERR(ipage);
613
201a05be 614 inline_dentry = inline_data_addr(ipage);
201a05be 615
d8c6822a 616 make_dentry_ptr(inode, &d, (void *)inline_dentry, 2);
7b3cd7d6 617
d8c6822a 618 if (!f2fs_fill_dentries(ctx, &d, 0, fstr))
38594de7 619 ctx->pos = NR_INLINE_DENTRY;
201a05be 620
38594de7 621 f2fs_put_page(ipage, 1);
201a05be
CY
622 return 0;
623}
67f8cf3c
JK
624
625int f2fs_inline_data_fiemap(struct inode *inode,
626 struct fiemap_extent_info *fieinfo, __u64 start, __u64 len)
627{
628 __u64 byteaddr, ilen;
629 __u32 flags = FIEMAP_EXTENT_DATA_INLINE | FIEMAP_EXTENT_NOT_ALIGNED |
630 FIEMAP_EXTENT_LAST;
631 struct node_info ni;
632 struct page *ipage;
633 int err = 0;
634
635 ipage = get_node_page(F2FS_I_SB(inode), inode->i_ino);
636 if (IS_ERR(ipage))
637 return PTR_ERR(ipage);
638
639 if (!f2fs_has_inline_data(inode)) {
640 err = -EAGAIN;
641 goto out;
642 }
643
644 ilen = min_t(size_t, MAX_INLINE_DATA, i_size_read(inode));
645 if (start >= ilen)
646 goto out;
647 if (start + len < ilen)
648 ilen = start + len;
649 ilen -= start;
650
651 get_node_info(F2FS_I_SB(inode), inode->i_ino, &ni);
652 byteaddr = (__u64)ni.blk_addr << inode->i_sb->s_blocksize_bits;
653 byteaddr += (char *)inline_data_addr(ipage) - (char *)F2FS_INODE(ipage);
654 err = fiemap_fill_next_extent(fieinfo, start, byteaddr, ilen, flags);
655out:
656 f2fs_put_page(ipage, 1);
657 return err;
658}