[pve-devel] [RFC qemu-server 2/2] QEMU: add comment fields

Matthias Heiserer m.heiserer at proxmox.com
Mon Feb 14 15:01:41 CET 2022


This patch adds comment fields to all values shown in the
QEMU/Hardware GUI.
As I tried to keep changes minimal, this is achieved in two
different ways:
 - adding `comment` as field. Easiest/simplest option,
    but not always possible, when data is stored as a single
    int (e.g memory). Although the UI stores the data as a
    URIComponent-encoded string, this is not yet checked in
    the perl code.

 - adding a separate `<name>_comment` field. Not that great,
    but it works. One advantage of this is that we don't have
    to encode/decode the data, but many new fields bloat the config.
    Changing this seems to require some more rewriting.

Signed-off-by: Matthias Heiserer <m.heiserer at proxmox.com>
---
 PVE/QemuServer.pm           | 49 ++++++++++++++++++++++++++++++++++---
 PVE/QemuServer/CPUConfig.pm |  7 ++++--
 PVE/QemuServer/Drive.pm     |  6 ++++-
 PVE/QemuServer/PCI.pm       |  4 ++-
 4 files changed, 58 insertions(+), 8 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 0071a06..3b2abfe 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -44,7 +44,7 @@ use PVE::Tools qw(run_command file_read_firstline file_get_contents dir_glob_for
 
 use PVE::QMPClient;
 use PVE::QemuConfig;
-use PVE::QemuServer::Helpers qw(min_version config_aware_timeout);
+use PVE::QemuServer::Helpers qw(min_version config_aware_timeout make_comment_fmt);
 use PVE::QemuServer::Cloudinit;
 use PVE::QemuServer::CGroup;
 use PVE::QemuServer::CPUConfig qw(print_cpu_device get_cpu_options);
@@ -205,6 +205,7 @@ my $vga_fmt = {
 	minimum => 4,
 	maximum => 512,
     },
+    comment => make_comment_fmt(),
 };
 
 my $ivshmem_fmt = {
@@ -235,6 +236,7 @@ my $audio_fmt = {
 	optional => 1,
 	description => "Driver backend for the audio device."
     },
+    comment => make_comment_fmt(),
 };
 
 my $spice_enhancements_fmt = {
@@ -284,6 +286,7 @@ my $rng_fmt = {
 	optional => 1,
 	default => 1000,
     },
+    comment => make_comment_fmt(),
 };
 
 my $meta_info_fmt = {
@@ -728,6 +731,31 @@ EODESCR
 	description => "Some (read-only) meta-information about this guest.",
 	optional => 1,
     },
+    sockets_comment => {
+	type => 'string',
+	optional => 1,
+	description => 'Comment on cpu',
+    },
+    memory_comment => {
+	type => 'string',
+	optional => 1,
+	description => 'Comment on memory',
+    },
+    bios_comment => {
+	type => 'string',
+	optional => 1,
+	description => 'Comment on bios',
+    },
+    machine_comment => {
+	type => 'string',
+	optional => 1,
+	description => 'Comment on machine',
+    },
+    scsihw_comment => {
+	type => 'string',
+	optional => 1,
+	description => 'Comment on SCSI controller',
+    },
 };
 
 my $cicustom_fmt = {
@@ -977,6 +1005,7 @@ my $net_fmt = {
 	description => "Force MTU, for VirtIO only. Set to '1' to use the bridge MTU",
 	optional => 1,
     },
+    comment => make_comment_fmt(),
 };
 
 my $netdesc = {
@@ -1093,6 +1122,7 @@ EODESCR
 	description => "Specifies whether if given host option is a USB3 device or port.",
         default => 0,
     },
+    comment => make_comment_fmt(),
 };
 
 my $usbdesc = {
@@ -1102,12 +1132,23 @@ my $usbdesc = {
 };
 PVE::JSONSchema::register_standard_option("pve-qm-usb", $usbdesc);
 
-my $serialdesc = {
+my $serial_fmt = {
+    serial => {
+	default_key => 1,
 	optional => 1,
 	type => 'string',
 	pattern => '(/dev/.+|socket)',
-	description =>  "Create a serial device inside the VM (n is 0 to 3)",
-	verbose_description =>  <<EODESCR,
+	format_description => '(/dev/.+|socket)',
+    },
+    comment => make_comment_fmt(),
+};
+
+my $serialdesc = {
+    optional => 1,
+    type => 'string',
+    format => $serial_fmt,
+    description =>  "Create a serial device inside the VM (n is 0 to 3)",
+    verbose_description =>  <<EODESCR,
 Create a serial device inside the VM (n is 0 to 3), and pass through a
 host serial device (i.e. /dev/ttyS0), or create a unix socket on the
 host side (use 'qm terminal' to open a terminal connection).
diff --git a/PVE/QemuServer/CPUConfig.pm b/PVE/QemuServer/CPUConfig.pm
index b9981c8..d83c1e9 100644
--- a/PVE/QemuServer/CPUConfig.pm
+++ b/PVE/QemuServer/CPUConfig.pm
@@ -5,7 +5,7 @@ use warnings;
 
 use PVE::JSONSchema;
 use PVE::Cluster qw(cfs_register_file cfs_read_file);
-use PVE::QemuServer::Helpers qw(min_version);
+use PVE::QemuServer::Helpers qw(min_version make_comment_fmt);
 
 use base qw(PVE::SectionConfig Exporter);
 
@@ -160,6 +160,7 @@ my $cpu_fmt = {
 		     . " doing so will break live migration to CPUs with other values.",
 	optional => 1,
     },
+    comment => make_comment_fmt(),
 };
 
 PVE::JSONSchema::register_format('pve-phys-bits', \&parse_phys_bits);
@@ -368,7 +369,9 @@ sub print_cpu_device {
     my $current_core = ($id - 1) % $cores;
     my $current_socket = int(($id - 1 - $current_core)/$cores);
 
-    return "$cpu-x86_64-cpu,id=cpu$id,socket-id=$current_socket,core-id=$current_core,thread-id=0";
+    my $comment = $conf->{comment} || '';
+
+    return "$cpu-x86_64-cpu,id=cpu$id,socket-id=$current_socket,core-id=$current_core,thread-id=0,comment=$comment";
 }
 
 # Resolves multiple arrays of hashes representing CPU flags with metadata to a
diff --git a/PVE/QemuServer/Drive.pm b/PVE/QemuServer/Drive.pm
index 7b82fb2..708d95e 100644
--- a/PVE/QemuServer/Drive.pm
+++ b/PVE/QemuServer/Drive.pm
@@ -5,6 +5,7 @@ use warnings;
 
 use PVE::Storage;
 use PVE::JSONSchema qw(get_standard_option);
+use PVE::QemuServer::Helpers qw(make_comment_fmt);
 
 use base qw(Exporter);
 
@@ -146,7 +147,8 @@ my %drivedesc_base = (
 	verbose_description => "Mark this locally-managed volume as available on all nodes.\n\nWARNING: This option does not share the volume automatically, it assumes it is shared already!",
 	optional => 1,
 	default => 0,
-    }
+    },
+    comment => make_comment_fmt(),
 );
 
 my %iothread_fmt = ( iothread => {
@@ -353,6 +355,7 @@ my $efidisk_fmt = {
 	description => "Disk size. This is purely informational and has no effect.",
 	optional => 1,
     },
+    comment => make_comment_fmt(),
     %efitype_fmt,
 };
 
@@ -393,6 +396,7 @@ my $tpmstate_fmt = {
 	optional => 1,
     },
     %tpmversion_fmt,
+    comment => make_comment_fmt(),
 };
 my $tpmstate_desc = {
     optional => 1,
diff --git a/PVE/QemuServer/PCI.pm b/PVE/QemuServer/PCI.pm
index 70987d8..a961bda 100644
--- a/PVE/QemuServer/PCI.pm
+++ b/PVE/QemuServer/PCI.pm
@@ -6,6 +6,7 @@ use strict;
 use PVE::JSONSchema;
 use PVE::SysFSTools;
 use PVE::Tools;
+use PVE::QemuServer::Helpers qw(make_comment_fmt);
 
 use base 'Exporter';
 
@@ -105,7 +106,8 @@ EODESCR
 	format_description => 'hex id',
 	optional => 1,
 	description => "Override PCI subsystem device ID visible to guest"
-    }
+    },
+    comment => make_comment_fmt(),
 };
 PVE::JSONSchema::register_format('pve-qm-hostpci', $hostpci_fmt);
 
-- 
2.30.2






More information about the pve-devel mailing list