public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: "Fabian Grünbichler" <f.gruenbichler@proxmox.com>
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>
Subject: Re: [pve-devel] [PATCH guest-common v6 1/1] add DIR mapping config
Date: Wed, 19 Jul 2023 14:09:13 +0200	[thread overview]
Message-ID: <1689765790.wijl3s8z55.astroid@yuna.none> (raw)
In-Reply-To: <20230706105421.54949-3-m.frank@proxmox.com>

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.
> 
> next to node & path, there are xattr, acl & submounts parameters for
> virtiofsd in the map array.
> 
> example config:
> ```
> 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/
> ```

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..

> 
> 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
> 
> 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_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/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) = @_;
> +
> +    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.39.2
> 
> 
> 
> _______________________________________________
> pve-devel mailing list
> pve-devel@lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
> 
> 
> 




  reply	other threads:[~2023-07-19 12:09 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-06 10:54 [pve-devel] [PATCH cluster/guest-common/qemu-server/manager v6 0/11] virtiofs Markus Frank
2023-07-06 10:54 ` [pve-devel] [PATCH cluster v6 1/1] add mapping/dir.cfg for resource mapping Markus Frank
2023-07-06 10:54 ` [pve-devel] [PATCH guest-common v6 1/1] add DIR mapping config Markus Frank
2023-07-19 12:09   ` Fabian Grünbichler [this message]
2023-07-06 10:54 ` [pve-devel] [PATCH docs v6 1/1] added shared filesystem doc for virtio-fs Markus Frank
2023-07-17  8:08   ` Christoph Heiss
2023-07-06 10:54 ` [pve-devel] [PATCH qemu-server v6 1/3] feature #1027: virtio-fs support Markus Frank
2023-07-19 12:08   ` Fabian Grünbichler
2023-07-06 10:54 ` [pve-devel] [PATCH qemu-server v6 2/3] Permission check for virtiofs directory access Markus Frank
2023-07-06 10:54 ` [pve-devel] [PATCH qemu-server v6 3/3] check_local_resources: virtiofs Markus Frank
2023-07-06 10:54 ` [pve-devel] [PATCH manager v6 1/5] api: add resource map api endpoints for directories Markus Frank
2023-07-06 10:54 ` [pve-devel] [PATCH manager v6 2/5] ui: add edit window for dir mappings Markus Frank
2023-07-06 10:54 ` [pve-devel] [PATCH manager v6 3/5] ui: ResourceMapTree for DIR Markus Frank
2023-07-06 10:54 ` [pve-devel] [PATCH manager v6 4/5] ui: form: add DIRMapSelector Markus Frank
2023-07-06 10:54 ` [pve-devel] [PATCH manager v6 5/5] ui: added options to add virtio-fs to qemu config Markus Frank
2023-07-17  7:51 ` [pve-devel] [PATCH cluster/guest-common/qemu-server/manager v6 0/11] virtiofs Christoph Heiss
2023-07-18 12:56 ` Friedrich Weber
2023-07-19 12:08 ` Fabian Grünbichler
2023-07-20  7:12 ` Fabian Grünbichler

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=1689765790.wijl3s8z55.astroid@yuna.none \
    --to=f.gruenbichler@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