From patchwork Wed Jul 25 08:20:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Misono Tomohiro X-Patchwork-Id: 10543669 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7CCE99093 for ; Wed, 25 Jul 2018 08:17:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7064B29B0B for ; Wed, 25 Jul 2018 08:17:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 648AD29B1F; Wed, 25 Jul 2018 08:17:11 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 019D429B0F for ; Wed, 25 Jul 2018 08:17:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728679AbeGYJ1m (ORCPT ); Wed, 25 Jul 2018 05:27:42 -0400 Received: from mgwkm04.jp.fujitsu.com ([202.219.69.171]:45088 "EHLO mgwkm04.jp.fujitsu.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728673AbeGYJ1l (ORCPT ); Wed, 25 Jul 2018 05:27:41 -0400 Received: from kw-mxoi2.gw.nic.fujitsu.com (unknown [192.168.231.133]) by mgwkm04.jp.fujitsu.com with smtp id 2100_59c6_92fc0cca_1f7d_4fd2_886a_279436bad58f; Wed, 25 Jul 2018 17:17:01 +0900 Received: from g01jpfmpwyt01.exch.g01.fujitsu.local (g01jpfmpwyt01.exch.g01.fujitsu.local [10.128.193.38]) by kw-mxoi2.gw.nic.fujitsu.com (Postfix) with ESMTP id 3779DAC015F for ; Wed, 25 Jul 2018 17:17:01 +0900 (JST) Received: from g01jpexchyt33.g01.fujitsu.local (unknown [10.128.193.4]) by g01jpfmpwyt01.exch.g01.fujitsu.local (Postfix) with ESMTP id 556A06D68F8 for ; Wed, 25 Jul 2018 17:17:00 +0900 (JST) Received: from luna3.soft.fujitsu.com (10.124.196.199) by g01jpexchyt33.g01.fujitsu.local (10.128.193.36) with Microsoft SMTP Server id 14.3.352.0; Wed, 25 Jul 2018 17:17:00 +0900 From: Misono Tomohiro To: Subject: [PATCH 2/3] btrfs-progs: ins: logical-resolve: Print message when path cannot be resolved Date: Wed, 25 Jul 2018 17:20:17 +0900 Message-ID: X-Mailer: git-send-email 2.14.4 In-Reply-To: References: MIME-Version: 1.0 X-SecurityPolicyCheck-GC: OK by FENCE-Mail X-TM-AS-MML: disable 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 Since BTRFS_IOC_INO_PATHS requires fd of subvolume, logical-resolve cannot find the path when mount point is not FS_TREE (because the subvolume path cannot be opened). In that case, print message to try -P option instead. Signed-off-by: Misono Tomohiro --- cmds-inspect.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/cmds-inspect.c b/cmds-inspect.c index ac77a5ee..21aa2903 100644 --- a/cmds-inspect.c +++ b/cmds-inspect.c @@ -137,16 +137,18 @@ static const char * const cmd_inspect_logical_resolve_usage[] = { static int cmd_inspect_logical_resolve(int argc, char **argv) { int ret; - int fd; + int fd = -1; int i; int verbose = 0; int getpath = 1; int bytes_left; + u64 rootid; struct btrfs_ioctl_logical_ino_args loi; struct btrfs_data_container *inodes; u64 size = 4096; char full_path[PATH_MAX]; char *path_ptr; + char *mount_path = NULL; DIR *dirstream = NULL; optind = 0; @@ -178,6 +180,35 @@ static int cmd_inspect_logical_resolve(int argc, char **argv) if (!inodes) return 1; + /* Check if mount root is FS_ROOT */ + if (getpath) { + ret = find_mount_root(argv[optind + 1], &mount_path); + if (ret) { + error("cannot find mount root: %m"); + goto out; + } + + fd = btrfs_open_file_or_dir(mount_path, &dirstream, 1); + if (fd < 0) { + ret = 1; + goto out; + } + + ret = lookup_path_rootid(fd, &rootid); + if (ret) { + error("failed to lookup root id: %m"); + goto out; + } + + if (rootid != BTRFS_FS_TREE_OBJECTID) { + ret = 1; +printf("cannot resolve path when subvolume is mounted directly. try -P option\n"); + goto out; + } + + close_file_or_dir(fd, dirstream); + } + memset(inodes, 0, sizeof(*inodes)); loi.logical = arg_strtou64(argv[optind]); loi.size = size; @@ -259,6 +290,7 @@ static int cmd_inspect_logical_resolve(int argc, char **argv) out: close_file_or_dir(fd, dirstream); free(inodes); + free(mount_path); return !!ret; }