From patchwork Fri Feb 7 06:45:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 3599921 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 3A76BBF418 for ; Fri, 7 Feb 2014 07:00:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 79D9D20145 for ; Fri, 7 Feb 2014 07:00:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 554EA20115 for ; Fri, 7 Feb 2014 07:00:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751469AbaBGHAN (ORCPT ); Fri, 7 Feb 2014 02:00:13 -0500 Received: from cn.fujitsu.com ([222.73.24.84]:34462 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1751290AbaBGHAL (ORCPT ); Fri, 7 Feb 2014 02:00:11 -0500 X-IronPort-AV: E=Sophos;i="4.95,799,1384272000"; d="scan'208";a="9480001" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 07 Feb 2014 14:56:17 +0800 Received: from fnstmail02.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id s176j4oY018882; Fri, 7 Feb 2014 14:45:05 +0800 Received: from adam-work.lan ([10.167.226.24]) by fnstmail02.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.3) with ESMTP id 2014020714431465-1632237 ; Fri, 7 Feb 2014 14:43:14 +0800 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Cc: Anand Jain Subject: [PATCH 1/2] btrfs-progs: Add missing devices check for mounted btrfs. Date: Fri, 7 Feb 2014 14:45:59 +0800 Message-Id: <1391755560-4721-1-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 1.8.5.4 X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2014/02/07 14:43:14, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2014/02/07 14:43:16, Serialize complete at 2014/02/07 14:43:16 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.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 In btrfs/003 of xfstest, it will check whether btrfs fi show can find missing devices. But before the patch, btrfs-progs will not check whether device missing if given a mounted btrfs mountpoint/block device. This patch fixes the bug and will pass btrfs/003. Signed-off-by: Qu Wenruo Cc: Anand Jain --- cmds-filesystem.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cmds-filesystem.c b/cmds-filesystem.c index 384d1b9..4c9933d 100644 --- a/cmds-filesystem.c +++ b/cmds-filesystem.c @@ -363,6 +363,8 @@ static int print_one_fs(struct btrfs_ioctl_fs_info_args *fs_info, char *label, char *path) { int i; + int fd; + int missing; char uuidbuf[BTRFS_UUID_UNPARSED_SIZE]; struct btrfs_ioctl_dev_info_args *tmp_dev_info; int ret; @@ -385,6 +387,14 @@ static int print_one_fs(struct btrfs_ioctl_fs_info_args *fs_info, for (i = 0; i < fs_info->num_devices; i++) { tmp_dev_info = (struct btrfs_ioctl_dev_info_args *)&dev_info[i]; + + /* Add check for missing devices even mounted */ + fd = open((char *)tmp_dev_info->path, O_RDONLY); + if (fd < 0) { + missing = 1; + continue; + } + close(fd); printf("\tdevid %4llu size %s used %s path %s\n", tmp_dev_info->devid, pretty_size(tmp_dev_info->total_bytes), @@ -392,6 +402,8 @@ static int print_one_fs(struct btrfs_ioctl_fs_info_args *fs_info, tmp_dev_info->path); } + if (missing) + printf("\t*** Some devices missing\n"); printf("\n"); return 0; }