From: "Jakob Klocker" <j.klocker@proxmox.com>
To: "Dominik Csapak" <d.csapak@proxmox.com>, <pve-devel@lists.proxmox.com>
Subject: Re: [PATCH guest-common v4 1/7] helpers: exec hookscript: add optional parameters
Date: Thu, 03 Sep 2026 10:52:52 +0200 [thread overview]
Message-ID: <DL5JYDS78NW3.3T3ZTQ9RQBPYH@proxmox.com> (raw)
In-Reply-To: <20260825135502.3971930-2-d.csapak@proxmox.com>
style-nit inline.
On Tue Aug 25, 2026 at 3:54 PM CEST, Dominik Csapak wrote:
> sometimes we may want to call the hookscript with additional parameters
> in some phases, e.g. we want to call it for each pci device that was
> prepared before starting with the correct uuid or pci id.
>
> Add these new parameters to the environment instead of the positional
> parameters of the hookscript, since that is more future proof and we get
> a key/value pair instead of just the position.
>
> Use the prefix 'PVE_HOOK_' so they're always in a separate namespace.
>
> Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
> ---
> src/PVE/GuestHelpers.pm | 12 +++++++++++-
> 1 file changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/src/PVE/GuestHelpers.pm b/src/PVE/GuestHelpers.pm
> index f8d112b..6899b05 100644
> --- a/src/PVE/GuestHelpers.pm
> +++ b/src/PVE/GuestHelpers.pm
> @@ -115,14 +115,24 @@ sub check_hookscript {
> }
>
> sub exec_hookscript {
> - my ($conf, $vmid, $phase, $stop_on_error) = @_;
> + my ($conf, $vmid, $phase, $stop_on_error, $params) = @_;
>
> return if !$conf->{hookscript};
>
> + $params //= {};
According to the Perl style guide [0],
`$params = {} if !defined($params);` is prefered over the `//=`
syntax.
Since I keep seeing this "old" syntax in new patches, I'm not sure if
this is strictly lived though.
[0] https://pve.proxmox.com/wiki/Perl_Style_Guide#Perl_syntax_choices
> +
> eval {
> my $hookscript = check_hookscript($conf->{hookscript});
> die $@ if $@;
>
> + # copy EVN before adding to it
misspelled `ENV` in the comment. Might also be good adding why
we're making a copy, instead of commenting what we're doing
> + local %ENV = (%ENV);
> +
> + for my $key (keys $params->%*) {
> + my $new_key = "PVE_HOOK_" . uc($key);
> + $ENV{$new_key} = $params->{$key};
> + }
> +
> PVE::Tools::run_command([$hookscript, $vmid, $phase]);
> };
> if (my $err = $@) {
next prev parent reply other threads:[~2026-09-03 8:52 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-25 13:54 [PATCH docs/guest-common/qemu-server v4 0/7] add new pci passthrough specific hookscript phase Dominik Csapak
2026-08-25 13:54 ` [PATCH guest-common v4 1/7] helpers: exec hookscript: add optional parameters Dominik Csapak
2026-09-03 8:40 ` Elias Huhsovitz
2026-09-03 8:52 ` Jakob Klocker [this message]
2026-08-25 13:54 ` [PATCH qemu-server v4 2/7] pci: mdev preparation: always generate local uuid first Dominik Csapak
2026-08-25 13:54 ` [PATCH qemu-server v4 3/7] pci: nvidia vgpu: correct wrong comment about uuid Dominik Csapak
2026-08-25 13:54 ` [PATCH qemu-server v4 4/7] pci: factor 'prepare_pci_devices' out to PVE::QemuServer::PCI module Dominik Csapak
2026-09-03 8:53 ` Jakob Klocker
2026-08-25 13:54 ` [PATCH qemu-server v4 5/7] pci: preparation: mdev: only generate uuid once Dominik Csapak
2026-08-25 13:54 ` [PATCH qemu-server v4 6/7] pci: call hookscript for each prepared pci device Dominik Csapak
2026-09-03 8:41 ` Elias Huhsovitz
2026-08-25 13:54 ` [PATCH docs v4 7/7] examples: add new hookscript phase to example hookscript Dominik Csapak
2026-09-03 8:41 ` Elias Huhsovitz
2026-08-26 6:10 ` [PATCH docs/guest-common/qemu-server v4 0/7] add new pci passthrough specific hookscript phase Dominik Csapak
2026-09-03 8:54 ` Jakob Klocker
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=DL5JYDS78NW3.3T3ZTQ9RQBPYH@proxmox.com \
--to=j.klocker@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