blob: dd4cde8bfc4bbbf4d01445ba23a8d7ccd1448b24 [file] [log] [blame]
Huajun Lie18c65b2013-11-10 23:13:19 +08001/*
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"
Jaegeuk Kim67f8cf3c2015-10-15 11:34:49 -070015#include "node.h"
Mohan Srinivasan25cc70f2016-12-14 16:39:51 -080016#include <trace/events/android_fs.h>
Huajun Lie18c65b2013-11-10 23:13:19 +080017
Jaegeuk Kim01b960e2015-04-23 10:27:21 -070018bool f2fs_may_inline_data(struct inode *inode)
Huajun Lie18c65b2013-11-10 23:13:19 +080019{
Jaegeuk Kim88b88a62014-10-06 17:39:50 -070020 if (f2fs_is_atomic_file(inode))
21 return false;
22
Wanpeng Li368a0e42015-03-19 13:23:48 +080023 if (!S_ISREG(inode->i_mode) && !S_ISLNK(inode->i_mode))
Huajun Lie18c65b2013-11-10 23:13:19 +080024 return false;
25
Hyojun Kim63da4202017-10-06 17:10:08 -070026 if (i_size_read(inode) > MAX_INLINE_DATA(inode))
Jaegeuk Kim92dffd02014-11-11 14:10:01 -080027 return false;
28
Eric Biggersc6299742018-04-18 11:09:48 -070029 if (f2fs_post_read_required(inode))
Jaegeuk Kimfcc85a42015-04-21 20:39:58 -070030 return false;
31
Huajun Lie18c65b2013-11-10 23:13:19 +080032 return true;
33}
34
Jaegeuk Kim01b960e2015-04-23 10:27:21 -070035bool f2fs_may_inline_dentry(struct inode *inode)
36{
37 if (!test_opt(F2FS_I_SB(inode), INLINE_DENTRY))
38 return false;
39
40 if (!S_ISDIR(inode->i_mode))
41 return false;
42
43 return true;
44}
45
Chao Yu6b4d6a82018-05-30 00:20:41 +080046void f2fs_do_read_inline_data(struct page *page, struct page *ipage)
Huajun Lie18c65b2013-11-10 23:13:19 +080047{
Hyojun Kim63da4202017-10-06 17:10:08 -070048 struct inode *inode = page->mapping->host;
Huajun Lie18c65b2013-11-10 23:13:19 +080049 void *src_addr, *dst_addr;
50
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -070051 if (PageUptodate(page))
52 return;
Chao Yu04a17fb2013-12-30 18:36:23 +080053
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -070054 f2fs_bug_on(F2FS_P_SB(page), page->index);
Huajun Lie18c65b2013-11-10 23:13:19 +080055
Hyojun Kim63da4202017-10-06 17:10:08 -070056 zero_user_segment(page, MAX_INLINE_DATA(inode), PAGE_SIZE);
Huajun Lie18c65b2013-11-10 23:13:19 +080057
58 /* Copy the whole inline data block */
Hyojun Kim63da4202017-10-06 17:10:08 -070059 src_addr = inline_data_addr(inode, ipage);
Jaegeuk Kimf1e33a02014-10-18 23:41:38 -070060 dst_addr = kmap_atomic(page);
Hyojun Kim63da4202017-10-06 17:10:08 -070061 memcpy(dst_addr, src_addr, MAX_INLINE_DATA(inode));
Jaegeuk Kim427a45c2014-10-26 22:59:27 -070062 flush_dcache_page(page);
Jaegeuk Kimf1e33a02014-10-18 23:41:38 -070063 kunmap_atomic(dst_addr);
Jaegeuk Kim237c0792016-06-30 18:49:15 -070064 if (!PageUptodate(page))
65 SetPageUptodate(page);
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -070066}
Huajun Lie18c65b2013-11-10 23:13:19 +080067
Chao Yu6b4d6a82018-05-30 00:20:41 +080068void f2fs_truncate_inline_inode(struct inode *inode,
69 struct page *ipage, u64 from)
Chao Yufeeb0de2015-01-26 20:22:55 +080070{
Chao Yu0bfcfcc2015-03-10 13:16:25 +080071 void *addr;
72
Hyojun Kim63da4202017-10-06 17:10:08 -070073 if (from >= MAX_INLINE_DATA(inode))
74 return;
Chao Yu0bfcfcc2015-03-10 13:16:25 +080075
Hyojun Kim63da4202017-10-06 17:10:08 -070076 addr = inline_data_addr(inode, ipage);
Chao Yu0bfcfcc2015-03-10 13:16:25 +080077
Jaegeuk Kimfec1d652016-01-20 23:43:51 +080078 f2fs_wait_on_page_writeback(ipage, NODE, true);
Hyojun Kim63da4202017-10-06 17:10:08 -070079 memset(addr + from, 0, MAX_INLINE_DATA(inode) - from);
Jaegeuk Kimee6d1822016-05-20 16:32:49 -070080 set_page_dirty(ipage);
Hyojun Kim63da4202017-10-06 17:10:08 -070081
82 if (from == 0)
83 clear_inode_flag(inode, FI_DATA_EXIST);
Chao Yufeeb0de2015-01-26 20:22:55 +080084}
85
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -070086int f2fs_read_inline_data(struct inode *inode, struct page *page)
87{
88 struct page *ipage;
89
Mohan Srinivasan009e6082017-02-10 14:26:23 -080090 if (trace_android_fs_dataread_start_enabled()) {
91 char *path, pathbuf[MAX_TRACE_PATHBUF_LEN];
92
93 path = android_fstrace_get_pathname(pathbuf,
94 MAX_TRACE_PATHBUF_LEN,
95 inode);
96 trace_android_fs_dataread_start(inode, page_offset(page),
97 PAGE_SIZE, current->pid,
98 path, current->comm);
99 }
Mohan Srinivasan25cc70f2016-12-14 16:39:51 -0800100
Chao Yu6b4d6a82018-05-30 00:20:41 +0800101 ipage = f2fs_get_node_page(F2FS_I_SB(inode), inode->i_ino);
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -0700102 if (IS_ERR(ipage)) {
Mohan Srinivasan25cc70f2016-12-14 16:39:51 -0800103 trace_android_fs_dataread_end(inode, page_offset(page),
104 PAGE_SIZE);
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -0700105 unlock_page(page);
106 return PTR_ERR(ipage);
107 }
108
109 if (!f2fs_has_inline_data(inode)) {
110 f2fs_put_page(ipage, 1);
Mohan Srinivasan25cc70f2016-12-14 16:39:51 -0800111 trace_android_fs_dataread_end(inode, page_offset(page),
112 PAGE_SIZE);
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -0700113 return -EAGAIN;
114 }
115
116 if (page->index)
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +0300117 zero_user_segment(page, 0, PAGE_SIZE);
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -0700118 else
Chao Yu6b4d6a82018-05-30 00:20:41 +0800119 f2fs_do_read_inline_data(page, ipage);
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -0700120
Jaegeuk Kim237c0792016-06-30 18:49:15 -0700121 if (!PageUptodate(page))
122 SetPageUptodate(page);
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -0700123 f2fs_put_page(ipage, 1);
Mohan Srinivasan25cc70f2016-12-14 16:39:51 -0800124 trace_android_fs_dataread_end(inode, page_offset(page),
125 PAGE_SIZE);
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -0700126 unlock_page(page);
Huajun Lie18c65b2013-11-10 23:13:19 +0800127 return 0;
128}
129
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -0700130int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page)
Huajun Lie18c65b2013-11-10 23:13:19 +0800131{
Huajun Lie18c65b2013-11-10 23:13:19 +0800132 struct f2fs_io_info fio = {
Jaegeuk Kim05ca3632015-04-23 14:38:15 -0700133 .sbi = F2FS_I_SB(dn->inode),
Jaegeuk Kim8ae26d12017-09-23 17:02:18 +0800134 .ino = dn->inode->i_ino,
Huajun Lie18c65b2013-11-10 23:13:19 +0800135 .type = DATA,
Mike Christie04d328d2016-06-05 14:31:55 -0500136 .op = REQ_OP_WRITE,
Hyojun Kim63da4202017-10-06 17:10:08 -0700137 .op_flags = REQ_SYNC | REQ_PRIO,
Jaegeuk Kim05ca3632015-04-23 14:38:15 -0700138 .page = page,
Jaegeuk Kim4375a332015-04-23 12:04:33 -0700139 .encrypted_page = NULL,
Hyojun Kim63da4202017-10-06 17:10:08 -0700140 .io_type = FS_DATA_IO,
Huajun Lie18c65b2013-11-10 23:13:19 +0800141 };
Jaegeuk Kim158c1942014-11-25 11:34:02 -0800142 int dirty, err;
Huajun Lie18c65b2013-11-10 23:13:19 +0800143
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -0700144 if (!f2fs_exist_data(dn->inode))
145 goto clear_out;
Jaegeuk Kimec4e7af2014-08-18 14:41:11 -0700146
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -0700147 err = f2fs_reserve_block(dn, 0);
Jaegeuk Kim15c6e3a2014-04-16 14:22:50 +0900148 if (err)
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -0700149 return err;
Huajun Lie18c65b2013-11-10 23:13:19 +0800150
Chao Yu7e0782c2018-06-30 18:13:40 +0800151 if (unlikely(dn->data_blkaddr != NEW_ADDR)) {
152 f2fs_put_dnode(dn);
153 set_sbi_flag(fio.sbi, SBI_NEED_FSCK);
154 f2fs_msg(fio.sbi->sb, KERN_WARNING,
155 "%s: corrupted inline inode ino=%lx, i_addr[0]:0x%x, "
156 "run fsck to fix.",
157 __func__, dn->inode->i_ino, dn->data_blkaddr);
158 return -EINVAL;
159 }
160
Yunlei He85ead812016-02-03 10:26:13 +0800161 f2fs_bug_on(F2FS_P_SB(page), PageWriteback(page));
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -0700162
Chao Yu6b4d6a82018-05-30 00:20:41 +0800163 f2fs_do_read_inline_data(page, dn->inode_page);
Jaegeuk Kim6282adb2015-07-25 00:29:17 -0700164 set_page_dirty(page);
165
Jaegeuk Kim158c1942014-11-25 11:34:02 -0800166 /* clear dirty state */
167 dirty = clear_page_dirty_for_io(page);
168
Huajun Lie18c65b2013-11-10 23:13:19 +0800169 /* write data page to try to make data consistent */
170 set_page_writeback(page);
Jaegeuk Kim9731a2d2018-04-11 23:09:04 -0700171 ClearPageError(page);
Chao Yu7a9d7542016-02-22 18:36:38 +0800172 fio.old_blkaddr = dn->data_blkaddr;
Hyojun Kim63da4202017-10-06 17:10:08 -0700173 set_inode_flag(dn->inode, FI_HOT_DATA);
Chao Yu6b4d6a82018-05-30 00:20:41 +0800174 f2fs_outplace_write_data(dn, &fio);
Jaegeuk Kimfec1d652016-01-20 23:43:51 +0800175 f2fs_wait_on_page_writeback(page, DATA, true);
Hyojun Kim63da4202017-10-06 17:10:08 -0700176 if (dirty) {
Jaegeuk Kim158c1942014-11-25 11:34:02 -0800177 inode_dec_dirty_pages(dn->inode);
Chao Yu6b4d6a82018-05-30 00:20:41 +0800178 f2fs_remove_dirty_inode(dn->inode);
Hyojun Kim63da4202017-10-06 17:10:08 -0700179 }
Huajun Lie18c65b2013-11-10 23:13:19 +0800180
Jaegeuk Kim95f5b0f2014-11-25 17:27:38 -0800181 /* this converted inline_data should be recovered. */
Jaegeuk Kim91942322016-05-20 10:13:22 -0700182 set_inode_flag(dn->inode, FI_APPEND_WRITE);
Jaegeuk Kim95f5b0f2014-11-25 17:27:38 -0800183
Huajun Lie18c65b2013-11-10 23:13:19 +0800184 /* clear inline data and flag after data writeback */
Chao Yu6b4d6a82018-05-30 00:20:41 +0800185 f2fs_truncate_inline_inode(dn->inode, dn->inode_page, 0);
Jaegeuk Kim2049d4f2016-01-25 05:57:05 -0800186 clear_inline_node(dn->inode_page);
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -0700187clear_out:
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -0700188 stat_dec_inline_inode(dn->inode);
Hyojun Kim63da4202017-10-06 17:10:08 -0700189 clear_inode_flag(dn->inode, FI_INLINE_DATA);
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -0700190 f2fs_put_dnode(dn);
191 return 0;
Huajun Lie18c65b2013-11-10 23:13:19 +0800192}
193
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -0700194int f2fs_convert_inline_inode(struct inode *inode)
Huajun Lie18c65b2013-11-10 23:13:19 +0800195{
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -0700196 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
197 struct dnode_of_data dn;
198 struct page *ipage, *page;
199 int err = 0;
Huajun Lie18c65b2013-11-10 23:13:19 +0800200
Jaegeuk Kimb9d777b2015-12-22 11:09:35 -0800201 if (!f2fs_has_inline_data(inode))
202 return 0;
203
Jaegeuk Kim300e1292016-04-29 16:11:53 -0700204 page = f2fs_grab_cache_page(inode->i_mapping, 0, false);
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -0700205 if (!page)
206 return -ENOMEM;
Jaegeuk Kim9e09fc82013-12-27 12:28:59 +0900207
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -0700208 f2fs_lock_op(sbi);
209
Chao Yu6b4d6a82018-05-30 00:20:41 +0800210 ipage = f2fs_get_node_page(sbi, inode->i_ino);
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -0700211 if (IS_ERR(ipage)) {
Jaegeuk Kim6d20aff2014-11-17 16:06:55 -0800212 err = PTR_ERR(ipage);
213 goto out;
Jaegeuk Kimb067ba12014-08-07 16:32:25 -0700214 }
Huajun Lie18c65b2013-11-10 23:13:19 +0800215
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -0700216 set_new_dnode(&dn, inode, ipage, ipage, 0);
217
218 if (f2fs_has_inline_data(inode))
219 err = f2fs_convert_inline_page(&dn, page);
220
221 f2fs_put_dnode(&dn);
Jaegeuk Kim6d20aff2014-11-17 16:06:55 -0800222out:
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -0700223 f2fs_unlock_op(sbi);
224
225 f2fs_put_page(page, 1);
Jaegeuk Kim2a340762015-12-22 13:23:35 -0800226
Jaegeuk Kim2c4db1a2016-01-07 14:15:04 -0800227 f2fs_balance_fs(sbi, dn.node_changed);
Jaegeuk Kim2a340762015-12-22 13:23:35 -0800228
Huajun Lie18c65b2013-11-10 23:13:19 +0800229 return err;
230}
231
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -0700232int f2fs_write_inline_data(struct inode *inode, struct page *page)
Huajun Lie18c65b2013-11-10 23:13:19 +0800233{
234 void *src_addr, *dst_addr;
Huajun Lie18c65b2013-11-10 23:13:19 +0800235 struct dnode_of_data dn;
236 int err;
237
238 set_new_dnode(&dn, inode, NULL, NULL, 0);
Chao Yu6b4d6a82018-05-30 00:20:41 +0800239 err = f2fs_get_dnode_of_data(&dn, 0, LOOKUP_NODE);
Huajun Lie18c65b2013-11-10 23:13:19 +0800240 if (err)
241 return err;
Huajun Lie18c65b2013-11-10 23:13:19 +0800242
Jaegeuk Kimc08a6902014-10-15 10:16:54 -0700243 if (!f2fs_has_inline_data(inode)) {
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -0700244 f2fs_put_dnode(&dn);
245 return -EAGAIN;
Jaegeuk Kimc08a6902014-10-15 10:16:54 -0700246 }
247
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -0700248 f2fs_bug_on(F2FS_I_SB(inode), page->index);
249
Jaegeuk Kimfec1d652016-01-20 23:43:51 +0800250 f2fs_wait_on_page_writeback(dn.inode_page, NODE, true);
Jaegeuk Kimf1e33a02014-10-18 23:41:38 -0700251 src_addr = kmap_atomic(page);
Hyojun Kim63da4202017-10-06 17:10:08 -0700252 dst_addr = inline_data_addr(inode, dn.inode_page);
253 memcpy(dst_addr, src_addr, MAX_INLINE_DATA(inode));
Jaegeuk Kimf1e33a02014-10-18 23:41:38 -0700254 kunmap_atomic(src_addr);
Jaegeuk Kimee6d1822016-05-20 16:32:49 -0700255 set_page_dirty(dn.inode_page);
Huajun Lie18c65b2013-11-10 23:13:19 +0800256
Chao Yu6b4d6a82018-05-30 00:20:41 +0800257 f2fs_clear_radix_tree_dirty_tag(page);
Hyojun Kim63da4202017-10-06 17:10:08 -0700258
Jaegeuk Kim91942322016-05-20 10:13:22 -0700259 set_inode_flag(inode, FI_APPEND_WRITE);
260 set_inode_flag(inode, FI_DATA_EXIST);
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -0700261
Jaegeuk Kim2049d4f2016-01-25 05:57:05 -0800262 clear_inline_node(dn.inode_page);
Huajun Lie18c65b2013-11-10 23:13:19 +0800263 f2fs_put_dnode(&dn);
Huajun Lie18c65b2013-11-10 23:13:19 +0800264 return 0;
265}
Jaegeuk Kim1e1bb4b2013-12-26 12:49:48 +0900266
Chao Yu6b4d6a82018-05-30 00:20:41 +0800267bool f2fs_recover_inline_data(struct inode *inode, struct page *npage)
Jaegeuk Kim1e1bb4b2013-12-26 12:49:48 +0900268{
Jaegeuk Kim40813632014-09-02 15:31:18 -0700269 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
Jaegeuk Kim1e1bb4b2013-12-26 12:49:48 +0900270 struct f2fs_inode *ri = NULL;
271 void *src_addr, *dst_addr;
272 struct page *ipage;
273
274 /*
275 * The inline_data recovery policy is as follows.
276 * [prev.] [next] of inline_data flag
277 * o o -> recover inline_data
278 * o x -> remove inline_data, and then recover data blocks
279 * x o -> remove inline_data, and then recover inline_data
280 * x x -> recover data blocks
281 */
282 if (IS_INODE(npage))
283 ri = F2FS_INODE(npage);
284
285 if (f2fs_has_inline_data(inode) &&
Jaegeuk Kim0342fd32014-08-07 16:57:17 -0700286 ri && (ri->i_inline & F2FS_INLINE_DATA)) {
Jaegeuk Kim1e1bb4b2013-12-26 12:49:48 +0900287process_inline:
Chao Yu6b4d6a82018-05-30 00:20:41 +0800288 ipage = f2fs_get_node_page(sbi, inode->i_ino);
Jaegeuk Kim9850cf42014-09-02 15:52:58 -0700289 f2fs_bug_on(sbi, IS_ERR(ipage));
Jaegeuk Kim1e1bb4b2013-12-26 12:49:48 +0900290
Jaegeuk Kimfec1d652016-01-20 23:43:51 +0800291 f2fs_wait_on_page_writeback(ipage, NODE, true);
Jaegeuk Kim54b591d2014-04-29 17:28:32 +0900292
Hyojun Kim63da4202017-10-06 17:10:08 -0700293 src_addr = inline_data_addr(inode, npage);
294 dst_addr = inline_data_addr(inode, ipage);
295 memcpy(dst_addr, src_addr, MAX_INLINE_DATA(inode));
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -0700296
Jaegeuk Kim91942322016-05-20 10:13:22 -0700297 set_inode_flag(inode, FI_INLINE_DATA);
298 set_inode_flag(inode, FI_DATA_EXIST);
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -0700299
Jaegeuk Kimee6d1822016-05-20 16:32:49 -0700300 set_page_dirty(ipage);
Jaegeuk Kim1e1bb4b2013-12-26 12:49:48 +0900301 f2fs_put_page(ipage, 1);
Jaegeuk Kim0342fd32014-08-07 16:57:17 -0700302 return true;
Jaegeuk Kim1e1bb4b2013-12-26 12:49:48 +0900303 }
304
305 if (f2fs_has_inline_data(inode)) {
Chao Yu6b4d6a82018-05-30 00:20:41 +0800306 ipage = f2fs_get_node_page(sbi, inode->i_ino);
Jaegeuk Kim9850cf42014-09-02 15:52:58 -0700307 f2fs_bug_on(sbi, IS_ERR(ipage));
Chao Yu6b4d6a82018-05-30 00:20:41 +0800308 f2fs_truncate_inline_inode(inode, ipage, 0);
Hyojun Kim63da4202017-10-06 17:10:08 -0700309 clear_inode_flag(inode, FI_INLINE_DATA);
Jaegeuk Kim1e1bb4b2013-12-26 12:49:48 +0900310 f2fs_put_page(ipage, 1);
Jaegeuk Kim0342fd32014-08-07 16:57:17 -0700311 } else if (ri && (ri->i_inline & F2FS_INLINE_DATA)) {
Chao Yu6b4d6a82018-05-30 00:20:41 +0800312 if (f2fs_truncate_blocks(inode, 0, false))
Nicholas Krause545fe422015-09-21 18:55:49 -0400313 return false;
Jaegeuk Kim1e1bb4b2013-12-26 12:49:48 +0900314 goto process_inline;
315 }
Jaegeuk Kim0342fd32014-08-07 16:57:17 -0700316 return false;
Jaegeuk Kim1e1bb4b2013-12-26 12:49:48 +0900317}
Chao Yu201a05b2014-09-24 18:17:53 +0800318
Chao Yu6b4d6a82018-05-30 00:20:41 +0800319struct f2fs_dir_entry *f2fs_find_in_inline_dir(struct inode *dir,
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700320 struct fscrypt_name *fname, struct page **res_page)
Chao Yu201a05b2014-09-24 18:17:53 +0800321{
322 struct f2fs_sb_info *sbi = F2FS_SB(dir->i_sb);
Jaegeuk Kim6e22c692015-04-27 17:12:39 -0700323 struct qstr name = FSTR_TO_QSTR(&fname->disk_name);
Chao Yu201a05b2014-09-24 18:17:53 +0800324 struct f2fs_dir_entry *de;
Jaegeuk Kim7b3cd7d2014-10-18 22:52:52 -0700325 struct f2fs_dentry_ptr d;
Jaegeuk Kim4e6ebf62014-10-13 17:26:14 -0700326 struct page *ipage;
Hyojun Kim63da4202017-10-06 17:10:08 -0700327 void *inline_dentry;
Jaegeuk Kim6e22c692015-04-27 17:12:39 -0700328 f2fs_hash_t namehash;
Chao Yu201a05b2014-09-24 18:17:53 +0800329
Chao Yu6b4d6a82018-05-30 00:20:41 +0800330 ipage = f2fs_get_node_page(sbi, dir->i_ino);
Jaegeuk Kim42d96402016-05-25 14:29:11 -0700331 if (IS_ERR(ipage)) {
332 *res_page = ipage;
Chao Yu201a05b2014-09-24 18:17:53 +0800333 return NULL;
Jaegeuk Kim42d96402016-05-25 14:29:11 -0700334 }
Chao Yu201a05b2014-09-24 18:17:53 +0800335
Jaegeuk Kim8daed212017-04-24 10:00:08 -0700336 namehash = f2fs_dentry_hash(&name, fname);
Jaegeuk Kim6e22c692015-04-27 17:12:39 -0700337
Hyojun Kim63da4202017-10-06 17:10:08 -0700338 inline_dentry = inline_data_addr(dir, ipage);
Chao Yu201a05b2014-09-24 18:17:53 +0800339
Hyojun Kim63da4202017-10-06 17:10:08 -0700340 make_dentry_ptr_inline(dir, &d, inline_dentry);
Chao Yu6b4d6a82018-05-30 00:20:41 +0800341 de = f2fs_find_target_dentry(fname, namehash, NULL, &d);
Chao Yu201a05b2014-09-24 18:17:53 +0800342 unlock_page(ipage);
Jaegeuk Kim4e6ebf62014-10-13 17:26:14 -0700343 if (de)
344 *res_page = ipage;
345 else
346 f2fs_put_page(ipage, 0);
347
Chao Yu201a05b2014-09-24 18:17:53 +0800348 return de;
349}
350
Chao Yu6b4d6a82018-05-30 00:20:41 +0800351int f2fs_make_empty_inline_dir(struct inode *inode, struct inode *parent,
Chao Yu201a05b2014-09-24 18:17:53 +0800352 struct page *ipage)
353{
Jaegeuk Kim062a3e72014-10-18 23:06:41 -0700354 struct f2fs_dentry_ptr d;
Hyojun Kim63da4202017-10-06 17:10:08 -0700355 void *inline_dentry;
Chao Yu201a05b2014-09-24 18:17:53 +0800356
Hyojun Kim63da4202017-10-06 17:10:08 -0700357 inline_dentry = inline_data_addr(inode, ipage);
Chao Yu201a05b2014-09-24 18:17:53 +0800358
Hyojun Kim63da4202017-10-06 17:10:08 -0700359 make_dentry_ptr_inline(inode, &d, inline_dentry);
Chao Yu6b4d6a82018-05-30 00:20:41 +0800360 f2fs_do_make_empty_dir(inode, parent, &d);
Chao Yu201a05b2014-09-24 18:17:53 +0800361
362 set_page_dirty(ipage);
363
364 /* update i_size to MAX_INLINE_DATA */
Hyojun Kim63da4202017-10-06 17:10:08 -0700365 if (i_size_read(inode) < MAX_INLINE_DATA(inode))
366 f2fs_i_size_write(inode, MAX_INLINE_DATA(inode));
Chao Yu201a05b2014-09-24 18:17:53 +0800367 return 0;
368}
369
Chao Yu470f00e2015-07-14 18:14:06 +0800370/*
371 * NOTE: ipage is grabbed by caller, but if any error occurs, we should
372 * release ipage in this function.
373 */
Chao Yu675f10b2016-02-22 18:29:18 +0800374static int f2fs_move_inline_dirents(struct inode *dir, struct page *ipage,
Hyojun Kim63da4202017-10-06 17:10:08 -0700375 void *inline_dentry)
Chao Yu201a05b2014-09-24 18:17:53 +0800376{
377 struct page *page;
378 struct dnode_of_data dn;
379 struct f2fs_dentry_block *dentry_blk;
Hyojun Kim63da4202017-10-06 17:10:08 -0700380 struct f2fs_dentry_ptr src, dst;
Chao Yu201a05b2014-09-24 18:17:53 +0800381 int err;
382
Jaegeuk Kim300e1292016-04-29 16:11:53 -0700383 page = f2fs_grab_cache_page(dir->i_mapping, 0, false);
Chao Yu470f00e2015-07-14 18:14:06 +0800384 if (!page) {
385 f2fs_put_page(ipage, 1);
Chao Yu201a05b2014-09-24 18:17:53 +0800386 return -ENOMEM;
Chao Yu470f00e2015-07-14 18:14:06 +0800387 }
Chao Yu201a05b2014-09-24 18:17:53 +0800388
389 set_new_dnode(&dn, dir, ipage, NULL, 0);
390 err = f2fs_reserve_block(&dn, 0);
391 if (err)
392 goto out;
393
Chao Yu7e0782c2018-06-30 18:13:40 +0800394 if (unlikely(dn.data_blkaddr != NEW_ADDR)) {
395 f2fs_put_dnode(&dn);
396 set_sbi_flag(F2FS_P_SB(page), SBI_NEED_FSCK);
397 f2fs_msg(F2FS_P_SB(page)->sb, KERN_WARNING,
398 "%s: corrupted inline inode ino=%lx, i_addr[0]:0x%x, "
399 "run fsck to fix.",
400 __func__, dir->i_ino, dn.data_blkaddr);
401 err = -EINVAL;
402 goto out;
403 }
404
Jaegeuk Kimfec1d652016-01-20 23:43:51 +0800405 f2fs_wait_on_page_writeback(page, DATA, true);
Chao Yu201a05b2014-09-24 18:17:53 +0800406
Yunlong Song97d7f1c2018-02-28 20:31:52 +0800407 dentry_blk = page_address(page);
Chao Yu201a05b2014-09-24 18:17:53 +0800408
Hyojun Kim63da4202017-10-06 17:10:08 -0700409 make_dentry_ptr_inline(dir, &src, inline_dentry);
410 make_dentry_ptr_block(dir, &dst, dentry_blk);
411
Chao Yu201a05b2014-09-24 18:17:53 +0800412 /* copy data from inline dentry block to new dentry block */
Hyojun Kim63da4202017-10-06 17:10:08 -0700413 memcpy(dst.bitmap, src.bitmap, src.nr_bitmap);
414 memset(dst.bitmap + src.nr_bitmap, 0, dst.nr_bitmap - src.nr_bitmap);
Chao Yu4ec17d62015-08-24 17:36:25 +0800415 /*
416 * we do not need to zero out remainder part of dentry and filename
417 * field, since we have used bitmap for marking the usage status of
418 * them, besides, we can also ignore copying/zeroing reserved space
419 * of dentry block, because them haven't been used so far.
420 */
Hyojun Kim63da4202017-10-06 17:10:08 -0700421 memcpy(dst.dentry, src.dentry, SIZE_OF_DIR_ENTRY * src.max);
422 memcpy(dst.filename, src.filename, src.max * F2FS_SLOT_LEN);
Chao Yu201a05b2014-09-24 18:17:53 +0800423
Jaegeuk Kim237c0792016-06-30 18:49:15 -0700424 if (!PageUptodate(page))
425 SetPageUptodate(page);
Chao Yu201a05b2014-09-24 18:17:53 +0800426 set_page_dirty(page);
427
428 /* clear inline dir and flag after data writeback */
Chao Yu6b4d6a82018-05-30 00:20:41 +0800429 f2fs_truncate_inline_inode(dir, ipage, 0);
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -0700430
Jaegeuk Kim3289c062014-10-13 20:00:16 -0700431 stat_dec_inline_dir(dir);
Jaegeuk Kim91942322016-05-20 10:13:22 -0700432 clear_inode_flag(dir, FI_INLINE_DENTRY);
Chao Yu201a05b2014-09-24 18:17:53 +0800433
Jaegeuk Kim205b9822016-05-20 09:52:20 -0700434 f2fs_i_depth_write(dir, 1);
Jaegeuk Kimee6d1822016-05-20 16:32:49 -0700435 if (i_size_read(dir) < PAGE_SIZE)
Jaegeuk Kimfc9581c2016-05-20 09:22:03 -0700436 f2fs_i_size_write(dir, PAGE_SIZE);
Chao Yu201a05b2014-09-24 18:17:53 +0800437out:
438 f2fs_put_page(page, 1);
439 return err;
440}
441
Hyojun Kim63da4202017-10-06 17:10:08 -0700442static int f2fs_add_inline_entries(struct inode *dir, void *inline_dentry)
Chao Yu675f10b2016-02-22 18:29:18 +0800443{
444 struct f2fs_dentry_ptr d;
445 unsigned long bit_pos = 0;
446 int err = 0;
447
Hyojun Kim63da4202017-10-06 17:10:08 -0700448 make_dentry_ptr_inline(dir, &d, inline_dentry);
Chao Yu675f10b2016-02-22 18:29:18 +0800449
450 while (bit_pos < d.max) {
451 struct f2fs_dir_entry *de;
452 struct qstr new_name;
453 nid_t ino;
454 umode_t fake_mode;
455
456 if (!test_bit_le(bit_pos, d.bitmap)) {
457 bit_pos++;
458 continue;
459 }
460
461 de = &d.dentry[bit_pos];
Chao Yua4a13f52016-04-27 22:22:20 +0800462
463 if (unlikely(!de->name_len)) {
464 bit_pos++;
465 continue;
466 }
467
Chao Yu675f10b2016-02-22 18:29:18 +0800468 new_name.name = d.filename[bit_pos];
Hyojun Kim63da4202017-10-06 17:10:08 -0700469 new_name.len = le16_to_cpu(de->name_len);
Chao Yu675f10b2016-02-22 18:29:18 +0800470
471 ino = le32_to_cpu(de->ino);
Chao Yu6b4d6a82018-05-30 00:20:41 +0800472 fake_mode = f2fs_get_de_type(de) << S_SHIFT;
Chao Yu675f10b2016-02-22 18:29:18 +0800473
Chao Yu9421d572016-08-28 18:57:55 +0800474 err = f2fs_add_regular_entry(dir, &new_name, NULL, NULL,
Chao Yu675f10b2016-02-22 18:29:18 +0800475 ino, fake_mode);
476 if (err)
477 goto punch_dentry_pages;
478
Chao Yu675f10b2016-02-22 18:29:18 +0800479 bit_pos += GET_DENTRY_SLOTS(le16_to_cpu(de->name_len));
480 }
481 return 0;
482punch_dentry_pages:
483 truncate_inode_pages(&dir->i_data, 0);
Chao Yu6b4d6a82018-05-30 00:20:41 +0800484 f2fs_truncate_blocks(dir, 0, false);
485 f2fs_remove_dirty_inode(dir);
Chao Yu675f10b2016-02-22 18:29:18 +0800486 return err;
487}
488
489static int f2fs_move_rehashed_dirents(struct inode *dir, struct page *ipage,
Hyojun Kim63da4202017-10-06 17:10:08 -0700490 void *inline_dentry)
Chao Yu675f10b2016-02-22 18:29:18 +0800491{
Hyojun Kim63da4202017-10-06 17:10:08 -0700492 void *backup_dentry;
Chao Yu675f10b2016-02-22 18:29:18 +0800493 int err;
494
Chao Yu1ecc0c52016-09-23 21:30:09 +0800495 backup_dentry = f2fs_kmalloc(F2FS_I_SB(dir),
Hyojun Kim63da4202017-10-06 17:10:08 -0700496 MAX_INLINE_DATA(dir), GFP_F2FS_ZERO);
Chao Yu8975bdf2016-05-14 19:03:53 +0800497 if (!backup_dentry) {
498 f2fs_put_page(ipage, 1);
Chao Yu675f10b2016-02-22 18:29:18 +0800499 return -ENOMEM;
Chao Yu8975bdf2016-05-14 19:03:53 +0800500 }
Chao Yu675f10b2016-02-22 18:29:18 +0800501
Hyojun Kim63da4202017-10-06 17:10:08 -0700502 memcpy(backup_dentry, inline_dentry, MAX_INLINE_DATA(dir));
Chao Yu6b4d6a82018-05-30 00:20:41 +0800503 f2fs_truncate_inline_inode(dir, ipage, 0);
Chao Yu675f10b2016-02-22 18:29:18 +0800504
505 unlock_page(ipage);
506
507 err = f2fs_add_inline_entries(dir, backup_dentry);
508 if (err)
509 goto recover;
510
511 lock_page(ipage);
512
513 stat_dec_inline_dir(dir);
Jaegeuk Kim91942322016-05-20 10:13:22 -0700514 clear_inode_flag(dir, FI_INLINE_DENTRY);
Chao Yu675f10b2016-02-22 18:29:18 +0800515 kfree(backup_dentry);
516 return 0;
517recover:
518 lock_page(ipage);
Hyojun Kim63da4202017-10-06 17:10:08 -0700519 memcpy(inline_dentry, backup_dentry, MAX_INLINE_DATA(dir));
Jaegeuk Kim205b9822016-05-20 09:52:20 -0700520 f2fs_i_depth_write(dir, 0);
Hyojun Kim63da4202017-10-06 17:10:08 -0700521 f2fs_i_size_write(dir, MAX_INLINE_DATA(dir));
Jaegeuk Kimee6d1822016-05-20 16:32:49 -0700522 set_page_dirty(ipage);
Chao Yu675f10b2016-02-22 18:29:18 +0800523 f2fs_put_page(ipage, 1);
524
525 kfree(backup_dentry);
526 return err;
527}
528
529static int f2fs_convert_inline_dir(struct inode *dir, struct page *ipage,
Hyojun Kim63da4202017-10-06 17:10:08 -0700530 void *inline_dentry)
Chao Yu675f10b2016-02-22 18:29:18 +0800531{
532 if (!F2FS_I(dir)->i_dir_level)
533 return f2fs_move_inline_dirents(dir, ipage, inline_dentry);
534 else
535 return f2fs_move_rehashed_dirents(dir, ipage, inline_dentry);
536}
537
Chao Yu9421d572016-08-28 18:57:55 +0800538int f2fs_add_inline_entry(struct inode *dir, const struct qstr *new_name,
539 const struct qstr *orig_name,
540 struct inode *inode, nid_t ino, umode_t mode)
Chao Yu201a05b2014-09-24 18:17:53 +0800541{
542 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
543 struct page *ipage;
544 unsigned int bit_pos;
545 f2fs_hash_t name_hash;
Hyojun Kim63da4202017-10-06 17:10:08 -0700546 void *inline_dentry = NULL;
Chao Yu3b4d7322015-02-16 16:17:20 +0800547 struct f2fs_dentry_ptr d;
Chao Yu9421d572016-08-28 18:57:55 +0800548 int slots = GET_DENTRY_SLOTS(new_name->len);
Jaegeuk Kim510022a2015-03-30 15:07:16 -0700549 struct page *page = NULL;
Chao Yu201a05b2014-09-24 18:17:53 +0800550 int err = 0;
Chao Yu201a05b2014-09-24 18:17:53 +0800551
Chao Yu6b4d6a82018-05-30 00:20:41 +0800552 ipage = f2fs_get_node_page(sbi, dir->i_ino);
Chao Yu201a05b2014-09-24 18:17:53 +0800553 if (IS_ERR(ipage))
554 return PTR_ERR(ipage);
555
Hyojun Kim63da4202017-10-06 17:10:08 -0700556 inline_dentry = inline_data_addr(dir, ipage);
557 make_dentry_ptr_inline(dir, &d, inline_dentry);
558
Chao Yu6b4d6a82018-05-30 00:20:41 +0800559 bit_pos = f2fs_room_for_filename(d.bitmap, slots, d.max);
Hyojun Kim63da4202017-10-06 17:10:08 -0700560 if (bit_pos >= d.max) {
561 err = f2fs_convert_inline_dir(dir, ipage, inline_dentry);
Chao Yu470f00e2015-07-14 18:14:06 +0800562 if (err)
563 return err;
564 err = -EAGAIN;
Chao Yu201a05b2014-09-24 18:17:53 +0800565 goto out;
566 }
567
Jaegeuk Kim510022a2015-03-30 15:07:16 -0700568 if (inode) {
569 down_write(&F2FS_I(inode)->i_sem);
Chao Yu6b4d6a82018-05-30 00:20:41 +0800570 page = f2fs_init_inode_metadata(inode, dir, new_name,
Chao Yu9421d572016-08-28 18:57:55 +0800571 orig_name, ipage);
Jaegeuk Kim510022a2015-03-30 15:07:16 -0700572 if (IS_ERR(page)) {
573 err = PTR_ERR(page);
574 goto fail;
575 }
Chao Yu201a05b2014-09-24 18:17:53 +0800576 }
Jaegeuk Kimbce8d112014-10-13 19:42:53 -0700577
Jaegeuk Kimfec1d652016-01-20 23:43:51 +0800578 f2fs_wait_on_page_writeback(ipage, NODE, true);
Chao Yu3b4d7322015-02-16 16:17:20 +0800579
Jaegeuk Kim8daed212017-04-24 10:00:08 -0700580 name_hash = f2fs_dentry_hash(new_name, NULL);
Chao Yu9421d572016-08-28 18:57:55 +0800581 f2fs_update_dentry(ino, mode, &d, new_name, name_hash, bit_pos);
Chao Yu3b4d7322015-02-16 16:17:20 +0800582
Chao Yu201a05b2014-09-24 18:17:53 +0800583 set_page_dirty(ipage);
584
585 /* we don't need to mark_inode_dirty now */
Jaegeuk Kim510022a2015-03-30 15:07:16 -0700586 if (inode) {
Jaegeuk Kim205b9822016-05-20 09:52:20 -0700587 f2fs_i_pino_write(inode, dir->i_ino);
Jaegeuk Kim510022a2015-03-30 15:07:16 -0700588 f2fs_put_page(page, 1);
589 }
Chao Yu201a05b2014-09-24 18:17:53 +0800590
Chao Yu6b4d6a82018-05-30 00:20:41 +0800591 f2fs_update_parent_metadata(dir, inode, 0);
Chao Yu201a05b2014-09-24 18:17:53 +0800592fail:
Jaegeuk Kim510022a2015-03-30 15:07:16 -0700593 if (inode)
594 up_write(&F2FS_I(inode)->i_sem);
Chao Yu201a05b2014-09-24 18:17:53 +0800595out:
596 f2fs_put_page(ipage, 1);
597 return err;
598}
599
600void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry, struct page *page,
601 struct inode *dir, struct inode *inode)
602{
Hyojun Kim63da4202017-10-06 17:10:08 -0700603 struct f2fs_dentry_ptr d;
604 void *inline_dentry;
Chao Yu201a05b2014-09-24 18:17:53 +0800605 int slots = GET_DENTRY_SLOTS(le16_to_cpu(dentry->name_len));
606 unsigned int bit_pos;
607 int i;
608
609 lock_page(page);
Jaegeuk Kimfec1d652016-01-20 23:43:51 +0800610 f2fs_wait_on_page_writeback(page, NODE, true);
Chao Yu201a05b2014-09-24 18:17:53 +0800611
Hyojun Kim63da4202017-10-06 17:10:08 -0700612 inline_dentry = inline_data_addr(dir, page);
613 make_dentry_ptr_inline(dir, &d, inline_dentry);
614
615 bit_pos = dentry - d.dentry;
Chao Yu201a05b2014-09-24 18:17:53 +0800616 for (i = 0; i < slots; i++)
Hyojun Kim63da4202017-10-06 17:10:08 -0700617 __clear_bit_le(bit_pos + i, d.bitmap);
Chao Yu201a05b2014-09-24 18:17:53 +0800618
619 set_page_dirty(page);
Jaegeuk Kim9f7c45c2016-06-01 21:18:25 -0700620 f2fs_put_page(page, 1);
Chao Yu201a05b2014-09-24 18:17:53 +0800621
Deepa Dinamani078cd822016-09-14 07:48:04 -0700622 dir->i_ctime = dir->i_mtime = current_time(dir);
Hyojun Kim63da4202017-10-06 17:10:08 -0700623 f2fs_mark_inode_dirty_sync(dir, false);
Chao Yu201a05b2014-09-24 18:17:53 +0800624
625 if (inode)
Jaegeuk Kim9f7c45c2016-06-01 21:18:25 -0700626 f2fs_drop_nlink(dir, inode);
Chao Yu201a05b2014-09-24 18:17:53 +0800627}
628
629bool f2fs_empty_inline_dir(struct inode *dir)
630{
631 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
632 struct page *ipage;
633 unsigned int bit_pos = 2;
Hyojun Kim63da4202017-10-06 17:10:08 -0700634 void *inline_dentry;
635 struct f2fs_dentry_ptr d;
Chao Yu201a05b2014-09-24 18:17:53 +0800636
Chao Yu6b4d6a82018-05-30 00:20:41 +0800637 ipage = f2fs_get_node_page(sbi, dir->i_ino);
Chao Yu201a05b2014-09-24 18:17:53 +0800638 if (IS_ERR(ipage))
639 return false;
640
Hyojun Kim63da4202017-10-06 17:10:08 -0700641 inline_dentry = inline_data_addr(dir, ipage);
642 make_dentry_ptr_inline(dir, &d, inline_dentry);
643
644 bit_pos = find_next_bit_le(d.bitmap, d.max, bit_pos);
Chao Yu201a05b2014-09-24 18:17:53 +0800645
646 f2fs_put_page(ipage, 1);
647
Hyojun Kim63da4202017-10-06 17:10:08 -0700648 if (bit_pos < d.max)
Chao Yu201a05b2014-09-24 18:17:53 +0800649 return false;
650
651 return true;
652}
653
Jaegeuk Kimd8c68222015-04-27 16:26:24 -0700654int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx,
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700655 struct fscrypt_str *fstr)
Chao Yu201a05b2014-09-24 18:17:53 +0800656{
657 struct inode *inode = file_inode(file);
Chao Yu201a05b2014-09-24 18:17:53 +0800658 struct page *ipage = NULL;
Jaegeuk Kim7b3cd7d2014-10-18 22:52:52 -0700659 struct f2fs_dentry_ptr d;
Hyojun Kim63da4202017-10-06 17:10:08 -0700660 void *inline_dentry = NULL;
661 int err;
Chao Yu201a05b2014-09-24 18:17:53 +0800662
Hyojun Kim63da4202017-10-06 17:10:08 -0700663 make_dentry_ptr_inline(inode, &d, inline_dentry);
664
665 if (ctx->pos == d.max)
Chao Yu201a05b2014-09-24 18:17:53 +0800666 return 0;
667
Chao Yu6b4d6a82018-05-30 00:20:41 +0800668 ipage = f2fs_get_node_page(F2FS_I_SB(inode), inode->i_ino);
Chao Yu201a05b2014-09-24 18:17:53 +0800669 if (IS_ERR(ipage))
670 return PTR_ERR(ipage);
671
Hyojun Kim63da4202017-10-06 17:10:08 -0700672 inline_dentry = inline_data_addr(inode, ipage);
Chao Yu201a05b2014-09-24 18:17:53 +0800673
Hyojun Kim63da4202017-10-06 17:10:08 -0700674 make_dentry_ptr_inline(inode, &d, inline_dentry);
Jaegeuk Kim7b3cd7d2014-10-18 22:52:52 -0700675
Hyojun Kim63da4202017-10-06 17:10:08 -0700676 err = f2fs_fill_dentries(ctx, &d, 0, fstr);
677 if (!err)
678 ctx->pos = d.max;
Chao Yu201a05b2014-09-24 18:17:53 +0800679
Chao Yu201a05b2014-09-24 18:17:53 +0800680 f2fs_put_page(ipage, 1);
Hyojun Kim63da4202017-10-06 17:10:08 -0700681 return err < 0 ? err : 0;
Chao Yu201a05b2014-09-24 18:17:53 +0800682}
Jaegeuk Kim67f8cf3c2015-10-15 11:34:49 -0700683
684int f2fs_inline_data_fiemap(struct inode *inode,
685 struct fiemap_extent_info *fieinfo, __u64 start, __u64 len)
686{
687 __u64 byteaddr, ilen;
688 __u32 flags = FIEMAP_EXTENT_DATA_INLINE | FIEMAP_EXTENT_NOT_ALIGNED |
689 FIEMAP_EXTENT_LAST;
690 struct node_info ni;
691 struct page *ipage;
692 int err = 0;
693
Chao Yu6b4d6a82018-05-30 00:20:41 +0800694 ipage = f2fs_get_node_page(F2FS_I_SB(inode), inode->i_ino);
Jaegeuk Kim67f8cf3c2015-10-15 11:34:49 -0700695 if (IS_ERR(ipage))
696 return PTR_ERR(ipage);
697
698 if (!f2fs_has_inline_data(inode)) {
699 err = -EAGAIN;
700 goto out;
701 }
702
Hyojun Kim63da4202017-10-06 17:10:08 -0700703 ilen = min_t(size_t, MAX_INLINE_DATA(inode), i_size_read(inode));
Jaegeuk Kim67f8cf3c2015-10-15 11:34:49 -0700704 if (start >= ilen)
705 goto out;
706 if (start + len < ilen)
707 ilen = start + len;
708 ilen -= start;
709
Chao Yu6b4d6a82018-05-30 00:20:41 +0800710 f2fs_get_node_info(F2FS_I_SB(inode), inode->i_ino, &ni);
Jaegeuk Kim67f8cf3c2015-10-15 11:34:49 -0700711 byteaddr = (__u64)ni.blk_addr << inode->i_sb->s_blocksize_bits;
Hyojun Kim63da4202017-10-06 17:10:08 -0700712 byteaddr += (char *)inline_data_addr(inode, ipage) -
713 (char *)F2FS_INODE(ipage);
Jaegeuk Kim67f8cf3c2015-10-15 11:34:49 -0700714 err = fiemap_fill_next_extent(fieinfo, start, byteaddr, ilen, flags);
715out:
716 f2fs_put_page(ipage, 1);
717 return err;
718}