On 16.05.19 г. 12:06 ч., Qu Wenruo wrote:
>
>
> On 2019/5/16 下午4:42, Nikolay Borisov wrote:
>> This series fixes the following use case:
>>
>> truncate -s 3g btrfs.img
>> mkfs.btrfs btrfs.img
>> btrrfs fi show .img
>> ERROR: not a valid btrfs filesystem: /root/btrfs.img
>>
>>
>> As evident this currently produces an error due to libblkid not recognising
>> the
>> image file as a filesystem. This stems from the fact progs doesn't force the
>> addition of the image file to libblkid's cache. This series rectifies this.
>
> I'm wondering if we could just fall back to open_ctree() and print
> needed info using btrfs_fs_info.
>
> open_ctree() will scan the passed device no matter if it's a block
> device or a file or whatever, and get the correct result of fsid anyway.
> No need to bother blkid cache or whatever.
I agree, tested it locally and it worked, so will send revised version
with a more contained change, just in cmds-filesystem.c
>
> Thanks,
> Qu
>
>>
>> Patch 1 extends btrfs_scan_devices to take an optional path argument which
>> will
>> be added to libblkid's cache.
>>
>> Patch 2 Makes 'btrfs filesystem' Utilizes this btrfs_scan_devices' new
>> interface if it detects we want to query a filesystem placed on an image
>> file.
>>
>> Patch 3 Adds simple test case to ensure this works as expected and is not
>> broken in the future.
>>
>> Nikolay Borisov (3):
>> btrfs-progs: Make btrfs_scan_devices take a path
>> btrfs-progs: Correctly identify fs on image files in "filesystem"
>> subcommands
>> btrfs-progs: tests: Test fs on image files is correctly recognised
>>
>> cmds-device.c | 2 +-
>> cmds-filesystem.c | 3 +--
>> disk-io.c | 2 +-
>> tests/cli-tests/010-fi-show-on-new-file/test.sh | 16 ++++++++++++++++
>> utils.c | 18 +++++++++++++++---
>> utils.h | 2 +-
>> 6 files changed, 35 insertions(+), 8 deletions(-)
>> create mode 100755 tests/cli-tests/010-fi-show-on-new-file/test.sh
>>
>