public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>,
	Max Carrara <m.carrara@proxmox.com>
Subject: [pve-devel] applied: [PATCH v2 pve-manager 1/2] fix #5198: ceph: mon: fix mon existence check in mon removal assertion
Date: Thu, 21 Mar 2024 18:14:57 +0100	[thread overview]
Message-ID: <fc14609f-e26a-4dab-a37c-95a9c92ac1eb@proxmox.com> (raw)
In-Reply-To: <20240314101930.198214-1-m.carrara@proxmox.com>

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 <m.carrara@proxmox.com>
> ---

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 "...";
}






      parent reply	other threads:[~2024-03-21 17:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-14 10:19 [pve-devel] " Max Carrara
2024-03-14 10:19 ` [pve-devel] [PATCH v2 pve-manager 2/2] ceph: mon: adapt code style " Max Carrara
2024-03-21 17:14 ` Thomas Lamprecht [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fc14609f-e26a-4dab-a37c-95a9c92ac1eb@proxmox.com \
    --to=t.lamprecht@proxmox.com \
    --cc=m.carrara@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal