all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH guest-common 11/34] guest identity: allow taking over a uid that is unused in the cluster
Date: Mon, 16 Nov 2026 01:46:23 +0100	[thread overview]
Message-ID: <20261116004703.2908294-12-t.lamprecht@proxmox.com> (raw)
In-Reply-To: <20261116004703.2908294-1-t.lamprecht@proxmox.com>

Restores and remote migrations should keep the uid of the backup or of
the source guest, but must not duplicate it within the cluster. Config
writes keep the identity a guest already has, so provide a separate
step that takes over a uid after the final config write of the
operation.

The step checks the top-level 'meta' property of all guests and writes
the uid under a cluster-wide lock shared by VMs and containers. A guest
that had an identity before the operation keeps it. Otherwise, the step
only replaces the identity that the reservation of the operation
assigned, and checks right before writing that the guest still has
that identity.

An operation that fails or gets aborted can leave a guest behind with
the identity of its reservation. So the operation records the uid it
wants to take over as a pending change of 'meta'. A retry over such a
guest takes the pending uid over if it matches, under the same
cluster-wide check. A pending uid does not count as in use, so a retry
at another VMID stays possible.

The step removes the pending uid once it decided on an outcome. If the
cluster-wide lock cannot be taken, the pending uid stays for a later
operation. Removing it keeps the identity of the guest, even if the
'meta' property could not be parsed in full. The config view with
pending changes applied shows the identity of the guest, while the list
of pending changes still shows the pending uid.

Taking over the uid a guest already has leaves its registration time
unchanged. Both guest types use the same messages for the outcome. The
source of a remote migration only warns about an outcome it does not
know, as a newer target could report one, because the target accepted
the config at that point.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
---
 src/PVE/AbstractConfig.pm          |  85 ++++-
 src/PVE/GuestIdentity.pm           | 187 ++++++++++-
 src/tests/config-identity-tests.pl | 513 ++++++++++++++++++++++++++++-
 src/tests/guest-identity-tests.pl  | 130 ++++++++
 4 files changed, 904 insertions(+), 11 deletions(-)

diff --git a/src/PVE/AbstractConfig.pm b/src/PVE/AbstractConfig.pm
index fbcc930..7eb8eb5 100644
--- a/src/PVE/AbstractConfig.pm
+++ b/src/PVE/AbstractConfig.pm
@@ -149,7 +149,7 @@ sub __identity_read_published {
 #
 # 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.
+# never changes a published identity, only PVE::GuestIdentity::adopt does.
 sub write_config {
     my ($class, $vmid, $conf) = @_;
 
@@ -179,6 +179,78 @@ sub write_config {
     return;
 }
 
+# Replaces the published identity of the config of $vmid with $identity, but only if the published
+# uid is $expected_uid, and removes its pending uid in the same write. Returns a hash with
+# 'replaced' and 'uid', the uid published afterwards. Only for PVE::GuestIdentity::adopt, which
+# checks that no other guest has the uid.
+sub __identity_replace {
+    my ($class, $vmid, $expected_uid, $identity) = @_;
+
+    die "guest identities are not enabled for this guest type\n" if !$class->__identity_enabled();
+
+    return $class->__identity_lock(
+        $vmid,
+        sub {
+            my $published = $class->__identity_read_published($vmid);
+            die "Configuration file '" . $class->cfs_config_path($vmid) . "' does not exist\n"
+                if !defined($published);
+
+            my $uid = $published->{identity} && $published->{identity}->{uid};
+            return { replaced => 0, uid => $uid } if !defined($uid) || $uid ne $expected_uid;
+
+            # the file cache only notices writes of other processes after an update
+            PVE::Cluster::cfs_update();
+            my $conf = $class->load_config($vmid);
+
+            $class->__identity_set($conf, $identity);
+            PVE::GuestIdentity::set_pending_uid($conf, undef);
+            PVE::Cluster::cfs_write_file($class->cfs_config_path($vmid), $conf);
+
+            return { replaced => 1, uid => $identity->{uid} };
+        },
+    );
+}
+
+# Removes the pending uid from the config of $vmid, if it has one. Only for
+# PVE::GuestIdentity::adopt.
+sub __identity_clear_pending {
+    my ($class, $vmid) = @_;
+
+    $class->__identity_lock(
+        $vmid,
+        sub {
+            return if !defined($class->__identity_read_published($vmid));
+
+            # the file cache only notices writes of other processes after an update
+            PVE::Cluster::cfs_update();
+            my $conf = $class->load_config($vmid);
+            return if !defined(PVE::GuestIdentity::get_pending_uid($conf));
+
+            PVE::GuestIdentity::set_pending_uid($conf, undef);
+            # the parsed config lacks the published identity if the parser could not read the
+            # 'meta' property, but write_config puts it back
+            $class->write_config($vmid, $conf);
+        },
+    );
+
+    return;
+}
+
+# Writes $uid as pending uid into the config of $vmid, keeping everything else, see
+# PVE::GuestIdentity::set_pending_uid. The caller must hold the config lock.
+sub record_pending_uid {
+    my ($class, $vmid, $uid) = @_;
+
+    # the file cache only notices writes of other processes after an update
+    PVE::Cluster::cfs_update();
+    my $conf = $class->load_config($vmid);
+
+    PVE::GuestIdentity::set_pending_uid($conf, $uid);
+    $class->write_config($vmid, $conf);
+
+    return;
+}
+
 # Pending changes related
 
 sub parse_pending_delete {
@@ -343,14 +415,19 @@ sub load_current_config {
 
     # take pending changes in
     if (!$current) {
+        # a guest type with identities never applies a pending change of 'meta', which can hold
+        # the pending uid, see PVE::GuestIdentity::set_pending_uid
+        my $skip = $class->__identity_enabled() ? { meta => 1 } : {};
+
         foreach my $opt (keys %{ $conf->{pending} }) {
-            next if $opt eq 'delete';
+            next if $opt eq 'delete' || $skip->{$opt};
             my $value = $conf->{pending}->{$opt};
             next if ref($value); # just to be sure
             $conf->{$opt} = $value;
         }
         my $pending_delete_hash = $class->parse_pending_delete($conf->{pending}->{delete});
         foreach my $opt (keys %$pending_delete_hash) {
+            next if $skip->{$opt};
             delete $conf->{$opt} if $conf->{$opt};
         }
     }
@@ -368,6 +445,7 @@ sub load_current_config {
 # as the write can assign an identity to a config without one. PVE::GuestIdentity::adopt needs it.
 #   existed  - whether a config existed before
 #   identity - the guest identity of that config, undef if it had none or did not exist
+#   pending  - the pending uid of that config, see PVE::GuestIdentity::set_pending_uid
 #   reserved - the guest identity published by the write, undef with identities disabled
 sub create_and_lock_config {
     my ($class, $vmid, $allow_existing, $lock) = @_;
@@ -379,9 +457,11 @@ sub create_and_lock_config {
             PVE::Cluster::check_vmid_unused($vmid, $allow_existing);
 
             my $conf = eval { $class->load_config($vmid) };
+            my $pending = defined($conf) ? PVE::GuestIdentity::get_pending_uid($conf) : undef;
             my $state = {
                 existed => defined($conf) ? 1 : 0,
                 identity => defined($conf) ? $class->__identity_get($conf) : undef,
+                pending => $pending,
                 reserved => undef,
             };
 
@@ -403,6 +483,7 @@ sub create_and_lock_config {
                     $state = {
                         existed => defined($published) ? 1 : 0,
                         identity => $published && $published->{identity},
+                        pending => $pending,
                         reserved => $class->__identity_get($conf),
                     };
                 },
diff --git a/src/PVE/GuestIdentity.pm b/src/PVE/GuestIdentity.pm
index 44c9a1f..4886764 100644
--- a/src/PVE/GuestIdentity.pm
+++ b/src/PVE/GuestIdentity.pm
@@ -83,7 +83,8 @@ sub meta_format_properties {
             description =>
                 "Random identifier of the guest lineage. Restores and migrations from other"
                 . " clusters keep it, unless another guest in the cluster already uses it, the"
-                . " restore sets 'unique', or the restore target already has a uid of its own.",
+                . " restore sets 'unique', or the restore overwrites a guest that has its own uid"
+                . " and is not left over from an unfinished restore of the same backup.",
             optional => 1,
         },
         rtime => {
@@ -161,6 +162,190 @@ sub merge_identity {
     return join(',', @plain, map { $_->[1] } sort { $a->[0] cmp $b->[0] } @members);
 }
 
+# An operation that takes over a uid at its end, see adopt, keeps it in the config of the guest as
+# pending change of 'meta' with only the uid member until then. A guest that the operation leaves
+# behind after a failure or an abort thus still knows the uid, so that a retry of the operation can
+# take it over. A pending uid is never published: the check whether a uid is in use only looks at
+# the top-level section of guest configs, and only adopt can turn it into the uid of the guest.
+
+# Returns the pending uid in the parsed config $conf, undef if there is none.
+sub get_pending_uid {
+    my ($conf) = @_;
+
+    my $pending = $conf->{pending} && parse_identity($conf->{pending}->{meta});
+
+    return $pending && $pending->{uid};
+}
+
+# Sets $uid as pending uid in the parsed config $conf, replacing any pending change of 'meta', or
+# removes such a change if $uid is undef.
+sub set_pending_uid {
+    my ($conf, $uid) = @_;
+
+    if (defined($uid)) {
+        die "invalid guest identity uid '$uid'\n" if !is_valid_uid($uid);
+        $conf->{pending}->{meta} = "uid=$uid";
+    } elsif ($conf->{pending}) {
+        delete $conf->{pending}->{meta};
+    }
+
+    return;
+}
+
+# Returns $uid if adopt would try to publish it for the guest of the operation with the reservation
+# $reservation, which is the case if the guest had no identity before the operation, or $uid as
+# pending uid. Returns undef otherwise, or if $uid is undef. An operation keeps the uid it returns
+# as pending uid until it calls adopt.
+sub adoptable_uid {
+    my ($reservation, $uid) = @_;
+
+    return undef if !defined($uid) || !$reservation;
+    return $uid if !$reservation->{identity} || ($reservation->{pending} // '') eq $uid;
+
+    return undef;
+}
+
+# Returns whether $uid is the uid of the guest of the operation with the reservation $reservation,
+# published or pending, before the operation. A guest without identity matches any uid.
+sub uid_matches_target {
+    my ($reservation, $uid) = @_;
+
+    my $identity = $reservation->{identity};
+
+    return !$identity || $identity->{uid} eq $uid || ($reservation->{pending} // '') eq $uid;
+}
+
+my sub take_over {
+    my ($class, $vmid, $uid, $reservation) = @_;
+
+    my $result = sub {
+        my ($result, $current_uid, @extra) = @_;
+        return { result => $result, uid => $current_uid, requested => $uid, @extra };
+    };
+
+    my $previous = $reservation->{identity};
+    return $result->('kept', $previous->{uid}) if $previous && !adoptable_uid($reservation, $uid);
+
+    my $reserved_uid = $reservation->{reserved}->{uid};
+    return $result->('skipped', $reserved_uid) if !defined($uid);
+
+    # shared by all guest types, as they share the VMID and uid namespaces
+    my $res = PVE::Cluster::cfs_lock_domain(
+        'guest-identity',
+        undef,
+        sub {
+            my $metas = PVE::Cluster::get_guest_config_properties(['meta']);
+
+            my $current = parse_identity($metas->{$vmid} && $metas->{$vmid}->{meta});
+            if ($current && $current->{uid} eq $uid) {
+                # a uid without valid rtime can only come from a manual edit
+                $class->__identity_replace($vmid, $uid, new_identity($uid))
+                    if !defined($current->{rtime});
+                return $result->('kept', $uid);
+            }
+
+            for my $other (sort { $a <=> $b } keys %$metas) {
+                my $identity = parse_identity($metas->{$other}->{meta});
+                next if !$identity || $identity->{uid} ne $uid;
+
+                return $result->('in-use', $current && $current->{uid}, 'in-use-by' => $other);
+            }
+
+            my $replaced = $class->__identity_replace($vmid, $reserved_uid, new_identity($uid));
+            return $result->('changed', $replaced->{uid}) if !$replaced->{replaced};
+
+            return $result->('adopted', $uid);
+        },
+    );
+    die $@ if $@;
+
+    return $res;
+}
+
+# Publishes $uid, for example the one of a restored backup or of the source guest of a remote
+# migration, as the uid of the guest $vmid with the current time as rtime, where that is allowed.
+#
+# $class is the config class of the guest and must have guest identities enabled. $reservation is
+# what create_and_lock_config returned for the operation. The caller must still hold the config
+# lock of $vmid and call this after the final config write of the operation. $uid can be undef if
+# there is nothing to adopt, for example for a backup without uid.
+#
+# A guest that had an identity before the operation keeps it, unless it had $uid as pending uid,
+# see adoptable_uid. Otherwise, $uid only replaces the identity that the reservation published,
+# and only if no other guest in the cluster has it. Whatever the outcome, the pending uid of the
+# config is removed afterwards, as the operation is done.
+#
+# Dies if the cluster-wide identity lock cannot be taken, for example without quorum. The pending
+# uid then stays, as nothing got decided, so that a later operation can still take it over.
+#
+# Returns a hash with the keys 'result', 'uid' (the uid of $vmid afterwards), 'requested' ($uid)
+# and, for the result 'in-use', 'in-use-by' (the lowest VMID of the other guests with $uid). The
+# result is one of:
+#   kept    - the guest keeps the identity it had before the operation, or already has $uid
+#   adopted - $uid got published for $vmid
+#   in-use  - another guest has $uid, the identity of the reservation stays
+#   changed - the identity of the reservation is not published anymore, nothing got changed
+#   skipped - $uid is undef, the identity of the reservation stays
+sub adopt {
+    my ($class, $vmid, $uid, $reservation) = @_;
+
+    die "guest identities are not enabled for this guest type\n" if !$class->__identity_enabled();
+    die "missing guest identity reservation\n"
+        if ref($reservation) ne 'HASH' || !$reservation->{reserved};
+    die "invalid guest identity uid '$uid'\n" if defined($uid) && !is_valid_uid($uid);
+
+    my $res = take_over($class, $vmid, $uid, $reservation);
+
+    eval { $class->__identity_clear_pending($vmid) };
+    die "unable to remove the pending uid - $@" if $@;
+
+    return $res;
+}
+
+# Returns the task log line for the result $res of adopt(), so that all guest types use the same
+# wording. $origin is where the requested uid comes from, either 'backup' or 'source' for the
+# source guest of a remote migration.
+sub adopt_result_message {
+    my ($res, $origin) = @_;
+
+    my $origin_name = { backup => 'backup', source => 'source guest' }->{$origin}
+        // die "unknown origin of guest identity '$origin'\n";
+
+    my ($result, $requested) = $res->@{qw(result requested)};
+    my $uid = $res->{uid} // 'none';
+
+    if ($result eq 'kept') {
+        return "guest identity: kept uid $uid";
+    } elsif ($result eq 'adopted') {
+        return "guest identity: adopted uid $uid from the $origin_name";
+    } elsif ($result eq 'in-use') {
+        return "guest identity: $origin_name uid $requested is in use by guest"
+            . " $res->{'in-use-by'}, keeping uid $uid";
+    } elsif ($result eq 'changed') {
+        return "guest identity: uid changed during the operation, keeping uid $uid instead of"
+            . " adopting uid $requested from the $origin_name";
+    } elsif ($result eq 'skipped') {
+        return "guest identity: new uid $uid";
+    }
+
+    die "unknown result of guest identity adoption '$result'\n";
+}
+
+# Returns the log level and line for the result $res of adopt that the target of a remote migration
+# reported for the uid of the source guest. A target with a newer version can report results
+# unknown here, which only get a warning, as the target already took over the config by then.
+sub remote_adopt_result_log {
+    my ($res) = @_;
+
+    my $message = eval { adopt_result_message($res, 'source') };
+    if (my $err = $@) {
+        chomp($err);
+        return ('warn', $err);
+    }
+
+    return ('info', $message);
+}
+
 # Returns undef if $node runs a version of Proxmox VE that keeps the identity when writing guest
 # configs, see MIN_PVE_MANAGER_VERSION. Missing or invalid version information counts as too old.
 # Otherwise returns a hash with 'required-version', the minimum version, and 'version', the version
diff --git a/src/tests/config-identity-tests.pl b/src/tests/config-identity-tests.pl
index 8bcc9d8..7138053 100755
--- a/src/tests/config-identity-tests.pl
+++ b/src/tests/config-identity-tests.pl
@@ -99,9 +99,13 @@ my $cache = {};
 
 our $get_config_error;
 our $check_identity_lock = 1;
+our $lock_domain_error;
+our $domain_locked = 0;
+our $on_lookup;
 
 my $reads = 0;
 my $writes = 0;
+my $domain_writes = 0;
 
 sub parse_test_config {
     my ($raw) = @_;
@@ -110,7 +114,9 @@ sub parse_test_config {
     my $section = $conf;
     for my $line (split(/\n/, $raw)) {
         next if $line =~ m/^\s*$/;
-        if ($line =~ m/^\[([^\]]+)\]$/) {
+        if ($line =~ m/^\[PENDING\]$/) {
+            $section = $conf->{pending} = {};
+        } elsif ($line =~ m/^\[([^\]]+)\]$/) {
             $section = $conf->{snapshots}->{$1} = {};
         } elsif ($line =~ m/^([a-z][a-z0-9_\-]*):\s*(.*?)\s*$/) {
             $section->{$1} = $2;
@@ -132,6 +138,8 @@ sub write_test_config {
     };
 
     my $raw = $print_section->($conf);
+    $raw .= "\n[PENDING]\n" . $print_section->($conf->{pending})
+        if scalar(keys(($conf->{pending} // {})->%*));
     for my $snapname (sort keys(($conf->{snapshots} // {})->%*)) {
         $raw .= "\n[$snapname]\n" . $print_section->($conf->{snapshots}->{$snapname});
     }
@@ -177,6 +185,7 @@ $cluster_module->redefine(
         die "test error: config of $vmid written without identity lock\n"
             if $check_identity_lock && !identity_lock_held($vmid);
         $writes++;
+        $domain_writes++ if $domain_locked;
         $files->{$path} = write_test_config($conf);
         $versions->{$path} = ++$version_counter;
         $cache->{$path}->{version} = undef if $cache->{$path};
@@ -187,6 +196,37 @@ $cluster_module->redefine(
         return undef if $noerr;
         die "guest $vmid already exists\n";
     },
+    get_guest_config_properties => sub {
+        my ($properties, $vmid) = @_;
+        die "test error: unexpected arguments\n" if defined($vmid) || "@$properties" ne 'meta';
+
+        my $res = {};
+        for my $path (grep { defined($files->{$_}) } keys %$files) {
+            for my $line (split(/\n/, $files->{$path})) {
+                last if $line =~ m/^\[/;
+                $res->{ vmid_of_path($path) }->{meta} = $1 if $line =~ m/^meta:\s*(.*?)\s*$/;
+            }
+        }
+
+        $on_lookup->() if $on_lookup;
+
+        return $res;
+    },
+    cfs_lock_domain => sub {
+        my ($domain, $timeout, $code, @param) = @_;
+        die "test error: unexpected lock domain '$domain'\n" if $domain ne 'guest-identity';
+        die "test error: nested domain lock\n" if $domain_locked;
+
+        if ($lock_domain_error) {
+            $@ = $lock_domain_error;
+            return undef;
+        }
+
+        local $domain_locked = 1;
+        PVE::Cluster::cfs_update();
+        # like the real one, errors of $code are passed on in $@
+        return eval { $code->(@param) };
+    },
     get_config => sub {
         my ($path) = @_;
         my $vmid = vmid_of_path($path);
@@ -499,7 +539,7 @@ subtest 'create and lock config' => sub {
     ok($reserved, 'free VMID: reservation gets an identity');
     is_deeply(
         $state,
-        { existed => 0, identity => undef, reserved => $reserved },
+        { existed => 0, identity => undef, pending => undef, reserved => $reserved },
         'free VMID: no previous identity',
     );
     is(conf_of($class, 150)->{lock}, 'create', 'free VMID: reserved');
@@ -513,7 +553,7 @@ subtest 'create and lock config' => sub {
     $state = $class->create_and_lock_config(151, 1, 'restore');
     is_deeply(
         $state,
-        { existed => 1, identity => $published, reserved => $published },
+        { existed => 1, identity => $published, pending => undef, reserved => $published },
         'in place: previous identity',
     );
     my $conf = conf_of($class, 151);
@@ -528,7 +568,12 @@ subtest 'create and lock config' => sub {
     $state = $class->create_and_lock_config(152, 1);
     is_deeply(
         $state,
-        { existed => 1, identity => undef, reserved => identity_of($class, 152) },
+        {
+            existed => 1,
+            identity => undef,
+            pending => undef,
+            reserved => identity_of($class, 152),
+        },
         'in place without identity: reservation gets one',
     );
     ok($state->{reserved}, 'in place without identity: reserved identity');
@@ -537,7 +582,12 @@ subtest 'create and lock config' => sub {
     $state = $class->create_and_lock_config(157, 1);
     is_deeply(
         $state,
-        { existed => 1, identity => undef, reserved => identity_of($class, 157) },
+        {
+            existed => 1,
+            identity => undef,
+            pending => undef,
+            reserved => identity_of($class, 157),
+        },
         'in place with empty config: reservation gets an identity',
     );
     ok($state->{reserved}, 'in place with empty config: reserved identity');
@@ -547,7 +597,7 @@ subtest 'create and lock config' => sub {
     my $kept = { uid => $foreign_uid, rtime => 5 };
     is_deeply(
         $state,
-        { existed => 1, identity => $kept, reserved => $kept },
+        { existed => 1, identity => $kept, pending => undef, reserved => $kept },
         'in place, config fails to load: published identity',
     );
     is_deeply(
@@ -571,7 +621,7 @@ subtest 'create and lock config' => sub {
     $state = $class->create_and_lock_config(154);
     is_deeply(
         $state,
-        { existed => 0, identity => undef, reserved => undef },
+        { existed => 0, identity => undef, pending => undef, reserved => undef },
         'disabled, free VMID: no previous identity',
     );
     is(file_of($class, 154), "lock: create\n", 'disabled, free VMID: no identity assigned');
@@ -580,7 +630,12 @@ subtest 'create and lock config' => sub {
     $state = $class->create_and_lock_config(155, 1);
     is_deeply(
         $state,
-        { existed => 1, identity => { uid => $foreign_uid, rtime => 5 }, reserved => undef },
+        {
+            existed => 1,
+            identity => { uid => $foreign_uid, rtime => 5 },
+            pending => undef,
+            reserved => undef,
+        },
         'disabled, in place: identity from the config',
     );
     is(
@@ -590,4 +645,446 @@ subtest 'create and lock config' => sub {
     );
 };
 
+subtest 'adopt' => sub {
+    my $class = 'PVE::TestConfig';
+    my $ct_class = 'PVE::TestConfig::CT';
+
+    my $backup_uid = new_uid();
+
+    # restore to a free VMID, the final write carries the identity of the backup
+    my $reservation = $class->create_and_lock_config(200);
+    my $restored = { name => 'restored', meta => "ctime=1,rtime=5,uid=$backup_uid" };
+    $class->write_config(200, { $restored->%*, lock => 'create' });
+    my $generated = identity_of($class, 200);
+    is_deeply($generated, $reservation->{reserved}, 'final write keeps the reserved identity');
+
+    $now += 1000;
+    my $res = PVE::GuestIdentity::adopt($class, 200, $backup_uid, $reservation);
+    is_deeply(
+        $res,
+        { result => 'adopted', uid => $backup_uid, requested => $backup_uid },
+        'free uid is adopted',
+    );
+    is_deeply(
+        identity_of($class, 200),
+        { uid => $backup_uid, rtime => $now },
+        'adopted uid is published with the current time',
+    );
+    like(
+        file_of($class, 200),
+        qr/^meta: ctime=1,rtime=$now,uid=$backup_uid$/m,
+        'other members are kept',
+    );
+    is(conf_of($class, 200)->{lock}, 'create', 'rest of the config is kept');
+    is($domain_writes, 1, 'published under the cluster-wide lock');
+
+    my $adopted_rtime = $now;
+    $now += 1000;
+
+    my $stale = { $restored->%*, meta => "ctime=1,rtime=5,uid=$generated->{uid}" };
+    $class->write_config(200, $stale);
+    is_deeply(
+        identity_of($class, 200),
+        { uid => $backup_uid, rtime => $adopted_rtime },
+        'later write of a stale hash keeps the adopted identity',
+    );
+
+    my $writes_before = $writes;
+    $res = PVE::GuestIdentity::adopt($class, 200, $backup_uid, $reservation);
+    is_deeply(
+        $res,
+        { result => 'kept', uid => $backup_uid, requested => $backup_uid },
+        'repeated adoption keeps it',
+    );
+    is($writes, $writes_before, 'repeated adoption writes nothing');
+    is(identity_of($class, 200)->{rtime}, $adopted_rtime, 'repeated adoption keeps rtime');
+
+    set_file($class, 200, file_of($class, 200) =~ s/rtime=\d+,//r);
+    $res = PVE::GuestIdentity::adopt($class, 200, $backup_uid, $reservation);
+    is($res->{result}, 'kept', 'repeated adoption with manually removed rtime keeps it');
+    is_deeply(
+        identity_of($class, 200),
+        { uid => $backup_uid, rtime => $now },
+        'repeated adoption sets a missing rtime',
+    );
+
+    # restore in place onto a guest with identity
+    $class->write_config(210, { name => 'target' });
+    my $target = identity_of($class, 210);
+    $reservation = $class->create_and_lock_config(210, 1, 'restore');
+    my $other_uid = new_uid();
+    {
+        local $lock_domain_error = "test error: unexpected lock\n";
+        $res = PVE::GuestIdentity::adopt($class, 210, $other_uid, $reservation);
+    }
+    is_deeply(
+        $res,
+        { result => 'kept', uid => $target->{uid}, requested => $other_uid },
+        'in place: identity from before the operation is kept',
+    );
+    is_deeply(identity_of($class, 210), $target, 'in place: identity is unchanged');
+
+    set_file($class, 211, "meta: ctime=1\nname: old\n");
+    $reservation = $class->create_and_lock_config(211, 1);
+    $other_uid = new_uid();
+    $res = PVE::GuestIdentity::adopt($class, 211, $other_uid, $reservation);
+    is($res->{result}, 'adopted', 'in place without identity: uid is adopted');
+    is(identity_of($class, 211)->{uid}, $other_uid, 'in place without identity: published');
+
+    $reservation = $class->create_and_lock_config(212);
+    {
+        local $lock_domain_error = "test error: unexpected lock\n";
+        $res = PVE::GuestIdentity::adopt($class, 212, undef, $reservation);
+    }
+    is_deeply(
+        $res,
+        { result => 'skipped', uid => $reservation->{reserved}->{uid}, requested => undef },
+        'nothing to adopt',
+    );
+
+    # a wrong call must not replace an identity that the reservation did not publish
+    $class->write_config(213, { name => 'established' });
+    my $established = identity_of($class, 213);
+    my $wrong =
+        { existed => 0, identity => undef, reserved => PVE::GuestIdentity::new_identity() };
+    $other_uid = new_uid();
+    $writes_before = $writes;
+    $res = PVE::GuestIdentity::adopt($class, 213, $other_uid, $wrong);
+    is_deeply(
+        $res,
+        { result => 'changed', uid => $established->{uid}, requested => $other_uid },
+        'reservation of another identity: nothing adopted',
+    );
+    is_deeply(identity_of($class, 213), $established, 'established identity is kept');
+    is($writes, $writes_before, 'nothing is written');
+
+    $reservation = $class->create_and_lock_config(214);
+    my $recreated = new_uid();
+    set_file($class, 214, "meta: rtime=1,uid=$recreated\nname: recreated\n");
+    $res = PVE::GuestIdentity::adopt($class, 214, new_uid(), $reservation);
+    is($res->{result}, 'changed', 'config replaced since the reservation: nothing adopted');
+    is(identity_of($class, 214)->{uid}, $recreated, 'identity of the replaced config stays');
+
+    $reservation = $class->create_and_lock_config(201);
+    $class->write_config(201, { name => 'second restore', lock => 'create' });
+    my $second = identity_of($class, 201);
+    $writes_before = $writes;
+    $res = PVE::GuestIdentity::adopt($class, 201, $backup_uid, $reservation);
+    is_deeply(
+        $res,
+        {
+            result => 'in-use',
+            uid => $second->{uid},
+            requested => $backup_uid,
+            'in-use-by' => 200,
+        },
+        'uid of another VM is not adopted',
+    );
+    is_deeply(identity_of($class, 201), $second, 'reserved identity stays');
+    is($writes, $writes_before, 'nothing is written');
+
+    # manual copies of a config
+    my $copied_uid = new_uid();
+    set_file($class, 220, "meta: rtime=1,uid=$copied_uid\n");
+    set_file($ct_class, 205, "meta: rtime=1,uid=$copied_uid\n");
+    $res = PVE::GuestIdentity::adopt($class, 201, $copied_uid, $reservation);
+    is($res->{'in-use-by'}, 205, 'lowest VMID of several holders is reported');
+
+    my $ct_uid = new_uid();
+    my $ct_reservation = $ct_class->create_and_lock_config(300);
+    $res = PVE::GuestIdentity::adopt($ct_class, 300, $ct_uid, $ct_reservation);
+    is($res->{result}, 'adopted', 'container adopts a free uid');
+    like(file_of($ct_class, 300), qr/^meta: rtime=$now,uid=$ct_uid$/m, 'container config');
+
+    $res = PVE::GuestIdentity::adopt($class, 201, $ct_uid, $reservation);
+    is($res->{'in-use-by'}, 300, 'uid of a container is not adopted for a VM');
+
+    $ct_reservation = $ct_class->create_and_lock_config(301);
+    $res = PVE::GuestIdentity::adopt($ct_class, 301, $backup_uid, $ct_reservation);
+    is($res->{'in-use-by'}, 200, 'uid of a VM is not adopted for a container');
+
+    # another process writes the config after the cluster-wide lookup
+    $reservation = $class->create_and_lock_config(230);
+    $class->write_config(230, { name => 'restored', lock => 'create' });
+    PVE::Cluster::cfs_update();
+    $class->load_config(230);
+    {
+        local $on_lookup = sub {
+            set_file($class, 230, file_of($class, 230) =~ s/^name: .*$/name: hook/mr);
+        };
+        $res = PVE::GuestIdentity::adopt($class, 230, new_uid(), $reservation);
+    }
+    is($res->{result}, 'adopted', 'concurrent write: uid is adopted');
+    is(conf_of($class, 230)->{name}, 'hook', 'concurrent write: its change is kept');
+
+    $reservation = $class->create_and_lock_config(202);
+    my $before = identity_of($class, 202);
+    {
+        local $lock_domain_error = "cfs-lock 'domain-guest-identity' error: no quorum!\n";
+        eval { PVE::GuestIdentity::adopt($class, 202, new_uid(), $reservation) };
+        is($@, $lock_domain_error, 'lock error is passed on');
+        is_deeply(identity_of($class, 202), $before, 'lock error: identity is unchanged');
+    }
+
+    my $missing =
+        { existed => 0, identity => undef, reserved => PVE::GuestIdentity::new_identity() };
+    eval { PVE::GuestIdentity::adopt($class, 299, new_uid(), $missing) };
+    like($@, qr/does not exist/, 'missing config is an error');
+
+    eval { PVE::GuestIdentity::adopt($class, 202, 'GAYTEMZUGU3DOOBZMFRG', $reservation) };
+    like($@, qr/invalid guest identity uid/, 'invalid uid is refused');
+
+    for my $invalid (undef, {}, { existed => 0, identity => undef, reserved => undef }) {
+        eval { PVE::GuestIdentity::adopt($class, 202, new_uid(), $invalid) };
+        like($@, qr/missing guest identity reservation/, 'missing reservation is refused');
+    }
+
+    local $check_identity_lock = 0;
+    eval {
+        PVE::GuestIdentity::adopt('PVE::TestConfig::NoIdentity', 202, new_uid(), $reservation);
+    };
+    like($@, qr/not enabled/, 'guest type without identities is refused');
+};
+
+# like the guest that a failed operation leaves behind, with the lock removed by its error handling
+my sub unlock_config {
+    my ($class, $vmid) = @_;
+    my $conf = conf_of($class, $vmid);
+    delete $conf->{lock};
+    $class->write_config($vmid, $conf);
+}
+
+my sub pending_of {
+    my ($class, $vmid) = @_;
+    my $conf = conf_of($class, $vmid);
+    return $conf->{pending} && $conf->{pending}->{meta};
+}
+
+subtest 'pending uid' => sub {
+    my $class = 'PVE::TestConfig';
+
+    # a restore to a free VMID records the uid of the backup, then fails and leaves the guest
+    my $backup_uid = new_uid();
+    my $first = $class->create_and_lock_config(400);
+    my $leftover = $first->{reserved};
+    is(
+        PVE::GuestIdentity::adoptable_uid($first, $backup_uid),
+        $backup_uid,
+        'free VMID: adoptable',
+    );
+    $class->record_pending_uid(400, $backup_uid);
+    is(pending_of($class, 400), "uid=$backup_uid", 'pending uid is recorded');
+    is_deeply(identity_of($class, 400), $leftover, 'published identity is kept');
+    is(conf_of($class, 400)->{lock}, 'create', 'rest of the config is kept');
+    unlock_config($class, 400);
+    is(pending_of($class, 400), "uid=$backup_uid", 'write of the loaded config keeps it');
+
+    # a retry at another VMID takes over the uid, as a pending uid is not in use
+    my $elsewhere = $class->create_and_lock_config(401);
+    my $res = PVE::GuestIdentity::adopt($class, 401, $backup_uid, $elsewhere);
+    is($res->{result}, 'adopted',
+        'retry elsewhere: pending uid of another guest is not in use');
+    is(pending_of($class, 400), "uid=$backup_uid", 'retry elsewhere: leftover keeps it');
+
+    # a retry over the leftover is a restore of the same backup, but the uid is in use by now
+    my $retry = $class->create_and_lock_config(400, 1);
+    is_deeply(
+        $retry,
+        { existed => 1, identity => $leftover, pending => $backup_uid, reserved => $leftover },
+        'reservation reports the pending uid',
+    );
+    ok(PVE::GuestIdentity::uid_matches_target($retry, $backup_uid), 'pending uid matches');
+    ok(
+        PVE::GuestIdentity::uid_matches_target($retry, $leftover->{uid}),
+        'published uid matches',
+    );
+    ok(!PVE::GuestIdentity::uid_matches_target($retry, new_uid()), 'other uid does not match');
+    is(
+        PVE::GuestIdentity::adoptable_uid($retry, $backup_uid),
+        $backup_uid,
+        'pending: adoptable',
+    );
+    $res = PVE::GuestIdentity::adopt($class, 400, $backup_uid, $retry);
+    is_deeply(
+        $res,
+        {
+            result => 'in-use',
+            uid => $leftover->{uid},
+            requested => $backup_uid,
+            'in-use-by' => 401,
+        },
+        'retry in place after the retry elsewhere: in use',
+    );
+    is_deeply(identity_of($class, 400), $leftover, 'in use: identity is kept');
+    ok(!defined(pending_of($class, 400)), 'in use: pending uid is removed');
+
+    # a failed restore over a guest without identity, then retried in place
+    set_file($class, 410, "name: old\n");
+    $first = $class->create_and_lock_config(410, 1);
+    $backup_uid = new_uid();
+    is(
+        PVE::GuestIdentity::adoptable_uid($first, $backup_uid),
+        $backup_uid,
+        'no identity: adoptable',
+    );
+    $class->record_pending_uid(410, $backup_uid);
+    unlock_config($class, 410);
+
+    $retry = $class->create_and_lock_config(410, 1);
+    is($retry->{pending}, $backup_uid, 'retry in place: pending uid reported');
+    $class->write_config(
+        410,
+        { name => 'restored', lock => 'create', pending => { meta => "uid=$backup_uid" } },
+    );
+    $now += 1000;
+    my $writes_before = $writes;
+    $res = PVE::GuestIdentity::adopt($class, 410, $backup_uid, $retry);
+    is_deeply(
+        $res,
+        { result => 'adopted', uid => $backup_uid, requested => $backup_uid },
+        'retry in place: pending uid is adopted',
+    );
+    is_deeply(identity_of($class, 410), { uid => $backup_uid, rtime => $now }, 'published');
+    ok(!defined(pending_of($class, 410)), 'retry in place: pending uid is removed');
+    is($writes, $writes_before + 1, 'in the same write');
+    is(conf_of($class, 410)->{name}, 'restored', 'rest of the config is kept');
+
+    # the published uid changed since the reservation of the retry
+    set_file($class, 420, "name: old\n");
+    $first = $class->create_and_lock_config(420, 1);
+    $backup_uid = new_uid();
+    $class->record_pending_uid(420, $backup_uid);
+    unlock_config($class, 420);
+    $retry = $class->create_and_lock_config(420, 1);
+    my $replaced = new_uid();
+    set_file(
+        $class,
+        420,
+        "meta: rtime=1,uid=$replaced\nname: new\n\n[PENDING]\nmeta: uid=$backup_uid\n",
+    );
+    $res = PVE::GuestIdentity::adopt($class, 420, $backup_uid, $retry);
+    is($res->{result}, 'changed', 'published uid changed since the retry: not adopted');
+    is(identity_of($class, 420)->{uid}, $replaced, 'published uid changed: it stays');
+    ok(!defined(pending_of($class, 420)), 'published uid changed: pending uid is removed');
+
+    # an in-place restore of another backup keeps the identity, with a pending uid of the earlier
+    # backup
+    set_file($class, 430, "name: old\n");
+    $first = $class->create_and_lock_config(430, 1);
+    my $earlier_uid = new_uid();
+    $class->record_pending_uid(430, $earlier_uid);
+    unlock_config($class, 430);
+    $retry = $class->create_and_lock_config(430, 1);
+    my $target = identity_of($class, 430);
+    my $other_uid = new_uid();
+    ok(
+        !PVE::GuestIdentity::uid_matches_target($retry, $other_uid),
+        'other backup does not match',
+    );
+    ok(!defined(PVE::GuestIdentity::adoptable_uid($retry, $other_uid)), 'other backup: none');
+    {
+        local $lock_domain_error = "test error: unexpected lock\n";
+        $res = PVE::GuestIdentity::adopt($class, 430, $other_uid, $retry);
+    }
+    is($res->{result}, 'kept', 'other backup: identity is kept');
+    is_deeply(identity_of($class, 430), $target, 'other backup: identity is unchanged');
+    ok(!defined(pending_of($class, 430)), 'other backup: pending uid is removed');
+
+    # nothing to adopt, for example with 'unique'
+    $first = $class->create_and_lock_config(440);
+    $class->record_pending_uid(440, new_uid());
+    $res = PVE::GuestIdentity::adopt($class, 440, undef, $first);
+    is($res->{result}, 'skipped', 'nothing to adopt: skipped');
+    ok(!defined(pending_of($class, 440)), 'nothing to adopt: pending uid is removed');
+
+    # adopting fails
+    $first = $class->create_and_lock_config(450);
+    $backup_uid = new_uid();
+    $class->record_pending_uid(450, $backup_uid);
+    {
+        local $lock_domain_error = "cfs-lock 'domain-guest-identity' error: no quorum!\n";
+        eval { PVE::GuestIdentity::adopt($class, 450, $backup_uid, $first) };
+        is($@, $lock_domain_error, 'lock error is passed on');
+    }
+    is_deeply(identity_of($class, 450), $first->{reserved},
+        'lock error: identity is unchanged');
+    is(
+        pending_of($class, 450),
+        "uid=$backup_uid",
+        'lock error: nothing decided, pending uid stays',
+    );
+
+    unlock_config($class, 450);
+    $retry = $class->create_and_lock_config(450, 1);
+    $res = PVE::GuestIdentity::adopt($class, 450, $backup_uid, $retry);
+    is($res->{result}, 'adopted', 'lock error: a later operation takes the pending uid over');
+    ok(!defined(pending_of($class, 450)), 'lock error: then the pending uid is removed');
+
+    # removing the pending uid keeps a published identity that the parser could not read
+    my $config_module = Test::MockModule->new('PVE::TestConfig', no_auto => 1);
+    $config_module->mock(
+        load_config => sub {
+            my $conf = $config_module->original('load_config')->(@_);
+            delete $conf->{meta};
+            return $conf;
+        },
+    );
+    $class->write_config(470, { name => 'target', meta => 'ctime=1' });
+    $target = identity_of($class, 470);
+    $retry = $class->create_and_lock_config(470, 1);
+    $class->record_pending_uid(470, new_uid());
+    {
+        local $lock_domain_error = "test error: unexpected lock\n";
+        $res = PVE::GuestIdentity::adopt($class, 470, new_uid(), $retry);
+    }
+    $config_module->unmock('load_config');
+    is($res->{result}, 'kept', 'unreadable meta: identity is kept');
+    ok(!defined(pending_of($class, 470)), 'unreadable meta: pending uid is removed');
+    is_deeply(identity_of($class, 470), $target, 'unreadable meta: published identity is kept');
+
+    # removing the pending uid fails
+    $class->write_config(460, { name => 'target' });
+    $retry = $class->create_and_lock_config(460, 1);
+    $class->record_pending_uid(460, new_uid());
+    {
+        local $get_config_error = "Connection refused\n";
+        eval { PVE::GuestIdentity::adopt($class, 460, new_uid(), $retry) };
+        is($@, "unable to remove the pending uid - Connection refused\n", 'error is passed on');
+    }
+    ok(defined(pending_of($class, 460)), 'pending uid stays');
+
+    eval { $class->record_pending_uid(460, 'GAYTEMZUGU3DOOBZMFRG') };
+    like($@, qr/invalid guest identity uid/, 'invalid pending uid is refused');
+};
+
+subtest 'config view with pending changes' => sub {
+    my $class = 'PVE::TestConfig';
+
+    my $pending_uid = new_uid();
+    $class->write_config(480, { name => 'old', meta => 'ctime=1' });
+    my $meta = conf_of($class, 480)->{meta};
+    $class->record_pending_uid(480, $pending_uid);
+    my $conf = conf_of($class, 480);
+    $conf->{pending}->{name} = 'new';
+    $class->write_config(480, $conf);
+
+    PVE::Cluster::cfs_update();
+    $conf = $class->load_current_config(480);
+    is($conf->{name}, 'new', 'other pending change is shown');
+    is($conf->{meta}, $meta, 'pending uid is not shown as meta');
+    ok(!exists($conf->{pending}), 'no pending section');
+    is($class->load_current_config(480, 1)->{name}, 'old', 'current values only');
+
+    set_file($class, 481, "meta: $meta\nname: old\n\n[PENDING]\ndelete: meta\n");
+    PVE::Cluster::cfs_update();
+    is($class->load_current_config(481)->{meta}, $meta, 'pending deletion of meta not shown');
+
+    # a guest type without identities may apply pending changes of 'meta'
+    local $check_identity_lock = 0;
+    $class = 'PVE::TestConfig::NoIdentity';
+    set_file($class, 482, "meta: ctime=1\nname: old\n\n[PENDING]\nmeta: ctime=2\n");
+    PVE::Cluster::cfs_update();
+    is($class->load_current_config(482)->{meta}, 'ctime=2', 'without identities: shown');
+};
+
 done_testing();
diff --git a/src/tests/guest-identity-tests.pl b/src/tests/guest-identity-tests.pl
index fb5167d..335b8c6 100755
--- a/src/tests/guest-identity-tests.pl
+++ b/src/tests/guest-identity-tests.pl
@@ -288,4 +288,134 @@ subtest 'node version check' => sub {
     }
 };
 
+subtest 'adopt result message' => sub {
+    my $uid = 'gaytemzugu3doobzmfrg';
+    my $new = 'aaaaaaaaaaaaaaaaaaaa';
+
+    my $tests = [
+        [{ result => 'kept', uid => $uid, requested => $new }, 'backup', "kept uid $uid"],
+        [
+            { result => 'adopted', uid => $uid, requested => $uid },
+            'backup',
+            "adopted uid $uid from the backup",
+        ],
+        [
+            { result => 'adopted', uid => $uid, requested => $uid },
+            'source',
+            "adopted uid $uid from the source guest",
+        ],
+        [
+            { result => 'in-use', uid => $new, requested => $uid, 'in-use-by' => 105 },
+            'backup',
+            "backup uid $uid is in use by guest 105, keeping uid $new",
+        ],
+        [
+            { result => 'in-use', uid => $new, requested => $uid, 'in-use-by' => 105 },
+            'source',
+            "source guest uid $uid is in use by guest 105, keeping uid $new",
+        ],
+        [
+            { result => 'changed', uid => $new, requested => $uid },
+            'source',
+            "uid changed during the operation, keeping uid $new instead of adopting uid $uid"
+                . " from the source guest",
+        ],
+        [
+            { result => 'changed', uid => $new, requested => $uid },
+            'backup',
+            "uid changed during the operation, keeping uid $new instead of adopting uid $uid"
+                . " from the backup",
+        ],
+        [{ result => 'skipped', uid => $new, requested => undef }, 'backup', "new uid $new"],
+    ];
+
+    for my $test (@$tests) {
+        my ($res, $origin, $expected) = @$test;
+        is(
+            PVE::GuestIdentity::adopt_result_message($res, $origin),
+            "guest identity: $expected",
+            "$res->{result} ($origin)",
+        );
+    }
+
+    eval {
+        PVE::GuestIdentity::adopt_result_message({ result => 'kept', uid => $uid }, 'other');
+    };
+    like($@, qr/unknown origin/, 'unknown origin is refused');
+
+    eval {
+        PVE::GuestIdentity::adopt_result_message({ result => 'bogus', uid => $uid }, 'backup');
+    };
+    like($@, qr/unknown result/, 'unknown result is refused');
+
+    is_deeply(
+        [PVE::GuestIdentity::remote_adopt_result_log({ result => 'adopted', uid => $uid })],
+        ['info', "guest identity: adopted uid $uid from the source guest"],
+        'remote result: known result is logged as info',
+    );
+    is_deeply(
+        [PVE::GuestIdentity::remote_adopt_result_log({ result => 'bogus', uid => $uid })],
+        ['warn', "unknown result of guest identity adoption 'bogus'"],
+        'remote result: unknown result is a warning',
+    );
+};
+
+subtest 'pending uid' => sub {
+    my $uid = 'gaytemzugu3doobzmfrg';
+    my $other = 'aaaaaaaaaaaaaaaaaaaa';
+
+    is(PVE::GuestIdentity::get_pending_uid({}), undef, 'none without pending section');
+    is(PVE::GuestIdentity::get_pending_uid({ pending => { memory => 1 } }), undef, 'none');
+    is(
+        PVE::GuestIdentity::get_pending_uid({ pending => { meta => 'uid=' . uc($uid) } }),
+        undef,
+        'invalid pending uid is none',
+    );
+    is(
+        PVE::GuestIdentity::get_pending_uid({ pending => { meta => "ctime=1,uid=$uid" } }),
+        $uid,
+        'other members are ignored',
+    );
+
+    my $conf = { meta => "rtime=1,uid=$other", pending => { memory => 1 } };
+    PVE::GuestIdentity::set_pending_uid($conf, $uid);
+    is_deeply(
+        $conf,
+        { meta => "rtime=1,uid=$other", pending => { memory => 1, meta => "uid=$uid" } },
+        'set: only the uid member, other pending changes are kept',
+    );
+    is(PVE::GuestIdentity::get_pending_uid($conf), $uid, 'set: read back');
+
+    PVE::GuestIdentity::set_pending_uid($conf, undef);
+    is_deeply(
+        $conf,
+        { meta => "rtime=1,uid=$other", pending => { memory => 1 } },
+        'remove: other pending changes are kept',
+    );
+    $conf = {};
+    PVE::GuestIdentity::set_pending_uid($conf, undef);
+    is_deeply($conf, {}, 'remove without pending section changes nothing');
+
+    eval { PVE::GuestIdentity::set_pending_uid({}, 'GAYTEMZUGU3DOOBZMFRG') };
+    like($@, qr/invalid guest identity uid/, 'invalid uid is refused');
+
+    my $reservation = { identity => undef, pending => undef };
+    is(PVE::GuestIdentity::adoptable_uid($reservation, $uid), $uid, 'no identity: adoptable');
+    is(PVE::GuestIdentity::adoptable_uid($reservation, undef), undef, 'nothing to adopt');
+    is(PVE::GuestIdentity::adoptable_uid(undef, $uid), undef, 'no reservation: none');
+    ok(PVE::GuestIdentity::uid_matches_target($reservation, $uid), 'no identity: matches');
+
+    $reservation = { identity => { uid => $other, rtime => 1 }, pending => undef };
+    is(PVE::GuestIdentity::adoptable_uid($reservation, $uid), undef, 'identity: not adoptable');
+    is(PVE::GuestIdentity::adoptable_uid($reservation, $other), undef,
+        'own uid: not adoptable');
+    ok(!PVE::GuestIdentity::uid_matches_target($reservation, $uid), 'identity: no match');
+    ok(PVE::GuestIdentity::uid_matches_target($reservation, $other), 'own uid: matches');
+
+    $reservation->{pending} = $uid;
+    is(PVE::GuestIdentity::adoptable_uid($reservation, $uid), $uid, 'pending uid: adoptable');
+    ok(PVE::GuestIdentity::uid_matches_target($reservation, $uid), 'pending uid: matches');
+    is(PVE::GuestIdentity::adoptable_uid($reservation, $other), undef, 'own uid still not');
+};
+
 done_testing();
-- 
2.47.3





  parent reply	other threads:[~2026-11-16  0:52 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 ` [PATCH guest-common 09/34] abstract config: assign a guest identity and keep it on config writes Thomas Lamprecht
2026-11-17 10:47   ` 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 ` Thomas Lamprecht [this message]
2026-11-17 13:14   ` [PATCH guest-common 11/34] guest identity: allow taking over a uid that is unused in the cluster 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-12-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 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