Commit Graph

143 Commits (1bff5b826177ae971eb986a261839dbeb76c8a74)

Author SHA1 Message Date
David Sterba 1bff5b8261 btrfs-progs: docs: enhance subvol show documentation and help
There's a suggestion in #158 to improve the documenatation of the subvol
show command so it's more obvious what kind of information it provides.

I've updated the docs according to that and added an example that should
make the request for creation time at least greppable, the overall
description mentions 'times' so this should be enough as a pointer.

Pull-request: #158
Suggested-by: Robert Pollak <robert.pollak@posteo.net>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-01-15 18:42:13 +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
Su Yanjun 3ea85fa886 btrfs-progs: change filename limit to 255 when creating subvolume
Modify the file name length limit to meet the Linux naming convention.
In addition, the file name length is always bigger than 0, no need to
compare with 0 again.

Issue: #145
Signed-off-by: Su Yanjun <suyj.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-10-25 16:11: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
Nicholas D Steeves 0dc758d89e btrfs-progs: Fix typos in docs and user-facing strings
Signed-off-by: Nicholas D Steeves <nsteeves@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-30 22:15:54 +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 bbf7acbef0 btrfs-progs: use libbtrfsutil for subvol sync
btrfs_util_f_deleted_subvolumes() replaces enumerate_dead_subvols() and
btrfs_util_f_subvolume_info() replaces is_subvolume_cleaned().

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-06 11:28:37 +01:00
Omar Sandoval 9005b603d7 btrfs-progs: use libbtrfsutil for subvol show
Now implemented with btrfs_util_subvolume_path(),
btrfs_util_subvolume_info(), and subvolume iterators.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-06 11:28:37 +01:00
Omar Sandoval afb0426016 btrfs-progs: use libbtrfsutil for subvol delete
Most of the interesting part of this command is the commit mode, so this
only saves a little bit of code.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-06 11:28:37 +01:00
Omar Sandoval 9e73a416f0 btrfs-progs: use libbtrfsutil for get-default
The only thing of note here is the "top level" column. This used to mean
something else, but for a long time it has been equal to the parent ID.
I preserved this for backwards compatability.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-06 11:28:37 +01:00
Omar Sandoval 2116398b1d btrfs-progs: use libbtrfsutil for set-default
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-06 11:28:37 +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
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
Misono, Tomohiro 4a5b95abb6 btrfs-progs: subvol: change set-default to also accept path
This patch changes "subvol set-default" to also accept the subvolume path
for convenience.

If there are two args, they are assumed as subvol id and path to the fs
(the same as current behavior), and if there is only one arg, it is assumed
as the path to the subvolume.

subvol id is resolved by test_issubvolume() + lookup_path_rootid().
The empty subvol (ino == 2) will get error on test_issubvolume() which
checks whether inode num is 256 or not.

Issue: #35
Signed-off-by: Tomohiro Misono <misono.tomohiro@jp.fujitsu.com>
[ update documentation, use the new multi-line command scheme ]
Signed-off-by: David Sterba <dsterba@suse.com>
2017-11-14 15:59:00 +01:00
David Sterba 7b533f161c btrfs-progs: subvol: group options in help
Signed-off-by: David Sterba <dsterba@suse.com>
2017-10-06 13:41:21 +02:00
Misono, Tomohiro 8d93d71f6a btrfs-progs: subvol: fix subvol del --commit-after
Fix 'subvolume delete --commit-after' to work properly:
- SYNC ioctl will be issued even when last delete fails
- SYNC ioctl will be issued on each file system only once in the end

To achieve this, get_fsid() and add_seen_fsid() are called after each
delete to keep only one fd for each fs.

In the end, seen_fsid_hash will be traversed and SYNC is issued on each
fs.

Signed-off-by: Tomohiro Misono <misono.tomohiro@jp.fujitsu.com>
Reviewed-by: Qu Wenruo <quwenruo.btrfs@gmx.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-10-06 13:23:31 +02:00
Misono, Tomohiro 75716f6a8f btrfs-progs: subvol: exchange subvol del --commit-after and --commit-each
Current code is reversed in --commit-after and --commit-each operation,
i.e. --commit-after means --commit-each actually. This patch fixes this
and also introduces enum type for more readable code.

Signed-off-by: Tomohiro Misono <misono.tomohiro@jp.fujitsu.com>
Reviewed-by: Qu Wenruo <quwenruo.btrfs@gmx.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-10-06 13:23:26 +02:00
Anand Jain 8714e458f1 btrfs-progs: subvol show: add support to search subvolume by rootid or uuid
Unless the top level is mounted there is no way to know the
details of all the subvolume.  For example:

mount -o subvol=sv1/newsv1 /dev/sdb /btrfs

btrfs su list /btrfs
ID 257 gen 12 top level 5 path sv1
ID 258 gen 9 top level 257 path sv1/snap
ID 259 gen 11 top level 257 path sv1/newsv1

You can't subvol show for sv1 and sv1/snap as its paths aren't
accessible to the user unless the its top level is mounted.

This patch adds two new options to the existing btrfs subvol show
cli. They are --rootid/-r or --uuid/-u, with this now the user will
be able to look for a subvolume using the rootid OR the uuid.

./btrfs su show -r 257 /btrfs
sv1
	Name: 			sv1
	UUID: 			30129358-c69d-3e4a-a662-29509cc69c95
	Parent UUID: 		-
	Received UUID: 		-
	Creation time: 		2017-07-11 20:32:57 +0800
	Subvolume ID: 		257
	Generation: 		12
	Gen at creation: 	7
	Parent ID: 		5
	Top level ID: 		5
	Flags: 			-
	Snapshot(s):
				sv1/snap

Signed-off-by: Anand Jain <anand.jain@oracle.com>
[ minor adjustments in the help text ]
Signed-off-by: David Sterba <dsterba@suse.com>
2017-07-20 17:43:43 +02:00
Anand Jain b7df24aa5c btrfs-progs: subvol show: fix the path use full_path as provided by the root info
This is a kind of preparatory patch for the patch which will add
--rootid and --uuid options for the btrfs subvol show command.

As of now btrfs subvol show is using the external user provided subvol
path to show in the output. Which is kind of confusing.

btrfs su show /btrfs
/btrfs <--
	Name: 			<FS_TREE>

It will be even more confusing when proposed --uuid or --rootid
options are used.

btrfs su show --rootid 258 /btrfs
/btrfs <--
	Name: 			snap <--
	UUID: 			9630a45f-e647-4242-bd19-97590b4e20b2
	Parent UUID: 		30129358-c69d-3e4a-a662-29509cc69c95
	Received UUID: 		-
	Creation time: 		2017-07-12 12:43:28 +0800
	Subvolume ID: 		258
	Generation: 		9
	Gen at creation: 	9
	Parent ID: 		257
	Top level ID: 		257
	Flags: 			-
	Snapshot(s):

Now with this patch, it will only show what is provided by the root_info.

btrfs su show --rootid 258 /btrfs
sv1/snap <--
	Name: 			snap
	UUID: 			9630a45f-e647-4242-bd19-97590b4e20b2
	Parent UUID: 		30129358-c69d-3e4a-a662-29509cc69c95
	Received UUID: 		-
	Creation time: 		2017-07-12 12:43:28 +0800
	Subvolume ID: 		258
	Generation: 		9
	Gen at creation: 	9
	Parent ID: 		257
	Top level ID: 		257
	Flags: 			-
	Snapshot(s):

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-07-20 17:43:43 +02: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 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