Skip to content

Commit d1b7f92

Browse files
Christoph Hellwigmartinkpetersen
authored andcommitted
scsi: sd: Call sd_revalidate_disk() for ioctl(BLKRRPART)
While the disk state has nothing to do with partitions, BLKRRPART is used to force a full revalidate after things like a disk format for historical reasons. Restore that behavior. Link: https://lore.kernel.org/r/[email protected] Fixes: 471bd0a ("sd: use bdev_check_media_change") Reported-by: Xiang Chen <[email protected]> Tested-by: Xiang Chen <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 7dd753c commit d1b7f92

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-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.

0 commit comments

Comments
 (0)