From patchwork Thu Sep 25 20:46:55 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 4977471 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C6DD3BEEA6 for ; Thu, 25 Sep 2014 20:47:04 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B495420279 for ; Thu, 25 Sep 2014 20:47:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D6A59201F2 for ; Thu, 25 Sep 2014 20:47:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751594AbaIYUq6 (ORCPT ); Thu, 25 Sep 2014 16:46:58 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:14131 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751474AbaIYUq6 (ORCPT ); Thu, 25 Sep 2014 16:46:58 -0400 Received: from pps.filterd (m0044010 [127.0.0.1]) by mx0a-00082601.pphosted.com (8.14.5/8.14.5) with SMTP id s8PKjPcp032124 for ; Thu, 25 Sep 2014 13:46:57 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fb.com; h=from : to : subject : date : message-id : mime-version : content-type; s=facebook; bh=dvNPkeBN5bt9IfxRJLikU9RfXevlCYHbnAWEjFL2nhE=; b=nvQsB7FGCFwhNmWp07EQvo1MivqmlPCvG7PNsXXs1eVR2EEUjXc7mnrVZw/kPmMwoY2+ 0YwiwtWGV3gaq9ceA+d3zKNWrmvVqkKFVstTgguDiIpSZESurQALJQtGFKN+MSze3k7J FTzZjL8TDySzv1XyneeQrfXV38+SJF0yFDo= Received: from mail.thefacebook.com (mailwest.thefacebook.com [173.252.71.148]) by mx0a-00082601.pphosted.com with ESMTP id 1pkytgtpc6-1 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=OK) for ; Thu, 25 Sep 2014 13:46:57 -0700 Received: from localhost (192.168.16.4) by mail.thefacebook.com (192.168.16.21) with Microsoft SMTP Server (TLS) id 14.3.195.1; Thu, 25 Sep 2014 13:46:55 -0700 From: Josef Bacik To: Subject: [PATCH] Btrfs-progs: let btrfs-image actually work on a balanced fs Date: Thu, 25 Sep 2014 16:46:55 -0400 Message-ID: <1411678015-5928-1-git-send-email-jbacik@fb.com> X-Mailer: git-send-email 1.9.3 MIME-Version: 1.0 X-Originating-IP: [192.168.16.4] X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.12.52, 1.0.28, 0.0.0000 definitions=2014-09-25_08:2014-09-25, 2014-09-25, 1970-01-01 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 spamscore=0 suspectscore=1 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=7.0.1-1402240000 definitions=main-1409250214 X-FB-Internal: deliver Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,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 We use the read extent buffer infrastructure to read the super block when we are creating a btrfs-image. This works out fine most of the time except when the fs has been balanced, then it fails to map the super block. So we could fix btrfs-image to read in the super in a special way, but thats more code. So instead just check in the eb reading code if we are reading the super and then don't bother mapping the block, just read the actual offset. This fixed some poor guy who was trying to btrfs-image his fs that had been balanced. Thanks, Signed-off-by: Josef Bacik --- btrfs-image.c | 5 ++++- disk-io.c | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/btrfs-image.c b/btrfs-image.c index cb17f16..6643ad1 100644 --- a/btrfs-image.c +++ b/btrfs-image.c @@ -1020,6 +1020,9 @@ static int copy_tree_blocks(struct btrfs_root *root, struct extent_buffer *eb, int i = 0; int ret; + if (btrfs_header_bytenr(eb) == 65536) + printf("We have bytenr 65536, belongs to %llu, level %d\n", + btrfs_header_owner(eb), btrfs_header_level(eb)); ret = add_extent(btrfs_header_bytenr(eb), root->leafsize, metadump, 0); if (ret) { fprintf(stderr, "Error adding metadata block\n"); @@ -1279,7 +1282,7 @@ static int create_metadump(const char *input, FILE *out, int num_threads, } ret = add_extent(BTRFS_SUPER_INFO_OFFSET, BTRFS_SUPER_INFO_SIZE, - &metadump, 0); + &metadump, 1); if (ret) { fprintf(stderr, "Error adding metadata %d\n", ret); err = ret; diff --git a/disk-io.c b/disk-io.c index 26a532e..34c0a97 100644 --- a/disk-io.c +++ b/disk-io.c @@ -201,7 +201,8 @@ int read_whole_eb(struct btrfs_fs_info *info, struct extent_buffer *eb, int mirr read_len = bytes_left; device = NULL; - if (!info->on_restoring) { + if (!info->on_restoring && + eb->start != BTRFS_SUPER_INFO_OFFSET) { ret = btrfs_map_block(&info->mapping_tree, READ, eb->start + offset, &read_len, &multi, mirror, NULL);