public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH guest-common] replication: avoid passing removed storages to target
@ 2023-06-23 10:08 Fiona Ebner
  2023-08-30  9:12 ` Fiona Ebner
  2023-08-30  9:27 ` Thomas Lamprecht
  0 siblings, 2 replies; 5+ messages in thread
From: Fiona Ebner @ 2023-06-23 10:08 UTC (permalink / raw)
  To: pve-devel

After removing a storage, replication states can still contain
references to it, even if no volume references it anymore.

If a storage does not exist in the storage configuration, the
replication target runs into an error when preparing the job locally.
This error prevents both running and removing the replication job. Fix
it by not passing the invalid storage ID in the first place.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
 src/PVE/Replication.pm | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/PVE/Replication.pm b/src/PVE/Replication.pm
index 469ca19..bd627e5 100644
--- a/src/PVE/Replication.pm
+++ b/src/PVE/Replication.pm
@@ -275,6 +275,9 @@ sub replicate {
     $logfunc->("guest => $guest_name, running => $running");
     $logfunc->("volumes => " . join(',', @$sorted_volids));
 
+    # filter out left-over non-existing/removed storages - avoids error on target
+    $state->{storeid_list} = [ grep { $storecfg->{ids}->{$_} } $state->{storeid_list}->@* ];
+
     if (my $remove_job = $jobcfg->{remove_job}) {
 
 	$logfunc->("start job removal - mode '${remove_job}'");
-- 
2.39.2





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [pve-devel] [PATCH guest-common] replication: avoid passing removed storages to target
  2023-06-23 10:08 [pve-devel] [PATCH guest-common] replication: avoid passing removed storages to target Fiona Ebner
@ 2023-08-30  9:12 ` Fiona Ebner
  2023-08-30  9:27 ` Thomas Lamprecht
  1 sibling, 0 replies; 5+ messages in thread
From: Fiona Ebner @ 2023-08-30  9:12 UTC (permalink / raw)
  To: pve-devel

Ping

Am 23.06.23 um 12:08 schrieb Fiona Ebner:
> After removing a storage, replication states can still contain
> references to it, even if no volume references it anymore.
> 
> If a storage does not exist in the storage configuration, the
> replication target runs into an error when preparing the job locally.
> This error prevents both running and removing the replication job. Fix
> it by not passing the invalid storage ID in the first place.
> 
> Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [pve-devel] [PATCH guest-common] replication: avoid passing removed storages to target
  2023-06-23 10:08 [pve-devel] [PATCH guest-common] replication: avoid passing removed storages to target Fiona Ebner
  2023-08-30  9:12 ` Fiona Ebner
@ 2023-08-30  9:27 ` Thomas Lamprecht
  2023-08-30  9:42   ` Fiona Ebner
  1 sibling, 1 reply; 5+ messages in thread
From: Thomas Lamprecht @ 2023-08-30  9:27 UTC (permalink / raw)
  To: Proxmox VE development discussion, Fiona Ebner

Am 23/06/2023 um 12:08 schrieb Fiona Ebner:
> +    # filter out left-over non-existing/removed storages - avoids error on target
> +    $state->{storeid_list} = [ grep { $storecfg->{ids}->{$_} } $state->{storeid_list}->@* ];

looks fine in general, just wondering if we'd be better of to make
the grep include-condition a bit more explicit by using `exists` on
the hash:

$state->{storeid_list} = [ grep { exists $storecfg->{ids}->{$_} } $state->{storeid_list}->@* ];

albeit, the value should be always truthy, so might be redundant,
depending on how you see this I can apply this patch or a v2.




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [pve-devel] [PATCH guest-common] replication: avoid passing removed storages to target
  2023-08-30  9:27 ` Thomas Lamprecht
@ 2023-08-30  9:42   ` Fiona Ebner
  2023-09-01  7:40     ` Thomas Lamprecht
  0 siblings, 1 reply; 5+ messages in thread
From: Fiona Ebner @ 2023-08-30  9:42 UTC (permalink / raw)
  To: Thomas Lamprecht, Proxmox VE development discussion

Am 30.08.23 um 11:27 schrieb Thomas Lamprecht:
> Am 23/06/2023 um 12:08 schrieb Fiona Ebner:
>> +    # filter out left-over non-existing/removed storages - avoids error on target
>> +    $state->{storeid_list} = [ grep { $storecfg->{ids}->{$_} } $state->{storeid_list}->@* ];
> 
> looks fine in general, just wondering if we'd be better of to make
> the grep include-condition a bit more explicit by using `exists` on
> the hash:
> 
> $state->{storeid_list} = [ grep { exists $storecfg->{ids}->{$_} } $state->{storeid_list}->@* ];
> 
> albeit, the value should be always truthy, so might be redundant,
> depending on how you see this I can apply this patch or a v2.

I don't like using exists() expect when it's really necessary, because
it's way too easy picking up something that was auto-vivified
accidentally (shouldn't happen in this case, but still). And yes, we can
assume the value is truthy if it's an existing storage, so I didn't
bother with defined() either.




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [pve-devel] [PATCH guest-common] replication: avoid passing removed storages to target
  2023-08-30  9:42   ` Fiona Ebner
@ 2023-09-01  7:40     ` Thomas Lamprecht
  0 siblings, 0 replies; 5+ messages in thread
From: Thomas Lamprecht @ 2023-09-01  7:40 UTC (permalink / raw)
  To: Fiona Ebner, Proxmox VE development discussion

Am 30/08/2023 um 11:42 schrieb Fiona Ebner:
> Am 30.08.23 um 11:27 schrieb Thomas Lamprecht:
>> Am 23/06/2023 um 12:08 schrieb Fiona Ebner:
>>> +    # filter out left-over non-existing/removed storages - avoids error on target
>>> +    $state->{storeid_list} = [ grep { $storecfg->{ids}->{$_} } $state->{storeid_list}->@* ];
>>
>> looks fine in general, just wondering if we'd be better of to make
>> the grep include-condition a bit more explicit by using `exists` on
>> the hash:
>>
>> $state->{storeid_list} = [ grep { exists $storecfg->{ids}->{$_} } $state->{storeid_list}->@* ];
>>
>> albeit, the value should be always truthy, so might be redundant,
>> depending on how you see this I can apply this patch or a v2.
> 
> I don't like using exists() expect when it's really necessary, because
> it's way too easy picking up something that was auto-vivified
> accidentally (shouldn't happen in this case, but still).

Unwanted auto-vivification is always a bug though, and can cause problems
elsewhere, so "hiding" them more might make things harder to debug..
But yeah, if, defined would be the better choice here.

> And yes, we can
> assume the value is truthy if it's an existing storage, so I didn't
> bother with defined() either.

Yeah, while refactoring can sometimes change such invariants, I really
doubt it will happen here, so it's fine.

applied, thanks!




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-09-01  7:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-23 10:08 [pve-devel] [PATCH guest-common] replication: avoid passing removed storages to target Fiona Ebner
2023-08-30  9:12 ` Fiona Ebner
2023-08-30  9:27 ` Thomas Lamprecht
2023-08-30  9:42   ` Fiona Ebner
2023-09-01  7:40     ` Thomas Lamprecht

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal