[pbs-devel] [PATCH backup] zfs: check if given pool name is reserved

Oguz Bektas o.bektas at proxmox.com
Tue Nov 23 13:21:02 CET 2021


man zpool-create:
The pool names mirror, raidz, draid, spare and log are reserved, as
are names _beginning_ with mirror, raidz, draid, and spare. The vdev
specification is described in the Virtual Devices section of
zpoolconcepts(7).

Signed-off-by: Oguz Bektas <o.bektas at proxmox.com>
---
 src/api2/node/disks/zfs.rs | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/src/api2/node/disks/zfs.rs b/src/api2/node/disks/zfs.rs
index c9a6ac72..58e5a83e 100644
--- a/src/api2/node/disks/zfs.rs
+++ b/src/api2/node/disks/zfs.rs
@@ -201,6 +201,15 @@ pub fn create_zpool(
     };
 
     // Sanity checks
+
+    lazy_static::lazy_static! {
+        // pool names starting with these are reserved
+        static ref RESERVED_POOL_NAMES: regex::Regex = regex::Regex::new(r"^(mirror|raidz|draid|spare).*$").unwrap();
+    }
+    if RESERVED_POOL_NAMES.is_match(&name) || &name == "log" {
+        bail!("Pool name {:?} is reserved.", &name);
+    }
+
     if raidlevel == ZfsRaidLevel::Raid10 && devices.len() % 2 != 0 {
         bail!("Raid10 needs an even number of disks.");
     }
-- 
2.30.2





More information about the pbs-devel mailing list