+sub add_hyperv_enlightenments {
+ my ($cpuFlags, $winversion, $machine_type, $kvmver, $bios, $gpu_passthrough) = @_;
+
+ return if $winversion < 6;
+ return if $bios && $bios eq 'ovmf' && $winversion < 8;
+
+ push @$cpuFlags , 'hv_vendor_id=proxmox' if $gpu_passthrough;
+
+ if (qemu_machine_feature_enabled ($machine_type, $kvmver, 2, 3)) {
+ push @$cpuFlags , 'hv_spinlocks=0x1fff';
+ push @$cpuFlags , 'hv_vapic';
+ push @$cpuFlags , 'hv_time';
+ } else {
+ push @$cpuFlags , 'hv_spinlocks=0xffff';
+ }
+
+ if (qemu_machine_feature_enabled ($machine_type, $kvmver, 2, 6)) {
+ push @$cpuFlags , 'hv_reset';
+ push @$cpuFlags , 'hv_vpindex';
+ push @$cpuFlags , 'hv_runtime';
+ }
+
+ if ($winversion >= 7) {
+ push @$cpuFlags , 'hv_relaxed';
+ }
+}
+
+sub windows_version {
+ my ($ostype) = @_;
+
+ return 0 if !$ostype;
+
+ my $winversion = 0;
+
+ if($ostype eq 'wxp' || $ostype eq 'w2k3' || $ostype eq 'w2k') {
+ $winversion = 5;
+ } elsif($ostype eq 'w2k8' || $ostype eq 'wvista') {
+ $winversion = 6;
+ } elsif ($ostype =~ m/^win(\d+)$/) {
+ $winversion = $1;
+ }
+
+ return $winversion;
+}
+
+sub resolve_dst_disk_format {
+ my ($storecfg, $storeid, $src_volname, $format) = @_;
+ my ($defFormat, $validFormats) = PVE::Storage::storage_default_format($storecfg, $storeid);
+
+ if (!$format) {
+ # if no target format is specified, use the source disk format as hint
+ if ($src_volname) {
+ my $scfg = PVE::Storage::storage_config($storecfg, $storeid);
+ $format = qemu_img_format($scfg, $src_volname);
+ } else {
+ return $defFormat;
+ }
+ }
+
+ # test if requested format is supported - else use default
+ my $supported = grep { $_ eq $format } @$validFormats;
+ $format = $defFormat if !$supported;
+ return $format;
+}
+
+sub resolve_first_disk {
+ my $conf = shift;
+ my @disks = PVE::QemuServer::valid_drive_names();
+ my $firstdisk;
+ foreach my $ds (reverse @disks) {
+ next if !$conf->{$ds};
+ my $disk = PVE::QemuServer::parse_drive($ds, $conf->{$ds});
+ next if PVE::QemuServer::drive_is_cdrom($disk);
+ $firstdisk = $ds;
+ }
+ return $firstdisk;
+}
+
+sub generate_smbios1_uuid {
+ my ($uuid, $uuid_str);
+ UUID::generate($uuid);
+ UUID::unparse($uuid, $uuid_str);
+ return "uuid=$uuid_str";
+}
+