All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nikolay Borisov <nborisov@suse.com>
To: linux-btrfs@vger.kernel.org
Cc: Nikolay Borisov <nborisov@suse.com>
Subject: [PATCH 2/3] btrfs-progs: Correctly identify fs on image files in "filesystem" subcommands
Date: Thu, 16 May 2019 11:42:49 +0300	[thread overview]
Message-ID: <20190516084250.19363-3-nborisov@suse.com> (raw)
In-Reply-To: <20190516084250.19363-1-nborisov@suse.com>

Currently if a new filesystem is created and interrogated with we get
an error:

    truncate -s 3g btrfs.img
    mkfs.btrfs btrfs.img
    btrfs fi show btrfs.img
    ERROR: not a valid btrfs filesystem: /root/btrfs.img

The reason is that the image is not automatically recognised by libblkid
meaning btrfs_scan_devices will not "see" the device, resulting in the
aofrementioned error.

Fix it by detecting when this condition occurs and pass the path to the
file to btrfs_scan_devices, which will correctly add it to libblkid's
cache.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
 cmds-filesystem.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index 4657deb20fde..0327563154d5 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -771,8 +771,7 @@ static int cmd_filesystem_show(int argc, char **argv)
 		goto out;
 
 devs_only:
-	ret = btrfs_scan_devices(NULL);
-
+	ret = btrfs_scan_devices(type == BTRFS_ARG_REG ? search : NULL);
 	if (ret) {
 		error("blkid device scan returned %d", ret);
 		return 1;
-- 
2.7.4


  parent reply	other threads:[~2019-05-16  8:42 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-16  8:42 [PATCH 0/3] Fix "filesystem" command when fs is on file image Nikolay Borisov
2019-05-16  8:42 ` [PATCH 1/3] btrfs-progs: Make btrfs_scan_devices take a path Nikolay Borisov
2019-05-16  8:42 ` Nikolay Borisov [this message]
2019-05-16  8:42 ` [PATCH 3/3] btrfs-progs: tests: Test fs on image files is correctly recognised Nikolay Borisov
2019-05-16  9:06 ` [PATCH 0/3] Fix "filesystem" command when fs is on file image Qu Wenruo
2019-05-16 12:24   ` Nikolay Borisov

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=20190516084250.19363-3-nborisov@suse.com \
    --to=nborisov@suse.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.