From: Hannes Laimer <h.laimer@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH pve-manager v3 1/3] fix #3903: jobs: add remove vmid from jobs helper
Date: Mon, 14 Mar 2022 09:26:55 +0000 [thread overview]
Message-ID: <20220314092657.48696-2-h.laimer@proxmox.com> (raw)
In-Reply-To: <20220314092657.48696-1-h.laimer@proxmox.com>
Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
---
PVE/Jobs.pm | 21 ++++++++++++++++++++-
PVE/Jobs/Plugin.pm | 7 +++++++
PVE/Jobs/VZDump.pm | 13 +++++++++++++
3 files changed, 40 insertions(+), 1 deletion(-)
diff --git a/PVE/Jobs.pm b/PVE/Jobs.pm
index ba3685ec..5b2c4c7b 100644
--- a/PVE/Jobs.pm
+++ b/PVE/Jobs.pm
@@ -4,7 +4,7 @@ use strict;
use warnings;
use JSON;
-use PVE::Cluster qw(cfs_read_file cfs_lock_file);
+use PVE::Cluster qw(cfs_read_file cfs_lock_file cfs_write_file);
use PVE::Jobs::Plugin;
use PVE::Jobs::VZDump;
use PVE::Tools;
@@ -274,6 +274,25 @@ sub synchronize_job_states_with_config {
die $@ if $@;
}
+sub remove_vmid_from_jobs {
+ my ($vmid) = @_;
+
+ cfs_lock_file('jobs.cfg', undef, sub {
+ my $jobs_data = cfs_read_file('jobs.cfg');
+ for my $id (keys %{$jobs_data->{ids}}) {
+ my $job = $jobs_data->{ids}->{$id};
+ my $type = $job->{type};
+ my $plugin = PVE::Jobs::Plugin->lookup($type);
+ $jobs_data->{ids}->{$id} = $plugin->remove_vmid_from_job($job, $vmid);
+ if (!defined($jobs_data->{ids}->{$id})) {
+ delete $jobs_data->{ids}->{$id};
+ remove_job($id, $type);
+ }
+ }
+ cfs_write_file('jobs.cfg', $jobs_data);
+ });
+}
+
sub setup_dirs {
mkdir $state_dir;
mkdir $lock_dir;
diff --git a/PVE/Jobs/Plugin.pm b/PVE/Jobs/Plugin.pm
index 6098360b..645c460f 100644
--- a/PVE/Jobs/Plugin.pm
+++ b/PVE/Jobs/Plugin.pm
@@ -80,6 +80,13 @@ sub encode_value {
return $plugin->encode_value($type, $key, $value);
}
+sub remove_vmid_from_job {
+ my ($class, $type, $job, $vmid) = @_;
+
+ my $plugin = __PACKAGE__->lookup($type);
+ $plugin->remove_vmid_from_job($job, $vmid);
+}
+
sub write_config {
my ($class, $filename, $cfg) = @_;
diff --git a/PVE/Jobs/VZDump.pm b/PVE/Jobs/VZDump.pm
index 44fe33dc..3aaa66b8 100644
--- a/PVE/Jobs/VZDump.pm
+++ b/PVE/Jobs/VZDump.pm
@@ -64,6 +64,19 @@ sub encode_value {
return $value;
}
+sub remove_vmid_from_job {
+ my ($class, $job, $vmid) = @_;
+
+ if (defined($job->{vmid})) {
+ $job->{vmid} = join(',', grep { $_ ne $vmid } PVE::Tools::split_list($job->{vmid}));
+ undef $job if $job->{vmid} eq '';
+ } elsif (defined($job->{exclude})) {
+ $job->{exclude} = join(',', grep { $_ ne $vmid } PVE::Tools::split_list($job->{exclude}));
+ delete $job->{exclude} if $job->{exclude} eq '';
+ }
+ return $job;
+}
+
sub run {
my ($class, $conf) = @_;
--
2.30.2
next prev parent reply other threads:[~2022-03-14 9:27 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-14 9:26 [pve-devel] [PATCH-SERIES v3] fix #3903: remove vmid from jobs.cfg on destroy Hannes Laimer
2022-03-14 9:26 ` Hannes Laimer [this message]
2022-03-14 10:00 ` [pve-devel] [PATCH pve-manager v3 1/3] fix #3903: jobs: add remove vmid from jobs helper Fabian Ebner
2022-03-14 10:18 ` Fabian Ebner
2022-03-15 10:52 ` [pve-devel] [PATCH pve-manager v4 " Hannes Laimer
2022-03-14 9:26 ` [pve-devel] [PATCH pve-container v3 2/3] fix #3903: api2: remove vmid from jobs.cfg Hannes Laimer
2022-03-14 9:26 ` [pve-devel] [PATCH qemu-server v3 3/3] " Hannes Laimer
2022-03-16 7:15 ` [pve-devel] [PATCH-SERIES v3] fix #3903: remove vmid from jobs.cfg on destroy 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=20220314092657.48696-2-h.laimer@proxmox.com \
--to=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