From e198c6674a440ec699e068c338e66b2632962197 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Thu, 5 Nov 2020 03:38:00 +0100 Subject: [PATCH] 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 Signed-off-by: David Sterba --- Documentation/btrfs-balance.asciidoc | 2 + Documentation/btrfs-device.asciidoc | 9 ++++- Documentation/btrfs-filesystem.asciidoc | 7 +++- Documentation/btrfs-replace.asciidoc | 4 +- cmds/balance.c | 30 +++++++++----- cmds/device.c | 54 +++++++++++++++++++------ cmds/filesystem.c | 35 ++++++++++++---- cmds/replace.c | 30 ++++++++++---- common/utils.c | 5 ++- common/utils.h | 2 +- 10 files changed, 132 insertions(+), 46 deletions(-) diff --git a/Documentation/btrfs-balance.asciidoc b/Documentation/btrfs-balance.asciidoc index d94719a0..8e3c9097 100644 --- a/Documentation/btrfs-balance.asciidoc +++ b/Documentation/btrfs-balance.asciidoc @@ -117,6 +117,8 @@ force a reduction of metadata integrity, eg. when going from 'raid1' to 'single' --background|--bg:::: run the balance operation asynchronously in the background, uses `fork`(2) to start the process that calls the kernel ioctl +--enqueue:::: +wait if there's another exclusive operation running, otherwise continue -v:::: (deprecated) alias for global '-v' option diff --git a/Documentation/btrfs-device.asciidoc b/Documentation/btrfs-device.asciidoc index 70ce6c5a..873c756f 100644 --- a/Documentation/btrfs-device.asciidoc +++ b/Documentation/btrfs-device.asciidoc @@ -61,8 +61,10 @@ headers. do not perform discard (TRIM) by default -f|--force:::: force overwrite of existing filesystem on the given disk(s) +--enqueue:::: +wait if there's another exclusive operation running, otherwise continue -*remove* | [|...] :: +*remove* [options] | [|...] :: Remove device(s) from a filesystem identified by + Device removal must satisfy the profile constraints, otherwise the command @@ -85,6 +87,11 @@ NOTE: In most cases, there is only one missing device in degraded mode, otherwise mount fails. If there are two or more devices missing (e.g. possible in RAID6), you need specify 'missing' as many times as the number of missing devices to remove all of them. ++ +`Options` ++ +--enqueue:::: +wait if there's another exclusive operation running, otherwise continue *delete* | [|...] :: Alias of remove kept for backward compatibility diff --git a/Documentation/btrfs-filesystem.asciidoc b/Documentation/btrfs-filesystem.asciidoc index 0e299c2b..32616b4a 100644 --- a/Documentation/btrfs-filesystem.asciidoc +++ b/Documentation/btrfs-filesystem.asciidoc @@ -186,7 +186,7 @@ NOTE: the maximum allowable length shall be less than 256 chars and must not con a newline. The trailing newline is stripped automatically. // Some wording are extracted by the resize2fs man page -*resize* [:][+/-][kKmMgGtTpPeE]|[:]max :: +*resize* [options] [:][+/-][kKmMgGtTpPeE]|[:]max :: Resize a mounted filesystem identified by 'path'. A particular device can be resized by specifying a 'devid'. + @@ -220,6 +220,11 @@ take a long time if there are data in the device area that's beyond the new end. Relocation of the data takes time. + See also section 'EXAMPLES'. ++ +`Options` ++ +--enqueue:::: +wait if there's another exclusive operation running, otherwise continue *show* [options] [|||