all lists on 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] pbs-tape: sgutils2: check sense data when status is 'CHECK_CONDITION'
Date: Wed, 20 Apr 2022 15:39:56 +0200	[thread overview]
Message-ID: <20220420133956.1571816-1-d.csapak@proxmox.com> (raw)

some raid controllers return a 'transport error' when we expected a
'sense error'. it seems the correct way to check the sense data is when
either the result category is 'SENSE' or when the status i 'CHECK_CONDITION',
so do that. (similar to how 'sg_raw' returns the errors)

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 pbs-tape/src/sgutils2.rs | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/pbs-tape/src/sgutils2.rs b/pbs-tape/src/sgutils2.rs
index 1fc487be..888f74ec 100644
--- a/pbs-tape/src/sgutils2.rs
+++ b/pbs-tape/src/sgutils2.rs
@@ -141,6 +141,9 @@ pub const SENSE_KEY_ABORTED_COMMAND: u8 = 0x0b;
 pub const SENSE_KEY_VOLUME_OVERFLOW: u8 = 0x0d;
 pub const SENSE_KEY_MISCOMPARE: u8 = 0x0e;
 
+// SAM STAT
+const SAM_STAT_CHECK_CONDITION: i32 = 0x02;
+
 /// Sense Key Descriptions
 pub const SENSE_KEY_DESCRIPTIONS: [&str; 16] = [
     "No Sense",
@@ -458,10 +461,10 @@ impl<'a, F: AsRawFd> SgRaw<'a, F> {
         let sense_len = unsafe { get_scsi_pt_sense_len(ptvp.as_ptr()) };
 
         let res_cat = unsafe { get_scsi_pt_result_category(ptvp.as_ptr()) };
-        match res_cat {
-            SCSI_PT_RESULT_GOOD => Ok(()),
-            SCSI_PT_RESULT_STATUS => {
-                let status = unsafe { get_scsi_pt_status_response(ptvp.as_ptr()) };
+        let status = unsafe { get_scsi_pt_status_response(ptvp.as_ptr()) };
+        match (res_cat, status) {
+            (SCSI_PT_RESULT_GOOD, _) => Ok(()),
+            (SCSI_PT_RESULT_STATUS, status) => {
                 if status != 0 {
                     return Err(
                         format_err!("unknown scsi error - status response {}", status).into(),
@@ -469,7 +472,7 @@ impl<'a, F: AsRawFd> SgRaw<'a, F> {
                 }
                 Ok(())
             }
-            SCSI_PT_RESULT_SENSE => {
+            (SCSI_PT_RESULT_SENSE, _) | (_, SAM_STAT_CHECK_CONDITION) => {
                 if sense_len == 0 {
                     return Err(format_err!("scsi command failed, but got no sense data").into());
                 }
@@ -511,15 +514,15 @@ impl<'a, F: AsRawFd> SgRaw<'a, F> {
 
                 Err(ScsiError::Sense(sense))
             }
-            SCSI_PT_RESULT_TRANSPORT_ERR => {
-                return Err(format_err!("scsi command failed: transport error").into())
+            (SCSI_PT_RESULT_TRANSPORT_ERR, _) => {
+                return Err(format_err!("scsi command failed: transport error").into());
             }
-            SCSI_PT_RESULT_OS_ERR => {
+            (SCSI_PT_RESULT_OS_ERR, _) => {
                 let errno = unsafe { get_scsi_pt_os_err(ptvp.as_ptr()) };
                 let err = nix::Error::from_errno(nix::errno::Errno::from_i32(errno));
                 return Err(format_err!("scsi command failed with err {}", err).into());
             }
-            unknown => {
+            (unknown, _) => {
                 return Err(
                     format_err!("scsi command failed: unknown result category {}", unknown).into(),
                 )
-- 
2.30.2





             reply	other threads:[~2022-04-20 13:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-20 13:39 Dominik Csapak [this message]
2022-04-21  7:38 ` Dietmar Maurer

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=20220420133956.1571816-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal