btrbk: add --rootid command option for "btrfs subvolume show"

pull/245/head
Axel Burri 2018-06-29 18:47:47 +02:00
parent 1aa0fe1aad
commit cb5e361f7a
2 changed files with 12 additions and 4 deletions

14
btrbk
View File

@ -878,11 +878,14 @@ sub btrfs_filesystem_usage($)
# for btrfs root, returns at least: (id is_root) # for btrfs root, returns at least: (id is_root)
# for btrfs-progs >= 4.1, also returns key: "received_uuid" # for btrfs-progs >= 4.1, also returns key: "received_uuid"
# if present, also returns (unvalidated) keys: (name creation_time flags) # if present, also returns (unvalidated) keys: (name creation_time flags)
sub btrfs_subvolume_show($) sub btrfs_subvolume_show($;@)
{ {
my $vol = shift || die; my $vol = shift || die;
my %opts = @_;
my @cmd_options;
push(@cmd_options, '--rootid=' . $opts{rootid}) if($opts{rootid}); # btrfs-progs >= 4.12
my $path = $vol->{PATH} // die; my $path = $vol->{PATH} // die;
my $ret = run_cmd(cmd => vinfo_cmd($vol, "btrfs subvolume show", { unsafe => $path }), my $ret = run_cmd(cmd => vinfo_cmd($vol, "btrfs subvolume show", @cmd_options, { unsafe => $path }),
rsh => vinfo_rsh($vol), rsh => vinfo_rsh($vol),
non_destructive => 1, non_destructive => 1,
catch_stderr => 1, # hack for shell-based run_cmd() catch_stderr => 1, # hack for shell-based run_cmd()
@ -943,7 +946,7 @@ sub btrfs_subvolume_show($)
"Top level ID" => "top_level", # btrfs-progs >= 4.1 "Top level ID" => "top_level", # btrfs-progs >= 4.1
"Flags" => "flags", "Flags" => "flags",
); );
foreach (split("\n", $ret)) { foreach (@ret_lines) {
next unless /^\s+(.+):\s+(.*)$/; next unless /^\s+(.+):\s+(.*)$/;
my ($key, $value) = ($1, $2); my ($key, $value) = ($1, $2);
if($trans{$key}) { if($trans{$key}) {
@ -990,6 +993,11 @@ sub btrfs_subvolume_show($)
VINFO(\%detail, "detail") if($loglevel >=4); VINFO(\%detail, "detail") if($loglevel >=4);
} }
if($opts{rootid} && ($detail{id} != $opts{rootid})) {
ERROR "Failed to parse subvolume detail (rootid mismatch) for: $vol->{PRINT}";
return undef;
}
if($detail{id} == 5) { if($detail{id} == 5) {
DEBUG "found btrfs root: $vol->{PRINT}"; DEBUG "found btrfs root: $vol->{PRINT}";
$detail{is_root} = 1; $detail{is_root} = 1;

View File

@ -48,7 +48,7 @@ run_cmd()
reject_filtered_cmd() reject_filtered_cmd()
{ {
# note that the backslash is NOT a metacharacter in a POSIX bracket expression! # note that the backslash is NOT a metacharacter in a POSIX bracket expression!
option_match='-[a-zA-Z-]+' # matches short as well as long options option_match='-[a-zA-Z0-9=-]+' # matches short as well as long options
file_match='[0-9a-zA-Z_@+./-]*' # matches file path (equal to $file_match in btrbk) file_match='[0-9a-zA-Z_@+./-]*' # matches file path (equal to $file_match in btrbk)
if [[ -n "$restrict_path_list" ]]; then if [[ -n "$restrict_path_list" ]]; then