Commit graph

42 commits

Author SHA1 Message Date
David Sterba 9150cdd7e6 btrfs-progs: rename MUST_LOG to LOG_ALWAYS
Rename MUST_LOG Use a prefix LOG_ so we can add more levels, use it
where it was hardcoded as argument to pr_verbose.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:09 +02:00
David Sterba 0e38e1c4f2 btrfs-progs: use error helper for messages in non-kernel code
Lots of code still uses fprintf(stderr, "...") that should be the
error() helper. The kernel-shared code is left out of the conversion for
now.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:07 +02:00
David Sterba 40c4ba74ec btrfs-progs: cmds: update include lists
The tool IWYU (include what you use) suggests to remove and add some
includes.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:07:59 +02:00
David Sterba 6edd4b2121 btrfs-progs: factor string helpers out of utils.c
Utils is the catch-all file, we can now separate some string utility
functions.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:06:13 +02:00
David Sterba b121ac4404 btrfs-progs: fix path to internal libbtrfsutil includes
All files include the <btrfsutil.h> which could be confused with the
system-wide installation. Drop the -I path from build and use full path
for any libbtrfsutil headers.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:06:12 +02:00
David Sterba 3df6617b9b btrfs-progs: cmds: reorder includes
The preferred order:
- system headers
- standard headers
- libraries
- kernel library
- kernel shared
- common headers
- other tools
- own headers

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:06:12 +02:00
Howard 1bce4429be btrfs-progs: subvolume snapshot: added clarity how snapshot path is interprted
A snapshot could be created in an existing directory, explain the
difference in the command line help options.

Pull-request: #117
Author: Howard <hwj@BridgeportContractor.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2022-02-16 22:48:01 +01:00
David Sterba 193cd24b24 btrfs-progs: subvol delete: more fine grained check when looking for default subvol
The search for default subvolume could fail for two reasons, the lack of
CAP_SYS_ADMIN for TREE_SEARCH ioctl is one but the default subvolume
could be unset as well, thus no restrictions for deletion.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-02-01 18:41:56 +01:00
Adam Borowski 0e66228959 btrfs-progs: subvol delete: hide a warning on an unprivileged delete
Checking the default subvolume uses TREE_SEARCH which is a CAP_SYS_ADMIN
only operation, and thus will fail when unprivileged, even if we have
permissions to actually delete the subvolume.

This produces a warning even if all is ok.  Let's hide it if we're not
root (root but !CAP is odd enough to warn).

Fixes 87804a3f06 ("btrfs-progs: subvolume: check deleting default subvolume")
Link: https://bugs.debian.org/998840
Signed-off-by: Adam Borowski <kilobyte@angband.pl>
Signed-off-by: David Sterba <dsterba@suse.com>
2022-02-01 18:41:55 +01:00
David Sterba dca6b12f0a btrfs-progs: fix read-write subvol and received_uuid flags check
There's a report that a read-only subvolume with a received_uuid set
emits the warning in command 'btrfs subvolume show', which is obviously
wrong.

The reason is that there are different types of root item flags,
depending on how we read them. The check in cmd_subvol_show uses the
ioctl GET_SUBVOL_INFO and the appropriate flag is raw
BTRFS_ROOT_SUBVOL_RDONLY (0x1), while there's another SUBVOL_GETFLAGS that
maps the flags and the raw value is different (BTRFS_SUBVOL_RDONLY, 0x2).

Due to this the warning was issued. Fix that by using the right flag
constant. The test has been extended to check for all combinations of
read-write and received_uuid.

