Skip to content

Commit 28f4821

Browse files
josephhzakpm00
authored andcommitted
ocfs2: clear dinode links count in case of error
In ocfs2_mknod(), if error occurs after dinode successfully allocated, ocfs2 i_links_count will not be 0. So even though we clear inode i_nlink before iput in error handling, it still won't wipe inode since we'll refresh inode from dinode during inode lock. So just like clear inode i_nlink, we clear ocfs2 i_links_count as well. Also do the same change for ocfs2_symlink(). Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Joseph Qi <[email protected]> Reported-by: Yan Wang <[email protected]> Cc: Mark Fasheh <[email protected]> Cc: Joel Becker <[email protected]> Cc: Junxiao Bi <[email protected]> Cc: Changwei Ge <[email protected]> Cc: Gang He <[email protected]> Cc: Jun Piao <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 759a7c6 commit 28f4821

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

fs/ocfs2/namei.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ static int ocfs2_mknod(struct user_namespace *mnt_userns,
232232
handle_t *handle = NULL;
233233
struct ocfs2_super *osb;
234234
struct ocfs2_dinode *dirfe;
235+
struct ocfs2_dinode *fe = NULL;
235236
struct buffer_head *new_fe_bh = NULL;
236237
struct inode *inode = NULL;
237238
struct ocfs2_alloc_context *inode_ac = NULL;
@@ -382,6 +383,7 @@ static int ocfs2_mknod(struct user_namespace *mnt_userns,
382383
goto leave;
383384
}
384385

386+
fe = (struct ocfs2_dinode *) new_fe_bh->b_data;
385387
if (S_ISDIR(mode)) {
386388
status = ocfs2_fill_new_dir(osb, handle, dir, inode,
387389
new_fe_bh, data_ac, meta_ac);
@@ -454,8 +456,11 @@ static int ocfs2_mknod(struct user_namespace *mnt_userns,
454456
leave:
455457
if (status < 0 && did_quota_inode)
456458
dquot_free_inode(inode);
457-
if (handle)
459+
if (handle) {
460+
if (status < 0 && fe)
461+
ocfs2_set_links_count(fe, 0);
458462
ocfs2_commit_trans(osb, handle);
463+
}
459464

460465
ocfs2_inode_unlock(dir, 1);
461466
if (did_block_signals)
@@ -2019,8 +2024,11 @@ static int ocfs2_symlink(struct user_namespace *mnt_userns,
20192024
ocfs2_clusters_to_bytes(osb->sb, 1));
20202025
if (status < 0 && did_quota_inode)
20212026
dquot_free_inode(inode);
2022-
if (handle)
2027+
if (handle) {
2028+
if (status < 0 && fe)
2029+
ocfs2_set_links_count(fe, 0);
20232030
ocfs2_commit_trans(osb, handle);
2031+
}
20242032

20252033
ocfs2_inode_unlock(dir, 1);
20262034
if (did_block_signals)

0 commit comments

Comments
 (0)