Print a better message when there are unknown problems while parsing the
sort string. This currently is -ENOMEM and -1 on uknown format. This
will be changed.
Signed-off-by: David Sterba <dsterba@suse.com>
Since commit 208ba29007 "btrfs-progs: qgroup assign: can't handle
options", the unknown options will not be reported for qgroup
assign/remove as this was mistakenly removed from the caller.
Signed-off-by: David Sterba <dsterba@suse.com>
The error message about the unsatisfied argument count is scrolled away
by the full usage string dump. This is not considered a good usability
practice.
This commit switches all direct usage -> return patterns, where the
argument check has no other constraint, eg. dependency on an option.
Signed-off-by: David Sterba <dsterba@suse.com>
Update handling of unknown option in all commands. This will not print
only the unknown option and short pointer to help. Dumping the whole
help was a bad idea that stuck for too long.
Signed-off-by: David Sterba <dsterba@suse.com>
Even though we have --rescan option, it still needs the user to manually
specify it or call quota rescan command.
This does not make much sense for the most common usecase and only
confuses users. When the rescan is not desired, the --no-rescan option
can be used, eg. when a mass qgruop assignment happens and the repeated
rescan would slow things down. This is considered a marginal usecase.
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Similar to the changes where strerror(errno) was converted, continue
with the remaining cases where the argument was stored in another
variable.
The savings in object size are about 4500 bytes:
$ size btrfs.old btrfs.new
text data bss dec hex filename
805055 24248 19748 849051 cf49b btrfs.old
804527 24248 19748 848523 cf28b btrfs.new
Signed-off-by: David Sterba <dsterba@suse.com>
BTRFS_IOC_QGROUP_ASSIGN ioctl could return >0 if qgroup is marked
inconsistent after successful relationship assignment/removal.
We leak the return value as the final return value of btrfs command.
But according to the man page, return value other than 0 means failure.
Fix this by resetting the return value to 0 for --no-rescan case.
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
In function handle_global_options(), we reset @optind to 1.
However according to man page of getopt(3) NOTES section, if we need to
rescan options later, @optind should be reset to 0 to initialize the
internal variables correctly.
This explains the reason why in cmd_check(), getopt_long() doesn't
handle the following command correctly:
"btrfs check /dev/data/btrfs --check-data-csum"
While mkfs.btrfs handles mixed non-option and option correctly:
"mkfs.btrfs -f /dev/data/disk1 --data raid1 /dev/data/disk2"
Cc: Paul Jones <paul@pauljones.id.au>
Cc: Hugo Mills <hugo@carfax.org.uk>
Fixes: 010ceab56e ("btrfs-progs: rework option parser to use getopt for global options")
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This gets the remaining occurrences that weren't covered by previous
conversions.
Signed-off-by: Omar Sandoval <osandov@fb.com>
[ fixup test_issubvolume due to removed dependency patch ]
Signed-off-by: David Sterba <dsterba@suse.com>
btrfs_show_qgroups frees the filter and comparer in case it succeeds.
This makes the caller slightly more complicated so move the freeing up
one level.
Issue: #20
Signed-off-by: David Sterba <dsterba@suse.com>
As btrfs is specific to Linux, %m can be used instead of strerror(errno)
in format strings. This has some size reduction benefits for embedded
systems.
glibc, musl, and uclibc-ng all support %m as a modifier to printf.
A quick glance at the BIONIC libc source indicates that it has
support for %m as well. BSDs and Windows do not but I do believe
them to be beyond the scope of btrfs-progs.
Compiled sizes on Ubuntu 16.04:
Before:
3916512 btrfs
233688 libbtrfs.so.0.1
4899 bcp
2367672 btrfs-convert
2208488 btrfs-corrupt-block
13302 btrfs-debugfs
2152160 btrfs-debug-tree
2136024 btrfs-find-root
2287592 btrfs-image
2144600 btrfs-map-logical
2130760 btrfs-select-super
2152608 btrfstune
2131760 btrfs-zero-log
2277752 mkfs.btrfs
9166 show-blocks
After:
3908744 btrfs
233256 libbtrfs.so.0.1
4899 bcp
2366560 btrfs-convert
2207432 btrfs-corrupt-block
13302 btrfs-debugfs
2151104 btrfs-debug-tree
2134968 btrfs-find-root
2281864 btrfs-image
2143536 btrfs-map-logical
2129704 btrfs-select-super
2151552 btrfstune
2130696 btrfs-zero-log
2276272 mkfs.btrfs
9166 show-blocks
Total savings: 23928 (24 kilo)bytes
Signed-off-by: Rosen Penev <rosenp@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
We have to process the return value of BTRFS_IOC_TREE_SEARCH ioctl in
advance, so that we can distinguish between the two case where quota
is not enabled (ioctl return -ENOENT) and either parent qgroup or child
qgroup does not exist (update_qgroup_relation return -ENOENT). Besides
this, any error in this routine has been reported, so we don't need to
report again in cmd_qgroup_show.
Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
The sync call is unlikely to fail so we optimistically turn it to a
warning if that happens so we return inaccurate numbers instead of a
hard exit.
Signed-off-by: David Sterba <dsterba@suse.com>
The value of sort option ('S') is not used for option letter.
Therefore, I'll change the single letter to non-character.
Signed-off-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
The 'qgroup show' command does not synchronize filesystem.
Therefore, 'qgroup show' may not display the correct value unless
synchronized with 'filesystem sync' command etc.
So add the '--sync' option so that we can choose whether or not
to synchronize when executing the command.
Signed-off-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
When qgroup show is called on a filesystem that does not have quotas
enabled, the error message is very unclear:
ERROR: can't perform the search - No such file or directory
ERROR: can't list qgroups: No such file or director
Remove the error from low level helper and let the command handler
decide what to print.
Signed-off-by: David Sterba <dsterba@suse.com>
If btrfs_get_path_rootid fails, prints an error message but continues.
Replace with a helper that returns an error.
Signed-off-by: David Sterba <dsterba@suse.com>
"qgroup assign" is considered as working without any options
from the following commit.
commit 176aeca9a148 ("btrfs-progs: add getopt stubs where needed")
However, we can pass options to this command.
* actual result
==================================================
# ./btrfs qgroup assign --rescan 0/260 1/261 /btrfs
btrfs qgroup assign: unrecognized option '--rescan'
usage: btrfs qgroup assign [options] <src> <dst> <path>
Assign SRC as the child qgroup of DST
--rescan schedule qutoa rescan if needed
--no-rescan
==================================================
* expected result
==================================================
# ./btrfs qgroup assign --rescan 0/260 1/261 /btrfs
#
==================================================
Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Commands that do not take any options do not use getopt, which means the
standard option separator "--" does not work. Update all command
handlers that need it, argv needs to be referenced using the optind that
is correctly pointed after the separator.
Signed-off-by: David Sterba <dsterba@suse.com>
We can use btrfs_open_dir() to check whether target dir is
in btrfs's mount point before open, instead of checking it in
kernel space of ioctl, and return fuzzy error message.
Before patch:
# ./btrfs qgroup create 1/5 /mnt/tmp1
ERROR: unable to create quota group: Inappropriate ioctl for device
#
# ./btrfs qgroup assign 1/5 2/5 /mnt/tmp1
ERROR: unable to assign quota group: Inappropriate ioctl for device
#
# ./btrfs qgroup show /mnt/tmp1
ERROR: can't perform the search - Inappropriate ioctl for device
ERROR: can't list qgroups: Inappropriate ioctl for device
#
# ./btrfs qgroup limit 1G 1/5 /mnt/tmp1
ERROR: unable to limit requested quota group: Inappropriate ioctl for device
After patch:
# ./btrfs qgroup create 1/5 /mnt/tmp1
ERROR: not a btrfs filesystem: /mnt/tmp1
# ./btrfs qgroup assign 1/5 2/5 /mnt/tmp1
ERROR: not a btrfs filesystem: /mnt/tmp1
# ./btrfs qgroup show /mnt/tmp1
ERROR: not a btrfs filesystem: /mnt/tmp1
# ./btrfs qgroup limit 1G 1/5 /mnt/tmp1
ERROR: not a btrfs filesystem: /mnt/tmp1
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Move to use get_unit_mode_from_arg() for btrfs qgroup command,
to make "btrfs qgroup show"'s unit argument same with other
tools.
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Previous patch detecs inconsistency and unconditionally triggers quota
rescan. This may not be always desired as it's a heavy metadata
operation. In case of batch assignments it's better to trigger the
rescan at the end.
Signed-off-by: David Sterba <dsterba@suse.com>
NOTE: This patch needs to cooperate with kernel patches, which will fix
a kernel bug that never clear INCONSISTENT bit and return 1 if quota
assign makes qgroup data inconsistent.
Some qgroup assign will cause qgroup data inconsistent, like remove a
qgroup with shared extents from a parent qgroup. But some won't, like
assign a empty(OK, nodesize rfer and exel) to a qgroup.
Newer kernel will return 1 if qgroup data inconsistent and in that case
we should schedule a quota rescan.
This patch will do this in btrfs-progs.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Add a check to error out in the following case:
# ./btrfs qgroup limit T /mnt/
Invalid size argument given
Without this patch, btrfs-progs would parse the input as 0
and continue.
Signed-off-by: Dongsheng Yang <yangds.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
If we pass a negative value to command qgroup limit, btrfs-progs
would convert it to unsigned long long silently. That's a little
confusing to user, why I can limit my quota to a negative value.
This patch add a check in parse_limit, if the input value is negative,
error out to user.
Reported-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com>
Signed-off-by: Dongsheng Yang <yangds.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Currently, we can not clear a limitation on a qgroup. Although
there is a 'none' choice provided to user to do it, it does not
work well.
It does not set the flag which user want to clear, then kernel
will never know what the user want to do at all.
*Without this commit*
# ./btrfs qgroup show -re /mnt
qgroupid rfer excl max_rfer max_excl
-------- ---- ---- -------- --------
0/5 2.19GiB 2.19GiB 5.00GiB none
0/257 100.02MiB 100.02MiB none none
# ./btrfs qgroup limit none /mnt
# ./btrfs qgroup show -re /mnt
qgroupid rfer excl max_rfer max_excl
-------- ---- ---- -------- --------
0/5 2.19GiB 2.19GiB 5.00GiB none
0/257 100.02MiB 100.02MiB none none
This patch will set the flag user want to clear and pass a
size=-1 to kernel. Then kernel will clear it correctly.
*With this commit*
# ./btrfs qgroup show -re /mnt
qgroupid rfer excl max_rfer max_excl
-------- ---- ---- -------- --------
0/5 2.19GiB 2.19GiB 5.00GiB none
0/257 100.02MiB 100.02MiB none none
# ./btrfs qgroup limit none /mnt
# ./btrfs qgroup show -re /mnt
qgroupid rfer excl max_rfer max_excl
-------- ---- ---- -------- --------
0/5 2.19GiB 2.19GiB none none
0/257 100.02MiB 100.02MiB none none
Reported-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com>
Signed-off-by: Dongsheng Yang <yangds.fnst@cn.fujitsu.com>
Tested-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
We're not using it anywhere. The best practice is to add enums with
values > 255 for the long options, option index counting is error prone.
Signed-off-by: David Sterba <dsterba@suse.cz>