From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 99A8975575 for ; Mon, 12 Jul 2021 17:23:42 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 8D0FC17EE3 for ; Mon, 12 Jul 2021 17:23:42 +0200 (CEST) Received: from elsa.proxmox.com (unknown [94.136.29.99]) by firstgate.proxmox.com (Proxmox) with ESMTP id 3C88E17ED9 for ; Mon, 12 Jul 2021 17:23:41 +0200 (CEST) Received: by elsa.proxmox.com (Postfix, from userid 0) id 2325BAE1B1C; Mon, 12 Jul 2021 17:23:41 +0200 (CEST) From: Dietmar Maurer To: pbs-devel@lists.proxmox.com Date: Mon, 12 Jul 2021 17:23:38 +0200 Message-Id: <20210712152338.249178-1-dietmar@proxmox.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.491 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment PROLO_LEO1 0.1 Meta Catches all Leo drug variations so far RDNS_NONE 0.793 Delivered to internal network by a host with no rDNS SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [PATCH proxmox-backup] change tape drive lock path X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 12 Jul 2021 15:23:42 -0000 New kernel has stricter checks on tmpfs with stick-bit on directories, so some commands (i.e. proxmox-tape changer status) fails when executed as root, because permission checks fails when locking the drive. This patch move the drive locks to /run/proxmox-backup/drive-lock. Note: This is incompatible to old locking mechmanism, so users may not run tape backups during update (or running backup can fail). --- Lock file permissions are still wrong if the user runs "proxmox-tape changer status" as root and the lock file does not exist already. src/bin/proxmox-backup-api.rs | 1 + src/tape/drive/mod.rs | 6 +++--- src/tape/mod.rs | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/bin/proxmox-backup-api.rs b/src/bin/proxmox-backup-api.rs index 25ed030a..a8fbbadb 100644 --- a/src/bin/proxmox-backup-api.rs +++ b/src/bin/proxmox-backup-api.rs @@ -45,6 +45,7 @@ async fn run() -> Result<(), Error> { proxmox_backup::tape::create_tape_status_dir()?; proxmox_backup::tape::create_drive_state_dir()?; proxmox_backup::tape::create_changer_state_dir()?; + proxmox_backup::tape::create_drive_lock_dir()?; if let Err(err) = generate_auth_key() { bail!("unable to generate auth key - {}", err); diff --git a/src/tape/drive/mod.rs b/src/tape/drive/mod.rs index 8010d576..fb4b6f47 100644 --- a/src/tape/drive/mod.rs +++ b/src/tape/drive/mod.rs @@ -568,7 +568,7 @@ pub fn get_tape_device_state( config: &SectionConfigData, drive: &str, ) -> Result, Error> { - let path = format!("/run/proxmox-backup/drive-state/{}", drive); + let path = format!("{}/{}", crate::tape::DRIVE_STATE_DIR, drive); let state = file_read_optional_string(path)?; let device_path = tape_device_path(config, drive)?; @@ -612,7 +612,7 @@ fn lock_device_path(device_path: &str) -> Result let lock_name = crate::tools::systemd::escape_unit(device_path, true); - let mut path = std::path::PathBuf::from("/var/lock"); + let mut path = std::path::PathBuf::from(crate::tape::DRIVE_LOCK_DIR); path.push(lock_name); let timeout = std::time::Duration::new(10, 0); @@ -637,7 +637,7 @@ fn test_device_path_lock(device_path: &str) -> Result { let lock_name = crate::tools::systemd::escape_unit(device_path, true); - let mut path = std::path::PathBuf::from("/var/lock"); + let mut path = std::path::PathBuf::from(crate::tape::DRIVE_LOCK_DIR); path.push(lock_name); let timeout = std::time::Duration::new(0, 0); diff --git a/src/tape/mod.rs b/src/tape/mod.rs index 5248d21b..8190e141 100644 --- a/src/tape/mod.rs +++ b/src/tape/mod.rs @@ -48,6 +48,9 @@ pub use pool_writer::*; /// Directory path where we store all tape status information pub const TAPE_STATUS_DIR: &str = "/var/lib/proxmox-backup/tape"; +/// Directory path where we store drive lock file +pub const DRIVE_LOCK_DIR: &str = concat!(PROXMOX_BACKUP_RUN_DIR_M!(), "/drive-lock"); + /// Directory path where we store temporary drive state pub const DRIVE_STATE_DIR: &str = concat!(PROXMOX_BACKUP_RUN_DIR_M!(), "/drive-state"); @@ -78,6 +81,21 @@ pub fn create_tape_status_dir() -> Result<(), Error> { Ok(()) } +/// Create drive lock dir with correct permission +pub fn create_drive_lock_dir() -> Result<(), Error> { + let backup_user = crate::backup::backup_user()?; + let mode = nix::sys::stat::Mode::from_bits_truncate(0o0750); + let options = CreateOptions::new() + .perm(mode) + .owner(backup_user.uid) + .group(backup_user.gid); + + create_path(DRIVE_LOCK_DIR, None, Some(options)) + .map_err(|err: Error| format_err!("unable to create drive state dir - {}", err))?; + + Ok(()) +} + /// Create drive state dir with correct permission pub fn create_drive_state_dir() -> Result<(), Error> { let backup_user = crate::backup::backup_user()?; -- 2.30.2