Huajun Li | e18c65b | 2013-11-10 23:13:19 +0800 | [diff] [blame] | 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" |
Jaegeuk Kim | 67f8cf3 | 2015-10-15 11:34:49 -0700 | [diff] [blame] | 15 | #include "node.h" |
Huajun Li | e18c65b | 2013-11-10 23:13:19 +0800 | [diff] [blame] | 16 | |
Jaegeuk Kim | 01b960e | 2015-04-23 10:27:21 -0700 | [diff] [blame] | 17 | bool f2fs_may_inline_data(struct inode *inode) |
Huajun Li | e18c65b | 2013-11-10 23:13:19 +0800 | [diff] [blame] | 18 | { |
Jaegeuk Kim | 4081363 | 2014-09-02 15:31:18 -0700 | [diff] [blame] | 19 | if (!test_opt(F2FS_I_SB(inode), INLINE_DATA)) |
Huajun Li | e18c65b | 2013-11-10 23:13:19 +0800 | [diff] [blame] | 20 | return false; |
| 21 | |
Jaegeuk Kim | 88b88a6 | 2014-10-06 17:39:50 -0700 | [diff] [blame] | 22 | if (f2fs_is_atomic_file(inode)) |
| 23 | return false; |
| 24 | |
Wanpeng Li | 368a0e4 | 2015-03-19 13:23:48 +0800 | [diff] [blame] | 25 | if (!S_ISREG(inode->i_mode) && !S_ISLNK(inode->i_mode)) |
Huajun Li | e18c65b | 2013-11-10 23:13:19 +0800 | [diff] [blame] | 26 | return false; |
| 27 | |
Jaegeuk Kim | 92dffd0 | 2014-11-11 14:10:01 -0800 | [diff] [blame] | 28 | if (i_size_read(inode) > MAX_INLINE_DATA) |
| 29 | return false; |
| 30 | |
Jaegeuk Kim | fcc85a4 | 2015-04-21 20:39:58 -0700 | [diff] [blame] | 31 | if (f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode)) |
| 32 | return false; |
| 33 | |
Huajun Li | e18c65b | 2013-11-10 23:13:19 +0800 | [diff] [blame] | 34 | return true; |
| 35 | } |
| 36 | |
Jaegeuk Kim | 01b960e | 2015-04-23 10:27:21 -0700 | [diff] [blame] | 37 | bool f2fs_may_inline_dentry(struct inode *inode) |
| 38 | { |
| 39 | if (!test_opt(F2FS_I_SB(inode), INLINE_DENTRY)) |
| 40 | return false; |
| 41 | |
| 42 | if (!S_ISDIR(inode->i_mode)) |
| 43 | return false; |
| 44 | |
| 45 | return true; |
| 46 | } |
| 47 | |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 48 | void read_inline_data(struct page *page, struct page *ipage) |
Huajun Li | e18c65b | 2013-11-10 23:13:19 +0800 | [diff] [blame] | 49 | { |
Huajun Li | e18c65b | 2013-11-10 23:13:19 +0800 | [diff] [blame] | 50 | void *src_addr, *dst_addr; |
| 51 | |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 52 | if (PageUptodate(page)) |
| 53 | return; |
Chao Yu | 04a17fb | 2013-12-30 18:36:23 +0800 | [diff] [blame] | 54 | |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 55 | f2fs_bug_on(F2FS_P_SB(page), page->index); |
Huajun Li | e18c65b | 2013-11-10 23:13:19 +0800 | [diff] [blame] | 56 | |
Chao Yu | 18309aa | 2013-12-30 09:29:06 +0800 | [diff] [blame] | 57 | zero_user_segment(page, MAX_INLINE_DATA, PAGE_CACHE_SIZE); |
Huajun Li | e18c65b | 2013-11-10 23:13:19 +0800 | [diff] [blame] | 58 | |
| 59 | /* Copy the whole inline data block */ |
| 60 | src_addr = inline_data_addr(ipage); |
Jaegeuk Kim | f1e33a0 | 2014-10-18 23:41:38 -0700 | [diff] [blame] | 61 | dst_addr = kmap_atomic(page); |
Huajun Li | e18c65b | 2013-11-10 23:13:19 +0800 | [diff] [blame] | 62 | memcpy(dst_addr, src_addr, MAX_INLINE_DATA); |
Jaegeuk Kim | 427a45c | 2014-10-26 22:59:27 -0700 | [diff] [blame] | 63 | flush_dcache_page(page); |
Jaegeuk Kim | f1e33a0 | 2014-10-18 23:41:38 -0700 | [diff] [blame] | 64 | kunmap_atomic(dst_addr); |
Huajun Li | e18c65b | 2013-11-10 23:13:19 +0800 | [diff] [blame] | 65 | SetPageUptodate(page); |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 66 | } |
Huajun Li | e18c65b | 2013-11-10 23:13:19 +0800 | [diff] [blame] | 67 | |
Chao Yu | 0bfcfcc | 2015-03-10 13:16:25 +0800 | [diff] [blame] | 68 | bool truncate_inline_inode(struct page *ipage, u64 from) |
Chao Yu | feeb0de | 2015-01-26 20:22:55 +0800 | [diff] [blame] | 69 | { |
Chao Yu | 0bfcfcc | 2015-03-10 13:16:25 +0800 | [diff] [blame] | 70 | void *addr; |
| 71 | |
Chao Yu | 0bfcfcc | 2015-03-10 13:16:25 +0800 | [diff] [blame] | 72 | if (from >= MAX_INLINE_DATA) |
| 73 | return false; |
| 74 | |
| 75 | addr = inline_data_addr(ipage); |
| 76 | |
Chao Yu | feeb0de | 2015-01-26 20:22:55 +0800 | [diff] [blame] | 77 | f2fs_wait_on_page_writeback(ipage, NODE); |
Chao Yu | 0bfcfcc | 2015-03-10 13:16:25 +0800 | [diff] [blame] | 78 | memset(addr + from, 0, MAX_INLINE_DATA - from); |
| 79 | |
| 80 | return true; |
Chao Yu | feeb0de | 2015-01-26 20:22:55 +0800 | [diff] [blame] | 81 | } |
| 82 | |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 83 | int f2fs_read_inline_data(struct inode *inode, struct page *page) |
| 84 | { |
| 85 | struct page *ipage; |
| 86 | |
| 87 | ipage = get_node_page(F2FS_I_SB(inode), inode->i_ino); |
| 88 | if (IS_ERR(ipage)) { |
| 89 | unlock_page(page); |
| 90 | return PTR_ERR(ipage); |
| 91 | } |
| 92 | |
| 93 | if (!f2fs_has_inline_data(inode)) { |
| 94 | f2fs_put_page(ipage, 1); |
| 95 | return -EAGAIN; |
| 96 | } |
| 97 | |
| 98 | if (page->index) |
| 99 | zero_user_segment(page, 0, PAGE_CACHE_SIZE); |
| 100 | else |
| 101 | read_inline_data(page, ipage); |
| 102 | |
| 103 | SetPageUptodate(page); |
| 104 | f2fs_put_page(ipage, 1); |
| 105 | unlock_page(page); |
Huajun Li | e18c65b | 2013-11-10 23:13:19 +0800 | [diff] [blame] | 106 | return 0; |
| 107 | } |
| 108 | |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 109 | int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page) |
Huajun Li | e18c65b | 2013-11-10 23:13:19 +0800 | [diff] [blame] | 110 | { |
Huajun Li | e18c65b | 2013-11-10 23:13:19 +0800 | [diff] [blame] | 111 | void *src_addr, *dst_addr; |
Huajun Li | e18c65b | 2013-11-10 23:13:19 +0800 | [diff] [blame] | 112 | struct f2fs_io_info fio = { |
Jaegeuk Kim | 05ca363 | 2015-04-23 14:38:15 -0700 | [diff] [blame] | 113 | .sbi = F2FS_I_SB(dn->inode), |
Huajun Li | e18c65b | 2013-11-10 23:13:19 +0800 | [diff] [blame] | 114 | .type = DATA, |
| 115 | .rw = WRITE_SYNC | REQ_PRIO, |
Jaegeuk Kim | 05ca363 | 2015-04-23 14:38:15 -0700 | [diff] [blame] | 116 | .page = page, |
Jaegeuk Kim | 4375a33 | 2015-04-23 12:04:33 -0700 | [diff] [blame] | 117 | .encrypted_page = NULL, |
Huajun Li | e18c65b | 2013-11-10 23:13:19 +0800 | [diff] [blame] | 118 | }; |
Jaegeuk Kim | 158c194 | 2014-11-25 11:34:02 -0800 | [diff] [blame] | 119 | int dirty, err; |
Huajun Li | e18c65b | 2013-11-10 23:13:19 +0800 | [diff] [blame] | 120 | |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 121 | f2fs_bug_on(F2FS_I_SB(dn->inode), page->index); |
Huajun Li | e18c65b | 2013-11-10 23:13:19 +0800 | [diff] [blame] | 122 | |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 123 | if (!f2fs_exist_data(dn->inode)) |
| 124 | goto clear_out; |
Jaegeuk Kim | ec4e7af | 2014-08-18 14:41:11 -0700 | [diff] [blame] | 125 | |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 126 | err = f2fs_reserve_block(dn, 0); |
Jaegeuk Kim | 15c6e3a | 2014-04-16 14:22:50 +0900 | [diff] [blame] | 127 | if (err) |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 128 | return err; |
Huajun Li | e18c65b | 2013-11-10 23:13:19 +0800 | [diff] [blame] | 129 | |
Jaegeuk Kim | 9ac1349 | 2014-04-29 17:35:10 +0900 | [diff] [blame] | 130 | f2fs_wait_on_page_writeback(page, DATA); |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 131 | |
| 132 | if (PageUptodate(page)) |
| 133 | goto no_update; |
| 134 | |
Chao Yu | 18309aa | 2013-12-30 09:29:06 +0800 | [diff] [blame] | 135 | zero_user_segment(page, MAX_INLINE_DATA, PAGE_CACHE_SIZE); |
Huajun Li | e18c65b | 2013-11-10 23:13:19 +0800 | [diff] [blame] | 136 | |
| 137 | /* Copy the whole inline data block */ |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 138 | src_addr = inline_data_addr(dn->inode_page); |
Jaegeuk Kim | f1e33a0 | 2014-10-18 23:41:38 -0700 | [diff] [blame] | 139 | dst_addr = kmap_atomic(page); |
Huajun Li | e18c65b | 2013-11-10 23:13:19 +0800 | [diff] [blame] | 140 | memcpy(dst_addr, src_addr, MAX_INLINE_DATA); |
Jaegeuk Kim | 09b8b3c | 2014-11-18 10:50:21 -0800 | [diff] [blame] | 141 | flush_dcache_page(page); |
Jaegeuk Kim | f1e33a0 | 2014-10-18 23:41:38 -0700 | [diff] [blame] | 142 | kunmap_atomic(dst_addr); |
Jaegeuk Kim | 9e09fc8 | 2013-12-27 12:28:59 +0900 | [diff] [blame] | 143 | SetPageUptodate(page); |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 144 | no_update: |
Jaegeuk Kim | 6282adb | 2015-07-25 00:29:17 -0700 | [diff] [blame] | 145 | set_page_dirty(page); |
| 146 | |
Jaegeuk Kim | 158c194 | 2014-11-25 11:34:02 -0800 | [diff] [blame] | 147 | /* clear dirty state */ |
| 148 | dirty = clear_page_dirty_for_io(page); |
| 149 | |
Huajun Li | e18c65b | 2013-11-10 23:13:19 +0800 | [diff] [blame] | 150 | /* write data page to try to make data consistent */ |
| 151 | set_page_writeback(page); |
Jaegeuk Kim | cf04e8e | 2014-12-17 19:33:13 -0800 | [diff] [blame] | 152 | fio.blk_addr = dn->data_blkaddr; |
Jaegeuk Kim | 05ca363 | 2015-04-23 14:38:15 -0700 | [diff] [blame] | 153 | write_data_page(dn, &fio); |
Chao Yu | 216a620 | 2015-03-19 19:23:32 +0800 | [diff] [blame] | 154 | set_data_blkaddr(dn); |
Chao Yu | 7e4dde7 | 2015-02-05 17:51:34 +0800 | [diff] [blame] | 155 | f2fs_update_extent_cache(dn); |
Yuan Zhong | 5514f0a | 2014-01-10 07:26:14 +0000 | [diff] [blame] | 156 | f2fs_wait_on_page_writeback(page, DATA); |
Jaegeuk Kim | 158c194 | 2014-11-25 11:34:02 -0800 | [diff] [blame] | 157 | if (dirty) |
| 158 | inode_dec_dirty_pages(dn->inode); |
Huajun Li | e18c65b | 2013-11-10 23:13:19 +0800 | [diff] [blame] | 159 | |
Jaegeuk Kim | 95f5b0f | 2014-11-25 17:27:38 -0800 | [diff] [blame] | 160 | /* this converted inline_data should be recovered. */ |
| 161 | set_inode_flag(F2FS_I(dn->inode), FI_APPEND_WRITE); |
| 162 | |
Huajun Li | e18c65b | 2013-11-10 23:13:19 +0800 | [diff] [blame] | 163 | /* clear inline data and flag after data writeback */ |
Chao Yu | 0bfcfcc | 2015-03-10 13:16:25 +0800 | [diff] [blame] | 164 | truncate_inline_inode(dn->inode_page, 0); |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 165 | clear_out: |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 166 | stat_dec_inline_inode(dn->inode); |
Jaegeuk Kim | 57e2a2c | 2014-11-10 16:29:14 -0800 | [diff] [blame] | 167 | f2fs_clear_inline_inode(dn->inode); |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 168 | sync_inode_page(dn); |
| 169 | f2fs_put_dnode(dn); |
| 170 | return 0; |
Huajun Li | e18c65b | 2013-11-10 23:13:19 +0800 | [diff] [blame] | 171 | } |
| 172 | |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 173 | int f2fs_convert_inline_inode(struct inode *inode) |
Huajun Li | e18c65b | 2013-11-10 23:13:19 +0800 | [diff] [blame] | 174 | { |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 175 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); |
| 176 | struct dnode_of_data dn; |
| 177 | struct page *ipage, *page; |
| 178 | int err = 0; |
Huajun Li | e18c65b | 2013-11-10 23:13:19 +0800 | [diff] [blame] | 179 | |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 180 | page = grab_cache_page(inode->i_mapping, 0); |
| 181 | if (!page) |
| 182 | return -ENOMEM; |
Jaegeuk Kim | 9e09fc8 | 2013-12-27 12:28:59 +0900 | [diff] [blame] | 183 | |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 184 | f2fs_lock_op(sbi); |
| 185 | |
| 186 | ipage = get_node_page(sbi, inode->i_ino); |
| 187 | if (IS_ERR(ipage)) { |
Jaegeuk Kim | 6d20aff | 2014-11-17 16:06:55 -0800 | [diff] [blame] | 188 | err = PTR_ERR(ipage); |
| 189 | goto out; |
Jaegeuk Kim | b067ba1 | 2014-08-07 16:32:25 -0700 | [diff] [blame] | 190 | } |
Huajun Li | e18c65b | 2013-11-10 23:13:19 +0800 | [diff] [blame] | 191 | |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 192 | set_new_dnode(&dn, inode, ipage, ipage, 0); |
| 193 | |
| 194 | if (f2fs_has_inline_data(inode)) |
| 195 | err = f2fs_convert_inline_page(&dn, page); |
| 196 | |
| 197 | f2fs_put_dnode(&dn); |
Jaegeuk Kim | 6d20aff | 2014-11-17 16:06:55 -0800 | [diff] [blame] | 198 | out: |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 199 | f2fs_unlock_op(sbi); |
| 200 | |
| 201 | f2fs_put_page(page, 1); |
Huajun Li | e18c65b | 2013-11-10 23:13:19 +0800 | [diff] [blame] | 202 | return err; |
| 203 | } |
| 204 | |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 205 | int f2fs_write_inline_data(struct inode *inode, struct page *page) |
Huajun Li | e18c65b | 2013-11-10 23:13:19 +0800 | [diff] [blame] | 206 | { |
| 207 | void *src_addr, *dst_addr; |
Huajun Li | e18c65b | 2013-11-10 23:13:19 +0800 | [diff] [blame] | 208 | struct dnode_of_data dn; |
| 209 | int err; |
| 210 | |
| 211 | set_new_dnode(&dn, inode, NULL, NULL, 0); |
| 212 | err = get_dnode_of_data(&dn, 0, LOOKUP_NODE); |
| 213 | if (err) |
| 214 | return err; |
Huajun Li | e18c65b | 2013-11-10 23:13:19 +0800 | [diff] [blame] | 215 | |
Jaegeuk Kim | c08a690 | 2014-10-15 10:16:54 -0700 | [diff] [blame] | 216 | if (!f2fs_has_inline_data(inode)) { |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 217 | f2fs_put_dnode(&dn); |
| 218 | return -EAGAIN; |
Jaegeuk Kim | c08a690 | 2014-10-15 10:16:54 -0700 | [diff] [blame] | 219 | } |
| 220 | |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 221 | f2fs_bug_on(F2FS_I_SB(inode), page->index); |
| 222 | |
| 223 | f2fs_wait_on_page_writeback(dn.inode_page, NODE); |
Jaegeuk Kim | f1e33a0 | 2014-10-18 23:41:38 -0700 | [diff] [blame] | 224 | src_addr = kmap_atomic(page); |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 225 | dst_addr = inline_data_addr(dn.inode_page); |
| 226 | memcpy(dst_addr, src_addr, MAX_INLINE_DATA); |
Jaegeuk Kim | f1e33a0 | 2014-10-18 23:41:38 -0700 | [diff] [blame] | 227 | kunmap_atomic(src_addr); |
Huajun Li | e18c65b | 2013-11-10 23:13:19 +0800 | [diff] [blame] | 228 | |
Jaegeuk Kim | fff04f9 | 2014-07-25 07:40:59 -0700 | [diff] [blame] | 229 | set_inode_flag(F2FS_I(inode), FI_APPEND_WRITE); |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 230 | set_inode_flag(F2FS_I(inode), FI_DATA_EXIST); |
| 231 | |
Huajun Li | e18c65b | 2013-11-10 23:13:19 +0800 | [diff] [blame] | 232 | sync_inode_page(&dn); |
| 233 | f2fs_put_dnode(&dn); |
Huajun Li | e18c65b | 2013-11-10 23:13:19 +0800 | [diff] [blame] | 234 | return 0; |
| 235 | } |
Jaegeuk Kim | 1e1bb4b | 2013-12-26 12:49:48 +0900 | [diff] [blame] | 236 | |
Jaegeuk Kim | 0342fd3 | 2014-08-07 16:57:17 -0700 | [diff] [blame] | 237 | bool recover_inline_data(struct inode *inode, struct page *npage) |
Jaegeuk Kim | 1e1bb4b | 2013-12-26 12:49:48 +0900 | [diff] [blame] | 238 | { |
Jaegeuk Kim | 4081363 | 2014-09-02 15:31:18 -0700 | [diff] [blame] | 239 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); |
Jaegeuk Kim | 1e1bb4b | 2013-12-26 12:49:48 +0900 | [diff] [blame] | 240 | struct f2fs_inode *ri = NULL; |
| 241 | void *src_addr, *dst_addr; |
| 242 | struct page *ipage; |
| 243 | |
| 244 | /* |
| 245 | * The inline_data recovery policy is as follows. |
| 246 | * [prev.] [next] of inline_data flag |
| 247 | * o o -> recover inline_data |
| 248 | * o x -> remove inline_data, and then recover data blocks |
| 249 | * x o -> remove inline_data, and then recover inline_data |
| 250 | * x x -> recover data blocks |
| 251 | */ |
| 252 | if (IS_INODE(npage)) |
| 253 | ri = F2FS_INODE(npage); |
| 254 | |
| 255 | if (f2fs_has_inline_data(inode) && |
Jaegeuk Kim | 0342fd3 | 2014-08-07 16:57:17 -0700 | [diff] [blame] | 256 | ri && (ri->i_inline & F2FS_INLINE_DATA)) { |
Jaegeuk Kim | 1e1bb4b | 2013-12-26 12:49:48 +0900 | [diff] [blame] | 257 | process_inline: |
| 258 | ipage = get_node_page(sbi, inode->i_ino); |
Jaegeuk Kim | 9850cf4 | 2014-09-02 15:52:58 -0700 | [diff] [blame] | 259 | f2fs_bug_on(sbi, IS_ERR(ipage)); |
Jaegeuk Kim | 1e1bb4b | 2013-12-26 12:49:48 +0900 | [diff] [blame] | 260 | |
Jaegeuk Kim | 54b591d | 2014-04-29 17:28:32 +0900 | [diff] [blame] | 261 | f2fs_wait_on_page_writeback(ipage, NODE); |
| 262 | |
Jaegeuk Kim | 1e1bb4b | 2013-12-26 12:49:48 +0900 | [diff] [blame] | 263 | src_addr = inline_data_addr(npage); |
| 264 | dst_addr = inline_data_addr(ipage); |
| 265 | memcpy(dst_addr, src_addr, MAX_INLINE_DATA); |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 266 | |
| 267 | set_inode_flag(F2FS_I(inode), FI_INLINE_DATA); |
| 268 | set_inode_flag(F2FS_I(inode), FI_DATA_EXIST); |
| 269 | |
Jaegeuk Kim | 1e1bb4b | 2013-12-26 12:49:48 +0900 | [diff] [blame] | 270 | update_inode(inode, ipage); |
| 271 | f2fs_put_page(ipage, 1); |
Jaegeuk Kim | 0342fd3 | 2014-08-07 16:57:17 -0700 | [diff] [blame] | 272 | return true; |
Jaegeuk Kim | 1e1bb4b | 2013-12-26 12:49:48 +0900 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | if (f2fs_has_inline_data(inode)) { |
| 276 | ipage = get_node_page(sbi, inode->i_ino); |
Jaegeuk Kim | 9850cf4 | 2014-09-02 15:52:58 -0700 | [diff] [blame] | 277 | f2fs_bug_on(sbi, IS_ERR(ipage)); |
Nicholas Krause | 545fe42 | 2015-09-21 18:55:49 -0400 | [diff] [blame] | 278 | if (!truncate_inline_inode(ipage, 0)) |
| 279 | return false; |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 280 | f2fs_clear_inline_inode(inode); |
Jaegeuk Kim | 1e1bb4b | 2013-12-26 12:49:48 +0900 | [diff] [blame] | 281 | update_inode(inode, ipage); |
| 282 | f2fs_put_page(ipage, 1); |
Jaegeuk Kim | 0342fd3 | 2014-08-07 16:57:17 -0700 | [diff] [blame] | 283 | } else if (ri && (ri->i_inline & F2FS_INLINE_DATA)) { |
Nicholas Krause | 545fe42 | 2015-09-21 18:55:49 -0400 | [diff] [blame] | 284 | if (truncate_blocks(inode, 0, false)) |
| 285 | return false; |
Jaegeuk Kim | 1e1bb4b | 2013-12-26 12:49:48 +0900 | [diff] [blame] | 286 | goto process_inline; |
| 287 | } |
Jaegeuk Kim | 0342fd3 | 2014-08-07 16:57:17 -0700 | [diff] [blame] | 288 | return false; |
Jaegeuk Kim | 1e1bb4b | 2013-12-26 12:49:48 +0900 | [diff] [blame] | 289 | } |
Chao Yu | 201a05b | 2014-09-24 18:17:53 +0800 | [diff] [blame] | 290 | |
| 291 | struct f2fs_dir_entry *find_in_inline_dir(struct inode *dir, |
Jaegeuk Kim | 6e22c69 | 2015-04-27 17:12:39 -0700 | [diff] [blame] | 292 | struct f2fs_filename *fname, struct page **res_page) |
Chao Yu | 201a05b | 2014-09-24 18:17:53 +0800 | [diff] [blame] | 293 | { |
| 294 | struct f2fs_sb_info *sbi = F2FS_SB(dir->i_sb); |
Jaegeuk Kim | 4e6ebf6 | 2014-10-13 17:26:14 -0700 | [diff] [blame] | 295 | struct f2fs_inline_dentry *inline_dentry; |
Jaegeuk Kim | 6e22c69 | 2015-04-27 17:12:39 -0700 | [diff] [blame] | 296 | struct qstr name = FSTR_TO_QSTR(&fname->disk_name); |
Chao Yu | 201a05b | 2014-09-24 18:17:53 +0800 | [diff] [blame] | 297 | struct f2fs_dir_entry *de; |
Jaegeuk Kim | 7b3cd7d | 2014-10-18 22:52:52 -0700 | [diff] [blame] | 298 | struct f2fs_dentry_ptr d; |
Jaegeuk Kim | 4e6ebf6 | 2014-10-13 17:26:14 -0700 | [diff] [blame] | 299 | struct page *ipage; |
Jaegeuk Kim | 6e22c69 | 2015-04-27 17:12:39 -0700 | [diff] [blame] | 300 | f2fs_hash_t namehash; |
Chao Yu | 201a05b | 2014-09-24 18:17:53 +0800 | [diff] [blame] | 301 | |
| 302 | ipage = get_node_page(sbi, dir->i_ino); |
| 303 | if (IS_ERR(ipage)) |
| 304 | return NULL; |
| 305 | |
Jaegeuk Kim | 6e22c69 | 2015-04-27 17:12:39 -0700 | [diff] [blame] | 306 | namehash = f2fs_dentry_hash(&name); |
| 307 | |
Jaegeuk Kim | 4e6ebf6 | 2014-10-13 17:26:14 -0700 | [diff] [blame] | 308 | inline_dentry = inline_data_addr(ipage); |
Chao Yu | 201a05b | 2014-09-24 18:17:53 +0800 | [diff] [blame] | 309 | |
Jaegeuk Kim | d8c6822 | 2015-04-27 16:26:24 -0700 | [diff] [blame] | 310 | make_dentry_ptr(NULL, &d, (void *)inline_dentry, 2); |
Jaegeuk Kim | 6e22c69 | 2015-04-27 17:12:39 -0700 | [diff] [blame] | 311 | de = find_target_dentry(fname, namehash, NULL, &d); |
Chao Yu | 201a05b | 2014-09-24 18:17:53 +0800 | [diff] [blame] | 312 | unlock_page(ipage); |
Jaegeuk Kim | 4e6ebf6 | 2014-10-13 17:26:14 -0700 | [diff] [blame] | 313 | if (de) |
| 314 | *res_page = ipage; |
| 315 | else |
| 316 | f2fs_put_page(ipage, 0); |
| 317 | |
| 318 | /* |
| 319 | * For the most part, it should be a bug when name_len is zero. |
| 320 | * We stop here for figuring out where the bugs has occurred. |
| 321 | */ |
Jaegeuk Kim | 7b3cd7d | 2014-10-18 22:52:52 -0700 | [diff] [blame] | 322 | f2fs_bug_on(sbi, d.max < 0); |
Chao Yu | 201a05b | 2014-09-24 18:17:53 +0800 | [diff] [blame] | 323 | return de; |
| 324 | } |
| 325 | |
| 326 | struct f2fs_dir_entry *f2fs_parent_inline_dir(struct inode *dir, |
| 327 | struct page **p) |
| 328 | { |
| 329 | struct f2fs_sb_info *sbi = F2FS_I_SB(dir); |
| 330 | struct page *ipage; |
| 331 | struct f2fs_dir_entry *de; |
| 332 | struct f2fs_inline_dentry *dentry_blk; |
| 333 | |
| 334 | ipage = get_node_page(sbi, dir->i_ino); |
| 335 | if (IS_ERR(ipage)) |
| 336 | return NULL; |
| 337 | |
| 338 | dentry_blk = inline_data_addr(ipage); |
| 339 | de = &dentry_blk->dentry[1]; |
| 340 | *p = ipage; |
| 341 | unlock_page(ipage); |
| 342 | return de; |
| 343 | } |
| 344 | |
| 345 | int make_empty_inline_dir(struct inode *inode, struct inode *parent, |
| 346 | struct page *ipage) |
| 347 | { |
| 348 | struct f2fs_inline_dentry *dentry_blk; |
Jaegeuk Kim | 062a3e7 | 2014-10-18 23:06:41 -0700 | [diff] [blame] | 349 | struct f2fs_dentry_ptr d; |
Chao Yu | 201a05b | 2014-09-24 18:17:53 +0800 | [diff] [blame] | 350 | |
| 351 | dentry_blk = inline_data_addr(ipage); |
| 352 | |
Jaegeuk Kim | d8c6822 | 2015-04-27 16:26:24 -0700 | [diff] [blame] | 353 | make_dentry_ptr(NULL, &d, (void *)dentry_blk, 2); |
Jaegeuk Kim | 062a3e7 | 2014-10-18 23:06:41 -0700 | [diff] [blame] | 354 | do_make_empty_dir(inode, parent, &d); |
Chao Yu | 201a05b | 2014-09-24 18:17:53 +0800 | [diff] [blame] | 355 | |
| 356 | set_page_dirty(ipage); |
| 357 | |
| 358 | /* update i_size to MAX_INLINE_DATA */ |
| 359 | if (i_size_read(inode) < MAX_INLINE_DATA) { |
| 360 | i_size_write(inode, MAX_INLINE_DATA); |
| 361 | set_inode_flag(F2FS_I(inode), FI_UPDATE_DIR); |
| 362 | } |
| 363 | return 0; |
| 364 | } |
| 365 | |
Chao Yu | 470f00e | 2015-07-14 18:14:06 +0800 | [diff] [blame] | 366 | /* |
| 367 | * NOTE: ipage is grabbed by caller, but if any error occurs, we should |
| 368 | * release ipage in this function. |
| 369 | */ |
Jaegeuk Kim | d64948a | 2014-10-20 20:28:49 -0700 | [diff] [blame] | 370 | static int f2fs_convert_inline_dir(struct inode *dir, struct page *ipage, |
Chao Yu | 201a05b | 2014-09-24 18:17:53 +0800 | [diff] [blame] | 371 | struct f2fs_inline_dentry *inline_dentry) |
| 372 | { |
| 373 | struct page *page; |
| 374 | struct dnode_of_data dn; |
| 375 | struct f2fs_dentry_block *dentry_blk; |
| 376 | int err; |
| 377 | |
| 378 | page = grab_cache_page(dir->i_mapping, 0); |
Chao Yu | 470f00e | 2015-07-14 18:14:06 +0800 | [diff] [blame] | 379 | if (!page) { |
| 380 | f2fs_put_page(ipage, 1); |
Chao Yu | 201a05b | 2014-09-24 18:17:53 +0800 | [diff] [blame] | 381 | return -ENOMEM; |
Chao Yu | 470f00e | 2015-07-14 18:14:06 +0800 | [diff] [blame] | 382 | } |
Chao Yu | 201a05b | 2014-09-24 18:17:53 +0800 | [diff] [blame] | 383 | |
| 384 | set_new_dnode(&dn, dir, ipage, NULL, 0); |
| 385 | err = f2fs_reserve_block(&dn, 0); |
| 386 | if (err) |
| 387 | goto out; |
| 388 | |
| 389 | f2fs_wait_on_page_writeback(page, DATA); |
Chao Yu | 4ec17d6 | 2015-08-24 17:36:25 +0800 | [diff] [blame] | 390 | zero_user_segment(page, MAX_INLINE_DATA, PAGE_CACHE_SIZE); |
Chao Yu | 201a05b | 2014-09-24 18:17:53 +0800 | [diff] [blame] | 391 | |
Jaegeuk Kim | f1e33a0 | 2014-10-18 23:41:38 -0700 | [diff] [blame] | 392 | dentry_blk = kmap_atomic(page); |
Chao Yu | 201a05b | 2014-09-24 18:17:53 +0800 | [diff] [blame] | 393 | |
| 394 | /* copy data from inline dentry block to new dentry block */ |
| 395 | memcpy(dentry_blk->dentry_bitmap, inline_dentry->dentry_bitmap, |
| 396 | INLINE_DENTRY_BITMAP_SIZE); |
Chao Yu | 4ec17d6 | 2015-08-24 17:36:25 +0800 | [diff] [blame] | 397 | memset(dentry_blk->dentry_bitmap + INLINE_DENTRY_BITMAP_SIZE, 0, |
| 398 | SIZE_OF_DENTRY_BITMAP - INLINE_DENTRY_BITMAP_SIZE); |
| 399 | /* |
| 400 | * we do not need to zero out remainder part of dentry and filename |
| 401 | * field, since we have used bitmap for marking the usage status of |
| 402 | * them, besides, we can also ignore copying/zeroing reserved space |
| 403 | * of dentry block, because them haven't been used so far. |
| 404 | */ |
Chao Yu | 201a05b | 2014-09-24 18:17:53 +0800 | [diff] [blame] | 405 | memcpy(dentry_blk->dentry, inline_dentry->dentry, |
| 406 | sizeof(struct f2fs_dir_entry) * NR_INLINE_DENTRY); |
| 407 | memcpy(dentry_blk->filename, inline_dentry->filename, |
| 408 | NR_INLINE_DENTRY * F2FS_SLOT_LEN); |
| 409 | |
Jaegeuk Kim | f1e33a0 | 2014-10-18 23:41:38 -0700 | [diff] [blame] | 410 | kunmap_atomic(dentry_blk); |
Chao Yu | 201a05b | 2014-09-24 18:17:53 +0800 | [diff] [blame] | 411 | SetPageUptodate(page); |
| 412 | set_page_dirty(page); |
| 413 | |
| 414 | /* clear inline dir and flag after data writeback */ |
Chao Yu | 0bfcfcc | 2015-03-10 13:16:25 +0800 | [diff] [blame] | 415 | truncate_inline_inode(ipage, 0); |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 416 | |
Jaegeuk Kim | 3289c06 | 2014-10-13 20:00:16 -0700 | [diff] [blame] | 417 | stat_dec_inline_dir(dir); |
Chao Yu | 622f28a | 2014-09-24 18:19:10 +0800 | [diff] [blame] | 418 | clear_inode_flag(F2FS_I(dir), FI_INLINE_DENTRY); |
Chao Yu | 201a05b | 2014-09-24 18:17:53 +0800 | [diff] [blame] | 419 | |
| 420 | if (i_size_read(dir) < PAGE_CACHE_SIZE) { |
| 421 | i_size_write(dir, PAGE_CACHE_SIZE); |
| 422 | set_inode_flag(F2FS_I(dir), FI_UPDATE_DIR); |
| 423 | } |
| 424 | |
| 425 | sync_inode_page(&dn); |
| 426 | out: |
| 427 | f2fs_put_page(page, 1); |
| 428 | return err; |
| 429 | } |
| 430 | |
| 431 | int f2fs_add_inline_entry(struct inode *dir, const struct qstr *name, |
Jaegeuk Kim | 510022a | 2015-03-30 15:07:16 -0700 | [diff] [blame] | 432 | struct inode *inode, nid_t ino, umode_t mode) |
Chao Yu | 201a05b | 2014-09-24 18:17:53 +0800 | [diff] [blame] | 433 | { |
| 434 | struct f2fs_sb_info *sbi = F2FS_I_SB(dir); |
| 435 | struct page *ipage; |
| 436 | unsigned int bit_pos; |
| 437 | f2fs_hash_t name_hash; |
Chao Yu | 201a05b | 2014-09-24 18:17:53 +0800 | [diff] [blame] | 438 | size_t namelen = name->len; |
| 439 | struct f2fs_inline_dentry *dentry_blk = NULL; |
Chao Yu | 3b4d732 | 2015-02-16 16:17:20 +0800 | [diff] [blame] | 440 | struct f2fs_dentry_ptr d; |
Chao Yu | 201a05b | 2014-09-24 18:17:53 +0800 | [diff] [blame] | 441 | int slots = GET_DENTRY_SLOTS(namelen); |
Jaegeuk Kim | 510022a | 2015-03-30 15:07:16 -0700 | [diff] [blame] | 442 | struct page *page = NULL; |
Chao Yu | 201a05b | 2014-09-24 18:17:53 +0800 | [diff] [blame] | 443 | int err = 0; |
Chao Yu | 201a05b | 2014-09-24 18:17:53 +0800 | [diff] [blame] | 444 | |
| 445 | ipage = get_node_page(sbi, dir->i_ino); |
| 446 | if (IS_ERR(ipage)) |
| 447 | return PTR_ERR(ipage); |
| 448 | |
| 449 | dentry_blk = inline_data_addr(ipage); |
Jaegeuk Kim | a82afa2 | 2014-10-13 16:28:13 -0700 | [diff] [blame] | 450 | bit_pos = room_for_filename(&dentry_blk->dentry_bitmap, |
| 451 | slots, NR_INLINE_DENTRY); |
Chao Yu | 201a05b | 2014-09-24 18:17:53 +0800 | [diff] [blame] | 452 | if (bit_pos >= NR_INLINE_DENTRY) { |
| 453 | err = f2fs_convert_inline_dir(dir, ipage, dentry_blk); |
Chao Yu | 470f00e | 2015-07-14 18:14:06 +0800 | [diff] [blame] | 454 | if (err) |
| 455 | return err; |
| 456 | err = -EAGAIN; |
Chao Yu | 201a05b | 2014-09-24 18:17:53 +0800 | [diff] [blame] | 457 | goto out; |
| 458 | } |
| 459 | |
Jaegeuk Kim | 510022a | 2015-03-30 15:07:16 -0700 | [diff] [blame] | 460 | if (inode) { |
| 461 | down_write(&F2FS_I(inode)->i_sem); |
| 462 | page = init_inode_metadata(inode, dir, name, ipage); |
| 463 | if (IS_ERR(page)) { |
| 464 | err = PTR_ERR(page); |
| 465 | goto fail; |
| 466 | } |
Chao Yu | 201a05b | 2014-09-24 18:17:53 +0800 | [diff] [blame] | 467 | } |
Jaegeuk Kim | bce8d11 | 2014-10-13 19:42:53 -0700 | [diff] [blame] | 468 | |
| 469 | f2fs_wait_on_page_writeback(ipage, NODE); |
Chao Yu | 3b4d732 | 2015-02-16 16:17:20 +0800 | [diff] [blame] | 470 | |
| 471 | name_hash = f2fs_dentry_hash(name); |
Jaegeuk Kim | d8c6822 | 2015-04-27 16:26:24 -0700 | [diff] [blame] | 472 | make_dentry_ptr(NULL, &d, (void *)dentry_blk, 2); |
Jaegeuk Kim | 510022a | 2015-03-30 15:07:16 -0700 | [diff] [blame] | 473 | f2fs_update_dentry(ino, mode, &d, name, name_hash, bit_pos); |
Chao Yu | 3b4d732 | 2015-02-16 16:17:20 +0800 | [diff] [blame] | 474 | |
Chao Yu | 201a05b | 2014-09-24 18:17:53 +0800 | [diff] [blame] | 475 | set_page_dirty(ipage); |
| 476 | |
| 477 | /* we don't need to mark_inode_dirty now */ |
Jaegeuk Kim | 510022a | 2015-03-30 15:07:16 -0700 | [diff] [blame] | 478 | if (inode) { |
| 479 | F2FS_I(inode)->i_pino = dir->i_ino; |
| 480 | update_inode(inode, page); |
| 481 | f2fs_put_page(page, 1); |
| 482 | } |
Chao Yu | 201a05b | 2014-09-24 18:17:53 +0800 | [diff] [blame] | 483 | |
| 484 | update_parent_metadata(dir, inode, 0); |
| 485 | fail: |
Jaegeuk Kim | 510022a | 2015-03-30 15:07:16 -0700 | [diff] [blame] | 486 | if (inode) |
| 487 | up_write(&F2FS_I(inode)->i_sem); |
Chao Yu | 201a05b | 2014-09-24 18:17:53 +0800 | [diff] [blame] | 488 | |
| 489 | if (is_inode_flag_set(F2FS_I(dir), FI_UPDATE_DIR)) { |
| 490 | update_inode(dir, ipage); |
| 491 | clear_inode_flag(F2FS_I(dir), FI_UPDATE_DIR); |
| 492 | } |
| 493 | out: |
| 494 | f2fs_put_page(ipage, 1); |
| 495 | return err; |
| 496 | } |
| 497 | |
| 498 | void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry, struct page *page, |
| 499 | struct inode *dir, struct inode *inode) |
| 500 | { |
| 501 | struct f2fs_inline_dentry *inline_dentry; |
| 502 | int slots = GET_DENTRY_SLOTS(le16_to_cpu(dentry->name_len)); |
| 503 | unsigned int bit_pos; |
| 504 | int i; |
| 505 | |
| 506 | lock_page(page); |
Jaegeuk Kim | 59a0615 | 2014-10-13 19:34:26 -0700 | [diff] [blame] | 507 | f2fs_wait_on_page_writeback(page, NODE); |
Chao Yu | 201a05b | 2014-09-24 18:17:53 +0800 | [diff] [blame] | 508 | |
| 509 | inline_dentry = inline_data_addr(page); |
| 510 | bit_pos = dentry - inline_dentry->dentry; |
| 511 | for (i = 0; i < slots; i++) |
| 512 | test_and_clear_bit_le(bit_pos + i, |
| 513 | &inline_dentry->dentry_bitmap); |
| 514 | |
| 515 | set_page_dirty(page); |
| 516 | |
| 517 | dir->i_ctime = dir->i_mtime = CURRENT_TIME; |
| 518 | |
| 519 | if (inode) |
| 520 | f2fs_drop_nlink(dir, inode, page); |
| 521 | |
| 522 | f2fs_put_page(page, 1); |
| 523 | } |
| 524 | |
| 525 | bool f2fs_empty_inline_dir(struct inode *dir) |
| 526 | { |
| 527 | struct f2fs_sb_info *sbi = F2FS_I_SB(dir); |
| 528 | struct page *ipage; |
| 529 | unsigned int bit_pos = 2; |
| 530 | struct f2fs_inline_dentry *dentry_blk; |
| 531 | |
| 532 | ipage = get_node_page(sbi, dir->i_ino); |
| 533 | if (IS_ERR(ipage)) |
| 534 | return false; |
| 535 | |
| 536 | dentry_blk = inline_data_addr(ipage); |
| 537 | bit_pos = find_next_bit_le(&dentry_blk->dentry_bitmap, |
| 538 | NR_INLINE_DENTRY, |
| 539 | bit_pos); |
| 540 | |
| 541 | f2fs_put_page(ipage, 1); |
| 542 | |
| 543 | if (bit_pos < NR_INLINE_DENTRY) |
| 544 | return false; |
| 545 | |
| 546 | return true; |
| 547 | } |
| 548 | |
Jaegeuk Kim | d8c6822 | 2015-04-27 16:26:24 -0700 | [diff] [blame] | 549 | int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx, |
| 550 | struct f2fs_str *fstr) |
Chao Yu | 201a05b | 2014-09-24 18:17:53 +0800 | [diff] [blame] | 551 | { |
| 552 | struct inode *inode = file_inode(file); |
Chao Yu | 201a05b | 2014-09-24 18:17:53 +0800 | [diff] [blame] | 553 | struct f2fs_inline_dentry *inline_dentry = NULL; |
Chao Yu | 201a05b | 2014-09-24 18:17:53 +0800 | [diff] [blame] | 554 | struct page *ipage = NULL; |
Jaegeuk Kim | 7b3cd7d | 2014-10-18 22:52:52 -0700 | [diff] [blame] | 555 | struct f2fs_dentry_ptr d; |
Chao Yu | 201a05b | 2014-09-24 18:17:53 +0800 | [diff] [blame] | 556 | |
| 557 | if (ctx->pos == NR_INLINE_DENTRY) |
| 558 | return 0; |
| 559 | |
Jaegeuk Kim | 38594de | 2014-10-15 21:29:51 -0700 | [diff] [blame] | 560 | ipage = get_node_page(F2FS_I_SB(inode), inode->i_ino); |
Chao Yu | 201a05b | 2014-09-24 18:17:53 +0800 | [diff] [blame] | 561 | if (IS_ERR(ipage)) |
| 562 | return PTR_ERR(ipage); |
| 563 | |
Chao Yu | 201a05b | 2014-09-24 18:17:53 +0800 | [diff] [blame] | 564 | inline_dentry = inline_data_addr(ipage); |
Chao Yu | 201a05b | 2014-09-24 18:17:53 +0800 | [diff] [blame] | 565 | |
Jaegeuk Kim | d8c6822 | 2015-04-27 16:26:24 -0700 | [diff] [blame] | 566 | make_dentry_ptr(inode, &d, (void *)inline_dentry, 2); |
Jaegeuk Kim | 7b3cd7d | 2014-10-18 22:52:52 -0700 | [diff] [blame] | 567 | |
Jaegeuk Kim | d8c6822 | 2015-04-27 16:26:24 -0700 | [diff] [blame] | 568 | if (!f2fs_fill_dentries(ctx, &d, 0, fstr)) |
Jaegeuk Kim | 38594de | 2014-10-15 21:29:51 -0700 | [diff] [blame] | 569 | ctx->pos = NR_INLINE_DENTRY; |
Chao Yu | 201a05b | 2014-09-24 18:17:53 +0800 | [diff] [blame] | 570 | |
Chao Yu | 201a05b | 2014-09-24 18:17:53 +0800 | [diff] [blame] | 571 | f2fs_put_page(ipage, 1); |
Chao Yu | 201a05b | 2014-09-24 18:17:53 +0800 | [diff] [blame] | 572 | return 0; |
| 573 | } |
Jaegeuk Kim | 67f8cf3 | 2015-10-15 11:34:49 -0700 | [diff] [blame] | 574 | |
| 575 | int f2fs_inline_data_fiemap(struct inode *inode, |
| 576 | struct fiemap_extent_info *fieinfo, __u64 start, __u64 len) |
| 577 | { |
| 578 | __u64 byteaddr, ilen; |
| 579 | __u32 flags = FIEMAP_EXTENT_DATA_INLINE | FIEMAP_EXTENT_NOT_ALIGNED | |
| 580 | FIEMAP_EXTENT_LAST; |
| 581 | struct node_info ni; |
| 582 | struct page *ipage; |
| 583 | int err = 0; |
| 584 | |
| 585 | ipage = get_node_page(F2FS_I_SB(inode), inode->i_ino); |
| 586 | if (IS_ERR(ipage)) |
| 587 | return PTR_ERR(ipage); |
| 588 | |
| 589 | if (!f2fs_has_inline_data(inode)) { |
| 590 | err = -EAGAIN; |
| 591 | goto out; |
| 592 | } |
| 593 | |
| 594 | ilen = min_t(size_t, MAX_INLINE_DATA, i_size_read(inode)); |
| 595 | if (start >= ilen) |
| 596 | goto out; |
| 597 | if (start + len < ilen) |
| 598 | ilen = start + len; |
| 599 | ilen -= start; |
| 600 | |
| 601 | get_node_info(F2FS_I_SB(inode), inode->i_ino, &ni); |
| 602 | byteaddr = (__u64)ni.blk_addr << inode->i_sb->s_blocksize_bits; |
| 603 | byteaddr += (char *)inline_data_addr(ipage) - (char *)F2FS_INODE(ipage); |
| 604 | err = fiemap_fill_next_extent(fieinfo, start, byteaddr, ilen, flags); |
| 605 | out: |
| 606 | f2fs_put_page(ipage, 1); |
| 607 | return err; |
| 608 | } |