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 6719C93149 for ; Mon, 8 Apr 2024 14:27:22 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 483DC9E6E for ; Mon, 8 Apr 2024 14:27:22 +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 ; Mon, 8 Apr 2024 14:27:21 +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 D066B44074 for ; Mon, 8 Apr 2024 14:27:20 +0200 (CEST) Message-ID: <7a4b8210-ef17-4016-a1c9-6fcc0b027ba5@proxmox.com> Date: Mon, 8 Apr 2024 14:27:19 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: pbs-devel@lists.proxmox.com References: <20231130103724.46301-1-m.frank@proxmox.com> Content-Language: en-US From: Markus Frank In-Reply-To: <20231130103724.46301-1-m.frank@proxmox.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.033 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy 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 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [directory.rs] Subject: Re: [pbs-devel] [PATCH proxmox-backup v3] api: enhance directory existence check 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, 08 Apr 2024 12:27:22 -0000 Ping, the patch still applies. On 2023-11-30 11:37, Markus Frank wrote: > If a directory exists on the specified path, > it now also checks whether the directory is empty and not already mounted. > > Previously, if a directory were deleted and a directory with the same name > would be created, the old check prevented the creation even though the > directory could be used as a mount point. > > Signed-off-by: Markus Frank > Tested-by: Christian Ebner > --- > v3: changed comment > v2: added check if another file system is mounted on the specified path > > src/api2/node/disks/directory.rs | 15 ++++++++++++--- > 1 file changed, 12 insertions(+), 3 deletions(-) > > diff --git a/src/api2/node/disks/directory.rs b/src/api2/node/disks/directory.rs > index 5e1cb124..9f1112a9 100644 > --- a/src/api2/node/disks/directory.rs > +++ b/src/api2/node/disks/directory.rs > @@ -1,6 +1,7 @@ > use ::serde::{Deserialize, Serialize}; > use anyhow::{bail, Error}; > use serde_json::json; > +use std::os::linux::fs::MetadataExt; > > use proxmox_router::{Permission, Router, RpcEnvironment, RpcEnvironmentType}; > use proxmox_schema::api; > @@ -155,13 +156,21 @@ pub fn create_datastore_disk( > > let mount_point = format!("{}{}", BASE_MOUNT_DIR, &name); > > - // check if the default path does exist already and bail if it does > + // check if the default path exists already. > + // bail if it is not empty or another filesystem mounted on top > 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); > + Ok(stat) => { > + let basedir_dev = std::fs::metadata(BASE_MOUNT_DIR)?.st_dev(); > + if stat.st_dev() != basedir_dev { > + bail!("path {default_path:?} already exists and is mountpoint"); > + } > + let is_empty = default_path.read_dir()?.next().is_none(); > + if !is_empty { > + bail!("path {default_path:?} already exists and is not empty"); > + } > } > } >