From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 7C1C5BADB3 for ; Thu, 21 Mar 2024 18:15:30 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 56C4032938 for ; Thu, 21 Mar 2024 18:15:00 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Thu, 21 Mar 2024 18:14:59 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id E82C740EF9 for ; Thu, 21 Mar 2024 18:14:58 +0100 (CET) Message-ID: Date: Thu, 21 Mar 2024 18:14:57 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Beta From: Thomas Lamprecht To: Proxmox VE development discussion , Max Carrara References: <20240314101930.198214-1-m.carrara@proxmox.com> Content-Language: en-GB In-Reply-To: <20240314101930.198214-1-m.carrara@proxmox.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.054 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pve-devel] applied: [PATCH v2 pve-manager 1/2] fix #5198: ceph: mon: fix mon existence check in mon removal assertion X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Mar 2024 17:15:30 -0000 Am 14/03/2024 um 11:19 schrieb Max Carrara: > The Ceph monitor removal assertion contains a condition that checks > whether the given mon ID actually exists and thus may be removed. > > The first part of the condition checks whether the hash returned by > `get_services_info` [0] contains the key "mon.$monid". However, the > hash's keys are never prefixed with "mon.", which makes this check > incorrect. > > This is fixed by just using "$monid" directly. > > The second part checks whether the mon hashes returned by > Ceph contain the "name" key before comparing the key with the given > mon ID. This key existence check is also incorrect; in particular: > * If the lookup `$_->{name}` evaluates to e.g. "foo", the check > passes, because "foo" is truthy. [1] > * If the lookup `$_->{name}` evaluates to "0", the check fails, > because "0" is falsy (due to it being equivalent to the number 0, > according to Perl [1]). > > This is solved by using the inbuilt `defined()` instead of relying on > Perl's definition of truthiness. > > [0]: https://git.proxmox.com/?p=pve-manager.git;a=blob;f=PVE/Ceph/Services.pm;h=e0f31e8eb6bc9b3777b3d0d548497276efaa5c41;hb=HEAD#l112 > [1]: https://perldoc.perl.org/perldata#Scalar-values > > Fixes: https://bugzilla.proxmox.com/show_bug.cgi?id=5198 > Signed-off-by: Max Carrara > --- having the changes since v1 listed here would be nice. > PVE/API2/Ceph/MON.pm | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/PVE/API2/Ceph/MON.pm b/PVE/API2/Ceph/MON.pm > index 1e959ef3..057ca70d 100644 > --- a/PVE/API2/Ceph/MON.pm > +++ b/PVE/API2/Ceph/MON.pm > @@ -147,8 +147,8 @@ my $assert_mon_prerequisites = sub { > my $assert_mon_can_remove = sub { > my ($monhash, $monlist, $monid, $mondir) = @_; > > - if (!(defined($monhash->{"mon.$monid"}) || > - grep { $_->{name} && $_->{name} eq $monid } @$monlist)) > + if (!(defined($monhash->{$monid}) || > + grep { defined($_->{name}) && $_->{name} eq $monid } @$monlist)) > { applied, thanks! I squashed into your clean-up patch 2/2 another style fix, namely for long if expressions: if ( !(defined($monhash->{$monid}) || grep { defined($_->{name}) && $_->{name} eq $monid } $monlist->@*)) ) { die "..."; }