all lists on 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 12/15] tape: use proxmox-product-config helper for user lookup
Date: Wed,  1 Jul 2026 16:04:09 +0200	[thread overview]
Message-ID: <20260701140412.200920-13-c.ebner@proxmox.com> (raw)
In-Reply-To: <20260701140412.200920-1-c.ebner@proxmox.com>

By this the globally cached user information is used instead of doing
a lookup to be consistent with the rest of the codebase.

Tests are adapted to call the init exactly once by an init callback
for a LazyLock. This is thread safe, so tests can be run in parallel
without interference.

Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
---
 src/tape/media_catalog.rs             | 14 ++++----------
 src/tape/mod.rs                       |  8 ++++----
 src/tape/test/alloc_writable_media.rs | 17 +++++++++++++++++
 3 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/src/tape/media_catalog.rs b/src/tape/media_catalog.rs
index 41c1dcad0..4fcf45dc3 100644
--- a/src/tape/media_catalog.rs
+++ b/src/tape/media_catalog.rs
@@ -10,7 +10,7 @@ use endian_trait::Endian;
 use proxmox_sys::fs::read_subdir;
 
 use proxmox_io::{ReadExt, WriteExt};
-use proxmox_sys::fs::{CreateOptions, create_path, fchown};
+use proxmox_sys::fs::{create_path, fchown};
 use proxmox_uuid::Uuid;
 
 use pbs_api_types::{BackupDir, BackupNamespace, parse_ns_and_snapshot, print_ns_and_snapshot};
