diff options
author | Jaegeuk Kim <jaegeuk.kim@samsung.com> | 2013-03-21 02:21:57 -0400 |
---|---|---|
committer | Jaegeuk Kim <jaegeuk.kim@samsung.com> | 2013-03-26 20:16:25 -0400 |
commit | 953a3e27e10fc6acb480801ea47197d0270d735e (patch) | |
tree | 8ff66198318ee79464b9ac47e8ee091acf140c20 | |
parent | fa37241743ac26ba0ac6f54579158c2fae310a5c (diff) |
f2fs: fix to give correct parent inode number for roll forward
When we recover fsync'ed data after power-off-recovery, we should guarantee
that any parent inode number should be correct for each direct inode blocks.
So, let's make the following rules.
- The fsync should do checkpoint to all the inodes that were experienced hard
links.
- So, the only normal files can be recovered by roll-forward.
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
-rw-r--r-- | fs/f2fs/f2fs.h | 2 | ||||
-rw-r--r-- | fs/f2fs/file.c | 22 | ||||
-rw-r--r-- | fs/f2fs/namei.c | 14 | ||||
-rw-r--r-- | fs/f2fs/node.h | 15 |
4 files changed, 28 insertions, 25 deletions
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 380e2b3cdac7..77e2eb061bfa 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h | |||
@@ -148,6 +148,7 @@ struct extent_info { | |||
148 | * i_advise uses FADVISE_XXX_BIT. We can add additional hints later. | 148 | * i_advise uses FADVISE_XXX_BIT. We can add additional hints later. |
149 | */ | 149 | */ |
150 | #define FADVISE_COLD_BIT 0x01 | 150 | #define FADVISE_COLD_BIT 0x01 |
151 | #define FADVISE_CP_BIT 0x02 | ||
151 | 152 | ||
152 | struct f2fs_inode_info { | 153 | struct f2fs_inode_info { |
153 | struct inode vfs_inode; /* serve a vfs inode */ | 154 | struct inode vfs_inode; /* serve a vfs inode */ |
@@ -825,7 +826,6 @@ static inline int f2fs_clear_bit(unsigned int nr, char *addr) | |||
825 | /* used for f2fs_inode_info->flags */ | 826 | /* used for f2fs_inode_info->flags */ |
826 | enum { | 827 | enum { |
827 | FI_NEW_INODE, /* indicate newly allocated inode */ | 828 | FI_NEW_INODE, /* indicate newly allocated inode */ |
828 | FI_NEED_CP, /* need to do checkpoint during fsync */ | ||
829 | FI_INC_LINK, /* need to increment i_nlink */ | 829 | FI_INC_LINK, /* need to increment i_nlink */ |
830 | FI_ACL_MODE, /* indicate acl mode */ | 830 | FI_ACL_MODE, /* indicate acl mode */ |
831 | FI_NO_ALLOC, /* should not allocate any blocks */ | 831 | FI_NO_ALLOC, /* should not allocate any blocks */ |
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index d65fcad578c5..e031f570df79 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c | |||
@@ -103,23 +103,6 @@ static const struct vm_operations_struct f2fs_file_vm_ops = { | |||
103 | .remap_pages = generic_file_remap_pages, | 103 | .remap_pages = generic_file_remap_pages, |
104 | }; | 104 | }; |
105 | 105 | ||
106 | static int need_to_sync_dir(struct f2fs_sb_info *sbi, struct inode *inode) | ||
107 | { | ||
108 | struct dentry *dentry; | ||
109 | nid_t pino; | ||
110 | |||
111 | inode = igrab(inode); | ||
112 | dentry = d_find_any_alias(inode); | ||
113 | if (!dentry) { | ||
114 | iput(inode); | ||
115 | return 0; | ||
116 | } | ||
117 | pino = dentry->d_parent->d_inode->i_ino; | ||
118 | dput(dentry); | ||
119 | iput(inode); | ||
120 | return !is_checkpointed_node(sbi, pino); | ||
121 | } | ||
122 | |||
123 | int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync) | 106 | int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync) |
124 | { | 107 | { |
125 | struct inode *inode = file->f_mapping->host; | 108 | struct inode *inode = file->f_mapping->host; |
@@ -149,17 +132,16 @@ int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync) | |||
149 | 132 | ||
150 | if (!S_ISREG(inode->i_mode) || inode->i_nlink != 1) | 133 | if (!S_ISREG(inode->i_mode) || inode->i_nlink != 1) |
151 | need_cp = true; | 134 | need_cp = true; |
152 | else if (is_inode_flag_set(F2FS_I(inode), FI_NEED_CP)) | 135 | else if (is_cp_file(inode)) |
153 | need_cp = true; | 136 | need_cp = true; |
154 | else if (!space_for_roll_forward(sbi)) | 137 | else if (!space_for_roll_forward(sbi)) |
155 | need_cp = true; | 138 | need_cp = true; |
156 | else if (need_to_sync_dir(sbi, inode)) | 139 | else if (!is_checkpointed_node(sbi, F2FS_I(inode)->i_pino)) |
157 | need_cp = true; | 140 | need_cp = true; |
158 | 141 | ||
159 | if (need_cp) { | 142 | if (need_cp) { |
160 | /* all the dirty node pages should be flushed for POR */ | 143 | /* all the dirty node pages should be flushed for POR */ |
161 | ret = f2fs_sync_fs(inode->i_sb, 1); | 144 | ret = f2fs_sync_fs(inode->i_sb, 1); |
162 | clear_inode_flag(F2FS_I(inode), FI_NEED_CP); | ||
163 | } else { | 145 | } else { |
164 | /* if there is no written node page, write its inode page */ | 146 | /* if there is no written node page, write its inode page */ |
165 | while (!sync_node_pages(sbi, inode->i_ino, &wbc)) { | 147 | while (!sync_node_pages(sbi, inode->i_ino, &wbc)) { |
diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c index d4a171b1a68b..7c6e219a479c 100644 --- a/fs/f2fs/namei.c +++ b/fs/f2fs/namei.c | |||
@@ -15,6 +15,7 @@ | |||
15 | #include <linux/ctype.h> | 15 | #include <linux/ctype.h> |
16 | 16 | ||
17 | #include "f2fs.h" | 17 | #include "f2fs.h" |
18 | #include "node.h" | ||
18 | #include "xattr.h" | 19 | #include "xattr.h" |
19 | #include "acl.h" | 20 | #include "acl.h" |
20 | 21 | ||
@@ -99,7 +100,7 @@ static int is_multimedia_file(const unsigned char *s, const char *sub) | |||
99 | /* | 100 | /* |
100 | * Set multimedia files as cold files for hot/cold data separation | 101 | * Set multimedia files as cold files for hot/cold data separation |
101 | */ | 102 | */ |
102 | static inline void set_cold_file(struct f2fs_sb_info *sbi, struct inode *inode, | 103 | static inline void set_cold_files(struct f2fs_sb_info *sbi, struct inode *inode, |
103 | const unsigned char *name) | 104 | const unsigned char *name) |
104 | { | 105 | { |
105 | int i; | 106 | int i; |
@@ -108,7 +109,7 @@ static inline void set_cold_file(struct f2fs_sb_info *sbi, struct inode *inode, | |||
108 | int count = le32_to_cpu(sbi->raw_super->extension_count); | 109 | int count = le32_to_cpu(sbi->raw_super->extension_count); |
109 | for (i = 0; i < count; i++) { | 110 | for (i = 0; i < count; i++) { |
110 | if (!is_multimedia_file(name, extlist[i])) { | 111 | if (!is_multimedia_file(name, extlist[i])) { |
111 | F2FS_I(inode)->i_advise |= FADVISE_COLD_BIT; | 112 | set_cold_file(inode); |
112 | break; | 113 | break; |
113 | } | 114 | } |
114 | } | 115 | } |
@@ -130,7 +131,7 @@ static int f2fs_create(struct inode *dir, struct dentry *dentry, umode_t mode, | |||
130 | return PTR_ERR(inode); | 131 | return PTR_ERR(inode); |
131 | 132 | ||
132 | if (!test_opt(sbi, DISABLE_EXT_IDENTIFY)) | 133 | if (!test_opt(sbi, DISABLE_EXT_IDENTIFY)) |
133 | set_cold_file(sbi, inode, dentry->d_name.name); | 134 | set_cold_files(sbi, inode, dentry->d_name.name); |
134 | 135 | ||
135 | inode->i_op = &f2fs_file_inode_operations; | 136 | inode->i_op = &f2fs_file_inode_operations; |
136 | inode->i_fop = &f2fs_file_operations; | 137 | inode->i_fop = &f2fs_file_operations; |
@@ -173,6 +174,12 @@ static int f2fs_link(struct dentry *old_dentry, struct inode *dir, | |||
173 | if (err) | 174 | if (err) |
174 | goto out; | 175 | goto out; |
175 | 176 | ||
177 | /* | ||
178 | * This file should be checkpointed during fsync. | ||
179 | * We lost i_pino from now on. | ||
180 | */ | ||
181 | set_cp_file(inode); | ||
182 | |||
176 | d_instantiate(dentry, inode); | 183 | d_instantiate(dentry, inode); |
177 | return 0; | 184 | return 0; |
178 | out: | 185 | out: |
@@ -425,7 +432,6 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
425 | } | 432 | } |
426 | 433 | ||
427 | old_inode->i_ctime = CURRENT_TIME; | 434 | old_inode->i_ctime = CURRENT_TIME; |
428 | set_inode_flag(F2FS_I(old_inode), FI_NEED_CP); | ||
429 | mark_inode_dirty(old_inode); | 435 | mark_inode_dirty(old_inode); |
430 | 436 | ||
431 | f2fs_delete_entry(old_entry, old_page, NULL); | 437 | f2fs_delete_entry(old_entry, old_page, NULL); |
diff --git a/fs/f2fs/node.h b/fs/f2fs/node.h index afdb130f782e..d009cdfd2679 100644 --- a/fs/f2fs/node.h +++ b/fs/f2fs/node.h | |||
@@ -277,6 +277,21 @@ static inline int is_cold_file(struct inode *inode) | |||
277 | return F2FS_I(inode)->i_advise & FADVISE_COLD_BIT; | 277 | return F2FS_I(inode)->i_advise & FADVISE_COLD_BIT; |
278 | } | 278 | } |
279 | 279 | ||
280 | static inline void set_cold_file(struct inode *inode) | ||
281 | { | ||
282 | F2FS_I(inode)->i_advise |= FADVISE_COLD_BIT; | ||
283 | } | ||
284 | |||
285 | static inline int is_cp_file(struct inode *inode) | ||
286 | { | ||
287 | return F2FS_I(inode)->i_advise & FADVISE_CP_BIT; | ||
288 | } | ||
289 | |||
290 | static inline void set_cp_file(struct inode *inode) | ||
291 | { | ||
292 | F2FS_I(inode)->i_advise |= FADVISE_CP_BIT; | ||
293 | } | ||
294 | |||
280 | static inline int is_cold_data(struct page *page) | 295 | static inline int is_cold_data(struct page *page) |
281 | { | 296 | { |
282 | return PageChecked(page); | 297 | return PageChecked(page); |