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] tape: changer: sg_pt: make extra scsi request for dvcid
Date: Thu, 15 Jul 2021 13:07:20 +0200	[thread overview]
Message-ID: <20210715110720.3036773-1-d.csapak@proxmox.com> (raw)

some libraries cannot handle a request with volume tags and DVCID set at
the same time.

So we make 2 separate requests and merge them, since we want to keep
the vendor/model/serial data.

to not overcomplicate the code, add another special type to ElementType

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

diff --git a/src/tape/changer/sg_pt_changer.rs b/src/tape/changer/sg_pt_changer.rs
index 66da140d..f4154ced 100644
--- a/src/tape/changer/sg_pt_changer.rs
+++ b/src/tape/changer/sg_pt_changer.rs
@@ -265,13 +265,34 @@ pub fn transfer_medium<F: AsRawFd>(
     Ok(())
 }
 
-#[repr(u8)]
 #[derive(Clone, Copy)]
 enum ElementType {
-    MediumTransport = 1,
-    Storage = 2,
-    ImportExport = 3,
-    DataTransfer = 4,
+    MediumTransport,
+    Storage,
+    ImportExport,
+    DataTransfer,
+    DataTransferWithDVCID,
+}
+
+impl ElementType {
+    fn byte1(&self) -> u8 {
+        let volume_tag_bit = 1u8 << 4;
+        match *self {
+            ElementType::MediumTransport => volume_tag_bit | 1,
+            ElementType::Storage => volume_tag_bit | 2,
+            ElementType::ImportExport => volume_tag_bit | 3,
+            ElementType::DataTransfer => volume_tag_bit | 4,
+            // some changers cannot get voltag + dvcid at the same time
+            ElementType::DataTransferWithDVCID => 4,
+        }
+    }
+
+    fn byte6(&self) -> u8 {
+        match *self {
+            ElementType::DataTransferWithDVCID => 0b001, //  Mixed=0,CurData=0,DVCID=1
+            _ => 0b000, // Mixed=0,CurData=0,DVCID=0
+        }
+    }
 }
 
 fn scsi_read_element_status_cdb(
@@ -283,15 +304,11 @@ fn scsi_read_element_status_cdb(
 
     let mut cmd = Vec::new();
     cmd.push(0xB8); // READ ELEMENT STATUS (B8h)
-    cmd.push(1u8<<4 | (element_type as u8)); // volume tags and given type
+    cmd.push(element_type.byte1());
     cmd.extend(&start_element_address.to_be_bytes());
 
     cmd.extend(&number_of_elements.to_be_bytes());
-    let byte6 = match element_type {
-        ElementType::DataTransfer => 0b001, //  Mixed=0,CurData=0,DVCID=1
-        _ => 0b000, // Mixed=0,CurData=0,DVCID=0
-    };
-    cmd.push(byte6);
+    cmd.push(element_type.byte6());
     cmd.extend(&allocation_len.to_be_bytes()[1..4]);
     cmd.push(0);
     cmd.push(0);
@@ -385,6 +402,21 @@ pub fn read_element_status<F: AsRawFd>(file: &mut F) -> Result<MtxStatus, Error>
     let page = get_element(&inquiry, &mut sg_raw, ElementType::DataTransfer, allocation_len, false)?;
     drives.extend(page.drives);
 
+    // get the serial + vendor + model,
+    // some changer require this to be an extra scsi command
+    let page = get_element(&inquiry, &mut sg_raw, ElementType::DataTransferWithDVCID, allocation_len, false)?;
+    // should be in same order and same count, but be on the safe side.
+    // there should not be too many drives normally
+    for drive in drives.iter_mut() {
+        for drive2 in &page.drives {
+            if drive2.element_address == drive.element_address {
+                drive.vendor = drive2.vendor.clone();
+                drive.model = drive2.model.clone();
+                drive.drive_serial_number = drive2.drive_serial_number.clone();
+            }
+        }
+    }
+
     let page = get_element(&inquiry, &mut sg_raw, ElementType::MediumTransport, allocation_len, false)?;
     transports.extend(page.transports);
 
-- 
2.30.2





             reply	other threads:[~2021-07-15 11:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-15 11:07 Dominik Csapak [this message]
2021-07-16  6:46 ` [pbs-devel] applied: " 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=20210715110720.3036773-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