|
14 | 14 | #include "node.h" |
15 | 15 | #include "segment.h" |
16 | 16 |
|
| 17 | +/* |
| 18 | + * Roll forward recovery scenarios. |
| 19 | + * |
| 20 | + * [Term] F: fsync_mark, D: dentry_mark |
| 21 | + * |
| 22 | + * 1. inode(x) | CP | inode(x) | dnode(F) |
| 23 | + * -> Update the latest inode(x). |
| 24 | + * |
| 25 | + * 2. inode(x) | CP | inode(F) | dnode(F) |
| 26 | + * -> No problem. |
| 27 | + * |
| 28 | + * 3. inode(x) | CP | dnode(F) | inode(x) |
| 29 | + * -> Recover to the latest dnode(F), and drop the last inode(x) |
| 30 | + * |
| 31 | + * 4. inode(x) | CP | dnode(F) | inode(F) |
| 32 | + * -> No problem. |
| 33 | + * |
| 34 | + * 5. CP | inode(x) | dnode(F) |
| 35 | + * -> The inode(DF) was missing. Should drop this dnode(F). |
| 36 | + * |
| 37 | + * 6. CP | inode(DF) | dnode(F) |
| 38 | + * -> No problem. |
| 39 | + * |
| 40 | + * 7. CP | dnode(F) | inode(DF) |
| 41 | + * -> If f2fs_iget fails, then goto next to find inode(DF). |
| 42 | + * |
| 43 | + * 8. CP | dnode(F) | inode(x) |
| 44 | + * -> If f2fs_iget fails, then goto next to find inode(DF). |
| 45 | + * But it will fail due to no inode(DF). |
| 46 | + */ |
| 47 | + |
17 | 48 | static struct kmem_cache *fsync_entry_slab; |
18 | 49 |
|
19 | 50 | bool space_for_roll_forward(struct f2fs_sb_info *sbi) |
@@ -110,27 +141,32 @@ static int recover_dentry(struct page *ipage, struct inode *inode) |
110 | 141 | return err; |
111 | 142 | } |
112 | 143 |
|
113 | | -static int recover_inode(struct inode *inode, struct page *node_page) |
| 144 | +static void __recover_inode(struct inode *inode, struct page *page) |
114 | 145 | { |
115 | | - struct f2fs_inode *raw_inode = F2FS_INODE(node_page); |
| 146 | + struct f2fs_inode *raw = F2FS_INODE(page); |
| 147 | + |
| 148 | + inode->i_mode = le16_to_cpu(raw->i_mode); |
| 149 | + i_size_write(inode, le64_to_cpu(raw->i_size)); |
| 150 | + inode->i_atime.tv_sec = le64_to_cpu(raw->i_mtime); |
| 151 | + inode->i_ctime.tv_sec = le64_to_cpu(raw->i_ctime); |
| 152 | + inode->i_mtime.tv_sec = le64_to_cpu(raw->i_mtime); |
| 153 | + inode->i_atime.tv_nsec = le32_to_cpu(raw->i_mtime_nsec); |
| 154 | + inode->i_ctime.tv_nsec = le32_to_cpu(raw->i_ctime_nsec); |
| 155 | + inode->i_mtime.tv_nsec = le32_to_cpu(raw->i_mtime_nsec); |
| 156 | +} |
116 | 157 |
|
| 158 | +static int recover_inode(struct inode *inode, struct page *node_page) |
| 159 | +{ |
117 | 160 | if (!IS_INODE(node_page)) |
118 | 161 | return 0; |
119 | 162 |
|
120 | | - inode->i_mode = le16_to_cpu(raw_inode->i_mode); |
121 | | - i_size_write(inode, le64_to_cpu(raw_inode->i_size)); |
122 | | - inode->i_atime.tv_sec = le64_to_cpu(raw_inode->i_mtime); |
123 | | - inode->i_ctime.tv_sec = le64_to_cpu(raw_inode->i_ctime); |
124 | | - inode->i_mtime.tv_sec = le64_to_cpu(raw_inode->i_mtime); |
125 | | - inode->i_atime.tv_nsec = le32_to_cpu(raw_inode->i_mtime_nsec); |
126 | | - inode->i_ctime.tv_nsec = le32_to_cpu(raw_inode->i_ctime_nsec); |
127 | | - inode->i_mtime.tv_nsec = le32_to_cpu(raw_inode->i_mtime_nsec); |
| 163 | + __recover_inode(inode, node_page); |
128 | 164 |
|
129 | 165 | if (is_dent_dnode(node_page)) |
130 | 166 | return recover_dentry(node_page, inode); |
131 | 167 |
|
132 | 168 | f2fs_msg(inode->i_sb, KERN_NOTICE, "recover_inode: ino = %x, name = %s", |
133 | | - ino_of_node(node_page), raw_inode->i_name); |
| 169 | + ino_of_node(node_page), F2FS_INODE(node_page)->i_name); |
134 | 170 | return 0; |
135 | 171 | } |
136 | 172 |
|
@@ -180,10 +216,16 @@ static int find_fsync_dnodes(struct f2fs_sb_info *sbi, struct list_head *head) |
180 | 216 | break; |
181 | 217 | } |
182 | 218 |
|
| 219 | + /* |
| 220 | + * CP | dnode(F) | inode(DF) |
| 221 | + * For this case, we should not give up now. |
| 222 | + */ |
183 | 223 | entry->inode = f2fs_iget(sbi->sb, ino_of_node(page)); |
184 | 224 | if (IS_ERR(entry->inode)) { |
185 | 225 | err = PTR_ERR(entry->inode); |
186 | 226 | kmem_cache_free(fsync_entry_slab, entry); |
| 227 | + if (err == -ENOENT) |
| 228 | + goto next; |
187 | 229 | break; |
188 | 230 | } |
189 | 231 | list_add_tail(&entry->list, head); |
@@ -417,6 +459,13 @@ static int recover_data(struct f2fs_sb_info *sbi, |
417 | 459 | entry = get_fsync_inode(head, ino_of_node(page)); |
418 | 460 | if (!entry) |
419 | 461 | goto next; |
| 462 | + /* |
| 463 | + * inode(x) | CP | inode(x) | dnode(F) |
| 464 | + * In this case, we can lose the latest inode(x). |
| 465 | + * So, call __recover_inode for the inode update. |
| 466 | + */ |
| 467 | + if (IS_INODE(page)) |
| 468 | + __recover_inode(entry->inode, page); |
420 | 469 |
|
421 | 470 | err = do_recover_data(sbi, entry->inode, page, blkaddr); |
422 | 471 | if (err) { |
|
0 commit comments