[PATCH 1/4] block: add a hard-readonly flag to struct gendisk

Hannes Reinecke hare at suse.de
Mon Nov 30 02:55:54 EST 2020


On 11/29/20 7:19 PM, Christoph Hellwig wrote:
> Commit 20bd1d026aac ("scsi: sd: Keep disk read-only when re-reading
> partition") addressed a long-standing problem with user read-only
> policy being overridden as a result of a device-initiated revalidate.
> The commit has since been reverted due to a regression that left some
> USB devices read-only indefinitely.
> 
> To fix the underlying problems with revalidate we need to keep track
> of hardware state and user policy separately.
> 
> The gendisk has been updated to reflect the current hardware state set
> by the device driver. This is done to allow returning the device to
> the hardware state once the user clears the BLKROSET flag.
> 
> The resulting semantics are as follows:
> 
>   - If BLKROSET is used to set a whole-disk device read-only, any
>     partitions will end up in a read-only state until the user
>     explicitly clears the flag.
> 
>   - If BLKROSET sets a given partition read-only, that partition will
>     remain read-only even if the underlying storage stack initiates a
>     revalidate. However, the BLKRRPART ioctl will cause the partition
>     table to be dropped and any user policy on partitions will be lost.
> 
>   - If BLKROSET has not been set, both the whole disk device and any
>     partitions will reflect the current write-protect state of the
>     underlying device.
> 
> Based on a patch from Martin K. Petersen <martin.petersen at oracle.com>.
> 
> Reported-by: Oleksii Kurochko <olkuroch at cisco.com>
> Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=201221
> Signed-off-by: Christoph Hellwig <hch at lst.de>
> ---
>   block/blk-core.c        |  2 +-
>   block/genhd.c           | 34 +++++++++++++++++++---------------
>   block/partitions/core.c |  3 +--
>   include/linux/genhd.h   |  6 ++++--
>   4 files changed, 25 insertions(+), 20 deletions(-)
> 
Reviewed-by: Hannes Reinecke <hare at suse.de>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                Kernel Storage Architect
hare at suse.de                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer



More information about the Linux-nvme mailing list