[pbs-devel] [PATCH proxmox-backup] disk: zfs: improve error logging for zfs commands

Dominik Csapak d.csapak at proxmox.com
Tue Nov 29 09:16:11 CET 2022


zfs errors might include a newline in the output (e.g. when trying to
create a mirror on two differently sized disks), which trips up our
task log status parser since that expectes a 'TASK {status}' on the
beginning of the first line.

print the error from zfs into the log and bail out with a short notice
to check the task log

this fixes the 'unknown error' issue in the ui when an error happnes
during the zfs commands

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 src/api2/node/disks/zfs.rs | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/src/api2/node/disks/zfs.rs b/src/api2/node/disks/zfs.rs
index 3efc8a05..2dcd6cfd 100644
--- a/src/api2/node/disks/zfs.rs
+++ b/src/api2/node/disks/zfs.rs
@@ -3,7 +3,7 @@ use serde_json::{json, Value};
 
 use proxmox_router::{Permission, Router, RpcEnvironment, RpcEnvironmentType};
 use proxmox_schema::api;
-use proxmox_sys::task_log;
+use proxmox_sys::{task_error, task_log};
 
 use pbs_api_types::{
     DataStoreConfig, ZfsCompressionType, ZfsRaidLevel, ZpoolListItem, DATASTORE_SCHEMA,
@@ -277,8 +277,13 @@ pub fn create_zpool(
 
             task_log!(worker, "# {:?}", command);
 
-            let output = proxmox_sys::command::run_command(command, None)?;
-            task_log!(worker, "{}", output);
+            match proxmox_sys::command::run_command(command, None) {
+                Ok(output) => task_log!(worker, "{output}"),
+                Err(err) => {
+                    task_error!(worker, "{err}");
+                    bail!("Error during 'zpool create', see task log for more details");
+                }
+            };
 
             if std::path::Path::new("/lib/systemd/system/zfs-import at .service").exists() {
                 let import_unit = format!(
@@ -295,8 +300,13 @@ pub fn create_zpool(
             }
             command.args(&["relatime=on", &name]);
             task_log!(worker, "# {:?}", command);
-            let output = proxmox_sys::command::run_command(command, None)?;
-            task_log!(worker, "{}", output);
+            match proxmox_sys::command::run_command(command, None) {
+                Ok(output) => task_log!(worker, "{output}"),
+                Err(err) => {
+                    task_error!(worker, "{err}");
+                    bail!("Error during 'zfs set', see task log for more details");
+                }
+            };
 
             if add_datastore {
                 let lock = pbs_config::datastore::lock_config()?;
-- 
2.30.2






More information about the pbs-devel mailing list