public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Max Carrara <m.carrara@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [RFC pve-storage 33/36] plugin: rbd: update private sub signatures and make helpers private
Date: Wed, 17 Jul 2024 11:40:31 +0200	[thread overview]
Message-ID: <20240717094034.124857-34-m.carrara@proxmox.com> (raw)
In-Reply-To: <20240717094034.124857-1-m.carrara@proxmox.com>

Instead of assigning anonymous subs to a reference, make them "proper"
private subs instead. Thus, signatures like

  my $foo = sub { ... };

are changed to

  my sub foo { ... }

and their call sites are updated correspondingly.

The remaining helpers are also made private, because they're not used
anywhere else in our code.

Signed-off-by: Max Carrara <m.carrara@proxmox.com>
---
 src/PVE/Storage/RBDPlugin.pm | 84 ++++++++++++++++++------------------
 1 file changed, 42 insertions(+), 42 deletions(-)

diff --git a/src/PVE/Storage/RBDPlugin.pm b/src/PVE/Storage/RBDPlugin.pm
index f45ad3f..919b9f9 100644
--- a/src/PVE/Storage/RBDPlugin.pm
+++ b/src/PVE/Storage/RBDPlugin.pm
@@ -20,13 +20,13 @@ use PVE::Tools qw(run_command trim file_read_firstline);
 
 use base qw(PVE::Storage::Plugin);
 
-my $get_parent_image_name = sub {
+my sub get_parent_image_name {
     my ($parent) = @_;
     return undef if !$parent;
     return $parent->{image} . "@" . $parent->{snapshot};
 };
 
-my $librados_connect = sub {
+my sub librados_connect {
     my ($scfg, $storeid, $options) = @_;
 
     $options->{timeout} = 60
@@ -55,7 +55,7 @@ my sub get_rbd_dev_path {
 	# NOTE: the config doesn't support this currently (but it could!), hack for qemu-server tests
 	$cluster_id = $scfg->{fsid};
     } elsif ($scfg->{monhost}) {
-	my $rados = $librados_connect->($scfg, $storeid);
+	my $rados = librados_connect($scfg, $storeid);
 	$cluster_id = $rados->mon_command({ prefix => 'fsid', format => 'json' })->{fsid};
     } else {
 	$cluster_id = cfs_read_file('ceph.conf')->{global}->{fsid};
@@ -82,7 +82,7 @@ my sub get_rbd_dev_path {
     return $pve_path;
 }
 
-my $build_cmd = sub {
+my sub build_cmd {
     my ($binary, $scfg, $storeid, $op, @options) = @_;
 
     my $cmd_option = PVE::CephConfig::ceph_connect_option($scfg, $storeid);
@@ -110,20 +110,20 @@ my $build_cmd = sub {
     return $cmd;
 };
 
-my $rbd_cmd = sub {
+my sub rbd_cmd {
     my ($scfg, $storeid, $op, @options) = @_;
 
-    return $build_cmd->('/usr/bin/rbd', $scfg, $storeid, $op, @options);
+    return build_cmd('/usr/bin/rbd', $scfg, $storeid, $op, @options);
 };
 
-my $rados_cmd = sub {
+my sub rados_cmd {
     my ($scfg, $storeid, $op, @options) = @_;
 
-    return $build_cmd->('/usr/bin/rados', $scfg, $storeid, $op, @options);
+    return build_cmd('/usr/bin/rados', $scfg, $storeid, $op, @options);
 };
 
 # needed for volumes created using ceph jewel (or higher)
-my $krbd_feature_update = sub {
+my sub krbd_feature_update {
     my ($scfg, $storeid, $name) = @_;
 
     my (@disable, @enable);
@@ -150,7 +150,7 @@ my $krbd_feature_update = sub {
 
     if ($to_disable) {
 	print "disable RBD image features this kernel RBD drivers is not compatible with: $to_disable\n";
-	my $cmd = $rbd_cmd->($scfg, $storeid, 'feature', 'disable', $name, $to_disable);
+	my $cmd = rbd_cmd($scfg, $storeid, 'feature', 'disable', $name, $to_disable);
 	run_rbd_command(
 	    $cmd,
 	    errmsg => "could not disable krbd-incompatible image features '$to_disable' for rbd image: $name",
@@ -159,7 +159,7 @@ my $krbd_feature_update = sub {
     if ($to_enable) {
 	print "enable RBD image features this kernel RBD drivers supports: $to_enable\n";
 	eval {
-	    my $cmd = $rbd_cmd->($scfg, $storeid, 'feature', 'enable', $name, $to_enable);
+	    my $cmd = rbd_cmd($scfg, $storeid, 'feature', 'enable', $name, $to_enable);
 	    run_rbd_command(
 		$cmd,
 		errmsg => "could not enable krbd-compatible image features '$to_enable' for rbd image: $name",
@@ -169,7 +169,7 @@ my $krbd_feature_update = sub {
     }
 };
 
-sub run_rbd_command {
+my sub run_rbd_command {
     my ($cmd, %args) = @_;
 
     my $lasterr;
@@ -198,7 +198,7 @@ sub run_rbd_command {
     return undef;
 }
 
-sub rbd_ls {
+my sub rbd_ls {
     my ($scfg, $storeid) = @_;
 
     my $pool =  $scfg->{pool} ? $scfg->{pool} : 'rbd';
@@ -207,7 +207,7 @@ sub rbd_ls {
     my $raw = '';
     my $parser = sub { $raw .= shift };
 
-    my $cmd = $rbd_cmd->($scfg, $storeid, 'ls', '-l', '--format', 'json');
+    my $cmd = rbd_cmd($scfg, $storeid, 'ls', '-l', '--format', 'json');
     eval {
 	run_rbd_command($cmd, errmsg => "rbd error", errfunc => sub {}, outfunc => $parser);
     };
@@ -237,7 +237,7 @@ sub rbd_ls {
 	$list->{$pool}->{$image} = {
 	    name => $image,
 	    size => $el->{size},
-	    parent => $get_parent_image_name->($el->{parent}),
+	    parent => get_parent_image_name($el->{parent}),
 	    vmid => $owner
 	};
     }
@@ -245,10 +245,10 @@ sub rbd_ls {
     return $list;
 }
 
-sub rbd_ls_snap {
+my sub rbd_ls_snap {
     my ($scfg, $storeid, $name) = @_;
 
-    my $cmd = $rbd_cmd->($scfg, $storeid, 'snap', 'ls', $name, '--format', 'json');
+    my $cmd = rbd_cmd($scfg, $storeid, 'snap', 'ls', $name, '--format', 'json');
 
     my $raw = '';
     run_rbd_command($cmd, errmsg => "rbd error", errfunc => sub {}, outfunc => sub { $raw .= shift; });
@@ -277,7 +277,7 @@ sub rbd_ls_snap {
     return $res;
 }
 
-sub rbd_volume_info {
+my sub rbd_volume_info {
     my ($scfg, $storeid, $volname, $snap) = @_;
 
     my $cmd = undef;
@@ -287,7 +287,7 @@ sub rbd_volume_info {
 	push @options, '--snap', $snap;
     }
 
-    $cmd = $rbd_cmd->($scfg, $storeid, @options);
+    $cmd = rbd_cmd($scfg, $storeid, @options);
 
     my $raw = '';
     my $parser = sub { $raw .= shift };
@@ -303,17 +303,17 @@ sub rbd_volume_info {
 	die "got unexpected data from rbd info: '$raw'\n";
     }
 
-    $volume->{parent} = $get_parent_image_name->($volume->{parent});
+    $volume->{parent} = get_parent_image_name($volume->{parent});
     $volume->{protected} = defined($volume->{protected}) && $volume->{protected} eq "true" ? 1 : undef;
 
     return $volume->@{qw(size parent format protected features)};
 }
 
-sub rbd_volume_du {
+my sub rbd_volume_du {
     my ($scfg, $storeid, $volname) = @_;
 
     my @options = ('du', $volname, '--format', 'json');
-    my $cmd = $rbd_cmd->($scfg, $storeid, @options);
+    my $cmd = rbd_cmd($scfg, $storeid, @options);
 
     my $raw = '';
     my $parser = sub { $raw .= shift };
@@ -484,7 +484,7 @@ sub path {
 sub find_free_diskname {
     my ($class, $storeid, $scfg, $vmid, $fmt, $add_fmt_suffix) = @_;
 
-    my $cmd = $rbd_cmd->($scfg, $storeid, 'ls');
+    my $cmd = rbd_cmd($scfg, $storeid, 'ls');
 
     my $disk_list = [];
 
@@ -528,7 +528,7 @@ sub create_base {
 
     my $newvolname = $basename ? "$basename/$newname" : "$newname";
 
-    my $cmd = $rbd_cmd->(
+    my $cmd = rbd_cmd(
 	$scfg,
 	$storeid,
 	'rename',
@@ -547,7 +547,7 @@ sub create_base {
     my (undef, undef, undef, $protected) = rbd_volume_info($scfg, $storeid, $newname, $snap);
 
     if (!$protected){
-	my $cmd = $rbd_cmd->($scfg, $storeid, 'snap', 'protect', $newname, '--snap', $snap);
+	my $cmd = rbd_cmd($scfg, $storeid, 'snap', 'protect', $newname, '--snap', $snap);
 	run_rbd_command($cmd, errmsg => "rbd protect $newname snap '$snap' error");
     }
 
@@ -575,7 +575,7 @@ sub clone_image {
 	my (undef, undef, undef, $protected) = rbd_volume_info($scfg, $storeid, $volname, $snapname);
 
 	if (!$protected) {
-	    my $cmd = $rbd_cmd->($scfg, $storeid, 'snap', 'protect', $volname, '--snap', $snapname);
+	    my $cmd = rbd_cmd($scfg, $storeid, 'snap', 'protect', $volname, '--snap', $snapname);
 	    run_rbd_command($cmd, errmsg => "rbd protect $volname snap $snapname error");
 	}
     }
@@ -589,7 +589,7 @@ sub clone_image {
     );
     push @options, ('--data-pool', $scfg->{'data-pool'}) if $scfg->{'data-pool'};
 
-    my $cmd = $rbd_cmd->($scfg, $storeid, 'clone', @options, get_rbd_path($scfg, $name));
+    my $cmd = rbd_cmd($scfg, $storeid, 'clone', @options, get_rbd_path($scfg, $name));
     run_rbd_command($cmd, errmsg => "rbd clone '$basename' error");
 
     return $newvol;
@@ -610,7 +610,7 @@ sub alloc_image {
     );
     push @options, ('--data-pool', $scfg->{'data-pool'}) if $scfg->{'data-pool'};
 
-    my $cmd = $rbd_cmd->($scfg, $storeid, 'create', @options, $name);
+    my $cmd = rbd_cmd($scfg, $storeid, 'create', @options, $name);
     run_rbd_command($cmd, errmsg => "rbd create '$name' error");
 
     return $name;
@@ -626,17 +626,17 @@ sub free_image {
     my $snaps = rbd_ls_snap($scfg, $storeid, $name);
     foreach my $snap (keys %$snaps) {
 	if ($snaps->{$snap}->{protected}) {
-	    my $cmd = $rbd_cmd->($scfg, $storeid, 'snap', 'unprotect', $name, '--snap', $snap);
+	    my $cmd = rbd_cmd($scfg, $storeid, 'snap', 'unprotect', $name, '--snap', $snap);
 	    run_rbd_command($cmd, errmsg => "rbd unprotect $name snap '$snap' error");
 	}
     }
 
     $class->deactivate_volume($storeid, $scfg, $volname);
 
-    my $cmd = $rbd_cmd->($scfg, $storeid, 'snap', 'purge',  $name);
+    my $cmd = rbd_cmd($scfg, $storeid, 'snap', 'purge',  $name);
     run_rbd_command($cmd, errmsg => "rbd snap purge '$name' error");
 
-    $cmd = $rbd_cmd->($scfg, $storeid, 'rm', $name);
+    $cmd = rbd_cmd($scfg, $storeid, 'rm', $name);
     run_rbd_command($cmd, errmsg => "rbd rm '$name' error");
 
     return undef;
@@ -679,7 +679,7 @@ sub list_images {
 sub status {
     my ($class, $storeid, $scfg, $cache) = @_;
 
-    my $rados = $librados_connect->($scfg, $storeid);
+    my $rados = librados_connect($scfg, $storeid);
     my $df = $rados->mon_command({ prefix => 'df', format => 'json' });
 
     my $pool = $scfg->{'data-pool'} // $scfg->{pool} // 'rbd';
@@ -724,9 +724,9 @@ sub map_volume {
     return $kerneldev if -b $kerneldev; # already mapped
 
     # features can only be enabled/disabled for image, not for snapshot!
-    $krbd_feature_update->($scfg, $storeid, $img_name);
+    krbd_feature_update($scfg, $storeid, $img_name);
 
-    my $cmd = $rbd_cmd->($scfg, $storeid, 'map', $name);
+    my $cmd = rbd_cmd($scfg, $storeid, 'map', $name);
     run_rbd_command($cmd, errmsg => "can't map rbd volume $name");
 
     return $kerneldev;
@@ -741,7 +741,7 @@ sub unmap_volume {
     my $kerneldev = get_rbd_dev_path($scfg, $storeid, $name);
 
     if (-b $kerneldev) {
-	my $cmd = $rbd_cmd->($scfg, $storeid, 'unmap', $kerneldev);
+	my $cmd = rbd_cmd($scfg, $storeid, 'unmap', $kerneldev);
 	run_rbd_command($cmd, errmsg => "can't unmap rbd device $kerneldev");
     }
 
@@ -780,7 +780,7 @@ sub volume_resize {
 
     my ($vtype, $name, $vmid) = $class->parse_volname($volname);
 
-    my $cmd = $rbd_cmd->($scfg, $storeid, 'resize', '--size', int(ceil($size/1024/1024)), $name);
+    my $cmd = rbd_cmd($scfg, $storeid, 'resize', '--size', int(ceil($size/1024/1024)), $name);
     run_rbd_command($cmd, errmsg => "rbd resize '$volname' error");
     return undef;
 }
@@ -790,7 +790,7 @@ sub volume_snapshot {
 
     my ($vtype, $name, $vmid) = $class->parse_volname($volname);
 
-    my $cmd = $rbd_cmd->($scfg, $storeid, 'snap', 'create', '--snap', $snap, $name);
+    my $cmd = rbd_cmd($scfg, $storeid, 'snap', 'create', '--snap', $snap, $name);
     run_rbd_command($cmd, errmsg => "rbd snapshot '$volname' error");
     return undef;
 }
@@ -800,7 +800,7 @@ sub volume_snapshot_rollback {
 
     my ($vtype, $name, $vmid) = $class->parse_volname($volname);
 
-    my $cmd = $rbd_cmd->($scfg, $storeid, 'snap', 'rollback', '--snap', $snap, $name);
+    my $cmd = rbd_cmd($scfg, $storeid, 'snap', 'rollback', '--snap', $snap, $name);
     run_rbd_command($cmd, errmsg => "rbd snapshot $volname to '$snap' error");
 }
 
@@ -813,11 +813,11 @@ sub volume_snapshot_delete {
 
     my (undef, undef, undef, $protected) = rbd_volume_info($scfg, $storeid, $name, $snap);
     if ($protected){
-	my $cmd = $rbd_cmd->($scfg, $storeid, 'snap', 'unprotect', $name, '--snap', $snap);
+	my $cmd = rbd_cmd($scfg, $storeid, 'snap', 'unprotect', $name, '--snap', $snap);
 	run_rbd_command($cmd, errmsg => "rbd unprotect $name snap '$snap' error");
     }
 
-    my $cmd = $rbd_cmd->($scfg, $storeid, 'snap', 'rm', '--snap', $snap, $name);
+    my $cmd = rbd_cmd($scfg, $storeid, 'snap', 'rm', '--snap', $snap, $name);
 
     run_rbd_command($cmd, errmsg => "rbd snapshot '$volname' error");
 
@@ -869,12 +869,12 @@ sub rename_volume {
 	if !$target_volname;
 
     eval {
-	my $cmd = $rbd_cmd->($scfg, $storeid, 'info', $target_volname);
+	my $cmd = rbd_cmd($scfg, $storeid, 'info', $target_volname);
 	run_rbd_command($cmd, errmsg => "exist check",  quiet => 1);
     };
     die "target volume '${target_volname}' already exists\n" if !$@;
 
-    my $cmd = $rbd_cmd->($scfg, $storeid, 'rename', $source_image, $target_volname);
+    my $cmd = rbd_cmd($scfg, $storeid, 'rename', $source_image, $target_volname);
 
     run_rbd_command(
 	$cmd,
-- 
2.39.2



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


  parent reply	other threads:[~2024-07-17  9:43 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-17  9:39 [pve-devel] [RFC pve-storage 00/36] Refactor / Cleanup of Storage Plugins Max Carrara
2024-07-17  9:39 ` [pve-devel] [RFC pve-storage 01/36] plugin: base: remove old fixme comments Max Carrara
2024-07-17 16:02   ` Thomas Lamprecht
2024-07-18  7:43     ` Max Carrara
2024-07-17  9:40 ` [pve-devel] [RFC pve-storage 02/36] plugin: btrfs: make plugin-specific helpers private Max Carrara
2024-07-17  9:40 ` [pve-devel] [RFC pve-storage 03/36] plugin: cephfs: " Max Carrara
2024-07-17  9:40 ` [pve-devel] [RFC pve-storage 04/36] api: remove unused import of CIFS storage plugin Max Carrara
2024-07-17  9:40 ` [pve-devel] [RFC pve-storage 05/36] plugin: cifs: make plugin-specific helpers private Max Carrara
2024-07-17  9:40 ` [pve-devel] [RFC pve-storage 06/36] api: remove unused import of LVM storage plugin Max Carrara
2024-07-17  9:40 ` [pve-devel] [RFC pve-storage 07/36] common: introduce common module Max Carrara
2024-07-17  9:40 ` [pve-devel] [RFC pve-storage 08/36] plugin: dir: move helper subs of directory plugin to common modules Max Carrara
2024-07-17  9:40 ` [pve-devel] [RFC pve-storage 09/36] plugin: lvm: move LVM helper subroutines into separate common module Max Carrara
2024-07-17  9:40 ` [pve-devel] [RFC pve-storage 10/36] api: replace usages of deprecated LVM helper subs with new ones Max Carrara
2024-07-17  9:40 ` [pve-devel] [RFC pve-storage 11/36] plugin: lvmthin: replace usages of deprecated LVM helpers " Max Carrara
2024-07-17  9:40 ` [pve-devel] [RFC pve-storage 12/36] plugin: lvmthin: move helper that lists thinpools to common LVM module Max Carrara
2024-07-17  9:40 ` [pve-devel] [RFC pve-storage 13/36] common: lvm: update code style Max Carrara
2024-07-17  9:40 ` [pve-devel] [RFC pve-storage 14/36] api: replace usages of deprecated LVM thin pool helper sub Max Carrara
2024-07-17  9:40 ` [pve-devel] [RFC pve-storage 15/36] plugin: btrfs: replace deprecated helpers from directory plugin Max Carrara
2024-07-17  9:40 ` [pve-devel] [RFC pve-storage 16/36] plugin: dir: factor storage methods into separate common subs Max Carrara
2024-07-17  9:40 ` [pve-devel] [RFC pve-storage 17/36] plugin: dir: factor path validity check into helper methods Max Carrara
2024-07-17  9:40 ` [pve-devel] [RFC pve-storage 18/36] plugin: btrfs: remove dependency on directory plugin Max Carrara
2024-07-17  9:40 ` [pve-devel] [RFC pve-storage 19/36] plugin: cifs: " Max Carrara
2024-07-17  9:40 ` [pve-devel] [RFC pve-storage 20/36] plugin: cephfs: " Max Carrara
2024-07-17  9:40 ` [pve-devel] [RFC pve-storage 21/36] plugin: nfs: " Max Carrara
2024-07-17  9:40 ` [pve-devel] [RFC pve-storage 22/36] plugin: btrfs: make helper methods private Max Carrara
2024-07-17  9:40 ` [pve-devel] [RFC pve-storage 23/36] plugin: esxi: make helper subroutines private Max Carrara
2024-07-17  9:40 ` [pve-devel] [RFC pve-storage 24/36] plugin: esxi: remove unused helper subroutine `query_vmdk_size` Max Carrara
2024-07-17  9:40 ` [pve-devel] [RFC pve-storage 25/36] plugin: esxi: make helper methods private Max Carrara
2024-07-17  9:40 ` [pve-devel] [RFC pve-storage 26/36] plugin: gluster: make helper subroutines private Max Carrara
2024-07-17  9:40 ` [pve-devel] [RFC pve-storage 27/36] plugin: iscsi-direct: make helper subroutine `iscsi_ls` private Max Carrara
2024-07-17  9:40 ` [pve-devel] [RFC pve-storage 28/36] plugin: iscsi: factor helper functions into common module Max Carrara
2024-07-17  9:40 ` [pve-devel] [RFC pve-storage 29/36] plugin: iscsi: make helper subroutine `iscsi_session` private Max Carrara
2024-07-17  9:40 ` [pve-devel] [RFC pve-storage 30/36] plugin: lvm: update definition of subroutine `check_tags` Max Carrara
2024-07-17  9:40 ` [pve-devel] [RFC pve-storage 31/36] plugin: lvmthin: update definition of subroutine `activate_lv` Max Carrara
2024-07-17  9:40 ` [pve-devel] [RFC pve-storage 32/36] plugin: nfs: make helper subroutines private Max Carrara
2024-07-17  9:40 ` Max Carrara [this message]
2024-07-17  9:40 ` [pve-devel] [RFC pve-storage 34/36] common: zfs: introduce module for common ZFS helpers Max Carrara
2024-07-17  9:40 ` [pve-devel] [RFC pve-storage 35/36] plugin: zfspool: move helper `zfs_parse_zvol_list` to common module Max Carrara
2024-07-17  9:40 ` [pve-devel] [RFC pve-storage 36/36] plugin: zfspool: refactor method `zfs_request` into helper subroutine Max Carrara

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=20240717094034.124857-34-m.carrara@proxmox.com \
    --to=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