public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pbs-devel] [PATCH proxmox-backup 1/4] api: types: CHANGER_DRIVENUM_SCHEMA: increase maximum drives per changer
@ 2021-07-21 14:04 Dominik Csapak
  2021-07-21 14:04 ` [pbs-devel] [PATCH proxmox-backup 2/4] tape: changer: sg_pt: add SCSI_VOLUME_TAG_LEN const Dominik Csapak
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Dominik Csapak @ 2021-07-21 14:04 UTC (permalink / raw)
  To: pbs-devel

to 255. 8 drives per changer was a rather arbitrary limitation and could
well be reached in practice with big libraries.

Altough 255 is still a arbirtrary limitation, this is much less likely
to be reached in practice.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 src/api2/types/tape/drive.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/api2/types/tape/drive.rs b/src/api2/types/tape/drive.rs
index ecc65088..f50b1d5f 100644
--- a/src/api2/types/tape/drive.rs
+++ b/src/api2/types/tape/drive.rs
@@ -28,7 +28,7 @@ pub const LTO_DRIVE_PATH_SCHEMA: Schema = StringSchema::new(
 pub const CHANGER_DRIVENUM_SCHEMA: Schema = IntegerSchema::new(
     "Associated changer drive number (requires option changer)")
     .minimum(0)
-    .maximum(8)
+    .maximum(255)
     .default(0)
     .schema();
 
-- 
2.30.2





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

* [pbs-devel] [PATCH proxmox-backup 2/4] tape: changer: sg_pt: add SCSI_VOLUME_TAG_LEN const
  2021-07-21 14:04 [pbs-devel] [PATCH proxmox-backup 1/4] api: types: CHANGER_DRIVENUM_SCHEMA: increase maximum drives per changer Dominik Csapak
@ 2021-07-21 14:04 ` Dominik Csapak
  2021-07-21 15:02   ` [pbs-devel] applied: " Dietmar Maurer
  2021-07-21 14:04 ` [pbs-devel] [PATCH proxmox-backup 3/4] tape: changer: sg_pt: fix typo Dominik Csapak
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Dominik Csapak @ 2021-07-21 14:04 UTC (permalink / raw)
  To: pbs-devel

so that we do have less 'magic' constants without description

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

diff --git a/src/tape/changer/sg_pt_changer.rs b/src/tape/changer/sg_pt_changer.rs
index f4154ced..908311b0 100644
--- a/src/tape/changer/sg_pt_changer.rs
+++ b/src/tape/changer/sg_pt_changer.rs
@@ -33,6 +33,7 @@ use crate::{
 };
 
 const SCSI_CHANGER_DEFAULT_TIMEOUT: usize = 60*5; // 5 minutes
+const SCSI_VOLUME_TAG_LEN: usize = 36;
 
 /// Initialize element status (Inventory)
 pub fn initialize_element_status<F: AsRawFd>(file: &mut F) -> Result<(), Error> {
@@ -509,7 +510,7 @@ impl SubHeader {
     ) -> Result<Option<String>, Error> {
 
         if (self.flags & 128) != 0 { // has PVolTag
-            let tmp = reader.read_exact_allocated(36)?;
+            let tmp = reader.read_exact_allocated(SCSI_VOLUME_TAG_LEN)?;
             if full {
                 let volume_tag = scsi_ascii_to_string(&tmp);
                 return Ok(Some(volume_tag));
@@ -526,7 +527,7 @@ impl SubHeader {
     ) -> Result<Option<String>, Error> {
 
         if (self.flags & 64) != 0 { // has AVolTag
-            let _tmp = reader.read_exact_allocated(36)?;
+            let _tmp = reader.read_exact_allocated(SCSI_VOLUME_TAG_LEN)?;
         }
 
         Ok(None)
-- 
2.30.2





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

* [pbs-devel] [PATCH proxmox-backup 3/4] tape: changer: sg_pt: fix typo
  2021-07-21 14:04 [pbs-devel] [PATCH proxmox-backup 1/4] api: types: CHANGER_DRIVENUM_SCHEMA: increase maximum drives per changer Dominik Csapak
  2021-07-21 14:04 ` [pbs-devel] [PATCH proxmox-backup 2/4] tape: changer: sg_pt: add SCSI_VOLUME_TAG_LEN const Dominik Csapak
@ 2021-07-21 14:04 ` Dominik Csapak
  2021-07-21 15:02   ` [pbs-devel] applied: " Dietmar Maurer
  2021-07-21 14:04 ` [pbs-devel] [PATCH proxmox-backup 4/4] tape: changer: sg_pt: correctly consume data in decode_element_status_page Dominik Csapak
  2021-07-21 15:01 ` [pbs-devel] applied: [PATCH proxmox-backup 1/4] api: types: CHANGER_DRIVENUM_SCHEMA: increase maximum drives per changer Dietmar Maurer
  3 siblings, 1 reply; 8+ messages in thread
From: Dominik Csapak @ 2021-07-21 14:04 UTC (permalink / raw)
  To: pbs-devel

ok, since its a private struct

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

diff --git a/src/tape/changer/sg_pt_changer.rs b/src/tape/changer/sg_pt_changer.rs
index 908311b0..a15d8192 100644
--- a/src/tape/changer/sg_pt_changer.rs
+++ b/src/tape/changer/sg_pt_changer.rs
@@ -536,7 +536,7 @@ impl SubHeader {
 
 #[repr(C, packed)]
 #[derive(Endian)]
-struct TrasnsportDescriptor { // Robot/Griper
+struct TransportDescriptor { // Robot/Griper
     element_address: u16,
     flags1: u8,
     reserved_3: u8,
@@ -665,7 +665,7 @@ fn decode_element_status_page(
 
                 match subhead.element_type_code {
                     1 => {
-                        let desc: TrasnsportDescriptor = unsafe { reader.read_be_value()? };
+                        let desc: TransportDescriptor = unsafe { reader.read_be_value()? };
 
                         let full = (desc.flags1 & 1) != 0;
                         let volume_tag = subhead.parse_optional_volume_tag(&mut reader, full)?;
-- 
2.30.2





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

* [pbs-devel] [PATCH proxmox-backup 4/4] tape: changer: sg_pt: correctly consume data in decode_element_status_page
  2021-07-21 14:04 [pbs-devel] [PATCH proxmox-backup 1/4] api: types: CHANGER_DRIVENUM_SCHEMA: increase maximum drives per changer Dominik Csapak
  2021-07-21 14:04 ` [pbs-devel] [PATCH proxmox-backup 2/4] tape: changer: sg_pt: add SCSI_VOLUME_TAG_LEN const Dominik Csapak
  2021-07-21 14:04 ` [pbs-devel] [PATCH proxmox-backup 3/4] tape: changer: sg_pt: fix typo Dominik Csapak
@ 2021-07-21 14:04 ` Dominik Csapak
  2021-07-21 14:18   ` Dominik Csapak
  2021-07-21 15:01 ` [pbs-devel] applied: [PATCH proxmox-backup 1/4] api: types: CHANGER_DRIVENUM_SCHEMA: increase maximum drives per changer Dietmar Maurer
  3 siblings, 1 reply; 8+ messages in thread
From: Dominik Csapak @ 2021-07-21 14:04 UTC (permalink / raw)
  To: pbs-devel

instead of 'blindly' trusting the changer to deliver the fields written
in the specification, trust the length data it returns in the header.

now we count the data we consume from it, and do not error out if some
fields at the end are missing (we do not need most of them anyway)

this also makes the code to read the rest of the page a bit easier,
since we already counted how much should be left

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

diff --git a/src/tape/changer/sg_pt_changer.rs b/src/tape/changer/sg_pt_changer.rs
index a15d8192..b0417f82 100644
--- a/src/tape/changer/sg_pt_changer.rs
+++ b/src/tape/changer/sg_pt_changer.rs
@@ -657,23 +657,32 @@ fn decode_element_status_page(
                 if reader.is_empty() {
                     break;
                 }
-                if reader.len() < (subhead.descriptor_length as usize) {
+                let mut remaining_size = subhead.descriptor_length as usize;
+                if reader.len() < remaining_size {
                     break;
                 }
 
-                let len_before = reader.len();
-
                 match subhead.element_type_code {
                     1 => {
                         let desc: TransportDescriptor = unsafe { reader.read_be_value()? };
+                        remaining_size -= std::mem::size_of::<TransportDescriptor>();
 
                         let full = (desc.flags1 & 1) != 0;
                         let volume_tag = subhead.parse_optional_volume_tag(&mut reader, full)?;
+                        if volume_tag.is_some() {
+                            remaining_size -= SCSI_VOLUME_TAG_LEN;
+                        }
 
-                        subhead.skip_alternate_volume_tag(&mut reader)?;
+                        if remaining_size >= SCSI_VOLUME_TAG_LEN {
+                            subhead.skip_alternate_volume_tag(&mut reader)?;
+                            remaining_size -= SCSI_VOLUME_TAG_LEN;
+                        }
 
-                        let mut reserved = [0u8; 4];
-                        reader.read_exact(&mut reserved)?;
+                        if remaining_size >= 4 {
+                            let mut reserved = [0u8; 4];
+                            reader.read_exact(&mut reserved)?;
+                            remaining_size -= 4;
+                        }
 
                         result.last_element_address = Some(desc.element_address);
 
@@ -685,14 +694,24 @@ fn decode_element_status_page(
                     }
                     2 | 3 => {
                         let desc: StorageDescriptor = unsafe { reader.read_be_value()? };
+                        remaining_size -= std::mem::size_of::<StorageDescriptor>();
 
                         let full = (desc.flags1 & 1) != 0;
                         let volume_tag = subhead.parse_optional_volume_tag(&mut reader, full)?;
+                        if volume_tag.is_some() {
+                            remaining_size -= SCSI_VOLUME_TAG_LEN;
+                        }
 
-                        subhead.skip_alternate_volume_tag(&mut reader)?;
+                        if remaining_size >= SCSI_VOLUME_TAG_LEN {
+                            subhead.skip_alternate_volume_tag(&mut reader)?;
+                            remaining_size -= SCSI_VOLUME_TAG_LEN;
+                        }
 
-                        let mut reserved = [0u8; 4];
-                        reader.read_exact(&mut reserved)?;
+                        if remaining_size >= 4 {
+                            let mut reserved = [0u8; 4];
+                            reader.read_exact(&mut reserved)?;
+                            remaining_size -= 4;
+                        }
 
                         result.last_element_address = Some(desc.element_address);
 
@@ -714,6 +733,7 @@ fn decode_element_status_page(
                     }
                     4 => {
                         let desc: TransferDescriptor = unsafe { reader.read_be_value()? };
+                        remaining_size -= std::mem::size_of::<TransferDescriptor>();
 
                         let loaded_slot = if (desc.flags2 & 128) != 0 { // SValid
                             Some(desc.source_storage_element_address as u64)
@@ -723,30 +743,39 @@ fn decode_element_status_page(
 
                         let full = (desc.flags1 & 1) != 0;
                         let volume_tag = subhead.parse_optional_volume_tag(&mut reader, full)?;
+                        if volume_tag.is_some() {
+                            remaining_size -= SCSI_VOLUME_TAG_LEN;
+                        }
 
-                        subhead.skip_alternate_volume_tag(&mut reader)?;
-
-                        let dvcid: DvcidHead = unsafe { reader.read_be_value()? };
+                        if remaining_size >= SCSI_VOLUME_TAG_LEN {
+                            subhead.skip_alternate_volume_tag(&mut reader)?;
+                            remaining_size -= SCSI_VOLUME_TAG_LEN;
+                        }
 
-                        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 (drive_serial_number, vendor, model) = if remaining_size >= std::mem::size_of::<DvcidHead>() {
+                            let dvcid: DvcidHead = unsafe { reader.read_be_value()? };
+                            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))
                                 }
-                                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),
                             }
-                            _ => (None, None, None),
+                        } else {
+                            (None, None, None)
                         };
 
                         result.last_element_address = Some(desc.element_address);
@@ -766,15 +795,11 @@ fn decode_element_status_page(
 
                 // we have to consume the whole descriptor size, else
                 // our position in the reader is not correct
-                let len_after = reader.len();
-                let have_read = len_before - len_after;
-                let desc_len = subhead.descriptor_length as usize;
-                if desc_len > have_read {
-                    let mut left_to_read = desc_len - have_read;
-                    if left_to_read > len_after {
-                        left_to_read = len_after; // reader has not enough data?
+                if remaining_size > 0 {
+                    if remaining_size > reader.len() {
+                        remaining_size = reader.len();  // reader has not enough data?
                     }
-                    let _ = reader.read_exact_allocated(left_to_read)?;
+                    let _ = reader.read_exact_allocated(remaining_size)?;
                 }
             }
         }
-- 
2.30.2





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

* Re: [pbs-devel] [PATCH proxmox-backup 4/4] tape: changer: sg_pt: correctly consume data in decode_element_status_page
  2021-07-21 14:04 ` [pbs-devel] [PATCH proxmox-backup 4/4] tape: changer: sg_pt: correctly consume data in decode_element_status_page Dominik Csapak
@ 2021-07-21 14:18   ` Dominik Csapak
  0 siblings, 0 replies; 8+ messages in thread
From: Dominik Csapak @ 2021-07-21 14:18 UTC (permalink / raw)
  To: pbs-devel

disregard this patch, there is a small bug. i'll send a v2




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

* [pbs-devel] applied: [PATCH proxmox-backup 1/4] api: types: CHANGER_DRIVENUM_SCHEMA: increase maximum drives per changer
  2021-07-21 14:04 [pbs-devel] [PATCH proxmox-backup 1/4] api: types: CHANGER_DRIVENUM_SCHEMA: increase maximum drives per changer Dominik Csapak
                   ` (2 preceding siblings ...)
  2021-07-21 14:04 ` [pbs-devel] [PATCH proxmox-backup 4/4] tape: changer: sg_pt: correctly consume data in decode_element_status_page Dominik Csapak
@ 2021-07-21 15:01 ` Dietmar Maurer
  3 siblings, 0 replies; 8+ messages in thread
From: Dietmar Maurer @ 2021-07-21 15:01 UTC (permalink / raw)
  To: Proxmox Backup Server development discussion, Dominik Csapak

applied

On 7/21/21 4:04 PM, Dominik Csapak wrote:
> to 255. 8 drives per changer was a rather arbitrary limitation and could
> well be reached in practice with big libraries.
>
> Altough 255 is still a arbirtrary limitation, this is much less likely
> to be reached in practice.
>
> Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
> ---
>   src/api2/types/tape/drive.rs | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/api2/types/tape/drive.rs b/src/api2/types/tape/drive.rs
> index ecc65088..f50b1d5f 100644
> --- a/src/api2/types/tape/drive.rs
> +++ b/src/api2/types/tape/drive.rs
> @@ -28,7 +28,7 @@ pub const LTO_DRIVE_PATH_SCHEMA: Schema = StringSchema::new(
>   pub const CHANGER_DRIVENUM_SCHEMA: Schema = IntegerSchema::new(
>       "Associated changer drive number (requires option changer)")
>       .minimum(0)
> -    .maximum(8)
> +    .maximum(255)
>       .default(0)
>       .schema();
>   




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

* [pbs-devel] applied: [PATCH proxmox-backup 2/4] tape: changer: sg_pt: add SCSI_VOLUME_TAG_LEN const
  2021-07-21 14:04 ` [pbs-devel] [PATCH proxmox-backup 2/4] tape: changer: sg_pt: add SCSI_VOLUME_TAG_LEN const Dominik Csapak
@ 2021-07-21 15:02   ` Dietmar Maurer
  0 siblings, 0 replies; 8+ messages in thread
From: Dietmar Maurer @ 2021-07-21 15:02 UTC (permalink / raw)
  To: Proxmox Backup Server development discussion, Dominik Csapak

applied

On 7/21/21 4:04 PM, Dominik Csapak wrote:
> so that we do have less 'magic' constants without description
>
> Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
> ---
>   src/tape/changer/sg_pt_changer.rs | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/src/tape/changer/sg_pt_changer.rs b/src/tape/changer/sg_pt_changer.rs
> index f4154ced..908311b0 100644
> --- a/src/tape/changer/sg_pt_changer.rs
> +++ b/src/tape/changer/sg_pt_changer.rs
> @@ -33,6 +33,7 @@ use crate::{
>   };
>   
>   const SCSI_CHANGER_DEFAULT_TIMEOUT: usize = 60*5; // 5 minutes
> +const SCSI_VOLUME_TAG_LEN: usize = 36;
>   
>   /// Initialize element status (Inventory)
>   pub fn initialize_element_status<F: AsRawFd>(file: &mut F) -> Result<(), Error> {
> @@ -509,7 +510,7 @@ impl SubHeader {
>       ) -> Result<Option<String>, Error> {
>   
>           if (self.flags & 128) != 0 { // has PVolTag
> -            let tmp = reader.read_exact_allocated(36)?;
> +            let tmp = reader.read_exact_allocated(SCSI_VOLUME_TAG_LEN)?;
>               if full {
>                   let volume_tag = scsi_ascii_to_string(&tmp);
>                   return Ok(Some(volume_tag));
> @@ -526,7 +527,7 @@ impl SubHeader {
>       ) -> Result<Option<String>, Error> {
>   
>           if (self.flags & 64) != 0 { // has AVolTag
> -            let _tmp = reader.read_exact_allocated(36)?;
> +            let _tmp = reader.read_exact_allocated(SCSI_VOLUME_TAG_LEN)?;
>           }
>   
>           Ok(None)




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

* [pbs-devel] applied: [PATCH proxmox-backup 3/4] tape: changer: sg_pt: fix typo
  2021-07-21 14:04 ` [pbs-devel] [PATCH proxmox-backup 3/4] tape: changer: sg_pt: fix typo Dominik Csapak
@ 2021-07-21 15:02   ` Dietmar Maurer
  0 siblings, 0 replies; 8+ messages in thread
From: Dietmar Maurer @ 2021-07-21 15:02 UTC (permalink / raw)
  To: Proxmox Backup Server development discussion, Dominik Csapak

applied

On 7/21/21 4:04 PM, Dominik Csapak wrote:
> ok, since its a private struct
>
> Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
> ---
>   src/tape/changer/sg_pt_changer.rs | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/src/tape/changer/sg_pt_changer.rs b/src/tape/changer/sg_pt_changer.rs
> index 908311b0..a15d8192 100644
> --- a/src/tape/changer/sg_pt_changer.rs
> +++ b/src/tape/changer/sg_pt_changer.rs
> @@ -536,7 +536,7 @@ impl SubHeader {
>   
>   #[repr(C, packed)]
>   #[derive(Endian)]
> -struct TrasnsportDescriptor { // Robot/Griper
> +struct TransportDescriptor { // Robot/Griper
>       element_address: u16,
>       flags1: u8,
>       reserved_3: u8,
> @@ -665,7 +665,7 @@ fn decode_element_status_page(
>   
>                   match subhead.element_type_code {
>                       1 => {
> -                        let desc: TrasnsportDescriptor = unsafe { reader.read_be_value()? };
> +                        let desc: TransportDescriptor = unsafe { reader.read_be_value()? };
>   
>                           let full = (desc.flags1 & 1) != 0;
>                           let volume_tag = subhead.parse_optional_volume_tag(&mut reader, full)?;




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

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

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-21 14:04 [pbs-devel] [PATCH proxmox-backup 1/4] api: types: CHANGER_DRIVENUM_SCHEMA: increase maximum drives per changer Dominik Csapak
2021-07-21 14:04 ` [pbs-devel] [PATCH proxmox-backup 2/4] tape: changer: sg_pt: add SCSI_VOLUME_TAG_LEN const Dominik Csapak
2021-07-21 15:02   ` [pbs-devel] applied: " Dietmar Maurer
2021-07-21 14:04 ` [pbs-devel] [PATCH proxmox-backup 3/4] tape: changer: sg_pt: fix typo Dominik Csapak
2021-07-21 15:02   ` [pbs-devel] applied: " Dietmar Maurer
2021-07-21 14:04 ` [pbs-devel] [PATCH proxmox-backup 4/4] tape: changer: sg_pt: correctly consume data in decode_element_status_page Dominik Csapak
2021-07-21 14:18   ` Dominik Csapak
2021-07-21 15:01 ` [pbs-devel] applied: [PATCH proxmox-backup 1/4] api: types: CHANGER_DRIVENUM_SCHEMA: increase maximum drives per changer Dietmar Maurer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal