public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Christian Ebner <c.ebner@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [PATCH proxmox-backup v3 06/15] pbs-config: use proxmox-product-config helpers
Date: Wed,  1 Jul 2026 16:04:03 +0200	[thread overview]
Message-ID: <20260701140412.200920-7-c.ebner@proxmox.com> (raw)
In-Reply-To: <20260701140412.200920-1-c.ebner@proxmox.com>

Avoids expensive user lookups via pbs-config::backup_user(),
which internally calls User::from_name() and uses getpwnam_r(3) [0],
therefore can involve nsswitch.conf and /etc/passwd parsing
requiring several syscalls to do so.

[0] https://docs.rs/nix/0.29.0/nix/unistd/struct.User.html#method.from_name

Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
---
 pbs-config/src/config_version_cache.rs | 2 +-
 pbs-config/src/encryption_keys.rs      | 2 +-
 pbs-config/src/token_shadow.rs         | 8 +-------
 3 files changed, 3 insertions(+), 9 deletions(-)

diff --git a/pbs-config/src/config_version_cache.rs b/pbs-config/src/config_version_cache.rs
index a282da746..5053f6dc6 100644
--- a/pbs-config/src/config_version_cache.rs
+++ b/pbs-config/src/config_version_cache.rs
@@ -92,7 +92,7 @@ impl ConfigVersionCache {
 
     // Actual work of `new`:
     fn open() -> Result<Arc<Self>, Error> {
-        let user = crate::backup_user()?;
+        let user = proxmox_product_config::get_api_user();
 
         let dir_opts = CreateOptions::new()
             .perm(Mode::from_bits_truncate(0o770))
diff --git a/pbs-config/src/encryption_keys.rs b/pbs-config/src/encryption_keys.rs
index 3f8870254..367ac1e12 100644
--- a/pbs-config/src/encryption_keys.rs
+++ b/pbs-config/src/encryption_keys.rs
@@ -107,7 +107,7 @@ pub fn store_key(id: &str, key: &KeyConfig) -> Result<(), Error> {
         bail!("key with id '{id}' already exists.");
     }
 
-    let backup_user = crate::backup_user()?;
+    let backup_user = proxmox_product_config::get_api_user();
     let dir_options = CreateOptions::new()
         .perm(Mode::from_bits_truncate(0o0750))
         .owner(Uid::from_raw(0))
diff --git a/pbs-config/src/token_shadow.rs b/pbs-config/src/token_shadow.rs
index 871218411..d931cc6fa 100644
--- a/pbs-config/src/token_shadow.rs
+++ b/pbs-config/src/token_shadow.rs
@@ -9,7 +9,6 @@ use parking_lot::RwLock;
 use serde::{Deserialize, Serialize};
 use serde_json::{Value, from_value};
 
-use proxmox_sys::fs::CreateOptions;
 use proxmox_time::epoch_i64;
 
 use pbs_api_types::Authid;
@@ -59,12 +58,7 @@ fn read_file() -> Result<HashMap<Authid, String>, Error> {
 }
 
 fn write_file(data: HashMap<Authid, String>) -> Result<(), Error> {
-    let backup_user = crate::backup_user()?;
-    let options = CreateOptions::new()
-        .perm(nix::sys::stat::Mode::from_bits_truncate(0o0640))
-        .owner(backup_user.uid)
-        .group(backup_user.gid);
-
+    let options = proxmox_product_config::default_create_options();
     let json = serde_json::to_vec(&data)?;
     proxmox_sys::fs::replace_file(CONF_FILE, &json, options, true)
 }
-- 
2.47.3





  parent reply	other threads:[~2026-07-01 14:05 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-01 14:03 [PATCH proxmox-backup v3 00/15] fix 7642: avoid expensive uid/gid lookups for lock- and config-files Christian Ebner
2026-07-01 14:03 ` [PATCH proxmox-backup v3 01/15] bin: api: early init proxmox-product-config Christian Ebner
2026-07-01 14:03 ` [PATCH proxmox-backup v3 02/15] bin: daily update: refactor to use proxmox-product-config Christian Ebner
2026-07-01 14:04 ` [PATCH proxmox-backup v3 03/15] pbs-config: use proxmox-product-config::replace_secret_config() Christian Ebner
2026-07-01 14:04 ` [PATCH proxmox-backup v3 04/15] pbs-config: use proxmox-product-config::replace_config() Christian Ebner
2026-07-01 14:04 ` [PATCH proxmox-backup v3 05/15] fix #7642: avoid expensive user lookups on file locking Christian Ebner
2026-07-01 14:04 ` Christian Ebner [this message]
2026-07-01 14:04 ` [PATCH proxmox-backup v3 07/15] pbs-config: drop backup_group helper, use users gid instead Christian Ebner
2026-07-01 14:04 ` [PATCH proxmox-backup v3 08/15] pbs-datastore: use proxmox-product-config cached backup user Christian Ebner
2026-07-01 14:04 ` [PATCH proxmox-backup v3 09/15] pbs-datastore: use general helpers for file lock create options Christian Ebner
2026-07-01 14:04 ` [PATCH proxmox-backup v3 10/15] server: auth helpers: use proxmox-product-config create options helpers Christian Ebner
2026-07-01 14:04 ` [PATCH proxmox-backup v3 11/15] api: subscription: use proxmox-product-config create options Christian Ebner
2026-07-01 14:04 ` [PATCH proxmox-backup v3 12/15] tape: use proxmox-product-config helper for user lookup Christian Ebner
2026-07-01 14:04 ` [PATCH proxmox-backup v3 13/15] tape: use proxmox-product-config lock file create options Christian Ebner
2026-07-01 14:04 ` [PATCH proxmox-backup v3 14/15] tape: use proxmox-product-config to generate " Christian Ebner
2026-07-01 14:04 ` [PATCH proxmox-backup v3 15/15] tree-wide: use proxmox-product-config::get_api_user for user lookup Christian Ebner

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=20260701140412.200920-7-c.ebner@proxmox.com \
    --to=c.ebner@proxmox.com \
    --cc=pbs-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
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal