Commit Graph

123 Commits

Author SHA1 Message Date
David Sterba 86d2e4b64b btrfs-progs: remove extra newline from messages
The common message helpers add the newline.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-12-14 15:06:34 +01:00
David Sterba d4aa2bc07e btrfs-progs: subvol show: print more details about toplevel subvolume
The toplevel subvolume is special and the other listing code leaves it
out so we have to add several special cases to handle it. There's no
backreference so the path is built artificially. New helper
btrfs_get_toplevel_subvol is a reduced version of btrfs_get_subvol.

There's some information usually missing for the toplevel subvolume, eg.
the uuid or creation info. This has to be fixed on the mkfs side, the
other subvolumes are created by kernel.

Example:
/mnt
        Name:                   <FS_TREE>
        UUID:                   -
        Parent UUID:            -
        Received UUID:          -
        Creation time:          -
        Subvolume ID:           5
        Generation:             233
        Gen at creation:        0
        Parent ID:              0
        Top level ID:           0
        Flags:                  -
        Snapshot(s):
                                subv1

Signed-off-by: David Sterba <dsterba@suse.com>
2016-11-09 13:47:29 +01:00
David Sterba f52b559873 btrfs-progs: subvol list: cleanup layout argument setup
Signed-off-by: David Sterba <dsterba@suse.com>
2016-11-09 13:47:29 +01:00
David Sterba 8df2d94bf9 btrfs-progs: subvol list: setup list filters later
First check for arguments and whether we can open the filesystem.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-11-09 13:47:29 +01:00
David Sterba 1c85c3de5a btrfs-progs: use existing rootid resolving helper in btrfs_list_get_path_rootid
The utils helper is not verbose in case of an error, for now the helper
used for subvolume listing will print the error message but not
duplicate the ioctl anymore.

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 eccba6261a btrfs-progs: subvol create: remove v from getopt
The option 'v' was mistakenly added in
2ed161bd28 but there's no such option for
create at the moment, remove it.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-09-21 11:50:38 +02:00
Vincent Batts c68759eaa6 btrfs-progs: subvol delete: add missing verbose option
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>
2016-09-21 11:50:35 +02:00
David Sterba 49184a737b btrfs-progs: switch ternary op to an if in cmd_subvol_show
Signed-off-by: David Sterba <dsterba@suse.com>
2016-08-19 15:45:04 +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
Marek Rusinowski a6bbbe6087 btrfs-progs: subvolume sync: fix handling of -s option
Setting check interval for subvolume sync resulted
in picking wrong element from argv for it's value:

  $ btrfs subvolume sync -s 10 ./dir
  ERROR: invalid sleep interval ./dir
  $ btrfs subvolume sync ./dir -s 10
  Segmentation fault

Signed-off-by: Marek Rusinowski <marekrusinowski@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-05-11 16:37:12 +02:00
David Sterba 1e4abbdf96 btrfs-progs: use ioctl search headers everywhere
Generated by following semantic patch and manually tweaked.

<SmPL>
@@
struct btrfs_ioctl_search_header *SH;
@@
(
- SH->objectid
+ btrfs_search_header_objectid(SH)
|
- SH->offset
+ btrfs_search_header_offset(SH)
|
- SH->transid
+ btrfs_search_header_transid(SH)
|
- SH->len
+ btrfs_search_header_len(SH)
|
- SH->type
+ btrfs_search_header_type(SH)
)
</SmPL>

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=112131
Reported-and-tested-by: Anatoly Pugachev <matorola@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-05-11 15:53:16 +02:00
Anand Jain e494f5790f btrfs-progs: create get_subvol_info()
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>
2016-03-30 16:25:28 +02:00
Anand Jain a5dbd2064e btrfs-progs: move test_issubvolume() to utils.c
Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2016-03-30 16:25:13 +02:00
Satoru Takeuchi d0408017d0 btrfs-progs: subvol get-default: fix argument parsing
"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>
2016-03-18 14:10:12 +01:00
David Sterba cdd1bae403 btrfs-progs: subvol sync: fix memory corruption, undersized array
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>
2016-03-17 11:41:18 +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 62cb593894 btrfs-progs: subvol show: use clean_args_no_options instead of opencoding
Signed-off-by: David Sterba <dsterba@suse.com>
2016-01-14 11:07:10 +01:00
David Sterba 7faf96e30a btrfs-progs: also check filesystem type in test_issubvolume
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>
2016-01-14 11:07:10 +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 7afde59e38 btrfs-progs: let test_issubvolume return the exact error
Return any error from stat, minor cleanups.

Signed-off-by: David Sterba <dsterba@suse.com>
2016-01-14 11:07:10 +01:00
David Sterba 33ac47b5fb btrfs-progs: use symbolic name for subvolume inode number in test_issubvolume
Signed-off-by: David Sterba <dsterba@suse.com>
2016-01-14 11:07:10 +01:00
David Sterba 5b56fe9db5 btrfs-progs: handle errors from test_isdir
Signed-off-by: David Sterba <dsterba@suse.com>
2016-01-14 11:07:09 +01:00
David Sterba 0aa796cad7 btrfs-progs: subvol show: handle options by getopt
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>
2016-01-13 16:43:48 +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 e7e759017d btrfs-progs: cmd subvolume: 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
Zhao Lei 2dfb710803 btrfs-progs: subvolume: use btrfs_open_dir for btrfs subvolume 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:
  # (/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>
2015-11-02 09:35:00 +01:00
David Sterba d3be5b65da btrfs-progs: subvol sync: fix reversed condition
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>
2015-10-07 12:13:47 +02:00
Zhao Lei 07cc891d1d btrfs-progs: Simplify all-subvolumn-clean condition for wait_for_subvolume_cleaning
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>
2015-09-01 14:02:49 +02:00
Zhao Lei 601c5e1b23 btrfs-progs: Simplify memory allocation for enumerate_dead_subvols
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>
2015-09-01 14:02:49 +02:00
Zhao Lei 298746b958 btrfs-progs: Fix wrong return value of wait_for_subvolume_cleaning()
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>
2015-09-01 14:02:49 +02:00
Zhao Lei 6425752ab2 btrfs-progs: Fix infinite loop of btrfs subvolumn sync
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>
2015-09-01 14:02:48 +02:00
Zhao Lei 64650e13bb btrfs-progs: remove code for setup mntid in cmd_subvol_show
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>
2015-08-31 19:25:14 +02:00
David Sterba c6cf9778e8 btrfs-progs: unify naming of command handlers
Use cmd_ + group + command schema.

Signed-off-by: David Sterba <dsterba@suse.com>
2015-08-31 19:25:09 +02:00
David Sterba 6a039e5063 btrfs-progs: properly set up ioctl arguments
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>
2015-06-12 16:44:48 +02:00
David Sterba 76a9be2e72 btrfs-progs: add helper to wait for subvolume cleaning
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-09 19:36:30 +02:00
David Sterba c9f885ec89 btrfs-progs: subvol: let sync check only current deletions
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>
2015-06-09 18:18:19 +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
David Sterba d020af5235 btrfs-progs: subvol show: tweak output
- 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>
2015-06-03 12:52:56 +02:00
David Sterba 67db275e90 btrfs-progs: subvol show: print received uuid
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-06-03 12:52:52 +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 2b7cdab425 btrfs-progs: make getopt tables static const
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-01-19 13:44:49 +01:00
David Sterba ecbf1339a6 btrfs-progs: cleanup, move getop long options close to their use
Move long_option defintions just before getopt_long everywhere.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-01-19 13:30:06 +01:00
Gui Hecheng 3d47cc9ae1 btrfs-progs: remove uneccessary subvol name check for subvol deletion
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>
2015-01-14 18:34:04 +01:00
Martin Volf 3b7a87d795 btrfs-progs: Remove redundant short description from cmd_snapshot_usage
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>
2015-01-14 02:20:26 +01:00
David Sterba 1519ee3f58 btrfs-progs: subvol delete: rename variable to match the option name
Signed-off-by: David Sterba <dsterba@suse.cz>
2014-12-10 16:04:08 +01:00
David Sterba 2ed161bd28 btrfs-progs: subvol delete: add verbosity option
Add an the option -v and use it for the transaction commit mode message.

Signed-off-by: David Sterba <dsterba@suse.cz>
2014-12-10 16:04:04 +01:00
David Sterba 47bbff777e btrfs-progs: let subvol delete print commit mode inline
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>
2014-12-10 15:46:17 +01:00
Gui Hecheng 05afee3468 btrfs-progs: fix return value problem for btrfs sub show
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>
2014-11-27 18:36:55 +01:00
David Sterba 6420192e87 btrfs-progs: wait until all subvolumes are cleaned
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>
2014-10-10 09:32:05 +02:00