btrfs-progs/btrfs-completion
Qu Wenruo 87b3197d81 btrfs-progs: move space cache removal to rescue group
The option "--clear-space-cache" is not really that suitable for "btrfs
check" group, as there are some concerns:

- Allowing transid mismatch
- No leaf item checks

  Thoe behaviour are inherited from the default open ctree flags for
  "btrfs check", which can be unsafe if the end user just wants to clear
  the cache.

- Unclear if the cache clearing would happen along with repair

  Thankfully the clearing of space cache is done without any repair

Thus there is a proposal to move space cache removal to rescue group,
and this patch would do that exactly.

However this would lead to some behavior changes:

- Transid mismatch would be treated as error
- Leaf items size/offset would still be checked

  If we hit any above error, we should just abort without doing any
  write.

These change would increase the safety of the space cache removal, thus
I believe it's worthy to introduce such behavior change.

Since we're here, also add a small explanation on why we need this
dedicated tool to clear space cache (especially for v1 cache).

Issue: #698
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-11-03 18:04:37 +01:00

173 lines
3.5 KiB
Plaintext

# original by Alfredo Esteban <aedelatorre at xxxxxxxxx>
# (http://www.spinics.net/lists/linux-btrfs/msg15899.html)
# edited by Joseph Wang <joequant at gmail.com>
# (http://lists.alioth.debian.org/pipermail/bash-completion-devel/2013-June/004868.html)
# edited by John C F <john.ch.fr at gmail.com> on 2015-02-02
_btrfs_mnts()
{
local MNTS
MNTS=''
while read mnt; do MNTS+="$mnt "
done < <(mount -t btrfs | awk '{print $3}')
COMPREPLY+=( $( compgen -W "$MNTS" -- "$cur" ) )
}
_btrfs()
{
local cur prev words cword
_init_completion || return
COMPREPLY=()
local cmd=${words[1]}
commands='subvolume filesystem balance device scrub check rescue restore inspect-internal property send receive quota qgroup replace help version'
commands_subvolume='create delete list snapshot find-new get-default set-default show sync'
commands_filesystem='defragment sync resize show df du label usage mkswapfile'
commands_balance='start pause cancel resume status'
commands_device='scan add delete remove ready stats usage'
commands_scrub='start cancel resume status'
commands_rescue='chunk-recover super-recover zero-log fix-device-size create-control-device clear-uuid-tree clear-ino-cache clear-space-cache'
commands_inspect_internal='inode-resolve logical-resolve subvolid-resolve rootid min-dev-size dump-tree dump-super tree-stats map-swapfile'
commands_property='get set list'
commands_quota='enable disable rescan'
commands_qgroup='assign remove create destroy show limit clear-stale'
commands_replace='start status cancel'
if [[ "$cur" == -* && $cword -le 3 && "$cmd" != "help" ]]; then
COMPREPLY=( $( compgen -W '--help' -- "$cur" ) )
return 0
fi
if [[ $cword -eq 1 ]]; then
COMPREPLY=( $( compgen -W "$commands" -- "$cur" ) )
return 0
elif [[ $cword -eq 2 ]]; then
case $cmd in
subvolume)
opts="$commands_subvolume"
;;
filesystem)
opts="$commands_filesystem"
;;
balance)
opts="$commands_balance"
;;
device)
opts="$commands_device"
;;
scrub)
opts="$commands_scrub"
;;
check)
_filedir
return 0
;;
rescue)
opts="$commands_rescue"
;;
restore)
_filedir
return 0
;;
inspect-internal)
opts="$commands_inspect_internal"
;;
property)
opts="$commands_property"
;;
send|receive)
_filedir -d
return 0
;;
quota)
opts="$commands_quota"
;;
qgroup)
opts="$commands_qgroup"
;;
replace)
opts="$commands_replace"
;;
help)
opts="--full"
;;
version)
return 0
;;
esac
COMPREPLY=( $( compgen -W "$opts" -- "$cur" ) )
return 0
elif [[ $cword -eq 3 ]]; then
case $cmd in
filesystem)
case $prev in
du|defragment)
_filedir
return 0
;;
df|usage)
_btrfs_mnts
return 0
;;
label)
_btrfs_mnts
_filedir
return 0
;;
esac
;;
device|rescue)
_filedir
return 0
;;
inspect-internal)
case $prev in
min-dev-size)
_btrfs_mnts
return 0
;;
dump-tree|dump-super|rootid|inode-resolve)
_filedir
return 0
;;
esac
;;
receive)
case $prev in
-f)
_filedir
return 0
;;
esac
;;
replace)
case $prev in
status|cancel)
_btrfs_mnts
return 0
;;
start)
_filedir
return 0
;;
esac
;;
subvolume)
case $prev in
list)
_btrfs_mnts
return 0
;;
esac
;;
esac
fi
_filedir -d
return 0
}
complete -F _btrfs btrfs