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
> 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