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 2D5F76621F for ; Thu, 5 Nov 2020 14:42:01 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 2447118F69 for ; Thu, 5 Nov 2020 14:41:31 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (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 id 6F10918F5B for ; Thu, 5 Nov 2020 14:41:29 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 3BD7C46038 for ; Thu, 5 Nov 2020 14:41:29 +0100 (CET) From: Fabian Ebner To: pbs-devel@lists.proxmox.com Date: Thu, 5 Nov 2020 14:36:29 +0100 Message-Id: <20201105133629.9802-2-f.ebner@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201105133629.9802-1-f.ebner@proxmox.com> References: <20201105133629.9802-1-f.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.029 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [proxmox.com, directory.rs] Subject: [pbs-devel] [PATCH proxmox-backup 2/2] bail if mount point already exists for directories 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: Thu, 05 Nov 2020 13:42:01 -0000 similar to what we do for zfs. By bailing before partitioning, the disk is still considered unused after a failed attempt. Signed-off-by: Fabian Ebner --- There is no other caller for create_datastore_mount_unit, so the check from the not yet applied https://lists.proxmox.com/pipermail/pbs-devel/2020-November/001297.html is superseded by this. src/api2/node/disks/directory.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/api2/node/disks/directory.rs b/src/api2/node/disks/directory.rs index 2a4780f2..da16e753 100644 --- a/src/api2/node/disks/directory.rs +++ b/src/api2/node/disks/directory.rs @@ -142,6 +142,18 @@ pub fn create_datastore_disk( bail!("disk '{}' is already in use.", disk); } + let mount_point = format!("/mnt/datastore/{}", &name); + + // check if the default path does exist already and bail if it does + let default_path = std::path::PathBuf::from(&mount_point); + + match std::fs::metadata(&default_path) { + Err(_) => {}, // path does not exist + Ok(_) => { + bail!("path {:?} already exists", default_path); + } + } + let upid_str = WorkerTask::new_thread( "dircreate", Some(name.clone()), auth_id, to_stdout, move |worker| { @@ -160,7 +172,7 @@ pub fn create_datastore_disk( let uuid = get_fs_uuid(&partition)?; let uuid_path = format!("/dev/disk/by-uuid/{}", uuid); - let (mount_unit_name, mount_point) = create_datastore_mount_unit(&name, filesystem, &uuid_path)?; + let mount_unit_name = create_datastore_mount_unit(&name, &mount_point, filesystem, &uuid_path)?; systemd::reload_daemon()?; systemd::enable_unit(&mount_unit_name)?; @@ -243,11 +255,11 @@ pub const ROUTER: Router = Router::new() fn create_datastore_mount_unit( datastore_name: &str, + mount_point: &str, fs_type: FileSystemType, what: &str, -) -> Result<(String, String), Error> { +) -> Result { - let mount_point = format!("/mnt/datastore/{}", datastore_name); let mut mount_unit_name = systemd::escape_unit(&mount_point, true); mount_unit_name.push_str(".mount"); @@ -265,7 +277,7 @@ fn create_datastore_mount_unit( let mount = SystemdMountSection { What: what.to_string(), - Where: mount_point.clone(), + Where: mount_point.to_string(), Type: Some(fs_type.to_string()), Options: Some(String::from("defaults")), ..Default::default() @@ -278,5 +290,5 @@ fn create_datastore_mount_unit( systemd::config::save_systemd_mount(&mount_unit_path, &config)?; - Ok((mount_unit_name, mount_point)) + Ok(mount_unit_name) } -- 2.20.1