Skip to content

Commit

Permalink
do not call mkfs.btrfs if preserve is set, Closes: #945239
Browse files Browse the repository at this point in the history
Currently this only works for a single device, not for btrfs raid devices
  • Loading branch information
Mrfai committed Feb 19, 2020
1 parent 84f70b5 commit 298be81
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions lib/setup-storage/Commands.pm
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ sub build_btrfs_commands {
next unless defined($this_fs);
next unless ($this_fs eq 'btrfs');
$volume = 'single_' . $single_vol_index;
$FAI::configs{$config}{volumes}{$volume}{preserve} = $FAI::configs{$c}{partitions}{$p}{size}{preserve};
$FAI::configs{$config}{volumes}{$volume}{encrypt} = $FAI::configs{$c}{partitions}{$p}{encrypt};
$FAI::configs{$config}{volumes}{$volume}{raidlevel} = 'single';
$FAI::configs{$config}{volumes}{$volume}{filesystem} = $this_fs;
Expand Down Expand Up @@ -357,6 +358,7 @@ sub build_btrfs_commands {
my $createopts = $vol->{createopts} // "";
$createopts .= " $forcebtrfs";
my $pre_req = "";
my $btrfs_tool = "";
# creates the proper prerequisites for later command ordering
foreach (@devs) {
my $tmp = $_;
Expand All @@ -366,25 +368,26 @@ sub build_btrfs_commands {
if (scalar @devs == 1) {
$pre_req = "exist_" . $devs[0];
}

# creates the BTRFS volume/RAID
if ($raidlevel eq 'single') {
if (exists $mkfs_done{join(" ", @devs)}) {
&FAI::push_command("true",
"$pre_req",
"btrfs_built_raid_$id");
$btrfs_tool = "true";
} else {
print "Adding mkfs command for '", join(", ", @devs), "'.\n";
&FAI::push_command("mkfs.btrfs -d single $createopts ".join(" ",@devs),
"$pre_req",
"btrfs_built_raid_$id");
print "Adding mkfs command for '", join(", ", @devs), "'.\n";
$btrfs_tool = "mkfs.btrfs -d single $createopts ".join(" ",@devs);
$mkfs_done{join(" ", @devs)} = '1';
}
} else {
&FAI::push_command("mkfs.btrfs -d raid$raidlevel $createopts ".join(" ",@devs),
"$pre_req",
"btrfs_built_raid_$id");
$btrfs_tool = "mkfs.btrfs -d raid$raidlevel $createopts ".join(" ",@devs);
}

# nothing more to do if we need to proserve this volume. No mkfs, no subvolume
next if ($vol->{preserve});

# add mkfs.btrfs if needed (otherwise add true)
&FAI::push_command("$btrfs_tool", "$pre_req", "btrfs_built_raid_$id");

# initial mount, required to create the initial subvolume
&FAI::push_command("mount $devs[0] /mnt",
"btrfs_built_raid_$id",
Expand Down

0 comments on commit 298be81

Please sign in to comment.