scsi: st: improve pos_unknown handling after reset
Subsystems (2)
cover scsi: st: improve pos_unknown handling after reset
These patches address some issues with positoin lost handling which where introduced by commit 9604eea5bd3a ("scsi: st: Add third party poweron reset handling"). That commit added code which detected any unexpected power on/reset unit attention to st_chk_results() and correclty set pos_unknown in the driver.
However, the aforementioned changes is catching POR UAs that are expected as well as those that are unexpected as st_chk_results() sets pos_unknown every time a POR UA is seen. This results in a change of behavior that is confusing as some tape drives can set a POR UA when the system reboots, the driver reloads, or a tape is reloaded. This results in regressions as MTIOGET now fails following and kind of reset.
These issues are documented in the kernel bugzilla:
A reproducer test script can be found at:
John Meneghini (3):
scsi: st: instrument the pos_unknown code
scsi: st: clear was_reset when CHKRES_NEW_SESSION
scsi: st: clear pos_unknown when the por ua is expected
drivers/scsi/st.c | 63 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 54 insertions(+), 9 deletions(-)
Signature · 1 line
2.47.0
PATCH 1/3 scsi: st: instrument the pos_unknown code
Add debugging printfs to the various code paths that use pos_unknown. This code is a little chatty but nothing has been added to the datapath. It has been used to help debug a number of customer reported problems from the field since the change for commit 9604eea5bd3a ("scsi: st: Add third party poweron reset handling") was added.
To enable:
echo 1 > /sys/module/st/drivers/scsi:st/debug_flag
--- drivers/scsi/st.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)
drivers/scsi/st.c +31 -0
@@ -418,6 +418,10 @@ static int st_chk_result(struct scsi_tape *STp, struct st_request * SRpnt) STp->pos_unknown |= STp->device->was_reset; +DEBC_printk (STp,"%s: %d: pos_unknown %x was_reset %x ready %x, result %d\n" , + __func__, __LINE__, STp->pos_unknown, STp->device->was_reset, + STp->ready, result); + if (cmdstatp->have_sense && scode == RECOVERED_ERROR#if ST_RECOVERED_WRITE_FATAL
@@ -834,6 +838,10 @@ static int flush_buffer(struct scsi_tape *STp, int seek_next)int backspace, result;struct st_partstat *STps; +DEBC_printk (STp,"%s: %d: pos_unknown %x was_reset %x ready %x\n" , + __func__, __LINE__, STp->pos_unknown, STp->device->was_reset, + STp->ready); +if (STp->ready !=ST_READY )return 0 ;
@@ -1050,6 +1058,10 @@ static int check_tape(struct scsi_tape *STp, struct file *filp)struct inode *inode =file_inode (filp);int mode =TAPE_MODE (inode); +DEBC_printk (STp,"%s: %d: pos_unknown %x was_reset %x ready %x\n" , + __func__, __LINE__, STp->pos_unknown, + STp->device->was_reset, STp->ready); + STp->ready =ST_READY ;if (mode != STp->current_mode) {
@@ -1085,6 +1097,9 @@ static int check_tape(struct scsi_tape *STp, struct file *filp) STps->drv_file =0 ; } new_session =1 ; +DEBC_printk (STp,"%s: %d: CHKRES_NEW_SESS pos_unknown %x was_reset %x ready %x\n" , + __func__, __LINE__, STp->pos_unknown, STp->device->was_reset, + STp->ready); }else { STp->cleaning_req |= saved_cleaning;
@@ -1101,6 +1116,12 @@ static int check_tape(struct scsi_tape *STp, struct file *filp) STp->ps[0 ].drv_file = STp->ps[0 ].drv_block = (-1 ); STp->partition = STp->new_partition =0 ; STp->door_locked =ST_UNLOCKED ; + +DEBC_printk (STp, +"%s: %d: CHKRES_NOT_READY pos_unknown %x was_reset %x ready %x\n" , + __func__, __LINE__, STp->pos_unknown, STp->device->was_reset, + STp->ready); +return CHKRES_NOT_READY ; } }
@@ -1237,9 +1258,16 @@ static int check_tape(struct scsi_tape *STp, struct file *filp) } } +DEBC_printk (STp,"%s: %d: CHKRES_READY pos_unknown %x was_reset %x ready %x\n" , + __func__, __LINE__, STp->pos_unknown, STp->device->was_reset, + STp->ready); +return CHKRES_READY ; err_out: +DEBC_printk (STp,"%s: %d: pos_unknown %x was_reset %x ready %x retval %d\n" , + __func__, __LINE__, STp->pos_unknown, STp->device->was_reset, + STp->ready, retval);return retval; }
@@ -1352,6 +1380,9 @@ static int st_flush(struct file *filp, fl_owner_t id)if (file_count (filp) >1 )return 0 ; +DEBC_printk (STp,"%s: %d: pos_unknown %x was_reset %x ready %x\n" , + __func__, __LINE__, STp->pos_unknown, STp->device->was_reset, STp->ready); +if (STps->rw ==ST_WRITING && !STp->pos_unknown) { result =st_flush_write_buffer (STp);if (result !=0 && result != (-ENOSPC ))
Signature · 1 line
2.47.0
PATCH 2/3 scsi: st: clear was_reset when CHKRES_NEW_SESSION
In reply to John MeneghiniBe sure to clear was_reset when ever we clear pos_unknown. If we don't then the code in st_chk_result() will turn on pos_unknown again.
STp->pos_unknown |= STp->device->was_reset;
This results in confusion as future commands fail unexpectedly.
--- drivers/scsi/st.c | 1 + 1 file changed, 1 insertion(+)
drivers/scsi/st.c +1 -0
@@ -1083,6 +1083,7 @@ static int check_tape(struct scsi_tape *STp, struct file *filp)if (retval ==CHKRES_NEW_SESSION ) { STp->pos_unknown =0 ; + STp->device->was_reset =0 ; STp->partition = STp->new_partition =0 ;if (STp->can_partitions) STp->nbr_partitions =1 ;/* This guess will be updated later
Signature · 1 line
2.47.0
Re: [PATCH 2/3] scsi: st: clear was_reset when CHKRES_NEW_SESSION
Quoted 10 lines · John Meneghini
Be sure to clear
was_resetwhen ever we clearpos_unknown. If we don't then the code inst_chk_result()will turn onpos_unknownagain.STp->pos_unknown |= STp->device->was_reset;This results in confusion as future commands fail unexpectedly.
This brings in my mind (again) the question: is the hack using was_reset set by scsi_error to detect device reset necessary any more? It was introduced as a temporary method somewhere between 1.3.20 and 1.3.30 (in 1995) when the POR (power on/reset) UAs (Unit Attention) were not passed to st. The worst problem with this hack is clearing was_reset. St should not clear something set by error handling (layering violation).
Your earlier patch added code to st to set pos_unknown when a POR UA was found. So, is this now alone enough to catch the resets?
I now did some experiments with scsi_debug and in those experiments reset initiated using sg_reset did result in st getting POR UA. But this was just a simple and somewhat artificial test.
Re: [PATCH 2/3] scsi: st: clear was_reset when CHKRES_NEW_SESSION
Quoted 7 lines · Kai Mäkisara (Kolumbus)
Quoted 7 lines · John Meneghini
Be sure to clear
was_resetwhen ever we clearpos_unknown. If we don't then the code inst_chk_result()will turn onpos_unknownagain.STp->pos_unknown |= STp->device->was_reset;
Quoted 8 lines
Quoted 1 line
This results in confusion as future commands fail unexpectedly.
This brings in my mind (again) the question: is the hack using
was_resetset byscsi_errorto detect device reset necessary any more? It was introduced as a temporary method somewhere between 1.3.20 and 1.3.30 (in 1995) when the POR (power on/reset) UAs (Unit Attention) were not passed to st. The worst problem with this hack is clearingwas_reset. St should not clear something set by error handling (layering violation).
OK. I wasn't aware of the history here... but I agree we want to get rid of the layering violation.
Quoted 2 lines
Your earlier patch added code to st to set
pos_unknownwhen a POR UA was found. So, is this now alone enough to catch the resets?
As long at the tape device actually sends a UA, no I don't think we need the was_reset code anymore. We should remove the device->was_reset code from st.c.
Quoted 3 lines
I now did some experiments with
scsi_debugand in those experiments reset initiated usingsg_resetdid result in st getting POR UA. But this was just a simple and somewhat artificial test.
Yes, I've noticed that not all of the different emulators out there like MHVTL and scsi_debug will reliably send a POR UA following sg_reset. Especially scsi_debug. The tape emulation in scsi_debug is inadequate when it comes to resets AFAIAC.
I'll see if I can develop some further tests for MHVLT, but scsi_debug isn't worth the trouble (for me) and I've told our QE group here at Red Hat to stop testing the st driver with scsi_debug. Doing this has led to too many false positives and passing tests. That's why I finally purchased a tape drive and started testing this myself.
If you want to remove the device->was_reset from the st driver I can help by running the patch through my tests with the tape device.
Signature · 4 lines
John A. Meneghini Senior Principal Platform Storage Engineer RHEL SST - Platform Storage Group [email protected]
Re: [PATCH 2/3] scsi: st: clear was_reset when CHKRES_NEW_SESSION
Quoted 13 lines · John Meneghini
Quoted 8 lines · Kai Mäkisara (Kolumbus)
Quoted 8 lines · John Meneghini
Be sure to clear
was_resetwhen ever we clearpos_unknown. If we don't then the code inst_chk_result()will turn onpos_unknownagain.STp->pos_unknown |= STp->device->was_reset;This results in confusion as future commands fail unexpectedly.
Quoted 9 lines
Quoted 6 lines
This brings in my mind (again) the question: is the hack using
was_resetset byscsi_errorto detect device reset necessary any more? It was introduced as a temporary method somewhere between 1.3.20 and 1.3.30 (in 1995) when the POR (power on/reset) UAs (Unit Attention) were not passed to st. The worst problem with this hack is clearingwas_reset. St should not clear something set by error handling (layering violation).OK. I wasn't aware of the history here... but I agree we want to get rid of the layering violation.
I have read code and done experiments. I think I now know how the POR UAs were lost in 1990s. And why that does not happen now.
In 1.3.30, scsi.c handled resets. When resetting, it set the device->expecting_cc_ua flag. If UA was received when expecting_cc_ua was set, the command was retried if retries were allowed. St allowed five retries for TEST UNIT READY and so the POR UA was left in the midlevel. (If expecting_cc_ua was zero, UA:s were returned to the upper level.)
Now, st does allow zero retries. In addition to this, the requests use either REQ_OP_DRV_IN or REQ_OP_DRV_OUT and these requests are not retried. So, now POR UAs reach st (as the experiments have indicated).
Quoted 6 lines
Quoted 2 lines
Your earlier patch added code to st to set
pos_unknownwhen a POR UA was found. So, is this now alone enough to catch the resets?As long at the tape device actually sends a UA, no I don't think we need the
was_resetcode anymore. We should remove thedevice->was_resetcode fromst.c.
Using device->was_reset has the advantage that it does not depend on the drives sending UA. However, I think that a probability of a working drive not sending UA after reset is minimal.
Quoted 4 lines
Quoted 3 lines
I now did some experiments with
scsi_debugand in those experiments reset initiated usingsg_resetdid result in st getting POR UA. But this was just a simple and somewhat artificial test.
Quoted 8 lines
Yes, I've noticed that not all of the different emulators out there like MHVTL and
scsi_debugwill reliably send a POR UA followingsg_reset. Especiallyscsi_debug. The tape emulation inscsi_debugis inadequate when it comes to resets AFAIAC.I'll see if I can develop some further tests for MHVLT, but
scsi_debugisn't worth the trouble (for me) and I've told our QE group here at Red Hat to stop testing the st driver withscsi_debug. Doing this has led to too many false positives and passing tests. That's why I finally purchased a tape drive and started testing this myself.
I have a more positive view about scsi_debug. Its tape support is minimal, but it can be useful if you consider what it does support and what it doesn't support.
A real drive is better, of course.
Quoted 2 lines
If you want to remove the
device->was_resetfrom the st driver I can help by running the patch through my tests with the tape device.
I will send patches tomorrow. The patches will also include a fix to another problem:
some parameters should be restored after reset in case of some operations like rewind:
the partition, density and block size should be restored to the values set before reset.
Thanks for your testing (so far and in future).
Kai
Re: [PATCH 2/3] scsi: st: clear was_reset when CHKRES_NEW_SESSION
On 11/14/24 11:51, "Kai Mäkisara (Kolumbus)" wrote:>
Quoted 29 lines
Quoted 11 lines · John Meneghini
Quoted 8 lines · Kai Mäkisara (Kolumbus)
Quoted 8 lines · John Meneghini
Be sure to clear
was_resetwhen ever we clearpos_unknown. If we don't then the code inst_chk_result()will turn onpos_unknownagain.STp->pos_unknown |= STp->device->was_reset;This results in confusion as future commands fail unexpectedly.
Quoted 9 lines
Quoted 6 lines
This brings in my mind (again) the question: is the hack using
was_resetset byscsi_errorto detect device reset necessary any more? It was introduced as a temporary method somewhere between 1.3.20 and 1.3.30 (in 1995) when the POR (power on/reset) UAs (Unit Attention) were not passed to st. The worst problem with this hack is clearingwas_reset. St should not clear something set by error handling (layering violation).OK. I wasn't aware of the history here... but I agree we want to get rid of the layering violation.
I have read code and done experiments. I think I now know how the POR UAs were lost in 1990s. And why that does not happen now.
In 1.3.30,
scsi.chandled resets. When resetting, it set thedevice->expecting_cc_uaflag. If UA was received whenexpecting_cc_uawas set, the command was retried if retries were allowed. St allowed five retries for TEST UNIT READY and so the POR UA was left in the midlevel. (Ifexpecting_cc_uawas zero, UA:s were returned to the upper level.)
Quoted 3 lines
Now, st does allow zero retries. In addition to this, the requests use either
REQ_OP_DRV_INorREQ_OP_DRV_OUTand these requests are not retried. So, now POR UAs reach st (as the experiments have indicated).
Yes, the only time I've see the POR UA not get passed to the st driver is with scsi_debug, when the driver first loads.
[tape_tests]# modprobe -r scsi_debug
[tape_tests]# modprobe scsi_debug ptype=1 max_luns=1 dev_size_mb=10000
[Fri Nov 15 09:28:51 2024] scsi_debug:sdebug_driver_probe: scsi_debug: trim poll_queues to 0. poll_q/nr_hw = (0/1)
[Fri Nov 15 09:28:51 2024] scsi host8: scsi_debug: version 0191 [20210520]
dev_size_mb=10000, opts=0x0, submit_queues=1, statistics=0
[Fri Nov 15 09:28:51 2024] scsi 8:0:0:0: Sequential-Access Linux scsi_debug 0191 PQ: 0 ANSI: 7
[Fri Nov 15 09:28:51 2024] scsi 8:0:0:0: Power-on or device reset occurred^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The sg driver is clearing the UA here.
[Fri Nov 15 09:28:51 2024] st 8:0:0:0: Attached scsi tape st1 [Fri Nov 15 09:28:51 2024] st 8:0:0:0: st1: try direct i/o: yes (alignment 4 B) [Fri Nov 15 09:28:51 2024] st 8:0:0:0: Attached scsi generic sg3 type 1
[tape_tests]# mt -f /dev/nst1 status
[Fri Nov 15 09:28:55 2024] st 8:0:0:0: [st1] check_tape: 1064: pos_unknown 0 was_reset 0 ready 0 [Fri Nov 15 09:28:55 2024] st 8:0:0:0: [st1] Error: 402, cmd: 5 0 0 0 0 0 [Fri Nov 15 09:28:55 2024] st 8:0:0:0: [st1] Sense Key : Illegal Request [current] [Fri Nov 15 09:28:55 2024] st 8:0:0:0: [st1] Add. Sense: Invalid command operation code
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
There should be a UA right here.
I have no idea whey the scsi_debug driver doesn't support READ BLOCK LIMITS.
[Fri Nov 15 09:28:55 2024] st 8:0:0:0: [st1] st_chk_result: 421: pos_unknown 0 was_reset 0 ready 0, result 1026 [Fri Nov 15 09:28:55 2024] st 8:0:0:0: [st1] Can't read block limits.
SCSI 2 tape drive:
File number=-1, block number=-1, partition=0. Tape block size 0 bytes. Density code 0x0 (default). Soft error count since last status=0
General status bits on (1010000):
ONLINE IM_REP_EN
Another problem with using scsi_debug is:
[tape_tests]# sg_reset --target /dev/sg3
This does nothing. I have to use the /dev/st device to reset. This is not true if you have a real tape device.
[tape_tests]# sg_reset --target /dev/nst1
[Fri Nov 15 09:37:18 2024] st 8:0:0:0: [st1] check_tape: 1064: pos_unknown 0 was_reset 1 ready 0 [Fri Nov 15 09:37:18 2024] st 8:0:0:0: Power-on or device reset occurred [Fri Nov 15 09:37:18 2024] st 8:0:0:0: [st1] Error: 2, cmd: 0 0 0 0 0 0 [Fri Nov 15 09:37:18 2024] st 8:0:0:0: [st1] Sense Key : Unit Attention [current] [Fri Nov 15 09:37:18 2024] st 8:0:0:0: [st1] Add. Sense: Scsi bus reset occurred [Fri Nov 15 09:37:18 2024] st 8:0:0:0: [st1] st_chk_result: 421: pos_unknown 1 was_reset 1 ready 0, result 2
^^^^^^^^^^^^^^^^^^
Now we've set pos_unkown.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Your earlier patch added code to st to set
pos_unknownwhen a POR UA was found. So, is this now alone enough to catch the resets?As long at the tape device actually sends a UA, no I don't think we need the
was_resetcode anymore. We should remove thedevice->was_resetcode fromst.c. >Using
device->was_resethas the advantage that it does not depend on the drives sending UA. However, I think that a probability of a working drive not sending UA after reset is minimal.
Agreed. There are some idiosyncrasies in the scsi_debug tape emulation. But I don't want those problems to make their way into the st driver. I don't think the st driver should be paying attention to was_reset, or anything else in the mid layer.
Quoted 13 lines
Quoted 4 lines
Quoted 3 lines
I now did some experiments with
scsi_debugand in those experiments reset initiated usingsg_resetdid result in st getting POR UA. But this was just a simple and somewhat artificial test.Quoted 8 lines
Yes, I've noticed that not all of the different emulators out there like MHVTL and
scsi_debugwill reliably send a POR UA followingsg_reset. Especiallyscsi_debug. The tape emulation inscsi_debugis inadequate when it comes to resets AFAIAC.I'll see if I can develop some further tests for MHVLT, but
scsi_debugisn't worth the trouble (for me) and I've told our QE group here at Red Hat to stop testing the st driver withscsi_debug. Doing this has led to too many false positives and passing tests. That's why I finally purchased a tape drive and started testing this myself.
Quoted 4 lines
I have a more positive view about
scsi_debug. Its tape support is minimal, but it can be useful if you consider what it does support and what it doesn't support.A real drive is better, of course.
Please try my latest version of the tape_reset_debug.sh script.
https://github.com/johnmeneghini/tape_tests/blob/master/tape_reset_debug.sh
This test uses the scsi_debug driver with ptype=1 to test these patches using "sg_reset --target /dev/nst$i".
There is also the tape_reset_debug_sg.sh script. That script runs the same tests using "sg_reset --target /dev/sg$i"
They each give me different false negative and false positive results... but that may because of something I'm doing wrong.
Quoted 6 lines
Quoted 2 lines
If you want to remove the
device->was_resetfrom the st driver I can help by running the patch through my tests with the tape device.I will send patches tomorrow. The patches will also include a fix to another problem:
some parameters should be restored after reset in case of some operations like rewind:
the partition, density and block size should be restored to the values set before reset.
OK, I will test those as soon as they show up.
Quoted 1 line
Thanks for your testing (so far and in future).
And Thanks for your help fixing these bugs...
/John
Quoted 2 lines
Kai
Re: [PATCH 2/3] scsi: st: clear was_reset when CHKRES_NEW_SESSION
Quoted 4 lines · John Meneghini
...
Quoted 9 lines
Quoted 3 lines
Now, st does allow zero retries. In addition to this, the requests use either
REQ_OP_DRV_INorREQ_OP_DRV_OUTand these requests are not retried. So, now POR UAs reach st (as the experiments have indicated).Yes, the only time I've see the POR UA not get passed to the st driver is with
scsi_debug, when the driver first loads.[tape_tests]# modprobe -r
scsi_debug
[tape_tests]# modprobescsi_debugptype=1 max_luns=1 dev_size_mb=10000
Quoted 7 lines
[Fri Nov 15 09:28:51 2024] scsi_debug:sdebug_driver_probe: scsi_debug: trim poll_queues to 0. poll_q/nr_hw = (0/1) [Fri Nov 15 09:28:51 2024] scsi host8: scsi_debug: version 0191 [20210520] dev_size_mb=10000, opts=0x0, submit_queues=1, statistics=0 [Fri Nov 15 09:28:51 2024] scsi 8:0:0:0: Sequential-Access Linux scsi_debug 0191 PQ: 0 ANSI: 7 [Fri Nov 15 09:28:51 2024] scsi 8:0:0:0: Power-on or device reset occurred^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The sg driver is clearing the UA here.
I enabled some SCSI debug logging (0x3001). It shows that the UA is received as response to a 'Report supported operation codes' command. I looked at the code and it seems that scsi_add_lun() in scsi_scan.c uses this operation. So, the UA is not cleared by any ULD.
...
Quoted 2 lines
I have no idea whey the
scsi_debugdriver doesn't support READ BLOCK LIMITS.
scsi_debug does not support any "tape-specific" commands. This includes READ BLOCK LIMITS, WRITE FILEMARKS, REWIND, etc. Additionally the CDB definition for tapes is special for reads and writes.
REWIND is implemented in scsi_debug, but it is buggy. MODE SENSE and MODE SELECT without any page (i.e., interested only in block descriptor) are not allowed in scsi_debug.
St is designed to work with minimal command support. READ BLOCK LIMITS is not needed. I have fixed REWIND and MODE SENSE/SELECT for my tests. Using fake_rw I can "read" tape, but writing does not work because WRITE FILEMARKS is missing.
...
Quoted 5 lines
Another problem with using
scsi_debugis:[tape_tests]#
sg_reset--target/dev/sg3This does nothing. I have to use the
/dev/stdevice to reset. This is not true if you have a real tape device.
In my tests, resets using both /dev/nstx and /dev/sgx have been working. However, you should note that when using /dev/nstx, the device is opened using st driver, whereas if /dev/sgx is used, it is opened using the sg driver. Digging deeper reveals that SG_SCSI_RESET through st does not go through sg at all. (Both end up to scsi_ioctl_reset() in scsi_error.c, but in a different way.) (And if you use, /dev/stx, the tape is rewound.)
Quoted 9 lines
[tape_tests]#
sg_reset--target/dev/nst1[Fri Nov 15 09:37:18 2024] st 8:0:0:0: [st1] check_tape: 1064: pos_unknown 0 was_reset 1 ready 0 [Fri Nov 15 09:37:18 2024] st 8:0:0:0: Power-on or device reset occurred [Fri Nov 15 09:37:18 2024] st 8:0:0:0: [st1] Error: 2, cmd: 0 0 0 0 0 0 [Fri Nov 15 09:37:18 2024] st 8:0:0:0: [st1] Sense Key : Unit Attention [current] [Fri Nov 15 09:37:18 2024] st 8:0:0:0: [st1] Add. Sense: Scsi bus reset occurred [Fri Nov 15 09:37:18 2024] st 8:0:0:0: [st1] st_chk_result: 421: pos_unknown 1 was_reset 1 ready 0, result 2^^^^^^^^^^^^^^^^^^
Now we've setpos_unkown.
If you use /dev/sgx, you are not supposed to see any output. The next operation sent to /dev/nstx (e.g., mt status) sets pos_unknown. In the example above, you probably have used sg_reset -target /dev/sg1 previously and it is opening /dev/nst1 the the next sg_reset that catches the previous reset.
...
Quoted 2 lines
Please try my latest version of the
tape_reset_debug.shscript.
I looked at the script. It tries to write to tape and that is not implemented in the scsi_debug I have
PATCH 3/3 scsi: st: clear pos_unknown when the por ua is expected
In reply to John MeneghiniFrom: Kai Makisara <[email protected]>
The change for commit 9604eea5bd3a ("scsi: st: Add third party poweron reset handling") was introduced to handle the problem where an unexpected power/on reset resulted in an undetected position lost condition which caused lost data as the driver flushed data and wrote a file mark at the beginning of the tape.
To solve this problem code was added which detected the unexpected a power on/reset Unit Attention in st_chk_results(). This correctly set pos_unknown in the driver and prevented further access to the device until the tape is re-positioned or rewound.
The problem with this solution is that it is catching POR Unit Attentions that are expected as well as those that are unexpected. This results in an unwanted EIO response to MTIOCGET.
The change for commit 3d882cca73be ("scsi: st: Fix input/output error on empty drive reset") attempts to fix this problem by returning success in flush_buffer() when ready != to ST_READY. However, once ST_READY is set, if pos_unknown remains uncleared, MTIOGET can still return EIO. This is confusing as some tape drives will set a POR UA when the system reboots or the driver is reloaded.
--- drivers/scsi/st.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-)
drivers/scsi/st.c +22 -9
@@ -3538,6 +3538,7 @@ static long st_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg)int i, cmd_nr, cmd_type, bt;int retval =0 ;unsigned int blk; +bool cmd_mtiocget;struct scsi_tape *STp = file->private_data;struct st_modedef *STm;struct st_partstat *STps;
@@ -3651,6 +3652,7 @@ static long st_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg)*/ if (mtc.mt_op != MTREW && mtc.mt_op != MTOFFL && + mtc.mt_op != MTLOAD && mtc.mt_op != MTRETEN && mtc.mt_op != MTERASE && mtc.mt_op != MTSEEK &&
@@ -3764,17 +3766,28 @@ static long st_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg) goto out; } + cmd_mtiocget = cmd_type ==_IOC_TYPE (MTIOCGET ) && cmd_nr ==_IOC_NR (MTIOCGET ); +if ((i =flush_buffer (STp,0 )) <0 ) { - retval = i; - goto out; - } -if (STp->can_partitions && - (i =switch_partition (STp)) <0 ) { - retval = i; - goto out; +/* flush fails -> modify status accordingly */ +if (cmd_mtiocget && STp->pos_unknown) { +reset_state (STp); + STp->pos_unknown =1 ; + }else {/* return error */ + retval = i; + goto out; + } + }else {/* flush_buffer succeeds */ +if (STp->can_partitions) { + i =switch_partition (STp); +if (i <0 ) { + retval = i; + goto out; + } + } } -if (cmd_type ==_IOC_TYPE (MTIOCGET ) && cmd_nr ==_IOC_NR (MTIOCGET )) { +if (cmd_mtiocget) {struct mtget mt_status;if (_IOC_SIZE (cmd_in) !=sizeof (struct mtget )) {
@@ -3788,7 +3801,7 @@ static long st_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg) ((STp->density <<MT_ST_DENSITY_SHIFT ) &MT_ST_DENSITY_MASK ); mt_status.mt_blkno = STps->drv_block; mt_status.mt_fileno = STps->drv_file; -if (STp->block_size !=0 ) { +if (STp->block_size !=0 && mt_status.mt_blkno >=0 ) {if (STps->rw ==ST_WRITING ) mt_status.mt_blkno += (STp->buffer)->buffer_bytes / STp->block_size;
Signature · 1 line
2.47.0
Re: [PATCH 3/3] scsi: st: clear pos_unknown when the por ua is expected
Quoted 3 lines · John Meneghini
From: Kai Makisara <[email protected]>
The patch in this message is a WIP patch discussed in Bugzilla. It is not meant to be submitted as such. (In addition to changes, it contains a bug fix not related to the changes.) Those interested in the progress can look at the Bugzilla entry shown below.
Quoted 3 lines
Fixes 3d882cca73be ("scsi: st: Fix input/output error on empty drive reset")Signed-off-by Kai Makisara <[email protected]>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I have NOT signed of this patch.
Quoted 1 line
Tested-by John Meneghini <[email protected]>
John has done extensive tests to see if the patch works.
Quoted 8 lines
---
drivers/scsi/st.c| 31 ++++++++++++++++++++++---------1 file changed, 22 insertions(+), 9 deletions(-)drivers/scsi/st.c +0
-0
...
Re: [PATCH 3/3] scsi: st: clear pos_unknown when the por ua is expected
Quoted 9 lines · Kai Mäkisara (Kolumbus)
Quoted 3 lines · John Meneghini
From: Kai Makisara <[email protected]>
The patch in this message is a WIP patch discussed in Bugzilla. It is not meant to be submitted as such. (In addition to changes, it contains a bug fix not related to the changes.) Those interested in the progress can look at the Bugzilla entry shown below.
Agreed.
Quoted 5 lines
Quoted 3 lines
Fixes 3d882cca73be ("scsi: st: Fix input/output error on empty drive reset")Signed-off-by Kai Makisara <[email protected]>^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^I have NOT signed of this patch.
Sorry, I added this because I wanted to publish the changes and checkpatch.pl was complaining that your name wasn't contained in the signed-off.
Quoted 3 lines
Quoted 1 line
Tested-by John Meneghini <[email protected]>John has done extensive tests to see if the patch works.
Yes, please see the bugzilla for more information.
/John