use PVE::QemuConfig;
use PVE::QMPClient;
use PVE::RPCEnvironment;
+use PVE::GuestHelpers;
use PVE::QemuServer::PCI qw(print_pci_addr print_pcie_addr);
use PVE::QemuServer::Memory;
use PVE::QemuServer::USB qw(parse_usb_device);
optional => 1,
default => 0
},
+ 'hv-vendor-id' => {
+ type => 'string',
+ pattern => qr/[a-zA-Z0-9]{1,12}/,
+ format_description => 'vendor-id',
+ description => 'The Hyper-V vendor ID. Some drivers or programs inside Windows guests need a specific ID.',
+ optional => 1,
+ },
flags => {
description => "List of additional CPU flags separated by ';'."
. " Use '+FLAG' to enable, '-FLAG' to disable a flag."
default => 'std',
optional => 1,
default_key => 1,
- enum => [qw(cirrus qxl qxl2 qxl3 qxl4 serial0 serial1 serial2 serial3 std virtio vmware)],
+ enum => [qw(cirrus qxl qxl2 qxl3 qxl4 none serial0 serial1 serial2 serial3 std virtio vmware)],
},
memory => {
description => "Sets the VGA memory (in MiB). Has no effect with serial display.",
},
};
+my $ivshmem_fmt = {
+ size => {
+ type => 'integer',
+ minimum => 1,
+ description => "The size of the file in MB.",
+ },
+ name => {
+ type => 'string',
+ pattern => '[a-zA-Z0-9\-]+',
+ optional => 1,
+ format_description => 'string',
+ description => "The name of the file. Will be prefixed with 'pve-shm-'. Default is the VMID. Will be deleted when the VM is stopped.",
+ },
+};
+
my $confdesc = {
onboot => {
optional => 1,
optional => 1,
type => 'string',
description => "Lock/unlock the VM.",
- enum => [qw(migrate backup snapshot rollback)],
+ enum => [qw(backup clone create migrate rollback snapshot snapshot-delete)],
},
cpulimit => {
optional => 1,
default => "1 (autogenerated)",
optional => 1,
},
+ hookscript => {
+ type => 'string',
+ format => 'pve-volume-id',
+ optional => 1,
+ description => "Script that will be executed during various steps in the vms lifetime.",
+ },
+ ivshmem => {
+ type => 'string',
+ format => $ivshmem_fmt,
+ description => "Inter-VM shared memory. Useful for direct communication between VMs, or to the host.",
+ optional => 1,
+ }
};
my $confdesc_cloudinit = {
},
);
+my %wwn_fmt = (
+ wwn => {
+ type => 'string',
+ pattern => qr/^(0x)[0-9a-fA-F]{16}/,
+ format_description => 'wwn',
+ description => "The drive's worldwide name, encoded as 16 bytes hex string, prefixed by '0x'.",
+ optional => 1,
+ },
+);
+
my $add_throttle_desc = sub {
my ($key, $type, $what, $unit, $longunit, $minimum) = @_;
my $d = {
%drivedesc_base,
%model_fmt,
%ssd_fmt,
+ %wwn_fmt,
};
PVE::JSONSchema::register_format("pve-qm-ide", $ide_fmt);
%queues_fmt,
%scsiblock_fmt,
%ssd_fmt,
+ %wwn_fmt,
};
my $scsidesc = {
optional => 1,
my $sata_fmt = {
%drivedesc_base,
%ssd_fmt,
+ %wwn_fmt,
};
my $satadesc = {
optional => 1,
%queues_fmt,
%scsiblock_fmt,
%ssd_fmt,
+ %wwn_fmt,
};
my $efidisk_fmt = {
};
PVE::JSONSchema::register_standard_option("pve-qm-usb", $usbdesc);
-# NOTE: the match-groups of this regex are used in parse_hostpci
-my $PCIRE = qr/([a-f0-9]{2}:[a-f0-9]{2})(?:\.([a-f0-9]))?/;
+my $PCIRE = qr/[a-f0-9]{2}:[a-f0-9]{2}(?:\.[a-f0-9])?/;
my $hostpci_fmt = {
host => {
default_key => 1,
optional => 1,
default => 0,
},
+ 'mdev' => {
+ type => 'string',
+ format_description => 'string',
+ pattern => '[^/\.:]+',
+ optional => 1,
+ description => <<EODESCR
+The type of mediated device to use.
+An instance of this type will be created on startup of the VM and
+will be cleaned up when the VM stops.
+EODESCR
+ }
};
PVE::JSONSchema::register_format('pve-qm-hostpci', $hostpci_fmt);
}
-my $kernel_has_vhost_net = -c '/dev/vhost-net';
+sub kernel_has_vhost_net {
+ return -c '/dev/vhost-net';
+}
sub valid_drive_names {
# order is important - used to autoselect boot disk
if ($drive->{ssd} && ($devicetype eq 'block' || $devicetype eq 'hd')) {
$device .= ",rotation_rate=1";
}
+ $device .= ",wwn=$drive->{wwn}" if $drive->{wwn};
} elsif ($drive->{interface} eq 'ide' || $drive->{interface} eq 'sata') {
my $maxdev = ($drive->{interface} eq 'sata') ? $MAX_SATA_DISKS : 2;
$device .= ",rotation_rate=1";
}
}
+ $device .= ",wwn=$drive->{wwn}" if $drive->{wwn};
} elsif ($drive->{interface} eq 'usb') {
die "implement me";
# -device ide-drive,bus=ide.1,unit=0,drive=drive-ide0-1-0,id=ide0-1-0
my $vhostparam = '';
if (is_native($arch)) {
- $vhostparam = ',vhost=on' if $kernel_has_vhost_net && $net->{model} eq 'virtio';
+ $vhostparam = ',vhost=on' if kernel_has_vhost_net() && $net->{model} eq 'virtio';
}
my $vmname = $conf->{name} || "vm$vmid";
my ($conf, $vga, $arch, $machine, $id, $qxlnum, $bridges) = @_;
my $type = $vga_map->{$vga->{type}};
- if ($type eq 'virtio-vga' && $arch eq 'aarch64') {
+ if ($arch eq 'aarch64' && defined($type) && $type eq 'virtio-vga') {
$type = 'virtio-gpu';
}
my $vgamem_mb = $vga->{memory};
my @idlist = split(/;/, $res->{host});
delete $res->{host};
foreach my $id (@idlist) {
- if ($id =~ /^$PCIRE$/) {
- if (defined($2)) {
- push @{$res->{pciid}}, { id => $1, function => $2 };
- } else {
- my $pcidevices = PVE::SysFSTools::lspci($1);
- $res->{pciid} = $pcidevices->{$1};
- }
- } else {
- # should have been caught by parse_property_string already
- die "failed to parse PCI id: $id\n";
+ if ($id =~ m/\./) { # full id 00:00.1
+ push @{$res->{pciid}}, {
+ id => $id,
+ };
+ } else { # partial id 00:00
+ $res->{pciid} = PVE::SysFSTools::lspci($id);
}
}
return $res;
$loc_res = 1 if $conf->{hostusb}; # old syntax
$loc_res = 1 if $conf->{hostpci}; # old syntax
+ $loc_res = 1 if $conf->{ivshmem};
+
foreach my $k (keys %$conf) {
next if $k =~ m/^usb/ && ($conf->{$k} eq 'spice');
# sockets are safe: they will recreated be on the target side post-migrate
if ($arch eq 'aarch64') {
$cpu = 'cortex-a57';
}
+ my $hv_vendor_id;
if (my $cputype = $conf->{cpu}) {
my $cpuconf = PVE::JSONSchema::parse_property_string($cpu_fmt, $cputype)
or die "Cannot parse cpu description: $cputype\n";
$cpu = $cpuconf->{cputype};
$kvm_off = 1 if $cpuconf->{hidden};
+ $hv_vendor_id = $cpuconf->{'hv-vendor-id'};
if (defined(my $flags = $cpuconf->{flags})) {
push @$cpuFlags, split(";", $flags);
push @$cpuFlags , '+kvm_pv_eoi' if $kvm;
}
- add_hyperv_enlightenments($cpuFlags, $winversion, $machine_type, $kvmver, $conf->{bios}, $gpu_passthrough) if $kvm;
+ add_hyperv_enlightenments($cpuFlags, $winversion, $machine_type, $kvmver, $conf->{bios}, $gpu_passthrough, $hv_vendor_id) if $kvm;
push @$cpuFlags, 'enforce' if $cpu ne 'host' && $kvm && $arch eq 'x86_64';
my $pcie = $d->{pcie};
if($pcie){
die "q35 machine model is not enabled" if !$q35;
- $pciaddr = print_pcie_addr("hostpci$i");
+ # win7 wants to have the pcie devices directly on the pcie bus
+ # instead of in the root port
+ if ($winversion == 7) {
+ $pciaddr = print_pcie_addr("hostpci${i}bus0");
+ } else {
+ $pciaddr = print_pcie_addr("hostpci$i");
+ }
}else{
$pciaddr = print_pci_addr("hostpci$i", $bridges, $arch, $machine_type);
}
if ($d->{'x-vga'}) {
$xvga = ',x-vga=on';
$kvm_off = 1;
- $vga->{type} = 'none';
+ $vga->{type} = 'none' if !defined($conf->{vga});
$gpu_passthrough = 1;
if ($conf->{bios} && $conf->{bios} eq 'ovmf') {
}
my $pcidevices = $d->{pciid};
my $multifunction = 1 if @$pcidevices > 1;
+ my $sysfspath;
+ if ($d->{mdev} && scalar(@$pcidevices) == 1) {
+ my $id = $pcidevices->[0]->{id};
+ my $uuid = PVE::SysFSTools::generate_mdev_uuid($vmid, $i);
+ $sysfspath = "/sys/bus/pci/devices/0000:$id/$uuid";
+ } elsif ($d->{mdev}) {
+ warn "ignoring mediated device with multifunction device\n";
+ }
my $j=0;
foreach my $pcidevice (@$pcidevices) {
$id .= ".$j" if $multifunction;
my $addr = $pciaddr;
$addr .= ".$j" if $multifunction;
- my $devicestr = "vfio-pci,host=$pcidevice->{id}.$pcidevice->{function},id=$id$addr";
+ my $devicestr = "vfio-pci";
+ if ($sysfspath) {
+ $devicestr .= ",sysfsdev=$sysfspath";
+ } else {
+ $devicestr .= ",host=$pcidevice->{id}";
+ }
+ $devicestr .= ",id=$id$addr";
if($j == 0){
$devicestr .= "$rombar$xvga";
push @$devices, '-device', $netdevicefull;
}
+ if ($conf->{ivshmem}) {
+ my $ivshmem = PVE::JSONSchema::parse_property_string($ivshmem_fmt, $conf->{ivshmem});
+ my $bus;
+ if ($q35) {
+ $bus = print_pcie_addr("ivshmem");
+ } else {
+ $bus = print_pci_addr("ivshmem", $bridges, $arch, $machine_type);
+ }
+ my $path = '/dev/shm/pve-shm-';
+ if ($ivshmem->{name}) {
+ $path .= $ivshmem->{name};
+ } else {
+ $path .= $vmid;
+ }
+ push @$devices, '-device', "ivshmem-plain,memdev=ivshmem$bus,";
+ push @$devices, '-object', "memory-backend-file,id=ivshmem,share=on,mem-path=$path,size=$ivshmem->{size}M";
+ }
+
if (!$q35) {
# add pci bridges
if (qemu_machine_feature_enabled ($machine_type, $kvmver, 2, 3)) {
}
}
- # add custom args
- if ($conf->{args}) {
- my $aa = PVE::Tools::split_args($conf->{args});
- push @$cmd, @$aa;
- }
-
push @$cmd, @$devices;
push @$cmd, '-rtc', join(',', @$rtcFlags)
if scalar(@$rtcFlags);
push @$cmd, '-global', join(',', @$globalFlags)
if scalar(@$globalFlags);
+ # add custom args
+ if ($conf->{args}) {
+ my $aa = PVE::Tools::split_args($conf->{args});
+ push @$cmd, @$aa;
+ }
+
return wantarray ? ($cmd, $vollist, $spice_port) : $cmd;
}
'description' => 1,
'protection' => 1,
'vmstatestorage' => 1,
+ 'hookscript' => 1,
};
# hotplug changes in [PENDING]
}
}
+ PVE::GuestHelpers::exec_hookscript($conf, $vmid, 'pre-start', 1);
+
my ($cmd, $vollist, $spice_port) = config_to_command($storecfg, $vmid, $conf, $defaults, $forcemachine);
my $migrate_port = 0;
next if !$d;
my $pcidevices = $d->{pciid};
foreach my $pcidevice (@$pcidevices) {
- my $pciid = $pcidevice->{id}.".".$pcidevice->{function};
+ my $pciid = $pcidevice->{id};
my $info = PVE::SysFSTools::pci_device_info("0000:$pciid");
die "IOMMU not present\n" if !PVE::SysFSTools::check_iommu_support();
die "no pci device info for device '$pciid'\n" if !$info;
- die "can't unbind/bind pci group to vfio '$pciid'\n"
- if !PVE::SysFSTools::pci_dev_group_bind_to_vfio($pciid);
- die "can't reset pci device '$pciid'\n"
- if $info->{has_fl_reset} and !PVE::SysFSTools::pci_dev_reset($info);
+
+ if ($d->{mdev}) {
+ my $uuid = PVE::SysFSTools::generate_mdev_uuid($vmid, $i);
+ PVE::SysFSTools::pci_create_mdev_device($pciid, $uuid, $d->{mdev});
+ } else {
+ die "can't unbind/bind pci group to vfio '$pciid'\n"
+ if !PVE::SysFSTools::pci_dev_group_bind_to_vfio($pciid);
+ die "can't reset pci device '$pciid'\n"
+ if $info->{has_fl_reset} and !PVE::SysFSTools::pci_dev_reset($info);
+ }
}
}
PVE::Storage::activate_volumes($storecfg, $vollist);
- if (!check_running($vmid, 1)) {
+ if (-d "/sys/fs/cgroup/systemd/qemu.slice/$vmid.scope") {
eval {
run_command(['/bin/systemctl', 'stop', "$vmid.scope"],
outfunc => sub {}, errfunc => sub {});
property => "guest-stats-polling-interval",
value => 2) if (!defined($conf->{balloon}) || $conf->{balloon});
+ PVE::GuestHelpers::exec_hookscript($conf, $vmid, 'post-start');
});
}
}
sub vm_commandline {
- my ($storecfg, $vmid) = @_;
+ my ($storecfg, $vmid, $snapname) = @_;
my $conf = PVE::QemuConfig->load_config($vmid);
+ if ($snapname) {
+ my $snapshot = $conf->{snapshots}->{$snapname};
+ die "snapshot '$snapname' does not exist\n" if !defined($snapshot);
+
+ $snapshot->{digest} = $conf->{digest}; # keep file digest for API
+
+ $conf = $snapshot;
+ }
+
my $defaults = load_defaults();
my $cmd = config_to_command($storecfg, $vmid, $conf, $defaults);
unlink "/var/run/qemu-server/${vmid}.$ext";
}
+ if ($conf->{ivshmem}) {
+ my $ivshmem = PVE::JSONSchema::parse_property_string($ivshmem_fmt, $conf->{ivshmem});
+ unlink '/dev/shm/pve-shm-' . ($ivshmem->{name} // $vmid);
+ }
+
+ foreach my $key (keys %$conf) {
+ next if $key !~ m/^hostpci(\d+)$/;
+ my $hostpciindex = $1;
+ my $d = parse_hostpci($conf->{$key});
+ my $uuid = PVE::SysFSTools::generate_mdev_uuid($vmid, $hostpciindex);
+
+ foreach my $pci (@{$d->{pciid}}) {
+ my $pciid = $pci->{id};
+ PVE::SysFSTools::pci_cleanup_mdev_device($pciid, $uuid);
+ }
+ }
+
vmconfig_apply_pending($vmid, $conf, $storecfg) if $apply_pending_changes;
};
warn $@ if $@; # avoid errors - just warn
my $opts = PVE::JSONSchema::pve_parse_startup_order($conf->{startup});
$timeout = $opts->{down} if $opts->{down};
}
+ PVE::GuestHelpers::exec_hookscript($conf, $vmid, 'pre-stop');
}
$timeout = 60 if !defined($timeout);
my $name = undef;
if (drive_is_cloudinit($drive)) {
$name = "vm-$newvmid-cloudinit";
+ $snapname = undef;
# cloudinit only supports raw and qcow2 atm:
if ($dst_format eq 'qcow2') {
$name .= '.qcow2';
}
sub add_hyperv_enlightenments {
- my ($cpuFlags, $winversion, $machine_type, $kvmver, $bios, $gpu_passthrough) = @_;
+ my ($cpuFlags, $winversion, $machine_type, $kvmver, $bios, $gpu_passthrough, $hv_vendor_id) = @_;
return if $winversion < 6;
return if $bios && $bios eq 'ovmf' && $winversion < 8;
- push @$cpuFlags , 'hv_vendor_id=proxmox' if $gpu_passthrough;
+ if ($gpu_passthrough || defined($hv_vendor_id)) {
+ $hv_vendor_id //= 'proxmox';
+ push @$cpuFlags , "hv_vendor_id=$hv_vendor_id";
+ }
if (qemu_machine_feature_enabled ($machine_type, $kvmver, 2, 3)) {
push @$cpuFlags , 'hv_spinlocks=0x1fff';