2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2025-08-31 23:38:22 +00:00

Randomize genesis temp name

When multiple xCAT updates were running against the same FS, they would
corrupt the image.  Mitigate this by operating on probably unique names
and replacing at the end.
This commit is contained in:
Jarrod Johnson
2018-08-14 18:31:44 -04:00
parent ec778af056
commit c651e7b8c7

View File

@@ -177,26 +177,30 @@ sub process_request {
my $lzma_exit_value = 1;
if ($invisibletouch) {
my $done = 0;
my @chars = ("A".."Z", "a".."z", "0".."9");
my $suffix = $chars[rand @chars] for 1..24;
if (-x "/usr/bin/lzma") { #let's reclaim some of that size...
$callback->({ data => ["Creating genesis.fs.$arch.lzma in $tftpdir/xcat"] });
system("cd $tempdir; find . | cpio -o -H newc | lzma -C crc32 -9 > $tftpdir/xcat/genesis.fs.$arch.lzma");
system("cd $tempdir; find . | cpio -o -H newc | lzma -C crc32 -9 > $tftpdir/xcat/genesis.fs.$arch.lzma.$suffix");
$lzma_exit_value = $? >> 8;
if ($lzma_exit_value) {
$callback->({ data => ["Creating genesis.fs.$arch.lzma in $tftpdir/xcat failed, falling back to gzip"] });
unlink("$tftpdir/xcat/genesis.fs.$arch.lzma");
unlink("$tftpdir/xcat/genesis.fs.$arch.lzma.$suffix");
} else {
move("$tftpdir/xcat/genesis.fs.$arch.lzma.$suffix", "$tftpdir/xcat/genesis.fs.$arch.lzma");
$done = 1;
$initrd_file = "$tftpdir/xcat/genesis.fs.$arch.lzma";
}
}
if (not $done and -x "/usr/bin/xz") { #let's reclaim some of that size...
$callback->({ data => ["Creating genesis.fs.$arch.lzma in $tftpdir/xcat"] });
system("cd $tempdir; find . | cpio -o -H newc | xz -C crc32 -9 > $tftpdir/xcat/genesis.fs.$arch.lzma");
system("cd $tempdir; find . | cpio -o -H newc | xz -C crc32 -9 > $tftpdir/xcat/genesis.fs.$arch.lzma.$suffix");
$lzma_exit_value = $? >> 8;
if ($lzma_exit_value) {
$callback->({ data => ["Creating genesis.fs.$arch.lzma in $tftpdir/xcat failed, falling back to gzip"] });
unlink("$tftpdir/xcat/genesis.fs.$arch.lzma");
unlink("$tftpdir/xcat/genesis.fs.$arch.lzma.$suffix");
} else {
move("$tftpdir/xcat/genesis.fs.$arch.lzma.$suffix", "$tftpdir/xcat/genesis.fs.$arch.lzma");
$done = 1;
$initrd_file = "$tftpdir/xcat/genesis.fs.$arch.lzma";
}
@@ -204,7 +208,8 @@ sub process_request {
if (not $done) {
$callback->({ data => ["Creating genesis.fs.$arch.gz in $tftpdir/xcat"] });
system("cd $tempdir; find . | cpio -o -H newc | gzip -9 > $tftpdir/xcat/genesis.fs.$arch.gz");
system("cd $tempdir; find . | cpio -o -H newc | gzip -9 > $tftpdir/xcat/genesis.fs.$arch.gz.$suffix");
move("$tftpdir/xcat/genesis.fs.$arch.gz.$suffix", "$tftpdir/xcat/genesis.fs.$arch.gz");
$initrd_file = "$tftpdir/xcat/genesis.fs.$arch.gz";
}
} else {