@@ -168,13 +168,7 @@ impl MediaCatalog {
     }
 
     fn create_basedir<P: AsRef<Path>>(base_path: P) -> Result<(), Error> {
-        let backup_user = pbs_config::backup_user()?;
-        let mode = nix::sys::stat::Mode::from_bits_truncate(0o0640);
-        let opts = CreateOptions::new()
-            .perm(mode)
-            .owner(backup_user.uid)
-            .group(backup_user.gid);
-
+        let opts = proxmox_product_config::default_create_options();
         create_path(base_path, None, Some(opts))
             .map_err(|err: Error| format_err!("unable to create media catalog dir - {}", err))?;
         Ok(())
@@ -200,7 +194,7 @@ impl MediaCatalog {
                 .create(create)
                 .open(&path)?;
 
-            let backup_user = pbs_config::backup_user()?;
+            let backup_user = proxmox_product_config::get_api_user();
             fchown(
                 file.as_raw_fd(),
                 Some(backup_user.uid),
@@ -261,7 +255,7 @@ impl MediaCatalog {
             return Ok(file);
         }
 
-        let backup_user = pbs_config::backup_user()?;
+        let backup_user = proxmox_product_config::get_api_user();
         fchown(
             file.as_raw_fd(),
             Some(backup_user.uid),
diff --git a/src/tape/mod.rs b/src/tape/mod.rs
index eba692035..c1f04595f 100644
--- a/src/tape/mod.rs
+++ b/src/tape/mod.rs
@@ -57,7 +57,7 @@ pub const COMMIT_BLOCK_SIZE: usize = 128 * 1024 * 1024 * 1024; // 128 GiB
 
 /// Create tape status dir with correct permission
 pub fn create_tape_status_dir() -> Result<(), Error> {
-    let backup_user = pbs_config::backup_user()?;
+    let backup_user = proxmox_product_config::get_api_user();
     let mode = nix::sys::stat::Mode::from_bits_truncate(0o0750);
     let options = CreateOptions::new()
         .perm(mode)
@@ -76,7 +76,7 @@ pub fn create_tape_status_dir() -> Result<(), Error> {
 
 /// Create drive lock dir with correct permission
 pub fn create_drive_lock_dir() -> Result<(), Error> {
-    let backup_user = pbs_config::backup_user()?;
+    let backup_user = proxmox_product_config::get_api_user();
     let mode = nix::sys::stat::Mode::from_bits_truncate(0o0750);
     let options = CreateOptions::new()
         .perm(mode)
@@ -95,7 +95,7 @@ pub fn create_drive_lock_dir() -> Result<(), Error> {
 
 /// Create drive state dir with correct permission
 pub fn create_drive_state_dir() -> Result<(), Error> {
-    let backup_user = pbs_config::backup_user()?;
+    let backup_user = proxmox_product_config::get_api_user();
     let mode = nix::sys::stat::Mode::from_bits_truncate(0o0750);
     let options = CreateOptions::new()
         .perm(mode)
@@ -114,7 +114,7 @@ pub fn create_drive_state_dir() -> Result<(), Error> {
 
 /// Create changer state cache dir with correct permission
 pub fn create_changer_state_dir() -> Result<(), Error> {
-    let backup_user = pbs_config::backup_user()?;
+    let backup_user = proxmox_product_config::get_api_user();
     let mode = nix::sys::stat::Mode::from_bits_truncate(0o0750);
     let options = CreateOptions::new()
         .perm(mode)
diff --git a/src/tape/test/alloc_writable_media.rs b/src/tape/test/alloc_writable_media.rs
index ff9a63489..fc1bb88ce 100644
--- a/src/tape/test/alloc_writable_media.rs
+++ b/src/tape/test/alloc_writable_media.rs
@@ -4,11 +4,20 @@
 
 use anyhow::Error;
 use std::path::PathBuf;
+use std::sync::LazyLock;
 
 use pbs_api_types::{MediaSetPolicy, RetentionPolicy};
 
 use crate::tape::{Inventory, MediaPool};
 
+static PROXMOX_PRODUCT_CONFIG_INIT_FOR_TESTS: LazyLock<bool> = LazyLock::new(|| {
+    proxmox_product_config::init(
+        pbs_config::backup_user().unwrap(),
+        pbs_config::priv_user().unwrap(),
+    );
+    true
+});
+
 fn create_testdir(name: &str) -> Result<PathBuf, Error> {
     let mut testdir: PathBuf = String::from("./target/testout").into();
     testdir.push(std::module_path!());
@@ -22,6 +31,8 @@ fn create_testdir(name: &str) -> Result<PathBuf, Error> {
 
 #[test]
 fn test_alloc_writable_media_1() -> Result<(), Error> {
+    assert_eq!(LazyLock::force(&PROXMOX_PRODUCT_CONFIG_INIT_FOR_TESTS), &true);
+
     let testdir = create_testdir("test_alloc_writable_media_1")?;
 
     let mut ctime = 0;
@@ -48,6 +59,8 @@ fn test_alloc_writable_media_1() -> Result<(), Error> {
 
 #[test]
 fn test_alloc_writable_media_2() -> Result<(), Error> {
+    assert_eq!(LazyLock::force(&PROXMOX_PRODUCT_CONFIG_INIT_FOR_TESTS), &true);
+
     let testdir = create_testdir("test_alloc_writable_media_2")?;
 
     let mut inventory = Inventory::load(&testdir)?;
@@ -85,6 +98,8 @@ fn test_alloc_writable_media_2() -> Result<(), Error> {
 
 #[test]
 fn test_alloc_writable_media_3() -> Result<(), Error> {
+    assert_eq!(LazyLock::force(&PROXMOX_PRODUCT_CONFIG_INIT_FOR_TESTS), &true);
+
     let testdir = create_testdir("test_alloc_writable_media_3")?;
 
     let mut inventory = Inventory::load(&testdir)?;
@@ -133,6 +148,8 @@ fn test_alloc_writable_media_3() -> Result<(), Error> {
 
 #[test]
 fn test_alloc_writable_media_4() -> Result<(), Error> {
+    assert_eq!(LazyLock::force(&PROXMOX_PRODUCT_CONFIG_INIT_FOR_TESTS), &true);
+
     let testdir = create_testdir("test_alloc_writable_media_4")?;
 
     let mut inventory = Inventory::load(&testdir)?;
-- 
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 ` [PATCH proxmox-backup v3 06/15] pbs-config: use proxmox-product-config helpers Christian Ebner
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 ` Christian Ebner [this message]
2026-07-01 14:04 ` [PATCH proxmox-backup v3 13/15] tape: use proxmox-product-config lock file " 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-13-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal