block: Rename hd_struct.policy into hd_struct.read_only
diff mbox series

Message ID 20190628195615.201990-1-bvanassche@acm.org
State New
Headers show
Series
  • block: Rename hd_struct.policy into hd_struct.read_only
Related show

Commit Message

Bart Van Assche June 28, 2019, 7:56 p.m. UTC
Since nobody knows what "policy" means, rename the field to "read_only"
for clarity. Martin Petersen proposed this earlier - see also his patch
"scsi: sd: block: Fix regressions in read-only block device handling"
(https://www.spinics.net/lists/linux-scsi/msg129146.html). This patch
is an extension of a subset of Martin's patch.

The only change in this patch is if another value than 0 or 1 is passed
to set_device_ro() that that function converts that value into a
boolean. This change is not user visible because the BLKROGET ioctl
implementation converts the part->policy value into a boolean anyway.

The policy member was introduced by commit 4d466c1fcdce ("[PATCH] r/o
state moved to gendisks") # v2.6.12.

Cc: Martin K. Petersen <martin.petersen@oracle.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Ming Lei <ming.lei@redhat.com>
Cc: Hannes Reinecke <hare@suse.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 block/blk-core.c          |  2 +-
 block/genhd.c             | 18 +++++++++---------
 block/ioctl.c             |  2 +-
 block/partition-generic.c |  4 ++--
 include/linux/fs.h        |  2 +-
 include/linux/genhd.h     | 11 ++++++-----
 6 files changed, 20 insertions(+), 19 deletions(-)

Comments

Martin K. Petersen June 28, 2019, 8:09 p.m. UTC | #1
Bart,

> Since nobody knows what "policy" means, rename the field to "read_only"
> for clarity. Martin Petersen proposed this earlier - see also his patch
> "scsi: sd: block: Fix regressions in read-only block device handling"
> (https://www.spinics.net/lists/linux-scsi/msg129146.html). This patch
> is an extension of a subset of Martin's patch.

I'd rather we just get this one merged:

	https://patchwork.kernel.org/patch/10967367/

It even comes with a shiny blktest.
Bart Van Assche June 28, 2019, 8:26 p.m. UTC | #2
On 6/28/19 1:09 PM, Martin K. Petersen wrote:
> 
> Bart,
> 
>> Since nobody knows what "policy" means, rename the field to "read_only"
>> for clarity. Martin Petersen proposed this earlier - see also his patch
>> "scsi: sd: block: Fix regressions in read-only block device handling"
>> (https://www.spinics.net/lists/linux-scsi/msg129146.html). This patch
>> is an extension of a subset of Martin's patch.
> 
> I'd rather we just get this one merged:
> 
> 	https://patchwork.kernel.org/patch/10967367/
> 
> It even comes with a shiny blktest.

Ah, I had overlooked that patch.

Jens, please drop my patch.

Bart.

Patch
diff mbox series

diff --git a/block/blk-core.c b/block/blk-core.c
index 6361419f0b6e..cfa0687bf86c 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -802,7 +802,7 @@  static inline bool bio_check_ro(struct bio *bio, struct hd_struct *part)
 {
 	const int op = bio_op(bio);
 
-	if (part->policy && op_is_write(op)) {
+	if (part->read_only && op_is_write(op)) {
 		char b[BDEVNAME_SIZE];
 
 		if (op_is_flush(bio->bi_opf) && !bio_sectors(bio))
diff --git a/block/genhd.c b/block/genhd.c
index 97887e59f3b2..290deeb3bacf 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -1558,36 +1558,36 @@  static void set_disk_ro_uevent(struct gendisk *gd, int ro)
 	kobject_uevent_env(&disk_to_dev(gd)->kobj, KOBJ_CHANGE, envp);
 }
 
-void set_device_ro(struct block_device *bdev, int flag)
+void set_device_ro(struct block_device *bdev, bool read_only)
 {
-	bdev->bd_part->policy = flag;
+	bdev->bd_part->read_only = read_only;
 }
 
 EXPORT_SYMBOL(set_device_ro);
 
-void set_disk_ro(struct gendisk *disk, int flag)
+void set_disk_ro(struct gendisk *disk, bool read_only)
 {
 	struct disk_part_iter piter;
 	struct hd_struct *part;
 
-	if (disk->part0.policy != flag) {
-		set_disk_ro_uevent(disk, flag);
-		disk->part0.policy = flag;
+	if (disk->part0.read_only != read_only) {
+		set_disk_ro_uevent(disk, read_only);
+		disk->part0.read_only = read_only;
 	}
 
 	disk_part_iter_init(&piter, disk, DISK_PITER_INCL_EMPTY);
 	while ((part = disk_part_iter_next(&piter)))
-		part->policy = flag;
+		part->read_only = read_only;
 	disk_part_iter_exit(&piter);
 }
 
 EXPORT_SYMBOL(set_disk_ro);
 
-int bdev_read_only(struct block_device *bdev)
+bool bdev_read_only(struct block_device *bdev)
 {
 	if (!bdev)
 		return 0;
-	return bdev->bd_part->policy;
+	return bdev->bd_part->read_only;
 }
 
 EXPORT_SYMBOL(bdev_read_only);
diff --git a/block/ioctl.c b/block/ioctl.c
index 15a0eb80ada9..4871f58eaea2 100644
--- a/block/ioctl.c
+++ b/block/ioctl.c
@@ -545,7 +545,7 @@  int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
 			return -EINVAL;
 		return put_long(arg, (bdev->bd_bdi->ra_pages*PAGE_SIZE) / 512);
 	case BLKROGET:
-		return put_int(arg, bdev_read_only(bdev) != 0);
+		return put_int(arg, bdev_read_only(bdev));
 	case BLKBSZGET: /* get block device soft block size (cf. BLKSSZGET) */
 		return put_int(arg, block_size(bdev));
 	case BLKSSZGET: /* get block device logical block size */
diff --git a/block/partition-generic.c b/block/partition-generic.c
index aee643ce13d1..4ab79a66a5a6 100644
--- a/block/partition-generic.c
+++ b/block/partition-generic.c
@@ -98,7 +98,7 @@  static ssize_t part_ro_show(struct device *dev,
 			    struct device_attribute *attr, char *buf)
 {
 	struct hd_struct *p = dev_to_part(dev);
-	return sprintf(buf, "%d\n", p->policy ? 1 : 0);
+	return sprintf(buf, "%d\n", p->read_only);
 }
 
 static ssize_t part_alignment_offset_show(struct device *dev,
@@ -345,7 +345,7 @@  struct hd_struct *add_partition(struct gendisk *disk, int partno,
 		queue_limit_discard_alignment(&disk->queue->limits, start);
 	p->nr_sects = len;
 	p->partno = partno;
-	p->policy = get_disk_ro(disk);
+	p->read_only = get_disk_ro(disk);
 
 	if (info) {
 		struct partition_meta_info *pinfo = alloc_part_info(disk);
diff --git a/include/linux/fs.h b/include/linux/fs.h
index f7fdfe93e25d..bb679ab2bfe7 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -3034,7 +3034,7 @@  static inline void remove_inode_hash(struct inode *inode)
 extern void inode_sb_list_add(struct inode *inode);
 
 #ifdef CONFIG_BLOCK
-extern int bdev_read_only(struct block_device *);
+extern bool bdev_read_only(struct block_device *);
 #endif
 extern int set_blocksize(struct block_device *, int);
 extern int sb_set_blocksize(struct super_block *, int);
diff --git a/include/linux/genhd.h b/include/linux/genhd.h
index 8b5330dd5ac0..797043ff699b 100644
--- a/include/linux/genhd.h
+++ b/include/linux/genhd.h
@@ -118,7 +118,8 @@  struct hd_struct {
 	unsigned int discard_alignment;
 	struct device __dev;
 	struct kobject *holder_dir;
-	int policy, partno;
+	bool read_only;
+	int partno;
 	struct partition_meta_info *info;
 #ifdef CONFIG_FAIL_MAKE_REQUEST
 	int make_it_fail;
@@ -438,12 +439,12 @@  extern void del_gendisk(struct gendisk *gp);
 extern struct gendisk *get_gendisk(dev_t dev, int *partno);
 extern struct block_device *bdget_disk(struct gendisk *disk, int partno);
 
-extern void set_device_ro(struct block_device *bdev, int flag);
-extern void set_disk_ro(struct gendisk *disk, int flag);
+extern void set_device_ro(struct block_device *bdev, bool read_only);
+extern void set_disk_ro(struct gendisk *disk, bool read_only);
 
-static inline int get_disk_ro(struct gendisk *disk)
+static inline bool get_disk_ro(struct gendisk *disk)
 {
-	return disk->part0.policy;
+	return disk->part0.read_only;
 }
 
 extern void disk_block_events(struct gendisk *disk);