public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pbs-devel] [PATCH proxmox-backup v3] api: enhance directory existence check
@ 2023-11-30 10:37 Markus Frank
  2024-04-08 12:27 ` Markus Frank
  2024-04-08 13:13 ` [pbs-devel] applied: " Thomas Lamprecht
  0 siblings, 2 replies; 3+ messages in thread
From: Markus Frank @ 2023-11-30 10:37 UTC (permalink / raw)
  To: pbs-devel

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 <m.frank@proxmox.com>
Tested-by: Christian Ebner <c.ebner@proxmox.com>
---
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");
+            }
         }
     }
 
-- 
2.39.2





^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [pbs-devel] [PATCH proxmox-backup v3] api: enhance directory existence check
  2023-11-30 10:37 [pbs-devel] [PATCH proxmox-backup v3] api: enhance directory existence check Markus Frank
@ 2024-04-08 12:27 ` Markus Frank
  2024-04-08 13:13 ` [pbs-devel] applied: " Thomas Lamprecht
  1 sibling, 0 replies; 3+ messages in thread
From: Markus Frank @ 2024-04-08 12:27 UTC (permalink / raw)
  To: pbs-devel

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 <m.frank@proxmox.com>
> Tested-by: Christian Ebner <c.ebner@proxmox.com>
> ---
> 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");
> +            }
>           }
>       }
>   




^ permalink raw reply	[flat|nested] 3+ messages in thread

* [pbs-devel] applied: [PATCH proxmox-backup v3] api: enhance directory existence check
  2023-11-30 10:37 [pbs-devel] [PATCH proxmox-backup v3] api: enhance directory existence check Markus Frank
  2024-04-08 12:27 ` Markus Frank
@ 2024-04-08 13:13 ` Thomas Lamprecht
  1 sibling, 0 replies; 3+ messages in thread
From: Thomas Lamprecht @ 2024-04-08 13:13 UTC (permalink / raw)
  To: Proxmox Backup Server development discussion, Markus Frank

The commit subject is not really telling, "enhance" can mean lots of things
and which directory check is meant would be also good to get here...

I changed it to:

"api: datastore create: allow re-using existing dirs if empty & not a mountpoint"

It's a bit crowded, but much more telling about what this is about.

I also reworded the commit message, as when reading first I got slightly
confused and for a moment thought that we allowed this before your patch, but
would not allow it anymore now.


Am 30/11/2023 um 11:37 schrieb Markus Frank:
> 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 <m.frank@proxmox.com>
> Tested-by: Christian Ebner <c.ebner@proxmox.com>
> ---
> 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(-)
> 
>

applied, thanks!




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-04-08 13:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-30 10:37 [pbs-devel] [PATCH proxmox-backup v3] api: enhance directory existence check Markus Frank
2024-04-08 12:27 ` Markus Frank
2024-04-08 13:13 ` [pbs-devel] applied: " Thomas Lamprecht

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal