From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com, h.laimer@proxmox.com
Subject: Re: [pve-devel] [PATCH pve-manager 1/3] fix #3903: jobs-plugin: add remove vmid from jobs helper
Date: Wed, 2 Mar 2022 11:12:45 +0100 [thread overview]
Message-ID: <d466c9a4-e4ba-d97e-003b-b08e0b7fcedc@proxmox.com> (raw)
In-Reply-To: <20220301085153.31445-2-h.laimer@proxmox.com>
Am 01.03.22 um 09:51 schrieb Hannes Laimer:
> Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
> ---
> PVE/Jobs/Plugin.pm | 19 ++++++++++++++++++-
> 1 file changed, 18 insertions(+), 1 deletion(-)
>
> diff --git a/PVE/Jobs/Plugin.pm b/PVE/Jobs/Plugin.pm
> index 6098360b..4883a193 100644
> --- a/PVE/Jobs/Plugin.pm
> +++ b/PVE/Jobs/Plugin.pm
> @@ -3,7 +3,7 @@ package PVE::Jobs::Plugin;
> use strict;
> use warnings;
>
> -use PVE::Cluster qw(cfs_register_file);
> +use PVE::Cluster qw(cfs_register_file cfs_lock_file cfs_read_file cfs_write_file);
>
> use base qw(PVE::SectionConfig);
>
> @@ -92,6 +92,23 @@ sub write_config {
> $class->SUPER::write_config($filename, $cfg);
> }
>
> +sub remove_vmid_from_jobs {
Since this is iterating over jobs of all kinds and not something that
should be overridden by derived plugins, it should rather be part of
Jobs.pm.
If, in the future, plugins ever need more fine-grained control, we can
always add a helper method to remove a vmid from a single job and adapt
this function to call the helper method from the appropriate plugin for
each job.
> + my ($vmid) = @_;
Style nit: we usually put a blank line after the parameter assignment.
> + cfs_lock_file('jobs.cfg', undef, sub {
> + my $jobs_data = cfs_read_file('jobs.cfg');
> + while((my $id, my $job) = each (%{$jobs_data->{ids}})){
Style nits:
* We don't really use 'each'. One reason is that the state of the
iterator is not reset when returning early. Not relevant here, but it's
just not nice behavior.
* Missing spaces before/after outermost parentheses
> + next if !defined($job->{vmid});
> + $job->{vmid} = join(',', grep { $_ ne $vmid } PVE::Tools::split_list($job->{vmid}));
> + if ($job->{vmid} eq '') {
> + delete $jobs_data->{ids}->{$id};
> + } else {
> + $jobs_data->{ids}->{$id} = $job;
Isn't this just assigning the same reference again?
> + }
> + }
> + cfs_write_file('jobs.cfg', $jobs_data);
> + });
> +}
> +
> sub run {
> my ($class, $cfg) = @_;
> # implement in subclass
next prev parent reply other threads:[~2022-03-02 10:13 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-01 8:51 [pve-devel] [PATCH-SERIES] fix #3903: remove vmid from jobs.cfg on destroy Hannes Laimer
2022-03-01 8:51 ` [pve-devel] [PATCH pve-manager 1/3] fix #3903: jobs-plugin: add remove vmid from jobs helper Hannes Laimer
2022-03-02 10:12 ` Fabian Ebner [this message]
2022-03-01 8:51 ` [pve-devel] [PATCH pve-container 2/3] fix #3903: api2: remove vmid from jobs.cfg Hannes Laimer
2022-03-02 10:16 ` Fabian Ebner
2022-03-02 14:28 ` Hannes Laimer
2022-03-03 9:08 ` Fabian Ebner
2022-03-01 8:51 ` [pve-devel] [PATCH qemu-server 3/3] " Hannes Laimer
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=d466c9a4-e4ba-d97e-003b-b08e0b7fcedc@proxmox.com \
--to=f.ebner@proxmox.com \
--cc=h.laimer@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