There was already the logic for verbose output, but the flag parsing did
not include it.
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
Signed-off-by: David Sterba <dsterba@suse.com>
get_subvol_info() is useful as we are adding more features around
subvolume. This function was inline with the function
cmd_subvol_show().
Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
"sub get-default" does't work since the following commit.
commit 176aeca9a148 ("btrfs-progs: add getopt stubs where needed")
* actual result
==================================================
# ./btrfs sub get-default /btrfs
btrfs subvolume get-default: too few arguments
usage: btrfs subvolume get-default <path>
Get the default subvolume of a filesystem
==================================================
* expected result
==================================================
# btrfs sub get-default /btrfs
ID 5 (FS_TREE)
==================================================
Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
The subvol sync command crashed randomly at the end with
*** glibc detected *** btrfs: double free or corruption (out): 0x00000000006ab040 ***
This is caused by running out of the ids array in case there are more
than 128 subvolumes. The array is increased in steps but does not
account the size of the item, so there was room for 1024 / 8 = 128
subvolume ids.
Fixes: c9f885ec89 ("btrfs-progs: subvol: let sync check only current deletions")
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>
A subvolume is a directory with inode number 256 on a btrfs filesytem.
Add the missing check to test_issubvolume for completeness, otherwise we
always do that in btrfs_open_dir.
Signed-off-by: David Sterba <dsterba@suse.com>
The subvolume show command does not take any optios but at least it
should honor "--", as reported.
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=110181
Reported-by: <moviuro+kernel@gmail.com>
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:
# (/mnt/tmp is not btrfs mountpoint)
#
# btrfs subvolume create /mnt/tmp/123
Create subvolume '/mnt/tmp/123'
ERROR: cannot create subvolume - Inappropriate ioctl for device
#
After patch:
# btrfs subvolume create /mnt/tmp/123
ERROR: not btrfs filesystem: /mnt/tmp
#
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
In my local change to 07cc891d1d
("btrfs-progs: Simplify all-subvolumn-clean condition for
wait_for_subvolume_cleaning") that reversed the meaning of the variable
dirty -> clean, I made a mistake and broke 'subvol sync' that will not
wait as expected and ends prematurely. Zhao Lei's original patch worked.
CC: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Instead of using a dirty-subvolumn-counter in old code, this patch
turn to use a simple and direct way:
If (not dirty-subvolumn found in current loop) {
return all_clean;
}
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
No need prepare memory for enumerate_dead_subvols() in caller, and pass
additional argument for allocated length.
Just do every thing inside enumerate_dead_subvols(), it will not
increase malloc count, but make code simple.
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Reproduce:
# btrfs subvolume sync /mnt/btrfs
Subvolume id 323 is gone
# echo $?
1
#
Reason:
wait_for_subvolume_cleaning() return !0 in right case, because
value of ret is set to "is subvolume clean" state before return.
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
We can trigger the bug by following operation:
(no wait between commands 3~5)
btrfs subvolume create /mnt/btrfs/mysubvol
btrfs subvolume snapshot /mnt/btrfs/mysubvol /mnt/btrfs/mysubvol_snap
btrfs subvolume delete /mnt/btrfs/mysubvol_snap
btrfs subvolume delete /mnt/btrfs/mysubvol
btrfs subvolume sync /mnt/btrfs
The last command will not exit.
Reason:
List of "deleted subvolumes" are not currectly set.
It caused by a typo of value assign, in detail:
*ids[idx] = sh->offset;
should be:
(*ids)[idx] = sh->offset;
So only first element is set to right memory address.
If there are multiple "deleted subvolumes", program will
keep wait.
Above typo also caused some segment fault in my test.
This patch fixed above bug.
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
We don't need to use value of mntid in cmd_subvol_show(), no need
to get its value.
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
At some places we do not clear the whole ioctl structure and could
pass garbage to kernel. Zero the ioctl vol_args and use a helper for
copying the path.
Signed-off-by: David Sterba <dsterba@suse.cz>
So far the subvol sync command takes a shortcut and looks if there are
any deleted subvols at all. It does not print the deleted subvolumes as
they get cleaned. Arguably this is what the user would like to see and
has to do
$ btrfs subvol sync /path $(btrfs subvol list -d /path | "extract the ids")
to see the progress.
Make it look for all currently deleted subvolumes automatically and
print the progress as if the ids were listed manually.
This is a slight change in the semantics of the command. Previously, any
new subvol deletion would prevent subvol sync to return. To simulate the
old behaviour, run 'subvol sync' in a loop until it returns 0.
Signed-off-by: David Sterba <dsterba@suse.cz>
- capitalize UUID
- print otime with timezone
- rename 'Object ID' to 'Subvolume ID'
- add ID to Parent and Top level
Signed-off-by: David Sterba <dsterba@suse.cz>
When we want to delete a subvol, we first check to see whether it is
a subvolume or not. After the check, we are sure that it is a valid
subvol, don't have to check its name.
Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
[removed unused variable 'len']
Signed-off-by: David Sterba <dsterba@suse.cz>
cmd_snapshot_usage in cmds-subvolume.c contains the short description
twice. Remove the first one.
Signed-off-by: Martin Volf <martin.volf.42@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
There are options to specify if the subvolume deletion should wait for
commit after each subvol or at the end. This is reported at the
beginning and considered as a noise. We'd like to report the mode for
each subvolume instead.
http://www.mail-archive.com/linux-btrfs%40vger.kernel.org/msg34617.html
Reported-by: Marc MERLIN <marc@merlins.org
Signed-off-by: David Sterba <dsterba@suse.cz>
If you exec:
# btrfs sub show <dir> <== non-subvolume dir
The cmd print error messages as expected, but returns 0.
By convetion, it should return non-zero and we should explicitly
set it before it goto out.
With other pieces adopted:
1) removed a unnecessary return value set -EINVAL
2) fixed another code branch which may return 0 upon error.
3) with 2) applied, the ret = 0 follows can be removed
Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Enhance the 'subvolume' subcommand to wait until a given list of
subvolumes or all currently scheduled for deletion are cleaned
completely from the filesystem.
Signed-off-by: David Sterba <dsterba@suse.cz>
When using send/receive, it it useful to be able to match up source
subvols on the send side (as, say, for -p or -c clone sources) with their
corresponding copies on the receive side. This patch adds a -R option to
btrfs sub list to show the received subvolume UUID on the receive side,
allowing the user to perform that matching correctly.
Signed-off-by: Hugo Mills <hugo@carfax.org.uk>
Signed-off-by: David Sterba <dsterba@suse.cz>
Since test_isdir() is a utility function, it's better to
move it to utils.c. In addition, "const char *" is
more appropriate type as its "path" argument because
this argument is not changed in this function.
Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Cc: David Sterba <dsterba@suse.cz>
Cc: Mike Fleetwood <mike.fleetwood@googlemail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
There are many duplicated codes to check if the given string is
correct subvolume name. Introduce test_issubvolname() for this
purpose for simplicity.
Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Cc: David Sterba <dsterba@suse.cz>
Cc: Mike Fleetwood <mike.fleetwood@googlemail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
When calling find_mount_root(), caller in fact wants to find the mount
point of *BTRFS*.
So also check ent->fstype in find_mount_root() and do special error
string output in caller.
This will suppress a lot of "Inapproiate ioctl for device" error
message.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Switch to new helper arg_strtou64(), also check if user assign
a valid super copy.
Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>