Commit graph

66 commits

Author SHA1 Message Date
David Sterba cb740b3dfb btrfs-progs: fi show: canonicalize path when using blkid and -d
There's a report that passing raw device mapper path and -d don't work
together:

  yyy@xxx ~ $ sudo btrfs filesystem show /dev/dm-0
  Label: none  uuid: a7fbb8d6-ec5d-4e88-bd8b-c686553e0dc7
	  Total devices 1 FS bytes used 144.00KiB
	  devid    1 size 256.00MiB used 88.00MiB path /dev/mapper/da0972636816-LogVol00

  With --all-devices

  yyy@xxx ~ $ sudo btrfs filesystem show --all-devices /dev/dm-0
  ERROR: not a valid btrfs filesystem: /dev/dm-0

Where dm-0 corresponds to the LogVol00 device from above.

Passing the option -d skips some steps but still uses the real path of
the device that is required for scanning and identification, while
blkid uses the canonicalized path.

The combination of raw device name and -d was not handled as the raw
path is not in cache and thus not recognized. Canonicalization fixes
that although this changes the device name in the output.

Issue: #732
Signed-off-by: David Sterba <dsterba@suse.com>
2024-01-31 11:07:39 +01:00
Qu Wenruo 389c959d6d btrfs-progs: implement arg_strtou64_with_suffix() with a new helper
This patch introduces a new parser helper, parse_u64_with_suffix(),
which has a better error handling, following all the parse_*()
helpers to return non-zero value for errors.

This new helper is going to replace parse_size_from_string(), which
would directly call exit(1) to stop the whole program.

Furthermore most callers of parse_size_from_string() are expecting
exit(1) for error, so that they can skip the error handling.

