From 45c224073e1688b739236b2e9a79b0afda2bf654 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Tue, 31 Aug 2021 05:29:56 +0000 Subject: add support for obtaining sense status and source slot of a media this fixes a bug in bacula where the catalog was not properly kept up-to-date if a tape was in a drive becuse its source slot was unknown based on code from FreeBSD; ok krw@ picker 0: sense: <0x00/0x00> voltag: <:0> avoltag: <:0> source: <> slot 0: sense: <0x00/0x00> voltag: avoltag: <:0> source: slot 1: sense: <0x00/0x00> voltag: avoltag: <:0> source: slot 2: sense: <0x00/0x00> voltag: avoltag: <:0> source: slot 3: sense: <0x00/0x00> voltag: avoltag: <:0> source: slot 4: sense: <0x00/0x00> voltag: avoltag: <:0> source: slot 5: sense: <0x00/0x00> voltag: avoltag: <:0> source: slot 6: sense: <0x00/0x00> voltag: avoltag: <:0> source: slot 7: sense: <0x00/0x00> voltag: avoltag: <:0> source: slot 8: sense: <0x00/0x00> voltag: avoltag: <:0> source: slot 9: sense: <0x00/0x00> voltag: avoltag: <:0> source: slot 10: sense: <0x00/0x00> voltag: <:0> avoltag: <:0> source: slot 11: sense: <0x00/0x00> voltag: avoltag: <:0> source: slot 12: sense: <0x00/0x00> voltag: avoltag: <:0> source: slot 13: sense: <0x00/0x00> voltag: avoltag: <:0> source: slot 14: sense: <0x00/0x00> voltag: avoltag: <:0> source: slot 15: sense: <0x00/0x00> voltag: avoltag: <:0> source: slot 16: sense: <0x00/0x00> voltag: avoltag: <:0> source: slot 17: sense: <0x00/0x00> voltag: avoltag: <:0> source: slot 18: sense: <0x00/0x00> voltag: avoltag: <:0> source: slot 19: sense: <0x00/0x00> voltag: avoltag: <:0> source: slot 20: sense: <0x00/0x00> voltag: avoltag: <:0> source: slot 21: sense: <0x00/0x00> voltag: avoltag: <:0> source: slot 22: sense: <0x00/0x00> voltag: avoltag: <:0> source: slot 23: sense: <0x00/0x00> voltag: avoltag: <:0> source: drive 0: sense: <0x00/0x00> voltag: avoltag: <:0> source: --- sys/scsi/ch.c | 48 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) (limited to 'sys/scsi') diff --git a/sys/scsi/ch.c b/sys/scsi/ch.c index 672bd9560b2..7672970b5c8 100644 --- a/sys/scsi/ch.c +++ b/sys/scsi/ch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ch.c,v 1.68 2021/03/12 10:22:46 jsg Exp $ */ +/* $OpenBSD: ch.c,v 1.69 2021/08/31 05:29:55 robert Exp $ */ /* $NetBSD: ch.c,v 1.26 1997/02/21 22:06:52 thorpej Exp $ */ /* @@ -514,11 +514,53 @@ copy_voltag(struct changer_voltag *uvoltag, struct volume_tag *voltag) * changer_element_status structure. */ static void -copy_element_status(int flags, struct read_element_status_descriptor *desc, +copy_element_status(struct ch_softc *sc, int flags, + struct read_element_status_descriptor *desc, struct changer_element_status *ces) { + u_int16_t eaddr = _2btol(desc->eaddr); + u_int16_t et; + + for (et = CHET_MT; et <= CHET_DT; et++) { + if ((sc->sc_firsts[et] <= eaddr) + && ((sc->sc_firsts[et] + sc->sc_counts[et]) + > eaddr)) { + ces->ces_addr = eaddr - sc->sc_firsts[et]; + ces->ces_type = et; + break; + } + } + ces->ces_flags = desc->flags1; + ces->ces_sensecode = desc->sense_code; + ces->ces_sensequal = desc->sense_qual; + + if (desc->flags2 & READ_ELEMENT_STATUS_INVERT) + ces->ces_flags |= READ_ELEMENT_STATUS_EXCEPT; + + if (desc->flags2 & READ_ELEMENT_STATUS_SVALID) { + eaddr = _2btol(desc->ssea); + + /* convert source address to logical format */ + for (et = CHET_MT; et <= CHET_DT; et++) { + if ((sc->sc_firsts[et] <= eaddr) + && ((sc->sc_firsts[et] + sc->sc_counts[et]) + > eaddr)) { + ces->ces_source_addr = + eaddr - sc->sc_firsts[et]; + ces->ces_source_type = et; + ces->ces_flags |= READ_ELEMENT_STATUS_ACCESS; + break; + } + } + + if (!(ces->ces_flags & READ_ELEMENT_STATUS_ACCESS)) + printf("ch: warning: could not map element source " + "address %ud to a valid element type\n", + eaddr); + } + if (ISSET(flags, READ_ELEMENT_STATUS_PVOLTAG)) copy_voltag(&ces->ces_pvoltag, &desc->pvoltag); if (ISSET(flags, READ_ELEMENT_STATUS_AVOLTAG)) @@ -604,7 +646,7 @@ ch_usergetelemstatus(struct ch_softc *sc, desc = (caddr_t)(pg_hdr + 1); for (i = 0; i < avail; ++i) { struct changer_element_status *ces = &(user_data[i]); - copy_element_status(pg_hdr->flags, + copy_element_status(sc, pg_hdr->flags, (struct read_element_status_descriptor *)desc, ces); desc += desclen; } -- cgit v1.2.3