[PATCH 3/8] btrfs-progs: sub list: Change the default behavior of "subvolume list" and allow non-privileged user to call it

2018-11-26 Thread Misono Tomohiro
ogs <= 4.19 $ mount -o subvol=AAA $DEV /mnt $ btrfs subvolume list /mnt ID 256 gen 11 top level 5 path AAA ID 257 gen 8 top level 256 path BBB ID 258 gen 8 top level 257 path BBB/dir/CCC ID 259 gen 11 top level 256 path ZZZ Signed-off-by: Misono Tomohiro Signed-off-by: David Sterba

[PATCH 2/8] btrfs-progs: sub list: factor out main part of btrfs_list_subvols

2018-11-26 Thread Misono Tomohiro
No functional changes. This is a preparation work for reworking "subvolume list". Signed-off-by: Misono Tomohiro Signed-off-by: David Sterba --- cmds-subvolume.c | 50 +--- 1 file changed, 30 insertions(+), 20 deletions(-) diff --

[PATCH 5/8] btrfs-progs: utils: Fallback to open without O_NOATIME flag in find_mount_root():

2018-11-26 Thread Misono Tomohiro
t;. Signed-off-by: Misono Tomohiro Signed-off-by: David Sterba --- utils.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/utils.c b/utils.c index 3a4bc92a..8ce8417d 100644 --- a/utils.c +++ b/utils.c @@ -2054,6 +2054,9 @@ int find_mount_root(const char *path, char **mount_roo

[PATCH RESEND 0/8] btrfs-progs: sub: Relax the privileges of "subvolume list/show"

2018-11-26 Thread Misono Tomohiro
it is relative to top-level subvolume) Also, snapshots to be shown are to which the user can access from current mount point. (for root, all snapshots in the fs) === [1] https://lore.kernel.org/linux-btrfs/cover.1529310485.git.misono.tomoh...@jp.fujitsu.com/ [

[PATCH 7/8] btrfs-progs: test: Add helper function to check if test user exists

2018-11-26 Thread Misono Tomohiro
Add helper function to check that if user 'nobody' exists or not. Note that 'nobody' should not have root privileges as it will be used to test the behavior of non-privileged user. Signed-off-by: Misono Tomohiro Signed-off-by: David Sterba --- tests/common | 10 ++

[PATCH 4/8] btrfs-progs: sub list: Update -a option and remove meaningless filter

2018-11-26 Thread Misono Tomohiro
path AAA/BBB ID 258 gen 10 top level 5 path ZZZ ** output of progs <= 4.19 $ btrfs subvolume list -a /mnt ID 256 gen 9 top level 5 path AAA ID 257 gen 9 top level 256 path /AAA/BBB ID 258 gen 10 top level 5 path ZZZ Signed-off-by: Misono Tomohiro Signed-off-by: David Sterba --- Do

[PATCH 8/8] btrfs-porgs: test: Add cli-test/009 to check subvolume list for both root and normal user

2018-11-26 Thread Misono Tomohiro
Signed-off-by: Misono Tomohiro Signed-off-by: David Sterba --- tests/cli-tests/009-subvolume-list/test.sh | 130 + 1 file changed, 130 insertions(+) create mode 100755 tests/cli-tests/009-subvolume-list/test.sh diff --git a/tests/cli-tests/009-subvolume-list/test.sh b

[PATCH 6/8] btrfs-progs: sub show: Allow non-privileged user to call "subvolume show"

2018-11-26 Thread Misono Tomohiro
:15e80697-2ffb-0b4b-8e1e-e0873a7cf944 ... Snapshot(s): /mnt/snap2 Signed-off-by: Misono Tomohiro Signed-off-by: David Sterba --- Documentation/btrfs-subvolume.asciidoc | 11 ++- cmds-subvolume.c | 107 ++--- 2 files

[PATCH 1/8] btrfs-progs: sub list: Use libbtrfsuitl for subvolume list

2018-11-26 Thread Misono Tomohiro
Sandoval Signed-off-by: Misono Tomohiro Signed-off-by: David Sterba --- cmds-subvolume.c | 963 +-- 1 file changed, 936 insertions(+), 27 deletions(-) diff --git a/cmds-subvolume.c b/cmds-subvolume.c index a8395aac..84a03fd8 100644 --- a/cmds-subvolume.c

[PATCH] btrfs/150: add _scratch_dev_pool_get/put to run the test as expected

2018-02-19 Thread Misono, Tomohiro
btrfs/150 uses RAID1 profile and make SCRATCH_DEV fail for test. However, if SCRATCH_DEV_POOL consists more than two devices, SCRATCH_DEV may not be used for RAID1 pair and the tests may not run as expected. Fix this by add _scratch_dev_pool_get/put like other tests (141, 143 etc.) do. Signed-off

Re: [PATCH v2 03/27] libbtrfsutil: add Python bindings

2018-02-21 Thread Misono, Tomohiro
On 2018/02/16 4:04, Omar Sandoval wrote: > From: Omar Sandoval > > The C libbtrfsutil library isn't very useful for scripting, so we also > want bindings for Python. Writing unit tests in Python is also much > easier than doing so in C. Only Python 3 is supported; if someone really > wants Python

Re: [PATCH v2 10/27] libbtrfsutil: add btrfs_util_[gs]et_default_subvolume()

2018-02-21 Thread Misono, Tomohiro
On 2018/02/16 4:04, Omar Sandoval wrote: > From: Omar Sandoval > > set_default_subvolume() is a trivial ioctl(), but there's no ioctl() for > get_default_subvolume(), so we need to search the root tree. > > Signed-off-by: Omar Sandoval > --- > libbtrfsutil/btrfsutil.h| 41

Re: [PATCH v2 23/27] btrfs-progs: use libbtrfsutil for subvol sync

2018-02-21 Thread Misono, Tomohiro
On 2018/02/16 4:05, Omar Sandoval wrote: > From: Omar Sandoval > > btrfs_util_f_deleted_subvolumes() replaces enumerate_dead_subvols() and > btrfs_util_f_subvolume_info() replaces is_subvolume_cleaned(). > > Signed-off-by: Omar Sandoval > --- > cmds-subvolume.c | 217 > ++---

Re: [PATCH v2 23/27] btrfs-progs: use libbtrfsutil for subvol sync

2018-02-21 Thread Misono, Tomohiro
On 2018/02/16 4:05, Omar Sandoval wrote: > From: Omar Sandoval > > btrfs_util_f_deleted_subvolumes() replaces enumerate_dead_subvols() and > btrfs_util_f_subvolume_info() replaces is_subvolume_cleaned(). And, the function names are older version. > > Signed-off-by: Omar Sandoval > --- > cmds

Re: [PATCH v2 16/27] btrfs-progs: use libbtrfsutil for read-only property

2018-02-21 Thread Misono, Tomohiro
On 2018/02/16 4:05, Omar Sandoval wrote: > From: Omar Sandoval > > Signed-off-by: Omar Sandoval > --- > messages.h | 13 > props.c| 69 > +++--- > 2 files changed, 38 insertions(+), 44 deletions(-) > > diff --git a/mes

Re: [PATCH v2 14/27] libbtrfsutil: add btrfs_util_deleted_subvolumes()

2018-02-22 Thread Misono, Tomohiro
On 2018/02/16 4:04, Omar Sandoval wrote: > From: Omar Sandoval > > Signed-off-by: Omar Sandoval > --- > libbtrfsutil/btrfsutil.h| 21 +++ > libbtrfsutil/python/btrfsutilpy.h | 3 + > libbtrfsutil/python/module.c| 30 ++ > libbtrfsutil/

Re: [PATCH v2 26/27] btrfs-progs: use libbtrfsutil for subvolume list

2018-02-22 Thread Misono, Tomohiro
On 2018/02/16 4:05, Omar Sandoval wrote: > From: Omar Sandoval > +static struct subvol_list *btrfs_list_deleted_subvols(int fd, > + struct > btrfs_list_filter_set *filter_set) > +{ > + struct subvol_list *subvols = NULL; > + uint64_t *i

Re: [PATCH v2 07/27] libbtrfsutil: add btrfs_util_subvolume_path()

2018-02-22 Thread Misono, Tomohiro
On 2018/02/16 4:04, Omar Sandoval wrote: > From: Omar Sandoval > +PUBLIC enum btrfs_util_error btrfs_util_subvolume_path_fd(int fd, uint64_t > id, > + char **path_ret) > +{ > + char *path, *p; > + size_t capacity = 4096; > + > + p

Re: [PATCH v2 11/27] libbtrfsutil: add subvolume iterator helpers

2018-02-22 Thread Misono, Tomohiro
On 2018/02/16 4:04, Omar Sandoval wrote: > From: Omar Sandoval > +PUBLIC enum btrfs_util_error btrfs_util_create_subvolume_iterator(const char > *path, > + uint64_t top, > +

Re: [PATCH v2 06/27] libbtrfsutil: add btrfs_util_create_subvolume()

2018-02-23 Thread Misono, Tomohiro
On 2018/02/16 4:04, Omar Sandoval wrote: > From: Omar Sandoval > +static enum btrfs_util_error openat_parent_and_name(int dirfd, const char > *path, > + char *name, size_t name_len, > + int *fd) > +{

Re: [PATCH v2 14/27] libbtrfsutil: add btrfs_util_deleted_subvolumes()

2018-02-27 Thread Misono, Tomohiro
On 2018/02/24 8:33, Omar Sandoval wrote: > On Fri, Feb 23, 2018 at 11:12:56AM +0900, Misono, Tomohiro wrote: >> >> On 2018/02/16 4:04, Omar Sandoval wrote: >>> From: Omar Sandoval >>> >>> Signed-off-by: Omar Sandoval >>> --- &g

Re: [PATCH 5/5] btrfs: Show more accurate max_inline

2018-03-02 Thread Misono, Tomohiro
On 2018/03/02 14:22, Qu Wenruo wrote: > Btrfs shows max_inline option into kernel message, but for > max_inline=4096, btrfs won't really inline 4096 bytes inline data if > it's not compressed. Hello, I have a question. man mount(8) says: max_inline=bytes Specify the maximum amoun

[PATCH 0/2] btrfs: Add two new unprivileged ioctls to allow normal users to call "sub list/show" etc.

2018-03-06 Thread Misono, Tomohiro
This adds two new unprivileged ioctls: 1st patch: version of tree_search ioctl which only searches/returns subvolume related item. 2nd patch: user version of ino_lookup ioctl which also performs permission check. They will be used to implement user version of "subvolume list/show" etc in user

[PATCH 1/2] btrfs: Add unprivileged subvolume search ioctl

2018-03-06 Thread Misono, Tomohiro
Add new unprivileged ioctl (BTRFS_IOC_GET_SUBVOL_INFO) which searches and returns only subvolume related item (ROOT_ITEM/ROOT_BACKREF/ROOT_REF) from root tree. The arguments of this ioctl are the same as treesearch ioctl and can be used like treesearch ioctl. Since treesearch ioctl requires root p

[PATCH 2/2] btrfs: Add unprivileged version of ino_lookup ioctl

2018-03-06 Thread Misono, Tomohiro
Add unprivileged version of ino_lookup ioctl (BTRFS_IOC_INO_LOOKUP_USER) to allow normal users to call "btrfs subvololume list/show" etc. in combination with BTRFS_IOC_GET_SUBVOL_INFO. This can be used like BTRFS_IOC_INO_LOOKUP but the argument is different because it also returns the name of bott

[RFC PATCH 0/7] btrfs-progs: Allow normal user to call "subvolume list/show"

2018-03-06 Thread Misono, Tomohiro
This RFC implements user version of "subvolume list/show" using two new ioctls. The ioctl patch to the kernel can be found in the ML titled "[PATCH 0/2] btrfs: Add two new unprivileged ioctls to allow normal users to call "sub list/show" etc." 1st-4th are some prepartion works. 5th patch is th

[RFC PATCH 1/7] btrfs-progs: Add 2 definitions of new unprivileged ioctl

2018-03-06 Thread Misono, Tomohiro
Add 2 definitions of new unprivileged ioctl (BTRFS_IOC_GET_SUBVOL_INFO and BTRFS_IOC_INO_LOOKUP_USER). They will be used to implement user version of "btrfs subvolume list" etc. Signed-off-by: Tomohiro Misono --- ioctl.h | 19 +++ 1 file changed, 19 insertions(+) diff --git a/io

[RFC PATCH 2/7] btrfs-progs: sub list: Add helper function which checks the permission for tree search ioctl

2018-03-06 Thread Misono, Tomohiro
This is a preparetion work to allow normal user to call "subvolume list". Signed-off-by: Tomohiro Misono --- btrfs-list.c | 30 ++ btrfs-list.h | 1 + 2 files changed, 31 insertions(+) diff --git a/btrfs-list.c b/btrfs-list.c index e01c5899..aea917c5 100644 --- a/bt

[PATCH 3/7] btrfs-progs: sub list: Pass specified path down to btrfs_list_subvols()

2018-03-06 Thread Misono, Tomohiro
This is a preparetion work to allow normal user to call "subvolume list". Signed-off-by: Tomohiro Misono --- btrfs-list.c | 16 +--- btrfs-list.h | 7 --- cmds-subvolume.c | 6 +++--- utils.c | 10 +- 4 files changed, 21 insertions(+), 18 deletions(-)

[RFC PATCH 4/7] btrfs-progs: fallback to open without O_NOATIME flag in, find_mount_root()

2018-03-06 Thread Misono, Tomohiro
O_NOATIME flag requires effective UID of process matches file's owner or has CAP_FOWNER capabilities. Fallback to open without O_NOATIME flag so that normal user can also call find_mount_root(). This is a preparation work to allow normal user to call "subvolume show". Signed-off-by: Tomohiro Miso

[RFC PATCH 5/7] btrfs-progs: sub list: Allow normal user to call "subvolume list/show"

2018-03-06 Thread Misono, Tomohiro
Allow normal user to call "subvolume list/show" by using 2 new unprivileged ioctls (BTRFS_IOC_GET_SUBVOL_INFO and BTRFS_IOC_INO_LOOKUP_USER). Note that for root, "subvolume list" returns all the subvolume in the filesystem by default, but for normal user, it returns subvolumes which exist under th

[RFC PATCH 6/7] btrfs-progs: test: Add helper function to check if test user exists

2018-03-06 Thread Misono, Tomohiro
Test user 'progs-test' will be used to test the behavior of normal user. In order to pass this check, add the user by "useradd -M progs-test". Note that progs-test should not have root privileges. Signed-off-by: Tomohiro Misono --- tests/common | 10 ++ 1 file changed, 10 insertions(+)

[RFC PATCH 7/7] btrfs-porgs: test: Add cli-test/009 to check subvolume list for both root and normal user

2018-03-06 Thread Misono, Tomohiro
Signed-off-by: Tomohiro Misono --- tests/cli-tests/009-subvolume-list/test.sh | 136 + 1 file changed, 136 insertions(+) create mode 100755 tests/cli-tests/009-subvolume-list/test.sh diff --git a/tests/cli-tests/009-subvolume-list/test.sh b/tests/cli-tests/009-subv

Re: [PATCH 1/2] btrfs: Add unprivileged subvolume search ioctl

2018-03-06 Thread Misono, Tomohiro
On 2018/03/07 5:29, Goffredo Baroncelli wrote: > On 03/06/2018 09:30 AM, Misono, Tomohiro wrote: >> Add new unprivileged ioctl (BTRFS_IOC_GET_SUBVOL_INFO) which searches >> and returns only subvolume related item (ROOT_ITEM/ROOT_BACKREF/ROOT_REF) >> from root tree. The argume

Re: [PATCH 2/2] btrfs: Add unprivileged version of ino_lookup ioctl

2018-03-06 Thread Misono, Tomohiro
On 2018/03/06 17:31, Misono, Tomohiro wrote: > Add unprivileged version of ino_lookup ioctl (BTRFS_IOC_INO_LOOKUP_USER) > to allow normal users to call "btrfs subvololume list/show" etc. in > combination with BTRFS_IOC_GET_SUBVOL_INFO. > > This can be used like BTR

Re: [PATCH 6/8] btrfs-progs: qgroups: introduce btrfs_qgroup_query

2018-03-07 Thread Misono, Tomohiro
On 2018/03/03 3:47, je...@suse.com wrote: > From: Jeff Mahoney > > The only mechanism we have in the progs for searching qgroups is to load > all of them and filter the results. This works for qgroup show but > to add quota information to 'btrfs subvoluem show' it's pretty wasteful. > > This pa

Re: [PATCH 1/2] btrfs: Add unprivileged subvolume search ioctl

2018-03-08 Thread Misono, Tomohiro
On 2018/03/08 4:00, Goffredo Baroncelli wrote: > On 03/07/2018 01:40 AM, Misono, Tomohiro wrote: >> On 2018/03/07 5:29, Goffredo Baroncelli wrote: >>> On 03/06/2018 09:30 AM, Misono, Tomohiro wrote: >>>> Add new unprivileged ioctl (BTRFS_IOC_GET_SUBVOL_INFO) which

Re: [PATCH 1/2] btrfs: Add unprivileged subvolume search ioctl

2018-03-08 Thread Misono, Tomohiro
On 2018/03/08 17:29, Nikolay Borisov wrote: > > > On 6.03.2018 10:30, Misono, Tomohiro wrote: >> Add new unprivileged ioctl (BTRFS_IOC_GET_SUBVOL_INFO) which searches >> and returns only subvolume related item (ROOT_ITEM/ROOT_BACKREF/ROOT_REF) >> from root tree. The

Re: [PATCH 2/2] btrfs: Add unprivileged version of ino_lookup ioctl

2018-03-08 Thread Misono, Tomohiro
On 2018/03/08 18:47, Nikolay Borisov wrote: > > > On 6.03.2018 10:31, Misono, Tomohiro wrote: >> Add unprivileged version of ino_lookup ioctl (BTRFS_IOC_INO_LOOKUP_USER) >> to allow normal users to call "btrfs subvololume list/show" etc. in >> combi

[PATCH v2 0/3] btrfs: Add three new unprivileged ioctls to allow normal users to call "sub list/show" etc.

2018-03-15 Thread Misono, Tomohiro
changelog: v1 -> v2 - completely reimplement 1st/2nd ioctl to have user friendly api - various cleanup, remove unnecessary goto === This adds three new unprivileged ioctls: 1st patch: ioctl which returns subvolume information of ROOT_ITEM and ROOT_BACKREF 2nd patch: ioctl which returns subvo

[PATCH v2 1/3] btrfs: Add unprivileged ioctl which returns subvolume information

2018-03-15 Thread Misono, Tomohiro
Add new unprivileged ioctl BTRFS_IOC_GET_SUBVOL_INFO which returns the information of subvolume containing this inode. (i.e. returns the information in ROOT_ITEM and ROOT_BACKREF.) Signed-off-by: Tomohiro Misono --- fs/btrfs/ioctl.c | 118 +

[PATCH v2 2/3] btrfs: Add unprivileged ioctl which returns subvolume's ROOT_REF

2018-03-15 Thread Misono, Tomohiro
Add unprivileged ioctl BTRFS_IOC_GET_SUBVOL_ROOTREF which returns ROOT_REF information of the subvolume containing this inode. The min id of root ref's subvolume to be searched is specified by min_id in struct btrfs_ioctl_get_subvol_rootref_args. If there are more root refs than BTRFS_MAX_ROOTREF_

[PATCH v2 3/3] btrfs: Add unprivileged version of ino_lookup ioctl

2018-03-15 Thread Misono, Tomohiro
Add unprivileged version of ino_lookup ioctl BTRFS_IOC_INO_LOOKUP_USER to allow normal users to call "btrfs subvololume list/show" etc. in combination with BTRFS_IOC_GET_SUBVOL_INFO/BTRFS_IOC_GET_SUBVOL_ROOTREF. This can be used like BTRFS_IOC_INO_LOOKUP but the argument is different. This is bec

[RFC PATCH v2 1/8] btrfs-progs: sub list: Call rb_free_nodes() in error path

2018-03-15 Thread Misono, Tomohiro
After btrfs_list_subvols() is called, root_lookup may hold some allocated memory area even if the function fails. Therefore rb_free_nodes() should be called. Signed-off-by: Tomohiro Misono --- btrfs-list.c | 16 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/btrf

[RFC PATCH v2 0/8] btrfs-progs: Allow normal user to call "subvolume list/show"

2018-03-15 Thread Misono, Tomohiro
changelog: v1 -> v2 - add independent error handling patch (1st patch) - reimplement according to ioctl change - various cleanup === This RFC implements user version of "subvolume list/show" using three new ioctls. The ioctl patch to the kernel can be found in the ML titled "[PATCH v2 0/

[RFC PATCH v2 3/8] btrfs-progs: sub list: Add helper function which checks the permission for tree search ioctl

2018-03-15 Thread Misono, Tomohiro
This is a preparetion work to allow normal user to call "subvolume list/show". Signed-off-by: Tomohiro Misono --- btrfs-list.c | 33 + btrfs-list.h | 1 + 2 files changed, 34 insertions(+) diff --git a/btrfs-list.c b/btrfs-list.c index 50e5ce5f..88689a9d 100644

[RFC PATCH v2 2/8] btrfs-progs: ioctl: Add 3 definitions of new unprivileged ioctl

2018-03-15 Thread Misono, Tomohiro
Add 3 definitions of new unprivileged ioctl (BTRFS_IOC_GET_SUBVOL_INFO, BTRFS_IOC_GET_SUBVOL_ROOTREF and BTRFS_IOC_INO_LOOKUP_USER). They will be used to implement user version of "btrfs subvolume list" etc. Signed-off-by: Tomohiro Misono --- ioctl.h | 86

[RFC PATCH v2 4/8] btrfs-progs: sub list: Pass specified path down to btrfs_list_subvols()

2018-03-15 Thread Misono, Tomohiro
This is a preparetion work to allow normal user to call "subvolume list/show". Signed-off-by: Tomohiro Misono --- btrfs-list.c | 16 +--- btrfs-list.h | 7 --- cmds-subvolume.c | 6 +++--- utils.c | 10 +- 4 files changed, 21 insertions(+), 18 deletions

[RFC PATCH v2 5/8] btrfs-progs: fallback to open without O_NOATIME flag in find_mount_root()

2018-03-15 Thread Misono, Tomohiro
O_NOATIME flag requires effective UID of process matches file's owner or has CAP_FOWNER capabilities. Fallback to open without O_NOATIME flag so that normal user can also call find_mount_root(). This is a preparation work to allow normal user to call "subvolume show". Signed-off-by: Tomohiro Miso

[RFC PATCH v2 7/8] btrfs-progs: test: Add helper function to check if test user exists

2018-03-15 Thread Misono, Tomohiro
Test user 'progs-test' will be used to test the behavior of normal user. In order to pass this check, add the user by "useradd -M progs-test". Note that progs-test should not have root privileges. Signed-off-by: Tomohiro Misono --- tests/common | 10 ++ 1 file changed, 10 insertions(+)

[RFC PATCH v2 6/8] btrfs-progs: sub list: Allow normal user to call "subvolume list/show"

2018-03-15 Thread Misono, Tomohiro
Allow normal user to call "subvolume list/show" by using 3 new unprivileged ioctls (BTRFS_IOC_GET_SUBVOL_INFO, BTRFS_IOC_GET_SUBVOL_ROOTREF and BTRFS_IOC_INO_LOOKUP_USER). Note that for root, "subvolume list" returns all the subvolume in the filesystem by default, but for normal user, it returns s

[RFC PATCH v2 8/8] btrfs-porgs: test: Add cli-test/009 to check subvolume list for both root and normal user

2018-03-15 Thread Misono, Tomohiro
Signed-off-by: Tomohiro Misono --- tests/cli-tests/009-subvolume-list/test.sh | 136 + 1 file changed, 136 insertions(+) create mode 100755 tests/cli-tests/009-subvolume-list/test.sh diff --git a/tests/cli-tests/009-subvolume-list/test.sh b/tests/cli-tests/009-subv

Re: [RFC PATCH v2 3/8] btrfs-progs: sub list: Add helper function which checks the permission for tree search ioctl

2018-03-18 Thread Misono, Tomohiro
On 2018/03/17 22:23, Goffredo Baroncelli wrote: > On 03/15/2018 09:13 AM, Misono, Tomohiro wrote: >> This is a preparetion work to allow normal user to call >> "subvolume list/show". >> >> Signed-off-by: Tomohiro Misono >> --- >> btrfs-list.c

Re: [RFC PATCH v2 6/8] btrfs-progs: sub list: Allow normal user to call "subvolume list/show"

2018-03-18 Thread Misono, Tomohiro
On 2018/03/17 22:23, Goffredo Baroncelli wrote: > On 03/15/2018 09:15 AM, Misono, Tomohiro wrote: >> Allow normal user to call "subvolume list/show" by using 3 new >> unprivileged ioctls (BTRFS_IOC_GET_SUBVOL_INFO, >> BTRFS_IOC_GET_SUBVOL_ROOTREF and BTRFS_IOC_INO_LO

[PATCH v3 0/3] btrfs: Add three new unprivileged ioctls to allow normal users to call "sub list/show" etc.

2018-03-19 Thread Misono, Tomohiro
changelog: v2-> v3 - fix kbuild test bot warning v1 -> v2 - completely reimplement 1st/2nd ioctl to have user friendly api - various cleanup, remove unnecessary goto === This adds three new unprivileged ioctls: 1st patch: ioctl which returns subvolume information of ROOT_ITEM and ROOT_BACK

[PATCH v3 1/3] btrfs: Add unprivileged ioctl which returns subvolume information

2018-03-19 Thread Misono, Tomohiro
Add new unprivileged ioctl BTRFS_IOC_GET_SUBVOL_INFO which returns the information of subvolume containing this inode. (i.e. returns the information in ROOT_ITEM and ROOT_BACKREF.) Signed-off-by: Tomohiro Misono --- fs/btrfs/ioctl.c | 118 +

[PATCH v3 2/3] btrfs: Add unprivileged ioctl which returns subvolume's ROOT_REF

2018-03-19 Thread Misono, Tomohiro
Add unprivileged ioctl BTRFS_IOC_GET_SUBVOL_ROOTREF which returns ROOT_REF information of the subvolume containing this inode. The min id of root ref's subvolume to be searched is specified by min_id in struct btrfs_ioctl_get_subvol_rootref_args. If there are more root refs than BTRFS_MAX_ROOTREF_

[PATCH v3 3/3] btrfs: Add unprivileged version of ino_lookup ioctl

2018-03-19 Thread Misono, Tomohiro
Add unprivileged version of ino_lookup ioctl BTRFS_IOC_INO_LOOKUP_USER to allow normal users to call "btrfs subvololume list/show" etc. in combination with BTRFS_IOC_GET_SUBVOL_INFO/BTRFS_IOC_GET_SUBVOL_ROOTREF. This can be used like BTRFS_IOC_INO_LOOKUP but the argument is different. This is bec

[RFC PATCH v3 0/7] btrfs-progs: Allow normal user to call "subvolume list/show"

2018-03-19 Thread Misono, Tomohiro
changelog: v2 -> v3 - use get_euid() to check the caller's privilege (and remove 3rd patch) - improve error handling v1 -> v2 - add independent error handling patch (1st patch) - reimplement according to ioctl change - various cleanup === This RFC implements user version of "subvolume l

[RFC PATCH v3 2/7] btrfs-progs: ioctl: Add 3 definitions of new unprivileged ioctl

2018-03-19 Thread Misono, Tomohiro
Add 3 definitions of new unprivileged ioctl (BTRFS_IOC_GET_SUBVOL_INFO, BTRFS_IOC_GET_SUBVOL_ROOTREF and BTRFS_IOC_INO_LOOKUP_USER). They will be used to implement user version of "btrfs subvolume list" etc. Signed-off-by: Tomohiro Misono --- ioctl.h | 86

[RFC PATCH v3 1/7] btrfs-progs: sub list: Call rb_free_nodes() in error path

2018-03-19 Thread Misono, Tomohiro
After btrfs_list_subvols() is called, root_lookup may hold some allocated memory area even if the function fails. Therefore rb_free_nodes() should be called. Signed-off-by: Tomohiro Misono --- btrfs-list.c | 16 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/btrf

[RFC PATCH v3 4/7] btrfs-progs: fallback to open without O_NOATIME flag in find_mount_root()

2018-03-19 Thread Misono, Tomohiro
O_NOATIME flag requires effective UID of process matches file's owner or has CAP_FOWNER capabilities. Fallback to open without O_NOATIME flag so that normal user can also call find_mount_root(). This is a preparation work to allow normal user to call "subvolume show". Signed-off-by: Tomohiro Miso

[RFC PATCH v3 3/7] btrfs-progs: sub list: Pass specified path down to btrfs_list_subvols()

2018-03-19 Thread Misono, Tomohiro
This is a preparetion work to allow normal user to call "subvolume list/show". Signed-off-by: Tomohiro Misono --- btrfs-list.c | 16 +--- btrfs-list.h | 7 --- cmds-subvolume.c | 6 +++--- utils.c | 10 +- 4 files changed, 21 insertions(+), 18 deletions

[RFC PATCH v3 6/7] btrfs-progs: test: Add helper function to check if test user exists

2018-03-19 Thread Misono, Tomohiro
Test user 'progs-test' will be used to test the behavior of normal user. In order to pass this check, add the user by "useradd -M progs-test". Note that progs-test should not have root privileges. Signed-off-by: Tomohiro Misono --- tests/common | 10 ++ 1 file changed, 10 insertions(+)

[RFC PATCH v3 7/7] btrfs-porgs: test: Add cli-test/009 to check subvolume list for both root and normal user

2018-03-19 Thread Misono, Tomohiro
Signed-off-by: Tomohiro Misono --- tests/cli-tests/009-subvolume-list/test.sh | 136 + 1 file changed, 136 insertions(+) create mode 100755 tests/cli-tests/009-subvolume-list/test.sh diff --git a/tests/cli-tests/009-subvolume-list/test.sh b/tests/cli-tests/009-subv

[RFC PATCH v3 5/7] btrfs-progs: sub list: Allow normal user to call "subvolume list/show"

2018-03-19 Thread Misono, Tomohiro
Allow normal user to call "subvolume list/show" by using 3 new unprivileged ioctls (BTRFS_IOC_GET_SUBVOL_INFO, BTRFS_IOC_GET_SUBVOL_ROOTREF and BTRFS_IOC_INO_LOOKUP_USER). Note that for root, "subvolume list" returns all the subvolume in the filesystem by default, but for normal user, it returns s

[PATCH] btrfs-progs: mkfs: add uuid and otime to ROOT_ITEM of FS_TREE

2018-03-19 Thread Misono, Tomohiro
Currently, the top-level subvolume lacks the UUID. As a result, both non-snapshot subvolume and snapshot of top-level subvolume do not have Parent UUID and cannot be distinguisued. Therefore "fi show" of top-level lists all the subvolumes which lacks the UUID in "Snapshot(s)" filed. Also, it lacks

Re: [RFC PATCH v3 5/7] btrfs-progs: sub list: Allow normal user to call "subvolume list/show"

2018-03-19 Thread Misono, Tomohiro
On 2018/03/20 2:09, Goffredo Baroncelli wrote: > On 03/19/2018 08:32 AM, Misono, Tomohiro wrote [snip] >> static void print_subvolume_column(struct root_info *subv, >> enum btrfs_list_column_enum column) >> { >> @@ -1492,19 +1800

[PATCH] btrfs: Allow non-privileged user to delete empty subvolume by default

2018-03-19 Thread Misono, Tomohiro
Deletion of subvolume by non-privileged user is completely restricted by default because we can delete a subvolume even if it is not empty and may cause data loss. In other words, when user_subvol_rm_allowed mount option is used, a user can delete a subvolume containing the directory which cannot b

[PATCH] btrfs: ctree.h: Fix wrong comment position about csum size

2018-03-19 Thread Misono, Tomohiro
Signed-off-by: Tomohiro Misono --- fs/btrfs/ctree.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index da308774b8a4..8f59cb20dd4c 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -86,9 +86,9 @@ struct btrfs_ordered_sum; */ #def

Re: [PATCH] btrfs: Allow non-privileged user to delete empty subvolume by default

2018-03-22 Thread Misono Tomohiro
On 2018/03/21 16:46, Nikolay Borisov wrote: > > > On 20.03.2018 22:06, Goffredo Baroncelli wrote: >> On 03/20/2018 07:45 AM, Misono, Tomohiro wrote: >>> Deletion of subvolume by non-privileged user is completely restricted >>> by default because we can delete a

Re: [PATCH] btrfs-progs: mkfs: add uuid and otime to ROOT_ITEM of FS_TREE

2018-03-23 Thread Misono Tomohiro
On 2018/03/22 2:48, David Sterba wrote: > On Mon, Mar 19, 2018 at 05:16:42PM +0900, Misono, Tomohiro wrote: >> Currently, the top-level subvolume lacks the UUID. As a result, both >> non-snapshot subvolume and snapshot of top-level subvolume do not have >> Parent UUID and ca

[PATCH v2] btrfs-progs: mkfs: add uuid and otime to ROOT_ITEM of, FS_TREE

2018-03-23 Thread Misono Tomohiro
Currently, the top-level subvolume lacks the UUID. As a result, both non-snapshot subvolume and snapshot of top-level subvolume do not have Parent UUID and cannot be distinguisued. Therefore "fi show" of top-level lists all the subvolumes which lacks the UUID in "Snapshot(s)" filed. Also, it lacks

Re: [PATCH] btrfs: ctree.h: Fix wrong comment position about csum size

2018-03-23 Thread Misono Tomohiro
On 2018/03/20 17:50, Qu Wenruo wrote: > > > On 2018年03月20日 14:47, Misono, Tomohiro wrote: >> >> Signed-off-by: Tomohiro Misono > > Reviewed-by: Qu Wenruo > > BTW this reminds me that, btrfs-progs is still using BTRFS_CRC32_SIZE > macro which the original c

[PATCH] btrfs-progs: remove BTRFS_CRC32_SIZE definition

2018-03-23 Thread Misono Tomohiro
The kernel code no longer has BTRFS_CRC32_SIZE and only uses btrfs_csum_sizes[]. So, update the progs code as well. Suggested-by: Qu Wenruo Signed-off-by: Tomohiro Misono --- convert/common.c | 2 +- convert/main.c | 2 +- ctree.h | 3 +-- image/main.c | 4 ++-- mkfs/common.c

[PATCH] btrfs: Allow rmdir(2) to delete a subvolume

2018-03-23 Thread Misono Tomohiro
This patch changes the behavior of rmdir(2) to allow it to delete an empty subvolume. In order to do that the core logic of subvolume deletion is moved from ioctl.c to inode.c and named as btrfs_delete_subvolume(), which is also called in the btrfs_rmdir() if a directory is an empty subvolume. No

Re: [PATCH] btrfs-progs: remove BTRFS_CRC32_SIZE definition

2018-03-25 Thread Misono Tomohiro
On 2018/03/23 18:14, Qu Wenruo wrote: > > > On 2018年03月23日 16:20, Misono Tomohiro wrote: >> The kernel code no longer has BTRFS_CRC32_SIZE and only uses >> btrfs_csum_sizes[]. So, update the progs code as well. >> >> Suggested-by: Qu Wenruo >> Signed-off-

Re: [PATCH] btrfs: Allow rmdir(2) to delete a subvolume

2018-03-25 Thread Misono Tomohiro
On 2018/03/23 18:09, Nikolay Borisov wrote: > > > On 23.03.2018 10:28, Misono Tomohiro wrote: >> This patch changes the behavior of rmdir(2) to allow it to delete >> an empty subvolume. >> >> In order to do that the core logic of subvolume deletion is moved fro

[PATCH v2 0/3] Allow rmdir(2) to delete a subvolume

2018-03-26 Thread Misono Tomohiro
changelog: v1 -> v2 ... split the patch to hopefully make review easier 1st patch is a preparation work just moving the declaration of may_destroy_subvol(). 2nd patch is the main part. New function btrfs_delete_subvolume() is introduced and used in btrfs_rmdir() when a direcoty is an empty subv

[PATCH v2 1/3] btrfs: Move may_destroy_subvol() from ioctl.c to inode.c

2018-03-26 Thread Misono Tomohiro
This is a preparation work to allow rmdir(2) to delete a subvolume. Signed-off-by: Tomohiro Misono --- fs/btrfs/ctree.h | 1 + fs/btrfs/inode.c | 54 ++ fs/btrfs/ioctl.c | 54 -- 3 files chan

[PATCH v2 3/3] btrfs: Cleanup btrfs_ioctl_snap_destroy() by using btrfs_delete_subvolume()

2018-03-26 Thread Misono Tomohiro
Use btrfs_delete_subvolume() in btrfs_ioctl_snap_destroy() too to cleanup the code. Call of d_delete() is still required since btrfs_delete_subvolume() does not call it (for rmdir(2), vfs layer later calls it). As a result, btrfs_unlink_subvol() and may_destroy_subvol() become static functions. No

[PATCH v2 2/3] btrfs: Allow rmdir(2) to delete a subvolume

2018-03-26 Thread Misono Tomohiro
This patch changes the behavior of rmdir(2) to allow it to delete an empty subvolume by default, unless it is not a default subvolume and send is not in progress. New function btrfs_delete_subvolume() is almost equal to the second half of btrfs_ioctl_snap_destroy(). This function requires inode_lo

error report: misc-test 006 sometimes fails in current devel branch

2018-03-27 Thread Misono Tomohiro
current devel branch of btrfs-progs (github) occasionally fails at misc-test 006: (kernel is 4.16.0-rc7) == $ sudo make test-misc TEST=006\* [LD] fssum [TEST] misc-tests.sh [TEST/misc] 006-image-on-missing-device /usr/data/src/btrfs-progs/tests//common: line 177: 10819 Abo

Re: [PATCH v2 1/3] btrfs: Move may_destroy_subvol() from ioctl.c to inode.c

2018-03-27 Thread Misono Tomohiro
On 2018/03/26 17:51, Nikolay Borisov wrote: > > > On 26.03.2018 11:28, Misono Tomohiro wrote: >> This is a preparation work to allow rmdir(2) to delete a subvolume. >> >> Signed-off-by: Tomohiro Misono >> --- >> fs/btrfs/c

Re: [PATCH v2 2/3] btrfs: Allow rmdir(2) to delete a subvolume

2018-03-27 Thread Misono Tomohiro
On 2018/03/27 21:39, Nikolay Borisov wrote: > > > On 26.03.2018 11:30, Misono Tomohiro wrote: >> This patch changes the behavior of rmdir(2) to allow it to delete >> an empty subvolume by default, unless it is not a default subvolume >> and send is not in p

Re: error report: misc-test 006 sometimes fails in current devel branch

2018-03-28 Thread Misono Tomohiro
On 2018/03/28 23:50, David Sterba wrote: > On Wed, Mar 28, 2018 at 10:55:56AM +0900, Misono Tomohiro wrote: >> current devel branch of btrfs-progs (github) occasionally fails at misc-test >> 006: >> (kernel is 4.16.0-rc7) > > Can you please also open an issue on github

[PATCH v2 0/3] btrfs-progs: Some fix for fi usage

2018-03-29 Thread Misono Tomohiro
v1->v2 These were sent several months ago, just rebased to current devel branch. Patch 1 and 2 aims to fix the "fi du" to include the information of "fi df" even when running without root privilege. Patch 3 is an independent cleanup. Tomohiro Misono (3): btrfs-progs: fi usage: change warning

[PATCH v2 2/3] btrfs-progs: fi usage: change to output more info without root privilege

2018-03-29 Thread Misono Tomohiro
Although per device usage cannot be shown without root privilege, per profile usage can be shown. To achieve this, we just basically need to remove the check of nullness of chunkinfo in print_filesystem_usage_by_chunk(), because other functions except print_unused() properly handles chunkinfo by c

[PATCH v2 1/3] btrfs-progs: fi usage: change warning message more appropriately

2018-03-29 Thread Misono Tomohiro
"fi usage" shows the warning "RAID5/6 numbers will be incorrect" when running without root privilege even if raid5/6 is not used. What happens is it cannot get the per device profile usage info, so change the message more appropriately. Reviewed-by: Qu Wenruo Signed-off-by: Tomohiro Misono ---

[PATCH v2 3/3] btrfs-progs: fi usage: cleanup unnecessary permission error check

2018-03-29 Thread Misono Tomohiro
Since BTRFS_IOC_FS_INFO does not require root privilege, there is no need to check EPERM error. Reviewed-by: Qu Wenruo Signed-off-by: Tomohiro Misono --- cmds-fi-usage.c | 7 --- 1 file changed, 7 deletions(-) diff --git a/cmds-fi-usage.c b/cmds-fi-usage.c index 2d45b3bb..5ce87a37 100644 -

Re: [RFC PATCH v3 0/7] btrfs-progs: Allow normal user to call "subvolume list/show"

2018-03-29 Thread Misono Tomohiro
92 gen 696884 top level 257 path a > ID 593 gen 696885 top level 592 path a/a1 > ID 594 gen 696885 top level 593 path a/a1/a2 > ID 595 gen 0 top level 257 path b > > > ghigo@venice:/tmp$ /home/ghigo/btrfs/btrfs-progs/btrfs sub show a > tmp/a > Name: a

[PATCH v3 1/3] btrfs: move may_destroy_subvol() from ioctl.c to inode.c

2018-03-29 Thread Misono Tomohiro
This is a preparation work to allow rmdir(2) to delete a subvolume. Signed-off-by: Tomohiro Misono --- fs/btrfs/ctree.h | 1 + fs/btrfs/inode.c | 54 ++ fs/btrfs/ioctl.c | 54 -- 3 files chan

[PATCH v3 0/3] Allow rmdir(2) to delete a subvolume

2018-03-29 Thread Misono Tomohiro
changelog: v2 -> v3 ... use if-else block instead of two if blocks and add Tested-by tag in 2nd patch v1 -> v2 ... split the patch to hopefully make review easier Note: I will send a xfstest if this series is merged. 1st patch is a preparation work just moving the declaration

[PATCH v3 2/3] btrfs: Allow rmdir(2) to delete a subvolume

2018-03-29 Thread Misono Tomohiro
This patch changes the behavior of rmdir(2) to allow it to delete an empty subvolume by default, unless it is not a default subvolume and send is not in progress. New function btrfs_delete_subvolume() is almost equal to the second half of btrfs_ioctl_snap_destroy(). This function requires inode_lo

[PATCH v3 3/3] btrfs: cleanup btrfs_ioctl_snap_destroy() by using btrfs_delete_subvolume()

2018-03-29 Thread Misono Tomohiro
Use btrfs_delete_subvolume() in btrfs_ioctl_snap_destroy() too to cleanup the code. Call of d_delete() is still required since btrfs_delete_subvolume() does not call it (for rmdir(2), vfs layer later calls it). As a result, btrfs_unlink_subvol() and may_destroy_subvol() become static functions. No

Re: [PATCH 5/5] libbtrfsutil: fix test assumptions about top-level subvolume

2018-03-30 Thread Misono Tomohiro
On 2018/03/29 16:53, Omar Sandoval wrote: > From: Omar Sandoval > > Since "btrfs-progs: mkfs: add uuid and otime to ROOT_ITEM of, FS_TREE", > the top-level subvolume has a non-zero UUID, ctime, and otime. Fix the > subvolume_info() test to not check for zero. Sorry, I didn't notice this. I chec

[PATCH] btrfs-progs: mkfs rootdir: use lgetxattr() not to follow a symbolic link

2018-04-01 Thread Misono Tomohiro
mkfs-test 016 "rootdir-bad-symbolic-link" fails when selinux is enabled. This is because add_xattr_item() uses getxattr() and tries to follow a bad symbolic link for selinux item, which causes ENOENT error. The line above already uses llistxattr() for getting list of xattr in order not to follow a

Re: [PATCH v3 2/3] btrfs: Allow rmdir(2) to delete a subvolume

2018-04-10 Thread Misono Tomohiro
On 2018/04/06 23:46, David Sterba wrote: > On Fri, Mar 30, 2018 at 03:16:47PM +0900, Misono Tomohiro wrote: >> This patch changes the behavior of rmdir(2) to allow it to delete >> an empty subvolume by default, unless it is not a default subvolume >> and send is not in progres

[PATCH v4 0/4] Allow rmdir(2) to delete a subvolume

2018-04-10 Thread Misono Tomohiro
changelog: v3 -> v4 ... Reorganize patches and updates commit log. No code change in total v2 -> v3 ... Use if-else block instead of two if blocks and add Tested-by tag in 2nd patch v1 -> v2 ... Split the patch to hopefully make review easier Note: I will send

[PATCH v4 1/4] btrfs: move may_destroy_subvol() from ioctl.c to inode.c

2018-04-10 Thread Misono Tomohiro
This is a preparation work to refactor btrfs_ioctl_snap_destroy() and to allow rmdir(2) to delete an empty subvolume. Signed-off-by: Tomohiro Misono --- fs/btrfs/ctree.h | 1 + fs/btrfs/inode.c | 54 ++ fs/btrfs/ioctl.c | 54 --

  1   2   3   4   >