For those call sites, introduce a wrapper, arg_strtou64_with_suffix(),
to do that.  The only disadvantage is a little less detailed error
report for why the parse failed, but for most cases the generic error
string should be enough.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-01-18 02:14:23 +01:00
David Sterba c08071e7be btrfs-progs: resize: properly return error from check_resize_args
The function almost always returns 0 even for errors as the ret value is
not used in the final return. This was attempted to be fixed in
55438f3930 ("btrfs-progs: resize: return error value from
check_resize_args()") but this broke 'resize cancel' when devid 1 was
missing and was later reverted as 4286eb552e ("Revert "btrfs-progs:
resize: return error value from check_resize_args()"").

The devid fallback has been fixed so the proper return value can be
returned now.

Issue: #539
Signed-off-by: David Sterba <dsterba@suse.com>
2023-11-03 18:04:37 +01:00
David Sterba b64f8437b6 btrfs-progs: resize: fallback to lowest devid when 1 does not exist
The implicit devid is 1 but when it does not exist then the command
'btrfs fi resize max /path' fails and requires the user to specify the
number (and finding it elsewhere, e.g. in 'btrfs fi us -T' output).

This is a usability bug, we can verify if devid 1 exists and use the
lowest devid as a fallback. This does what user would expected, though
there's still a warning. Kernel has the hardcoded devid 1 when none is
specified, with this fix in user space the kernel does not need to be
changed (or could behave the same eventually).

Example use:

  $ btrfs fi us -T .
		Data      Metadata  System
  Id Path       single    single    single   Unallocated Total   Slack
  -- ---------- --------- --------- -------- ----------- ------- -----
   4 /dev/loop3         -         -        -     4.00GiB 4.00GiB     -
  -- ---------- --------- --------- -------- ----------- ------- -----
     Total      416.00MiB 256.00MiB 64.00MiB     4.00GiB 4.00GiB 0.00B
     Used           0.00B 128.00KiB 16.00KiB

  $ btrfs fi resize max .
  WARNING: no devid specified means devid 1 which does not exist, using
           lowest devid 4 as a fallback
  Resize device id 4 (/dev/loop3) from 4.00GiB to max

Issue: #470
Signed-off-by: David Sterba <dsterba@suse.com>
2023-11-03 18:04:37 +01:00
David Sterba 93f263650c btrfs-progs: fi defrag: add new option to process the range in steps
Add a convenience option to processing the range in smaller steps than
the whole file, where a flush is done after each steps. This could be
potentially used to measure progress with 'btrfs -vv fi defrag'.

Issue: #616
Signed-off-by: David Sterba <dsterba@suse.com>
2023-11-03 18:04:37 +01:00
David Sterba 21aa6777b2 btrfs-progs: clean up includes, using include-what-you-use
Signed-off-by: David Sterba <dsterba@suse.com>
2023-10-03 01:11:57 +02:00
Anand Jain a11d468e98 btrfs-progs: rename fs_devices::list to match the kernel
Aligning with the kernel's struct btrfs_fs_devices:fs_list, rename
btrfs_fs_devices::list to btrfs_fs_devices::fs_list.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-08-28 17:24:58 +02:00
Anand Jain d46a0ef6a0 btrfs-progs: rename struct open_ctree_flags to open_ctree_args
The struct open_ctree_flags currently holds arguments for
open_ctree_fs_info(), it can be confusing when mixed with a local variable
named open_ctree_flags as below in the function cmd_inspect_dump_tree().

  cmd_inspect_dump_tree()
  ::
  struct open_ctree_flags ocf = { 0 };
  ::
  unsigned open_ctree_flags;

So rename struct open_ctree_flags to struct open_ctree_args.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-07-26 15:00:47 +02:00
Josef Bacik a754fe29d9 btrfs-progs: sync uapi/btrfs.h into btrfs-progs
We want to keep this file locally as we want to be uptodate with
upstream, so we can build btrfs-progs regardless of which kernel is
currently installed.  Sync this with the upstream version and put it in
kernel-shared/uapi to maintain some semblance of where this file comes
from.

There are some changes that need to be synced back to kernel. A local
definition of static_assert is used to avoid compilation problems on gcc
(< 9) due to mandatory 2nd parameter.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-05-26 18:02:28 +02:00
David Sterba 5dd9506409 btrfs-progs: filesystem: convert help text to option formatter
Signed-off-by: David Sterba <dsterba@suse.com>
2023-02-28 20:11:23 +01:00
Qu Wenruo f61b90aff9 btrfs-progs: make usage call properly return an exit value
[BUG]
Currently cli/009 test case failed with different exit number:

  ====== RUN CHECK /home/adam/btrfs-progs/btrfstune --help
  usage: btrfstune [options] device
  [...]
  failed: /home/adam/btrfs-progs/btrfstune --help
  test failed for case 009-btrfstune

[CAUSE]
In tune/main.c, we have the following call on usage():

  static void print_usage(int ret)
  {
	usage(&tune_cmd);
	exit(ret);
  }

However usage() itself would always call exit(1):

  void usage(const struct cmd_struct *cmd)
  {
	usage_command_usagestr(cmd->usagestr, NULL, 0, true, true);
	exit(1);
  }

This makes prevents any caller of usage() to modify its exit number.

[FIX]
Add a new argument @error for print_usage(), so we can properly return 0
for -h/--help usage.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-02-28 20:11:23 +01:00
David Sterba b08b429ee2 btrfs-progs: fi mkswapfile: add option --uuid
Add option --uuid with same semantics that is provided by command
'mkswap'. By default a random UUID is generated, to not set any use
'btrfs filesystem mkswapfile -U clear swapfile'.

Issue: #581
Signed-off-by: David Sterba <dsterba@suse.com>
2023-02-28 20:11:22 +01:00
David Sterba 54b90cb6e5 btrfs-progs: fi mkswapfile: fix page count in header
Per user report on https://old.reddit.com/r/btrfs/comments/107fnw1/btrfs_filesystem_mkswapfile_results_in_an/
the swapfile header does not contain the correct number of pages that
matches the file size and the activated swapfile is only 1GiB:

  # btrfs filesystem mkswapfile -s 10g swapfile
  # swapon swapfile
  # cat /proc/swaps
  Filename          Type    Size       Used    Priority
  /swap/swapfile    file    1048572    0       -2

A workaround is to run 'mkswap swapfile' before activation. Proper fix
is to calculate the number of (fixed size) 4K pages available for the
swap.

Issue: #568
Signed-off-by: David Sterba <dsterba@suse.com>
2023-01-25 16:19:36 +01:00
David Sterba 427bf75a1e btrfs-progs: fi mkswapfile: update help text
The help text of mkswapfile was a copy&paste leftover, fix it.

Issue: #554
Signed-off-by: David Sterba <dsterba@suse.com>
2022-12-06 23:19:13 +01:00
David Sterba 0b3df991db btrfs-progs: fi df: implement json output
Print JSON output with example output:

  $ btrfs --format json filesystem df /path
  {
    "__header": {
      "version": "1"
    },
    "filesystem-df": [
      {
	"bg-type": "Data",
	"bg-profile": "single",
	"total": "841813590016",
	"used": "494085484544"
      },
      {
	"bg-type": "System",
	"bg-profile": "single",
	"total": "33554432",
	"used": "114688"
      },
      {
	"bg-type": "Metadata",
	"bg-profile": "single",
	"total": "24696061952",
	"used": "5743165440"
      },
      {
	"bg-type": "GlobalReserve",
	"bg-profile": "single",
	"total": "536870912",
	"used": "0"
      }
    ]
  }

Optionally there's "zone_unusable" key. The rowspec cannot print the
same output as now so the original implementation is preserved.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-12-06 21:03:31 +01:00
Josef Bacik 788a71c16a btrfs-progs: sync compression.h from the kernel
This patch copies in compression.h from the kernel.  This is relatively
straightforward, we just have to drop the compression types definition
from ctree.h, and update the image to use BTRFS_NR_COMPRESS_TYPES
instead of BTRFS_COMPRESS_LAST, and add a few things to kerncompat.h to
make everything build smoothly.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2022-11-30 19:14:29 +01:00
David Sterba 9b9216668d btrfs-progs: defrag: fix verbosity with default level
Defrag should not print the filenames by default, this got accidentally
changed in v6.0. Do a workaround that restores the original behaviour,
ie. no filenames and print them with -v, either as global or local
option. Proper fix is not to initialize with BTRFS_BCONF_UNSET and only
adjust the levels by -v/-q options.

Issue: #540
Signed-off-by: David Sterba <dsterba@suse.com>
2022-11-24 17:29:12 +01:00
David Sterba 4286eb552e Revert "btrfs-progs: resize: return error value from check_resize_args()"
This reverts commit 55438f3930.

The patch breaks resize cancel.

Reproducer:

    #!/bin/bash

    fallocate -l 7g /var/tmp/7g1 && fallocate -l 7g /var/tmp/7g2

    thing1=$(sudo losetup --show -f /var/tmp/7g1)
    thing2=$(sudo losetup --show -f /var/tmp/7g2)

    echo Make the fs
    mkfs.btrfs -L test539 $thing1
    mkdir test539
    mount -L test539 test539

    echo Get rid of devid:1 by adding a new device and removing the original
    btrfs dev add $thing2 test539
    btrfs dev del $thing1 test539
    echo Creating wiggleroom
    fallocate -l 3g test539/3g1 && fallocate -l 3g test539/3g2
    rm test539/3g1

    echo Start a resize operation and wait 3s to run a cancel
    echo Under 6.0 cancel, under 6.0.1 no cancel and runs out of space
    btrfs fi re 2:-4g test539 &
    sleep 3s && btrfs fi re cancel test539
    wait

    echo Cleanup
    umount test539

    losetup -d $thing1 && losetup -d $thing2

    rm /var/tmp/7g{1,2}
    rmdir test539

Issue: #539
Signed-off-by: David Sterba <dsterba@suse.com>
2022-11-24 17:26:24 +01:00
David Sterba 90548b8295 btrfs-progs: filesystem: new subcommand mkswapfile
Add a command to create a new swapfile. The same can be achieved by
seandalone tools but they're just wrappers around the syscalls. The swap
format is simple enough to be created directly without mkswap command so
the swapfile can be created in one go.

The file must not exist before, this is to avoid problems with file
attributes or any other effects of existing extents. This also means the
command can't be used on block devices.

Default size is 2G, minimum size is 40KiB.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-11-08 11:30:21 +01:00
Sidong Yang 55438f3930 btrfs-progs: resize: return error value from check_resize_args()
check_resize_args() function checks user argument amount but does not
return the correct value in case it's not valid.

Signed-off-by: Sidong Yang <realwakka@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-18 15:57:59 +02:00
David Sterba b2729396d2 btrfs-progs: cmds: use bool for status variables
Using bool for on/off variables is cleaner, convert all in cmds/ .

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:12 +02:00
David Sterba fb6e0c5448 btrfs-progs: filesystem: use pr_verbose and pr_stderr for messages
Replace printing to stderr and stdout by the level-aware helper. No
change for commands that don't have the global -q/-v options, otherwise
the output can be quieted.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:11 +02:00
David Sterba b0fcdb9224 btrfs-progs: cmds: remove unnecessary casts for u64
The (unsigned long long) type casts can be dropped, printf understands
%llu and u64 and does not warn. In cases where the type is not u64 keep
the cast.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:11 +02:00
David Sterba 285e9786da btrfs-progs: filesystem: use pr_verbose for messages
Replace printf by the level-aware helper. No change for commands that
don't have the global -q/-v options, otherwise the output can be
quieted.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:11 +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 d04a1fa10e btrfs-progs: factor filesystem helpers out of utils.c
Group helpers that retrieve information from the filesystem out of
utils.c.

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
Nikolay Borisov 957a79c9b0 btrfs-progs: fi show: print missing device for a mounted file system
Currently when a device is missing for a mounted filesystem the output
that is produced is unhelpful:

Label: none  uuid: 139ef309-021f-4b98-a3a8-ce230a83b1e2
	Total devices 2 FS bytes used 128.00KiB
	devid    1 size 5.00GiB used 1.26GiB path /dev/loop0
	*** Some devices missing

While the context which prints this is perfectly capable of showing
which device exactly is missing, like so:

Label: none  uuid: 4a85a40b-9b79-4bde-8e52-c65a550a176b
	Total devices 2 FS bytes used 128.00KiB
	devid    1 size 5.00GiB used 1.26GiB path /dev/loop0
	devid    2 size 0 used 0 path /dev/loop1 MISSING

This is a lot more usable output as it presents the user with the id
of the missing device and its path.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2022-08-16 15:18:11 +02:00
Adam Borowski 6da5478a38 btrfs-progs: fix a bunch of typos
These have been detected by lintian and codespell.

Signed-off-by: Adam Borowski <kilobyte@angband.pl>
Signed-off-by: David Sterba <dsterba@suse.com>
2022-02-01 18:40:53 +01:00
Josef Bacik 44aecdc20c btrfs-progs: fi show: close ctree once we're done
Running with ASAN we won't pass the self tests because we leak the whole
fs_info with btrfs filesystem show.  Fix this by making sure we close
out the fs_info and clean up all of the memory and such.

Reviewed-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-11-22 21:45:37 +01:00
Anand Jain edd57bf494 btrfs-progs: fix comments in cmd_filesystem_show
I had to go back to find what BTRFS_ARG_REG is, add a comment for that.

And, search_umounted_fs_uuids() is also to find the seed device, so bring
the related comment above it.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-06 16:50:46 +02:00
David Sterba 61e00694e7 btrfs-progs: fix defrag -c option parsing
The refactoring f3a132fa1b ("btrfs-progs: factor out compression type
name parsing to common utils") caused a bug with parsing option -c with
defrag:

  # btrfs fi defrag -v -czstd file
  ERROR: unknown compression type: zstd

  # btrfs fi defrag -v -clzo file
  ERROR: unknown compression type: lzo

  # btrfs fi defrag -v -czlib file
  ERROR: unknown compression type: zlib

Fix it by properly checking the value representing unknown compression
algorithm.

Issue: #403
Signed-off-by: David Sterba <dsterba@suse.com>
2021-09-18 17:48:32 +02:00
David Sterba f3a132fa1b btrfs-progs: factor out compression type name parsing to common utils
Signed-off-by: David Sterba <dsterba@suse.com>
2021-09-07 13:58:44 +02:00
David Sterba af56460de8 btrfs-progs: split parsing helpers from utils.c
There are various parsing helpers scattered everywhere, unify them to
one file and start with helpers already in utils.c.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-09-06 17:15:51 +02:00
David Sterba f123c28412 btrfs-progs: fi resize: add support for cancel
Recognize special resize amount 'cancel' for resize operation.  This
will request kernel to stop running any resize operation (most likely
shrinking resize). This needs support in kernel, otherwise this will
fail due to another exclusive operation running (though could be the
same one).

The command returns after kernel finishes any work that got interrupted,
but this should not take long in kernels 5.10+ that allow interruptible
relocation. The waiting inside kernel is interruptible so this command
(and the waiting stage) can be interrupted.

The resize operation could relocate block groups but the nominal
filesystem size will be restored when resize won't finish. It's
recommended to review the filesystem state.

Note: in kernels 5.10+ sending a fatal signal (TERM, KILL, Ctrl-C) to
the process running the resize will cancel it too.

Example:

  $ btrfs fi resize -10G /mnt
  ...
  $ btrfs fi resize cancel /mnt

Signed-off-by: David Sterba <dsterba@suse.com>
2021-05-20 22:43:29 +02:00
David Sterba a2495d1e6e btrfs-progs: export get_zone_unusable and move to utils.c
Getting the per bg type zone unusable space will be used in other size
reports like 'fi us', so export it to the device utils.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-05-08 00:58:50 +02:00
David Sterba e295a8ad4c btrfs-progs: fi df: report zone_unusable on zoned filesystem
In the zoned mode there are parts of chunks that become unusable once
they get COWed and the zone must be reclaimed and reset to make the
space usable again. Provide a way to show the total size per block group
type in fi df:

  $ btrfs fi df .
  Data, single: total=1.00GiB, used=257.51MiB, zone_unusable=238.43MiB
  System, single: total=256.00MiB, used=16.00KiB, zone_unusable=224.00KiB
  Metadata, single: total=256.00MiB, used=816.00KiB, zone_unusable=8.61MiB
  GlobalReserve, single: total=3.25MiB, used=0.00B

This will not be shown on non-zoned filesystems.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-05-08 00:58:50 +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
Su Yue 31934b1161 btrfs-progs: fi resize: fix false 0.00B size output
Resize to nums without sign prefix makes false output:

  $ btrfs fi resize 1:150g /srv/extra
  Resize device id 1 (/dev/sdb1) from 298.09GiB to 0.00B

The resize operation would take effect though.

Fix it by handling the case if mod is 0 in check_resize_args().

Issue: #307
Reported-by: Chris Murphy <lists@colorremedies.com>
Reviewed-by: Boris Burkov <boris@bur.io>
Signed-off-by: Su Yue <l@damenly.su>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-05-06 16:41:44 +02:00
David Sterba 6bb6d1215d btrfs-progs: factor open_ctree parameters to a structure
Extending open_ctree with more parameters would be difficult, we'll need
to add more so factor out the parameters to a structure for easier
extension.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-24 22:20:19 +01:00
Sidong Yang 78aa1d95dd btrfs-progs: fi resize: make output more readable
Make output of 'btrfs filesystem resize' command more readable and
describe the changes in more detail.

Before:
Resize '/mnt' of '1:-1G'

After:
Resize device id 1 (/dev/vdb) from 4.00GiB to 3.00GiB

Issue: #307
Signed-off-by: Sidong Yang <realwakka@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-23 17:04:22 +01:00
Nikolay Borisov 3e653e801c btrfs-progs: remove duplicate checks from cmd_filesystem_resize
btrfs_open_dir already has a check whether the passed path is a
directory and if so it returns a specific error code (-3) when such an
error occurs. Use this instead of open-coding the directory check. To
avoid regression in cli/003 test also move directory checks before fs
type in btrfs_open.

Output before this check:

  ERROR: resize works on mounted filesystems and accepts only
  directories as argument. Passing file containing a btrfs image
  would resize the underlying filesystem instead of the image.

After:

  ERROR: not a directory: /root/btrfs-progs/tests/test.img
  ERROR: resize works on mounted filesystems and accepts only
  directories as argument. Passing file containing a btrfs image
  would resize the underlying filesystem instead of the image.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-02-19 15:24:42 +01:00
David Sterba 922eaa7b54 btrfs-progs: build: fix linking with static libmount
The libmount dependency has been added in commit 61ecaff036
("btrfs-progs: build: add libmount dependency"), and static build got
broken. There are functions that do basically the same thing and also
share the name, which in turn fails at link time.

  ld: /../lib64/libmount.a(libcommon_la-canonicalize.o): in function `canonicalize_dm_name':
  util-linux-2.34/lib/canonicalize.c:58: multiple definition of `canonicalize_dm_name';
	  common/path-utils.static.o:btrfs-progs/common/path-utils.c:286: first defined here

In case the collision can be resolved by renaming, it's done
(canonicalize_path and parse_size). There are 2 symbols from selinux
that are substituted by a weak aliases during the static build.

There's one new warning due to use of getgrnam_r in libmount that
depends on dynamic linking and may not work properly with static build.
We're not using the related functions directly or indirectly, so it
should be safe to ignore the warnings.

  ld: ../lib64/libmount.a(la-utils.o): in function `mnt_get_gid':
  util-linux-2.34/libmount/src/utils.c:625: warning: Using 'getgrnam_r' in statically linked applications
  +requires at runtime the shared libraries from the glibc version used for linking

Issue: #333
Signed-off-by: David Sterba <dsterba@suse.com>
2021-01-25 23:31:56 +01:00
David Sterba e198c6674a btrfs-progs: add enqueue parameter for exclusive ops
The exclusive ops will not start if there's one already running. Now
that we have the sysfs export (since kernel 5.10) to check if there's
one already running, use it to allow enqueueing of the operations as a
convenience.

Supported enqueuing:

  btrfs balance start --enqueue
  btrfs filesystem resize --enqueue
  btrfs device add --enqueue
  btrfs device delete --enqueue
  btrfs replace start --enqueue

This patch implements the functionality based on Goldwyn's patch
https://lore.kernel.org/linux-btrfs/?q=20200825150338.32610-4-rgoldwyn%40suse.de
but on top of previous preparatory patches.

Note that 'filesystem resize' options could confuse getopt as the
negative size change looks like a series of short options and there's no
way to make getopt ignore the short options, so there's a custom option
parser.

Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.de>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-12-16 17:08:12 +01:00
Goldwyn Rodrigues 80df942fe7 btrfs-progs: check for exclusive operation before issuing another
If the exclusive operation is available in sysfs file, check if there's
one already running. The check is done for:

- device add, remove, replace
- balance
- filesystem resize

All commands will validate arguments and check before the ioctl or
before any potentially irreversible operations (like clearing device
before replacing).

Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-12-10 17:10:29 +01:00
David Sterba 0144bcb713 btrfs-progs: move volumes.c to kernel-shared/
Signed-off-by: David Sterba <dsterba@suse.com>
2020-08-31 17:01:06 +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