From patchwork Tue Feb 25 18:25:39 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 3718351 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 C4A9F9F2F7 for ; Tue, 25 Feb 2014 18:26:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BFFA82017E for ; Tue, 25 Feb 2014 18:26:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DFC5A201EF for ; Tue, 25 Feb 2014 18:26:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751747AbaBYSZz (ORCPT ); Tue, 25 Feb 2014 13:25:55 -0500 Received: from mail-we0-f171.google.com ([74.125.82.171]:36685 "EHLO mail-we0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753514AbaBYSZt (ORCPT ); Tue, 25 Feb 2014 13:25:49 -0500 Received: by mail-we0-f171.google.com with SMTP id u56so737508wes.2 for ; Tue, 25 Feb 2014 10:25:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=C9WujVEtOSoBgVrjXfLoaw1nvIZOxroU/M29ZPN0njw=; b=zKosaOnEjZ8tiqFXX91YehqaQ/BYvd1gUpFm4Kv8S4qTyFIQzlaPVkCHcne+2nSiQ5 SBb8ZJ1gtwULi/G+6sui26Z5b03Cop3RlRZYfEq1kVHW6C24h0ljSSx5OCEfpM3VbSn8 zJ4rKrIBiL+lHPG252503idlqoJVVnsIyP98PQzE+llaGVUmaj3i+awkdYuLawrtVTSq NagitXTsYfZfqs+rjFvrl1BI6Nsv6J8KxSSXTyzb/BQ2C/SpUAS9ID71CRtvhk5JZ+FE lb/mo1ap4GSMz8CjA5JiguU2Kvw0ICC97+zY4UM00rQkEuqyckP9f3BiRDl2h+80TMNe OaEg== X-Received: by 10.194.110.41 with SMTP id hx9mr26547477wjb.28.1393352748516; Tue, 25 Feb 2014 10:25:48 -0800 (PST) Received: from storm-desktop.lan (bl9-170-181.dsl.telepac.pt. [85.242.170.181]) by mx.google.com with ESMTPSA id 12sm52775206wjm.10.2014.02.25.10.25.47 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Feb 2014 10:25:47 -0800 (PST) From: Filipe David Borba Manana To: linux-btrfs@vger.kernel.org Cc: Filipe David Borba Manana Subject: [PATCH] Btrfs-progs: fix restore of files with compressed extents Date: Tue, 25 Feb 2014 18:25:39 +0000 Message-Id: <1393352739-25073-1-git-send-email-fdmanana@gmail.com> X-Mailer: git-send-email 1.7.9.5 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_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, 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 The code was incorrectly adding the file extent items' data offset to the logical disk address of the extent (bytenr) when the extent is compressed. The offset is relative to the uncompressed data and not to what we store on disk (compressed). Also it attempted to copy ram_bytes to destination, which is incorrect when the data offset field is non-zero, it must use num_bytes instead. A test case for xfstests follows. Signed-off-by: Filipe David Borba Manana --- cmds-restore.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cmds-restore.c b/cmds-restore.c index 1748262..e620ee7 100644 --- a/cmds-restore.c +++ b/cmds-restore.c @@ -297,7 +297,8 @@ static int copy_one_extent(struct btrfs_root *root, int fd, offset = btrfs_file_extent_offset(leaf, fi); num_bytes = btrfs_file_extent_num_bytes(leaf, fi); size_left = num_bytes; - bytenr += offset; + if (compress == BTRFS_COMPRESS_NONE) + bytenr += offset; if (offset) printf("offset is %Lu\n", offset); @@ -387,8 +388,10 @@ again: goto again; } - while (total < ram_size) { - done = pwrite(fd, outbuf+total, ram_size-total, pos+total); + while (total < num_bytes) { + done = pwrite(fd, outbuf + offset + total, + num_bytes - total, + pos + total); if (done < 0) { ret = -1; goto out;