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 2/2] tape: changer: sg_pt: correctly loop over MODE SENSE (B8h)
Date: Mon, 12 Jul 2021 12:22:09 +0200	[thread overview]
Message-ID: <20210712102209.3061802-2-d.csapak@proxmox.com> (raw)
In-Reply-To: <20210712102209.3061802-1-d.csapak@proxmox.com>

and limit to 1000 elements per request.
(Because some changers limit that request with the options we set)

instead of checking if the data len was equal to the allocation_len
for getting more data, we count the returned elements and compare
that with the number we requested

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 src/tape/changer/sg_pt_changer.rs | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/src/tape/changer/sg_pt_changer.rs b/src/tape/changer/sg_pt_changer.rs
index 29b04ad6..da114074 100644
--- a/src/tape/changer/sg_pt_changer.rs
+++ b/src/tape/changer/sg_pt_changer.rs
@@ -279,6 +279,7 @@ pub fn transfer_medium<F: AsRawFd>(
 
 fn scsi_read_element_status_cdb(
     start_element_address: u16,
+    number_of_elements: u16,
     allocation_len: u32,
 ) -> Vec<u8> {
 
@@ -287,7 +288,6 @@ fn scsi_read_element_status_cdb(
     cmd.push(1u8<<4); // report all types and volume tags
     cmd.extend(&start_element_address.to_be_bytes());
 
-    let number_of_elements: u16 = 0xffff;
     cmd.extend(&number_of_elements.to_be_bytes());
     cmd.push(0b001); //  Mixed=0,CurData=0,DVCID=1
     cmd.extend(&allocation_len.to_be_bytes()[1..4]);
@@ -315,6 +315,7 @@ pub fn read_element_status<F: AsRawFd>(file: &mut F) -> Result<MtxStatus, Error>
     sg_raw.set_timeout(SCSI_CHANGER_DEFAULT_TIMEOUT);
 
     let mut start_element_address = 0;
+    let number_of_elements: u16 = 1000; // some changers limit the query
 
     let mut drives = Vec::new();
     let mut storage_slots = Vec::new();
@@ -324,12 +325,17 @@ pub fn read_element_status<F: AsRawFd>(file: &mut F) -> Result<MtxStatus, Error>
     let mut retry = true;
 
     loop {
-        let cmd = scsi_read_element_status_cdb(start_element_address, allocation_len);
+        let cmd = scsi_read_element_status_cdb(start_element_address, number_of_elements, allocation_len);
 
         let data = execute_scsi_command(&mut sg_raw, &cmd, "read element status (B8h)", retry)?;
 
         let page = decode_element_status_page(&inquiry, &data, start_element_address)?;
 
+        let returned_number_of_elements = page.transports.len()
+            + page.drives.len()
+            + page.storage_slots.len()
+            + page.import_export_slots.len();
+
         retry = false; // only retry the first command
 
         transports.extend(page.transports);
@@ -337,19 +343,16 @@ pub fn read_element_status<F: AsRawFd>(file: &mut F) -> Result<MtxStatus, Error>
         storage_slots.extend(page.storage_slots);
         import_export_slots.extend(page.import_export_slots);
 
-        if data.len() < (allocation_len as usize) {
-            break;
-        }
-
         if let Some(last_element_address) = page.last_element_address {
-            if last_element_address >= start_element_address {
-                start_element_address = last_element_address + 1;
-            } else {
+            if last_element_address < start_element_address {
                 bail!("got strange element address");
             }
-        } else {
-            break;
+            if returned_number_of_elements >= (number_of_elements as usize) {
+                start_element_address = last_element_address + 1;
+                continue; // we possibly have to read additional elements
+            }
         }
+        break;
     }
 
     if (setup.transport_element_count as usize) != transports.len() {
-- 
2.30.2





      reply	other threads:[~2021-07-12 10:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-12 10:22 [pbs-devel] [PATCH proxmox-backup 1/2] tape: changer: sg_pt: do not retry on unknown errors Dominik Csapak
2021-07-12 10:22 ` Dominik Csapak [this message]

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=20210712102209.3061802-2-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