Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: Naohiro Aota <naota@elisp.net>, linux-btrfs@vger.kernel.org
Cc: quwenruo@cn.fujitsu.com
Subject: Re: [PATCH 2/3] btrfs-progs: properly reset nlink of multi-linked file
Date: Sat, 5 Dec 2015 09:34:19 +0800	[thread overview]
Message-ID: <56623F1B.9010106@gmx.com> (raw)
In-Reply-To: <1449207447-1203-3-git-send-email-naota@elisp.net>



On 12/04/2015 01:37 PM, Naohiro Aota wrote:
> If a file is linked from more than one directory and only one
> of the links is corrupted, btrfs check dose not reset the nlink
> properly. Actually it can go into infinite loop to link the broken file
> into lost+found.
>
> This patch fix two part of the code. The first one delay the freeing
> valid (no error, found inode ref, directory index, and directory
> item) backrefs. Freeing valid backrefs earier prevent reset_nlink() to
> add back all valid links.
>
> The second fix is obvious: passing `ref_type' to btrfs_add_link() is just
> wrong. It should be `filetype' instead. The current code can break all valid
> file links.
>
> Signed-off-by: Naohiro Aota <naota@elisp.net>

Thanks for the fix, that's truly my fault.
The fix looks good.

Reviewed-by: Qu Wenruo <quwenruo@cn.fujitsu.com>

Thanks,
Qu

> ---
>   cmds-check.c | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/cmds-check.c b/cmds-check.c
> index 6a0b50a..11ff3fe 100644
> --- a/cmds-check.c
> +++ b/cmds-check.c
> @@ -810,7 +810,8 @@ static void maybe_free_inode_rec(struct cache_tree *inode_cache,
>   		if (backref->found_dir_item && backref->found_dir_index) {
>   			if (backref->filetype != filetype)
>   				backref->errors |= REF_ERR_FILETYPE_UNMATCH;
> -			if (!backref->errors && backref->found_inode_ref) {
> +			if (!backref->errors && backref->found_inode_ref &&
> +			    rec->nlink == rec->found_link) {
>   				list_del(&backref->list);
>   				free(backref);
>   			}
> @@ -2392,7 +2393,7 @@ static int reset_nlink(struct btrfs_trans_handle *trans,
>   	list_for_each_entry(backref, &rec->backrefs, list) {
>   		ret = btrfs_add_link(trans, root, rec->ino, backref->dir,
>   				     backref->name, backref->namelen,
> -				     backref->ref_type, &backref->index, 1);
> +				     backref->filetype, &backref->index, 1);
>   		if (ret < 0)
>   			goto out;
>   	}
>

  reply	other threads:[~2015-12-05  1:35 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-04  5:37 [PATCH 0/3] btrfs-progs: fix file restore to lost+found bug Naohiro Aota
2015-12-04  5:37 ` [PATCH 1/3] btrfs-progs: test: umount if confirmation failed Naohiro Aota
2015-12-07 15:33   ` David Sterba
2015-12-08  2:18     ` Naohiro Aota
2015-12-04  5:37 ` [PATCH 2/3] btrfs-progs: properly reset nlink of multi-linked file Naohiro Aota
2015-12-05  1:34   ` Qu Wenruo [this message]
2015-12-07 15:37   ` David Sterba
2015-12-05  1:35 ` [PATCH 0/3] btrfs-progs: fix file restore to lost+found bug Qu Wenruo
2015-12-07  2:59   ` Naohiro Aota
2015-12-07  3:02     ` Qu Wenruo
2015-12-07 15:35     ` David Sterba
2015-12-08  2:06       ` Naohiro Aota
2015-12-15 10:13         ` David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=56623F1B.9010106@gmx.com \
    --to=quwenruo.btrfs@gmx.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=naota@elisp.net \
    --cc=quwenruo@cn.fujitsu.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox