[pbs-devel] [PATCH proxmox-backup] pbs-tape: sgutils2: check sense data when status is 'CHECK_CONDITION'

Dominik Csapak d.csapak at proxmox.com
Wed Apr 20 15:39:56 CEST 2022


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 at 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






More information about the pbs-devel mailing list