public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH pve-esxi-import-tools/storage v2] improve error handling/logging
@ 2024-05-10 13:56 Dominik Csapak
  2024-05-10 13:56 ` [pve-devel] [PATCH pve-esxi-import-tools v2 1/1] improve error handling before mounting Dominik Csapak
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Dominik Csapak @ 2024-05-10 13:56 UTC (permalink / raw)
  To: pve-devel

two smaller patches that improve which error gets shown to the user and
logged to syslog in case of an early error when trying to fuse mount

changes from v1:
* improved commit message
* remove superfluous space in error
* split 'open_file' into its own line
* reworded context messages
* removed (de)reference operator
* removed unnecessary comment
* removed unnecessary context adds (inside the functions is enough context)

pve-esxi-import-tools:

Dominik Csapak (1):
  improve error handling before mounting

 src/esxi.rs |  7 ++++++-
 src/main.rs | 15 +++++++++++----
 2 files changed, 17 insertions(+), 5 deletions(-)

pve-storage:

Dominik Csapak (1):
  esxi: improve error handling for fuse mount tool

 src/PVE/Storage/ESXiPlugin.pm | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

-- 
2.39.2



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [pve-devel] [PATCH pve-esxi-import-tools v2 1/1] improve error handling before mounting
  2024-05-10 13:56 [pve-devel] [PATCH pve-esxi-import-tools/storage v2] improve error handling/logging Dominik Csapak
@ 2024-05-10 13:56 ` Dominik Csapak
  2024-05-10 13:56 ` [pve-devel] [PATCH storage v2 1/1] esxi: improve error handling for fuse mount tool Dominik Csapak
  2024-06-07 11:27 ` [pve-devel] applied: [PATCH pve-esxi-import-tools/storage v2] improve error handling/logging Wolfgang Bumiller
  2 siblings, 0 replies; 4+ messages in thread
From: Dominik Csapak @ 2024-05-10 13:56 UTC (permalink / raw)
  To: pve-devel

when we fail early in the mount process, we did not log any error to the
syslog, but only the top most one to stderr.

sadly we were not able to see them anywhere, so improve the log by
* log the complete error chain with log::error (so we also can see the
  causes)
* add more context hints

This can help debug issues where we failed early and could not see any
error output otherwise, e.g. this thread in the forum:

