From 905147a5ee0274170953235aa1ab8522d0a6dcd8 Mon Sep 17 00:00:00 2001 From: Stoiko Ivanov Date: Wed, 16 Sep 2020 14:14:18 +0200 Subject: [PATCH] api2/node/disks/zfs: instantiate import service MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When creating a new zpool for a datastore, also instantiate an import-unit for it. This helps in cases where '/etc/zfs/zool.cache' get corrupted and thus the pool is not imported upon boot. This patch needs the corresponding addition of 'zfs-import@.service' in the zfsonlinux repository. Suggested-by: Fabian Grünbichler Signed-off-by: Stoiko Ivanov --- src/api2/node/disks/zfs.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/api2/node/disks/zfs.rs b/src/api2/node/disks/zfs.rs index c5d6f6a6..0f0e4220 100644 --- a/src/api2/node/disks/zfs.rs +++ b/src/api2/node/disks/zfs.rs @@ -25,6 +25,8 @@ use crate::server::WorkerTask; use crate::api2::types::*; +use crate::tools::systemd; + pub const DISK_ARRAY_SCHEMA: Schema = ArraySchema::new( "Disk name list.", &BLOCKDEVICE_NAME_SCHEMA) .schema(); @@ -355,6 +357,9 @@ pub fn create_zpool( let output = crate::tools::run_command(command, None)?; worker.log(output); + let import_unit = format!("zfs-import@{}.service", systemd::escape_unit(&name, false)); + systemd::enable_unit(&import_unit)?; + if let Some(compression) = compression { let mut command = std::process::Command::new("zfs"); command.args(&["set", &format!("compression={}", compression), &name]);