All of lore.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo@cn.fujitsu.com>
To: <mwilck@arcor.de>, <linux-btrfs@vger.kernel.org>
Subject: Re: [PATCH 09/18] btrfs restore: more graceful error handling in copy_file
Date: Thu, 11 Dec 2014 16:37:52 +0800	[thread overview]
Message-ID: <548957E0.3010708@cn.fujitsu.com> (raw)
In-Reply-To: <1418244708-7087-10-git-send-email-mwilck@arcor.de>


-------- Original Message --------
Subject: [PATCH 09/18] btrfs restore: more graceful error handling in 
copy_file
From: <mwilck@arcor.de>
To: <linux-btrfs@vger.kernel.org>
Date: 2014年12月11日 04:51
> From: Martin Wilck <mwilck@arcor.de>
>
> Setting size and attributes of a file makes sense even if some
> errors have occured during revovery.
>
> Also, do something useful with the number of bytes written.
>
> Signed-off-by: Martin Wilck <mwilck@arcor.de>
> ---
>   cmds-restore.c |   27 ++++++++++++++-------------
>   1 files changed, 14 insertions(+), 13 deletions(-)
>
> diff --git a/cmds-restore.c b/cmds-restore.c
> index 8ecd896..10bb8be 100644
> --- a/cmds-restore.c
> +++ b/cmds-restore.c
> @@ -715,7 +715,7 @@ static int copy_file(struct btrfs_root *root, int fd, struct btrfs_key *key,
>   					return ret;
>   				} else if (ret) {
>   					/* No more leaves to search */
> -					btrfs_free_path(path);
> +					ret = 0;
>   					goto set_size;
>   				}
>   				leaf = path->nodes[0];
> @@ -734,35 +734,36 @@ static int copy_file(struct btrfs_root *root, int fd, struct btrfs_key *key,
>   		if (compression >= BTRFS_COMPRESS_LAST) {
>   			fprintf(stderr, "Don't support compression yet %d\n",
>   				compression);
> -			btrfs_free_path(path);
> -			return -1;
> +			ret = -1;
Although the original one uses -1, IMHO it would be more meaningful 
using -ENOTTY.
If someone later adds stderr() for the ret and print it, the author will 
be graceful.
> +			goto set_size;
>   		}
>   
> +		bytes_written = 0ULL;
>   		if (extent_type == BTRFS_FILE_EXTENT_PREALLOC)
>   			goto next;
>   		if (extent_type == BTRFS_FILE_EXTENT_INLINE) {
>   			ret = copy_one_inline(fd, path, found_key.offset,
>   					      &bytes_written);
> -			if (ret) {
> -				btrfs_free_path(path);
> -				return -1;
> -			}
>   		} else if (extent_type == BTRFS_FILE_EXTENT_REG) {
>   			ret = copy_one_extent(root, fd, leaf, fi,
>   					      found_key.offset, &bytes_written);
> -			if (ret) {
> -				btrfs_free_path(path);
> -				return ret;
> -			}
>   		} else {
>   			printf("Weird extent type %d\n", extent_type);
>   		}
> +		total_written += bytes_written;
> +		next_pos = found_key.offset + bytes_written;
> +		if (ret) {
> +			fprintf(stderr, "ERROR after writing %llu bytes\n",
> +				total_written);
Just a advice, what about add stderr(-ret) for the info?
> +			ret = -1;
Why change ret to -1? At least some of the ret above can be meaningful 
like -EIO or -ENOENT.
> +			goto set_size;
> +		}
>   next:
>   		path->slots[0]++;
>   	}
>   
> -	btrfs_free_path(path);
>   set_size:
> +	btrfs_free_path(path);
>   	if (get_xattrs) {
>   		ret = set_file_xattrs(root, key->objectid, fd, file);
>   		if (ret)
> @@ -771,7 +772,7 @@ set_size:
>   	}
>   
>   	set_fd_attrs(fd, &st, file);
> -	return 0;
> +	return ret;
>   }
>   
>   static int search_dir(struct btrfs_root *root, struct btrfs_key *key,
Other part looks good for me.

Thanks,
Qu

  reply	other threads:[~2014-12-11  8:37 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-10 20:51 [PATCH 00/18] Patch series related to my btrfs recovery mwilck
2014-12-10 20:51 ` [PATCH 01/18] btrfs-progs: btrfs-debug-tree: add option -f for "block only" mwilck
2014-12-11  7:42   ` Qu Wenruo
2014-12-10 20:51 ` [PATCH 02/18] btrfs-progs: btrfs-debug-tree: add option -B (backup root) mwilck
2014-12-10 20:51 ` [PATCH 03/18] btrfs-progs: btrfs-debug-tree: fix usage message mwilck
2014-12-10 20:51 ` [PATCH 04/18] btrfs-progs: btrfs-debug-tree: handle corruption more gracefully mwilck
2014-12-10 20:51 ` [PATCH 05/18] btrfs-progs: ctree.h: fix btrfs_inode_[amc]time mwilck
2014-12-11  7:59   ` Qu Wenruo
2014-12-11  8:16     ` Qu Wenruo
2014-12-10 20:51 ` [PATCH 06/18] btrfs restore: set uid/gid/mode/times mwilck
2014-12-10 20:51 ` [PATCH 07/18] btrfs restore: better output readability mwilck
2014-12-10 20:51 ` [PATCH 08/18] btrfs restore: track number of bytes restored mwilck
2014-12-10 20:51 ` [PATCH 09/18] btrfs restore: more graceful error handling in copy_file mwilck
2014-12-11  8:37   ` Qu Wenruo [this message]
2014-12-10 20:51 ` [PATCH 10/18] btrfs restore: hide "offset is X" messages mwilck
2014-12-10 20:51 ` [PATCH 11/18] btrfs restore: print progress marks for big files mwilck
2014-12-10 20:51 ` [PATCH 12/18] btrfs restore: check progress of file restoration mwilck
2014-12-11  8:44   ` Qu Wenruo
2014-12-10 20:51 ` [PATCH 13/18] btrfs restore: improve user-asking logic for files with many extents mwilck
2014-12-10 20:51 ` [PATCH 14/18] btrfs restore: report mismatch in file size mwilck
2014-12-10 20:51 ` [PATCH 15/18] btrfs-progs: NEW: btrfs-raw mwilck
2014-12-10 20:51 ` [PATCH 16/18] btrfs-progs: NEW: brtfs-search-metadata mwilck
2014-12-10 20:51 ` [PATCH 17/18] btrfs-progs: ctree.c: make bin_search non-static mwilck
2014-12-10 20:51 ` [PATCH 18/18] btrfs-progs: documentation for btrfs-raw and btrfs-search-metadata mwilck

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=548957E0.3010708@cn.fujitsu.com \
    --to=quwenruo@cn.fujitsu.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=mwilck@arcor.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.