[pve-devel] [PATCH storage] fix #5008: prevent adding pbs storage with invalid namespace

Philipp Hufnagl p.hufnagl at proxmox.com
Wed Nov 15 11:40:26 CET 2023



On 11/15/23 11:09, Thomas Lamprecht wrote:
> Am 15/11/2023 um 11:05 schrieb Philipp Hufnagl:
>>
>>
>> On 11/15/23 10:52, Thomas Lamprecht wrote:
>>> Am 15/11/2023 um 10:37 schrieb Philipp Hufnagl:
>>>> On 11/15/23 09:31, Fiona Ebner wrote:
>>>>> Am 14.11.23 um 15:27 schrieb Philipp Hufnagl:
>>>>>> diff --git a/src/PVE/Storage/PBSPlugin.pm b/src/PVE/Storage/PBSPlugin.pm
>>>>>> index 4320974..aceb2c4 100644
>>>>>> --- a/src/PVE/Storage/PBSPlugin.pm
>>>>>> +++ b/src/PVE/Storage/PBSPlugin.pm
>>>>>> @@ -817,6 +817,17 @@ sub scan_datastores {
>>>>>>      return $response;
>>>>>>  }
>>>>>>  
>>>>>> +sub scan_namespaces {
>>>>>> +    my ($scfg, $datastore, $password) = @_;
>>>>>> +
>>>>>> +    my $conn = pbs_api_connect($scfg, $password);
>>>>>
>>>>> Not super important, but would be nice to have a way to re-use the same
>>>>> connection in scan_datastores() and here, since activate_storage() will
>>>>> call both of them.
>>>>
>>>> scan_datastores() seem to be called somewhere else as well. I see if I
>>>> can find a way to reuse the connection but not break the code there.
>>>
>>>
>>> In the long run it maybe could be better to have an explicit check_availability
>>> hook, but IMO it's a bit late in the release cycle for that as this needs a bit
>>> extra care, especially w.r.t. external plugins and our ABI compat.
>>>
>>> Anyhow, as workaround we might be able to do this check in the on_add_hook and
>>> on_update_hook methods for now.
>>
>> I am planning on introducing a function called "connect_if_none" that
>> checks if it gets passed a connection and if so, return it. If it gets
>> passed undef, it will establish a connection and return that one.
>>
>> That way a user can simply write something like
>>
>>   my $conn = connect_if_none($scfg, $password, $conn);
>>
>> and not worry about it.
> 
> 
> not sure how above fits to my comment at all...
> Connection re-use is not the real issue here, doing it senslessy on every
> activate is..
> 
> And connect_if_none is a rather generic/undescriptive name and still would
> not solve re-use if done in different method calls, so a rather for only
> a very limited use case where one can just pass $conn around directly.

I can rename it.

I am not certain if I understand correctly. Aren't those hooks
trigered after adding a storage? The issue I am resolving here is
before the storage is actually added.





More information about the pve-devel mailing list