Skip to content

Commit

Permalink
scsi: sd: Call sd_revalidate_disk() for ioctl(BLKRRPART)
Browse files Browse the repository at this point in the history
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/20210617115504.1732350-1-hch@lst.de
Fixes: 471bd0a ("sd: use bdev_check_media_change")
Reported-by: Xiang Chen <chenxiang66@hisilicon.com>
Tested-by: Xiang Chen <chenxiang66@hisilicon.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
  • Loading branch information
Christoph Hellwig authored and Martin K. Petersen committed Jun 23, 2021
1 parent 7dd753c commit d1b7f92
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions drivers/scsi/sd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1387,6 +1387,22 @@ static void sd_uninit_command(struct scsi_cmnd *SCpnt)
}
}

static bool sd_need_revalidate(struct block_device *bdev,
struct scsi_disk *sdkp)
{
if (sdkp->device->removable || sdkp->write_prot) {
if (bdev_check_media_change(bdev))
return true;
}

/*
* Force a full rescan after ioctl(BLKRRPART). While the disk state has
* nothing to do with partitions, BLKRRPART is used to force a full
* revalidate after things like a format for historical reasons.
*/
return test_bit(GD_NEED_PART_SCAN, &bdev->bd_disk->state);
}

/**
* sd_open - open a scsi disk device
* @bdev: Block device of the scsi disk to open
Expand Down Expand Up @@ -1423,10 +1439,8 @@ static int sd_open(struct block_device *bdev, fmode_t mode)
if (!scsi_block_when_processing_errors(sdev))
goto error_out;

if (sdev->removable || sdkp->write_prot) {
if (bdev_check_media_change(bdev))
sd_revalidate_disk(bdev->bd_disk);
}
if (sd_need_revalidate(bdev, sdkp))
sd_revalidate_disk(bdev->bd_disk);

/*
* If the drive is empty, just let the open fail.
Expand Down

0 comments on commit d1b7f92

Please sign in to comment.