summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaulo Alcantara <palcantara@suse.de>2018-04-06 11:41:52 -0300
committerPaulo Alcantara <palcantara@suse.de>2018-04-06 11:41:52 -0300
commite3a982d01953b0f26f6a18bfcb3a546a43251285 (patch)
tree5b1073bda3e9a9053143bdf5d7cf421ad7b41643
parent74d4e33c34f1dbf01b3088e36e471a4f59ccd2de (diff)
downloadvmhtool-e3a982d01953b0f26f6a18bfcb3a546a43251285.tar.gz
vmhtool-e3a982d01953b0f26f6a18bfcb3a546a43251285.tar.xz
vmhtool-e3a982d01953b0f26f6a18bfcb3a546a43251285.zip
Abort gracefully in case of kernel build/run failures.
Signed-off-by: Paulo Alcantara <palcantara@suse.de>
-rwxr-xr-xvmhelper64
1 files changed, 45 insertions, 19 deletions
diff --git a/vmhelper b/vmhelper
index 4d70af8..1aa067e 100755
--- a/vmhelper
+++ b/vmhelper
@@ -382,8 +382,8 @@ my $rootfs_path = `mktemp -d`;
chomp($rootfs_path) if $rootfs_path;
sub mount_rootfs {
- die "$rootfs_path does not exist" unless $rootfs_path and
- -e $rootfs_path and -d $rootfs_path;
+ die "$rootfs_path does not exist" unless $rootfs_path or
+ -e $rootfs_path or -d $rootfs_path;
system("guestmount -a $vm_img_path -m /dev/sda2 $rootfs_path") == 0 or
die "failed to mount rootfs: $?";
}
@@ -440,7 +440,7 @@ sub setup_shared_dirs {
foreach (@dirs) {
my $path = abs_path($_);
- die "$_ does not exist" unless -e $path and -d $path;
+ die "$_ does not exist" unless -e $path or -d $path;
my $tag = "__sharevh-" . sprintf "%d", rand(4096);
mkdir("$rootfs_path/share/" . basename($path));
@@ -467,39 +467,58 @@ sub setup_shared_dirs {
##
## linux vms
##
-create_tap_dev();
-
my $qemu_cmd = "/usr/bin/qemu-system-x86_64";
$qemu_cmd .= " $qemu_linux_opts{'mach'} $qemu_linux_opts{'cpu'}";
$qemu_cmd .= " $qemu_linux_opts{'mem'} $qemu_linux_opts{'bus'}";
$qemu_cmd .= " " . sprintf $qemu_linux_opts{'hdd'}, $vm_img_path;
-$qemu_cmd .= " " . sprintf $qemu_linux_opts{'net'}, get_vm_macaddr(), $tap_iface;
setup_shared_dirs();
$qemu_cmd .= " $qemu_linux_opts{'share'}";
+create_tap_dev();
+$qemu_cmd .= " " . sprintf $qemu_linux_opts{'net'}, get_vm_macaddr(), $tap_iface;
+
+my $err;
+
if ($kernel_path) {
- die "$kernel_path does not exist" unless -e $kernel_path and
- -d $kernel_path;
+ unless (-e $kernel_path or -d $kernel_path) {
+ $err = "$kernel_path does not exist";
+ goto OUT;
+ }
if ($build_kernel) {
- chdir($kernel_path) or die "failed to change directory: $!";
- unless ($config_path) {
- system("make mrproper");
- system("make x86_64_defconfig");
- system("make kvmconfig");
- } else {
+ unless (chdir($kernel_path)) {
+ $err = "failed to change dir: $!";
+ goto OUT;
+ }
+
+ if ($config_path) {
+ unless (-e $config_path or -f $config_path) {
+ $err = "$config_path does not exist";
+ goto OUT;
+ }
copy($config_path, "$kernel_path/.config") or
die "failed to copy file: $!";
system("make oldconfig");
+ } else {
+ system("make mrproper");
+ system("make x86_64_defconfig");
+ system("make kvmconfig");
}
- system("make -j\$(getconf _NPROCESSORS_ONLN)");
+ if (system('make -j$(getconf _NPROCESSORS_ONLN)')) {
+ $err = "failed to build kernel: $?";
+ goto OUT;
+ }
if ($install_modules) {
mount_rootfs();
- system("make modules");
+ if (system("make modules")) {
+ $err = "failed to build kernel modules: $?";
+ umount_rootfs();
+ goto OUT;
+ }
system("INSTALL_MOD_PATH=$rootfs_path make modules_install");
umount_rootfs();
}
@@ -507,19 +526,26 @@ if ($kernel_path) {
}
my $linux_img = "$kernel_path/arch/x86/boot/bzImage";
- die "$linux_img does not exist" unless -e $linux_img and -f $linux_img;
+ unless (-e $linux_img or -f $linux_img) {
+ $err = "$linux_img does not exist";
+ goto OUT;
+ }
$qemu_cmd .= " " . sprintf $qemu_linux_opts{'kernel'}, $linux_img;
$qemu_cmd .= " $qemu_linux_opts{'cmdline'} -nographic";
if ($initrd_img) {
- die "$initrd_img does not exist" unless -e $initrd_img and
- -f $initrd_img;
+ unless (-e $initrd_img or -f $initrd_img) {
+ $err = "$initrd_img does not exist";
+ goto OUT;
+ }
$qemu_cmd .= " " . sprintf $qemu_linux_opts{'initrd'}, $initrd_img;
}
}
system($qemu_cmd);
+OUT:
destroy_tap_dev();
+die "$err" if $err;
exit 0;