Virtual tape library and PBS

Diego Zuccato <[email protected]> Fri, 15 May 2026 14:48:17 +0200
Newsgroups org.kernel.vger.stgt
Message-ID <[email protected]>
Hello all.

I've configured a virtual tape library to store backups from 
ProxmoxBackupServer in raw hdds (treating each HDD as a tape cartridge).

Too bad when I tried to scan the vtapes PBS reported an error: seems the 
answer to READ_ELEMENT_STATUS is too short.

Looking at the code, it seems the logic in the switch should be changed 
slightly, especially in the first case statement.

I think this could be a suitable patch (I'll test monday morning):
-8<--
index bbc7b7f..fae389b 100644
--- a/usr/smc.c
+++ b/usr/smc.c
@@ -302,6 +302,7 @@ static int smc_read_element_status(int host_no, 
struct scsi_cmd *cmd)
         uint8_t dvcid;
         int alloc_len;
         uint16_t count = 0;
+       uint16_t total_count = 0;
         int first = 0;          /* First valid slot location */
         int len = 8;
         int elementSize;
@@ -349,18 +350,21 @@ static int smc_read_element_status(int host_no, 
struct scsi_cmd *cmd)
                                                   ELEMENT_MEDIUM_TRANSPORT,
                                                   &first, req_start_elem,
                                                   dvcid, voltag);
-               len = count * elementSize;
-               count += build_element_descriptors(&data[len], &smc->slots,
+               len += count * elementSize;
+               total_count+=count;
+               count = build_element_descriptors(&data[len], &smc->slots,
                                                    ELEMENT_STORAGE,
                                                    &first, req_start_elem,
                                                    dvcid, voltag);
                 len += count * elementSize;
-               count += build_element_descriptors(&data[len], &smc->slots,
+               total_count+=count;
+               count = build_element_descriptors(&data[len], &smc->slots,
                                                    ELEMENT_MAP,
                                                    &first, req_start_elem,
                                                    dvcid, voltag);
                 len += count * elementSize;
-               count += build_element_descriptors(&data[len], &smc->slots,
+               total_count+=count;
+               count = build_element_descriptors(&data[len], &smc->slots,
                                                    ELEMENT_DATA_TRANSFER,
                                                    &first, req_start_elem,
                                                    dvcid, voltag);
@@ -394,8 +398,11 @@ static int smc_read_element_status(int host_no, 
struct scsi_cmd *cmd)
                 break;
         }

+       len += count * elementSize;
+       total_count+=count;
+
         /* Lastly, fill in data header */
-       len = element_status_data_hdr(data, dvcid, voltag, first, count);
+       element_status_data_hdr(data, dvcid, voltag, first, total_count);
         memcpy(scsi_get_in_buffer(cmd), data, min(len, alloc_len));
         scsi_set_in_resid_by_actual(cmd, len);
         free(data);
-8<--

Since I've never worked on tgt code before, I could easily be completely 
off. Does it seem reasonable?
IIUC, the case ELEMENT_ANY must "accumulate" all the 
build_element_descriptors() calls in data, but old code overwrote 
previous contents with later calls.

-- 
Diego Zuccato
DIFA - Dip. di Fisica e Astronomia
Servizi Informatici
Alma Mater Studiorum - Università di Bologna
V.le Berti-Pichat 6/2 - 40127 Bologna - Italy
tel.: +39 051 20 95786