From patchwork Wed Dec 10 20:51:38 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: mwilck@arcor.de X-Patchwork-Id: 5472451 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 68A3E9F444 for ; Wed, 10 Dec 2014 21:05:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8E290201B4 for ; Wed, 10 Dec 2014 21:05:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9F8F42018E for ; Wed, 10 Dec 2014 21:05:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933339AbaLJVFq (ORCPT ); Wed, 10 Dec 2014 16:05:46 -0500 Received: from mail-in-03.arcor-online.net ([151.189.21.43]:41843 "EHLO mail-in-03.arcor-online.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933311AbaLJVFm (ORCPT ); Wed, 10 Dec 2014 16:05:42 -0500 Received: from mail-in-05-z2.arcor-online.net (mail-in-05-z2.arcor-online.net [151.189.8.17]) by mx.arcor.de (Postfix) with ESMTP id 4705AD7F4A for ; Wed, 10 Dec 2014 22:05:41 +0100 (CET) Received: from mail-in-10.arcor-online.net (mail-in-10.arcor-online.net [151.189.21.50]) by mail-in-05-z2.arcor-online.net (Postfix) with ESMTP id 4D0FC6F2F71; Wed, 10 Dec 2014 22:05:41 +0100 (CET) X-Greylist: Passed host: 188.96.131.100 X-DKIM: Sendmail DKIM Filter v2.8.2 mail-in-10.arcor-online.net 1BE212D62EC DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arcor.de; s=mail-in; t=1418245541; bh=nZr16fhawF8eo0StxKMlSUPIWg9JjmqsMgqRdIn728E=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=ajn0LeZ+j+UTsiri2qOBrfBDrEnaaAkYJnTBEc9ThAEtkWZg58nhX44jxtIcJuiXy JMfTx/L0i/AD9HXvSnANx6dYT0LOlc/L40vusyLUD0e9Qtr1JYmdWVCIZeI7FGK3B1 0sSjqLnxMF1QlBxAL7suM9iYp4wawqvVc6bMokEA= X-Greylist: Passed host: 188.96.131.100 Received: from localhost.localdomain (dslb-188-096-131-100.188.096.pools.vodafone-ip.de [188.96.131.100]) (Authenticated sender: mwilck@arcor.de) by mail-in-10.arcor-online.net (Postfix) with ESMTPSA id 1BE212D62EC; Wed, 10 Dec 2014 22:05:41 +0100 (CET) From: mwilck@arcor.de To: linux-btrfs@vger.kernel.org Cc: mwilck@arcor.de Subject: [PATCH 08/18] btrfs restore: track number of bytes restored Date: Wed, 10 Dec 2014 21:51:38 +0100 Message-Id: <1418244708-7087-9-git-send-email-mwilck@arcor.de> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: <1418244708-7087-1-git-send-email-mwilck@arcor.de> References: <1418244708-7087-1-git-send-email-mwilck@arcor.de> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, FREEMAIL_FROM,RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Martin Wilck Track the number of bytes read from extents and restored. This is useful for detecting errors and corruptions. Signed-off-by: Martin Wilck --- cmds-restore.c | 16 ++++++++++++---- 1 files changed, 12 insertions(+), 4 deletions(-) diff --git a/cmds-restore.c b/cmds-restore.c index f9dab7e..8ecd896 100644 --- a/cmds-restore.c +++ b/cmds-restore.c @@ -222,7 +222,8 @@ again: return 0; } -static int copy_one_inline(int fd, struct btrfs_path *path, u64 pos) +static int copy_one_inline(int fd, struct btrfs_path *path, u64 pos, + u64 *bytes_written) { struct extent_buffer *leaf = path->nodes[0]; struct btrfs_file_extent_item *fi; @@ -246,6 +247,7 @@ static int copy_one_inline(int fd, struct btrfs_path *path, u64 pos) compress = btrfs_file_extent_compression(leaf, fi); if (compress == BTRFS_COMPRESS_NONE) { done = pwrite(fd, buf, len, pos); + *bytes_written += done; if (done < len) { fprintf(stderr, "Short inline write, wanted %d, did " "%zd: %d\n", len, done, errno); @@ -269,6 +271,7 @@ static int copy_one_inline(int fd, struct btrfs_path *path, u64 pos) done = pwrite(fd, outbuf, ram_size, pos); free(outbuf); + *bytes_written += done; if (done < ram_size) { fprintf(stderr, "Short compressed inline write, wanted %Lu, " "did %zd: %d\n", ram_size, done, errno); @@ -280,7 +283,8 @@ static int copy_one_inline(int fd, struct btrfs_path *path, u64 pos) static int copy_one_extent(struct btrfs_root *root, int fd, struct extent_buffer *leaf, - struct btrfs_file_extent_item *fi, u64 pos) + struct btrfs_file_extent_item *fi, u64 pos, + u64 *bytes_written) { struct btrfs_multi_bio *multi = NULL; struct btrfs_device *device; @@ -410,6 +414,7 @@ again: total += done; } out: + *bytes_written += total; free(inbuf); free(outbuf); return ret; @@ -651,6 +656,8 @@ static int copy_file(struct btrfs_root *root, int fd, struct btrfs_key *key, int extent_type; int compression; int loops = 0; + u64 bytes_written, next_pos = 0ULL; + u64 total_written = 0ULL; struct stat st; path = btrfs_alloc_path(); @@ -734,14 +741,15 @@ static int copy_file(struct btrfs_root *root, int fd, struct btrfs_key *key, 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); + 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); + found_key.offset, &bytes_written); if (ret) { btrfs_free_path(path); return ret;