https://forum.proxmox.com/threads/146248/

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 src/esxi.rs |  7 ++++++-
 src/main.rs | 15 +++++++++++----
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/src/esxi.rs b/src/esxi.rs
index 6be9466..88930b0 100644
--- a/src/esxi.rs
+++ b/src/esxi.rs
@@ -278,7 +278,12 @@ impl EsxiClient {
     ) -> Result<EsxiFile, Error> {
         log::debug!("open file [{datacenter}, {datastore}] {path:?}");
         let query = self.file_url(datacenter, datastore, path);
-        let size = self.get_file_size(datacenter, datastore, path).await?;
+        let size = self
+            .get_file_size(datacenter, datastore, path)
+            .await
+            .with_context(|| {
+                format!("error when getting file size: {datacenter:?}/{datastore:?}/{path:?}")
+            })?;
         Ok(EsxiFile {
             client: Arc::clone(self),
             query: query.into(),
diff --git a/src/main.rs b/src/main.rs
index 281ec3d..216173d 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,4 +1,5 @@
 use std::ffi::{CString, OsStr, OsString};
+use std::fmt::Write;
 use std::io;
 use std::os::fd::RawFd;
 use std::os::unix::ffi::OsStrExt;
@@ -221,7 +222,12 @@ fn main() {
     });
 
     if let Err(err) = runtime.block_on(main_do()) {
-        eprintln!("Error: {}", err);
+        let mut err_chain = String::new();
+        for err in err.chain() {
+            let _ = writeln!(err_chain, " {err}");
+        }
+        eprintln!("Error: {err}");
+        log::error!("Error:{err_chain}");
         std::process::exit(-1);
     }
 }
@@ -302,9 +308,10 @@ async fn main_do() -> Result<(), Error> {
             let fs_datastore = fs_datacenter.create_datastore(datastore);
 
             log::debug!("loading {datacenter:?}/{datastore:?}/{path:?}");
-            let config =
-                vmx::VmConfig::parse(client.open_file(datacenter, datastore, path).await?, path)
-                    .await?;
+            let config = client.open_file(datacenter, datastore, path).await?;
+            let config = vmx::VmConfig::parse(config, path).await.with_context(|| {
+                format!("error when parsing VM config: {datacenter:?}/{datastore:?}/{path:?}")
+            })?;
             log::debug!("{config:#?}");
             for disk in config.disks.values() {
                 let other_fs_datastore;
-- 
2.39.2



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [pve-devel] [PATCH storage v2 1/1] esxi: improve error handling for fuse mount tool
  2024-05-10 13:56 [pve-devel] [PATCH pve-esxi-import-tools/storage v2] improve error handling/logging Dominik Csapak
  2024-05-10 13:56 ` [pve-devel] [PATCH pve-esxi-import-tools v2 1/1] improve error handling before mounting Dominik Csapak
@ 2024-05-10 13:56 ` Dominik Csapak
  2024-06-07 11:27 ` [pve-devel] applied: [PATCH pve-esxi-import-tools/storage v2] improve error handling/logging Wolfgang Bumiller
  2 siblings, 0 replies; 4+ messages in thread
From: Dominik Csapak @ 2024-05-10 13:56 UTC (permalink / raw)
  To: pve-devel

if the fuse tool encounters an error early, it prints it like:
   Error: some error message
on stderr.

Redirect STDERR of the child process (which mounts the ESXi instance) to
the pipe of the parent (API) process, so that it can pass a hopefully
more meaningful message to the user than just an erroneous return code.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 src/PVE/Storage/ESXiPlugin.pm | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/PVE/Storage/ESXiPlugin.pm b/src/PVE/Storage/ESXiPlugin.pm
index b8bce0e..4bcd7ff 100644
--- a/src/PVE/Storage/ESXiPlugin.pm
+++ b/src/PVE/Storage/ESXiPlugin.pm
@@ -222,6 +222,9 @@ sub esxi_mount : prototype($$$;$) {
 		// die "failed to get file descriptor flags: $!\n";
 	    fcntl($wr, F_SETFD, $flags & ~FD_CLOEXEC)
 		// die "failed to remove CLOEXEC flag from fd: $!\n";
+
+	    open(STDERR, ">&", $wr) or die "unable to redirect STDERR: $!\n";
+
 	    # FIXME: use the user/group options!
 	    exec {$ESXI_FUSE_TOOL}
 		$ESXI_FUSE_TOOL,
@@ -245,7 +248,7 @@ sub esxi_mount : prototype($$$;$) {
     undef $wr;
 
     my $result = do { local $/ = undef; <$rd> };
-    if ($result =~ /^ERROR: (.*)$/) {
+    if ($result =~ /^ERROR: (.*)$/i) {
 	die "$1\n";
     }
 
-- 
2.39.2



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [pve-devel] applied: [PATCH pve-esxi-import-tools/storage v2] improve error handling/logging
  2024-05-10 13:56 [pve-devel] [PATCH pve-esxi-import-tools/storage v2] improve error handling/logging Dominik Csapak
  2024-05-10 13:56 ` [pve-devel] [PATCH pve-esxi-import-tools v2 1/1] improve error handling before mounting Dominik Csapak
  2024-05-10 13:56 ` [pve-devel] [PATCH storage v2 1/1] esxi: improve error handling for fuse mount tool Dominik Csapak
@ 2024-06-07 11:27 ` Wolfgang Bumiller
  2 siblings, 0 replies; 4+ messages in thread
From: Wolfgang Bumiller @ 2024-06-07 11:27 UTC (permalink / raw)
  To: Dominik Csapak; +Cc: pve-devel

applied both patches, thanks


_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-06-07 11:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-10 13:56 [pve-devel] [PATCH pve-esxi-import-tools/storage v2] improve error handling/logging Dominik Csapak
2024-05-10 13:56 ` [pve-devel] [PATCH pve-esxi-import-tools v2 1/1] improve error handling before mounting Dominik Csapak
2024-05-10 13:56 ` [pve-devel] [PATCH storage v2 1/1] esxi: improve error handling for fuse mount tool Dominik Csapak
2024-06-07 11:27 ` [pve-devel] applied: [PATCH pve-esxi-import-tools/storage v2] improve error handling/logging Wolfgang Bumiller

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