Issue: #419
Signed-off-by: David Sterba <dsterba@suse.com>
2021-11-04 20:56:42 +01:00
David Sterba fb0bfb967f btrfs-progs: subvol find-new: copy code from btrfs-list.c
The actual implementation of find-new functionality is outside of
subvolume.c, copy it where it's supposed to be. No reformatting or style
changes.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-08 20:47:03 +02:00
David Sterba 03650851c5 btrfs-progs: split subvolume list to its own file
The main functionality of subvolume listing is now in btrfs-list.c but
there are no other commands using the API so this will be merged. It's a
lot of code so split it to another file.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-08 20:47:03 +02:00
David Sterba cb9bd8e326 btrfs-progs: subvol show: print a warning with rw and receive_uuid
Add a slightly more convenient way to identify the subvolumes with bad
combination of flags and received uuid.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-07 18:40:34 +02:00
David Sterba ad4d5b163b btrfs-progs: subvol show: print send and receive generation and timestamp
There are some send/receive related data not printed in subvol show,
while they're exported by the ioctls. Print them for convenience:

  $ btrfs subvol show test
  test
	  Name: 		test
	  UUID: 		dc16dd1b-825f-3245-94a8-557672d6cf85
	  Parent UUID: 		-
	  Received UUID: 	-
	  Creation time: 	2021-05-17 16:17:14 +0200
	  Subvolume ID: 	19112
	  Generation: 		7730702
	  Gen at creation:	7730701
	  Parent ID: 		5
	  Top level ID: 	5
	  Flags: 		-
	  Send transid: 	0
	  Send time: 		2021-05-17 16:17:14 +0200
	  Receive transid: 	0
	  Receive time: 	-
	  Snapshot(s):
				  test-snap

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-07 18:39:38 +02:00
David Sterba 419cb3011c btrfs-progs: open code btrfs_list_get_path_rootid
The function btrfs_list_get_path_rootid is exported to libbtrfs so it
needs to stay, but we can inline the implementation.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-09-08 16:35:47 +02:00
David Sterba 49671bf29e btrfs-progs: add prefixes to exported qgroup helpers
Signed-off-by: David Sterba <dsterba@suse.com>
2021-09-07 19:09:33 +02:00
David Sterba 6e0e0d467f btrfs-progs: move qgroup.h to cmds/
There are declarations that are namely for the command line out put,
filters and formatting. Move it to cmds/.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-09-07 18:45:59 +02:00
Qu Wenruo 9d5d3de01c btrfs-progs: subvol delete: try to delete subvolume by id when its path can't be resolved
There is a recent report of ghost subvolumes where such subvolumes has
no ROOT_REF/BACKREF, and 0 root ref.  But without an orphan item, thus
kernel won't queue them for cleanup.

Such ghost subvolumes are just here to take up space, and no way to
delete them except by btrfs check, which will try to fix the problem by
adding orphan item.

There is a kernel patch submitted to allow btrfs to detect such ghost
subvolumes and queue them for cleanup.

But btrfs-progs will not continue to call the ioctl if it can't find the
full subvolume path.

