From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id CE0651FF13B for ; Wed, 08 Apr 2026 09:35:41 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id CE5CE213C; Wed, 8 Apr 2026 09:36:16 +0200 (CEST) Date: Wed, 08 Apr 2026 09:35:36 +0200 From: Fabian =?iso-8859-1?q?Gr=FCnbichler?= Subject: Re: [PATCH proxmox-backup v6 5/8] api: add PUT endpoint for move_namespace To: Hannes Laimer , pbs-devel@lists.proxmox.com References: <20260331123409.198353-1-h.laimer@proxmox.com> <20260331123409.198353-6-h.laimer@proxmox.com> In-Reply-To: <20260331123409.198353-6-h.laimer@proxmox.com> MIME-Version: 1.0 User-Agent: astroid/0.17.0 (https://github.com/astroidmail/astroid) Message-Id: <1775633527.1rtwr8uwd3.astroid@yuna.none> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1775633672430 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.096 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment POISEN_SPAM_PILL 0.1 Meta: its spam POISEN_SPAM_PILL_1 0.1 random spam to be learned in bayes POISEN_SPAM_PILL_3 0.1 random spam to be learned in bayes SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: DHC7AVOQYQVGCUIDAJMCVPTR3UKD6HJN X-Message-ID-Hash: DHC7AVOQYQVGCUIDAJMCVPTR3UKD6HJN X-MailFrom: f.gruenbichler@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox Backup Server development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On March 31, 2026 2:34 pm, Hannes Laimer wrote: > Add a PUT handler on /admin/datastore/{store}/namespace to move a > namespace (including all child namespaces and groups) to a new > location within the same datastore. The handler performs fast > pre-checks synchronously and spawns a worker task for the actual move. >=20 > Requires DATASTORE_MODIFY on the parent of both the source and target > namespaces, matching the permissions used by create_namespace() and > delete_namespace(). >=20 > Signed-off-by: Hannes Laimer > --- > src/api2/admin/namespace.rs | 78 ++++++++++++++++++++++++++++++++++++- > 1 file changed, 76 insertions(+), 2 deletions(-) >=20 > diff --git a/src/api2/admin/namespace.rs b/src/api2/admin/namespace.rs > index 30e24d8d..5b64fb0d 100644 > --- a/src/api2/admin/namespace.rs > +++ b/src/api2/admin/namespace.rs > @@ -1,12 +1,16 @@ > use anyhow::{bail, Error}; > =20 > use pbs_config::CachedUserInfo; > -use proxmox_router::{http_bail, ApiMethod, Permission, Router, RpcEnviro= nment}; > +use proxmox_rest_server::WorkerTask; > +use proxmox_router::{ > + http_bail, ApiMethod, Permission, Router, RpcEnvironment, RpcEnviron= mentType, > +}; > use proxmox_schema::*; > +use serde_json::{json, Value}; > =20 > use pbs_api_types::{ > Authid, BackupGroupDeleteStats, BackupNamespace, NamespaceListItem, = Operation, > - DATASTORE_SCHEMA, NS_MAX_DEPTH_SCHEMA, PROXMOX_SAFE_ID_FORMAT, > + DATASTORE_SCHEMA, NS_MAX_DEPTH_SCHEMA, PROXMOX_SAFE_ID_FORMAT, UPID_= SCHEMA, > }; > =20 > use pbs_datastore::DataStore; > @@ -189,7 +193,77 @@ pub fn delete_namespace( > Ok(stats) > } > =20 > +#[api( > + input: { > + properties: { > + store: { schema: DATASTORE_SCHEMA }, > + ns: { > + type: BackupNamespace, > + }, > + "new-ns": { > + type: BackupNamespace, same applies here, this is the target namespace > + }, > + }, > + }, > + returns: { > + schema: UPID_SCHEMA, > + }, > + access: { > + permission: &Permission::Anybody, > + description: "Requires DATASTORE_MODIFY on the parent of 'ns' an= d on the parent of 'new-ns'.", this matches what is required to delete and create namespaces, so seems fine. > + }, > +)] > +/// Move a backup namespace (including all child namespaces and groups) = to a new location. > +pub fn move_namespace( > + store: String, > + ns: BackupNamespace, > + new_ns: BackupNamespace, > + rpcenv: &mut dyn RpcEnvironment, > +) -> Result { > + let auth_id: Authid =3D rpcenv.get_auth_id().unwrap().parse()?; > + > + check_ns_modification_privs(&store, &ns, &auth_id)?; > + check_ns_modification_privs(&store, &new_ns, &auth_id)?; > + > + let datastore =3D DataStore::lookup_datastore(&store, Operation::Wri= te)?; > + > + // Best-effort pre-checks for a fast synchronous error before spawni= ng a worker. > + if ns.is_root() { > + bail!("cannot move root namespace"); > + } > + if ns =3D=3D new_ns { > + bail!("source and target namespace must be different"); > + } > + if !datastore.namespace_exists(&ns) { > + bail!("source namespace '{ns}' does not exist"); > + } > + if datastore.namespace_exists(&new_ns) { > + bail!("target namespace '{new_ns}' already exists"); > + } > + let target_parent =3D new_ns.parent(); > + if !datastore.namespace_exists(&target_parent) { > + bail!("target parent namespace '{target_parent}' does not exist"= ); > + } > + if ns.contains(&new_ns).is_some() { > + bail!("cannot move namespace '{ns}' into its own subtree (target= : '{new_ns}')"); > + } > + > + let worker_id =3D format!("{store}:{ns}"); same question here - would it make sense to include both source and target for better filtering? > + let to_stdout =3D rpcenv.env_type() =3D=3D RpcEnvironmentType::CLI; > + > + let upid_str =3D WorkerTask::new_thread( > + "move-namespace", > + Some(worker_id), > + auth_id.to_string(), > + to_stdout, > + move |_worker| datastore.move_namespace(&ns, &new_ns), > + )?; > + > + Ok(json!(upid_str)) > +} > + > pub const ROUTER: Router =3D Router::new() > .get(&API_METHOD_LIST_NAMESPACES) > .post(&API_METHOD_CREATE_NAMESPACE) > + .put(&API_METHOD_MOVE_NAMESPACE) > .delete(&API_METHOD_DELETE_NAMESPACE); > --=20 > 2.47.3 >=20 >=20 >=20 >=20 >=20 >=20