#2080 PR merged: Make both btrfs_subvolumes_setup implementations available (follow up of issue 2079)

Labels: enhancement, fixed / solved / done

jsmeix opened issue at 2019-03-12 14:02:

Now there are two functions that implement btrfs subvolumes setup:

The old btrfs_subvolumes_setup is now btrfs_subvolumes_setup_SLES

The new one from https://github.com/rear/rear/pull/2079
is now btrfs_subvolumes_setup_generic

There are two new user config array variables
BTRFS_SUBVOLUME_SLES_SETUP
and
BTRFS_SUBVOLUME_GENERIC_SETUP
where the suer can - if needed - specify how his btrfs subvolumes
should be set up.

When neither BTRFS_SUBVOLUME_SLES_SETUP
nor BTRFS_SUBVOLUME_GENERIC_SETUP
is set the old behaviour is kept (now via btrfs_subvolumes_setup_SLES).

When both BTRFS_SUBVOLUME_SLES_SETUP
and BTRFS_SUBVOLUME_GENERIC_SETUP are set to a false value
no btrfs subvolumes setup is done.

When BTRFS_SUBVOLUME_GENERIC_SETUP is set to a true value
or when BTRFS_SUBVOLUME_SLES_SETUP is set to a false value
btrfs subvolumes setup is done via btrfs_subvolumes_setup_generic

When BTRFS_SUBVOLUME_GENERIC_SETUP is set to a false value
or when BTRFS_SUBVOLUME_SLES_SETUP is set to a true value
btrfs subvolumes setup is done via btrfs_subvolumes_setup_SLES

When the BTRFS_SUBVOLUME_GENERIC_SETUP array contains
devices those are set up via btrfs_subvolumes_setup_generic

When the BTRFS_SUBVOLUME_SLES_SETUP array contains
devices those are set up via btrfs_subvolumes_setup_SLES

jsmeix commented at 2019-03-12 14:04:

@rear/contributors @OliverO2
I did the pull request early so that you can have an early look at the code
and provide comments what you think about it.

Currently this is work in progress...

jsmeix commented at 2019-03-12 16:03:

Tested it a bit on SLES12:

"rear recover" still works with the defaults (which is using the old code).

"rear recover" fails on SLES12 with its btrfs structure when the new code is used,
then the diskrestore.sh script fails, I have the "rear recover" log file
but will have a closer look tomorrow...

jsmeix commented at 2019-03-13 11:12:

My latest commit
https://github.com/rear/rear/pull/2080/commits/c0b0ddd5657b0e981ee33274db0f4d40fd1a1674
intends to implement some automatism that ensures
during "rear recover" btrfs_subvolumes_setup_SLES()
gets called when needed so that for SLES things should even work
when the user has specified BTRFS_SUBVOLUME_GENERIC_SETUP="true".

OliverO2 commented at 2019-03-13 11:17:

Sound reasonable to include such an automatism for now. I'm curious about discovering why the diskrestore.sh script created by the generic implementation failed on SLES12, though.

jsmeix commented at 2019-03-13 11:23:

@OliverO2
I need to test my latest geratest automatisms first...
...and if it works it could (hopefully) be some kind of template
for you how you could later add an automatism to call
btrfs_subvolumes_setup_generic() as needed for your case.

OliverO2 commented at 2019-03-13 11:30:

Take your time. The reason why I am curious is that the generic code should create a layout for any setup (which would include SLES12). It might not be the "right" or "ideal" layout for now, but at least diskrestore.sh should not abort.

jsmeix commented at 2019-03-13 13:10:

Testing helps ( unsurprisingly ;-)
My automatism does not yet work - I know why - will fix it...

jsmeix commented at 2019-03-13 14:18:

Now things work for me so far so that I like to merge it right now
to have it in ReaR master code where all can test it more easily.

jsmeix commented at 2019-03-13 14:37:

@OliverO2
the "rear -D recover" log and disklayout.conf and diskrestore.sh
from my failed attempt

rear-recover-fail.log

diskrestore-sh.txt

disklayout-conf.txt

In "rear -D recover" log there is

++ source /var/lib/rear/layout/diskrestore.sh
...
Create subvolume '/mnt/local/@/.snapshots/1/snapshot'
+++ btrfs subvolume set-default /mnt/local/@/.snapshots/1/snapshot
btrfs subvolume set-default: too few arguments
usage: btrfs subvolume set-default <subvolid> <path>

    Set the default subvolume of a filesystem

OliverO2 commented at 2019-03-13 14:42:

Ah, I see: Your version of the Btrfs tool suite requires the subvolid parameter for the subvolume set-default command. Newer versions seem to be clever enough to figure out that /mnt/local/@/.snapshots/1/snapshot already uniquely specifies a subvolume. I could easily fix that (by using another invocation to retrieve the subvolid first) but probably no earlier than somewhere in April...

jsmeix commented at 2019-03-13 14:58:

On my SLES15-like openSUSE Leap 15.0 system
"man btrfs subvolume" shows

set-default [<subvolume>|<id> <path>]

Set the default subvolume for the (mounted) filesystem.
...
There are two ways how to specify the subvolume,
by <id> or by the <subvolume> path.
The id can be obtained from
btrfs subvolume list
btrfs subvolume show
or
btrfs inspect-internal rootid

which belongs to btrfsprogs version 4.15.

On my SLES12 system I have btrfsprogs-4.5.3
where "man btrfs subvolume" shows

set-default <id> <path>

Set the subvolume of the filesystem <path>
which is mounted as default.
The subvolume is identified by <id>,
which is returned by the
subvolume list
command.

so for SLES12 the subvolume's "name" is not possible.
On SLES12 one must use the (numerical) ID,
cf. the btrfs subvolume set-default code in the (now renamed)
layout/prepare/GNU/Linux/136_include_btrfs_subvolumes_SLES_code.sh


[Export of Github issue for rear/rear.]