aboutsummaryrefslogtreecommitdiffstats
path: root/fs/f2fs/dir.c
diff options
context:
space:
mode:
authorJaegeuk Kim <jaegeuk.kim@samsung.com>2012-12-10 03:52:48 -0500
committerJaegeuk Kim <jaegeuk.kim@samsung.com>2012-12-10 23:43:45 -0500
commit6666e6aa9f36b2bfd6b30072c07b34f2a24becf1 (patch)
tree29a4b75710c8dc3e8df25617aae0b6e51359f1f3 /fs/f2fs/dir.c
parent3cd8a23948b29301f8f67b8d70c5c18fabbc05e1 (diff)
f2fs: fix tracking parent inode number
Previously, f2fs didn't track the parent inode number correctly which is stored in each f2fs_inode. In the case of the following scenario, a bug can be occured. Let's suppose there are one directory, "/b", and two files, "/a" and "/b/a". - pino of "/a" is ROOT_INO. - pino of "/b/a" is DIR_B_INO. Then, # sync : The inode pages of "/a" and "/b/a" contain the parent inode numbers as ROOT_INO and DIR_B_INO respectively. # mv /a /b/a : The parent inode number of "/a" should be changed to DIR_B_INO, but f2fs didn't do that. Ref. f2fs_set_link(). In order to fix this clearly, I added i_pino in f2fs_inode_info, and whenever it needs to be changed like in f2fs_add_link() and f2fs_set_link(), it is updated temporarily in f2fs_inode_info. And later, f2fs_write_inode() stores the latest information to the inode pages. For power-off-recovery, f2fs_sync_file() triggers simply f2fs_write_inode(). Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Diffstat (limited to 'fs/f2fs/dir.c')
-rw-r--r--fs/f2fs/dir.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c
index d900c088c7c6..b4e24f32b54e 100644
--- a/fs/f2fs/dir.c
+++ b/fs/f2fs/dir.c
@@ -256,13 +256,16 @@ void f2fs_set_link(struct inode *dir, struct f2fs_dir_entry *de,
256 set_page_dirty(page); 256 set_page_dirty(page);
257 dir->i_mtime = dir->i_ctime = CURRENT_TIME; 257 dir->i_mtime = dir->i_ctime = CURRENT_TIME;
258 mark_inode_dirty(dir); 258 mark_inode_dirty(dir);
259
260 /* update parent inode number before releasing dentry page */
261 F2FS_I(inode)->i_pino = dir->i_ino;
262
259 f2fs_put_page(page, 1); 263 f2fs_put_page(page, 1);
260 mutex_unlock_op(sbi, DENTRY_OPS); 264 mutex_unlock_op(sbi, DENTRY_OPS);
261} 265}
262 266
263void init_dent_inode(struct dentry *dentry, struct page *ipage) 267void init_dent_inode(struct dentry *dentry, struct page *ipage)
264{ 268{
265 struct inode *dir = dentry->d_parent->d_inode;
266 struct f2fs_node *rn; 269 struct f2fs_node *rn;
267 270
268 if (IS_ERR(ipage)) 271 if (IS_ERR(ipage))
@@ -272,7 +275,6 @@ void init_dent_inode(struct dentry *dentry, struct page *ipage)
272 275
273 /* copy dentry info. to this inode page */ 276 /* copy dentry info. to this inode page */
274 rn = (struct f2fs_node *)page_address(ipage); 277 rn = (struct f2fs_node *)page_address(ipage);
275 rn->i.i_pino = cpu_to_le32(dir->i_ino);
276 rn->i.i_namelen = cpu_to_le32(dentry->d_name.len); 278 rn->i.i_namelen = cpu_to_le32(dentry->d_name.len);
277 memcpy(rn->i.i_name, dentry->d_name.name, dentry->d_name.len); 279 memcpy(rn->i.i_name, dentry->d_name.name, dentry->d_name.len);
278 set_page_dirty(ipage); 280 set_page_dirty(ipage);
@@ -444,7 +446,11 @@ add_dentry:
444 for (i = 0; i < slots; i++) 446 for (i = 0; i < slots; i++)
445 test_and_set_bit_le(bit_pos + i, &dentry_blk->dentry_bitmap); 447 test_and_set_bit_le(bit_pos + i, &dentry_blk->dentry_bitmap);
446 set_page_dirty(dentry_page); 448 set_page_dirty(dentry_page);
449
447 update_parent_metadata(dir, inode, current_depth); 450 update_parent_metadata(dir, inode, current_depth);
451
452 /* update parent inode number before releasing dentry page */
453 F2FS_I(inode)->i_pino = dir->i_ino;
448fail: 454fail:
449 kunmap(dentry_page); 455 kunmap(dentry_page);
450 f2fs_put_page(dentry_page, 1); 456 f2fs_put_page(dentry_page, 1);