inline.c 15.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*
 * fs/f2fs/inline.c
 * Copyright (c) 2013, Intel Corporation
 * Authors: Huajun Li <huajun.li@intel.com>
 *          Haicheng Li <haicheng.li@intel.com>
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

#include <linux/fs.h>
#include <linux/f2fs_fs.h>

#include "f2fs.h"
J
Jaegeuk Kim 已提交
15
#include "node.h"
16

17
bool f2fs_may_inline_data(struct inode *inode)
18
{
J
Jaegeuk Kim 已提交
19 20 21
	if (f2fs_is_atomic_file(inode))
		return false;

22
	if (!S_ISREG(inode->i_mode) && !S_ISLNK(inode->i_mode))
23 24
		return false;

C
Chao Yu 已提交
25
	if (i_size_read(inode) > MAX_INLINE_DATA(inode))
26 27
		return false;

28
	if (f2fs_post_read_required(inode))
29 30
		return false;

31 32 33
	return true;
}

34 35 36 37 38 39 40 41 42 43 44
bool f2fs_may_inline_dentry(struct inode *inode)
{
	if (!test_opt(F2FS_I_SB(inode), INLINE_DENTRY))
		return false;

	if (!S_ISDIR(inode->i_mode))
		return false;

	return true;
}

C
Chao Yu 已提交
45
void f2fs_do_read_inline_data(struct page *page, struct page *ipage)
46
{
C
Chao Yu 已提交
47
	struct inode *inode = page->mapping->host;
48 49
	void *src_addr, *dst_addr;

50 51
	if (PageUptodate(page))
		return;
52

53
	f2fs_bug_on(F2FS_P_SB(page), page->index);
54

C
Chao Yu 已提交
55
	zero_user_segment(page, MAX_INLINE_DATA(inode), PAGE_SIZE);
56 57

	/* Copy the whole inline data block */
C
Chao Yu 已提交
58
	src_addr = inline_data_addr(inode, ipage);
59
	dst_addr = kmap_atomic(page);
C
Chao Yu 已提交
60
	memcpy(dst_addr, src_addr, MAX_INLINE_DATA(inode));
61
	flush_dcache_page(page);
62
	kunmap_atomic(dst_addr);
63 64
	if (!PageUptodate(page))
		SetPageUptodate(page);
65 66
}

C
Chao Yu 已提交
67 68
void f2fs_truncate_inline_inode(struct inode *inode,
					struct page *ipage, u64 from)
C
Chao Yu 已提交
69
{
70 71
	void *addr;

C
Chao Yu 已提交
72
	if (from >= MAX_INLINE_DATA(inode))
73
		return;
74

C
Chao Yu 已提交
75
	addr = inline_data_addr(inode, ipage);
76

77
	f2fs_wait_on_page_writeback(ipage, NODE, true);
C
Chao Yu 已提交
78
	memset(addr + from, 0, MAX_INLINE_DATA(inode) - from);
79
	set_page_dirty(ipage);
80 81 82

	if (from == 0)
		clear_inode_flag(inode, FI_DATA_EXIST);
C
Chao Yu 已提交
83 84
}

85 86 87 88
int f2fs_read_inline_data(struct inode *inode, struct page *page)
{
	struct page *ipage;

C
Chao Yu 已提交
89
	ipage = f2fs_get_node_page(F2FS_I_SB(inode), inode->i_ino);
90 91 92 93
	if (IS_ERR(ipage)) {
		unlock_page(page);
		return PTR_ERR(ipage);
	}
94

95 96 97 98 99 100
	if (!f2fs_has_inline_data(inode)) {
		f2fs_put_page(ipage, 1);
		return -EAGAIN;
	}

	if (page->index)
101
		zero_user_segment(page, 0, PAGE_SIZE);
102
	else
C
Chao Yu 已提交
103
		f2fs_do_read_inline_data(page, ipage);
104

105 106
	if (!PageUptodate(page))
		SetPageUptodate(page);
107 108
	f2fs_put_page(ipage, 1);
	unlock_page(page);
109 110 111
	return 0;
}

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),
C
Chao Yu 已提交
116
		.ino = dn->inode->i_ino,
