From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 170B61FF13E for ; Wed, 01 Jul 2026 11:46:58 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id BA47B2145A; Wed, 01 Jul 2026 11:46:56 +0200 (CEST) From: Christian Ebner To: pbs-devel@lists.proxmox.com Subject: [PATCH proxmox-backup v2 5/5] fix #7642: avoid expensive user lookups on file locking Date: Wed, 1 Jul 2026 11:46:42 +0200 Message-ID: <20260701094642.23895-6-c.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260701094642.23895-1-c.ebner@proxmox.com> References: <20260701094642.23895-1-c.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1782899199299 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.001 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) KAM_SHORT 0.001 Use of a URL Shortener for very short URL 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: 2E3QGD6LKEW5ZAXX4H2T64I6B3NSM2S7 X-Message-ID-Hash: 2E3QGD6LKEW5ZAXX4H2T64I6B3NSM2S7 X-MailFrom: c.ebner@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: Currently each time a backup lock file is being acquired, the backup user is looked in order to instantiate the create options used if the lock file is not pre-existing, which requires knowledge of the uid and gid. backup_user() internally however calls User::from_name(), which itself uses getpwnam_r(3) [0] and therefore can involve nsswitch.conf and /etc/passwd parsing, including several syscalls to do so (see backtrace in linked issue). Ideally proxmox_product_config::open_api_lockfile() would be used as drop in replacement for open_backup_lockfile(), which is however not possible until the currently required legacy locking fallback implementation remains in place (to be dropped with PBS 5). Therefore, only switch to proxmox_product_config::lockfile_create_options() for the time being. By this the api user as read on init is used for all file lock operations using this helper. [0] https://docs.rs/nix/0.29.0/nix/unistd/struct.User.html#method.from_name Fixes: https://bugzilla.proxmox.com/show_bug.cgi?id=7642 Signed-off-by: Christian Ebner --- pbs-config/src/lib.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pbs-config/src/lib.rs b/pbs-config/src/lib.rs index b9d5a4d20..73a8a87fa 100644 --- a/pbs-config/src/lib.rs +++ b/pbs-config/src/lib.rs @@ -4,6 +4,7 @@ use anyhow::{Error, bail, format_err}; use hex::FromHex; use nix::unistd::{Gid, Group, Uid, User}; +use proxmox_product_config::lockfile_create_options; use proxmox_sys::fs::DirLockGuard; pub use pbs_buildcfg::{BACKUP_GROUP_NAME, BACKUP_USER_NAME}; @@ -106,11 +107,9 @@ pub fn open_backup_lockfile>( timeout: Option, exclusive: bool, ) -> Result { - let user = backup_user()?; - let options = proxmox_sys::fs::CreateOptions::new() - .perm(nix::sys::stat::Mode::from_bits_truncate(0o660)) - .owner(user.uid) - .group(user.gid); + // TODO: Replace whole helper with proxmox_product_config::open_api_lockfile() when + // dropping _legacy_dir in in PBS5. + let options = lockfile_create_options(); let timeout = timeout.unwrap_or(std::time::Duration::new(10, 0)); -- 2.47.3