From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 3FC521FF0AB for ; Wed, 23 Sep 2026 09:52:16 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 2FE3F21487; Wed, 23 Sep 2026 09:52:15 +0200 (CEST) Message-ID: Date: Wed, 23 Sep 2026 09:52:10 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH pve-guest-common v5 3/7] add module to track previously used guest IDs To: =?UTF-8?Q?Michael_K=C3=B6ppl?= , pve-devel@lists.proxmox.com References: <20260921155410.938337-1-m.koeppl@proxmox.com> <20260921155410.938337-4-m.koeppl@proxmox.com> <0ee919d3-7ff6-4905-ae82-c348f8445037@proxmox.com> Content-Language: en-US From: Fiona Ebner In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1790149930991 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.373 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) POISEN_SPAM_PILL 0.1 Meta: its spam POISEN_SPAM_PILL_1 0.1 random spam to be learned in bayes POISEN_SPAM_PILL_3 0.1 random spam to be learned in bayes RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: WV5H4AQSPRSKIHRHAITSMUKRWQAQV6YE X-Message-ID-Hash: WV5H4AQSPRSKIHRHAITSMUKRWQAQV6YE X-MailFrom: f.ebner@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Am 22.09.26 um 5:55 PM schrieb Michael Köppl: > On Tue Sep 22, 2026 at 4:22 PM CEST, Fiona Ebner wrote: >>> + my ($filename, $raw) = @_; >>> + >>> + my $used_ids = {}; >>> + >>> + return $used_ids if !defined($raw); >>> + >>> + for my $line (split(/\n/, $raw)) { >>> + next if $line =~ m/^\s*$/; >>> + >>> + if ($line =~ m/^(\d+)$/) { >>> + $used_ids->{$1} = 1; >>> + } elsif ($line =~ m/^(\d+)-(\d+)$/) { >>> + my ($start, $end) = ($1, $2); >>> + if ($start > $end) { >>> + warn "skipping reversed range in $filename: $line\n"; >>> + next; >>> + } >>> + $used_ids->{$_} = 1 for $start .. $end; >> >> Nit: we could be smarter and avoid adding every single ID to the hash >> (with a lot of (past) guests that can become a non-trivial cost), and >> instead track ranges. Instead of having a public read_list() function >> then, there could be a check_id_unused() function. When writing out the >> file we can still merge adjacent ranges. > > Thanks for pointing this out! I think the range approach is a good idea! > Should we have a public function that returns the end of a range for a > given guest ID instead of the boolean check_id_unused()? We could then > use it to skip ranges when searching for a free guest ID at > /cluster/nextid instead of invoking cfs_read_file() for each check if a > candidate ID is available. Something like this: > > my $i = $lower; > while ($i < $upper) { > if (defined($idlist->{$i})) { $i++; next; } > if ($check_unique) { > if (defined(my $end = > PVE::UsedGuestIDs::get_used_range_end($i))) { > $i = $end + 1; > next; > } > } > return $i; > } Yes. Or have the function return the next free ID equal to or bigger than the input directly?