* [PATCH 1/2] btrfs: btrfs_defrag_root() doesn't support any option
@ 2016-12-21 7:42 Anand Jain
2016-12-21 7:42 ` [PATCH 2/2 RFC] btrfs: btrfs_defrag_root() doesn't defrag extent root tree Anand Jain
2017-01-03 16:21 ` [PATCH 1/2] btrfs: btrfs_defrag_root() doesn't support any option David Sterba
0 siblings, 2 replies; 5+ messages in thread
From: Anand Jain @ 2016-12-21 7:42 UTC (permalink / raw)
To: linux-btrfs; +Cc: dsterba, Anand Jain
Both BTRFS_IOC_DEFRAG and BTRFS_IOC_DEFRAG_RANGE call the same
function- btrfs_ioctl_defrag(), however BTRFS_IOC_DEFRAG does
not support any argument, so check that and return not supported
if provided. This has valid impact at the user end, in the cli below
btrfs filesystem defrag -clzo /btrfs
the -c option (or similarly other) is only applicable to the file
defrag, which is either provided in the argument or when used along
with the -r option, however as of now the above cli does not report
any error. This patch will fix it.
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
fs/btrfs/ioctl.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 7acbd2cf6192..bd1bb7fcea8a 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -2608,6 +2608,10 @@ static int btrfs_ioctl_defrag(struct file *file, void __user *argp)
ret = -EPERM;
goto out;
}
+ if (argp) {
+ ret = -EOPNOTSUPP;
+ goto out;
+ }
ret = btrfs_defrag_root(root);
if (ret)
goto out;
--
2.10.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2 RFC] btrfs: btrfs_defrag_root() doesn't defrag extent root tree
2016-12-21 7:42 [PATCH 1/2] btrfs: btrfs_defrag_root() doesn't support any option Anand Jain
@ 2016-12-21 7:42 ` Anand Jain
2017-01-03 16:24 ` David Sterba
2017-01-03 16:21 ` [PATCH 1/2] btrfs: btrfs_defrag_root() doesn't support any option David Sterba
1 sibling, 1 reply; 5+ messages in thread
From: Anand Jain @ 2016-12-21 7:42 UTC (permalink / raw)
To: linux-btrfs; +Cc: dsterba, Anand Jain
Since btrfs_defrag_leaves() does not support extent_root,
remove its corresponding call. The user can use the file
based defrag to defrag extents as of now.
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
fs/btrfs/ioctl.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index bd1bb7fcea8a..112456baffe9 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -2613,9 +2613,6 @@ static int btrfs_ioctl_defrag(struct file *file, void __user *argp)
goto out;
}
ret = btrfs_defrag_root(root);
- if (ret)
- goto out;
- ret = btrfs_defrag_root(root->fs_info->extent_root);
break;
case S_IFREG:
if (!(file->f_mode & FMODE_WRITE)) {
--
2.10.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] btrfs: btrfs_defrag_root() doesn't support any option
2016-12-21 7:42 [PATCH 1/2] btrfs: btrfs_defrag_root() doesn't support any option Anand Jain
2016-12-21 7:42 ` [PATCH 2/2 RFC] btrfs: btrfs_defrag_root() doesn't defrag extent root tree Anand Jain
@ 2017-01-03 16:21 ` David Sterba
2017-01-04 11:30 ` Anand Jain
1 sibling, 1 reply; 5+ messages in thread
From: David Sterba @ 2017-01-03 16:21 UTC (permalink / raw)
To: Anand Jain; +Cc: linux-btrfs, dsterba
On Wed, Dec 21, 2016 at 03:42:07PM +0800, Anand Jain wrote:
> Both BTRFS_IOC_DEFRAG and BTRFS_IOC_DEFRAG_RANGE call the same
> function- btrfs_ioctl_defrag(), however BTRFS_IOC_DEFRAG does
> not support any argument, so check that and return not supported
> if provided. This has valid impact at the user end, in the cli below
> btrfs filesystem defrag -clzo /btrfs
> the -c option (or similarly other) is only applicable to the file
> defrag, which is either provided in the argument or when used along
> with the -r option, however as of now the above cli does not report
> any error. This patch will fix it.
I think it would be better to do the sanitization on the userspace side.
In this case combination of a compression option and bare directory
would not lead to the expected result.
IMO it's deciding between
"pass any arguments to kernel" - here returning EOPNOTSUPP would be
quite unclear what went wrong
vs.
"validate as much arguments as we can before passing to kernel" - and
we'll know early that the combination is not valid, also that we want
to deprecate it etc.
I vote for #2 as we have enough information to give an informative error
message.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2 RFC] btrfs: btrfs_defrag_root() doesn't defrag extent root tree
2016-12-21 7:42 ` [PATCH 2/2 RFC] btrfs: btrfs_defrag_root() doesn't defrag extent root tree Anand Jain
@ 2017-01-03 16:24 ` David Sterba
0 siblings, 0 replies; 5+ messages in thread
From: David Sterba @ 2017-01-03 16:24 UTC (permalink / raw)
To: Anand Jain; +Cc: linux-btrfs, dsterba
On Wed, Dec 21, 2016 at 03:42:08PM +0800, Anand Jain wrote:
> Since btrfs_defrag_leaves() does not support extent_root,
> remove its corresponding call. The user can use the file
> based defrag to defrag extents as of now.
>
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Oh right, btrfs_defrag_leaves even explicitly checks for extent_root, so
this has never worked anyway, safe to remove.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] btrfs: btrfs_defrag_root() doesn't support any option
2017-01-03 16:21 ` [PATCH 1/2] btrfs: btrfs_defrag_root() doesn't support any option David Sterba
@ 2017-01-04 11:30 ` Anand Jain
0 siblings, 0 replies; 5+ messages in thread
From: Anand Jain @ 2017-01-04 11:30 UTC (permalink / raw)
To: dsterba, linux-btrfs
On 01/04/17 00:21, David Sterba wrote:
> On Wed, Dec 21, 2016 at 03:42:07PM +0800, Anand Jain wrote:
>> Both BTRFS_IOC_DEFRAG and BTRFS_IOC_DEFRAG_RANGE call the same
>> function- btrfs_ioctl_defrag(), however BTRFS_IOC_DEFRAG does
>> not support any argument, so check that and return not supported
>> if provided. This has valid impact at the user end, in the cli below
>> btrfs filesystem defrag -clzo /btrfs
>> the -c option (or similarly other) is only applicable to the file
>> defrag, which is either provided in the argument or when used along
>> with the -r option, however as of now the above cli does not report
>> any error. This patch will fix it.
>
> I think it would be better to do the sanitization on the userspace side.
>
> In this case combination of a compression option and bare directory
> would not lead to the expected result.
Hmm.. I am confused on the expected result here, what should it be ?
My thinking, compression option on the directory is not supported.
That's because the kernel calls btrfs_defrag_root() for dir as arg,
which does not accept any option.
In the same context if either -r option is used (then it picks up
individual files as arg) or if a file is used as arg, then kernel
calls btrfs_defrag_files() which then the options makes sense.
> IMO it's deciding between
>
> "pass any arguments to kernel" - here returning EOPNOTSUPP would be
> quite unclear what went wrong
>
> vs.
>
> "validate as much arguments as we can before passing to kernel" - and
> we'll know early that the combination is not valid, also that we want
> to deprecate it etc.
btrfs-progs is one of the tool. If API is tested with a test program
it will still can be shown as failing.
The kernel problem statement is:
- ioctl("/dir", BTRFS_IOC_DEFRAG, options)
- ioctl("/dir", BTRFS_IOC_DEFRAG_RANGE, options)
the above ioctl usage provides false impression that options have
worked, but the kernel does not use the options at all.
Its a different story if btrfs_defrag_root() would support options
in the long term ?
> I vote for #2 as we have enough information to give an informative error
> message.
Thanks, Anand
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-01-04 11:28 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-21 7:42 [PATCH 1/2] btrfs: btrfs_defrag_root() doesn't support any option Anand Jain
2016-12-21 7:42 ` [PATCH 2/2 RFC] btrfs: btrfs_defrag_root() doesn't defrag extent root tree Anand Jain
2017-01-03 16:24 ` David Sterba
2017-01-03 16:21 ` [PATCH 1/2] btrfs: btrfs_defrag_root() doesn't support any option David Sterba
2017-01-04 11:30 ` Anand Jain
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.