From: Hans van Kranenburg <Hans.van.Kranenburg@mendix.com>
To: "Holger Hoffstätte" <holger@applied-asynchrony.com>,
linux-btrfs <linux-btrfs@vger.kernel.org>
Subject: Re: Curious problem: btrfs device stats & unpriviliged access
Date: Mon, 8 Oct 2018 14:54:01 +0000 [thread overview]
Message-ID: <a0fe89e7-e2c4-8816-0465-1994f0f2e9d4@mendix.com> (raw)
In-Reply-To: <5eafba35-c79b-17f2-e296-aafddf06ebf1@mendix.com>
On 10/08/2018 04:40 PM, Hans van Kranenburg wrote:
> On 10/08/2018 04:27 PM, Holger Hoffstätte wrote:
>> (moving the discussion here from GH [1])
>>
>> Apparently there is something weird going on with the device stats
>> ioctls. I cannot get them to work as regular user, while they work
>> for David. A friend confirms the same issue on his system - no access
>> as non-root.
>>
>> So I made a new empty fs, mounted it, built btrfs-progs-4.17.1 with
>> debug symbols and stepped into search_chunk_tree_for_fs_info().
>> Everything is fine, all args are correct, right until:
>>
>> (gdb) s
>> 1614 ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &search_args);
>> (gdb) s
>> 1615 if (ret < 0)
>> (gdb) p ret
>> $4 = -1
>> (gdb) p search_args
>> $5 = {key = {tree_id = 3, min_objectid = 1, max_objectid = 1, min_offset
>> = 1,
>> max_offset = 18446744073709551615, min_transid = 0, max_transid =
>> 18446744073709551615,
>> min_type = 216, max_type = 216, nr_items = 30, unused = 0, unused1 = 0,
>> unused2 = 0,
>> unused3 = 0, unused4 = 0}, buf = '\000' <repeats 3991 times>}
>>
>> Looking at the kernel side of things in fs/btrfs/ioctl.c I see both
>> BTRFS_IOC_TREE_SEARCH[_V2} unconditionally require CAP_SYS_ADMIN.
>
> That's the tree search ioctl, for reading arbitrary metadata.
>
> The device stats ioctl is IOC_GET_DEV_STATS...
>
> I can do the device stats ioctl as normal user:
>
> import btrfs
> fs = btrfs.FileSystem('/')
> btrfs.utils.pretty_print(fs.dev_stats(1))
>
> <btrfs.ioctl.DevStats>
> devid: 1
> nr_items: 5
> flags: 0
> write_errs: 0
> read_errs: 0
> flush_errs: 0
> generation_errs: 0
> corruption_errs: 0
By the way, I can also do BTRFS_IOC_FS_INFO, BTRFS_IOC_DEV_INFO and
BTRFS_IOC_SPACE_INFO as normal user.
However, while fs_info tells me that there are num_devices devices,
there's no place where you can actually get which devids these are, and
you need to provide them one by one to dev_info and dev_stats... :
btrfs.utils.pretty_print(fs.fs_info())
<btrfs.ioctl.FsInfo>
max_id: 1
num_devices: 1
nodesize: 4096
sectorsize: 4096
clone_alignment: 4096
fsid: 91077ca5-6559-4a90-9d03-912d3a33412e
btrfs.utils.pretty_print(fs.dev_info(1))
<btrfs.ioctl.DevInfo>
devid: 1
bytes_used: 60699967488
total_bytes: 107374182400
path: /dev/xvda
uuid: 7e998baa-b533-4476-9132-d7d748d28044
btrfs.utils.pretty_print(fs.space_info())
-
<btrfs.ioctl.SpaceInfo>
flags: Data, single
total_bytes: 54.00GiB
used_bytes: 53.27GiB
-
<btrfs.ioctl.SpaceInfo>
flags: System, single
total_bytes: 32.00MiB
used_bytes: 12.00KiB
-
<btrfs.ioctl.SpaceInfo>
flags: Metadata, single
total_bytes: 2.50GiB
used_bytes: 1.30GiB
-
<btrfs.ioctl.SpaceInfo>
flags: GlobalReserve, single
total_bytes: 181.02MiB
used_bytes: 0.00B
>
>> So why can Dave get his dev stats as unprivileged user?
>> Does this work for anybody else? And why? :)
>>
>> cheers
>> Holger
>>
>> [1]
>> https://github.com/prometheus/node_exporter/issues/1100#issuecomment-427823190
>>
>
>
--
Hans van Kranenburg
next prev parent reply other threads:[~2018-10-08 14:54 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-08 14:27 Curious problem: btrfs device stats & unpriviliged access Holger Hoffstätte
2018-10-08 14:40 ` Hans van Kranenburg
2018-10-08 14:54 ` Hans van Kranenburg [this message]
2018-10-08 15:29 ` Holger Hoffstätte
2018-10-08 15:46 ` Hans van Kranenburg
2018-10-08 16:37 ` Holger Hoffstätte
2018-10-08 20:02 ` Hans van Kranenburg
2019-10-23 14:24 ` Holger Hoffstätte
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=a0fe89e7-e2c4-8816-0465-1994f0f2e9d4@mendix.com \
--to=hans.van.kranenburg@mendix.com \
--cc=holger@applied-asynchrony.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).