* [pbs-devel] [PATCH proxmox-backup] api: create_datastore: fix nesting checks
@ 2024-11-27 13:05 Fabian Grünbichler
2024-11-27 13:23 ` [pbs-devel] applied: " Thomas Lamprecht
0 siblings, 1 reply; 2+ messages in thread
From: Fabian Grünbichler @ 2024-11-27 13:05 UTC (permalink / raw)
To: pbs-devel
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* [pbs-devel] applied: [PATCH proxmox-backup] api: create_datastore: fix nesting checks
2024-11-27 13:05 [pbs-devel] [PATCH proxmox-backup] api: create_datastore: fix nesting checks Fabian Grünbichler
@ 2024-11-27 13:23 ` Thomas Lamprecht
0 siblings, 0 replies; 2+ messages in thread
From: Thomas Lamprecht @ 2024-11-27 13:23 UTC (permalink / raw)
To: Proxmox Backup Server development discussion, Fabian Grünbichler
Am 27.11.24 um 14:05 schrieb Fabian Grünbichler:
> 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(-)
>
>
applied, thanks!
FWIW, switching the "store" loop variable to something like "existing_store"
and "datastore" to "new_store" would help on reading here.
_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-11-27 13:24 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-27 13:05 [pbs-devel] [PATCH proxmox-backup] api: create_datastore: fix nesting checks Fabian Grünbichler
2024-11-27 13:23 ` [pbs-devel] applied: " Thomas Lamprecht
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal