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 DAE9A69552; Fri, 13 Nov 2020 10:39:26 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id CF0D3189A9; Fri, 13 Nov 2020 10:38:56 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (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 id 126A71892A; Fri, 13 Nov 2020 10:38:54 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id D260E4219A; Fri, 13 Nov 2020 10:38:53 +0100 (CET) From: Dominik Csapak To: pve-devel@lists.proxmox.com, pbs-devel@lists.proxmox.com Date: Fri, 13 Nov 2020 10:38:51 +0100 Message-Id: <20201113093852.28788-5-d.csapak@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201113093852.28788-1-d.csapak@proxmox.com> References: <20201113093852.28788-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.362 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment KAM_SHORT 0.001 Use of a URL Shortener for very short URL RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [plugin.pm, dirplugin.pm, gnu.org, content.pm, pbsplugin.pm, storage.pm] Subject: [pve-devel] [PATCH storage 2/2] Storage/Plugin: add get/update_volume_comment and implement for dir/pbs 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: Fri, 13 Nov 2020 09:39:27 -0000 and add the appropriate api call to set and get the comment we need to bump APIVER for this and can bump APIAGE, since we only use it at this new call that can work with the default implementation Signed-off-by: Dominik Csapak --- PVE/API2/Storage/Content.pm | 63 +++++++++++++++++++++++++++++++++++-- PVE/Storage.pm | 24 ++++++++++++-- PVE/Storage/DirPlugin.pm | 30 ++++++++++++++++++ PVE/Storage/PBSPlugin.pm | 20 ++++++++++++ PVE/Storage/Plugin.pm | 12 +++++++ 5 files changed, 145 insertions(+), 4 deletions(-) diff --git a/PVE/API2/Storage/Content.pm b/PVE/API2/Storage/Content.pm index 8eeb2eb..acaf8f3 100644 --- a/PVE/API2/Storage/Content.pm +++ b/PVE/API2/Storage/Content.pm @@ -285,6 +285,11 @@ __PACKAGE__->register_method ({ description => "Format identifier ('raw', 'qcow2', 'subvol', 'iso', 'tgz' ...)", type => 'string', }, + comment => { + description => "The optional comment", + optional => 1, + type => 'string', + } }, }, code => sub { @@ -303,13 +308,67 @@ __PACKAGE__->register_method ({ my ($size, $format, $used, $parent) = PVE::Storage::volume_size_info($cfg, $volid); die "volume_size_info on '$volid' failed\n" if !($format && $size); - # fixme: return more attributes? - return { + my $entry = { path => $path, size => $size, used => $used, format => $format, }; + + # not all storages/types support comments, so ignore errors here + eval { + my $comment = PVE::Storage::get_volume_comment($cfg, $volid); + $entry->{comment} = $comment if defined($comment); + }; + + return $entry; + }}); + +__PACKAGE__->register_method ({ + name => 'updateattributes', + path => '{volume}', + method => 'PUT', + description => "Update volume attributes", + permissions => { + description => "You need read access for the volume.", + user => 'all', + }, + protected => 1, + proxyto => 'node', + parameters => { + additionalProperties => 0, + properties => { + node => get_standard_option('pve-node'), + storage => get_standard_option('pve-storage-id', { optional => 1 }), + volume => { + description => "Volume identifier", + type => 'string', + }, + comment => { + description => "The new comment", + type => 'string', + optional => 1, + }, + }, + }, + returns => { type => 'null' }, + code => sub { + my ($param) = @_; + + my $rpcenv = PVE::RPCEnvironment::get(); + my $authuser = $rpcenv->get_user(); + + my ($volid, $storeid) = &$real_volume_id($param->{storage}, $param->{volume}); + + my $cfg = PVE::Storage::config(); + + PVE::Storage::check_volume_access($rpcenv, $authuser, $cfg, undef, $volid); + + if (my $comment = $param->{comment}) { + PVE::Storage::update_volume_comment($cfg, $volid, $comment); + } + + return undef; }}); __PACKAGE__->register_method ({ diff --git a/PVE/Storage.pm b/PVE/Storage.pm index 932f0f1..4d1cc5d 100755 --- a/PVE/Storage.pm +++ b/PVE/Storage.pm @@ -41,11 +41,11 @@ use PVE::Storage::DRBDPlugin; use PVE::Storage::PBSPlugin; # Storage API version. Increment it on changes in storage API interface. -use constant APIVER => 7; +use constant APIVER => 8; # Age is the number of versions we're backward compatible with. # This is like having 'current=APIVER' and age='APIAGE' in libtool, # see https://www.gnu.org/software/libtool/manual/html_node/Libtool-versioning.html -use constant APIAGE => 6; +use constant APIAGE => 7; # load standard plugins PVE::Storage::DirPlugin->register(); @@ -193,6 +193,26 @@ sub file_size_info { return PVE::Storage::Plugin::file_size_info($filename, $timeout); } +sub get_volume_comment { + my ($cfg, $volid, $timeout) = @_; + + my ($storeid, $volname) = parse_volume_id($volid); + my $scfg = storage_config($cfg, $storeid); + my $plugin = PVE::Storage::Plugin->lookup($scfg->{type}); + + return $plugin->get_volume_comment($scfg, $storeid, $volname, $timeout); +} + +sub update_volume_comment { + my ($cfg, $volid, $notes, $timeout) = @_; + + my ($storeid, $volname) = parse_volume_id($volid); + my $scfg = storage_config($cfg, $storeid); + my $plugin = PVE::Storage::Plugin->lookup($scfg->{type}); + + $plugin->update_volume_comment($scfg, $storeid, $volname, $notes, $timeout); +} + sub volume_size_info { my ($cfg, $volid, $timeout) = @_; diff --git a/PVE/Storage/DirPlugin.pm b/PVE/Storage/DirPlugin.pm index 3c81d24..bcc490a 100644 --- a/PVE/Storage/DirPlugin.pm +++ b/PVE/Storage/DirPlugin.pm @@ -87,6 +87,36 @@ sub parse_is_mountpoint { return $is_mp; # contains a path } +sub get_volume_comment { + my ($class, $scfg, $storeid, $volname, $timeout) = @_; + my $path = $class->filesystem_path($scfg, $volname); + $path .= $class->SUPER::COMMENT_EXT; + + my $comment = ""; + + if (-f $path) { + $comment = PVE::Tools::file_get_contents($path); + } + + return $comment; +} + +sub update_volume_comment { + my ($class, $scfg, $storeid, $volname, $comment, $timeout) = @_; + my $path = $class->filesystem_path($scfg, $volname); + my ($vtype, undef, undef, undef, undef, undef, undef) = $class->parse_volname($volname); + + if ($vtype ne 'backup') { + die "only backups can have comments\n"; + } + + $path .= $class->SUPER::COMMENT_EXT; + + PVE::Tools::file_set_contents($path, $comment); + + return undef; +} + sub status { my ($class, $storeid, $scfg, $cache) = @_; diff --git a/PVE/Storage/PBSPlugin.pm b/PVE/Storage/PBSPlugin.pm index f3bf016..2bf5cdf 100644 --- a/PVE/Storage/PBSPlugin.pm +++ b/PVE/Storage/PBSPlugin.pm @@ -590,6 +590,26 @@ sub deactivate_volume { return 1; } +sub get_volume_comment { + my ($class, $scfg, $storeid, $volname, $timeout) = @_; + + my (undef, $name, undef, undef, undef, undef, $format) = $class->parse_volname($volname); + + my $data = run_client_cmd($scfg, $storeid, "snapshot", [ "notes", "show", $name ]); + + return $data->{comment}; +} + +sub update_volume_comment { + my ($class, $scfg, $storeid, $volname, $comment, $timeout) = @_; + + my (undef, $name, undef, undef, undef, undef, $format) = $class->parse_volname($volname); + + run_client_cmd($scfg, $storeid, "snapshot", [ "notes", "update", $name, $comment ], 1); + + return undef; +} + sub volume_size_info { my ($class, $scfg, $storeid, $volname, $timeout) = @_; diff --git a/PVE/Storage/Plugin.pm b/PVE/Storage/Plugin.pm index b4f3be8..56398a8 100644 --- a/PVE/Storage/Plugin.pm +++ b/PVE/Storage/Plugin.pm @@ -813,6 +813,18 @@ sub file_size_info { return wantarray ? ($size, $format, $used, $parent, $st->ctime) : $size; } +sub get_volume_comment { + my ($class, $scfg, $storeid, $volname, $timeout) = @_; + + die "volume comments are not supported for $class"; +} + +sub update_volume_comment { + my ($class, $scfg, $storeid, $volname, $comment, $timeout) = @_; + + die "volume comments are not supported for $class"; +} + sub volume_size_info { my ($class, $scfg, $storeid, $volname, $timeout) = @_; my $path = $class->filesystem_path($scfg, $volname); -- 2.20.1