From patchwork Tue Mar 12 17:38:09 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 2257561 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 7E867DF23A for ; Tue, 12 Mar 2013 17:31:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933128Ab3CLRbK (ORCPT ); Tue, 12 Mar 2013 13:31:10 -0400 Received: from dkim1.fusionio.com ([66.114.96.53]:50752 "EHLO dkim1.fusionio.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933112Ab3CLRbJ (ORCPT ); Tue, 12 Mar 2013 13:31:09 -0400 Received: from mx2.fusionio.com (unknown [10.101.1.160]) by dkim1.fusionio.com (Postfix) with ESMTP id 16D347C04E9 for ; Tue, 12 Mar 2013 11:31:09 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fusionio.com; s=default; t=1363109469; bh=KQ13MRpSNiju+VEBjxem1s3gQbDus1WdVK6owHI1Lt0=; h=From:To:Subject:Date:In-Reply-To:References; b=bMq2X/7GxsUySzg2y3zSuDP1Hb11B9v8zncKE6KyaWbppihiKC1IaiU3RnxGw0CEz Qyv/H9gh5pY+f2Q5J7qY83QVh1Yn/SSf/hwfEaHj/NZNujl8yAas/hkDThFdR0xrpN 1WlOGQzboQTjgkvvOU5qGOnxzQBaExxLiAILE1FU= X-ASG-Debug-ID: 1363109468-0421b5685a0f490001-6jHSXT Received: from mail1.int.fusionio.com (mail1.int.fusionio.com [10.101.1.21]) by mx2.fusionio.com with ESMTP id GIQiezE57tPNMXux (version=TLSv1 cipher=AES128-SHA bits=128 verify=NO) for ; Tue, 12 Mar 2013 11:31:08 -0600 (MDT) X-Barracuda-Envelope-From: JBacik@fusionio.com Received: from localhost (98.26.82.158) by mail.fusionio.com (10.101.1.19) with Microsoft SMTP Server (TLS) id 8.3.83.0; Tue, 12 Mar 2013 11:31:07 -0600 From: Josef Bacik To: Subject: [PATCH 02/10] Btrfs-progs: try other mirrors if decomression fails Date: Tue, 12 Mar 2013 13:38:09 -0400 X-ASG-Orig-Subj: [PATCH 02/10] Btrfs-progs: try other mirrors if decomression fails Message-ID: <1363109897-7931-3-git-send-email-jbacik@fusionio.com> X-Mailer: git-send-email 1.7.7.6 In-Reply-To: <1363109897-7931-1-git-send-email-jbacik@fusionio.com> References: <1363109897-7931-1-git-send-email-jbacik@fusionio.com> MIME-Version: 1.0 X-Barracuda-Connect: mail1.int.fusionio.com[10.101.1.21] X-Barracuda-Start-Time: 1363109468 X-Barracuda-Encrypted: AES128-SHA X-Barracuda-URL: http://10.101.1.181:8000/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at fusionio.com X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=9.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.2.125008 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Josef Bacik This will make the restore program fall back on other mirrors if it fails to decompress an extent for whatever reason. Thanks, Signed-off-by: Josef Bacik --- cmds-restore.c | 46 +++++++++++++++++++++++++--------------------- 1 files changed, 25 insertions(+), 21 deletions(-) diff --git a/cmds-restore.c b/cmds-restore.c index 467e5ef..1d24691 100644 --- a/cmds-restore.c +++ b/cmds-restore.c @@ -65,7 +65,7 @@ static int decompress(char *inbuf, char *outbuf, u64 compress_len, ret = inflate(&strm, Z_NO_FLUSH); if (ret != Z_STREAM_END) { (void)inflateEnd(&strm); - fprintf(stderr, "ret is %d\n", ret); + fprintf(stderr, "failed to inflate: %d\n", ret); return -1; } @@ -198,6 +198,8 @@ static int copy_one_extent(struct btrfs_root *root, int fd, int compress; int ret; int dev_fd; + int mirror_num = 0; + int num_copies; compress = btrfs_file_extent_compression(leaf, fi); bytenr = btrfs_file_extent_disk_bytenr(leaf, fi); @@ -226,12 +228,10 @@ static int copy_one_extent(struct btrfs_root *root, int fd, again: length = size_left; ret = btrfs_map_block(&root->fs_info->mapping_tree, READ, - bytenr, &length, &multi, 0, NULL); + bytenr, &length, &multi, mirror_num, NULL); if (ret) { - free(inbuf); - free(outbuf); fprintf(stderr, "Error mapping block %d\n", ret); - return ret; + goto out; } device = multi->stripes[0].dev; dev_fd = device->fd; @@ -245,10 +245,9 @@ again: done = pread(dev_fd, inbuf+count, length, dev_bytenr); if (done < length) { - free(inbuf); - free(outbuf); + ret = -1; fprintf(stderr, "Short read %d\n", errno); - return -1; + goto out; } count += length; @@ -256,41 +255,46 @@ again: if (size_left) goto again; - if (compress == BTRFS_COMPRESS_NONE) { while (total < ram_size) { done = pwrite(fd, inbuf+total, ram_size-total, pos+total); if (done < 0) { - free(inbuf); + ret = -1; fprintf(stderr, "Error writing: %d %s\n", errno, strerror(errno)); - return -1; + goto out; } total += done; } - free(inbuf); - return 0; + ret = 0; + goto out; } ret = decompress(inbuf, outbuf, disk_size, ram_size); - free(inbuf); if (ret) { - free(outbuf); - return ret; + num_copies = btrfs_num_copies(&root->fs_info->mapping_tree, + bytenr, length); + mirror_num++; + if (mirror_num >= num_copies) { + ret = -1; + goto out; + } + fprintf(stderr, "Trying another mirror\n"); + goto again; } while (total < ram_size) { done = pwrite(fd, outbuf+total, ram_size-total, pos+total); if (done < 0) { - free(outbuf); - fprintf(stderr, "Error writing: %d %s\n", errno, strerror(errno)); - return -1; + ret = -1; + goto out; } total += done; } +out: + free(inbuf); free(outbuf); - - return 0; + return ret; } static int ask_to_continue(const char *file)