* [pbs-devel] [PATCH proxmox-backup] fix: proxmox-backup-manager network reload wait on worker
@ 2024-08-21 10:22 Gabriel Goller
2024-08-29 12:17 ` [pbs-devel] applied: " Wolfgang Bumiller
0 siblings, 1 reply; 4+ messages in thread
From: Gabriel Goller @ 2024-08-21 10:22 UTC (permalink / raw)
To: pbs-devel
Make the `network reload` command in proxmox-backup-manager wait on the
api handler's workertask. Otherwise the task would be killed when the
client exits.
Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
---
src/bin/proxmox_backup_manager/network.rs | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/src/bin/proxmox_backup_manager/network.rs b/src/bin/proxmox_backup_manager/network.rs
index deac5b1b2960..0f0a50a8932a 100644
--- a/src/bin/proxmox_backup_manager/network.rs
+++ b/src/bin/proxmox_backup_manager/network.rs
@@ -129,6 +129,24 @@ fn pending_network_changes(
Ok(Value::Null)
}
+#[api()]
+/// Reload network changes
+async fn reload_network_changes(
+ mut param: Value,
+ rpcenv: &mut dyn RpcEnvironment,
+) -> Result<Value, Error> {
+ param["node"] = "localhost".into();
+
+ let info = &api2::node::network::API_METHOD_RELOAD_NETWORK_CONFIG;
+ let result = match info.handler {
+ ApiHandler::Async(handler) => (handler)(param, info, rpcenv).await?,
+ _ => unreachable!(),
+ };
+ crate::wait_for_local_worker(result.as_str().unwrap()).await?;
+
+ Ok(Value::Null)
+}
+
pub fn network_commands() -> CommandLineInterface {
let cmd_def = CliCommandMap::new()
.insert("list", CliCommand::new(&API_METHOD_LIST_NETWORK_DEVICES))
@@ -168,8 +186,7 @@ pub fn network_commands() -> CommandLineInterface {
)
.insert(
"reload",
- CliCommand::new(&api2::node::network::API_METHOD_RELOAD_NETWORK_CONFIG)
- .fixed_param("node", String::from("localhost")),
+ CliCommand::new(&API_METHOD_RELOAD_NETWORK_CHANGES),
);
cmd_def.into()
--
2.39.2
_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* [pbs-devel] applied: [PATCH proxmox-backup] fix: proxmox-backup-manager network reload wait on worker
2024-08-21 10:22 [pbs-devel] [PATCH proxmox-backup] fix: proxmox-backup-manager network reload wait on worker Gabriel Goller
@ 2024-08-29 12:17 ` Wolfgang Bumiller
2024-08-30 8:18 ` Gabriel Goller
0 siblings, 1 reply; 4+ messages in thread
From: Wolfgang Bumiller @ 2024-08-29 12:17 UTC (permalink / raw)
To: Gabriel Goller; +Cc: pbs-devel
applied, thanks
On Wed, Aug 21, 2024 at 12:22:36PM GMT, Gabriel Goller wrote:
> Make the `network reload` command in proxmox-backup-manager wait on the
> api handler's workertask. Otherwise the task would be killed when the
> client exits.
>
> Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
> ---
> src/bin/proxmox_backup_manager/network.rs | 21 +++++++++++++++++++--
> 1 file changed, 19 insertions(+), 2 deletions(-)
>
> diff --git a/src/bin/proxmox_backup_manager/network.rs b/src/bin/proxmox_backup_manager/network.rs
> index deac5b1b2960..0f0a50a8932a 100644
> --- a/src/bin/proxmox_backup_manager/network.rs
> +++ b/src/bin/proxmox_backup_manager/network.rs
> @@ -129,6 +129,24 @@ fn pending_network_changes(
> Ok(Value::Null)
> }
>
> +#[api()]
> +/// Reload network changes
> +async fn reload_network_changes(
> + mut param: Value,
> + rpcenv: &mut dyn RpcEnvironment,
> +) -> Result<Value, Error> {
> + param["node"] = "localhost".into();
> +
> + let info = &api2::node::network::API_METHOD_RELOAD_NETWORK_CONFIG;
> + let result = match info.handler {
> + ApiHandler::Async(handler) => (handler)(param, info, rpcenv).await?,
> + _ => unreachable!(),
> + };
Note: we have the above pattern a lot. For `Schema` we already have a
bunch of `const fn unwrap_<type>_schema()`.
We can now also use `const {}` expressions, so maybe we should have
something like this for `ApiHandler` as well, with all these handler
functions then using something like:
let handler = const { info.handler.unwrap_async_handler() };
let result = (handler)(param, info, rpcenv).await?
> + crate::wait_for_local_worker(result.as_str().unwrap()).await?;
> +
> + Ok(Value::Null)
> +}
> +
> pub fn network_commands() -> CommandLineInterface {
> let cmd_def = CliCommandMap::new()
> .insert("list", CliCommand::new(&API_METHOD_LIST_NETWORK_DEVICES))
> @@ -168,8 +186,7 @@ pub fn network_commands() -> CommandLineInterface {
> )
> .insert(
> "reload",
> - CliCommand::new(&api2::node::network::API_METHOD_RELOAD_NETWORK_CONFIG)
> - .fixed_param("node", String::from("localhost")),
> + CliCommand::new(&API_METHOD_RELOAD_NETWORK_CHANGES),
> );
>
> cmd_def.into()
> --
> 2.39.2
_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [pbs-devel] applied: [PATCH proxmox-backup] fix: proxmox-backup-manager network reload wait on worker
2024-08-29 12:17 ` [pbs-devel] applied: " Wolfgang Bumiller
@ 2024-08-30 8:18 ` Gabriel Goller
2024-08-30 9:00 ` Wolfgang Bumiller
0 siblings, 1 reply; 4+ messages in thread
From: Gabriel Goller @ 2024-08-30 8:18 UTC (permalink / raw)
To: Wolfgang Bumiller; +Cc: pbs-devel
On 29.08.2024 14:17, Wolfgang Bumiller wrote:
>applied, thanks
>
>On Wed, Aug 21, 2024 at 12:22:36PM GMT, Gabriel Goller wrote:
>> Make the `network reload` command in proxmox-backup-manager wait on the
>> api handler's workertask. Otherwise the task would be killed when the
>> client exits.
>>
>> Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
>> ---
>> src/bin/proxmox_backup_manager/network.rs | 21 +++++++++++++++++++--
>> 1 file changed, 19 insertions(+), 2 deletions(-)
>>
>> diff --git a/src/bin/proxmox_backup_manager/network.rs b/src/bin/proxmox_backup_manager/network.rs
>> index deac5b1b2960..0f0a50a8932a 100644
>> --- a/src/bin/proxmox_backup_manager/network.rs
>> +++ b/src/bin/proxmox_backup_manager/network.rs
>> @@ -129,6 +129,24 @@ fn pending_network_changes(
>> Ok(Value::Null)
>> }
>>
>> +#[api()]
>> +/// Reload network changes
>> +async fn reload_network_changes(
>> + mut param: Value,
>> + rpcenv: &mut dyn RpcEnvironment,
>> +) -> Result<Value, Error> {
>> + param["node"] = "localhost".into();
>> +
>> + let info = &api2::node::network::API_METHOD_RELOAD_NETWORK_CONFIG;
>> + let result = match info.handler {
>> + ApiHandler::Async(handler) => (handler)(param, info, rpcenv).await?,
>> + _ => unreachable!(),
>> + };
>
>Note: we have the above pattern a lot. For `Schema` we already have a
>bunch of `const fn unwrap_<type>_schema()`.
>We can now also use `const {}` expressions, so maybe we should have
>something like this for `ApiHandler` as well, with all these handler
>functions then using something like:
>
> let handler = const { info.handler.unwrap_async_handler() };
> let result = (handler)(param, info, rpcenv).await?
>
Hmm on a second glance, I don't think we can do this currently.
I tried this:
pub const fn unwrap_async_handler(&self) -> &ApiAsyncHandlerFn {
match self {
ApiHandler::Async(a) => a,
_ => panic!("unwrap_async_handler called on wrong apihandler"),
}
}
But it doesn't compile because we have a &mut reference in
`ApiAsyncHandlerFn` and mutable references in `const fn`'s currently
don't work [0].
Obviously we can make everything non-const and still improve the
readability.
[0]: https://github.com/rust-lang/rust/issues/57349.
_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [pbs-devel] applied: [PATCH proxmox-backup] fix: proxmox-backup-manager network reload wait on worker
2024-08-30 8:18 ` Gabriel Goller
@ 2024-08-30 9:00 ` Wolfgang Bumiller
0 siblings, 0 replies; 4+ messages in thread
From: Wolfgang Bumiller @ 2024-08-30 9:00 UTC (permalink / raw)
To: Gabriel Goller; +Cc: pbs-devel
On Fri, Aug 30, 2024 at 10:18:22AM GMT, Gabriel Goller wrote:
> On 29.08.2024 14:17, Wolfgang Bumiller wrote:
> > applied, thanks
> >
> > On Wed, Aug 21, 2024 at 12:22:36PM GMT, Gabriel Goller wrote:
> > > Make the `network reload` command in proxmox-backup-manager wait on the
> > > api handler's workertask. Otherwise the task would be killed when the
> > > client exits.
> > >
> > > Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
> > > ---
> > > src/bin/proxmox_backup_manager/network.rs | 21 +++++++++++++++++++--
> > > 1 file changed, 19 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/src/bin/proxmox_backup_manager/network.rs b/src/bin/proxmox_backup_manager/network.rs
> > > index deac5b1b2960..0f0a50a8932a 100644
> > > --- a/src/bin/proxmox_backup_manager/network.rs
> > > +++ b/src/bin/proxmox_backup_manager/network.rs
> > > @@ -129,6 +129,24 @@ fn pending_network_changes(
> > > Ok(Value::Null)
> > > }
> > >
> > > +#[api()]
> > > +/// Reload network changes
> > > +async fn reload_network_changes(
> > > + mut param: Value,
> > > + rpcenv: &mut dyn RpcEnvironment,
> > > +) -> Result<Value, Error> {
> > > + param["node"] = "localhost".into();
> > > +
> > > + let info = &api2::node::network::API_METHOD_RELOAD_NETWORK_CONFIG;
> > > + let result = match info.handler {
> > > + ApiHandler::Async(handler) => (handler)(param, info, rpcenv).await?,
> > > + _ => unreachable!(),
> > > + };
> >
> > Note: we have the above pattern a lot. For `Schema` we already have a
> > bunch of `const fn unwrap_<type>_schema()`.
> > We can now also use `const {}` expressions, so maybe we should have
> > something like this for `ApiHandler` as well, with all these handler
> > functions then using something like:
> >
> > let handler = const { info.handler.unwrap_async_handler() };
> > let result = (handler)(param, info, rpcenv).await?
> >
>
> Hmm on a second glance, I don't think we can do this currently.
>
> I tried this:
>
> pub const fn unwrap_async_handler(&self) -> &ApiAsyncHandlerFn {
> match self {
> ApiHandler::Async(a) => a,
> _ => panic!("unwrap_async_handler called on wrong apihandler"),
> }
> }
>
> But it doesn't compile because we have a &mut reference in
> `ApiAsyncHandlerFn` and mutable references in `const fn`'s currently
> don't work [0].
>
> Obviously we can make everything non-const and still improve the
> readability.
>
> [0]: https://github.com/rust-lang/rust/issues/57349.
This looks like a bug, actually. The linked issue is about mutable
references used inside the functions, however, this mutable references
is actually part of a function signature in the *output*.
This has been addressed for *regular* function pointers here[0], but
apparently not for Fn traits.
[0] https://github.com/rust-lang/rust/pull/116015
_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-08-30 8:59 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-21 10:22 [pbs-devel] [PATCH proxmox-backup] fix: proxmox-backup-manager network reload wait on worker Gabriel Goller
2024-08-29 12:17 ` [pbs-devel] applied: " Wolfgang Bumiller
2024-08-30 8:18 ` Gabriel Goller
2024-08-30 9:00 ` Wolfgang Bumiller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox