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 18EC8AE41 for ; Tue, 8 Aug 2023 13:23:17 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 0060A8CC4 for ; Tue, 8 Aug 2023 13:23:17 +0200 (CEST) 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 ; Tue, 8 Aug 2023 13:23:16 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 229F043776 for ; Tue, 8 Aug 2023 13:23:16 +0200 (CEST) From: Fiona Ebner To: pve-devel@lists.proxmox.com Date: Tue, 8 Aug 2023 13:23:10 +0200 Message-Id: <20230808112312.64667-2-f.ebner@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230808112312.64667-1-f.ebner@proxmox.com> References: <20230808112312.64667-1-f.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.053 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 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [rados.pm] Subject: [pve-devel] [PATCH librados2-perl 1/3] refactor pverados worker into dedicated function 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, 08 Aug 2023 11:23:17 -0000 No functional change intended. Signed-off-by: Fiona Ebner --- Better viewed with git diff --color-moved=zebra --color-moved-ws=ignore-all-space or similar PVE/RADOS.pm | 116 +++++++++++++++++++++++++++------------------------ 1 file changed, 61 insertions(+), 55 deletions(-) diff --git a/PVE/RADOS.pm b/PVE/RADOS.pm index aba6653..162e7db 100644 --- a/PVE/RADOS.pm +++ b/PVE/RADOS.pm @@ -105,6 +105,66 @@ my $sendcmd = sub { return $raw; }; +sub pve_rados_work { + my ($self, $parent, $timeout, %params) = @_; + + my $conn; + eval { + my $ceph_user = delete $params{userid} || $ceph_default_user; + $conn = pve_rados_create($ceph_user) || + die "unable to create RADOS object\n"; + + if (defined($params{ceph_conf}) && (!-e $params{ceph_conf})) { + die "Supplied ceph config doesn't exist, $params{ceph_conf}\n"; + } + + my $ceph_conf = delete $params{ceph_conf} || $ceph_default_conf; + + if (-e $ceph_conf) { + pve_rados_conf_read_file($conn, $ceph_conf); + } + + pve_rados_conf_set($conn, 'client_mount_timeout', $timeout); + + foreach my $k (keys %params) { + pve_rados_conf_set($conn, $k, $params{$k}); + } + + pve_rados_connect($conn); + }; + if (my $err = $@) { + &$writedata($parent, 'E', $err); + die $err; + } + &$writedata($parent, 'S'); + + $self->{conn} = $conn; + + for (;;) { + my ($cmd, $data) = &$readdata($parent, 1); + + last if !$cmd || $cmd eq 'Q'; + + my $res; + eval { + if ($cmd eq 'M') { # rados monitor commands + $res = encode_json(pve_rados_mon_command($self->{conn}, [ $data ])); + } elsif ($cmd eq 'C') { # class methods + my $aref = decode_json($data); + my $method = shift @$aref; + $res = encode_json($self->$method(@$aref)); + } else { + die "invalid command\n"; + } + }; + if (my $err = $@) { + &$writedata($parent, 'E', $err); + die $err; + } + &$writedata($parent, '>', $res); + } +} + sub new { my ($class, %params) = @_; @@ -145,61 +205,7 @@ sub new { close $child; - my $conn; - eval { - my $ceph_user = delete $params{userid} || $ceph_default_user; - $conn = pve_rados_create($ceph_user) || - die "unable to create RADOS object\n"; - - if (defined($params{ceph_conf}) && (!-e $params{ceph_conf})) { - die "Supplied ceph config doesn't exist, $params{ceph_conf}\n"; - } - - my $ceph_conf = delete $params{ceph_conf} || $ceph_default_conf; - - if (-e $ceph_conf) { - pve_rados_conf_read_file($conn, $ceph_conf); - } - - pve_rados_conf_set($conn, 'client_mount_timeout', $timeout); - - foreach my $k (keys %params) { - pve_rados_conf_set($conn, $k, $params{$k}); - } - - pve_rados_connect($conn); - }; - if (my $err = $@) { - &$writedata($parent, 'E', $err); - die $err; - } - &$writedata($parent, 'S'); - - $self->{conn} = $conn; - - for (;;) { - my ($cmd, $data) = &$readdata($parent, 1); - - last if !$cmd || $cmd eq 'Q'; - - my $res; - eval { - if ($cmd eq 'M') { # rados monitor commands - $res = encode_json(pve_rados_mon_command($self->{conn}, [ $data ])); - } elsif ($cmd eq 'C') { # class methods - my $aref = decode_json($data); - my $method = shift @$aref; - $res = encode_json($self->$method(@$aref)); - } else { - die "invalid command\n"; - } - }; - if (my $err = $@) { - &$writedata($parent, 'E', $err); - die $err; - } - &$writedata($parent, '>', $res); - } + $self->pve_rados_work($parent, $timeout, %params); exit(0); } -- 2.39.2