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 5378F629D4 for ; Tue, 22 Feb 2022 13:42:33 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 4A38B242C7 for ; Tue, 22 Feb 2022 13:42:33 +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 id A014B242BC for ; Tue, 22 Feb 2022 13:42:32 +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 72A1346331 for ; Tue, 22 Feb 2022 13:42:32 +0100 (CET) Message-ID: <5683f184-4159-b330-c278-c8557b551821@proxmox.com> Date: Tue, 22 Feb 2022 13:42:31 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Content-Language: en-US To: Thomas Lamprecht , Proxmox VE development discussion References: <20220218113827.1415641-1-a.lauterer@proxmox.com> <20220218113827.1415641-3-a.lauterer@proxmox.com> From: Aaron Lauterer In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.012 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment NICE_REPLY_A -0.001 Looks like a legit reply (A) 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: Re: [pve-devel] [PATCH librados2-perl 2/6] mon_command: optionally ignore errors and return hashmap 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: Tue, 22 Feb 2022 12:42:33 -0000 On 2/21/22 16:44, Thomas Lamprecht wrote: > On 18.02.22 12:38, Aaron Lauterer wrote: >> This patch requires patch 3 of the series to not break OSD removal! >> Therefore releasing a new version of librados2-perl and pve-manager >> needs to be coordinated. > > I don't like that and think it can be avoided. I'll look into it again. >> [...] >> sub mon_command { >> - my ($self, $cmd) = @_; >> + my ($self, $cmd, $noerr) = @_; >> + >> + $noerr = 0 if !$noerr; >> >> $cmd->{format} = 'json' if !$cmd->{format}; >> >> my $json = encode_json($cmd); >> >> - my $raw = eval { $sendcmd->($self, 'M', $json) }; >> + my $ret = eval { $sendcmd->($self, 'M', $json, undef, $noerr) }; > > I'd rather like to avoid chaining through that $noerr every where, rather pass all the > info via the die (errors can be references to structured data too, like PVE::Exception is), > or just avoid the die at the lower level completely and map the error inside the struct > too, it can then be thrown here, depending on $noerr parameters or what not. Okay, definitely sounds like the cleaner approach. >> [...] >> - if (ret < 0) { >> + if (ret < 0 && noerr == false) { >> char msg[4096]; >> if (outslen > sizeof(msg)) { >> outslen = sizeof(msg); >> @@ -142,9 +143,22 @@ CODE: >> die(msg); >> } >> >> - RETVAL = newSVpv(outbuf, outbuflen); >> + char status[(int)outslen + 1]; > > this is on the stack and could be to large to guarantee it always fits, but... > >> + if (outslen > sizeof(status)) { >> + outslen = sizeof(status); >> + } >> + snprintf(status, sizeof(status), "%.*s\n", (int)outslen, outs); > > ...why not just chain outs through instead of re-allocating it and writing it out in a > relatively expensive way? > Yeah, will do that.