cmds-balance.c: In function 'cmd_balance_start':
cmds-balance.c:654:6: warning: ignoring return value of 'chdir', declared with
attribute warn_unused_result [-Wunused-result]
chdir("/");
Reported-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Currently, balance operations are run synchronously in the foreground.
This is nice for interactive management, but is kind of crappy when you
start looking at automation and similar things.
This patch adds an option to `btrfs balance start` to tell it to
daemonize prior to running the balance operation, thus allowing us to
preform balances asynchronously. The two biggest use cases I have for
this are starting a balance on a remote server without establishing a
full shell session, and being able to background the balance in a
recovery shell (which usually has no job control) so I can still get
progress information.
Because it simply daemonizes prior to calling the balance ioctl, this
doesn't actually need any kernel support.
Signed-off-by: Austin S. Hemmelgarn <ahferroin7@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
When printing the countdown in the safety delay, the number should
correspond to the number of seconds remaining to wait at the time the
delay is printed.
In other words, there should be a one second sleep after printing '1'.
Signed-off-by: Noah Massey <noah.massey@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
A short delay with a warning before starting a full balance should
improve usability. We have been getting reports from people who run full
balance after following some random advice and then get surprised by the
performance impact.
The countdown is done even when run from scripts, but as the whole
balance takes significanly more time, this shouldn't be an issue.
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>
s/*end/*start.
This makes 'btrfs balance start -dvrange=xxx..yyy' really work.
Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
We can do more with the balance usage filter. Enhance it so we can
specify also the minimum usage of the block groups to process. The
'usage' filter now accepts a range (a..b, can be partial) and needs
kernel support.
The 'usage=value' filter is equivalent to 'limit=..value' but works on
older kernels as well.
The min/max values are 32bit, unlike the single-value limit which is
64bit.
Signed-off-by: David Sterba <dsterba@suse.com>
Add the overlapping usage and [usage_min, usage_max] members to the
balance args. The min/max values are interpreted iff the corresponding
flag BTRFS_BALANCE_ARGS_USAGE_RANGE is set.
The minimum boundary is inclusive, maximum is exclusive:
* usage_min <= chunk_usage < usage_max
Signed-off-by: David Sterba <dsterba@suse.com>
Add new balance filter 'stripes=<range>' to process only chunks that are
spread accross given number of chunks.
The range minimum and maximum are inclusive.
Signed-off-by: Gabríel Arthúr Pétursson <gabriel@system.is>
[ reworked a bit to use the range helpers, dropped the single value
for stripes ]
Signed-off-by: David Sterba <dsterba@suse.com>
We can do more with the balance filter. Enhance it so we can specify
also the minimum number of block groups to process. The 'limit' filter
now accepts a range (a..b, can be partial) and needs kernel support.
The 'limit=value' filter is equivalent to 'limit=..value' but works on
older kernels as well.
The min/max values are 32bit, unlike the single-value limit which is
64bit.
Signed-off-by: David Sterba <dsterba@suse.com>
Add the overlapping limit and [limit_min, limit_max] members to the
balance args. The min/max values are interpreted iff the corresponding
flag BTRFS_BALANCE_ARGS_LIMIT_RANGE is set.
The minimum and maximum are inclusive.
Note that the values are only 32bit, but this should be enough for the
foreseeable future.
Signed-off-by: David Sterba <dsterba@suse.com>
In some cases we want to accept a range of type [a..a]. Add a new
function to do the 'a < b' check for the caller and use it.
Signed-off-by: David Sterba <dsterba@suse.com>
It's passed as const but we modify it through 'dots'. This would break
parsing the string multiple times.
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 balance start /mnt/tmp
ERROR: error during balancing '/mnt/tmp' - Inappropriate ioctl for device
There may be more info in syslog - try dmesg | tail
#
After patch:
# btrfs balance start /mnt/tmp
ERROR: not btrfs filesystem: /mnt/tmp
#
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
The 1st level balance subcommand is the right one but it accidentally
inherited the notice about 'filesystem balance' deprecation.
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>
Add more control to the balance behaviour.
Usage filter may not be finegrained enough and can lead to moving too
many chunks at once. Another example use is in connection with
drange+devid or vrange filters that allow to work with a specific chunk
or even with a chunk on a given device.
The limit filter applies last, the value of 0 means no limiting.
CC: Ilya Dryomov <idryomov@gmail.com>
CC: Hugo Mills <hugo@carfax.org.uk>
Signed-off-by: David Sterba <dsterba@suse.cz>
Remove the extraneous `to' from `Can't access to X'.
Signed-off-by: Mitchel Humpherys <mitch.special@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
If there is no balance in progress, resume/pause/cancel
will return 2. Usage or syntax errors will return 1.
And 0 means operations return successfully.
Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Reviewed-by: Ilya Dryomov <idryomov@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
These were mostly in option structs but there were a few gross string
pointer arguments given as 0.
Signed-off-by: Zach Brown <zab@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
valgrind complains open_file_or_dir() causes a memory leak.That is because
if we open a directoy by opendir(), and then we should call closedir()
to free memory.
Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
Having no balance running/ paused/completed is a normal
situation, so the current output message should be positive
with return val zero.
Signed-off-by: Anand Jain <anand.jain@oracle.com>
The coverity runs had a false positive complaining that
save_ptr is uninitialized in the call to strtok_r.
Turns out that under the covers glibc was doing enough
to confuse the checker about what was being called.
Just to keep the noise down, do a harmless initialization,
with a comment as to why.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
This is a progs counterpart to a "Btrfs: allow for selecting only
completely empty chunks". usage=0 now means "select only only
completely empty chunks and nothing else".
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
David Woodhouse originally contributed this code, and Chris Mason
changed it around to reflect the current design goals for raid56.
The original code expected all metadata and data writes to be full
stripes. This meant metadata block size == stripe size, and had a few
other restrictions.
This version allows metadata blocks smaller than the stripe size. It
implements both raid5 and raid6, although it does not have code to
rebuild from parity if one of the drives is missing or incorrect.
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
The definition of the function open_file_or_dir() is moved from common.c
to utils.c in order to be able to share some common code between scrub
and the device stats in the following step. That common code uses
open_file_or_dir(). Since open_file_or_dir() makes use of the function
dirfd(3), the required XOPEN version was raised from 6 to 7.
Signed-off-by: Anand Jain <anand.jain@oracle.com>
Original-Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
This only falls back if the plain version of balance start is used.
Any args make us report the ioctl isn't supported.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
Add balance command group under both 'btrfs' and 'btrfs filesystem'.
Preserve the old 'btrfs filesystem balance <path>' behaviour.
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>