117
		.type = DATA,
M
Mike Christie 已提交
118
		.op = REQ_OP_WRITE,
119
		.op_flags = REQ_SYNC | REQ_PRIO,
120
		.page = page,
121
		.encrypted_page = NULL,
C
Chao Yu 已提交
122
		.io_type = FS_DATA_IO,
123
	};
124
	int dirty, err;
125

126 127
	if (!f2fs_exist_data(dn->inode))
		goto clear_out;
128

129
	err = f2fs_reserve_block(dn, 0);
130
	if (err)
131
		return err;
132

133
	f2fs_bug_on(F2FS_P_SB(page), PageWriteback(page));
134

C
Chao Yu 已提交
135
	f2fs_do_read_inline_data(page, dn->inode_page);
136 137
	set_page_dirty(page);

138 139 140
	/* clear dirty state */
	dirty = clear_page_dirty_for_io(page);

141 142
	/* write data page to try to make data consistent */
	set_page_writeback(page);
J
Jaegeuk Kim 已提交
143
	ClearPageError(page);
144
	fio.old_blkaddr = dn->data_blkaddr;
145
	set_inode_flag(dn->inode, FI_HOT_DATA);
C
Chao Yu 已提交
146
	f2fs_outplace_write_data(dn, &fio);
147
	f2fs_wait_on_page_writeback(page, DATA, true);
148
	if (dirty) {
149
		inode_dec_dirty_pages(dn->inode);
C
Chao Yu 已提交
150
		f2fs_remove_dirty_inode(dn->inode);
151
	}
152

153
	/* this converted inline_data should be recovered. */
154
	set_inode_flag(dn->inode, FI_APPEND_WRITE);
155

156
	/* clear inline data and flag after data writeback */
C
Chao Yu 已提交
157
	f2fs_truncate_inline_inode(dn->inode, dn->inode_page, 0);
158
	clear_inline_node(dn->inode_page);
159 160
clear_out:
	stat_dec_inline_inode(dn->inode);
161
	clear_inode_flag(dn->inode, FI_INLINE_DATA);
162 163
	f2fs_put_dnode(dn);
	return 0;
164 165
}

166
int f2fs_convert_inline_inode(struct inode *inode)
167
{
168 169 170 171
	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
	struct dnode_of_data dn;
	struct page *ipage, *page;
	int err = 0;
172

173 174 175
	if (!f2fs_has_inline_data(inode))
		return 0;

176
	page = f2fs_grab_cache_page(inode->i_mapping, 0, false);
177 178
	if (!page)
		return -ENOMEM;
179

180 181
	f2fs_lock_op(sbi);

C
Chao Yu 已提交
182
	ipage = f2fs_get_node_page(sbi, inode->i_ino);
183
	if (IS_ERR(ipage)) {
184 185
		err = PTR_ERR(ipage);
		goto out;
186
	}
187

188 189 190 191 192 193
	set_new_dnode(&dn, inode, ipage, ipage, 0);

	if (f2fs_has_inline_data(inode))
		err = f2fs_convert_inline_page(&dn, page);

	f2fs_put_dnode(&dn);
194
out:
195 196 197
	f2fs_unlock_op(sbi);

	f2fs_put_page(page, 1);
198

J
Jaegeuk Kim 已提交
199
	f2fs_balance_fs(sbi, dn.node_changed);
200

201 202 203
	return err;
}

