From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH guest-common 09/34] abstract config: assign a guest identity and keep it on config writes
Date: Mon, 16 Nov 2026 01:46:21 +0100 [thread overview]
Message-ID: <20261116004703.2908294-10-t.lamprecht@proxmox.com> (raw)
In-Reply-To: <20261116004703.2908294-1-t.lamprecht@proxmox.com>
With identities enabled for a guest type, every config write keeps the
identity that the guest already has, regardless of the identity in the
written config, and assigns a new one if the guest has none. This
covers new guests and guests from older versions without identity
handling in every operation. A stale config, a config copied from a
clone source, or a snapshot rollback can neither change nor duplicate
an identity that way. Taking over the uid of a backup needs a separate
check that no other guest in the cluster uses it.
Read the existing identity directly from the cluster filesystem, as
the parsed config in the cache can be outdated, and abort the write on
read errors. A failed IPC connection can look like a missing or empty
file, so verify such a result against the mounted filesystem before
assigning an identity. A file that cannot be checked does not count as
missing.
Some writers, including the container post-stop hook, do not hold the
guest config lock. Read the identity and write the config under a short
local lock, so that concurrent writers cannot assign different
identities.
Guest types have to enable this explicitly: older qemu-server versions
validate 'meta' strictly on writes and would reject a config with the
identity members.
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
---
src/PVE/AbstractConfig.pm | 111 ++++++-
src/tests/Makefile | 7 +-
src/tests/config-identity-tests.pl | 488 +++++++++++++++++++++++++++++
3 files changed, 603 insertions(+), 3 deletions(-)
create mode 100755 src/tests/config-identity-tests.pl
diff --git a/src/PVE/AbstractConfig.pm b/src/PVE/AbstractConfig.pm
index 7bcae19..e78b8cc 100644
--- a/src/PVE/AbstractConfig.pm
+++ b/src/PVE/AbstractConfig.pm
@@ -3,6 +3,8 @@ package PVE::AbstractConfig;
use strict;
use warnings;
+use Errno qw(ENOENT);
+
use PVE::Cluster;
use PVE::INotify;
use PVE::JSONSchema;
@@ -10,6 +12,7 @@ use PVE::Storage;
use PVE::Tools qw(lock_file lock_file_full);
use PVE::GuestHelpers qw(typesafe_ne);
+use PVE::GuestIdentity;
use PVE::ReplicationConfig;
use PVE::Replication;
@@ -61,13 +64,119 @@ sub load_config {
return $conf;
}
+# Guest identity, see PVE::GuestIdentity
+
+# Whether writing a config keeps the published guest identity, or assigns one if there is none,
+# see write_config. Only enable it for a guest type whose config format accepts the identity
+# members, as a strict parser would otherwise reject every written config.
+sub __identity_enabled {
+ my ($class) = @_;
+
+ return 0;
+}
+
+# Returns the guest identity contained in the parsed config $conf, undef if there is none. Guest
+# types can override this and __identity_set for a different representation of 'meta' in parsed
+# configs, but the config file must have the identity in the top-level 'meta' property string, as
+# that is where the published identity gets read from.
+sub __identity_get {
+ my ($class, $conf) = @_;
+
+ return PVE::GuestIdentity::parse_identity($conf->{meta});
+}
+
+# Sets the guest identity $identity in the parsed config $conf, keeping everything else.
+sub __identity_set {
+ my ($class, $conf, $identity) = @_;
+
+ $conf->{meta} = PVE::GuestIdentity::merge_identity($conf->{meta}, $identity);
+}
+
+# Returns the guest identity contained in the parsed config $conf, for example of a backup, undef
+# if there is none.
+sub get_identity {
+ my ($class, $conf) = @_;
+
+ return $class->__identity_get($conf);
+}
+
+# Runs $code with the local identity lock of $vmid held and returns its result. Every config write
+# takes it, also ones without the guest config lock like hooks, so never take another lock while
+# holding it. Tests can override it to run without access to the lock directory.
+sub __identity_lock {
+ my ($class, $vmid, $code, @param) = @_;
+
+ my $lockdir = $PVE::GuestHelpers::lockdir;
+ mkdir $lockdir;
+
+ my $res = lock_file("$lockdir/pve-guest-identity-$vmid", 10, $code, @param);
+ die $@ if $@;
+
+ return $res;
+}
+
+# Returns undef if no config file exists for $vmid on this node, otherwise a hash with the identity
+# published in its top-level section, undef if there is none. Reads the file directly, as the
+# parsed configs in the file cache can be outdated. Dies on other read errors. Tests can override
+# it to run without the cluster filesystem.
+sub __identity_read_published {
+ my ($class, $vmid) = @_;
+
+ my $raw = PVE::Cluster::get_config($class->cfs_config_path($vmid));
+ if (!defined($raw) || $raw eq '') {
+ # a failed connection to pmxcfs returns undef with errno left as it was, which can look
+ # like a missing file (ENOENT) or an empty one (no error)
+ my $path = $class->config_file($vmid);
+ my $size = -s $path;
+ # only a file known not to exist counts as missing, not one that cannot be checked
+ die "unable to check config file '$path' for its guest identity - $!\n"
+ if !defined($size) && $! != ENOENT;
+ die "unable to read config file '$path' to check its guest identity\n"
+ if defined($raw) ? $size : defined($size);
+ return undef if !defined($raw);
+ }
+
+ my $meta;
+ for my $line (split(/\n/, $raw)) {
+ last if $line =~ m/^\[/; # snapshot or other section
+ $meta = $1 if $line =~ m/^meta:\s*(.*?)\s*$/;
+ }
+
+ return { identity => PVE::GuestIdentity::parse_identity($meta) };
+}
+
# Generate and write config file for this VM/CT
+#
+# With guest identities enabled for the class, the identity published in the existing config file
+# gets set in $conf, whatever $conf contains, or a new one if none is published. So a config write
+# never changes a published identity.
sub write_config {
my ($class, $vmid, $conf) = @_;
my $cfspath = $class->cfs_config_path($vmid);
- PVE::Cluster::cfs_write_file($cfspath, $conf);
+ if (!$class->__identity_enabled()) {
+ PVE::Cluster::cfs_write_file($cfspath, $conf);
+ return;
+ }
+
+ $class->__identity_lock(
+ $vmid,
+ sub {
+ my $published = $class->__identity_read_published($vmid);
+ my $identity = $published && $published->{identity};
+
+ # a published uid without valid rtime can only come from a manual edit
+ if (!$identity || !defined($identity->{rtime})) {
+ $identity = PVE::GuestIdentity::new_identity($identity && $identity->{uid});
+ }
+
+ $class->__identity_set($conf, $identity);
+ PVE::Cluster::cfs_write_file($cfspath, $conf);
+ },
+ );
+
+ return;
}
# Pending changes related
diff --git a/src/tests/Makefile b/src/tests/Makefile
index 129a57e..ae66694 100644
--- a/src/tests/Makefile
+++ b/src/tests/Makefile
@@ -1,12 +1,15 @@
all:
-.PHONY: check abstract-config guest-identity hookscript
-check: abstract-config guest-identity hookscript
+.PHONY: check abstract-config config-identity guest-identity hookscript
+check: abstract-config config-identity guest-identity hookscript
abstract-config: abstract-config-tests.pl
perl -I.. ./abstract-config-tests.pl
+config-identity: config-identity-tests.pl
+ perl -I.. ./config-identity-tests.pl
+
guest-identity: guest-identity-tests.pl
perl -I.. ./guest-identity-tests.pl
diff --git a/src/tests/config-identity-tests.pl b/src/tests/config-identity-tests.pl
new file mode 100755
index 0000000..92864ca
--- /dev/null
+++ b/src/tests/config-identity-tests.pl
@@ -0,0 +1,488 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use lib qw(..);
+
+use Fcntl qw(:flock);
+use File::Path qw(make_path);
+use File::Temp qw(tempdir);
+use Storable qw(dclone);
+use Test::MockModule;
+use Test::More;
+
+use PVE::AbstractConfig;
+use PVE::GuestHelpers;
+use PVE::GuestIdentity;
+
+my $tmpdir = tempdir('config-identity-XXXXXX', DIR => '.', CLEANUP => 1);
+$PVE::GuestHelpers::lockdir = "$tmpdir/lock";
+
+# guest config classes using a minimal config file format, see below
+
+package PVE::TestConfig {
+ use base qw(PVE::AbstractConfig);
+
+ sub guest_type { return 'VM'; }
+
+ sub config_file_lock {
+ my ($class, $vmid) = @_;
+ return "$tmpdir/config-$vmid.lock";
+ }
+
+ sub cfs_config_path {
+ my ($class, $vmid, $node) = @_;
+ return "nodes/local/qemu-server/$vmid.conf";
+ }
+
+ # only checked for existence, the fake cluster filesystem below does not create it
+ sub config_file {
+ my ($class, $vmid, $node) = @_;
+ return "$tmpdir/etc-pve/" . $class->cfs_config_path($vmid, $node);
+ }
+
+ sub __identity_enabled { return 1; }
+
+ # just enough for snapshot rollbacks without volumes
+ sub valid_volume_keys { return (); }
+ sub __snapshot_check_running { return 0; }
+ sub __snapshot_rollback_vm_stop { return; }
+ sub __snapshot_rollback_get_unused { return []; }
+}
+
+package PVE::TestConfig::CT {
+ use base qw(PVE::TestConfig);
+
+ sub guest_type { return 'CT'; }
+
+ sub cfs_config_path {
+ my ($class, $vmid, $node) = @_;
+ return "nodes/local/lxc/$vmid.conf";
+ }
+}
+
+package PVE::TestConfig::NoIdentity {
+ use base qw(PVE::TestConfig);
+
+ sub __identity_enabled { return 0; }
+}
+
+# like the tests of a guest type that run without lock directory and cluster filesystem
+package PVE::TestConfig::Seams {
+ use base qw(PVE::TestConfig);
+
+ our $published = {};
+
+ sub __identity_lock {
+ my ($class, $vmid, $code, @param) = @_;
+ return $code->(@param);
+ }
+
+ sub __identity_read_published {
+ my ($class, $vmid) = @_;
+ return $published->{$vmid};
+ }
+}
+
+package main;
+
+# fake cluster filesystem with raw config files, indexed by their cfs path, and a file cache that
+# behaves like the one of PVE::Cluster: it only reads a config again after a write of this process,
+# or after cfs_update noticed a newer version
+
+my $files = {};
+my $versions = {};
+my $version_counter = 0;
+my $seen_versions = {};
+my $cache = {};
+
+our $get_config_error;
+our $check_identity_lock = 1;
+
+my $reads = 0;
+my $writes = 0;
+
+sub parse_test_config {
+ my ($raw) = @_;
+
+ my $conf = { snapshots => {} };
+ my $section = $conf;
+ for my $line (split(/\n/, $raw)) {
+ next if $line =~ m/^\s*$/;
+ if ($line =~ m/^\[([^\]]+)\]$/) {
+ $section = $conf->{snapshots}->{$1} = {};
+ } elsif ($line =~ m/^([a-z][a-z0-9_\-]*):\s*(.*?)\s*$/) {
+ $section->{$1} = $2;
+ } else {
+ die "test error: unable to parse config line '$line'\n";
+ }
+ }
+
+ return $conf;
+}
+
+sub write_test_config {
+ my ($conf) = @_;
+
+ my $print_section = sub {
+ my ($section) = @_;
+ return join('',
+ map { "$_: $section->{$_}\n" } grep { !ref($section->{$_}) } sort keys %$section);
+ };
+
+ my $raw = $print_section->($conf);
+ for my $snapname (sort keys(($conf->{snapshots} // {})->%*)) {
+ $raw .= "\n[$snapname]\n" . $print_section->($conf->{snapshots}->{$snapname});
+ }
+
+ return $raw;
+}
+
+sub vmid_of_path {
+ my ($path) = @_;
+ return $path =~ m!/(\d+)\.conf$! ? $1 : die "test error: unexpected path '$path'\n";
+}
+
+sub identity_lock_held {
+ my ($vmid) = @_;
+
+ open(my $fh, '>>', "$PVE::GuestHelpers::lockdir/pve-guest-identity-$vmid") or return 0;
+ my $free = flock($fh, LOCK_EX | LOCK_NB);
+ close($fh);
+
+ return !$free;
+}
+
+my $cluster_module = Test::MockModule->new('PVE::Cluster');
+$cluster_module->redefine(
+ cfs_update => sub {
+ $seen_versions = { $versions->%* };
+ return;
+ },
+ cfs_read_file => sub {
+ my ($path) = @_;
+ my $version = $seen_versions->{$path};
+ my $entry = $cache->{$path};
+ if (!$entry || !$entry->{version} || !$version || $entry->{version} != $version) {
+ my $raw = $files->{$path};
+ my $data = defined($raw) ? parse_test_config($raw) : undef;
+ $entry = $cache->{$path} = { version => $version, data => $data };
+ }
+ return defined($entry->{data}) ? dclone($entry->{data}) : undef;
+ },
+ cfs_write_file => sub {
+ my ($path, $conf) = @_;
+ my $vmid = vmid_of_path($path);
+ die "test error: config of $vmid written without identity lock\n"
+ if $check_identity_lock && !identity_lock_held($vmid);
+ $writes++;
+ $files->{$path} = write_test_config($conf);
+ $versions->{$path} = ++$version_counter;
+ $cache->{$path}->{version} = undef if $cache->{$path};
+ },
+ get_config => sub {
+ my ($path) = @_;
+ my $vmid = vmid_of_path($path);
+ die "test error: config of $vmid read without identity lock\n"
+ if !identity_lock_held($vmid);
+ die $get_config_error if $get_config_error;
+ $reads++;
+ return $files->{$path};
+ },
+);
+
+# deterministic identities: uids count up, the time is set by the tests
+
+my $uid_counter = 0;
+my $now = 1_700_000_000_000;
+
+my $identity_module = Test::MockModule->new('PVE::GuestIdentity');
+$identity_module->redefine(
+ __random_bytes => sub {
+ my ($len) = @_;
+ return pack('N', ++$uid_counter) . ("\0" x ($len - 4));
+ },
+ __time_ms => sub { return $now; },
+);
+
+my sub new_uid {
+ return PVE::GuestIdentity::new_identity()->{uid};
+}
+
+my sub file_of {
+ my ($class, $vmid) = @_;
+ return $files->{ $class->cfs_config_path($vmid) };
+}
+
+my sub conf_of {
+ my ($class, $vmid) = @_;
+ my $raw = file_of($class, $vmid);
+ return defined($raw) ? parse_test_config($raw) : undef;
+}
+
+my sub identity_of {
+ my ($class, $vmid) = @_;
+ my $conf = conf_of($class, $vmid) or return undef;
+ return PVE::GuestIdentity::parse_identity($conf->{meta});
+}
+
+# write of another process, the file cache of this process does not notice it
+my sub set_file {
+ my ($class, $vmid, $raw) = @_;
+ my $path = $class->cfs_config_path($vmid);
+ $files->{$path} = $raw;
+ $versions->{$path} = ++$version_counter;
+}
+
+my $foreign_uid = new_uid();
+
+subtest 'disabled by default' => sub {
+ ok(!PVE::AbstractConfig->__identity_enabled(), 'abstract config does not enable it');
+
+ local $check_identity_lock = 0;
+ my $class = 'PVE::TestConfig::NoIdentity';
+ my $reads_before = $reads;
+
+ my $res = [$class->write_config(100, { name => 'a' })];
+ is(file_of($class, 100), "name: a\n", 'config without identity written as is');
+ is_deeply($res, [], 'nothing is returned');
+
+ my $meta = "ctime=1,rtime=5,uid=$foreign_uid";
+ $class->write_config(100, { name => 'a', meta => $meta });
+ is(file_of($class, 100), "meta: $meta\nname: a\n", 'carried identity written as is');
+
+ is($reads, $reads_before, 'published identity is not read');
+};
+
+subtest 'none published' => sub {
+ my $class = 'PVE::TestConfig';
+
+ my $conf = { name => 'new' };
+ my $res = [$class->write_config(101, $conf)];
+ my $identity = identity_of($class, 101);
+ ok($identity, 'new config gets an identity');
+ is($identity->{rtime}, $now, 'rtime is the current time');
+ is_deeply($class->get_identity($conf), $identity, 'identity is set in the written hash');
+ is_deeply($res, [], 'nothing is returned');
+
+ # copied from a clone source, a snapshot, or a backup
+ $class->write_config(102, { name => 'clone', meta => "ctime=7,rtime=5,uid=$foreign_uid" });
+ $identity = identity_of($class, 102);
+ isnt($identity->{uid}, $foreign_uid, 'carried identity is not published');
+ is($identity->{rtime}, $now, 'carried rtime is not published');
+ like(
+ file_of($class, 102),
+ qr/^meta: ctime=7,rtime=$now,uid=[a-z2-7]{20}$/m,
+ 'other members are kept',
+ );
+
+ set_file($class, 103, "meta: ctime=1\nname: old\n");
+ $class->write_config(103, conf_of($class, 103));
+ $identity = identity_of($class, 103);
+ ok($identity, 'existing config without identity gets one');
+ like(file_of($class, 103), qr/^meta: ctime=1,rtime=$now,uid=/m, 'other members are kept');
+
+ set_file($class, 104, "name: old\n\n[snap]\nmeta: rtime=1,uid=$foreign_uid\n");
+ $class->write_config(104, conf_of($class, 104));
+ isnt(identity_of($class, 104)->{uid}, $foreign_uid, 'identity of a snapshot is ignored');
+ like(
+ file_of($class, 104),
+ qr/^\[snap\]\nmeta: rtime=1,uid=$foreign_uid$/m,
+ 'snapshot keeps its copy',
+ );
+
+ set_file($class, 105, '');
+ $class->write_config(105, { name => 'empty' });
+ ok(identity_of($class, 105), 'existing empty config gets an identity');
+};
+
+subtest 'published identity wins' => sub {
+ my $class = 'PVE::TestConfig';
+
+ $class->write_config(110, { name => 'a', meta => 'ctime=1' });
+ my $published = identity_of($class, 110);
+ my $stale = new_uid();
+
+ $now += 1000;
+
+ my $tests = [
+ [{ name => 'b' }, 'missing identity'],
+ [{ name => 'b', meta => 'ctime=1' }, 'missing identity members'],
+ [{ name => 'b', meta => "ctime=1,rtime=5,uid=$stale" }, 'stale identity'],
+ [{ name => 'b', meta => "ctime=1,rtime=$now,uid=$foreign_uid" }, 'foreign identity'],
+ [{ name => 'b', meta => "ctime=1,rtime=5,uid=bogus" }, 'invalid identity'],
+ [{ name => 'b', meta => "ctime=1,uid=$published->{uid}" }, 'identity without rtime'],
+ ];
+
+ for my $test (@$tests) {
+ my ($conf, $name) = @$test;
+ my $other_members = $conf->{meta} && $conf->{meta} =~ m/ctime=1/;
+
+ $class->write_config(110, $conf);
+ is_deeply(identity_of($class, 110), $published, "$name: published identity is kept");
+ is_deeply($class->get_identity($conf), $published, "$name: hash has it too");
+ like(file_of($class, 110), qr/^meta: ctime=1,/m, "$name: other members are kept")
+ if $other_members;
+ }
+
+ set_file($class, 111, "meta: ctime=1,uid=$stale\nname: old\n");
+ $class->write_config(111, conf_of($class, 111));
+ is_deeply(
+ identity_of($class, 111),
+ { uid => $stale, rtime => $now },
+ 'published uid without rtime is kept and gets the current time',
+ );
+
+ my ($first, $last) = (new_uid(), new_uid());
+ set_file($class, 112, "meta: rtime=1,uid=$first\nname: x\nmeta: rtime=2,uid=$last\n");
+ $class->write_config(112, { name => 'y' });
+ is_deeply(
+ identity_of($class, 112),
+ { uid => $last, rtime => 2 },
+ 'last top-level meta line counts, like for the config parsers',
+ );
+};
+
+subtest 'read and write under identity lock' => sub {
+ my $class = 'PVE::TestConfig';
+
+ # the cluster filesystem mocks die without the lock, the lock is gone afterwards
+ $class->write_config(120, { name => 'a' });
+ ok(identity_of($class, 120), 'written');
+ ok(!identity_lock_held(120), 'lock is released');
+
+ $class->lock_config(120, sub { $class->write_config(120, conf_of($class, 120)) });
+ ok(!identity_lock_held(120), 'lock is released when nested in config lock');
+};
+
+subtest 'read errors are fatal' => sub {
+ my $class = 'PVE::TestConfig';
+
+ $class->write_config(130, { name => 'a' });
+ my $raw = file_of($class, 130);
+
+ {
+ local $get_config_error = "Connection refused\n";
+ eval { $class->write_config(130, { name => 'b' }) };
+ is($@, "Connection refused\n", 'write dies');
+ is(file_of($class, 130), $raw, 'config is unchanged');
+
+ eval { $class->write_config(131, { name => 'b' }) };
+ is($@, "Connection refused\n", 'write of new config dies');
+ ok(!defined(file_of($class, 131)), 'config is not written');
+ }
+
+ # the read reports a missing file, but the mounted filesystem has it
+ my $path = $class->config_file(132);
+ make_path($path =~ s!/[^/]+$!!r);
+ open(my $fh, '>', $path) or die "unable to create '$path' - $!\n";
+ close($fh);
+ eval { $class->write_config(132, { name => 'b' }) };
+ like(
+ $@,
+ qr/^unable to read config file '\Q$path\E'/,
+ 'inconsistent missing file is an error',
+ );
+ ok(!defined(file_of($class, 132)), 'config is not written');
+
+ # the read reports an empty file, but the mounted filesystem has content
+ set_file($class, 133, '');
+ $path = $class->config_file(133);
+ open($fh, '>', $path) or die "unable to create '$path' - $!\n";
+ print $fh "name: a\n";
+ close($fh);
+ eval { $class->write_config(133, { name => 'b' }) };
+ like(
+ $@,
+ qr/^unable to read config file '\Q$path\E'/,
+ 'inconsistent empty file is an error',
+ );
+ is(file_of($class, 133), '', 'config is not written');
+
+ # empty for both, a config without identity
+ set_file($class, 134, '');
+ $path = $class->config_file(134);
+ open($fh, '>', $path) or die "unable to create '$path' - $!\n";
+ close($fh);
+ $class->write_config(134, { name => 'b' });
+ ok(identity_of($class, 134), 'empty file gets an identity');
+
+ # the mounted filesystem cannot be checked either, like while pmxcfs restarts
+ my $not_a_dir = "$tmpdir/not-a-dir";
+ open($fh, '>', $not_a_dir) or die "unable to create '$not_a_dir' - $!\n";
+ close($fh);
+ my $config_module = Test::MockModule->new('PVE::TestConfig', no_auto => 1);
+ $config_module->redefine(config_file => sub { return "$not_a_dir/$_[1].conf"; });
+
+ eval { $class->write_config(135, { name => 'b' }) };
+ like(
+ $@,
+ qr/^unable to check config file '\Q$not_a_dir\E\/135\.conf' for its guest identity - /,
+ 'missing file that cannot be checked is an error',
+ );
+ ok(!defined(file_of($class, 135)), 'config is not written');
+
+ set_file($class, 136, '');
+ eval { $class->write_config(136, { name => 'b' }) };
+ like(
+ $@,
+ qr/^unable to check config file '\Q$not_a_dir\E\/136\.conf' for its guest identity - /,
+ 'empty file that cannot be checked is an error',
+ );
+ is(file_of($class, 136), '', 'config is not written');
+};
+
+subtest 'snapshot rollback' => sub {
+ my $class = 'PVE::TestConfig';
+
+ my $storage_module = Test::MockModule->new('PVE::Storage');
+ $storage_module->redefine(config => sub { return {}; });
+ my $replication_module = Test::MockModule->new('PVE::ReplicationConfig');
+ $replication_module->redefine(
+ new => sub { return bless({}, 'PVE::ReplicationConfig'); },
+ check_for_existing_jobs => sub { return 0; },
+ );
+
+ $class->write_config(140, { name => 'current', meta => 'ctime=2' });
+ my $published = identity_of($class, 140);
+
+ my $conf = conf_of($class, 140);
+ $conf->{snapshots}->{old} = { name => 'old', meta => "ctime=1,rtime=5,uid=$foreign_uid" };
+ $conf->{snapshots}->{none} = { name => 'none' };
+ $class->write_config(140, $conf);
+
+ $now += 1000;
+
+ for my $snapname (qw(old none)) {
+ $class->snapshot_rollback(140, $snapname);
+ $conf = conf_of($class, 140);
+ is($conf->{name}, $snapname, "rolled back to '$snapname'");
+ is_deeply(identity_of($class, 140), $published,
+ "'$snapname': current identity is kept");
+ }
+ is(
+ $conf->{snapshots}->{old}->{meta},
+ "ctime=1,rtime=5,uid=$foreign_uid",
+ 'snapshot is unchanged',
+ );
+};
+
+subtest 'overridden lock and published identity read' => sub {
+ my $class = 'PVE::TestConfig::Seams';
+ local $check_identity_lock = 0;
+ my $reads_before = $reads;
+
+ $class->write_config(160, { name => 'a', meta => "rtime=5,uid=$foreign_uid" });
+ my $identity = identity_of($class, 160);
+ isnt($identity->{uid}, $foreign_uid, 'nothing published: new identity');
+
+ local $PVE::TestConfig::Seams::published->{161} = { identity => $identity };
+ $class->write_config(161, { name => 'b' });
+ is_deeply(identity_of($class, 161), $identity, 'published identity is kept');
+
+ is($reads, $reads_before, 'cluster filesystem is not read');
+ ok(!-e "$PVE::GuestHelpers::lockdir/pve-guest-identity-160", 'no lock file is used');
+};
+
+done_testing();
--
2.47.3
next prev parent reply other threads:[~2026-11-16 0:49 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 0:46 [PATCH cluster/guest-common/qemu-server/container/manager/docs 00/34] fix #7846: guest identity (uid) and cluster ID Thomas Lamprecht
2026-11-16 0:46 ` [PATCH cluster 01/34] pmxcfs: reject changes to the cluster ID file from user space Thomas Lamprecht
2026-11-16 0:46 ` [PATCH cluster 02/34] pmxcfs: generate a cluster ID on standalone nodes Thomas Lamprecht
2026-11-16 0:46 ` [PATCH cluster 03/34] pmxcfs: dfsm: add a callback that runs once all members are in sync Thomas Lamprecht
2026-11-16 0:46 ` [PATCH cluster 04/34] pmxcfs: quorum: pass the corosync membership to an optional listener Thomas Lamprecht
2026-11-16 0:46 ` [PATCH cluster 05/34] pmxcfs: dcdb: generate the cluster ID once the cluster is in sync Thomas Lamprecht
2026-11-16 0:46 ` [PATCH cluster 06/34] cluster: add helper to read the cluster ID Thomas Lamprecht
2026-11-16 0:46 ` [PATCH cluster 07/34] pmxcfs: allow removing the cluster ID file in forced local mode Thomas Lamprecht
2026-11-16 0:46 ` [PATCH guest-common 08/34] guest identity: add helpers for the guest uid and registration time Thomas Lamprecht
2026-11-17 10:47 ` Dominik Csapak
2026-11-16 0:46 ` Thomas Lamprecht [this message]
2026-11-17 10:47 ` [PATCH guest-common 09/34] abstract config: assign a guest identity and keep it on config writes Dominik Csapak
2026-11-17 12:47 ` Dominik Csapak
2026-11-16 0:46 ` [PATCH guest-common 10/34] abstract config: let the VMID reservation return the previous state Thomas Lamprecht
2026-11-16 0:46 ` [PATCH guest-common 11/34] guest identity: allow taking over a uid that is unused in the cluster Thomas Lamprecht
2026-11-17 13:14 ` Dominik Csapak
2026-11-16 0:46 ` [PATCH qemu-server 12/34] api: restore: release the VMID if a restore to an unused VMID fails Thomas Lamprecht
2026-11-16 0:46 ` [PATCH qemu-server 13/34] api: migrate, clone: refuse targets that would drop the guest identity Thomas Lamprecht
2026-11-16 0:46 ` [PATCH qemu-server 14/34] fix #7846: config: add a guest identity to the 'meta' property Thomas Lamprecht
2026-11-16 0:46 ` [PATCH qemu-server 15/34] restore: take over the guest uid from the backup where possible Thomas Lamprecht
2026-11-17 15:17 ` Dominik Csapak
2026-11-16 0:46 ` [PATCH qemu-server 16/34] api: remote migration: take over the guest uid from the source Thomas Lamprecht
2026-11-17 15:26 ` Dominik Csapak
2026-11-16 0:46 ` [PATCH qemu-server 17/34] api: status: return the guest uid Thomas Lamprecht
2026-11-16 0:46 ` [PATCH container 18/34] config: add read-only meta property with the creation time Thomas Lamprecht
2026-11-16 0:46 ` [PATCH container 19/34] fix #7846: config: add a guest identity to the 'meta' property Thomas Lamprecht
2026-11-16 0:46 ` [PATCH container 20/34] api: migrate, clone: refuse targets that would drop the guest identity Thomas Lamprecht
2026-11-16 0:46 ` [PATCH container 21/34] restore: take over the guest uid from the backup where possible Thomas Lamprecht
2026-11-16 0:46 ` [PATCH container 22/34] restore: refuse overwriting a container with another guest's backup Thomas Lamprecht
2026-11-16 0:46 ` [PATCH container 23/34] migrate: remote: clean up the target on a tunnel version mismatch Thomas Lamprecht
2026-11-16 0:46 ` [PATCH container 24/34] api: remote migration: take over the guest uid from the source Thomas Lamprecht
2026-11-16 0:46 ` [PATCH container 25/34] api: status: return the guest uid Thomas Lamprecht
2026-11-16 0:46 ` [PATCH manager 26/34] api: cluster resources: add guest uid and registration time Thomas Lamprecht
2026-11-17 15:30 ` Dominik Csapak
2026-11-16 0:46 ` [PATCH manager 27/34] api: cluster status: add cluster ID Thomas Lamprecht
2026-11-16 0:46 ` [PATCH manager 28/34] ui: restore: allow overwriting a guest with a backup of another guest Thomas Lamprecht
2026-11-16 0:46 ` [PATCH manager 29/34] ui: migrate: refuse target nodes that would drop the guest identity Thomas Lamprecht
2026-11-16 0:46 ` [PATCH manager 30/34] ui: guest summary: show " Thomas Lamprecht
2026-11-17 15:44 ` Dominik Csapak
2026-11-16 0:46 ` [PATCH docs 31/34] vzdump: describe the guest identity of VMs and containers Thomas Lamprecht
2026-11-16 0:46 ` [PATCH docs 32/34] pvecm: document the cluster ID and how to get a new one Thomas Lamprecht
2026-11-16 0:46 ` [PATCH docs 33/34] qm: configuration: describe the read-only meta property Thomas Lamprecht
2026-11-16 0:46 ` [PATCH docs 34/34] pct: " Thomas Lamprecht
2026-11-17 10:47 ` [PATCH cluster/guest-common/qemu-server/container/manager/docs 00/34] fix #7846: guest identity (uid) and cluster ID Dominik Csapak
2026-11-17 11:29 ` Thomas Lamprecht
2026-11-17 11:55 ` Dominik Csapak
2026-11-17 12:47 ` Thomas Lamprecht
2026-11-17 13:54 ` Dominik Csapak
2026-11-17 15:55 ` Dominik Csapak
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=20261116004703.2908294-10-t.lamprecht@proxmox.com \
--to=t.lamprecht@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox