From: Fiona Ebner <f.ebner@proxmox.com>
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>,
Markus Frank <m.frank@proxmox.com>
Subject: Re: [pve-devel] [PATCH guest-common v8 2/7] add Dir mapping config
Date: Wed, 31 Jan 2024 13:01:35 +0100 [thread overview]
Message-ID: <38d62435-50ed-48ac-96f5-932e2be9e2c7@proxmox.com> (raw)
In-Reply-To: <20231108085254.53574-3-m.frank@proxmox.com>
Am 08.11.23 um 09:52 schrieb Markus Frank:
> Adds a config file for directories by using a 'map'
> array propertystring for each node mapping.
>
> Next to node & path, there is the optional
> submounts parameter in the map array.
> Additionally there are the default settings for xattr & acl.
>
> example config:
> ```
> some-dir-id
> map node=node1,path=/mnt/share/,submounts=1
> map node=node2,path=/mnt/share/,
> xattr 1
> acl 1
> ```
>
> Signed-off-by: Markus Frank <m.frank@proxmox.com>
> ---
> src/Makefile | 1 +
> src/PVE/Mapping/Dir.pm | 177 +++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 178 insertions(+)
> create mode 100644 src/PVE/Mapping/Dir.pm
>
> diff --git a/src/PVE/Mapping/Dir.pm b/src/PVE/Mapping/Dir.pm
> new file mode 100644
> index 0000000..6c87073
> --- /dev/null
> +++ b/src/PVE/Mapping/Dir.pm
> @@ -0,0 +1,177 @@
> +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;
Nit: not sorted alphabetically
---snip---
> +my $map_fmt = {
> + node => get_standard_option('pve-node'),
> + path => {
> + description => "Directory-path that should be shared with the guest.",
Nit: space instead of - is nicer IMHO and since it's an absolute path
"Absolute directory path"
> + type => 'string',
> + format => 'pve-storage-path',
This is registered in PVE/Storage/Plugin.pm
To be clean, we should either add an include here (guest-common already
depends on libpve-storage) or move registering the format to PVE::JSONSchema
> + },
> + submounts => {
> + type => 'boolean',
> + description => "Option to tell the guest which directories are mount points.",
I haven't looked at the code where this is used yet, so I'm as confused
as a user now ;) Does this affect mount points within the directory
(which the "sub" prefix suggests)? But it's a boolean, so how can I tell
"which directories"? The description should answer: When does it need to
be set/what effect does it have?
> + 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,
> + },
> + },
Style nit: Indentation is mostly wrong since the beginning of
$defaultData until here.
> + xattr => {
> + type => 'boolean',
> + description => "Enable support for extended attributes.",
> + optional => 1,
> + },
> + acl => {
> + type => 'boolean',
> + description => "Enable support for posix ACLs (implies --xattr).",
s/posix/POSIX/
> + optional => 1,
What could also be mentioned for xattr and acl: do the underlying file
systems need to support these? What happens if they don't?
> + },
> + },
> +};
> +
> +sub private {
> + return $defaultData;
> +}
> +
> +sub options {
> + return {
> + description => { optional => 1 },
> + map => {},
> + xattr => { optional => 1 },
> + acl => { optional => 1 },
Style nit: wrong indentation
> + };
> +}
> +
> +sub assert_valid {
> + my ($dir_cfg) = @_;
> +
> + my $path = $dir_cfg->{path};
> +
> + if (! -e $path) {
> + die "Path $path does not exist\n";
Style nit: wrong indentation
> + }
> + if ((-e $path) && (! -d $path)) {
Style nit: could be made into an elsif to avoid an extra -e check
> + die "Path $path exists but is not a directory\n"
Style nit: wrong indentation
> + }
> +
> + 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) {
Style nit: could be if (my $err = $@) {
> + $errmsg ? die "$errmsg: $err" : die $err;
Style nit: wrong indentation
> + }
> +}
> +
> +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}) {
Style nit: new code should use "for"
> + 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;
next prev parent reply other threads:[~2024-01-31 12:02 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-08 8:52 [pve-devel] [PATCH cluster/guest-common/docs/qemu-server/manager v8 0/7] virtiofs Markus Frank
2023-11-08 8:52 ` [pve-devel] [PATCH cluster v8 1/7] add mapping/dir.cfg for resource mapping Markus Frank
2024-01-31 12:01 ` Fiona Ebner
2023-11-08 8:52 ` [pve-devel] [PATCH guest-common v8 2/7] add Dir mapping config Markus Frank
2024-01-31 12:01 ` Fiona Ebner [this message]
2024-01-31 13:42 ` Markus Frank
2024-01-31 13:53 ` Fiona Ebner
2024-01-31 14:00 ` Fiona Ebner
2024-01-31 14:15 ` Markus Frank
2024-01-31 13:02 ` Fiona Ebner
2023-11-08 8:52 ` [pve-devel] [PATCH docs v8 3/7] added shared filesystem doc for virtio-fs Markus Frank
2024-01-31 13:26 ` Fiona Ebner
2024-01-31 13:34 ` Fiona Ebner
2023-11-08 8:52 ` [pve-devel] [PATCH qemu-server v8 4/7] feature #1027: virtio-fs support Markus Frank
2024-01-31 15:02 ` Fiona Ebner
2024-02-13 11:52 ` Markus Frank
2024-02-13 12:04 ` Fiona Ebner
2023-11-08 8:52 ` [pve-devel] [PATCH qemu-server v8 5/7] Permission check for virtiofs directory access Markus Frank
2024-01-31 15:23 ` Fiona Ebner
2023-11-08 8:52 ` [pve-devel] [PATCH qemu-server v8 6/7] check_local_resources: virtiofs Markus Frank
2024-01-31 15:35 ` Fiona Ebner
2024-02-22 10:44 ` Markus Frank
2023-11-08 8:52 ` [pve-devel] [PATCH manager v8 7/7] api: add resource map api endpoints for directories Markus Frank
2024-01-31 15:56 ` Fiona Ebner
2024-01-30 12:31 ` [pve-devel] [PATCH cluster/guest-common/docs/qemu-server/manager v8 0/7] virtiofs Markus Frank
2024-01-31 12:01 ` Fiona Ebner
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=38d62435-50ed-48ac-96f5-932e2be9e2c7@proxmox.com \
--to=f.ebner@proxmox.com \
--cc=m.frank@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.