From: "Fabian Grünbichler" <f.gruenbichler@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup] api: create_datastore: fix nesting checks
Date: Wed, 27 Nov 2024 14:05:21 +0100 [thread overview]
Message-ID: <20241127130521.1019765-1-f.gruenbichler@proxmox.com> (raw)
there two kinds of overlap we need to check here:
- two removable datastores backed by the same device must not have nested
relative paths on the device
- any two datastores must not have nested absolute paths
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
---
src/api2/config/datastore.rs | 25 +++++++++++++++++--------
1 file changed, 17 insertions(+), 8 deletions(-)
diff --git a/src/api2/config/datastore.rs b/src/api2/config/datastore.rs
index 24d3f6303..c72eb5a72 100644
--- a/src/api2/config/datastore.rs
+++ b/src/api2/config/datastore.rs
@@ -82,21 +82,30 @@ pub(crate) fn do_create_datastore(
bail!("cannot create datastore in root path");
}
- let new_store_path = Path::new(&datastore.path);
+ let new_store_path = PathBuf::from(&datastore.absolute_path());
+ let removable = datastore.backing_device.is_some();
for store in config.convert_to_typed_array::<DataStoreConfig>("datastore")? {
- if store.backing_device != datastore.backing_device {
- continue;
+ // Relative paths must not be nested on the backing device of removable datastores
+ if removable && store.backing_device == datastore.backing_device {
+ let new_path = Path::new(&datastore.path);
+ let path = Path::new(&store.path);
+ if new_path.starts_with(path) || path.starts_with(new_path) {
+ param_bail!(
+ "path",
+ "paths on backing device must not be nested - {path:?} already used by '{store}'!",
+ store = store.name
+ );
+ }
}
- // Since we check for that on creation, we assume all removable datastore
- // paths are relative, so don't have a leading `/`.
- let store_path = Path::new(&store.path);
+ // No two datastores should have a nested absolute path
+ let store_path = PathBuf::from(store.absolute_path());
if store_path.starts_with(&new_store_path) || new_store_path.starts_with(&store_path) {
param_bail!(
"path",
- "nested datastores not allowed: '{}' already in '{}'",
+ "nested datastores not allowed: '{}' already in {:?}",
store.name,
- store.path
+ store_path,
);
}
}
--
2.39.5
_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
next reply other threads:[~2024-11-27 13:05 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-27 13:05 Fabian Grünbichler [this message]
2024-11-27 13:23 ` [pbs-devel] applied: " Thomas Lamprecht
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241127130521.1019765-1-f.gruenbichler@proxmox.com \
--to=f.gruenbichler@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox