all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [pbs-devel] [PATCH proxmox-backup] tape: changer: handle missing dvcid information
@ 2021-07-22  9:57 Dominik Csapak
  2021-07-22 10:02 ` [pbs-devel] applied: " Dietmar Maurer
  0 siblings, 1 reply; 2+ messages in thread
From: Dominik Csapak @ 2021-07-22  9:57 UTC (permalink / raw)
  To: pbs-devel

the dvcid information is not always available, so skip it if is missing

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

diff --git a/src/tape/changer/sg_pt_changer.rs b/src/tape/changer/sg_pt_changer.rs
index daa1ad82..c94eaf2e 100644
--- a/src/tape/changer/sg_pt_changer.rs
+++ b/src/tape/changer/sg_pt_changer.rs
@@ -630,6 +630,43 @@ fn create_element_status(full: bool, volume_tag: Option<String>) -> ElementStatu
     }
 }
 
+struct DvcidInfo {
+    vendor: Option<String>,
+    model: Option<String>,
+    serial: Option<String>,
+}
+
+fn decode_dvcid_info<R: Read>(reader: &mut R) -> Result<DvcidInfo, Error> {
+    let dvcid: DvcidHead = unsafe { reader.read_be_value()? };
+
+    let (serial, vendor, model) = match (dvcid.code_set, dvcid.identifier_type) {
+        (2, 0) => { // Serial number only (Quantum Superloader3 uses this)
+            let serial = reader.read_exact_allocated(dvcid.identifier_len as usize)?;
+            let serial = scsi_ascii_to_string(&serial);
+            (Some(serial), None, None)
+        }
+        (2, 1) => {
+            if dvcid.identifier_len != 34 {
+                bail!("got wrong DVCID length");
+            }
+            let vendor = reader.read_exact_allocated(8)?;
+            let vendor = scsi_ascii_to_string(&vendor);
+            let model = reader.read_exact_allocated(16)?;
+            let model = scsi_ascii_to_string(&model);
+            let serial = reader.read_exact_allocated(10)?;
+            let serial = scsi_ascii_to_string(&serial);
+            (Some(serial), Some(vendor), Some(model))
+        }
+        _ => (None, None, None),
+    };
+
+    Ok(DvcidInfo {
+        vendor,
+        model,
+        serial,
+    })
+}
+
 fn decode_element_status_page(
     _info: &InquiryInfo,
     data: &[u8],
@@ -733,37 +770,20 @@ fn decode_element_status_page(
 
                         subhead.skip_alternate_volume_tag(&mut reader)?;
 
-                        let dvcid: DvcidHead = unsafe { reader.read_be_value()? };
-
-                        let (drive_serial_number, vendor, model) = match (dvcid.code_set, dvcid.identifier_type) {
-                            (2, 0) => { // Serial number only (Quantum Superloader3 uses this)
-                                let serial = reader.read_exact_allocated(dvcid.identifier_len as usize)?;
-                                let serial = scsi_ascii_to_string(&serial);
-                                (Some(serial), None, None)
-                            }
-                            (2, 1) => {
-                                if dvcid.identifier_len != 34 {
-                                    bail!("got wrong DVCID length");
-                                }
-                                let vendor = reader.read_exact_allocated(8)?;
-                                let vendor = scsi_ascii_to_string(&vendor);
-                                let model = reader.read_exact_allocated(16)?;
-                                let model = scsi_ascii_to_string(&model);
-                                let serial = reader.read_exact_allocated(10)?;
-                                let serial = scsi_ascii_to_string(&serial);
-                                (Some(serial), Some(vendor), Some(model))
-                            }
-                            _ => (None, None, None),
-                        };
+                        let dvcid = decode_dvcid_info(&mut reader).unwrap_or(DvcidInfo {
+                            vendor: None,
+                            model: None,
+                            serial: None,
+                        });
 
                         result.last_element_address = Some(desc.element_address);
 
                         let drive = DriveStatus {
                             loaded_slot,
                             status: create_element_status(full, volume_tag),
-                            drive_serial_number,
-                            vendor,
-                            model,
+                            drive_serial_number: dvcid.serial,
+                            vendor: dvcid.vendor,
+                            model: dvcid.model,
                             element_address: desc.element_address,
                         };
                         result.drives.push(drive);
-- 
2.30.2





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

* [pbs-devel] applied: [PATCH proxmox-backup] tape: changer: handle missing dvcid information
  2021-07-22  9:57 [pbs-devel] [PATCH proxmox-backup] tape: changer: handle missing dvcid information Dominik Csapak
@ 2021-07-22 10:02 ` Dietmar Maurer
  0 siblings, 0 replies; 2+ messages in thread
From: Dietmar Maurer @ 2021-07-22 10:02 UTC (permalink / raw)
  To: Proxmox Backup Server development discussion, Dominik Csapak

applied

On 7/22/21 11:57 AM, Dominik Csapak wrote:
> the dvcid information is not always available, so skip it if is missing
>
> Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
> ---
>   src/tape/changer/sg_pt_changer.rs | 70 ++++++++++++++++++++-----------
>   1 file changed, 45 insertions(+), 25 deletions(-)
>
> diff --git a/src/tape/changer/sg_pt_changer.rs b/src/tape/changer/sg_pt_changer.rs
> index daa1ad82..c94eaf2e 100644
> --- a/src/tape/changer/sg_pt_changer.rs
> +++ b/src/tape/changer/sg_pt_changer.rs
> @@ -630,6 +630,43 @@ fn create_element_status(full: bool, volume_tag: Option<String>) -> ElementStatu
>       }
>   }
>   
> +struct DvcidInfo {
> +    vendor: Option<String>,
> +    model: Option<String>,
> +    serial: Option<String>,
> +}
> +
> +fn decode_dvcid_info<R: Read>(reader: &mut R) -> Result<DvcidInfo, Error> {
> +    let dvcid: DvcidHead = unsafe { reader.read_be_value()? };
> +
> +    let (serial, vendor, model) = match (dvcid.code_set, dvcid.identifier_type) {
> +        (2, 0) => { // Serial number only (Quantum Superloader3 uses this)
> +            let serial = reader.read_exact_allocated(dvcid.identifier_len as usize)?;
> +            let serial = scsi_ascii_to_string(&serial);
> +            (Some(serial), None, None)
> +        }
> +        (2, 1) => {
> +            if dvcid.identifier_len != 34 {
> +                bail!("got wrong DVCID length");
> +            }
> +            let vendor = reader.read_exact_allocated(8)?;
> +            let vendor = scsi_ascii_to_string(&vendor);
> +            let model = reader.read_exact_allocated(16)?;
> +            let model = scsi_ascii_to_string(&model);
> +            let serial = reader.read_exact_allocated(10)?;
> +            let serial = scsi_ascii_to_string(&serial);
> +            (Some(serial), Some(vendor), Some(model))
> +        }
> +        _ => (None, None, None),
> +    };
> +
> +    Ok(DvcidInfo {
> +        vendor,
> +        model,
> +        serial,
> +    })
> +}
> +
>   fn decode_element_status_page(
>       _info: &InquiryInfo,
>       data: &[u8],
> @@ -733,37 +770,20 @@ fn decode_element_status_page(
>   
>                           subhead.skip_alternate_volume_tag(&mut reader)?;
>   
> -                        let dvcid: DvcidHead = unsafe { reader.read_be_value()? };
> -
> -                        let (drive_serial_number, vendor, model) = match (dvcid.code_set, dvcid.identifier_type) {
> -                            (2, 0) => { // Serial number only (Quantum Superloader3 uses this)
> -                                let serial = reader.read_exact_allocated(dvcid.identifier_len as usize)?;
> -                                let serial = scsi_ascii_to_string(&serial);
> -                                (Some(serial), None, None)
> -                            }
> -                            (2, 1) => {
> -                                if dvcid.identifier_len != 34 {
> -                                    bail!("got wrong DVCID length");
> -                                }
> -                                let vendor = reader.read_exact_allocated(8)?;
> -                                let vendor = scsi_ascii_to_string(&vendor);
> -                                let model = reader.read_exact_allocated(16)?;
> -                                let model = scsi_ascii_to_string(&model);
> -                                let serial = reader.read_exact_allocated(10)?;
> -                                let serial = scsi_ascii_to_string(&serial);
> -                                (Some(serial), Some(vendor), Some(model))
> -                            }
> -                            _ => (None, None, None),
> -                        };
> +                        let dvcid = decode_dvcid_info(&mut reader).unwrap_or(DvcidInfo {
> +                            vendor: None,
> +                            model: None,
> +                            serial: None,
> +                        });
>   
>                           result.last_element_address = Some(desc.element_address);
>   
>                           let drive = DriveStatus {
>                               loaded_slot,
>                               status: create_element_status(full, volume_tag),
> -                            drive_serial_number,
> -                            vendor,
> -                            model,
> +                            drive_serial_number: dvcid.serial,
> +                            vendor: dvcid.vendor,
> +                            model: dvcid.model,
>                               element_address: desc.element_address,
>                           };
>                           result.drives.push(drive);




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

end of thread, other threads:[~2021-07-22 10:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-22  9:57 [pbs-devel] [PATCH proxmox-backup] tape: changer: handle missing dvcid information Dominik Csapak
2021-07-22 10:02 ` [pbs-devel] applied: " Dietmar Maurer

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