public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup] disk: zfs: improve error logging for zfs commands
Date: Tue, 29 Nov 2022 09:16:11 +0100	[thread overview]
Message-ID: <20221129081611.591774-1-d.csapak@proxmox.com> (raw)

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@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@.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





             reply	other threads:[~2022-11-29  8:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-29  8:16 Dominik Csapak [this message]
2023-01-05  9:37 ` [pbs-devel] applied: " Wolfgang Bumiller

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=20221129081611.591774-1-d.csapak@proxmox.com \
    --to=d.csapak@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
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal