From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 08D0C1FF2C8 for ; Wed, 17 Jul 2024 11:42:37 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 13585387C6; Wed, 17 Jul 2024 11:42:40 +0200 (CEST) From: Max Carrara To: pve-devel@lists.proxmox.com Date: Wed, 17 Jul 2024 11:40:16 +0200 Message-Id: <20240717094034.124857-19-m.carrara@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240717094034.124857-1-m.carrara@proxmox.com> References: <20240717094034.124857-1-m.carrara@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.221 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 URI_NOVOWEL 0.5 URI hostname has long non-vowel sequence Subject: [pve-devel] [RFC pve-storage 18/36] plugin: btrfs: remove dependency on directory plugin 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: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" This commit removes the BTRFS plugin's dependency on the directory plugin. This is done by replacing calls to the dir plugin's methods with the corresponding helper subroutines from the `Common` module instead. Furthermore, the methods `check_config` and `status` both get their own implementations that behave essentially the same as the ones from the dir plugin. Signed-off-by: Max Carrara --- src/PVE/Storage/BTRFSPlugin.pm | 49 +++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/src/PVE/Storage/BTRFSPlugin.pm b/src/PVE/Storage/BTRFSPlugin.pm index 10fd441..daff8a4 100644 --- a/src/PVE/Storage/BTRFSPlugin.pm +++ b/src/PVE/Storage/BTRFSPlugin.pm @@ -13,9 +13,15 @@ use POSIX qw(EEXIST); use PVE::Tools qw(run_command dir_glob_foreach); -use PVE::Storage::Common qw(storage_parse_is_mountpoint); -use PVE::Storage::Common::Path qw(path_is_mounted); -use PVE::Storage::DirPlugin; +use PVE::Storage::Common qw( + storage_parse_is_mountpoint + storage_dir_get_volume_attribute + storage_dir_update_volume_attribute +); +use PVE::Storage::Common::Path qw( + path_is_mounted + path_is_storage_dir +); use constant { BTRFS_FIRST_FREE_OBJECTID => 256, @@ -92,10 +98,16 @@ sub options { # -> `images/VMID/vm-VMID-disk-ID/disk.raw` # where the `vm-VMID-disk-ID/` subdirectory is a btrfs subvolume -# Reuse `DirPlugin`'s `check_config`. This simply checks for invalid paths. sub check_config { my ($self, $sectionId, $config, $create, $skipSchemaCheck) = @_; - return PVE::Storage::DirPlugin::check_config($self, $sectionId, $config, $create, $skipSchemaCheck); + my $opts = PVE::SectionConfig::check_config($self, $sectionId, $config, $create, $skipSchemaCheck); + return $opts if !$create; + + if (!path_is_storage_dir($opts->{path})) { + die "illegal path for directory of BTRFS storage: $opts->{path}\n"; + } + + return $opts; } my sub getfsmagic($) { @@ -137,23 +149,30 @@ sub activate_storage { sub status { my ($class, $storeid, $scfg, $cache) = @_; - return PVE::Storage::DirPlugin::status($class, $storeid, $scfg, $cache); + + if (defined(my $mp = storage_parse_is_mountpoint($scfg))) { + $cache->{mountdata} = PVE::ProcFSTools::parse_proc_mounts() + if !$cache->{mountdata}; + + return undef if !path_is_mounted($mp, $cache->{mountdata}); + } + + return $class->SUPER::status($storeid, $scfg, $cache); } sub get_volume_attribute { my ($class, $scfg, $storeid, $volname, $attribute) = @_; - return PVE::Storage::DirPlugin::get_volume_attribute($class, $scfg, $storeid, $volname, $attribute); + + return storage_dir_get_volume_attribute( + $class, $scfg, $storeid, $volname, $attribute + ); } sub update_volume_attribute { my ($class, $scfg, $storeid, $volname, $attribute, $value) = @_; - return PVE::Storage::DirPlugin::update_volume_attribute( - $class, - $scfg, - $storeid, - $volname, - $attribute, - $value, + + return storage_dir_update_volume_attribute( + $class, $scfg, $storeid, $volname, $attribute, $value ); } @@ -295,7 +314,7 @@ sub clone_image { # If we're not working with a 'raw' file, which is the only thing that's "different" for btrfs, # or a subvolume, we forward to the DirPlugin if ($format ne 'raw' && $format ne 'subvol') { - return PVE::Storage::DirPlugin::clone_image(@_); + return $class->SUPER::clone_image(@_); } my $imagedir = $class->get_subdir($scfg, 'images'); -- 2.39.2 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel