btrbk: add system_list_mountinfo: parse /proc/self/mountinfo

preparatory patch for removing system_list_mounts().
prune-ignore-latest-common
Axel Burri 2018-08-27 14:52:28 +02:00
parent 37c0e840e9
commit e02c2cf249
1 changed files with 47 additions and 0 deletions

47
btrbk
View File

@ -1760,6 +1760,53 @@ sub btrfs_send_to_file($$$;$$)
}
sub system_list_mountinfo($)
{
my $vol = shift // die;
my $file = '/proc/self/mountinfo';
my $ret = run_cmd(cmd => [ qw(cat), $file ],
rsh => vinfo_rsh($vol),
non_destructive => 1,
catch_stderr => 1, # hack for shell-based run_cmd()
);
return undef unless(defined($ret));
my @mountinfo;
foreach (split(/\n/, $ret))
{
# https://www.kernel.org/doc/Documentation/filesystems/proc.txt
unless(/^(?<mount_id>[0-9]+) # mount ID: unique identifier of the mount (may be reused after umount)
\s(?<parent_id>[0-9]+) # parent ID: ID of parent (or of self for the top of the mount tree)
\s(?<st_dev>[0-9]+:[0-9]+) # major:minor: value of st_dev for files on filesystem
\s(?<fs_root>\S+) # root: root of the mount within the filesystem
\s(?<mount_point>\S+) # mount point: mount point relative to the process's root
\s(?<mount_options>\S+) # mount options: per mount options
(\s\S+)* # optional fields: zero or more fields of the form "tag[:value]"
\s- # separator: marks the end of the optional fields
\s(?<fs_type>\S+) # filesystem type: name of filesystem of the form "type[.subtype]"
\s(?<mount_source>\S+) # mount source: filesystem specific information or "none"
\s(?<super_options>\S+)$ # super options: per super block options
/x)
{
ERROR "Failed to parse \"$file\" on " . ($vol->{HOST} || "localhost");
DEBUG "Offending line: $_";
return undef;
}
my %line = %+;
foreach (split(',', $line{super_options})) {
if(/^(.+?)=(.+)$/) {
$line{MNTOPS}->{$1} = $2;
} else {
$line{MNTOPS}->{$_} = 1;
}
}
push @mountinfo, \%line;
}
# TRACE(Data::Dumper->Dump([\@mountinfo], ["mountinfo"])) if($do_dumper);
return \@mountinfo;
}
sub system_list_mounts($)
{
my $vol = shift // die;