Commit Graph

84 Commits

Author SHA1 Message Date
David Sterba 9a1550bb2d btrfs-progs: qgroup show: report unrecognized format of sort string
Let the parsing function distinguish between parsing and other errors
and use that in qgroup show.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-03-05 12:57:57 +01:00
David Sterba 88ab0824a2 btrfs-progs: qgroup show: report errors while parsing sort string
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>
2019-03-05 12:57:57 +01:00
David Sterba 6927db8ad9 btrfs-progs: qgroup: remove unused option handling
The commands create/destroy do not take any arguments so the error
hanling does not make sense here.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-03-05 12:57:57 +01:00
David Sterba f34d4c5ac0 btrfs-progs: qgroup: report unknown option
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>
2019-03-05 12:57:56 +01:00
David Sterba 4ac63ccbd8 btrfs-progs: help: don't print usage on wrong argument counts
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>
2019-03-05 12:57:56 +01:00
David Sterba 4ac44631a4 btrfs-progs: help: use unknown command option helper
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>
2019-03-05 12:57:55 +01:00
Qu Wenruo dda84b8a16 btrfs-progs: qgroup: make --rescan the default behavior after assign
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>
2018-10-31 18:24:14 +01:00
Qu Wenruo 922e555108 btrfs-progs: qgroup: Use bool to replace int for @rescan
Use more appropriate type.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-10-31 18:24:14 +01:00
David Sterba e578b59bf6 btrfs-progs: convert strerror to implicit %m
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>
2018-10-31 18:24:14 +01:00
Rosen Penev 251d32ea5c btrfs-progs: Eliminate remaining uses of strerror(errno)
%m allows a smaller filesize. Useful on embedded systems.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-10-25 16:11:40 +02:00
Qu Wenruo 51e1faee06 btrfs-progs: qgroup: don't return 1 if qgroup is marked inconsistent during relationship assignment
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>
2018-10-23 14:48:40 +02:00
Qu Wenruo 7fb70440cf btrfs-progs: Fix wrong optind re-initialization to allow mixed option and non-option
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>
2018-08-06 14:59:45 +02:00
Omar Sandoval f0a376df47 btrfs-progs: replace test_issubvolume() with btrfs_util_is_subvolume()
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>
2018-03-06 11:28:38 +01:00
Omar Sandoval ec7251486d btrfs-progs: use libbtrfsutil for sync ioctls
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-06 11:28:37 +01:00
David Sterba 7bb936f382 btrfs-progs: let callers of btrfs_show_qgroups free the buffers
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>
2018-02-16 16:59:42 +01:00
Rosen Penev e4df433b8a btrfs-progs: treewide: Replace strerror(errno) with %m.
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>
2018-01-31 15:14:03 +01:00
Lu Fengqi f0445b8a34 btrfs-progs: qgroup: move btrfs_show_qgroups's error handler to __qgroup_search
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>
2018-01-08 19:22:43 +01:00
David Sterba 1c880f34f1 btrfs-progs: move help defines to own header
Signed-off-by: David Sterba <dsterba@suse.com>
2017-03-08 13:00:45 +01:00
David Sterba 5c87a1b92c btrfs-progs: qgroup show: do not error if sync fails
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>
2017-01-25 09:48:38 +01:00
Tsutomu Itoh 6f7c540d77 btrfs-progs: qgroup: change the value of sort option
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>
2017-01-25 09:48:36 +01:00
Tsutomu Itoh bd1ac1fb1d btrfs-progs: qgroup: add sync option to 'qgroup show'
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>
2017-01-25 09:48:33 +01:00
David Sterba 7610cbf729 btrfs-progs: qgroup show: refine error messages
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>
2017-01-25 09:47:58 +01:00
David Sterba 4415ff6bcc btrfs-progs: qgroups show: clean up errno passing
We should use return value for errors, not errno.

Signed-off-by: David Sterba <dsterba@suse.com>
2017-01-25 09:47:56 +01:00
David Sterba 49cb98e5d6 btrfs-progs: rename lookup_ino_rootid
It does not resolve the inode number but path where fd has been opened.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-11-09 13:47:28 +01:00
David Sterba f2744dbc93 btrfs-progs: qgroups show: handle errors when resolving root id
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>
2016-11-09 13:47:28 +01:00
David Sterba c027c13531 btrfs-progs: remove trivial helpers for filtering functions
Signed-off-by: David Sterba <dsterba@suse.com>
2016-09-21 14:12:38 +02:00
David Sterba f551548372 btrfs-progs: do not set optind if not necessary
In the subcommand callbacks that are called just once, we don't need to
explicitly reset optind.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-07-13 19:41:55 +02:00
Satoru Takeuchi 9fa1f12caa btrfs-progs: qgroup assign: handle --no-rescan option
* actual result

   ==================================================
   # btrfs qgroup assign --no-rescan 0/260 1/261 /btrfs
   btrfs qgroup assign: unrecognized option '--no-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 --no-rescan 0/260 1/261 /btrfs
   #
   ==================================================

Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-18 14:19:29 +01:00
Satoru Takeuchi 208ba29007 btrfs-progs: qgroup assign: can't handle options
"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>
2016-03-18 14:17:11 +01:00
Satoru Takeuchi 5bec887333 btrfs-progs: qgroup create/destroy: fix argument parsing
"qgroup create/destroy" don't work from the following commit.

commit 176aeca9a148 ("btrfs-progs: add getopt stubs where needed")

* actual result

   ==================================================
   # ./btrfs qgroup create 1 /btrfs/sub
   btrfs qgroup create: too few arguments
   usage: btrfs qgroup create <qgroupid> <path>

       Create a subvolume quota group.
   ==================================================
   # btrfs qgroup create 1 /btrfs/sub
   # ./btrfs qgroup destroy 1 /btrfs/sub
   btrfs qgroup destroy: too few arguments
   usage: btrfs qgroup destroy <qgroupid> <path>

       Destroy a quota group.

   ==================================================

* expected result

   ==================================================
   # btrfs qgroup create 1 /btrfs/sub
   # btrfs qgroup destroy 1 /btrfs/sub/
   ==================================================

Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-18 14:12:19 +01:00
David Sterba f4fc6efa4b btrfs-progs: rename commandline helpers
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-14 13:42:47 +01:00
David Sterba babe94e481 btrfs-progs: add getopt stubs where needed
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>
2016-03-14 13:42:47 +01:00
David Sterba dddc3e08cb btrfs-progs: more verbose errors from test_issubvolume
Signed-off-by: David Sterba <dsterba@suse.com>
2016-01-14 11:07:10 +01:00
David Sterba df3a134d0e btrfs-porgs: qgroup: rename variable to avoid shadowing
Reported by gcc -Wshadow .

Signed-off-by: David Sterba <dsterba@suse.com>
2016-01-12 15:02:56 +01:00
David Sterba 633dc6f80f btrfs-progs: remove unnecessary errno temp variables
We can read errno directly if it's not clobbered by any intermediate
calls.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-01-12 15:02:55 +01:00
David Sterba e3926b4dc8 btrfs-progs: cmd qgroup: switch to common error message wrapper
Message texts were adjusted.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-01-12 15:02:52 +01:00
David Sterba 49e0f3e646 btrfs-progs: utils: rename helpinfo unit vairables
Signed-off-by: David Sterba <dsterba@suse.com>
2015-11-06 16:39:49 +01:00
Eryu Guan 1669d8afa6 btrfs-progs: fix memory leak in cmd_qgroup_show()
filter_set and comparer_set should be freed on return.

Signed-off-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2015-11-02 09:35:03 +01:00
Zhao Lei bbbe7fd7d0 btrfs-progs: qgroup: use btrfs_open_dir for btrfs qgroup command
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>
2015-11-02 09:35:01 +01:00
Zhao Lei 71d856ba3c btrfs-progs: Use common unit parser for btrfs qgroup command
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>
2015-09-01 14:01:59 +02:00
David Sterba c78f3eea94 btrfs-progs: doc: update qgroup docs
Signed-off-by: David Sterba <dsterba@suse.com>
2015-08-31 19:25:11 +02:00
David Sterba e5a6610c94 btrfs-progs: qgroup assign: add option to schedule rescan
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>
2015-08-31 19:25:11 +02:00
David Sterba 79a851f143 btrfs-progs: qgroup assign: set path after checking argument count
Signed-off-by: David Sterba <dsterba@suse.com>
2015-08-31 19:25:11 +02:00
Qu Wenruo 62ae6b2bf2 btrfs-progs: Schedule quota rescan if qgroup assign caused inconsistence.
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>
2015-08-31 19:25:11 +02:00
David Sterba 330709ee13 btrfs-progs: add command group info strings
They're printed in the 'btrfs' command group summary.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-09 14:26:33 +02:00
Dongsheng Yang d91f5ef091 btrfs-progs: qgroup limit: add a check for invalid input of 'T/G/M/K'
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>
2015-06-05 18:45:21 +02:00
Dongsheng Yang d9fd7cc0f5 btrfs-progs: qgroup limit: error out if input value is negative
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>
2015-06-05 18:40:32 +02:00
Dongsheng Yang ea496435d5 btrfs-progs: qgroup: allow user to clear some limitation on qgroup.
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>
2015-06-05 18:36:55 +02:00
David Sterba 08f9acadab btrfs-progs: getopt, use symbolic name for argument requirements
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-04-08 17:39:51 +02:00
David Sterba 4074ae5f2b btrfs-progs: cleanup option index argument from getopt_long
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>
2015-04-08 17:33:55 +02:00