Skip to content

Commit e2f527b

Browse files
committed
Merge tag 'scsi-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi
Pull SCSI fixes from James Bottomley: "Two small fixes, both in upper layer drivers (scsi disk and cdrom). The sd one is fixing a commit changing revalidation that came from the block tree a while ago (5.10) and the sr one adds handling of a condition we didn't previously handle for manually removed media" * tag 'scsi-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi: scsi: sd: Call sd_revalidate_disk() for ioctl(BLKRRPART) scsi: sr: Return appropriate error code when disk is ejected
2 parents 7ce32ac + d1b7f92 commit e2f527b

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

drivers/scsi/sd.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,6 +1387,22 @@ static void sd_uninit_command(struct scsi_cmnd *SCpnt)
13871387
}
13881388
}
13891389

1390+
static bool sd_need_revalidate(struct block_device *bdev,
1391+
struct scsi_disk *sdkp)
1392+
{
1393+
if (sdkp->device->removable || sdkp->write_prot) {
1394+
if (bdev_check_media_change(bdev))
1395+
return true;
1396+
}
1397+
1398+
/*
1399+
* Force a full rescan after ioctl(BLKRRPART). While the disk state has
1400+
* nothing to do with partitions, BLKRRPART is used to force a full
1401+
* revalidate after things like a format for historical reasons.
1402+
*/
1403+
return test_bit(GD_NEED_PART_SCAN, &bdev->bd_disk->state);
1404+
}
1405+
13901406
/**
13911407
* sd_open - open a scsi disk device
13921408
* @bdev: Block device of the scsi disk to open
@@ -1423,10 +1439,8 @@ static int sd_open(struct block_device *bdev, fmode_t mode)
14231439
if (!scsi_block_when_processing_errors(sdev))
14241440
goto error_out;
14251441

1426-
if (sdev->removable || sdkp->write_prot) {
1427-
if (bdev_check_media_change(bdev))
1428-
sd_revalidate_disk(bdev->bd_disk);
1429-
}
1442+
if (sd_need_revalidate(bdev, sdkp))
1443+
sd_revalidate_disk(bdev->bd_disk);
14301444

14311445
/*
14321446
* If the drive is empty, just let the open fail.

drivers/scsi/sr.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ static unsigned int sr_get_events(struct scsi_device *sdev)
220220
return DISK_EVENT_EJECT_REQUEST;
221221
else if (med->media_event_code == 2)
222222
return DISK_EVENT_MEDIA_CHANGE;
223+
else if (med->media_event_code == 3)
224+
return DISK_EVENT_EJECT_REQUEST;
223225
return 0;
224226
}
225227

0 commit comments

Comments
 (0)