From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>,
Dominik Csapak <d.csapak@proxmox.com>
Subject: Re: [pve-devel] [PATCH storage 2/2] Storage/Plugin: read .comment files for comments
Date: Thu, 12 Nov 2020 17:50:26 +0100 [thread overview]
Message-ID: <41f856f4-1f8b-c518-27f3-cf02f9ed7a20@proxmox.com> (raw)
In-Reply-To: <20201112152603.8106-3-d.csapak@proxmox.com>
On 12.11.20 16:26, Dominik Csapak wrote:
> we have no way of setting them yet via api, but we can read them now
>
> Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
> ---
> PVE/Storage/Plugin.pm | 23 +++++++++++++++++++++++
> 1 file changed, 23 insertions(+)
>
applied, but dropped the relatively complicated optimizations which avoided
a probably cached stat in an edge case - I do not see much value in such
over optimizations which make a previous simple sub harder to understand
without even noting why it was done anywhere - especially without any stats
providing some hard numbers about if and in what environments this actually
helps.
> diff --git a/PVE/Storage/Plugin.pm b/PVE/Storage/Plugin.pm
> index a046640..00ce9cb 100644
> --- a/PVE/Storage/Plugin.pm
> +++ b/PVE/Storage/Plugin.pm
> @@ -19,6 +19,8 @@ use base qw(PVE::SectionConfig);
>
> use constant COMPRESSOR_RE => 'gz|lzo|zst';
>
> +use constant COMMENT_EXT => ".comment";
> +
> our @COMMON_TAR_FLAGS = qw(
> --one-file-system
> -p --sparse --numeric-owner --acls
> @@ -987,8 +989,18 @@ my $get_subdir_files = sub {
>
> my $res = [];
>
> + my $has_comment = {};
> +
> foreach my $fn (<$path/*>) {
>
> + if (COMMENT_EXT eq substr($fn, -length(COMMENT_EXT))) {
> + my $real_fn = substr($fn, 0, length($fn) - length(COMMENT_EXT));
> + if (!defined($has_comment->{$real_fn})) {
> + $has_comment->{$real_fn} = (-f $fn);
this is a stat too, so this all only avoided one unused away stat for each
unlikely case that a backup has a comment file.
> + }
> + next; # we do not need to do anything with comments themselves
> + }
> +
> my $st = File::stat::stat($fn);
>
> next if (!$st || S_ISDIR($st->mode));
> @@ -1008,6 +1020,7 @@ my $get_subdir_files = sub {
> } elsif ($tt eq 'backup') {
> next if defined($vmid) && $fn !~ m/\S+-$vmid-\S+/;
> next if $fn !~ m!/([^/]+\.(tgz|(?:(?:tar|vma)(?:\.(${\COMPRESSOR_RE}))?)))$!;
> + my $original = $fn;
> my $format = $2;
> $fn = $1;
> $info = { volid => "$sid:backup/$fn", format => $format };
> @@ -1020,6 +1033,16 @@ my $get_subdir_files = sub {
> $info->{vmid} = $vmid // $1;
> }
>
> + my $comment_fn = $original.COMMENT_EXT;
> + if (!defined($has_comment->{$original})) {
> + $has_comment->{$original} = (-f $comment_fn);
> + }
> +
> + if ($has_comment->{$original}) {
> + my $comment = PVE::Tools::file_read_firstline($comment_fn);
> + $info->{comment} = $comment if defined($comment);
> + }
> +
> } elsif ($tt eq 'snippets') {
>
> $info = {
>
next prev parent reply other threads:[~2020-11-12 16:50 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-12 15:26 [pve-devel] [PATCH storage/manager] show comment/verification info for backups Dominik Csapak
2020-11-12 15:26 ` [pve-devel] [PATCH storage 1/2] api2/storage/content: add comment and verification fields to content listing Dominik Csapak
2020-11-12 16:42 ` [pve-devel] applied: " Thomas Lamprecht
2020-11-12 15:26 ` [pve-devel] [PATCH storage 2/2] Storage/Plugin: read .comment files for comments Dominik Csapak
2020-11-12 16:50 ` Thomas Lamprecht [this message]
2020-11-12 15:26 ` [pve-devel] [PATCH manager 1/1] ui: add comment/verification columns to backup/content grid Dominik Csapak
2020-11-12 17:38 ` [pve-devel] applied: " Thomas Lamprecht
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=41f856f4-1f8b-c518-27f3-cf02f9ed7a20@proxmox.com \
--to=t.lamprecht@proxmox.com \
--cc=d.csapak@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