From patchwork Tue Sep 20 02:19:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 9340861 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 380FC601C2 for ; Tue, 20 Sep 2016 02:19:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 289E829B45 for ; Tue, 20 Sep 2016 02:19:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1D09A29B48; Tue, 20 Sep 2016 02:19:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A54DE29B45 for ; Tue, 20 Sep 2016 02:19:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753363AbcITCTf (ORCPT ); Mon, 19 Sep 2016 22:19:35 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:43954 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1753276AbcITCTf (ORCPT ); Mon, 19 Sep 2016 22:19:35 -0400 X-IronPort-AV: E=Sophos;i="5.20,367,1444665600"; d="scan'208";a="850996" Received: from unknown (HELO cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 20 Sep 2016 10:19:21 +0800 Received: from adam-work.localdomain (unknown [10.167.226.34]) by cn.fujitsu.com (Postfix) with ESMTP id D2C334042C5C; Tue, 20 Sep 2016 10:19:16 +0800 (CST) From: Qu Wenruo To: linux-btrfs@vger.kernel.org Cc: hawken@thehawken.org Subject: [PATCH 1/2] btrfs-progs: Return more meaningful value for btrfs_read_dev_super Date: Tue, 20 Sep 2016 10:19:01 +0800 Message-Id: <20160920021902.818-1-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.10.0 MIME-Version: 1.0 X-yoursite-MailScanner-ID: D2C334042C5C.AD616 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: quwenruo@cn.fujitsu.com Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP btrfs_read_dev_super() only returns 0 or -1, which doesn't really help, caller won't know if it's caused by bad superblock or superblock out of range. Change it to return -ENOENT for superblock which is out of range, and return -EIO for bad superblocks. Signed-off-by: Qu Wenruo --- disk-io.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/disk-io.c b/disk-io.c index 854c285..26852ee 100644 --- a/disk-io.c +++ b/disk-io.c @@ -1590,14 +1590,15 @@ int btrfs_read_dev_super(int fd, struct btrfs_super_block *sb, u64 sb_bytenr, if (sb_bytenr != BTRFS_SUPER_INFO_OFFSET) { ret = pread64(fd, buf, BTRFS_SUPER_INFO_SIZE, sb_bytenr); + /* Special return value for out of dev/file range */ if (ret < BTRFS_SUPER_INFO_SIZE) - return -1; + return -ENOENT; if (btrfs_super_bytenr(buf) != sb_bytenr) - return -1; + return -EIO; if (check_super(buf, sbflags)) - return -1; + return -EIO; memcpy(sb, buf, BTRFS_SUPER_INFO_SIZE); return 0; } @@ -1641,7 +1642,7 @@ int btrfs_read_dev_super(int fd, struct btrfs_super_block *sb, u64 sb_bytenr, } } - return transid > 0 ? 0 : -1; + return transid > 0 ? 0 : -EIO; } static int write_dev_supers(struct btrfs_root *root,