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 9009A9EAE4 for ; Wed, 7 Jun 2023 10:58:19 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 71E113E924 for ; Wed, 7 Jun 2023 10:57:49 +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 ; Wed, 7 Jun 2023 10:57:48 +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 51CE041DED for ; Wed, 7 Jun 2023 10:57:48 +0200 (CEST) From: Markus Frank To: pve-devel@lists.proxmox.com Date: Wed, 7 Jun 2023 10:57:31 +0200 Message-Id: <20230607085732.32063-3-m.frank@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230607085732.32063-1-m.frank@proxmox.com> References: <20230607085732.32063-1-m.frank@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.059 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 T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pve-devel] [PATCH guest-common v5 1/1] add DIR mapping config 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: Wed, 07 Jun 2023 08:58:19 -0000 adds a config file for directories by using a 'map' array propertystring for each node mapping. next to node & path, there are xattr, acl & submounts parameters for virtiofsd in the map array. --- some-dir-id map node=node1,path=/mnt/share/,xattr=1,acl=1,submounts=1 map node=node2,path=/mnt/share/,xattr=1 map node=node3,path=/mnt/share/,submounts=1 map node=node4,path=/mnt/share/ --- Signed-off-by: Markus Frank --- Dominik's "schema/config array support" patch-series is required. src/Makefile | 2 + src/PVE/Mapping/DIR.pm | 175 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 177 insertions(+) create mode 100644 src/PVE/Mapping/DIR.pm diff --git a/src/Makefile b/src/Makefile index 57a360b..37688ef 100644 --- a/src/Makefile +++ b/src/Makefile @@ -14,6 +14,8 @@ install: PVE install -m 0644 PVE/Replication.pm ${PERL5DIR}/PVE/ install -m 0644 PVE/StorageTunnel.pm ${PERL5DIR}/PVE/ install -m 0644 PVE/Tunnel.pm ${PERL5DIR}/PVE/ + install -d ${PERL5DIR}/PVE/Mapping + install -m 0644 PVE/Mapping/DIR.pm ${PERL5DIR}/PVE/Mapping/ install -d ${PERL5DIR}/PVE/VZDump install -m 0644 PVE/VZDump/Plugin.pm ${PERL5DIR}/PVE/VZDump/ install -m 0644 PVE/VZDump/Common.pm ${PERL5DIR}/PVE/VZDump/ diff --git a/src/PVE/Mapping/DIR.pm b/src/PVE/Mapping/DIR.pm new file mode 100644 index 0000000..1f8b033 --- /dev/null +++ b/src/PVE/Mapping/DIR.pm @@ -0,0 +1,175 @@ +package PVE::Mapping::DIR; + +use strict; +use warnings; + +use PVE::Cluster qw(cfs_register_file cfs_read_file cfs_lock_file cfs_write_file); +use PVE::JSONSchema qw(get_standard_option parse_property_string); +use PVE::SectionConfig; +use PVE::INotify; + +use base qw(PVE::SectionConfig); + +my $FILENAME = 'mapping/dirs.cfg'; + +cfs_register_file($FILENAME, + sub { __PACKAGE__->parse_config(@_); }, + sub { __PACKAGE__->write_config(@_); }); + + +# so we don't have to repeat the type every time +sub parse_section_header { + my ($class, $line) = @_; + + if ($line =~ m/^(\S+)\s*$/) { + my $id = $1; + my $errmsg = undef; # set if you want to skip whole section + eval { PVE::JSONSchema::pve_verify_configid($id) }; + $errmsg = $@ if $@; + my $config = {}; # to return additional attributes + return ('dir', $id, $errmsg, $config); + } + return undef; +} + +sub format_section_header { + my ($class, $type, $sectionId, $scfg, $done_hash) = @_; + + return "$sectionId\n"; +} + +sub type { + return 'dir'; +} + +my $map_fmt = { + node => get_standard_option('pve-node'), + path => { + description => "Directory-path that should be shared with the guest.", + type => 'string', + format => 'pve-storage-path', + }, + xattr => { + type => 'boolean', + description => "Enable support for extended attributes (xattrs).", + optional => 1, + }, + acl => { + type => 'boolean', + description => "Enable support for posix ACLs (implies --xattr).", + optional => 1, + }, + submounts => { + type => 'boolean', + description => "Option to tell the guest which directories are mount points.", + optional => 1, + }, + description => { + description => "Description of the node specific directory.", + type => 'string', + optional => 1, + maxLength => 4096, + }, +}; + +my $defaultData = { + propertyList => { + id => { + type => 'string', + description => "The ID of the directory", + format => 'pve-configid', + }, + description => { + description => "Description of the directory", + type => 'string', + optional => 1, + maxLength => 4096, + }, + map => { + type => 'array', + description => 'A list of maps for the cluster nodes.', + optional => 1, + items => { + type => 'string', + format => $map_fmt, + }, + }, + }, +}; + +sub private { + return $defaultData; +} + +sub options { + return { + description => { optional => 1 }, + map => {}, + }; +} + +sub assert_valid { + my ($dir_cfg) = @_; + + my $path = $dir_cfg->{path}; + + if (! -e $path) { + die "Path $path does not exist\n"; + } + if ((-e $path) && (! -d $path)) { + die "Path $path exists but is not a directory\n" + } + + return 1; +}; + +sub config { + return cfs_read_file($FILENAME); +} + +sub lock_dir_config { + my ($code, $errmsg) = @_; + + cfs_lock_file($FILENAME, undef, $code); + my $err = $@; + if ($err) { + $errmsg ? die "$errmsg: $err" : die $err; + } +} + +sub write_dir_config { + my ($cfg) = @_; + + cfs_write_file($FILENAME, $cfg); +} + +sub find_on_current_node { + my ($id) = @_; + + my $cfg = config(); + my $node = PVE::INotify::nodename(); + + return get_node_mapping($cfg, $id, $node); +} + +sub get_node_mapping { + my ($cfg, $id, $nodename) = @_; + + return undef if !defined($cfg->{ids}->{$id}); + + my $res = []; + my $mapping_list = $cfg->{ids}->{$id}->{map}; + foreach my $map (@{$mapping_list}) { + my $entry = eval { parse_property_string($map_fmt, $map) }; + warn $@ if $@; + if ($entry && $entry->{node} eq $nodename) { + push $res->@*, $entry; + } + } + return $res; +} + +PVE::Mapping::DIR->register(); +PVE::Mapping::DIR->init(); + +1; -- 2.30.2