public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Fiona Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH librados2-perl 1/3] refactor pverados worker into dedicated function
Date: Tue,  8 Aug 2023 13:23:10 +0200	[thread overview]
Message-ID: <20230808112312.64667-2-f.ebner@proxmox.com> (raw)
In-Reply-To: <20230808112312.64667-1-f.ebner@proxmox.com>

No functional change intended.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---

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





  reply	other threads:[~2023-08-08 11:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-08 11:23 [pve-devel] [PATCH-SERIES librados2-perl] improve fork behavior Fiona Ebner
2023-08-08 11:23 ` Fiona Ebner [this message]
2023-08-08 11:23 ` [pve-devel] [PATCH librados2-perl 2/3] reset inherited signal handlers in child worker Fiona Ebner
2023-08-08 11:23 ` [pve-devel] [PATCH librados2-perl 3/3] use POSIX::_exit instead of exit in forked child Fiona Ebner
2023-08-11  7:13 ` [pve-devel] applied-series: [PATCH-SERIES librados2-perl] improve fork behavior Wolfgang Bumiller

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=20230808112312.64667-2-f.ebner@proxmox.com \
    --to=f.ebner@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