]> git.proxmox.com Git - qemu-server.git/blobdiff - PVE/QemuServer.pm
correct 'snapshot' flag description
[qemu-server.git] / PVE / QemuServer.pm
index 0ebe6e93cb784ab3d07553e6dbe8c9f89424a682..20d668274677794e91ff27e41235955a037d4b4d 100644 (file)
@@ -108,17 +108,28 @@ my $cpu_vendor_list = {
     coreduo => 'GenuineIntel',
     core2duo => 'GenuineIntel',
     Conroe  => 'GenuineIntel',
-    Penryn  => 'GenuineIntel', 
+    Penryn  => 'GenuineIntel',
     Nehalem  => 'GenuineIntel',
+    'Nehalem-IBRS'  => 'GenuineIntel',
     Westmere => 'GenuineIntel',
+    'Westmere-IBRS' => 'GenuineIntel',
     SandyBridge => 'GenuineIntel',
+    'SandyBridge-IBRS' => 'GenuineIntel',
     IvyBridge => 'GenuineIntel',
+    'IvyBridge-IBRS' => 'GenuineIntel',
     Haswell => 'GenuineIntel',
+    'Haswell-IBRS' => 'GenuineIntel',
     'Haswell-noTSX' => 'GenuineIntel',
+    'Haswell-noTSX-IBRS' => 'GenuineIntel',
     Broadwell => 'GenuineIntel',
+    'Broadwell-IBRS' => 'GenuineIntel',
     'Broadwell-noTSX' => 'GenuineIntel',
+    'Broadwell-noTSX-IBRS' => 'GenuineIntel',
     'Skylake-Client' => 'GenuineIntel',
-    
+    'Skylake-Client-IBRS' => 'GenuineIntel',
+    'Skylake-Server' => 'GenuineIntel',
+    'Skylake-Server-IBRS' => 'GenuineIntel',
+
     # AMD CPUs
     athlon => 'AuthenticAMD',
     phenom  => 'AuthenticAMD',
@@ -134,8 +145,11 @@ my $cpu_vendor_list = {
     kvm64 => 'default',
     qemu32 => 'default',
     qemu64 => 'default',
+    max => 'default',
 };
 
+my $cpu_flag = qr/[+-](pcid|spec-ctrl)/;
+
 my $cpu_fmt = {
     cputype => {
        description => "Emulated CPU type.",
@@ -150,6 +164,15 @@ my $cpu_fmt = {
        optional => 1,
        default => 0
     },
+    flags => {
+       description => "List of additional CPU flags separated by ';'."
+                    . " Use '+FLAG' to enable, '-FLAG' to disable a flag."
+                    . " Currently supported flags: 'pcid', 'spec-ctrl'.",
+       format_description => '+FLAG[;-FLAG...]',
+       type => 'string',
+       pattern => qr/$cpu_flag(;$cpu_flag)*/,
+       optional => 1,
+    },
 };
 
 my $watchdog_fmt = {
@@ -243,9 +266,10 @@ my $confdesc = {
     keyboard => {
        optional => 1,
        type => 'string',
-       description => "Keybord layout for vnc server. Default is read from the '/etc/pve/datacenter.conf' configuration file.",
+       description => "Keybord layout for vnc server. Default is read from the '/etc/pve/datacenter.conf' configuration file.".
+                      "It should not be necessary to set it.",
        enum => PVE::Tools::kvmkeymaplist(),
-       default => 'en-us',
+       default => undef,
     },
     name => {
        optional => 1,
@@ -281,7 +305,8 @@ w2k3;; Microsoft Windows 2003
 w2k8;; Microsoft Windows 2008
 wvista;; Microsoft Windows Vista
 win7;; Microsoft Windows 7
-win8;; Microsoft Windows 8/2012
+win8;; Microsoft Windows 8/2012/2012r2
+win10;; Microsoft Windows 10/2016
 l24;; Linux 2.4 Kernel
 l26;; Linux 2.6/3.X Kernel
 solaris;; Solaris/OpenSolaris/OpenIndiania kernel
@@ -728,7 +753,9 @@ my %drivedesc_base = (
     },
     snapshot => {
        type => 'boolean',
-       description => "Whether the drive should be included when making snapshots.",
+       description => "Controls qemu's snapshot mode feature."
+           . " If activated, changes made to the disk are temporary and will"
+           . " be discarded when the VM is shutdown.",
        optional => 1,
     },
     cache => {
@@ -1597,10 +1624,17 @@ sub print_drive_full {
    }
 
     my $opts = '';
-    my @qemu_drive_options = qw(heads secs cyls trans media format cache snapshot rerror werror aio discard);
+    my @qemu_drive_options = qw(heads secs cyls trans media format cache rerror werror aio discard);
     foreach my $o (@qemu_drive_options) {
-       $opts .= ",$o=$drive->{$o}" if $drive->{$o};
+       $opts .= ",$o=$drive->{$o}" if defined($drive->{$o});
+    }
+
+    # snapshot only accepts on|off
+    if (defined($drive->{snapshot})) {
+       my $v = $drive->{snapshot} ? 'on' : 'off';
+       $opts .= ",snapshot=$v";
     }
+
     foreach my $type (['', '-total'], [_rd => '-read'], [_wr => '-write']) {
        my ($dir, $qmpname) = @$type;
        if (my $v = $drive->{"mbps$dir"}) {
@@ -2589,6 +2623,8 @@ sub vmstatus {
     my $storecfg = PVE::Storage::config();
 
     my $list = vzlist();
+    my $defaults = load_defaults();
+
     my ($uptime) = PVE::ProcFSTools::read_proc_uptime(1);
 
     my $cpucount = $cpuinfo->{cpus} || 1;
@@ -2614,16 +2650,19 @@ sub vmstatus {
            $d->{maxdisk} = 0;
        }
 
-       $d->{cpus} = ($conf->{sockets} || 1) * ($conf->{cores} || 1);
+       $d->{cpus} = ($conf->{sockets} || $defaults->{sockets})
+           * ($conf->{cores} || $defaults->{cores});
        $d->{cpus} = $cpucount if $d->{cpus} > $cpucount;
        $d->{cpus} = $conf->{vcpus} if $conf->{vcpus};
 
        $d->{name} = $conf->{name} || "VM $vmid";
-       $d->{maxmem} = $conf->{memory} ? $conf->{memory}*(1024*1024) : 0;
+       $d->{maxmem} = $conf->{memory} ? $conf->{memory}*(1024*1024)
+           : $defaults->{memory}*(1024*1024);
 
        if ($conf->{balloon}) {
            $d->{balloon_min} = $conf->{balloon}*(1024*1024);
-           $d->{shares} = defined($conf->{shares}) ? $conf->{shares} : 1000;
+           $d->{shares} = defined($conf->{shares}) ? $conf->{shares}
+               : $defaults->{shares};
        }
 
        $d->{uptime} = 0;
@@ -2638,6 +2677,8 @@ sub vmstatus {
 
         $d->{template} = PVE::QemuConfig->is_template($conf);
 
+       $d->{serial} = 1 if conf_has_serial($conf);
+
        $res->{$vmid} = $d;
     }
 
@@ -2832,6 +2873,18 @@ sub foreach_volid {
     }
 }
 
+sub conf_has_serial {
+    my ($conf) = @_;
+
+    for (my $i = 0; $i < $MAX_SERIAL_PORTS; $i++)  {
+       if ($conf->{"serial$i"}) {
+           return 1;
+       }
+    }
+
+    return 0;
+}
+
 sub vga_conf_has_spice {
     my ($vga) = @_;
 
@@ -2901,20 +2954,27 @@ sub config_to_command {
        die "uefi base image not found\n" if ! -f $OVMF_CODE;
 
        my $path;
-       my $format = 'raw';
+       my $format;
        if (my $efidisk = $conf->{efidisk0}) {
            my $d = PVE::JSONSchema::parse_property_string($efidisk_fmt, $efidisk);
            my ($storeid, $volname) = PVE::Storage::parse_volume_id($d->{file}, 1);
+           $format = $d->{format};
            if ($storeid) {
                $path = PVE::Storage::path($storecfg, $d->{file});
+               if (!defined($format)) {
+                   my $scfg = PVE::Storage::storage_config($storecfg, $storeid);
+                   $format = qemu_img_format($scfg, $volname);
+               }
            } else {
                $path = $d->{file};
+               die "efidisk format must be specified\n"
+                   if !defined($format);
            }
-           $format = $d->{format} if $d->{format};
        } else {
            warn "no efidisk configured! Using temporary efivars disk.\n";
            $path = "/tmp/$vmid-ovmf.fd";
            PVE::Tools::file_copy($OVMF_VARS, $path, -s $OVMF_VARS);
+           $format = 'raw';
        }
 
        push @$cmd, '-drive', "if=pflash,unit=0,format=raw,readonly,file=$OVMF_CODE";
@@ -3129,6 +3189,10 @@ sub config_to_command {
            or die "Cannot parse cpu description: $cputype\n";
        $cpu = $cpuconf->{cputype};
        $kvm_off = 1 if $cpuconf->{hidden};
+
+       if (defined(my $flags = $cpuconf->{flags})) {
+           push @$cpuFlags, split(";", $flags);
+       }
     }
 
     push @$cpuFlags , '+lahf_lm' if $cpu eq 'kvm64';
@@ -4660,7 +4724,8 @@ sub vm_start {
        my $cpuunits = defined($conf->{cpuunits}) ? $conf->{cpuunits}
                                                  : $defaults->{cpuunits};
 
-       my %run_params = (timeout => $statefile ? undef : 30, umask => 0077);
+       my $start_timeout = $conf->{hugepages} ? 300 : 30;
+       my %run_params = (timeout => $statefile ? undef : $start_timeout, umask => 0077);
 
        my %properties = (
            Slice => 'qemu.slice',
@@ -5291,6 +5356,13 @@ sub restore_update_config_line {
        } else {
            print $outfd $line;
        }
+    } elsif (($line =~ m/^(smbios1: )(.*)/) && $unique) {
+       my ($uuid, $uuid_str);
+       UUID::generate($uuid);
+       UUID::unparse($uuid, $uuid_str);
+       my $smbios1 = parse_smbios1($2);
+       $smbios1->{uuid} = $uuid_str;
+       print $outfd $1.print_smbios1($smbios1)."\n";
     } else {
        print $outfd $line;
     }
@@ -5359,13 +5431,14 @@ sub update_disksize {
 
     my $changes;
 
-    my $used = {};
+    # used and unused disks
+    my $referenced = {};
 
     # Note: it is allowed to define multiple storages with same path (alias), so
     # we need to check both 'volid' and real 'path' (two different volid can point
     # to the same path).
 
-    my $usedpath = {};
+    my $referencedpath = {};
 
     # update size info
     foreach my $opt (keys %$conf) {
@@ -5374,10 +5447,10 @@ sub update_disksize {
            my $volid = $drive->{file};
            next if !$volid;
 
-           $used->{$volid} = 1;
+           $referenced->{$volid} = 1;
            if ($volid_hash->{$volid} &&
                (my $path = $volid_hash->{$volid}->{path})) {
-               $usedpath->{$path} = 1;
+               $referencedpath->{$path} = 1;
            }
 
            next if drive_is_cdrom($drive);
@@ -5397,21 +5470,24 @@ sub update_disksize {
        next if $opt !~ m/^unused\d+$/;
        my $volid = $conf->{$opt};
        my $path = $volid_hash->{$volid}->{path} if $volid_hash->{$volid};
-       if ($used->{$volid} || ($path && $usedpath->{$path})) {
+       if ($referenced->{$volid} || ($path && $referencedpath->{$path})) {
            $changes = 1;
            delete $conf->{$opt};
        }
+
+       $referenced->{$volid} = 1;
+       $referencedpath->{$path} = 1 if $path;
     }
 
     foreach my $volid (sort keys %$volid_hash) {
        next if $volid =~ m/vm-$vmid-state-/;
-       next if $used->{$volid};
+       next if $referenced->{$volid};
        my $path = $volid_hash->{$volid}->{path};
        next if !$path; # just to be sure
-       next if $usedpath->{$path};
+       next if $referencedpath->{$path};
        $changes = 1;
        PVE::QemuConfig->add_unused_volume($conf, $volid);
-       $usedpath->{$path} = 1; # avoid to add more than once (aliases)
+       $referencedpath->{$path} = 1; # avoid to add more than once (aliases)
     }
 
     return $changes;
@@ -5881,7 +5957,7 @@ sub qga_check_running {
 
     eval { vm_mon_cmd($vmid, "guest-ping", timeout => 3); };
     if ($@) {
-       warn "Qemu Guest Agent are not running - $@";
+       warn "Qemu Guest Agent is not running - $@";
        return 0;
     }
     return 1;
@@ -6078,7 +6154,8 @@ sub qemu_drive_mirror_monitor {
                last if $skipcomplete; #do the complete later
 
                if ($vmiddst && $vmiddst != $vmid) {
-                   if ($qga) {
+                   my $agent_running = $qga && qga_check_running($vmid);
+                   if ($agent_running) {
                        print "freeze filesystem\n";
                        eval { PVE::QemuServer::vm_mon_cmd($vmid, "guest-fsfreeze-freeze"); };
                    } else {
@@ -6089,7 +6166,7 @@ sub qemu_drive_mirror_monitor {
                    # if we clone a disk for a new target vm, we don't switch the disk
                    PVE::QemuServer::qemu_blockjobs_cancel($vmid, $jobs);
 
-                   if ($qga) {
+                   if ($agent_running) {
                        print "unfreeze filesystem\n";
                        eval { PVE::QemuServer::vm_mon_cmd($vmid, "guest-fsfreeze-thaw"); };
                    } else {