code and indentation cleanups

fix the classic indentation error on `additionalProperties` in the
main QEMU API

drop some not so useful empty lines to avoid making rather huge
methods even bigger (more intimidating, less on screen to grasp the
full picture).

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2021-10-20 17:31:45 +02:00
parent fa3b3ce067
commit 3326ae19de
2 changed files with 51 additions and 77 deletions

View File

@ -636,8 +636,7 @@ __PACKAGE__->register_method({
raise_param_exc({ archive => "option conflicts with other options ($keystr)"}) if $keystr; raise_param_exc({ archive => "option conflicts with other options ($keystr)"}) if $keystr;
if ($archive eq '-') { if ($archive eq '-') {
die "pipe requires cli environment\n" die "pipe requires cli environment\n" if $rpcenv->{type} ne 'cli';
if $rpcenv->{type} ne 'cli';
$archive = { type => 'pipe' }; $archive = { type => 'pipe' };
} else { } else {
PVE::Storage::check_volume_access($rpcenv, $authuser, $storecfg, $vmid, $archive); PVE::Storage::check_volume_access($rpcenv, $authuser, $storecfg, $vmid, $archive);

View File

@ -1844,7 +1844,6 @@ sub print_vga_device {
my $q35 = PVE::QemuServer::Machine::machine_type_is_q35($conf); my $q35 = PVE::QemuServer::Machine::machine_type_is_q35($conf);
my $vgaid = "vga" . ($id // ''); my $vgaid = "vga" . ($id // '');
my $pciaddr; my $pciaddr;
if ($q35 && $vgaid eq 'vga') { if ($q35 && $vgaid eq 'vga') {
# the first display uses pcie.0 bus on q35 machines # the first display uses pcie.0 bus on q35 machines
$pciaddr = print_pcie_addr($vgaid, $bridges, $arch, $machine); $pciaddr = print_pcie_addr($vgaid, $bridges, $arch, $machine);
@ -3313,11 +3312,8 @@ sub config_to_command {
$pbs_backing) = @_; $pbs_backing) = @_;
my $cmd = []; my $cmd = [];
my $globalFlags = []; my ($globalFlags, $machineFlags, $rtcFlags) = ([], [], []);
my $machineFlags = [];
my $rtcFlags = [];
my $devices = []; my $devices = [];
my $pciaddr = '';
my $bridges = {}; my $bridges = {};
my $ostype = $conf->{ostype}; my $ostype = $conf->{ostype};
my $winversion = windows_version($ostype); my $winversion = windows_version($ostype);
@ -3739,13 +3735,13 @@ sub config_to_command {
# enable balloon by default, unless explicitly disabled # enable balloon by default, unless explicitly disabled
if (!defined($conf->{balloon}) || $conf->{balloon}) { if (!defined($conf->{balloon}) || $conf->{balloon}) {
$pciaddr = print_pci_addr("balloon0", $bridges, $arch, $machine_type); my $pciaddr = print_pci_addr("balloon0", $bridges, $arch, $machine_type);
push @$devices, '-device', "virtio-balloon-pci,id=balloon0$pciaddr"; push @$devices, '-device', "virtio-balloon-pci,id=balloon0$pciaddr";
} }
if ($conf->{watchdog}) { if ($conf->{watchdog}) {
my $wdopts = parse_watchdog($conf->{watchdog}); my $wdopts = parse_watchdog($conf->{watchdog});
$pciaddr = print_pci_addr("watchdog", $bridges, $arch, $machine_type); my $pciaddr = print_pci_addr("watchdog", $bridges, $arch, $machine_type);
my $watchdog = $wdopts->{model} || 'i6300esb'; my $watchdog = $wdopts->{model} || 'i6300esb';
push @$devices, '-device', "$watchdog$pciaddr"; push @$devices, '-device', "$watchdog$pciaddr";
push @$devices, '-watchdog-action', $wdopts->{action} if $wdopts->{action}; push @$devices, '-watchdog-action', $wdopts->{action} if $wdopts->{action};
@ -3789,7 +3785,7 @@ sub config_to_command {
die "scsi$drive->{index}: machine version 4.1~pve2 or higher is required to use more than 14 SCSI disks\n" die "scsi$drive->{index}: machine version 4.1~pve2 or higher is required to use more than 14 SCSI disks\n"
if $drive->{index} > 13 && !&$version_guard(4, 1, 2); if $drive->{index} > 13 && !&$version_guard(4, 1, 2);
$pciaddr = print_pci_addr("$controller_prefix$controller", $bridges, $arch, $machine_type); my $pciaddr = print_pci_addr("$controller_prefix$controller", $bridges, $arch, $machine_type);
my $scsihw_type = $scsihw =~ m/^virtio-scsi-single/ ? "virtio-scsi-pci" : $scsihw; my $scsihw_type = $scsihw =~ m/^virtio-scsi-single/ ? "virtio-scsi-pci" : $scsihw;
my $iothread = ''; my $iothread = '';
@ -3812,7 +3808,7 @@ sub config_to_command {
if ($drive->{interface} eq 'sata') { if ($drive->{interface} eq 'sata') {
my $controller = int($drive->{index} / $PVE::QemuServer::Drive::MAX_SATA_DISKS); my $controller = int($drive->{index} / $PVE::QemuServer::Drive::MAX_SATA_DISKS);
$pciaddr = print_pci_addr("ahci$controller", $bridges, $arch, $machine_type); my $pciaddr = print_pci_addr("ahci$controller", $bridges, $arch, $machine_type);
push @$devices, '-device', "ahci,id=ahci$controller,multifunction=on$pciaddr" push @$devices, '-device', "ahci,id=ahci$controller,multifunction=on$pciaddr"
if !$ahcicontroller->{$controller}; if !$ahcicontroller->{$controller};
$ahcicontroller->{$controller}=1; $ahcicontroller->{$controller}=1;
@ -3877,15 +3873,12 @@ sub config_to_command {
# pci.4 is nested in pci.1 # pci.4 is nested in pci.1
$bridges->{1} = 1 if $bridges->{4}; $bridges->{1} = 1 if $bridges->{4};
if (!$q35) { if (!$q35) { # add pci bridges
# add pci bridges
if (min_version($machine_version, 2, 3)) { if (min_version($machine_version, 2, 3)) {
$bridges->{1} = 1; $bridges->{1} = 1;
$bridges->{2} = 1; $bridges->{2} = 1;
} }
$bridges->{3} = 1 if $scsihw =~ m/^virtio-scsi-single/; $bridges->{3} = 1 if $scsihw =~ m/^virtio-scsi-single/;
} }
for my $k (sort {$b cmp $a} keys %$bridges) { for my $k (sort {$b cmp $a} keys %$bridges) {
@ -3895,11 +3888,10 @@ sub config_to_command {
if ($k == 2 && $legacy_igd) { if ($k == 2 && $legacy_igd) {
$k_name = "$k-igd"; $k_name = "$k-igd";
} }
$pciaddr = print_pci_addr("pci.$k_name", undef, $arch, $machine_type); my $pciaddr = print_pci_addr("pci.$k_name", undef, $arch, $machine_type);
my $devstr = "pci-bridge,id=pci.$k,chassis_nr=$k$pciaddr"; my $devstr = "pci-bridge,id=pci.$k,chassis_nr=$k$pciaddr";
if ($q35) {
# add after -readconfig pve-q35.cfg if ($q35) { # add after -readconfig pve-q35.cfg
splice @$devices, 2, 0, '-device', $devstr; splice @$devices, 2, 0, '-device', $devstr;
} else { } else {
unshift @$devices, '-device', $devstr if $k > 0; unshift @$devices, '-device', $devstr if $k > 0;
@ -4030,22 +4022,15 @@ sub vm_deviceplug {
qemu_add_pci_bridge($storecfg, $conf, $vmid, $deviceid, $arch, $machine_type); qemu_add_pci_bridge($storecfg, $conf, $vmid, $deviceid, $arch, $machine_type);
if ($deviceid eq 'tablet') { if ($deviceid eq 'tablet') {
qemu_deviceadd($vmid, print_tabletdevice_full($conf, $arch)); qemu_deviceadd($vmid, print_tabletdevice_full($conf, $arch));
} elsif ($deviceid eq 'keyboard') { } elsif ($deviceid eq 'keyboard') {
qemu_deviceadd($vmid, print_keyboarddevice_full($conf, $arch)); qemu_deviceadd($vmid, print_keyboarddevice_full($conf, $arch));
} elsif ($deviceid =~ m/^usb(\d+)$/) { } elsif ($deviceid =~ m/^usb(\d+)$/) {
die "usb hotplug currently not reliable\n"; die "usb hotplug currently not reliable\n";
# since we can't reliably hot unplug all added usb devices and usb # since we can't reliably hot unplug all added usb devices and usb
# passthrough breaks live migration we disable usb hotplugging for now # passthrough breaks live migration we disable usb hotplugging for now
#qemu_deviceadd($vmid, PVE::QemuServer::USB::print_usbdevice_full($conf, $deviceid, $device)); #qemu_deviceadd($vmid, PVE::QemuServer::USB::print_usbdevice_full($conf, $deviceid, $device));
} elsif ($deviceid =~ m/^(virtio)(\d+)$/) { } elsif ($deviceid =~ m/^(virtio)(\d+)$/) {
qemu_iothread_add($vmid, $deviceid, $device); qemu_iothread_add($vmid, $deviceid, $device);
qemu_driveadd($storecfg, $vmid, $device); qemu_driveadd($storecfg, $vmid, $device);
@ -4058,10 +4043,7 @@ sub vm_deviceplug {
warn $@ if $@; warn $@ if $@;
die $err; die $err;
} }
} elsif ($deviceid =~ m/^(virtioscsi|scsihw)(\d+)$/) { } elsif ($deviceid =~ m/^(virtioscsi|scsihw)(\d+)$/) {
my $scsihw = defined($conf->{scsihw}) ? $conf->{scsihw} : "lsi"; my $scsihw = defined($conf->{scsihw}) ? $conf->{scsihw} : "lsi";
my $pciaddr = print_pci_addr($deviceid, undef, $arch, $machine_type); my $pciaddr = print_pci_addr($deviceid, undef, $arch, $machine_type);
my $scsihw_type = $scsihw eq 'virtio-scsi-single' ? "virtio-scsi-pci" : $scsihw; my $scsihw_type = $scsihw eq 'virtio-scsi-single' ? "virtio-scsi-pci" : $scsihw;
@ -4079,9 +4061,7 @@ sub vm_deviceplug {
qemu_deviceadd($vmid, $devicefull); qemu_deviceadd($vmid, $devicefull);
qemu_deviceaddverify($vmid, $deviceid); qemu_deviceaddverify($vmid, $deviceid);
} elsif ($deviceid =~ m/^(scsi)(\d+)$/) { } elsif ($deviceid =~ m/^(scsi)(\d+)$/) {
qemu_findorcreatescsihw($storecfg,$conf, $vmid, $device, $arch, $machine_type); qemu_findorcreatescsihw($storecfg,$conf, $vmid, $device, $arch, $machine_type);
qemu_driveadd($storecfg, $vmid, $device); qemu_driveadd($storecfg, $vmid, $device);
@ -4092,9 +4072,7 @@ sub vm_deviceplug {
warn $@ if $@; warn $@ if $@;
die $err; die $err;
} }
} elsif ($deviceid =~ m/^(net)(\d+)$/) { } elsif ($deviceid =~ m/^(net)(\d+)$/) {
return if !qemu_netdevadd($vmid, $conf, $arch, $device, $deviceid); return if !qemu_netdevadd($vmid, $conf, $arch, $device, $deviceid);
my $machine_type = PVE::QemuServer::Machine::qemu_machine_pxe($vmid, $conf); my $machine_type = PVE::QemuServer::Machine::qemu_machine_pxe($vmid, $conf);
@ -4113,16 +4091,13 @@ sub vm_deviceplug {
warn $@ if $@; warn $@ if $@;
die $err; die $err;
} }
} elsif (!$q35 && $deviceid =~ m/^(pci\.)(\d+)$/) { } elsif (!$q35 && $deviceid =~ m/^(pci\.)(\d+)$/) {
my $bridgeid = $2; my $bridgeid = $2;
my $pciaddr = print_pci_addr($deviceid, undef, $arch, $machine_type); my $pciaddr = print_pci_addr($deviceid, undef, $arch, $machine_type);
my $devicefull = "pci-bridge,id=pci.$bridgeid,chassis_nr=$bridgeid$pciaddr"; my $devicefull = "pci-bridge,id=pci.$bridgeid,chassis_nr=$bridgeid$pciaddr";
qemu_deviceadd($vmid, $devicefull); qemu_deviceadd($vmid, $devicefull);
qemu_deviceaddverify($vmid, $deviceid); qemu_deviceaddverify($vmid, $deviceid);
} else { } else {
die "can't hotplug device '$deviceid'\n"; die "can't hotplug device '$deviceid'\n";
} }