Thus this patch will loose the restriction by allowing btrfs-progs to
continue to call the ioctl even if it can't grab the subvolume path.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-08-20 14:24:55 +02:00
David Sterba d591cd7c08 btrfs-progs: split unit related helpers from utils.c
Signed-off-by: David Sterba <dsterba@suse.com>
2021-05-06 16:41:47 +02:00
David Sterba 7fa07e2abb btrfs-progs: split open/close helpers from utils.c
There's a group of functions that are related to opening filesystem in
various modes, this can be moved to a separate file.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-05-06 16:41:47 +02:00
David Sterba b19a603d62 btrfs-progs: remove unnecessary linux/*.h includes
Decrease dependency on system headers, remove where they're not needed
or became stale after code moved. The path-utils.h encapsulate path
operations so include linux/limits.h here, that's where PATH_MAX is
defined.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-05-06 16:41:47 +02:00
David Sterba 3c49295e8a btrfs-progs: subvol set-default: change id to 5 if specified as 0
The id 0 of the default subvolume is an internal alias for the toplevel
fs tree, kernel does that conversion. Until 2116398b1d ("btrfs-progs:
use libbtrfsutil for set-default") there was no manual conversion and
the value was passed to kernel as-is. With the switch to the
libbtrfsutil API this got broken (4.19).

  $ btrfs subvol set-default 0 /path

In this case the default subvolume would be containing subvolume of
/path instead of the toplevel one.

Fix it by manually switching the 0 to 5 in case user specifies that to
avoid the difference in the API, that we can't change.

Issue: #327
Reported-by: Chris Murphy
Signed-off-by: David Sterba <dsterba@suse.com>
2021-01-18 17:49:23 +01:00
David Sterba 022168c32d btrfs-progs: subvol show: fix required arguments in help texts
The help text and documentation of the --rootid and --uuid parameters
is wrong as it does not say there's a required parameter. Add it and
enhance the docs to clarify what the options do.

Issue: #317
Signed-off-by: David Sterba <dsterba@suse.com>
2020-12-16 17:08:52 +01:00
Su Yue b431ee33e8 btrfs-progs: subvol show: reset subvol_path to NULL after free
User reported that 'btrfs subvolume show -u -- /mnt' causes double free.

Pointer subvol_path was freed in iterations but still keeps the old
value.  In the last iteration, error BTRFS_UTIL_ERROR_STOP_ITERATION
returned, then the double free of subvol_path happens in the out goto
label.

Set subvol_path to NULL after each free() in the loop to fix the issue.

Issue: #317
Signed-off-by: Su Yue <l@damenly.su>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-12-16 17:08:52 +01:00
David Sterba 74f45db76c btrfs-progs: subvolume delete: print message for EPERM, possible send in progress
If subvolume deletion fails with EPERM, the most common reasons are that
it's a default subvolume (addressed by an earlier patch) or that the
subvolume is part of a send operation. This is printed to the system log
and there's no information available for user space, but at least the
warning can hint the user that something could be going on.

Signed-off-by: David Sterba <dsterba@suse.com>
2020-10-02 20:12:08 +02:00
Sidong Yang 87804a3f06 btrfs-progs: subvolume: check deleting default subvolume
Deleting the default subvolume is not permitted and kernel prints a
message to the system log. This is not immediately clear to the user and
we had requests to improve that.

This patch will read the default subvolume id and reject deletion
without trying to delete it.

Issue: #274
Issue: #255
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=207975
Signed-off-by: Sidong Yang <realwakka@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-10-02 20:04:08 +02:00
David Sterba abb670f883 btrfs-progs: move ctree.c to kernel-shared/
Signed-off-by: David Sterba <dsterba@suse.com>
2020-08-31 17:01:05 +02:00
David Sterba 68e26c1917 btrfs-progs: fixup spacing in help texts
Unify spacing between options and texts.

Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-29 17:45:40 +02:00
David Sterba 27a65e016e btrfs-progs: deprecate subcommand specific verbose/quiet options
Many subcommands have their own verbosity options that are being
superseded by the global options. Update the help text to reflect that
where applicable.

Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-29 17:45:40 +02:00
Anand Jain 4eb7b36534 btrfs-progs: subvolume snapshot: add global quiet option
Enable the quiet option to the subvolume snapshot command.
Does the job quietly. For example:

  $ btrfs -q subvolume snapshot <src> <dest>

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-12 19:33:07 +02:00
Anand Jain ec2e60bf55 btrfs-progs: subvolume delete: add global quiet option
Enable the quiet option to the subvolume delete command.
Does the job quietly. For example:

  $ btrfs --quiet subvolume delete <path>

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-12 19:32:47 +02:00
Anand Jain ebeaf0089d btrfs-progs: subvolume create: add global quiet option
Enable the quiet option to the subvolume create command.
Does the job quietly. For example:

  $ btrfs --quiet subvolume create <path>

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-12 19:32:39 +02:00
Anand Jain 177d307229 btrfs-progs: subvolume delete: add global verbose option
Propagate global --verbose option down to the btrfs subvolume delete
subcommand.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-12 19:31:13 +02:00
Marcos Paulo de Souza 6e85994e80 btrfs-progs: subvol delete: add --subvolid argument to deletee by id
This ioctl will be responsible for deleting a subvolume using its id.
This can be used when a system has a file system mounted from a
subvolume, rather than the root file system, like below:

/
@subvol1/
@subvol2/
@subvol_default/

If only @subvol_default is mounted, we have no path to reach @subvol1
(id 256) and @subvol2 (id 257), thus no way to delete them. Current
subvolume delete ioctl takes a file handle point as argument, and if
@subvol_default is mounted, we can't reach @subvol1 and @subvol2 from
the same mount point.

  $ mount -o subvol=subvol_default /mnt
  $ btrfs subvolume delete -i 257 /mnt

This will delete @subvol2 although it's path is hidden.

Fixes: #152
Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-03-04 19:21:09 +01:00
David Sterba a62b7854de btrfs-progs: utils: split device scanning functions to own file
All helpers and data structures that are used for device registration.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-04 02:06:34 +02:00
David Sterba b98a984f0b btrfs-progs: path-utils: rename test_isdir
Rename so it follows the path_ conventions.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-04 02:06:33 +02:00
David Sterba f83e81c61b btrfs-progs: utils: split path related utils to own file
Group helpers that return some status of a given path to own file so we
debloat utils.c a bit.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-04 02:06:31 +02:00
David Sterba add5079974 btrfs-progs: fix helpinfo formats, short and options separation
For options that do not have the long description, the empty string is
required to mark where the options start. Some commands were missing
that.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:04 +02:00
David Sterba c07960c8be btrfs-progs: move utils.[ch] to common/
Update include paths and remove some duplicates.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:04 +02:00
David Sterba aac564aca6 btrfs-progs: move commonh to common/
Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:03 +02:00
David Sterba f93b471143 btrfs-progs: move help.[ch] to common/
Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:03 +02:00
David Sterba d8bdd9e6a7 btrfs-progs: move cmds-subvolume.c to cmds/
Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-03 20:49:02 +02:00
Renamed from cmds-subvolume.c (Browse further)