Bug 198689 - Setro has no effect for SCSI device
Summary: Setro has no effect for SCSI device
Status: RESOLVED CODE_FIX
Alias: None
Product: SCSI Drivers
Classification: Unclassified
Component: Other (show other bugs)
Hardware: All Linux
: P1 high
Assignee: scsi_drivers-aacraid
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-02-06 08:18 UTC by Li Ning
Modified: 2018-05-24 06:48 UTC (History)
2 users (show)

See Also:
Kernel Version: all
Subsystem:
Regression: No
Bisected commit-id:


Attachments

Description Li Ning 2018-02-06 08:18:00 UTC
Hi,
We found a problem when using SCSI device.

Setting the read-only attribute to scsi disk by calling "ioctl(fd, BLKROSET, &ro)"
only block the first write operation.

In detail:
1: set ioctl(fd, BLKROSET, &ro)
2: dd to the block device(as /dev/sdc), write failed
3: dd to the block device again, write successed

Above operation can be reproduced by following script:

#! /bin/bash
DEV=$1
[[ "$DEV" =~ ^/dev/sd ]] || echo "Need a scsi device to reproduce"
blockdev --setro $DEV
echo $DEV getro is [ $(blockdev --getro $DEV) ]
dd if=/dev/zero of=$DEV count=1
echo $DEV getro is [ $(blockdev --getro $1) ]
dd if=/dev/zero of=$DEV count=1

Environment:
  - Kernel: ALL
  We reproduced this problem in following kernel version: 4.15 4.10, 3.10.
  And by reference source, we think the problem exist in all versions.
  - Driver: SCSI
  it exists only when using SCSI disks, and xen-blk,virtio-blk do not have such a 
  problem

Here is a test result:
# uname -r
4.15.0+

# ./reproduce.sh /dev/sda
/dev/sda getro is [ 1 ]
dd: writing to ‘/dev/sda’: Operation not permitted
1+0 records in
0+0 records out
0 bytes (0 B) copied, 0.000258806 s, 0.0 kB/s
/dev/sda getro is [ 0 ]
1+0 records in
1+0 records out
512 bytes (512 B) copied, 0.000321595 s, 1.6 MB/s

---
Comment 1 John Pittman 2018-03-26 20:54:00 UTC
Issue fixed by:

20bd1d026aac ("scsi: sd: Keep disk read-only when re-reading partition")
https://marc.info/?l=linux-scsi&m=151991330722943&w=2

Note You need to log in before you can comment on or make changes to this bug.