block/swim: Minor fixes
v2 cover block/swim: Minor fixes
Two old bugs were reported to me by Stan Johnson while he was testing my recent patch series, "[PATCH v3] block/swim: Fixes and improvements". The following patches fix those bugs.
---
Changed since v1:
- Patch 2/2 was split into two such that each patch alters one driver.
- 2/3 and 3/3 were revised as described in the commit log entries.
- Tested-by tags were added.
---
Finn Thain (3):
swim: Return -EROFS when opened with BLK_OPEN_WRITE flag
swim: Fix FDEJECT ioctl for exclusive open
swim3: Fix FDEJECT ioctl for exclusive open
drivers/block/swim.c | 10 ++++++---- drivers/block/swim3.c | 8 +++----- 2 files changed, 9 insertions(+), 9 deletions(-)
PATCH v2 1/3 swim: Return -EROFS when opened with BLK_OPEN_WRITE flag
Write requests are not supported by the driver and produce IO errors as shown below. Avoid this by returning -EROFS when opened for writing.
[ 4111.690000] I/O error, dev fd0, sector 2 op 0x1:(WRITE) flags 0x800800 phys_seg 1 prio class 2 [ 4111.700000] Buffer I/O error on dev fd0, logical block 2, lost async page write
--- drivers/block/swim.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/block/swim.c +2 -1
@@ -639,7 +639,8 @@ static int floppy_open(struct gendisk *disk, blk_mode_t mode)if (mode & (BLK_OPEN_READ |BLK_OPEN_WRITE )) {if (disk_check_media_change (disk) && fs->disk_in) fs->ejected =0 ; -if ((mode &BLK_OPEN_WRITE ) && fs->write_protected) { +if (mode &BLK_OPEN_WRITE ) { +/* Write support isn't implemented. */ err = -EROFS ; goto out; }
PATCH v2 2/3 swim: Fix FDEJECT ioctl for exclusive open
In reply to Finn ThainThe eject command from the util-linux package does not work with the swim
driver: the drive doesn't eject anything and the command fails. Apparently, ioctl(fd, FDEJECT) returns -EBUSY when fd is opened O_EXCL. Fix this by checking ref_count for either 1 or -1. Either value means that the caller is the sole user of the disk.
---
Changed since v1:
- Access ref_count after mutex has been acquired.
--- drivers/block/swim.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/block/swim.c +4 -3
@@ -700,10 +700,11 @@ static int floppy_ioctl(struct block_device *bdev, blk_mode_t mode,switch (cmd) {case FDEJECT : -if (fs->ref_count !=1 ) -return -EBUSY ;mutex_lock (&swim_mutex); - err =floppy_eject (fs); +if (fs->ref_count ==-1 || fs->ref_count ==1 ) + err =floppy_eject (fs); +else + err = -EBUSY ;mutex_unlock (&swim_mutex);return err;
PATCH v2 3/3 swim3: Fix FDEJECT ioctl for exclusive open
In reply to Finn ThainThe eject command from the util-linux package does not work with the swim3 driver: the drive doesn't eject anything and the command fails. Apparently, ioctl(fd, FDEJECT) returns -EBUSY after fd was opened O_EXCL. Fix this by checking ref_count for either 1 or -1. Either value means that the caller is the sole user of the disk.
---
Changed since v1:
- Simplify by removing 'err' temporary variable.
--- drivers/block/swim3.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/block/swim3.c +3 -5
@@ -887,7 +887,6 @@ static int floppy_locked_ioctl(struct block_device *bdev, blk_mode_t mode, unsigned int cmd, unsigned long param) {struct floppy_state *fs = bdev->bd_disk->private_data; -int err;if ((cmd &0x80 ) && !capable (CAP_SYS_ADMIN ))return -EPERM ;
@@ -898,10 +897,9 @@ static int floppy_locked_ioctl(struct block_device *bdev, blk_mode_t mode,switch (cmd) {case FDEJECT : -if (fs->ref_count !=1 ) -return -EBUSY ; - err =fd_eject (fs); -return err; +if (fs->ref_count ==-1 || fs->ref_count ==1 ) +return fd_eject (fs); +return -EBUSY ;case FDGETPRM :if (copy_to_user ((void __user *) param, &floppy_type,sizeof (struct floppy_struct )))
Quoted 3 lines · Finn Thain
Two old bugs were reported to me by Stan Johnson while he was testing my recent patch series, "[PATCH v3] block/swim: Fixes and improvements". The following patches fix those bugs.
Applied, thanks!
[1/3] swim: Return -EROFS when opened with BLK_OPEN_WRITE flag
commit: d8fe777978a12a96cb5d10d6d888720fcba2da2b
[2/3] swim: Fix FDEJECT ioctl for exclusive open
commit: c76b93df9ae61d8ddebf6aa3bc218252f85e80c6
[3/3] swim3: Fix FDEJECT ioctl for exclusive open
commit: ce054fbe9a4bf4ffefef0f8e2504ea54da058ed2Best regards,
Signature · 1 line
Jens Axboe