Skip to content

Commit 094b6d1

Browse files
Zhihao Chengrichardweinberger
authored andcommitted
ubifs: Fix wrong orphan node deletion in ubifs_jnl_update|rename
There a wrong orphan node deleting in error handling path in ubifs_jnl_update() and ubifs_jnl_rename(), which may cause following error msg: UBIFS error (ubi0:0 pid 1522): ubifs_delete_orphan [ubifs]: missing orphan ino 65 Fix this by checking whether the node has been operated for adding to orphan list before being deleted, Signed-off-by: Zhihao Cheng <[email protected]> Fixes: 823838a ("ubifs: Add hashes to the tree node cache") Signed-off-by: Richard Weinberger <[email protected]>
1 parent c3fc1a3 commit 094b6d1

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

fs/ubifs/journal.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ int ubifs_jnl_update(struct ubifs_info *c, const struct inode *dir,
539539
const struct fscrypt_name *nm, const struct inode *inode,
540540
int deletion, int xent)
541541
{
542-
int err, dlen, ilen, len, lnum, ino_offs, dent_offs;
542+
int err, dlen, ilen, len, lnum, ino_offs, dent_offs, orphan_added = 0;
543543
int aligned_dlen, aligned_ilen, sync = IS_DIRSYNC(dir);
544544
int last_reference = !!(deletion && inode->i_nlink == 0);
545545
struct ubifs_inode *ui = ubifs_inode(inode);
@@ -630,6 +630,7 @@ int ubifs_jnl_update(struct ubifs_info *c, const struct inode *dir,
630630
goto out_finish;
631631
}
632632
ui->del_cmtno = c->cmt_no;
633+
orphan_added = 1;
633634
}
634635

635636
err = write_head(c, BASEHD, dent, len, &lnum, &dent_offs, sync);
@@ -702,7 +703,7 @@ int ubifs_jnl_update(struct ubifs_info *c, const struct inode *dir,
702703
kfree(dent);
703704
out_ro:
704705
ubifs_ro_mode(c, err);
705-
if (last_reference)
706+
if (orphan_added)
706707
ubifs_delete_orphan(c, inode->i_ino);
707708
finish_reservation(c);
708709
return err;
@@ -1218,7 +1219,7 @@ int ubifs_jnl_rename(struct ubifs_info *c, const struct inode *old_dir,
12181219
void *p;
12191220
union ubifs_key key;
12201221
struct ubifs_dent_node *dent, *dent2;
1221-
int err, dlen1, dlen2, ilen, lnum, offs, len;
1222+
int err, dlen1, dlen2, ilen, lnum, offs, len, orphan_added = 0;
12221223
int aligned_dlen1, aligned_dlen2, plen = UBIFS_INO_NODE_SZ;
12231224
int last_reference = !!(new_inode && new_inode->i_nlink == 0);
12241225
int move = (old_dir != new_dir);
@@ -1334,6 +1335,7 @@ int ubifs_jnl_rename(struct ubifs_info *c, const struct inode *old_dir,
13341335
goto out_finish;
13351336
}
13361337
new_ui->del_cmtno = c->cmt_no;
1338+
orphan_added = 1;
13371339
}
13381340

13391341
err = write_head(c, BASEHD, dent, len, &lnum, &offs, sync);
@@ -1415,7 +1417,7 @@ int ubifs_jnl_rename(struct ubifs_info *c, const struct inode *old_dir,
14151417
release_head(c, BASEHD);
14161418
out_ro:
14171419
ubifs_ro_mode(c, err);
1418-
if (last_reference)
1420+
if (orphan_added)
14191421
ubifs_delete_orphan(c, new_inode->i_ino);
14201422
out_finish:
14211423
finish_reservation(c);

0 commit comments

Comments
 (0)