btrbk: fix mountinfo parsing (octal encoded chars)

Making sure this is done after splitting, as encoded value could be a
comma.

After some testing it shows that the kernel [1] produces ambigous
output in "super options" if a subvolume containing a comma is mounted
using "-o subvolid=" (tried hard to mount with "-o subvol=", seems not
possible via shell):

    # btrfs sub create /tmp/btrbk_unittest/mnt_source/svol\,comma
    # mount /dev/loop0 -o subvolid=282 '/tmp/btrbk_unittest/mount,comma'
    # cat /proc/self/mountinfo
    [...]
    48 40 0:319 /svol,comma /tmp/btrbk_unittest/mount,comma rw,relatime - btrfs /dev/loop0 rw,ssd,noacl,space_cache,subvolid=282,subvol=/svol,comma
                                                                                                                                ^^^^^^^^^^^^^^^^^^

  [1] sys-kernel/gentoo-sources-5.10.45
pull/409/head
Axel Burri 2021-07-14 21:47:09 +02:00
parent eac9ef9828
commit 6c13a64459
1 changed files with 13 additions and 4 deletions

17
btrbk
View File

@ -1975,15 +1975,24 @@ sub system_list_mountinfo($)
return undef;
}
my %line = %+;
# merge super_options and mount_options to MNTOPS.
foreach (split(',', $line{super_options}), split(',', $line{mount_options})) {
my %mntops;
foreach (split(',', delete($line{super_options})),
split(',', delete($line{mount_options})))
{
if(/^(.+?)=(.+)$/) {
$line{MNTOPS}->{$1} = $2;
$mntops{$1} = $2;
} else {
$line{MNTOPS}->{$_} = 1;
$mntops{$_} = 1;
}
}
$line{MNTOPS}->{rw} = 0 if($line{MNTOPS}->{ro}); # e.g. mount_options="ro", super_options="rw"
$mntops{rw} = 0 if($mntops{ro}); # e.g. mount_options="ro", super_options="rw"
# decode values (octal, e.g. "\040" = whitespace)
s/\\([0-7]{3})/chr(oct($1))/eg foreach(values %line, values %mntops);
$line{MNTOPS} = \%mntops;
push @mountinfo, \%line;
}
# TRACE(Data::Dumper->Dump([\@mountinfo], ["mountinfo"])) if($do_trace && $do_dumper);