From patchwork Thu Nov 27 02:01:35 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gui Hecheng X-Patchwork-Id: 5391131 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 B7680C11AC for ; Thu, 27 Nov 2014 02:03:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D70522012D for ; Thu, 27 Nov 2014 02:03:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 00E5A20115 for ; Thu, 27 Nov 2014 02:03:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753540AbaK0CDa (ORCPT ); Wed, 26 Nov 2014 21:03:30 -0500 Received: from cn.fujitsu.com ([59.151.112.132]:15539 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751882AbaK0CD3 (ORCPT ); Wed, 26 Nov 2014 21:03:29 -0500 X-IronPort-AV: E=Sophos;i="5.04,848,1406563200"; d="scan'208";a="44051006" Received: from localhost (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 27 Nov 2014 10:00:09 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id sAR236Ng010593 for ; Thu, 27 Nov 2014 10:03:06 +0800 Received: from localhost.localdomain (10.167.226.111) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Thu, 27 Nov 2014 10:03:23 +0800 From: Gui Hecheng To: CC: Gui Hecheng Subject: [PATCH] btrfs-progs: apply realpath for btrfs fi show when mount point is given Date: Thu, 27 Nov 2014 10:01:35 +0800 Message-ID: <1417053695-14210-2-git-send-email-guihc.fnst@cn.fujitsu.com> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <1417053695-14210-1-git-send-email-guihc.fnst@cn.fujitsu.com> References: <1417053695-14210-1-git-send-email-guihc.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.111] 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.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_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 For now, # btrfs fi show /mnt/btrfs gives info correctly, while # btrfs fi show /mnt/btrfs/ gives nothing. This implies that the @realpath() function should be applied to unify the behavior. Made a more clear comment right above the call as well. Signed-off-by: Gui Hecheng --- cmds-filesystem.c | 60 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/cmds-filesystem.c b/cmds-filesystem.c index cd6b3c6..4e6d2f6 100644 --- a/cmds-filesystem.c +++ b/cmds-filesystem.c @@ -901,39 +901,47 @@ static int cmd_show(int argc, char **argv) if (strlen(search) == 0) usage(cmd_show_usage); type = check_arg_type(search); + + /* + * For search is a device: + * realpath do /dev/mapper/XX => /dev/dm-X + * which is required by BTRFS_SCAN_DEV + * For search is a mountpoint: + * realpath do /mnt/btrfs/ => /mnt/btrfs + * which shall be recognized by btrfs_scan_kernel() + */ + if (!realpath(search, path)) { + fprintf(stderr, "ERROR: Could not show %s: %s\n", + search, strerror(errno)); + return 1; + } + + search = path; + /* * needs spl handling if input arg is block dev * And if input arg is mount-point just print it * right away */ - if (type == BTRFS_ARG_BLKDEV) { - if (where == BTRFS_SCAN_LBLKID) { - /* we need to do this because - * legacy BTRFS_SCAN_DEV - * provides /dev/dm-x paths - */ - if (realpath(search, path)) - search = path; + if (type == BTRFS_ARG_BLKDEV && where != BTRFS_SCAN_LBLKID) { + ret = get_btrfs_mount(search, + mp, sizeof(mp)); + if (!ret) { + /* given block dev is mounted*/ + search = mp; + type = BTRFS_ARG_MNTPOINT; } else { - ret = get_btrfs_mount(search, - mp, sizeof(mp)); - if (!ret) { - /* given block dev is mounted*/ - search = mp; - type = BTRFS_ARG_MNTPOINT; - } else { - ret = dev_to_fsid(search, fsid); - if (ret) { - fprintf(stderr, - "ERROR: No btrfs on %s\n", - search); - return 1; - } - uuid_unparse(fsid, uuid_buf); - search = uuid_buf; - type = BTRFS_ARG_UUID; - goto devs_only; + ret = dev_to_fsid(search, fsid); + if (ret) { + fprintf(stderr, + "ERROR: No btrfs on %s\n", + search); + return 1; } + uuid_unparse(fsid, uuid_buf); + search = uuid_buf; + type = BTRFS_ARG_UUID; + goto devs_only; } } }