From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <f.gruenbichler@proxmox.com>
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 B54E9E8CE
 for <pve-devel@lists.proxmox.com>; Wed, 19 Jul 2023 14:09:54 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 96FB86AF0
 for <pve-devel@lists.proxmox.com>; Wed, 19 Jul 2023 14:09:24 +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 <pve-devel@lists.proxmox.com>; Wed, 19 Jul 2023 14:09:21 +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 CCD0541017
 for <pve-devel@lists.proxmox.com>; Wed, 19 Jul 2023 14:09:20 +0200 (CEST)
Date: Wed, 19 Jul 2023 14:09:13 +0200
From: Fabian =?iso-8859-1?q?Gr=FCnbichler?= <f.gruenbichler@proxmox.com>
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>
References: <20230706105421.54949-1-m.frank@proxmox.com>
 <20230706105421.54949-3-m.frank@proxmox.com>
In-Reply-To: <20230706105421.54949-3-m.frank@proxmox.com>
MIME-Version: 1.0
User-Agent: astroid/0.16.0 (https://github.com/astroidmail/astroid)
Message-Id: <1689765790.wijl3s8z55.astroid@yuna.none>
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.070 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: Re: [pve-devel] [PATCH guest-common v6 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 <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Wed, 19 Jul 2023 12:09:54 -0000

On July 6, 2023 12:54 pm, Markus Frank wrote:
> adds a config file for directories by using a 'map'
> array propertystring for each node mapping.
>=20
> next to node & path, there are xattr, acl & submounts parameters for
> virtiofsd in the map array.
>=20
> example config:
> ```
> some-dir-id
> 	map node=3Dnode1,path=3D/mnt/share/,xattr=3D1,acl=3D1,submounts=3D1
> 	map node=3Dnode2,path=3D/mnt/share/,xattr=3D1
> 	map node=3Dnode3,path=3D/mnt/share/,submounts=3D1
> 	map node=3Dnode4,path=3D/mnt/share/
> ```

does it really make sense to configure a dir with acl (support) on one
node, and without on another? same for xattr? submounts I could kinda
see a use case, although it would be a bit contrived..

e.g., for pci mappings we have the node-specific parts in the "map"
array items, but the "global" mdev boolean property is defined once per
ID, and not for each node..

>=20
> Signed-off-by: Markus Frank <m.frank@proxmox.com>
> ---
>  src/Makefile           |   1 +
>  src/PVE/Mapping/DIR.pm | 175 +++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 176 insertions(+)
>  create mode 100644 src/PVE/Mapping/DIR.pm
>=20
> diff --git a/src/Makefile b/src/Makefile
> index cbc40c1..876829a 100644
> --- a/src/Makefile
> +++ b/src/Makefile
> @@ -17,6 +17,7 @@ install: PVE
>  	install -d ${PERL5DIR}/PVE/Mapping
>  	install -m 0644 PVE/Mapping/PCI.pm ${PERL5DIR}/PVE/Mapping/
>  	install -m 0644 PVE/Mapping/USB.pm ${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

nit: why DIR and not Dir ? USB and PCI are acronyms, Dir is just short for
Directory..

> new file mode 100644
> index 0000000..a5da042
> --- /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_wr=
ite_file);
> +use PVE::JSONSchema qw(get_standard_option parse_property_string);
> +use PVE::SectionConfig;
> +use PVE::INotify;
> +
> +use base qw(PVE::SectionConfig);
> +
> +my $FILENAME =3D 'mapping/dir.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) =3D @_;
> +
> +    if ($line =3D~ m/^(\S+)\s*$/) {
> +	my $id =3D $1;
> +	my $errmsg =3D undef; # set if you want to skip whole section
> +	eval { PVE::JSONSchema::pve_verify_configid($id) };
> +	$errmsg =3D $@ if $@;
> +	my $config =3D {}; # to return additional attributes
> +	return ('dir', $id, $errmsg, $config);
> +    }
> +    return undef;
> +}
> +
> +sub format_section_header {
> +    my ($class, $type, $sectionId, $scfg, $done_hash) =3D @_;
> +
> +    return "$sectionId\n";
> +}
> +
> +sub type {
> +    return 'dir';
> +}
> +
> +my $map_fmt =3D {
> +    node =3D> get_standard_option('pve-node'),
> +    path =3D> {
> +	description =3D> "Directory-path that should be shared with the guest."=
,
> +	type =3D> 'string',
> +	format =3D> 'pve-storage-path',
> +    },
> +    xattr =3D> {
> +	type =3D> 'boolean',
> +	description =3D> "Enable support for extended attributes (xattrs).",
> +	optional =3D> 1,
> +    },
> +    acl =3D> {
> +	type =3D> 'boolean',
> +	description =3D> "Enable support for posix ACLs (implies --xattr).",
> +	optional =3D> 1,
> +    },
> +    submounts =3D> {
> +	type =3D> 'boolean',
> +	description =3D> "Option to tell the guest which directories are mount =
points.",
> +	optional =3D> 1,
> +    },
> +    description =3D> {
> +	description =3D> "Description of the node specific directory.",
> +	type =3D> 'string',
> +	optional =3D> 1,
> +	maxLength =3D> 4096,
> +    },
> +};
> +
> +my $defaultData =3D {
> +    propertyList =3D> {
> +        id =3D> {
> +            type =3D> 'string',
> +            description =3D> "The ID of the directory",
> +            format =3D> 'pve-configid',
> +        },
> +        description =3D> {
> +            description =3D> "Description of the directory",
> +            type =3D> 'string',
> +            optional =3D> 1,
> +            maxLength =3D> 4096,
> +        },
> +        map =3D> {
> +            type =3D> 'array',
> +            description =3D> 'A list of maps for the cluster nodes.',
> +	    optional =3D> 1,
> +            items =3D> {
> +                type =3D> 'string',
> +                format =3D> $map_fmt,
> +            },
> +        },
> +    },
> +};
> +
> +sub private {
> +    return $defaultData;
> +}
> +
> +sub options {
> +    return {
> +        description =3D> { optional =3D> 1 },
> +        map =3D> {},
> +    };
> +}
> +
> +sub assert_valid {
> +    my ($dir_cfg) =3D @_;
> +
> +    my $path =3D $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) =3D @_;
> +
> +    cfs_lock_file($FILENAME, undef, $code);
> +    my $err =3D $@;
> +    if ($err) {
> +        $errmsg ? die "$errmsg: $err" : die $err;
> +    }
> +}
> +
> +sub write_dir_config {
> +    my ($cfg) =3D @_;
> +
> +    cfs_write_file($FILENAME, $cfg);
> +}
> +
> +sub find_on_current_node {
> +    my ($id) =3D @_;
> +
> +    my $cfg =3D config();
> +    my $node =3D PVE::INotify::nodename();
> +
> +    return get_node_mapping($cfg, $id, $node);
> +}
> +
> +sub get_node_mapping {
> +    my ($cfg, $id, $nodename) =3D @_;
> +
> +    return undef if !defined($cfg->{ids}->{$id});
> +
> +    my $res =3D [];
> +    my $mapping_list =3D $cfg->{ids}->{$id}->{map};
> +    foreach my $map (@{$mapping_list}) {
> +	my $entry =3D 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;
> --=20
> 2.39.2
>=20
>=20
>=20
> _______________________________________________
> pve-devel mailing list
> pve-devel@lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
>=20
>=20
>=20