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 6F48B7A8E1 for ; Tue, 5 Jul 2022 15:09:17 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id B53E82F509 for ; Tue, 5 Jul 2022 15:08:55 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (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 firstgate.proxmox.com (Proxmox) with ESMTPS for ; Tue, 5 Jul 2022 15:08:50 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 50E1B43C5F for ; Tue, 5 Jul 2022 15:08:49 +0200 (CEST) From: Hannes Laimer To: pbs-devel@lists.proxmox.com Date: Tue, 5 Jul 2022 13:08:15 +0000 Message-Id: <20220705130834.14285-10-h.laimer@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220705130834.14285-1-h.laimer@proxmox.com> References: <20220705130834.14285-1-h.laimer@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.042 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 SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [datastore.rs] Subject: [pbs-devel] [PATCH proxmox-backup 07/26] api2: datastore create: don't init chunkstore if removable 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: Tue, 05 Jul 2022 13:09:17 -0000 .. instead set the maintenance mode to unplugged. So on creation every removable datastore is unplugged until a removable device is associated with it. Signed-off-by: Hannes Laimer --- src/api2/config/datastore.rs | 52 +++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/src/api2/config/datastore.rs b/src/api2/config/datastore.rs index 2d769722..24d7a37a 100644 --- a/src/api2/config/datastore.rs +++ b/src/api2/config/datastore.rs @@ -1,19 +1,20 @@ use std::path::PathBuf; use ::serde::{Deserialize, Serialize}; -use anyhow::Error; +use anyhow::{bail, Error}; use hex::FromHex; use serde_json::Value; use proxmox_router::{http_bail, Permission, Router, RpcEnvironment, RpcEnvironmentType}; use proxmox_schema::{api, param_bail, ApiType}; use proxmox_section_config::SectionConfigData; +use proxmox_sys::fs::CreateOptions; use proxmox_sys::WorkerTaskContext; use pbs_api_types::{ - Authid, DataStoreConfig, DataStoreConfigUpdater, DatastoreNotify, DATASTORE_SCHEMA, - PRIV_DATASTORE_ALLOCATE, PRIV_DATASTORE_AUDIT, PRIV_DATASTORE_MODIFY, - PROXMOX_CONFIG_DIGEST_SCHEMA, + Authid, DataStoreConfig, DataStoreConfigUpdater, DatastoreNotify, MaintenanceMode, + MaintenanceType, DATASTORE_SCHEMA, PRIV_DATASTORE_ALLOCATE, PRIV_DATASTORE_AUDIT, + PRIV_DATASTORE_MODIFY, PROXMOX_CONFIG_DIGEST_SCHEMA, }; use pbs_config::BackupLockGuard; use pbs_datastore::chunk_store::ChunkStore; @@ -65,19 +66,37 @@ pub fn list_datastores( pub(crate) fn do_create_datastore( _lock: BackupLockGuard, mut config: SectionConfigData, - datastore: DataStoreConfig, + mut datastore: DataStoreConfig, worker: Option<&dyn WorkerTaskContext>, ) -> Result<(), Error> { let path: PathBuf = datastore.path.clone().into(); - let backup_user = pbs_config::backup_user()?; - let _store = ChunkStore::create( - &datastore.name, - path, - backup_user.uid, - backup_user.gid, - worker, - )?; + let _store; + + if !datastore.removable { + _store = ChunkStore::create( + &datastore.name, + path, + backup_user.uid, + backup_user.gid, + worker, + )?; + } else { + let options = CreateOptions::new() + .owner(backup_user.uid) + .group(backup_user.gid); + let default_options = CreateOptions::new(); + match proxmox_sys::fs::create_path(&datastore.path, Some(default_options), Some(options)) { + Err(err) => bail!("unable to create directory '{}' - {}", &datastore.path, err), + Ok(res) => { + if !res { + nix::unistd::chown(&path, Some(backup_user.uid), Some(backup_user.gid))? + } + } + } + + datastore.set_maintenance_mode(MaintenanceMode::new(MaintenanceType::Unplugged, None)); + } config.set_data(&datastore.name, "datastore", &datastore)?; @@ -351,6 +370,13 @@ pub fn update_datastore( } if update.maintenance_mode.is_some() { + if let Some(maintenance) = data.get_maintenance_mode() { + if data.removable && maintenance.ty == MaintenanceType::Unplugged { + bail!( + "can't change the maintenance mode as long as no removable device is present" + ); + } + } data.maintenance_mode = update.maintenance_mode; } -- 2.30.2