204
int f2fs_write_inline_data(struct inode *inode, struct page *page)
205 206 207 208 209 210
{
	void *src_addr, *dst_addr;
	struct dnode_of_data dn;
	int err;

	set_new_dnode(&dn, inode, NULL, NULL, 0);
C
Chao Yu 已提交
211
	err = f2fs_get_dnode_of_data(&dn, 0, LOOKUP_NODE);
212 213 214
	if (err)
		return err;

215
	if (!f2fs_has_inline_data(inode)) {
216 217
		f2fs_put_dnode(&dn);
		return -EAGAIN;
218 219
	}

220 221
	f2fs_bug_on(F2FS_I_SB(inode), page->index);

222
	f2fs_wait_on_page_writeback(dn.inode_page, NODE, true);
223
	src_addr = kmap_atomic(page);
C
Chao Yu 已提交
224 225
	dst_addr = inline_data_addr(inode, dn.inode_page);
	memcpy(dst_addr, src_addr, MAX_INLINE_DATA(inode));
226
	kunmap_atomic(src_addr);
227
	set_page_dirty(dn.inode_page);
228

C
Chao Yu 已提交
229
	f2fs_clear_radix_tree_dirty_tag(page);
230

231 232
	set_inode_flag(inode, FI_APPEND_WRITE);
	set_inode_flag(inode, FI_DATA_EXIST);
233

234
	clear_inline_node(dn.inode_page);
235 236 237
	f2fs_put_dnode(&dn);
	return 0;
}
238

C
Chao Yu 已提交
239
bool f2fs_recover_inline_data(struct inode *inode, struct page *npage)
240
{
241
	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
	struct f2fs_inode *ri = NULL;
	void *src_addr, *dst_addr;
	struct page *ipage;

	/*
	 * The inline_data recovery policy is as follows.
	 * [prev.] [next] of inline_data flag
	 *    o       o  -> recover inline_data
	 *    o       x  -> remove inline_data, and then recover data blocks
	 *    x       o  -> remove inline_data, and then recover inline_data
	 *    x       x  -> recover data blocks
	 */
	if (IS_INODE(npage))
		ri = F2FS_INODE(npage);

	if (f2fs_has_inline_data(inode) &&
258
			ri && (ri->i_inline & F2FS_INLINE_DATA)) {
259
process_inline:
C
Chao Yu 已提交
260
		ipage = f2fs_get_node_page(sbi, inode->i_ino);
261
		f2fs_bug_on(sbi, IS_ERR(ipage));
262

263
		f2fs_wait_on_page_writeback(ipage, NODE, true);
264

C
Chao Yu 已提交
265 266 267
		src_addr = inline_data_addr(inode, npage);
		dst_addr = inline_data_addr(inode, ipage);
		memcpy(dst_addr, src_addr, MAX_INLINE_DATA(inode));
268

269 270
		set_inode_flag(inode, FI_INLINE_DATA);
		set_inode_flag(inode, FI_DATA_EXIST);
271

272
		set_page_dirty(ipage);
273
		f2fs_put_page(ipage, 1);
274
		return true;
275 276 277
	}

	if (f2fs_has_inline_data(inode)) {
C
Chao Yu 已提交
278
		ipage = f2fs_get_node_page(sbi, inode->i_ino);
279
		f2fs_bug_on(sbi, IS_ERR(ipage));
C
Chao Yu 已提交
280
		f2fs_truncate_inline_inode(inode, ipage, 0);
281
		clear_inode_flag(inode, FI_INLINE_DATA);
282
		f2fs_put_page(ipage, 1);
283
	} else if (ri && (ri->i_inline & F2FS_INLINE_DATA)) {
C
Chao Yu 已提交
284
		if (f2fs_truncate_blocks(inode, 0, false))
285
			return false;
286 287
		goto process_inline;
	}
288
	return false;
289
}
290

C
Chao Yu 已提交
291
struct f2fs_dir_entry *f2fs_find_in_inline_dir(struct inode *dir,
292
			struct fscrypt_name *fname, struct page **res_page)
293 294
{
	struct f2fs_sb_info *sbi = F2FS_SB(dir->i_sb);
295
	struct qstr name = FSTR_TO_QSTR(&fname->disk_name);
296
	struct f2fs_dir_entry *de;
297
	struct f2fs_dentry_ptr d;
298
	struct page *ipage;
C
Chao Yu 已提交
299
	void *inline_dentry;
300
	f2fs_hash_t namehash;
301

C
Chao Yu 已提交
302
	ipage = f2fs_get_node_page(sbi, dir->i_ino);
303 304
	if (IS_ERR(ipage)) {
		*res_page = ipage;
305
		return NULL;
306
	}
307

308
	namehash = f2fs_dentry_hash(&name, fname);
309

C
Chao Yu 已提交
310
	inline_dentry = inline_data_addr(dir, ipage);
311

C
Chao Yu 已提交
312
	make_dentry_ptr_inline(dir, &d, inline_dentry);
C
Chao Yu 已提交
313
	de = f2fs_find_target_dentry(fname, namehash, NULL, &d);
314
	unlock_page(ipage);
315 316 317 318 319
	if (de)
		*res_page = ipage;
	else
		f2fs_put_page(ipage, 0);

320 321 322
	return de;
}

C
Chao Yu 已提交
323
int f2fs_make_empty_inline_dir(struct inode *inode, struct inode *parent,
324 325
							struct page *ipage)
{
326
	struct f2fs_dentry_ptr d;
C
Chao Yu 已提交
327
	void *inline_dentry;
328

C
Chao Yu 已提交
329
	inline_dentry = inline_data_addr(inode, ipage);
330

C
Chao Yu 已提交
331
	make_dentry_ptr_inline(inode, &d, inline_dentry);
C
Chao Yu 已提交
332
	f2fs_do_make_empty_dir(inode, parent, &d);
333 334 335 336

	set_page_dirty(ipage);

	/* update i_size to MAX_INLINE_DATA */
C
Chao Yu 已提交
337 338
	if (i_size_read(inode) < MAX_INLINE_DATA(inode))
		f2fs_i_size_write(inode, MAX_INLINE_DATA(inode));
339 340 341
	return 0;
}

342 343 344 345
/*
 * NOTE: ipage is grabbed by caller, but if any error occurs, we should
 * release ipage in this function.
 */
346
static int f2fs_move_inline_dirents(struct inode *dir, struct page *ipage,
C
Chao Yu 已提交
347
							void *inline_dentry)
348 349 350 351
{
	struct page *page;
	struct dnode_of_data dn;
	struct f2fs_dentry_block *dentry_blk;
352
	struct f2fs_dentry_ptr src, dst;
353 354
	int err;

355
	page = f2fs_grab_cache_page(dir->i_mapping, 0, false);
356 357
	if (!page) {
		f2fs_put_page(ipage, 1);
358
		return -ENOMEM;
359
	}
360 361 362 363 364 365

	set_new_dnode(&dn, dir, ipage, NULL, 0);
	err = f2fs_reserve_block(&dn, 0);
	if (err)
		goto out;

366
	f2fs_wait_on_page_writeback(page, DATA, true);
367

368
	dentry_blk = page_address(page);
369

C
Chao Yu 已提交
370 371
	make_dentry_ptr_inline(dir, &src, inline_dentry);
	make_dentry_ptr_block(dir, &dst, dentry_blk);
372

373
	/* copy data from inline dentry block to new dentry block */
374 375
	memcpy(dst.bitmap, src.bitmap, src.nr_bitmap);
	memset(dst.bitmap + src.nr_bitmap, 0, dst.nr_bitmap - src.nr_bitmap);
376 377 378 379 380 381
	/*
	 * we do not need to zero out remainder part of dentry and filename
	 * field, since we have used bitmap for marking the usage status of
	 * them, besides, we can also ignore copying/zeroing reserved space
	 * of dentry block, because them haven't been used so far.
	 */
382 383
	memcpy(dst.dentry, src.dentry, SIZE_OF_DIR_ENTRY * src.max);
	memcpy(dst.filename, src.filename, src.max * F2FS_SLOT_LEN);
384

385 386
	if (!PageUptodate(page))
		SetPageUptodate(page);
387 388 389
	set_page_dirty(page);

	/* clear inline dir and flag after data writeback */
C
Chao Yu 已提交
390
	f2fs_truncate_inline_inode(dir, ipage, 0);
391

392
	stat_dec_inline_dir(dir);
393
	clear_inode_flag(dir, FI_INLINE_DENTRY);
394

395
	f2fs_i_depth_write(dir, 1);
396
	if (i_size_read(dir) < PAGE_SIZE)
397
		f2fs_i_size_write(dir, PAGE_SIZE);
398 399 400 401 402
out:
	f2fs_put_page(page, 1);
	return err;
}

C
Chao Yu 已提交
403
static int f2fs_add_inline_entries(struct inode *dir, void *inline_dentry)
404 405 406 407 408
{
	struct f2fs_dentry_ptr d;
	unsigned long bit_pos = 0;
	int err = 0;

C
Chao Yu 已提交
409
	make_dentry_ptr_inline(dir, &d, inline_dentry);
410 411 412 413 414 415 416 417 418 419 420 421 422

	while (bit_pos < d.max) {
		struct f2fs_dir_entry *de;
		struct qstr new_name;
		nid_t ino;
		umode_t fake_mode;

		if (!test_bit_le(bit_pos, d.bitmap)) {
			bit_pos++;
			continue;
		}

		de = &d.dentry[bit_pos];
423 424 425 426 427 428

		if (unlikely(!de->name_len)) {
			bit_pos++;
			continue;
		}

429
		new_name.name = d.filename[bit_pos];
E
Eric Biggers 已提交
430
		new_name.len = le16_to_cpu(de->name_len);
431 432

		ino = le32_to_cpu(de->ino);
C
Chao Yu 已提交
433
		fake_mode = f2fs_get_de_type(de) << S_SHIFT;
434

435
		err = f2fs_add_regular_entry(dir, &new_name, NULL, NULL,
436 437 438 439 440 441 442 443 444
							ino, fake_mode);
		if (err)
			goto punch_dentry_pages;

		bit_pos += GET_DENTRY_SLOTS(le16_to_cpu(de->name_len));
	}
	return 0;
punch_dentry_pages:
	truncate_inode_pages(&dir->i_data, 0);
C
Chao Yu 已提交
445 446
	f2fs_truncate_blocks(dir, 0, false);
	f2fs_remove_dirty_inode(dir);
447 448 449 450
	return err;
}

static int f2fs_move_rehashed_dirents(struct inode *dir, struct page *ipage,
C
Chao Yu 已提交
451
							void *inline_dentry)
452
{
C
Chao Yu 已提交
453
	void *backup_dentry;
454 455
	int err;

456
	backup_dentry = f2fs_kmalloc(F2FS_I_SB(dir),
C
Chao Yu 已提交
457
				MAX_INLINE_DATA(dir), GFP_F2FS_ZERO);
458 459
	if (!backup_dentry) {
		f2fs_put_page(ipage, 1);
460
		return -ENOMEM;
461
	}
462

C
Chao Yu 已提交
463
	memcpy(backup_dentry, inline_dentry, MAX_INLINE_DATA(dir));
C
Chao Yu 已提交
464
	f2fs_truncate_inline_inode(dir, ipage, 0);
465 466 467 468 469 470 471 472 473 474

	unlock_page(ipage);

	err = f2fs_add_inline_entries(dir, backup_dentry);
	if (err)
		goto recover;

	lock_page(ipage);

	stat_dec_inline_dir(dir);
475
	clear_inode_flag(dir, FI_INLINE_DENTRY);
476 477 478 479
	kfree(backup_dentry);
	return 0;
recover:
	lock_page(ipage);
C
Chao Yu 已提交
480
	memcpy(inline_dentry, backup_dentry, MAX_INLINE_DATA(dir));
481
	f2fs_i_depth_write(dir, 0);
C
Chao Yu 已提交
482
	f2fs_i_size_write(dir, MAX_INLINE_DATA(dir));
483
	set_page_dirty(ipage);
484 485 486 487 488 489 490
	f2fs_put_page(ipage, 1);

	kfree(backup_dentry);
	return err;
}

static int f2fs_convert_inline_dir(struct inode *dir, struct page *ipage,
C
Chao Yu 已提交
491
							void *inline_dentry)
492 493 494 495 496 497 498
{
	if (!F2FS_I(dir)->i_dir_level)
		return f2fs_move_inline_dirents(dir, ipage, inline_dentry);
	else
		return f2fs_move_rehashed_dirents(dir, ipage, inline_dentry);
}

499 500 501
int 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)
502 503 504 505 506
{
	struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
	struct page *ipage;
	unsigned int bit_pos;
	f2fs_hash_t name_hash;
C
Chao Yu 已提交
507
	void *inline_dentry = NULL;
508
	struct f2fs_dentry_ptr d;
509
	int slots = GET_DENTRY_SLOTS(new_name->len);
510
	struct page *page = NULL;
511 512
	int err = 0;

C
Chao Yu 已提交
513
	ipage = f2fs_get_node_page(sbi, dir->i_ino);
514 515 516
	if (IS_ERR(ipage))
		return PTR_ERR(ipage);

C
Chao Yu 已提交
517 518
	inline_dentry = inline_data_addr(dir, ipage);
	make_dentry_ptr_inline(dir, &d, inline_dentry);
519

C
Chao Yu 已提交
520
	bit_pos = f2fs_room_for_filename(d.bitmap, slots, d.max);
521
	if (bit_pos >= d.max) {
T
Tiezhu Yang 已提交
522
		err = f2fs_convert_inline_dir(dir, ipage, inline_dentry);
523 524 525
		if (err)
			return err;
		err = -EAGAIN;
526 527 528
		goto out;
	}

529 530
	if (inode) {
		down_write(&F2FS_I(inode)->i_sem);
C
Chao Yu 已提交
531
		page = f2fs_init_inode_metadata(inode, dir, new_name,
532
						orig_name, ipage);
533 534 535 536
		if (IS_ERR(page)) {
			err = PTR_ERR(page);
			goto fail;
		}
537
	}
538

539
	f2fs_wait_on_page_writeback(ipage, NODE, true);
540

541
	name_hash = f2fs_dentry_hash(new_name, NULL);
542
	f2fs_update_dentry(ino, mode, &d, new_name, name_hash, bit_pos);
543

544 545 546
	set_page_dirty(ipage);

	/* we don't need to mark_inode_dirty now */
547
	if (inode) {
548
		f2fs_i_pino_write(inode, dir->i_ino);
549 550
		f2fs_put_page(page, 1);
	}
551

C
Chao Yu 已提交
552
	f2fs_update_parent_metadata(dir, inode, 0);
553
fail:
554 555
	if (inode)
		up_write(&F2FS_I(inode)->i_sem);
556 557 558 559 560 561 562 563
out:
	f2fs_put_page(ipage, 1);
	return err;
}

void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry, struct page *page,
					struct inode *dir, struct inode *inode)
{
564
	struct f2fs_dentry_ptr d;
C
Chao Yu 已提交
565
	void *inline_dentry;
566 567 568 569 570
	int slots = GET_DENTRY_SLOTS(le16_to_cpu(dentry->name_len));
	unsigned int bit_pos;
	int i;

	lock_page(page);
571
	f2fs_wait_on_page_writeback(page, NODE, true);
572

C
Chao Yu 已提交
573 574
	inline_dentry = inline_data_addr(dir, page);
	make_dentry_ptr_inline(dir, &d, inline_dentry);
575 576

	bit_pos = dentry - d.dentry;
577
	for (i = 0; i < slots; i++)
578
		__clear_bit_le(bit_pos + i, d.bitmap);
579 580

	set_page_dirty(page);
J
Jaegeuk Kim 已提交
581
	f2fs_put_page(page, 1);
582

583
	dir->i_ctime = dir->i_mtime = current_time(dir);
584
	f2fs_mark_inode_dirty_sync(dir, false);
585 586

	if (inode)
J
Jaegeuk Kim 已提交
587
		f2fs_drop_nlink(dir, inode);
588 589 590 591 592 593 594
}

bool f2fs_empty_inline_dir(struct inode *dir)
{
	struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
	struct page *ipage;
	unsigned int bit_pos = 2;
C
Chao Yu 已提交
595
	void *inline_dentry;
596
	struct f2fs_dentry_ptr d;
597

C
Chao Yu 已提交
598
	ipage = f2fs_get_node_page(sbi, dir->i_ino);
599 600 601
	if (IS_ERR(ipage))
		return false;

C
Chao Yu 已提交
602 603
	inline_dentry = inline_data_addr(dir, ipage);
	make_dentry_ptr_inline(dir, &d, inline_dentry);
604 605

	bit_pos = find_next_bit_le(d.bitmap, d.max, bit_pos);
606 607 608

	f2fs_put_page(ipage, 1);

609
	if (bit_pos < d.max)
610 611 612 613 614
		return false;

	return true;
}

615
int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx,
616
				struct fscrypt_str *fstr)
617 618 619
{
	struct inode *inode = file_inode(file);
	struct page *ipage = NULL;
620
	struct f2fs_dentry_ptr d;
C
Chao Yu 已提交
621
	void *inline_dentry = NULL;
C
Chao Yu 已提交
622
	int err;
623

624 625 626
	make_dentry_ptr_inline(inode, &d, inline_dentry);

	if (ctx->pos == d.max)
627 628
		return 0;

C
Chao Yu 已提交
629
	ipage = f2fs_get_node_page(F2FS_I_SB(inode), inode->i_ino);
630 631 632
	if (IS_ERR(ipage))
		return PTR_ERR(ipage);

C
Chao Yu 已提交
633
	inline_dentry = inline_data_addr(inode, ipage);
634

635
	make_dentry_ptr_inline(inode, &d, inline_dentry);
636

C
Chao Yu 已提交
637 638
	err = f2fs_fill_dentries(ctx, &d, 0, fstr);
	if (!err)
639
		ctx->pos = d.max;
640

641
	f2fs_put_page(ipage, 1);
C
Chao Yu 已提交
642
	return err < 0 ? err : 0;
643
}
J
Jaegeuk Kim 已提交
644 645 646 647 648 649 650 651 652 653 654

int f2fs_inline_data_fiemap(struct inode *inode,
		struct fiemap_extent_info *fieinfo, __u64 start, __u64 len)
{
	__u64 byteaddr, ilen;
	__u32 flags = FIEMAP_EXTENT_DATA_INLINE | FIEMAP_EXTENT_NOT_ALIGNED |
		FIEMAP_EXTENT_LAST;
	struct node_info ni;
	struct page *ipage;
	int err = 0;

C
Chao Yu 已提交
655
	ipage = f2fs_get_node_page(F2FS_I_SB(inode), inode->i_ino);
J
Jaegeuk Kim 已提交
656 657 658 659 660 661 662 663
	if (IS_ERR(ipage))
		return PTR_ERR(ipage);

	if (!f2fs_has_inline_data(inode)) {
		err = -EAGAIN;
		goto out;
	}

C
Chao Yu 已提交
664
	ilen = min_t(size_t, MAX_INLINE_DATA(inode), i_size_read(inode));
J
Jaegeuk Kim 已提交
665 666 667 668 669 670
	if (start >= ilen)
		goto out;
	if (start + len < ilen)
		ilen = start + len;
	ilen -= start;

C
Chao Yu 已提交
671
	f2fs_get_node_info(F2FS_I_SB(inode), inode->i_ino, &ni);
J
Jaegeuk Kim 已提交
672
	byteaddr = (__u64)ni.blk_addr << inode->i_sb->s_blocksize_bits;
C
Chao Yu 已提交
673 674
	byteaddr += (char *)inline_data_addr(inode, ipage) -
					(char *)F2FS_INODE(ipage);
J
Jaegeuk Kim 已提交
675 676 677 678 679
	err = fiemap_fill_next_extent(fieinfo, start, byteaddr, ilen, flags);
out:
	f2fs_put_page(ipage, 1);
	return err;
}