All of lore.kernel.org
 help / color / mirror / Atom feed
From: Misono Tomohiro <misono.tomohiro@jp.fujitsu.com>
To: <linux-btrfs@vger.kernel.org>
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	[thread overview]
Message-ID: <a5545edbef2d2b1800a5ea83d9c14773b5b1fbe7.1532501096.git.misono.tomohiro@jp.fujitsu.com> (raw)
In-Reply-To: <cover.1532501096.git.misono.tomohiro@jp.fujitsu.com>

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 <misono.tomohiro@jp.fujitsu.com>
---
 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;
 }
 
-- 
2.14.4



  parent reply	other threads:[~2018-07-25  9:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-25  8:20 [PATCH 0/3] btrfs-progs: ins: Update for logical-resolve command Misono Tomohiro
2018-07-25  8:20 ` [PATCH 1/3] btrfs-progs: ins: logical-resolve: Set correct error value Misono Tomohiro
2018-08-03 15:07   ` David Sterba
2018-07-25  8:20 ` Misono Tomohiro [this message]
2018-08-03 15:06   ` [PATCH 2/3] btrfs-progs: ins: logical-resolve: Print message when path cannot be resolved David Sterba
2018-08-06  2:34     ` Misono Tomohiro
2018-07-25  8:20 ` [PATCH v2 3/3] btrfs-progs: ins: logical-resolve: Add v2 ioctl support Misono Tomohiro

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a5545edbef2d2b1800a5ea83d9c14773b5b1fbe7.1532501096.git.misono.tomohiro@jp.fujitsu.com \
    --to=misono.tomohiro@jp.fujitsu.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.