scsi: sg: Add warning message in source code about non-idempotent SG_IO
Subsystems (2)
PATCH 1/1 scsi: sg: Add warning message in source code about non-idempotent SG_IO
The SG_IO ioctl() is interruptible, and it is not obvious that using it to send arbitrary commands that are non-idempotent can resulted in failures or data corruption due to the syscall being reissued. Add a warning message in the source code of the function to inform potential users of this pitfall.
--- drivers/scsi/sg.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/scsi/sg.c +11 -0
@@ -924,6 +924,17 @@ sg_ioctl_common(struct file *filp, Sg_device *sdp, Sg_fd *sfp,switch (cmd_in) {case SG_IO : +/* +* WARNING: +* +* This ioctl() uses an interruptible wait for I/O completion. +* As a result, if it is interrupted by a signal (e.g. SIGSTOP) +* the result will be discarded and the syscall will be retried. +* Caution should be used with issuing commands that are not +* idempotent (e.g. COMPARE AND WRITE, or commands to a sequential +* media device such as a tape device) as this will likely not +* have the desired behavior. Data corruption could occur. +*/ if (atomic_read (&sdp->detaching))return -ENODEV ;if (!scsi_block_when_processing_errors (sdp->device))
Signature · 1 line
2.43.0
drivers/scsi/sg.c sg_ioctl_common(struct file *filp, Sg_device *sdp, Sg_fd *sfp, · line 934
Quoted 9 lines · Ewan D. Milne
drivers/scsi/sg.c +8
-0case SG_IO : +/* +* WARNING: +* +* This ioctl() uses an interruptible wait for I/O completion. +* As a result, if it is interrupted by a signal (e.g. SIGSTOP) +* the result will be discarded and the syscall will be retried. +* Caution should be used with issuing commands that are not +* idempotent (e.g. COMPARE AND WRITE, or commands to a sequential
overly long line.
But I don't think a comment in the source code is helpful for applications anyway.
Maybe we need a proper man page for this ioctl or some other kind of official user facing documentation?
A message that is not in the archive (sent off-list or not yet received): CAGtn9rk2TFYEdRh8q7LCZNiCcotU-f+xZLv=N_XbZtzcWgx+9Q@mail.gmail.com
Ewan,
Quoted 2 lines
Quoted 2 lines
Maybe we need a proper man page for this ioctl or some other kind of official user facing documentation?
A man page would be appreciated.
Signature · 1 line
Martin K. Petersen