diff mbox series

ubifs: Fix wrong orphan node deletion in ubifs_jnl_update()

Message ID 20200702152048.1819867-1-chengzhihao1@huawei.com
State Changes Requested
Headers show
Series ubifs: Fix wrong orphan node deletion in ubifs_jnl_update() | expand

Commit Message

Zhihao Cheng July 2, 2020, 3:20 p.m. UTC
There a wrong orphan node deleting in error handling path in
ubifs_jnl_update(), 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 <chengzhihao1@huawei.com>
---
 fs/ubifs/journal.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Richard Weinberger July 7, 2020, 11:52 a.m. UTC | #1
On Thu, Jul 2, 2020 at 5:21 PM Zhihao Cheng <chengzhihao1@huawei.com> wrote:
>
> There a wrong orphan node deleting in error handling path in
> ubifs_jnl_update(), 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 <chengzhihao1@huawei.com>
> ---
>  fs/ubifs/journal.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/fs/ubifs/journal.c b/fs/ubifs/journal.c
> index e5ec1afe1c66..db0a80dd9d52 100644
> --- a/fs/ubifs/journal.c
> +++ b/fs/ubifs/journal.c
> @@ -539,7 +539,7 @@ int ubifs_jnl_update(struct ubifs_info *c, const struct inode *dir,
>                      const struct fscrypt_name *nm, const struct inode *inode,
>                      int deletion, int xent)
>  {
> -       int err, dlen, ilen, len, lnum, ino_offs, dent_offs;
> +       int err, dlen, ilen, len, lnum, ino_offs, dent_offs, orphan_added = 0;
>         int aligned_dlen, aligned_ilen, sync = IS_DIRSYNC(dir);
>         int last_reference = !!(deletion && inode->i_nlink == 0);
>         struct ubifs_inode *ui = ubifs_inode(inode);
> @@ -630,6 +630,7 @@ int ubifs_jnl_update(struct ubifs_info *c, const struct inode *dir,
>                         goto out_finish;
>                 }
>                 ui->del_cmtno = c->cmt_no;
> +               orphan_added = 1;
>         }
>
>         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,
>         kfree(dent);
>  out_ro:
>         ubifs_ro_mode(c, err);
> -       if (last_reference)
> +       if (last_reference && orphan_added)

I think you can just check for orphan_added here.
Looks good otherwise, thanks for fixing! :-)
Zhihao Cheng July 7, 2020, 11:57 a.m. UTC | #2
在 2020/7/7 19:52, Richard Weinberger 写道:
> On Thu, Jul 2, 2020 at 5:21 PM Zhihao Cheng <chengzhihao1@huawei.com> wrote:
>> There a wrong orphan node deleting in error handling path in
>> ubifs_jnl_update(), 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 <chengzhihao1@huawei.com>
>> ---
>>   fs/ubifs/journal.c | 5 +++--
>>   1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git a/fs/ubifs/journal.c b/fs/ubifs/journal.c
>> index e5ec1afe1c66..db0a80dd9d52 100644
>> --- a/fs/ubifs/journal.c
>> +++ b/fs/ubifs/journal.c
>> @@ -539,7 +539,7 @@ int ubifs_jnl_update(struct ubifs_info *c, const struct inode *dir,
>>                       const struct fscrypt_name *nm, const struct inode *inode,
>>                       int deletion, int xent)
>>   {
>> -       int err, dlen, ilen, len, lnum, ino_offs, dent_offs;
>> +       int err, dlen, ilen, len, lnum, ino_offs, dent_offs, orphan_added = 0;
>>          int aligned_dlen, aligned_ilen, sync = IS_DIRSYNC(dir);
>>          int last_reference = !!(deletion && inode->i_nlink == 0);
>>          struct ubifs_inode *ui = ubifs_inode(inode);
>> @@ -630,6 +630,7 @@ int ubifs_jnl_update(struct ubifs_info *c, const struct inode *dir,
>>                          goto out_finish;
>>                  }
>>                  ui->del_cmtno = c->cmt_no;
>> +               orphan_added = 1;
>>          }
>>
>>          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,
>>          kfree(dent);
>>   out_ro:
>>          ubifs_ro_mode(c, err);
>> -       if (last_reference)
>> +       if (last_reference && orphan_added)
> I think you can just check for orphan_added here.
> Looks good otherwise, thanks for fixing! :-)
Sounds reasonable. I will send v2.
diff mbox series

Patch

diff --git a/fs/ubifs/journal.c b/fs/ubifs/journal.c
index e5ec1afe1c66..db0a80dd9d52 100644
--- a/fs/ubifs/journal.c
+++ b/fs/ubifs/journal.c
@@ -539,7 +539,7 @@  int ubifs_jnl_update(struct ubifs_info *c, const struct inode *dir,
 		     const struct fscrypt_name *nm, const struct inode *inode,
 		     int deletion, int xent)
 {
-	int err, dlen, ilen, len, lnum, ino_offs, dent_offs;
+	int err, dlen, ilen, len, lnum, ino_offs, dent_offs, orphan_added = 0;
 	int aligned_dlen, aligned_ilen, sync = IS_DIRSYNC(dir);
 	int last_reference = !!(deletion && inode->i_nlink == 0);
 	struct ubifs_inode *ui = ubifs_inode(inode);
@@ -630,6 +630,7 @@  int ubifs_jnl_update(struct ubifs_info *c, const struct inode *dir,
 			goto out_finish;
 		}
 		ui->del_cmtno = c->cmt_no;
+		orphan_added = 1;
 	}
 
 	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,
 	kfree(dent);
 out_ro:
 	ubifs_ro_mode(c, err);
-	if (last_reference)
+	if (last_reference && orphan_added)
 		ubifs_delete_orphan(c, inode->i_ino);
 	finish_reservation(c);
 	return err;