From: Fiona Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH qemu-server v2 11/18] move meta information handling to its own module
Date: Thu, 16 Jan 2025 12:50:47 +0100 [thread overview]
Message-ID: <20250116115054.124447-12-f.ebner@proxmox.com> (raw)
In-Reply-To: <20250116115054.124447-1-f.ebner@proxmox.com>
Like this, it can be used by modules that cannot depend on
QemuServer.pm without creating a cyclic dependency.
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
PVE/API2/Qemu.pm | 3 ++-
PVE/QemuServer.pm | 42 +++-------------------------------
PVE/QemuServer/Makefile | 1 +
PVE/QemuServer/MetaInfo.pm | 47 ++++++++++++++++++++++++++++++++++++++
4 files changed, 53 insertions(+), 40 deletions(-)
create mode 100644 PVE/QemuServer/MetaInfo.pm
diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 868049cb..60b8a4cc 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -35,6 +35,7 @@ use PVE::QemuServer::ImportDisk;
use PVE::QemuServer::Monitor qw(mon_cmd);
use PVE::QemuServer::Machine;
use PVE::QemuServer::Memory qw(get_current_memory);
+use PVE::QemuServer::MetaInfo;
use PVE::QemuServer::PCI;
use PVE::QemuServer::QMPHelpers;
use PVE::QemuServer::USB;
@@ -1205,7 +1206,7 @@ __PACKAGE__->register_method({
assert_scsi_feature_compatibility($opt, $conf, $storecfg, $param->{$opt});
}
- $conf->{meta} = PVE::QemuServer::new_meta_info_string();
+ $conf->{meta} = PVE::QemuServer::MetaInfo::new_meta_info_string();
my $vollist = [];
eval {
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 04d251e0..6f2a9aed 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -57,6 +57,7 @@ use PVE::QemuServer::CPUConfig qw(print_cpu_device get_cpu_options get_cpu_bitne
use PVE::QemuServer::Drive qw(is_valid_drivename checked_volume_format drive_is_cloudinit drive_is_cdrom drive_is_read_only parse_drive print_drive);
use PVE::QemuServer::Machine;
use PVE::QemuServer::Memory qw(get_current_memory);
+use PVE::QemuServer::MetaInfo;
use PVE::QemuServer::Monitor qw(mon_cmd);
use PVE::QemuServer::PCI qw(print_pci_addr print_pcie_addr print_pcie_root_port parse_hostpci);
use PVE::QemuServer::QMPHelpers qw(qemu_deviceadd qemu_devicedel qemu_objectadd qemu_objectdel);
@@ -281,21 +282,6 @@ my $rng_fmt = {
},
};
-my $meta_info_fmt = {
- 'ctime' => {
- type => 'integer',
- description => "The guest creation timestamp as UNIX epoch time",
- minimum => 0,
- optional => 1,
- },
- 'creation-qemu' => {
- type => 'string',
- description => "The QEMU (machine) version from the time this VM was created.",
- pattern => '\d+(\.\d+)+',
- optional => 1,
- },
-};
-
my $confdesc = {
onboot => {
optional => 1,
@@ -729,7 +715,7 @@ EODESCR
},
meta => {
type => 'string',
- format => $meta_info_fmt,
+ format => $PVE::QemuServer::MetaInfo::meta_info_fmt,
description => "Some (read-only) meta-information about this guest.",
optional => 1,
},
@@ -2058,32 +2044,10 @@ sub parse_rng {
return $res;
}
-sub parse_meta_info {
- my ($value) = @_;
-
- return if !$value;
-
- my $res = eval { parse_property_string($meta_info_fmt, $value) };
- warn $@ if $@;
- return $res;
-}
-
-sub new_meta_info_string {
- my () = @_; # for now do not allow to override any value
-
- return PVE::JSONSchema::print_property_string(
- {
- 'creation-qemu' => kvm_user_version(),
- ctime => "". int(time()),
- },
- $meta_info_fmt
- );
-}
-
sub qemu_created_version_fixups {
my ($conf, $forcemachine, $kvmver) = @_;
- my $meta = parse_meta_info($conf->{meta}) // {};
+ my $meta = PVE::QemuServer::MetaInfo::parse_meta_info($conf->{meta}) // {};
my $forced_vers = PVE::QemuServer::Machine::extract_version($forcemachine);
# check if we need to apply some handling for VMs that always use the latest machine version but
diff --git a/PVE/QemuServer/Makefile b/PVE/QemuServer/Makefile
index 89d12091..18fd13ea 100644
--- a/PVE/QemuServer/Makefile
+++ b/PVE/QemuServer/Makefile
@@ -7,6 +7,7 @@ SOURCES=PCI.pm \
Helpers.pm \
Monitor.pm \
Machine.pm \
+ MetaInfo.pm \
CPUConfig.pm \
CGroup.pm \
Drive.pm \
diff --git a/PVE/QemuServer/MetaInfo.pm b/PVE/QemuServer/MetaInfo.pm
new file mode 100644
index 00000000..a8cb6c5e
--- /dev/null
+++ b/PVE/QemuServer/MetaInfo.pm
@@ -0,0 +1,47 @@
+package PVE::QemuServer::MetaInfo;
+
+use strict;
+use warnings;
+
+use PVE::JSONSchema;
+
+use PVE::QemuServer::Helpers;
+
+our $meta_info_fmt = {
+ 'ctime' => {
+ type => 'integer',
+ description => "The guest creation timestamp as UNIX epoch time",
+ minimum => 0,
+ optional => 1,
+ },
+ 'creation-qemu' => {
+ type => 'string',
+ description => "The QEMU (machine) version from the time this VM was created.",
+ pattern => '\d+(\.\d+)+',
+ optional => 1,
+ },
+};
+
+sub parse_meta_info {
+ my ($value) = @_;
+
+ return if !$value;
+
+ my $res = eval { PVE::JSONSchema::parse_property_string($meta_info_fmt, $value) };
+ warn $@ if $@;
+ return $res;
+}
+
+sub new_meta_info_string {
+ my () = @_; # for now do not allow to override any value
+
+ return PVE::JSONSchema::print_property_string(
+ {
+ 'creation-qemu' => PVE::QemuServer::Helpers::kvm_user_version(),
+ ctime => "". int(time()),
+ },
+ $meta_info_fmt,
+ );
+}
+
+1;
--
2.39.5
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
next prev parent reply other threads:[~2025-01-16 11:52 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-16 11:50 [pve-devel] [PATCH qemu/qemu-server/docs v2 00/18] adapt to changes in QEMU machine version deprecation/removal Fiona Ebner
2025-01-16 11:50 ` [pve-devel] [PATCH qemu v2 01/18] adapt machine version deprecation for Proxmox VE Fiona Ebner
2025-01-16 11:50 ` [pve-devel] [PATCH qemu-server v2 02/18] machine: drop unused parameter from assert_valid_machine_property() helper Fiona Ebner
2025-01-16 11:50 ` [pve-devel] [PATCH qemu-server v2 03/18] move get_command_for_arch() helper to helpers module Fiona Ebner
2025-01-17 12:20 ` Thomas Lamprecht
2025-01-16 11:50 ` [pve-devel] [PATCH qemu-server v2 04/18] helpers: improve name for variable for mapping arch to binary Fiona Ebner
2025-01-17 12:19 ` Thomas Lamprecht
2025-01-16 11:50 ` [pve-devel] [PATCH qemu-server v2 05/18] move kvm_user_version() function to helpers module Fiona Ebner
2025-01-16 11:50 ` [pve-devel] [PATCH qemu-server v2 06/18] move get_vm_arch() helper " Fiona Ebner
2025-01-16 11:50 ` [pve-devel] [PATCH qemu-server v2 07/18] machine: add default_machine_for_arch() helper Fiona Ebner
2025-01-16 11:50 ` [pve-devel] [PATCH qemu-server v2 08/18] move get_installed_machine_version() helper to machine module Fiona Ebner
2025-01-16 11:50 ` [pve-devel] [PATCH qemu-server v2 09/18] move windows_get_pinned_machine_version() function " Fiona Ebner
2025-01-16 11:50 ` [pve-devel] [PATCH qemu-server v2 10/18] move get_vm_machine() " Fiona Ebner
2025-01-16 11:50 ` Fiona Ebner [this message]
2025-01-16 11:50 ` [pve-devel] [PATCH qemu-server v2 12/18] machine: get vm machine: fallback to creation QEMU version for windows starting with 9.1 Fiona Ebner
2025-01-17 9:19 ` Thomas Lamprecht
2025-01-17 9:27 ` Fiona Ebner
2025-01-17 9:58 ` Thomas Lamprecht
2025-01-16 11:50 ` [pve-devel] [PATCH qemu-server v2 13/18] machine: add check_and_pin_machine_string() helper Fiona Ebner
2025-01-16 11:50 ` [pve-devel] [PATCH qemu-server v2 14/18] api: update vm config: pin machine version when switching to windows os type Fiona Ebner
2025-01-16 11:50 ` [pve-devel] [PATCH qemu-server v2 15/18] machine: log informational line when pinning machine version for Windows guest Fiona Ebner
2025-01-16 11:50 ` [pve-devel] [PATCH qemu-server v2 16/18] machine: rename machine_version() function to machine_version_at_least() Fiona Ebner
2025-01-17 12:39 ` Thomas Lamprecht
2025-01-17 13:33 ` Fiona Ebner
2025-01-17 13:43 ` Thomas Lamprecht
2025-01-16 11:50 ` [pve-devel] [PATCH qemu-server v2 17/18] machine: code cleanup: avoid superfluous augmented assignment operator Fiona Ebner
2025-01-16 11:50 ` [pve-devel] [PATCH docs v2 18/18] qm: machine version: document support in PVE Fiona Ebner
2025-01-17 13:07 ` Thomas Lamprecht
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250116115054.124447-12-f.ebner@proxmox.com \
--to=f.ebner@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal