public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* Re: [PATCH cluster/guest-common/qemu-server/container/manager/docs v5 00/41] fix #7846: guest identity (uid) and cluster ID
  2026-11-19 19:18 17% [PATCH cluster/guest-common/qemu-server/container/manager/docs v5 " Thomas Lamprecht
                   ` (2 preceding siblings ...)
  2026-11-19 19:19 17% ` [PATCH docs v5 37/41] vzdump: describe the guest identity of VMs and containers Thomas Lamprecht
@ 2026-11-20  3:07 21% ` Thomas Lamprecht
  3 siblings, 0 replies; 32+ results
From: Thomas Lamprecht @ 2026-11-20  3:07 UTC (permalink / raw)
  To: pve-devel, Thomas Lamprecht

On Thu, 19 Nov 2026 20:18:32 +0100, Thomas Lamprecht wrote:
> A VMID can be reused for another guest, and a guest can get another
> VMID or move to another cluster through a restore or a remote
> migration. So backup software and other tools cannot tell whether they
> still look at the same guest, see [0].
> 
> This series gives every VM and container a guest identity in the
> read-only 'meta' property: a random uid (100 bits as 20 base32
> characters) and the time the guest was registered in the cluster. Create
> and clone get a new uid. Config changes, migration, rollback, backup and
> restore keep it, also under another VMID or in another cluster, as long
> as no other guest there has it. Each cluster or standalone node also
> gets a cluster ID in the same format, generated and protected by pmxcfs.
> The docs patches describe the details.
> 
> [...]

Applied, thanks @Dominik for the reviews!

Relevant changes on top of v5:

- ui: restore: the 'Allow restoring a backup of another guest' checkbox
  only shows if the backup and the guest have different uids, together
  with a hint, or if the window cannot compare them.
- container restore: extract the backup file through the handle that was
  opened to read its config, without looking up its path again. A backup
  that a prune job removed in between no longer makes the restore fail
  after it destroyed the old container.
- backup providers get the guest uid and the cluster ID as 'guest-uid'
  and 'cluster-id' in the info hash of the backup calls, with new
  commits in qemu-server and pve-container, documented in pve-storage.
- container config: refuse writing a value with a null character, as the
  pmxcfs lookup that the uid uniqueness check uses would cut it short.
- qmextract: fail if a restored volume of a legacy tar archive cannot be
  recorded, instead of keeping the drive line of the backup, which names
  a disk of the original VM.

The HA change, which checks the target before an HA move stops a guest,
is sent separately:
https://lore.proxmox.com/20261120025517.3031086-1-t.lamprecht@proxmox.com

[01/41] pmxcfs: reject changes to the cluster ID file from user space
        commit: 80bfea496eea6b2f2d6dad0aeb8d0779ce4e6887
[02/41] pmxcfs: generate a cluster ID on standalone nodes
        commit: 08af730be735a4bb53ebbc810dcad86292296595
[03/41] pmxcfs: dfsm: add a callback that runs once all members are in sync
        commit: e8ab9df65539d96036dbfabddc470d714b2998a3
[04/41] pmxcfs: quorum: record the corosync membership
        commit: 29bdd4a38eaba6a479f2b540b6d9b9ca98c72b78
[05/41] pmxcfs: dcdb: generate the cluster ID once the cluster is in sync
        commit: 00d3623ac7dca7fd4f3182e1799b2ebaebb16078
[06/41] cluster: add helper to read the cluster ID
        commit: abe3f3255d63cd0cfa6cb6787dd8b2e5ea401422
[07/41] pmxcfs: allow removing the cluster ID file in forced local mode
        commit: 2b3f8b7958a1512992d60fe043ffc0c96e37ade7
[08/41] guest identity: add helpers for the guest uid and registration time
        commit: d6abe33d85d4fba903e9b20e2b220fe8acdfb8d6
[09/41] abstract config: assign a guest identity and keep it on config writes
        commit: ceb4de65f8daf518926c11107e1d254f9cd8c5e7
[10/41] abstract config: let the VMID reservation return the previous state
        commit: b3c31bfdd4872412fdf603b55a6e33e2ed7be606
[11/41] guest identity: allow adopting a uid that is unused in the cluster
        commit: 849d16c923048b3c4bca42188a4d6a3569abe930
[12/41] migrate: add shared helpers for the identity command of the migration tunnel
        commit: 470f2beb306cf045a46e7573bb26293de9e6062d
[13/41] vzdump: notes template: list the uid variable
        commit: f71c9aa5bcda4e64f767fa789fc203bb764595d7
[14/41] api: restore: release the VMID if a restore to an unused VMID fails
        commit: 74b4a27e41ae286b2108fee73314d34ae126b378
[15/41] api: migrate, clone: refuse targets that would drop the guest identity
        commit: 61feb80f3c7bec3390e4f7f259084520a796f7d5
[16/41] fix #7846: config: add a guest identity to the 'meta' property
        commit: ca8b246e51a3dbe9f605f32279889d133b17314d
[17/41] restore: adopt the guest uid from the backup where possible
        commit: e72b64d37c3a1392fe322b6823ca14791b5c3403
[18/41] api: remote migration: adopt the guest uid from the source
        commit: cd54b862cb6a53e7df84f7d95b866063e5fb6473
[19/41] api: status: return the guest uid
        commit: a6556ca3b894f6619a884b87d84611acd7df65d3
[20/41] restore: decide by the reservation whether the container is new
        commit: 591a5b2290bad28c9ab362ab275069bb5026876d
[21/41] config: add read-only meta property with the creation time
        commit: b8390705980392efe6de6f55c191e14d9b3d8cf5
[22/41] fix #7846: config: add a guest identity to the 'meta' property
        commit: 3ac61bcc3d5056a7089ffc4f5eb0adb0d49e7121
[23/41] api: migrate, clone: refuse targets that would drop the guest identity
        commit: 22efc2fc1f6c1e010e218747e157e87a892ebdd3
[24/41] restore: adopt the guest uid from the backup where possible
        commit: 1cb35f7af05b59195a4f69218eadcd0e840b1fd1
[25/41] restore: refuse overwriting a container with another guest's backup
        commit: 0bdfe1409ab0af658763319cc5c3cee17999fe87
[26/41] api: remote migration: adopt the guest uid from the source
        commit: 7872093384e596a7c1242f091e6bef5fe466d294
[27/41] api: status: return the guest uid
        commit: 6c00625d47ec2844425c2cff59f5e97de1680b1e
[28/41] api: cluster resources: add guest uid and registration time
        commit: edc625ee58da21ac2c2abbcf2543564b17e2b062
[29/41] api: cluster status: add cluster ID
        commit: 0b834c59ad0882b4eb8387e33674bba8d45b8170
[30/41] ui: datacenter summary: show the cluster ID
        commit: 8e228d11d1c0b4ea3ba8a312820d0da0d02b0905
[31/41] ui: restore: allow overwriting a guest with a backup of another guest
        commit: 7033417f0e07219a44efdcb1fdf6d303359e0dad
[32/41] ui: migrate: refuse target nodes that would drop the guest identity
        commit: 582f8751155f407328a31b2b50ef21426db648d7
[33/41] ui: guest summary: show the guest identity
        commit: 45ade9e2e1c64476e3cacbd111f24b8ef4d3c463
[34/41] api: bulk migrate: refuse targets that would drop the guest identity
        commit: 90f90c412189dcb050d59971279308ccfa814a6c
[35/41] vzdump: notes template: add the guest uid as variable
        commit: d16ed476671d1f3601d431e266bd2f78ee9bc322
[36/41] vzdump: restore: describe what a failed restore can leave behind
        commit: 546a2957c573701b38ab99989075cd22df59bcc6
[37/41] vzdump: describe the guest identity of VMs and containers
        commit: b78d0cf66f5b9a9cf755079418625af267c47408
[38/41] pvecm: document the cluster ID and how to get a new one
        commit: 24c02ec4adfbc7b84e55b242353970673d57d4ab
[39/41] qm: configuration: describe the read-only meta property
        commit: 3c8dd3271a2c0205bb6941af5291609f12bc684d
[40/41] pct: configuration: describe the read-only meta property
        commit: 442090df05a172414f7e4a952634047b81822534
[41/41] vzdump: notes: document the uid template variable
        commit: 09c13af8f3b82f721992175de2db348554cbd4e5




^ permalink raw reply	[relevance 21%]

* superseded: [PATCH cluster/guest-common/qemu-server/container/manager/docs v4 00/41] fix #7846: guest identity (uid) and cluster ID
  2026-11-19 10:33 17% [PATCH cluster/guest-common/qemu-server/container/manager/docs v4 00/41] " Thomas Lamprecht
                   ` (3 preceding siblings ...)
  2026-11-19 14:46 17% ` [PATCH cluster/guest-common/qemu-server/container/manager/docs v4 00/41] fix #7846: guest identity (uid) and cluster ID Dominik Csapak
@ 2026-11-19 19:49 11% ` Thomas Lamprecht
  4 siblings, 0 replies; 32+ results
From: Thomas Lamprecht @ 2026-11-19 19:49 UTC (permalink / raw)
  To: pve-devel

Superseded-by: https://lore.proxmox.com/pve-devel/20261119191914.2336934-1-t.lamprecht@proxmox.com/




^ permalink raw reply	[relevance 11%]

* [PATCH qemu-server v5 16/41] fix #7846: config: add a guest identity to the 'meta' property
  2026-11-19 19:18 17% [PATCH cluster/guest-common/qemu-server/container/manager/docs v5 " Thomas Lamprecht
  2026-11-19 19:18 22% ` [PATCH guest-common v5 08/41] guest identity: add helpers for the guest uid and registration time Thomas Lamprecht
@ 2026-11-19 19:18 16% ` Thomas Lamprecht
  2026-11-19 19:19 17% ` [PATCH docs v5 37/41] vzdump: describe the guest identity of VMs and containers Thomas Lamprecht
  2026-11-20  3:07 21% ` [PATCH cluster/guest-common/qemu-server/container/manager/docs v5 00/41] fix #7846: guest identity (uid) and cluster ID Thomas Lamprecht
  3 siblings, 0 replies; 32+ results
From: Thomas Lamprecht @ 2026-11-19 19:18 UTC (permalink / raw)
  To: pve-devel

Give VMs a guest identity in the read-only 'meta' property: a random
identifier, 'uid', and a registration time, 'rtime'. Tools can use it
to recognize a guest across restores and migrations, independently of
its VMID.

Enable the identity handling of the config class, so that each config
write keeps the identity a VM already has or assigns one if it has
none. New VMs, clones and imports get an identity when their VMID is
reserved. Existing VMs get one with their next config write. A stale
config, a clone source or a snapshot rollback cannot replace the
identity of a VM.

The other members of 'meta' behave as before. A config without creation
information thus gets a 'meta' property with only the identity. Older
qemu-server versions reject the new members and drop the whole property
on their next config write.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Reviewed-by: Dominik Csapak <d.csapak@proxmox.com>
Tested-by: Dominik Csapak <d.csapak@proxmox.com>
---

no changes since v4

changes v3 -> v4:
* tests: 'create' and 'clone' call the API handlers instead of repeating
  their config writes, and cases that only checked the schema parser are
  gone
* the identity parts of the fake cluster filesystem come with this
  patch, its base is in an independent test commit before the series
* rebase onto current master (tests only)

changes v2 -> v3:
* group the imports of the new test script

changes v1 -> v2:
* rebase, adapt the tests

 src/PVE/QemuConfig.pm                         |   7 +
 src/PVE/QemuServer/MetaInfo.pm                |   2 +
 src/test/Makefile                             |   5 +-
 src/test/QemuServerTest/FakeCFS.pm            |  84 +++++-
 .../q35-windows-pinning-identity-only.conf    |   6 +
 ...q35-windows-pinning-identity-only.conf.cmd |  26 ++
 .../meta-identity-invalid.conf                |   6 +
 .../meta-identity-invalid.conf.strict.error   |   2 +
 .../meta-identity-invalid.conf                |   7 +
 .../parse-config-input/meta-identity.conf     |  20 ++
 src/test/run_guest_identity_tests.pl          | 275 ++++++++++++++++++
 src/test/run_parse_config_tests.pl            |   2 +-
 src/test/run_qemu_restore_config_tests.pl     |   3 +-
 .../create/qemu-server/401.conf               |  31 ++
 .../create/qemu-server/402.conf               |  31 ++
 .../rollback/qemu-server/401.conf             |  36 +++
 .../rollback/qemu-server/402.conf             |  35 +++
 .../create/qemu-server/401.conf               |  13 +
 .../create/qemu-server/402.conf               |  13 +
 .../rollback/qemu-server/401.conf             |  35 +++
 .../rollback/qemu-server/402.conf             |  34 +++
 src/test/snapshot-test.pm                     |  82 +++++-
 22 files changed, 738 insertions(+), 17 deletions(-)
 create mode 100644 src/test/cfg2cmd/q35-windows-pinning-identity-only.conf
 create mode 100644 src/test/cfg2cmd/q35-windows-pinning-identity-only.conf.cmd
 create mode 100644 src/test/parse-config-expected/meta-identity-invalid.conf
 create mode 100644 src/test/parse-config-expected/meta-identity-invalid.conf.strict.error
 create mode 100644 src/test/parse-config-input/meta-identity-invalid.conf
 create mode 100644 src/test/parse-config-input/meta-identity.conf
 create mode 100755 src/test/run_guest_identity_tests.pl
 create mode 100644 src/test/snapshot-expected/create/qemu-server/401.conf
 create mode 100644 src/test/snapshot-expected/create/qemu-server/402.conf
 create mode 100644 src/test/snapshot-expected/rollback/qemu-server/401.conf
 create mode 100644 src/test/snapshot-expected/rollback/qemu-server/402.conf
 create mode 100644 src/test/snapshot-input/create/qemu-server/401.conf
 create mode 100644 src/test/snapshot-input/create/qemu-server/402.conf
 create mode 100644 src/test/snapshot-input/rollback/qemu-server/401.conf
 create mode 100644 src/test/snapshot-input/rollback/qemu-server/402.conf

diff --git a/src/PVE/QemuConfig.pm b/src/PVE/QemuConfig.pm
index 6656c137..e7adfbfb 100644
--- a/src/PVE/QemuConfig.pm
+++ b/src/PVE/QemuConfig.pm
@@ -672,6 +672,13 @@ sub write_config {
     return $class->SUPER::write_config($vmid, $conf);
 }
 
+# the format of the 'meta' property includes the guest identity, see PVE::QemuServer::MetaInfo
+sub __identity_enabled {
+    my ($class) = @_;
+
+    return 1;
+}
+
 # END implemented abstract methods from PVE::AbstractConfig
 
 sub has_cloudinit {
diff --git a/src/PVE/QemuServer/MetaInfo.pm b/src/PVE/QemuServer/MetaInfo.pm
index b69e5a1c..399cd920 100644
--- a/src/PVE/QemuServer/MetaInfo.pm
+++ b/src/PVE/QemuServer/MetaInfo.pm
@@ -3,6 +3,7 @@ package PVE::QemuServer::MetaInfo;
 use strict;
 use warnings;
 
+use PVE::GuestIdentity;
 use PVE::JSONSchema;
 
 use PVE::QemuServer::Helpers;
@@ -20,6 +21,7 @@ our $meta_info_fmt = {
         pattern => '\d+(\.\d+)+',
         optional => 1,
     },
+    PVE::GuestIdentity::meta_format_properties()->%*,
 };
 
 sub parse_meta_info {
diff --git a/src/test/Makefile b/src/test/Makefile
index 7cd88247..0d47205d 100644
--- a/src/test/Makefile
+++ b/src/test/Makefile
@@ -1,6 +1,6 @@
 all: test
 
-test: test_snapshot test_cfg_to_cmd test_cfg_to_cmd_aarch64 test_hotplug test_hotplug_aarch64 test_pci_addr_conflicts test_pci_reservation test_qemu_img_convert test_migration test_restore_config test_parse_config test_memory test_agent test_raw_config_write test_api test_api_cloudinit_dump test_mtunnel
+test: test_snapshot test_cfg_to_cmd test_cfg_to_cmd_aarch64 test_hotplug test_hotplug_aarch64 test_pci_addr_conflicts test_pci_reservation test_qemu_img_convert test_migration test_restore_config test_parse_config test_memory test_agent test_raw_config_write test_api test_api_cloudinit_dump test_mtunnel test_guest_identity
 
 test_snapshot: run_snapshot_tests.pl
 	./run_snapshot_tests.pl
@@ -60,6 +60,9 @@ test_api_cloudinit_dump: run_api_cloudinit_dump_tests.pl
 test_mtunnel: run_mtunnel_tests.pl QemuServerTest/FakeCFS.pm QemuServerTest/MTunnel.pm
 	./run_mtunnel_tests.pl
 
+test_guest_identity: run_guest_identity_tests.pl QemuServerTest/FakeCFS.pm
+	./run_guest_identity_tests.pl
+
 .PHONY: clean
 clean:
 	rm -rf MigrationTest/run
diff --git a/src/test/QemuServerTest/FakeCFS.pm b/src/test/QemuServerTest/FakeCFS.pm
index c5609892..a9949d63 100644
--- a/src/test/QemuServerTest/FakeCFS.pm
+++ b/src/test/QemuServerTest/FakeCFS.pm
@@ -1,10 +1,12 @@
 package QemuServerTest::FakeCFS;
 
 # Fake cluster filesystem for VM config files, so that tests can use the real config class methods
-# of PVE::QemuConfig without pmxcfs.
+# of PVE::QemuConfig, including the guest identity handling of write_config, without pmxcfs.
 #
 # Configs are kept as raw text, indexed by VMID, and an empty file at the path that config_file()
-# returns exists for each, for checks of the file's existence.
+# returns exists for each, for checks of the file's existence. Generated guest identities are
+# deterministic: the n-th generated uid is 'a' repeated 17 times followed by the base32 encoding of
+# n, and rtime is $now_ms.
 
 use v5.36;
 
@@ -15,10 +17,15 @@ use Test::MockModule;
 
 use PVE::GuestHelpers;
 use PVE::GuestID;
+use PVE::GuestIdentity;
 use PVE::QemuConfig;
 use PVE::QemuServer;
 
 our $configs = {}; # VMID => raw config, for VMs on the local node
+our $other_guests = {}; # VMID => raw 'meta' property of other guests, like on other nodes or CTs
+our $now_ms = 1700000000000;
+our $generated = 0;
+our $lock_domain_error;
 our $written = {}; # VMID => the written raw configs, in the order of the writes
 
 my $tmpdir = tempdir('fake-cfs-XXXXXX', DIR => '.', CLEANUP => 1);
@@ -28,6 +35,10 @@ $PVE::GuestHelpers::lockdir = "$tmpdir/lock";
 sub reset() {
     remove_tree("$tmpdir/etc-pve");
     $configs = {};
+    $other_guests = {};
+    $now_ms = 1700000000000;
+    $generated = 0;
+    $lock_domain_error = undef;
     $written = {};
 }
 
@@ -53,12 +64,55 @@ sub set_config($vmid, $raw) {
     sync_config_file($vmid);
 }
 
+# Returns the last 'meta' property of the top-level section of the raw config $raw, like the config
+# class reads the stored identity.
+my sub top_level_meta($raw) {
+    my $meta;
+    for my $line (split(/\n/, $raw // '')) {
+        last if $line =~ m/^\[/;
+        # like pmxcfs, a line with nothing after the colon does not count
+        $meta = $1 =~ s/^\s+|\s+$//gr if $line =~ m/^meta:(.+)$/;
+    }
+
+    return $meta;
+}
+
+# Returns the identity stored in the raw config of $vmid, undef if there is none.
+sub stored_identity($vmid) {
+    return PVE::GuestIdentity::parse_identity(top_level_meta($configs->{$vmid}));
+}
+
+# Returns the uid that the $n-th generation of an identity yields.
+sub generated_uid($n) {
+    my $alphabet = 'abcdefghijklmnopqrstuvwxyz234567';
+    return ('a' x 17) . join('', map { substr($alphabet, ($n >> (5 * $_)) & 31, 1) } (2, 1, 0));
+}
+
 # the list of used guest IDs is not part of the fake cluster filesystem
 our $guest_id_module = Test::MockModule->new('PVE::GuestID');
 $guest_id_module->mock(register_used_id => sub { return; });
 
+our $guest_identity_module = Test::MockModule->new('PVE::GuestIdentity');
+$guest_identity_module->mock(
+    __random_bytes => sub {
+        my ($len) = @_;
+        die "unexpected length $len\n" if $len != 20;
+        $generated++;
+        # one byte per uid character, the last three hold 5 bits of the counter each
+        return ("\0" x 17) . pack('C3', map { ($generated >> $_) & 31 } (10, 5, 0));
+    },
+    __time_ms => sub {
+        return $now_ms;
+    },
+);
+
 our $cluster_module = Test::MockModule->new('PVE::Cluster');
 $cluster_module->mock(
+    get_config => sub {
+        my ($path) = @_;
+        my $vmid = vmid_of_path($path) // die "get_config (mocked) - unexpected path '$path'\n";
+        return $configs->{$vmid};
+    },
     cfs_read_file => sub {
         my ($path) = @_;
         return {} if $path eq 'datacenter.cfg';
@@ -80,10 +134,34 @@ $cluster_module->mock(
     },
     check_vmid_unused => sub {
         my ($vmid, $noerr) = @_;
-        return 1 if !defined($configs->{$vmid});
+        return 1 if !defined($configs->{$vmid}) && !defined($other_guests->{$vmid});
         return undef if $noerr;
         die "VM $vmid already exists\n";
     },
+    cfs_lock_domain => sub {
+        my ($domain, $timeout, $code, @param) = @_;
+        die "cfs_lock_domain (mocked) - unexpected domain '$domain'\n"
+            if $domain ne 'guest-identity';
+        if ($lock_domain_error) {
+            $@ = $lock_domain_error;
+            return undef;
+        }
+        my $res = eval { $code->(@param) };
+        return $res;
+    },
+    get_guest_config_properties => sub {
+        my ($properties) = @_;
+        die "get_guest_config_properties (mocked) - unexpected properties\n"
+            if join(',', $properties->@*) ne 'meta';
+
+        my $res = {};
+        for my $vmid (keys $configs->%*) {
+            my $meta = top_level_meta($configs->{$vmid});
+            $res->{$vmid} = { meta => $meta } if defined($meta);
+        }
+        $res->{$_} = { meta => $other_guests->{$_} } for keys $other_guests->%*;
+        return $res;
+    },
 );
 
 our $qemu_config_module = Test::MockModule->new('PVE::QemuConfig');
diff --git a/src/test/cfg2cmd/q35-windows-pinning-identity-only.conf b/src/test/cfg2cmd/q35-windows-pinning-identity-only.conf
new file mode 100644
index 00000000..5242ec13
--- /dev/null
+++ b/src/test/cfg2cmd/q35-windows-pinning-identity-only.conf
@@ -0,0 +1,6 @@
+# TEST: Windows without pinned machine and with only the guest identity as meta info stays on 5.1
+machine: q35
+meta: rtime=1762300000000,uid=abcdefghijklmnopqrst
+ostype: win11
+smbios1: uuid=7b10d7af-b932-4c66-b2c3-3996152ec465
+vmgenid: c773c261-d800-4348-9f5d-167fadd53cf8
diff --git a/src/test/cfg2cmd/q35-windows-pinning-identity-only.conf.cmd b/src/test/cfg2cmd/q35-windows-pinning-identity-only.conf.cmd
new file mode 100644
index 00000000..67d20b79
--- /dev/null
+++ b/src/test/cfg2cmd/q35-windows-pinning-identity-only.conf.cmd
@@ -0,0 +1,26 @@
+/usr/bin/kvm \
+  -id 8006 \
+  -name vm8006 \
+  -no-shutdown \
+  -chardev 'socket,id=qmp,path=/var/run/qemu-server/8006.qmp,server=on,wait=off' \
+  -object 'monitor-qmp,chardev=qmp,id=monitor-qmp' \
+  -chardev 'socket,id=qmp-event,path=/var/run/qmeventd.sock,reconnect-ms=5000' \
+  -object 'monitor-qmp,chardev=qmp-event,id=monitor-qmp-event' \
+  -pidfile /var/run/qemu-server/8006.pid \
+  -daemonize \
+  -smbios 'type=1,uuid=7b10d7af-b932-4c66-b2c3-3996152ec465' \
+  -smp '1,sockets=1,cores=1,maxcpus=1' \
+  -nodefaults \
+  -boot 'menu=on,strict=on,reboot-timeout=1000,splash=/usr/share/qemu-server/bootsplash.jpg' \
+  -vnc 'unix:/var/run/qemu-server/8006.vnc,password=on' \
+  -global 'kvm-pit.lost_tick_policy=discard' \
+  -cpu 'kvm64,-cet-ibt,-cet-ss,enforce,hv_ipi,hv_relaxed,hv_reset,hv_runtime,hv_spinlocks=0x1fff,hv_stimer,hv_synic,hv_time,hv_vapic,hv_vpindex,+kvm_pv_eoi,+kvm_pv_unhalt,+lahf_lm,+sep' \
+  -m 512 \
+  -readconfig /usr/share/qemu-server/pve-q35-4.0.cfg \
+  -device 'vmgenid,guid=c773c261-d800-4348-9f5d-167fadd53cf8' \
+  -device 'usb-tablet,id=tablet,bus=ehci.0,port=1' \
+  -device 'VGA,id=vga,bus=pcie.0,addr=0x1,edid=off' \
+  -device 'virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3' \
+  -iscsi 'initiator-name=iqn.1993-08.org.debian:01:aabbccddeeff' \
+  -rtc 'driftfix=slew,base=localtime' \
+  -machine 'hpet=off,type=pc-q35-5.1+pve0'
diff --git a/src/test/parse-config-expected/meta-identity-invalid.conf b/src/test/parse-config-expected/meta-identity-invalid.conf
new file mode 100644
index 00000000..195514fa
--- /dev/null
+++ b/src/test/parse-config-expected/meta-identity-invalid.conf
@@ -0,0 +1,6 @@
+# VM with a guest uid that is not valid
+boot: order=scsi0
+cores: 2
+memory: 4096
+name: identity
+scsi0: local-lvm:vm-8006-disk-0,size=32G
diff --git a/src/test/parse-config-expected/meta-identity-invalid.conf.strict.error b/src/test/parse-config-expected/meta-identity-invalid.conf.strict.error
new file mode 100644
index 00000000..ae584c1f
--- /dev/null
+++ b/src/test/parse-config-expected/meta-identity-invalid.conf.strict.error
@@ -0,0 +1,2 @@
+vm 8006 - unable to parse value of 'meta' - format error
+uid: value does not match the regex pattern
diff --git a/src/test/parse-config-input/meta-identity-invalid.conf b/src/test/parse-config-input/meta-identity-invalid.conf
new file mode 100644
index 00000000..90e60197
--- /dev/null
+++ b/src/test/parse-config-input/meta-identity-invalid.conf
@@ -0,0 +1,7 @@
+# VM with a guest uid that is not valid
+boot: order=scsi0
+cores: 2
+memory: 4096
+meta: creation-qemu=10.1.2,ctime=1762000000,rtime=1762000000123,uid=ABCDEFGHIJKLMNOPQRST
+name: identity
+scsi0: local-lvm:vm-8006-disk-0,size=32G
diff --git a/src/test/parse-config-input/meta-identity.conf b/src/test/parse-config-input/meta-identity.conf
new file mode 100644
index 00000000..7a1e03be
--- /dev/null
+++ b/src/test/parse-config-input/meta-identity.conf
@@ -0,0 +1,20 @@
+# VM with guest identity
+boot: order=scsi0
+cores: 2
+memory: 4096
+meta: creation-qemu=10.1.2,ctime=1762000000,rtime=1762000000123,uid=abcdefghijklmnopqrst
+name: identity
+scsi0: local-lvm:vm-8006-disk-0,size=32G
+scsihw: virtio-scsi-single
+smbios1: uuid=7b4f2a1e-3c2d-4e5f-8a9b-0c1d2e3f4a5b
+
+[snap]
+boot: order=scsi0
+cores: 2
+memory: 4096
+meta: creation-qemu=10.1.2,ctime=1762000000,rtime=1762000000123,uid=abcdefghijklmnopqrst
+name: identity
+scsi0: local-lvm:vm-8006-disk-0,size=32G
+scsihw: virtio-scsi-single
+smbios1: uuid=7b4f2a1e-3c2d-4e5f-8a9b-0c1d2e3f4a5b
+snaptime: 1762000100
diff --git a/src/test/run_guest_identity_tests.pl b/src/test/run_guest_identity_tests.pl
new file mode 100755
index 00000000..3eec153f
--- /dev/null
+++ b/src/test/run_guest_identity_tests.pl
@@ -0,0 +1,275 @@
+#!/usr/bin/perl
+
+# Tests the guest identity of VM configs through the real config class methods, with a fake cluster
+# filesystem, see QemuServerTest::FakeCFS.
+
+use v5.36;
+
+use lib qw(.. .);
+
+use File::Temp qw(tempdir);
+use Test::MockModule;
+use Test::More;
+
+use PVE::JSONSchema;
+use PVE::RPCEnvironment;
+
+use PVE::QemuConfig;
+use PVE::QemuConfig::NoWrite;
+use PVE::QemuServer;
+use PVE::QemuServer::MetaInfo;
+
+use PVE::API2::Qemu;
+
+use QemuServerTest::FakeCFS;
+use QemuServerTest::Utils qw(capture_output);
+
+my $UID_A = 'abcdefghijklmnopqrst';
+my $UID_B = 'bbbbbbbbbbbbbbbbbbbb';
+
+my $helpers_module = Test::MockModule->new('PVE::QemuServer::Helpers');
+$helpers_module->mock(kvm_user_version => sub { return '10.1.2'; });
+
+my $rpcenv = PVE::RPCEnvironment->init('cli');
+$rpcenv->set_user('root@pam');
+
+my $rpcenv_module = Test::MockModule->new('PVE::RPCEnvironment');
+$rpcenv_module->mock(
+    check => sub { return 1; },
+    check_vm_perm => sub { return 1; },
+    fork_worker => sub {
+        my ($self, $type, $id, $user, $code) = @_;
+        $code->('UPID:test');
+        return 'UPID:test';
+    },
+);
+$QemuServerTest::FakeCFS::cluster_module->mock(check_cfs_quorum => sub { return 1; });
+my $network_module = Test::MockModule->new('PVE::QemuServer::Network');
+$network_module->mock(create_ifaces_ipams_ips => sub { return; });
+
+sub configs { return $QemuServerTest::FakeCFS::configs; }
+sub generated_uid { return QemuServerTest::FakeCFS::generated_uid(@_); }
+sub stored_identity { return QemuServerTest::FakeCFS::stored_identity(@_); }
+
+sub load_meta($vmid) {
+    return PVE::QemuServer::MetaInfo::parse_meta_info(PVE::QemuConfig->load_config($vmid)->{meta});
+}
+
+subtest 'meta format' => sub {
+    my $meta =
+        'creation-qemu=10.1.2,ctime=1700000000,rtime=1700000000123,uid=abcdefghijklmnopqrst';
+
+    is_deeply(
+        PVE::QemuServer::MetaInfo::parse_meta_info($meta),
+        {
+            'creation-qemu' => '10.1.2',
+            ctime => 1700000000,
+            rtime => 1700000000123,
+            uid => $UID_A,
+        },
+        'identity members get parsed',
+    );
+    is(
+        PVE::JSONSchema::print_property_string(
+            PVE::QemuServer::MetaInfo::parse_meta_info($meta),
+            $PVE::QemuServer::MetaInfo::meta_info_fmt,
+        ),
+        $meta,
+        'printing the parsed property gives the same string',
+    );
+};
+
+subtest 'identities are enabled, but not for writing temporary configs' => sub {
+    QemuServerTest::FakeCFS::reset();
+
+    ok(PVE::QemuConfig->__identity_enabled(), 'enabled for PVE::QemuConfig');
+
+    my $conf = { name => 'template-cmd' };
+    PVE::QemuConfig::NoWrite->mark_config($conf);
+    eval { PVE::QemuConfig->write_config(100, $conf) };
+    is($@, "refusing to write temporary configuration\n", 'NoWrite refuses');
+    eval { PVE::QemuConfig::NoWrite->write_config(100, $conf) };
+    is(
+        $@,
+        "refusing to write temporary configuration\n",
+        'NoWrite refuses when called directly',
+    );
+    is_deeply(configs(), {}, 'nothing written');
+    is($QemuServerTest::FakeCFS::generated, 0, 'no identity generated');
+};
+
+subtest 'config writes keep the stored identity' => sub {
+    QemuServerTest::FakeCFS::reset();
+
+    PVE::QemuConfig->write_config(100, { memory => 512, meta => "rtime=1,uid=$UID_B" });
+    is_deeply(
+        stored_identity(100),
+        { uid => generated_uid(1), rtime => 1700000000000 },
+        'first write ignores a carried identity and generates one',
+    );
+    like(configs()->{100}, qr/^meta: rtime=1700000000000,uid=\w+$/m,
+        'written as meta property');
+
+    $QemuServerTest::FakeCFS::now_ms = 1800000000000;
+
+    my $conf = PVE::QemuConfig->load_config(100);
+    $conf->{meta} = "creation-qemu=9.2.0,ctime=1600000000,rtime=1,uid=$UID_B";
+    PVE::QemuConfig->write_config(100, $conf);
+    is_deeply(
+        load_meta(100),
+        {
+            'creation-qemu' => '9.2.0',
+            ctime => 1600000000,
+            rtime => 1700000000000,
+            uid => generated_uid(1),
+        },
+        'foreign identity replaced by the stored one, other members kept',
+    );
+
+    $conf = PVE::QemuConfig->load_config(100);
+    delete $conf->{meta};
+    PVE::QemuConfig->write_config(100, $conf);
+    is_deeply(
+        load_meta(100),
+        { rtime => 1700000000000, uid => generated_uid(1) },
+        'identity kept when the property is gone',
+    );
+
+    configs()->{101} = "memory: 512\nmeta: creation-qemu=8.0.2,ctime=1500000000\n";
+    $conf = PVE::QemuConfig->load_config(101);
+    $conf->{name} = 'old';
+    PVE::QemuConfig->write_config(101, $conf);
+    is_deeply(
+        load_meta(101),
+        {
+            'creation-qemu' => '8.0.2',
+            ctime => 1500000000,
+            rtime => 1800000000000,
+            uid => generated_uid(2),
+        },
+        'existing guest without identity gets one on its first write',
+    );
+};
+
+subtest 'create' => sub {
+    QemuServerTest::FakeCFS::reset();
+
+    my $storage_module = Test::MockModule->new('PVE::Storage');
+    $storage_module->mock(config => sub { return {}; });
+    my $replication_state_module = Test::MockModule->new('PVE::ReplicationState');
+    $replication_state_module->mock(delete_guest_states => sub { return; });
+
+    capture_output(sub {
+        PVE::API2::Qemu->create_vm({ node => 'localhost', vmid => 100, memory => 512 });
+    });
+
+    my $reserved = $QemuServerTest::FakeCFS::written->{100}->[0];
+    like(
+        $reserved,
+        qr/^meta: rtime=1700000000000,uid=\w+$/m,
+        'reservation stores a new identity',
+    );
+    my $meta = load_meta(100);
+    is_deeply(
+        [$meta->@{qw(creation-qemu uid rtime)}],
+        ['10.1.2', generated_uid(1), 1700000000000],
+        'final config keeps the reserved identity next to the creation info',
+    );
+    ok($meta->{ctime}, 'creation time set');
+};
+
+subtest 'clone' => sub {
+    QemuServerTest::FakeCFS::reset();
+
+    my $disk = "scsi0: local:100/vm-100-disk-0.raw,size=4G\n";
+    my $source = "memory: 512\nmeta: creation-qemu=9.2.0,ctime=1600000000,"
+        . "rtime=1600000000000,uid=$UID_A\nname: source\n$disk";
+    # a snapshot can carry any identity
+    configs()->{100} =
+        "$source\n[snap]\nmemory: 256\nmeta: rtime=1,uid=$UID_B\n${disk}snaptime: 1600000001\n";
+
+    my $storage_module = Test::MockModule->new('PVE::Storage');
+    $storage_module->mock(
+        activate_volumes => sub { return; },
+        config => sub {
+            return {
+                ids => {
+                    local =>
+                        { type => 'dir', path => '/var/lib/vz', content => { images => 1 } },
+                },
+            };
+        },
+        deactivate_volumes => sub { return; },
+        get_bandwidth_limit => sub { return undef; },
+        volume_has_feature => sub { return 1; },
+    );
+    my $qemu_server_module = Test::MockModule->new('PVE::QemuServer');
+    $qemu_server_module->mock(
+        check_running => sub { return 0; },
+        clone_disk => sub {
+            my ($storecfg, $source, $dest) = @_;
+            return { file => "local:$dest->{vmid}/vm-$dest->{vmid}-disk-0.raw", size => '4G' };
+        },
+    );
+    my $firewall_module = Test::MockModule->new('PVE::Firewall');
+    $firewall_module->mock(clone_vmfw_conf => sub { return; });
+
+    my $output = capture_output(sub {
+        PVE::API2::Qemu->clone_vm({ node => 'localhost', vmid => 100, newid => 300 });
+        PVE::API2::Qemu->clone_vm(
+            { node => 'localhost', vmid => 100, newid => 301, snapname => 'snap' });
+    });
+
+    is(stored_identity(300)->{uid}, generated_uid(1), 'clone has a new uid');
+    is_deeply(
+        load_meta(300),
+        {
+            'creation-qemu' => '9.2.0',
+            ctime => 1600000000,
+            rtime => 1700000000000,
+            uid => generated_uid(1),
+        },
+        'clone keeps the creation info of its source',
+    );
+    is_deeply(
+        load_meta(301),
+        { rtime => 1700000000000, uid => generated_uid(2) },
+        'clone of a snapshot has a new uid as well',
+    );
+    is(stored_identity(100)->{uid}, $UID_A, 'source keeps its uid');
+};
+
+subtest 'importovf' => sub {
+    QemuServerTest::FakeCFS::reset();
+
+    require PVE::CLI::qm;
+
+    my $tmpdir = tempdir('importovf-XXXXXX', DIR => '.', CLEANUP => 1);
+    my $manifest = "$tmpdir/test.ovf";
+    PVE::Tools::file_set_contents($manifest, "<ovf/>\n");
+
+    my $storage_module = Test::MockModule->new('PVE::Storage');
+    $storage_module->mock(
+        config => sub { return {}; },
+        storage_check_enabled => sub { return {}; },
+    );
+    my $ovf_module = Test::MockModule->new('PVE::GuestImport::OVF');
+    $ovf_module->mock(
+        parse_ovf => sub {
+            return { qm => { name => 'imported', memory => 1024, cores => 2 }, disks => [] };
+        },
+    );
+
+    PVE::CLI::qm->importovf({ vmid => 100, manifest => $manifest, storage => 'local' });
+
+    my $conf = PVE::QemuConfig->load_config(100);
+    is($conf->{name}, 'imported', 'config imported');
+    ok(!defined($conf->{lock}), 'create lock removed');
+    is_deeply(
+        stored_identity(100),
+        { uid => generated_uid(1), rtime => 1700000000000 },
+        'imported VM got a new identity on reservation and kept it',
+    );
+};
+
+done_testing();
diff --git a/src/test/run_parse_config_tests.pl b/src/test/run_parse_config_tests.pl
index c30aad99..566eec4f 100755
--- a/src/test/run_parse_config_tests.pl
+++ b/src/test/run_parse_config_tests.pl
@@ -25,7 +25,7 @@ my $INPUT_DIR = './parse-config-input';
 my $EXPECTED_DIR = './parse-config-expected';
 
 # NOTE update when you add/remove tests
-plan tests => 2 * 11;
+plan tests => 2 * 13;
 
 sub run_tests {
     my ($strict) = @_;
diff --git a/src/test/run_qemu_restore_config_tests.pl b/src/test/run_qemu_restore_config_tests.pl
index f5f9e026..4e2bc798 100755
--- a/src/test/run_qemu_restore_config_tests.pl
+++ b/src/test/run_qemu_restore_config_tests.pl
@@ -312,7 +312,8 @@ sub restore_api {
     return ($err, $output);
 }
 
-my $TARGET_CONF = "memory: 1024\nmeta: creation-qemu=10.0.0,ctime=1700000000\nname: target\n";
+my $TARGET_CONF = "memory: 1024\nmeta: creation-qemu=10.0.0,ctime=1700000000,"
+    . "rtime=1700000000000,uid=tttttttttttttttttttt\nname: target\n";
 my $NOT_CLEANED_UP = qr/VM 100 state is NOT cleaned up/;
 my $KEPT_LOCKED = 'WARN: keeping VM 100 locked, the cleanup left behind';
 
diff --git a/src/test/snapshot-expected/create/qemu-server/401.conf b/src/test/snapshot-expected/create/qemu-server/401.conf
new file mode 100644
index 00000000..87aadf80
--- /dev/null
+++ b/src/test/snapshot-expected/create/qemu-server/401.conf
@@ -0,0 +1,31 @@
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+memory: 8192
+meta: creation-qemu=10.0.0,ctime=1700000000,rtime=1700000000000,uid=abcdefghijklmnopqrst
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+parent: test
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+sockets: 1
+vga: qxl
+
+[test]
+#test comment
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+memory: 8192
+meta: creation-qemu=10.0.0,ctime=1700000000,rtime=1700000000000,uid=abcdefghijklmnopqrst
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+snaptime: 1234567890
+sockets: 1
+vga: qxl
diff --git a/src/test/snapshot-expected/create/qemu-server/402.conf b/src/test/snapshot-expected/create/qemu-server/402.conf
new file mode 100644
index 00000000..976c0a39
--- /dev/null
+++ b/src/test/snapshot-expected/create/qemu-server/402.conf
@@ -0,0 +1,31 @@
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+memory: 8192
+meta: creation-qemu=8.0.2,ctime=1600000000,rtime=1234567890123,uid=qrstuvwxyzbcdefghijk
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+parent: test
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+sockets: 1
+vga: qxl
+
+[test]
+#test comment
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+memory: 8192
+meta: creation-qemu=8.0.2,ctime=1600000000
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+snaptime: 1234567890
+sockets: 1
+vga: qxl
diff --git a/src/test/snapshot-expected/rollback/qemu-server/401.conf b/src/test/snapshot-expected/rollback/qemu-server/401.conf
new file mode 100644
index 00000000..6215ce26
--- /dev/null
+++ b/src/test/snapshot-expected/rollback/qemu-server/401.conf
@@ -0,0 +1,36 @@
+# this is a description
+agent: 1
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+memory: 8192
+meta: creation-qemu=9.2.0,ctime=1600000000,rtime=1700000000000,uid=abcdefghijklmnopqrst
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+parent: test
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+sockets: 1
+vga: qxl
+
+[test]
+#test comment
+agent: 1
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+machine: q35
+memory: 8192
+meta: creation-qemu=9.2.0,ctime=1600000000,rtime=1600000000000,uid=bbbbbbbbbbbbbbbbbbbb
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+snaptime: 1234567890
+sockets: 1
+vga: qxl
+vmstate: somestorage:state-volume
diff --git a/src/test/snapshot-expected/rollback/qemu-server/402.conf b/src/test/snapshot-expected/rollback/qemu-server/402.conf
new file mode 100644
index 00000000..a10bfa13
--- /dev/null
+++ b/src/test/snapshot-expected/rollback/qemu-server/402.conf
@@ -0,0 +1,35 @@
+# this is a description
+agent: 1
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+memory: 8192
+meta: rtime=1700000000000,uid=abcdefghijklmnopqrst
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+parent: test
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+sockets: 1
+vga: qxl
+
+[test]
+#test comment
+agent: 1
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+machine: q35
+memory: 8192
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+snaptime: 1234567890
+sockets: 1
+vga: qxl
+vmstate: somestorage:state-volume
diff --git a/src/test/snapshot-input/create/qemu-server/401.conf b/src/test/snapshot-input/create/qemu-server/401.conf
new file mode 100644
index 00000000..41ccdae5
--- /dev/null
+++ b/src/test/snapshot-input/create/qemu-server/401.conf
@@ -0,0 +1,13 @@
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+memory: 8192
+meta: creation-qemu=10.0.0,ctime=1700000000,rtime=1700000000000,uid=abcdefghijklmnopqrst
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+sockets: 1
+vga: qxl
diff --git a/src/test/snapshot-input/create/qemu-server/402.conf b/src/test/snapshot-input/create/qemu-server/402.conf
new file mode 100644
index 00000000..e03717b6
--- /dev/null
+++ b/src/test/snapshot-input/create/qemu-server/402.conf
@@ -0,0 +1,13 @@
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+memory: 8192
+meta: creation-qemu=8.0.2,ctime=1600000000
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+sockets: 1
+vga: qxl
diff --git a/src/test/snapshot-input/rollback/qemu-server/401.conf b/src/test/snapshot-input/rollback/qemu-server/401.conf
new file mode 100644
index 00000000..7895e0df
--- /dev/null
+++ b/src/test/snapshot-input/rollback/qemu-server/401.conf
@@ -0,0 +1,35 @@
+# this is a description
+agent: 1
+bootdisk: ide2
+cores: 2
+ide0: local:snapshotable-disk-1,size=32G
+ide2: none,media=cdrom
+memory: 4096
+meta: creation-qemu=10.0.0,ctime=1700000000,rtime=1700000000000,uid=abcdefghijklmnopqrst
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+parent: test
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+sockets: 2
+
+[test]
+#test comment
+agent: 1
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+machine: q35
+memory: 8192
+meta: creation-qemu=9.2.0,ctime=1600000000,rtime=1600000000000,uid=bbbbbbbbbbbbbbbbbbbb
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+snaptime: 1234567890
+sockets: 1
+vga: qxl
+vmstate: somestorage:state-volume
diff --git a/src/test/snapshot-input/rollback/qemu-server/402.conf b/src/test/snapshot-input/rollback/qemu-server/402.conf
new file mode 100644
index 00000000..0fa7fe51
--- /dev/null
+++ b/src/test/snapshot-input/rollback/qemu-server/402.conf
@@ -0,0 +1,34 @@
+# this is a description
+agent: 1
+bootdisk: ide2
+cores: 2
+ide0: local:snapshotable-disk-1,size=32G
+ide2: none,media=cdrom
+memory: 4096
+meta: creation-qemu=10.0.0,ctime=1700000000,rtime=1700000000000,uid=abcdefghijklmnopqrst
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+parent: test
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+sockets: 2
+
+[test]
+#test comment
+agent: 1
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+machine: q35
+memory: 8192
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+snaptime: 1234567890
+sockets: 1
+vga: qxl
+vmstate: somestorage:state-volume
diff --git a/src/test/snapshot-test.pm b/src/test/snapshot-test.pm
index b5269538..4e7fccdb 100644
--- a/src/test/snapshot-test.pm
+++ b/src/test/snapshot-test.pm
@@ -7,6 +7,7 @@ use lib qw(..);
 
 use JSON;
 
+use PVE::GuestHelpers;
 use PVE::Storage;
 use PVE::Storage::Plugin;
 use PVE::QemuServer;
@@ -33,6 +34,9 @@ my $stop_possible;
 my $save_vmstate_works;
 my $vm_mon = {};
 my $vm_start_sync_time;
+my $real_write_config;
+
+my $original_write_config = \&PVE::QemuConfig::write_config;
 
 # Mocked methods
 
@@ -312,6 +316,13 @@ sub cfs_config_path {
     return "snapshot-working/$node/qemu-server/$vmid.conf";
 }
 
+# the same file that mocked_get_config reads, so that nothing looks at the host's /etc/pve
+sub config_file {
+    my ($class, $vmid, $node) = @_;
+
+    return $class->cfs_config_path($vmid, $node);
+}
+
 sub load_config {
     my ($class, $vmid, $node) = @_;
 
@@ -326,18 +337,10 @@ sub load_config {
 sub write_config {
     my ($class, $vmid, $conf) = @_;
 
-    my $filename = $class->cfs_config_path($vmid);
-
-    if ($conf->{snapshots}) {
-        foreach my $snapname (keys %{ $conf->{snapshots} }) {
-            $conf->{snapshots}->{$snapname}->{snaptime} = "1234567890"
-                if $conf->{snapshots}->{$snapname}->{snaptime};
-        }
-    }
+    # the real method with the guest identity handling, which writes through mocked_cfs_write_file
+    return $original_write_config->($class, $vmid, $conf) if $real_write_config;
 
-    my $raw = PVE::QemuServer::write_vm_config($filename, $conf);
-
-    PVE::Tools::file_set_contents($filename, $raw);
+    mocked_cfs_write_file($class->cfs_config_path($vmid), $conf);
 }
 
 sub has_feature {
@@ -361,6 +364,31 @@ sub assert_config_exists_on_node {
 }
 # END mocked PVE::QemuConfig methods
 
+# BEGIN mocked PVE::Cluster methods
+
+sub mocked_get_config {
+    my ($path) = @_;
+
+    return -e $path ? PVE::Tools::file_get_contents($path) : undef;
+}
+
+sub mocked_cfs_write_file {
+    my ($filename, $conf) = @_;
+
+    if ($conf->{snapshots}) {
+        foreach my $snapname (keys %{ $conf->{snapshots} }) {
+            $conf->{snapshots}->{$snapname}->{snaptime} = "1234567890"
+                if $conf->{snapshots}->{$snapname}->{snaptime};
+        }
+    }
+
+    my $raw = PVE::QemuServer::write_vm_config($filename, $conf);
+
+    PVE::Tools::file_set_contents($filename, $raw);
+}
+
+# END mocked PVE::Cluster methods
+
 # BEGIN mocked PVE::QemuServer::Helpers methods
 
 sub vm_running_locally {
@@ -477,6 +505,16 @@ sub vm_stop {
 PVE::Tools::run_command("rm -rf snapshot-working");
 PVE::Tools::run_command("cp -a snapshot-input snapshot-working");
 
+$PVE::GuestHelpers::lockdir = "snapshot-working/lock";
+
+my $cluster_module = Test::MockModule->new('PVE::Cluster');
+$cluster_module->mock('get_config', \&mocked_get_config);
+$cluster_module->mock('cfs_write_file', \&mocked_cfs_write_file);
+
+my $guest_identity_module = Test::MockModule->new('PVE::GuestIdentity');
+$guest_identity_module->mock('__random_bytes', sub { return '0123456789abcdefghij'; });
+$guest_identity_module->mock('__time_ms', sub { return 1234567890123; });
+
 my $qemu_migrate_helpers_module = Test::MockModule->new('PVE::QemuMigrate::Helpers');
 $qemu_migrate_helpers_module->mock('set_migration_caps', \&set_migration_caps);
 
@@ -489,6 +527,7 @@ $qemu_monitor_module->mock('qmp_cmd', \&qmp_cmd);
 my $qemu_config_module = Test::MockModule->new('PVE::QemuConfig');
 $qemu_config_module->mock('config_file_lock', \&config_file_lock);
 $qemu_config_module->mock('cfs_config_path', \&cfs_config_path);
+$qemu_config_module->mock('config_file', \&config_file);
 $qemu_config_module->mock('load_config', \&load_config);
 $qemu_config_module->mock('write_config', \&write_config);
 $qemu_config_module->mock('has_feature', \&has_feature);
@@ -694,6 +733,16 @@ testcase_create("303", "test", 1, "test comment", "storage activation failed\n\n
 
 $activate_storage_possible = 1;
 
+$real_write_config = 1;
+
+printf("Successful snapshot_create keeping the guest identity\n");
+testcase_create("401", "test", 0, "test comment", "", { "local:snapshotable-disk-1" => "test" });
+
+printf("Successful snapshot_create assigning a guest identity to a config without one\n");
+testcase_create("402", "test", 0, "test comment", "", { "local:snapshotable-disk-1" => "test" });
+
+$real_write_config = 0;
+
 $nodename = "delete";
 printf("\n");
 printf("Running delete tests\n");
@@ -845,6 +894,17 @@ testcase_rollback("303", "test", "storage activation failed\n");
 
 $activate_storage_possible = 1;
 
+$real_write_config = 1;
+
+printf("Successful snapshot_rollback keeping the current guest identity, not the snapshot's\n");
+testcase_rollback("401", "test", "", { "local:snapshotable-disk-1" => "test" });
+
+printf(
+    "Successful snapshot_rollback to a snapshot without meta info, keeping the guest identity\n");
+testcase_rollback("402", "test", "", { "local:snapshotable-disk-1" => "test" });
+
+$real_write_config = 0;
+
 done_testing();
 
 1;
-- 
2.47.3





^ permalink raw reply related	[relevance 16%]

* [PATCH docs v5 37/41] vzdump: describe the guest identity of VMs and containers
  2026-11-19 19:18 17% [PATCH cluster/guest-common/qemu-server/container/manager/docs v5 " Thomas Lamprecht
  2026-11-19 19:18 22% ` [PATCH guest-common v5 08/41] guest identity: add helpers for the guest uid and registration time Thomas Lamprecht
  2026-11-19 19:18 16% ` [PATCH qemu-server v5 16/41] fix #7846: config: add a guest identity to the 'meta' property Thomas Lamprecht
@ 2026-11-19 19:19 17% ` Thomas Lamprecht
  2026-11-20  3:07 21% ` [PATCH cluster/guest-common/qemu-server/container/manager/docs v5 00/41] fix #7846: guest identity (uid) and cluster ID Thomas Lamprecht
  3 siblings, 0 replies; 32+ results
From: Thomas Lamprecht @ 2026-11-19 19:19 UTC (permalink / raw)
  To: pve-devel

Since Proxmox VE 9.3, VMs and containers have a guest identity in
'meta': a random uid and a registration time. Backup software and other
tools can distinguish a guest from another that reuses its VMID [0].

Administrators need to understand why restores over a different guest
are refused, when a restore keeps the uid of the backup, and why
migrations and clones to older nodes are blocked. Those nodes drop
'meta', including VM creation information used for hardware defaults.

Document the lifecycle, failed-restore retries, and mixed-version
restrictions in the backup and restore chapter, where users are most
likely to encounter the identity. Include migration and HA behavior
there so the rules can be read together.

[0]: https://bugzilla.proxmox.com/show_bug.cgi?id=7846

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Reviewed-by: Dominik Csapak <d.csapak@proxmox.com>
Tested-by: Dominik Csapak <d.csapak@proxmox.com>
---

changes v4 -> v5:
* 'adopt' instead of 'take over' for the uid, as in the task logs

changes v3 -> v4:
* the part of 'Failed Restores' about locks and leftovers moved to a
  patch of its own before this one, what stays is 'Retrying a Failed
  Restore'
* lifecycle table and restore section: a guest with a uid keeps it,
  except in the retry of a failed restore of that backup
* drop the sentence that a retry from standard input needs the override,
  which only holds for containers
* the resource API has uid and rtime only for guests with an identity
* remote migration: remove the guest that holds the uid only if it is
  not needed anymore; the refusal of older targets is described there
  instead of with the mixed versions
* shorter descriptions of uid and rtime, one note with the hints for
  tools, and the reason for the refusals first in the mixed versions
  section

changes v2 -> v3:
* backups are still grouped by type and VMID, also for retention
* refused remote migration: do not remove the reported guest if it is
  the source itself
* own section for failed restores, with what a killed or late-failing
  restore leaves behind
* remote migration of a guest without uid, HA recovery through the node
  of the active CRM, and smaller corrections (the uid gets compared, not
  the identity)

changes v1 -> v2:
* say that the uid has 100 random bits and how rtime differs from ctime
* describe the refusal of a migration to another cluster, its typical
  cases and 'allow-new-uid'
* retry after a failed restore: scope the pending entry, name the
  warning, correct the placeholder case and add the note for enforced
  unique guest IDs

 vzdump.adoc | 312 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 312 insertions(+)

diff --git a/vzdump.adoc b/vzdump.adoc
index 84b388c..cad87dd 100644
--- a/vzdump.adoc
+++ b/vzdump.adoc
@@ -464,6 +464,13 @@ following CLI tools:
 
 For details see the corresponding manual pages.
 
+When you restore a backup over an existing guest, {pve} compares the `uid` of
+the backup and of the guest. If they differ, the restore is refused, unless you
+set the `allow-identity-mismatch` option. The existing guest then keeps its
+identity. See
+xref:guest_identity_restore[Restore Over an Existing Guest] for details and
+exceptions.
+
 Bandwidth Limit
 ~~~~~~~~~~~~~~~
 
@@ -596,6 +603,311 @@ To clean up and retry:
   if the xref:pvecm_next_id_range[`next-id`] setting of the datacenter has the
   `unique` and `enforce` options set, as the first VMID then counts as used.
 
+For how a retry handles the guest identity, see
+xref:guest_identity_failed_restore[Retrying a Failed Restore].
+
+[[guest_identity]]
+Guest Identity
+--------------
+
+Since {pve} 9.3, each virtual machine and container gets a guest identity: a
+random identifier, `uid`, and a registration time, `rtime`. Unlike a VMID,
+which can be reused after a guest is destroyed, the `uid` lets backup software
+and other tools recognize the same logical guest across restores and
+migrations, even under a different VMID.
+
+Backups are still grouped by guest type and VMID, also for retention. If a new
+guest reuses the VMID of a removed guest of the same type, pruning handles the
+backups of both guests together.
+
+[[guest_identity_values]]
+Identity Values
+~~~~~~~~~~~~~~~
+
+The guest identity is part of the `meta` property in the guest configuration.
+This property also contains the creation time `ctime` and, for VMs, the QEMU
+version that the VM was created with, `creation-qemu`:
+
+----
+meta: creation-qemu=10.1.2,ctime=1772444467,rtime=1794320571482,uid=w5qczgiem26qnwzwsoil
+----
+
+`uid`::
+
+A random identifier of 20 lowercase letters and digits that encode 100 random
+bits, so two guests practically never get the same `uid` by chance.
+
+`rtime`::
+
+The time at which the guest was registered in this cluster, in milliseconds
+since the UNIX epoch. It is set whenever the guest gets its `uid` in this
+cluster, so a guest restored to a free VMID gets a new `rtime`, even if it keeps
+the `uid` of the backup. The creation time `ctime`, in contrast, stays with the
+guest: a clone has the `ctime` of its source, and a restored guest or a guest
+migrated from another cluster has that of the backup or of the source guest. As
+a timestamp, the `rtime` is not guaranteed to be unique.
+
+{pve} manages the `meta` property automatically. It is read-only through the
+API, even for `root@pam`.
+
+IMPORTANT: The `uid` helps to correlate a guest with its backups and copies,
+but does not prove where a guest comes from. Whoever restores a backup or
+migrates a guest into the cluster supplies the `uid` of that guest, which {pve}
+adopts if no other guest in the cluster has it. {pve} keeps a `uid` unique
+within a cluster only for operations through its API. A configuration file
+copied by hand has the same `uid` as the original, and guests in different
+clusters can have the same `uid`.
+
+[[guest_identity_read]]
+Reading the Identity
+~~~~~~~~~~~~~~~~~~~~
+
+The following places show the guest identity. All of them require the
+`VM.Audit` privilege on the guest.
+
+* In the web interface, the 'Summary' panel of the guest shows the `uid` as
+  'Unique ID'. The 'Details' button next to it, which has an info icon, opens
+  the 'Guest Identity' window. This window additionally shows the `rtime` as
+  'Registered' and the creation information.
+* The guest configuration, for example with `qm config <vmid>` or
+  `pct config <vmid>`, and through the API paths
+  `/nodes/<node>/qemu/<vmid>/config` and `/nodes/<node>/lxc/<vmid>/config`.
+* The guest status at the API paths `/nodes/<node>/qemu/<vmid>/status/current`
+  and `/nodes/<node>/lxc/<vmid>/status/current`, which contains the `uid`.
+* The cluster resources at the API path `/cluster/resources`, which contain the
+  `uid` and `rtime` of each guest that has a guest identity, for example:
++
+----
+# pvesh get /cluster/resources --type vm --output-format json-pretty
+----
+
+The configuration in a backup contains the `meta` property as well. You can
+show it with `pvesm extractconfig <volume>`, for example.
+
+[[guest_identity_lifecycle]]
+Lifecycle
+~~~~~~~~~
+
+The following table shows how operations affect the identity of a guest.
+
+[width="100%",cols="3,4,2",options="header"]
+|===========================================================================
+|Operation |`uid` |`rtime`
+|Create, including import |new |current time
+|Clone, including linked clones and clones from snapshots |new |current time
+|Restore to a free VMID |the backup's `uid` if present and not used by another
+guest in the cluster; otherwise new |current time
+|Restore to a free VMID with `unique` set |new |current time
+|Restore over an existing guest that has a `uid`, with or without `unique` set
+|kept, see xref:guest_identity_restore[Restore Over an Existing Guest]; the
+retry of a failed restore can adopt the backup's `uid` instead, see
+xref:guest_identity_failed_restore[Retrying a Failed Restore] |kept; current
+time if the retry adopts the `uid`
+|Restore over an existing guest without a `uid` |as for a free VMID |current
+time
+|Migration to another cluster, on the target |the source guest's `uid`; new if
+another guest in the target cluster has it and `allow-new-uid` is set, or if the
+source node runs a {pve} version older than 9.3, see
+xref:guest_identity_remote_migration[Migration to Another Cluster] |current time
+|Migration to another cluster, on the source if the guest is kept |kept |kept
+|Snapshot rollback |kept, not taken from the snapshot |kept
+|Migration within the cluster, HA recovery, configuration change, backup,
+replication, conversion to a template |kept |kept
+|Destroy |removed |removed
+|===========================================================================
+
+Restores and migrations from another cluster report the outcome in their task
+log, in a line with `guest identity:`, for example:
+
+----
+guest identity: backup uid w5qczgiem26qnwzwsoil is in use by guest 100, keeping uid er3n3wqoqgcl362ep3da
+----
+
+Guests that existed before the upgrade to {pve} 9.3 get their identity the
+first time a node running {pve} 9.3 or later writes their configuration. This
+happens, for example, when their configuration changes, when they are backed
+up, or when they are migrated to such a node. Their `rtime` is the time of that
+write. Backups made before that have no `uid`.
+
+NOTE: For tools that track guests by their `uid`: a restore that adopts the
+`uid` of the backup first assigns a new `uid` to the guest and replaces it at
+its end, which can be after the guest got unlocked. A migration from another
+cluster adopts the `uid` of the source guest right at its start. A changed
+`uid`, for example in `/cluster/resources`, therefore does not mean that the
+task has finished. A guest that a tool restores by removing it and creating a
+new one through the API gets a new `uid`. To keep the identity, change the
+existing guest in place, or let {pve} restore the guest.
+
+[[guest_identity_restore]]
+Restore Over an Existing Guest
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+If the existing guest already has a guest identity, restoring a backup over it
+keeps the `uid` and `rtime` of that guest, unless the guest is left over from a
+failed restore of that backup, see
+xref:guest_identity_failed_restore[Retrying a Failed Restore]. When both the
+guest and the backup have a `uid` and the values differ, {pve} treats the backup
+as belonging to another guest. This can happen when a VMID was reused. {pve}
+refuses such a restore before it overwrites the guest:
+
+----
+backup belongs to another guest: its uid 'w5qczgiem26qnwzwsoil' differs from uid 'er3n3wqoqgcl362ep3da' of the existing VM 100 - use 'allow-identity-mismatch' to overwrite the VM anyway
+----
+
+To restore such a backup anyway, set the `allow-identity-mismatch` option. The
+existing guest then keeps its identity. In the web interface, select 'Allow
+restoring a backup of another guest' in the restore window, which you open from
+the 'Backup' panel of the guest. On the command line, use for example:
+
+----
+# qmrestore <archive> <vmid> --force 1 --allow-identity-mismatch 1
+# pct restore <vmid> <archive> --force 1 --allow-identity-mismatch 1
+----
+
+Backups without a `uid`, such as backups made with {pve} versions older than
+9.3, are not refused. Container restores from standard input
+(`pct restore <vmid> -`) are an exception: the `uid` of such a backup is only
+known once the container has been overwritten. A restore from standard input
+over a container with a `uid` therefore always requires
+`allow-identity-mismatch`.
+
+[[guest_identity_failed_restore]]
+Retrying a Failed Restore
+~~~~~~~~~~~~~~~~~~~~~~~~~
+
+For locks and leftovers of a failed restore, see
+xref:vzdump_restore_failed[Failed Restores].
+
+If the failed restore was to a free VMID or over a guest without a `uid`, and it
+had already read a backup that has a `uid`, `qm pending <vmid>` or
+`pct pending <vmid>` lists an entry for `meta` with the `uid` of the backup. As
+long as this entry exists, retrying the same restore over the guest left behind
+is accepted. Starting the guest or changing its options removes the entry and
+logs a warning that names the `uid`. The retry is then refused like a restore of
+another guest's backup.
+
+A successful retry adopts the `uid` of the backup and sets a new `rtime`, as
+a restore to a free VMID does. The guest keeps its `uid` and `rtime` instead if
+another guest in the cluster has the `uid` of the backup, or if the retry sets
+`unique`.
+
+A guest that had a `uid` and no such entry before the failed restore keeps its
+`uid` and gets no entry. A retry is checked like the first attempt: a backup
+with the same `uid` is accepted, also after the guest was started or changed,
+and a backup with another `uid` requires `allow-identity-mismatch`.
+
+If a restore over an existing guest without a `uid` stopped before it read the
+backup, for example because the backup storage was unreachable, the guest now
+has a new `uid`. Retry with `allow-identity-mismatch`. The guest then keeps the
+new `uid`.
+
+A restore can also complete with a warning starting with
+`guest identity: unable to adopt backup uid`, for example if the cluster-wide
+lock for this step could not be taken in time. The guest is then restored
+completely, but keeps its new `uid`. To adopt the `uid` of the backup,
+repeat the restore over the guest before you start it or change its
+configuration.
+
+[[guest_identity_remote_migration]]
+Migration to Another Cluster
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+A migration to another cluster (`qm remote-migrate`, `pct remote-migrate`) keeps
+the `uid` of the guest. The target adopts it at the start of the migration,
+before any data is transferred.
+
+If another guest in the target cluster already has that `uid`, the migration is
+refused at that point. Typical cases are:
+
+* the guest gets migrated back to a cluster that still has the source guest of
+  an earlier migration, which stays there unless `delete` was set,
+* a copy of the guest was restored in the target cluster from a backup,
+* an earlier migration of the guest broke off after it had transferred the
+  configuration and left a locked guest in the target cluster,
+* the target is the cluster that the guest is in.
+
+The error ends with:
+
+----
+guest 105 in the target cluster already has the uid 'w5qczgiem26qnwzwsoil' of this guest - use 'allow-new-uid' to migrate it with a new uid
+----
+
+If the reported guest is the source guest itself, do not remove it. To keep the
+`uid`, migrate the guest within the cluster instead, with `qm migrate` or
+`pct migrate`.
+
+Otherwise, to keep the `uid`, remove the other guest in the target cluster if
+you no longer need it, and migrate again. To migrate anyway, set the
+`allow-new-uid` option. The migrated guest then gets a new `uid`, and the other
+guest keeps the old one. In both cases, use another target VMID if the
+xref:pvecm_next_id_range[`next-id`] setting of the target cluster has the
+`unique` and `enforce` options set, as the refused migration already used the
+first one. For example:
+
+----
+# qm remote-migrate <vmid> <target-vmid> <target-endpoint> --target-bridge <bridge> --target-storage <storage> --allow-new-uid 1
+----
+
+A migration to another cluster is refused right after connecting to a target
+node with a version older than 9.3, before any data is transferred. The error is
+`Remote tunnel endpoint too old, upgrade required`.
+
+[[guest_identity_mixed_versions]]
+Mixed Versions in a Cluster
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+{pve} versions older than 9.3 ignore the whole `meta` property of a guest that
+has a guest identity, including the creation information. A VM started on a node
+running such a version can therefore get different virtual hardware, see
+xref:qm_machine_type[Machine Type]. When such a node writes the configuration,
+the property is lost.
+
+Therefore, while some nodes of a cluster still run such a version, migrating or
+cloning a guest to one of these nodes is refused. The guest keeps running on its
+current node. If the target node reports its version, the error message shows
+that version and the minimum required version. If the node does not report its
+version, the operation is refused because {pve} cannot verify that the node
+supports guest identities. The 'Migrate' window of the web interface shows the
+reason for the selected target node.
+
+Moves of HA-managed guests to such nodes are refused in the same way. A running
+VM that the HA stack migrates keeps running. The HA stack stops a container, and
+a VM that it relocates, before it migrates the guest, so such a guest is stopped
+although the move is then refused. The HA stack retries automatic moves as long
+as it selects such a node, and such a guest can stay stopped in the meantime.
+This includes moves for:
+
+* the maintenance mode,
+* a node shutdown with the `migrate` shutdown policy,
+* node affinity rules,
+* the CRS load balancer.
+
+Such moves complete only after the target nodes that the HA stack selects run
+{pve} 9.3 or later.
+
+To avoid refused moves while you upgrade a cluster, do one of the following:
+
+* Move all guests away from a node before you upgrade it.
+* Upgrade the packages on all nodes, one node at a time, before you reboot any
+  node or enable the maintenance mode.
+
+The check covers migrations and clones started on a node running {pve} 9.3 or
+later. It does not cover:
+
+* the HA recovery of guests from a fenced node,
+* configuration files moved by hand,
+* operations started on a node with an older version.
+
+If an older node writes the configuration of a guest in one of these cases, the
+guest loses its `meta` property. In an HA recovery, such a node can also be the
+node of the active HA manager (CRM), which writes the configuration when it
+removes a leftover lock, for example of a backup. The guest gets a new identity
+the next time a node running {pve} 9.3 or later writes its configuration.
+
+Backups made with {pve} 9.3 or later contain the guest identity. Restore them
+only on nodes running {pve} 9.3 or later, because older versions ignore the
+`meta` property of such backups in the same way.
+
 [[vzdump_configuration]]
 Configuration
 -------------
-- 
2.47.3





^ permalink raw reply related	[relevance 17%]

* [PATCH guest-common v5 08/41] guest identity: add helpers for the guest uid and registration time
  2026-11-19 19:18 17% [PATCH cluster/guest-common/qemu-server/container/manager/docs v5 " Thomas Lamprecht
@ 2026-11-19 19:18 22% ` Thomas Lamprecht
  2026-11-19 19:18 16% ` [PATCH qemu-server v5 16/41] fix #7846: config: add a guest identity to the 'meta' property Thomas Lamprecht
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 32+ results
From: Thomas Lamprecht @ 2026-11-19 19:18 UTC (permalink / raw)
  To: pve-devel

A VMID can be reused, and a guest can get a different VMID or move
to another cluster after a restore or remote migration. External tools
such as backup products need to recognize the same logical guest
independently of its VMID, as described in bug #7846.

Provide shared helpers for a random uid of 20 characters from the
lowercase base32 alphabet, which is 100 random bits, and a registration
time in milliseconds. Both are members of the guest config's 'meta'
property. Supply format definitions for both guest types and extract or
merge the identity without requiring knowledge of other members,
including newer ones. Also read it from a raw config, as the parser of a
guest type can drop a 'meta' property with members it does not know.

100 bits make a duplicate practically impossible, and the uid still fits
into a 128-bit value with 28 bits to spare, for example for a format
version and extra data, should a later format need them. Base32 keeps it
at 20 characters, about half the width of a UUID in its usual notation,
and only uses lowercase letters and digits. Each character comes from a
random byte of its own, so no encoder is needed.

The registration time is the time a guest got its uid in this cluster.
Unlike the creation time, which a clone, a restore and a migration from
another cluster copy along with the guest, it changes when a guest is
registered again, for example by a restore to a free VMID. Tools can use
it to tell such a guest from the one they knew, also if both have the
same uid.

Also provide a minimum node-version check for migration targets. Older
versions drop the identity on config writes. Report the required and
available versions so callers can explain a refusal, with a shared
schema for API results; missing version information counts as too old.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Reviewed-by: Dominik Csapak <d.csapak@proxmox.com>
Tested-by: Dominik Csapak <d.csapak@proxmox.com>
---

changes v4 -> v5:
* the description of 'uid' and a comment no longer say 'lineage', which
  suggested that clones share the uid

changes v3 -> v4:
* the stand-in MIN_PVE_MANAGER_VERSION is 9.2.33, as 9.2.31 and 9.2.32
  got released without this series
* tests: control and replacement characters in 'meta', moved here from
  the resource API test of pve-manager
* rebase (test Makefile), and 'adopt' instead of 'take over' in a
  comment

changes v2 -> v3:
* shorter description of the uid, which the status and resource APIs
  show too
* reword the comment about the size and the commit message about rtime:
  an in-place restore keeps the rtime

changes v1 -> v2:
* use v5.36 and signatures
* take each character of the uid from a random byte of its own, without
  an encoder (Dominik)
* add a helper to read the identity from a raw config, shared by the
  config write and the VM restore, which picks the 'meta' line like
  pmxcfs does
* add the schema of the migration precondition result, shared by both
  guest types
* explain the format, the difference between rtime and ctime, and why
  the generic property string helpers are not used (Dominik)
* shorter description of the uid

Note: MIN_PVE_MANAGER_VERSION (9.2.33) is a stand-in. It has to become
the first pve-manager version that depends on the qemu-server and
pve-container versions with this series, see the cover letter.

 src/Makefile                      |   1 +
 src/PVE/GuestIdentity.pm          | 232 ++++++++++++++++++++
 src/tests/Makefile                |   7 +-
 src/tests/guest-identity-tests.pl | 346 ++++++++++++++++++++++++++++++
 4 files changed, 584 insertions(+), 2 deletions(-)
 create mode 100644 src/PVE/GuestIdentity.pm
 create mode 100755 src/tests/guest-identity-tests.pl

diff --git a/src/Makefile b/src/Makefile
index 161dbe5..af4c277 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -10,6 +10,7 @@ install: PVE
 	install -m 0644 PVE/AbstractMigrate.pm ${PERL5DIR}/PVE/
 	install -m 0644 PVE/GuestHelpers.pm ${PERL5DIR}/PVE/
 	install -m 0644 PVE/GuestID.pm ${PERL5DIR}/PVE/
+	install -m 0644 PVE/GuestIdentity.pm ${PERL5DIR}/PVE/
 	install -m 0644 PVE/Replication.pm ${PERL5DIR}/PVE/
 	install -m 0644 PVE/ReplicationConfig.pm ${PERL5DIR}/PVE/
 	install -m 0644 PVE/ReplicationState.pm ${PERL5DIR}/PVE/
diff --git a/src/PVE/GuestIdentity.pm b/src/PVE/GuestIdentity.pm
new file mode 100644
index 0000000..01102ea
--- /dev/null
+++ b/src/PVE/GuestIdentity.pm
@@ -0,0 +1,232 @@
+package PVE::GuestIdentity;
+
+use v5.36;
+
+use Time::HiRes;
+
+use PVE::Cluster;
+
+# The identity of a guest, VM or container alike, consists of two members of the 'meta' property
+# string in the top-level section of its config: 'uid', a random identifier of the guest (100 bits
+# as 20 characters of the lowercase RFC 4648 base32 alphabet), and 'rtime', the time the config was
+# registered in this cluster (milliseconds since the epoch). The functions here pass it as a hash
+# with these two keys.
+#
+# 100 random bits make a duplicate uid practically impossible: a billion uids contain one with a
+# probability of about 4 * 10^-13. They also leave 28 bits of a 128-bit value free, for example for
+# a format version and extra data, should a later format need them. Base32 keeps the uid at 20
+# characters, about half the width of a UUID in its usual notation, and only uses lowercase letters
+# and digits, which need no quoting in a property string.
+#
+# Unlike the creation time 'ctime' of the same property, which a clone, a restore and a migration
+# from another cluster copy along with the guest, the rtime belongs to the uid of the guest in this
+# cluster: it is the time the guest got its uid here, be it a new one or one it adopted. So a
+# changed rtime tells that a guest was registered again, even if its uid is the same as before.
+
+# Must match the first pve-manager release that depends on the qemu-server and pve-container
+# versions handling the identity. Older nodes drop the whole 'meta' property on their next write
+# of a guest config.
+use constant MIN_PVE_MANAGER_VERSION => '9.2.33';
+
+my $UID_LENGTH = 20;
+my $UID_ALPHABET = 'abcdefghijklmnopqrstuvwxyz234567';
+my $UID_PATTERN = "[a-z2-7]{$UID_LENGTH}";
+
+# 15 digits of milliseconds last until the year 33658
+my $RTIME_MAX = 999_999_999_999_999;
+
+# Returns $len random bytes from the kernel's random number generator.
+sub __random_bytes($len) {
+    open(my $fh, '<', '/dev/urandom') or die "unable to open /dev/urandom - $!\n";
+    my $buf = '';
+    my $read = sysread($fh, $buf, $len);
+    die "unable to read from /dev/urandom - $!\n" if !defined($read);
+    die "short read from /dev/urandom\n" if $read != $len;
+    close($fh);
+
+    return $buf;
+}
+
+# Returns the current time in milliseconds since the epoch.
+sub __time_ms() {
+    my ($sec, $usec) = Time::HiRes::gettimeofday();
+
+    return $sec * 1000 + int($usec / 1000);
+}
+
+# Returns a random uid. Each character comes from the lowest 5 bits of a random byte of its own, so
+# it is uniformly distributed over the alphabet.
+my sub random_uid() {
+    my $bytes = __random_bytes($UID_LENGTH);
+
+    return join('', map { substr($UID_ALPHABET, ord($_) & 31, 1) } split(//, $bytes));
+}
+
+my sub is_valid_uid($uid) {
+    return defined($uid) && $uid =~ m/^$UID_PATTERN\z/;
+}
+
+my sub is_valid_rtime($rtime) {
+    return defined($rtime) && $rtime =~ m/^[0-9]{1,15}\z/;
+}
+
+# Returns the JSON schema properties of the identity members, for merging into the format of the
+# 'meta' property string of a guest type. Every call returns a new copy.
+sub meta_format_properties() {
+    return {
+        uid => {
+            type => 'string',
+            pattern => $UID_PATTERN,
+            description => "Random identifier of the guest, kept across restores and migrations"
+                . " and independent of the VMID.",
+            optional => 1,
+        },
+        rtime => {
+            type => 'integer',
+            minimum => 0,
+            maximum => $RTIME_MAX,
+            description => "Time the guest was registered in this cluster, for example by"
+                . " creation, restore, or migration from another cluster, in milliseconds since"
+                . " the UNIX epoch.",
+            optional => 1,
+        },
+    };
+}
+
+# Returns a new identity with the current time as rtime. Its uid is $uid if given, otherwise a
+# random one.
+sub new_identity($uid = undef) {
+    die "invalid guest identity uid '$uid'\n" if defined($uid) && !is_valid_uid($uid);
+
+    return {
+        uid => $uid // random_uid(),
+        rtime => __time_ms(),
+    };
+}
+
+# Extracts the identity from the 'meta' property string $meta, which may contain any other
+# members, including ones unknown to this version.
+#
+# Returns undef if $meta has no valid uid, and an identity otherwise. Its rtime is undef if the
+# rtime member is missing or invalid. A member given more than once counts as invalid.
+#
+# This does not use PVE::JSONSchema::parse_property_string on purpose. That parser rejects the
+# whole string if one member is unknown or invalid. A guest without a readable identity gets a new
+# one with the next config write, so a problem with another member must not hide the uid.
+sub parse_identity($meta) {
+    return undef if !defined($meta);
+
+    my $values = {};
+    for my $part (split(/,/, $meta)) {
+        my ($key, $value) = $part =~ m/^([^=]+)=(.*)\z/ or next;
+        next if $key ne 'uid' && $key ne 'rtime';
+        $values->{$key} = exists($values->{$key}) ? undef : $value;
+    }
+
+    return undef if !is_valid_uid($values->{uid});
+
+    return {
+        uid => $values->{uid},
+        rtime => is_valid_rtime($values->{rtime}) ? $values->{rtime} : undef,
+    };
+}
+
+# Returns the 'meta' property string $meta, which may be undef, with the identity members set to
+# $identity. All other members are kept as they are, also ones unknown to this version, which
+# PVE::JSONSchema::print_property_string would reject.
+sub merge_identity($meta, $identity) {
+    die "invalid guest identity uid\n" if !is_valid_uid($identity->{uid});
+    die "invalid guest identity rtime\n" if !is_valid_rtime($identity->{rtime});
+
+    my (@plain, @members);
+    for my $part (split(/,/, $meta // '')) {
+        next if $part =~ m/^\s*\z/;
+
+        if (my ($key) = $part =~ m/^([^=]+)=/) {
+            push @members, [$key, $part] if $key ne 'uid' && $key ne 'rtime';
+        } else {
+            push @plain, $part;
+        }
+    }
+    push @members, ['rtime', "rtime=$identity->{rtime}"], ['uid', "uid=$identity->{uid}"];
+
+    # same order as PVE::JSONSchema::print_property_string uses, so that a guest type parsing and
+    # printing the property string again does not change it
+    return join(',', @plain, map { $_->[1] } sort { $a->[0] cmp $b->[0] } @members);
+}
+
+# Returns the identity in the top-level section of the raw guest config $raw, undef if it has none.
+# Only looks at the 'meta' property, so this also finds the identity in a config that the parser of
+# the guest type rejects or reads without 'meta', for example because of members from a newer
+# version.
+#
+# If a manual edit left more than one 'meta' line, the last one with anything after the colon
+# counts, also if that is only whitespace. The property lookup of pmxcfs does the same, and the
+# cluster-wide check of adopt uses it.
+sub parse_identity_from_raw_config($raw) {
+    my $meta;
+    for my $line (split(/\n/, $raw)) {
+        last if $line =~ m/^\[/; # snapshot or other section
+        $meta = $1 =~ s/^\s+|\s+$//gr if $line =~ m/^meta:(.+)$/;
+    }
+
+    return parse_identity($meta);
+}
+
+# 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
+# the node reports, if any.
+sub node_identity_unsupported($node) {
+    my $required = MIN_PVE_MANAGER_VERSION;
+    my ($major, $minor, $release) = split(/\./, $required);
+
+    my $supported =
+        eval { PVE::Cluster::node_pvecfg_version_at_least($node, $major, $minor, $release) };
+    return undef if $supported;
+
+    my $version = eval { PVE::Cluster::get_node_pvecfg_version($node) };
+
+    return { 'required-version' => $required, defined($version) ? (version => $version) : () };
+}
+
+# Returns the JSON schema of what node_identity_unsupported returns for a refused node, for the
+# result of API calls that report why a node is not allowed as migration target. Every call returns
+# a new copy.
+sub node_identity_unsupported_schema() {
+    return {
+        description =>
+            "Set if migrating to the node is refused because the node does not report a"
+            . " Proxmox VE version that keeps the guest identity.",
+        type => 'object',
+        optional => 1,
+        properties => {
+            version => {
+                description => "The Proxmox VE version the node reports.",
+                type => 'string',
+                optional => 1,
+            },
+            'required-version' => {
+                description => "The minimum Proxmox VE version that keeps the guest identity.",
+                type => 'string',
+            },
+        },
+    };
+}
+
+# Dies unless $node runs a version of Proxmox VE that keeps the identity when writing guest
+# configs, see node_identity_unsupported.
+sub assert_node_supports_identity($node) {
+    my $unsupported = node_identity_unsupported($node) or return;
+    my ($version, $required) = $unsupported->@{qw(version required-version)};
+
+    if (!defined($version)) {
+        die "node '$node' does not report its Proxmox VE version, so it is unknown whether the node"
+            . " keeps the guest identity\n";
+    }
+
+    die "node '$node' runs Proxmox VE $version, keeping the guest identity requires $required or"
+        . " newer - upgrade the node first\n";
+}
+
+1;
diff --git a/src/tests/Makefile b/src/tests/Makefile
index 11820bf..778b296 100644
--- a/src/tests/Makefile
+++ b/src/tests/Makefile
@@ -1,8 +1,8 @@
 
 all:
 
-.PHONY: check abstract-config config-reservation firewall-config guest-id hookscript storage-tunnel
-check: abstract-config config-reservation firewall-config guest-id hookscript storage-tunnel
+.PHONY: check abstract-config config-reservation firewall-config guest-id guest-identity hookscript storage-tunnel
+check: abstract-config config-reservation firewall-config guest-id guest-identity hookscript storage-tunnel
 
 abstract-config: abstract-config-tests.pl
 	perl -I.. ./abstract-config-tests.pl
@@ -16,6 +16,9 @@ firewall-config: firewall-config-tests.pl
 guest-id: guest-id-tests.pl
 	perl -I.. ./guest-id-tests.pl
 
+guest-identity: guest-identity-tests.pl
+	perl -I.. ./guest-identity-tests.pl
+
 hookscript: hookscript-tests.pl
 	perl -I.. ./hookscript-tests.pl
 
diff --git a/src/tests/guest-identity-tests.pl b/src/tests/guest-identity-tests.pl
new file mode 100755
index 0000000..b6a7c85
--- /dev/null
+++ b/src/tests/guest-identity-tests.pl
@@ -0,0 +1,346 @@
+#!/usr/bin/perl
+
+use v5.36;
+
+use lib qw(..);
+
+use Test::MockModule;
+use Test::More;
+use Time::HiRes;
+
+use PVE::JSONSchema;
+use PVE::Tools;
+
+use PVE::GuestIdentity;
+
+subtest 'generation with fixed random bytes and time' => sub {
+    my $random_bytes = [];
+    my $time_ms = 1_700_000_000_123;
+
+    my $identity_module = Test::MockModule->new('PVE::GuestIdentity');
+    $identity_module->redefine(
+        __random_bytes => sub {
+            my ($len) = @_;
+            my $bytes = shift(@$random_bytes) // die "test error: no random bytes left\n";
+            die "test error: requested $len random bytes\n" if length($bytes) != $len;
+            return $bytes;
+        },
+        __time_ms => sub { return $time_ms; },
+    );
+
+    # each byte gives one character, its lowest 5 bits select it from the lowercase RFC 4648 base32
+    # alphabet
+    my $vectors = [
+        ["\x00" x 20, 'a' x 20],
+        ["\xff" x 20, '7' x 20],
+        ['0123456789abcdefghij', 'qrstuvwxyzbcdefghijk'],
+        [pack('C*', 0 .. 19), 'abcdefghijklmnopqrst'],
+        [pack('C*', 12 .. 31), 'mnopqrstuvwxyz234567'],
+        [pack('C*', map { $_ | 0xe0 } 0 .. 19), 'abcdefghijklmnopqrst'],
+    ];
+
+    for my $vector (@$vectors) {
+        my ($bytes, $uid) = @$vector;
+        $random_bytes = [$bytes];
+        is_deeply(
+            PVE::GuestIdentity::new_identity(),
+            { uid => $uid, rtime => $time_ms },
+            "encodes " . unpack('H*', $bytes),
+        );
+    }
+
+    # every symbol is as likely at each position, as each of them comes from 8 of the 256 values of
+    # the byte at that position
+    my $alphabet = 'abcdefghijklmnopqrstuvwxyz234567';
+    my $mismatches = 0;
+    for my $position (0 .. 19) {
+        for my $value (0 .. 255) {
+            my $bytes = "\x00" x 20;
+            substr($bytes, $position, 1) = chr($value);
+            $random_bytes = [$bytes];
+            my $expected = 'a' x 20;
+            substr($expected, $position, 1) = substr($alphabet, $value % 32, 1);
+            $mismatches++ if PVE::GuestIdentity::new_identity()->{uid} ne $expected;
+        }
+    }
+    is($mismatches, 0, 'each character comes from the byte at its position');
+
+    $random_bytes = [];
+    is_deeply(
+        PVE::GuestIdentity::new_identity('gaytemzugu3doobzmfrg'),
+        { uid => 'gaytemzugu3doobzmfrg', rtime => $time_ms },
+        'given uid is used',
+    );
+    eval { PVE::GuestIdentity::new_identity('GAYTEMZUGU3DOOBZMFRG') };
+    like($@, qr/invalid guest identity uid/, 'invalid given uid is rejected');
+};
+
+subtest 'generation' => sub {
+    my $first = PVE::GuestIdentity::new_identity();
+    my $second = PVE::GuestIdentity::new_identity();
+    like($first->{uid}, qr/^[a-z2-7]{20}\z/, 'uid has the expected format');
+    my @uids = map { PVE::GuestIdentity::new_identity()->{uid} } 1 .. 100;
+    is_deeply([grep { !m/^[a-z2-7]{20}\z/ } @uids], [], 'uids have 20 characters, no padding');
+    isnt($first->{uid}, $second->{uid}, 'uids differ');
+
+    my $before = int(Time::HiRes::time() * 1000);
+    my $rtime = PVE::GuestIdentity::new_identity()->{rtime};
+    my $after = int(Time::HiRes::time() * 1000) + 1;
+    like($rtime, qr/^\d+\z/, 'rtime is an integer');
+    ok($rtime >= $before && $rtime <= $after, 'rtime is the current time in milliseconds');
+};
+
+subtest 'format properties' => sub {
+    my $format = {
+        ctime => { type => 'integer', optional => 1 },
+        PVE::GuestIdentity::meta_format_properties()->%*,
+    };
+
+    is_deeply(
+        PVE::JSONSchema::parse_property_string(
+            $format,
+            'ctime=1700000000,rtime=1700000000123,uid=gaytemzugu3doobzmfrg',
+        ),
+        { ctime => 1700000000, rtime => 1700000000123, uid => 'gaytemzugu3doobzmfrg' },
+        'meta string with identity parses with a merged format',
+    );
+
+    for my $invalid (
+        'uid=GAYTEMZUGU3DOOBZMFRG',
+        'uid=gaytemzugu3doobzmfr',
+        'uid=gaytemzugu3doobzmfrga',
+        'uid=gaytemzugu3doobzmfr0',
+        'uid=' . substr('gaytemzugu3doobzmfrg', 0, 16),
+        'rtime=-1',
+        'rtime=1.5',
+        'rtime=1000000000000000',
+    ) {
+        eval { PVE::JSONSchema::parse_property_string($format, $invalid) };
+        ok($@, "format rejects '$invalid'");
+    }
+
+    my $copy = PVE::GuestIdentity::meta_format_properties();
+    $copy->{uid}->{pattern} = '.*';
+    isnt(
+        PVE::GuestIdentity::meta_format_properties()->{uid}->{pattern},
+        '.*',
+        'callers get their own copy',
+    );
+};
+
+subtest 'parse identity' => sub {
+    my $uid = 'gaytemzugu3doobzmfrg';
+    my $tests = [
+        [undef, undef, 'no meta'],
+        ['', undef, 'empty meta'],
+        ['ctime=1700000000', undef, 'meta without identity'],
+        [
+            "creation-qemu=10.1.2,ctime=1700000000,rtime=123,uid=$uid",
+            { uid => $uid, rtime => 123 },
+            'identity next to other members',
+        ],
+        [
+            "future=a b,uid=$uid,other,rtime=0",
+            { uid => $uid, rtime => 0 },
+            'unknown members and odd parts are ignored',
+        ],
+        ["rtime=123,uid=$uid", { uid => $uid, rtime => 123 }, 'identity only'],
+        ["uid=$uid", { uid => $uid, rtime => undef }, 'missing rtime'],
+        ["uid=$uid,rtime=12a", { uid => $uid, rtime => undef }, 'invalid rtime'],
+        ["uid=$uid,rtime=-5", { uid => $uid, rtime => undef }, 'negative rtime'],
+        [
+            "uid=$uid,rtime=999999999999999",
+            { uid => $uid, rtime => 999999999999999 },
+            'maximum rtime',
+        ],
+        ["uid=$uid,rtime=1000000000000000", { uid => $uid, rtime => undef }, 'too large rtime'],
+        [
+            "uid=$uid,rtime=\x{0661}\x{0662}",
+            { uid => $uid, rtime => undef },
+            'non-ASCII digits',
+        ],
+        ["uid=$uid,rtime=1,rtime=2", { uid => $uid, rtime => undef }, 'duplicate rtime'],
+        ['rtime=123', undef, 'rtime without uid'],
+        ["uid=$uid,uid=$uid,rtime=1", undef, 'duplicate uid'],
+        ['uid=GAYTEMZUGU3DOOBZMFRG,rtime=1', undef, 'uppercase uid'],
+        ['uid=gaytemzugu3doobzmfr,rtime=1', undef, 'short uid'],
+        ['uid=gaytemzugu3doobzmfrga,rtime=1', undef, 'long uid'],
+        ['uid=' . substr($uid, 0, 16) . ',rtime=1', undef, '16-character uid'],
+        ['uid=gaytemzugu3doobzmfr1,rtime=1', undef, 'uid outside of the alphabet'],
+        ["uid= $uid,rtime=1", undef, 'uid with whitespace'],
+        # pmxcfs passes control characters on and replaces invalid UTF-8 with U+FFFD
+        ["uid=gaytemzugu\tdoobzmfrg,rtime=1", undef, 'control character in the uid'],
+        ["uid=gaytemzugu\x{FFFD}doobzmfrg,rtime=1", undef, 'replacement character in the uid'],
+        [
+            "ctime=17000\x{1}00000,rtime=1,uid=$uid",
+            { uid => $uid, rtime => 1 },
+            'control character in another member',
+        ],
+    ];
+
+    for my $test (@$tests) {
+        my ($meta, $expected, $name) = @$test;
+        is_deeply(PVE::GuestIdentity::parse_identity($meta), $expected, $name);
+    }
+};
+
+subtest 'parse identity from raw config' => sub {
+    my $uid = 'gaytemzugu3doobzmfrg';
+    my $other = 'aaaqeayeaudaocajbifq';
+    my $identity = { uid => $uid, rtime => 123 };
+    my $tests = [
+        ['', undef, 'empty config'],
+        ["memory: 512\n", undef, 'no meta'],
+        [
+            "memory: 512\nmeta: ctime=1,rtime=123,uid=$uid\ncores: 2\n",
+            $identity,
+            'top-level meta',
+        ],
+        ["meta:   rtime=123,uid=$uid  \n", $identity, 'surrounding whitespace'],
+        ["meta: rtime=1,uid=$other\nmeta: rtime=123,uid=$uid\n", $identity, 'last meta wins'],
+        ["meta: future=a b,rtime=123,uid=$uid\n", $identity, 'unknown members'],
+        ["meta: rtime=123,uid=$uid\nmeta:\n", $identity, 'meta line without value is ignored'],
+        [
+            "meta: rtime=123,uid=$uid\nmeta:   \n", undef, 'meta line with only spaces counts',
+        ],
+        ["#meta: rtime=123,uid=$uid\n", undef, 'description line'],
+        ["memory: 512\n\n[PENDING]\nmeta: uid=$uid\n", undef, 'pending section is ignored'],
+        [
+            "meta: rtime=123,uid=$uid\n\n[snap]\nmeta: rtime=1,uid=$other\n",
+            $identity,
+            'snapshot section is ignored',
+        ],
+    ];
+
+    for my $test (@$tests) {
+        my ($raw, $expected, $name) = @$test;
+        is_deeply(PVE::GuestIdentity::parse_identity_from_raw_config($raw), $expected, $name);
+    }
+};
+
+subtest 'merge identity' => sub {
+    my $identity = { uid => 'gaytemzugu3doobzmfrg', rtime => 1700000000123 };
+    my $members = 'rtime=1700000000123,uid=gaytemzugu3doobzmfrg';
+    my $tests = [
+        [undef, $members, 'no meta'],
+        ['', $members, 'empty meta'],
+        [
+            'creation-qemu=10.1.2,ctime=1700000000',
+            "creation-qemu=10.1.2,ctime=1700000000,$members",
+            'other members are kept',
+        ],
+        [
+            'ctime=1,rtime=5,uid=aaaaaaaaaaaaaaaaaaaa',
+            "ctime=1,$members",
+            'existing identity is replaced',
+        ],
+        [
+            'uid=bogus,zz-future=x,rtime=1,uid=aaaaaaaaaaaaaaaaaaaa,ctime=1',
+            "ctime=1,$members,zz-future=x",
+            'invalid and duplicate identity members are dropped, unknown members kept',
+        ],
+        ['plain,ctime=1', "plain,ctime=1,$members", 'parts without key stay first'],
+    ];
+
+    for my $test (@$tests) {
+        my ($meta, $expected, $name) = @$test;
+        my $merged = PVE::GuestIdentity::merge_identity($meta, $identity);
+        is($merged, $expected, $name);
+        is_deeply(PVE::GuestIdentity::parse_identity($merged), $identity, "$name, parses back");
+    }
+
+    for my $invalid (
+        { uid => 'GAYTEMZUGU3DOOBZMFRG', rtime => 1 },
+        { uid => 'gaytemzugu3doobzmfrg', rtime => undef },
+        { uid => 'gaytemzugu3doobzmfrg', rtime => 'now' },
+        { uid => 'gaytemzugu3doobzmfrg', rtime => '1000000000000000' },
+        { uid => 'gaytemzugu3doobzmfrg,ctime=1', rtime => 1 },
+        { rtime => 1 },
+    ) {
+        eval { PVE::GuestIdentity::merge_identity('ctime=1', $invalid) };
+        ok($@, "invalid identity is rejected");
+    }
+};
+
+subtest 'node version check' => sub {
+    my $min = PVE::GuestIdentity::MIN_PVE_MANAGER_VERSION;
+    like($min, qr/^[0-9]+\.[0-9]+\.[0-9]+\z/, 'minimum version is a version string');
+    my ($major, $minor, $release) = split(/\./, $min);
+
+    my $versions = {
+        current => "$major.$minor.$release",
+        newer => "$major." . ($minor + 1) . ".0",
+        older => "$major.$minor." . ($release - 1),
+        invalid => 'invalid',
+    };
+
+    my $cluster_module = Test::MockModule->new('PVE::Cluster');
+    $cluster_module->mock(
+        get_node_pvecfg_version => sub {
+            my ($node) = @_;
+            die "malformed version info\n" if $node eq 'malformed';
+            return $versions->{$node};
+        },
+        node_pvecfg_version_at_least => sub {
+            my ($node, @min) = @_;
+            my $version = PVE::Cluster::get_node_pvecfg_version($node);
+            return $version && PVE::Tools::pvecfg_min_version($version, @min);
+        },
+    );
+
+    for my $node (qw(current newer)) {
+        eval { PVE::GuestIdentity::assert_node_supports_identity($node) };
+        is($@, '', "node with version '$versions->{$node}' is supported");
+        my $unsupported = PVE::GuestIdentity::node_identity_unsupported($node);
+        is($unsupported, undef, "no reason for '$node'");
+    }
+
+    for my $node (qw(older invalid missing malformed)) {
+        eval { PVE::GuestIdentity::assert_node_supports_identity($node) };
+        like($@, qr/node '$node'/, "node '$node' is refused");
+    }
+
+    my $schema = PVE::GuestIdentity::node_identity_unsupported_schema();
+    isnt(
+        $schema,
+        PVE::GuestIdentity::node_identity_unsupported_schema(),
+        'schema is a new copy',
+    );
+    for my $node (qw(older invalid missing malformed)) {
+        my $unsupported = PVE::GuestIdentity::node_identity_unsupported($node);
+        eval { PVE::JSONSchema::validate($unsupported, $schema) };
+        is($@, '', "reason for '$node' matches the schema");
+    }
+
+    for my $node (qw(older invalid)) {
+        is_deeply(
+            PVE::GuestIdentity::node_identity_unsupported($node),
+            { version => $versions->{$node}, 'required-version' => $min },
+            "reason for '$node' has both versions",
+        );
+        eval { PVE::GuestIdentity::assert_node_supports_identity($node) };
+        is(
+            $@,
+            "node '$node' runs Proxmox VE $versions->{$node}, keeping the guest identity requires"
+                . " $min or newer - upgrade the node first\n",
+            "refusal of '$node' names both versions",
+        );
+    }
+
+    for my $node (qw(missing malformed)) {
+        is_deeply(
+            PVE::GuestIdentity::node_identity_unsupported($node),
+            { 'required-version' => $min },
+            "reason for '$node' has only the required version",
+        );
+        eval { PVE::GuestIdentity::assert_node_supports_identity($node) };
+        is(
+            $@,
+            "node '$node' does not report its Proxmox VE version, so it is unknown whether the"
+                . " node keeps the guest identity\n",
+            "refusal of '$node' says why",
+        );
+    }
+};
+
+done_testing();
-- 
2.47.3





^ permalink raw reply related	[relevance 22%]

* [PATCH cluster/guest-common/qemu-server/container/manager/docs v5 00/41] fix #7846: guest identity (uid) and cluster ID
@ 2026-11-19 19:18 17% Thomas Lamprecht
  2026-11-19 19:18 22% ` [PATCH guest-common v5 08/41] guest identity: add helpers for the guest uid and registration time Thomas Lamprecht
                   ` (3 more replies)
  0 siblings, 4 replies; 32+ results
From: Thomas Lamprecht @ 2026-11-19 19:18 UTC (permalink / raw)
  To: pve-devel

A VMID can be reused for another guest, and a guest can get another
VMID or move to another cluster through a restore or a remote
migration. So backup software and other tools cannot tell whether they
still look at the same guest, see [0].

This series gives every VM and container a guest identity in the
read-only 'meta' property: a random uid (100 bits as 20 base32
characters) and the time the guest was registered in the cluster. Create
and clone get a new uid. Config changes, migration, rollback, backup and
restore keep it, also under another VMID or in another cluster, as long
as no other guest there has it. Each cluster or standalone node also
gets a cluster ID in the same format, generated and protected by pmxcfs.
The docs patches describe the details.

The uid is a plain random nonce: 100 bits make a duplicate practically
impossible and fit into a 128-bit value with room to spare, and 20
base32 characters stay short and need no quoting. The registration time
is separate from the creation time, which clones, restores and remote
migrations copy along. It changes when a guest gets registered again, so
tools can tell such a guest from the one they knew.

Three behavior changes come with it:

* Restoring over an existing guest whose uid differs from the one of
  the backup is refused unless 'allow-identity-mismatch' is set. 'force'
  alone does not override this.
* A migration to another cluster is refused if another guest there
  already has the uid, unless 'allow-new-uid' is set. The check runs
  before anything is transferred. PDM does not know the option yet.
* Older versions drop the whole 'meta' property of a guest that has an
  identity. So migration and clone to such nodes is refused, and remote
  migration bumps the tunnel version. This also hits moves by the HA
  stack, which stops a container or a relocated VM before the migration
  gets refused. Making the HA stack aware of the node versions, so that
  for example the maintenance mode does not pick such nodes, is a
  separate follow-up.

The patches are in dependency order: guest-common needs the pve-cluster
of this series, qemu-server and container need guest-common, and manager
needs all of them. manager also has to depend on the qemu-server and
container versions with this series, as the migration guard takes the
pve-manager version of a node as proof that the node keeps the identity.
MIN_PVE_MANAGER_VERSION in guest-common is a stand-in for that version.

Tested with the affected tests of the repositories for every patch and
their full suites at the end, pmxcfs with corosync in network
namespaces, and end to end on a nested three-node cluster that was
upgraded node by node, with remote migrations to a standalone node.

changes v4 -> v5, thanks again to Dominik for the review and the
tests:
* no lock of its own for the guest identity anymore, as Dominik noted
  too. A config write reads the stored identity and writes the config
  under the config lock of its caller, like every config change
  (patches 9, 10, 11). The lock was there because the container
  post-stop hook wrote the config without the config lock. That is a
  bug of the hook and fixed by an independent patch before the series,
  as is the same for the disk of a template in 'qm importdisk'.
  This was actually quite nasty pre-existing hole that was found
  here, nice.
* remote migration from a cluster without guest identities: the task
  on the target logs the new uid of the guest, and that a migration
  back to such a cluster gets refused (patches 12, 18, 26)
* new test for the cluster-wide bulk migration check (patch 34)
* 'adopt' is the one word for getting the uid of a backup or of the
  source guest now, also in option descriptions, docs and subjects,
  where it was 'take over' before; the task logs already said 'adopt'
* docs: the section about failed restores is a list of what can be
  left behind and numbered steps to clean up now (patch 36)
* clearer wording of some comments, option descriptions and commit
  messages
I added Dominik's Reviewed-by and Tested-by from v4 on all patches but
9, 10, 11, whose code changed with the removal of the lock, and
36, whose text got rewritten.

changes v3 -> v4, thanks a lot (!) to Dominik for the review and the
tests:
* cluster ID: pmxcfs checks after each sync and then every ten seconds
  while in sync, by the current state alone, instead of on single
  events, which missed failed sends (the confdb listener patch is
  gone); a standalone node that cannot store its ID starts without one
* failed restores: independent fixes before the series put the previous
  firewall config back, keep a guest whose cleanup was incomplete at
  its VMID and locked, for VMs as for containers, and do not create a
  guest for a caller that may only overwrite one
* shared code: pve-guest-common has one helper for the start of a
  restore, both overrides as standard options and the wait for a volume
  transfer in the tunnel cleanup
* tests of existing behavior moved to independent commits before the
  series, so both remote migration test patches left it
* new, suggested by Dominik: the uid as variable of the backup notes
  template (patches 13, 35, 41) and the cluster ID in the datacenter
  summary (patch 30)
* cluster-wide bulk migration between two older nodes works again, and
  the stand-in for the minimum pve-manager version is 9.2.33, as 9.2.31
  and 9.2.32 got released without this series
I added Dominik's Reviewed-by and Tested-by from v3 on the patches that
did not change or only got polish since.

changes v2 -> v3:
* remote migration: a guest without uid gets one before the source
  sends it, so source and target no longer end up with unrelated uids;
  the identity command moved to pve-guest-common for both guest types
  (new patch 13)
* restore: keep the guest if a restored volume or firewall config
  cannot be removed, fail if a container backup changes between its
  check and its extraction, and let the cleanup follow the reservation
* reserving a VMID refuses an existing config that fails to load
  instead of replacing it
* cluster ID: generate it right away when the configured nodes change
  (new patch 5)
* feature API without version lookups for snapshot requests, and the
  cluster-wide bulk migration refuses its target up front
* docs: failed restores, uid conflicts on migration, qm.conf(5) and
  pct.conf(5)
* more independent fixes that the series builds on were applied on
  their own: failed and concurrent restores and creates, the schema of
  the migration preconditions, the lock of a VMA restore, a node list
  cut short in pmxcfs

changes v1 -> v2, thanks to Dominik for the review:
* rebase onto current master (tracking of used guest IDs, dfsm rework)
* remote migration takes the uid over at its start and refuses a uid
  that is in use in the target cluster, unless 'allow-new-uid' is set
* qemu-server and container share the restore checks and messages
  through pve-guest-common, with fewer special cases
* IDs take each character from one random byte, without an encoder
* the clone dialog does not offer nodes that would drop the identity,
  and a bulk migration checks its target once (patch 35)
* independent fixes moved out of the series and got applied on their
  own: the IPC client error, the order of removing firewall and guest
  config, and the cleanup of a remote migration target after failures
* comments, commit messages and docs give the reasons for the format,
  for rtime next to ctime and for the separate lock
Details are in the notes below the "---" of each patch.

v4: https://lore.proxmox.com/pve-devel/20261119103551.1666964-1-t.lamprecht@proxmox.com/
v3: https://lore.proxmox.com/pve-devel/20261118043817.1659212-1-t.lamprecht@proxmox.com/
v2: https://lore.proxmox.com/pve-devel/20261117223945.862914-1-t.lamprecht@proxmox.com/
v1: https://lore.proxmox.com/pve-devel/20261116004703.2908294-1-t.lamprecht@proxmox.com/

[0]: https://bugzilla.proxmox.com/show_bug.cgi?id=7846

cluster:

Thomas Lamprecht (7):
  pmxcfs: reject changes to the cluster ID file from user space
  pmxcfs: generate a cluster ID on standalone nodes
  pmxcfs: dfsm: add a callback that runs once all members are in sync
  pmxcfs: quorum: record the corosync membership
  pmxcfs: dcdb: generate the cluster ID once the cluster is in sync
  cluster: add helper to read the cluster ID
  pmxcfs: allow removing the cluster ID file in forced local mode

 src/PVE/Cluster.pm          |  16 +
 src/pmxcfs/Makefile         |  12 +-
 src/pmxcfs/cfs-plug-memdb.c |  46 ++
 src/pmxcfs/cfs-utils.c      |   8 +
 src/pmxcfs/cfs-utils.h      |   5 +
 src/pmxcfs/check_dcdb.c     | 876 ++++++++++++++++++++++++++++++++++++
 src/pmxcfs/check_memdb.c    | 312 +++++++++++++
 src/pmxcfs/cluster-id.c     | 142 ++++++
 src/pmxcfs/cluster-id.h     |  50 ++
 src/pmxcfs/dcdb.c           | 141 ++++++
 src/pmxcfs/dcdb.h           |   5 +-
 src/pmxcfs/dfsm.c           |  70 ++-
 src/pmxcfs/dfsm.h           |  10 +
 src/pmxcfs/memdb.c          |  17 +
 src/pmxcfs/memdb.h          |   4 +
 src/pmxcfs/pmxcfs.c         |   8 +-
 src/pmxcfs/quorum.c         |  13 +-
 src/pmxcfs/status.c         |  44 ++
 src/pmxcfs/status.h         |  13 +
 src/test/Makefile           |   6 +-
 src/test/test_cluster_id.pl |  46 ++
 21 files changed, 1832 insertions(+), 12 deletions(-)
 create mode 100644 src/pmxcfs/check_dcdb.c
 create mode 100644 src/pmxcfs/cluster-id.c
 create mode 100644 src/pmxcfs/cluster-id.h
 create mode 100644 src/test/test_cluster_id.pl


guest-common:

Thomas Lamprecht (6):
  guest identity: add helpers for the guest uid and registration time
  abstract config: assign a guest identity and keep it on config writes
  abstract config: let the VMID reservation return the previous state
  guest identity: allow adopting a uid that is unused in the cluster
  migrate: add shared helpers for the identity command of the migration tunnel
  vzdump: notes template: list the uid variable

 src/Makefile                       |    1 +
 src/PVE/AbstractConfig.pm          |  166 +++-
 src/PVE/AbstractMigrate.pm         |   42 +
 src/PVE/GuestIdentity.pm           |  514 +++++++++++
 src/PVE/VZDump/Common.pm           |    6 +-
 src/tests/Makefile                 |   10 +-
 src/tests/config-identity-tests.pl | 1341 ++++++++++++++++++++++++++++
 src/tests/guest-identity-tests.pl  |  474 ++++++++++
 8 files changed, 2545 insertions(+), 9 deletions(-)
 create mode 100644 src/PVE/GuestIdentity.pm
 create mode 100755 src/tests/config-identity-tests.pl
 create mode 100755 src/tests/guest-identity-tests.pl


qemu-server:

Thomas Lamprecht (6):
  api: restore: release the VMID if a restore to an unused VMID fails
  api: migrate, clone: refuse targets that would drop the guest identity
  fix #7846: config: add a guest identity to the 'meta' property
  restore: adopt the guest uid from the backup where possible
  api: remote migration: adopt the guest uid from the source
  api: status: return the guest uid

 src/PVE/API2/Qemu.pm                          | 108 ++-
 src/PVE/CLI/qm.pm                             |   1 +
 src/PVE/CLI/qmrestore.pm                      |   5 +-
 src/PVE/QemuConfig.pm                         |   7 +
 src/PVE/QemuMigrate.pm                        |  18 +-
 src/PVE/QemuServer.pm                         | 166 +++-
 src/PVE/QemuServer/MetaInfo.pm                |   2 +
 src/test/Makefile                             |   5 +-
 src/test/QemuServerTest/FakeCFS.pm            |  84 +-
 .../q35-windows-pinning-identity-only.conf    |   6 +
 ...q35-windows-pinning-identity-only.conf.cmd |  26 +
 .../meta-identity-invalid.conf                |   6 +
 .../meta-identity-invalid.conf.strict.error   |   2 +
 .../meta-identity-invalid.conf                |   7 +
 .../parse-config-input/meta-identity.conf     |  20 +
 src/test/restore-config-expected/150.conf     |   9 +
 src/test/restore-config-input/150.conf        |  10 +
 src/test/run_api_tests.pl                     | 198 +++++
 src/test/run_guest_identity_tests.pl          | 630 +++++++++++++++
 src/test/run_parse_config_tests.pl            |   2 +-
 src/test/run_qemu_restore_config_tests.pl     | 754 +++++++++++++++++-
 .../create/qemu-server/401.conf               |  31 +
 .../create/qemu-server/402.conf               |  31 +
 .../rollback/qemu-server/401.conf             |  36 +
 .../rollback/qemu-server/402.conf             |  35 +
 .../create/qemu-server/401.conf               |  13 +
 .../create/qemu-server/402.conf               |  13 +
 .../rollback/qemu-server/401.conf             |  35 +
 .../rollback/qemu-server/402.conf             |  34 +
 src/test/snapshot-test.pm                     |  82 +-
 30 files changed, 2300 insertions(+), 76 deletions(-)
 create mode 100644 src/test/cfg2cmd/q35-windows-pinning-identity-only.conf
 create mode 100644 src/test/cfg2cmd/q35-windows-pinning-identity-only.conf.cmd
 create mode 100644 src/test/parse-config-expected/meta-identity-invalid.conf
 create mode 100644 src/test/parse-config-expected/meta-identity-invalid.conf.strict.error
 create mode 100644 src/test/parse-config-input/meta-identity-invalid.conf
 create mode 100644 src/test/parse-config-input/meta-identity.conf
 create mode 100644 src/test/restore-config-expected/150.conf
 create mode 100644 src/test/restore-config-input/150.conf
 create mode 100755 src/test/run_guest_identity_tests.pl
 create mode 100644 src/test/snapshot-expected/create/qemu-server/401.conf
 create mode 100644 src/test/snapshot-expected/create/qemu-server/402.conf
 create mode 100644 src/test/snapshot-expected/rollback/qemu-server/401.conf
 create mode 100644 src/test/snapshot-expected/rollback/qemu-server/402.conf
 create mode 100644 src/test/snapshot-input/create/qemu-server/401.conf
 create mode 100644 src/test/snapshot-input/create/qemu-server/402.conf
 create mode 100644 src/test/snapshot-input/rollback/qemu-server/401.conf
 create mode 100644 src/test/snapshot-input/rollback/qemu-server/402.conf


container:

Thomas Lamprecht (8):
  restore: decide by the reservation whether the container is new
  config: add read-only meta property with the creation time
  fix #7846: config: add a guest identity to the 'meta' property
  api: migrate, clone: refuse targets that would drop the guest identity
  restore: adopt the guest uid from the backup where possible
  restore: refuse overwriting a container with another guest's backup
  api: remote migration: adopt the guest uid from the source
  api: status: return the guest uid

 src/PVE/API2/LXC.pm         |  136 +++-
 src/PVE/API2/LXC/Config.pm  |    8 +
 src/PVE/API2/LXC/Status.pm  |    6 +
 src/PVE/CLI/pct.pm          |    2 +
 src/PVE/LXC/Config.pm       |   42 +-
 src/PVE/LXC/Create.pm       |   26 +-
 src/PVE/LXC/Migrate.pm      |    8 +-
 src/test/config_tests.pl    |   26 +-
 src/test/lifecycle_tests.pl | 1479 +++++++++++++++++++++++++++++++++++
 9 files changed, 1702 insertions(+), 31 deletions(-)


manager:

Thomas Lamprecht (8):
  api: cluster resources: add guest uid and registration time
  api: cluster status: add cluster ID
  ui: datacenter summary: show the cluster ID
  ui: restore: allow overwriting a guest with a backup of another guest
  ui: migrate: refuse target nodes that would drop the guest identity
  ui: guest summary: show the guest identity
  api: bulk migrate: refuse targets that would drop the guest identity
  vzdump: notes template: add the guest uid as variable

 PVE/API2/Cluster.pm                      |  24 +++-
 PVE/API2/Cluster/BulkAction/Guest.pm     |  17 +++
 PVE/API2/Nodes.pm                        |   3 +
 PVE/VZDump.pm                            |  12 +-
 test/BulkMigrate_test.pl                 | 102 ++++++++++++++
 test/ClusterResources_test.pl            | 171 +++++++++++++++++++++++
 test/ClusterStatus_test.pl               | 114 +++++++++++++++
 test/Makefile                            |  14 +-
 www/manager6/Makefile                    |   1 +
 www/manager6/Utils.js                    |   2 +-
 www/manager6/dc/Health.js                |   6 +
 www/manager6/panel/GuestIdentity.js      | 120 ++++++++++++++++
 www/manager6/panel/GuestStatusView.js    |   3 +
 www/manager6/panel/TemplateStatusView.js |   3 +
 www/manager6/window/Migrate.js           |  29 ++++
 www/manager6/window/Restore.js           |  18 +++
 16 files changed, 635 insertions(+), 4 deletions(-)
 create mode 100755 test/BulkMigrate_test.pl
 create mode 100755 test/ClusterResources_test.pl
 create mode 100755 test/ClusterStatus_test.pl
 create mode 100644 www/manager6/panel/GuestIdentity.js


docs:

Thomas Lamprecht (6):
  vzdump: restore: describe what a failed restore can leave behind
  vzdump: describe the guest identity of VMs and containers
  pvecm: document the cluster ID and how to get a new one
  qm: configuration: describe the read-only meta property
  pct: configuration: describe the read-only meta property
  vzdump: notes: document the uid template variable

 pct.adoc      |  35 +++++
 pct.conf.adoc |   3 +
 pmxcfs.adoc   |   1 +
 pvecm.adoc    | 106 +++++++++++++++
 qm.adoc       |  38 ++++++
 qm.conf.adoc  |   3 +
 vzdump.adoc   | 354 ++++++++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 540 insertions(+)


Summary over all repositories:
  91 files changed, 9554 insertions(+), 132 deletions(-)

-- 
2.47.3





^ permalink raw reply	[relevance 17%]

* Re: [PATCH cluster/guest-common/qemu-server/container/manager/docs v4 00/41] fix #7846: guest identity (uid) and cluster ID
  2026-11-19 10:33 17% [PATCH cluster/guest-common/qemu-server/container/manager/docs v4 00/41] " Thomas Lamprecht
                   ` (2 preceding siblings ...)
  2026-11-19 10:34 17% ` [PATCH docs v4 37/41] vzdump: describe the guest identity of VMs and containers Thomas Lamprecht
@ 2026-11-19 14:46 17% ` Dominik Csapak
  2026-11-19 19:49 11% ` superseded: " Thomas Lamprecht
  4 siblings, 0 replies; 32+ results
From: Dominik Csapak @ 2026-11-19 14:46 UTC (permalink / raw)
  To: Thomas Lamprecht, pve-devel

Tested and checked again, and seems even better to me now :)

The error messages are clearer, cluster id on the gui makes sense
uid in templates, etc. all worked out fine

This time tested also remote migration more with old vs new cluster
and worked as expected. One tiny nit here (but can be done later too)

If i remote migrate from an old to new cluster, it does not say
anywhere in the migration log that a uid was adapted.

So from e.g. PDMs perspective i can migrate old -> new, but
suddenly not back (expected) but the first log didn't give
me a hint.

Not super tragic, but maybe worth a log line.
Though we want to adapt PDM to show/check/etc the id anyway,
so maybe that's not necessary. Easy would be, to show a warning if the
target has a cluster-id but the source not,
and indicate that a move back isn't possible anymore.

As talked off-list, the identity lock doesn't seem to be harmful,
but also not strictly necessary:

We have to take a (local) lock on the vm config while adopting
so having another (local) lock with vmid scope seems unnecessary.
Though that can probably worked out later too and remove
if deemed unncessary

Note that i didn't look too deeply into the code this time,
mostly looked at diffs from old-> new (where sensible due to
changing code on master) and the patches that are new/changed.

So again from me (especially for the new patches):

Reviewed-by: Dominik Csapak <d.csapak@proxmox.com>
Tested-by: Dominik Csapak <d.csapak@proxmox.com>

On 11/19/26 11:37 AM, Thomas Lamprecht wrote:
> A VMID can be reused for another guest, and a guest can get another
> VMID or move to another cluster through a restore or a remote
> migration. So backup software and other tools cannot tell whether they
> still look at the same guest, see [0].
> 
> This series gives every VM and container a guest identity in the
> read-only 'meta' property: a random uid (100 bits as 20 base32
> characters) and the time the guest was registered in the cluster. Create
> and clone get a new uid. Config changes, migration, rollback, backup and
> restore keep it, also under another VMID or in another cluster, as long
> as no other guest there has it. Each cluster or standalone node also
> gets a cluster ID in the same format, generated and protected by pmxcfs.
> The docs patches describe the details.
> 
> The uid is a plain random nonce: 100 bits make a duplicate practically
> impossible and fit into a 128-bit value with room to spare, and 20
> base32 characters stay short and need no quoting. The registration time
> is separate from the creation time, which clones, restores and remote
> migrations copy along. It changes when a guest gets registered again, so
> tools can tell such a guest from the one they knew.
> 
> Three behavior changes come with it:
> 
> * Restoring over an existing guest whose uid differs from the one of
>    the backup is refused unless 'allow-identity-mismatch' is set. 'force'
>    alone does not override this.
> * A migration to another cluster is refused if another guest there
>    already has the uid, unless 'allow-new-uid' is set. The check runs
>    before anything is transferred. PDM does not know the option yet.
> * Older versions drop the whole 'meta' property of a guest that has an
>    identity. So migration and clone to such nodes is refused, and remote
>    migration bumps the tunnel version. This also hits moves by the HA
>    stack, which stops a container or a relocated VM before the migration
>    gets refused. A target check in the LRM that avoids this will follow
>    separately.
> 
> The patches are in dependency order: guest-common needs the pve-cluster
> of this series, qemu-server and container need guest-common, and manager
> needs all of them. manager also has to depend on the qemu-server and
> container versions with this series, as the migration guard takes the
> pve-manager version of a node as proof that the node keeps the identity.
> MIN_PVE_MANAGER_VERSION in guest-common is a stand-in for that version.
> 
> Tested with the affected tests of the repositories for every patch and
> their full suites at the end, pmxcfs with corosync in network
> namespaces, and end to end on a nested three-node cluster that was
> upgraded node by node, with remote migrations to a standalone node.
> 
> changes v3 -> v4, thanks a lot (!) to Dominik for the review and the
> tests:
> * cluster ID: pmxcfs checks after each sync and then every ten seconds
>    while in sync, by the current state alone, instead of on single
>    events, which missed failed sends (the confdb listener patch is
>    gone); a standalone node that cannot store its ID starts without one
> * failed restores: independent fixes before the series put the previous
>    firewall config back, keep a guest whose cleanup was incomplete at
>    its VMID and locked, for VMs as for containers, and do not create a
>    guest for a caller that may only overwrite one
> * shared code: pve-guest-common has one helper for the start of a
>    restore, both overrides as standard options and the wait for a volume
>    transfer in the tunnel cleanup
> * tests of existing behavior moved to independent commits before the
>    series, so both remote migration test patches left it
> * new, suggested by Dominik: the uid as variable of the backup notes
>    template (patches 13, 35, 41) and the cluster ID in the datacenter
>    summary (patch 30)
> * cluster-wide bulk migration between two older nodes works again, and
>    the stand-in for the minimum pve-manager version is 9.2.33, as 9.2.31
>    and 9.2.32 got released without this series
> I added Dominik's Reviewed-by and Tested-by from v3 on the patches that
> did not change or only got polish since.
> 
> changes v2 -> v3:
> * remote migration: a guest without uid gets one before the source
>    sends it, so source and target no longer end up with unrelated uids;
>    the identity command moved to pve-guest-common for both guest types
>    (new patch 13)
> * restore: keep the guest if a restored volume or firewall config
>    cannot be removed, fail if a container backup changes between its
>    check and its extraction, and let the cleanup follow the reservation
> * reserving a VMID refuses an existing config that fails to load
>    instead of replacing it
> * cluster ID: generate it right away when the configured nodes change
>    (new patch 5)
> * feature API without version lookups for snapshot requests, and the
>    cluster-wide bulk migration refuses its target up front
> * docs: failed restores, uid conflicts on migration, qm.conf(5) and
>    pct.conf(5)
> * more independent fixes that the series builds on were applied on
>    their own: failed and concurrent restores and creates, the schema of
>    the migration preconditions, the lock of a VMA restore, a node list
>    cut short in pmxcfs
> 
> changes v1 -> v2, thanks to Dominik for the review:
> * rebase onto current master (tracking of used guest IDs, dfsm rework)
> * remote migration takes the uid over at its start and refuses a uid
>    that is in use in the target cluster, unless 'allow-new-uid' is set
> * qemu-server and container share the restore checks and messages
>    through pve-guest-common, with fewer special cases
> * IDs take each character from one random byte, without an encoder
> * the clone dialog does not offer nodes that would drop the identity,
>    and a bulk migration checks its target once (patch 35)
> * independent fixes moved out of the series and got applied on their
>    own: the IPC client error, the order of removing firewall and guest
>    config, and the cleanup of a remote migration target after failures
> * comments, commit messages and docs give the reasons for the format,
>    for rtime next to ctime and for the separate lock
> Details are in the notes below the "---" of each patch.
> 
> v3: https://lore.proxmox.com/pve-devel/20261118043817.1659212-1-t.lamprecht@proxmox.com/
> v2: https://lore.proxmox.com/pve-devel/20261117223945.862914-1-t.lamprecht@proxmox.com/
> v1: https://lore.proxmox.com/pve-devel/20261116004703.2908294-1-t.lamprecht@proxmox.com/
> 
> [0]: https://bugzilla.proxmox.com/show_bug.cgi?id=7846
> 
> cluster:
> 
> Thomas Lamprecht (7):
>    pmxcfs: reject changes to the cluster ID file from user space
>    pmxcfs: generate a cluster ID on standalone nodes
>    pmxcfs: dfsm: add a callback that runs once all members are in sync
>    pmxcfs: quorum: record the corosync membership
>    pmxcfs: dcdb: generate the cluster ID once the cluster is in sync
>    cluster: add helper to read the cluster ID
>    pmxcfs: allow removing the cluster ID file in forced local mode
> 
>   src/PVE/Cluster.pm          |  16 +
>   src/pmxcfs/Makefile         |  12 +-
>   src/pmxcfs/cfs-plug-memdb.c |  46 ++
>   src/pmxcfs/cfs-utils.c      |   8 +
>   src/pmxcfs/cfs-utils.h      |   5 +
>   src/pmxcfs/check_dcdb.c     | 876 ++++++++++++++++++++++++++++++++++++
>   src/pmxcfs/check_memdb.c    | 312 +++++++++++++
>   src/pmxcfs/cluster-id.c     | 142 ++++++
>   src/pmxcfs/cluster-id.h     |  50 ++
>   src/pmxcfs/dcdb.c           | 141 ++++++
>   src/pmxcfs/dcdb.h           |   5 +-
>   src/pmxcfs/dfsm.c           |  70 ++-
>   src/pmxcfs/dfsm.h           |  10 +
>   src/pmxcfs/memdb.c          |  17 +
>   src/pmxcfs/memdb.h          |   4 +
>   src/pmxcfs/pmxcfs.c         |   8 +-
>   src/pmxcfs/quorum.c         |  13 +-
>   src/pmxcfs/status.c         |  44 ++
>   src/pmxcfs/status.h         |  13 +
>   src/test/Makefile           |   6 +-
>   src/test/test_cluster_id.pl |  46 ++
>   21 files changed, 1832 insertions(+), 12 deletions(-)
>   create mode 100644 src/pmxcfs/check_dcdb.c
>   create mode 100644 src/pmxcfs/cluster-id.c
>   create mode 100644 src/pmxcfs/cluster-id.h
>   create mode 100644 src/test/test_cluster_id.pl
> 
> 
> guest-common:
> 
> Thomas Lamprecht (6):
>    guest identity: add helpers for the guest uid and registration time
>    abstract config: assign a guest identity and keep it on config writes
>    abstract config: let the VMID reservation return the previous state
>    guest identity: allow adopting a uid that is unused in the cluster
>    migrate: add shared helpers for the identity command of the migration tunnel
>    vzdump: notes template: list the uid variable
> 
>   src/Makefile                       |    1 +
>   src/PVE/AbstractConfig.pm          |  203 ++++-
>   src/PVE/AbstractMigrate.pm         |   42 +
>   src/PVE/GuestIdentity.pm           |  497 ++++++++++
>   src/PVE/VZDump/Common.pm           |    6 +-
>   src/tests/Makefile                 |   10 +-
>   src/tests/config-identity-tests.pl | 1358 ++++++++++++++++++++++++++++
>   src/tests/guest-identity-tests.pl  |  474 ++++++++++
>   8 files changed, 2580 insertions(+), 11 deletions(-)
>   create mode 100644 src/PVE/GuestIdentity.pm
>   create mode 100755 src/tests/config-identity-tests.pl
>   create mode 100755 src/tests/guest-identity-tests.pl
> 
> 
> qemu-server:
> 
> Thomas Lamprecht (6):
>    api: restore: release the VMID if a restore to an unused VMID fails
>    api: migrate, clone: refuse targets that would drop the guest identity
>    fix #7846: config: add a guest identity to the 'meta' property
>    restore: take over the guest uid from the backup where possible
>    api: remote migration: take over the guest uid from the source
>    api: status: return the guest uid
> 
>   src/PVE/API2/Qemu.pm                          | 107 ++-
>   src/PVE/CLI/qm.pm                             |   1 +
>   src/PVE/CLI/qmrestore.pm                      |   5 +-
>   src/PVE/QemuConfig.pm                         |   7 +
>   src/PVE/QemuMigrate.pm                        |  18 +-
>   src/PVE/QemuServer.pm                         | 166 +++-
>   src/PVE/QemuServer/MetaInfo.pm                |   2 +
>   src/test/Makefile                             |   5 +-
>   src/test/QemuServerTest/FakeCFS.pm            |  84 +-
>   .../q35-windows-pinning-identity-only.conf    |   6 +
>   ...q35-windows-pinning-identity-only.conf.cmd |  26 +
>   .../meta-identity-invalid.conf                |   6 +
>   .../meta-identity-invalid.conf.strict.error   |   2 +
>   .../meta-identity-invalid.conf                |   7 +
>   .../parse-config-input/meta-identity.conf     |  20 +
>   src/test/restore-config-expected/150.conf     |   9 +
>   src/test/restore-config-input/150.conf        |  10 +
>   src/test/run_api_tests.pl                     | 198 +++++
>   src/test/run_guest_identity_tests.pl          | 614 ++++++++++++++
>   src/test/run_parse_config_tests.pl            |   2 +-
>   src/test/run_qemu_restore_config_tests.pl     | 754 +++++++++++++++++-
>   .../create/qemu-server/401.conf               |  31 +
>   .../create/qemu-server/402.conf               |  31 +
>   .../rollback/qemu-server/401.conf             |  36 +
>   .../rollback/qemu-server/402.conf             |  35 +
>   .../create/qemu-server/401.conf               |  13 +
>   .../create/qemu-server/402.conf               |  13 +
>   .../rollback/qemu-server/401.conf             |  35 +
>   .../rollback/qemu-server/402.conf             |  34 +
>   src/test/snapshot-test.pm                     |  82 +-
>   30 files changed, 2283 insertions(+), 76 deletions(-)
>   create mode 100644 src/test/cfg2cmd/q35-windows-pinning-identity-only.conf
>   create mode 100644 src/test/cfg2cmd/q35-windows-pinning-identity-only.conf.cmd
>   create mode 100644 src/test/parse-config-expected/meta-identity-invalid.conf
>   create mode 100644 src/test/parse-config-expected/meta-identity-invalid.conf.strict.error
>   create mode 100644 src/test/parse-config-input/meta-identity-invalid.conf
>   create mode 100644 src/test/parse-config-input/meta-identity.conf
>   create mode 100644 src/test/restore-config-expected/150.conf
>   create mode 100644 src/test/restore-config-input/150.conf
>   create mode 100755 src/test/run_guest_identity_tests.pl
>   create mode 100644 src/test/snapshot-expected/create/qemu-server/401.conf
>   create mode 100644 src/test/snapshot-expected/create/qemu-server/402.conf
>   create mode 100644 src/test/snapshot-expected/rollback/qemu-server/401.conf
>   create mode 100644 src/test/snapshot-expected/rollback/qemu-server/402.conf
>   create mode 100644 src/test/snapshot-input/create/qemu-server/401.conf
>   create mode 100644 src/test/snapshot-input/create/qemu-server/402.conf
>   create mode 100644 src/test/snapshot-input/rollback/qemu-server/401.conf
>   create mode 100644 src/test/snapshot-input/rollback/qemu-server/402.conf
> 
> 
> container:
> 
> Thomas Lamprecht (8):
>    restore: decide by the reservation whether the container is new
>    config: add read-only meta property with the creation time
>    fix #7846: config: add a guest identity to the 'meta' property
>    api: migrate, clone: refuse targets that would drop the guest identity
>    restore: take over the guest uid from the backup where possible
>    restore: refuse overwriting a container with another guest's backup
>    api: remote migration: take over the guest uid from the source
>    api: status: return the guest uid
> 
>   src/PVE/API2/LXC.pm         |  133 ++-
>   src/PVE/API2/LXC/Config.pm  |    8 +
>   src/PVE/API2/LXC/Status.pm  |    6 +
>   src/PVE/CLI/pct.pm          |    2 +
>   src/PVE/LXC/Config.pm       |   42 +-
>   src/PVE/LXC/Create.pm       |   26 +-
>   src/PVE/LXC/Migrate.pm      |    8 +-
>   src/test/config_tests.pl    |   22 +
>   src/test/lifecycle_tests.pl | 1522 +++++++++++++++++++++++++++++++++++
>   9 files changed, 1740 insertions(+), 29 deletions(-)
> 
> 
> manager:
> 
> Thomas Lamprecht (8):
>    api: cluster resources: add guest uid and registration time
>    api: cluster status: add cluster ID
>    ui: datacenter summary: show the cluster ID
>    ui: restore: allow overwriting a guest with a backup of another guest
>    ui: migrate: refuse target nodes that would drop the guest identity
>    ui: guest summary: show the guest identity
>    api: bulk migrate: refuse targets that would drop the guest identity
>    vzdump: notes template: add the guest uid as variable
> 
>   PVE/API2/Cluster.pm                      |  24 +++-
>   PVE/API2/Cluster/BulkAction/Guest.pm     |  17 +++
>   PVE/API2/Nodes.pm                        |   3 +
>   PVE/VZDump.pm                            |  12 +-
>   test/ClusterResources_test.pl            | 171 +++++++++++++++++++++++
>   test/ClusterStatus_test.pl               | 114 +++++++++++++++
>   test/Makefile                            |  10 +-
>   www/manager6/Makefile                    |   1 +
>   www/manager6/Utils.js                    |   2 +-
>   www/manager6/dc/Health.js                |   6 +
>   www/manager6/panel/GuestIdentity.js      | 120 ++++++++++++++++
>   www/manager6/panel/GuestStatusView.js    |   3 +
>   www/manager6/panel/TemplateStatusView.js |   3 +
>   www/manager6/window/Migrate.js           |  29 ++++
>   www/manager6/window/Restore.js           |  18 +++
>   15 files changed, 529 insertions(+), 4 deletions(-)
>   create mode 100755 test/ClusterResources_test.pl
>   create mode 100755 test/ClusterStatus_test.pl
>   create mode 100644 www/manager6/panel/GuestIdentity.js
> 
> 
> docs:
> 
> Thomas Lamprecht (6):
>    vzdump: restore: describe what a failed restore can leave behind
>    vzdump: describe the guest identity of VMs and containers
>    pvecm: document the cluster ID and how to get a new one
>    qm: configuration: describe the read-only meta property
>    pct: configuration: describe the read-only meta property
>    vzdump: notes: document the uid template variable
> 
>   pct.adoc      |  35 +++++
>   pct.conf.adoc |   3 +
>   pmxcfs.adoc   |   1 +
>   pvecm.adoc    | 106 +++++++++++++++
>   qm.adoc       |  38 ++++++
>   qm.conf.adoc  |   3 +
>   vzdump.adoc   | 349 ++++++++++++++++++++++++++++++++++++++++++++++++++
>   7 files changed, 535 insertions(+)
> 
> 
> Summary over all repositories:
>    90 files changed, 9499 insertions(+), 132 deletions(-)
> 





^ permalink raw reply	[relevance 17%]

* superseded: [PATCH cluster/guest-common/qemu-server/container/manager/docs v3 00/38] fix #7846: guest identity (uid) and cluster ID
  2026-11-18  4:37 18% [PATCH cluster/guest-common/qemu-server/container/manager/docs v3 00/38] " Thomas Lamprecht
                   ` (3 preceding siblings ...)
  2026-11-18 13:49 17% ` [PATCH cluster/guest-common/qemu-server/container/manager/docs v3 00/38] fix #7846: guest identity (uid) and cluster ID Dominik Csapak
@ 2026-11-19 10:38 11% ` Thomas Lamprecht
  4 siblings, 0 replies; 32+ results
From: Thomas Lamprecht @ 2026-11-19 10:38 UTC (permalink / raw)
  To: pve-devel

Superseded-by: https://lore.proxmox.com/all/20261119103551.1666964-1-t.lamprecht@proxmox.com/




^ permalink raw reply	[relevance 11%]

* [PATCH docs v4 37/41] vzdump: describe the guest identity of VMs and containers
  2026-11-19 10:33 17% [PATCH cluster/guest-common/qemu-server/container/manager/docs v4 00/41] " Thomas Lamprecht
  2026-11-19 10:33 22% ` [PATCH guest-common v4 08/41] guest identity: add helpers for the guest uid and registration time Thomas Lamprecht
  2026-11-19 10:34 16% ` [PATCH qemu-server v4 16/41] fix #7846: config: add a guest identity to the 'meta' property Thomas Lamprecht
@ 2026-11-19 10:34 17% ` Thomas Lamprecht
  2026-11-19 14:46 17% ` [PATCH cluster/guest-common/qemu-server/container/manager/docs v4 00/41] fix #7846: guest identity (uid) and cluster ID Dominik Csapak
  2026-11-19 19:49 11% ` superseded: " Thomas Lamprecht
  4 siblings, 0 replies; 32+ results
From: Thomas Lamprecht @ 2026-11-19 10:34 UTC (permalink / raw)
  To: pve-devel

Since Proxmox VE 9.3, VMs and containers have a guest identity in
'meta': a random uid and a registration time. Backup software and other
tools can distinguish a guest from another that reuses its VMID [0].

Administrators need to understand why restores over a different guest
are refused, when a restore keeps the uid of the backup, and why
migrations and clones to older nodes are blocked. Those nodes drop
'meta', including VM creation information used for hardware defaults.

Document the lifecycle, failed-restore retries, and mixed-version
restrictions in the backup and restore chapter, where users are most
likely to encounter the identity. Include migration and HA behavior
there so the rules can be read together.

[0]: https://bugzilla.proxmox.com/show_bug.cgi?id=7846

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
---

changes v3 -> v4:
* the part of 'Failed Restores' about locks and leftovers moved to a
  patch of its own before this one, what stays is 'Retrying a Failed
  Restore'
* lifecycle table and restore section: a guest with a uid keeps it,
  except in the retry of a failed restore of that backup
* drop the sentence that a retry from standard input needs the override,
  which only holds for containers
* the resource API has uid and rtime only for guests with an identity
* remote migration: remove the guest that holds the uid only if it is
  not needed anymore; the refusal of older targets is described there
  instead of with the mixed versions
* shorter descriptions of uid and rtime, one note with the hints for
  tools, and the reason for the refusals first in the mixed versions
  section

changes v2 -> v3:
* backups are still grouped by type and VMID, also for retention
* refused remote migration: do not remove the reported guest if it is
  the source itself
* own section for failed restores, with what a killed or late-failing
  restore leaves behind
* remote migration of a guest without uid, HA recovery through the node
  of the active CRM, and smaller corrections (the uid gets compared, not
  the identity)

changes v1 -> v2:
* say that the uid has 100 random bits and how rtime differs from ctime
* describe the refusal of a migration to another cluster, its typical
  cases and 'allow-new-uid'
* retry after a failed restore: scope the pending entry, name the
  warning, correct the placeholder case and add the note for enforced
  unique guest IDs

 vzdump.adoc | 312 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 312 insertions(+)

diff --git a/vzdump.adoc b/vzdump.adoc
index 7587580..5a813c4 100644
--- a/vzdump.adoc
+++ b/vzdump.adoc
@@ -464,6 +464,13 @@ following CLI tools:
 
 For details see the corresponding manual pages.
 
+When you restore a backup over an existing guest, {pve} compares the `uid` of
+the backup and of the guest. If they differ, the restore is refused, unless you
+set the `allow-identity-mismatch` option. The existing guest then keeps its
+identity. See
+xref:guest_identity_restore[Restore Over an Existing Guest] for details and
+exceptions.
+
 Bandwidth Limit
 ~~~~~~~~~~~~~~~
 
@@ -591,6 +598,311 @@ Use another VMID if the xref:pvecm_next_id_range[`next-id`] setting of the
 datacenter has the `unique` and `enforce` options set, as the first VMID then
 counts as used.
 
+For how a retry handles the guest identity, see
+xref:guest_identity_failed_restore[Retrying a Failed Restore].
+
+[[guest_identity]]
+Guest Identity
+--------------
+
+Since {pve} 9.3, each virtual machine and container gets a guest identity: a
+random identifier, `uid`, and a registration time, `rtime`. Unlike a VMID,
+which can be reused after a guest is destroyed, the `uid` lets backup software
+and other tools recognize the same logical guest across restores and
+migrations, even under a different VMID.
+
+Backups are still grouped by guest type and VMID, also for retention. If a new
+guest reuses the VMID of a removed guest of the same type, pruning handles the
+backups of both guests together.
+
+[[guest_identity_values]]
+Identity Values
+~~~~~~~~~~~~~~~
+
+The guest identity is part of the `meta` property in the guest configuration.
+This property also contains the creation time `ctime` and, for VMs, the QEMU
+version that the VM was created with, `creation-qemu`:
+
+----
+meta: creation-qemu=10.1.2,ctime=1772444467,rtime=1794320571482,uid=w5qczgiem26qnwzwsoil
+----
+
+`uid`::
+
+A random identifier of 20 lowercase letters and digits that encode 100 random
+bits, so two guests practically never get the same `uid` by chance.
+
+`rtime`::
+
+The time at which the guest was registered in this cluster, in milliseconds
+since the UNIX epoch. It is set whenever the guest gets its `uid` in this
+cluster, so a guest restored to a free VMID gets a new `rtime`, even if it keeps
+the `uid` of the backup. The creation time `ctime`, in contrast, stays with the
+guest: a clone has the `ctime` of its source, and a restored guest or a guest
+migrated from another cluster has that of the backup or of the source guest. As
+a timestamp, the `rtime` is not guaranteed to be unique.
+
+{pve} manages the `meta` property automatically. It is read-only through the
+API, even for `root@pam`.
+
+IMPORTANT: The `uid` helps to correlate a guest with its backups and copies,
+but does not prove where a guest comes from. Whoever restores a backup or
+migrates a guest into the cluster supplies the `uid` of that guest, which {pve}
+takes over if no other guest in the cluster has it. {pve} keeps a `uid` unique
+within a cluster only for operations through its API. A configuration file
+copied by hand has the same `uid` as the original, and guests in different
+clusters can have the same `uid`.
+
+[[guest_identity_read]]
+Reading the Identity
+~~~~~~~~~~~~~~~~~~~~
+
+The following places show the guest identity. All of them require the
+`VM.Audit` privilege on the guest.
+
+* In the web interface, the 'Summary' panel of the guest shows the `uid` as
+  'Unique ID'. The 'Details' button next to it, which has an info icon, opens
+  the 'Guest Identity' window. This window additionally shows the `rtime` as
+  'Registered' and the creation information.
+* The guest configuration, for example with `qm config <vmid>` or
+  `pct config <vmid>`, and through the API paths
+  `/nodes/<node>/qemu/<vmid>/config` and `/nodes/<node>/lxc/<vmid>/config`.
+* The guest status at the API paths `/nodes/<node>/qemu/<vmid>/status/current`
+  and `/nodes/<node>/lxc/<vmid>/status/current`, which contains the `uid`.
+* The cluster resources at the API path `/cluster/resources`, which contain the
+  `uid` and `rtime` of each guest that has a guest identity, for example:
++
+----
+# pvesh get /cluster/resources --type vm --output-format json-pretty
+----
+
+The configuration in a backup contains the `meta` property as well. You can
+show it with `pvesm extractconfig <volume>`, for example.
+
+[[guest_identity_lifecycle]]
+Lifecycle
+~~~~~~~~~
+
+The following table shows how operations affect the identity of a guest.
+
+[width="100%",cols="3,4,2",options="header"]
+|===========================================================================
+|Operation |`uid` |`rtime`
+|Create, including import |new |current time
+|Clone, including linked clones and clones from snapshots |new |current time
+|Restore to a free VMID |the backup's `uid` if present and not used by another
+guest in the cluster; otherwise new |current time
+|Restore to a free VMID with `unique` set |new |current time
+|Restore over an existing guest that has a `uid`, with or without `unique` set
+|kept, see xref:guest_identity_restore[Restore Over an Existing Guest]; the
+retry of a failed restore can take over the backup's `uid` instead, see
+xref:guest_identity_failed_restore[Retrying a Failed Restore] |kept; current
+time if the retry takes over the `uid`
+|Restore over an existing guest without a `uid` |as for a free VMID |current
+time
+|Migration to another cluster, on the target |the source guest's `uid`; new if
+another guest in the target cluster has it and `allow-new-uid` is set, or if the
+source node runs a {pve} version older than 9.3, see
+xref:guest_identity_remote_migration[Migration to Another Cluster] |current time
+|Migration to another cluster, on the source if the guest is kept |kept |kept
+|Snapshot rollback |kept, not taken from the snapshot |kept
+|Migration within the cluster, HA recovery, configuration change, backup,
+replication, conversion to a template |kept |kept
+|Destroy |removed |removed
+|===========================================================================
+
+Restores and migrations from another cluster report the outcome in their task
+log, in a line with `guest identity:`, for example:
+
+----
+guest identity: backup uid w5qczgiem26qnwzwsoil is in use by guest 100, keeping uid er3n3wqoqgcl362ep3da
+----
+
+Guests that existed before the upgrade to {pve} 9.3 get their identity the
+first time a node running {pve} 9.3 or later writes their configuration. This
+happens, for example, when their configuration changes, when they are backed
+up, or when they are migrated to such a node. Their `rtime` is the time of that
+write. Backups made before that have no `uid`.
+
+NOTE: For tools that track guests by their `uid`: a restore that takes over the
+`uid` of the backup first assigns a new `uid` to the guest and replaces it at
+its end, which can be after the guest got unlocked. A migration from another
+cluster takes over the `uid` of the source guest right at its start. A changed
+`uid`, for example in `/cluster/resources`, therefore does not mean that the
+task has finished. A guest that a tool restores by removing it and creating a
+new one through the API gets a new `uid`. To keep the identity, change the
+existing guest in place, or let {pve} restore the guest.
+
+[[guest_identity_restore]]
+Restore Over an Existing Guest
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+If the existing guest already has a guest identity, restoring a backup over it
+keeps the `uid` and `rtime` of that guest, unless the guest is left over from a
+failed restore of that backup, see
+xref:guest_identity_failed_restore[Retrying a Failed Restore]. When both the
+guest and the backup have a `uid` and the values differ, {pve} treats the backup
+as belonging to another guest. This can happen when a VMID was reused. {pve}
+refuses such a restore before it overwrites the guest:
+
+----
+backup belongs to another guest: its uid 'w5qczgiem26qnwzwsoil' differs from uid 'er3n3wqoqgcl362ep3da' of the existing VM 100 - use 'allow-identity-mismatch' to overwrite the VM anyway
+----
+
+To restore such a backup anyway, set the `allow-identity-mismatch` option. The
+existing guest then keeps its identity. In the web interface, select 'Allow
+restoring a backup of another guest' in the restore window, which you open from
+the 'Backup' panel of the guest. On the command line, use for example:
+
+----
+# qmrestore <archive> <vmid> --force 1 --allow-identity-mismatch 1
+# pct restore <vmid> <archive> --force 1 --allow-identity-mismatch 1
+----
+
+Backups without a `uid`, such as backups made with {pve} versions older than
+9.3, are not refused. Container restores from standard input
+(`pct restore <vmid> -`) are an exception: the `uid` of such a backup is only
+known once the container has been overwritten. A restore from standard input
+over a container with a `uid` therefore always requires
+`allow-identity-mismatch`.
+
+[[guest_identity_failed_restore]]
+Retrying a Failed Restore
+~~~~~~~~~~~~~~~~~~~~~~~~~
+
+For locks and leftovers of a failed restore, see
+xref:vzdump_restore_failed[Failed Restores].
+
+If the failed restore was to a free VMID or over a guest without a `uid`, and it
+had already read a backup that has a `uid`, `qm pending <vmid>` or
+`pct pending <vmid>` lists an entry for `meta` with the `uid` of the backup. As
+long as this entry exists, retrying the same restore over the guest left behind
+is accepted. Starting the guest or changing its options removes the entry and
+logs a warning that names the `uid`. The retry is then refused like a restore of
+another guest's backup.
+
+A successful retry takes over the `uid` of the backup and sets a new `rtime`, as
+a restore to a free VMID does. The guest keeps its `uid` and `rtime` instead if
+another guest in the cluster has the `uid` of the backup, or if the retry sets
+`unique`.
+
+A guest that had a `uid` and no such entry before the failed restore keeps its
+`uid` and gets no entry. A retry is checked like the first attempt: a backup
+with the same `uid` is accepted, also after the guest was started or changed,
+and a backup with another `uid` requires `allow-identity-mismatch`.
+
+If a restore over an existing guest without a `uid` stopped before it read the
+backup, for example because the backup storage was unreachable, the guest now
+has a new `uid`. Retry with `allow-identity-mismatch`. The guest then keeps the
+new `uid`.
+
+A restore can also complete with a warning starting with
+`guest identity: unable to adopt backup uid`, for example if the cluster-wide
+lock for this step could not be taken in time. The guest is then restored
+completely, but keeps its new `uid`. To take over the `uid` of the backup,
+repeat the restore over the guest before you start it or change its
+configuration.
+
+[[guest_identity_remote_migration]]
+Migration to Another Cluster
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+A migration to another cluster (`qm remote-migrate`, `pct remote-migrate`) keeps
+the `uid` of the guest. The target takes it over at the start of the migration,
+before any data is transferred.
+
+If another guest in the target cluster already has that `uid`, the migration is
+refused at that point. Typical cases are:
+
+* the guest gets migrated back to a cluster that still has the source guest of
+  an earlier migration, which stays there unless `delete` was set,
+* a copy of the guest was restored in the target cluster from a backup,
+* an earlier migration of the guest broke off after it had transferred the
+  configuration and left a locked guest in the target cluster,
+* the target is the cluster that the guest is in.
+
+The error ends with:
+
+----
+guest 105 in the target cluster already has the uid 'w5qczgiem26qnwzwsoil' of this guest - use 'allow-new-uid' to migrate it with a new uid
+----
+
+If the reported guest is the source guest itself, do not remove it. To keep the
+`uid`, migrate the guest within the cluster instead, with `qm migrate` or
+`pct migrate`.
+
+Otherwise, to keep the `uid`, remove the other guest in the target cluster if
+you no longer need it, and migrate again. To migrate anyway, set the
+`allow-new-uid` option. The migrated guest then gets a new `uid`, and the other
+guest keeps the old one. In both cases, use another target VMID if the
+xref:pvecm_next_id_range[`next-id`] setting of the target cluster has the
+`unique` and `enforce` options set, as the refused migration already used the
+first one. For example:
+
+----
+# qm remote-migrate <vmid> <target-vmid> <target-endpoint> --target-bridge <bridge> --target-storage <storage> --allow-new-uid 1
+----
+
+A migration to another cluster is refused right after connecting to a target
+node with a version older than 9.3, before any data is transferred. The error is
+`Remote tunnel endpoint too old, upgrade required`.
+
+[[guest_identity_mixed_versions]]
+Mixed Versions in a Cluster
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+{pve} versions older than 9.3 ignore the whole `meta` property of a guest that
+has a guest identity, including the creation information. A VM started on a node
+running such a version can therefore get different virtual hardware, see
+xref:qm_machine_type[Machine Type]. When such a node writes the configuration,
+the property is lost.
+
+Therefore, while some nodes of a cluster still run such a version, migrating or
+cloning a guest to one of these nodes is refused. The guest keeps running on its
+current node. If the target node reports its version, the error message shows
+that version and the minimum required version. If the node does not report its
+version, the operation is refused because {pve} cannot verify that the node
+supports guest identities. The 'Migrate' window of the web interface shows the
+reason for the selected target node.
+
+Moves of HA-managed guests to such nodes are refused in the same way. A running
+VM that the HA stack migrates keeps running. The HA stack stops a container, and
+a VM that it relocates, before it migrates the guest, so such a guest is stopped
+although the move is then refused. The HA stack retries automatic moves as long
+as it selects such a node, and such a guest can stay stopped in the meantime.
+This includes moves for:
+
+* the maintenance mode,
+* a node shutdown with the `migrate` shutdown policy,
+* node affinity rules,
+* the CRS load balancer.
+
+Such moves complete only after the target nodes that the HA stack selects run
+{pve} 9.3 or later.
+
+To avoid refused moves while you upgrade a cluster, do one of the following:
+
+* Move all guests away from a node before you upgrade it.
+* Upgrade the packages on all nodes, one node at a time, before you reboot any
+  node or enable the maintenance mode.
+
+The check covers migrations and clones started on a node running {pve} 9.3 or
+later. It does not cover:
+
+* the HA recovery of guests from a fenced node,
+* configuration files moved by hand,
+* operations started on a node with an older version.
+
+If an older node writes the configuration of a guest in one of these cases, the
+guest loses its `meta` property. In an HA recovery, such a node can also be the
+node of the active HA manager (CRM), which writes the configuration when it
+removes a leftover lock, for example of a backup. The guest gets a new identity
+the next time a node running {pve} 9.3 or later writes its configuration.
+
+Backups made with {pve} 9.3 or later contain the guest identity. Restore them
+only on nodes running {pve} 9.3 or later, because older versions ignore the
+`meta` property of such backups in the same way.
+
 [[vzdump_configuration]]
 Configuration
 -------------
-- 
2.47.3





^ permalink raw reply related	[relevance 17%]

* [PATCH qemu-server v4 16/41] fix #7846: config: add a guest identity to the 'meta' property
  2026-11-19 10:33 17% [PATCH cluster/guest-common/qemu-server/container/manager/docs v4 00/41] " Thomas Lamprecht
  2026-11-19 10:33 22% ` [PATCH guest-common v4 08/41] guest identity: add helpers for the guest uid and registration time Thomas Lamprecht
@ 2026-11-19 10:34 16% ` Thomas Lamprecht
  2026-11-19 10:34 17% ` [PATCH docs v4 37/41] vzdump: describe the guest identity of VMs and containers Thomas Lamprecht
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 32+ results
From: Thomas Lamprecht @ 2026-11-19 10:34 UTC (permalink / raw)
  To: pve-devel

Give VMs a guest identity in the read-only 'meta' property: a random
identifier, 'uid', and a registration time, 'rtime'. Tools can use it
to recognize a guest across restores and migrations, independently of
its VMID.

Enable the identity handling of the config class, so that each config
write keeps the identity a VM already has or assigns one if it has
none. New VMs, clones and imports get an identity when their VMID is
reserved. Existing VMs get one with their next config write. A stale
config, a clone source or a snapshot rollback cannot replace the
identity of a VM.

The other members of 'meta' behave as before. A config without creation
information thus gets a 'meta' property with only the identity. Older
qemu-server versions reject the new members and drop the whole property
on their next config write.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
---

changes v3 -> v4:
* tests: 'create' and 'clone' call the API handlers instead of repeating
  their config writes, and cases that only checked the schema parser are
  gone
* the identity parts of the fake cluster filesystem come with this
  patch, its base is in an independent test commit before the series
* rebase onto current master (tests only)

changes v2 -> v3:
* group the imports of the new test script

changes v1 -> v2:
* rebase, adapt the tests

 src/PVE/QemuConfig.pm                         |   7 +
 src/PVE/QemuServer/MetaInfo.pm                |   2 +
 src/test/Makefile                             |   5 +-
 src/test/QemuServerTest/FakeCFS.pm            |  84 +++++-
 .../q35-windows-pinning-identity-only.conf    |   6 +
 ...q35-windows-pinning-identity-only.conf.cmd |  26 ++
 .../meta-identity-invalid.conf                |   6 +
 .../meta-identity-invalid.conf.strict.error   |   2 +
 .../meta-identity-invalid.conf                |   7 +
 .../parse-config-input/meta-identity.conf     |  20 ++
 src/test/run_guest_identity_tests.pl          | 275 ++++++++++++++++++
 src/test/run_parse_config_tests.pl            |   2 +-
 src/test/run_qemu_restore_config_tests.pl     |   3 +-
 .../create/qemu-server/401.conf               |  31 ++
 .../create/qemu-server/402.conf               |  31 ++
 .../rollback/qemu-server/401.conf             |  36 +++
 .../rollback/qemu-server/402.conf             |  35 +++
 .../create/qemu-server/401.conf               |  13 +
 .../create/qemu-server/402.conf               |  13 +
 .../rollback/qemu-server/401.conf             |  35 +++
 .../rollback/qemu-server/402.conf             |  34 +++
 src/test/snapshot-test.pm                     |  82 +++++-
 22 files changed, 738 insertions(+), 17 deletions(-)
 create mode 100644 src/test/cfg2cmd/q35-windows-pinning-identity-only.conf
 create mode 100644 src/test/cfg2cmd/q35-windows-pinning-identity-only.conf.cmd
 create mode 100644 src/test/parse-config-expected/meta-identity-invalid.conf
 create mode 100644 src/test/parse-config-expected/meta-identity-invalid.conf.strict.error
 create mode 100644 src/test/parse-config-input/meta-identity-invalid.conf
 create mode 100644 src/test/parse-config-input/meta-identity.conf
 create mode 100755 src/test/run_guest_identity_tests.pl
 create mode 100644 src/test/snapshot-expected/create/qemu-server/401.conf
 create mode 100644 src/test/snapshot-expected/create/qemu-server/402.conf
 create mode 100644 src/test/snapshot-expected/rollback/qemu-server/401.conf
 create mode 100644 src/test/snapshot-expected/rollback/qemu-server/402.conf
 create mode 100644 src/test/snapshot-input/create/qemu-server/401.conf
 create mode 100644 src/test/snapshot-input/create/qemu-server/402.conf
 create mode 100644 src/test/snapshot-input/rollback/qemu-server/401.conf
 create mode 100644 src/test/snapshot-input/rollback/qemu-server/402.conf

diff --git a/src/PVE/QemuConfig.pm b/src/PVE/QemuConfig.pm
index 6656c137..e7adfbfb 100644
--- a/src/PVE/QemuConfig.pm
+++ b/src/PVE/QemuConfig.pm
@@ -672,6 +672,13 @@ sub write_config {
     return $class->SUPER::write_config($vmid, $conf);
 }
 
+# the format of the 'meta' property includes the guest identity, see PVE::QemuServer::MetaInfo
+sub __identity_enabled {
+    my ($class) = @_;
+
+    return 1;
+}
+
 # END implemented abstract methods from PVE::AbstractConfig
 
 sub has_cloudinit {
diff --git a/src/PVE/QemuServer/MetaInfo.pm b/src/PVE/QemuServer/MetaInfo.pm
index b69e5a1c..399cd920 100644
--- a/src/PVE/QemuServer/MetaInfo.pm
+++ b/src/PVE/QemuServer/MetaInfo.pm
@@ -3,6 +3,7 @@ package PVE::QemuServer::MetaInfo;
 use strict;
 use warnings;
 
+use PVE::GuestIdentity;
 use PVE::JSONSchema;
 
 use PVE::QemuServer::Helpers;
@@ -20,6 +21,7 @@ our $meta_info_fmt = {
         pattern => '\d+(\.\d+)+',
         optional => 1,
     },
+    PVE::GuestIdentity::meta_format_properties()->%*,
 };
 
 sub parse_meta_info {
diff --git a/src/test/Makefile b/src/test/Makefile
index 7cd88247..0d47205d 100644
--- a/src/test/Makefile
+++ b/src/test/Makefile
@@ -1,6 +1,6 @@
 all: test
 
-test: test_snapshot test_cfg_to_cmd test_cfg_to_cmd_aarch64 test_hotplug test_hotplug_aarch64 test_pci_addr_conflicts test_pci_reservation test_qemu_img_convert test_migration test_restore_config test_parse_config test_memory test_agent test_raw_config_write test_api test_api_cloudinit_dump test_mtunnel
+test: test_snapshot test_cfg_to_cmd test_cfg_to_cmd_aarch64 test_hotplug test_hotplug_aarch64 test_pci_addr_conflicts test_pci_reservation test_qemu_img_convert test_migration test_restore_config test_parse_config test_memory test_agent test_raw_config_write test_api test_api_cloudinit_dump test_mtunnel test_guest_identity
 
 test_snapshot: run_snapshot_tests.pl
 	./run_snapshot_tests.pl
@@ -60,6 +60,9 @@ test_api_cloudinit_dump: run_api_cloudinit_dump_tests.pl
 test_mtunnel: run_mtunnel_tests.pl QemuServerTest/FakeCFS.pm QemuServerTest/MTunnel.pm
 	./run_mtunnel_tests.pl
 
+test_guest_identity: run_guest_identity_tests.pl QemuServerTest/FakeCFS.pm
+	./run_guest_identity_tests.pl
+
 .PHONY: clean
 clean:
 	rm -rf MigrationTest/run
diff --git a/src/test/QemuServerTest/FakeCFS.pm b/src/test/QemuServerTest/FakeCFS.pm
index c5609892..a9949d63 100644
--- a/src/test/QemuServerTest/FakeCFS.pm
+++ b/src/test/QemuServerTest/FakeCFS.pm
@@ -1,10 +1,12 @@
 package QemuServerTest::FakeCFS;
 
 # Fake cluster filesystem for VM config files, so that tests can use the real config class methods
-# of PVE::QemuConfig without pmxcfs.
+# of PVE::QemuConfig, including the guest identity handling of write_config, without pmxcfs.
 #
 # Configs are kept as raw text, indexed by VMID, and an empty file at the path that config_file()
-# returns exists for each, for checks of the file's existence.
+# returns exists for each, for checks of the file's existence. Generated guest identities are
+# deterministic: the n-th generated uid is 'a' repeated 17 times followed by the base32 encoding of
+# n, and rtime is $now_ms.
 
 use v5.36;
 
@@ -15,10 +17,15 @@ use Test::MockModule;
 
 use PVE::GuestHelpers;
 use PVE::GuestID;
+use PVE::GuestIdentity;
 use PVE::QemuConfig;
 use PVE::QemuServer;
 
 our $configs = {}; # VMID => raw config, for VMs on the local node
+our $other_guests = {}; # VMID => raw 'meta' property of other guests, like on other nodes or CTs
+our $now_ms = 1700000000000;
+our $generated = 0;
+our $lock_domain_error;
 our $written = {}; # VMID => the written raw configs, in the order of the writes
 
 my $tmpdir = tempdir('fake-cfs-XXXXXX', DIR => '.', CLEANUP => 1);
@@ -28,6 +35,10 @@ $PVE::GuestHelpers::lockdir = "$tmpdir/lock";
 sub reset() {
     remove_tree("$tmpdir/etc-pve");
     $configs = {};
+    $other_guests = {};
+    $now_ms = 1700000000000;
+    $generated = 0;
+    $lock_domain_error = undef;
     $written = {};
 }
 
@@ -53,12 +64,55 @@ sub set_config($vmid, $raw) {
     sync_config_file($vmid);
 }
 
+# Returns the last 'meta' property of the top-level section of the raw config $raw, like the config
+# class reads the stored identity.
+my sub top_level_meta($raw) {
+    my $meta;
+    for my $line (split(/\n/, $raw // '')) {
+        last if $line =~ m/^\[/;
+        # like pmxcfs, a line with nothing after the colon does not count
+        $meta = $1 =~ s/^\s+|\s+$//gr if $line =~ m/^meta:(.+)$/;
+    }
+
+    return $meta;
+}
+
+# Returns the identity stored in the raw config of $vmid, undef if there is none.
+sub stored_identity($vmid) {
+    return PVE::GuestIdentity::parse_identity(top_level_meta($configs->{$vmid}));
+}
+
+# Returns the uid that the $n-th generation of an identity yields.
+sub generated_uid($n) {
+    my $alphabet = 'abcdefghijklmnopqrstuvwxyz234567';
+    return ('a' x 17) . join('', map { substr($alphabet, ($n >> (5 * $_)) & 31, 1) } (2, 1, 0));
+}
+
 # the list of used guest IDs is not part of the fake cluster filesystem
 our $guest_id_module = Test::MockModule->new('PVE::GuestID');
 $guest_id_module->mock(register_used_id => sub { return; });
 
+our $guest_identity_module = Test::MockModule->new('PVE::GuestIdentity');
+$guest_identity_module->mock(
+    __random_bytes => sub {
+        my ($len) = @_;
+        die "unexpected length $len\n" if $len != 20;
+        $generated++;
+        # one byte per uid character, the last three hold 5 bits of the counter each
+        return ("\0" x 17) . pack('C3', map { ($generated >> $_) & 31 } (10, 5, 0));
+    },
+    __time_ms => sub {
+        return $now_ms;
+    },
+);
+
 our $cluster_module = Test::MockModule->new('PVE::Cluster');
 $cluster_module->mock(
+    get_config => sub {
+        my ($path) = @_;
+        my $vmid = vmid_of_path($path) // die "get_config (mocked) - unexpected path '$path'\n";
+        return $configs->{$vmid};
+    },
     cfs_read_file => sub {
         my ($path) = @_;
         return {} if $path eq 'datacenter.cfg';
@@ -80,10 +134,34 @@ $cluster_module->mock(
     },
     check_vmid_unused => sub {
         my ($vmid, $noerr) = @_;
-        return 1 if !defined($configs->{$vmid});
+        return 1 if !defined($configs->{$vmid}) && !defined($other_guests->{$vmid});
         return undef if $noerr;
         die "VM $vmid already exists\n";
     },
+    cfs_lock_domain => sub {
+        my ($domain, $timeout, $code, @param) = @_;
+        die "cfs_lock_domain (mocked) - unexpected domain '$domain'\n"
+            if $domain ne 'guest-identity';
+        if ($lock_domain_error) {
+            $@ = $lock_domain_error;
+            return undef;
+        }
+        my $res = eval { $code->(@param) };
+        return $res;
+    },
+    get_guest_config_properties => sub {
+        my ($properties) = @_;
+        die "get_guest_config_properties (mocked) - unexpected properties\n"
+            if join(',', $properties->@*) ne 'meta';
+
+        my $res = {};
+        for my $vmid (keys $configs->%*) {
+            my $meta = top_level_meta($configs->{$vmid});
+            $res->{$vmid} = { meta => $meta } if defined($meta);
+        }
+        $res->{$_} = { meta => $other_guests->{$_} } for keys $other_guests->%*;
+        return $res;
+    },
 );
 
 our $qemu_config_module = Test::MockModule->new('PVE::QemuConfig');
diff --git a/src/test/cfg2cmd/q35-windows-pinning-identity-only.conf b/src/test/cfg2cmd/q35-windows-pinning-identity-only.conf
new file mode 100644
index 00000000..5242ec13
--- /dev/null
+++ b/src/test/cfg2cmd/q35-windows-pinning-identity-only.conf
@@ -0,0 +1,6 @@
+# TEST: Windows without pinned machine and with only the guest identity as meta info stays on 5.1
+machine: q35
+meta: rtime=1762300000000,uid=abcdefghijklmnopqrst
+ostype: win11
+smbios1: uuid=7b10d7af-b932-4c66-b2c3-3996152ec465
+vmgenid: c773c261-d800-4348-9f5d-167fadd53cf8
diff --git a/src/test/cfg2cmd/q35-windows-pinning-identity-only.conf.cmd b/src/test/cfg2cmd/q35-windows-pinning-identity-only.conf.cmd
new file mode 100644
index 00000000..67d20b79
--- /dev/null
+++ b/src/test/cfg2cmd/q35-windows-pinning-identity-only.conf.cmd
@@ -0,0 +1,26 @@
+/usr/bin/kvm \
+  -id 8006 \
+  -name vm8006 \
+  -no-shutdown \
+  -chardev 'socket,id=qmp,path=/var/run/qemu-server/8006.qmp,server=on,wait=off' \
+  -object 'monitor-qmp,chardev=qmp,id=monitor-qmp' \
+  -chardev 'socket,id=qmp-event,path=/var/run/qmeventd.sock,reconnect-ms=5000' \
+  -object 'monitor-qmp,chardev=qmp-event,id=monitor-qmp-event' \
+  -pidfile /var/run/qemu-server/8006.pid \
+  -daemonize \
+  -smbios 'type=1,uuid=7b10d7af-b932-4c66-b2c3-3996152ec465' \
+  -smp '1,sockets=1,cores=1,maxcpus=1' \
+  -nodefaults \
+  -boot 'menu=on,strict=on,reboot-timeout=1000,splash=/usr/share/qemu-server/bootsplash.jpg' \
+  -vnc 'unix:/var/run/qemu-server/8006.vnc,password=on' \
+  -global 'kvm-pit.lost_tick_policy=discard' \
+  -cpu 'kvm64,-cet-ibt,-cet-ss,enforce,hv_ipi,hv_relaxed,hv_reset,hv_runtime,hv_spinlocks=0x1fff,hv_stimer,hv_synic,hv_time,hv_vapic,hv_vpindex,+kvm_pv_eoi,+kvm_pv_unhalt,+lahf_lm,+sep' \
+  -m 512 \
+  -readconfig /usr/share/qemu-server/pve-q35-4.0.cfg \
+  -device 'vmgenid,guid=c773c261-d800-4348-9f5d-167fadd53cf8' \
+  -device 'usb-tablet,id=tablet,bus=ehci.0,port=1' \
+  -device 'VGA,id=vga,bus=pcie.0,addr=0x1,edid=off' \
+  -device 'virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3' \
+  -iscsi 'initiator-name=iqn.1993-08.org.debian:01:aabbccddeeff' \
+  -rtc 'driftfix=slew,base=localtime' \
+  -machine 'hpet=off,type=pc-q35-5.1+pve0'
diff --git a/src/test/parse-config-expected/meta-identity-invalid.conf b/src/test/parse-config-expected/meta-identity-invalid.conf
new file mode 100644
index 00000000..195514fa
--- /dev/null
+++ b/src/test/parse-config-expected/meta-identity-invalid.conf
@@ -0,0 +1,6 @@
+# VM with a guest uid that is not valid
+boot: order=scsi0
+cores: 2
+memory: 4096
+name: identity
+scsi0: local-lvm:vm-8006-disk-0,size=32G
diff --git a/src/test/parse-config-expected/meta-identity-invalid.conf.strict.error b/src/test/parse-config-expected/meta-identity-invalid.conf.strict.error
new file mode 100644
index 00000000..ae584c1f
--- /dev/null
+++ b/src/test/parse-config-expected/meta-identity-invalid.conf.strict.error
@@ -0,0 +1,2 @@
+vm 8006 - unable to parse value of 'meta' - format error
+uid: value does not match the regex pattern
diff --git a/src/test/parse-config-input/meta-identity-invalid.conf b/src/test/parse-config-input/meta-identity-invalid.conf
new file mode 100644
index 00000000..90e60197
--- /dev/null
+++ b/src/test/parse-config-input/meta-identity-invalid.conf
@@ -0,0 +1,7 @@
+# VM with a guest uid that is not valid
+boot: order=scsi0
+cores: 2
+memory: 4096
+meta: creation-qemu=10.1.2,ctime=1762000000,rtime=1762000000123,uid=ABCDEFGHIJKLMNOPQRST
+name: identity
+scsi0: local-lvm:vm-8006-disk-0,size=32G
diff --git a/src/test/parse-config-input/meta-identity.conf b/src/test/parse-config-input/meta-identity.conf
new file mode 100644
index 00000000..7a1e03be
--- /dev/null
+++ b/src/test/parse-config-input/meta-identity.conf
@@ -0,0 +1,20 @@
+# VM with guest identity
+boot: order=scsi0
+cores: 2
+memory: 4096
+meta: creation-qemu=10.1.2,ctime=1762000000,rtime=1762000000123,uid=abcdefghijklmnopqrst
+name: identity
+scsi0: local-lvm:vm-8006-disk-0,size=32G
+scsihw: virtio-scsi-single
+smbios1: uuid=7b4f2a1e-3c2d-4e5f-8a9b-0c1d2e3f4a5b
+
+[snap]
+boot: order=scsi0
+cores: 2
+memory: 4096
+meta: creation-qemu=10.1.2,ctime=1762000000,rtime=1762000000123,uid=abcdefghijklmnopqrst
+name: identity
+scsi0: local-lvm:vm-8006-disk-0,size=32G
+scsihw: virtio-scsi-single
+smbios1: uuid=7b4f2a1e-3c2d-4e5f-8a9b-0c1d2e3f4a5b
+snaptime: 1762000100
diff --git a/src/test/run_guest_identity_tests.pl b/src/test/run_guest_identity_tests.pl
new file mode 100755
index 00000000..3eec153f
--- /dev/null
+++ b/src/test/run_guest_identity_tests.pl
@@ -0,0 +1,275 @@
+#!/usr/bin/perl
+
+# Tests the guest identity of VM configs through the real config class methods, with a fake cluster
+# filesystem, see QemuServerTest::FakeCFS.
+
+use v5.36;
+
+use lib qw(.. .);
+
+use File::Temp qw(tempdir);
+use Test::MockModule;
+use Test::More;
+
+use PVE::JSONSchema;
+use PVE::RPCEnvironment;
+
+use PVE::QemuConfig;
+use PVE::QemuConfig::NoWrite;
+use PVE::QemuServer;
+use PVE::QemuServer::MetaInfo;
+
+use PVE::API2::Qemu;
+
+use QemuServerTest::FakeCFS;
+use QemuServerTest::Utils qw(capture_output);
+
+my $UID_A = 'abcdefghijklmnopqrst';
+my $UID_B = 'bbbbbbbbbbbbbbbbbbbb';
+
+my $helpers_module = Test::MockModule->new('PVE::QemuServer::Helpers');
+$helpers_module->mock(kvm_user_version => sub { return '10.1.2'; });
+
+my $rpcenv = PVE::RPCEnvironment->init('cli');
+$rpcenv->set_user('root@pam');
+
+my $rpcenv_module = Test::MockModule->new('PVE::RPCEnvironment');
+$rpcenv_module->mock(
+    check => sub { return 1; },
+    check_vm_perm => sub { return 1; },
+    fork_worker => sub {
+        my ($self, $type, $id, $user, $code) = @_;
+        $code->('UPID:test');
+        return 'UPID:test';
+    },
+);
+$QemuServerTest::FakeCFS::cluster_module->mock(check_cfs_quorum => sub { return 1; });
+my $network_module = Test::MockModule->new('PVE::QemuServer::Network');
+$network_module->mock(create_ifaces_ipams_ips => sub { return; });
+
+sub configs { return $QemuServerTest::FakeCFS::configs; }
+sub generated_uid { return QemuServerTest::FakeCFS::generated_uid(@_); }
+sub stored_identity { return QemuServerTest::FakeCFS::stored_identity(@_); }
+
+sub load_meta($vmid) {
+    return PVE::QemuServer::MetaInfo::parse_meta_info(PVE::QemuConfig->load_config($vmid)->{meta});
+}
+
+subtest 'meta format' => sub {
+    my $meta =
+        'creation-qemu=10.1.2,ctime=1700000000,rtime=1700000000123,uid=abcdefghijklmnopqrst';
+
+    is_deeply(
+        PVE::QemuServer::MetaInfo::parse_meta_info($meta),
+        {
+            'creation-qemu' => '10.1.2',
+            ctime => 1700000000,
+            rtime => 1700000000123,
+            uid => $UID_A,
+        },
+        'identity members get parsed',
+    );
+    is(
+        PVE::JSONSchema::print_property_string(
+            PVE::QemuServer::MetaInfo::parse_meta_info($meta),
+            $PVE::QemuServer::MetaInfo::meta_info_fmt,
+        ),
+        $meta,
+        'printing the parsed property gives the same string',
+    );
+};
+
+subtest 'identities are enabled, but not for writing temporary configs' => sub {
+    QemuServerTest::FakeCFS::reset();
+
+    ok(PVE::QemuConfig->__identity_enabled(), 'enabled for PVE::QemuConfig');
+
+    my $conf = { name => 'template-cmd' };
+    PVE::QemuConfig::NoWrite->mark_config($conf);
+    eval { PVE::QemuConfig->write_config(100, $conf) };
+    is($@, "refusing to write temporary configuration\n", 'NoWrite refuses');
+    eval { PVE::QemuConfig::NoWrite->write_config(100, $conf) };
+    is(
+        $@,
+        "refusing to write temporary configuration\n",
+        'NoWrite refuses when called directly',
+    );
+    is_deeply(configs(), {}, 'nothing written');
+    is($QemuServerTest::FakeCFS::generated, 0, 'no identity generated');
+};
+
+subtest 'config writes keep the stored identity' => sub {
+    QemuServerTest::FakeCFS::reset();
+
+    PVE::QemuConfig->write_config(100, { memory => 512, meta => "rtime=1,uid=$UID_B" });
+    is_deeply(
+        stored_identity(100),
+        { uid => generated_uid(1), rtime => 1700000000000 },
+        'first write ignores a carried identity and generates one',
+    );
+    like(configs()->{100}, qr/^meta: rtime=1700000000000,uid=\w+$/m,
+        'written as meta property');
+
+    $QemuServerTest::FakeCFS::now_ms = 1800000000000;
+
+    my $conf = PVE::QemuConfig->load_config(100);
+    $conf->{meta} = "creation-qemu=9.2.0,ctime=1600000000,rtime=1,uid=$UID_B";
+    PVE::QemuConfig->write_config(100, $conf);
+    is_deeply(
+        load_meta(100),
+        {
+            'creation-qemu' => '9.2.0',
+            ctime => 1600000000,
+            rtime => 1700000000000,
+            uid => generated_uid(1),
+        },
+        'foreign identity replaced by the stored one, other members kept',
+    );
+
+    $conf = PVE::QemuConfig->load_config(100);
+    delete $conf->{meta};
+    PVE::QemuConfig->write_config(100, $conf);
+    is_deeply(
+        load_meta(100),
+        { rtime => 1700000000000, uid => generated_uid(1) },
+        'identity kept when the property is gone',
+    );
+
+    configs()->{101} = "memory: 512\nmeta: creation-qemu=8.0.2,ctime=1500000000\n";
+    $conf = PVE::QemuConfig->load_config(101);
+    $conf->{name} = 'old';
+    PVE::QemuConfig->write_config(101, $conf);
+    is_deeply(
+        load_meta(101),
+        {
+            'creation-qemu' => '8.0.2',
+            ctime => 1500000000,
+            rtime => 1800000000000,
+            uid => generated_uid(2),
+        },
+        'existing guest without identity gets one on its first write',
+    );
+};
+
+subtest 'create' => sub {
+    QemuServerTest::FakeCFS::reset();
+
+    my $storage_module = Test::MockModule->new('PVE::Storage');
+    $storage_module->mock(config => sub { return {}; });
+    my $replication_state_module = Test::MockModule->new('PVE::ReplicationState');
+    $replication_state_module->mock(delete_guest_states => sub { return; });
+
+    capture_output(sub {
+        PVE::API2::Qemu->create_vm({ node => 'localhost', vmid => 100, memory => 512 });
+    });
+
+    my $reserved = $QemuServerTest::FakeCFS::written->{100}->[0];
+    like(
+        $reserved,
+        qr/^meta: rtime=1700000000000,uid=\w+$/m,
+        'reservation stores a new identity',
+    );
+    my $meta = load_meta(100);
+    is_deeply(
+        [$meta->@{qw(creation-qemu uid rtime)}],
+        ['10.1.2', generated_uid(1), 1700000000000],
+        'final config keeps the reserved identity next to the creation info',
+    );
+    ok($meta->{ctime}, 'creation time set');
+};
+
+subtest 'clone' => sub {
+    QemuServerTest::FakeCFS::reset();
+
+    my $disk = "scsi0: local:100/vm-100-disk-0.raw,size=4G\n";
+    my $source = "memory: 512\nmeta: creation-qemu=9.2.0,ctime=1600000000,"
+        . "rtime=1600000000000,uid=$UID_A\nname: source\n$disk";
+    # a snapshot can carry any identity
+    configs()->{100} =
+        "$source\n[snap]\nmemory: 256\nmeta: rtime=1,uid=$UID_B\n${disk}snaptime: 1600000001\n";
+
+    my $storage_module = Test::MockModule->new('PVE::Storage');
+    $storage_module->mock(
+        activate_volumes => sub { return; },
+        config => sub {
+            return {
+                ids => {
+                    local =>
+                        { type => 'dir', path => '/var/lib/vz', content => { images => 1 } },
+                },
+            };
+        },
+        deactivate_volumes => sub { return; },
+        get_bandwidth_limit => sub { return undef; },
+        volume_has_feature => sub { return 1; },
+    );
+    my $qemu_server_module = Test::MockModule->new('PVE::QemuServer');
+    $qemu_server_module->mock(
+        check_running => sub { return 0; },
+        clone_disk => sub {
+            my ($storecfg, $source, $dest) = @_;
+            return { file => "local:$dest->{vmid}/vm-$dest->{vmid}-disk-0.raw", size => '4G' };
+        },
+    );
+    my $firewall_module = Test::MockModule->new('PVE::Firewall');
+    $firewall_module->mock(clone_vmfw_conf => sub { return; });
+
+    my $output = capture_output(sub {
+        PVE::API2::Qemu->clone_vm({ node => 'localhost', vmid => 100, newid => 300 });
+        PVE::API2::Qemu->clone_vm(
+            { node => 'localhost', vmid => 100, newid => 301, snapname => 'snap' });
+    });
+
+    is(stored_identity(300)->{uid}, generated_uid(1), 'clone has a new uid');
+    is_deeply(
+        load_meta(300),
+        {
+            'creation-qemu' => '9.2.0',
+            ctime => 1600000000,
+            rtime => 1700000000000,
+            uid => generated_uid(1),
+        },
+        'clone keeps the creation info of its source',
+    );
+    is_deeply(
+        load_meta(301),
+        { rtime => 1700000000000, uid => generated_uid(2) },
+        'clone of a snapshot has a new uid as well',
+    );
+    is(stored_identity(100)->{uid}, $UID_A, 'source keeps its uid');
+};
+
+subtest 'importovf' => sub {
+    QemuServerTest::FakeCFS::reset();
+
+    require PVE::CLI::qm;
+
+    my $tmpdir = tempdir('importovf-XXXXXX', DIR => '.', CLEANUP => 1);
+    my $manifest = "$tmpdir/test.ovf";
+    PVE::Tools::file_set_contents($manifest, "<ovf/>\n");
+
+    my $storage_module = Test::MockModule->new('PVE::Storage');
+    $storage_module->mock(
+        config => sub { return {}; },
+        storage_check_enabled => sub { return {}; },
+    );
+    my $ovf_module = Test::MockModule->new('PVE::GuestImport::OVF');
+    $ovf_module->mock(
+        parse_ovf => sub {
+            return { qm => { name => 'imported', memory => 1024, cores => 2 }, disks => [] };
+        },
+    );
+
+    PVE::CLI::qm->importovf({ vmid => 100, manifest => $manifest, storage => 'local' });
+
+    my $conf = PVE::QemuConfig->load_config(100);
+    is($conf->{name}, 'imported', 'config imported');
+    ok(!defined($conf->{lock}), 'create lock removed');
+    is_deeply(
+        stored_identity(100),
+        { uid => generated_uid(1), rtime => 1700000000000 },
+        'imported VM got a new identity on reservation and kept it',
+    );
+};
+
+done_testing();
diff --git a/src/test/run_parse_config_tests.pl b/src/test/run_parse_config_tests.pl
index c30aad99..566eec4f 100755
--- a/src/test/run_parse_config_tests.pl
+++ b/src/test/run_parse_config_tests.pl
@@ -25,7 +25,7 @@ my $INPUT_DIR = './parse-config-input';
 my $EXPECTED_DIR = './parse-config-expected';
 
 # NOTE update when you add/remove tests
-plan tests => 2 * 11;
+plan tests => 2 * 13;
 
 sub run_tests {
     my ($strict) = @_;
diff --git a/src/test/run_qemu_restore_config_tests.pl b/src/test/run_qemu_restore_config_tests.pl
index f5f9e026..4e2bc798 100755
--- a/src/test/run_qemu_restore_config_tests.pl
+++ b/src/test/run_qemu_restore_config_tests.pl
@@ -312,7 +312,8 @@ sub restore_api {
     return ($err, $output);
 }
 
-my $TARGET_CONF = "memory: 1024\nmeta: creation-qemu=10.0.0,ctime=1700000000\nname: target\n";
+my $TARGET_CONF = "memory: 1024\nmeta: creation-qemu=10.0.0,ctime=1700000000,"
+    . "rtime=1700000000000,uid=tttttttttttttttttttt\nname: target\n";
 my $NOT_CLEANED_UP = qr/VM 100 state is NOT cleaned up/;
 my $KEPT_LOCKED = 'WARN: keeping VM 100 locked, the cleanup left behind';
 
diff --git a/src/test/snapshot-expected/create/qemu-server/401.conf b/src/test/snapshot-expected/create/qemu-server/401.conf
new file mode 100644
index 00000000..87aadf80
--- /dev/null
+++ b/src/test/snapshot-expected/create/qemu-server/401.conf
@@ -0,0 +1,31 @@
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+memory: 8192
+meta: creation-qemu=10.0.0,ctime=1700000000,rtime=1700000000000,uid=abcdefghijklmnopqrst
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+parent: test
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+sockets: 1
+vga: qxl
+
+[test]
+#test comment
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+memory: 8192
+meta: creation-qemu=10.0.0,ctime=1700000000,rtime=1700000000000,uid=abcdefghijklmnopqrst
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+snaptime: 1234567890
+sockets: 1
+vga: qxl
diff --git a/src/test/snapshot-expected/create/qemu-server/402.conf b/src/test/snapshot-expected/create/qemu-server/402.conf
new file mode 100644
index 00000000..976c0a39
--- /dev/null
+++ b/src/test/snapshot-expected/create/qemu-server/402.conf
@@ -0,0 +1,31 @@
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+memory: 8192
+meta: creation-qemu=8.0.2,ctime=1600000000,rtime=1234567890123,uid=qrstuvwxyzbcdefghijk
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+parent: test
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+sockets: 1
+vga: qxl
+
+[test]
+#test comment
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+memory: 8192
+meta: creation-qemu=8.0.2,ctime=1600000000
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+snaptime: 1234567890
+sockets: 1
+vga: qxl
diff --git a/src/test/snapshot-expected/rollback/qemu-server/401.conf b/src/test/snapshot-expected/rollback/qemu-server/401.conf
new file mode 100644
index 00000000..6215ce26
--- /dev/null
+++ b/src/test/snapshot-expected/rollback/qemu-server/401.conf
@@ -0,0 +1,36 @@
+# this is a description
+agent: 1
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+memory: 8192
+meta: creation-qemu=9.2.0,ctime=1600000000,rtime=1700000000000,uid=abcdefghijklmnopqrst
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+parent: test
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+sockets: 1
+vga: qxl
+
+[test]
+#test comment
+agent: 1
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+machine: q35
+memory: 8192
+meta: creation-qemu=9.2.0,ctime=1600000000,rtime=1600000000000,uid=bbbbbbbbbbbbbbbbbbbb
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+snaptime: 1234567890
+sockets: 1
+vga: qxl
+vmstate: somestorage:state-volume
diff --git a/src/test/snapshot-expected/rollback/qemu-server/402.conf b/src/test/snapshot-expected/rollback/qemu-server/402.conf
new file mode 100644
index 00000000..a10bfa13
--- /dev/null
+++ b/src/test/snapshot-expected/rollback/qemu-server/402.conf
@@ -0,0 +1,35 @@
+# this is a description
+agent: 1
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+memory: 8192
+meta: rtime=1700000000000,uid=abcdefghijklmnopqrst
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+parent: test
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+sockets: 1
+vga: qxl
+
+[test]
+#test comment
+agent: 1
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+machine: q35
+memory: 8192
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+snaptime: 1234567890
+sockets: 1
+vga: qxl
+vmstate: somestorage:state-volume
diff --git a/src/test/snapshot-input/create/qemu-server/401.conf b/src/test/snapshot-input/create/qemu-server/401.conf
new file mode 100644
index 00000000..41ccdae5
--- /dev/null
+++ b/src/test/snapshot-input/create/qemu-server/401.conf
@@ -0,0 +1,13 @@
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+memory: 8192
+meta: creation-qemu=10.0.0,ctime=1700000000,rtime=1700000000000,uid=abcdefghijklmnopqrst
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+sockets: 1
+vga: qxl
diff --git a/src/test/snapshot-input/create/qemu-server/402.conf b/src/test/snapshot-input/create/qemu-server/402.conf
new file mode 100644
index 00000000..e03717b6
--- /dev/null
+++ b/src/test/snapshot-input/create/qemu-server/402.conf
@@ -0,0 +1,13 @@
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+memory: 8192
+meta: creation-qemu=8.0.2,ctime=1600000000
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+sockets: 1
+vga: qxl
diff --git a/src/test/snapshot-input/rollback/qemu-server/401.conf b/src/test/snapshot-input/rollback/qemu-server/401.conf
new file mode 100644
index 00000000..7895e0df
--- /dev/null
+++ b/src/test/snapshot-input/rollback/qemu-server/401.conf
@@ -0,0 +1,35 @@
+# this is a description
+agent: 1
+bootdisk: ide2
+cores: 2
+ide0: local:snapshotable-disk-1,size=32G
+ide2: none,media=cdrom
+memory: 4096
+meta: creation-qemu=10.0.0,ctime=1700000000,rtime=1700000000000,uid=abcdefghijklmnopqrst
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+parent: test
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+sockets: 2
+
+[test]
+#test comment
+agent: 1
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+machine: q35
+memory: 8192
+meta: creation-qemu=9.2.0,ctime=1600000000,rtime=1600000000000,uid=bbbbbbbbbbbbbbbbbbbb
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+snaptime: 1234567890
+sockets: 1
+vga: qxl
+vmstate: somestorage:state-volume
diff --git a/src/test/snapshot-input/rollback/qemu-server/402.conf b/src/test/snapshot-input/rollback/qemu-server/402.conf
new file mode 100644
index 00000000..0fa7fe51
--- /dev/null
+++ b/src/test/snapshot-input/rollback/qemu-server/402.conf
@@ -0,0 +1,34 @@
+# this is a description
+agent: 1
+bootdisk: ide2
+cores: 2
+ide0: local:snapshotable-disk-1,size=32G
+ide2: none,media=cdrom
+memory: 4096
+meta: creation-qemu=10.0.0,ctime=1700000000,rtime=1700000000000,uid=abcdefghijklmnopqrst
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+parent: test
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+sockets: 2
+
+[test]
+#test comment
+agent: 1
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+machine: q35
+memory: 8192
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+snaptime: 1234567890
+sockets: 1
+vga: qxl
+vmstate: somestorage:state-volume
diff --git a/src/test/snapshot-test.pm b/src/test/snapshot-test.pm
index b5269538..4e7fccdb 100644
--- a/src/test/snapshot-test.pm
+++ b/src/test/snapshot-test.pm
@@ -7,6 +7,7 @@ use lib qw(..);
 
 use JSON;
 
+use PVE::GuestHelpers;
 use PVE::Storage;
 use PVE::Storage::Plugin;
 use PVE::QemuServer;
@@ -33,6 +34,9 @@ my $stop_possible;
 my $save_vmstate_works;
 my $vm_mon = {};
 my $vm_start_sync_time;
+my $real_write_config;
+
+my $original_write_config = \&PVE::QemuConfig::write_config;
 
 # Mocked methods
 
@@ -312,6 +316,13 @@ sub cfs_config_path {
     return "snapshot-working/$node/qemu-server/$vmid.conf";
 }
 
+# the same file that mocked_get_config reads, so that nothing looks at the host's /etc/pve
+sub config_file {
+    my ($class, $vmid, $node) = @_;
+
+    return $class->cfs_config_path($vmid, $node);
+}
+
 sub load_config {
     my ($class, $vmid, $node) = @_;
 
@@ -326,18 +337,10 @@ sub load_config {
 sub write_config {
     my ($class, $vmid, $conf) = @_;
 
-    my $filename = $class->cfs_config_path($vmid);
-
-    if ($conf->{snapshots}) {
-        foreach my $snapname (keys %{ $conf->{snapshots} }) {
-            $conf->{snapshots}->{$snapname}->{snaptime} = "1234567890"
-                if $conf->{snapshots}->{$snapname}->{snaptime};
-        }
-    }
+    # the real method with the guest identity handling, which writes through mocked_cfs_write_file
+    return $original_write_config->($class, $vmid, $conf) if $real_write_config;
 
-    my $raw = PVE::QemuServer::write_vm_config($filename, $conf);
-
-    PVE::Tools::file_set_contents($filename, $raw);
+    mocked_cfs_write_file($class->cfs_config_path($vmid), $conf);
 }
 
 sub has_feature {
@@ -361,6 +364,31 @@ sub assert_config_exists_on_node {
 }
 # END mocked PVE::QemuConfig methods
 
+# BEGIN mocked PVE::Cluster methods
+
+sub mocked_get_config {
+    my ($path) = @_;
+
+    return -e $path ? PVE::Tools::file_get_contents($path) : undef;
+}
+
+sub mocked_cfs_write_file {
+    my ($filename, $conf) = @_;
+
+    if ($conf->{snapshots}) {
+        foreach my $snapname (keys %{ $conf->{snapshots} }) {
+            $conf->{snapshots}->{$snapname}->{snaptime} = "1234567890"
+                if $conf->{snapshots}->{$snapname}->{snaptime};
+        }
+    }
+
+    my $raw = PVE::QemuServer::write_vm_config($filename, $conf);
+
+    PVE::Tools::file_set_contents($filename, $raw);
+}
+
+# END mocked PVE::Cluster methods
+
 # BEGIN mocked PVE::QemuServer::Helpers methods
 
 sub vm_running_locally {
@@ -477,6 +505,16 @@ sub vm_stop {
 PVE::Tools::run_command("rm -rf snapshot-working");
 PVE::Tools::run_command("cp -a snapshot-input snapshot-working");
 
+$PVE::GuestHelpers::lockdir = "snapshot-working/lock";
+
+my $cluster_module = Test::MockModule->new('PVE::Cluster');
+$cluster_module->mock('get_config', \&mocked_get_config);
+$cluster_module->mock('cfs_write_file', \&mocked_cfs_write_file);
+
+my $guest_identity_module = Test::MockModule->new('PVE::GuestIdentity');
+$guest_identity_module->mock('__random_bytes', sub { return '0123456789abcdefghij'; });
+$guest_identity_module->mock('__time_ms', sub { return 1234567890123; });
+
 my $qemu_migrate_helpers_module = Test::MockModule->new('PVE::QemuMigrate::Helpers');
 $qemu_migrate_helpers_module->mock('set_migration_caps', \&set_migration_caps);
 
@@ -489,6 +527,7 @@ $qemu_monitor_module->mock('qmp_cmd', \&qmp_cmd);
 my $qemu_config_module = Test::MockModule->new('PVE::QemuConfig');
 $qemu_config_module->mock('config_file_lock', \&config_file_lock);
 $qemu_config_module->mock('cfs_config_path', \&cfs_config_path);
+$qemu_config_module->mock('config_file', \&config_file);
 $qemu_config_module->mock('load_config', \&load_config);
 $qemu_config_module->mock('write_config', \&write_config);
 $qemu_config_module->mock('has_feature', \&has_feature);
@@ -694,6 +733,16 @@ testcase_create("303", "test", 1, "test comment", "storage activation failed\n\n
 
 $activate_storage_possible = 1;
 
+$real_write_config = 1;
+
+printf("Successful snapshot_create keeping the guest identity\n");
+testcase_create("401", "test", 0, "test comment", "", { "local:snapshotable-disk-1" => "test" });
+
+printf("Successful snapshot_create assigning a guest identity to a config without one\n");
+testcase_create("402", "test", 0, "test comment", "", { "local:snapshotable-disk-1" => "test" });
+
+$real_write_config = 0;
+
 $nodename = "delete";
 printf("\n");
 printf("Running delete tests\n");
@@ -845,6 +894,17 @@ testcase_rollback("303", "test", "storage activation failed\n");
 
 $activate_storage_possible = 1;
 
+$real_write_config = 1;
+
+printf("Successful snapshot_rollback keeping the current guest identity, not the snapshot's\n");
+testcase_rollback("401", "test", "", { "local:snapshotable-disk-1" => "test" });
+
+printf(
+    "Successful snapshot_rollback to a snapshot without meta info, keeping the guest identity\n");
+testcase_rollback("402", "test", "", { "local:snapshotable-disk-1" => "test" });
+
+$real_write_config = 0;
+
 done_testing();
 
 1;
-- 
2.47.3





^ permalink raw reply related	[relevance 16%]

* [PATCH guest-common v4 08/41] guest identity: add helpers for the guest uid and registration time
  2026-11-19 10:33 17% [PATCH cluster/guest-common/qemu-server/container/manager/docs v4 00/41] " Thomas Lamprecht
@ 2026-11-19 10:33 22% ` Thomas Lamprecht
  2026-11-19 10:34 16% ` [PATCH qemu-server v4 16/41] fix #7846: config: add a guest identity to the 'meta' property Thomas Lamprecht
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 32+ results
From: Thomas Lamprecht @ 2026-11-19 10:33 UTC (permalink / raw)
  To: pve-devel

A VMID can be reused, and a guest can get a different VMID or move
to another cluster after a restore or remote migration. External tools
such as backup products need to recognize the same logical guest
independently of its VMID, as described in bug #7846.

Provide shared helpers for a random uid of 20 characters from the
lowercase base32 alphabet, which is 100 random bits, and a registration
time in milliseconds. Both are members of the guest config's 'meta'
property. Supply format definitions for both guest types and extract or
merge the identity without requiring knowledge of other members,
including newer ones. Also read it from a raw config, as the parser of a
guest type can drop a 'meta' property with members it does not know.

100 bits make a duplicate practically impossible, and the uid still fits
into a 128-bit value with 28 bits to spare, for example for a format
version and extra data, should a later format need them. Base32 keeps it
at 20 characters, about half the width of a UUID in its usual notation,
and only uses lowercase letters and digits. Each character comes from a
random byte of its own, so no encoder is needed.

The registration time is the time a guest got its uid in this cluster.
Unlike the creation time, which a clone, a restore and a migration from
another cluster copy along with the guest, it changes when a guest is
registered again, for example by a restore to a free VMID. Tools can use
it to tell such a guest from the one they knew, also if both have the
same uid.

Also provide a minimum node-version check for migration targets. Older
versions drop the identity on config writes. Report the required and
available versions so callers can explain a refusal, with a shared
schema for API results; missing version information counts as too old.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Reviewed-by: Dominik Csapak <d.csapak@proxmox.com>
Tested-by: Dominik Csapak <d.csapak@proxmox.com>
---

changes v3 -> v4:
* the stand-in MIN_PVE_MANAGER_VERSION is 9.2.33, as 9.2.31 and 9.2.32
  got released without this series
* tests: control and replacement characters in 'meta', moved here from
  the resource API test of pve-manager
* rebase (test Makefile), and 'adopt' instead of 'take over' in a
  comment

changes v2 -> v3:
* shorter description of the uid, which the status and resource APIs
  show too
* reword the comment about the size and the commit message about rtime:
  an in-place restore keeps the rtime

changes v1 -> v2:
* use v5.36 and signatures
* take each character of the uid from a random byte of its own, without
  an encoder (Dominik)
* add a helper to read the identity from a raw config, shared by the
  config write and the VM restore, which picks the 'meta' line like
  pmxcfs does
* add the schema of the migration precondition result, shared by both
  guest types
* explain the format, the difference between rtime and ctime, and why
  the generic property string helpers are not used (Dominik)
* shorter description of the uid

Note: MIN_PVE_MANAGER_VERSION (9.2.33) is a stand-in. It has to become
the first pve-manager version that depends on the qemu-server and
pve-container versions with this series, see the cover letter.

 src/Makefile                      |   1 +
 src/PVE/GuestIdentity.pm          | 231 ++++++++++++++++++++
 src/tests/Makefile                |   7 +-
 src/tests/guest-identity-tests.pl | 346 ++++++++++++++++++++++++++++++
 4 files changed, 583 insertions(+), 2 deletions(-)
 create mode 100644 src/PVE/GuestIdentity.pm
 create mode 100755 src/tests/guest-identity-tests.pl

diff --git a/src/Makefile b/src/Makefile
index 161dbe5..af4c277 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -10,6 +10,7 @@ install: PVE
 	install -m 0644 PVE/AbstractMigrate.pm ${PERL5DIR}/PVE/
 	install -m 0644 PVE/GuestHelpers.pm ${PERL5DIR}/PVE/
 	install -m 0644 PVE/GuestID.pm ${PERL5DIR}/PVE/
+	install -m 0644 PVE/GuestIdentity.pm ${PERL5DIR}/PVE/
 	install -m 0644 PVE/Replication.pm ${PERL5DIR}/PVE/
 	install -m 0644 PVE/ReplicationConfig.pm ${PERL5DIR}/PVE/
 	install -m 0644 PVE/ReplicationState.pm ${PERL5DIR}/PVE/
diff --git a/src/PVE/GuestIdentity.pm b/src/PVE/GuestIdentity.pm
new file mode 100644
index 0000000..5621a35
--- /dev/null
+++ b/src/PVE/GuestIdentity.pm
@@ -0,0 +1,231 @@
+package PVE::GuestIdentity;
+
+use v5.36;
+
+use Time::HiRes;
+
+use PVE::Cluster;
+
+# The identity of a guest, VM or container alike, consists of two members of the 'meta' property
+# string in the top-level section of its config: 'uid', a random identifier of the guest's lineage
+# (100 bits as 20 characters of the lowercase RFC 4648 base32 alphabet), and 'rtime', the time the
+# config was registered in this cluster (milliseconds since the epoch). The functions here pass it
+# as a hash with these two keys.
+#
+# 100 random bits make a duplicate uid practically impossible: a billion uids contain one with a
+# probability of about 4 * 10^-13. They also leave 28 bits of a 128-bit value free, for example for
+# a format version and extra data, should a later format need them. Base32 keeps the uid at 20
+# characters, about half the width of a UUID in its usual notation, and only uses lowercase letters
+# and digits, which need no quoting in a property string.
+#
+# Unlike the creation time 'ctime' of the same property, which a clone, a restore and a migration
+# from another cluster copy along with the guest, the rtime belongs to the uid of the guest in this
+# cluster: it is the time the guest got its uid here, be it a new one or one it adopted. So a
+# changed rtime tells that a guest was registered again, even if its uid is the same as before.
+
+# Must match the first pve-manager release that depends on the qemu-server and pve-container
+# versions handling the identity. Older nodes drop the whole 'meta' property on their next write
+# of a guest config.
+use constant MIN_PVE_MANAGER_VERSION => '9.2.33';
+
+my $UID_LENGTH = 20;
+my $UID_ALPHABET = 'abcdefghijklmnopqrstuvwxyz234567';
+my $UID_PATTERN = "[a-z2-7]{$UID_LENGTH}";
+
+# 15 digits of milliseconds last until the year 33658
+my $RTIME_MAX = 999_999_999_999_999;
+
+# Returns $len random bytes from the kernel's random number generator.
+sub __random_bytes($len) {
+    open(my $fh, '<', '/dev/urandom') or die "unable to open /dev/urandom - $!\n";
+    my $buf = '';
+    my $read = sysread($fh, $buf, $len);
+    die "unable to read from /dev/urandom - $!\n" if !defined($read);
+    die "short read from /dev/urandom\n" if $read != $len;
+    close($fh);
+
+    return $buf;
+}
+
+# Returns the current time in milliseconds since the epoch.
+sub __time_ms() {
+    my ($sec, $usec) = Time::HiRes::gettimeofday();
+
+    return $sec * 1000 + int($usec / 1000);
+}
+
+# Returns a random uid. Each character comes from the lowest 5 bits of a random byte of its own, so
+# it is uniformly distributed over the alphabet.
+my sub random_uid() {
+    my $bytes = __random_bytes($UID_LENGTH);
+
+    return join('', map { substr($UID_ALPHABET, ord($_) & 31, 1) } split(//, $bytes));
+}
+
+my sub is_valid_uid($uid) {
+    return defined($uid) && $uid =~ m/^$UID_PATTERN\z/;
+}
+
+my sub is_valid_rtime($rtime) {
+    return defined($rtime) && $rtime =~ m/^[0-9]{1,15}\z/;
+}
+
+# Returns the JSON schema properties of the identity members, for merging into the format of the
+# 'meta' property string of a guest type. Every call returns a new copy.
+sub meta_format_properties() {
+    return {
+        uid => {
+            type => 'string',
+            pattern => $UID_PATTERN,
+            description => "Random identifier of the guest lineage, independent of the VMID.",
+            optional => 1,
+        },
+        rtime => {
+            type => 'integer',
+            minimum => 0,
+            maximum => $RTIME_MAX,
+            description => "Time the guest was registered in this cluster, for example by"
+                . " creation, restore, or migration from another cluster, in milliseconds since"
+                . " the UNIX epoch.",
+            optional => 1,
+        },
+    };
+}
+
+# Returns a new identity with the current time as rtime. Its uid is $uid if given, otherwise a
+# random one.
+sub new_identity($uid = undef) {
+    die "invalid guest identity uid '$uid'\n" if defined($uid) && !is_valid_uid($uid);
+
+    return {
+        uid => $uid // random_uid(),
+        rtime => __time_ms(),
+    };
+}
+
+# Extracts the identity from the 'meta' property string $meta, which may contain any other
+# members, including ones unknown to this version.
+#
+# Returns undef if $meta has no valid uid, and an identity otherwise. Its rtime is undef if the
+# rtime member is missing or invalid. A member given more than once counts as invalid.
+#
+# This does not use PVE::JSONSchema::parse_property_string on purpose. That parser rejects the
+# whole string if one member is unknown or invalid. A guest without a readable identity gets a new
+# one with the next config write, so a problem with another member must not hide the uid.
+sub parse_identity($meta) {
+    return undef if !defined($meta);
+
+    my $values = {};
+    for my $part (split(/,/, $meta)) {
+        my ($key, $value) = $part =~ m/^([^=]+)=(.*)\z/ or next;
+        next if $key ne 'uid' && $key ne 'rtime';
+        $values->{$key} = exists($values->{$key}) ? undef : $value;
+    }
+
+    return undef if !is_valid_uid($values->{uid});
+
+    return {
+        uid => $values->{uid},
+        rtime => is_valid_rtime($values->{rtime}) ? $values->{rtime} : undef,
+    };
+}
+
+# Returns the 'meta' property string $meta, which may be undef, with the identity members set to
+# $identity. All other members are kept as they are, also ones unknown to this version, which
+# PVE::JSONSchema::print_property_string would reject.
+sub merge_identity($meta, $identity) {
+    die "invalid guest identity uid\n" if !is_valid_uid($identity->{uid});
+    die "invalid guest identity rtime\n" if !is_valid_rtime($identity->{rtime});
+
+    my (@plain, @members);
+    for my $part (split(/,/, $meta // '')) {
+        next if $part =~ m/^\s*\z/;
+
+        if (my ($key) = $part =~ m/^([^=]+)=/) {
+            push @members, [$key, $part] if $key ne 'uid' && $key ne 'rtime';
+        } else {
+            push @plain, $part;
+        }
+    }
+    push @members, ['rtime', "rtime=$identity->{rtime}"], ['uid', "uid=$identity->{uid}"];
+
+    # same order as PVE::JSONSchema::print_property_string uses, so that a guest type parsing and
+    # printing the property string again does not change it
+    return join(',', @plain, map { $_->[1] } sort { $a->[0] cmp $b->[0] } @members);
+}
+
+# Returns the identity in the top-level section of the raw guest config $raw, undef if it has none.
+# Only looks at the 'meta' property, so this also finds the identity in a config that the parser of
+# the guest type rejects or reads without 'meta', for example because of members from a newer
+# version.
+#
+# If a manual edit left more than one 'meta' line, the last one with anything after the colon
+# counts, also if that is only whitespace. The property lookup of pmxcfs does the same, and the
+# cluster-wide check of adopt uses it.
+sub parse_identity_from_raw_config($raw) {
+    my $meta;
+    for my $line (split(/\n/, $raw)) {
+        last if $line =~ m/^\[/; # snapshot or other section
+        $meta = $1 =~ s/^\s+|\s+$//gr if $line =~ m/^meta:(.+)$/;
+    }
+
+    return parse_identity($meta);
+}
+
+# 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
+# the node reports, if any.
+sub node_identity_unsupported($node) {
+    my $required = MIN_PVE_MANAGER_VERSION;
+    my ($major, $minor, $release) = split(/\./, $required);
+
+    my $supported =
+        eval { PVE::Cluster::node_pvecfg_version_at_least($node, $major, $minor, $release) };
+    return undef if $supported;
+
+    my $version = eval { PVE::Cluster::get_node_pvecfg_version($node) };
+
+    return { 'required-version' => $required, defined($version) ? (version => $version) : () };
+}
+
+# Returns the JSON schema of what node_identity_unsupported returns for a refused node, for the
+# result of API calls that report why a node is not allowed as migration target. Every call returns
+# a new copy.
+sub node_identity_unsupported_schema() {
+    return {
+        description =>
+            "Set if migrating to the node is refused because the node does not report a"
+            . " Proxmox VE version that keeps the guest identity.",
+        type => 'object',
+        optional => 1,
+        properties => {
+            version => {
+                description => "The Proxmox VE version the node reports.",
+                type => 'string',
+                optional => 1,
+            },
+            'required-version' => {
+                description => "The minimum Proxmox VE version that keeps the guest identity.",
+                type => 'string',
+            },
+        },
+    };
+}
+
+# Dies unless $node runs a version of Proxmox VE that keeps the identity when writing guest
+# configs, see node_identity_unsupported.
+sub assert_node_supports_identity($node) {
+    my $unsupported = node_identity_unsupported($node) or return;
+    my ($version, $required) = $unsupported->@{qw(version required-version)};
+
+    if (!defined($version)) {
+        die "node '$node' does not report its Proxmox VE version, so it is unknown whether the node"
+            . " keeps the guest identity\n";
+    }
+
+    die "node '$node' runs Proxmox VE $version, keeping the guest identity requires $required or"
+        . " newer - upgrade the node first\n";
+}
+
+1;
diff --git a/src/tests/Makefile b/src/tests/Makefile
index 11820bf..778b296 100644
--- a/src/tests/Makefile
+++ b/src/tests/Makefile
@@ -1,8 +1,8 @@
 
 all:
 
-.PHONY: check abstract-config config-reservation firewall-config guest-id hookscript storage-tunnel
-check: abstract-config config-reservation firewall-config guest-id hookscript storage-tunnel
+.PHONY: check abstract-config config-reservation firewall-config guest-id guest-identity hookscript storage-tunnel
+check: abstract-config config-reservation firewall-config guest-id guest-identity hookscript storage-tunnel
 
 abstract-config: abstract-config-tests.pl
 	perl -I.. ./abstract-config-tests.pl
@@ -16,6 +16,9 @@ firewall-config: firewall-config-tests.pl
 guest-id: guest-id-tests.pl
 	perl -I.. ./guest-id-tests.pl
 
+guest-identity: guest-identity-tests.pl
+	perl -I.. ./guest-identity-tests.pl
+
 hookscript: hookscript-tests.pl
 	perl -I.. ./hookscript-tests.pl
 
diff --git a/src/tests/guest-identity-tests.pl b/src/tests/guest-identity-tests.pl
new file mode 100755
index 0000000..b6a7c85
--- /dev/null
+++ b/src/tests/guest-identity-tests.pl
@@ -0,0 +1,346 @@
+#!/usr/bin/perl
+
+use v5.36;
+
+use lib qw(..);
+
+use Test::MockModule;
+use Test::More;
+use Time::HiRes;
+
+use PVE::JSONSchema;
+use PVE::Tools;
+
+use PVE::GuestIdentity;
+
+subtest 'generation with fixed random bytes and time' => sub {
+    my $random_bytes = [];
+    my $time_ms = 1_700_000_000_123;
+
+    my $identity_module = Test::MockModule->new('PVE::GuestIdentity');
+    $identity_module->redefine(
+        __random_bytes => sub {
+            my ($len) = @_;
+            my $bytes = shift(@$random_bytes) // die "test error: no random bytes left\n";
+            die "test error: requested $len random bytes\n" if length($bytes) != $len;
+            return $bytes;
+        },
+        __time_ms => sub { return $time_ms; },
+    );
+
+    # each byte gives one character, its lowest 5 bits select it from the lowercase RFC 4648 base32
+    # alphabet
+    my $vectors = [
+        ["\x00" x 20, 'a' x 20],
+        ["\xff" x 20, '7' x 20],
+        ['0123456789abcdefghij', 'qrstuvwxyzbcdefghijk'],
+        [pack('C*', 0 .. 19), 'abcdefghijklmnopqrst'],
+        [pack('C*', 12 .. 31), 'mnopqrstuvwxyz234567'],
+        [pack('C*', map { $_ | 0xe0 } 0 .. 19), 'abcdefghijklmnopqrst'],
+    ];
+
+    for my $vector (@$vectors) {
+        my ($bytes, $uid) = @$vector;
+        $random_bytes = [$bytes];
+        is_deeply(
+            PVE::GuestIdentity::new_identity(),
+            { uid => $uid, rtime => $time_ms },
+            "encodes " . unpack('H*', $bytes),
+        );
+    }
+
+    # every symbol is as likely at each position, as each of them comes from 8 of the 256 values of
+    # the byte at that position
+    my $alphabet = 'abcdefghijklmnopqrstuvwxyz234567';
+    my $mismatches = 0;
+    for my $position (0 .. 19) {
+        for my $value (0 .. 255) {
+            my $bytes = "\x00" x 20;
+            substr($bytes, $position, 1) = chr($value);
+            $random_bytes = [$bytes];
+            my $expected = 'a' x 20;
+            substr($expected, $position, 1) = substr($alphabet, $value % 32, 1);
+            $mismatches++ if PVE::GuestIdentity::new_identity()->{uid} ne $expected;
+        }
+    }
+    is($mismatches, 0, 'each character comes from the byte at its position');
+
+    $random_bytes = [];
+    is_deeply(
+        PVE::GuestIdentity::new_identity('gaytemzugu3doobzmfrg'),
+        { uid => 'gaytemzugu3doobzmfrg', rtime => $time_ms },
+        'given uid is used',
+    );
+    eval { PVE::GuestIdentity::new_identity('GAYTEMZUGU3DOOBZMFRG') };
+    like($@, qr/invalid guest identity uid/, 'invalid given uid is rejected');
+};
+
+subtest 'generation' => sub {
+    my $first = PVE::GuestIdentity::new_identity();
+    my $second = PVE::GuestIdentity::new_identity();
+    like($first->{uid}, qr/^[a-z2-7]{20}\z/, 'uid has the expected format');
+    my @uids = map { PVE::GuestIdentity::new_identity()->{uid} } 1 .. 100;
+    is_deeply([grep { !m/^[a-z2-7]{20}\z/ } @uids], [], 'uids have 20 characters, no padding');
+    isnt($first->{uid}, $second->{uid}, 'uids differ');
+
+    my $before = int(Time::HiRes::time() * 1000);
+    my $rtime = PVE::GuestIdentity::new_identity()->{rtime};
+    my $after = int(Time::HiRes::time() * 1000) + 1;
+    like($rtime, qr/^\d+\z/, 'rtime is an integer');
+    ok($rtime >= $before && $rtime <= $after, 'rtime is the current time in milliseconds');
+};
+
+subtest 'format properties' => sub {
+    my $format = {
+        ctime => { type => 'integer', optional => 1 },
+        PVE::GuestIdentity::meta_format_properties()->%*,
+    };
+
+    is_deeply(
+        PVE::JSONSchema::parse_property_string(
+            $format,
+            'ctime=1700000000,rtime=1700000000123,uid=gaytemzugu3doobzmfrg',
+        ),
+        { ctime => 1700000000, rtime => 1700000000123, uid => 'gaytemzugu3doobzmfrg' },
+        'meta string with identity parses with a merged format',
+    );
+
+    for my $invalid (
+        'uid=GAYTEMZUGU3DOOBZMFRG',
+        'uid=gaytemzugu3doobzmfr',
+        'uid=gaytemzugu3doobzmfrga',
+        'uid=gaytemzugu3doobzmfr0',
+        'uid=' . substr('gaytemzugu3doobzmfrg', 0, 16),
+        'rtime=-1',
+        'rtime=1.5',
+        'rtime=1000000000000000',
+    ) {
+        eval { PVE::JSONSchema::parse_property_string($format, $invalid) };
+        ok($@, "format rejects '$invalid'");
+    }
+
+    my $copy = PVE::GuestIdentity::meta_format_properties();
+    $copy->{uid}->{pattern} = '.*';
+    isnt(
+        PVE::GuestIdentity::meta_format_properties()->{uid}->{pattern},
+        '.*',
+        'callers get their own copy',
+    );
+};
+
+subtest 'parse identity' => sub {
+    my $uid = 'gaytemzugu3doobzmfrg';
+    my $tests = [
+        [undef, undef, 'no meta'],
+        ['', undef, 'empty meta'],
+        ['ctime=1700000000', undef, 'meta without identity'],
+        [
+            "creation-qemu=10.1.2,ctime=1700000000,rtime=123,uid=$uid",
+            { uid => $uid, rtime => 123 },
+            'identity next to other members',
+        ],
+        [
+            "future=a b,uid=$uid,other,rtime=0",
+            { uid => $uid, rtime => 0 },
+            'unknown members and odd parts are ignored',
+        ],
+        ["rtime=123,uid=$uid", { uid => $uid, rtime => 123 }, 'identity only'],
+        ["uid=$uid", { uid => $uid, rtime => undef }, 'missing rtime'],
+        ["uid=$uid,rtime=12a", { uid => $uid, rtime => undef }, 'invalid rtime'],
+        ["uid=$uid,rtime=-5", { uid => $uid, rtime => undef }, 'negative rtime'],
+        [
+            "uid=$uid,rtime=999999999999999",
+            { uid => $uid, rtime => 999999999999999 },
+            'maximum rtime',
+        ],
+        ["uid=$uid,rtime=1000000000000000", { uid => $uid, rtime => undef }, 'too large rtime'],
+        [
+            "uid=$uid,rtime=\x{0661}\x{0662}",
+            { uid => $uid, rtime => undef },
+            'non-ASCII digits',
+        ],
+        ["uid=$uid,rtime=1,rtime=2", { uid => $uid, rtime => undef }, 'duplicate rtime'],
+        ['rtime=123', undef, 'rtime without uid'],
+        ["uid=$uid,uid=$uid,rtime=1", undef, 'duplicate uid'],
+        ['uid=GAYTEMZUGU3DOOBZMFRG,rtime=1', undef, 'uppercase uid'],
+        ['uid=gaytemzugu3doobzmfr,rtime=1', undef, 'short uid'],
+        ['uid=gaytemzugu3doobzmfrga,rtime=1', undef, 'long uid'],
+        ['uid=' . substr($uid, 0, 16) . ',rtime=1', undef, '16-character uid'],
+        ['uid=gaytemzugu3doobzmfr1,rtime=1', undef, 'uid outside of the alphabet'],
+        ["uid= $uid,rtime=1", undef, 'uid with whitespace'],
+        # pmxcfs passes control characters on and replaces invalid UTF-8 with U+FFFD
+        ["uid=gaytemzugu\tdoobzmfrg,rtime=1", undef, 'control character in the uid'],
+        ["uid=gaytemzugu\x{FFFD}doobzmfrg,rtime=1", undef, 'replacement character in the uid'],
+        [
+            "ctime=17000\x{1}00000,rtime=1,uid=$uid",
+            { uid => $uid, rtime => 1 },
+            'control character in another member',
+        ],
+    ];
+
+    for my $test (@$tests) {
+        my ($meta, $expected, $name) = @$test;
+        is_deeply(PVE::GuestIdentity::parse_identity($meta), $expected, $name);
+    }
+};
+
+subtest 'parse identity from raw config' => sub {
+    my $uid = 'gaytemzugu3doobzmfrg';
+    my $other = 'aaaqeayeaudaocajbifq';
+    my $identity = { uid => $uid, rtime => 123 };
+    my $tests = [
+        ['', undef, 'empty config'],
+        ["memory: 512\n", undef, 'no meta'],
+        [
+            "memory: 512\nmeta: ctime=1,rtime=123,uid=$uid\ncores: 2\n",
+            $identity,
+            'top-level meta',
+        ],
+        ["meta:   rtime=123,uid=$uid  \n", $identity, 'surrounding whitespace'],
+        ["meta: rtime=1,uid=$other\nmeta: rtime=123,uid=$uid\n", $identity, 'last meta wins'],
+        ["meta: future=a b,rtime=123,uid=$uid\n", $identity, 'unknown members'],
+        ["meta: rtime=123,uid=$uid\nmeta:\n", $identity, 'meta line without value is ignored'],
+        [
+            "meta: rtime=123,uid=$uid\nmeta:   \n", undef, 'meta line with only spaces counts',
+        ],
+        ["#meta: rtime=123,uid=$uid\n", undef, 'description line'],
+        ["memory: 512\n\n[PENDING]\nmeta: uid=$uid\n", undef, 'pending section is ignored'],
+        [
+            "meta: rtime=123,uid=$uid\n\n[snap]\nmeta: rtime=1,uid=$other\n",
+            $identity,
+            'snapshot section is ignored',
+        ],
+    ];
+
+    for my $test (@$tests) {
+        my ($raw, $expected, $name) = @$test;
+        is_deeply(PVE::GuestIdentity::parse_identity_from_raw_config($raw), $expected, $name);
+    }
+};
+
+subtest 'merge identity' => sub {
+    my $identity = { uid => 'gaytemzugu3doobzmfrg', rtime => 1700000000123 };
+    my $members = 'rtime=1700000000123,uid=gaytemzugu3doobzmfrg';
+    my $tests = [
+        [undef, $members, 'no meta'],
+        ['', $members, 'empty meta'],
+        [
+            'creation-qemu=10.1.2,ctime=1700000000',
+            "creation-qemu=10.1.2,ctime=1700000000,$members",
+            'other members are kept',
+        ],
+        [
+            'ctime=1,rtime=5,uid=aaaaaaaaaaaaaaaaaaaa',
+            "ctime=1,$members",
+            'existing identity is replaced',
+        ],
+        [
+            'uid=bogus,zz-future=x,rtime=1,uid=aaaaaaaaaaaaaaaaaaaa,ctime=1',
+            "ctime=1,$members,zz-future=x",
+            'invalid and duplicate identity members are dropped, unknown members kept',
+        ],
+        ['plain,ctime=1', "plain,ctime=1,$members", 'parts without key stay first'],
+    ];
+
+    for my $test (@$tests) {
+        my ($meta, $expected, $name) = @$test;
+        my $merged = PVE::GuestIdentity::merge_identity($meta, $identity);
+        is($merged, $expected, $name);
+        is_deeply(PVE::GuestIdentity::parse_identity($merged), $identity, "$name, parses back");
+    }
+
+    for my $invalid (
+        { uid => 'GAYTEMZUGU3DOOBZMFRG', rtime => 1 },
+        { uid => 'gaytemzugu3doobzmfrg', rtime => undef },
+        { uid => 'gaytemzugu3doobzmfrg', rtime => 'now' },
+        { uid => 'gaytemzugu3doobzmfrg', rtime => '1000000000000000' },
+        { uid => 'gaytemzugu3doobzmfrg,ctime=1', rtime => 1 },
+        { rtime => 1 },
+    ) {
+        eval { PVE::GuestIdentity::merge_identity('ctime=1', $invalid) };
+        ok($@, "invalid identity is rejected");
+    }
+};
+
+subtest 'node version check' => sub {
+    my $min = PVE::GuestIdentity::MIN_PVE_MANAGER_VERSION;
+    like($min, qr/^[0-9]+\.[0-9]+\.[0-9]+\z/, 'minimum version is a version string');
+    my ($major, $minor, $release) = split(/\./, $min);
+
+    my $versions = {
+        current => "$major.$minor.$release",
+        newer => "$major." . ($minor + 1) . ".0",
+        older => "$major.$minor." . ($release - 1),
+        invalid => 'invalid',
+    };
+
+    my $cluster_module = Test::MockModule->new('PVE::Cluster');
+    $cluster_module->mock(
+        get_node_pvecfg_version => sub {
+            my ($node) = @_;
+            die "malformed version info\n" if $node eq 'malformed';
+            return $versions->{$node};
+        },
+        node_pvecfg_version_at_least => sub {
+            my ($node, @min) = @_;
+            my $version = PVE::Cluster::get_node_pvecfg_version($node);
+            return $version && PVE::Tools::pvecfg_min_version($version, @min);
+        },
+    );
+
+    for my $node (qw(current newer)) {
+        eval { PVE::GuestIdentity::assert_node_supports_identity($node) };
+        is($@, '', "node with version '$versions->{$node}' is supported");
+        my $unsupported = PVE::GuestIdentity::node_identity_unsupported($node);
+        is($unsupported, undef, "no reason for '$node'");
+    }
+
+    for my $node (qw(older invalid missing malformed)) {
+        eval { PVE::GuestIdentity::assert_node_supports_identity($node) };
+        like($@, qr/node '$node'/, "node '$node' is refused");
+    }
+
+    my $schema = PVE::GuestIdentity::node_identity_unsupported_schema();
+    isnt(
+        $schema,
+        PVE::GuestIdentity::node_identity_unsupported_schema(),
+        'schema is a new copy',
+    );
+    for my $node (qw(older invalid missing malformed)) {
+        my $unsupported = PVE::GuestIdentity::node_identity_unsupported($node);
+        eval { PVE::JSONSchema::validate($unsupported, $schema) };
+        is($@, '', "reason for '$node' matches the schema");
+    }
+
+    for my $node (qw(older invalid)) {
+        is_deeply(
+            PVE::GuestIdentity::node_identity_unsupported($node),
+            { version => $versions->{$node}, 'required-version' => $min },
+            "reason for '$node' has both versions",
+        );
+        eval { PVE::GuestIdentity::assert_node_supports_identity($node) };
+        is(
+            $@,
+            "node '$node' runs Proxmox VE $versions->{$node}, keeping the guest identity requires"
+                . " $min or newer - upgrade the node first\n",
+            "refusal of '$node' names both versions",
+        );
+    }
+
+    for my $node (qw(missing malformed)) {
+        is_deeply(
+            PVE::GuestIdentity::node_identity_unsupported($node),
+            { 'required-version' => $min },
+            "reason for '$node' has only the required version",
+        );
+        eval { PVE::GuestIdentity::assert_node_supports_identity($node) };
+        is(
+            $@,
+            "node '$node' does not report its Proxmox VE version, so it is unknown whether the"
+                . " node keeps the guest identity\n",
+            "refusal of '$node' says why",
+        );
+    }
+};
+
+done_testing();
-- 
2.47.3





^ permalink raw reply related	[relevance 22%]

* [PATCH cluster/guest-common/qemu-server/container/manager/docs v4 00/41] fix #7846: guest identity (uid) and cluster ID
@ 2026-11-19 10:33 17% Thomas Lamprecht
  2026-11-19 10:33 22% ` [PATCH guest-common v4 08/41] guest identity: add helpers for the guest uid and registration time Thomas Lamprecht
                   ` (4 more replies)
  0 siblings, 5 replies; 32+ results
From: Thomas Lamprecht @ 2026-11-19 10:33 UTC (permalink / raw)
  To: pve-devel

A VMID can be reused for another guest, and a guest can get another
VMID or move to another cluster through a restore or a remote
migration. So backup software and other tools cannot tell whether they
still look at the same guest, see [0].

This series gives every VM and container a guest identity in the
read-only 'meta' property: a random uid (100 bits as 20 base32
characters) and the time the guest was registered in the cluster. Create
and clone get a new uid. Config changes, migration, rollback, backup and
restore keep it, also under another VMID or in another cluster, as long
as no other guest there has it. Each cluster or standalone node also
gets a cluster ID in the same format, generated and protected by pmxcfs.
The docs patches describe the details.

The uid is a plain random nonce: 100 bits make a duplicate practically
impossible and fit into a 128-bit value with room to spare, and 20
base32 characters stay short and need no quoting. The registration time
is separate from the creation time, which clones, restores and remote
migrations copy along. It changes when a guest gets registered again, so
tools can tell such a guest from the one they knew.

Three behavior changes come with it:

* Restoring over an existing guest whose uid differs from the one of
  the backup is refused unless 'allow-identity-mismatch' is set. 'force'
  alone does not override this.
* A migration to another cluster is refused if another guest there
  already has the uid, unless 'allow-new-uid' is set. The check runs
  before anything is transferred. PDM does not know the option yet.
* Older versions drop the whole 'meta' property of a guest that has an
  identity. So migration and clone to such nodes is refused, and remote
  migration bumps the tunnel version. This also hits moves by the HA
  stack, which stops a container or a relocated VM before the migration
  gets refused. A target check in the LRM that avoids this will follow
  separately.

The patches are in dependency order: guest-common needs the pve-cluster
of this series, qemu-server and container need guest-common, and manager
needs all of them. manager also has to depend on the qemu-server and
container versions with this series, as the migration guard takes the
pve-manager version of a node as proof that the node keeps the identity.
MIN_PVE_MANAGER_VERSION in guest-common is a stand-in for that version.

Tested with the affected tests of the repositories for every patch and
their full suites at the end, pmxcfs with corosync in network
namespaces, and end to end on a nested three-node cluster that was
upgraded node by node, with remote migrations to a standalone node.

changes v3 -> v4, thanks a lot (!) to Dominik for the review and the
tests:
* cluster ID: pmxcfs checks after each sync and then every ten seconds
  while in sync, by the current state alone, instead of on single
  events, which missed failed sends (the confdb listener patch is
  gone); a standalone node that cannot store its ID starts without one
* failed restores: independent fixes before the series put the previous
  firewall config back, keep a guest whose cleanup was incomplete at
  its VMID and locked, for VMs as for containers, and do not create a
  guest for a caller that may only overwrite one
* shared code: pve-guest-common has one helper for the start of a
  restore, both overrides as standard options and the wait for a volume
  transfer in the tunnel cleanup
* tests of existing behavior moved to independent commits before the
  series, so both remote migration test patches left it
* new, suggested by Dominik: the uid as variable of the backup notes
  template (patches 13, 35, 41) and the cluster ID in the datacenter
  summary (patch 30)
* cluster-wide bulk migration between two older nodes works again, and
  the stand-in for the minimum pve-manager version is 9.2.33, as 9.2.31
  and 9.2.32 got released without this series
I added Dominik's Reviewed-by and Tested-by from v3 on the patches that
did not change or only got polish since.

changes v2 -> v3:
* remote migration: a guest without uid gets one before the source
  sends it, so source and target no longer end up with unrelated uids;
  the identity command moved to pve-guest-common for both guest types
  (new patch 13)
* restore: keep the guest if a restored volume or firewall config
  cannot be removed, fail if a container backup changes between its
  check and its extraction, and let the cleanup follow the reservation
* reserving a VMID refuses an existing config that fails to load
  instead of replacing it
* cluster ID: generate it right away when the configured nodes change
  (new patch 5)
* feature API without version lookups for snapshot requests, and the
  cluster-wide bulk migration refuses its target up front
* docs: failed restores, uid conflicts on migration, qm.conf(5) and
  pct.conf(5)
* more independent fixes that the series builds on were applied on
  their own: failed and concurrent restores and creates, the schema of
  the migration preconditions, the lock of a VMA restore, a node list
  cut short in pmxcfs

changes v1 -> v2, thanks to Dominik for the review:
* rebase onto current master (tracking of used guest IDs, dfsm rework)
* remote migration takes the uid over at its start and refuses a uid
  that is in use in the target cluster, unless 'allow-new-uid' is set
* qemu-server and container share the restore checks and messages
  through pve-guest-common, with fewer special cases
* IDs take each character from one random byte, without an encoder
* the clone dialog does not offer nodes that would drop the identity,
  and a bulk migration checks its target once (patch 35)
* independent fixes moved out of the series and got applied on their
  own: the IPC client error, the order of removing firewall and guest
  config, and the cleanup of a remote migration target after failures
* comments, commit messages and docs give the reasons for the format,
  for rtime next to ctime and for the separate lock
Details are in the notes below the "---" of each patch.

v3: https://lore.proxmox.com/pve-devel/20261118043817.1659212-1-t.lamprecht@proxmox.com/
v2: https://lore.proxmox.com/pve-devel/20261117223945.862914-1-t.lamprecht@proxmox.com/
v1: https://lore.proxmox.com/pve-devel/20261116004703.2908294-1-t.lamprecht@proxmox.com/

[0]: https://bugzilla.proxmox.com/show_bug.cgi?id=7846

cluster:

Thomas Lamprecht (7):
  pmxcfs: reject changes to the cluster ID file from user space
  pmxcfs: generate a cluster ID on standalone nodes
  pmxcfs: dfsm: add a callback that runs once all members are in sync
  pmxcfs: quorum: record the corosync membership
  pmxcfs: dcdb: generate the cluster ID once the cluster is in sync
  cluster: add helper to read the cluster ID
  pmxcfs: allow removing the cluster ID file in forced local mode

 src/PVE/Cluster.pm          |  16 +
 src/pmxcfs/Makefile         |  12 +-
 src/pmxcfs/cfs-plug-memdb.c |  46 ++
 src/pmxcfs/cfs-utils.c      |   8 +
 src/pmxcfs/cfs-utils.h      |   5 +
 src/pmxcfs/check_dcdb.c     | 876 ++++++++++++++++++++++++++++++++++++
 src/pmxcfs/check_memdb.c    | 312 +++++++++++++
 src/pmxcfs/cluster-id.c     | 142 ++++++
 src/pmxcfs/cluster-id.h     |  50 ++
 src/pmxcfs/dcdb.c           | 141 ++++++
 src/pmxcfs/dcdb.h           |   5 +-
 src/pmxcfs/dfsm.c           |  70 ++-
 src/pmxcfs/dfsm.h           |  10 +
 src/pmxcfs/memdb.c          |  17 +
 src/pmxcfs/memdb.h          |   4 +
 src/pmxcfs/pmxcfs.c         |   8 +-
 src/pmxcfs/quorum.c         |  13 +-
 src/pmxcfs/status.c         |  44 ++
 src/pmxcfs/status.h         |  13 +
 src/test/Makefile           |   6 +-
 src/test/test_cluster_id.pl |  46 ++
 21 files changed, 1832 insertions(+), 12 deletions(-)
 create mode 100644 src/pmxcfs/check_dcdb.c
 create mode 100644 src/pmxcfs/cluster-id.c
 create mode 100644 src/pmxcfs/cluster-id.h
 create mode 100644 src/test/test_cluster_id.pl


guest-common:

Thomas Lamprecht (6):
  guest identity: add helpers for the guest uid and registration time
  abstract config: assign a guest identity and keep it on config writes
  abstract config: let the VMID reservation return the previous state
  guest identity: allow adopting a uid that is unused in the cluster
  migrate: add shared helpers for the identity command of the migration tunnel
  vzdump: notes template: list the uid variable

 src/Makefile                       |    1 +
 src/PVE/AbstractConfig.pm          |  203 ++++-
 src/PVE/AbstractMigrate.pm         |   42 +
 src/PVE/GuestIdentity.pm           |  497 ++++++++++
 src/PVE/VZDump/Common.pm           |    6 +-
 src/tests/Makefile                 |   10 +-
 src/tests/config-identity-tests.pl | 1358 ++++++++++++++++++++++++++++
 src/tests/guest-identity-tests.pl  |  474 ++++++++++
 8 files changed, 2580 insertions(+), 11 deletions(-)
 create mode 100644 src/PVE/GuestIdentity.pm
 create mode 100755 src/tests/config-identity-tests.pl
 create mode 100755 src/tests/guest-identity-tests.pl


qemu-server:

Thomas Lamprecht (6):
  api: restore: release the VMID if a restore to an unused VMID fails
  api: migrate, clone: refuse targets that would drop the guest identity
  fix #7846: config: add a guest identity to the 'meta' property
  restore: take over the guest uid from the backup where possible
  api: remote migration: take over the guest uid from the source
  api: status: return the guest uid

 src/PVE/API2/Qemu.pm                          | 107 ++-
 src/PVE/CLI/qm.pm                             |   1 +
 src/PVE/CLI/qmrestore.pm                      |   5 +-
 src/PVE/QemuConfig.pm                         |   7 +
 src/PVE/QemuMigrate.pm                        |  18 +-
 src/PVE/QemuServer.pm                         | 166 +++-
 src/PVE/QemuServer/MetaInfo.pm                |   2 +
 src/test/Makefile                             |   5 +-
 src/test/QemuServerTest/FakeCFS.pm            |  84 +-
 .../q35-windows-pinning-identity-only.conf    |   6 +
 ...q35-windows-pinning-identity-only.conf.cmd |  26 +
 .../meta-identity-invalid.conf                |   6 +
 .../meta-identity-invalid.conf.strict.error   |   2 +
 .../meta-identity-invalid.conf                |   7 +
 .../parse-config-input/meta-identity.conf     |  20 +
 src/test/restore-config-expected/150.conf     |   9 +
 src/test/restore-config-input/150.conf        |  10 +
 src/test/run_api_tests.pl                     | 198 +++++
 src/test/run_guest_identity_tests.pl          | 614 ++++++++++++++
 src/test/run_parse_config_tests.pl            |   2 +-
 src/test/run_qemu_restore_config_tests.pl     | 754 +++++++++++++++++-
 .../create/qemu-server/401.conf               |  31 +
 .../create/qemu-server/402.conf               |  31 +
 .../rollback/qemu-server/401.conf             |  36 +
 .../rollback/qemu-server/402.conf             |  35 +
 .../create/qemu-server/401.conf               |  13 +
 .../create/qemu-server/402.conf               |  13 +
 .../rollback/qemu-server/401.conf             |  35 +
 .../rollback/qemu-server/402.conf             |  34 +
 src/test/snapshot-test.pm                     |  82 +-
 30 files changed, 2283 insertions(+), 76 deletions(-)
 create mode 100644 src/test/cfg2cmd/q35-windows-pinning-identity-only.conf
 create mode 100644 src/test/cfg2cmd/q35-windows-pinning-identity-only.conf.cmd
 create mode 100644 src/test/parse-config-expected/meta-identity-invalid.conf
 create mode 100644 src/test/parse-config-expected/meta-identity-invalid.conf.strict.error
 create mode 100644 src/test/parse-config-input/meta-identity-invalid.conf
 create mode 100644 src/test/parse-config-input/meta-identity.conf
 create mode 100644 src/test/restore-config-expected/150.conf
 create mode 100644 src/test/restore-config-input/150.conf
 create mode 100755 src/test/run_guest_identity_tests.pl
 create mode 100644 src/test/snapshot-expected/create/qemu-server/401.conf
 create mode 100644 src/test/snapshot-expected/create/qemu-server/402.conf
 create mode 100644 src/test/snapshot-expected/rollback/qemu-server/401.conf
 create mode 100644 src/test/snapshot-expected/rollback/qemu-server/402.conf
 create mode 100644 src/test/snapshot-input/create/qemu-server/401.conf
 create mode 100644 src/test/snapshot-input/create/qemu-server/402.conf
 create mode 100644 src/test/snapshot-input/rollback/qemu-server/401.conf
 create mode 100644 src/test/snapshot-input/rollback/qemu-server/402.conf


container:

Thomas Lamprecht (8):
  restore: decide by the reservation whether the container is new
  config: add read-only meta property with the creation time
  fix #7846: config: add a guest identity to the 'meta' property
  api: migrate, clone: refuse targets that would drop the guest identity
  restore: take over the guest uid from the backup where possible
  restore: refuse overwriting a container with another guest's backup
  api: remote migration: take over the guest uid from the source
  api: status: return the guest uid

 src/PVE/API2/LXC.pm         |  133 ++-
 src/PVE/API2/LXC/Config.pm  |    8 +
 src/PVE/API2/LXC/Status.pm  |    6 +
 src/PVE/CLI/pct.pm          |    2 +
 src/PVE/LXC/Config.pm       |   42 +-
 src/PVE/LXC/Create.pm       |   26 +-
 src/PVE/LXC/Migrate.pm      |    8 +-
 src/test/config_tests.pl    |   22 +
 src/test/lifecycle_tests.pl | 1522 +++++++++++++++++++++++++++++++++++
 9 files changed, 1740 insertions(+), 29 deletions(-)


manager:

Thomas Lamprecht (8):
  api: cluster resources: add guest uid and registration time
  api: cluster status: add cluster ID
  ui: datacenter summary: show the cluster ID
  ui: restore: allow overwriting a guest with a backup of another guest
  ui: migrate: refuse target nodes that would drop the guest identity
  ui: guest summary: show the guest identity
  api: bulk migrate: refuse targets that would drop the guest identity
  vzdump: notes template: add the guest uid as variable

 PVE/API2/Cluster.pm                      |  24 +++-
 PVE/API2/Cluster/BulkAction/Guest.pm     |  17 +++
 PVE/API2/Nodes.pm                        |   3 +
 PVE/VZDump.pm                            |  12 +-
 test/ClusterResources_test.pl            | 171 +++++++++++++++++++++++
 test/ClusterStatus_test.pl               | 114 +++++++++++++++
 test/Makefile                            |  10 +-
 www/manager6/Makefile                    |   1 +
 www/manager6/Utils.js                    |   2 +-
 www/manager6/dc/Health.js                |   6 +
 www/manager6/panel/GuestIdentity.js      | 120 ++++++++++++++++
 www/manager6/panel/GuestStatusView.js    |   3 +
 www/manager6/panel/TemplateStatusView.js |   3 +
 www/manager6/window/Migrate.js           |  29 ++++
 www/manager6/window/Restore.js           |  18 +++
 15 files changed, 529 insertions(+), 4 deletions(-)
 create mode 100755 test/ClusterResources_test.pl
 create mode 100755 test/ClusterStatus_test.pl
 create mode 100644 www/manager6/panel/GuestIdentity.js


docs:

Thomas Lamprecht (6):
  vzdump: restore: describe what a failed restore can leave behind
  vzdump: describe the guest identity of VMs and containers
  pvecm: document the cluster ID and how to get a new one
  qm: configuration: describe the read-only meta property
  pct: configuration: describe the read-only meta property
  vzdump: notes: document the uid template variable

 pct.adoc      |  35 +++++
 pct.conf.adoc |   3 +
 pmxcfs.adoc   |   1 +
 pvecm.adoc    | 106 +++++++++++++++
 qm.adoc       |  38 ++++++
 qm.conf.adoc  |   3 +
 vzdump.adoc   | 349 ++++++++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 535 insertions(+)


Summary over all repositories:
  90 files changed, 9499 insertions(+), 132 deletions(-)

-- 
2.47.3





^ permalink raw reply	[relevance 17%]

* Re: [PATCH cluster/guest-common/qemu-server/container/manager/docs v3 00/38] fix #7846: guest identity (uid) and cluster ID
  2026-11-18 13:49 17% ` [PATCH cluster/guest-common/qemu-server/container/manager/docs v3 00/38] fix #7846: guest identity (uid) and cluster ID Dominik Csapak
@ 2026-11-18 14:13 15%   ` Thomas Lamprecht
  0 siblings, 0 replies; 32+ results
From: Thomas Lamprecht @ 2026-11-18 14:13 UTC (permalink / raw)
  To: Dominik Csapak, pve-devel

Am 18.11.26 um 14:49 schrieb Dominik Csapak:
> Read through it again (though mostly via diff from the v1)
> and it looks good to me now:
> 
> * the rationale is given
> * the flow is better visible (and with better wording)
> * remote migrate is now blocked by default on conflicting uids
> 
> the biggest issue to discuss maybe still is if we want to allow
> restore with a new uid in case the same uid exists already,
> same argument as for the remote migration:
> 
> if the same vm already exists, restoring it again can have
> bad implications like duplicate ips, etc.
> 
> but IMHO it's not a blocker, maybe even something the admin
> would want to configure globally? (datacenter.cfg?)

IMO such restores can be - while potentially not highly frequent
– part of standard procedure, like test copy, restore test or partial
recovery.

It certainly is a valid point, but as we can only do a likely
correlation that same uid == same network and thus likely bad,
one can also have the situation with a different guest uid but
same network address in both the guests. Also, I'd rather have
this improved midterm by offering to restore to a isolated or
nat'ed or so vnet, and then show a warning hint (and adapt
the defaults to make that isolated-network-env-restore) if a guest
with the uid exist.

Might come out for free for a general slightly overdue improvement
for providing some convenience foundations for easier backup
restore testing.

> one thing i noticed during testing was if i modified a guest
> to have an invalid uid, on the next config write, the
> ctime and creation-qemu vanished from the config and
> only a new rtime and uid remained.
> (though i had to manually edit the config, so not a problem IMO)

will double check, but yeah, such manual edits are a bit hard
to handle correctly; maybe we can harden some simpler/specific
cases.

> 
> there are still some nits here and there, but they are mostly
> taste questions and nothing that can't be improved further down the line
> 
> for example: when restoring a vm over another another, the failure i get is:
> 
> TASK ERROR: command 'set -o pipefail && zstd -q -d -c -- /var/lib/vz/dump/vzdump-qemu-9999-2026_11_18-14_37_58.vma.zst | vma extract -v -r /var/tmp/vzdumptmp8272.fifo - /var/tmp/vzdumptmp8272' failed: backup belongs to another guest: its uid '2xuof4nw6rnowo5mpgs2' differs from uid 'itomggi4ofm33szeb3h2' of the existing VM 102 - use 'allow-identity-mismatch' to overwrite the VM anyway
> 
> which is not very readable in the task log window  (still functional though)

true, multi-line errors would help here a lot, we support them in
rust side, need to recheck if in perl side too.

> 
> also at least a few things in the ui i'm missing:
> 
> a way to show the cluster/node id (probably in the datacenter summary)

Or cluster status view, while not coming from corosync or so
directly at least naming wise it fits. I'll see if one seems clearly
better (summary one is probably easier), else keep that out for now.

> using the uid (maybe rtime) as variables in the templating for the notes

good idea.

> Tested it on a test cluster with some backup/restore cycles,
> adopting of uid, manually editing configs, etc.
> 
> Since nothing of these blocks this series from my POV, consider it:
> 
> Reviewed-by: Dominik Csapak <d.csapak@proxmox.com>
> Tested-by: Dominik Csapak <d.csapak@proxmox.com>

big thanks!





^ permalink raw reply	[relevance 15%]

* Re: [PATCH cluster/guest-common/qemu-server/container/manager/docs v3 00/38] fix #7846: guest identity (uid) and cluster ID
  2026-11-18  4:37 18% [PATCH cluster/guest-common/qemu-server/container/manager/docs v3 00/38] " Thomas Lamprecht
                   ` (2 preceding siblings ...)
  2026-11-18  4:37 16% ` [PATCH docs v3 35/38] vzdump: describe the guest identity of VMs and containers Thomas Lamprecht
@ 2026-11-18 13:49 17% ` Dominik Csapak
  2026-11-18 14:13 15%   ` Thomas Lamprecht
  2026-11-19 10:38 11% ` superseded: " Thomas Lamprecht
  4 siblings, 1 reply; 32+ results
From: Dominik Csapak @ 2026-11-18 13:49 UTC (permalink / raw)
  To: Thomas Lamprecht, pve-devel

Read through it again (though mostly via diff from the v1)
and it looks good to me now:

* the rationale is given
* the flow is better visible (and with better wording)
* remote migrate is now blocked by default on conflicting uids

the biggest issue to discuss maybe still is if we want to allow
restore with a new uid in case the same uid exists already,
same argument as for the remote migration:

if the same vm already exists, restoring it again can have
bad implications like duplicate ips, etc.

but IMHO it's not a blocker, maybe even something the admin
would want to configure globally? (datacenter.cfg?)

one thing i noticed during testing was if i modified a guest
to have an invalid uid, on the next config write, the
ctime and creation-qemu vanished from the config and
only a new rtime and uid remained.
(though i had to manually edit the config, so not a problem IMO)

there are still some nits here and there, but they are mostly
taste questions and nothing that can't be improved further down the line

for example: when restoring a vm over another another, the failure i get is:

TASK ERROR: command 'set -o pipefail && zstd -q -d -c -- 
/var/lib/vz/dump/vzdump-qemu-9999-2026_11_18-14_37_58.vma.zst | vma 
extract -v -r /var/tmp/vzdumptmp8272.fifo - /var/tmp/vzdumptmp8272' 
failed: backup belongs to another guest: its uid '2xuof4nw6rnowo5mpgs2' 
differs from uid 'itomggi4ofm33szeb3h2' of the existing VM 102 - use 
'allow-identity-mismatch' to overwrite the VM anyway

which is not very readable in the task log window  (still functional though)

also at least a few things in the ui i'm missing:

a way to show the cluster/node id (probably in the datacenter summary)
using the uid (maybe rtime) as variables in the templating for the notes

Tested it on a test cluster with some backup/restore cycles,
adopting of uid, manually editing configs, etc.

Since nothing of these blocks this series from my POV, consider it:

Reviewed-by: Dominik Csapak <d.csapak@proxmox.com>
Tested-by: Dominik Csapak <d.csapak@proxmox.com>


On 11/18/26 5:39 AM, Thomas Lamprecht wrote:
> A VMID can be reused for another guest, and a guest can get another
> VMID or move to another cluster through a restore or a remote
> migration. So backup software and other tools cannot tell whether they
> still look at the same guest, see [0].
> 
> This series gives every VM and container a guest identity in the
> read-only 'meta' property: a random uid (100 bits as 20 base32
> characters) and the time the guest was registered in the cluster. Create
> and clone get a new uid. Config changes, migration, rollback, backup and
> restore keep it, also under another VMID or in another cluster, as long
> as no other guest there has it. Each cluster or standalone node also
> gets a cluster ID in the same format, generated and protected by pmxcfs.
> The docs patches describe the details.
> 
> The uid is a plain random nonce: 100 bits make a duplicate practically
> impossible and fit into a 128-bit value with room to spare, and 20
> base32 characters stay short and need no quoting. The registration time
> is separate from the creation time, which clones, restores and remote
> migrations copy along. It changes when a guest gets registered again, so
> tools can tell such a guest from the one they knew.
> 
> Three behavior changes come with it:
> 
> * Restoring over an existing guest whose uid differs from the one of
>    the backup is refused unless 'allow-identity-mismatch' is set. 'force'
>    alone does not override this.
> * A migration to another cluster is refused if another guest there
>    already has the uid, unless 'allow-new-uid' is set. The check runs
>    before anything is transferred. PDM does not know the option yet.
> * Older versions drop the whole 'meta' property of a guest that has an
>    identity. So migration and clone to such nodes is refused, and remote
>    migration bumps the tunnel version. This also hits moves by the HA
>    stack, which stops a container or a relocated VM before the migration
>    gets refused. A target check in the LRM that avoids this will follow
>    separately.
> 
> The patches are in dependency order: guest-common needs the pve-cluster
> of this series, qemu-server and container need guest-common, and manager
> needs all of them. manager also has to depend on the qemu-server and
> container versions with this series, as the migration guard takes the
> pve-manager version of a node as proof that the node keeps the identity.
> MIN_PVE_MANAGER_VERSION in guest-common is a stand-in for that version.
> 
> Tested with the affected tests of the repositories for every patch and
> their full suites at the end, pmxcfs with corosync in network
> namespaces, and end to end on a nested three-node cluster that was
> upgraded node by node, with remote migrations to a standalone node.
> 
> changes v2 -> v3:
> * remote migration: a guest without uid gets one before the source
>    sends it, so source and target no longer end up with unrelated uids;
>    the identity command moved to pve-guest-common for both guest types
>    (new patch 13)
> * restore: keep the guest if a restored volume or firewall config
>    cannot be removed, fail if a container backup changes between its
>    check and its extraction, and let the cleanup follow the reservation
> * reserving a VMID refuses an existing config that fails to load
>    instead of replacing it
> * cluster ID: generate it right away when the configured nodes change
>    (new patch 5)
> * feature API without version lookups for snapshot requests, and the
>    cluster-wide bulk migration refuses its target up front
> * docs: failed restores, uid conflicts on migration, qm.conf(5) and
>    pct.conf(5)
> * more independent fixes that the series builds on were applied on
>    their own: failed and concurrent restores and creates, the schema of
>    the migration preconditions, the lock of a VMA restore, a node list
>    cut short in pmxcfs
> 
> changes v1 -> v2, thanks to Dominik for the review:
> * rebase onto current master (tracking of used guest IDs, dfsm rework)
> * remote migration takes the uid over at its start and refuses a uid
>    that is in use in the target cluster, unless 'allow-new-uid' is set
> * qemu-server and container share the restore checks and messages
>    through pve-guest-common, with fewer special cases
> * IDs take each character from one random byte, without an encoder
> * the clone dialog does not offer nodes that would drop the identity,
>    and a bulk migration checks its target once (patch 34)
> * independent fixes moved out of the series and got applied on their
>    own: the IPC client error, the order of removing firewall and guest
>    config, and the cleanup of a remote migration target after failures
> * comments, commit messages and docs give the reasons for the format,
>    for rtime next to ctime and for the separate lock
> Details are in the notes below the "---" of each patch.
> 
> v2: https://lore.proxmox.com/pve-devel/20261117223945.862914-1-t.lamprecht@proxmox.com/
> v1: https://lore.proxmox.com/pve-devel/20261116004703.2908294-1-t.lamprecht@proxmox.com/
> 
> [0]: https://bugzilla.proxmox.com/show_bug.cgi?id=7846
> 
> cluster:
> 
> Thomas Lamprecht (8):
>    pmxcfs: reject changes to the cluster ID file from user space
>    pmxcfs: generate a cluster ID on standalone nodes
>    pmxcfs: dfsm: add a callback that runs once all members are in sync
>    pmxcfs: quorum: pass the corosync membership to an optional listener
>    pmxcfs: confdb: call an optional listener when the nodes get published
>    pmxcfs: dcdb: generate the cluster ID once the cluster is in sync
>    cluster: add helper to read the cluster ID
>    pmxcfs: allow removing the cluster ID file in forced local mode
> 
>   src/PVE/Cluster.pm          |  16 +
>   src/pmxcfs/Makefile         |  12 +-
>   src/pmxcfs/cfs-plug-memdb.c |  46 +++
>   src/pmxcfs/cfs-utils.c      |   8 +
>   src/pmxcfs/cfs-utils.h      |   5 +
>   src/pmxcfs/check_dcdb.c     | 563 ++++++++++++++++++++++++++++++++++++
>   src/pmxcfs/check_memdb.c    | 283 ++++++++++++++++++
>   src/pmxcfs/cluster-id.c     | 142 +++++++++
>   src/pmxcfs/cluster-id.h     |  50 ++++
>   src/pmxcfs/confdb.c         |  18 +-
>   src/pmxcfs/confdb.h         |   5 +-
>   src/pmxcfs/dcdb.c           | 153 ++++++++++
>   src/pmxcfs/dcdb.h           |   8 +
>   src/pmxcfs/dfsm.c           |  59 ++++
>   src/pmxcfs/dfsm.h           |  14 +
>   src/pmxcfs/pmxcfs.c         |  12 +-
>   src/pmxcfs/quorum.c         |  26 +-
>   src/pmxcfs/quorum.h         |   9 +-
>   src/pmxcfs/status.c         |  12 +
>   src/pmxcfs/status.h         |   3 +
>   src/test/Makefile           |   6 +-
>   src/test/test_cluster_id.pl |  46 +++
>   22 files changed, 1478 insertions(+), 18 deletions(-)
>   create mode 100644 src/pmxcfs/check_dcdb.c
>   create mode 100644 src/pmxcfs/cluster-id.c
>   create mode 100644 src/pmxcfs/cluster-id.h
>   create mode 100644 src/test/test_cluster_id.pl
> 
> 
> guest-common:
> 
> Thomas Lamprecht (5):
>    guest identity: add helpers for the guest uid and registration time
>    abstract config: assign a guest identity and keep it on config writes
>    abstract config: let the VMID reservation return the previous state
>    guest identity: allow taking over a uid that is unused in the cluster
>    migrate: add shared helpers for the identity command of the migration tunnel
> 
>   src/Makefile                       |    1 +
>   src/PVE/AbstractConfig.pm          |  202 +++-
>   src/PVE/AbstractMigrate.pm         |   30 +
>   src/PVE/GuestIdentity.pm           |  510 ++++++++++
>   src/tests/Makefile                 |   10 +-
>   src/tests/config-identity-tests.pl | 1391 ++++++++++++++++++++++++++++
>   src/tests/guest-identity-tests.pl  |  530 +++++++++++
>   7 files changed, 2668 insertions(+), 6 deletions(-)
>   create mode 100644 src/PVE/GuestIdentity.pm
>   create mode 100755 src/tests/config-identity-tests.pl
>   create mode 100755 src/tests/guest-identity-tests.pl
> 
> 
> qemu-server:
> 
> Thomas Lamprecht (7):
>    api: restore: release the VMID if a restore to an unused VMID fails
>    api: migrate, clone: refuse targets that would drop the guest identity
>    fix #7846: config: add a guest identity to the 'meta' property
>    restore: take over the guest uid from the backup where possible
>    api: remote migration: take over the guest uid from the source
>    api: status: return the guest uid
>    tests: remote migration: check a failed command and an early tunnel end
> 
>   src/PVE/API2/Qemu.pm                          |  118 +-
>   src/PVE/CLI/qm.pm                             |    7 +
>   src/PVE/CLI/qmrestore.pm                      |   11 +-
>   src/PVE/QemuConfig.pm                         |    7 +
>   src/PVE/QemuMigrate.pm                        |   18 +-
>   src/PVE/QemuServer.pm                         |  155 ++-
>   src/PVE/QemuServer/MetaInfo.pm                |    2 +
>   src/test/Makefile                             |    5 +-
>   src/test/QemuServerTest/FakeCFS.pm            |  189 +++
>   .../q35-windows-pinning-identity-only.conf    |    6 +
>   ...q35-windows-pinning-identity-only.conf.cmd |   26 +
>   .../meta-identity-invalid.conf                |    6 +
>   .../meta-identity-invalid.conf.strict.error   |    2 +
>   .../meta-identity-invalid.conf                |    7 +
>   .../parse-config-input/meta-identity.conf     |   20 +
>   src/test/restore-config-expected/150.conf     |    9 +
>   src/test/restore-config-input/150.conf        |   10 +
>   src/test/run_api_tests.pl                     |  206 ++++
>   src/test/run_guest_identity_tests.pl          |  803 +++++++++++++
>   src/test/run_parse_config_tests.pl            |    2 +-
>   src/test/run_qemu_restore_config_tests.pl     | 1053 ++++++++++++++++-
>   .../create/qemu-server/401.conf               |   31 +
>   .../create/qemu-server/402.conf               |   31 +
>   .../rollback/qemu-server/401.conf             |   36 +
>   .../rollback/qemu-server/402.conf             |   35 +
>   .../create/qemu-server/401.conf               |   13 +
>   .../create/qemu-server/402.conf               |   13 +
>   .../rollback/qemu-server/401.conf             |   35 +
>   .../rollback/qemu-server/402.conf             |   34 +
>   src/test/snapshot-test.pm                     |   82 +-
>   30 files changed, 2899 insertions(+), 73 deletions(-)
>   create mode 100644 src/test/QemuServerTest/FakeCFS.pm
>   create mode 100644 src/test/cfg2cmd/q35-windows-pinning-identity-only.conf
>   create mode 100644 src/test/cfg2cmd/q35-windows-pinning-identity-only.conf.cmd
>   create mode 100644 src/test/parse-config-expected/meta-identity-invalid.conf
>   create mode 100644 src/test/parse-config-expected/meta-identity-invalid.conf.strict.error
>   create mode 100644 src/test/parse-config-input/meta-identity-invalid.conf
>   create mode 100644 src/test/parse-config-input/meta-identity.conf
>   create mode 100644 src/test/restore-config-expected/150.conf
>   create mode 100644 src/test/restore-config-input/150.conf
>   create mode 100755 src/test/run_guest_identity_tests.pl
>   create mode 100644 src/test/snapshot-expected/create/qemu-server/401.conf
>   create mode 100644 src/test/snapshot-expected/create/qemu-server/402.conf
>   create mode 100644 src/test/snapshot-expected/rollback/qemu-server/401.conf
>   create mode 100644 src/test/snapshot-expected/rollback/qemu-server/402.conf
>   create mode 100644 src/test/snapshot-input/create/qemu-server/401.conf
>   create mode 100644 src/test/snapshot-input/create/qemu-server/402.conf
>   create mode 100644 src/test/snapshot-input/rollback/qemu-server/401.conf
>   create mode 100644 src/test/snapshot-input/rollback/qemu-server/402.conf
> 
> 
> container:
> 
> Thomas Lamprecht (8):
>    config: add read-only meta property with the creation time
>    fix #7846: config: add a guest identity to the 'meta' property
>    api: migrate, clone: refuse targets that would drop the guest identity
>    restore: take over the guest uid from the backup where possible
>    restore: refuse overwriting a container with another guest's backup
>    test: remote migration: check the cleanup of the target after failures
>    api: remote migration: take over the guest uid from the source
>    api: status: return the guest uid
> 
>   src/PVE/API2/LXC.pm         |  190 ++-
>   src/PVE/API2/LXC/Config.pm  |   29 +-
>   src/PVE/API2/LXC/Status.pm  |    6 +
>   src/PVE/CLI/pct.pm          |    7 +
>   src/PVE/LXC/Config.pm       |   51 +-
>   src/PVE/LXC/Migrate.pm      |    8 +-
>   src/test/Makefile           |    8 +-
>   src/test/config_tests.pl    |   23 +
>   src/test/lifecycle_tests.pl | 2446 +++++++++++++++++++++++++++++++++++
>   9 files changed, 2730 insertions(+), 38 deletions(-)
>   create mode 100755 src/test/lifecycle_tests.pl
> 
> 
> manager:
> 
> Thomas Lamprecht (6):
>    api: cluster resources: add guest uid and registration time
>    api: cluster status: add cluster ID
>    ui: restore: allow overwriting a guest with a backup of another guest
>    ui: migrate: refuse target nodes that would drop the guest identity
>    ui: guest summary: show the guest identity
>    api: bulk migrate: refuse targets that would drop the guest identity
> 
>   PVE/API2/Cluster.pm                      |  24 ++-
>   PVE/API2/Cluster/BulkAction/Guest.pm     |   5 +
>   PVE/API2/Nodes.pm                        |   3 +
>   test/ClusterResources_test.pl            | 249 +++++++++++++++++++++++
>   test/ClusterStatus_test.pl               | 114 +++++++++++
>   test/Makefile                            |  10 +-
>   www/manager6/Makefile                    |   1 +
>   www/manager6/panel/GuestIdentity.js      | 142 +++++++++++++
>   www/manager6/panel/GuestStatusView.js    |   3 +
>   www/manager6/panel/TemplateStatusView.js |   3 +
>   www/manager6/window/Migrate.js           |  29 +++
>   www/manager6/window/Restore.js           |  18 ++
>   12 files changed, 599 insertions(+), 2 deletions(-)
>   create mode 100755 test/ClusterResources_test.pl
>   create mode 100755 test/ClusterStatus_test.pl
>   create mode 100644 www/manager6/panel/GuestIdentity.js
> 
> 
> docs:
> 
> Thomas Lamprecht (4):
>    vzdump: describe the guest identity of VMs and containers
>    pvecm: document the cluster ID and how to get a new one
>    qm: configuration: describe the read-only meta property
>    pct: configuration: describe the read-only meta property
> 
>   pct.adoc      |  35 ++++++
>   pct.conf.adoc |   3 +
>   pmxcfs.adoc   |   1 +
>   pvecm.adoc    |  87 +++++++++++++
>   qm.adoc       |  38 ++++++
>   qm.conf.adoc  |   3 +
>   vzdump.adoc   | 335 ++++++++++++++++++++++++++++++++++++++++++++++++++
>   7 files changed, 502 insertions(+)
> 
> 
> Summary over all repositories:
>    87 files changed, 10876 insertions(+), 137 deletions(-)
> 





^ permalink raw reply	[relevance 17%]

* superseded: [PATCH cluster/guest-common/qemu-server/container/manager/docs v2 00/36] fix #7846: guest identity (uid) and cluster ID
  2026-11-17 22:34 18% [PATCH cluster/guest-common/qemu-server/container/manager/docs v2 00/36] " Thomas Lamprecht
                   ` (2 preceding siblings ...)
  2026-11-17 22:34 16% ` [PATCH docs v2 33/36] vzdump: describe the guest identity of VMs and containers Thomas Lamprecht
@ 2026-11-18  5:57 11% ` Thomas Lamprecht
  3 siblings, 0 replies; 32+ results
From: Thomas Lamprecht @ 2026-11-18  5:57 UTC (permalink / raw)
  To: pve-devel

I found a few issues here so sent a v3 to avoid having these cause friction
on testing/review.

superseded-by: https://lore.proxmox.com/pve-devel/20261118043817.1659212-1-t.lamprecht@proxmox.com/




^ permalink raw reply	[relevance 11%]

* [PATCH docs v3 35/38] vzdump: describe the guest identity of VMs and containers
  2026-11-18  4:37 18% [PATCH cluster/guest-common/qemu-server/container/manager/docs v3 00/38] " Thomas Lamprecht
  2026-11-18  4:37 22% ` [PATCH guest-common v3 09/38] guest identity: add helpers for the guest uid and registration time Thomas Lamprecht
  2026-11-18  4:37 15% ` [PATCH qemu-server v3 16/38] fix #7846: config: add a guest identity to the 'meta' property Thomas Lamprecht
@ 2026-11-18  4:37 16% ` Thomas Lamprecht
  2026-11-18 13:49 17% ` [PATCH cluster/guest-common/qemu-server/container/manager/docs v3 00/38] fix #7846: guest identity (uid) and cluster ID Dominik Csapak
  2026-11-19 10:38 11% ` superseded: " Thomas Lamprecht
  4 siblings, 0 replies; 32+ results
From: Thomas Lamprecht @ 2026-11-18  4:37 UTC (permalink / raw)
  To: pve-devel

Since Proxmox VE 9.3, VMs and containers have a guest identity in
'meta': a random uid and a registration time. Backup software and other
tools can distinguish a guest from another that reuses its VMID [0].

Administrators need to understand why restores over a different guest
are refused, when a restore keeps the uid of the backup, and why
migrations and clones to older nodes are blocked. Those nodes drop
'meta', including VM creation information used for hardware defaults.

Document the lifecycle, failed-restore retries, and mixed-version
restrictions in the backup and restore chapter, where users are most
likely to encounter the identity. Include migration and HA behavior
there so the rules can be read together.

[0]: https://bugzilla.proxmox.com/show_bug.cgi?id=7846

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
---

changes v2 -> v3:
* backups are still grouped by type and VMID, also for retention
* refused remote migration: do not remove the reported guest if it is
  the source itself
* own section for failed restores, with what a killed or late-failing
  restore leaves behind
* remote migration of a guest without uid, HA recovery through the node
  of the active CRM, and smaller corrections (the uid gets compared, not
  the identity)

changes v1 -> v2:
* say that the uid has 100 random bits and how rtime differs from ctime
* describe the refusal of a migration to another cluster, its typical
  cases and 'allow-new-uid'
* retry after a failed restore: scope the pending entry, name the
  warning, correct the placeholder case and add the note for enforced
  unique guest IDs

 vzdump.adoc | 332 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 332 insertions(+)

diff --git a/vzdump.adoc b/vzdump.adoc
index 44db027..1d74602 100644
--- a/vzdump.adoc
+++ b/vzdump.adoc
@@ -464,6 +464,13 @@ following CLI tools:
 
 For details see the corresponding manual pages.
 
+When you restore a backup over an existing guest, {pve} compares the `uid` of
+the backup and of the guest. If they differ, the restore is refused, unless you
+set the `allow-identity-mismatch` option. The existing guest then keeps its
+identity. See
+xref:guest_identity_restore[Restore Over an Existing Guest] for details and
+exceptions.
+
 Bandwidth Limit
 ~~~~~~~~~~~~~~~
 
@@ -563,6 +570,331 @@ file in `/var/log/proxmox-backup/file-restore/`. The log file might contain
 additional information in case an attempt to restore individual files or
 accessing file systems contained in a backup archive fails.
 
+[[guest_identity]]
+Guest Identity
+--------------
+
+Since {pve} 9.3, each virtual machine and container gets a guest identity: a
+random identifier, `uid`, and a registration time, `rtime`. Unlike a VMID,
+which can be reused after a guest is destroyed, the `uid` lets backup software
+and other tools recognize the same logical guest across restores and
+migrations, even under a different VMID. Whether an operation keeps the `uid`
+depends on the target and the options of the operation, as described in
+xref:guest_identity_lifecycle[Lifecycle].
+
+Backups are still grouped by guest type and VMID, also for retention. If a new
+guest reuses the VMID of a removed guest of the same type, pruning handles the
+backups of both guests together.
+
+[[guest_identity_values]]
+Identity Values
+~~~~~~~~~~~~~~~
+
+The guest identity is part of the `meta` property in the guest configuration.
+This property also contains the creation time `ctime` and, for VMs, the QEMU
+version that the VM was created with, `creation-qemu`:
+
+----
+meta: creation-qemu=10.1.2,ctime=1772444467,rtime=1794320571482,uid=w5qczgiem26qnwzwsoil
+----
+
+`uid`::
+
+A random identifier of 20 characters, consisting of the lowercase letters `a` to
+`z` and the digits `2` to `7`. It encodes 100 random bits, so two guests
+practically never get the same `uid` by chance.
+
+`rtime`::
+
+The time at which the guest was registered in this cluster, in milliseconds
+since the UNIX epoch. Creating or cloning a guest, restoring it to a free VMID,
+and migrating it from another cluster register the guest in the cluster. A
+guest restored to a free VMID gets a new `rtime`, even if it keeps the backup's
+`uid`. See xref:guest_identity_lifecycle[Lifecycle] for the other operations.
+As a timestamp, the `rtime` is not guaranteed to be unique.
+
+The `rtime` differs from the creation time `ctime`. The `ctime` stays with the
+guest: a clone has the `ctime` of its source, and a restored guest or a guest
+migrated from another cluster has that of the backup or of the source guest. The
+`rtime` is set whenever the guest gets its `uid` in this cluster. A guest whose
+`uid` is unchanged but whose `rtime` is newer was therefore registered again,
+for example by a restore to a free VMID.
+
+{pve} manages the `meta` property automatically. It is read-only through the
+API, even for `root@pam`.
+
+IMPORTANT: The `uid` helps to correlate a guest with its backups and copies,
+but does not prove where a guest comes from. Whoever restores a backup or
+migrates a guest into the cluster supplies the `uid` of that guest, which {pve}
+takes over if no other guest in the cluster has it. {pve} keeps a `uid` unique
+within a cluster only for operations through its API. A configuration file
+copied by hand has the same `uid` as the original, and guests in different
+clusters can have the same `uid`.
+
+[[guest_identity_read]]
+Reading the Identity
+~~~~~~~~~~~~~~~~~~~~
+
+The following places show the guest identity. All of them require the
+`VM.Audit` privilege on the guest.
+
+* In the web interface, the 'Summary' panel of the guest shows the `uid` as
+  'Unique ID'. The 'Details' button next to it, which has an info icon, opens
+  the 'Guest Identity' window. This window additionally shows the `rtime` as
+  'Registered' and the creation information.
+* The guest configuration, for example with `qm config <vmid>` or
+  `pct config <vmid>`, and through the API paths
+  `/nodes/<node>/qemu/<vmid>/config` and `/nodes/<node>/lxc/<vmid>/config`.
+* The guest status at the API paths `/nodes/<node>/qemu/<vmid>/status/current`
+  and `/nodes/<node>/lxc/<vmid>/status/current`, which contains the `uid`.
+* The cluster resources at the API path `/cluster/resources`, which contain the
+  `uid` and `rtime` of each guest, for example:
++
+----
+# pvesh get /cluster/resources --type vm --output-format json-pretty
+----
+
+The configuration in a backup contains the `meta` property as well. You can
+show it with `pvesm extractconfig <volume>`, for example.
+
+[[guest_identity_lifecycle]]
+Lifecycle
+~~~~~~~~~
+
+The following table shows how operations affect the identity of a guest.
+
+[width="100%",cols="3,4,2",options="header"]
+|===========================================================================
+|Operation |`uid` |`rtime`
+|Create, including import |new |current time
+|Clone, including linked clones and clones from snapshots |new |current time
+|Restore to a free VMID |the backup's `uid` if present and not used by another
+guest in the cluster; otherwise new |current time
+|Restore to a free VMID with `unique` set |new |current time
+|Restore over an existing guest that has a `uid`, with or without `unique` set
+|kept, see xref:guest_identity_restore[Restore Over an Existing Guest] |kept
+|Restore over an existing guest without a `uid` |as for a free VMID |current
+time
+|Migration to another cluster, on the target |the source guest's `uid`; new if
+another guest in the target cluster has it and `allow-new-uid` is set, or if the
+source node runs a {pve} version older than 9.3, see
+xref:guest_identity_remote_migration[Migration to Another Cluster] |current time
+|Migration to another cluster, on the source if the guest is kept |kept |kept
+|Snapshot rollback |kept, not taken from the snapshot |kept
+|Migration within the cluster, HA recovery, configuration change, backup,
+replication, conversion to a template |kept |kept
+|Destroy |removed |removed
+|===========================================================================
+
+Restores and migrations from another cluster report the outcome in their task
+log, in a line with `guest identity:`, for example:
+
+----
+guest identity: backup uid w5qczgiem26qnwzwsoil is in use by guest 100, keeping uid er3n3wqoqgcl362ep3da
+----
+
+When a restore takes over a `uid`, the guest first has a newly assigned `uid`,
+which the restore replaces with the `uid` of the backup at its end. Tools that
+read `/cluster/resources` during a restore can therefore see a `uid` that
+disappears afterwards, also on a guest that is no longer locked. A migration
+from another cluster takes over the `uid` of the source guest right at its
+start. In both cases, a changed `uid` does not mean that the task has finished.
+
+Guests that existed before the upgrade to {pve} 9.3 get their identity the
+first time a node running {pve} 9.3 or later writes their configuration. This
+happens, for example, when their configuration changes, when they are backed
+up, or when they are migrated to such a node. Their `rtime` is the time of that
+write. Backups made before that have no `uid`.
+
+When a tool restores a guest by removing it and creating a new one through the
+API, the new guest gets a new `uid`. To keep the identity, a tool has to change
+the existing guest in place, or let {pve} restore the guest.
+
+[[guest_identity_restore]]
+Restore Over an Existing Guest
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+If the existing guest already has a guest identity, restoring a backup over it
+keeps the `uid` and `rtime` of that guest. When both the guest and the backup
+have a `uid` and the values differ, {pve} treats the backup as belonging to
+another guest. This can happen when a VMID was reused. {pve} refuses such a
+restore before it overwrites the guest:
+
+----
+backup belongs to another guest: its uid 'w5qczgiem26qnwzwsoil' differs from uid 'er3n3wqoqgcl362ep3da' of the existing VM 100 - use 'allow-identity-mismatch' to overwrite the VM anyway
+----
+
+To restore such a backup anyway, set the `allow-identity-mismatch` option. The
+existing guest then keeps its identity. In the web interface, select 'Allow
+restoring a backup of another guest' in the restore window, which you open from
+the 'Backup' panel of the guest. On the command line, use for example:
+
+----
+# qmrestore <archive> <vmid> --force 1 --allow-identity-mismatch 1
+# pct restore <vmid> <archive> --force 1 --allow-identity-mismatch 1
+----
+
+Backups without a `uid`, such as backups made with {pve} versions older than
+9.3, are not refused. Container restores from standard input
+(`pct restore <vmid> -`) are an exception: the `uid` of such a backup is only
+known once the container has been overwritten. A restore from standard input
+over a container with a `uid` therefore always requires
+`allow-identity-mismatch`.
+
+[[guest_identity_failed_restore]]
+Failed Restores
+~~~~~~~~~~~~~~~
+
+A restore that fails or is stopped can leave the guest behind, for example a
+restore over an existing guest, or a VM restore that fails after it restored the
+data or in the live phase of a live restore. A container restore over an
+existing container that fails after it removed the old volumes removes the
+container. If the restore task was killed, the guest can also stay locked.
+Remove the lock with `qm unlock <vmid>` or `pct unlock <vmid>` before you retry
+the restore or remove the guest.
+
+If the failed restore was to a free VMID or over a guest without a `uid`, and it
+had already read a backup that has a `uid`, `qm pending <vmid>` or
+`pct pending <vmid>` lists an entry for `meta` with the `uid` of the backup. As
+long as this entry exists, retrying the same restore over the guest left behind
+is accepted. Starting the guest or changing its options removes the entry and
+logs a warning that names the `uid`. The retry is then refused like a restore of
+another guest's backup.
+
+A successful retry takes over the `uid` of the backup and sets a new `rtime`, as
+a restore to a free VMID does. The guest keeps its `uid` and `rtime` instead if
+another guest in the cluster has the `uid` of the backup, or if the retry sets
+`unique`. Restores from standard input still require `allow-identity-mismatch`,
+as described above.
+
+A guest that had a `uid` and no such entry before the failed restore keeps its
+`uid` and gets no entry. A retry is checked like the first attempt: a backup
+with the same `uid` is accepted, also after the guest was started or changed,
+and a backup with another `uid` requires `allow-identity-mismatch`.
+
+A restore to a free VMID that fails before it restored the data normally
+removes the guest again. If the restore task was killed, or if that removal
+failed, an empty placeholder can stay at that VMID instead. Unlock it as
+described above if it is locked, and remove it, for example with
+`qm destroy <vmid>` or `pct destroy <vmid>`. Add
+`--destroy-unreferenced-disks 1` to also remove volumes that a killed restore
+created for that VMID. In both cases, restore again. Use
+another VMID if the xref:pvecm_next_id_range[`next-id`] setting of the
+datacenter has the `unique` and `enforce` options set, as the first VMID then
+counts as used.
+
+If a restore over an existing guest without a `uid` stopped before it read the
+backup, for example because the backup storage was unreachable, the guest now
+has a new `uid`. Retry with `allow-identity-mismatch`. The guest then keeps the
+new `uid`.
+
+A restore can also complete with a warning starting with
+`guest identity: unable to adopt backup uid`, for example if the cluster-wide
+lock for this step could not be taken in time. The guest is then restored
+completely, but keeps its new `uid`. To take over the `uid` of the backup,
+repeat the restore over the guest before you start it or change its
+configuration.
+
+[[guest_identity_remote_migration]]
+Migration to Another Cluster
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+A migration to another cluster (`qm remote-migrate`, `pct remote-migrate`) keeps
+the `uid` of the guest. The target takes it over at the start of the migration,
+before any data is transferred.
+
+If another guest in the target cluster already has that `uid`, the migration is
+refused at that point. Typical cases are:
+
+* the guest gets migrated back to a cluster that still has the source guest of
+  an earlier migration, which stays there unless `delete` was set,
+* a copy of the guest was restored in the target cluster from a backup,
+* an earlier migration of the guest broke off after it had transferred the
+  configuration and left a locked guest in the target cluster,
+* the target is the cluster that the guest is in.
+
+The error ends with:
+
+----
+guest 105 in the target cluster already has the uid 'w5qczgiem26qnwzwsoil' of this guest - use 'allow-new-uid' to migrate it with a new uid
+----
+
+If the reported guest is the source guest itself, do not remove it. To keep the
+`uid`, migrate the guest within the cluster instead, with `qm migrate` or
+`pct migrate`.
+
+Otherwise, to keep the `uid`, remove the other guest in the target cluster and
+migrate again. To migrate anyway, set the `allow-new-uid` option. The migrated
+guest then gets a new `uid`, and the other guest keeps the old one. In both
+cases, use another target VMID if the xref:pvecm_next_id_range[`next-id`]
+setting of the target cluster has the `unique` and `enforce` options set, as the
+refused migration already used the first one. For example:
+
+----
+# qm remote-migrate <vmid> <target-vmid> <target-endpoint> --target-bridge <bridge> --target-storage <storage> --allow-new-uid 1
+----
+
+[[guest_identity_mixed_versions]]
+Mixed Versions in a Cluster
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+While some nodes of a cluster still run a {pve} version older than 9.3,
+migrating or cloning a guest to one of these nodes is refused. The guest keeps
+running on its current node. If the target node reports its version, the error
+message shows that version and the minimum required version. If the node does
+not report its version, the operation is refused because {pve} cannot verify
+that the node supports guest identities. The 'Migrate' window of the web
+interface shows the reason for the selected target node.
+
+Moves of HA-managed guests to such nodes are refused in the same way. A running
+VM that the HA stack migrates keeps running. The HA stack stops a container, and
+a VM that it relocates, before it migrates the guest, so such a guest is stopped
+although the move is then refused. The HA stack retries automatic moves as long
+as it selects such a node, and such a guest can stay stopped in the meantime.
+This includes moves for:
+
+* the maintenance mode,
+* a node shutdown with the `migrate` shutdown policy,
+* node affinity rules,
+* the CRS load balancer.
+
+Such moves complete only after the target nodes that the HA stack selects run
+{pve} 9.3 or later.
+
+To avoid refused moves while you upgrade a cluster, do one of the following:
+
+* Move all guests away from a node before you upgrade it.
+* Upgrade the packages on all nodes, one node at a time, before you reboot any
+  node or enable the maintenance mode.
+
+The reason for these refusals is that {pve} versions older than 9.3 ignore the
+whole `meta` property of a guest that has a guest identity, including the
+creation information. A VM started on such a node can therefore get different
+virtual hardware, see xref:qm_machine_type[Machine Type]. When such a node
+writes the configuration, the property is lost.
+
+The check covers migrations and clones started on a node running {pve} 9.3 or
+later. It does not cover:
+
+* the HA recovery of guests from a fenced node,
+* configuration files moved by hand,
+* operations started on a node with an older version.
+
+If an older node writes the configuration of a guest in one of these cases, the
+guest loses its `meta` property. In an HA recovery, such a node can also be the
+node of the active HA manager (CRM), which writes the configuration when it
+removes a leftover lock, for example of a backup. The guest gets a new identity
+the next time a node running {pve} 9.3 or later writes its configuration.
+
+Backups made with {pve} 9.3 or later contain the guest identity. Restore them
+only on nodes running {pve} 9.3 or later, because older versions ignore the
+`meta` property of such backups in the same way.
+
+A migration to another cluster (`qm remote-migrate`, `pct remote-migrate`) is
+refused right after connecting to a target node with a version older than 9.3,
+before any data is transferred. The error is
+`Remote tunnel endpoint too old, upgrade required`.
+
 [[vzdump_configuration]]
 Configuration
 -------------
-- 
2.47.3





^ permalink raw reply related	[relevance 16%]

* [PATCH qemu-server v3 16/38] fix #7846: config: add a guest identity to the 'meta' property
  2026-11-18  4:37 18% [PATCH cluster/guest-common/qemu-server/container/manager/docs v3 00/38] " Thomas Lamprecht
  2026-11-18  4:37 22% ` [PATCH guest-common v3 09/38] guest identity: add helpers for the guest uid and registration time Thomas Lamprecht
@ 2026-11-18  4:37 15% ` Thomas Lamprecht
  2026-11-18  4:37 16% ` [PATCH docs v3 35/38] vzdump: describe the guest identity of VMs and containers Thomas Lamprecht
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 32+ results
From: Thomas Lamprecht @ 2026-11-18  4:37 UTC (permalink / raw)
  To: pve-devel

Give VMs a guest identity in the read-only 'meta' property: a random
identifier, 'uid', and a registration time, 'rtime'. Tools can use it
to recognize a guest across restores and migrations, independently of
its VMID.

Enable the identity handling of the config class, so that each config
write keeps the identity a VM already has or assigns one if it has
none. New VMs, clones and imports get an identity when their VMID is
reserved. Existing VMs get one with their next config write. A stale
config, a clone source or a snapshot rollback cannot replace the
identity of a VM.

The other members of 'meta' behave as before. A config without creation
information thus gets a 'meta' property with only the identity. Older
qemu-server versions reject the new members and drop the whole property
on their next config write.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
---

changes v2 -> v3:
* group the imports of the new test script

changes v1 -> v2:
* rebase, adapt the tests

 src/PVE/QemuConfig.pm                         |   7 +
 src/PVE/QemuServer/MetaInfo.pm                |   2 +
 src/test/Makefile                             |   5 +-
 .../q35-windows-pinning-identity-only.conf    |   6 +
 ...q35-windows-pinning-identity-only.conf.cmd |  26 ++
 .../meta-identity-invalid.conf                |   6 +
 .../meta-identity-invalid.conf.strict.error   |   2 +
 .../meta-identity-invalid.conf                |   7 +
 .../parse-config-input/meta-identity.conf     |  20 ++
 src/test/run_guest_identity_tests.pl          | 258 ++++++++++++++++++
 src/test/run_parse_config_tests.pl            |   2 +-
 src/test/run_qemu_restore_config_tests.pl     |   3 +-
 .../create/qemu-server/401.conf               |  31 +++
 .../create/qemu-server/402.conf               |  31 +++
 .../rollback/qemu-server/401.conf             |  36 +++
 .../rollback/qemu-server/402.conf             |  35 +++
 .../create/qemu-server/401.conf               |  13 +
 .../create/qemu-server/402.conf               |  13 +
 .../rollback/qemu-server/401.conf             |  35 +++
 .../rollback/qemu-server/402.conf             |  34 +++
 src/test/snapshot-test.pm                     |  82 +++++-
 21 files changed, 640 insertions(+), 14 deletions(-)
 create mode 100644 src/test/cfg2cmd/q35-windows-pinning-identity-only.conf
 create mode 100644 src/test/cfg2cmd/q35-windows-pinning-identity-only.conf.cmd
 create mode 100644 src/test/parse-config-expected/meta-identity-invalid.conf
 create mode 100644 src/test/parse-config-expected/meta-identity-invalid.conf.strict.error
 create mode 100644 src/test/parse-config-input/meta-identity-invalid.conf
 create mode 100644 src/test/parse-config-input/meta-identity.conf
 create mode 100755 src/test/run_guest_identity_tests.pl
 create mode 100644 src/test/snapshot-expected/create/qemu-server/401.conf
 create mode 100644 src/test/snapshot-expected/create/qemu-server/402.conf
 create mode 100644 src/test/snapshot-expected/rollback/qemu-server/401.conf
 create mode 100644 src/test/snapshot-expected/rollback/qemu-server/402.conf
 create mode 100644 src/test/snapshot-input/create/qemu-server/401.conf
 create mode 100644 src/test/snapshot-input/create/qemu-server/402.conf
 create mode 100644 src/test/snapshot-input/rollback/qemu-server/401.conf
 create mode 100644 src/test/snapshot-input/rollback/qemu-server/402.conf

diff --git a/src/PVE/QemuConfig.pm b/src/PVE/QemuConfig.pm
index d89a62e6..ac9e202a 100644
--- a/src/PVE/QemuConfig.pm
+++ b/src/PVE/QemuConfig.pm
@@ -644,6 +644,13 @@ sub write_config {
     return $class->SUPER::write_config($vmid, $conf);
 }
 
+# the format of the 'meta' property includes the guest identity, see PVE::QemuServer::MetaInfo
+sub __identity_enabled {
+    my ($class) = @_;
+
+    return 1;
+}
+
 # END implemented abstract methods from PVE::AbstractConfig
 
 sub has_cloudinit {
diff --git a/src/PVE/QemuServer/MetaInfo.pm b/src/PVE/QemuServer/MetaInfo.pm
index b69e5a1c..399cd920 100644
--- a/src/PVE/QemuServer/MetaInfo.pm
+++ b/src/PVE/QemuServer/MetaInfo.pm
@@ -3,6 +3,7 @@ package PVE::QemuServer::MetaInfo;
 use strict;
 use warnings;
 
+use PVE::GuestIdentity;
 use PVE::JSONSchema;
 
 use PVE::QemuServer::Helpers;
@@ -20,6 +21,7 @@ our $meta_info_fmt = {
         pattern => '\d+(\.\d+)+',
         optional => 1,
     },
+    PVE::GuestIdentity::meta_format_properties()->%*,
 };
 
 sub parse_meta_info {
diff --git a/src/test/Makefile b/src/test/Makefile
index d8ee1d59..9d490838 100644
--- a/src/test/Makefile
+++ b/src/test/Makefile
@@ -1,6 +1,6 @@
 all: test
 
-test: test_snapshot test_cfg_to_cmd test_cfg_to_cmd_aarch64 test_hotplug test_hotplug_aarch64 test_pci_addr_conflicts test_pci_reservation test_qemu_img_convert test_migration test_restore_config test_parse_config test_memory test_raw_config_write test_api test_api_cloudinit_dump
+test: test_snapshot test_cfg_to_cmd test_cfg_to_cmd_aarch64 test_hotplug test_hotplug_aarch64 test_pci_addr_conflicts test_pci_reservation test_qemu_img_convert test_migration test_restore_config test_parse_config test_memory test_raw_config_write test_api test_api_cloudinit_dump test_guest_identity
 
 test_snapshot: run_snapshot_tests.pl
 	./run_snapshot_tests.pl
@@ -54,6 +54,9 @@ test_api: run_api_tests.pl
 test_api_cloudinit_dump: run_api_cloudinit_dump_tests.pl
 	./run_api_cloudinit_dump_tests.pl
 
+test_guest_identity: run_guest_identity_tests.pl QemuServerTest/FakeCFS.pm
+	./run_guest_identity_tests.pl
+
 .PHONY: clean
 clean:
 	rm -rf MigrationTest/run
diff --git a/src/test/cfg2cmd/q35-windows-pinning-identity-only.conf b/src/test/cfg2cmd/q35-windows-pinning-identity-only.conf
new file mode 100644
index 00000000..5242ec13
--- /dev/null
+++ b/src/test/cfg2cmd/q35-windows-pinning-identity-only.conf
@@ -0,0 +1,6 @@
+# TEST: Windows without pinned machine and with only the guest identity as meta info stays on 5.1
+machine: q35
+meta: rtime=1762300000000,uid=abcdefghijklmnopqrst
+ostype: win11
+smbios1: uuid=7b10d7af-b932-4c66-b2c3-3996152ec465
+vmgenid: c773c261-d800-4348-9f5d-167fadd53cf8
diff --git a/src/test/cfg2cmd/q35-windows-pinning-identity-only.conf.cmd b/src/test/cfg2cmd/q35-windows-pinning-identity-only.conf.cmd
new file mode 100644
index 00000000..67d20b79
--- /dev/null
+++ b/src/test/cfg2cmd/q35-windows-pinning-identity-only.conf.cmd
@@ -0,0 +1,26 @@
+/usr/bin/kvm \
+  -id 8006 \
+  -name vm8006 \
+  -no-shutdown \
+  -chardev 'socket,id=qmp,path=/var/run/qemu-server/8006.qmp,server=on,wait=off' \
+  -object 'monitor-qmp,chardev=qmp,id=monitor-qmp' \
+  -chardev 'socket,id=qmp-event,path=/var/run/qmeventd.sock,reconnect-ms=5000' \
+  -object 'monitor-qmp,chardev=qmp-event,id=monitor-qmp-event' \
+  -pidfile /var/run/qemu-server/8006.pid \
+  -daemonize \
+  -smbios 'type=1,uuid=7b10d7af-b932-4c66-b2c3-3996152ec465' \
+  -smp '1,sockets=1,cores=1,maxcpus=1' \
+  -nodefaults \
+  -boot 'menu=on,strict=on,reboot-timeout=1000,splash=/usr/share/qemu-server/bootsplash.jpg' \
+  -vnc 'unix:/var/run/qemu-server/8006.vnc,password=on' \
+  -global 'kvm-pit.lost_tick_policy=discard' \
+  -cpu 'kvm64,-cet-ibt,-cet-ss,enforce,hv_ipi,hv_relaxed,hv_reset,hv_runtime,hv_spinlocks=0x1fff,hv_stimer,hv_synic,hv_time,hv_vapic,hv_vpindex,+kvm_pv_eoi,+kvm_pv_unhalt,+lahf_lm,+sep' \
+  -m 512 \
+  -readconfig /usr/share/qemu-server/pve-q35-4.0.cfg \
+  -device 'vmgenid,guid=c773c261-d800-4348-9f5d-167fadd53cf8' \
+  -device 'usb-tablet,id=tablet,bus=ehci.0,port=1' \
+  -device 'VGA,id=vga,bus=pcie.0,addr=0x1,edid=off' \
+  -device 'virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3' \
+  -iscsi 'initiator-name=iqn.1993-08.org.debian:01:aabbccddeeff' \
+  -rtc 'driftfix=slew,base=localtime' \
+  -machine 'hpet=off,type=pc-q35-5.1+pve0'
diff --git a/src/test/parse-config-expected/meta-identity-invalid.conf b/src/test/parse-config-expected/meta-identity-invalid.conf
new file mode 100644
index 00000000..195514fa
--- /dev/null
+++ b/src/test/parse-config-expected/meta-identity-invalid.conf
@@ -0,0 +1,6 @@
+# VM with a guest uid that is not valid
+boot: order=scsi0
+cores: 2
+memory: 4096
+name: identity
+scsi0: local-lvm:vm-8006-disk-0,size=32G
diff --git a/src/test/parse-config-expected/meta-identity-invalid.conf.strict.error b/src/test/parse-config-expected/meta-identity-invalid.conf.strict.error
new file mode 100644
index 00000000..ae584c1f
--- /dev/null
+++ b/src/test/parse-config-expected/meta-identity-invalid.conf.strict.error
@@ -0,0 +1,2 @@
+vm 8006 - unable to parse value of 'meta' - format error
+uid: value does not match the regex pattern
diff --git a/src/test/parse-config-input/meta-identity-invalid.conf b/src/test/parse-config-input/meta-identity-invalid.conf
new file mode 100644
index 00000000..90e60197
--- /dev/null
+++ b/src/test/parse-config-input/meta-identity-invalid.conf
@@ -0,0 +1,7 @@
+# VM with a guest uid that is not valid
+boot: order=scsi0
+cores: 2
+memory: 4096
+meta: creation-qemu=10.1.2,ctime=1762000000,rtime=1762000000123,uid=ABCDEFGHIJKLMNOPQRST
+name: identity
+scsi0: local-lvm:vm-8006-disk-0,size=32G
diff --git a/src/test/parse-config-input/meta-identity.conf b/src/test/parse-config-input/meta-identity.conf
new file mode 100644
index 00000000..7a1e03be
--- /dev/null
+++ b/src/test/parse-config-input/meta-identity.conf
@@ -0,0 +1,20 @@
+# VM with guest identity
+boot: order=scsi0
+cores: 2
+memory: 4096
+meta: creation-qemu=10.1.2,ctime=1762000000,rtime=1762000000123,uid=abcdefghijklmnopqrst
+name: identity
+scsi0: local-lvm:vm-8006-disk-0,size=32G
+scsihw: virtio-scsi-single
+smbios1: uuid=7b4f2a1e-3c2d-4e5f-8a9b-0c1d2e3f4a5b
+
+[snap]
+boot: order=scsi0
+cores: 2
+memory: 4096
+meta: creation-qemu=10.1.2,ctime=1762000000,rtime=1762000000123,uid=abcdefghijklmnopqrst
+name: identity
+scsi0: local-lvm:vm-8006-disk-0,size=32G
+scsihw: virtio-scsi-single
+smbios1: uuid=7b4f2a1e-3c2d-4e5f-8a9b-0c1d2e3f4a5b
+snaptime: 1762000100
diff --git a/src/test/run_guest_identity_tests.pl b/src/test/run_guest_identity_tests.pl
new file mode 100755
index 00000000..16f012d4
--- /dev/null
+++ b/src/test/run_guest_identity_tests.pl
@@ -0,0 +1,258 @@
+#!/usr/bin/perl
+
+# Tests the guest identity of VM configs through the real config class methods, with a fake cluster
+# filesystem, see QemuServerTest::FakeCFS.
+
+use v5.36;
+
+use lib qw(.. .);
+
+use File::Temp qw(tempdir);
+use Test::MockModule;
+use Test::More;
+
+use PVE::JSONSchema;
+
+use PVE::QemuConfig;
+use PVE::QemuConfig::NoWrite;
+use PVE::QemuServer;
+use PVE::QemuServer::MetaInfo;
+
+use QemuServerTest::FakeCFS;
+
+my $UID_A = 'abcdefghijklmnopqrst';
+my $UID_B = 'bbbbbbbbbbbbbbbbbbbb';
+
+my $helpers_module = Test::MockModule->new('PVE::QemuServer::Helpers');
+$helpers_module->mock(kvm_user_version => sub { return '10.1.2'; });
+
+sub configs { return $QemuServerTest::FakeCFS::configs; }
+sub generated_uid { return QemuServerTest::FakeCFS::generated_uid(@_); }
+sub stored_identity { return QemuServerTest::FakeCFS::stored_identity(@_); }
+
+sub load_meta($vmid) {
+    return PVE::QemuServer::MetaInfo::parse_meta_info(PVE::QemuConfig->load_config($vmid)->{meta});
+}
+
+subtest 'meta format' => sub {
+    my $meta =
+        'creation-qemu=10.1.2,ctime=1700000000,rtime=1700000000123,uid=abcdefghijklmnopqrst';
+
+    is_deeply(
+        PVE::QemuServer::MetaInfo::parse_meta_info($meta),
+        {
+            'creation-qemu' => '10.1.2',
+            ctime => 1700000000,
+            rtime => 1700000000123,
+            uid => $UID_A,
+        },
+        'identity members get parsed',
+    );
+    is(
+        PVE::JSONSchema::print_property_string(
+            PVE::QemuServer::MetaInfo::parse_meta_info($meta),
+            $PVE::QemuServer::MetaInfo::meta_info_fmt,
+        ),
+        $meta,
+        'printing the parsed property gives the same string',
+    );
+
+    for my $invalid (
+        'uid=ABCDEFGHIJKLMNOPQRST', 'uid=abcdefghijklmnopqrs', 'rtime=-1', 'rtime=1x',
+    ) {
+        eval {
+            PVE::JSONSchema::parse_property_string(
+                $PVE::QemuServer::MetaInfo::meta_info_fmt, $invalid,
+            );
+        };
+        ok($@, "'$invalid' is rejected");
+    }
+
+    # versions before the identity members only know these two, and drop the whole property
+    my $old_fmt = {
+        ctime => $PVE::QemuServer::MetaInfo::meta_info_fmt->{ctime},
+        'creation-qemu' => $PVE::QemuServer::MetaInfo::meta_info_fmt->{'creation-qemu'},
+    };
+    eval { PVE::JSONSchema::parse_property_string($old_fmt, $meta) };
+    like(
+        $@,
+        qr/property is not defined in schema/,
+        'format without identity members rejects it',
+    );
+};
+
+subtest 'identities are enabled, but not for writing temporary configs' => sub {
+    QemuServerTest::FakeCFS::reset();
+
+    ok(PVE::QemuConfig->__identity_enabled(), 'enabled for PVE::QemuConfig');
+
+    my $conf = { name => 'template-cmd' };
+    PVE::QemuConfig::NoWrite->mark_config($conf);
+    eval { PVE::QemuConfig->write_config(100, $conf) };
+    is($@, "refusing to write temporary configuration\n", 'NoWrite refuses');
+    eval { PVE::QemuConfig::NoWrite->write_config(100, $conf) };
+    is(
+        $@,
+        "refusing to write temporary configuration\n",
+        'NoWrite refuses when called directly',
+    );
+    is_deeply(configs(), {}, 'nothing written');
+    is($QemuServerTest::FakeCFS::generated, 0, 'no identity generated');
+};
+
+subtest 'config writes keep the stored identity' => sub {
+    QemuServerTest::FakeCFS::reset();
+
+    PVE::QemuConfig->write_config(100, { memory => 512, meta => "rtime=1,uid=$UID_B" });
+    is_deeply(
+        stored_identity(100),
+        { uid => generated_uid(1), rtime => 1700000000000 },
+        'first write ignores a carried identity and generates one',
+    );
+    like(configs()->{100}, qr/^meta: rtime=1700000000000,uid=\w+$/m,
+        'written as meta property');
+
+    $QemuServerTest::FakeCFS::now_ms = 1800000000000;
+
+    my $conf = PVE::QemuConfig->load_config(100);
+    $conf->{meta} = "creation-qemu=9.2.0,ctime=1600000000,rtime=1,uid=$UID_B";
+    PVE::QemuConfig->write_config(100, $conf);
+    is_deeply(
+        load_meta(100),
+        {
+            'creation-qemu' => '9.2.0',
+            ctime => 1600000000,
+            rtime => 1700000000000,
+            uid => generated_uid(1),
+        },
+        'foreign identity replaced by the stored one, other members kept',
+    );
+
+    $conf = PVE::QemuConfig->load_config(100);
+    delete $conf->{meta};
+    PVE::QemuConfig->write_config(100, $conf);
+    is_deeply(
+        load_meta(100),
+        { rtime => 1700000000000, uid => generated_uid(1) },
+        'identity kept when the property is gone',
+    );
+
+    configs()->{101} = "memory: 512\nmeta: creation-qemu=8.0.2,ctime=1500000000\n";
+    $conf = PVE::QemuConfig->load_config(101);
+    $conf->{name} = 'old';
+    PVE::QemuConfig->write_config(101, $conf);
+    is_deeply(
+        load_meta(101),
+        {
+            'creation-qemu' => '8.0.2',
+            ctime => 1500000000,
+            rtime => 1800000000000,
+            uid => generated_uid(2),
+        },
+        'existing guest without identity gets one on its first write',
+    );
+};
+
+subtest 'create' => sub {
+    QemuServerTest::FakeCFS::reset();
+
+    my $reservation = PVE::QemuConfig->create_and_lock_config(100);
+    is_deeply(
+        $reservation,
+        {
+            existed => 0,
+            previous => undef,
+            'previous-pending-uid' => undef,
+            assigned => { uid => generated_uid(1), rtime => 1700000000000 },
+        },
+        'reservation stores a new identity',
+    );
+
+    $QemuServerTest::FakeCFS::now_ms = 1700000005000;
+
+    my $conf = { memory => 512, meta => PVE::QemuServer::MetaInfo::new_meta_info_string() };
+    PVE::QemuConfig->write_config(100, $conf);
+    my $meta = load_meta(100);
+    is_deeply(
+        [$meta->@{qw(creation-qemu uid rtime)}],
+        ['10.1.2', generated_uid(1), 1700000000000],
+        'final config keeps the reserved identity next to the creation info',
+    );
+    ok($meta->{ctime}, 'creation time set');
+};
+
+subtest 'clone' => sub {
+    QemuServerTest::FakeCFS::reset();
+
+    configs()->{100} = "memory: 512\nmeta: creation-qemu=9.2.0,ctime=1600000000,"
+        . "rtime=1600000000000,uid=$UID_A\nname: source\n";
+
+    for my $snapshot (0, 1) {
+        my $newid = 200 + $snapshot;
+        my $source = PVE::QemuConfig->load_config(100);
+        if ($snapshot) {
+            # a snapshot can carry any identity, the clone must not take it over either
+            $source = { memory => 256, meta => "rtime=1,uid=$UID_B" };
+        }
+
+        PVE::QemuConfig->create_and_lock_config($newid, 0, 'clone');
+
+        # like the clone API, which copies everything but some snapshot related keys
+        my $newconf = { $source->%*, lock => 'clone', name => "clone-$newid" };
+        delete $newconf->{digest};
+        PVE::QemuConfig->write_config($newid, $newconf);
+        delete $newconf->{lock};
+        PVE::QemuConfig->write_config($newid, $newconf);
+
+        my $uid = generated_uid(1 + $snapshot);
+        is(stored_identity($newid)->{uid}, $uid, "clone $newid has a new uid");
+        is_deeply(
+            load_meta($newid),
+            $snapshot
+            ? { rtime => 1700000000000, uid => $uid }
+            : {
+                'creation-qemu' => '9.2.0',
+                ctime => 1600000000,
+                rtime => 1700000000000,
+                uid => $uid,
+            },
+            "clone $newid keeps the creation info of its source",
+        );
+    }
+    is(stored_identity(100)->{uid}, $UID_A, 'source keeps its uid');
+};
+
+subtest 'importovf' => sub {
+    QemuServerTest::FakeCFS::reset();
+
+    require PVE::CLI::qm;
+
+    my $tmpdir = tempdir('importovf-XXXXXX', DIR => '.', CLEANUP => 1);
+    my $manifest = "$tmpdir/test.ovf";
+    PVE::Tools::file_set_contents($manifest, "<ovf/>\n");
+
+    my $storage_module = Test::MockModule->new('PVE::Storage');
+    $storage_module->mock(
+        config => sub { return {}; },
+        storage_check_enabled => sub { return {}; },
+    );
+    my $ovf_module = Test::MockModule->new('PVE::GuestImport::OVF');
+    $ovf_module->mock(
+        parse_ovf => sub {
+            return { qm => { name => 'imported', memory => 1024, cores => 2 }, disks => [] };
+        },
+    );
+
+    PVE::CLI::qm->importovf({ vmid => 100, manifest => $manifest, storage => 'local' });
+
+    my $conf = PVE::QemuConfig->load_config(100);
+    is($conf->{name}, 'imported', 'config imported');
+    ok(!defined($conf->{lock}), 'create lock removed');
+    is_deeply(
+        stored_identity(100),
+        { uid => generated_uid(1), rtime => 1700000000000 },
+        'imported VM got a new identity on reservation and kept it',
+    );
+};
+
+done_testing();
diff --git a/src/test/run_parse_config_tests.pl b/src/test/run_parse_config_tests.pl
index c30aad99..566eec4f 100755
--- a/src/test/run_parse_config_tests.pl
+++ b/src/test/run_parse_config_tests.pl
@@ -25,7 +25,7 @@ my $INPUT_DIR = './parse-config-input';
 my $EXPECTED_DIR = './parse-config-expected';
 
 # NOTE update when you add/remove tests
-plan tests => 2 * 11;
+plan tests => 2 * 13;
 
 sub run_tests {
     my ($strict) = @_;
diff --git a/src/test/run_qemu_restore_config_tests.pl b/src/test/run_qemu_restore_config_tests.pl
index 24abf046..1c6c6fef 100755
--- a/src/test/run_qemu_restore_config_tests.pl
+++ b/src/test/run_qemu_restore_config_tests.pl
@@ -309,7 +309,8 @@ sub restore_api {
     return ($err, $output);
 }
 
-my $TARGET_CONF = "memory: 1024\nmeta: creation-qemu=10.0.0,ctime=1700000000\nname: target\n";
+my $TARGET_CONF = "memory: 1024\nmeta: creation-qemu=10.0.0,ctime=1700000000,"
+    . "rtime=1700000000000,uid=tttttttttttttttttttt\nname: target\n";
 my $NOT_CLEANED_UP = qr/VM 100 state is NOT cleaned up/;
 
 for my $type (sort keys $ARCHIVES->%*) {
diff --git a/src/test/snapshot-expected/create/qemu-server/401.conf b/src/test/snapshot-expected/create/qemu-server/401.conf
new file mode 100644
index 00000000..87aadf80
--- /dev/null
+++ b/src/test/snapshot-expected/create/qemu-server/401.conf
@@ -0,0 +1,31 @@
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+memory: 8192
+meta: creation-qemu=10.0.0,ctime=1700000000,rtime=1700000000000,uid=abcdefghijklmnopqrst
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+parent: test
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+sockets: 1
+vga: qxl
+
+[test]
+#test comment
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+memory: 8192
+meta: creation-qemu=10.0.0,ctime=1700000000,rtime=1700000000000,uid=abcdefghijklmnopqrst
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+snaptime: 1234567890
+sockets: 1
+vga: qxl
diff --git a/src/test/snapshot-expected/create/qemu-server/402.conf b/src/test/snapshot-expected/create/qemu-server/402.conf
new file mode 100644
index 00000000..976c0a39
--- /dev/null
+++ b/src/test/snapshot-expected/create/qemu-server/402.conf
@@ -0,0 +1,31 @@
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+memory: 8192
+meta: creation-qemu=8.0.2,ctime=1600000000,rtime=1234567890123,uid=qrstuvwxyzbcdefghijk
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+parent: test
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+sockets: 1
+vga: qxl
+
+[test]
+#test comment
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+memory: 8192
+meta: creation-qemu=8.0.2,ctime=1600000000
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+snaptime: 1234567890
+sockets: 1
+vga: qxl
diff --git a/src/test/snapshot-expected/rollback/qemu-server/401.conf b/src/test/snapshot-expected/rollback/qemu-server/401.conf
new file mode 100644
index 00000000..6215ce26
--- /dev/null
+++ b/src/test/snapshot-expected/rollback/qemu-server/401.conf
@@ -0,0 +1,36 @@
+# this is a description
+agent: 1
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+memory: 8192
+meta: creation-qemu=9.2.0,ctime=1600000000,rtime=1700000000000,uid=abcdefghijklmnopqrst
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+parent: test
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+sockets: 1
+vga: qxl
+
+[test]
+#test comment
+agent: 1
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+machine: q35
+memory: 8192
+meta: creation-qemu=9.2.0,ctime=1600000000,rtime=1600000000000,uid=bbbbbbbbbbbbbbbbbbbb
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+snaptime: 1234567890
+sockets: 1
+vga: qxl
+vmstate: somestorage:state-volume
diff --git a/src/test/snapshot-expected/rollback/qemu-server/402.conf b/src/test/snapshot-expected/rollback/qemu-server/402.conf
new file mode 100644
index 00000000..a10bfa13
--- /dev/null
+++ b/src/test/snapshot-expected/rollback/qemu-server/402.conf
@@ -0,0 +1,35 @@
+# this is a description
+agent: 1
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+memory: 8192
+meta: rtime=1700000000000,uid=abcdefghijklmnopqrst
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+parent: test
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+sockets: 1
+vga: qxl
+
+[test]
+#test comment
+agent: 1
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+machine: q35
+memory: 8192
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+snaptime: 1234567890
+sockets: 1
+vga: qxl
+vmstate: somestorage:state-volume
diff --git a/src/test/snapshot-input/create/qemu-server/401.conf b/src/test/snapshot-input/create/qemu-server/401.conf
new file mode 100644
index 00000000..41ccdae5
--- /dev/null
+++ b/src/test/snapshot-input/create/qemu-server/401.conf
@@ -0,0 +1,13 @@
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+memory: 8192
+meta: creation-qemu=10.0.0,ctime=1700000000,rtime=1700000000000,uid=abcdefghijklmnopqrst
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+sockets: 1
+vga: qxl
diff --git a/src/test/snapshot-input/create/qemu-server/402.conf b/src/test/snapshot-input/create/qemu-server/402.conf
new file mode 100644
index 00000000..e03717b6
--- /dev/null
+++ b/src/test/snapshot-input/create/qemu-server/402.conf
@@ -0,0 +1,13 @@
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+memory: 8192
+meta: creation-qemu=8.0.2,ctime=1600000000
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+sockets: 1
+vga: qxl
diff --git a/src/test/snapshot-input/rollback/qemu-server/401.conf b/src/test/snapshot-input/rollback/qemu-server/401.conf
new file mode 100644
index 00000000..7895e0df
--- /dev/null
+++ b/src/test/snapshot-input/rollback/qemu-server/401.conf
@@ -0,0 +1,35 @@
+# this is a description
+agent: 1
+bootdisk: ide2
+cores: 2
+ide0: local:snapshotable-disk-1,size=32G
+ide2: none,media=cdrom
+memory: 4096
+meta: creation-qemu=10.0.0,ctime=1700000000,rtime=1700000000000,uid=abcdefghijklmnopqrst
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+parent: test
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+sockets: 2
+
+[test]
+#test comment
+agent: 1
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+machine: q35
+memory: 8192
+meta: creation-qemu=9.2.0,ctime=1600000000,rtime=1600000000000,uid=bbbbbbbbbbbbbbbbbbbb
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+snaptime: 1234567890
+sockets: 1
+vga: qxl
+vmstate: somestorage:state-volume
diff --git a/src/test/snapshot-input/rollback/qemu-server/402.conf b/src/test/snapshot-input/rollback/qemu-server/402.conf
new file mode 100644
index 00000000..0fa7fe51
--- /dev/null
+++ b/src/test/snapshot-input/rollback/qemu-server/402.conf
@@ -0,0 +1,34 @@
+# this is a description
+agent: 1
+bootdisk: ide2
+cores: 2
+ide0: local:snapshotable-disk-1,size=32G
+ide2: none,media=cdrom
+memory: 4096
+meta: creation-qemu=10.0.0,ctime=1700000000,rtime=1700000000000,uid=abcdefghijklmnopqrst
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+parent: test
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+sockets: 2
+
+[test]
+#test comment
+agent: 1
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+machine: q35
+memory: 8192
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+snaptime: 1234567890
+sockets: 1
+vga: qxl
+vmstate: somestorage:state-volume
diff --git a/src/test/snapshot-test.pm b/src/test/snapshot-test.pm
index 44e55d6a..84629f00 100644
--- a/src/test/snapshot-test.pm
+++ b/src/test/snapshot-test.pm
@@ -5,6 +5,7 @@ use warnings;
 
 use lib qw(..);
 
+use PVE::GuestHelpers;
 use PVE::Storage;
 use PVE::Storage::Plugin;
 use PVE::QemuServer;
@@ -30,6 +31,9 @@ my $freeze_possible;
 my $stop_possible;
 my $save_vmstate_works;
 my $vm_mon = {};
+my $real_write_config;
+
+my $original_write_config = \&PVE::QemuConfig::write_config;
 
 # Mocked methods
 
@@ -296,6 +300,13 @@ sub cfs_config_path {
     return "snapshot-working/$node/qemu-server/$vmid.conf";
 }
 
+# the same file that mocked_get_config reads, so that nothing looks at the host's /etc/pve
+sub config_file {
+    my ($class, $vmid, $node) = @_;
+
+    return $class->cfs_config_path($vmid, $node);
+}
+
 sub load_config {
     my ($class, $vmid, $node) = @_;
 
@@ -310,18 +321,10 @@ sub load_config {
 sub write_config {
     my ($class, $vmid, $conf) = @_;
 
-    my $filename = $class->cfs_config_path($vmid);
-
-    if ($conf->{snapshots}) {
-        foreach my $snapname (keys %{ $conf->{snapshots} }) {
-            $conf->{snapshots}->{$snapname}->{snaptime} = "1234567890"
-                if $conf->{snapshots}->{$snapname}->{snaptime};
-        }
-    }
+    # the real method with the guest identity handling, which writes through mocked_cfs_write_file
+    return $original_write_config->($class, $vmid, $conf) if $real_write_config;
 
-    my $raw = PVE::QemuServer::write_vm_config($filename, $conf);
-
-    PVE::Tools::file_set_contents($filename, $raw);
+    mocked_cfs_write_file($class->cfs_config_path($vmid), $conf);
 }
 
 sub has_feature {
@@ -345,6 +348,31 @@ sub assert_config_exists_on_node {
 }
 # END mocked PVE::QemuConfig methods
 
+# BEGIN mocked PVE::Cluster methods
+
+sub mocked_get_config {
+    my ($path) = @_;
+
+    return -e $path ? PVE::Tools::file_get_contents($path) : undef;
+}
+
+sub mocked_cfs_write_file {
+    my ($filename, $conf) = @_;
+
+    if ($conf->{snapshots}) {
+        foreach my $snapname (keys %{ $conf->{snapshots} }) {
+            $conf->{snapshots}->{$snapname}->{snaptime} = "1234567890"
+                if $conf->{snapshots}->{$snapname}->{snaptime};
+        }
+    }
+
+    my $raw = PVE::QemuServer::write_vm_config($filename, $conf);
+
+    PVE::Tools::file_set_contents($filename, $raw);
+}
+
+# END mocked PVE::Cluster methods
+
 # BEGIN mocked PVE::QemuServer::Helpers methods
 
 sub vm_running_locally {
@@ -441,6 +469,16 @@ sub vm_stop {
 PVE::Tools::run_command("rm -rf snapshot-working");
 PVE::Tools::run_command("cp -a snapshot-input snapshot-working");
 
+$PVE::GuestHelpers::lockdir = "snapshot-working/lock";
+
+my $cluster_module = Test::MockModule->new('PVE::Cluster');
+$cluster_module->mock('get_config', \&mocked_get_config);
+$cluster_module->mock('cfs_write_file', \&mocked_cfs_write_file);
+
+my $guest_identity_module = Test::MockModule->new('PVE::GuestIdentity');
+$guest_identity_module->mock('__random_bytes', sub { return '0123456789abcdefghij'; });
+$guest_identity_module->mock('__time_ms', sub { return 1234567890123; });
+
 my $qemu_migrate_helpers_module = Test::MockModule->new('PVE::QemuMigrate::Helpers');
 $qemu_migrate_helpers_module->mock('set_migration_caps', \&set_migration_caps);
 
@@ -453,6 +491,7 @@ $qemu_monitor_module->mock('qmp_cmd', \&qmp_cmd);
 my $qemu_config_module = Test::MockModule->new('PVE::QemuConfig');
 $qemu_config_module->mock('config_file_lock', \&config_file_lock);
 $qemu_config_module->mock('cfs_config_path', \&cfs_config_path);
+$qemu_config_module->mock('config_file', \&config_file);
 $qemu_config_module->mock('load_config', \&load_config);
 $qemu_config_module->mock('write_config', \&write_config);
 $qemu_config_module->mock('has_feature', \&has_feature);
@@ -641,6 +680,16 @@ testcase_create("303", "test", 1, "test comment", "storage activation failed\n\n
 
 $activate_storage_possible = 1;
 
+$real_write_config = 1;
+
+printf("Successful snapshot_create keeping the guest identity\n");
+testcase_create("401", "test", 0, "test comment", "", { "local:snapshotable-disk-1" => "test" });
+
+printf("Successful snapshot_create assigning a guest identity to a config without one\n");
+testcase_create("402", "test", 0, "test comment", "", { "local:snapshotable-disk-1" => "test" });
+
+$real_write_config = 0;
+
 $nodename = "delete";
 printf("\n");
 printf("Running delete tests\n");
@@ -777,6 +826,17 @@ testcase_rollback("303", "test", "storage activation failed\n");
 
 $activate_storage_possible = 1;
 
+$real_write_config = 1;
+
+printf("Successful snapshot_rollback keeping the current guest identity, not the snapshot's\n");
+testcase_rollback("401", "test", "", { "local:snapshotable-disk-1" => "test" });
+
+printf(
+    "Successful snapshot_rollback to a snapshot without meta info, keeping the guest identity\n");
+testcase_rollback("402", "test", "", { "local:snapshotable-disk-1" => "test" });
+
+$real_write_config = 0;
+
 done_testing();
 
 1;
-- 
2.47.3





^ permalink raw reply related	[relevance 15%]

* [PATCH guest-common v3 09/38] guest identity: add helpers for the guest uid and registration time
  2026-11-18  4:37 18% [PATCH cluster/guest-common/qemu-server/container/manager/docs v3 00/38] " Thomas Lamprecht
@ 2026-11-18  4:37 22% ` Thomas Lamprecht
  2026-11-18  4:37 15% ` [PATCH qemu-server v3 16/38] fix #7846: config: add a guest identity to the 'meta' property Thomas Lamprecht
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 32+ results
From: Thomas Lamprecht @ 2026-11-18  4:37 UTC (permalink / raw)
  To: pve-devel

A VMID can be reused, and a guest can get a different VMID or move
to another cluster after a restore or remote migration. External tools
such as backup products need to recognize the same logical guest
independently of its VMID, as described in bug #7846.

Provide shared helpers for a random uid of 20 characters from the
lowercase base32 alphabet, which is 100 random bits, and a registration
time in milliseconds. Both are members of the guest config's 'meta'
property. Supply format definitions for both guest types and extract or
merge the identity without requiring knowledge of other members,
including newer ones. Also read it from a raw config, as the parser of a
guest type can drop a 'meta' property with members it does not know.

100 bits make a duplicate practically impossible, and the uid still fits
into a 128-bit value with 28 bits to spare, for example for a format
version and extra data, should a later format need them. Base32 keeps it
at 20 characters, about half the width of a UUID in its usual notation,
and only uses lowercase letters and digits. Each character comes from a
random byte of its own, so no encoder is needed.

The registration time is the time a guest got its uid in this cluster.
Unlike the creation time, which a clone, a restore and a migration from
another cluster copy along with the guest, it changes when a guest is
registered again, for example by a restore to a free VMID. Tools can use
it to tell such a guest from the one they knew, also if both have the
same uid.

Also provide a minimum node-version check for migration targets. Older
versions drop the identity on config writes. Report the required and
available versions so callers can explain a refusal, with a shared
schema for API results; missing version information counts as too old.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
---

changes v2 -> v3:
* shorter description of the uid, which the status and resource APIs
  show too
* reword the comment about the size and the commit message about rtime:
  an in-place restore keeps the rtime

changes v1 -> v2:
* use v5.36 and signatures
* take each character of the uid from a random byte of its own, without
  an encoder (Dominik)
* add a helper to read the identity from a raw config, shared by the
  config write and the VM restore, which picks the 'meta' line like
  pmxcfs does
* add the schema of the migration precondition result, shared by both
  guest types
* explain the format, the difference between rtime and ctime, and why
  the generic property string helpers are not used (Dominik)
* shorter description of the uid

Note: MIN_PVE_MANAGER_VERSION (9.2.31) is a stand-in. It has to become
the first pve-manager version that depends on the qemu-server and
pve-container versions with this series, see the cover letter.

 src/Makefile                      |   1 +
 src/PVE/GuestIdentity.pm          | 231 ++++++++++++++++++++
 src/tests/Makefile                |   7 +-
 src/tests/guest-identity-tests.pl | 338 ++++++++++++++++++++++++++++++
 4 files changed, 575 insertions(+), 2 deletions(-)
 create mode 100644 src/PVE/GuestIdentity.pm
 create mode 100755 src/tests/guest-identity-tests.pl

diff --git a/src/Makefile b/src/Makefile
index 161dbe5..af4c277 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -10,6 +10,7 @@ install: PVE
 	install -m 0644 PVE/AbstractMigrate.pm ${PERL5DIR}/PVE/
 	install -m 0644 PVE/GuestHelpers.pm ${PERL5DIR}/PVE/
 	install -m 0644 PVE/GuestID.pm ${PERL5DIR}/PVE/
+	install -m 0644 PVE/GuestIdentity.pm ${PERL5DIR}/PVE/
 	install -m 0644 PVE/Replication.pm ${PERL5DIR}/PVE/
 	install -m 0644 PVE/ReplicationConfig.pm ${PERL5DIR}/PVE/
 	install -m 0644 PVE/ReplicationState.pm ${PERL5DIR}/PVE/
diff --git a/src/PVE/GuestIdentity.pm b/src/PVE/GuestIdentity.pm
new file mode 100644
index 0000000..27dbf8b
--- /dev/null
+++ b/src/PVE/GuestIdentity.pm
@@ -0,0 +1,231 @@
+package PVE::GuestIdentity;
+
+use v5.36;
+
+use Time::HiRes;
+
+use PVE::Cluster;
+
+# The identity of a guest, VM or container alike, consists of two members of the 'meta' property
+# string in the top-level section of its config: 'uid', a random identifier of the guest's lineage
+# (100 bits as 20 characters of the lowercase RFC 4648 base32 alphabet), and 'rtime', the time the
+# config was registered in this cluster (milliseconds since the epoch). The functions here pass it
+# as a hash with these two keys.
+#
+# 100 random bits make a duplicate uid practically impossible: a billion uids contain one with a
+# probability of about 4 * 10^-13. They also leave 28 bits of a 128-bit value free, for example for
+# a format version and extra data, should a later format need them. Base32 keeps the uid at 20
+# characters, about half the width of a UUID in its usual notation, and only uses lowercase letters
+# and digits, which need no quoting in a property string.
+#
+# Unlike the creation time 'ctime' of the same property, which a clone, a restore and a migration
+# from another cluster copy along with the guest, the rtime belongs to the uid of the guest in this
+# cluster: it is the time the guest got its uid here, be it a new one or one it took over. So a
+# changed rtime tells that a guest was registered again, even if its uid is the same as before.
+
+# Must match the first pve-manager release that depends on the qemu-server and pve-container
+# versions handling the identity. Older nodes drop the whole 'meta' property on their next write
+# of a guest config.
+use constant MIN_PVE_MANAGER_VERSION => '9.2.31';
+
+my $UID_LENGTH = 20;
+my $UID_ALPHABET = 'abcdefghijklmnopqrstuvwxyz234567';
+my $UID_PATTERN = "[a-z2-7]{$UID_LENGTH}";
+
+# 15 digits of milliseconds last until the year 33658
+my $RTIME_MAX = 999_999_999_999_999;
+
+# Returns $len random bytes from the kernel's random number generator.
+sub __random_bytes($len) {
+    open(my $fh, '<', '/dev/urandom') or die "unable to open /dev/urandom - $!\n";
+    my $buf = '';
+    my $read = sysread($fh, $buf, $len);
+    die "unable to read from /dev/urandom - $!\n" if !defined($read);
+    die "short read from /dev/urandom\n" if $read != $len;
+    close($fh);
+
+    return $buf;
+}
+
+# Returns the current time in milliseconds since the epoch.
+sub __time_ms() {
+    my ($sec, $usec) = Time::HiRes::gettimeofday();
+
+    return $sec * 1000 + int($usec / 1000);
+}
+
+# Returns a random uid. Each character comes from the lowest 5 bits of a random byte of its own, so
+# it is uniformly distributed over the alphabet.
+my sub random_uid() {
+    my $bytes = __random_bytes($UID_LENGTH);
+
+    return join('', map { substr($UID_ALPHABET, ord($_) & 31, 1) } split(//, $bytes));
+}
+
+my sub is_valid_uid($uid) {
+    return defined($uid) && $uid =~ m/^$UID_PATTERN\z/;
+}
+
+my sub is_valid_rtime($rtime) {
+    return defined($rtime) && $rtime =~ m/^[0-9]{1,15}\z/;
+}
+
+# Returns the JSON schema properties of the identity members, for merging into the format of the
+# 'meta' property string of a guest type. Every call returns a new copy.
+sub meta_format_properties() {
+    return {
+        uid => {
+            type => 'string',
+            pattern => $UID_PATTERN,
+            description => "Random identifier of the guest lineage, independent of the VMID.",
+            optional => 1,
+        },
+        rtime => {
+            type => 'integer',
+            minimum => 0,
+            maximum => $RTIME_MAX,
+            description => "Time the guest was registered in this cluster, for example by"
+                . " creation, restore, or migration from another cluster, in milliseconds since"
+                . " the UNIX epoch.",
+            optional => 1,
+        },
+    };
+}
+
+# Returns a new identity with the current time as rtime. Its uid is $uid if given, otherwise a
+# random one.
+sub new_identity($uid = undef) {
+    die "invalid guest identity uid '$uid'\n" if defined($uid) && !is_valid_uid($uid);
+
+    return {
+        uid => $uid // random_uid(),
+        rtime => __time_ms(),
+    };
+}
+
+# Extracts the identity from the 'meta' property string $meta, which may contain any other
+# members, including ones unknown to this version.
+#
+# Returns undef if $meta has no valid uid, and an identity otherwise. Its rtime is undef if the
+# rtime member is missing or invalid. A member given more than once counts as invalid.
+#
+# This does not use PVE::JSONSchema::parse_property_string on purpose. That parser rejects the
+# whole string if one member is unknown or invalid. A guest without a readable identity gets a new
+# one with the next config write, so a problem with another member must not hide the uid.
+sub parse_identity($meta) {
+    return undef if !defined($meta);
+
+    my $values = {};
+    for my $part (split(/,/, $meta)) {
+        my ($key, $value) = $part =~ m/^([^=]+)=(.*)\z/ or next;
+        next if $key ne 'uid' && $key ne 'rtime';
+        $values->{$key} = exists($values->{$key}) ? undef : $value;
+    }
+
+    return undef if !is_valid_uid($values->{uid});
+
+    return {
+        uid => $values->{uid},
+        rtime => is_valid_rtime($values->{rtime}) ? $values->{rtime} : undef,
+    };
+}
+
+# Returns the 'meta' property string $meta, which may be undef, with the identity members set to
+# $identity. All other members are kept as they are, also ones unknown to this version, which
+# PVE::JSONSchema::print_property_string would reject.
+sub merge_identity($meta, $identity) {
+    die "invalid guest identity uid\n" if !is_valid_uid($identity->{uid});
+    die "invalid guest identity rtime\n" if !is_valid_rtime($identity->{rtime});
+
+    my (@plain, @members);
+    for my $part (split(/,/, $meta // '')) {
+        next if $part =~ m/^\s*\z/;
+
+        if (my ($key) = $part =~ m/^([^=]+)=/) {
+            push @members, [$key, $part] if $key ne 'uid' && $key ne 'rtime';
+        } else {
+            push @plain, $part;
+        }
+    }
+    push @members, ['rtime', "rtime=$identity->{rtime}"], ['uid', "uid=$identity->{uid}"];
+
+    # same order as PVE::JSONSchema::print_property_string uses, so that a guest type parsing and
+    # printing the property string again does not change it
+    return join(',', @plain, map { $_->[1] } sort { $a->[0] cmp $b->[0] } @members);
+}
+
+# Returns the identity in the top-level section of the raw guest config $raw, undef if it has none.
+# Only looks at the 'meta' property, so this also finds the identity in a config that the parser of
+# the guest type rejects or reads without 'meta', for example because of members from a newer
+# version.
+#
+# If a manual edit left more than one 'meta' line, the last one with anything after the colon
+# counts, also if that is only whitespace. The property lookup of pmxcfs does the same, and the
+# cluster-wide check of adopt uses it.
+sub parse_identity_from_raw_config($raw) {
+    my $meta;
+    for my $line (split(/\n/, $raw)) {
+        last if $line =~ m/^\[/; # snapshot or other section
+        $meta = $1 =~ s/^\s+|\s+$//gr if $line =~ m/^meta:(.+)$/;
+    }
+
+    return parse_identity($meta);
+}
+
+# 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
+# the node reports, if any.
+sub node_identity_unsupported($node) {
+    my $required = MIN_PVE_MANAGER_VERSION;
+    my ($major, $minor, $release) = split(/\./, $required);
+
+    my $supported =
+        eval { PVE::Cluster::node_pvecfg_version_at_least($node, $major, $minor, $release) };
+    return undef if $supported;
+
+    my $version = eval { PVE::Cluster::get_node_pvecfg_version($node) };
+
+    return { 'required-version' => $required, defined($version) ? (version => $version) : () };
+}
+
+# Returns the JSON schema of what node_identity_unsupported returns for a refused node, for the
+# result of API calls that report why a node is not allowed as migration target. Every call returns
+# a new copy.
+sub node_identity_unsupported_schema() {
+    return {
+        description =>
+            "Set if migrating to the node is refused because the node does not report a"
+            . " Proxmox VE version that keeps the guest identity.",
+        type => 'object',
+        optional => 1,
+        properties => {
+            version => {
+                description => "The Proxmox VE version the node reports.",
+                type => 'string',
+                optional => 1,
+            },
+            'required-version' => {
+                description => "The minimum Proxmox VE version that keeps the guest identity.",
+                type => 'string',
+            },
+        },
+    };
+}
+
+# Dies unless $node runs a version of Proxmox VE that keeps the identity when writing guest
+# configs, see node_identity_unsupported.
+sub assert_node_supports_identity($node) {
+    my $unsupported = node_identity_unsupported($node) or return;
+    my ($version, $required) = $unsupported->@{qw(version required-version)};
+
+    if (!defined($version)) {
+        die "node '$node' does not report its Proxmox VE version, so it is unknown whether the node"
+            . " keeps the guest identity\n";
+    }
+
+    die "node '$node' runs Proxmox VE $version, keeping the guest identity requires $required or"
+        . " newer - upgrade the node first\n";
+}
+
+1;
diff --git a/src/tests/Makefile b/src/tests/Makefile
index 8eb38a8..e2c3d01 100644
--- a/src/tests/Makefile
+++ b/src/tests/Makefile
@@ -1,8 +1,8 @@
 
 all:
 
-.PHONY: check abstract-config guest-id hookscript
-check: abstract-config guest-id hookscript
+.PHONY: check abstract-config guest-id guest-identity hookscript
+check: abstract-config guest-id guest-identity hookscript
 
 abstract-config: abstract-config-tests.pl
 	perl -I.. ./abstract-config-tests.pl
@@ -10,5 +10,8 @@ abstract-config: abstract-config-tests.pl
 guest-id: guest-id-tests.pl
 	perl -I.. ./guest-id-tests.pl
 
+guest-identity: guest-identity-tests.pl
+	perl -I.. ./guest-identity-tests.pl
+
 hookscript: hookscript-tests.pl
 	perl -I.. ./hookscript-tests.pl
diff --git a/src/tests/guest-identity-tests.pl b/src/tests/guest-identity-tests.pl
new file mode 100755
index 0000000..241e18c
--- /dev/null
+++ b/src/tests/guest-identity-tests.pl
@@ -0,0 +1,338 @@
+#!/usr/bin/perl
+
+use v5.36;
+
+use lib qw(..);
+
+use Test::MockModule;
+use Test::More;
+use Time::HiRes;
+
+use PVE::JSONSchema;
+use PVE::Tools;
+
+use PVE::GuestIdentity;
+
+subtest 'generation with fixed random bytes and time' => sub {
+    my $random_bytes = [];
+    my $time_ms = 1_700_000_000_123;
+
+    my $identity_module = Test::MockModule->new('PVE::GuestIdentity');
+    $identity_module->redefine(
+        __random_bytes => sub {
+            my ($len) = @_;
+            my $bytes = shift(@$random_bytes) // die "test error: no random bytes left\n";
+            die "test error: requested $len random bytes\n" if length($bytes) != $len;
+            return $bytes;
+        },
+        __time_ms => sub { return $time_ms; },
+    );
+
+    # each byte gives one character, its lowest 5 bits select it from the lowercase RFC 4648 base32
+    # alphabet
+    my $vectors = [
+        ["\x00" x 20, 'a' x 20],
+        ["\xff" x 20, '7' x 20],
+        ['0123456789abcdefghij', 'qrstuvwxyzbcdefghijk'],
+        [pack('C*', 0 .. 19), 'abcdefghijklmnopqrst'],
+        [pack('C*', 12 .. 31), 'mnopqrstuvwxyz234567'],
+        [pack('C*', map { $_ | 0xe0 } 0 .. 19), 'abcdefghijklmnopqrst'],
+    ];
+
+    for my $vector (@$vectors) {
+        my ($bytes, $uid) = @$vector;
+        $random_bytes = [$bytes];
+        is_deeply(
+            PVE::GuestIdentity::new_identity(),
+            { uid => $uid, rtime => $time_ms },
+            "encodes " . unpack('H*', $bytes),
+        );
+    }
+
+    # every symbol is as likely at each position, as each of them comes from 8 of the 256 values of
+    # the byte at that position
+    my $alphabet = 'abcdefghijklmnopqrstuvwxyz234567';
+    my $mismatches = 0;
+    for my $position (0 .. 19) {
+        for my $value (0 .. 255) {
+            my $bytes = "\x00" x 20;
+            substr($bytes, $position, 1) = chr($value);
+            $random_bytes = [$bytes];
+            my $expected = 'a' x 20;
+            substr($expected, $position, 1) = substr($alphabet, $value % 32, 1);
+            $mismatches++ if PVE::GuestIdentity::new_identity()->{uid} ne $expected;
+        }
+    }
+    is($mismatches, 0, 'each character comes from the byte at its position');
+
+    $random_bytes = [];
+    is_deeply(
+        PVE::GuestIdentity::new_identity('gaytemzugu3doobzmfrg'),
+        { uid => 'gaytemzugu3doobzmfrg', rtime => $time_ms },
+        'given uid is used',
+    );
+    eval { PVE::GuestIdentity::new_identity('GAYTEMZUGU3DOOBZMFRG') };
+    like($@, qr/invalid guest identity uid/, 'invalid given uid is rejected');
+};
+
+subtest 'generation' => sub {
+    my $first = PVE::GuestIdentity::new_identity();
+    my $second = PVE::GuestIdentity::new_identity();
+    like($first->{uid}, qr/^[a-z2-7]{20}\z/, 'uid has the expected format');
+    my @uids = map { PVE::GuestIdentity::new_identity()->{uid} } 1 .. 100;
+    is_deeply([grep { !m/^[a-z2-7]{20}\z/ } @uids], [], 'uids have 20 characters, no padding');
+    isnt($first->{uid}, $second->{uid}, 'uids differ');
+
+    my $before = int(Time::HiRes::time() * 1000);
+    my $rtime = PVE::GuestIdentity::new_identity()->{rtime};
+    my $after = int(Time::HiRes::time() * 1000) + 1;
+    like($rtime, qr/^\d+\z/, 'rtime is an integer');
+    ok($rtime >= $before && $rtime <= $after, 'rtime is the current time in milliseconds');
+};
+
+subtest 'format properties' => sub {
+    my $format = {
+        ctime => { type => 'integer', optional => 1 },
+        PVE::GuestIdentity::meta_format_properties()->%*,
+    };
+
+    is_deeply(
+        PVE::JSONSchema::parse_property_string(
+            $format,
+            'ctime=1700000000,rtime=1700000000123,uid=gaytemzugu3doobzmfrg',
+        ),
+        { ctime => 1700000000, rtime => 1700000000123, uid => 'gaytemzugu3doobzmfrg' },
+        'meta string with identity parses with a merged format',
+    );
+
+    for my $invalid (
+        'uid=GAYTEMZUGU3DOOBZMFRG',
+        'uid=gaytemzugu3doobzmfr',
+        'uid=gaytemzugu3doobzmfrga',
+        'uid=gaytemzugu3doobzmfr0',
+        'uid=' . substr('gaytemzugu3doobzmfrg', 0, 16),
+        'rtime=-1',
+        'rtime=1.5',
+        'rtime=1000000000000000',
+    ) {
+        eval { PVE::JSONSchema::parse_property_string($format, $invalid) };
+        ok($@, "format rejects '$invalid'");
+    }
+
+    my $copy = PVE::GuestIdentity::meta_format_properties();
+    $copy->{uid}->{pattern} = '.*';
+    isnt(
+        PVE::GuestIdentity::meta_format_properties()->{uid}->{pattern},
+        '.*',
+        'callers get their own copy',
+    );
+};
+
+subtest 'parse identity' => sub {
+    my $uid = 'gaytemzugu3doobzmfrg';
+    my $tests = [
+        [undef, undef, 'no meta'],
+        ['', undef, 'empty meta'],
+        ['ctime=1700000000', undef, 'meta without identity'],
+        [
+            "creation-qemu=10.1.2,ctime=1700000000,rtime=123,uid=$uid",
+            { uid => $uid, rtime => 123 },
+            'identity next to other members',
+        ],
+        [
+            "future=a b,uid=$uid,other,rtime=0",
+            { uid => $uid, rtime => 0 },
+            'unknown members and odd parts are ignored',
+        ],
+        ["rtime=123,uid=$uid", { uid => $uid, rtime => 123 }, 'identity only'],
+        ["uid=$uid", { uid => $uid, rtime => undef }, 'missing rtime'],
+        ["uid=$uid,rtime=12a", { uid => $uid, rtime => undef }, 'invalid rtime'],
+        ["uid=$uid,rtime=-5", { uid => $uid, rtime => undef }, 'negative rtime'],
+        [
+            "uid=$uid,rtime=999999999999999",
+            { uid => $uid, rtime => 999999999999999 },
+            'maximum rtime',
+        ],
+        ["uid=$uid,rtime=1000000000000000", { uid => $uid, rtime => undef }, 'too large rtime'],
+        [
+            "uid=$uid,rtime=\x{0661}\x{0662}",
+            { uid => $uid, rtime => undef },
+            'non-ASCII digits',
+        ],
+        ["uid=$uid,rtime=1,rtime=2", { uid => $uid, rtime => undef }, 'duplicate rtime'],
+        ['rtime=123', undef, 'rtime without uid'],
+        ["uid=$uid,uid=$uid,rtime=1", undef, 'duplicate uid'],
+        ['uid=GAYTEMZUGU3DOOBZMFRG,rtime=1', undef, 'uppercase uid'],
+        ['uid=gaytemzugu3doobzmfr,rtime=1', undef, 'short uid'],
+        ['uid=gaytemzugu3doobzmfrga,rtime=1', undef, 'long uid'],
+        ['uid=' . substr($uid, 0, 16) . ',rtime=1', undef, '16-character uid'],
+        ['uid=gaytemzugu3doobzmfr1,rtime=1', undef, 'uid outside of the alphabet'],
+        ["uid= $uid,rtime=1", undef, 'uid with whitespace'],
+    ];
+
+    for my $test (@$tests) {
+        my ($meta, $expected, $name) = @$test;
+        is_deeply(PVE::GuestIdentity::parse_identity($meta), $expected, $name);
+    }
+};
+
+subtest 'parse identity from raw config' => sub {
+    my $uid = 'gaytemzugu3doobzmfrg';
+    my $other = 'aaaqeayeaudaocajbifq';
+    my $identity = { uid => $uid, rtime => 123 };
+    my $tests = [
+        ['', undef, 'empty config'],
+        ["memory: 512\n", undef, 'no meta'],
+        [
+            "memory: 512\nmeta: ctime=1,rtime=123,uid=$uid\ncores: 2\n",
+            $identity,
+            'top-level meta',
+        ],
+        ["meta:   rtime=123,uid=$uid  \n", $identity, 'surrounding whitespace'],
+        ["meta: rtime=1,uid=$other\nmeta: rtime=123,uid=$uid\n", $identity, 'last meta wins'],
+        ["meta: future=a b,rtime=123,uid=$uid\n", $identity, 'unknown members'],
+        ["meta: rtime=123,uid=$uid\nmeta:\n", $identity, 'meta line without value is ignored'],
+        [
+            "meta: rtime=123,uid=$uid\nmeta:   \n", undef, 'meta line with only spaces counts',
+        ],
+        ["#meta: rtime=123,uid=$uid\n", undef, 'description line'],
+        ["memory: 512\n\n[PENDING]\nmeta: uid=$uid\n", undef, 'pending section is ignored'],
+        [
+            "meta: rtime=123,uid=$uid\n\n[snap]\nmeta: rtime=1,uid=$other\n",
+            $identity,
+            'snapshot section is ignored',
+        ],
+    ];
+
+    for my $test (@$tests) {
+        my ($raw, $expected, $name) = @$test;
+        is_deeply(PVE::GuestIdentity::parse_identity_from_raw_config($raw), $expected, $name);
+    }
+};
+
+subtest 'merge identity' => sub {
+    my $identity = { uid => 'gaytemzugu3doobzmfrg', rtime => 1700000000123 };
+    my $members = 'rtime=1700000000123,uid=gaytemzugu3doobzmfrg';
+    my $tests = [
+        [undef, $members, 'no meta'],
+        ['', $members, 'empty meta'],
+        [
+            'creation-qemu=10.1.2,ctime=1700000000',
+            "creation-qemu=10.1.2,ctime=1700000000,$members",
+            'other members are kept',
+        ],
+        [
+            'ctime=1,rtime=5,uid=aaaaaaaaaaaaaaaaaaaa',
+            "ctime=1,$members",
+            'existing identity is replaced',
+        ],
+        [
+            'uid=bogus,zz-future=x,rtime=1,uid=aaaaaaaaaaaaaaaaaaaa,ctime=1',
+            "ctime=1,$members,zz-future=x",
+            'invalid and duplicate identity members are dropped, unknown members kept',
+        ],
+        ['plain,ctime=1', "plain,ctime=1,$members", 'parts without key stay first'],
+    ];
+
+    for my $test (@$tests) {
+        my ($meta, $expected, $name) = @$test;
+        my $merged = PVE::GuestIdentity::merge_identity($meta, $identity);
+        is($merged, $expected, $name);
+        is_deeply(PVE::GuestIdentity::parse_identity($merged), $identity, "$name, parses back");
+    }
+
+    for my $invalid (
+        { uid => 'GAYTEMZUGU3DOOBZMFRG', rtime => 1 },
+        { uid => 'gaytemzugu3doobzmfrg', rtime => undef },
+        { uid => 'gaytemzugu3doobzmfrg', rtime => 'now' },
+        { uid => 'gaytemzugu3doobzmfrg', rtime => '1000000000000000' },
+        { uid => 'gaytemzugu3doobzmfrg,ctime=1', rtime => 1 },
+        { rtime => 1 },
+    ) {
+        eval { PVE::GuestIdentity::merge_identity('ctime=1', $invalid) };
+        ok($@, "invalid identity is rejected");
+    }
+};
+
+subtest 'node version check' => sub {
+    my $min = PVE::GuestIdentity::MIN_PVE_MANAGER_VERSION;
+    like($min, qr/^[0-9]+\.[0-9]+\.[0-9]+\z/, 'minimum version is a version string');
+    my ($major, $minor, $release) = split(/\./, $min);
+
+    my $versions = {
+        current => "$major.$minor.$release",
+        newer => "$major." . ($minor + 1) . ".0",
+        older => "$major.$minor." . ($release - 1),
+        invalid => 'invalid',
+    };
+
+    my $cluster_module = Test::MockModule->new('PVE::Cluster');
+    $cluster_module->mock(
+        get_node_pvecfg_version => sub {
+            my ($node) = @_;
+            die "malformed version info\n" if $node eq 'malformed';
+            return $versions->{$node};
+        },
+        node_pvecfg_version_at_least => sub {
+            my ($node, @min) = @_;
+            my $version = PVE::Cluster::get_node_pvecfg_version($node);
+            return $version && PVE::Tools::pvecfg_min_version($version, @min);
+        },
+    );
+
+    for my $node (qw(current newer)) {
+        eval { PVE::GuestIdentity::assert_node_supports_identity($node) };
+        is($@, '', "node with version '$versions->{$node}' is supported");
+        my $unsupported = PVE::GuestIdentity::node_identity_unsupported($node);
+        is($unsupported, undef, "no reason for '$node'");
+    }
+
+    for my $node (qw(older invalid missing malformed)) {
+        eval { PVE::GuestIdentity::assert_node_supports_identity($node) };
+        like($@, qr/node '$node'/, "node '$node' is refused");
+    }
+
+    my $schema = PVE::GuestIdentity::node_identity_unsupported_schema();
+    isnt(
+        $schema,
+        PVE::GuestIdentity::node_identity_unsupported_schema(),
+        'schema is a new copy',
+    );
+    for my $node (qw(older invalid missing malformed)) {
+        my $unsupported = PVE::GuestIdentity::node_identity_unsupported($node);
+        eval { PVE::JSONSchema::validate($unsupported, $schema) };
+        is($@, '', "reason for '$node' matches the schema");
+    }
+
+    for my $node (qw(older invalid)) {
+        is_deeply(
+            PVE::GuestIdentity::node_identity_unsupported($node),
+            { version => $versions->{$node}, 'required-version' => $min },
+            "reason for '$node' has both versions",
+        );
+        eval { PVE::GuestIdentity::assert_node_supports_identity($node) };
+        is(
+            $@,
+            "node '$node' runs Proxmox VE $versions->{$node}, keeping the guest identity requires"
+                . " $min or newer - upgrade the node first\n",
+            "refusal of '$node' names both versions",
+        );
+    }
+
+    for my $node (qw(missing malformed)) {
+        is_deeply(
+            PVE::GuestIdentity::node_identity_unsupported($node),
+            { 'required-version' => $min },
+            "reason for '$node' has only the required version",
+        );
+        eval { PVE::GuestIdentity::assert_node_supports_identity($node) };
+        is(
+            $@,
+            "node '$node' does not report its Proxmox VE version, so it is unknown whether the"
+                . " node keeps the guest identity\n",
+            "refusal of '$node' says why",
+        );
+    }
+};
+
+done_testing();
-- 
2.47.3





^ permalink raw reply related	[relevance 22%]

* [PATCH cluster/guest-common/qemu-server/container/manager/docs v3 00/38] fix #7846: guest identity (uid) and cluster ID
@ 2026-11-18  4:37 18% Thomas Lamprecht
  2026-11-18  4:37 22% ` [PATCH guest-common v3 09/38] guest identity: add helpers for the guest uid and registration time Thomas Lamprecht
                   ` (4 more replies)
  0 siblings, 5 replies; 32+ results
From: Thomas Lamprecht @ 2026-11-18  4:37 UTC (permalink / raw)
  To: pve-devel

A VMID can be reused for another guest, and a guest can get another
VMID or move to another cluster through a restore or a remote
migration. So backup software and other tools cannot tell whether they
still look at the same guest, see [0].

This series gives every VM and container a guest identity in the
read-only 'meta' property: a random uid (100 bits as 20 base32
characters) and the time the guest was registered in the cluster. Create
and clone get a new uid. Config changes, migration, rollback, backup and
restore keep it, also under another VMID or in another cluster, as long
as no other guest there has it. Each cluster or standalone node also
gets a cluster ID in the same format, generated and protected by pmxcfs.
The docs patches describe the details.

The uid is a plain random nonce: 100 bits make a duplicate practically
impossible and fit into a 128-bit value with room to spare, and 20
base32 characters stay short and need no quoting. The registration time
is separate from the creation time, which clones, restores and remote
migrations copy along. It changes when a guest gets registered again, so
tools can tell such a guest from the one they knew.

Three behavior changes come with it:

* Restoring over an existing guest whose uid differs from the one of
  the backup is refused unless 'allow-identity-mismatch' is set. 'force'
  alone does not override this.
* A migration to another cluster is refused if another guest there
  already has the uid, unless 'allow-new-uid' is set. The check runs
  before anything is transferred. PDM does not know the option yet.
* Older versions drop the whole 'meta' property of a guest that has an
  identity. So migration and clone to such nodes is refused, and remote
  migration bumps the tunnel version. This also hits moves by the HA
  stack, which stops a container or a relocated VM before the migration
  gets refused. A target check in the LRM that avoids this will follow
  separately.

The patches are in dependency order: guest-common needs the pve-cluster
of this series, qemu-server and container need guest-common, and manager
needs all of them. manager also has to depend on the qemu-server and
container versions with this series, as the migration guard takes the
pve-manager version of a node as proof that the node keeps the identity.
MIN_PVE_MANAGER_VERSION in guest-common is a stand-in for that version.

Tested with the affected tests of the repositories for every patch and
their full suites at the end, pmxcfs with corosync in network
namespaces, and end to end on a nested three-node cluster that was
upgraded node by node, with remote migrations to a standalone node.

changes v2 -> v3:
* remote migration: a guest without uid gets one before the source
  sends it, so source and target no longer end up with unrelated uids;
  the identity command moved to pve-guest-common for both guest types
  (new patch 13)
* restore: keep the guest if a restored volume or firewall config
  cannot be removed, fail if a container backup changes between its
  check and its extraction, and let the cleanup follow the reservation
* reserving a VMID refuses an existing config that fails to load
  instead of replacing it
* cluster ID: generate it right away when the configured nodes change
  (new patch 5)
* feature API without version lookups for snapshot requests, and the
  cluster-wide bulk migration refuses its target up front
* docs: failed restores, uid conflicts on migration, qm.conf(5) and
  pct.conf(5)
* more independent fixes that the series builds on were applied on
  their own: failed and concurrent restores and creates, the schema of
  the migration preconditions, the lock of a VMA restore, a node list
  cut short in pmxcfs

changes v1 -> v2, thanks to Dominik for the review:
* rebase onto current master (tracking of used guest IDs, dfsm rework)
* remote migration takes the uid over at its start and refuses a uid
  that is in use in the target cluster, unless 'allow-new-uid' is set
* qemu-server and container share the restore checks and messages
  through pve-guest-common, with fewer special cases
* IDs take each character from one random byte, without an encoder
* the clone dialog does not offer nodes that would drop the identity,
  and a bulk migration checks its target once (patch 34)
* independent fixes moved out of the series and got applied on their
  own: the IPC client error, the order of removing firewall and guest
  config, and the cleanup of a remote migration target after failures
* comments, commit messages and docs give the reasons for the format,
  for rtime next to ctime and for the separate lock
Details are in the notes below the "---" of each patch.

v2: https://lore.proxmox.com/pve-devel/20261117223945.862914-1-t.lamprecht@proxmox.com/
v1: https://lore.proxmox.com/pve-devel/20261116004703.2908294-1-t.lamprecht@proxmox.com/

[0]: https://bugzilla.proxmox.com/show_bug.cgi?id=7846

cluster:

Thomas Lamprecht (8):
  pmxcfs: reject changes to the cluster ID file from user space
  pmxcfs: generate a cluster ID on standalone nodes
  pmxcfs: dfsm: add a callback that runs once all members are in sync
  pmxcfs: quorum: pass the corosync membership to an optional listener
  pmxcfs: confdb: call an optional listener when the nodes get published
  pmxcfs: dcdb: generate the cluster ID once the cluster is in sync
  cluster: add helper to read the cluster ID
  pmxcfs: allow removing the cluster ID file in forced local mode

 src/PVE/Cluster.pm          |  16 +
 src/pmxcfs/Makefile         |  12 +-
 src/pmxcfs/cfs-plug-memdb.c |  46 +++
 src/pmxcfs/cfs-utils.c      |   8 +
 src/pmxcfs/cfs-utils.h      |   5 +
 src/pmxcfs/check_dcdb.c     | 563 ++++++++++++++++++++++++++++++++++++
 src/pmxcfs/check_memdb.c    | 283 ++++++++++++++++++
 src/pmxcfs/cluster-id.c     | 142 +++++++++
 src/pmxcfs/cluster-id.h     |  50 ++++
 src/pmxcfs/confdb.c         |  18 +-
 src/pmxcfs/confdb.h         |   5 +-
 src/pmxcfs/dcdb.c           | 153 ++++++++++
 src/pmxcfs/dcdb.h           |   8 +
 src/pmxcfs/dfsm.c           |  59 ++++
 src/pmxcfs/dfsm.h           |  14 +
 src/pmxcfs/pmxcfs.c         |  12 +-
 src/pmxcfs/quorum.c         |  26 +-
 src/pmxcfs/quorum.h         |   9 +-
 src/pmxcfs/status.c         |  12 +
 src/pmxcfs/status.h         |   3 +
 src/test/Makefile           |   6 +-
 src/test/test_cluster_id.pl |  46 +++
 22 files changed, 1478 insertions(+), 18 deletions(-)
 create mode 100644 src/pmxcfs/check_dcdb.c
 create mode 100644 src/pmxcfs/cluster-id.c
 create mode 100644 src/pmxcfs/cluster-id.h
 create mode 100644 src/test/test_cluster_id.pl


guest-common:

Thomas Lamprecht (5):
  guest identity: add helpers for the guest uid and registration time
  abstract config: assign a guest identity and keep it on config writes
  abstract config: let the VMID reservation return the previous state
  guest identity: allow taking over a uid that is unused in the cluster
  migrate: add shared helpers for the identity command of the migration tunnel

 src/Makefile                       |    1 +
 src/PVE/AbstractConfig.pm          |  202 +++-
 src/PVE/AbstractMigrate.pm         |   30 +
 src/PVE/GuestIdentity.pm           |  510 ++++++++++
 src/tests/Makefile                 |   10 +-
 src/tests/config-identity-tests.pl | 1391 ++++++++++++++++++++++++++++
 src/tests/guest-identity-tests.pl  |  530 +++++++++++
 7 files changed, 2668 insertions(+), 6 deletions(-)
 create mode 100644 src/PVE/GuestIdentity.pm
 create mode 100755 src/tests/config-identity-tests.pl
 create mode 100755 src/tests/guest-identity-tests.pl


qemu-server:

Thomas Lamprecht (7):
  api: restore: release the VMID if a restore to an unused VMID fails
  api: migrate, clone: refuse targets that would drop the guest identity
  fix #7846: config: add a guest identity to the 'meta' property
  restore: take over the guest uid from the backup where possible
  api: remote migration: take over the guest uid from the source
  api: status: return the guest uid
  tests: remote migration: check a failed command and an early tunnel end

 src/PVE/API2/Qemu.pm                          |  118 +-
 src/PVE/CLI/qm.pm                             |    7 +
 src/PVE/CLI/qmrestore.pm                      |   11 +-
 src/PVE/QemuConfig.pm                         |    7 +
 src/PVE/QemuMigrate.pm                        |   18 +-
 src/PVE/QemuServer.pm                         |  155 ++-
 src/PVE/QemuServer/MetaInfo.pm                |    2 +
 src/test/Makefile                             |    5 +-
 src/test/QemuServerTest/FakeCFS.pm            |  189 +++
 .../q35-windows-pinning-identity-only.conf    |    6 +
 ...q35-windows-pinning-identity-only.conf.cmd |   26 +
 .../meta-identity-invalid.conf                |    6 +
 .../meta-identity-invalid.conf.strict.error   |    2 +
 .../meta-identity-invalid.conf                |    7 +
 .../parse-config-input/meta-identity.conf     |   20 +
 src/test/restore-config-expected/150.conf     |    9 +
 src/test/restore-config-input/150.conf        |   10 +
 src/test/run_api_tests.pl                     |  206 ++++
 src/test/run_guest_identity_tests.pl          |  803 +++++++++++++
 src/test/run_parse_config_tests.pl            |    2 +-
 src/test/run_qemu_restore_config_tests.pl     | 1053 ++++++++++++++++-
 .../create/qemu-server/401.conf               |   31 +
 .../create/qemu-server/402.conf               |   31 +
 .../rollback/qemu-server/401.conf             |   36 +
 .../rollback/qemu-server/402.conf             |   35 +
 .../create/qemu-server/401.conf               |   13 +
 .../create/qemu-server/402.conf               |   13 +
 .../rollback/qemu-server/401.conf             |   35 +
 .../rollback/qemu-server/402.conf             |   34 +
 src/test/snapshot-test.pm                     |   82 +-
 30 files changed, 2899 insertions(+), 73 deletions(-)
 create mode 100644 src/test/QemuServerTest/FakeCFS.pm
 create mode 100644 src/test/cfg2cmd/q35-windows-pinning-identity-only.conf
 create mode 100644 src/test/cfg2cmd/q35-windows-pinning-identity-only.conf.cmd
 create mode 100644 src/test/parse-config-expected/meta-identity-invalid.conf
 create mode 100644 src/test/parse-config-expected/meta-identity-invalid.conf.strict.error
 create mode 100644 src/test/parse-config-input/meta-identity-invalid.conf
 create mode 100644 src/test/parse-config-input/meta-identity.conf
 create mode 100644 src/test/restore-config-expected/150.conf
 create mode 100644 src/test/restore-config-input/150.conf
 create mode 100755 src/test/run_guest_identity_tests.pl
 create mode 100644 src/test/snapshot-expected/create/qemu-server/401.conf
 create mode 100644 src/test/snapshot-expected/create/qemu-server/402.conf
 create mode 100644 src/test/snapshot-expected/rollback/qemu-server/401.conf
 create mode 100644 src/test/snapshot-expected/rollback/qemu-server/402.conf
 create mode 100644 src/test/snapshot-input/create/qemu-server/401.conf
 create mode 100644 src/test/snapshot-input/create/qemu-server/402.conf
 create mode 100644 src/test/snapshot-input/rollback/qemu-server/401.conf
 create mode 100644 src/test/snapshot-input/rollback/qemu-server/402.conf


container:

Thomas Lamprecht (8):
  config: add read-only meta property with the creation time
  fix #7846: config: add a guest identity to the 'meta' property
  api: migrate, clone: refuse targets that would drop the guest identity
  restore: take over the guest uid from the backup where possible
  restore: refuse overwriting a container with another guest's backup
  test: remote migration: check the cleanup of the target after failures
  api: remote migration: take over the guest uid from the source
  api: status: return the guest uid

 src/PVE/API2/LXC.pm         |  190 ++-
 src/PVE/API2/LXC/Config.pm  |   29 +-
 src/PVE/API2/LXC/Status.pm  |    6 +
 src/PVE/CLI/pct.pm          |    7 +
 src/PVE/LXC/Config.pm       |   51 +-
 src/PVE/LXC/Migrate.pm      |    8 +-
 src/test/Makefile           |    8 +-
 src/test/config_tests.pl    |   23 +
 src/test/lifecycle_tests.pl | 2446 +++++++++++++++++++++++++++++++++++
 9 files changed, 2730 insertions(+), 38 deletions(-)
 create mode 100755 src/test/lifecycle_tests.pl


manager:

Thomas Lamprecht (6):
  api: cluster resources: add guest uid and registration time
  api: cluster status: add cluster ID
  ui: restore: allow overwriting a guest with a backup of another guest
  ui: migrate: refuse target nodes that would drop the guest identity
  ui: guest summary: show the guest identity
  api: bulk migrate: refuse targets that would drop the guest identity

 PVE/API2/Cluster.pm                      |  24 ++-
 PVE/API2/Cluster/BulkAction/Guest.pm     |   5 +
 PVE/API2/Nodes.pm                        |   3 +
 test/ClusterResources_test.pl            | 249 +++++++++++++++++++++++
 test/ClusterStatus_test.pl               | 114 +++++++++++
 test/Makefile                            |  10 +-
 www/manager6/Makefile                    |   1 +
 www/manager6/panel/GuestIdentity.js      | 142 +++++++++++++
 www/manager6/panel/GuestStatusView.js    |   3 +
 www/manager6/panel/TemplateStatusView.js |   3 +
 www/manager6/window/Migrate.js           |  29 +++
 www/manager6/window/Restore.js           |  18 ++
 12 files changed, 599 insertions(+), 2 deletions(-)
 create mode 100755 test/ClusterResources_test.pl
 create mode 100755 test/ClusterStatus_test.pl
 create mode 100644 www/manager6/panel/GuestIdentity.js


docs:

Thomas Lamprecht (4):
  vzdump: describe the guest identity of VMs and containers
  pvecm: document the cluster ID and how to get a new one
  qm: configuration: describe the read-only meta property
  pct: configuration: describe the read-only meta property

 pct.adoc      |  35 ++++++
 pct.conf.adoc |   3 +
 pmxcfs.adoc   |   1 +
 pvecm.adoc    |  87 +++++++++++++
 qm.adoc       |  38 ++++++
 qm.conf.adoc  |   3 +
 vzdump.adoc   | 335 ++++++++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 502 insertions(+)


Summary over all repositories:
  87 files changed, 10876 insertions(+), 137 deletions(-)

-- 
2.47.3





^ permalink raw reply	[relevance 18%]

* [PATCH docs v2 33/36] vzdump: describe the guest identity of VMs and containers
  2026-11-17 22:34 18% [PATCH cluster/guest-common/qemu-server/container/manager/docs v2 00/36] " Thomas Lamprecht
  2026-11-17 22:34 22% ` [PATCH guest-common v2 08/36] guest identity: add helpers for the guest uid and registration time Thomas Lamprecht
  2026-11-17 22:34 15% ` [PATCH qemu-server v2 14/36] fix #7846: config: add a guest identity to the 'meta' property Thomas Lamprecht
@ 2026-11-17 22:34 16% ` Thomas Lamprecht
  2026-11-18  5:57 11% ` superseded: [PATCH cluster/guest-common/qemu-server/container/manager/docs v2 00/36] fix #7846: guest identity (uid) and cluster ID Thomas Lamprecht
  3 siblings, 0 replies; 32+ results
From: Thomas Lamprecht @ 2026-11-17 22:34 UTC (permalink / raw)
  To: pve-devel

Since Proxmox VE 9.3, VMs and containers have a guest identity in
'meta': a random uid and a registration time. Backup software and other
tools can distinguish a guest from another that reuses its VMID [0].

Administrators need to understand why restores over a different guest
are refused, when a restore keeps the uid of the backup, and why
migrations and clones to older nodes are blocked. Those nodes drop
'meta', including VM creation information used for hardware defaults.

Document the lifecycle, failed-restore retries, and mixed-version
restrictions in the backup and restore chapter, where users are most
likely to encounter the identity. Include migration and HA behavior
there so the rules can be read together.

[0]: https://bugzilla.proxmox.com/show_bug.cgi?id=7846

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
---

changes v1 -> v2:
* say that the uid has 100 random bits and how rtime differs from ctime
* describe the refusal of a migration to another cluster, its typical
  cases and 'allow-new-uid'
* retry after a failed restore: scope the pending entry, name the
  warning, correct the placeholder case and add the note for enforced
  unique guest IDs

 vzdump.adoc | 312 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 312 insertions(+)

diff --git a/vzdump.adoc b/vzdump.adoc
index 44db027..d398fd6 100644
--- a/vzdump.adoc
+++ b/vzdump.adoc
@@ -464,6 +464,13 @@ following CLI tools:
 
 For details see the corresponding manual pages.
 
+When you restore a backup over an existing guest, {pve} compares the guest
+identities of the backup and of the guest. If they differ, the restore is
+refused, unless you set the `allow-identity-mismatch` option. The existing guest
+then keeps its identity. See
+xref:guest_identity_restore[Restore Over an Existing Guest] for details and
+exceptions.
+
 Bandwidth Limit
 ~~~~~~~~~~~~~~~
 
@@ -563,6 +570,311 @@ file in `/var/log/proxmox-backup/file-restore/`. The log file might contain
 additional information in case an attempt to restore individual files or
 accessing file systems contained in a backup archive fails.
 
+[[guest_identity]]
+Guest Identity
+--------------
+
+Since {pve} 9.3, each virtual machine and container has a guest identity: a
+random identifier, `uid`, and a registration time, `rtime`. Unlike a VMID,
+which can be reused after a guest is destroyed, the `uid` lets backup software
+and other tools recognize the same logical guest across restores and
+migrations, even under a different VMID. Whether an operation keeps the `uid`
+depends on the target and the options of the operation, as described in
+xref:guest_identity_lifecycle[Lifecycle].
+
+[[guest_identity_values]]
+Identity Values
+~~~~~~~~~~~~~~~
+
+The guest identity is part of the `meta` property in the guest configuration.
+This property also contains the creation time `ctime` and, for VMs, the QEMU
+version that the VM was created with, `creation-qemu`:
+
+----
+meta: creation-qemu=10.1.2,ctime=1772444467,rtime=1794320571482,uid=w5qczgiem26qnwzwsoil
+----
+
+`uid`::
+
+A random identifier of 20 characters, consisting of the lowercase letters `a` to
+`z` and the digits `2` to `7`. It encodes 100 random bits, so two guests
+practically never get the same `uid` by chance.
+
+`rtime`::
+
+The time at which the guest was registered in this cluster, in milliseconds
+since the UNIX epoch. Creating or cloning a guest, restoring it to a free VMID,
+and migrating it from another cluster register the guest in the cluster. A
+guest restored to a free VMID gets a new `rtime`, even if it keeps the backup's
+`uid`. See xref:guest_identity_lifecycle[Lifecycle] for the other operations.
+As a timestamp, the `rtime` is not guaranteed to be unique.
+
+The `rtime` differs from the creation time `ctime`. The `ctime` stays with the
+guest: a clone has the `ctime` of its source, and a restored guest or a guest
+migrated from another cluster has that of the backup or of the source guest. The
+`rtime` is set whenever the guest gets its `uid` in this cluster. A guest whose
+`uid` is unchanged but whose `rtime` is newer was therefore registered again,
+for example by a restore to a free VMID.
+
+{pve} manages the `meta` property automatically. It is read-only through the
+API, even for `root@pam`.
+
+IMPORTANT: The `uid` helps to correlate a guest with its backups and copies,
+but does not prove where a guest comes from. Whoever restores a backup or
+migrates a guest into the cluster supplies the `uid` of that guest, which {pve}
+takes over if no other guest in the cluster has it. {pve} keeps a `uid` unique
+within a cluster only for operations through its API. A configuration file
+copied by hand has the same `uid` as the original, and guests in different
+clusters can have the same `uid`.
+
+[[guest_identity_read]]
+Reading the Identity
+~~~~~~~~~~~~~~~~~~~~
+
+The following places show the guest identity. All of them require the
+`VM.Audit` privilege on the guest.
+
+* In the web interface, the 'Summary' panel of the guest shows the `uid` as
+  'Unique ID'. The 'Details' button next to it, which has an info icon, opens
+  the 'Guest Identity' window. This window additionally shows the `rtime` as
+  'Registered' and the creation information.
+* The guest configuration, for example with `qm config <vmid>` or
+  `pct config <vmid>`, and through the API paths
+  `/nodes/<node>/qemu/<vmid>/config` and `/nodes/<node>/lxc/<vmid>/config`.
+* The guest status at the API paths `/nodes/<node>/qemu/<vmid>/status/current`
+  and `/nodes/<node>/lxc/<vmid>/status/current`, which contains the `uid`.
+* The cluster resources at the API path `/cluster/resources`, which contain the
+  `uid` and `rtime` of each guest, for example:
++
+----
+# pvesh get /cluster/resources --type vm --output-format json-pretty
+----
+
+The configuration in a backup contains the `meta` property as well. You can
+show it with `pvesm extractconfig <volume>`, for example.
+
+[[guest_identity_lifecycle]]
+Lifecycle
+~~~~~~~~~
+
+The following table shows how operations affect the identity of a guest.
+
+[width="100%",cols="3,4,2",options="header"]
+|===========================================================================
+|Operation |`uid` |`rtime`
+|Create, including import |new |current time
+|Clone, including linked clones and clones from snapshots |new |current time
+|Restore to a free VMID |the backup's `uid` if present and not used by another
+guest in the cluster; otherwise new |current time
+|Restore to a free VMID with `unique` set |new |current time
+|Restore over an existing guest that has a `uid`, with or without `unique` set
+|kept, see xref:guest_identity_restore[Restore Over an Existing Guest] |kept
+|Restore over an existing guest without a `uid` |as for a free VMID |current
+time
+|Migration to another cluster, on the target |the source guest's `uid`; new if
+the source guest has none, or if another guest in the target cluster has it and
+`allow-new-uid` is set, see
+xref:guest_identity_remote_migration[Migration to Another Cluster] |current time
+|Migration to another cluster, on the source if the guest is kept |kept |kept
+|Snapshot rollback |kept, not taken from the snapshot |kept
+|Migration within the cluster, HA recovery, configuration change, backup,
+replication, conversion to a template |kept |kept
+|Destroy |removed |removed
+|===========================================================================
+
+Restores and migrations from another cluster report the outcome in their task
+log, in a line with `guest identity:`, for example:
+
+----
+guest identity: backup uid w5qczgiem26qnwzwsoil is in use by guest 100, keeping uid er3n3wqoqgcl362ep3da
+----
+
+When a restore takes over a `uid`, the guest first has a newly assigned `uid`,
+which the restore replaces with the `uid` of the backup at its end. Tools that
+read `/cluster/resources` during a restore can therefore see a `uid` that
+disappears afterwards. A migration from another cluster takes over the `uid` of
+the source guest right at its start. In both cases, a changed `uid` does not
+mean that the task has finished.
+
+Guests that existed before the upgrade to {pve} 9.3 get their identity the
+first time a node running {pve} 9.3 or later writes their configuration. This
+happens, for example, when their configuration changes, when they are backed
+up, or when they are migrated to such a node. Their `rtime` is the time of that
+write. Backups made before that have no `uid`.
+
+When a tool restores a guest by removing it and creating a new one through the
+API, the new guest gets a new `uid`. To keep the identity, a tool has to change
+the existing guest in place, or let {pve} restore the guest.
+
+[[guest_identity_restore]]
+Restore Over an Existing Guest
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+If the existing guest already has a guest identity, restoring a backup over it
+keeps the `uid` and `rtime` of that guest. When both the guest and the backup
+have a `uid` and the values differ, {pve} treats the backup as belonging to
+another guest. This can happen when a VMID was reused. {pve} refuses such a
+restore before it overwrites the guest:
+
+----
+backup belongs to another guest: its uid 'w5qczgiem26qnwzwsoil' differs from uid 'er3n3wqoqgcl362ep3da' of the existing VM 100 - use 'allow-identity-mismatch' to overwrite the VM anyway
+----
+
+To restore such a backup anyway, set the `allow-identity-mismatch` option. The
+existing guest then keeps its identity. In the web interface, select 'Allow
+restoring a backup of another guest' in the restore window, which you open from
+the 'Backup' panel of the guest. On the command line, use for example:
+
+----
+# qmrestore <archive> <vmid> --force 1 --allow-identity-mismatch 1
+# pct restore <vmid> <archive> --force 1 --allow-identity-mismatch 1
+----
+
+Backups without a `uid`, such as backups made with {pve} versions older than
+9.3, are not refused. Container restores from standard input
+(`pct restore <vmid> -`) are an exception: the `uid` of such a backup is only
+known once the container has been overwritten. A restore from standard input
+over a container with a `uid` therefore always requires
+`allow-identity-mismatch`.
+
+A restore that fails or is stopped can leave the guest behind, for example a
+restore over an existing guest, or a VM restore that fails after it restored the
+data. If the restore task was killed, the guest also stays locked. Remove the
+lock with `qm unlock <vmid>` or `pct unlock <vmid>` before you retry the restore
+or remove the guest.
+
+If the failed restore was to a free VMID or over a guest without a `uid`, and it
+had already read a backup that has a `uid`, `qm pending <vmid>` or
+`pct pending <vmid>` lists an entry for `meta` with the `uid` of the backup. As
+long as this entry exists, retrying the same restore over the guest left behind
+is accepted. Starting the guest or changing its options removes the entry and
+logs a warning that names the `uid`. The retry is then refused like a restore of
+another guest's backup.
+
+A successful retry takes over the `uid` of the backup and sets a new `rtime`, as
+a restore to a free VMID does. The guest keeps its `uid` and `rtime` instead if
+another guest in the cluster has the `uid` of the backup, or if the retry sets
+`unique`. Restores from standard input still require `allow-identity-mismatch`,
+as described above.
+
+A guest that had a `uid` and no such entry before the failed restore keeps its
+`uid` and gets no entry. A retry is checked like the first attempt: a backup
+with the same `uid` is accepted, also after the guest was started or changed,
+and a backup with another `uid` requires `allow-identity-mismatch`.
+
+A restore to a free VMID that fails before it restored the data removes the
+guest again. Only a killed restore task can leave an empty, locked placeholder
+at that VMID. Unlock it as described above and remove it, for example with
+`qm destroy <vmid>` or `pct destroy <vmid>`. In both cases, restore again. Use
+another VMID if the xref:pvecm_next_id_range[`next-id`] setting of the
+datacenter has the `unique` and `enforce` options set, as the first VMID then
+counts as used.
+
+If a restore over an existing guest without a `uid` stopped before it read the
+backup, for example because the backup storage was unreachable, the guest now
+has a new `uid`. Retry with `allow-identity-mismatch`.
+
+A restore can also complete with a warning starting with
+`guest identity: unable to adopt backup uid`, for example if the cluster-wide
+lock for this step could not be taken in time. The guest is then restored
+completely, but keeps its new `uid`. To take over the `uid` of the backup,
+repeat the restore over the guest before you start it or change its
+configuration.
+
+[[guest_identity_remote_migration]]
+Migration to Another Cluster
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+A migration to another cluster (`qm remote-migrate`, `pct remote-migrate`) keeps
+the `uid` of the guest. The target takes it over at the start of the migration,
+before any data is transferred.
+
+If another guest in the target cluster already has that `uid`, the migration is
+refused at that point. Typical cases are:
+
+* the guest gets migrated back to a cluster that still has the source guest of
+  an earlier migration, which stays there unless `delete` was set,
+* a copy of the guest was restored in the target cluster from a backup,
+* an earlier migration of the guest broke off after it had transferred the
+  configuration and left a locked guest in the target cluster,
+* the target is the cluster that the guest is in.
+
+The error ends with:
+
+----
+guest 105 in the target cluster already has the uid 'w5qczgiem26qnwzwsoil' of this guest - use 'allow-new-uid' to migrate it with a new uid
+----
+
+To keep the `uid`, remove the other guest in the target cluster and migrate
+again. To migrate anyway, set the `allow-new-uid` option. The migrated guest
+then gets a new `uid`, and the other guest keeps the old one. In both cases, use
+another target VMID if the xref:pvecm_next_id_range[`next-id`] setting of the
+target cluster has the `unique` and `enforce` options set, as the refused
+migration already used the first one. For example:
+
+----
+# qm remote-migrate <vmid> <target-vmid> <target-endpoint> --target-bridge <bridge> --target-storage <storage> --allow-new-uid 1
+----
+
+[[guest_identity_mixed_versions]]
+Mixed Versions in a Cluster
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+While some nodes of a cluster still run a {pve} version older than 9.3,
+migrating or cloning a guest to one of these nodes is refused. The guest keeps
+running on its current node. If the target node reports its version, the error
+message shows that version and the minimum required version. If the node does
+not report its version, the operation is refused because {pve} cannot verify
+that the node supports guest identities. The 'Migrate' window of the web
+interface shows the reason for the selected target node.
+
+Moves of HA-managed guests to such nodes are refused in the same way. A running
+VM that the HA stack migrates keeps running. The HA stack stops a container, and
+a VM that it relocates, before it migrates the guest, so such a guest is stopped
+although the move is then refused. The HA stack retries automatic moves until
+they succeed, and such a guest can stay stopped in the meantime. This includes
+moves for:
+
+* the maintenance mode,
+* a node shutdown with the `migrate` shutdown policy,
+* node affinity rules,
+* the CRS load balancer.
+
+Such moves complete only after the target nodes that the HA stack selects run
+{pve} 9.3 or later.
+
+To avoid refused moves while you upgrade a cluster, do one of the following:
+
+* Move all guests away from a node before you upgrade it.
+* Upgrade the packages on all nodes, one node at a time, before you reboot any
+  node or enable the maintenance mode.
+
+The reason for these refusals is that {pve} versions older than 9.3 ignore the
+whole `meta` property of a guest that has a guest identity, including the
+creation information. A VM started on such a node can therefore get different
+virtual hardware, see xref:qm_machine_type[Machine Type]. When such a node
+writes the configuration, the property is lost.
+
+The check covers migrations and clones started on a node running {pve} 9.3 or
+later. It does not cover:
+
+* the HA recovery of guests from a fenced node,
+* configuration files moved by hand,
+* operations started on a node with an older version.
+
+If an older node writes the configuration of a guest in one of these cases, the
+guest loses its `meta` property. It gets a new identity the next time a node
+running {pve} 9.3 or later writes its configuration.
+
+Backups made with {pve} 9.3 or later contain the guest identity. Restore them
+only on nodes running {pve} 9.3 or later, because older versions ignore the
+`meta` property of such backups in the same way.
+
+A migration to another cluster (`qm remote-migrate`, `pct remote-migrate`) is
+refused right after connecting to a target node with a version older than 9.3,
+before any data is transferred. The error is
+`Remote tunnel endpoint too old, upgrade required`.
+
 [[vzdump_configuration]]
 Configuration
 -------------
-- 
2.47.3





^ permalink raw reply related	[relevance 16%]

* [PATCH qemu-server v2 14/36] fix #7846: config: add a guest identity to the 'meta' property
  2026-11-17 22:34 18% [PATCH cluster/guest-common/qemu-server/container/manager/docs v2 00/36] " Thomas Lamprecht
  2026-11-17 22:34 22% ` [PATCH guest-common v2 08/36] guest identity: add helpers for the guest uid and registration time Thomas Lamprecht
@ 2026-11-17 22:34 15% ` Thomas Lamprecht
  2026-11-17 22:34 16% ` [PATCH docs v2 33/36] vzdump: describe the guest identity of VMs and containers Thomas Lamprecht
  2026-11-18  5:57 11% ` superseded: [PATCH cluster/guest-common/qemu-server/container/manager/docs v2 00/36] fix #7846: guest identity (uid) and cluster ID Thomas Lamprecht
  3 siblings, 0 replies; 32+ results
From: Thomas Lamprecht @ 2026-11-17 22:34 UTC (permalink / raw)
  To: pve-devel

Give VMs a guest identity in the read-only 'meta' property: a random
identifier, 'uid', and a registration time, 'rtime'. Tools can use it
to recognize a guest across restores and migrations, independently of
its VMID.

Enable the identity handling of the config class, so that each config
write keeps the identity a VM already has or assigns one if it has
none. New VMs, clones and imports get an identity when their VMID is
reserved. Existing VMs get one with their next config write. A stale
config, a clone source or a snapshot rollback cannot replace the
identity of a VM.

The other members of 'meta' behave as before. A config without creation
information thus gets a 'meta' property with only the identity. Older
qemu-server versions reject the new members and drop the whole property
on their next config write.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
---

changes v1 -> v2:
* rebase, adapt the tests

 src/PVE/QemuConfig.pm                         |   7 +
 src/PVE/QemuServer/MetaInfo.pm                |   2 +
 src/test/Makefile                             |   5 +-
 .../q35-windows-pinning-identity-only.conf    |   6 +
 ...q35-windows-pinning-identity-only.conf.cmd |  26 ++
 .../meta-identity-invalid.conf                |   6 +
 .../meta-identity-invalid.conf.strict.error   |   2 +
 .../meta-identity-invalid.conf                |   7 +
 .../parse-config-input/meta-identity.conf     |  20 ++
 src/test/run_guest_identity_tests.pl          | 257 ++++++++++++++++++
 src/test/run_parse_config_tests.pl            |   2 +-
 src/test/run_qemu_restore_config_tests.pl     |   3 +-
 .../create/qemu-server/401.conf               |  31 +++
 .../create/qemu-server/402.conf               |  31 +++
 .../rollback/qemu-server/401.conf             |  36 +++
 .../rollback/qemu-server/402.conf             |  35 +++
 .../create/qemu-server/401.conf               |  13 +
 .../create/qemu-server/402.conf               |  13 +
 .../rollback/qemu-server/401.conf             |  35 +++
 .../rollback/qemu-server/402.conf             |  34 +++
 src/test/snapshot-test.pm                     |  82 +++++-
 21 files changed, 639 insertions(+), 14 deletions(-)
 create mode 100644 src/test/cfg2cmd/q35-windows-pinning-identity-only.conf
 create mode 100644 src/test/cfg2cmd/q35-windows-pinning-identity-only.conf.cmd
 create mode 100644 src/test/parse-config-expected/meta-identity-invalid.conf
 create mode 100644 src/test/parse-config-expected/meta-identity-invalid.conf.strict.error
 create mode 100644 src/test/parse-config-input/meta-identity-invalid.conf
 create mode 100644 src/test/parse-config-input/meta-identity.conf
 create mode 100755 src/test/run_guest_identity_tests.pl
 create mode 100644 src/test/snapshot-expected/create/qemu-server/401.conf
 create mode 100644 src/test/snapshot-expected/create/qemu-server/402.conf
 create mode 100644 src/test/snapshot-expected/rollback/qemu-server/401.conf
 create mode 100644 src/test/snapshot-expected/rollback/qemu-server/402.conf
 create mode 100644 src/test/snapshot-input/create/qemu-server/401.conf
 create mode 100644 src/test/snapshot-input/create/qemu-server/402.conf
 create mode 100644 src/test/snapshot-input/rollback/qemu-server/401.conf
 create mode 100644 src/test/snapshot-input/rollback/qemu-server/402.conf

diff --git a/src/PVE/QemuConfig.pm b/src/PVE/QemuConfig.pm
index d89a62e6..ac9e202a 100644
--- a/src/PVE/QemuConfig.pm
+++ b/src/PVE/QemuConfig.pm
@@ -644,6 +644,13 @@ sub write_config {
     return $class->SUPER::write_config($vmid, $conf);
 }
 
+# the format of the 'meta' property includes the guest identity, see PVE::QemuServer::MetaInfo
+sub __identity_enabled {
+    my ($class) = @_;
+
+    return 1;
+}
+
 # END implemented abstract methods from PVE::AbstractConfig
 
 sub has_cloudinit {
diff --git a/src/PVE/QemuServer/MetaInfo.pm b/src/PVE/QemuServer/MetaInfo.pm
index b69e5a1c..399cd920 100644
--- a/src/PVE/QemuServer/MetaInfo.pm
+++ b/src/PVE/QemuServer/MetaInfo.pm
@@ -3,6 +3,7 @@ package PVE::QemuServer::MetaInfo;
 use strict;
 use warnings;
 
+use PVE::GuestIdentity;
 use PVE::JSONSchema;
 
 use PVE::QemuServer::Helpers;
@@ -20,6 +21,7 @@ our $meta_info_fmt = {
         pattern => '\d+(\.\d+)+',
         optional => 1,
     },
+    PVE::GuestIdentity::meta_format_properties()->%*,
 };
 
 sub parse_meta_info {
diff --git a/src/test/Makefile b/src/test/Makefile
index 407567ef..750d4027 100644
--- a/src/test/Makefile
+++ b/src/test/Makefile
@@ -1,6 +1,6 @@
 all: test
 
-test: test_snapshot test_cfg_to_cmd test_cfg_to_cmd_aarch64 test_hotplug test_hotplug_aarch64 test_pci_addr_conflicts test_pci_reservation test_qemu_img_convert test_migration test_restore_config test_parse_config test_memory test_raw_config_write test_api
+test: test_snapshot test_cfg_to_cmd test_cfg_to_cmd_aarch64 test_hotplug test_hotplug_aarch64 test_pci_addr_conflicts test_pci_reservation test_qemu_img_convert test_migration test_restore_config test_parse_config test_memory test_raw_config_write test_api test_guest_identity
 
 test_snapshot: run_snapshot_tests.pl
 	./run_snapshot_tests.pl
@@ -51,6 +51,9 @@ test_raw_config_write: run_raw_config_write_tests.pl
 test_api: run_api_tests.pl
 	./run_api_tests.pl
 
+test_guest_identity: run_guest_identity_tests.pl QemuServerTest/FakeCFS.pm
+	./run_guest_identity_tests.pl
+
 .PHONY: clean
 clean:
 	rm -rf MigrationTest/run
diff --git a/src/test/cfg2cmd/q35-windows-pinning-identity-only.conf b/src/test/cfg2cmd/q35-windows-pinning-identity-only.conf
new file mode 100644
index 00000000..5242ec13
--- /dev/null
+++ b/src/test/cfg2cmd/q35-windows-pinning-identity-only.conf
@@ -0,0 +1,6 @@
+# TEST: Windows without pinned machine and with only the guest identity as meta info stays on 5.1
+machine: q35
+meta: rtime=1762300000000,uid=abcdefghijklmnopqrst
+ostype: win11
+smbios1: uuid=7b10d7af-b932-4c66-b2c3-3996152ec465
+vmgenid: c773c261-d800-4348-9f5d-167fadd53cf8
diff --git a/src/test/cfg2cmd/q35-windows-pinning-identity-only.conf.cmd b/src/test/cfg2cmd/q35-windows-pinning-identity-only.conf.cmd
new file mode 100644
index 00000000..67d20b79
--- /dev/null
+++ b/src/test/cfg2cmd/q35-windows-pinning-identity-only.conf.cmd
@@ -0,0 +1,26 @@
+/usr/bin/kvm \
+  -id 8006 \
+  -name vm8006 \
+  -no-shutdown \
+  -chardev 'socket,id=qmp,path=/var/run/qemu-server/8006.qmp,server=on,wait=off' \
+  -object 'monitor-qmp,chardev=qmp,id=monitor-qmp' \
+  -chardev 'socket,id=qmp-event,path=/var/run/qmeventd.sock,reconnect-ms=5000' \
+  -object 'monitor-qmp,chardev=qmp-event,id=monitor-qmp-event' \
+  -pidfile /var/run/qemu-server/8006.pid \
+  -daemonize \
+  -smbios 'type=1,uuid=7b10d7af-b932-4c66-b2c3-3996152ec465' \
+  -smp '1,sockets=1,cores=1,maxcpus=1' \
+  -nodefaults \
+  -boot 'menu=on,strict=on,reboot-timeout=1000,splash=/usr/share/qemu-server/bootsplash.jpg' \
+  -vnc 'unix:/var/run/qemu-server/8006.vnc,password=on' \
+  -global 'kvm-pit.lost_tick_policy=discard' \
+  -cpu 'kvm64,-cet-ibt,-cet-ss,enforce,hv_ipi,hv_relaxed,hv_reset,hv_runtime,hv_spinlocks=0x1fff,hv_stimer,hv_synic,hv_time,hv_vapic,hv_vpindex,+kvm_pv_eoi,+kvm_pv_unhalt,+lahf_lm,+sep' \
+  -m 512 \
+  -readconfig /usr/share/qemu-server/pve-q35-4.0.cfg \
+  -device 'vmgenid,guid=c773c261-d800-4348-9f5d-167fadd53cf8' \
+  -device 'usb-tablet,id=tablet,bus=ehci.0,port=1' \
+  -device 'VGA,id=vga,bus=pcie.0,addr=0x1,edid=off' \
+  -device 'virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3' \
+  -iscsi 'initiator-name=iqn.1993-08.org.debian:01:aabbccddeeff' \
+  -rtc 'driftfix=slew,base=localtime' \
+  -machine 'hpet=off,type=pc-q35-5.1+pve0'
diff --git a/src/test/parse-config-expected/meta-identity-invalid.conf b/src/test/parse-config-expected/meta-identity-invalid.conf
new file mode 100644
index 00000000..195514fa
--- /dev/null
+++ b/src/test/parse-config-expected/meta-identity-invalid.conf
@@ -0,0 +1,6 @@
+# VM with a guest uid that is not valid
+boot: order=scsi0
+cores: 2
+memory: 4096
+name: identity
+scsi0: local-lvm:vm-8006-disk-0,size=32G
diff --git a/src/test/parse-config-expected/meta-identity-invalid.conf.strict.error b/src/test/parse-config-expected/meta-identity-invalid.conf.strict.error
new file mode 100644
index 00000000..ae584c1f
--- /dev/null
+++ b/src/test/parse-config-expected/meta-identity-invalid.conf.strict.error
@@ -0,0 +1,2 @@
+vm 8006 - unable to parse value of 'meta' - format error
+uid: value does not match the regex pattern
diff --git a/src/test/parse-config-input/meta-identity-invalid.conf b/src/test/parse-config-input/meta-identity-invalid.conf
new file mode 100644
index 00000000..90e60197
--- /dev/null
+++ b/src/test/parse-config-input/meta-identity-invalid.conf
@@ -0,0 +1,7 @@
+# VM with a guest uid that is not valid
+boot: order=scsi0
+cores: 2
+memory: 4096
+meta: creation-qemu=10.1.2,ctime=1762000000,rtime=1762000000123,uid=ABCDEFGHIJKLMNOPQRST
+name: identity
+scsi0: local-lvm:vm-8006-disk-0,size=32G
diff --git a/src/test/parse-config-input/meta-identity.conf b/src/test/parse-config-input/meta-identity.conf
new file mode 100644
index 00000000..7a1e03be
--- /dev/null
+++ b/src/test/parse-config-input/meta-identity.conf
@@ -0,0 +1,20 @@
+# VM with guest identity
+boot: order=scsi0
+cores: 2
+memory: 4096
+meta: creation-qemu=10.1.2,ctime=1762000000,rtime=1762000000123,uid=abcdefghijklmnopqrst
+name: identity
+scsi0: local-lvm:vm-8006-disk-0,size=32G
+scsihw: virtio-scsi-single
+smbios1: uuid=7b4f2a1e-3c2d-4e5f-8a9b-0c1d2e3f4a5b
+
+[snap]
+boot: order=scsi0
+cores: 2
+memory: 4096
+meta: creation-qemu=10.1.2,ctime=1762000000,rtime=1762000000123,uid=abcdefghijklmnopqrst
+name: identity
+scsi0: local-lvm:vm-8006-disk-0,size=32G
+scsihw: virtio-scsi-single
+smbios1: uuid=7b4f2a1e-3c2d-4e5f-8a9b-0c1d2e3f4a5b
+snaptime: 1762000100
diff --git a/src/test/run_guest_identity_tests.pl b/src/test/run_guest_identity_tests.pl
new file mode 100755
index 00000000..b4242b63
--- /dev/null
+++ b/src/test/run_guest_identity_tests.pl
@@ -0,0 +1,257 @@
+#!/usr/bin/perl
+
+# Tests the guest identity of VM configs through the real config class methods, with a fake cluster
+# filesystem, see QemuServerTest::FakeCFS.
+
+use v5.36;
+
+use lib qw(.. .);
+
+use File::Temp qw(tempdir);
+use Test::MockModule;
+use Test::More;
+
+use PVE::JSONSchema;
+use PVE::QemuConfig;
+use PVE::QemuConfig::NoWrite;
+use PVE::QemuServer;
+use PVE::QemuServer::MetaInfo;
+
+use QemuServerTest::FakeCFS;
+
+my $UID_A = 'abcdefghijklmnopqrst';
+my $UID_B = 'bbbbbbbbbbbbbbbbbbbb';
+
+my $helpers_module = Test::MockModule->new('PVE::QemuServer::Helpers');
+$helpers_module->mock(kvm_user_version => sub { return '10.1.2'; });
+
+sub configs { return $QemuServerTest::FakeCFS::configs; }
+sub generated_uid { return QemuServerTest::FakeCFS::generated_uid(@_); }
+sub stored_identity { return QemuServerTest::FakeCFS::stored_identity(@_); }
+
+sub load_meta($vmid) {
+    return PVE::QemuServer::MetaInfo::parse_meta_info(PVE::QemuConfig->load_config($vmid)->{meta});
+}
+
+subtest 'meta format' => sub {
+    my $meta =
+        'creation-qemu=10.1.2,ctime=1700000000,rtime=1700000000123,uid=abcdefghijklmnopqrst';
+
+    is_deeply(
+        PVE::QemuServer::MetaInfo::parse_meta_info($meta),
+        {
+            'creation-qemu' => '10.1.2',
+            ctime => 1700000000,
+            rtime => 1700000000123,
+            uid => $UID_A,
+        },
+        'identity members get parsed',
+    );
+    is(
+        PVE::JSONSchema::print_property_string(
+            PVE::QemuServer::MetaInfo::parse_meta_info($meta),
+            $PVE::QemuServer::MetaInfo::meta_info_fmt,
+        ),
+        $meta,
+        'printing the parsed property gives the same string',
+    );
+
+    for my $invalid (
+        'uid=ABCDEFGHIJKLMNOPQRST', 'uid=abcdefghijklmnopqrs', 'rtime=-1', 'rtime=1x',
+    ) {
+        eval {
+            PVE::JSONSchema::parse_property_string(
+                $PVE::QemuServer::MetaInfo::meta_info_fmt, $invalid,
+            );
+        };
+        ok($@, "'$invalid' is rejected");
+    }
+
+    # versions before the identity members only know these two, and drop the whole property
+    my $old_fmt = {
+        ctime => $PVE::QemuServer::MetaInfo::meta_info_fmt->{ctime},
+        'creation-qemu' => $PVE::QemuServer::MetaInfo::meta_info_fmt->{'creation-qemu'},
+    };
+    eval { PVE::JSONSchema::parse_property_string($old_fmt, $meta) };
+    like(
+        $@,
+        qr/property is not defined in schema/,
+        'format without identity members rejects it',
+    );
+};
+
+subtest 'identities are enabled, but not for writing temporary configs' => sub {
+    QemuServerTest::FakeCFS::reset();
+
+    ok(PVE::QemuConfig->__identity_enabled(), 'enabled for PVE::QemuConfig');
+
+    my $conf = { name => 'template-cmd' };
+    PVE::QemuConfig::NoWrite->mark_config($conf);
+    eval { PVE::QemuConfig->write_config(100, $conf) };
+    is($@, "refusing to write temporary configuration\n", 'NoWrite refuses');
+    eval { PVE::QemuConfig::NoWrite->write_config(100, $conf) };
+    is(
+        $@,
+        "refusing to write temporary configuration\n",
+        'NoWrite refuses when called directly',
+    );
+    is_deeply(configs(), {}, 'nothing written');
+    is($QemuServerTest::FakeCFS::generated, 0, 'no identity generated');
+};
+
+subtest 'config writes keep the stored identity' => sub {
+    QemuServerTest::FakeCFS::reset();
+
+    PVE::QemuConfig->write_config(100, { memory => 512, meta => "rtime=1,uid=$UID_B" });
+    is_deeply(
+        stored_identity(100),
+        { uid => generated_uid(1), rtime => 1700000000000 },
+        'first write ignores a carried identity and generates one',
+    );
+    like(configs()->{100}, qr/^meta: rtime=1700000000000,uid=\w+$/m,
+        'written as meta property');
+
+    $QemuServerTest::FakeCFS::now_ms = 1800000000000;
+
+    my $conf = PVE::QemuConfig->load_config(100);
+    $conf->{meta} = "creation-qemu=9.2.0,ctime=1600000000,rtime=1,uid=$UID_B";
+    PVE::QemuConfig->write_config(100, $conf);
+    is_deeply(
+        load_meta(100),
+        {
+            'creation-qemu' => '9.2.0',
+            ctime => 1600000000,
+            rtime => 1700000000000,
+            uid => generated_uid(1),
+        },
+        'foreign identity replaced by the stored one, other members kept',
+    );
+
+    $conf = PVE::QemuConfig->load_config(100);
+    delete $conf->{meta};
+    PVE::QemuConfig->write_config(100, $conf);
+    is_deeply(
+        load_meta(100),
+        { rtime => 1700000000000, uid => generated_uid(1) },
+        'identity kept when the property is gone',
+    );
+
+    configs()->{101} = "memory: 512\nmeta: creation-qemu=8.0.2,ctime=1500000000\n";
+    $conf = PVE::QemuConfig->load_config(101);
+    $conf->{name} = 'old';
+    PVE::QemuConfig->write_config(101, $conf);
+    is_deeply(
+        load_meta(101),
+        {
+            'creation-qemu' => '8.0.2',
+            ctime => 1500000000,
+            rtime => 1800000000000,
+            uid => generated_uid(2),
+        },
+        'existing guest without identity gets one on its first write',
+    );
+};
+
+subtest 'create' => sub {
+    QemuServerTest::FakeCFS::reset();
+
+    my $reservation = PVE::QemuConfig->create_and_lock_config(100);
+    is_deeply(
+        $reservation,
+        {
+            existed => 0,
+            previous => undef,
+            'previous-pending-uid' => undef,
+            assigned => { uid => generated_uid(1), rtime => 1700000000000 },
+        },
+        'reservation stores a new identity',
+    );
+
+    $QemuServerTest::FakeCFS::now_ms = 1700000005000;
+
+    my $conf = { memory => 512, meta => PVE::QemuServer::MetaInfo::new_meta_info_string() };
+    PVE::QemuConfig->write_config(100, $conf);
+    my $meta = load_meta(100);
+    is_deeply(
+        [$meta->@{qw(creation-qemu uid rtime)}],
+        ['10.1.2', generated_uid(1), 1700000000000],
+        'final config keeps the reserved identity next to the creation info',
+    );
+    ok($meta->{ctime}, 'creation time set');
+};
+
+subtest 'clone' => sub {
+    QemuServerTest::FakeCFS::reset();
+
+    configs()->{100} = "memory: 512\nmeta: creation-qemu=9.2.0,ctime=1600000000,"
+        . "rtime=1600000000000,uid=$UID_A\nname: source\n";
+
+    for my $snapshot (0, 1) {
+        my $newid = 200 + $snapshot;
+        my $source = PVE::QemuConfig->load_config(100);
+        if ($snapshot) {
+            # a snapshot can carry any identity, the clone must not take it over either
+            $source = { memory => 256, meta => "rtime=1,uid=$UID_B" };
+        }
+
+        PVE::QemuConfig->create_and_lock_config($newid, 0, 'clone');
+
+        # like the clone API, which copies everything but some snapshot related keys
+        my $newconf = { $source->%*, lock => 'clone', name => "clone-$newid" };
+        delete $newconf->{digest};
+        PVE::QemuConfig->write_config($newid, $newconf);
+        delete $newconf->{lock};
+        PVE::QemuConfig->write_config($newid, $newconf);
+
+        my $uid = generated_uid(1 + $snapshot);
+        is(stored_identity($newid)->{uid}, $uid, "clone $newid has a new uid");
+        is_deeply(
+            load_meta($newid),
+            $snapshot
+            ? { rtime => 1700000000000, uid => $uid }
+            : {
+                'creation-qemu' => '9.2.0',
+                ctime => 1600000000,
+                rtime => 1700000000000,
+                uid => $uid,
+            },
+            "clone $newid keeps the creation info of its source",
+        );
+    }
+    is(stored_identity(100)->{uid}, $UID_A, 'source keeps its uid');
+};
+
+subtest 'importovf' => sub {
+    QemuServerTest::FakeCFS::reset();
+
+    require PVE::CLI::qm;
+
+    my $tmpdir = tempdir('importovf-XXXXXX', DIR => '.', CLEANUP => 1);
+    my $manifest = "$tmpdir/test.ovf";
+    PVE::Tools::file_set_contents($manifest, "<ovf/>\n");
+
+    my $storage_module = Test::MockModule->new('PVE::Storage');
+    $storage_module->mock(
+        config => sub { return {}; },
+        storage_check_enabled => sub { return {}; },
+    );
+    my $ovf_module = Test::MockModule->new('PVE::GuestImport::OVF');
+    $ovf_module->mock(
+        parse_ovf => sub {
+            return { qm => { name => 'imported', memory => 1024, cores => 2 }, disks => [] };
+        },
+    );
+
+    PVE::CLI::qm->importovf({ vmid => 100, manifest => $manifest, storage => 'local' });
+
+    my $conf = PVE::QemuConfig->load_config(100);
+    is($conf->{name}, 'imported', 'config imported');
+    ok(!defined($conf->{lock}), 'create lock removed');
+    is_deeply(
+        stored_identity(100),
+        { uid => generated_uid(1), rtime => 1700000000000 },
+        'imported VM got a new identity on reservation and kept it',
+    );
+};
+
+done_testing();
diff --git a/src/test/run_parse_config_tests.pl b/src/test/run_parse_config_tests.pl
index c30aad99..566eec4f 100755
--- a/src/test/run_parse_config_tests.pl
+++ b/src/test/run_parse_config_tests.pl
@@ -25,7 +25,7 @@ my $INPUT_DIR = './parse-config-input';
 my $EXPECTED_DIR = './parse-config-expected';
 
 # NOTE update when you add/remove tests
-plan tests => 2 * 11;
+plan tests => 2 * 13;
 
 sub run_tests {
     my ($strict) = @_;
diff --git a/src/test/run_qemu_restore_config_tests.pl b/src/test/run_qemu_restore_config_tests.pl
index ab4dd887..89d5bcf4 100755
--- a/src/test/run_qemu_restore_config_tests.pl
+++ b/src/test/run_qemu_restore_config_tests.pl
@@ -300,7 +300,8 @@ sub restore_api {
     return ($err, $output);
 }
 
-my $TARGET_CONF = "memory: 1024\nmeta: creation-qemu=10.0.0,ctime=1700000000\nname: target\n";
+my $TARGET_CONF = "memory: 1024\nmeta: creation-qemu=10.0.0,ctime=1700000000,"
+    . "rtime=1700000000000,uid=tttttttttttttttttttt\nname: target\n";
 my $NOT_CLEANED_UP = qr/VM 100 state is NOT cleaned up/;
 
 for my $type (sort keys $ARCHIVES->%*) {
diff --git a/src/test/snapshot-expected/create/qemu-server/401.conf b/src/test/snapshot-expected/create/qemu-server/401.conf
new file mode 100644
index 00000000..87aadf80
--- /dev/null
+++ b/src/test/snapshot-expected/create/qemu-server/401.conf
@@ -0,0 +1,31 @@
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+memory: 8192
+meta: creation-qemu=10.0.0,ctime=1700000000,rtime=1700000000000,uid=abcdefghijklmnopqrst
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+parent: test
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+sockets: 1
+vga: qxl
+
+[test]
+#test comment
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+memory: 8192
+meta: creation-qemu=10.0.0,ctime=1700000000,rtime=1700000000000,uid=abcdefghijklmnopqrst
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+snaptime: 1234567890
+sockets: 1
+vga: qxl
diff --git a/src/test/snapshot-expected/create/qemu-server/402.conf b/src/test/snapshot-expected/create/qemu-server/402.conf
new file mode 100644
index 00000000..976c0a39
--- /dev/null
+++ b/src/test/snapshot-expected/create/qemu-server/402.conf
@@ -0,0 +1,31 @@
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+memory: 8192
+meta: creation-qemu=8.0.2,ctime=1600000000,rtime=1234567890123,uid=qrstuvwxyzbcdefghijk
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+parent: test
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+sockets: 1
+vga: qxl
+
+[test]
+#test comment
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+memory: 8192
+meta: creation-qemu=8.0.2,ctime=1600000000
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+snaptime: 1234567890
+sockets: 1
+vga: qxl
diff --git a/src/test/snapshot-expected/rollback/qemu-server/401.conf b/src/test/snapshot-expected/rollback/qemu-server/401.conf
new file mode 100644
index 00000000..6215ce26
--- /dev/null
+++ b/src/test/snapshot-expected/rollback/qemu-server/401.conf
@@ -0,0 +1,36 @@
+# this is a description
+agent: 1
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+memory: 8192
+meta: creation-qemu=9.2.0,ctime=1600000000,rtime=1700000000000,uid=abcdefghijklmnopqrst
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+parent: test
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+sockets: 1
+vga: qxl
+
+[test]
+#test comment
+agent: 1
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+machine: q35
+memory: 8192
+meta: creation-qemu=9.2.0,ctime=1600000000,rtime=1600000000000,uid=bbbbbbbbbbbbbbbbbbbb
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+snaptime: 1234567890
+sockets: 1
+vga: qxl
+vmstate: somestorage:state-volume
diff --git a/src/test/snapshot-expected/rollback/qemu-server/402.conf b/src/test/snapshot-expected/rollback/qemu-server/402.conf
new file mode 100644
index 00000000..a10bfa13
--- /dev/null
+++ b/src/test/snapshot-expected/rollback/qemu-server/402.conf
@@ -0,0 +1,35 @@
+# this is a description
+agent: 1
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+memory: 8192
+meta: rtime=1700000000000,uid=abcdefghijklmnopqrst
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+parent: test
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+sockets: 1
+vga: qxl
+
+[test]
+#test comment
+agent: 1
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+machine: q35
+memory: 8192
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+snaptime: 1234567890
+sockets: 1
+vga: qxl
+vmstate: somestorage:state-volume
diff --git a/src/test/snapshot-input/create/qemu-server/401.conf b/src/test/snapshot-input/create/qemu-server/401.conf
new file mode 100644
index 00000000..41ccdae5
--- /dev/null
+++ b/src/test/snapshot-input/create/qemu-server/401.conf
@@ -0,0 +1,13 @@
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+memory: 8192
+meta: creation-qemu=10.0.0,ctime=1700000000,rtime=1700000000000,uid=abcdefghijklmnopqrst
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+sockets: 1
+vga: qxl
diff --git a/src/test/snapshot-input/create/qemu-server/402.conf b/src/test/snapshot-input/create/qemu-server/402.conf
new file mode 100644
index 00000000..e03717b6
--- /dev/null
+++ b/src/test/snapshot-input/create/qemu-server/402.conf
@@ -0,0 +1,13 @@
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+memory: 8192
+meta: creation-qemu=8.0.2,ctime=1600000000
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+sockets: 1
+vga: qxl
diff --git a/src/test/snapshot-input/rollback/qemu-server/401.conf b/src/test/snapshot-input/rollback/qemu-server/401.conf
new file mode 100644
index 00000000..7895e0df
--- /dev/null
+++ b/src/test/snapshot-input/rollback/qemu-server/401.conf
@@ -0,0 +1,35 @@
+# this is a description
+agent: 1
+bootdisk: ide2
+cores: 2
+ide0: local:snapshotable-disk-1,size=32G
+ide2: none,media=cdrom
+memory: 4096
+meta: creation-qemu=10.0.0,ctime=1700000000,rtime=1700000000000,uid=abcdefghijklmnopqrst
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+parent: test
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+sockets: 2
+
+[test]
+#test comment
+agent: 1
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+machine: q35
+memory: 8192
+meta: creation-qemu=9.2.0,ctime=1600000000,rtime=1600000000000,uid=bbbbbbbbbbbbbbbbbbbb
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+snaptime: 1234567890
+sockets: 1
+vga: qxl
+vmstate: somestorage:state-volume
diff --git a/src/test/snapshot-input/rollback/qemu-server/402.conf b/src/test/snapshot-input/rollback/qemu-server/402.conf
new file mode 100644
index 00000000..0fa7fe51
--- /dev/null
+++ b/src/test/snapshot-input/rollback/qemu-server/402.conf
@@ -0,0 +1,34 @@
+# this is a description
+agent: 1
+bootdisk: ide2
+cores: 2
+ide0: local:snapshotable-disk-1,size=32G
+ide2: none,media=cdrom
+memory: 4096
+meta: creation-qemu=10.0.0,ctime=1700000000,rtime=1700000000000,uid=abcdefghijklmnopqrst
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+parent: test
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+sockets: 2
+
+[test]
+#test comment
+agent: 1
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+machine: q35
+memory: 8192
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+snaptime: 1234567890
+sockets: 1
+vga: qxl
+vmstate: somestorage:state-volume
diff --git a/src/test/snapshot-test.pm b/src/test/snapshot-test.pm
index 44e55d6a..84629f00 100644
--- a/src/test/snapshot-test.pm
+++ b/src/test/snapshot-test.pm
@@ -5,6 +5,7 @@ use warnings;
 
 use lib qw(..);
 
+use PVE::GuestHelpers;
 use PVE::Storage;
 use PVE::Storage::Plugin;
 use PVE::QemuServer;
@@ -30,6 +31,9 @@ my $freeze_possible;
 my $stop_possible;
 my $save_vmstate_works;
 my $vm_mon = {};
+my $real_write_config;
+
+my $original_write_config = \&PVE::QemuConfig::write_config;
 
 # Mocked methods
 
@@ -296,6 +300,13 @@ sub cfs_config_path {
     return "snapshot-working/$node/qemu-server/$vmid.conf";
 }
 
+# the same file that mocked_get_config reads, so that nothing looks at the host's /etc/pve
+sub config_file {
+    my ($class, $vmid, $node) = @_;
+
+    return $class->cfs_config_path($vmid, $node);
+}
+
 sub load_config {
     my ($class, $vmid, $node) = @_;
 
@@ -310,18 +321,10 @@ sub load_config {
 sub write_config {
     my ($class, $vmid, $conf) = @_;
 
-    my $filename = $class->cfs_config_path($vmid);
-
-    if ($conf->{snapshots}) {
-        foreach my $snapname (keys %{ $conf->{snapshots} }) {
-            $conf->{snapshots}->{$snapname}->{snaptime} = "1234567890"
-                if $conf->{snapshots}->{$snapname}->{snaptime};
-        }
-    }
+    # the real method with the guest identity handling, which writes through mocked_cfs_write_file
+    return $original_write_config->($class, $vmid, $conf) if $real_write_config;
 
-    my $raw = PVE::QemuServer::write_vm_config($filename, $conf);
-
-    PVE::Tools::file_set_contents($filename, $raw);
+    mocked_cfs_write_file($class->cfs_config_path($vmid), $conf);
 }
 
 sub has_feature {
@@ -345,6 +348,31 @@ sub assert_config_exists_on_node {
 }
 # END mocked PVE::QemuConfig methods
 
+# BEGIN mocked PVE::Cluster methods
+
+sub mocked_get_config {
+    my ($path) = @_;
+
+    return -e $path ? PVE::Tools::file_get_contents($path) : undef;
+}
+
+sub mocked_cfs_write_file {
+    my ($filename, $conf) = @_;
+
+    if ($conf->{snapshots}) {
+        foreach my $snapname (keys %{ $conf->{snapshots} }) {
+            $conf->{snapshots}->{$snapname}->{snaptime} = "1234567890"
+                if $conf->{snapshots}->{$snapname}->{snaptime};
+        }
+    }
+
+    my $raw = PVE::QemuServer::write_vm_config($filename, $conf);
+
+    PVE::Tools::file_set_contents($filename, $raw);
+}
+
+# END mocked PVE::Cluster methods
+
 # BEGIN mocked PVE::QemuServer::Helpers methods
 
 sub vm_running_locally {
@@ -441,6 +469,16 @@ sub vm_stop {
 PVE::Tools::run_command("rm -rf snapshot-working");
 PVE::Tools::run_command("cp -a snapshot-input snapshot-working");
 
+$PVE::GuestHelpers::lockdir = "snapshot-working/lock";
+
+my $cluster_module = Test::MockModule->new('PVE::Cluster');
+$cluster_module->mock('get_config', \&mocked_get_config);
+$cluster_module->mock('cfs_write_file', \&mocked_cfs_write_file);
+
+my $guest_identity_module = Test::MockModule->new('PVE::GuestIdentity');
+$guest_identity_module->mock('__random_bytes', sub { return '0123456789abcdefghij'; });
+$guest_identity_module->mock('__time_ms', sub { return 1234567890123; });
+
 my $qemu_migrate_helpers_module = Test::MockModule->new('PVE::QemuMigrate::Helpers');
 $qemu_migrate_helpers_module->mock('set_migration_caps', \&set_migration_caps);
 
@@ -453,6 +491,7 @@ $qemu_monitor_module->mock('qmp_cmd', \&qmp_cmd);
 my $qemu_config_module = Test::MockModule->new('PVE::QemuConfig');
 $qemu_config_module->mock('config_file_lock', \&config_file_lock);
 $qemu_config_module->mock('cfs_config_path', \&cfs_config_path);
+$qemu_config_module->mock('config_file', \&config_file);
 $qemu_config_module->mock('load_config', \&load_config);
 $qemu_config_module->mock('write_config', \&write_config);
 $qemu_config_module->mock('has_feature', \&has_feature);
@@ -641,6 +680,16 @@ testcase_create("303", "test", 1, "test comment", "storage activation failed\n\n
 
 $activate_storage_possible = 1;
 
+$real_write_config = 1;
+
+printf("Successful snapshot_create keeping the guest identity\n");
+testcase_create("401", "test", 0, "test comment", "", { "local:snapshotable-disk-1" => "test" });
+
+printf("Successful snapshot_create assigning a guest identity to a config without one\n");
+testcase_create("402", "test", 0, "test comment", "", { "local:snapshotable-disk-1" => "test" });
+
+$real_write_config = 0;
+
 $nodename = "delete";
 printf("\n");
 printf("Running delete tests\n");
@@ -777,6 +826,17 @@ testcase_rollback("303", "test", "storage activation failed\n");
 
 $activate_storage_possible = 1;
 
+$real_write_config = 1;
+
+printf("Successful snapshot_rollback keeping the current guest identity, not the snapshot's\n");
+testcase_rollback("401", "test", "", { "local:snapshotable-disk-1" => "test" });
+
+printf(
+    "Successful snapshot_rollback to a snapshot without meta info, keeping the guest identity\n");
+testcase_rollback("402", "test", "", { "local:snapshotable-disk-1" => "test" });
+
+$real_write_config = 0;
+
 done_testing();
 
 1;
-- 
2.47.3





^ permalink raw reply related	[relevance 15%]

* [PATCH guest-common v2 08/36] guest identity: add helpers for the guest uid and registration time
  2026-11-17 22:34 18% [PATCH cluster/guest-common/qemu-server/container/manager/docs v2 00/36] " Thomas Lamprecht
@ 2026-11-17 22:34 22% ` Thomas Lamprecht
  2026-11-17 22:34 15% ` [PATCH qemu-server v2 14/36] fix #7846: config: add a guest identity to the 'meta' property Thomas Lamprecht
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 32+ results
From: Thomas Lamprecht @ 2026-11-17 22:34 UTC (permalink / raw)
  To: pve-devel

A VMID can be reused, and a guest can get a different VMID or move
to another cluster after a restore or remote migration. External tools
such as backup products need to recognize the same logical guest
independently of its VMID, as described in bug #7846.

Provide shared helpers for a random uid of 20 characters from the
lowercase base32 alphabet, which is 100 random bits, and a registration
time in milliseconds. Both are members of the guest config's 'meta'
property. Supply format definitions for both guest types and extract or
merge the identity without requiring knowledge of other members,
including newer ones. Also read it from a raw config, as the parser of a
guest type can drop a 'meta' property with members it does not know.

100 bits make a duplicate practically impossible, and the uid still fits
into a 128-bit value with 28 bits to spare, for example for a format
version and extra data, should a later format need them. Base32 keeps it
at 20 characters, about half the width of a UUID in its usual notation,
and only uses lowercase letters and digits. Each character comes from a
random byte of its own, so no encoder is needed.

The registration time is the time a guest got its uid in this cluster.
Unlike the creation time, which a clone, a restore and a migration from
another cluster copy along with the guest, it changes when a guest is
registered again. Tools can use it to tell a restored guest from the one
they knew, also if both have the same uid.

Also provide a minimum node-version check for migration targets. Older
versions drop the identity on config writes. Report the required and
available versions so callers can explain a refusal, with a shared
schema for API results; missing version information counts as too old.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
---

changes v1 -> v2:
* use v5.36 and signatures
* take each character of the uid from a random byte of its own, without
  an encoder (Dominik)
* add a helper to read the identity from a raw config, shared by the
  config write and the VM restore, which picks the 'meta' line like
  pmxcfs does
* add the schema of the migration precondition result, shared by both
  guest types
* explain the format, the difference between rtime and ctime, and why
  the generic property string helpers are not used (Dominik)
* shorter description of the uid

NOTE: MIN_PVE_MANAGER_VERSION (9.2.31) is a stand-in. It has to become
the first pve-manager version that depends on the qemu-server and
pve-container versions with this series, see the cover letter.

 src/Makefile                      |   1 +
 src/PVE/GuestIdentity.pm          | 235 +++++++++++++++++++++
 src/tests/Makefile                |   7 +-
 src/tests/guest-identity-tests.pl | 338 ++++++++++++++++++++++++++++++
 4 files changed, 579 insertions(+), 2 deletions(-)
 create mode 100644 src/PVE/GuestIdentity.pm
 create mode 100755 src/tests/guest-identity-tests.pl

diff --git a/src/Makefile b/src/Makefile
index 161dbe5..af4c277 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -10,6 +10,7 @@ install: PVE
 	install -m 0644 PVE/AbstractMigrate.pm ${PERL5DIR}/PVE/
 	install -m 0644 PVE/GuestHelpers.pm ${PERL5DIR}/PVE/
 	install -m 0644 PVE/GuestID.pm ${PERL5DIR}/PVE/
+	install -m 0644 PVE/GuestIdentity.pm ${PERL5DIR}/PVE/
 	install -m 0644 PVE/Replication.pm ${PERL5DIR}/PVE/
 	install -m 0644 PVE/ReplicationConfig.pm ${PERL5DIR}/PVE/
 	install -m 0644 PVE/ReplicationState.pm ${PERL5DIR}/PVE/
diff --git a/src/PVE/GuestIdentity.pm b/src/PVE/GuestIdentity.pm
new file mode 100644
index 0000000..b4e3582
--- /dev/null
+++ b/src/PVE/GuestIdentity.pm
@@ -0,0 +1,235 @@
+package PVE::GuestIdentity;
+
+use v5.36;
+
+use Time::HiRes;
+
+use PVE::Cluster;
+
+# The identity of a guest, VM or container alike, consists of two members of the 'meta' property
+# string in the top-level section of its config: 'uid', a random identifier of the guest's lineage
+# (100 bits as 20 characters of the lowercase RFC 4648 base32 alphabet), and 'rtime', the time the
+# config was registered in this cluster (milliseconds since the epoch). The functions here pass it
+# as a hash with these two keys.
+#
+# 100 random bits make a duplicate uid practically impossible, a billion uids contain one with a
+# probability of about 4 * 10^-13, and still leave 28 bits of a 128-bit value free, for example for
+# a format version and extra data, should a later format need them. Base32 keeps the uid at 20
+# characters, about half the width of a UUID in its usual notation, and only uses lowercase letters
+# and digits, which need no quoting in a property string.
+#
+# Unlike the creation time 'ctime' of the same property, which a clone, a restore and a migration
+# from another cluster copy along with the guest, the rtime belongs to the uid of the guest in this
+# cluster: it is the time the guest got its uid here, be it a new one or one it took over. So a
+# changed rtime tells that a guest was registered again, even if its uid is the same as before.
+
+# Must match the first pve-manager release that depends on the qemu-server and pve-container
+# versions handling the identity. Older nodes drop the whole 'meta' property on their next write
+# of a guest config.
+use constant MIN_PVE_MANAGER_VERSION => '9.2.31';
+
+my $UID_LENGTH = 20;
+my $UID_ALPHABET = 'abcdefghijklmnopqrstuvwxyz234567';
+my $UID_PATTERN = "[a-z2-7]{$UID_LENGTH}";
+
+# 15 digits of milliseconds last until the year 33658
+my $RTIME_MAX = 999_999_999_999_999;
+
+# Returns $len random bytes from the kernel's random number generator.
+sub __random_bytes($len) {
+    open(my $fh, '<', '/dev/urandom') or die "unable to open /dev/urandom - $!\n";
+    my $buf = '';
+    my $read = sysread($fh, $buf, $len);
+    die "unable to read from /dev/urandom - $!\n" if !defined($read);
+    die "short read from /dev/urandom\n" if $read != $len;
+    close($fh);
+
+    return $buf;
+}
+
+# Returns the current time in milliseconds since the epoch.
+sub __time_ms() {
+    my ($sec, $usec) = Time::HiRes::gettimeofday();
+
+    return $sec * 1000 + int($usec / 1000);
+}
+
+# Returns a random uid. Each character comes from the lowest 5 bits of a random byte of its own, so
+# it is uniformly distributed over the alphabet.
+my sub random_uid() {
+    my $bytes = __random_bytes($UID_LENGTH);
+
+    return join('', map { substr($UID_ALPHABET, ord($_) & 31, 1) } split(//, $bytes));
+}
+
+my sub is_valid_uid($uid) {
+    return defined($uid) && $uid =~ m/^$UID_PATTERN\z/;
+}
+
+my sub is_valid_rtime($rtime) {
+    return defined($rtime) && $rtime =~ m/^[0-9]{1,15}\z/;
+}
+
+# Returns the JSON schema properties of the identity members, for merging into the format of the
+# 'meta' property string of a guest type. Every call returns a new copy.
+sub meta_format_properties() {
+    return {
+        uid => {
+            type => 'string',
+            pattern => $UID_PATTERN,
+            description =>
+                "Random identifier of the guest lineage. A restore or a migration from another"
+                . " cluster keeps it if no other guest in the cluster uses it. A restore also does"
+                . " not take it over with 'unique', or when it overwrites a guest that has a uid"
+                . " of its own.",
+            optional => 1,
+        },
+        rtime => {
+            type => 'integer',
+            minimum => 0,
+            maximum => $RTIME_MAX,
+            description => "Time the guest was registered in this cluster, for example by"
+                . " creation, restore, or migration from another cluster, in milliseconds since"
+                . " the UNIX epoch.",
+            optional => 1,
+        },
+    };
+}
+
+# Returns a new identity with the current time as rtime. Its uid is $uid if given, otherwise a
+# random one.
+sub new_identity($uid = undef) {
+    die "invalid guest identity uid '$uid'\n" if defined($uid) && !is_valid_uid($uid);
+
+    return {
+        uid => $uid // random_uid(),
+        rtime => __time_ms(),
+    };
+}
+
+# Extracts the identity from the 'meta' property string $meta, which may contain any other
+# members, including ones unknown to this version.
+#
+# Returns undef if $meta has no valid uid, and an identity otherwise. Its rtime is undef if the
+# rtime member is missing or invalid. A member given more than once counts as invalid.
+#
+# This does not use PVE::JSONSchema::parse_property_string on purpose. That parser rejects the
+# whole string if one member is unknown or invalid. A guest without a readable identity gets a new
+# one with the next config write, so a problem with another member must not hide the uid.
+sub parse_identity($meta) {
+    return undef if !defined($meta);
+
+    my $values = {};
+    for my $part (split(/,/, $meta)) {
+        my ($key, $value) = $part =~ m/^([^=]+)=(.*)\z/ or next;
+        next if $key ne 'uid' && $key ne 'rtime';
+        $values->{$key} = exists($values->{$key}) ? undef : $value;
+    }
+
+    return undef if !is_valid_uid($values->{uid});
+
+    return {
+        uid => $values->{uid},
+        rtime => is_valid_rtime($values->{rtime}) ? $values->{rtime} : undef,
+    };
+}
+
+# Returns the 'meta' property string $meta, which may be undef, with the identity members set to
+# $identity. All other members are kept as they are, also ones unknown to this version, which
+# PVE::JSONSchema::print_property_string would reject.
+sub merge_identity($meta, $identity) {
+    die "invalid guest identity uid\n" if !is_valid_uid($identity->{uid});
+    die "invalid guest identity rtime\n" if !is_valid_rtime($identity->{rtime});
+
+    my (@plain, @members);
+    for my $part (split(/,/, $meta // '')) {
+        next if $part =~ m/^\s*\z/;
+
+        if (my ($key) = $part =~ m/^([^=]+)=/) {
+            push @members, [$key, $part] if $key ne 'uid' && $key ne 'rtime';
+        } else {
+            push @plain, $part;
+        }
+    }
+    push @members, ['rtime', "rtime=$identity->{rtime}"], ['uid', "uid=$identity->{uid}"];
+
+    # same order as PVE::JSONSchema::print_property_string uses, so that a guest type parsing and
+    # printing the property string again does not change it
+    return join(',', @plain, map { $_->[1] } sort { $a->[0] cmp $b->[0] } @members);
+}
+
+# Returns the identity in the top-level section of the raw guest config $raw, undef if it has none.
+# Only looks at the 'meta' property, so this also finds the identity in a config that the parser of
+# the guest type rejects or reads without 'meta', for example because of members from a newer
+# version.
+#
+# If a manual edit left more than one 'meta' line, the last one with anything after the colon
+# counts, also if that is only whitespace. The property lookup of pmxcfs does the same, and the
+# cluster-wide check of adopt uses it.
+sub parse_identity_from_raw_config($raw) {
+    my $meta;
+    for my $line (split(/\n/, $raw)) {
+        last if $line =~ m/^\[/; # snapshot or other section
+        $meta = $1 =~ s/^\s+|\s+$//gr if $line =~ m/^meta:(.+)$/;
+    }
+
+    return parse_identity($meta);
+}
+
+# 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
+# the node reports, if any.
+sub node_identity_unsupported($node) {
+    my $required = MIN_PVE_MANAGER_VERSION;
+    my ($major, $minor, $release) = split(/\./, $required);
+
+    my $supported =
+        eval { PVE::Cluster::node_pvecfg_version_at_least($node, $major, $minor, $release) };
+    return undef if $supported;
+
+    my $version = eval { PVE::Cluster::get_node_pvecfg_version($node) };
+
+    return { 'required-version' => $required, defined($version) ? (version => $version) : () };
+}
+
+# Returns the JSON schema of what node_identity_unsupported returns for a refused node, for the
+# result of API calls that report why a node is not allowed as migration target. Every call returns
+# a new copy.
+sub node_identity_unsupported_schema() {
+    return {
+        description =>
+            "Set if migrating to the node is refused because the node does not report a"
+            . " Proxmox VE version that keeps the guest identity.",
+        type => 'object',
+        optional => 1,
+        properties => {
+            version => {
+                description => "The Proxmox VE version the node reports.",
+                type => 'string',
+                optional => 1,
+            },
+            'required-version' => {
+                description => "The minimum Proxmox VE version that keeps the guest identity.",
+                type => 'string',
+            },
+        },
+    };
+}
+
+# Dies unless $node runs a version of Proxmox VE that keeps the identity when writing guest
+# configs, see node_identity_unsupported.
+sub assert_node_supports_identity($node) {
+    my $unsupported = node_identity_unsupported($node) or return;
+    my ($version, $required) = $unsupported->@{qw(version required-version)};
+
+    if (!defined($version)) {
+        die "node '$node' does not report its Proxmox VE version, so it is unknown whether the node"
+            . " keeps the guest identity\n";
+    }
+
+    die "node '$node' runs Proxmox VE $version, keeping the guest identity requires $required or"
+        . " newer - upgrade the node first\n";
+}
+
+1;
diff --git a/src/tests/Makefile b/src/tests/Makefile
index 8eb38a8..e2c3d01 100644
--- a/src/tests/Makefile
+++ b/src/tests/Makefile
@@ -1,8 +1,8 @@
 
 all:
 
-.PHONY: check abstract-config guest-id hookscript
-check: abstract-config guest-id hookscript
+.PHONY: check abstract-config guest-id guest-identity hookscript
+check: abstract-config guest-id guest-identity hookscript
 
 abstract-config: abstract-config-tests.pl
 	perl -I.. ./abstract-config-tests.pl
@@ -10,5 +10,8 @@ abstract-config: abstract-config-tests.pl
 guest-id: guest-id-tests.pl
 	perl -I.. ./guest-id-tests.pl
 
+guest-identity: guest-identity-tests.pl
+	perl -I.. ./guest-identity-tests.pl
+
 hookscript: hookscript-tests.pl
 	perl -I.. ./hookscript-tests.pl
diff --git a/src/tests/guest-identity-tests.pl b/src/tests/guest-identity-tests.pl
new file mode 100755
index 0000000..241e18c
--- /dev/null
+++ b/src/tests/guest-identity-tests.pl
@@ -0,0 +1,338 @@
+#!/usr/bin/perl
+
+use v5.36;
+
+use lib qw(..);
+
+use Test::MockModule;
+use Test::More;
+use Time::HiRes;
+
+use PVE::JSONSchema;
+use PVE::Tools;
+
+use PVE::GuestIdentity;
+
+subtest 'generation with fixed random bytes and time' => sub {
+    my $random_bytes = [];
+    my $time_ms = 1_700_000_000_123;
+
+    my $identity_module = Test::MockModule->new('PVE::GuestIdentity');
+    $identity_module->redefine(
+        __random_bytes => sub {
+            my ($len) = @_;
+            my $bytes = shift(@$random_bytes) // die "test error: no random bytes left\n";
+            die "test error: requested $len random bytes\n" if length($bytes) != $len;
+            return $bytes;
+        },
+        __time_ms => sub { return $time_ms; },
+    );
+
+    # each byte gives one character, its lowest 5 bits select it from the lowercase RFC 4648 base32
+    # alphabet
+    my $vectors = [
+        ["\x00" x 20, 'a' x 20],
+        ["\xff" x 20, '7' x 20],
+        ['0123456789abcdefghij', 'qrstuvwxyzbcdefghijk'],
+        [pack('C*', 0 .. 19), 'abcdefghijklmnopqrst'],
+        [pack('C*', 12 .. 31), 'mnopqrstuvwxyz234567'],
+        [pack('C*', map { $_ | 0xe0 } 0 .. 19), 'abcdefghijklmnopqrst'],
+    ];
+
+    for my $vector (@$vectors) {
+        my ($bytes, $uid) = @$vector;
+        $random_bytes = [$bytes];
+        is_deeply(
+            PVE::GuestIdentity::new_identity(),
+            { uid => $uid, rtime => $time_ms },
+            "encodes " . unpack('H*', $bytes),
+        );
+    }
+
+    # every symbol is as likely at each position, as each of them comes from 8 of the 256 values of
+    # the byte at that position
+    my $alphabet = 'abcdefghijklmnopqrstuvwxyz234567';
+    my $mismatches = 0;
+    for my $position (0 .. 19) {
+        for my $value (0 .. 255) {
+            my $bytes = "\x00" x 20;
+            substr($bytes, $position, 1) = chr($value);
+            $random_bytes = [$bytes];
+            my $expected = 'a' x 20;
+            substr($expected, $position, 1) = substr($alphabet, $value % 32, 1);
+            $mismatches++ if PVE::GuestIdentity::new_identity()->{uid} ne $expected;
+        }
+    }
+    is($mismatches, 0, 'each character comes from the byte at its position');
+
+    $random_bytes = [];
+    is_deeply(
+        PVE::GuestIdentity::new_identity('gaytemzugu3doobzmfrg'),
+        { uid => 'gaytemzugu3doobzmfrg', rtime => $time_ms },
+        'given uid is used',
+    );
+    eval { PVE::GuestIdentity::new_identity('GAYTEMZUGU3DOOBZMFRG') };
+    like($@, qr/invalid guest identity uid/, 'invalid given uid is rejected');
+};
+
+subtest 'generation' => sub {
+    my $first = PVE::GuestIdentity::new_identity();
+    my $second = PVE::GuestIdentity::new_identity();
+    like($first->{uid}, qr/^[a-z2-7]{20}\z/, 'uid has the expected format');
+    my @uids = map { PVE::GuestIdentity::new_identity()->{uid} } 1 .. 100;
+    is_deeply([grep { !m/^[a-z2-7]{20}\z/ } @uids], [], 'uids have 20 characters, no padding');
+    isnt($first->{uid}, $second->{uid}, 'uids differ');
+
+    my $before = int(Time::HiRes::time() * 1000);
+    my $rtime = PVE::GuestIdentity::new_identity()->{rtime};
+    my $after = int(Time::HiRes::time() * 1000) + 1;
+    like($rtime, qr/^\d+\z/, 'rtime is an integer');
+    ok($rtime >= $before && $rtime <= $after, 'rtime is the current time in milliseconds');
+};
+
+subtest 'format properties' => sub {
+    my $format = {
+        ctime => { type => 'integer', optional => 1 },
+        PVE::GuestIdentity::meta_format_properties()->%*,
+    };
+
+    is_deeply(
+        PVE::JSONSchema::parse_property_string(
+            $format,
+            'ctime=1700000000,rtime=1700000000123,uid=gaytemzugu3doobzmfrg',
+        ),
+        { ctime => 1700000000, rtime => 1700000000123, uid => 'gaytemzugu3doobzmfrg' },
+        'meta string with identity parses with a merged format',
+    );
+
+    for my $invalid (
+        'uid=GAYTEMZUGU3DOOBZMFRG',
+        'uid=gaytemzugu3doobzmfr',
+        'uid=gaytemzugu3doobzmfrga',
+        'uid=gaytemzugu3doobzmfr0',
+        'uid=' . substr('gaytemzugu3doobzmfrg', 0, 16),
+        'rtime=-1',
+        'rtime=1.5',
+        'rtime=1000000000000000',
+    ) {
+        eval { PVE::JSONSchema::parse_property_string($format, $invalid) };
+        ok($@, "format rejects '$invalid'");
+    }
+
+    my $copy = PVE::GuestIdentity::meta_format_properties();
+    $copy->{uid}->{pattern} = '.*';
+    isnt(
+        PVE::GuestIdentity::meta_format_properties()->{uid}->{pattern},
+        '.*',
+        'callers get their own copy',
+    );
+};
+
+subtest 'parse identity' => sub {
+    my $uid = 'gaytemzugu3doobzmfrg';
+    my $tests = [
+        [undef, undef, 'no meta'],
+        ['', undef, 'empty meta'],
+        ['ctime=1700000000', undef, 'meta without identity'],
+        [
+            "creation-qemu=10.1.2,ctime=1700000000,rtime=123,uid=$uid",
+            { uid => $uid, rtime => 123 },
+            'identity next to other members',
+        ],
+        [
+            "future=a b,uid=$uid,other,rtime=0",
+            { uid => $uid, rtime => 0 },
+            'unknown members and odd parts are ignored',
+        ],
+        ["rtime=123,uid=$uid", { uid => $uid, rtime => 123 }, 'identity only'],
+        ["uid=$uid", { uid => $uid, rtime => undef }, 'missing rtime'],
+        ["uid=$uid,rtime=12a", { uid => $uid, rtime => undef }, 'invalid rtime'],
+        ["uid=$uid,rtime=-5", { uid => $uid, rtime => undef }, 'negative rtime'],
+        [
+            "uid=$uid,rtime=999999999999999",
+            { uid => $uid, rtime => 999999999999999 },
+            'maximum rtime',
+        ],
+        ["uid=$uid,rtime=1000000000000000", { uid => $uid, rtime => undef }, 'too large rtime'],
+        [
+            "uid=$uid,rtime=\x{0661}\x{0662}",
+            { uid => $uid, rtime => undef },
+            'non-ASCII digits',
+        ],
+        ["uid=$uid,rtime=1,rtime=2", { uid => $uid, rtime => undef }, 'duplicate rtime'],
+        ['rtime=123', undef, 'rtime without uid'],
+        ["uid=$uid,uid=$uid,rtime=1", undef, 'duplicate uid'],
+        ['uid=GAYTEMZUGU3DOOBZMFRG,rtime=1', undef, 'uppercase uid'],
+        ['uid=gaytemzugu3doobzmfr,rtime=1', undef, 'short uid'],
+        ['uid=gaytemzugu3doobzmfrga,rtime=1', undef, 'long uid'],
+        ['uid=' . substr($uid, 0, 16) . ',rtime=1', undef, '16-character uid'],
+        ['uid=gaytemzugu3doobzmfr1,rtime=1', undef, 'uid outside of the alphabet'],
+        ["uid= $uid,rtime=1", undef, 'uid with whitespace'],
+    ];
+
+    for my $test (@$tests) {
+        my ($meta, $expected, $name) = @$test;
+        is_deeply(PVE::GuestIdentity::parse_identity($meta), $expected, $name);
+    }
+};
+
+subtest 'parse identity from raw config' => sub {
+    my $uid = 'gaytemzugu3doobzmfrg';
+    my $other = 'aaaqeayeaudaocajbifq';
+    my $identity = { uid => $uid, rtime => 123 };
+    my $tests = [
+        ['', undef, 'empty config'],
+        ["memory: 512\n", undef, 'no meta'],
+        [
+            "memory: 512\nmeta: ctime=1,rtime=123,uid=$uid\ncores: 2\n",
+            $identity,
+            'top-level meta',
+        ],
+        ["meta:   rtime=123,uid=$uid  \n", $identity, 'surrounding whitespace'],
+        ["meta: rtime=1,uid=$other\nmeta: rtime=123,uid=$uid\n", $identity, 'last meta wins'],
+        ["meta: future=a b,rtime=123,uid=$uid\n", $identity, 'unknown members'],
+        ["meta: rtime=123,uid=$uid\nmeta:\n", $identity, 'meta line without value is ignored'],
+        [
+            "meta: rtime=123,uid=$uid\nmeta:   \n", undef, 'meta line with only spaces counts',
+        ],
+        ["#meta: rtime=123,uid=$uid\n", undef, 'description line'],
+        ["memory: 512\n\n[PENDING]\nmeta: uid=$uid\n", undef, 'pending section is ignored'],
+        [
+            "meta: rtime=123,uid=$uid\n\n[snap]\nmeta: rtime=1,uid=$other\n",
+            $identity,
+            'snapshot section is ignored',
+        ],
+    ];
+
+    for my $test (@$tests) {
+        my ($raw, $expected, $name) = @$test;
+        is_deeply(PVE::GuestIdentity::parse_identity_from_raw_config($raw), $expected, $name);
+    }
+};
+
+subtest 'merge identity' => sub {
+    my $identity = { uid => 'gaytemzugu3doobzmfrg', rtime => 1700000000123 };
+    my $members = 'rtime=1700000000123,uid=gaytemzugu3doobzmfrg';
+    my $tests = [
+        [undef, $members, 'no meta'],
+        ['', $members, 'empty meta'],
+        [
+            'creation-qemu=10.1.2,ctime=1700000000',
+            "creation-qemu=10.1.2,ctime=1700000000,$members",
+            'other members are kept',
+        ],
+        [
+            'ctime=1,rtime=5,uid=aaaaaaaaaaaaaaaaaaaa',
+            "ctime=1,$members",
+            'existing identity is replaced',
+        ],
+        [
+            'uid=bogus,zz-future=x,rtime=1,uid=aaaaaaaaaaaaaaaaaaaa,ctime=1',
+            "ctime=1,$members,zz-future=x",
+            'invalid and duplicate identity members are dropped, unknown members kept',
+        ],
+        ['plain,ctime=1', "plain,ctime=1,$members", 'parts without key stay first'],
+    ];
+
+    for my $test (@$tests) {
+        my ($meta, $expected, $name) = @$test;
+        my $merged = PVE::GuestIdentity::merge_identity($meta, $identity);
+        is($merged, $expected, $name);
+        is_deeply(PVE::GuestIdentity::parse_identity($merged), $identity, "$name, parses back");
+    }
+
+    for my $invalid (
+        { uid => 'GAYTEMZUGU3DOOBZMFRG', rtime => 1 },
+        { uid => 'gaytemzugu3doobzmfrg', rtime => undef },
+        { uid => 'gaytemzugu3doobzmfrg', rtime => 'now' },
+        { uid => 'gaytemzugu3doobzmfrg', rtime => '1000000000000000' },
+        { uid => 'gaytemzugu3doobzmfrg,ctime=1', rtime => 1 },
+        { rtime => 1 },
+    ) {
+        eval { PVE::GuestIdentity::merge_identity('ctime=1', $invalid) };
+        ok($@, "invalid identity is rejected");
+    }
+};
+
+subtest 'node version check' => sub {
+    my $min = PVE::GuestIdentity::MIN_PVE_MANAGER_VERSION;
+    like($min, qr/^[0-9]+\.[0-9]+\.[0-9]+\z/, 'minimum version is a version string');
+    my ($major, $minor, $release) = split(/\./, $min);
+
+    my $versions = {
+        current => "$major.$minor.$release",
+        newer => "$major." . ($minor + 1) . ".0",
+        older => "$major.$minor." . ($release - 1),
+        invalid => 'invalid',
+    };
+
+    my $cluster_module = Test::MockModule->new('PVE::Cluster');
+    $cluster_module->mock(
+        get_node_pvecfg_version => sub {
+            my ($node) = @_;
+            die "malformed version info\n" if $node eq 'malformed';
+            return $versions->{$node};
+        },
+        node_pvecfg_version_at_least => sub {
+            my ($node, @min) = @_;
+            my $version = PVE::Cluster::get_node_pvecfg_version($node);
+            return $version && PVE::Tools::pvecfg_min_version($version, @min);
+        },
+    );
+
+    for my $node (qw(current newer)) {
+        eval { PVE::GuestIdentity::assert_node_supports_identity($node) };
+        is($@, '', "node with version '$versions->{$node}' is supported");
+        my $unsupported = PVE::GuestIdentity::node_identity_unsupported($node);
+        is($unsupported, undef, "no reason for '$node'");
+    }
+
+    for my $node (qw(older invalid missing malformed)) {
+        eval { PVE::GuestIdentity::assert_node_supports_identity($node) };
+        like($@, qr/node '$node'/, "node '$node' is refused");
+    }
+
+    my $schema = PVE::GuestIdentity::node_identity_unsupported_schema();
+    isnt(
+        $schema,
+        PVE::GuestIdentity::node_identity_unsupported_schema(),
+        'schema is a new copy',
+    );
+    for my $node (qw(older invalid missing malformed)) {
+        my $unsupported = PVE::GuestIdentity::node_identity_unsupported($node);
+        eval { PVE::JSONSchema::validate($unsupported, $schema) };
+        is($@, '', "reason for '$node' matches the schema");
+    }
+
+    for my $node (qw(older invalid)) {
+        is_deeply(
+            PVE::GuestIdentity::node_identity_unsupported($node),
+            { version => $versions->{$node}, 'required-version' => $min },
+            "reason for '$node' has both versions",
+        );
+        eval { PVE::GuestIdentity::assert_node_supports_identity($node) };
+        is(
+            $@,
+            "node '$node' runs Proxmox VE $versions->{$node}, keeping the guest identity requires"
+                . " $min or newer - upgrade the node first\n",
+            "refusal of '$node' names both versions",
+        );
+    }
+
+    for my $node (qw(missing malformed)) {
+        is_deeply(
+            PVE::GuestIdentity::node_identity_unsupported($node),
+            { 'required-version' => $min },
+            "reason for '$node' has only the required version",
+        );
+        eval { PVE::GuestIdentity::assert_node_supports_identity($node) };
+        is(
+            $@,
+            "node '$node' does not report its Proxmox VE version, so it is unknown whether the"
+                . " node keeps the guest identity\n",
+            "refusal of '$node' says why",
+        );
+    }
+};
+
+done_testing();
-- 
2.47.3





^ permalink raw reply related	[relevance 22%]

* [PATCH cluster/guest-common/qemu-server/container/manager/docs v2 00/36] fix #7846: guest identity (uid) and cluster ID
@ 2026-11-17 22:34 18% Thomas Lamprecht
  2026-11-17 22:34 22% ` [PATCH guest-common v2 08/36] guest identity: add helpers for the guest uid and registration time Thomas Lamprecht
                   ` (3 more replies)
  0 siblings, 4 replies; 32+ results
From: Thomas Lamprecht @ 2026-11-17 22:34 UTC (permalink / raw)
  To: pve-devel

A VMID can be reused for another guest, and a guest can get another
VMID or move to another cluster through a restore or a remote
migration. So backup software and other tools cannot tell whether they
still look at the same guest, see [0].

This series gives every VM and container a guest identity in the
read-only 'meta' property: a random uid (100 bits as 20 base32
characters) and the time the guest was registered in the cluster. Create
and clone get a new uid. Config changes, migration, rollback, backup and
restore keep it, also under another VMID or in another cluster, as long
as no other guest there has it. Each cluster or standalone node also
gets a cluster ID in the same format, generated and protected by pmxcfs.
The docs patches describe the details.

The uid is a plain random nonce: 100 bits make a duplicate practically
impossible and fit into a 128-bit value with room to spare, and 20
base32 characters stay short and need no quoting. The registration time
is separate from the creation time, which clones, restores and remote
migrations copy along. It changes when a guest gets registered again, so
tools can tell such a guest from the one they knew.

Three behavior changes come with it:

* Restoring over an existing guest whose uid differs from the one of
  the backup is refused unless 'allow-identity-mismatch' is set. 'force'
  alone does not override this.
* A migration to another cluster is refused if another guest there
  already has the uid, unless 'allow-new-uid' is set. The check runs
  before anything is transferred. PDM does not know the option yet.
* Older versions drop the whole 'meta' property of a guest that has an
  identity. So migration and clone to such nodes is refused, and remote
  migration bumps the tunnel version. This also hits moves by the HA
  stack, which stops a container or a relocated VM before the migration
  gets refused. A target check in the LRM that avoids this will follow
  separately.

The patches are in dependency order:
guest-common needs pve-cluster, qemu-server and container need
guest-common, and manager needs all of them. manager also has to depend
on the qemu-server and container versions with this series, as the
migration guard takes the pve-manager version of a node as proof that
the node keeps the identity. MIN_PVE_MANAGER_VERSION in guest-common is
a stand-in for that version.

Besides fully build-testing every commit, also tested this on simple
pmxcfs with corosync in network namespaces, and end to end on a nested
three-node cluster that was upgraded node by node, with external remote
migrations to a standalone node.

changes v1 -> v2, thanks to Dominik for the review:
* rebase onto current master (tracking of used guest IDs, dfsm rework)
* remote migration takes the uid over at its start and refuses a uid
  that is in use in the target cluster, unless 'allow-new-uid' is set
* qemu-server and container share the restore checks and messages
  through pve-guest-common, with fewer special cases
* IDs take each character from one random byte, without an encoder
* the clone dialog does not offer nodes that would drop the identity,
  and a bulk migration checks its target once (new patch 32)
* independent fixes moved out of the series and got applied on their
  own: the IPC client error, the order of removing firewall and guest
  config, and the cleanup of a remote migration target after failures
* comments, commit messages and docs give the reasons for the format,
  for rtime next to ctime and for the separate lock
Details are in the notes below the "---" of each patch.

v1: https://lore.proxmox.com/pve-devel/20261116004703.2908294-1-t.lamprecht@proxmox.com/

[0]: https://bugzilla.proxmox.com/show_bug.cgi?id=7846

cluster:

Thomas Lamprecht (7):
  pmxcfs: reject changes to the cluster ID file from user space
  pmxcfs: generate a cluster ID on standalone nodes
  pmxcfs: dfsm: add a callback that runs once all members are in sync
  pmxcfs: quorum: pass the corosync membership to an optional listener
  pmxcfs: dcdb: generate the cluster ID once the cluster is in sync
  cluster: add helper to read the cluster ID
  pmxcfs: allow removing the cluster ID file in forced local mode

 src/PVE/Cluster.pm          |  16 ++
 src/pmxcfs/Makefile         |  12 +-
 src/pmxcfs/cfs-plug-memdb.c |  46 ++++
 src/pmxcfs/cfs-utils.c      |   8 +
 src/pmxcfs/cfs-utils.h      |   5 +
 src/pmxcfs/check_dcdb.c     | 530 ++++++++++++++++++++++++++++++++++++
 src/pmxcfs/check_memdb.c    | 283 +++++++++++++++++++
 src/pmxcfs/cluster-id.c     | 142 ++++++++++
 src/pmxcfs/cluster-id.h     |  50 ++++
 src/pmxcfs/dcdb.c           | 144 ++++++++++
 src/pmxcfs/dcdb.h           |   5 +
 src/pmxcfs/dfsm.c           |  59 ++++
 src/pmxcfs/dfsm.h           |  14 +
 src/pmxcfs/pmxcfs.c         |  10 +-
 src/pmxcfs/quorum.c         |  26 +-
 src/pmxcfs/quorum.h         |   8 +-
 src/pmxcfs/status.c         |  12 +
 src/pmxcfs/status.h         |   3 +
 src/test/Makefile           |   6 +-
 src/test/test_cluster_id.pl |  46 ++++
 20 files changed, 1413 insertions(+), 12 deletions(-)
 create mode 100644 src/pmxcfs/check_dcdb.c
 create mode 100644 src/pmxcfs/cluster-id.c
 create mode 100644 src/pmxcfs/cluster-id.h
 create mode 100644 src/test/test_cluster_id.pl


guest-common:

Thomas Lamprecht (4):
  guest identity: add helpers for the guest uid and registration time
  abstract config: assign a guest identity and keep it on config writes
  abstract config: let the VMID reservation return the previous state
  guest identity: allow taking over a uid that is unused in the cluster

 src/Makefile                       |    1 +
 src/PVE/AbstractConfig.pm          |  196 ++++-
 src/PVE/GuestIdentity.pm           |  475 +++++++++++
 src/tests/Makefile                 |   10 +-
 src/tests/config-identity-tests.pl | 1173 ++++++++++++++++++++++++++++
 src/tests/guest-identity-tests.pl  |  530 +++++++++++++
 6 files changed, 2378 insertions(+), 7 deletions(-)
 create mode 100644 src/PVE/GuestIdentity.pm
 create mode 100755 src/tests/config-identity-tests.pl
 create mode 100755 src/tests/guest-identity-tests.pl


qemu-server:

Thomas Lamprecht (7):
  api: restore: release the VMID if a restore to an unused VMID fails
  api: migrate, clone: refuse targets that would drop the guest identity
  fix #7846: config: add a guest identity to the 'meta' property
  restore: take over the guest uid from the backup where possible
  api: remote migration: take over the guest uid from the source
  api: status: return the guest uid
  tests: remote migration: check a failed command and an early tunnel end

 src/PVE/API2/Qemu.pm                          | 120 ++-
 src/PVE/CLI/qm.pm                             |   7 +
 src/PVE/CLI/qmrestore.pm                      |  11 +-
 src/PVE/QemuConfig.pm                         |   7 +
 src/PVE/QemuMigrate.pm                        |  38 +-
 src/PVE/QemuServer.pm                         | 107 +-
 src/PVE/QemuServer/MetaInfo.pm                |   2 +
 src/test/Makefile                             |   5 +-
 src/test/QemuServerTest/FakeCFS.pm            | 188 ++++
 .../q35-windows-pinning-identity-only.conf    |   6 +
 ...q35-windows-pinning-identity-only.conf.cmd |  26 +
 .../meta-identity-invalid.conf                |   6 +
 .../meta-identity-invalid.conf.strict.error   |   2 +
 .../meta-identity-invalid.conf                |   7 +
 .../parse-config-input/meta-identity.conf     |  20 +
 src/test/restore-config-expected/150.conf     |   9 +
 src/test/restore-config-input/150.conf        |  10 +
 src/test/run_api_tests.pl                     | 190 ++++
 src/test/run_guest_identity_tests.pl          | 752 ++++++++++++++
 src/test/run_parse_config_tests.pl            |   2 +-
 src/test/run_qemu_restore_config_tests.pl     | 915 +++++++++++++++++-
 .../create/qemu-server/401.conf               |  31 +
 .../create/qemu-server/402.conf               |  31 +
 .../rollback/qemu-server/401.conf             |  36 +
 .../rollback/qemu-server/402.conf             |  35 +
 .../create/qemu-server/401.conf               |  13 +
 .../create/qemu-server/402.conf               |  13 +
 .../rollback/qemu-server/401.conf             |  35 +
 .../rollback/qemu-server/402.conf             |  34 +
 src/test/snapshot-test.pm                     |  82 +-
 30 files changed, 2674 insertions(+), 66 deletions(-)
 create mode 100644 src/test/QemuServerTest/FakeCFS.pm
 create mode 100644 src/test/cfg2cmd/q35-windows-pinning-identity-only.conf
 create mode 100644 src/test/cfg2cmd/q35-windows-pinning-identity-only.conf.cmd
 create mode 100644 src/test/parse-config-expected/meta-identity-invalid.conf
 create mode 100644 src/test/parse-config-expected/meta-identity-invalid.conf.strict.error
 create mode 100644 src/test/parse-config-input/meta-identity-invalid.conf
 create mode 100644 src/test/parse-config-input/meta-identity.conf
 create mode 100644 src/test/restore-config-expected/150.conf
 create mode 100644 src/test/restore-config-input/150.conf
 create mode 100755 src/test/run_guest_identity_tests.pl
 create mode 100644 src/test/snapshot-expected/create/qemu-server/401.conf
 create mode 100644 src/test/snapshot-expected/create/qemu-server/402.conf
 create mode 100644 src/test/snapshot-expected/rollback/qemu-server/401.conf
 create mode 100644 src/test/snapshot-expected/rollback/qemu-server/402.conf
 create mode 100644 src/test/snapshot-input/create/qemu-server/401.conf
 create mode 100644 src/test/snapshot-input/create/qemu-server/402.conf
 create mode 100644 src/test/snapshot-input/rollback/qemu-server/401.conf
 create mode 100644 src/test/snapshot-input/rollback/qemu-server/402.conf


container:

Thomas Lamprecht (8):
  config: add read-only meta property with the creation time
  fix #7846: config: add a guest identity to the 'meta' property
  api: migrate, clone: refuse targets that would drop the guest identity
  restore: take over the guest uid from the backup where possible
  restore: refuse overwriting a container with another guest's backup
  test: remote migration: check the cleanup of the target after failures
  api: remote migration: take over the guest uid from the source
  api: status: return the guest uid

 src/PVE/API2/LXC.pm         |  177 ++-
 src/PVE/API2/LXC/Config.pm  |   29 +-
 src/PVE/API2/LXC/Status.pm  |    6 +
 src/PVE/CLI/pct.pm          |    7 +
 src/PVE/LXC/Config.pm       |   50 +-
 src/PVE/LXC/Migrate.pm      |   31 +-
 src/test/Makefile           |    8 +-
 src/test/config_tests.pl    |   23 +
 src/test/lifecycle_tests.pl | 2092 +++++++++++++++++++++++++++++++++++
 9 files changed, 2388 insertions(+), 35 deletions(-)
 create mode 100755 src/test/lifecycle_tests.pl


manager:

Thomas Lamprecht (6):
  api: cluster resources: add guest uid and registration time
  api: cluster status: add cluster ID
  ui: restore: allow overwriting a guest with a backup of another guest
  ui: migrate: refuse target nodes that would drop the guest identity
  ui: guest summary: show the guest identity
  api: migrate all: refuse targets that would drop the guest identity

 PVE/API2/Cluster.pm                      |  24 ++-
 PVE/API2/Nodes.pm                        |   3 +
 test/ClusterResources_test.pl            | 249 +++++++++++++++++++++++
 test/ClusterStatus_test.pl               | 114 +++++++++++
 test/Makefile                            |  10 +-
 www/manager6/Makefile                    |   1 +
 www/manager6/panel/GuestIdentity.js      | 142 +++++++++++++
 www/manager6/panel/GuestStatusView.js    |   3 +
 www/manager6/panel/TemplateStatusView.js |   3 +
 www/manager6/window/Migrate.js           |  29 +++
 www/manager6/window/Restore.js           |  18 ++
 11 files changed, 594 insertions(+), 2 deletions(-)
 create mode 100755 test/ClusterResources_test.pl
 create mode 100755 test/ClusterStatus_test.pl
 create mode 100644 www/manager6/panel/GuestIdentity.js


docs:

Thomas Lamprecht (4):
  vzdump: describe the guest identity of VMs and containers
  pvecm: document the cluster ID and how to get a new one
  qm: configuration: describe the read-only meta property
  pct: configuration: describe the read-only meta property

 pct.adoc    |  35 ++++++
 pmxcfs.adoc |   1 +
 pvecm.adoc  |  86 ++++++++++++++
 qm.adoc     |  38 +++++++
 vzdump.adoc | 315 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 475 insertions(+)


Summary over all repositories:
  81 files changed, 9922 insertions(+), 122 deletions(-)

-- 
2.47.3





^ permalink raw reply	[relevance 18%]

* Re: [PATCH cluster/guest-common/qemu-server/container/manager/docs 00/34] fix #7846: guest identity (uid) and cluster ID
  2026-11-16  0:46 19% [PATCH cluster/guest-common/qemu-server/container/manager/docs 00/34] fix #7846: guest identity (uid) and cluster ID Thomas Lamprecht
                   ` (2 preceding siblings ...)
  2026-11-17 10:47 15% ` [PATCH cluster/guest-common/qemu-server/container/manager/docs 00/34] fix #7846: guest identity (uid) and cluster ID Dominik Csapak
@ 2026-11-17 15:55 13% ` Dominik Csapak
  3 siblings, 0 replies; 32+ results
From: Dominik Csapak @ 2026-11-17 15:55 UTC (permalink / raw)
  To: Thomas Lamprecht, pve-devel

looked over the rest of the patches and did notice too
problematic (see details on the individual patches though).

maybe the auto new uid on remote-migration is worth
thinking about.

couldn't test it for now since most do not apply anymore,
but will try tomorrow to fix the conficts if you
don't send another version by then




^ permalink raw reply	[relevance 13%]

* Re: [PATCH cluster/guest-common/qemu-server/container/manager/docs 00/34] fix #7846: guest identity (uid) and cluster ID
  2026-11-17 12:47 13%       ` Thomas Lamprecht
@ 2026-11-17 13:54 14%         ` Dominik Csapak
  0 siblings, 0 replies; 32+ results
From: Dominik Csapak @ 2026-11-17 13:54 UTC (permalink / raw)
  To: Thomas Lamprecht, pve-devel

Please don't take this the wrong way, i don't want
to bikeshed, just lay out my reasoning.

tl;dr there is nothing wrong with the current approach
from my POV, but I'd have chosen different formats/sizes.

On 11/17/26 1:47 PM, Thomas Lamprecht wrote:
> Am 17.11.26 um 12:55 schrieb Dominik Csapak:
>> On 11/17/26 12:29 PM, Thomas Lamprecht wrote:
>>> Am 17.11.26 um 11:47 schrieb Dominik Csapak:
>>> I had it at 80 bits, but that is borderline w.r.t. hundreds of billions
>>> of entities and the birthday problem, as we're getting near actual digit
>>> percentages then (1 % chance of a clash at ~150 billion IDs). 100 bits
>>> takes that boundary between practically impossible and a real chance of
>>> clash in the hundreds of trillion range (1 % at ~160 trillion), which
>>> seemed good enough for me.
>>
>> but this is about the cluster id, surely there aren't billions of
>> clusters/nodes ?
> 
> I want to use the same for clusters and guests, what benefit do I
> have in doing that differently?

nothing, that's not what i argued. What i meant is that having such
a custom format with "weird" sizes makes the code less maintainable
in my opinion. e.g. using some preexisting library
for generating a uuid here would have saved quite a bit of code
without (again, in my opinion) any practical downside.

The perl code generates the uid on its own (with "duplicated" code).
They're having the same format yes, but that's just a regex line.
Or did i miss something and we reuse the cluster id for the vm uids ?

I'm not again the base32 + some amount of randomness,
just that the sizes chosen here seemed weird to me and at least
warrant some rationale, which you gave. (That I would have chosen
different things shouldn't be interpreted as a blocker,
just giving my opinion)

> 
>> They also don't have to be globally unique in practice, just for one
>> provider/customer/etc.
> 
> They do, else reality catches up with you fast, companies get bought
> and their infra merged, cluster can move from providers (e.g., ceph
> moved their whole CI infra from a RH datacenter to an IBM one with
> some big trucks about a year ago), PDM can connect all of them. Really
> not sure what you're trying to recommend here? Why make these edge
> cases harder for anyone that has the bad luck handling them, what's
> the benefit.

I just argued that e.g. 80 bit would have been enough here, to get a
"round" 10 bytes of randomness, nothing more.
(it still would allow billions of clusters with a chance of < 1% of
collisions)

> 
>>>> since we then don't have to use half a byte (100bit => 12.5 byte)
>>>> and still provide enough randomness.
>>>
>>> Base32 has 5 bit per character, so 100 bits are always 20 chars without
>>> padding, that I found nice.
>>
>> yes i meant the 'raw size' and basically always discarding half a byte
>> of randomness, but sure.
> 
> What does that matter? 80 bit also doesn't align in word size of 64-bit,
> could be also relevant. How many bits are relevant for entropy, that
> needs a lower boundary and some upper bounder for practical purposes and
> leveraging the chosen serialization of it.
> 
> Sure, we can discuss all day about some in a framework of core rules
> somewhat arbitrary chosen specifics of our bikeshed color but if there
> is not actually a relevant problem (e.g., to continue the methaphor
> sun gets reflected and blinds one, or absorbed and heats the shed up)
> I rather keep them, I played around with a few different formats and
> bit sizes and this here felt best while still fulfilling the core
> properties needed for us. base32 is IMO a great tradeof here between
> ease of handling the character set and packing bits in single chars,
> the non-uuid format ensures this is not ever used (or its generation
> transformed to) something it shouldn't be.

Again, I'm not again this format, but I'm not sure that's true?
This not being uuid does not stop anyone from using this in a way
not intended by us? If you didn't mean that, disregard this...

> I value your skepticism but here I'd rather avoid us derailing into
> this to much, as while yes some properties are chosen by me in a way
> that might seem arbitrary and might bee done slightly different too
> while still fulfilling the core design-framework needs here, just
> switching to another flavor for the sake of it doesn't really help us
> much either – and IMO a random nonce being really just that and not
> looking like something else has its merits.
> 
> Adding some more rationale to docs and commit message is certainly
> warranted, this will be questioned by others, so from that POV I'm
> happy it happens upfront from you.>

I agree that the exact format is not that important, so current
is fine by me.

>>> That then allows one to tell apart e.g.:
>>> - Same uid, changed rtime: the guest was registered again, for example
>>>     destroyed and restored, or moved in from another cluster. A tool can
>>>     then tell this from an "untouched" guest.
>>
>> but this could also be detectable via ctime (except if we don't want
>> to touch that on restore/migration ofc)
> 
> With "ctime will always be kept as is for a restore to a new VMID" I
> meant that a ctime won't be touched and can't be used for this. Changing
> this would also divert from a fixed behavior, i.e. technically a
> breaking change. And yes, I do not believe in just technicalities
> guiding design and allowing some technical breakage if it's not gonna
> cause issues in practice and has some good justification (ROI), here the
> ROI of such a change is IMO questionable, and as said, rather than
> optimizing to much here I rather have this as complete as it might make
> practical sense
> 
>>
>>> - Same uid in two clusters, which can happen after a remote migration
>>>     that keeps the source, or a restore elsewhere. The uid together with
>>>     the cluster ID and rtime still tells the instances apart.
>>
>> for this the rtime is not needed though? uid + clusterid should
>> be enough? (since same uid in one cluster can't happen)
>>
> 
> I was a bit imprecise here, for a single point in time yes that's true, but
> backups normally have a history over a longer period of time and there
> this ensures one can tell them apart (also potentially in logs or so,
> but how/if we use them there is not all too relevant for now IMO, that
> can be checked out later, we're not getting worse there in that regard as
> the status quo now is after all). I.e., this is to differentiate between
> the same guest and cluster uid over time, which is not that far out for us
> due to remote migrations.

makes sense

> 
> 
>>> FWIW, my format allows to still map all uids into standard uuidv8,
>>> so we're not locked in, but I do not want to use them and their
>>> various versions here, simple random nonce that is formatted such
>>> to be easy to handle (just alphanumerical) and still reasonably short.
>>> That's my core requirement here. I.e., yes uuid might be wide spread,
>>> but there to many tried to hard to add additional meaning to what should
>>> be just a simple random nonce like this use case here.
>>
>> makes sense, though i think having 20 vs 36 bytes in a config
>> that is already ~500 bytes by default wouldn't make much difference IMO.
>> (also we already have at least 2 uuids in the default config, so
>> there would be precedent to using that format)
> 
> The uuid were not chosen by us and their (change) meaning is completely
> different, so I do not see how we should go down that road just because
> they got brought uppon us. Again, uid's are random nonces, the format
> reflects that and is roughly optimized for its use case. no uuid.
> We might look into deriving the smbios one from the uid by default
> in the future though, still allowing manual overriding it as that should
> be easily doable just needs a closer check if any change there when
> uid changes causes actual issues, that would allow to avoid ~45 chars
> by default. Similar we could also default the *initial* vmgenid to be
> derived from that and only persist it once actually needed, dropping
> like 92 bytes from our default config again, would make more than up
> for the ones added here (and no uuid by default in the config anymore).

yes that sounds like a good plan, even though it could have been
achieved with having a fixed uuid too (and in hindsight, i probably
could have reused the smbios uuid for the initial vmgenid )

> 
>> we could also already opt to use a custom uuid format with the
>> rtime encoded instead of having a separate property, but
>> that is probably more pain that having it separate...
> 
> That would always mean uid changes if rtime changes, which breaks the
> whole design.

depends what part we would have compared, in a uid comparison
we would have to ignore the timestamp part of course,
but as i wrote having that is more pain than having it separated.

> 
>>> It's only needed when a guest takes over an existing uid, so once at
>>> the end of a restore or of an incoming remote migration. Without it,
>>> restoring the same backup to two VMIDs, or to a new VMID while the
>>> original still exists, would give two guests with the same uid in one
>>> cluster. Newly generated uids (create, clone, first write of an
>>> existing guest after the upgrade) take no cluster lock and do no
>>> lookup, the randomness is enough there.
>>
>> it's also necessary on clone and creation though? otherwise we can't
>> be sure the random value is not in use? (unlikely but still)
>>
>> if you argue about billions of clusters/nodes for 100bit randomness,
>> then i think arguing with a much higher number of vms is fair?
> 
> No, I argue that this is safe for guests and the uses cases and reuse
> the same for cluster as they get used as tripple for determining the
> whole underlying reason of doing this all in the first place. Mixing
> those then has no benefit here, on the contrary IMO.





^ permalink raw reply	[relevance 14%]

* Re: [PATCH cluster/guest-common/qemu-server/container/manager/docs 00/34] fix #7846: guest identity (uid) and cluster ID
  2026-11-17 11:55 15%     ` Dominik Csapak
@ 2026-11-17 12:47 13%       ` Thomas Lamprecht
  2026-11-17 13:54 14%         ` Dominik Csapak
  0 siblings, 1 reply; 32+ results
From: Thomas Lamprecht @ 2026-11-17 12:47 UTC (permalink / raw)
  To: Dominik Csapak, pve-devel

Am 17.11.26 um 12:55 schrieb Dominik Csapak:
> On 11/17/26 12:29 PM, Thomas Lamprecht wrote:
>> Am 17.11.26 um 11:47 schrieb Dominik Csapak:
>> I had it at 80 bits, but that is borderline w.r.t. hundreds of billions
>> of entities and the birthday problem, as we're getting near actual digit
>> percentages then (1 % chance of a clash at ~150 billion IDs). 100 bits
>> takes that boundary between practically impossible and a real chance of
>> clash in the hundreds of trillion range (1 % at ~160 trillion), which
>> seemed good enough for me.
> 
> but this is about the cluster id, surely there aren't billions of
> clusters/nodes ?

I want to use the same for clusters and guests, what benefit do I
have in doing that differently? 

> They also don't have to be globally unique in practice, just for one
> provider/customer/etc.

They do, else reality catches up with you fast, companies get bought
and their infra merged, cluster can move from providers (e.g., ceph
moved their whole CI infra from a RH datacenter to an IBM one with
some big trucks about a year ago), PDM can connect all of them. Really
not sure what you're trying to recommend here? Why make these edge
cases harder for anyone that has the bad luck handling them, what's
the benefit.

>>> since we then don't have to use half a byte (100bit => 12.5 byte)
>>> and still provide enough randomness.
>>
>> Base32 has 5 bit per character, so 100 bits are always 20 chars without
>> padding, that I found nice.
> 
> yes i meant the 'raw size' and basically always discarding half a byte
> of randomness, but sure.

What does that matter? 80 bit also doesn't align in word size of 64-bit,
could be also relevant. How many bits are relevant for entropy, that
needs a lower boundary and some upper bounder for practical purposes and
leveraging the chosen serialization of it.

Sure, we can discuss all day about some in a framework of core rules
somewhat arbitrary chosen specifics of our bikeshed color but if there
is not actually a relevant problem (e.g., to continue the methaphor
sun gets reflected and blinds one, or absorbed and heats the shed up)
I rather keep them, I played around with a few different formats and
bit sizes and this here felt best while still fulfilling the core
properties needed for us. base32 is IMO a great tradeof here between
ease of handling the character set and packing bits in single chars,
the non-uuid format ensures this is not ever used (or its generation
transformed to) something it shouldn't be.
I value your skepticism but here I'd rather avoid us derailing into
this to much, as while yes some properties are chosen by me in a way
that might seem arbitrary and might bee done slightly different too
while still fulfilling the core design-framework needs here, just
switching to another flavor for the sake of it doesn't really help us
much either – and IMO a random nonce being really just that and not
looking like something else has its merits.

Adding some more rationale to docs and commit message is certainly
warranted, this will be questioned by others, so from that POV I'm
happy it happens upfront from you.

>> That then allows one to tell apart e.g.:
>> - Same uid, changed rtime: the guest was registered again, for example
>>    destroyed and restored, or moved in from another cluster. A tool can
>>    then tell this from an "untouched" guest.
> 
> but this could also be detectable via ctime (except if we don't want
> to touch that on restore/migration ofc)

With "ctime will always be kept as is for a restore to a new VMID" I
meant that a ctime won't be touched and can't be used for this. Changing
this would also divert from a fixed behavior, i.e. technically a
breaking change. And yes, I do not believe in just technicalities
guiding design and allowing some technical breakage if it's not gonna
cause issues in practice and has some good justification (ROI), here the
ROI of such a change is IMO questionable, and as said, rather than
optimizing to much here I rather have this as complete as it might make
practical sense

> 
>> - Same uid in two clusters, which can happen after a remote migration
>>    that keeps the source, or a restore elsewhere. The uid together with
>>    the cluster ID and rtime still tells the instances apart.
> 
> for this the rtime is not needed though? uid + clusterid should
> be enough? (since same uid in one cluster can't happen)
> 

I was a bit imprecise here, for a single point in time yes that's true, but
backups normally have a history over a longer period of time and there
this ensures one can tell them apart (also potentially in logs or so,
but how/if we use them there is not all too relevant for now IMO, that
can be checked out later, we're not getting worse there in that regard as
the status quo now is after all). I.e., this is to differentiate between
the same guest and cluster uid over time, which is not that far out for us
due to remote migrations.


>> FWIW, my format allows to still map all uids into standard uuidv8,
>> so we're not locked in, but I do not want to use them and their
>> various versions here, simple random nonce that is formatted such
>> to be easy to handle (just alphanumerical) and still reasonably short.
>> That's my core requirement here. I.e., yes uuid might be wide spread,
>> but there to many tried to hard to add additional meaning to what should
>> be just a simple random nonce like this use case here.
> 
> makes sense, though i think having 20 vs 36 bytes in a config
> that is already ~500 bytes by default wouldn't make much difference IMO.
> (also we already have at least 2 uuids in the default config, so
> there would be precedent to using that format)

The uuid were not chosen by us and their (change) meaning is completely
different, so I do not see how we should go down that road just because
they got brought uppon us. Again, uid's are random nonces, the format
reflects that and is roughly optimized for its use case. no uuid.
We might look into deriving the smbios one from the uid by default
in the future though, still allowing manual overriding it as that should
be easily doable just needs a closer check if any change there when
uid changes causes actual issues, that would allow to avoid ~45 chars
by default. Similar we could also default the *initial* vmgenid to be
derived from that and only persist it once actually needed, dropping
like 92 bytes from our default config again, would make more than up
for the ones added here (and no uuid by default in the config anymore).

> we could also already opt to use a custom uuid format with the
> rtime encoded instead of having a separate property, but
> that is probably more pain that having it separate...

That would always mean uid changes if rtime changes, which breaks the
whole design.

>> It's only needed when a guest takes over an existing uid, so once at
>> the end of a restore or of an incoming remote migration. Without it,
>> restoring the same backup to two VMIDs, or to a new VMID while the
>> original still exists, would give two guests with the same uid in one
>> cluster. Newly generated uids (create, clone, first write of an
>> existing guest after the upgrade) take no cluster lock and do no
>> lookup, the randomness is enough there.
> 
> it's also necessary on clone and creation though? otherwise we can't
> be sure the random value is not in use? (unlikely but still)
> 
> if you argue about billions of clusters/nodes for 100bit randomness,
> then i think arguing with a much higher number of vms is fair?

No, I argue that this is safe for guests and the uses cases and reuse
the same for cluster as they get used as tripple for determining the
whole underlying reason of doing this all in the first place. Mixing
those then has no benefit here, on the contrary IMO.




^ permalink raw reply	[relevance 13%]

* Re: [PATCH cluster/guest-common/qemu-server/container/manager/docs 00/34] fix #7846: guest identity (uid) and cluster ID
  2026-11-17 11:29 16%   ` Thomas Lamprecht
@ 2026-11-17 11:55 15%     ` Dominik Csapak
  2026-11-17 12:47 13%       ` Thomas Lamprecht
  0 siblings, 1 reply; 32+ results
From: Dominik Csapak @ 2026-11-17 11:55 UTC (permalink / raw)
  To: Thomas Lamprecht, pve-devel



On 11/17/26 12:29 PM, Thomas Lamprecht wrote:
> Am 17.11.26 um 11:47 schrieb Dominik Csapak:
>> I started reviewing this series and wanted to give some early feedback on the
>> overall approach. More in depth code review see the individual patches (might
>> take a bit going through every patch)
> 
> thank you for taking a look, appreciated!
> 
>> Note that i might have overlooked something. If so, please
>> do tell me.
>>
>> My high level feedback:
>>
>> Cluster IDs:
>>
>> Is there a particular reason why 100bit + base32?
> 
> Yes, they are much shorter serialized (20 chars) and have enough entropy
> to make them more than good enough with head room while not getting
> larger than needed.
> 
>> I couldn't find a rationale for the choice (did i overlook it?)
> 
> No, v1 only states the format (module comment in PVE::GuestIdentity,
> commit messages, docs), not really the reasoning/rational behind it.
> I'll expand on that for a v2 (or on applying) and will add a few
> sentences to the cover letter too, as it certainly is something one can
> wonder about.
> 
>> and I think using something 'industry standard' like a
>> UUIDv7 would be a better choice? I'ts just 28 bit more (
>> with a bit less randomness) but with a time stamp included and this
>> should make each cluster uniquely identifiable too.
> 
> While I thought earlier about using snowflake or some other timestamp
> influenced uid, they are not ideal here as they do not relate to
> anything over the lifetime of a guest w.r.t. restores and such.
> 
>> If we want to stay on base32, maybe 80 or 120 bit is a better choice,
> 
> I had it at 80 bits, but that is borderline w.r.t. hundreds of billions
> of entities and the birthday problem, as we're getting near actual digit
> percentages then (1 % chance of a clash at ~150 billion IDs). 100 bits
> takes that boundary between practically impossible and a real chance of
> clash in the hundreds of trillion range (1 % at ~160 trillion), which
> seemed good enough for me.

but this is about the cluster id, surely there aren't billions of
clusters/nodes ? they also don't have to be globally unique
in practice, just for one provider/customer/etc.

> 
>> since we then don't have to use half a byte (100bit => 12.5 byte)
>> and still provide enough randomness.
> 
> Base32 has 5 bit per character, so 100 bits are always 20 chars without
> padding, that I found nice.

yes i meant the 'raw size' and basically always discarding half a byte
of randomness, but sure.

> 
>> VM UIDs:
>>
>> Same question about the rationale behind the format, but with one
>> change: the 'registering' time is already recorded in
>> the meta object (as ctime), no? so providing an additional separate
> 
> ctime is creation time, which is the first creation ever. Registration
> time is something else, it's the time the guest got its identity in this
> cluster.
> 
> E.g. ctime will always be kept as is for a restore to a new VMID. The
> uid changes if unique is set or if another guest in the cluster
> already has it (e.g. the original still exists), but otherwise stays
> the same. The registration time is regenerated in any case – making
> the combination of rtime and uid (and cluster ID) unique in practice.
> This comes from the model that backup providers use and even if a bit
> odd at first it works well for all cases (if this series here
> implements it right that is...).
> 
> That then allows one to tell apart e.g.:
> - Same uid, changed rtime: the guest was registered again, for example
>    destroyed and restored, or moved in from another cluster. A tool can
>    then tell this from an "untouched" guest.

but this could also be detectable via ctime (except if we don't want
to touch that on restore/migration ofc)

> - Same uid in two clusters, which can happen after a remote migration
>    that keeps the source, or a restore elsewhere. The uid together with
>    the cluster ID and rtime still tells the instances apart.

for this the rtime is not needed though? uid + clusterid should
be enough? (since same uid in one cluster can't happen)

> 
> I tried hard to do all that's needed to cover all bases but only really
> that what's needed here. Ideally we do not touch this ever again from
> a principles POV (knocks wood).
> 

but fair, having a separate rtime can make sense i guess. and with
that having a time encoded in the 'uuid' makes less sense, got it.

>> timestamp seems weird to me. Also using UUIDv7 here
>> would include a timestamp too and also be more 'industry standard'
>> while only using 1 byte extra (36 vs 20 + 15). Though
> no v7 for these things for the same reason, it's rather confusing
> then. The timestamp of a v7 is fixed when the ID gets generated, while
> here the uid must stay the same over restores and remote migrations
> and the registration time must change then, so the two cannot be one
> value. uid *must* be random, that's a core property and ensures it's
> never taken for anything that it really isn't.
> 
> FWIW, my format allows to still map all uids into standard uuidv8,
> so we're not locked in, but I do not want to use them and their
> various versions here, simple random nonce that is formatted such
> to be easy to handle (just alphanumerical) and still reasonably short.
> That's my core requirement here. I.e., yes uuid might be wide spread,
> but there to many tried to hard to add additional meaning to what should
> be just a simple random nonce like this use case here.

makes sense, though i think having 20 vs 36 bytes in a config
that is already ~500 bytes by default wouldn't make much difference IMO.
(also we already have at least 2 uuids in the default config, so
there would be precedent to using that format)

we could also already opt to use a custom uuid format with the
rtime encoded instead of having a separate property, but
that is probably more pain that having it separate...

> 
>> we probably would save some space by not having two properties in
>> the meta object.
> 
> see above, required.
> 
>> UID adoption/checks:
>>
>> The cluster wide check is necessary, i get it. Handling
> 
> It's only needed when a guest takes over an existing uid, so once at
> the end of a restore or of an incoming remote migration. Without it,
> restoring the same backup to two VMIDs, or to a new VMID while the
> original still exists, would give two guests with the same uid in one
> cluster. Newly generated uids (create, clone, first write of an
> existing guest after the upgrade) take no cluster lock and do no
> lookup, the randomness is enough there.

it's also necessary on clone and creation though? otherwise we can't
be sure the random value is not in use? (unlikely but still)

if you argue about billions of clusters/nodes for 100bit randomness,
then i think arguing with a much higher number of vms is fair?

> 
>> it with a cluster lock + reading the cofnig
>> could make that lookup a bottleneck in big and dynamic clusters?
>> Or did i misunderstood how we get the meta config out?
> 
> The lookup does not read config files one by one, it's a single IPC
> call to pmxcfs that collects the 'meta' property from its in-memory
> configs, i.e. the same call /cluster/resources already does on every
> request for lock and tags. The lock is held for that call plus one
> config write. So I don't expect this to become a bottleneck, and once
> we have pmxcfs in rust with types for such guest configs we can do
> this there on a nice abstraction level while still being really fast.

ok sorry must have missed that or not yet read

> 
>> Alternatively we could have that lookup in pmxcfs itself and
>> replicate it like rrd, etc.? having a uuid saved as
>> a 128bit number (16byte) would mean
> 
> no, this must IMO not be a sidecar or saved out of band, coupling it
> directly to the guest config, the core entity that makes out a guest,
> is IMO crucial to get a safe design. The lookup already happens in
> pmxcfs as described above, just without a second copy of the data
> that could get out of sync with the configs.
> 
>> 160k for 10000 guests
>> 16M for 1000000 guests
>>
>> which looks reasonable to me?
>> (we already have to have much more data in pmxcfs
>> with that many guests...)
> 
> Probably not needed, but we can optimize the basic approach here if
> needed (special IPC call for check+lock), but that's basically an
> implementation detail that won't change the overall design IMO.

if the overall reading isn't happening in perl i don't think
we need anything specialized...





^ permalink raw reply	[relevance 15%]

* Re: [PATCH cluster/guest-common/qemu-server/container/manager/docs 00/34] fix #7846: guest identity (uid) and cluster ID
  2026-11-17 10:47 15% ` [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 16%   ` Thomas Lamprecht
  2026-11-17 11:55 15%     ` Dominik Csapak
  0 siblings, 1 reply; 32+ results
From: Thomas Lamprecht @ 2026-11-17 11:29 UTC (permalink / raw)
  To: Dominik Csapak, pve-devel

Am 17.11.26 um 11:47 schrieb Dominik Csapak:
> I started reviewing this series and wanted to give some early feedback on the
> overall approach. More in depth code review see the individual patches (might
> take a bit going through every patch)

thank you for taking a look, appreciated!

> Note that i might have overlooked something. If so, please
> do tell me.
>
> My high level feedback:
>
> Cluster IDs:
>
> Is there a particular reason why 100bit + base32?

Yes, they are much shorter serialized (20 chars) and have enough entropy
to make them more than good enough with head room while not getting
larger than needed.

> I couldn't find a rationale for the choice (did i overlook it?)

No, v1 only states the format (module comment in PVE::GuestIdentity,
commit messages, docs), not really the reasoning/rational behind it.
I'll expand on that for a v2 (or on applying) and will add a few
sentences to the cover letter too, as it certainly is something one can
wonder about.

> and I think using something 'industry standard' like a
> UUIDv7 would be a better choice? I'ts just 28 bit more (
> with a bit less randomness) but with a time stamp included and this
> should make each cluster uniquely identifiable too.

While I thought earlier about using snowflake or some other timestamp
influenced uid, they are not ideal here as they do not relate to
anything over the lifetime of a guest w.r.t. restores and such.

> If we want to stay on base32, maybe 80 or 120 bit is a better choice,

I had it at 80 bits, but that is borderline w.r.t. hundreds of billions
of entities and the birthday problem, as we're getting near actual digit
percentages then (1 % chance of a clash at ~150 billion IDs). 100 bits
takes that boundary between practically impossible and a real chance of
clash in the hundreds of trillion range (1 % at ~160 trillion), which
seemed good enough for me.

> since we then don't have to use half a byte (100bit => 12.5 byte)
> and still provide enough randomness.

Base32 has 5 bit per character, so 100 bits are always 20 chars without
padding, that I found nice.

> VM UIDs:
>
> Same question about the rationale behind the format, but with one
> change: the 'registering' time is already recorded in
> the meta object (as ctime), no? so providing an additional separate

ctime is creation time, which is the first creation ever. Registration
time is something else, it's the time the guest got its identity in this
cluster.

E.g. ctime will always be kept as is for a restore to a new VMID. The
uid changes if unique is set or if another guest in the cluster
already has it (e.g. the original still exists), but otherwise stays
the same. The registration time is regenerated in any case – making
the combination of rtime and uid (and cluster ID) unique in practice.
This comes from the model that backup providers use and even if a bit
odd at first it works well for all cases (if this series here
implements it right that is...).

That then allows one to tell apart e.g.:
- Same uid, changed rtime: the guest was registered again, for example
  destroyed and restored, or moved in from another cluster. A tool can
  then tell this from an "untouched" guest.
- Same uid in two clusters, which can happen after a remote migration
  that keeps the source, or a restore elsewhere. The uid together with
  the cluster ID and rtime still tells the instances apart.

I tried hard to do all that's needed to cover all bases but only really
that what's needed here. Ideally we do not touch this ever again from
a principles POV (knocks wood).

> timestamp seems weird to me. Also using UUIDv7 here
> would include a timestamp too and also be more 'industry standard'
> while only using 1 byte extra (36 vs 20 + 15). Though
no v7 for these things for the same reason, it's rather confusing
then. The timestamp of a v7 is fixed when the ID gets generated, while
here the uid must stay the same over restores and remote migrations
and the registration time must change then, so the two cannot be one
value. uid *must* be random, that's a core property and ensures it's
never taken for anything that it really isn't.

FWIW, my format allows to still map all uids into standard uuidv8,
so we're not locked in, but I do not want to use them and their
various versions here, simple random nonce that is formatted such
to be easy to handle (just alphanumerical) and still reasonably short.
That's my core requirement here. I.e., yes uuid might be wide spread,
but there to many tried to hard to add additional meaning to what should
be just a simple random nonce like this use case here.

> we probably would save some space by not having two properties in
> the meta object.

see above, required.

> UID adoption/checks:
>
> The cluster wide check is necessary, i get it. Handling

It's only needed when a guest takes over an existing uid, so once at
the end of a restore or of an incoming remote migration. Without it,
restoring the same backup to two VMIDs, or to a new VMID while the
original still exists, would give two guests with the same uid in one
cluster. Newly generated uids (create, clone, first write of an
existing guest after the upgrade) take no cluster lock and do no
lookup, the randomness is enough there.

> it with a cluster lock + reading the cofnig
> could make that lookup a bottleneck in big and dynamic clusters?
> Or did i misunderstood how we get the meta config out?

The lookup does not read config files one by one, it's a single IPC
call to pmxcfs that collects the 'meta' property from its in-memory
configs, i.e. the same call /cluster/resources already does on every
request for lock and tags. The lock is held for that call plus one
config write. So I don't expect this to become a bottleneck, and once
we have pmxcfs in rust with types for such guest configs we can do
this there on a nice abstraction level while still being really fast.

> Alternatively we could have that lookup in pmxcfs itself and
> replicate it like rrd, etc.? having a uuid saved as
> a 128bit number (16byte) would mean

no, this must IMO not be a sidecar or saved out of band, coupling it
directly to the guest config, the core entity that makes out a guest,
is IMO crucial to get a safe design. The lookup already happens in
pmxcfs as described above, just without a second copy of the data
that could get out of sync with the configs.

> 160k for 10000 guests
> 16M for 1000000 guests
>
> which looks reasonable to me?
> (we already have to have much more data in pmxcfs
> with that many guests...)

Probably not needed, but we can optimize the basic approach here if
needed (special IPC call for check+lock), but that's basically an
implementation detail that won't change the overall design IMO.




^ permalink raw reply	[relevance 16%]

* Re: [PATCH cluster/guest-common/qemu-server/container/manager/docs 00/34] fix #7846: guest identity (uid) and cluster ID
  2026-11-16  0:46 19% [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 15% ` [PATCH qemu-server 14/34] fix #7846: config: add a guest identity to the 'meta' property Thomas Lamprecht
  2026-11-16  0:46 15% ` [PATCH docs 31/34] vzdump: describe the guest identity of VMs and containers Thomas Lamprecht
@ 2026-11-17 10:47 15% ` Dominik Csapak
  2026-11-17 11:29 16%   ` Thomas Lamprecht
  2026-11-17 15:55 13% ` Dominik Csapak
  3 siblings, 1 reply; 32+ results
From: Dominik Csapak @ 2026-11-17 10:47 UTC (permalink / raw)
  To: Thomas Lamprecht, pve-devel

I started reviewing this series and wanted to give some early feedback 
on the overall approach. More in depth code review see the individual
patches (might take a bit going through every patch)

Note that i might have overlooked something. If so, please
do tell me.

My high level feedback:

Cluster IDs:

Is there a particular reason why 100bit + base32?
I couldn't find a rationale for the choice (did i overlook it?)
and I think using something 'industry standard' like a
UUIDv7 would be a better choice? I'ts just 28 bit more (
with a bit less randomness) but with a time stamp included and this
should make each cluster uniquely identifiable too.

If we want to stay on base32, maybe 80 or 120 bit is a better choice,
since we then don't have to use half a byte (100bit => 12.5 byte)
and still provide enough randomness.

VM UIDs:

Same question about the rationale behind the format, but with one
change: the 'registering' time is already recorded in
the meta object (as ctime), no? so providing an additional separate
timestamp seems weird to me. Also using UUIDv7 here
would include a timestamp too and also be more 'industry standard'
while only using 1 byte extra (36 vs 20 + 15). Though
we probably would save some space by not having two properties in
the meta object.

UID adoption/checks:

The cluster wide check is necessary, i get it. Handling
it with a cluster lock + reading the cofnig
could make that lookup a bottleneck in big and dynamic clusters?
Or did i misunderstood how we get the meta config out?

Alternatively we could have that lookup in pmxcfs itself and
replicate it like rrd, etc.? having a uuid saved as
a 128bit number (16byte) would mean

160k for 10000 guests
16M for 1000000 guests

which looks reasonable to me?
(we already have to have much more data in pmxcfs
with that many guests...)


Let me know what you think


On 11/16/26 1:48 AM, Thomas Lamprecht wrote:
> A VMID can be reused for another guest, and a guest can get another
> VMID or move to another cluster through a restore or a remote
> migration. So backup software and other tools cannot tell whether they
> still look at the same guest, see [0].
> 
> This series gives every VM and container a guest identity in the
> read-only 'meta' property: a random uid (100 bits as 20 base32
> characters) and the time the guest was registered in the cluster. Create
> and clone get a new uid. Config changes, migration, rollback, backup and
> restore keep it, also under another VMID or in another cluster, as long
> as no other guest there has it. Each cluster or standalone node also
> gets a cluster ID in the same format, generated and protected by pmxcfs.
> The docs patches describe the details.
> 
> Two behavior changes come with it:
> 
> * Restoring over an existing guest whose uid differs from the one of
>    the backup is refused unless 'allow-identity-mismatch' is set. 'force'
>    alone does not override this.
> * Older versions drop the whole 'meta' property of a guest that has an
>    identity. So migration and clone to such nodes is refused, and remote
>    migration bumps the tunnel version. This also hits moves by the HA
>    stack, which stops a container or a relocated VM before the migration
>    gets refused. A target check in the LRM that avoids this will follow
>    separately.
> 
> The patches are in dependency order: guest-common needs a pve-cluster
> newer than 9.1.9, qemu-server and container need guest-common, and
> manager needs all of them. manager also has to depend on the
> qemu-server and container versions with this series, as the migration
> guard takes the pve-manager version of a node as proof that the node
> keeps the identity. MIN_PVE_MANAGER_VERSION in guest-common is a
> stand-in for that pve-manager version.
> 
> Tested with the test suites of the repositories and end to end on a
> nested three-node cluster that was upgraded node by node.
> 
> [0]: https://bugzilla.proxmox.com/show_bug.cgi?id=7846
> 
> cluster:
> 
> Thomas Lamprecht (7):
>    pmxcfs: reject changes to the cluster ID file from user space
>    pmxcfs: generate a cluster ID on standalone nodes
>    pmxcfs: dfsm: add a callback that runs once all members are in sync
>    pmxcfs: quorum: pass the corosync membership to an optional listener
>    pmxcfs: dcdb: generate the cluster ID once the cluster is in sync
>    cluster: add helper to read the cluster ID
>    pmxcfs: allow removing the cluster ID file in forced local mode
> 
>   src/PVE/Cluster.pm          |  16 ++
>   src/pmxcfs/Makefile         |  12 +-
>   src/pmxcfs/cfs-plug-memdb.c |  46 ++++
>   src/pmxcfs/cfs-utils.c      |   8 +
>   src/pmxcfs/cfs-utils.h      |   5 +
>   src/pmxcfs/check_dcdb.c     | 529 ++++++++++++++++++++++++++++++++++++
>   src/pmxcfs/check_memdb.c    | 311 +++++++++++++++++++++
>   src/pmxcfs/cluster-id.c     | 158 +++++++++++
>   src/pmxcfs/cluster-id.h     |  52 ++++
>   src/pmxcfs/dcdb.c           | 144 ++++++++++
>   src/pmxcfs/dcdb.h           |   5 +
>   src/pmxcfs/dfsm.c           |  58 ++++
>   src/pmxcfs/dfsm.h           |  14 +
>   src/pmxcfs/pmxcfs.c         |  10 +-
>   src/pmxcfs/quorum.c         |  26 +-
>   src/pmxcfs/quorum.h         |   8 +-
>   src/pmxcfs/status.c         |  12 +
>   src/pmxcfs/status.h         |   3 +
>   src/test/Makefile           |   6 +-
>   src/test/test_cluster_id.pl |  47 ++++
>   20 files changed, 1458 insertions(+), 12 deletions(-)
>   create mode 100644 src/pmxcfs/check_dcdb.c
>   create mode 100644 src/pmxcfs/cluster-id.c
>   create mode 100644 src/pmxcfs/cluster-id.h
>   create mode 100644 src/test/test_cluster_id.pl
> 
> 
> guest-common:
> 
> Thomas Lamprecht (4):
>    guest identity: add helpers for the guest uid and registration time
>    abstract config: assign a guest identity and keep it on config writes
>    abstract config: let the VMID reservation return the previous state
>    guest identity: allow taking over a uid that is unused in the cluster
> 
>   debian/control                     |    1 +
>   src/Makefile                       |    1 +
>   src/PVE/AbstractConfig.pm          |  235 +++++-
>   src/PVE/GuestIdentity.pm           |  384 ++++++++++
>   src/tests/Makefile                 |   10 +-
>   src/tests/config-identity-tests.pl | 1090 ++++++++++++++++++++++++++++
>   src/tests/guest-identity-tests.pl  |  421 +++++++++++
>   7 files changed, 2135 insertions(+), 7 deletions(-)
>   create mode 100644 src/PVE/GuestIdentity.pm
>   create mode 100755 src/tests/config-identity-tests.pl
>   create mode 100755 src/tests/guest-identity-tests.pl
> 
> 
> qemu-server:
> 
> Thomas Lamprecht (6):
>    api: restore: release the VMID if a restore to an unused VMID fails
>    api: migrate, clone: refuse targets that would drop the guest identity
>    fix #7846: config: add a guest identity to the 'meta' property
>    restore: take over the guest uid from the backup where possible
>    api: remote migration: take over the guest uid from the source
>    api: status: return the guest uid
> 
>   src/PVE/API2/Qemu.pm                          | 104 +-
>   src/PVE/CLI/qmrestore.pm                      |   7 +
>   src/PVE/QemuConfig.pm                         |   7 +
>   src/PVE/QemuMigrate.pm                        |   9 +-
>   src/PVE/QemuServer.pm                         | 150 ++-
>   src/PVE/QemuServer/MetaInfo.pm                |   2 +
>   src/test/Makefile                             |   5 +-
>   src/test/QemuServerTest/FakeCFS.pm            | 197 ++++
>   .../q35-windows-pinning-identity-only.conf    |   6 +
>   ...q35-windows-pinning-identity-only.conf.cmd |  26 +
>   .../meta-identity-invalid.conf                |   6 +
>   .../meta-identity-invalid.conf.strict.error   |   2 +
>   .../meta-identity-invalid.conf                |   7 +
>   .../parse-config-input/meta-identity.conf     |  20 +
>   src/test/restore-config-expected/150.conf     |   9 +
>   src/test/restore-config-input/150.conf        |  10 +
>   src/test/run_api_tests.pl                     | 157 +++
>   src/test/run_guest_identity_tests.pl          | 533 ++++++++++
>   src/test/run_parse_config_tests.pl            |   2 +-
>   src/test/run_qemu_restore_config_tests.pl     | 916 +++++++++++++++++-
>   .../create/qemu-server/401.conf               |  31 +
>   .../create/qemu-server/402.conf               |  31 +
>   .../rollback/qemu-server/401.conf             |  36 +
>   .../rollback/qemu-server/402.conf             |  35 +
>   .../create/qemu-server/401.conf               |  13 +
>   .../create/qemu-server/402.conf               |  13 +
>   .../rollback/qemu-server/401.conf             |  35 +
>   .../rollback/qemu-server/402.conf             |  34 +
>   src/test/snapshot-test.pm                     |  85 +-
>   29 files changed, 2439 insertions(+), 49 deletions(-)
>   create mode 100644 src/test/QemuServerTest/FakeCFS.pm
>   create mode 100644 src/test/cfg2cmd/q35-windows-pinning-identity-only.conf
>   create mode 100644 src/test/cfg2cmd/q35-windows-pinning-identity-only.conf.cmd
>   create mode 100644 src/test/parse-config-expected/meta-identity-invalid.conf
>   create mode 100644 src/test/parse-config-expected/meta-identity-invalid.conf.strict.error
>   create mode 100644 src/test/parse-config-input/meta-identity-invalid.conf
>   create mode 100644 src/test/parse-config-input/meta-identity.conf
>   create mode 100644 src/test/restore-config-expected/150.conf
>   create mode 100644 src/test/restore-config-input/150.conf
>   create mode 100755 src/test/run_guest_identity_tests.pl
>   create mode 100644 src/test/snapshot-expected/create/qemu-server/401.conf
>   create mode 100644 src/test/snapshot-expected/create/qemu-server/402.conf
>   create mode 100644 src/test/snapshot-expected/rollback/qemu-server/401.conf
>   create mode 100644 src/test/snapshot-expected/rollback/qemu-server/402.conf
>   create mode 100644 src/test/snapshot-input/create/qemu-server/401.conf
>   create mode 100644 src/test/snapshot-input/create/qemu-server/402.conf
>   create mode 100644 src/test/snapshot-input/rollback/qemu-server/401.conf
>   create mode 100644 src/test/snapshot-input/rollback/qemu-server/402.conf
> 
> 
> container:
> 
> Thomas Lamprecht (8):
>    config: add read-only meta property with the creation time
>    fix #7846: config: add a guest identity to the 'meta' property
>    api: migrate, clone: refuse targets that would drop the guest identity
>    restore: take over the guest uid from the backup where possible
>    restore: refuse overwriting a container with another guest's backup
>    migrate: remote: clean up the target on a tunnel version mismatch
>    api: remote migration: take over the guest uid from the source
>    api: status: return the guest uid
> 
>   src/PVE/API2/LXC.pm         |  166 +++-
>   src/PVE/API2/LXC/Config.pm  |   29 +-
>   src/PVE/API2/LXC/Status.pm  |   10 +
>   src/PVE/LXC/Config.pm       |   63 +-
>   src/PVE/LXC/Migrate.pm      |   31 +-
>   src/test/Makefile           |    8 +-
>   src/test/config_tests.pl    |   23 +
>   src/test/lifecycle_tests.pl | 1878 +++++++++++++++++++++++++++++++++++
>   8 files changed, 2177 insertions(+), 31 deletions(-)
>   create mode 100755 src/test/lifecycle_tests.pl
> 
> 
> manager:
> 
> Thomas Lamprecht (5):
>    api: cluster resources: add guest uid and registration time
>    api: cluster status: add cluster ID
>    ui: restore: allow overwriting a guest with a backup of another guest
>    ui: migrate: refuse target nodes that would drop the guest identity
>    ui: guest summary: show the guest identity
> 
>   PVE/API2/Cluster.pm                      |  35 +++-
>   test/ClusterResources_test.pl            | 249 +++++++++++++++++++++++
>   test/ClusterStatus_test.pl               | 114 +++++++++++
>   test/Makefile                            |  10 +-
>   www/manager6/Makefile                    |   1 +
>   www/manager6/panel/GuestIdentity.js      | 142 +++++++++++++
>   www/manager6/panel/GuestStatusView.js    |   3 +
>   www/manager6/panel/TemplateStatusView.js |   3 +
>   www/manager6/window/Migrate.js           |  29 +++
>   www/manager6/window/Restore.js           |  18 ++
>   10 files changed, 602 insertions(+), 2 deletions(-)
>   create mode 100755 test/ClusterResources_test.pl
>   create mode 100755 test/ClusterStatus_test.pl
>   create mode 100644 www/manager6/panel/GuestIdentity.js
> 
> 
> docs:
> 
> Thomas Lamprecht (4):
>    vzdump: describe the guest identity of VMs and containers
>    pvecm: document the cluster ID and how to get a new one
>    qm: configuration: describe the read-only meta property
>    pct: configuration: describe the read-only meta property
> 
>   pct.adoc    |  35 +++++++
>   pmxcfs.adoc |   1 +
>   pvecm.adoc  |  86 +++++++++++++++++
>   qm.adoc     |  38 ++++++++
>   vzdump.adoc | 259 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>   5 files changed, 419 insertions(+)
> 
> 
> Summary over all repositories:
>    79 files changed, 9230 insertions(+), 101 deletions(-)
> 





^ permalink raw reply	[relevance 15%]

* [PATCH docs 31/34] vzdump: describe the guest identity of VMs and containers
  2026-11-16  0:46 19% [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 15% ` [PATCH qemu-server 14/34] fix #7846: config: add a guest identity to the 'meta' property Thomas Lamprecht
@ 2026-11-16  0:46 15% ` Thomas Lamprecht
  2026-11-17 10:47 15% ` [PATCH cluster/guest-common/qemu-server/container/manager/docs 00/34] fix #7846: guest identity (uid) and cluster ID Dominik Csapak
  2026-11-17 15:55 13% ` Dominik Csapak
  3 siblings, 0 replies; 32+ results
From: Thomas Lamprecht @ 2026-11-16  0:46 UTC (permalink / raw)
  To: pve-devel

Since Proxmox VE 9.3, VMs and containers have a guest identity in
'meta': a random uid and a registration time. Backup software and other
tools can distinguish a guest from another that reuses its VMID [0].

Administrators need to understand why restores over a different guest
are refused, when a restore keeps the uid of the backup, and why
migrations and clones to older nodes are blocked. Those nodes drop
'meta', including VM creation information used for hardware defaults.

Document the lifecycle, failed-restore retries, and mixed-version
restrictions in the backup and restore chapter, where users are most
likely to encounter the identity. Include migration and HA behavior
there so the rules can be read together.

[0]: https://bugzilla.proxmox.com/show_bug.cgi?id=7846

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
---
 vzdump.adoc | 256 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 256 insertions(+)

diff --git a/vzdump.adoc b/vzdump.adoc
index 44db027..87136af 100644
--- a/vzdump.adoc
+++ b/vzdump.adoc
@@ -464,6 +464,13 @@ following CLI tools:
 
 For details see the corresponding manual pages.
 
+When you restore a backup over an existing guest, {pve} compares the guest
+identities of the backup and of the guest. If they differ, the restore is
+refused, unless you set the `allow-identity-mismatch` option. The existing guest
+then keeps its identity. See
+xref:guest_identity_restore[Restore Over an Existing Guest] for details and
+exceptions.
+
 Bandwidth Limit
 ~~~~~~~~~~~~~~~
 
@@ -563,6 +570,255 @@ file in `/var/log/proxmox-backup/file-restore/`. The log file might contain
 additional information in case an attempt to restore individual files or
 accessing file systems contained in a backup archive fails.
 
+[[guest_identity]]
+Guest Identity
+--------------
+
+Since {pve} 9.3, each virtual machine and container has a guest identity: a
+random identifier, `uid`, and a registration time, `rtime`. Unlike a VMID,
+which can be reused after a guest is destroyed, the `uid` lets backup software
+and other tools recognize the same logical guest across restores and
+migrations, even under a different VMID. Whether an operation keeps the `uid`
+depends on the target and the options of the operation, as described in
+xref:guest_identity_lifecycle[Lifecycle].
+
+[[guest_identity_values]]
+Identity Values
+~~~~~~~~~~~~~~~
+
+The guest identity is part of the `meta` property in the guest configuration.
+This property also contains the creation time `ctime` and, for VMs, the QEMU
+version that the VM was created with, `creation-qemu`:
+
+----
+meta: creation-qemu=10.1.2,ctime=1772444467,rtime=1794320571482,uid=w5qczgiem26qnwzwsoil
+----
+
+`uid`::
+
+A random identifier of 20 characters, consisting of the lowercase letters `a` to
+`z` and the digits `2` to `7`.
+
+`rtime`::
+
+The time at which the guest was registered in this cluster, in milliseconds
+since the UNIX epoch. Creating or cloning a guest, restoring it to a free VMID,
+and migrating it from another cluster register the guest in the cluster. A
+guest restored to a free VMID gets a new `rtime`, even if it keeps the backup's
+`uid`. See xref:guest_identity_lifecycle[Lifecycle] for the other operations.
+As a timestamp, the `rtime` is not guaranteed to be unique.
+
+{pve} manages the `meta` property automatically. It is read-only through the
+API, even for `root@pam`.
+
+IMPORTANT: The `uid` helps to correlate a guest with its backups and copies,
+but does not prove where a guest comes from. Whoever restores a backup or
+migrates a guest into the cluster supplies the `uid` of that guest, which {pve}
+takes over if no other guest in the cluster has it. {pve} keeps a `uid` unique
+within a cluster only for operations through its API. A configuration file
+copied by hand has the same `uid` as the original, and guests in different
+clusters can have the same `uid`.
+
+[[guest_identity_read]]
+Reading the Identity
+~~~~~~~~~~~~~~~~~~~~
+
+The following places show the guest identity. All of them require the
+`VM.Audit` privilege on the guest.
+
+* In the web interface, the 'Summary' panel of the guest shows the `uid` as
+  'Unique ID'. The 'Details' button next to it, which has an info icon, opens
+  the 'Guest Identity' window. This window additionally shows the `rtime` as
+  'Registered' and the creation information.
+* The guest configuration, for example with `qm config <vmid>` or
+  `pct config <vmid>`, and through the API paths
+  `/nodes/<node>/qemu/<vmid>/config` and `/nodes/<node>/lxc/<vmid>/config`.
+* The guest status at the API paths `/nodes/<node>/qemu/<vmid>/status/current`
+  and `/nodes/<node>/lxc/<vmid>/status/current`, which contains the `uid`.
+* The cluster resources at the API path `/cluster/resources`, which contain the
+  `uid` and `rtime` of each guest, for example:
++
+----
+# pvesh get /cluster/resources --type vm --output-format json-pretty
+----
+
+The configuration in a backup contains the `meta` property as well. You can
+show it with `pvesm extractconfig <volume>`, for example.
+
+[[guest_identity_lifecycle]]
+Lifecycle
+~~~~~~~~~
+
+The following table shows how operations affect the identity of a guest.
+
+[width="100%",cols="3,4,2",options="header"]
+|===========================================================================
+|Operation |`uid` |`rtime`
+|Create, including import |new |current time
+|Clone, including linked clones and clones from snapshots |new |current time
+|Restore to a free VMID |the backup's `uid` if present and not used by another
+guest in the cluster; otherwise new |current time
+|Restore to a free VMID with `unique` set |new |current time
+|Restore over an existing guest that has a `uid`, with or without `unique` set
+|kept, see xref:guest_identity_restore[Restore Over an Existing Guest] |kept
+|Restore over an existing guest without a `uid` |as for a free VMID |current
+time
+|Migration to another cluster, on the target |the source guest's `uid` if no
+other guest in the target cluster has it; otherwise new |current time
+|Migration to another cluster, on the source if the guest is kept |kept |kept
+|Snapshot rollback |kept, not taken from the snapshot |kept
+|Migration within the cluster, HA recovery, configuration change, backup,
+replication, conversion to a template |kept |kept
+|Destroy |removed |removed
+|===========================================================================
+
+Restores and migrations from another cluster report the outcome in their task
+log, in a line starting with `guest identity:`, for example:
+
+----
+guest identity: backup uid w5qczgiem26qnwzwsoil is in use by guest 100, keeping uid er3n3wqoqgcl362ep3da
+----
+
+When a restore or a migration from another cluster takes over a `uid`, the guest
+first has a newly assigned `uid`. A restore replaces it with the `uid` of the
+backup at its end. A migration from another cluster replaces it with the `uid`
+of the source guest when the target takes over the configuration, which is
+before the migration finishes. Tools that read `/cluster/resources` during such
+a task can therefore see a `uid` that disappears afterwards. A changed `uid`
+does not mean that the task has finished.
+
+Guests that existed before the upgrade to {pve} 9.3 get their identity the
+first time a node running {pve} 9.3 or later writes their configuration. This
+happens, for example, when their configuration changes, when they are backed
+up, or when they are migrated to such a node. Their `rtime` is the time of that
+write. Backups made before that have no `uid`.
+
+When a tool restores a guest by removing it and creating a new one through the
+API, the new guest gets a new `uid`. To keep the identity, a tool has to change
+the existing guest in place, or let {pve} restore the guest.
+
+[[guest_identity_restore]]
+Restore Over an Existing Guest
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+If the existing guest already has a guest identity, restoring a backup over it
+keeps the `uid` and `rtime` of that guest. When both the guest and the backup
+have a `uid` and the values differ, {pve} treats the backup as belonging to
+another guest. This can happen when a VMID was reused. {pve} refuses such a
+restore before it overwrites the guest:
+
+----
+backup belongs to another guest: its uid 'w5qczgiem26qnwzwsoil' differs from uid 'er3n3wqoqgcl362ep3da' of the existing VM 100 - use 'allow-identity-mismatch' to overwrite the VM anyway
+----
+
+To restore such a backup anyway, set the `allow-identity-mismatch` option. The
+existing guest then keeps its identity. In the web interface, select 'Allow
+restoring a backup of another guest' in the restore window, which you open from
+the 'Backup' panel of the guest. On the command line, use for example:
+
+----
+# qmrestore <archive> <vmid> --force 1 --allow-identity-mismatch 1
+# pct restore <vmid> <archive> --force 1 --allow-identity-mismatch 1
+----
+
+Backups without a `uid`, such as backups made with {pve} versions older than
+9.3, are not refused. Container restores from standard input
+(`pct restore <vmid> -`) are an exception: the `uid` of such a backup is only
+known once the container has been overwritten. A restore from standard input
+over a container with a `uid` therefore always requires
+`allow-identity-mismatch`.
+
+A restore that fails or is stopped can leave the guest behind. If the restore
+was killed, the guest also stays locked. Remove the lock with `qm unlock <vmid>`
+or `pct unlock <vmid>` before you retry the restore or remove the guest.
+
+If the failed restore had already read the configuration of the backup,
+`qm pending <vmid>` or `pct pending <vmid>` lists an entry for `meta` with the
+`uid` of the backup. As long as this entry exists, retrying the same restore
+over the guest left behind is accepted. Starting the guest or changing its
+options removes the entry. The retry is then refused like a restore of another
+guest's backup.
+
+A successful retry takes over the `uid` of the backup and sets a new `rtime`, as
+a restore to a free VMID does. The guest keeps its `uid` and `rtime` instead if
+another guest in the cluster has the `uid` of the backup, or if the retry sets
+`unique`. Restores from standard input still require `allow-identity-mismatch`,
+as described above.
+
+If the failed restore stopped before it read the backup, for example because the
+backup storage was unreachable, the guest left behind is one of the following:
+
+* An empty placeholder of a restore to a free VMID. Unlock it as described
+  above, remove it, for example with `qm destroy <vmid>` or
+  `pct destroy <vmid>`, and restore again.
+* An existing guest that had no `uid` before the restore, now with a new `uid`.
+  Retry with `allow-identity-mismatch`.
+
+A restore can also complete with a warning starting with
+`guest identity: unable to adopt backup uid`, for example if the cluster has no
+quorum at the end of the restore. The guest is then restored completely, but
+keeps its new `uid`. To take over the `uid` of the backup, repeat the restore
+over the guest before you start it or change its configuration.
+
+[[guest_identity_mixed_versions]]
+Mixed Versions in a Cluster
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+While some nodes of a cluster still run a {pve} version older than 9.3,
+migrating or cloning a guest to one of these nodes is refused. The guest keeps
+running on its current node. If the target node reports its version, the error
+message shows that version and the minimum required version. If the node does
+not report its version, the operation is refused because {pve} cannot verify
+that the node supports guest identities. The 'Migrate' window of the web
+interface shows the reason for the selected target node.
+
+Moves of HA-managed guests to such nodes are refused in the same way. A running
+VM that the HA stack migrates keeps running. The HA stack stops a container, and
+a VM that it relocates, before it migrates the guest, so such a guest is stopped
+although the move is then refused. The HA stack retries automatic moves until
+they succeed, and such a guest can stay stopped in the meantime. This includes
+moves for:
+
+* the maintenance mode,
+* a node shutdown with the `migrate` shutdown policy,
+* node affinity rules,
+* the CRS load balancer.
+
+Such moves complete only after the target nodes that the HA stack selects run
+{pve} 9.3 or later.
+
+To avoid refused moves while you upgrade a cluster, do one of the following:
+
+* Move all guests away from a node before you upgrade it.
+* Upgrade the packages on all nodes, one node at a time, before you reboot any
+  node or enable the maintenance mode.
+
+The reason for these refusals is that {pve} versions older than 9.3 ignore the
+whole `meta` property of a guest that has a guest identity, including the
+creation information. A VM started on such a node can therefore get different
+virtual hardware, see xref:qm_machine_type[Machine Type]. When such a node
+writes the configuration, the property is lost.
+
+The check covers migrations and clones started on a node running {pve} 9.3 or
+later. It does not cover:
+
+* the HA recovery of guests from a fenced node,
+* configuration files moved by hand,
+* operations started on a node with an older version.
+
+If an older node writes the configuration of a guest in one of these cases, the
+guest loses its `meta` property. It gets a new identity the next time a node
+running {pve} 9.3 or later writes its configuration.
+
+Backups made with {pve} 9.3 or later contain the guest identity. Restore them
+only on nodes running {pve} 9.3 or later, because older versions ignore the
+`meta` property of such backups in the same way.
+
+A migration to another cluster (`qm remote-migrate`, `pct remote-migrate`) is
+refused right after connecting to a target node with a version older than 9.3,
+before any data is transferred. The error is
+`Remote tunnel endpoint too old, upgrade required`.
+
 [[vzdump_configuration]]
 Configuration
 -------------
-- 
2.47.3





^ permalink raw reply related	[relevance 15%]

* [PATCH qemu-server 14/34] fix #7846: config: add a guest identity to the 'meta' property
  2026-11-16  0:46 19% [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 15% ` Thomas Lamprecht
  2026-11-16  0:46 15% ` [PATCH docs 31/34] vzdump: describe the guest identity of VMs and containers Thomas Lamprecht
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 32+ results
From: Thomas Lamprecht @ 2026-11-16  0:46 UTC (permalink / raw)
  To: pve-devel

Give VMs a guest identity in the read-only 'meta' property: a random
identifier, 'uid', and a registration time, 'rtime'. Tools can use it
to recognize a guest across restores and migrations, independently of
its VMID.

Enable the identity handling of the config class, so that each config
write keeps the identity a VM already has or assigns one if it has
none. New VMs, clones and imports get an identity when their VMID is
reserved. Existing VMs get one with their next config write. A stale
config, a clone source or a snapshot rollback cannot replace the
identity of a VM.

The other members of 'meta' behave as before. A config without creation
information thus gets a 'meta' property with only the identity. Older
qemu-server versions reject the new members and drop the whole property
on their next config write.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
---
 src/PVE/QemuConfig.pm                         |   7 +
 src/PVE/QemuServer/MetaInfo.pm                |   2 +
 src/test/Makefile                             |   5 +-
 .../q35-windows-pinning-identity-only.conf    |   6 +
 ...q35-windows-pinning-identity-only.conf.cmd |  26 ++
 .../meta-identity-invalid.conf                |   6 +
 .../meta-identity-invalid.conf.strict.error   |   2 +
 .../meta-identity-invalid.conf                |   7 +
 .../parse-config-input/meta-identity.conf     |  20 ++
 src/test/run_guest_identity_tests.pl          | 259 ++++++++++++++++++
 src/test/run_parse_config_tests.pl            |   2 +-
 src/test/run_qemu_restore_config_tests.pl     |   3 +-
 .../create/qemu-server/401.conf               |  31 +++
 .../create/qemu-server/402.conf               |  31 +++
 .../rollback/qemu-server/401.conf             |  36 +++
 .../rollback/qemu-server/402.conf             |  35 +++
 .../create/qemu-server/401.conf               |  13 +
 .../create/qemu-server/402.conf               |  13 +
 .../rollback/qemu-server/401.conf             |  35 +++
 .../rollback/qemu-server/402.conf             |  34 +++
 src/test/snapshot-test.pm                     |  85 +++++-
 21 files changed, 644 insertions(+), 14 deletions(-)
 create mode 100644 src/test/cfg2cmd/q35-windows-pinning-identity-only.conf
 create mode 100644 src/test/cfg2cmd/q35-windows-pinning-identity-only.conf.cmd
 create mode 100644 src/test/parse-config-expected/meta-identity-invalid.conf
 create mode 100644 src/test/parse-config-expected/meta-identity-invalid.conf.strict.error
 create mode 100644 src/test/parse-config-input/meta-identity-invalid.conf
 create mode 100644 src/test/parse-config-input/meta-identity.conf
 create mode 100755 src/test/run_guest_identity_tests.pl
 create mode 100644 src/test/snapshot-expected/create/qemu-server/401.conf
 create mode 100644 src/test/snapshot-expected/create/qemu-server/402.conf
 create mode 100644 src/test/snapshot-expected/rollback/qemu-server/401.conf
 create mode 100644 src/test/snapshot-expected/rollback/qemu-server/402.conf
 create mode 100644 src/test/snapshot-input/create/qemu-server/401.conf
 create mode 100644 src/test/snapshot-input/create/qemu-server/402.conf
 create mode 100644 src/test/snapshot-input/rollback/qemu-server/401.conf
 create mode 100644 src/test/snapshot-input/rollback/qemu-server/402.conf

diff --git a/src/PVE/QemuConfig.pm b/src/PVE/QemuConfig.pm
index c84f10f8..29ec7c86 100644
--- a/src/PVE/QemuConfig.pm
+++ b/src/PVE/QemuConfig.pm
@@ -630,6 +630,13 @@ sub write_config {
     return $class->SUPER::write_config($vmid, $conf);
 }
 
+# the format of the 'meta' property includes the guest identity, see PVE::QemuServer::MetaInfo
+sub __identity_enabled {
+    my ($class) = @_;
+
+    return 1;
+}
+
 # END implemented abstract methods from PVE::AbstractConfig
 
 sub has_cloudinit {
diff --git a/src/PVE/QemuServer/MetaInfo.pm b/src/PVE/QemuServer/MetaInfo.pm
index b69e5a1c..399cd920 100644
--- a/src/PVE/QemuServer/MetaInfo.pm
+++ b/src/PVE/QemuServer/MetaInfo.pm
@@ -3,6 +3,7 @@ package PVE::QemuServer::MetaInfo;
 use strict;
 use warnings;
 
+use PVE::GuestIdentity;
 use PVE::JSONSchema;
 
 use PVE::QemuServer::Helpers;
@@ -20,6 +21,7 @@ our $meta_info_fmt = {
         pattern => '\d+(\.\d+)+',
         optional => 1,
     },
+    PVE::GuestIdentity::meta_format_properties()->%*,
 };
 
 sub parse_meta_info {
diff --git a/src/test/Makefile b/src/test/Makefile
index 3916179e..3c7865e5 100644
--- a/src/test/Makefile
+++ b/src/test/Makefile
@@ -1,6 +1,6 @@
 all: test
 
-test: test_snapshot test_cfg_to_cmd test_cfg_to_cmd_aarch64 test_hotplug test_hotplug_aarch64 test_pci_addr_conflicts test_pci_reservation test_qemu_img_convert test_migration test_restore_config test_parse_config test_memory test_raw_config_write test_api
+test: test_snapshot test_cfg_to_cmd test_cfg_to_cmd_aarch64 test_hotplug test_hotplug_aarch64 test_pci_addr_conflicts test_pci_reservation test_qemu_img_convert test_migration test_restore_config test_parse_config test_memory test_raw_config_write test_api test_guest_identity
 
 test_snapshot: run_snapshot_tests.pl
 	./run_snapshot_tests.pl
@@ -50,6 +50,9 @@ test_raw_config_write: run_raw_config_write_tests.pl
 test_api: run_api_tests.pl
 	./run_api_tests.pl
 
+test_guest_identity: run_guest_identity_tests.pl QemuServerTest/FakeCFS.pm
+	./run_guest_identity_tests.pl
+
 .PHONY: clean
 clean:
 	rm -rf MigrationTest/run
diff --git a/src/test/cfg2cmd/q35-windows-pinning-identity-only.conf b/src/test/cfg2cmd/q35-windows-pinning-identity-only.conf
new file mode 100644
index 00000000..5242ec13
--- /dev/null
+++ b/src/test/cfg2cmd/q35-windows-pinning-identity-only.conf
@@ -0,0 +1,6 @@
+# TEST: Windows without pinned machine and with only the guest identity as meta info stays on 5.1
+machine: q35
+meta: rtime=1762300000000,uid=abcdefghijklmnopqrst
+ostype: win11
+smbios1: uuid=7b10d7af-b932-4c66-b2c3-3996152ec465
+vmgenid: c773c261-d800-4348-9f5d-167fadd53cf8
diff --git a/src/test/cfg2cmd/q35-windows-pinning-identity-only.conf.cmd b/src/test/cfg2cmd/q35-windows-pinning-identity-only.conf.cmd
new file mode 100644
index 00000000..67d20b79
--- /dev/null
+++ b/src/test/cfg2cmd/q35-windows-pinning-identity-only.conf.cmd
@@ -0,0 +1,26 @@
+/usr/bin/kvm \
+  -id 8006 \
+  -name vm8006 \
+  -no-shutdown \
+  -chardev 'socket,id=qmp,path=/var/run/qemu-server/8006.qmp,server=on,wait=off' \
+  -object 'monitor-qmp,chardev=qmp,id=monitor-qmp' \
+  -chardev 'socket,id=qmp-event,path=/var/run/qmeventd.sock,reconnect-ms=5000' \
+  -object 'monitor-qmp,chardev=qmp-event,id=monitor-qmp-event' \
+  -pidfile /var/run/qemu-server/8006.pid \
+  -daemonize \
+  -smbios 'type=1,uuid=7b10d7af-b932-4c66-b2c3-3996152ec465' \
+  -smp '1,sockets=1,cores=1,maxcpus=1' \
+  -nodefaults \
+  -boot 'menu=on,strict=on,reboot-timeout=1000,splash=/usr/share/qemu-server/bootsplash.jpg' \
+  -vnc 'unix:/var/run/qemu-server/8006.vnc,password=on' \
+  -global 'kvm-pit.lost_tick_policy=discard' \
+  -cpu 'kvm64,-cet-ibt,-cet-ss,enforce,hv_ipi,hv_relaxed,hv_reset,hv_runtime,hv_spinlocks=0x1fff,hv_stimer,hv_synic,hv_time,hv_vapic,hv_vpindex,+kvm_pv_eoi,+kvm_pv_unhalt,+lahf_lm,+sep' \
+  -m 512 \
+  -readconfig /usr/share/qemu-server/pve-q35-4.0.cfg \
+  -device 'vmgenid,guid=c773c261-d800-4348-9f5d-167fadd53cf8' \
+  -device 'usb-tablet,id=tablet,bus=ehci.0,port=1' \
+  -device 'VGA,id=vga,bus=pcie.0,addr=0x1,edid=off' \
+  -device 'virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3' \
+  -iscsi 'initiator-name=iqn.1993-08.org.debian:01:aabbccddeeff' \
+  -rtc 'driftfix=slew,base=localtime' \
+  -machine 'hpet=off,type=pc-q35-5.1+pve0'
diff --git a/src/test/parse-config-expected/meta-identity-invalid.conf b/src/test/parse-config-expected/meta-identity-invalid.conf
new file mode 100644
index 00000000..195514fa
--- /dev/null
+++ b/src/test/parse-config-expected/meta-identity-invalid.conf
@@ -0,0 +1,6 @@
+# VM with a guest uid that is not valid
+boot: order=scsi0
+cores: 2
+memory: 4096
+name: identity
+scsi0: local-lvm:vm-8006-disk-0,size=32G
diff --git a/src/test/parse-config-expected/meta-identity-invalid.conf.strict.error b/src/test/parse-config-expected/meta-identity-invalid.conf.strict.error
new file mode 100644
index 00000000..ae584c1f
--- /dev/null
+++ b/src/test/parse-config-expected/meta-identity-invalid.conf.strict.error
@@ -0,0 +1,2 @@
+vm 8006 - unable to parse value of 'meta' - format error
+uid: value does not match the regex pattern
diff --git a/src/test/parse-config-input/meta-identity-invalid.conf b/src/test/parse-config-input/meta-identity-invalid.conf
new file mode 100644
index 00000000..90e60197
--- /dev/null
+++ b/src/test/parse-config-input/meta-identity-invalid.conf
@@ -0,0 +1,7 @@
+# VM with a guest uid that is not valid
+boot: order=scsi0
+cores: 2
+memory: 4096
+meta: creation-qemu=10.1.2,ctime=1762000000,rtime=1762000000123,uid=ABCDEFGHIJKLMNOPQRST
+name: identity
+scsi0: local-lvm:vm-8006-disk-0,size=32G
diff --git a/src/test/parse-config-input/meta-identity.conf b/src/test/parse-config-input/meta-identity.conf
new file mode 100644
index 00000000..7a1e03be
--- /dev/null
+++ b/src/test/parse-config-input/meta-identity.conf
@@ -0,0 +1,20 @@
+# VM with guest identity
+boot: order=scsi0
+cores: 2
+memory: 4096
+meta: creation-qemu=10.1.2,ctime=1762000000,rtime=1762000000123,uid=abcdefghijklmnopqrst
+name: identity
+scsi0: local-lvm:vm-8006-disk-0,size=32G
+scsihw: virtio-scsi-single
+smbios1: uuid=7b4f2a1e-3c2d-4e5f-8a9b-0c1d2e3f4a5b
+
+[snap]
+boot: order=scsi0
+cores: 2
+memory: 4096
+meta: creation-qemu=10.1.2,ctime=1762000000,rtime=1762000000123,uid=abcdefghijklmnopqrst
+name: identity
+scsi0: local-lvm:vm-8006-disk-0,size=32G
+scsihw: virtio-scsi-single
+smbios1: uuid=7b4f2a1e-3c2d-4e5f-8a9b-0c1d2e3f4a5b
+snaptime: 1762000100
diff --git a/src/test/run_guest_identity_tests.pl b/src/test/run_guest_identity_tests.pl
new file mode 100755
index 00000000..e80609d9
--- /dev/null
+++ b/src/test/run_guest_identity_tests.pl
@@ -0,0 +1,259 @@
+#!/usr/bin/perl
+
+# Tests the guest identity of VM configs through the real config class methods, with a fake cluster
+# filesystem, see QemuServerTest::FakeCFS.
+
+use strict;
+use warnings;
+
+use lib qw(.. .);
+
+use File::Temp qw(tempdir);
+use Test::MockModule;
+use Test::More;
+
+use PVE::JSONSchema;
+use PVE::QemuConfig;
+use PVE::QemuConfig::NoWrite;
+use PVE::QemuServer;
+use PVE::QemuServer::MetaInfo;
+
+use QemuServerTest::FakeCFS;
+
+my $UID_A = 'abcdefghijklmnopqrst';
+my $UID_B = 'bbbbbbbbbbbbbbbbbbbb';
+
+my $helpers_module = Test::MockModule->new('PVE::QemuServer::Helpers');
+$helpers_module->mock(kvm_user_version => sub { return '10.1.2'; });
+
+sub configs { return $QemuServerTest::FakeCFS::configs; }
+sub generated_uid { return QemuServerTest::FakeCFS::generated_uid(@_); }
+sub published_identity { return QemuServerTest::FakeCFS::published_identity(@_); }
+
+sub load_meta {
+    my ($vmid) = @_;
+    return PVE::QemuServer::MetaInfo::parse_meta_info(PVE::QemuConfig->load_config($vmid)->{meta});
+}
+
+subtest 'meta format' => sub {
+    my $meta =
+        'creation-qemu=10.1.2,ctime=1700000000,rtime=1700000000123,uid=abcdefghijklmnopqrst';
+
+    is_deeply(
+        PVE::QemuServer::MetaInfo::parse_meta_info($meta),
+        {
+            'creation-qemu' => '10.1.2',
+            ctime => 1700000000,
+            rtime => 1700000000123,
+            uid => $UID_A,
+        },
+        'identity members get parsed',
+    );
+    is(
+        PVE::JSONSchema::print_property_string(
+            PVE::QemuServer::MetaInfo::parse_meta_info($meta),
+            $PVE::QemuServer::MetaInfo::meta_info_fmt,
+        ),
+        $meta,
+        'printing the parsed property gives the same string',
+    );
+
+    for my $invalid (
+        'uid=ABCDEFGHIJKLMNOPQRST', 'uid=abcdefghijklmnopqrs', 'rtime=-1', 'rtime=1x',
+    ) {
+        eval {
+            PVE::JSONSchema::parse_property_string(
+                $PVE::QemuServer::MetaInfo::meta_info_fmt, $invalid,
+            );
+        };
+        ok($@, "'$invalid' is rejected");
+    }
+
+    # versions before the identity members only know these two, and drop the whole property
+    my $old_fmt = {
+        ctime => $PVE::QemuServer::MetaInfo::meta_info_fmt->{ctime},
+        'creation-qemu' => $PVE::QemuServer::MetaInfo::meta_info_fmt->{'creation-qemu'},
+    };
+    eval { PVE::JSONSchema::parse_property_string($old_fmt, $meta) };
+    like(
+        $@,
+        qr/property is not defined in schema/,
+        'format without identity members rejects it',
+    );
+};
+
+subtest 'identities are enabled, but not for writing temporary configs' => sub {
+    QemuServerTest::FakeCFS::reset();
+
+    ok(PVE::QemuConfig->__identity_enabled(), 'enabled for PVE::QemuConfig');
+
+    my $conf = { name => 'template-cmd' };
+    PVE::QemuConfig::NoWrite->mark_config($conf);
+    eval { PVE::QemuConfig->write_config(100, $conf) };
+    is($@, "refusing to write temporary configuration\n", 'NoWrite refuses');
+    eval { PVE::QemuConfig::NoWrite->write_config(100, $conf) };
+    is(
+        $@,
+        "refusing to write temporary configuration\n",
+        'NoWrite refuses when called directly',
+    );
+    is_deeply(configs(), {}, 'nothing written');
+    is($QemuServerTest::FakeCFS::generated, 0, 'no identity generated');
+};
+
+subtest 'config writes keep the published identity' => sub {
+    QemuServerTest::FakeCFS::reset();
+
+    PVE::QemuConfig->write_config(100, { memory => 512, meta => "rtime=1,uid=$UID_B" });
+    is_deeply(
+        published_identity(100),
+        { uid => generated_uid(1), rtime => 1700000000000 },
+        'first write ignores a carried identity and generates one',
+    );
+    like(configs()->{100}, qr/^meta: rtime=1700000000000,uid=\w+$/m,
+        'written as meta property');
+
+    $QemuServerTest::FakeCFS::now_ms = 1800000000000;
+
+    my $conf = PVE::QemuConfig->load_config(100);
+    $conf->{meta} = "creation-qemu=9.2.0,ctime=1600000000,rtime=1,uid=$UID_B";
+    PVE::QemuConfig->write_config(100, $conf);
+    is_deeply(
+        load_meta(100),
+        {
+            'creation-qemu' => '9.2.0',
+            ctime => 1600000000,
+            rtime => 1700000000000,
+            uid => generated_uid(1),
+        },
+        'foreign identity replaced by the published one, other members kept',
+    );
+
+    $conf = PVE::QemuConfig->load_config(100);
+    delete $conf->{meta};
+    PVE::QemuConfig->write_config(100, $conf);
+    is_deeply(
+        load_meta(100),
+        { rtime => 1700000000000, uid => generated_uid(1) },
+        'identity kept when the property is gone',
+    );
+
+    configs()->{101} = "memory: 512\nmeta: creation-qemu=8.0.2,ctime=1500000000\n";
+    $conf = PVE::QemuConfig->load_config(101);
+    $conf->{name} = 'old';
+    PVE::QemuConfig->write_config(101, $conf);
+    is_deeply(
+        load_meta(101),
+        {
+            'creation-qemu' => '8.0.2',
+            ctime => 1500000000,
+            rtime => 1800000000000,
+            uid => generated_uid(2),
+        },
+        'existing guest without identity gets one on its first write',
+    );
+};
+
+subtest 'create' => sub {
+    QemuServerTest::FakeCFS::reset();
+
+    my $reservation = PVE::QemuConfig->create_and_lock_config(100);
+    is_deeply(
+        $reservation,
+        {
+            existed => 0,
+            identity => undef,
+            pending => undef,
+            reserved => { uid => generated_uid(1), rtime => 1700000000000 },
+        },
+        'reservation publishes a new identity',
+    );
+
+    $QemuServerTest::FakeCFS::now_ms = 1700000005000;
+
+    my $conf = { memory => 512, meta => PVE::QemuServer::MetaInfo::new_meta_info_string() };
+    PVE::QemuConfig->write_config(100, $conf);
+    my $meta = load_meta(100);
+    is_deeply(
+        [$meta->@{qw(creation-qemu uid rtime)}],
+        ['10.1.2', generated_uid(1), 1700000000000],
+        'final config keeps the reserved identity next to the creation info',
+    );
+    ok($meta->{ctime}, 'creation time set');
+};
+
+subtest 'clone' => sub {
+    QemuServerTest::FakeCFS::reset();
+
+    configs()->{100} = "memory: 512\nmeta: creation-qemu=9.2.0,ctime=1600000000,"
+        . "rtime=1600000000000,uid=$UID_A\nname: source\n";
+
+    for my $snapshot (0, 1) {
+        my $newid = 200 + $snapshot;
+        my $source = PVE::QemuConfig->load_config(100);
+        if ($snapshot) {
+            # a snapshot can carry any identity, the clone must not take it over either
+            $source = { memory => 256, meta => "rtime=1,uid=$UID_B" };
+        }
+
+        PVE::QemuConfig->create_and_lock_config($newid, 0, 'clone');
+
+        # like the clone API, which copies everything but some snapshot related keys
+        my $newconf = { $source->%*, lock => 'clone', name => "clone-$newid" };
+        delete $newconf->{digest};
+        PVE::QemuConfig->write_config($newid, $newconf);
+        delete $newconf->{lock};
+        PVE::QemuConfig->write_config($newid, $newconf);
+
+        my $uid = generated_uid(1 + $snapshot);
+        is(published_identity($newid)->{uid}, $uid, "clone $newid has a new uid");
+        is_deeply(
+            load_meta($newid),
+            $snapshot
+            ? { rtime => 1700000000000, uid => $uid }
+            : {
+                'creation-qemu' => '9.2.0',
+                ctime => 1600000000,
+                rtime => 1700000000000,
+                uid => $uid,
+            },
+            "clone $newid keeps the creation info of its source",
+        );
+    }
+    is(published_identity(100)->{uid}, $UID_A, 'source keeps its uid');
+};
+
+subtest 'importovf' => sub {
+    QemuServerTest::FakeCFS::reset();
+
+    require PVE::CLI::qm;
+
+    my $tmpdir = tempdir('importovf-XXXXXX', DIR => '.', CLEANUP => 1);
+    my $manifest = "$tmpdir/test.ovf";
+    PVE::Tools::file_set_contents($manifest, "<ovf/>\n");
+
+    my $storage_module = Test::MockModule->new('PVE::Storage');
+    $storage_module->mock(
+        config => sub { return {}; },
+        storage_check_enabled => sub { return {}; },
+    );
+    my $ovf_module = Test::MockModule->new('PVE::GuestImport::OVF');
+    $ovf_module->mock(
+        parse_ovf => sub {
+            return { qm => { name => 'imported', memory => 1024, cores => 2 }, disks => [] };
+        },
+    );
+
+    PVE::CLI::qm->importovf({ vmid => 100, manifest => $manifest, storage => 'local' });
+
+    my $conf = PVE::QemuConfig->load_config(100);
+    is($conf->{name}, 'imported', 'config imported');
+    ok(!defined($conf->{lock}), 'create lock removed');
+    is_deeply(
+        published_identity(100),
+        { uid => generated_uid(1), rtime => 1700000000000 },
+        'imported VM got a new identity on reservation and kept it',
+    );
+};
+
+done_testing();
diff --git a/src/test/run_parse_config_tests.pl b/src/test/run_parse_config_tests.pl
index f68abc06..69bb96ad 100755
--- a/src/test/run_parse_config_tests.pl
+++ b/src/test/run_parse_config_tests.pl
@@ -25,7 +25,7 @@ my $INPUT_DIR = './parse-config-input';
 my $EXPECTED_DIR = './parse-config-expected';
 
 # NOTE update when you add/remove tests
-plan tests => 2 * 10;
+plan tests => 2 * 12;
 
 sub run_tests {
     my ($strict) = @_;
diff --git a/src/test/run_qemu_restore_config_tests.pl b/src/test/run_qemu_restore_config_tests.pl
index e6739d66..dd8629f4 100755
--- a/src/test/run_qemu_restore_config_tests.pl
+++ b/src/test/run_qemu_restore_config_tests.pl
@@ -289,7 +289,8 @@ sub restore_api {
     return ($err, $output);
 }
 
-my $TARGET_CONF = "memory: 1024\nmeta: creation-qemu=10.0.0,ctime=1700000000\nname: target\n";
+my $TARGET_CONF = "memory: 1024\nmeta: creation-qemu=10.0.0,ctime=1700000000,"
+    . "rtime=1700000000000,uid=tttttttttttttttttttt\nname: target\n";
 my $NOT_CLEANED_UP = qr/VM 100 state is NOT cleaned up/;
 
 for my $type (sort keys $ARCHIVES->%*) {
diff --git a/src/test/snapshot-expected/create/qemu-server/401.conf b/src/test/snapshot-expected/create/qemu-server/401.conf
new file mode 100644
index 00000000..87aadf80
--- /dev/null
+++ b/src/test/snapshot-expected/create/qemu-server/401.conf
@@ -0,0 +1,31 @@
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+memory: 8192
+meta: creation-qemu=10.0.0,ctime=1700000000,rtime=1700000000000,uid=abcdefghijklmnopqrst
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+parent: test
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+sockets: 1
+vga: qxl
+
+[test]
+#test comment
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+memory: 8192
+meta: creation-qemu=10.0.0,ctime=1700000000,rtime=1700000000000,uid=abcdefghijklmnopqrst
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+snaptime: 1234567890
+sockets: 1
+vga: qxl
diff --git a/src/test/snapshot-expected/create/qemu-server/402.conf b/src/test/snapshot-expected/create/qemu-server/402.conf
new file mode 100644
index 00000000..f5bccd87
--- /dev/null
+++ b/src/test/snapshot-expected/create/qemu-server/402.conf
@@ -0,0 +1,31 @@
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+memory: 8192
+meta: creation-qemu=8.0.2,ctime=1600000000,rtime=1234567890123,uid=aerukz4jvpg66ajdivty
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+parent: test
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+sockets: 1
+vga: qxl
+
+[test]
+#test comment
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+memory: 8192
+meta: creation-qemu=8.0.2,ctime=1600000000
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+snaptime: 1234567890
+sockets: 1
+vga: qxl
diff --git a/src/test/snapshot-expected/rollback/qemu-server/401.conf b/src/test/snapshot-expected/rollback/qemu-server/401.conf
new file mode 100644
index 00000000..6215ce26
--- /dev/null
+++ b/src/test/snapshot-expected/rollback/qemu-server/401.conf
@@ -0,0 +1,36 @@
+# this is a description
+agent: 1
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+memory: 8192
+meta: creation-qemu=9.2.0,ctime=1600000000,rtime=1700000000000,uid=abcdefghijklmnopqrst
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+parent: test
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+sockets: 1
+vga: qxl
+
+[test]
+#test comment
+agent: 1
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+machine: q35
+memory: 8192
+meta: creation-qemu=9.2.0,ctime=1600000000,rtime=1600000000000,uid=bbbbbbbbbbbbbbbbbbbb
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+snaptime: 1234567890
+sockets: 1
+vga: qxl
+vmstate: somestorage:state-volume
diff --git a/src/test/snapshot-expected/rollback/qemu-server/402.conf b/src/test/snapshot-expected/rollback/qemu-server/402.conf
new file mode 100644
index 00000000..a10bfa13
--- /dev/null
+++ b/src/test/snapshot-expected/rollback/qemu-server/402.conf
@@ -0,0 +1,35 @@
+# this is a description
+agent: 1
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+memory: 8192
+meta: rtime=1700000000000,uid=abcdefghijklmnopqrst
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+parent: test
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+sockets: 1
+vga: qxl
+
+[test]
+#test comment
+agent: 1
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+machine: q35
+memory: 8192
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+snaptime: 1234567890
+sockets: 1
+vga: qxl
+vmstate: somestorage:state-volume
diff --git a/src/test/snapshot-input/create/qemu-server/401.conf b/src/test/snapshot-input/create/qemu-server/401.conf
new file mode 100644
index 00000000..41ccdae5
--- /dev/null
+++ b/src/test/snapshot-input/create/qemu-server/401.conf
@@ -0,0 +1,13 @@
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+memory: 8192
+meta: creation-qemu=10.0.0,ctime=1700000000,rtime=1700000000000,uid=abcdefghijklmnopqrst
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+sockets: 1
+vga: qxl
diff --git a/src/test/snapshot-input/create/qemu-server/402.conf b/src/test/snapshot-input/create/qemu-server/402.conf
new file mode 100644
index 00000000..e03717b6
--- /dev/null
+++ b/src/test/snapshot-input/create/qemu-server/402.conf
@@ -0,0 +1,13 @@
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+memory: 8192
+meta: creation-qemu=8.0.2,ctime=1600000000
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+sockets: 1
+vga: qxl
diff --git a/src/test/snapshot-input/rollback/qemu-server/401.conf b/src/test/snapshot-input/rollback/qemu-server/401.conf
new file mode 100644
index 00000000..7895e0df
--- /dev/null
+++ b/src/test/snapshot-input/rollback/qemu-server/401.conf
@@ -0,0 +1,35 @@
+# this is a description
+agent: 1
+bootdisk: ide2
+cores: 2
+ide0: local:snapshotable-disk-1,size=32G
+ide2: none,media=cdrom
+memory: 4096
+meta: creation-qemu=10.0.0,ctime=1700000000,rtime=1700000000000,uid=abcdefghijklmnopqrst
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+parent: test
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+sockets: 2
+
+[test]
+#test comment
+agent: 1
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+machine: q35
+memory: 8192
+meta: creation-qemu=9.2.0,ctime=1600000000,rtime=1600000000000,uid=bbbbbbbbbbbbbbbbbbbb
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+snaptime: 1234567890
+sockets: 1
+vga: qxl
+vmstate: somestorage:state-volume
diff --git a/src/test/snapshot-input/rollback/qemu-server/402.conf b/src/test/snapshot-input/rollback/qemu-server/402.conf
new file mode 100644
index 00000000..0fa7fe51
--- /dev/null
+++ b/src/test/snapshot-input/rollback/qemu-server/402.conf
@@ -0,0 +1,34 @@
+# this is a description
+agent: 1
+bootdisk: ide2
+cores: 2
+ide0: local:snapshotable-disk-1,size=32G
+ide2: none,media=cdrom
+memory: 4096
+meta: creation-qemu=10.0.0,ctime=1700000000,rtime=1700000000000,uid=abcdefghijklmnopqrst
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+parent: test
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+sockets: 2
+
+[test]
+#test comment
+agent: 1
+bootdisk: ide0
+cores: 4
+ide0: local:snapshotable-disk-1,discard=on,size=32G
+ide2: none,media=cdrom
+machine: q35
+memory: 8192
+name: win
+net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
+numa: 0
+ostype: win7
+smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
+snaptime: 1234567890
+sockets: 1
+vga: qxl
+vmstate: somestorage:state-volume
diff --git a/src/test/snapshot-test.pm b/src/test/snapshot-test.pm
index 44e55d6a..345accea 100644
--- a/src/test/snapshot-test.pm
+++ b/src/test/snapshot-test.pm
@@ -5,6 +5,7 @@ use warnings;
 
 use lib qw(..);
 
+use PVE::GuestHelpers;
 use PVE::Storage;
 use PVE::Storage::Plugin;
 use PVE::QemuServer;
@@ -30,6 +31,9 @@ my $freeze_possible;
 my $stop_possible;
 my $save_vmstate_works;
 my $vm_mon = {};
+my $real_write_config;
+
+my $original_write_config = \&PVE::QemuConfig::write_config;
 
 # Mocked methods
 
@@ -296,6 +300,13 @@ sub cfs_config_path {
     return "snapshot-working/$node/qemu-server/$vmid.conf";
 }
 
+# the same file that mocked_get_config reads, so that nothing looks at the host's /etc/pve
+sub config_file {
+    my ($class, $vmid, $node) = @_;
+
+    return $class->cfs_config_path($vmid, $node);
+}
+
 sub load_config {
     my ($class, $vmid, $node) = @_;
 
@@ -310,18 +321,10 @@ sub load_config {
 sub write_config {
     my ($class, $vmid, $conf) = @_;
 
-    my $filename = $class->cfs_config_path($vmid);
-
-    if ($conf->{snapshots}) {
-        foreach my $snapname (keys %{ $conf->{snapshots} }) {
-            $conf->{snapshots}->{$snapname}->{snaptime} = "1234567890"
-                if $conf->{snapshots}->{$snapname}->{snaptime};
-        }
-    }
+    # the real method with the guest identity handling, which writes through mocked_cfs_write_file
+    return $original_write_config->($class, $vmid, $conf) if $real_write_config;
 
-    my $raw = PVE::QemuServer::write_vm_config($filename, $conf);
-
-    PVE::Tools::file_set_contents($filename, $raw);
+    mocked_cfs_write_file($class->cfs_config_path($vmid), $conf);
 }
 
 sub has_feature {
@@ -345,6 +348,31 @@ sub assert_config_exists_on_node {
 }
 # END mocked PVE::QemuConfig methods
 
+# BEGIN mocked PVE::Cluster methods
+
+sub mocked_get_config {
+    my ($path) = @_;
+
+    return -e $path ? PVE::Tools::file_get_contents($path) : undef;
+}
+
+sub mocked_cfs_write_file {
+    my ($filename, $conf) = @_;
+
+    if ($conf->{snapshots}) {
+        foreach my $snapname (keys %{ $conf->{snapshots} }) {
+            $conf->{snapshots}->{$snapname}->{snaptime} = "1234567890"
+                if $conf->{snapshots}->{$snapname}->{snaptime};
+        }
+    }
+
+    my $raw = PVE::QemuServer::write_vm_config($filename, $conf);
+
+    PVE::Tools::file_set_contents($filename, $raw);
+}
+
+# END mocked PVE::Cluster methods
+
 # BEGIN mocked PVE::QemuServer::Helpers methods
 
 sub vm_running_locally {
@@ -441,6 +469,19 @@ sub vm_stop {
 PVE::Tools::run_command("rm -rf snapshot-working");
 PVE::Tools::run_command("cp -a snapshot-input snapshot-working");
 
+$PVE::GuestHelpers::lockdir = "snapshot-working/lock";
+
+my $cluster_module = Test::MockModule->new('PVE::Cluster');
+$cluster_module->mock('get_config', \&mocked_get_config);
+$cluster_module->mock('cfs_write_file', \&mocked_cfs_write_file);
+
+my $guest_identity_module = Test::MockModule->new('PVE::GuestIdentity');
+$guest_identity_module->mock(
+    '__random_bytes',
+    sub { return pack('H26', '0123456789abcdef0123456789'); },
+);
+$guest_identity_module->mock('__time_ms', sub { return 1234567890123; });
+
 my $qemu_migrate_helpers_module = Test::MockModule->new('PVE::QemuMigrate::Helpers');
 $qemu_migrate_helpers_module->mock('set_migration_caps', \&set_migration_caps);
 
@@ -453,6 +494,7 @@ $qemu_monitor_module->mock('qmp_cmd', \&qmp_cmd);
 my $qemu_config_module = Test::MockModule->new('PVE::QemuConfig');
 $qemu_config_module->mock('config_file_lock', \&config_file_lock);
 $qemu_config_module->mock('cfs_config_path', \&cfs_config_path);
+$qemu_config_module->mock('config_file', \&config_file);
 $qemu_config_module->mock('load_config', \&load_config);
 $qemu_config_module->mock('write_config', \&write_config);
 $qemu_config_module->mock('has_feature', \&has_feature);
@@ -641,6 +683,16 @@ testcase_create("303", "test", 1, "test comment", "storage activation failed\n\n
 
 $activate_storage_possible = 1;
 
+$real_write_config = 1;
+
+printf("Successful snapshot_create keeping the guest identity\n");
+testcase_create("401", "test", 0, "test comment", "", { "local:snapshotable-disk-1" => "test" });
+
+printf("Successful snapshot_create assigning a guest identity to a config without one\n");
+testcase_create("402", "test", 0, "test comment", "", { "local:snapshotable-disk-1" => "test" });
+
+$real_write_config = 0;
+
 $nodename = "delete";
 printf("\n");
 printf("Running delete tests\n");
@@ -777,6 +829,17 @@ testcase_rollback("303", "test", "storage activation failed\n");
 
 $activate_storage_possible = 1;
 
+$real_write_config = 1;
+
+printf("Successful snapshot_rollback keeping the current guest identity, not the snapshot's\n");
+testcase_rollback("401", "test", "", { "local:snapshotable-disk-1" => "test" });
+
+printf(
+    "Successful snapshot_rollback to a snapshot without meta info, keeping the guest identity\n");
+testcase_rollback("402", "test", "", { "local:snapshotable-disk-1" => "test" });
+
+$real_write_config = 0;
+
 done_testing();
 
 1;
-- 
2.47.3





^ permalink raw reply related	[relevance 15%]

* [PATCH cluster/guest-common/qemu-server/container/manager/docs 00/34] fix #7846: guest identity (uid) and cluster ID
@ 2026-11-16  0:46 19% Thomas Lamprecht
  2026-11-16  0:46 15% ` [PATCH qemu-server 14/34] fix #7846: config: add a guest identity to the 'meta' property Thomas Lamprecht
                   ` (3 more replies)
  0 siblings, 4 replies; 32+ results
From: Thomas Lamprecht @ 2026-11-16  0:46 UTC (permalink / raw)
  To: pve-devel

A VMID can be reused for another guest, and a guest can get another
VMID or move to another cluster through a restore or a remote
migration. So backup software and other tools cannot tell whether they
still look at the same guest, see [0].

This series gives every VM and container a guest identity in the
read-only 'meta' property: a random uid (100 bits as 20 base32
characters) and the time the guest was registered in the cluster. Create
and clone get a new uid. Config changes, migration, rollback, backup and
restore keep it, also under another VMID or in another cluster, as long
as no other guest there has it. Each cluster or standalone node also
gets a cluster ID in the same format, generated and protected by pmxcfs.
The docs patches describe the details.

Two behavior changes come with it:

* Restoring over an existing guest whose uid differs from the one of
  the backup is refused unless 'allow-identity-mismatch' is set. 'force'
  alone does not override this.
* Older versions drop the whole 'meta' property of a guest that has an
  identity. So migration and clone to such nodes is refused, and remote
  migration bumps the tunnel version. This also hits moves by the HA
  stack, which stops a container or a relocated VM before the migration
  gets refused. A target check in the LRM that avoids this will follow
  separately.

The patches are in dependency order: guest-common needs a pve-cluster
newer than 9.1.9, qemu-server and container need guest-common, and
manager needs all of them. manager also has to depend on the
qemu-server and container versions with this series, as the migration
guard takes the pve-manager version of a node as proof that the node
keeps the identity. MIN_PVE_MANAGER_VERSION in guest-common is a
stand-in for that pve-manager version.

Tested with the test suites of the repositories and end to end on a
nested three-node cluster that was upgraded node by node.

[0]: https://bugzilla.proxmox.com/show_bug.cgi?id=7846

cluster:

Thomas Lamprecht (7):
  pmxcfs: reject changes to the cluster ID file from user space
  pmxcfs: generate a cluster ID on standalone nodes
  pmxcfs: dfsm: add a callback that runs once all members are in sync
  pmxcfs: quorum: pass the corosync membership to an optional listener
  pmxcfs: dcdb: generate the cluster ID once the cluster is in sync
  cluster: add helper to read the cluster ID
  pmxcfs: allow removing the cluster ID file in forced local mode

 src/PVE/Cluster.pm          |  16 ++
 src/pmxcfs/Makefile         |  12 +-
 src/pmxcfs/cfs-plug-memdb.c |  46 ++++
 src/pmxcfs/cfs-utils.c      |   8 +
 src/pmxcfs/cfs-utils.h      |   5 +
 src/pmxcfs/check_dcdb.c     | 529 ++++++++++++++++++++++++++++++++++++
 src/pmxcfs/check_memdb.c    | 311 +++++++++++++++++++++
 src/pmxcfs/cluster-id.c     | 158 +++++++++++
 src/pmxcfs/cluster-id.h     |  52 ++++
 src/pmxcfs/dcdb.c           | 144 ++++++++++
 src/pmxcfs/dcdb.h           |   5 +
 src/pmxcfs/dfsm.c           |  58 ++++
 src/pmxcfs/dfsm.h           |  14 +
 src/pmxcfs/pmxcfs.c         |  10 +-
 src/pmxcfs/quorum.c         |  26 +-
 src/pmxcfs/quorum.h         |   8 +-
 src/pmxcfs/status.c         |  12 +
 src/pmxcfs/status.h         |   3 +
 src/test/Makefile           |   6 +-
 src/test/test_cluster_id.pl |  47 ++++
 20 files changed, 1458 insertions(+), 12 deletions(-)
 create mode 100644 src/pmxcfs/check_dcdb.c
 create mode 100644 src/pmxcfs/cluster-id.c
 create mode 100644 src/pmxcfs/cluster-id.h
 create mode 100644 src/test/test_cluster_id.pl


guest-common:

Thomas Lamprecht (4):
  guest identity: add helpers for the guest uid and registration time
  abstract config: assign a guest identity and keep it on config writes
  abstract config: let the VMID reservation return the previous state
  guest identity: allow taking over a uid that is unused in the cluster

 debian/control                     |    1 +
 src/Makefile                       |    1 +
 src/PVE/AbstractConfig.pm          |  235 +++++-
 src/PVE/GuestIdentity.pm           |  384 ++++++++++
 src/tests/Makefile                 |   10 +-
 src/tests/config-identity-tests.pl | 1090 ++++++++++++++++++++++++++++
 src/tests/guest-identity-tests.pl  |  421 +++++++++++
 7 files changed, 2135 insertions(+), 7 deletions(-)
 create mode 100644 src/PVE/GuestIdentity.pm
 create mode 100755 src/tests/config-identity-tests.pl
 create mode 100755 src/tests/guest-identity-tests.pl


qemu-server:

Thomas Lamprecht (6):
  api: restore: release the VMID if a restore to an unused VMID fails
  api: migrate, clone: refuse targets that would drop the guest identity
  fix #7846: config: add a guest identity to the 'meta' property
  restore: take over the guest uid from the backup where possible
  api: remote migration: take over the guest uid from the source
  api: status: return the guest uid

 src/PVE/API2/Qemu.pm                          | 104 +-
 src/PVE/CLI/qmrestore.pm                      |   7 +
 src/PVE/QemuConfig.pm                         |   7 +
 src/PVE/QemuMigrate.pm                        |   9 +-
 src/PVE/QemuServer.pm                         | 150 ++-
 src/PVE/QemuServer/MetaInfo.pm                |   2 +
 src/test/Makefile                             |   5 +-
 src/test/QemuServerTest/FakeCFS.pm            | 197 ++++
 .../q35-windows-pinning-identity-only.conf    |   6 +
 ...q35-windows-pinning-identity-only.conf.cmd |  26 +
 .../meta-identity-invalid.conf                |   6 +
 .../meta-identity-invalid.conf.strict.error   |   2 +
 .../meta-identity-invalid.conf                |   7 +
 .../parse-config-input/meta-identity.conf     |  20 +
 src/test/restore-config-expected/150.conf     |   9 +
 src/test/restore-config-input/150.conf        |  10 +
 src/test/run_api_tests.pl                     | 157 +++
 src/test/run_guest_identity_tests.pl          | 533 ++++++++++
 src/test/run_parse_config_tests.pl            |   2 +-
 src/test/run_qemu_restore_config_tests.pl     | 916 +++++++++++++++++-
 .../create/qemu-server/401.conf               |  31 +
 .../create/qemu-server/402.conf               |  31 +
 .../rollback/qemu-server/401.conf             |  36 +
 .../rollback/qemu-server/402.conf             |  35 +
 .../create/qemu-server/401.conf               |  13 +
 .../create/qemu-server/402.conf               |  13 +
 .../rollback/qemu-server/401.conf             |  35 +
 .../rollback/qemu-server/402.conf             |  34 +
 src/test/snapshot-test.pm                     |  85 +-
 29 files changed, 2439 insertions(+), 49 deletions(-)
 create mode 100644 src/test/QemuServerTest/FakeCFS.pm
 create mode 100644 src/test/cfg2cmd/q35-windows-pinning-identity-only.conf
 create mode 100644 src/test/cfg2cmd/q35-windows-pinning-identity-only.conf.cmd
 create mode 100644 src/test/parse-config-expected/meta-identity-invalid.conf
 create mode 100644 src/test/parse-config-expected/meta-identity-invalid.conf.strict.error
 create mode 100644 src/test/parse-config-input/meta-identity-invalid.conf
 create mode 100644 src/test/parse-config-input/meta-identity.conf
 create mode 100644 src/test/restore-config-expected/150.conf
 create mode 100644 src/test/restore-config-input/150.conf
 create mode 100755 src/test/run_guest_identity_tests.pl
 create mode 100644 src/test/snapshot-expected/create/qemu-server/401.conf
 create mode 100644 src/test/snapshot-expected/create/qemu-server/402.conf
 create mode 100644 src/test/snapshot-expected/rollback/qemu-server/401.conf
 create mode 100644 src/test/snapshot-expected/rollback/qemu-server/402.conf
 create mode 100644 src/test/snapshot-input/create/qemu-server/401.conf
 create mode 100644 src/test/snapshot-input/create/qemu-server/402.conf
 create mode 100644 src/test/snapshot-input/rollback/qemu-server/401.conf
 create mode 100644 src/test/snapshot-input/rollback/qemu-server/402.conf


container:

Thomas Lamprecht (8):
  config: add read-only meta property with the creation time
  fix #7846: config: add a guest identity to the 'meta' property
  api: migrate, clone: refuse targets that would drop the guest identity
  restore: take over the guest uid from the backup where possible
  restore: refuse overwriting a container with another guest's backup
  migrate: remote: clean up the target on a tunnel version mismatch
  api: remote migration: take over the guest uid from the source
  api: status: return the guest uid

 src/PVE/API2/LXC.pm         |  166 +++-
 src/PVE/API2/LXC/Config.pm  |   29 +-
 src/PVE/API2/LXC/Status.pm  |   10 +
 src/PVE/LXC/Config.pm       |   63 +-
 src/PVE/LXC/Migrate.pm      |   31 +-
 src/test/Makefile           |    8 +-
 src/test/config_tests.pl    |   23 +
 src/test/lifecycle_tests.pl | 1878 +++++++++++++++++++++++++++++++++++
 8 files changed, 2177 insertions(+), 31 deletions(-)
 create mode 100755 src/test/lifecycle_tests.pl


manager:

Thomas Lamprecht (5):
  api: cluster resources: add guest uid and registration time
  api: cluster status: add cluster ID
  ui: restore: allow overwriting a guest with a backup of another guest
  ui: migrate: refuse target nodes that would drop the guest identity
  ui: guest summary: show the guest identity

 PVE/API2/Cluster.pm                      |  35 +++-
 test/ClusterResources_test.pl            | 249 +++++++++++++++++++++++
 test/ClusterStatus_test.pl               | 114 +++++++++++
 test/Makefile                            |  10 +-
 www/manager6/Makefile                    |   1 +
 www/manager6/panel/GuestIdentity.js      | 142 +++++++++++++
 www/manager6/panel/GuestStatusView.js    |   3 +
 www/manager6/panel/TemplateStatusView.js |   3 +
 www/manager6/window/Migrate.js           |  29 +++
 www/manager6/window/Restore.js           |  18 ++
 10 files changed, 602 insertions(+), 2 deletions(-)
 create mode 100755 test/ClusterResources_test.pl
 create mode 100755 test/ClusterStatus_test.pl
 create mode 100644 www/manager6/panel/GuestIdentity.js


docs:

Thomas Lamprecht (4):
  vzdump: describe the guest identity of VMs and containers
  pvecm: document the cluster ID and how to get a new one
  qm: configuration: describe the read-only meta property
  pct: configuration: describe the read-only meta property

 pct.adoc    |  35 +++++++
 pmxcfs.adoc |   1 +
 pvecm.adoc  |  86 +++++++++++++++++
 qm.adoc     |  38 ++++++++
 vzdump.adoc | 259 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 419 insertions(+)


Summary over all repositories:
  79 files changed, 9230 insertions(+), 101 deletions(-)

-- 
2.47.3





^ permalink raw reply	[relevance 19%]

Results 1-32 of 32 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2026-11-16  0:46 19% [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 15% ` [PATCH qemu-server 14/34] fix #7846: config: add a guest identity to the 'meta' property Thomas Lamprecht
2026-11-16  0:46 15% ` [PATCH docs 31/34] vzdump: describe the guest identity of VMs and containers Thomas Lamprecht
2026-11-17 10:47 15% ` [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 16%   ` Thomas Lamprecht
2026-11-17 11:55 15%     ` Dominik Csapak
2026-11-17 12:47 13%       ` Thomas Lamprecht
2026-11-17 13:54 14%         ` Dominik Csapak
2026-11-17 15:55 13% ` Dominik Csapak
2026-11-17 22:34 18% [PATCH cluster/guest-common/qemu-server/container/manager/docs v2 00/36] " Thomas Lamprecht
2026-11-17 22:34 22% ` [PATCH guest-common v2 08/36] guest identity: add helpers for the guest uid and registration time Thomas Lamprecht
2026-11-17 22:34 15% ` [PATCH qemu-server v2 14/36] fix #7846: config: add a guest identity to the 'meta' property Thomas Lamprecht
2026-11-17 22:34 16% ` [PATCH docs v2 33/36] vzdump: describe the guest identity of VMs and containers Thomas Lamprecht
2026-11-18  5:57 11% ` superseded: [PATCH cluster/guest-common/qemu-server/container/manager/docs v2 00/36] fix #7846: guest identity (uid) and cluster ID Thomas Lamprecht
2026-11-18  4:37 18% [PATCH cluster/guest-common/qemu-server/container/manager/docs v3 00/38] " Thomas Lamprecht
2026-11-18  4:37 22% ` [PATCH guest-common v3 09/38] guest identity: add helpers for the guest uid and registration time Thomas Lamprecht
2026-11-18  4:37 15% ` [PATCH qemu-server v3 16/38] fix #7846: config: add a guest identity to the 'meta' property Thomas Lamprecht
2026-11-18  4:37 16% ` [PATCH docs v3 35/38] vzdump: describe the guest identity of VMs and containers Thomas Lamprecht
2026-11-18 13:49 17% ` [PATCH cluster/guest-common/qemu-server/container/manager/docs v3 00/38] fix #7846: guest identity (uid) and cluster ID Dominik Csapak
2026-11-18 14:13 15%   ` Thomas Lamprecht
2026-11-19 10:38 11% ` superseded: " Thomas Lamprecht
2026-11-19 10:33 17% [PATCH cluster/guest-common/qemu-server/container/manager/docs v4 00/41] " Thomas Lamprecht
2026-11-19 10:33 22% ` [PATCH guest-common v4 08/41] guest identity: add helpers for the guest uid and registration time Thomas Lamprecht
2026-11-19 10:34 16% ` [PATCH qemu-server v4 16/41] fix #7846: config: add a guest identity to the 'meta' property Thomas Lamprecht
2026-11-19 10:34 17% ` [PATCH docs v4 37/41] vzdump: describe the guest identity of VMs and containers Thomas Lamprecht
2026-11-19 14:46 17% ` [PATCH cluster/guest-common/qemu-server/container/manager/docs v4 00/41] fix #7846: guest identity (uid) and cluster ID Dominik Csapak
2026-11-19 19:49 11% ` superseded: " Thomas Lamprecht
2026-11-19 19:18 17% [PATCH cluster/guest-common/qemu-server/container/manager/docs v5 " Thomas Lamprecht
2026-11-19 19:18 22% ` [PATCH guest-common v5 08/41] guest identity: add helpers for the guest uid and registration time Thomas Lamprecht
2026-11-19 19:18 16% ` [PATCH qemu-server v5 16/41] fix #7846: config: add a guest identity to the 'meta' property Thomas Lamprecht
2026-11-19 19:19 17% ` [PATCH docs v5 37/41] vzdump: describe the guest identity of VMs and containers Thomas Lamprecht
2026-11-20  3:07 21% ` [PATCH cluster/guest-common/qemu-server/container/manager/docs v5 00/41] fix #7846: guest identity (uid) and cluster ID Thomas Lamprecht

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal