From patchwork Mon Jul 27 11:32:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhaolei X-Patchwork-Id: 6872561 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.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 7304EC05AC for ; Mon, 27 Jul 2015 11:34:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8B71020532 for ; Mon, 27 Jul 2015 11:34:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D076E20531 for ; Mon, 27 Jul 2015 11:34:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752134AbbG0LeQ (ORCPT ); Mon, 27 Jul 2015 07:34:16 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:4253 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751924AbbG0LeP (ORCPT ); Mon, 27 Jul 2015 07:34:15 -0400 X-IronPort-AV: E=Sophos;i="5.15,520,1432569600"; d="scan'208";a="98933073" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 27 Jul 2015 19:37:49 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id t6RBWMM3021957 for ; Mon, 27 Jul 2015 19:32:23 +0800 Received: from localhost.localdomain (10.167.226.114) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server id 14.3.181.6; Mon, 27 Jul 2015 19:34:12 +0800 From: Zhaolei To: CC: Zhao Lei Subject: [PATCH] btrfs-progs: Show detail error message when write sb failed in write_dev_supers() Date: Mon, 27 Jul 2015 19:32:37 +0800 Message-ID: <8277e478b7947c957be606f17b5137ae8d78ee66.1437996746.git.zhaolei@cn.fujitsu.com> X-Mailer: git-send-email 1.8.5.1 MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-8.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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: Zhao Lei fsck-tests.sh failed and show following message in my node: # ./fsck-tests.sh [TEST] 001-bad-file-extent-bytenr disk-io.c:1444: write_dev_supers: Assertion `ret != BTRFS_SUPER_INFO_SIZE` failed. /root/btrfsprogs/btrfs-image(write_all_supers+0x2d2)[0x41031c] /root/btrfsprogs/btrfs-image(write_ctree_super+0xc5)[0x41042e] /root/btrfsprogs/btrfs-image(btrfs_commit_transaction+0x208)[0x410976] /root/btrfsprogs/btrfs-image[0x438780] /root/btrfsprogs/btrfs-image(main+0x3d5)[0x438c5c] /lib64/libc.so.6(__libc_start_main+0xfd)[0x335e01ecdd] /root/btrfsprogs/btrfs-image[0x4074e9] failed to restore image /root/btrfsprogs/tests/fsck-tests/001-bad-file-extent-bytenr/default_case.img # # cat fsck-tests-results.txt === Entering /root/btrfsprogs/tests/fsck-tests/001-bad-file-extent-bytenr restoring image default_case.img failed to restore image /root/btrfsprogs/tests/fsck-tests/001-bad-file-extent-bytenr/default_case.img # Reason: I run above test in a NFS mountpoint, it don't have enouth space to write all superblock to image file, and don't support sparse file. So write_dev_supers() failed in writing sb and output above message. It takes me quite of time to know what happened, we can save these time by output exact information in write-sb-fail case. After patch: # ./fsck-tests.sh [TEST] 001-bad-file-extent-bytenr WARNING: Write sb failed: File too large disk-io.c:1492: write_all_supers: Assertion `ret` failed. ... # Signed-off-by: Zhao Lei --- disk-io.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/disk-io.c b/disk-io.c index fdcfd6d..607d4a1 100644 --- a/disk-io.c +++ b/disk-io.c @@ -1419,7 +1419,8 @@ static int write_dev_supers(struct btrfs_root *root, ret = pwrite64(device->fd, root->fs_info->super_copy, BTRFS_SUPER_INFO_SIZE, root->fs_info->super_bytenr); - BUG_ON(ret != BTRFS_SUPER_INFO_SIZE); + if (ret != BTRFS_SUPER_INFO_SIZE) + goto write_err; return 0; } @@ -1441,10 +1442,19 @@ static int write_dev_supers(struct btrfs_root *root, */ ret = pwrite64(device->fd, root->fs_info->super_copy, BTRFS_SUPER_INFO_SIZE, bytenr); - BUG_ON(ret != BTRFS_SUPER_INFO_SIZE); + if (ret != BTRFS_SUPER_INFO_SIZE) + goto write_err; } return 0; + +write_err: + if (ret > 0) + fprintf(stderr, "WARNING: Failed to write all sb data\n"); + else + fprintf(stderr, "WARNING: Write sb failed: %s\n", + strerror(errno)); + return ret; } int write_all_supers(struct btrfs_root *root)