all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Fiona Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH qemu-server v3 2/3] config: add special class that prevents writing the configuration
Date: Wed, 12 Feb 2025 12:04:26 +0100	[thread overview]
Message-ID: <20250212110427.33757-3-f.ebner@proxmox.com> (raw)
In-Reply-To: <20250212110427.33757-1-f.ebner@proxmox.com>

To be used in the context of template backup, where a minimized
temporary configuration is created to start the VM in 'prelaunch'
mode. Issue a warning, so that code paths where this happens will be
noted and can be evaluated and adapted.

Since the code currently doesn't use blessed config objects, special
dispatching is needed to potentially defer to the new child class in
the write_config() method.

Suggested-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Suggested-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---

Changes in v3:
* use dedicated class

 PVE/Makefile              |  1 +
 PVE/QemuConfig.pm         | 15 +++++++++++++++
 PVE/QemuConfig/Makefile   |  5 +++++
 PVE/QemuConfig/NoWrite.pm | 25 +++++++++++++++++++++++++
 4 files changed, 46 insertions(+)
 create mode 100644 PVE/QemuConfig/Makefile
 create mode 100644 PVE/QemuConfig/NoWrite.pm

diff --git a/PVE/Makefile b/PVE/Makefile
index dc173681..440fbe77 100644
--- a/PVE/Makefile
+++ b/PVE/Makefile
@@ -11,4 +11,5 @@ install:
 	$(MAKE) -C VZDump install
 	$(MAKE) -C API2 install
 	$(MAKE) -C CLI install
+	$(MAKE) -C QemuConfig install
 	$(MAKE) -C QemuServer install
diff --git a/PVE/QemuConfig.pm b/PVE/QemuConfig.pm
index ffdf9f03..b60cc398 100644
--- a/PVE/QemuConfig.pm
+++ b/PVE/QemuConfig.pm
@@ -3,6 +3,8 @@ package PVE::QemuConfig;
 use strict;
 use warnings;
 
+use Scalar::Util qw(blessed);
+
 use PVE::AbstractConfig;
 use PVE::INotify;
 use PVE::JSONSchema;
@@ -561,6 +563,19 @@ sub get_derived_property {
     }
 }
 
+sub write_config {
+    my ($class, $vmid, $conf) = @_;
+
+    # Dispatch to class the object was blessed with if caller invoked the method via the
+    # 'PVE::QemuConfig' class name explicitly. This is hack, but the code currently doesn't
+    # generally use blessed config objects. Safeguard against infinite recursion.
+    if (blessed($conf) && !blessed($class)) {
+	return $conf->write_config($vmid, $conf);
+    }
+
+    return $class->SUPER::write_config($vmid, $conf);
+}
+
 # END implemented abstract methods from PVE::AbstractConfig
 
 sub has_cloudinit {
diff --git a/PVE/QemuConfig/Makefile b/PVE/QemuConfig/Makefile
new file mode 100644
index 00000000..c3a0d277
--- /dev/null
+++ b/PVE/QemuConfig/Makefile
@@ -0,0 +1,5 @@
+SOURCES=NoWrite.pm
+
+.PHONY: install
+install: ${SOURCES}
+	for i in ${SOURCES}; do install -D -m 0644 $$i ${DESTDIR}${PERLDIR}/PVE/QemuConfig/$$i; done
diff --git a/PVE/QemuConfig/NoWrite.pm b/PVE/QemuConfig/NoWrite.pm
new file mode 100644
index 00000000..f697506f
--- /dev/null
+++ b/PVE/QemuConfig/NoWrite.pm
@@ -0,0 +1,25 @@
+package PVE::QemuConfig::NoWrite;
+
+use strict;
+use warnings;
+
+use PVE::RESTEnvironment qw(log_warn);
+
+use base qw(PVE::QemuConfig);
+
+sub new {
+    my ($class, $conf) = @_;
+
+    bless($conf, $class);
+
+    return $conf;
+}
+
+sub write_config {
+    my ($class, $vmid, $conf) = @_;
+
+    log_warn("refusing to write temporary configuration");
+    return;
+}
+
+1;
-- 
2.39.5



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

  parent reply	other threads:[~2025-02-12 11:05 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-12 11:04 [pve-devel] [PATCH-SERIES qemu-server v3 0/3] fix #6007: fix PBS template backup for certain configurations Fiona Ebner
2025-02-12 11:04 ` [pve-devel] [PATCH qemu-server v3 1/3] backup: also restore VM power state for early failures Fiona Ebner
2025-02-12 11:04 ` Fiona Ebner [this message]
2025-02-18 11:03   ` [pve-devel] [PATCH qemu-server v3 2/3] config: add special class that prevents writing the configuration Wolfgang Bumiller
2025-02-18 13:08     ` [pve-devel] [PATCH qemu-server 0/2] follow-ups for "v3 fix #6007: fix PBS template backup for certain configurations" Fabian Grünbichler
2025-02-18 13:08       ` [pve-devel] [PATCH qemu-server 1/2] config: revamp NoWrite interface Fabian Grünbichler
2025-02-18 13:08       ` [pve-devel] [PATCH qemu-server 2/2] config: make attempts at writing out NoWrite configs fatal Fabian Grünbichler
2025-02-18 13:18       ` [pve-devel] [PATCH qemu-server 0/2] follow-ups for "v3 fix #6007: fix PBS template backup for certain configurations" Fiona Ebner
2025-02-12 11:04 ` [pve-devel] [PATCH qemu-server v3 3/3] fix #6007: template backup: use minimized configuration for handling the full vm start Fiona Ebner
2025-02-18 14:20 ` [pve-devel] applied-series: [PATCH-SERIES qemu-server v3 0/3] fix #6007: fix PBS template backup for certain configurations Fabian Grünbichler

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=20250212110427.33757-3-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