Jaegeuk Kim | 0a8165d | 2012-11-29 13:28:09 +0900 | [diff] [blame] | 1 | /* |
Jaegeuk Kim | d624c96 | 2012-11-02 17:13:32 +0900 | [diff] [blame] | 2 | * fs/f2fs/recovery.c |
| 3 | * |
| 4 | * Copyright (c) 2012 Samsung Electronics Co., Ltd. |
| 5 | * http://www.samsung.com/ |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | */ |
| 11 | #include <linux/fs.h> |
| 12 | #include <linux/f2fs_fs.h> |
| 13 | #include "f2fs.h" |
| 14 | #include "node.h" |
| 15 | #include "segment.h" |
| 16 | |
| 17 | static struct kmem_cache *fsync_entry_slab; |
| 18 | |
| 19 | bool space_for_roll_forward(struct f2fs_sb_info *sbi) |
| 20 | { |
| 21 | if (sbi->last_valid_block_count + sbi->alloc_valid_block_count |
| 22 | > sbi->user_block_count) |
| 23 | return false; |
| 24 | return true; |
| 25 | } |
| 26 | |
| 27 | static struct fsync_inode_entry *get_fsync_inode(struct list_head *head, |
| 28 | nid_t ino) |
| 29 | { |
| 30 | struct list_head *this; |
| 31 | struct fsync_inode_entry *entry; |
| 32 | |
| 33 | list_for_each(this, head) { |
| 34 | entry = list_entry(this, struct fsync_inode_entry, list); |
| 35 | if (entry->inode->i_ino == ino) |
| 36 | return entry; |
| 37 | } |
| 38 | return NULL; |
| 39 | } |
| 40 | |
| 41 | static int recover_dentry(struct page *ipage, struct inode *inode) |
| 42 | { |
| 43 | struct f2fs_node *raw_node = (struct f2fs_node *)kmap(ipage); |
| 44 | struct f2fs_inode *raw_inode = &(raw_node->i); |
Al Viro | b7f7a5e | 2013-01-25 16:15:43 -0500 | [diff] [blame] | 45 | struct qstr name; |
Jaegeuk Kim | d624c96 | 2012-11-02 17:13:32 +0900 | [diff] [blame] | 46 | struct f2fs_dir_entry *de; |
| 47 | struct page *page; |
| 48 | struct inode *dir; |
| 49 | int err = 0; |
| 50 | |
| 51 | if (!is_dent_dnode(ipage)) |
| 52 | goto out; |
| 53 | |
| 54 | dir = f2fs_iget(inode->i_sb, le32_to_cpu(raw_inode->i_pino)); |
| 55 | if (IS_ERR(dir)) { |
Chris Fries | 047184b | 2013-05-02 16:09:05 -0500 | [diff] [blame] | 56 | err = PTR_ERR(dir); |
Jaegeuk Kim | d624c96 | 2012-11-02 17:13:32 +0900 | [diff] [blame] | 57 | goto out; |
| 58 | } |
| 59 | |
Al Viro | b7f7a5e | 2013-01-25 16:15:43 -0500 | [diff] [blame] | 60 | name.len = le32_to_cpu(raw_inode->i_namelen); |
| 61 | name.name = raw_inode->i_name; |
Jaegeuk Kim | d624c96 | 2012-11-02 17:13:32 +0900 | [diff] [blame] | 62 | |
Al Viro | b7f7a5e | 2013-01-25 16:15:43 -0500 | [diff] [blame] | 63 | de = f2fs_find_entry(dir, &name, &page); |
Jaegeuk Kim | d624c96 | 2012-11-02 17:13:32 +0900 | [diff] [blame] | 64 | if (de) { |
| 65 | kunmap(page); |
| 66 | f2fs_put_page(page, 0); |
| 67 | } else { |
Jaegeuk Kim | 90b2fc6 | 2013-02-12 07:17:20 +0900 | [diff] [blame] | 68 | err = __f2fs_add_link(dir, &name, inode); |
Jaegeuk Kim | d624c96 | 2012-11-02 17:13:32 +0900 | [diff] [blame] | 69 | } |
| 70 | iput(dir); |
| 71 | out: |
| 72 | kunmap(ipage); |
| 73 | return err; |
| 74 | } |
| 75 | |
| 76 | static int recover_inode(struct inode *inode, struct page *node_page) |
| 77 | { |
| 78 | void *kaddr = page_address(node_page); |
| 79 | struct f2fs_node *raw_node = (struct f2fs_node *)kaddr; |
| 80 | struct f2fs_inode *raw_inode = &(raw_node->i); |
| 81 | |
Jaegeuk Kim | 25ca923 | 2012-11-28 16:12:41 +0900 | [diff] [blame] | 82 | inode->i_mode = le16_to_cpu(raw_inode->i_mode); |
Jaegeuk Kim | d624c96 | 2012-11-02 17:13:32 +0900 | [diff] [blame] | 83 | i_size_write(inode, le64_to_cpu(raw_inode->i_size)); |
| 84 | inode->i_atime.tv_sec = le64_to_cpu(raw_inode->i_mtime); |
| 85 | inode->i_ctime.tv_sec = le64_to_cpu(raw_inode->i_ctime); |
| 86 | inode->i_mtime.tv_sec = le64_to_cpu(raw_inode->i_mtime); |
| 87 | inode->i_atime.tv_nsec = le32_to_cpu(raw_inode->i_mtime_nsec); |
| 88 | inode->i_ctime.tv_nsec = le32_to_cpu(raw_inode->i_ctime_nsec); |
| 89 | inode->i_mtime.tv_nsec = le32_to_cpu(raw_inode->i_mtime_nsec); |
| 90 | |
| 91 | return recover_dentry(node_page, inode); |
| 92 | } |
| 93 | |
| 94 | static int find_fsync_dnodes(struct f2fs_sb_info *sbi, struct list_head *head) |
| 95 | { |
| 96 | unsigned long long cp_ver = le64_to_cpu(sbi->ckpt->checkpoint_ver); |
| 97 | struct curseg_info *curseg; |
| 98 | struct page *page; |
| 99 | block_t blkaddr; |
| 100 | int err = 0; |
| 101 | |
| 102 | /* get node pages in the current segment */ |
| 103 | curseg = CURSEG_I(sbi, CURSEG_WARM_NODE); |
| 104 | blkaddr = START_BLOCK(sbi, curseg->segno) + curseg->next_blkoff; |
| 105 | |
| 106 | /* read node page */ |
| 107 | page = alloc_page(GFP_F2FS_ZERO); |
| 108 | if (IS_ERR(page)) |
| 109 | return PTR_ERR(page); |
| 110 | lock_page(page); |
| 111 | |
| 112 | while (1) { |
| 113 | struct fsync_inode_entry *entry; |
| 114 | |
Jaegeuk Kim | 393ff91 | 2013-03-08 21:29:23 +0900 | [diff] [blame] | 115 | err = f2fs_readpage(sbi, page, blkaddr, READ_SYNC); |
| 116 | if (err) |
Jaegeuk Kim | d624c96 | 2012-11-02 17:13:32 +0900 | [diff] [blame] | 117 | goto out; |
| 118 | |
Jaegeuk Kim | 393ff91 | 2013-03-08 21:29:23 +0900 | [diff] [blame] | 119 | lock_page(page); |
| 120 | |
Jaegeuk Kim | 6ead114 | 2013-03-20 19:01:06 +0900 | [diff] [blame] | 121 | if (cp_ver != cpver_of_node(page)) |
Jaegeuk Kim | 393ff91 | 2013-03-08 21:29:23 +0900 | [diff] [blame] | 122 | goto unlock_out; |
Jaegeuk Kim | d624c96 | 2012-11-02 17:13:32 +0900 | [diff] [blame] | 123 | |
| 124 | if (!is_fsync_dnode(page)) |
| 125 | goto next; |
| 126 | |
| 127 | entry = get_fsync_inode(head, ino_of_node(page)); |
| 128 | if (entry) { |
| 129 | entry->blkaddr = blkaddr; |
| 130 | if (IS_INODE(page) && is_dent_dnode(page)) |
| 131 | set_inode_flag(F2FS_I(entry->inode), |
| 132 | FI_INC_LINK); |
| 133 | } else { |
| 134 | if (IS_INODE(page) && is_dent_dnode(page)) { |
Jaegeuk Kim | 6ead114 | 2013-03-20 19:01:06 +0900 | [diff] [blame] | 135 | err = recover_inode_page(sbi, page); |
| 136 | if (err) |
Jaegeuk Kim | 393ff91 | 2013-03-08 21:29:23 +0900 | [diff] [blame] | 137 | goto unlock_out; |
Jaegeuk Kim | d624c96 | 2012-11-02 17:13:32 +0900 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | /* add this fsync inode to the list */ |
| 141 | entry = kmem_cache_alloc(fsync_entry_slab, GFP_NOFS); |
| 142 | if (!entry) { |
| 143 | err = -ENOMEM; |
Jaegeuk Kim | 393ff91 | 2013-03-08 21:29:23 +0900 | [diff] [blame] | 144 | goto unlock_out; |
Jaegeuk Kim | d624c96 | 2012-11-02 17:13:32 +0900 | [diff] [blame] | 145 | } |
| 146 | |
Jaegeuk Kim | d624c96 | 2012-11-02 17:13:32 +0900 | [diff] [blame] | 147 | entry->inode = f2fs_iget(sbi->sb, ino_of_node(page)); |
| 148 | if (IS_ERR(entry->inode)) { |
| 149 | err = PTR_ERR(entry->inode); |
Namjae Jeon | fd8bb65 | 2012-12-22 12:10:12 +0900 | [diff] [blame] | 150 | kmem_cache_free(fsync_entry_slab, entry); |
Jaegeuk Kim | 393ff91 | 2013-03-08 21:29:23 +0900 | [diff] [blame] | 151 | goto unlock_out; |
Jaegeuk Kim | d624c96 | 2012-11-02 17:13:32 +0900 | [diff] [blame] | 152 | } |
Namjae Jeon | fd8bb65 | 2012-12-22 12:10:12 +0900 | [diff] [blame] | 153 | |
Namjae Jeon | fd8bb65 | 2012-12-22 12:10:12 +0900 | [diff] [blame] | 154 | list_add_tail(&entry->list, head); |
Jaegeuk Kim | d624c96 | 2012-11-02 17:13:32 +0900 | [diff] [blame] | 155 | entry->blkaddr = blkaddr; |
| 156 | } |
| 157 | if (IS_INODE(page)) { |
| 158 | err = recover_inode(entry->inode, page); |
Chris Fries | 047184b | 2013-05-02 16:09:05 -0500 | [diff] [blame] | 159 | if (err == -ENOENT) { |
| 160 | goto next; |
| 161 | } else if (err) { |
| 162 | err = -EINVAL; |
Jaegeuk Kim | 393ff91 | 2013-03-08 21:29:23 +0900 | [diff] [blame] | 163 | goto unlock_out; |
Chris Fries | 047184b | 2013-05-02 16:09:05 -0500 | [diff] [blame] | 164 | } |
Jaegeuk Kim | d624c96 | 2012-11-02 17:13:32 +0900 | [diff] [blame] | 165 | } |
| 166 | next: |
| 167 | /* check next segment */ |
| 168 | blkaddr = next_blkaddr_of_node(page); |
Jaegeuk Kim | d624c96 | 2012-11-02 17:13:32 +0900 | [diff] [blame] | 169 | } |
Jaegeuk Kim | 393ff91 | 2013-03-08 21:29:23 +0900 | [diff] [blame] | 170 | unlock_out: |
Jaegeuk Kim | d624c96 | 2012-11-02 17:13:32 +0900 | [diff] [blame] | 171 | unlock_page(page); |
Jaegeuk Kim | 393ff91 | 2013-03-08 21:29:23 +0900 | [diff] [blame] | 172 | out: |
Jaegeuk Kim | d624c96 | 2012-11-02 17:13:32 +0900 | [diff] [blame] | 173 | __free_pages(page, 0); |
| 174 | return err; |
| 175 | } |
| 176 | |
| 177 | static void destroy_fsync_dnodes(struct f2fs_sb_info *sbi, |
| 178 | struct list_head *head) |
| 179 | { |
Dan Carpenter | d8b79b2 | 2013-01-20 18:02:58 +0300 | [diff] [blame] | 180 | struct fsync_inode_entry *entry, *tmp; |
| 181 | |
| 182 | list_for_each_entry_safe(entry, tmp, head, list) { |
Jaegeuk Kim | d624c96 | 2012-11-02 17:13:32 +0900 | [diff] [blame] | 183 | iput(entry->inode); |
| 184 | list_del(&entry->list); |
| 185 | kmem_cache_free(fsync_entry_slab, entry); |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | static void check_index_in_prev_nodes(struct f2fs_sb_info *sbi, |
| 190 | block_t blkaddr) |
| 191 | { |
| 192 | struct seg_entry *sentry; |
| 193 | unsigned int segno = GET_SEGNO(sbi, blkaddr); |
| 194 | unsigned short blkoff = GET_SEGOFF_FROM_SEG0(sbi, blkaddr) & |
| 195 | (sbi->blocks_per_seg - 1); |
| 196 | struct f2fs_summary sum; |
| 197 | nid_t ino; |
| 198 | void *kaddr; |
| 199 | struct inode *inode; |
| 200 | struct page *node_page; |
| 201 | block_t bidx; |
| 202 | int i; |
| 203 | |
| 204 | sentry = get_seg_entry(sbi, segno); |
| 205 | if (!f2fs_test_bit(blkoff, sentry->cur_valid_map)) |
| 206 | return; |
| 207 | |
| 208 | /* Get the previous summary */ |
| 209 | for (i = CURSEG_WARM_DATA; i <= CURSEG_COLD_DATA; i++) { |
| 210 | struct curseg_info *curseg = CURSEG_I(sbi, i); |
| 211 | if (curseg->segno == segno) { |
| 212 | sum = curseg->sum_blk->entries[blkoff]; |
| 213 | break; |
| 214 | } |
| 215 | } |
| 216 | if (i > CURSEG_COLD_DATA) { |
| 217 | struct page *sum_page = get_sum_page(sbi, segno); |
| 218 | struct f2fs_summary_block *sum_node; |
| 219 | kaddr = page_address(sum_page); |
| 220 | sum_node = (struct f2fs_summary_block *)kaddr; |
| 221 | sum = sum_node->entries[blkoff]; |
| 222 | f2fs_put_page(sum_page, 1); |
| 223 | } |
| 224 | |
| 225 | /* Get the node page */ |
| 226 | node_page = get_node_page(sbi, le32_to_cpu(sum.nid)); |
| 227 | bidx = start_bidx_of_node(ofs_of_node(node_page)) + |
| 228 | le16_to_cpu(sum.ofs_in_node); |
| 229 | ino = ino_of_node(node_page); |
| 230 | f2fs_put_page(node_page, 1); |
| 231 | |
| 232 | /* Deallocate previous index in the node page */ |
Jaegeuk Kim | d4686d56 | 2013-01-31 15:36:04 +0900 | [diff] [blame] | 233 | inode = f2fs_iget(sbi->sb, ino); |
Namjae Jeon | 06025f4 | 2012-12-22 12:09:43 +0900 | [diff] [blame] | 234 | if (IS_ERR(inode)) |
| 235 | return; |
| 236 | |
Jaegeuk Kim | d624c96 | 2012-11-02 17:13:32 +0900 | [diff] [blame] | 237 | truncate_hole(inode, bidx, bidx + 1); |
| 238 | iput(inode); |
| 239 | } |
| 240 | |
Jaegeuk Kim | 6ead114 | 2013-03-20 19:01:06 +0900 | [diff] [blame] | 241 | static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode, |
Jaegeuk Kim | d624c96 | 2012-11-02 17:13:32 +0900 | [diff] [blame] | 242 | struct page *page, block_t blkaddr) |
| 243 | { |
| 244 | unsigned int start, end; |
| 245 | struct dnode_of_data dn; |
| 246 | struct f2fs_summary sum; |
| 247 | struct node_info ni; |
Jaegeuk Kim | 6ead114 | 2013-03-20 19:01:06 +0900 | [diff] [blame] | 248 | int err = 0; |
Jaegeuk Kim | 3993683 | 2012-11-22 16:21:29 +0900 | [diff] [blame] | 249 | int ilock; |
Jaegeuk Kim | d624c96 | 2012-11-02 17:13:32 +0900 | [diff] [blame] | 250 | |
| 251 | start = start_bidx_of_node(ofs_of_node(page)); |
| 252 | if (IS_INODE(page)) |
| 253 | end = start + ADDRS_PER_INODE; |
| 254 | else |
| 255 | end = start + ADDRS_PER_BLOCK; |
| 256 | |
Jaegeuk Kim | 3993683 | 2012-11-22 16:21:29 +0900 | [diff] [blame] | 257 | ilock = mutex_lock_op(sbi); |
Jaegeuk Kim | d624c96 | 2012-11-02 17:13:32 +0900 | [diff] [blame] | 258 | set_new_dnode(&dn, inode, NULL, NULL, 0); |
Jaegeuk Kim | 3993683 | 2012-11-22 16:21:29 +0900 | [diff] [blame] | 259 | |
Jaegeuk Kim | 6ead114 | 2013-03-20 19:01:06 +0900 | [diff] [blame] | 260 | err = get_dnode_of_data(&dn, start, ALLOC_NODE); |
Jaegeuk Kim | 3993683 | 2012-11-22 16:21:29 +0900 | [diff] [blame] | 261 | if (err) { |
| 262 | mutex_unlock_op(sbi, ilock); |
Jaegeuk Kim | 6ead114 | 2013-03-20 19:01:06 +0900 | [diff] [blame] | 263 | return err; |
Jaegeuk Kim | 3993683 | 2012-11-22 16:21:29 +0900 | [diff] [blame] | 264 | } |
Jaegeuk Kim | d624c96 | 2012-11-02 17:13:32 +0900 | [diff] [blame] | 265 | |
| 266 | wait_on_page_writeback(dn.node_page); |
| 267 | |
| 268 | get_node_info(sbi, dn.nid, &ni); |
| 269 | BUG_ON(ni.ino != ino_of_node(page)); |
| 270 | BUG_ON(ofs_of_node(dn.node_page) != ofs_of_node(page)); |
| 271 | |
| 272 | for (; start < end; start++) { |
| 273 | block_t src, dest; |
| 274 | |
| 275 | src = datablock_addr(dn.node_page, dn.ofs_in_node); |
| 276 | dest = datablock_addr(page, dn.ofs_in_node); |
| 277 | |
| 278 | if (src != dest && dest != NEW_ADDR && dest != NULL_ADDR) { |
| 279 | if (src == NULL_ADDR) { |
| 280 | int err = reserve_new_block(&dn); |
| 281 | /* We should not get -ENOSPC */ |
| 282 | BUG_ON(err); |
| 283 | } |
| 284 | |
| 285 | /* Check the previous node page having this index */ |
| 286 | check_index_in_prev_nodes(sbi, dest); |
| 287 | |
| 288 | set_summary(&sum, dn.nid, dn.ofs_in_node, ni.version); |
| 289 | |
| 290 | /* write dummy data page */ |
| 291 | recover_data_page(sbi, NULL, &sum, src, dest); |
| 292 | update_extent_cache(dest, &dn); |
| 293 | } |
| 294 | dn.ofs_in_node++; |
| 295 | } |
| 296 | |
| 297 | /* write node page in place */ |
| 298 | set_summary(&sum, dn.nid, 0, 0); |
| 299 | if (IS_INODE(dn.node_page)) |
| 300 | sync_inode_page(&dn); |
| 301 | |
| 302 | copy_node_footer(dn.node_page, page); |
| 303 | fill_node_footer(dn.node_page, dn.nid, ni.ino, |
| 304 | ofs_of_node(page), false); |
| 305 | set_page_dirty(dn.node_page); |
| 306 | |
| 307 | recover_node_page(sbi, dn.node_page, &sum, &ni, blkaddr); |
| 308 | f2fs_put_dnode(&dn); |
Jaegeuk Kim | 3993683 | 2012-11-22 16:21:29 +0900 | [diff] [blame] | 309 | mutex_unlock_op(sbi, ilock); |
Jaegeuk Kim | 6ead114 | 2013-03-20 19:01:06 +0900 | [diff] [blame] | 310 | return 0; |
Jaegeuk Kim | d624c96 | 2012-11-02 17:13:32 +0900 | [diff] [blame] | 311 | } |
| 312 | |
Jaegeuk Kim | 6ead114 | 2013-03-20 19:01:06 +0900 | [diff] [blame] | 313 | static int recover_data(struct f2fs_sb_info *sbi, |
Jaegeuk Kim | d624c96 | 2012-11-02 17:13:32 +0900 | [diff] [blame] | 314 | struct list_head *head, int type) |
| 315 | { |
| 316 | unsigned long long cp_ver = le64_to_cpu(sbi->ckpt->checkpoint_ver); |
| 317 | struct curseg_info *curseg; |
| 318 | struct page *page; |
Jaegeuk Kim | 6ead114 | 2013-03-20 19:01:06 +0900 | [diff] [blame] | 319 | int err = 0; |
Jaegeuk Kim | d624c96 | 2012-11-02 17:13:32 +0900 | [diff] [blame] | 320 | block_t blkaddr; |
| 321 | |
| 322 | /* get node pages in the current segment */ |
| 323 | curseg = CURSEG_I(sbi, type); |
| 324 | blkaddr = NEXT_FREE_BLKADDR(sbi, curseg); |
| 325 | |
| 326 | /* read node page */ |
| 327 | page = alloc_page(GFP_NOFS | __GFP_ZERO); |
| 328 | if (IS_ERR(page)) |
Jaegeuk Kim | 6ead114 | 2013-03-20 19:01:06 +0900 | [diff] [blame] | 329 | return -ENOMEM; |
| 330 | |
Jaegeuk Kim | d624c96 | 2012-11-02 17:13:32 +0900 | [diff] [blame] | 331 | lock_page(page); |
| 332 | |
| 333 | while (1) { |
| 334 | struct fsync_inode_entry *entry; |
| 335 | |
Jaegeuk Kim | 6ead114 | 2013-03-20 19:01:06 +0900 | [diff] [blame] | 336 | err = f2fs_readpage(sbi, page, blkaddr, READ_SYNC); |
| 337 | if (err) |
Jaegeuk Kim | d624c96 | 2012-11-02 17:13:32 +0900 | [diff] [blame] | 338 | goto out; |
| 339 | |
Jaegeuk Kim | 393ff91 | 2013-03-08 21:29:23 +0900 | [diff] [blame] | 340 | lock_page(page); |
| 341 | |
Jaegeuk Kim | d624c96 | 2012-11-02 17:13:32 +0900 | [diff] [blame] | 342 | if (cp_ver != cpver_of_node(page)) |
Jaegeuk Kim | 393ff91 | 2013-03-08 21:29:23 +0900 | [diff] [blame] | 343 | goto unlock_out; |
Jaegeuk Kim | d624c96 | 2012-11-02 17:13:32 +0900 | [diff] [blame] | 344 | |
| 345 | entry = get_fsync_inode(head, ino_of_node(page)); |
| 346 | if (!entry) |
| 347 | goto next; |
| 348 | |
Jaegeuk Kim | 6ead114 | 2013-03-20 19:01:06 +0900 | [diff] [blame] | 349 | err = do_recover_data(sbi, entry->inode, page, blkaddr); |
| 350 | if (err) |
| 351 | goto out; |
Jaegeuk Kim | d624c96 | 2012-11-02 17:13:32 +0900 | [diff] [blame] | 352 | |
| 353 | if (entry->blkaddr == blkaddr) { |
| 354 | iput(entry->inode); |
| 355 | list_del(&entry->list); |
| 356 | kmem_cache_free(fsync_entry_slab, entry); |
| 357 | } |
| 358 | next: |
| 359 | /* check next segment */ |
| 360 | blkaddr = next_blkaddr_of_node(page); |
Jaegeuk Kim | d624c96 | 2012-11-02 17:13:32 +0900 | [diff] [blame] | 361 | } |
Jaegeuk Kim | 393ff91 | 2013-03-08 21:29:23 +0900 | [diff] [blame] | 362 | unlock_out: |
Jaegeuk Kim | d624c96 | 2012-11-02 17:13:32 +0900 | [diff] [blame] | 363 | unlock_page(page); |
Jaegeuk Kim | 393ff91 | 2013-03-08 21:29:23 +0900 | [diff] [blame] | 364 | out: |
Jaegeuk Kim | d624c96 | 2012-11-02 17:13:32 +0900 | [diff] [blame] | 365 | __free_pages(page, 0); |
| 366 | |
Jaegeuk Kim | 6ead114 | 2013-03-20 19:01:06 +0900 | [diff] [blame] | 367 | if (!err) |
| 368 | allocate_new_segments(sbi); |
| 369 | return err; |
Jaegeuk Kim | d624c96 | 2012-11-02 17:13:32 +0900 | [diff] [blame] | 370 | } |
| 371 | |
Jaegeuk Kim | 6ead114 | 2013-03-20 19:01:06 +0900 | [diff] [blame] | 372 | int recover_fsync_data(struct f2fs_sb_info *sbi) |
Jaegeuk Kim | d624c96 | 2012-11-02 17:13:32 +0900 | [diff] [blame] | 373 | { |
| 374 | struct list_head inode_list; |
Jaegeuk Kim | 6ead114 | 2013-03-20 19:01:06 +0900 | [diff] [blame] | 375 | int err; |
Jaegeuk Kim | d624c96 | 2012-11-02 17:13:32 +0900 | [diff] [blame] | 376 | |
| 377 | fsync_entry_slab = f2fs_kmem_cache_create("f2fs_fsync_inode_entry", |
| 378 | sizeof(struct fsync_inode_entry), NULL); |
| 379 | if (unlikely(!fsync_entry_slab)) |
Jaegeuk Kim | 6ead114 | 2013-03-20 19:01:06 +0900 | [diff] [blame] | 380 | return -ENOMEM; |
Jaegeuk Kim | d624c96 | 2012-11-02 17:13:32 +0900 | [diff] [blame] | 381 | |
| 382 | INIT_LIST_HEAD(&inode_list); |
| 383 | |
| 384 | /* step #1: find fsynced inode numbers */ |
Jaegeuk Kim | 6ead114 | 2013-03-20 19:01:06 +0900 | [diff] [blame] | 385 | err = find_fsync_dnodes(sbi, &inode_list); |
| 386 | if (err) |
Jaegeuk Kim | d624c96 | 2012-11-02 17:13:32 +0900 | [diff] [blame] | 387 | goto out; |
| 388 | |
| 389 | if (list_empty(&inode_list)) |
| 390 | goto out; |
| 391 | |
| 392 | /* step #2: recover data */ |
| 393 | sbi->por_doing = 1; |
Jaegeuk Kim | 6ead114 | 2013-03-20 19:01:06 +0900 | [diff] [blame] | 394 | err = recover_data(sbi, &inode_list, CURSEG_WARM_NODE); |
Jaegeuk Kim | d624c96 | 2012-11-02 17:13:32 +0900 | [diff] [blame] | 395 | sbi->por_doing = 0; |
| 396 | BUG_ON(!list_empty(&inode_list)); |
| 397 | out: |
| 398 | destroy_fsync_dnodes(sbi, &inode_list); |
| 399 | kmem_cache_destroy(fsync_entry_slab); |
Jaegeuk Kim | 4372752 | 2013-02-04 15:11:17 +0900 | [diff] [blame] | 400 | write_checkpoint(sbi, false); |
Jaegeuk Kim | 6ead114 | 2013-03-20 19:01:06 +0900 | [diff] [blame] | 401 | return err; |
Jaegeuk Kim | d624c96 | 2012-11-02 17:13:32 +0900 | [diff] [blame] | 402 | } |