Skip to contentSkip to conversation

Improve static type checking for request flags

PATCH Superseded Bart Van Assche 14 participants 93 messages Jun 23, 2022 – Jun 28, 2022

Subsystems (38)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
author reviewer
#1 lore raw

PATCH 1/51 treewide: Rename enum req_opf into enum req_op

In reply to Bart Van Assche

The type name enum req_opf is misleading since it suggests that values of this type include both an operation type and flags. Since values of this type represent an operation only, change the type name into enum req_op.

Convert the enum req_op documentation into kernel-doc format. Move a few definitions such that the enum req_op documentation occurs just above the enum req_op definition.

The name "req_opf" was introduced by commit ef295ecf090d ("block: better op and flags encoding").

Cc Christoph Hellwig <[email protected]>
Cc Ming Lei <[email protected]>
---
 block/blk-zoned.c                 |  7 +++----
 drivers/block/null_blk/main.c     |  9 ++++-----
 drivers/block/null_blk/null_blk.h | 12 +++++-------
 drivers/block/null_blk/trace.h    |  2 +-
 drivers/block/null_blk/zoned.c    |  4 ++--
 drivers/md/dm-integrity.c         |  2 +-
 drivers/nvme/target/zns.c         |  4 ++--
 drivers/scsi/sd_zbc.c             |  2 +-
 drivers/ufs/core/ufshpb.c         |  5 ++---
 fs/zonefs/super.c                 |  5 ++---
 fs/zonefs/trace.h                 |  2 +-
 include/linux/blk_types.h         | 16 ++++++++--------
 include/linux/blkdev.h            |  2 +-
 13 files changed, 33 insertions(+), 39 deletions(-)
block/blk-zoned.c +3 -4
index 38cd840d8838..ac0b9dfd2321 100644
@@ -257,9 +257,8 @@ static int blkdev_zone_reset_all(struct block_device *bdev, gfp_t gfp_mask)
  *    The operation to execute on each zone can be a zone reset, open, close
  *    or finish request.
  */
-int blkdev_zone_mgmt(struct block_device *bdev, enum req_opf op,
-		     sector_t sector, sector_t nr_sectors,
-		     gfp_t gfp_mask)
+int blkdev_zone_mgmt(struct block_device *bdev, enum req_op op,
+		     sector_t sector, sector_t nr_sectors, gfp_t gfp_mask)
 {
 	struct request_queue *q = bdev_get_queue(bdev);
 	sector_t zone_sectors = blk_queue_zone_sectors(q);
@@ -398,7 +397,7 @@ int blkdev_zone_mgmt_ioctl(struct block_device *bdev, fmode_t mode,
 	void __user *argp = (void __user *)arg;
 	struct request_queue *q;
 	struct blk_zone_range zrange;
-	enum req_opf op;
+	enum req_op op;
 	int ret;
 
 	if (!argp)
drivers/block/null_blk/main.c +4 -5
index 6b67088f4ea7..d5b0412830e0 100644
@@ -1310,7 +1310,7 @@ static inline blk_status_t null_handle_badblocks(struct nullb_cmd *cmd,
 }
 
 static inline blk_status_t null_handle_memory_backed(struct nullb_cmd *cmd,
-						     enum req_opf op,
+						     enum req_op op,
 						     sector_t sector,
 						     sector_t nr_sectors)
 {
@@ -1381,9 +1381,8 @@ static inline void nullb_complete_cmd(struct nullb_cmd *cmd)
 	}
 }
 
-blk_status_t null_process_cmd(struct nullb_cmd *cmd,
-			      enum req_opf op, sector_t sector,
-			      unsigned int nr_sectors)
+blk_status_t null_process_cmd(struct nullb_cmd *cmd, enum req_op op,
+			      sector_t sector, unsigned int nr_sectors)
 {
 	struct nullb_device *dev = cmd->nq->dev;
 	blk_status_t ret;
@@ -1401,7 +1400,7 @@ blk_status_t null_process_cmd(struct nullb_cmd *cmd,
 }
 
 static blk_status_t null_handle_cmd(struct nullb_cmd *cmd, sector_t sector,
-				    sector_t nr_sectors, enum req_opf op)
+				    sector_t nr_sectors, enum req_op op)
 {
 	struct nullb_device *dev = cmd->nq->dev;
 	struct nullb *nullb = dev->nullb;
drivers/block/null_blk/null_blk.h +5 -7
index 8359b43842f2..6fbf0a1b2622 100644
@@ -136,9 +136,8 @@ struct nullb {
 
 blk_status_t null_handle_discard(struct nullb_device *dev, sector_t sector,
 				 sector_t nr_sectors);
-blk_status_t null_process_cmd(struct nullb_cmd *cmd,
-			      enum req_opf op, sector_t sector,
-			      unsigned int nr_sectors);
+blk_status_t null_process_cmd(struct nullb_cmd *cmd, enum req_op op,
+			      sector_t sector, unsigned int nr_sectors);
 
 #ifdef CONFIG_BLK_DEV_ZONED
 int null_init_zoned_dev(struct nullb_device *dev, struct request_queue *q);
@@ -146,9 +145,8 @@ int null_register_zoned_dev(struct nullb *nullb);
 void null_free_zoned_dev(struct nullb_device *dev);
 int null_report_zones(struct gendisk *disk, sector_t sector,
 		      unsigned int nr_zones, report_zones_cb cb, void *data);
-blk_status_t null_process_zoned_cmd(struct nullb_cmd *cmd,
-				    enum req_opf op, sector_t sector,
-				    sector_t nr_sectors);
+blk_status_t null_process_zoned_cmd(struct nullb_cmd *cmd, enum req_op op,
+				    sector_t sector, sector_t nr_sectors);
 size_t null_zone_valid_read_len(struct nullb *nullb,
 				sector_t sector, unsigned int len);
 #else
@@ -164,7 +162,7 @@ static inline int null_register_zoned_dev(struct nullb *nullb)
 }
 static inline void null_free_zoned_dev(struct nullb_device *dev) {}
 static inline blk_status_t null_process_zoned_cmd(struct nullb_cmd *cmd,
-			enum req_opf op, sector_t sector, sector_t nr_sectors)
+			enum req_op op, sector_t sector, sector_t nr_sectors)
 {
 	return BLK_STS_NOTSUPP;
 }
drivers/block/null_blk/trace.h +1 -1
index 86d6c12c603c..6b2b370e786f 100644
@@ -36,7 +36,7 @@ TRACE_EVENT(nullb_zone_op,
 	    TP_ARGS(cmd, zone_no, zone_cond),
 	    TP_STRUCT__entry(
 		__array(char, disk, DISK_NAME_LEN)
-		__field(enum req_opf, op)
+		__field(enum req_op, op)
 		__field(unsigned int, zone_no)
 		__field(unsigned int, zone_cond)
 	    ),
drivers/block/null_blk/zoned.c +2 -2
index 2fdd7b20c224..99f45bb85080 100644
@@ -600,7 +600,7 @@ static blk_status_t null_reset_zone(struct nullb_device *dev,
 	return BLK_STS_OK;
 }
 
-static blk_status_t null_zone_mgmt(struct nullb_cmd *cmd, enum req_opf op,
+static blk_status_t null_zone_mgmt(struct nullb_cmd *cmd, enum req_op op,
 				   sector_t sector)
 {
 	struct nullb_device *dev = cmd->nq->dev;
@@ -653,7 +653,7 @@ static blk_status_t null_zone_mgmt(struct nullb_cmd *cmd, enum req_opf op,
 	return ret;
 }
 
-blk_status_t null_process_zoned_cmd(struct nullb_cmd *cmd, enum req_opf op,
+blk_status_t null_process_zoned_cmd(struct nullb_cmd *cmd, enum req_op op,
 				    sector_t sector, sector_t nr_sectors)
 {
 	struct nullb_device *dev;
drivers/md/dm-integrity.c +1 -1
index 3d5a0ce123c9..148978ad03a8 100644
@@ -298,7 +298,7 @@ struct dm_integrity_io {
 	struct work_struct work;
 
 	struct dm_integrity_c *ic;
-	enum req_opf op;
+	enum req_op op;
 	bool fua;
 
 	struct dm_integrity_range range;
drivers/nvme/target/zns.c +2 -2
index 82b61acf7a72..62afb7936132 100644
@@ -308,7 +308,7 @@ void nvmet_bdev_execute_zone_mgmt_recv(struct nvmet_req *req)
 	queue_work(zbd_wq, &req->z.zmgmt_work);
 }
 
-static inline enum req_opf zsa_req_op(u8 zsa)
+static inline enum req_op zsa_req_op(u8 zsa)
 {
 	switch (zsa) {
 	case NVME_ZONE_OPEN:
@@ -465,7 +465,7 @@ static void nvmet_bdev_zmgmt_send_work(struct work_struct *w)
 {
 	struct nvmet_req *req = container_of(w, struct nvmet_req, z.zmgmt_work);
 	sector_t sect = nvmet_lba_to_sect(req->ns, req->cmd->zms.slba);
-	enum req_opf op = zsa_req_op(req->cmd->zms.zsa);
+	enum req_op op = zsa_req_op(req->cmd->zms.zsa);
 	struct block_device *bdev = req->ns->bdev;
 	sector_t zone_sectors = bdev_zone_sectors(bdev);
 	u16 status = NVME_SC_SUCCESS;
drivers/scsi/sd_zbc.c +1 -1
index 6acc4f406eb8..6d3658e36c84 100644
@@ -529,7 +529,7 @@ static unsigned int sd_zbc_zone_wp_update(struct scsi_cmnd *cmd,
 	struct request *rq = scsi_cmd_to_rq(cmd);
 	struct scsi_disk *sdkp = scsi_disk(rq->q->disk);
 	unsigned int zno = blk_rq_zone_no(rq);
-	enum req_opf op = req_op(rq);
+	enum req_op op = req_op(rq);
 	unsigned long flags;
 
 	/*
drivers/ufs/core/ufshpb.c +2 -3
index de2bb8401bc4..24f1ee82c215 100644
@@ -433,9 +433,8 @@ int ufshpb_prep(struct ufs_hba *hba, struct ufshcd_lrb *lrbp)
 	return 0;
 }
 
-static struct ufshpb_req *ufshpb_get_req(struct ufshpb_lu *hpb,
-					 int rgn_idx, enum req_opf dir,
-					 bool atomic)
+static struct ufshpb_req *ufshpb_get_req(struct ufshpb_lu *hpb, int rgn_idx,
+					 enum req_op dir, bool atomic)
 {
 	struct ufshpb_req *rq;
 	struct request *req;
fs/zonefs/super.c +2 -3
index 053299758deb..59e77992443c 100644
@@ -60,8 +60,7 @@ static void zonefs_account_active(struct inode *inode)
 	}
 }
 
-static inline int zonefs_zone_mgmt(struct inode *inode,
-				   enum req_opf op)
+static inline int zonefs_zone_mgmt(struct inode *inode, enum req_op op)
 {
 	struct zonefs_inode_info *zi = ZONEFS_I(inode);
 	int ret;
@@ -525,7 +524,7 @@ static int zonefs_file_truncate(struct inode *inode, loff_t isize)
 {
 	struct zonefs_inode_info *zi = ZONEFS_I(inode);
 	loff_t old_isize;
-	enum req_opf op;
+	enum req_op op;
 	int ret = 0;
 
 	/*
fs/zonefs/trace.h +1 -1
index f369d7d50303..21501da764bd 100644
@@ -20,7 +20,7 @@
 #define show_dev(dev) MAJOR(dev), MINOR(dev)
 
 TRACE_EVENT(zonefs_zone_mgmt,
-	    TP_PROTO(struct inode *inode, enum req_opf op),
+	    TP_PROTO(struct inode *inode, enum req_op op),
 	    TP_ARGS(inode, op),
 	    TP_STRUCT__entry(
 			     __field(dev_t, dev)
include/linux/blk_types.h +8 -8
index a24d4078fb21..0e6a2af7ed3d 100644
@@ -337,8 +337,12 @@ enum {
 
 typedef __u32 __bitwise blk_mq_req_flags_t;
 
-/*
- * Operations and flags common to the bio and request structures.
+#define REQ_OP_BITS	8
+#define REQ_OP_MASK	((1 << REQ_OP_BITS) - 1)
+#define REQ_FLAG_BITS	24
+
+/**
+ * enum req_op - Operations common to the bio and request structures.
  * We use 8 bits for encoding the operation, and the remaining 24 for flags.
  *
  * The least significant bit of the operation number indicates the data
@@ -350,11 +354,7 @@ typedef __u32 __bitwise blk_mq_req_flags_t;
  * If a operation does not transfer data the least significant bit has no
  * meaning.
  */
-#define REQ_OP_BITS	8
-#define REQ_OP_MASK	((1 << REQ_OP_BITS) - 1)
-#define REQ_FLAG_BITS	24
-
-enum req_opf {
+enum req_op {
 	/* read sectors from the device */
 	REQ_OP_READ		= 0,
 	/* write sectors to the device */
@@ -509,7 +509,7 @@ static inline bool op_is_discard(unsigned int op)
  * due to its different handling in the block layer and device response in
  * case of command failure.
  */
-static inline bool op_is_zone_mgmt(enum req_opf op)
+static inline bool op_is_zone_mgmt(enum req_op op)
 {
 	switch (op & REQ_OP_MASK) {
 	case REQ_OP_ZONE_RESET:
include/linux/blkdev.h +1 -1
index 92b3bffad328..94ceed805e76 100644
@@ -292,7 +292,7 @@ void blk_queue_set_zoned(struct gendisk *disk, enum blk_zoned_model model);
 int blkdev_report_zones(struct block_device *bdev, sector_t sector,
 			unsigned int nr_zones, report_zones_cb cb, void *data);
 unsigned int blkdev_nr_zones(struct gendisk *disk);
-extern int blkdev_zone_mgmt(struct block_device *bdev, enum req_opf op,
+extern int blkdev_zone_mgmt(struct block_device *bdev, enum req_op op,
 			    sector_t sectors, sector_t nr_sectors,
 			    gfp_t gfp_mask);
 int blk_revalidate_disk_zones(struct gendisk *disk,

Bart Van Assche

author reviewer
#0 lore raw

cover Improve static type checking for request flags

Hi Jens,

A source of confusion in the block layer is that can be nontrivial to determine which type of flags a u32 function argument accepts. This patch series clears up that confusion for request flags by introducing a new __bitwise type, namely blk_opf_t. Additionally, the type 'int' is change into 'enum req_op' where used to hold a request operation.

Analysis of the sparse warnings introduced by this conversion resulted in one bug fix ("blktrace: Trace remap operations correctly").

Although the number of patches in this series is significant, the risk of this patch series is low since most patches involve changing one integer type (int or u32) into another integer type of the same size (enum req_op or blk_opf_t).

Please consider this patch series for kernel v5.20.

Thanks,

Bart.

Bart Van Assche (51):
treewide: Rename enum req_opf into enum req_op
block: Use enum req_op where appropriate
block: Change the type of the last .rw_page() argument
block: Change the type of req_op() and bio_op() into enum req_op
block: Introduce the type blk_opf_t
block: Use the new blk_opf_t type
blktrace: Use the new blk_opf_t type
blktrace: Trace remap operations correctly
block/brd: Use the enum req_op type
block/drbd: Use the enum req_op and blk_opf_t types block/floppy: Fix a sparse warning
block/null_blk: Fix sparse warnings in tracing code
um: Use enum req_op where appropriate
dm/core: Use the enum req_op and blk_opf_t types
dm/bufio: Change 'int rw' into 'enum req_op op'
dm/kcopyd: Rename kcopyd_job.rw into kcopyd_job.op
dm/ebs: Change 'int rw' into 'enum req_op op' dm/dm-flakey: Use the new blk_opf_t type
dm/dm-integrity: Use the enum req_op and blk_opf_t types dm/dm-snap: Use the enum req_op and blk_opf_t types dm/dm-zoned: Use the enum req_op type
md/core: Use the enum req_op and blk_opf_t types md/bcache: Use the enum req_op and blk_opf_t types md/raid1: Use the new blk_opf_t type
md/raid10: Use the new blk_opf_t type
md/raid5: Use the enum req_op and blk_opf_t types nvme/host: Use the enum req_op and blk_opf_t types nvme/target: Use the new blk_opf_t type
scsi/core: Improve static type checking
scsi/core: Change the return type of scsi_noretry_cmd() into bool scsi/core: Use the new blk_opf_t type scsi/device_handlers: Use the new blk_opf_t type
scsi/ufs: Rename a 'dir' argument into 'op'
scsi/target: Use the new blk_opf_t type
mm: Use the new blk_opf_t type
fs/buffer: Use the new blk_opf_t type
fs/direct-io: Use the enum req_op and blk_opf_t types fs/mpage: Use the new blk_opf_t type
fs/btrfs: Use the enum req_op and blk_opf_t types
fs/ext4: Use the new blk_opf_t type
fs/f2fs: Use the enum req_op and blk_opf_t types
fs/gfs2: Use the enum req_op and blk_opf_t types fs/hfsplus: Use the enum req_op and blk_opf_t types fs/iomap: Use the new blk_opf_t type
fs/jbd2: Fix the documentation of the jbd2_write_superblock() callers fs/nilfs: Use the enum req_op and blk_opf_t types fs/ntfs3: Use enum req_op where appropriate
fs/ocfs2: Use the enum req_op and blk_opf_t types
PM: Use the enum req_op and blk_opf_t types
fs/xfs: Use the enum req_op and blk_opf_t types
fs/zonefs: Fix sparse warnings in tracing code

 arch/um/drivers/ubd_kern.c                  |   4 +-
 block/bfq-cgroup.c                          |  16 +--
 block/bfq-iosched.c                         |   8 +-
 block/bfq-iosched.h                         |   8 +-
 block/bio.c                                 |  10 +-
 block/blk-cgroup-rwstat.h                   |   2 +-
 block/blk-core.c                            |   8 +-
 block/blk-flush.c                           |   6 +-
 block/blk-merge.c                           |   8 +-
 block/blk-mq-debugfs.c                      |   6 +-
 block/blk-mq.c                              |  13 ++-
 block/blk-mq.h                              |   6 +-
 block/blk-wbt.c                             |  18 +--
 block/blk-zoned.c                           |   7 +-
 block/blk.h                                 |   2 +-
 block/elevator.h                            |   2 +-
 block/fops.c                                |   8 +-
 block/kyber-iosched.c                       |   6 +-
 block/mq-deadline.c                         |   2 +-
 drivers/block/brd.c                         |   4 +-
 drivers/block/drbd/drbd_actlog.c            |   9 +-
 drivers/block/drbd/drbd_bitmap.c            |   3 +-
 drivers/block/drbd/drbd_int.h               |   6 +-
 drivers/block/drbd/drbd_receiver.c          |  11 +-
 drivers/block/floppy.c                      |   2 +-
 drivers/block/null_blk/main.c               |   9 +-
 drivers/block/null_blk/null_blk.h           |  12 +-
 drivers/block/null_blk/trace.h              |   6 +-
 drivers/block/null_blk/zoned.c              |   4 +-
 drivers/block/paride/pd.c                   |   2 +
 drivers/block/zram/zram_drv.c               |   2 +-
 drivers/md/bcache/super.c                   |   4 +-
 drivers/md/dm-bufio.c                       |  19 ++--
 drivers/md/dm-ebs-target.c                  |  15 +--
 drivers/md/dm-flakey.c                      |   8 +-
 drivers/md/dm-integrity.c                   |  14 ++-
 drivers/md/dm-io.c                          |  18 +--
 drivers/md/dm-kcopyd.c                      |  25 ++--
 drivers/md/dm-snap-persistent.c             |   6 +-
 drivers/md/dm-zoned-metadata.c              |   2 +-
 drivers/md/dm.c                             |   4 +-
 drivers/md/md.c                             |   3 +-
 drivers/md/md.h                             |   4 +-
 drivers/md/raid1.c                          |   2 +-
 drivers/md/raid10.c                         |   6 +-
 drivers/md/raid5.c                          |   5 +-
 drivers/nvdimm/btt.c                        |   2 +-
 drivers/nvdimm/pmem.c                       |   2 +-
 drivers/nvme/host/ioctl.c                   |   4 +-
 drivers/nvme/host/nvme.h                    |   2 +-
 drivers/nvme/target/io-cmd-bdev.c           |   3 +-
 drivers/nvme/target/zns.c                   |   6 +-
 drivers/scsi/device_handler/scsi_dh_alua.c  |   4 +-
 drivers/scsi/device_handler/scsi_dh_emc.c   |   2 +-
 drivers/scsi/device_handler/scsi_dh_hp_sw.c |   4 +-
 drivers/scsi/device_handler/scsi_dh_rdac.c  |   2 +-
 drivers/scsi/scsi_error.c                   |  16 +--
 drivers/scsi/scsi_lib.c                     |  10 +-
 drivers/scsi/scsi_priv.h                    |   2 +-
 drivers/scsi/sd_zbc.c                       |   2 +-
 drivers/target/target_core_iblock.c         |   4 +-
 drivers/ufs/core/ufshpb.c                   |   7 +-
 fs/btrfs/check-integrity.c                  |   4 +-
 fs/btrfs/compression.c                      |   6 +-
 fs/btrfs/compression.h                      |   2 +-
 fs/btrfs/extent_io.c                        |  18 +--
 fs/btrfs/inode.c                            |   4 +-
 fs/btrfs/raid56.c                           |   4 +-
 fs/buffer.c                                 |  21 ++--
 fs/direct-io.c                              |   4 +-
 fs/ext4/ext4.h                              |   8 +-
 fs/ext4/fast_commit.c                       |   2 +-
 fs/ext4/super.c                             |  14 +--
 fs/f2fs/data.c                              |  11 +-
 fs/f2fs/f2fs.h                              |   6 +-
 fs/f2fs/node.c                              |   2 +-
 fs/f2fs/segment.c                           |   2 +-
 fs/gfs2/log.c                               |   4 +-
 fs/gfs2/log.h                               |   2 +-
 fs/gfs2/lops.c                              |   4 +-
 fs/gfs2/lops.h                              |   2 +-
 fs/gfs2/meta_io.c                           |   6 +-
 fs/hfsplus/hfsplus_fs.h                     |   2 +-
 fs/hfsplus/wrapper.c                        |   5 +-
 fs/iomap/direct-io.c                        |   8 +-
 fs/jbd2/journal.c                           |  15 +--
 fs/mpage.c                                  |   2 +-
 fs/nilfs2/btnode.c                          |   4 +-
 fs/nilfs2/btnode.h                          |   5 +-
 fs/nilfs2/mdt.c                             |   3 +-
 fs/ntfs3/fsntfs.c                           |   2 +-
 fs/ntfs3/ntfs_fs.h                          |   2 +-
 fs/ocfs2/cluster/heartbeat.c                |   4 +-
 fs/xfs/xfs_bio_io.c                         |   2 +-
 fs/xfs/xfs_buf.c                            |   4 +-
 fs/xfs/xfs_linux.h                          |   2 +-
 fs/xfs/xfs_log_recover.c                    |   2 +-
 fs/zonefs/super.c                           |   5 +-
 fs/zonefs/trace.h                           |   8 +-
 include/linux/bio.h                         |  10 +-
 include/linux/blk-mq.h                      |  12 +-
 include/linux/blk_types.h                   | 119 +++++++++++---------
 include/linux/blkdev.h                      |  15 +--
 include/linux/blktrace_api.h                |   3 +-
 include/linux/buffer_head.h                 |   9 +-
 include/linux/dm-io.h                       |   5 +-
 include/linux/jbd2.h                        |   2 +-
 include/linux/writeback.h                   |   4 +-
 include/scsi/scsi_cmnd.h                    |   2 +-
 include/scsi/scsi_device.h                  |   2 +-
 include/trace/events/f2fs.h                 |  28 ++---
 include/trace/events/jbd2.h                 |  12 +-
 include/trace/events/nilfs2.h               |   4 +-
 kernel/power/swap.c                         |   4 +-
 kernel/trace/blktrace.c                     |  22 ++--
 115 files changed, 456 insertions(+), 415 deletions(-)
author reviewer
#2 lore raw

PATCH 2/51 block: Use enum req_op where appropriate

Change the type of the arguments that are used to pass a REQ_OP_* value from int or unsigned int into enum req_op to improve static type checking.

Note: the type of the blk_mq_alloc_request() 'op' argument is not modified by this patch since at least once caller passes an operation and flags in this argument.

Cc Christoph Hellwig <[email protected]>
Cc Ming Lei <[email protected]>
---
 block/blk-core.c          | 6 +++---
 block/blk-mq-debugfs.c    | 2 +-
 block/blk-mq.c            | 2 +-
 block/blk-wbt.c           | 2 +-
 block/blk.h               | 2 +-
 include/linux/blk-mq.h    | 2 +-
 include/linux/blk_types.h | 2 +-
 include/linux/blkdev.h    | 6 +++---
 8 files changed, 12 insertions(+), 12 deletions(-)
block/blk-core.c +3 -3
index eb86c756a7fd..9d420dff90f6 100644
@@ -136,7 +136,7 @@ static const char *const blk_op_name[] = {
  * string format. Useful in the debugging and tracing bio or request. For
  * invalid REQ_OP_XXX it returns string "UNKNOWN".
  */
-inline const char *blk_op_str(unsigned int op)
+inline const char *blk_op_str(enum req_op op)
 {
 	const char *op_str = "UNKNOWN";
 
@@ -1010,7 +1010,7 @@ void update_io_ticks(struct block_device *part, unsigned long now, bool end)
 }
 
 unsigned long bdev_start_io_acct(struct block_device *bdev,
-				 unsigned int sectors, unsigned int op,
+				 unsigned int sectors, enum req_op op,
 				 unsigned long start_time)
 {
 	const int sgrp = op_stat_group(op);
@@ -1051,7 +1051,7 @@ unsigned long bio_start_io_acct(struct bio *bio)
 }
 EXPORT_SYMBOL_GPL(bio_start_io_acct);
 
-void bdev_end_io_acct(struct block_device *bdev, unsigned int op,
+void bdev_end_io_acct(struct block_device *bdev, enum req_op op,
 		      unsigned long start_time)
 {
 	const int sgrp = op_stat_group(op);
block/blk-mq-debugfs.c +1 -1
index 7e4136a60e1c..df0b9a458f34 100644
@@ -306,7 +306,7 @@ static const char *blk_mq_rq_state_name(enum mq_rq_state rq_state)
 int __blk_mq_debugfs_rq_show(struct seq_file *m, struct request *rq)
 {
 	const struct blk_mq_ops *const mq_ops = rq->q->mq_ops;
-	const unsigned int op = req_op(rq);
+	const enum req_op op = req_op(rq);
 	const char *op_str = blk_op_str(op);
 
 	seq_printf(m, "%p {.op=", rq);
block/blk-mq.c +1 -1
index f5cce377f1a8..50fc1194ebc0 100644
@@ -538,7 +538,7 @@ struct request *blk_mq_alloc_request(struct request_queue *q, unsigned int op,
 EXPORT_SYMBOL(blk_mq_alloc_request);
 
 struct request *blk_mq_alloc_request_hctx(struct request_queue *q,
-	unsigned int op, blk_mq_req_flags_t flags, unsigned int hctx_idx)
+	enum req_op op, blk_mq_req_flags_t flags, unsigned int hctx_idx)
 {
 	struct blk_mq_alloc_data data = {
 		.q		= q,
block/blk-wbt.c +1 -1
index 0c119be0e813..7bf09ae06577 100644
@@ -670,7 +670,7 @@ u64 wbt_default_latency_nsec(struct request_queue *q)
 
 static int wbt_data_dir(const struct request *rq)
 {
-	const int op = req_op(rq);
+	const enum req_op op = req_op(rq);
 
 	if (op == REQ_OP_READ)
 		return READ;
block/blk.h +1 -1
index 8e79296ee97a..13b43fb28b9f 100644
@@ -160,7 +160,7 @@ static inline bool blk_discard_mergable(struct request *req)
 }
 
 static inline unsigned int blk_queue_get_max_sectors(struct request_queue *q,
-						     int op)
+						     enum req_op op)
 {
 	if (unlikely(op == REQ_OP_DISCARD || op == REQ_OP_SECURE_ERASE))
 		return min(q->limits.max_discard_sectors,
include/linux/blk-mq.h +1 -1
index e2d9daf7e8dd..45d69cc46dc7 100644
@@ -713,7 +713,7 @@ enum {
 struct request *blk_mq_alloc_request(struct request_queue *q, unsigned int op,
 		blk_mq_req_flags_t flags);
 struct request *blk_mq_alloc_request_hctx(struct request_queue *q,
-		unsigned int op, blk_mq_req_flags_t flags,
+		enum req_op op, blk_mq_req_flags_t flags,
 		unsigned int hctx_idx);
 
 /*
include/linux/blk_types.h +1 -1
index 0e6a2af7ed3d..cce8768bc00b 100644
@@ -522,7 +522,7 @@ static inline bool op_is_zone_mgmt(enum req_op op)
 	}
 }
 
-static inline int op_stat_group(unsigned int op)
+static inline int op_stat_group(enum req_op op)
 {
 	if (op_is_discard(op))
 		return STAT_DISCARD;
include/linux/blkdev.h +3 -3
index 94ceed805e76..3f8ee0608d60 100644
@@ -886,7 +886,7 @@ extern void blk_queue_exit(struct request_queue *q);
 extern void blk_sync_queue(struct request_queue *q);
 
 /* Helper to convert REQ_OP_XXX to its string format XXX */
-extern const char *blk_op_str(unsigned int op);
+extern const char *blk_op_str(enum req_op op);
 
 int blk_status_to_errno(blk_status_t status);
 blk_status_t errno_to_blk_status(int errno);
@@ -1472,9 +1472,9 @@ static inline void blk_wake_io_task(struct task_struct *waiter)
 }
 
 unsigned long bdev_start_io_acct(struct block_device *bdev,
-				 unsigned int sectors, unsigned int op,
+				 unsigned int sectors, enum req_op op,
 				 unsigned long start_time);
-void bdev_end_io_acct(struct block_device *bdev, unsigned int op,
+void bdev_end_io_acct(struct block_device *bdev, enum req_op op,
 		unsigned long start_time);
 
 void bio_start_io_acct_time(struct bio *bio, unsigned long start_time);
author reviewer
#3 lore raw

PATCH 3/51 block: Change the type of the last .rw_page() argument

In reply to Bart Van Assche

All .rw_page() callers pass an enum req_op value as last argument. Make this explicit by changing the type of the last argument into enum req_op. See also commit 3f289dcb4b26 ("block: make bdev_ops->rw_page() take a REQ_OP instead of bool").

Cc Tejun Heo <[email protected]>
Cc Minchan Kim <[email protected]>
Cc Dan Williams <[email protected]>
---
 drivers/block/brd.c           | 2 +-
 drivers/block/zram/zram_drv.c | 2 +-
 drivers/nvdimm/btt.c          | 2 +-
 drivers/nvdimm/pmem.c         | 2 +-
 include/linux/blkdev.h        | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)
drivers/block/brd.c +1 -1
index 6e3f2f0d2352..c3d772bdd89f 100644
@@ -310,7 +310,7 @@ static void brd_submit_bio(struct bio *bio)
 }
 
 static int brd_rw_page(struct block_device *bdev, sector_t sector,
-		       struct page *page, unsigned int op)
+		       struct page *page, enum req_op op)
 {
 	struct brd_device *brd = bdev->bd_disk->private_data;
 	int err;
drivers/block/zram/zram_drv.c +1 -1
index b8549c61ff2c..481b06a50ab1 100644
@@ -1631,7 +1631,7 @@ static void zram_slot_free_notify(struct block_device *bdev,
 }
 
 static int zram_rw_page(struct block_device *bdev, sector_t sector,
-		       struct page *page, unsigned int op)
+		       struct page *page, enum req_op op)
 {
 	int offset, ret;
 	u32 index;
drivers/nvdimm/btt.c +1 -1
index 9613e54c7a67..143b98e39c38 100644
@@ -1483,7 +1483,7 @@ static void btt_submit_bio(struct bio *bio)
 }
 
 static int btt_rw_page(struct block_device *bdev, sector_t sector,
-		struct page *page, unsigned int op)
+		struct page *page, enum req_op op)
 {
 	struct btt *btt = bdev->bd_disk->private_data;
 	int rc;
drivers/nvdimm/pmem.c +1 -1
index 629d10fcf53b..ed58cbe9550f 100644
@@ -239,7 +239,7 @@ static void pmem_submit_bio(struct bio *bio)
 }
 
 static int pmem_rw_page(struct block_device *bdev, sector_t sector,
-		       struct page *page, unsigned int op)
+		       struct page *page, enum req_op op)
 {
 	struct pmem_device *pmem = bdev->bd_disk->private_data;
 	blk_status_t rc;
include/linux/blkdev.h +1 -1
index 3f8ee0608d60..de47b0e0e18f 100644
@@ -1419,7 +1419,7 @@ struct block_device_operations {
 			unsigned int flags);
 	int (*open) (struct block_device *, fmode_t);
 	void (*release) (struct gendisk *, fmode_t);
-	int (*rw_page)(struct block_device *, sector_t, struct page *, unsigned int);
+	int (*rw_page)(struct block_device *, sector_t, struct page *, enum req_op);
 	int (*ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
 	int (*compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
 	unsigned int (*check_events) (struct gendisk *disk,
author reviewer
#4 lore raw

PATCH 4/51 block: Change the type of req_op() and bio_op() into enum req_op

In reply to Bart Van Assche

Improve static type checking by changing the type of the value returned by req_op() and bio_op() from unsigned int into enum req_op. Insert 'default: break;' in switch statements on the enum req_op type to prevent that the compiler warns about these switch statements.

Cc Christoph Hellwig <[email protected]>
Cc Ming Lei <[email protected]>
---
 block/blk-merge.c         | 2 ++
 drivers/block/paride/pd.c | 2 ++
 drivers/md/dm.c           | 2 ++
 include/linux/blk-mq.h    | 6 ++++--
 include/linux/blk_types.h | 6 ++++--
 5 files changed, 14 insertions(+), 4 deletions(-)
block/blk-merge.c +2 -0
index 0f5f42ebd0bb..9d96c9239219 100644
@@ -405,6 +405,8 @@ unsigned int blk_recalc_rq_segments(struct request *rq)
 		return 1;
 	case REQ_OP_WRITE_ZEROES:
 		return 0;
+	default:
+		break;
 	}
 
 	rq_for_each_bvec(bv, rq, iter)
drivers/block/paride/pd.c +2 -0
index 3637c38c72f9..a186f5bf235e 100644
@@ -501,6 +501,8 @@ static enum action do_pd_io_start(void)
 			return do_pd_read_start();
 		else
 			return do_pd_write_start();
+	default:
+		break;
 	}
 	return Fail;
 }
drivers/md/dm.c +2 -0
index 789f48e1a0e5..bed7ad573f79 100644
@@ -1539,6 +1539,8 @@ static blk_status_t __process_abnormal_io(struct clone_info *ci,
 	case REQ_OP_WRITE_ZEROES:
 		num_bios = ti->num_write_zeroes_bios;
 		break;
+	default:
+		break;
 	}
 
 	/*
include/linux/blk-mq.h +4 -2
index 45d69cc46dc7..9a1838bbed02 100644
@@ -197,8 +197,10 @@ struct request {
 	void *end_io_data;
 };
 
-#define req_op(req) \
-	((req)->cmd_flags & REQ_OP_MASK)
+static inline enum req_op req_op(const struct request *req)
+{
+	return req->cmd_flags & REQ_OP_MASK;
+}
 
 static inline bool blk_rq_is_passthrough(struct request *rq)
 {
include/linux/blk_types.h +4 -2
index cce8768bc00b..e66cbe377ae8 100644
@@ -463,8 +463,10 @@ enum stat_group {
 	NR_STAT_GROUPS
 };
 
-#define bio_op(bio) \
-	((bio)->bi_opf & REQ_OP_MASK)
+static inline enum req_op bio_op(const struct bio *bio)
+{
+	return bio->bi_opf & REQ_OP_MASK;
+}
 
 /* obsolete, don't use in new code */
 static inline void bio_set_op_attrs(struct bio *bio, unsigned op,
author reviewer
#5 lore raw

PATCH 5/51 block: Introduce the type blk_opf_t

In reply to Bart Van Assche

Introduce the type blk_opf_t for the request operation and flags (REQ_OP_* and REQ_*). This type will be used to improve documentation of the block layer code and also to allow sparse to verify whether request flags are used correctly.

Cc Christoph Hellwig <[email protected]>
Cc Ming Lei <[email protected]>
---
 include/linux/blk_types.h | 97 ++++++++++++++++++++-------------------
 1 file changed, 51 insertions(+), 46 deletions(-)
include/linux/blk_types.h +51 -46
index e66cbe377ae8..1ef99790f6ed 100644
@@ -240,6 +240,8 @@ static inline void bio_issue_init(struct bio_issue *issue,
 			((u64)size << BIO_ISSUE_SIZE_SHIFT));
 }
 
+typedef __u32 __bitwise blk_opf_t;
+
 typedef unsigned int blk_qc_t;
 #define BLK_QC_T_NONE		-1U
 
@@ -250,7 +252,7 @@ typedef unsigned int blk_qc_t;
 struct bio {
 	struct bio		*bi_next;	/* request queue link */
 	struct block_device	*bi_bdev;
-	unsigned int		bi_opf;		/* bottom bits REQ_OP, top bits
+	blk_opf_t		bi_opf;		/* bottom bits REQ_OP, top bits
 						 * req_flags.
 						 */
 	unsigned short		bi_flags;	/* BIO_* below */
@@ -338,7 +340,7 @@ enum {
 typedef __u32 __bitwise blk_mq_req_flags_t;
 
 #define REQ_OP_BITS	8
-#define REQ_OP_MASK	((1 << REQ_OP_BITS) - 1)
+#define REQ_OP_MASK	(__force blk_opf_t)((1 << REQ_OP_BITS) - 1)
 #define REQ_FLAG_BITS	24
 
 /**
@@ -356,35 +358,35 @@ typedef __u32 __bitwise blk_mq_req_flags_t;
  */
 enum req_op {
 	/* read sectors from the device */
-	REQ_OP_READ		= 0,
+	REQ_OP_READ		= (__force blk_opf_t)0,
 	/* write sectors to the device */
-	REQ_OP_WRITE		= 1,
+	REQ_OP_WRITE		= (__force blk_opf_t)1,
 	/* flush the volatile write cache */
-	REQ_OP_FLUSH		= 2,
+	REQ_OP_FLUSH		= (__force blk_opf_t)2,
 	/* discard sectors */
-	REQ_OP_DISCARD		= 3,
+	REQ_OP_DISCARD		= (__force blk_opf_t)3,
 	/* securely erase sectors */
-	REQ_OP_SECURE_ERASE	= 5,
+	REQ_OP_SECURE_ERASE	= (__force blk_opf_t)5,
 	/* write the zero filled sector many times */
-	REQ_OP_WRITE_ZEROES	= 9,
+	REQ_OP_WRITE_ZEROES	= (__force blk_opf_t)9,
 	/* Open a zone */
-	REQ_OP_ZONE_OPEN	= 10,
+	REQ_OP_ZONE_OPEN	= (__force blk_opf_t)10,
 	/* Close a zone */
-	REQ_OP_ZONE_CLOSE	= 11,
+	REQ_OP_ZONE_CLOSE	= (__force blk_opf_t)11,
 	/* Transition a zone to full */
-	REQ_OP_ZONE_FINISH	= 12,
+	REQ_OP_ZONE_FINISH	= (__force blk_opf_t)12,
 	/* write data at the current zone write pointer */
-	REQ_OP_ZONE_APPEND	= 13,
+	REQ_OP_ZONE_APPEND	= (__force blk_opf_t)13,
 	/* reset a zone write pointer */
-	REQ_OP_ZONE_RESET	= 15,
+	REQ_OP_ZONE_RESET	= (__force blk_opf_t)15,
 	/* reset all the zone present on the device */
-	REQ_OP_ZONE_RESET_ALL	= 17,
+	REQ_OP_ZONE_RESET_ALL	= (__force blk_opf_t)17,
 
 	/* Driver private requests */
-	REQ_OP_DRV_IN		= 34,
-	REQ_OP_DRV_OUT		= 35,
+	REQ_OP_DRV_IN		= (__force blk_opf_t)34,
+	REQ_OP_DRV_OUT		= (__force blk_opf_t)35,
 
-	REQ_OP_LAST,
+	REQ_OP_LAST		= (__force blk_opf_t)36,
 };
 
 enum req_flag_bits {
@@ -425,28 +427,31 @@ enum req_flag_bits {
 	__REQ_NR_BITS,		/* stops here */
 };
 
-#define REQ_FAILFAST_DEV	(1ULL << __REQ_FAILFAST_DEV)
-#define REQ_FAILFAST_TRANSPORT	(1ULL << __REQ_FAILFAST_TRANSPORT)
-#define REQ_FAILFAST_DRIVER	(1ULL << __REQ_FAILFAST_DRIVER)
-#define REQ_SYNC		(1ULL << __REQ_SYNC)
-#define REQ_META		(1ULL << __REQ_META)
-#define REQ_PRIO		(1ULL << __REQ_PRIO)
-#define REQ_NOMERGE		(1ULL << __REQ_NOMERGE)
-#define REQ_IDLE		(1ULL << __REQ_IDLE)
-#define REQ_INTEGRITY		(1ULL << __REQ_INTEGRITY)
-#define REQ_FUA			(1ULL << __REQ_FUA)
-#define REQ_PREFLUSH		(1ULL << __REQ_PREFLUSH)
-#define REQ_RAHEAD		(1ULL << __REQ_RAHEAD)
-#define REQ_BACKGROUND		(1ULL << __REQ_BACKGROUND)
-#define REQ_NOWAIT		(1ULL << __REQ_NOWAIT)
-#define REQ_CGROUP_PUNT		(1ULL << __REQ_CGROUP_PUNT)
-
-#define REQ_NOUNMAP		(1ULL << __REQ_NOUNMAP)
-#define REQ_POLLED		(1ULL << __REQ_POLLED)
-#define REQ_ALLOC_CACHE		(1ULL << __REQ_ALLOC_CACHE)
-
-#define REQ_DRV			(1ULL << __REQ_DRV)
-#define REQ_SWAP		(1ULL << __REQ_SWAP)
+#define REQ_FAILFAST_DEV	\
+			(__force blk_opf_t)(1ULL << __REQ_FAILFAST_DEV)
+#define REQ_FAILFAST_TRANSPORT	\
+			(__force blk_opf_t)(1ULL << __REQ_FAILFAST_TRANSPORT)
+#define REQ_FAILFAST_DRIVER	\
+			(__force blk_opf_t)(1ULL << __REQ_FAILFAST_DRIVER)
+#define REQ_SYNC	(__force blk_opf_t)(1ULL << __REQ_SYNC)
+#define REQ_META	(__force blk_opf_t)(1ULL << __REQ_META)
+#define REQ_PRIO	(__force blk_opf_t)(1ULL << __REQ_PRIO)
+#define REQ_NOMERGE	(__force blk_opf_t)(1ULL << __REQ_NOMERGE)
+#define REQ_IDLE	(__force blk_opf_t)(1ULL << __REQ_IDLE)
+#define REQ_INTEGRITY	(__force blk_opf_t)(1ULL << __REQ_INTEGRITY)
+#define REQ_FUA		(__force blk_opf_t)(1ULL << __REQ_FUA)
+#define REQ_PREFLUSH	(__force blk_opf_t)(1ULL << __REQ_PREFLUSH)
+#define REQ_RAHEAD	(__force blk_opf_t)(1ULL << __REQ_RAHEAD)
+#define REQ_BACKGROUND	(__force blk_opf_t)(1ULL << __REQ_BACKGROUND)
+#define REQ_NOWAIT	(__force blk_opf_t)(1ULL << __REQ_NOWAIT)
+#define REQ_CGROUP_PUNT	(__force blk_opf_t)(1ULL << __REQ_CGROUP_PUNT)
+
+#define REQ_NOUNMAP	(__force blk_opf_t)(1ULL << __REQ_NOUNMAP)
+#define REQ_POLLED	(__force blk_opf_t)(1ULL << __REQ_POLLED)
+#define REQ_ALLOC_CACHE	(__force blk_opf_t)(1ULL << __REQ_ALLOC_CACHE)
+
+#define REQ_DRV		(__force blk_opf_t)(1ULL << __REQ_DRV)
+#define REQ_SWAP	(__force blk_opf_t)(1ULL << __REQ_SWAP)
 
 #define REQ_FAILFAST_MASK \
 	(REQ_FAILFAST_DEV | REQ_FAILFAST_TRANSPORT | REQ_FAILFAST_DRIVER)
@@ -469,22 +474,22 @@ static inline enum req_op bio_op(const struct bio *bio)
 }
 
 /* obsolete, don't use in new code */
-static inline void bio_set_op_attrs(struct bio *bio, unsigned op,
-		unsigned op_flags)
+static inline void bio_set_op_attrs(struct bio *bio, enum req_op op,
+				    blk_opf_t op_flags)
 {
 	bio->bi_opf = op | op_flags;
 }
 
-static inline bool op_is_write(unsigned int op)
+static inline bool op_is_write(blk_opf_t op)
 {
-	return (op & 1);
+	return !!(op & (__force blk_opf_t)1);
 }
 
 /*
  * Check if the bio or request is one that needs special treatment in the
  * flush state machine.
  */
-static inline bool op_is_flush(unsigned int op)
+static inline bool op_is_flush(blk_opf_t op)
 {
 	return op & (REQ_FUA | REQ_PREFLUSH);
 }
@@ -494,13 +499,13 @@ static inline bool op_is_flush(unsigned int op)
  * PREFLUSH flag.  Other operations may be marked as synchronous using the
  * REQ_SYNC flag.
  */
-static inline bool op_is_sync(unsigned int op)
+static inline bool op_is_sync(blk_opf_t op)
 {
 	return (op & REQ_OP_MASK) == REQ_OP_READ ||
 		(op & (REQ_SYNC | REQ_FUA | REQ_PREFLUSH));
 }
 
-static inline bool op_is_discard(unsigned int op)
+static inline bool op_is_discard(blk_opf_t op)
 {
 	return (op & REQ_OP_MASK) == REQ_OP_DISCARD;
 }
author reviewer
#6 lore raw

PATCH 6/51 block: Use the new blk_opf_t type

In reply to Bart Van Assche

Use the new blk_opf_t type for arguments and variables that represent request flags or a bitwise combination of a request operation and request flags. Rename the function arguments and also a structure member that hold a request operation and flags from 'rw' into 'opf'.

This patch does not change any functionality.

Cc Christoph Hellwig <[email protected]>
Cc Ming Lei <[email protected]>
---
 block/bfq-cgroup.c        | 16 ++++++++--------
 block/bfq-iosched.c       |  8 ++++----
 block/bfq-iosched.h       |  8 ++++----
 block/bio.c               | 10 +++++-----
 block/blk-cgroup-rwstat.h |  2 +-
 block/blk-core.c          |  2 +-
 block/blk-flush.c         |  6 +++---
 block/blk-merge.c         |  6 +++---
 block/blk-mq-debugfs.c    |  4 ++--
 block/blk-mq.c            | 11 ++++++-----
 block/blk-mq.h            |  6 +++---
 block/blk-wbt.c           | 16 ++++++++--------
 block/elevator.h          |  2 +-
 block/fops.c              |  8 ++++----
 block/kyber-iosched.c     |  6 +++---
 block/mq-deadline.c       |  2 +-
 include/linux/bio.h       | 10 +++++-----
 include/linux/blk-mq.h    |  4 ++--
 include/linux/blkdev.h    |  5 +++--
 19 files changed, 67 insertions(+), 65 deletions(-)
block/bfq-cgroup.c +8 -8
index 9fc605791b1e..af79028627a5 100644
@@ -220,7 +220,7 @@ void bfqg_stats_update_avg_queue_size(struct bfq_group *bfqg)
 }
 
 void bfqg_stats_update_io_add(struct bfq_group *bfqg, struct bfq_queue *bfqq,
-			      unsigned int op)
+			      blk_opf_t op)
 {
 	blkg_rwstat_add(&bfqg->stats.queued, op, 1);
 	bfqg_stats_end_empty_time(&bfqg->stats);
@@ -228,18 +228,18 @@ void bfqg_stats_update_io_add(struct bfq_group *bfqg, struct bfq_queue *bfqq,
 		bfqg_stats_set_start_group_wait_time(bfqg, bfqq_group(bfqq));
 }
 
-void bfqg_stats_update_io_remove(struct bfq_group *bfqg, unsigned int op)
+void bfqg_stats_update_io_remove(struct bfq_group *bfqg, blk_opf_t op)
 {
 	blkg_rwstat_add(&bfqg->stats.queued, op, -1);
 }
 
-void bfqg_stats_update_io_merged(struct bfq_group *bfqg, unsigned int op)
+void bfqg_stats_update_io_merged(struct bfq_group *bfqg, blk_opf_t op)
 {
 	blkg_rwstat_add(&bfqg->stats.merged, op, 1);
 }
 
 void bfqg_stats_update_completion(struct bfq_group *bfqg, u64 start_time_ns,
-				  u64 io_start_time_ns, unsigned int op)
+				  u64 io_start_time_ns, blk_opf_t op)
 {
 	struct bfqg_stats *stats = &bfqg->stats;
 	u64 now = ktime_get_ns();
@@ -255,11 +255,11 @@ void bfqg_stats_update_completion(struct bfq_group *bfqg, u64 start_time_ns,
 #else /* CONFIG_BFQ_CGROUP_DEBUG */
 
 void bfqg_stats_update_io_add(struct bfq_group *bfqg, struct bfq_queue *bfqq,
-			      unsigned int op) { }
-void bfqg_stats_update_io_remove(struct bfq_group *bfqg, unsigned int op) { }
-void bfqg_stats_update_io_merged(struct bfq_group *bfqg, unsigned int op) { }
+			      blk_opf_t op) { }
+void bfqg_stats_update_io_remove(struct bfq_group *bfqg, blk_opf_t op) { }
+void bfqg_stats_update_io_merged(struct bfq_group *bfqg, blk_opf_t op) { }
 void bfqg_stats_update_completion(struct bfq_group *bfqg, u64 start_time_ns,
-				  u64 io_start_time_ns, unsigned int op) { }
+				  u64 io_start_time_ns, blk_opf_t op) { }
 void bfqg_stats_update_dequeue(struct bfq_group *bfqg) { }
 void bfqg_stats_set_start_empty_time(struct bfq_group *bfqg) { }
 void bfqg_stats_update_idle_time(struct bfq_group *bfqg) { }
block/bfq-iosched.c +4 -4
index e6d7e6b01a05..a724fc882158 100644
@@ -668,7 +668,7 @@ static bool bfqq_request_over_limit(struct bfq_queue *bfqq, int limit)
  * significantly affect service guarantees coming from the BFQ scheduling
  * algorithm.
  */
-static void bfq_limit_depth(unsigned int op, struct blk_mq_alloc_data *data)
+static void bfq_limit_depth(blk_opf_t op, struct blk_mq_alloc_data *data)
 {
 	struct bfq_data *bfqd = data->q->elevator->elevator_data;
 	struct bfq_io_cq *bic = bfq_bic_lookup(data->q);
@@ -6104,7 +6104,7 @@ static bool __bfq_insert_request(struct bfq_data *bfqd, struct request *rq)
 static void bfq_update_insert_stats(struct request_queue *q,
 				    struct bfq_queue *bfqq,
 				    bool idle_timer_disabled,
-				    unsigned int cmd_flags)
+				    blk_opf_t cmd_flags)
 {
 	if (!bfqq)
 		return;
@@ -6129,7 +6129,7 @@ static void bfq_update_insert_stats(struct request_queue *q,
 static inline void bfq_update_insert_stats(struct request_queue *q,
 					   struct bfq_queue *bfqq,
 					   bool idle_timer_disabled,
-					   unsigned int cmd_flags) {}
+					   blk_opf_t cmd_flags) {}
 #endif /* CONFIG_BFQ_CGROUP_DEBUG */
 
 static struct bfq_queue *bfq_init_rq(struct request *rq);
@@ -6141,7 +6141,7 @@ static void bfq_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq,
 	struct bfq_data *bfqd = q->elevator->elevator_data;
 	struct bfq_queue *bfqq;
 	bool idle_timer_disabled = false;
-	unsigned int cmd_flags;
+	blk_opf_t cmd_flags;
 	LIST_HEAD(free);
 
 #ifdef CONFIG_BFQ_GROUP_IOSCHED
block/bfq-iosched.h +4 -4
index ca8177d7bf7c..6bde1f4ecc50 100644
@@ -994,11 +994,11 @@ void bfq_put_async_queues(struct bfq_data *bfqd, struct bfq_group *bfqg);
 
 void bfqg_stats_update_legacy_io(struct request_queue *q, struct request *rq);
 void bfqg_stats_update_io_add(struct bfq_group *bfqg, struct bfq_queue *bfqq,
-			      unsigned int op);
-void bfqg_stats_update_io_remove(struct bfq_group *bfqg, unsigned int op);
-void bfqg_stats_update_io_merged(struct bfq_group *bfqg, unsigned int op);
+			      blk_opf_t op);
+void bfqg_stats_update_io_remove(struct bfq_group *bfqg, blk_opf_t op);
+void bfqg_stats_update_io_merged(struct bfq_group *bfqg, blk_opf_t op);
 void bfqg_stats_update_completion(struct bfq_group *bfqg, u64 start_time_ns,
-				  u64 io_start_time_ns, unsigned int op);
+				  u64 io_start_time_ns, blk_opf_t op);
 void bfqg_stats_update_dequeue(struct bfq_group *bfqg);
 void bfqg_stats_set_start_empty_time(struct bfq_group *bfqg);
 void bfqg_stats_update_idle_time(struct bfq_group *bfqg);
block/bio.c +5 -5
index 933ea3210954..8978f7d3ae48 100644
@@ -239,7 +239,7 @@ static void bio_free(struct bio *bio)
  * when IO has completed, or when the bio is released.
  */
 void bio_init(struct bio *bio, struct block_device *bdev, struct bio_vec *table,
-	      unsigned short max_vecs, unsigned int opf)
+	      unsigned short max_vecs, blk_opf_t opf)
 {
 	bio->bi_next = NULL;
 	bio->bi_bdev = bdev;
@@ -292,7 +292,7 @@ EXPORT_SYMBOL(bio_init);
  *   preserved are the ones that are initialized by bio_alloc_bioset(). See
  *   comment in struct bio.
  */
-void bio_reset(struct bio *bio, struct block_device *bdev, unsigned int opf)
+void bio_reset(struct bio *bio, struct block_device *bdev, blk_opf_t opf)
 {
 	bio_uninit(bio);
 	memset(bio, 0, BIO_RESET_BYTES);
@@ -341,7 +341,7 @@ void bio_chain(struct bio *bio, struct bio *parent)
 EXPORT_SYMBOL(bio_chain);
 
 struct bio *blk_next_bio(struct bio *bio, struct block_device *bdev,
-		unsigned int nr_pages, unsigned int opf, gfp_t gfp)
+		unsigned int nr_pages, blk_opf_t opf, gfp_t gfp)
 {
 	struct bio *new = bio_alloc(bdev, nr_pages, opf, gfp);
 
@@ -409,7 +409,7 @@ static void punt_bios_to_rescuer(struct bio_set *bs)
 }
 
 static struct bio *bio_alloc_percpu_cache(struct block_device *bdev,
-		unsigned short nr_vecs, unsigned int opf, gfp_t gfp,
+		unsigned short nr_vecs, blk_opf_t opf, gfp_t gfp,
 		struct bio_set *bs)
 {
 	struct bio_alloc_cache *cache;
@@ -468,7 +468,7 @@ static struct bio *bio_alloc_percpu_cache(struct block_device *bdev,
  * Returns: Pointer to new bio on success, NULL on failure.
  */
 struct bio *bio_alloc_bioset(struct block_device *bdev, unsigned short nr_vecs,
-			     unsigned int opf, gfp_t gfp_mask,
+			     blk_opf_t opf, gfp_t gfp_mask,
 			     struct bio_set *bs)
 {
 	gfp_t saved_gfp = gfp_mask;
block/blk-cgroup-rwstat.h +1 -1
index 9f2723b34b75..6c0237148c0d 100644
@@ -59,7 +59,7 @@ void blkg_rwstat_recursive_sum(struct blkcg_gq *blkg, struct blkcg_policy *pol,
  * caller is responsible for synchronizing calls to this function.
  */
 static inline void blkg_rwstat_add(struct blkg_rwstat *rwstat,
-				   unsigned int op, uint64_t val)
+				   blk_opf_t op, uint64_t val)
 {
 	struct percpu_counter *cnt;
 
block/blk-core.c +1 -1
index 9d420dff90f6..ef082aa7b8fb 100644
@@ -1260,7 +1260,7 @@ EXPORT_SYMBOL_GPL(blk_io_schedule);
 
 int __init blk_dev_init(void)
 {
-	BUILD_BUG_ON(REQ_OP_LAST >= (1 << REQ_OP_BITS));
+	BUILD_BUG_ON((__force u32)REQ_OP_LAST >= (1 << REQ_OP_BITS));
 	BUILD_BUG_ON(REQ_OP_BITS + REQ_FLAG_BITS > 8 *
 			sizeof_field(struct request, cmd_flags));
 	BUILD_BUG_ON(REQ_OP_BITS + REQ_FLAG_BITS > 8 *
block/blk-flush.c +3 -3
index c68968724870..d20a0c6b2c66 100644
@@ -94,7 +94,7 @@ enum {
 };
 
 static void blk_kick_flush(struct request_queue *q,
-			   struct blk_flush_queue *fq, unsigned int flags);
+			   struct blk_flush_queue *fq, blk_opf_t flags);
 
 static inline struct blk_flush_queue *
 blk_get_flush_queue(struct request_queue *q, struct blk_mq_ctx *ctx)
@@ -173,7 +173,7 @@ static void blk_flush_complete_seq(struct request *rq,
 {
 	struct request_queue *q = rq->q;
 	struct list_head *pending = &fq->flush_queue[fq->flush_pending_idx];
-	unsigned int cmd_flags;
+	blk_opf_t cmd_flags;
 
 	BUG_ON(rq->flush.seq & seq);
 	rq->flush.seq |= seq;
@@ -290,7 +290,7 @@ bool is_flush_rq(struct request *rq)
  *
  */
 static void blk_kick_flush(struct request_queue *q, struct blk_flush_queue *fq,
-			   unsigned int flags)
+			   blk_opf_t flags)
 {
 	struct list_head *pending = &fq->flush_queue[fq->flush_pending_idx];
 	struct request *first_rq =
block/blk-merge.c +3 -3
index 9d96c9239219..3a928ebb6b5e 100644
@@ -712,7 +712,7 @@ static int ll_merge_requests_fn(struct request_queue *q, struct request *req,
  */
 void blk_rq_set_mixed_merge(struct request *rq)
 {
-	unsigned int ff = rq->cmd_flags & REQ_FAILFAST_MASK;
+	blk_opf_t ff = rq->cmd_flags & REQ_FAILFAST_MASK;
 	struct bio *bio;
 
 	if (rq->rq_flags & RQF_MIXED_MERGE)
@@ -928,7 +928,7 @@ enum bio_merge_status {
 static enum bio_merge_status bio_attempt_back_merge(struct request *req,
 		struct bio *bio, unsigned int nr_segs)
 {
-	const int ff = bio->bi_opf & REQ_FAILFAST_MASK;
+	const blk_opf_t ff = bio->bi_opf & REQ_FAILFAST_MASK;
 
 	if (!ll_back_merge_fn(req, bio, nr_segs))
 		return BIO_MERGE_FAILED;
@@ -952,7 +952,7 @@ static enum bio_merge_status bio_attempt_back_merge(struct request *req,
 static enum bio_merge_status bio_attempt_front_merge(struct request *req,
 		struct bio *bio, unsigned int nr_segs)
 {
-	const int ff = bio->bi_opf & REQ_FAILFAST_MASK;
+	const blk_opf_t ff = bio->bi_opf & REQ_FAILFAST_MASK;
 
 	if (!ll_front_merge_fn(req, bio, nr_segs))
 		return BIO_MERGE_FAILED;
block/blk-mq-debugfs.c +2 -2
index df0b9a458f34..e30ef69dfa39 100644
@@ -315,8 +315,8 @@ int __blk_mq_debugfs_rq_show(struct seq_file *m, struct request *rq)
 	else
 		seq_printf(m, "%s", op_str);
 	seq_puts(m, ", .cmd_flags=");
-	blk_flags_show(m, rq->cmd_flags & ~REQ_OP_MASK, cmd_flag_name,
-		       ARRAY_SIZE(cmd_flag_name));
+	blk_flags_show(m, (__force unsigned int)(rq->cmd_flags & ~REQ_OP_MASK),
+		       cmd_flag_name, ARRAY_SIZE(cmd_flag_name));
 	seq_puts(m, ", .rq_flags=");
 	blk_flags_show(m, (__force unsigned int)rq->rq_flags, rqf_name,
 		       ARRAY_SIZE(rqf_name));
block/blk-mq.c +6 -5
index 50fc1194ebc0..24548dc536cc 100644
@@ -508,13 +508,13 @@ static struct request *__blk_mq_alloc_requests(struct blk_mq_alloc_data *data)
 					alloc_time_ns);
 }
 
-struct request *blk_mq_alloc_request(struct request_queue *q, unsigned int op,
+struct request *blk_mq_alloc_request(struct request_queue *q, blk_opf_t opf,
 		blk_mq_req_flags_t flags)
 {
 	struct blk_mq_alloc_data data = {
 		.q		= q,
 		.flags		= flags,
-		.cmd_flags	= op,
+		.cmd_flags	= opf,
 		.nr_tags	= 1,
 	};
 	struct request *rq;
@@ -655,7 +655,7 @@ void blk_dump_rq_flags(struct request *rq, char *msg)
 {
 	printk(KERN_INFO "%s: dev %s: flags=%llx\n", msg,
 		rq->q->disk ? rq->q->disk->disk_name : "?",
-		(unsigned long long) rq->cmd_flags);
+		(__force unsigned long long) rq->cmd_flags);
 
 	printk(KERN_INFO "  sector %llu, nr/cnr %u/%u\n",
 	       (unsigned long long)blk_rq_pos(rq),
@@ -708,8 +708,9 @@ static void blk_print_req_error(struct request *req, blk_status_t status)
 		"phys_seg %u prio class %u\n",
 		blk_status_to_str(status),
 		req->q->disk ? req->q->disk->disk_name : "?",
-		blk_rq_pos(req), req_op(req), blk_op_str(req_op(req)),
-		req->cmd_flags & ~REQ_OP_MASK,
+		blk_rq_pos(req), (__force u32)req_op(req),
+		blk_op_str(req_op(req)),
+		(__force u32)(req->cmd_flags & ~REQ_OP_MASK),
 		req->nr_phys_segments,
 		IOPRIO_PRIO_CLASS(req->ioprio));
 }
block/blk-mq.h +3 -3
index e4c6fe2c8ac8..51fc5d6606e4 100644
@@ -86,7 +86,7 @@ static inline struct blk_mq_hw_ctx *blk_mq_map_queue_type(struct request_queue *
 	return xa_load(&q->hctx_table, q->tag_set->map[type].mq_map[cpu]);
 }
 
-static inline enum hctx_type blk_mq_get_hctx_type(unsigned int opf)
+static inline enum hctx_type blk_mq_get_hctx_type(blk_opf_t opf)
 {
 	enum hctx_type type = HCTX_TYPE_DEFAULT;
 
@@ -107,7 +107,7 @@ static inline enum hctx_type blk_mq_get_hctx_type(unsigned int opf)
  * @ctx: software queue cpu ctx
  */
 static inline struct blk_mq_hw_ctx *blk_mq_map_queue(struct request_queue *q,
-						     unsigned int opf,
+						     blk_opf_t opf,
 						     struct blk_mq_ctx *ctx)
 {
 	return ctx->hctxs[blk_mq_get_hctx_type(opf)];
@@ -151,7 +151,7 @@ struct blk_mq_alloc_data {
 	struct request_queue *q;
 	blk_mq_req_flags_t flags;
 	unsigned int shallow_depth;
-	unsigned int cmd_flags;
+	blk_opf_t cmd_flags;
 	req_flags_t rq_flags;
 
 	/* allocate multiple requests/tags in one go */
block/blk-wbt.c +8 -8
index 7bf09ae06577..f2e4bf1dca47 100644
@@ -451,7 +451,7 @@ static bool close_io(struct rq_wb *rwb)
 
 #define REQ_HIPRIO	(REQ_SYNC | REQ_META | REQ_PRIO)
 
-static inline unsigned int get_limit(struct rq_wb *rwb, unsigned long rw)
+static inline unsigned int get_limit(struct rq_wb *rwb, blk_opf_t opf)
 {
 	unsigned int limit;
 
@@ -462,7 +462,7 @@ static inline unsigned int get_limit(struct rq_wb *rwb, unsigned long rw)
 	if (!rwb_enabled(rwb))
 		return UINT_MAX;
 
-	if ((rw & REQ_OP_MASK) == REQ_OP_DISCARD)
+	if ((opf & REQ_OP_MASK) == REQ_OP_DISCARD)
 		return rwb->wb_background;
 
 	/*
@@ -473,9 +473,9 @@ static inline unsigned int get_limit(struct rq_wb *rwb, unsigned long rw)
 	 * the idle limit, or go to normal if we haven't had competing
 	 * IO for a bit.
 	 */
-	if ((rw & REQ_HIPRIO) || wb_recent_wait(rwb) || current_is_kswapd())
+	if ((opf & REQ_HIPRIO) || wb_recent_wait(rwb) || current_is_kswapd())
 		limit = rwb->rq_depth.max_depth;
-	else if ((rw & REQ_BACKGROUND) || close_io(rwb)) {
+	else if ((opf & REQ_BACKGROUND) || close_io(rwb)) {
 		/*
 		 * If less than 100ms since we completed unrelated IO,
 		 * limit us to half the depth for background writeback.
@@ -490,13 +490,13 @@ static inline unsigned int get_limit(struct rq_wb *rwb, unsigned long rw)
 struct wbt_wait_data {
 	struct rq_wb *rwb;
 	enum wbt_flags wb_acct;
-	unsigned long rw;
+	blk_opf_t opf;
 };
 
 static bool wbt_inflight_cb(struct rq_wait *rqw, void *private_data)
 {
 	struct wbt_wait_data *data = private_data;
-	return rq_wait_inc_below(rqw, get_limit(data->rwb, data->rw));
+	return rq_wait_inc_below(rqw, get_limit(data->rwb, data->opf));
 }
 
 static void wbt_cleanup_cb(struct rq_wait *rqw, void *private_data)
@@ -510,13 +510,13 @@ static void wbt_cleanup_cb(struct rq_wait *rqw, void *private_data)
  * the timer to kick off queuing again.
  */
 static void __wbt_wait(struct rq_wb *rwb, enum wbt_flags wb_acct,
-		       unsigned long rw)
+		       blk_opf_t opf)
 {
 	struct rq_wait *rqw = get_rq_wait(rwb, wb_acct);
 	struct wbt_wait_data data = {
 		.rwb = rwb,
 		.wb_acct = wb_acct,
-		.rw = rw,
+		.opf = opf,
 	};
 
 	rq_qos_wait(rqw, &data, wbt_inflight_cb, wbt_cleanup_cb);
block/elevator.h +1 -1
index 16cd8bdedb7e..3f0593b3bf9d 100644
@@ -34,7 +34,7 @@ struct elevator_mq_ops {
 	int (*request_merge)(struct request_queue *q, struct request **, struct bio *);
 	void (*request_merged)(struct request_queue *, struct request *, enum elv_merge);
 	void (*requests_merged)(struct request_queue *, struct request *, struct request *);
-	void (*limit_depth)(unsigned int, struct blk_mq_alloc_data *);
+	void (*limit_depth)(blk_opf_t, struct blk_mq_alloc_data *);
 	void (*prepare_request)(struct request *);
 	void (*finish_request)(struct request *);
 	void (*insert_requests)(struct blk_mq_hw_ctx *, struct list_head *, bool);
block/fops.c +4 -4
index 86d3cab9bf93..dd22e8c9b76f 100644
@@ -32,9 +32,9 @@ static int blkdev_get_block(struct inode *inode, sector_t iblock,
 	return 0;
 }
 
-static unsigned int dio_bio_write_op(struct kiocb *iocb)
+static blk_opf_t dio_bio_write_op(struct kiocb *iocb)
 {
-	unsigned int op = REQ_OP_WRITE | REQ_SYNC | REQ_IDLE;
+	blk_opf_t op = REQ_OP_WRITE | REQ_SYNC | REQ_IDLE;
 
 	/* avoid the need for a I/O completion work item */
 	if (iocb->ki_flags & IOCB_DSYNC)
@@ -175,7 +175,7 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
 	struct blkdev_dio *dio;
 	struct bio *bio;
 	bool is_read = (iov_iter_rw(iter) == READ), is_sync;
-	unsigned int opf = is_read ? REQ_OP_READ : dio_bio_write_op(iocb);
+	blk_opf_t opf = is_read ? REQ_OP_READ : dio_bio_write_op(iocb);
 	loff_t pos = iocb->ki_pos;
 	int ret = 0;
 
@@ -297,7 +297,7 @@ static ssize_t __blkdev_direct_IO_async(struct kiocb *iocb,
 {
 	struct block_device *bdev = iocb->ki_filp->private_data;
 	bool is_read = iov_iter_rw(iter) == READ;
-	unsigned int opf = is_read ? REQ_OP_READ : dio_bio_write_op(iocb);
+	blk_opf_t opf = is_read ? REQ_OP_READ : dio_bio_write_op(iocb);
 	struct blkdev_dio *dio;
 	struct bio *bio;
 	loff_t pos = iocb->ki_pos;
block/kyber-iosched.c +3 -3
index 8f7c745b4a57..102b6a311b5c 100644
@@ -195,9 +195,9 @@ struct kyber_hctx_data {
 static int kyber_domain_wake(wait_queue_entry_t *wait, unsigned mode, int flags,
 			     void *key);
 
-static unsigned int kyber_sched_domain(unsigned int op)
+static unsigned int kyber_sched_domain(blk_opf_t opf)
 {
-	switch (op & REQ_OP_MASK) {
+	switch (opf & REQ_OP_MASK) {
 	case REQ_OP_READ:
 		return KYBER_READ;
 	case REQ_OP_WRITE:
@@ -553,7 +553,7 @@ static void rq_clear_domain_token(struct kyber_queue_data *kqd,
 	}
 }
 
-static void kyber_limit_depth(unsigned int op, struct blk_mq_alloc_data *data)
+static void kyber_limit_depth(blk_opf_t op, struct blk_mq_alloc_data *data)
 {
 	/*
 	 * We use the scheduler tags as per-hardware queue queueing tokens.
block/mq-deadline.c +1 -1
index 1a9e835e816c..c5589e9155e6 100644
@@ -543,7 +543,7 @@ static struct request *dd_dispatch_request(struct blk_mq_hw_ctx *hctx)
  * Called by __blk_mq_alloc_request(). The shallow_depth value set by this
  * function is used by __blk_mq_get_tag().
  */
-static void dd_limit_depth(unsigned int op, struct blk_mq_alloc_data *data)
+static void dd_limit_depth(blk_opf_t op, struct blk_mq_alloc_data *data)
 {
 	struct deadline_data *dd = data->q->elevator->elevator_data;
 
include/linux/bio.h +5 -5
index 992ee987f273..ca22b06700a9 100644
@@ -405,7 +405,7 @@ extern void bioset_exit(struct bio_set *);
 extern int biovec_init_pool(mempool_t *pool, int pool_entries);
 
 struct bio *bio_alloc_bioset(struct block_device *bdev, unsigned short nr_vecs,
-			     unsigned int opf, gfp_t gfp_mask,
+			     blk_opf_t opf, gfp_t gfp_mask,
 			     struct bio_set *bs);
 struct bio *bio_kmalloc(unsigned short nr_vecs, gfp_t gfp_mask);
 extern void bio_put(struct bio *);
@@ -418,7 +418,7 @@ int bio_init_clone(struct block_device *bdev, struct bio *bio,
 extern struct bio_set fs_bio_set;
 
 static inline struct bio *bio_alloc(struct block_device *bdev,
-		unsigned short nr_vecs, unsigned int opf, gfp_t gfp_mask)
+		unsigned short nr_vecs, blk_opf_t opf, gfp_t gfp_mask)
 {
 	return bio_alloc_bioset(bdev, nr_vecs, opf, gfp_mask, &fs_bio_set);
 }
@@ -456,9 +456,9 @@ struct request_queue;
 
 extern int submit_bio_wait(struct bio *bio);
 void bio_init(struct bio *bio, struct block_device *bdev, struct bio_vec *table,
-	      unsigned short max_vecs, unsigned int opf);
+	      unsigned short max_vecs, blk_opf_t opf);
 extern void bio_uninit(struct bio *);
-void bio_reset(struct bio *bio, struct block_device *bdev, unsigned int opf);
+void bio_reset(struct bio *bio, struct block_device *bdev, blk_opf_t opf);
 void bio_chain(struct bio *, struct bio *);
 
 int bio_add_page(struct bio *, struct page *, unsigned len, unsigned off);
@@ -789,6 +789,6 @@ static inline void bio_clear_polled(struct bio *bio)
 }
 
 struct bio *blk_next_bio(struct bio *bio, struct block_device *bdev,
-		unsigned int nr_pages, unsigned int opf, gfp_t gfp);
+		unsigned int nr_pages, blk_opf_t opf, gfp_t gfp);
 
 #endif /* __LINUX_BIO_H */
include/linux/blk-mq.h +2 -2
index 9a1838bbed02..fbaacd4607a0 100644
@@ -79,7 +79,7 @@ struct request {
 	struct blk_mq_ctx *mq_ctx;
 	struct blk_mq_hw_ctx *mq_hctx;
 
-	unsigned int cmd_flags;		/* op and common flags */
+	blk_opf_t cmd_flags;		/* op and common flags */
 	req_flags_t rq_flags;
 
 	int tag;
@@ -712,7 +712,7 @@ enum {
 	BLK_MQ_REQ_PM		= (__force blk_mq_req_flags_t)(1 << 2),
 };
 
-struct request *blk_mq_alloc_request(struct request_queue *q, unsigned int op,
+struct request *blk_mq_alloc_request(struct request_queue *q, blk_opf_t opf,
 		blk_mq_req_flags_t flags);
 struct request *blk_mq_alloc_request_hctx(struct request_queue *q,
 		enum req_op op, blk_mq_req_flags_t flags,
include/linux/blkdev.h +3 -2
index de47b0e0e18f..9751f164d2f0 100644
@@ -220,9 +220,10 @@ static inline int blk_validate_block_size(unsigned long bsize)
 	return 0;
 }
 
-static inline bool blk_op_is_passthrough(unsigned int op)
+static inline bool blk_op_is_passthrough(blk_opf_t opf)
 {
-	op &= REQ_OP_MASK;
+	enum req_op op = opf & REQ_OP_MASK;
+
 	return op == REQ_OP_DRV_IN || op == REQ_OP_DRV_OUT;
 }
 
author reviewer
#7 lore raw

PATCH 7/51 blktrace: Use the new blk_opf_t type

In reply to Bart Van Assche

Improve static type checking by using the new blk_opf_t type for a function argument that represents a combination of a request operation and request flags. Rename that argument from 'op' into 'opf' to make its role more clear.

Cc Li Zefan <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Steven Rostedt <[email protected]>
---
 include/linux/blktrace_api.h |  3 ++-
 kernel/trace/blktrace.c      | 20 ++++++++++----------
 2 files changed, 12 insertions(+), 11 deletions(-)
include/linux/blktrace_api.h +2 -1
index 623e22492afa..de9ef5bb57a7 100644
@@ -7,6 +7,7 @@
 #include <linux/compat.h>
 #include <uapi/linux/blktrace_api.h>
 #include <linux/list.h>
+#include <linux/blk_types.h>
 
 #if defined(CONFIG_BLK_DEV_IO_TRACE)
 
@@ -115,7 +116,7 @@ struct compat_blk_user_trace_setup {
 
 #endif
 
-void blk_fill_rwbs(char *rwbs, unsigned int op);
+void blk_fill_rwbs(char *rwbs, blk_opf_t opf);
 
 static inline sector_t blk_rq_trace_sector(struct request *rq)
 {
kernel/trace/blktrace.c +10 -10
index 10a32b0f2deb..f24c7351071c 100644
@@ -205,7 +205,7 @@ static const u32 ddir_act[2] = { BLK_TC_ACT(BLK_TC_READ),
 #define BLK_TC_PREFLUSH		BLK_TC_FLUSH
 
 /* The ilog2() calls fall out because they're constant */
-#define MASK_TC_BIT(rw, __name) ((rw & REQ_ ## __name) << \
+#define MASK_TC_BIT(rw, __name) ((__force u32)(rw & REQ_ ## __name) <<	\
 	  (ilog2(BLK_TC_ ## __name) + BLK_TC_SHIFT - __REQ_ ## __name))
 
 /*
@@ -213,8 +213,8 @@ static const u32 ddir_act[2] = { BLK_TC_ACT(BLK_TC_READ),
  * blk_io_trace structure and places it in a per-cpu subbuffer.
  */
 static void __blk_add_trace(struct blk_trace *bt, sector_t sector, int bytes,
-		     int op, int op_flags, u32 what, int error, int pdu_len,
-		     void *pdu_data, u64 cgid)
+		     enum req_op op, blk_opf_t op_flags, u32 what, int error,
+		     int pdu_len, void *pdu_data, u64 cgid)
 {
 	struct task_struct *tsk = current;
 	struct ring_buffer_event *event = NULL;
@@ -1895,14 +1895,14 @@ void blk_trace_remove_sysfs(struct device *dev)
  *     caller with resulting string.
  *
  **/
-void blk_fill_rwbs(char *rwbs, unsigned int op)
+void blk_fill_rwbs(char *rwbs, blk_opf_t opf)
 {
 	int i = 0;
 
-	if (op & REQ_PREFLUSH)
+	if (opf & REQ_PREFLUSH)
 		rwbs[i++] = 'F';
 
-	switch (op & REQ_OP_MASK) {
+	switch (opf & REQ_OP_MASK) {
 	case REQ_OP_WRITE:
 		rwbs[i++] = 'W';
 		break;
@@ -1923,13 +1923,13 @@ void blk_fill_rwbs(char *rwbs, unsigned int op)
 		rwbs[i++] = 'N';
 	}
 
-	if (op & REQ_FUA)
+	if (opf & REQ_FUA)
 		rwbs[i++] = 'F';
-	if (op & REQ_RAHEAD)
+	if (opf & REQ_RAHEAD)
 		rwbs[i++] = 'A';
-	if (op & REQ_SYNC)
+	if (opf & REQ_SYNC)
 		rwbs[i++] = 'S';
-	if (op & REQ_META)
+	if (opf & REQ_META)
 		rwbs[i++] = 'M';
 
 	rwbs[i] = '\0';
author reviewer
#8 lore raw

PATCH 8/51 blktrace: Trace remap operations correctly

In reply to Bart Van Assche

Trace the remapped operation instead of only the data direction of remapped operations. This issue was detected by analyzing the warnings reported by sparse related to the new blk_opf_t type.

Cc Mike Snitzer <[email protected]>
Cc Jun'ichi Nomura <[email protected]>
Fixes b0da3f0dada7 ("Add a tracepoint for block request remapping")
---
 kernel/trace/blktrace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/blktrace.c +1 -1
index f24c7351071c..d9e0530080e2 100644
@@ -1061,7 +1061,7 @@ static void blk_add_trace_rq_remap(void *ignore, struct request *rq, dev_t dev,
 	r.sector_from = cpu_to_be64(from);
 
 	__blk_add_trace(bt, blk_rq_pos(rq), blk_rq_bytes(rq),
-			rq_data_dir(rq), 0, BLK_TA_REMAP, 0,
+			req_op(rq), 0, BLK_TA_REMAP, 0,
 			sizeof(r), &r, blk_trace_request_get_cgid(rq));
 	rcu_read_unlock();
 }
author reviewer
#9 lore raw

PATCH 9/51 block/brd: Use the enum req_op type

In reply to Bart Van Assche

Improve static type checking by using the enum req_op type for a function argument that represents a request operation.

Cc Christoph Hellwig <[email protected]>
Cc Ming Lei <[email protected]>
---
 drivers/block/brd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/block/brd.c +1 -1
index c3d772bdd89f..a3dfff0f73f5 100644
@@ -256,7 +256,7 @@ static void copy_from_brd(void *dst, struct brd_device *brd,
  * Process a single bvec of a bio.
  */
 static int brd_do_bvec(struct brd_device *brd, struct page *page,
-			unsigned int len, unsigned int off, unsigned int op,
+			unsigned int len, unsigned int off, enum req_op op,
 			sector_t sector)
 {
 	void *mem;
author reviewer
#12 lore raw

PATCH 11/51 block/floppy: Fix a sparse warning

In reply to Bart Van Assche

Since the type of request.cmd_flags has been changed from u32 into blk_opf_t, use the __force keyword when casting to an integer type to prevent that sparse warns about this cast.

---
 drivers/block/floppy.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/block/floppy.c +1 -1
index 015841f50f4e..2f24de4eb8da 100644
@@ -2859,7 +2859,7 @@ static blk_status_t floppy_queue_rq(struct blk_mq_hw_ctx *hctx,
 	if (WARN(atomic_read(&usage_count) == 0,
 		 "warning: usage count=0, current_req=%p sect=%ld flags=%llx\n",
 		 current_req, (long)blk_rq_pos(current_req),
-		 (unsigned long long) current_req->cmd_flags))
+		 (__force unsigned long long) current_req->cmd_flags))
 		return BLK_STS_IOERR;
 
 	if (test_and_set_bit(0, &fdc_busy)) {
author reviewer
#13 lore raw

PATCH 12/51 block/null_blk: Fix sparse warnings in tracing code

In reply to Bart Van Assche

Since the tracing infrastructure does not support bitwise types, store the request operation as an int. This patch does not change any functionality.

Cc Christoph Hellwig <[email protected]>
Cc Ming Lei <[email protected]>
---
 drivers/block/null_blk/trace.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/block/null_blk/trace.h +3 -3
index 6b2b370e786f..f79467e5310f 100644
@@ -36,19 +36,19 @@ TRACE_EVENT(nullb_zone_op,
 	    TP_ARGS(cmd, zone_no, zone_cond),
 	    TP_STRUCT__entry(
 		__array(char, disk, DISK_NAME_LEN)
-		__field(enum req_op, op)
+		__field(int, op)
 		__field(unsigned int, zone_no)
 		__field(unsigned int, zone_cond)
 	    ),
 	    TP_fast_assign(
-		__entry->op = req_op(cmd->rq);
+		__entry->op = (__force int)req_op(cmd->rq);
 		__entry->zone_no = zone_no;
 		__entry->zone_cond = zone_cond;
 		__assign_disk_name(__entry->disk, cmd->rq->q->disk);
 	    ),
 	    TP_printk("%s req=%-15s zone_no=%u zone_cond=%-10s",
 		      __print_disk_name(__entry->disk),
-		      blk_op_str(__entry->op),
+		      blk_op_str((__force enum req_op)__entry->op),
 		      __entry->zone_no,
 		      blk_zone_cond_str(__entry->zone_cond))
 );
author reviewer
#10 lore raw

PATCH 10/51 block/drbd: Use the enum req_op and blk_opf_t types

In reply to Bart Van Assche

Improve static type checking by using the enum req_op type for variables that represent a request operation and the new blk_opf_t type for variables that represent request flags.

Cc Lars Ellenberg <[email protected]>
Cc Philipp Reisner <[email protected]>
Cc Christoph Böhmwalder <[email protected]>
---
 drivers/block/drbd/drbd_actlog.c   |  9 +++++----
 drivers/block/drbd/drbd_bitmap.c   |  3 ++-
 drivers/block/drbd/drbd_int.h      |  6 +++---
 drivers/block/drbd/drbd_receiver.c | 11 ++++++-----
 4 files changed, 16 insertions(+), 13 deletions(-)
drivers/block/drbd/drbd_actlog.c +5 -4
index f5bcded3640d..e27478ae579c 100644
@@ -124,12 +124,13 @@ void wait_until_done_or_force_detached(struct drbd_device *device, struct drbd_b
 
 static int _drbd_md_sync_page_io(struct drbd_device *device,
 				 struct drbd_backing_dev *bdev,
-				 sector_t sector, int op)
+				 sector_t sector, enum req_op op)
 {
 	struct bio *bio;
 	/* we do all our meta data IO in aligned 4k blocks. */
 	const int size = 4096;
-	int err, op_flags = 0;
+	int err;
+	blk_opf_t op_flags = 0;
 
 	device->md_io.done = 0;
 	device->md_io.error = -ENODEV;
@@ -174,7 +175,7 @@ static int _drbd_md_sync_page_io(struct drbd_device *device,
 }
 
 int drbd_md_sync_page_io(struct drbd_device *device, struct drbd_backing_dev *bdev,
-			 sector_t sector, int op)
+			 sector_t sector, enum req_op op)
 {
 	int err;
 	D_ASSERT(device, atomic_read(&device->md_io.in_use) == 1);
@@ -385,7 +386,7 @@ static int __al_write_transaction(struct drbd_device *device, struct al_transact
 		write_al_updates = rcu_dereference(device->ldev->disk_conf)->al_updates;
 		rcu_read_unlock();
 		if (write_al_updates) {
-			if (drbd_md_sync_page_io(device, device->ldev, sector, WRITE)) {
+			if (drbd_md_sync_page_io(device, device->ldev, sector, REQ_OP_WRITE)) {
 				err = -EIO;
 				drbd_chk_io_error(device, 1, DRBD_META_IO_ERROR);
 			} else {
drivers/block/drbd/drbd_bitmap.c +2 -1
index bd2133ef6e0a..0845f28a48a7 100644
@@ -990,7 +990,8 @@ static inline sector_t drbd_md_last_bitmap_sector(struct drbd_backing_dev *bdev)
 static void bm_page_io_async(struct drbd_bm_aio_ctx *ctx, int page_nr) __must_hold(local)
 {
 	struct drbd_device *device = ctx->device;
-	unsigned int op = (ctx->flags & BM_AIO_READ) ? REQ_OP_READ : REQ_OP_WRITE;
+	const enum req_op op = ctx->flags & BM_AIO_READ ? REQ_OP_READ :
+		REQ_OP_WRITE;
 	struct drbd_bitmap *b = device->bitmap;
 	struct bio *bio;
 	struct page *page;
drivers/block/drbd/drbd_int.h +3 -3
index 4d3efaa20b7b..ecb2ecd8d67d 100644
@@ -1495,7 +1495,7 @@ extern int drbd_resync_finished(struct drbd_device *device);
 extern void *drbd_md_get_buffer(struct drbd_device *device, const char *intent);
 extern void drbd_md_put_buffer(struct drbd_device *device);
 extern int drbd_md_sync_page_io(struct drbd_device *device,
-		struct drbd_backing_dev *bdev, sector_t sector, int op);
+		struct drbd_backing_dev *bdev, sector_t sector, enum req_op op);
 extern void drbd_ov_out_of_sync_found(struct drbd_device *, sector_t, int);
 extern void wait_until_done_or_force_detached(struct drbd_device *device,
 		struct drbd_backing_dev *bdev, unsigned int *done);
@@ -1547,8 +1547,8 @@ extern bool drbd_rs_c_min_rate_throttle(struct drbd_device *device);
 extern bool drbd_rs_should_slow_down(struct drbd_device *device, sector_t sector,
 		bool throttle_if_app_is_waiting);
 extern int drbd_submit_peer_request(struct drbd_device *,
-				    struct drbd_peer_request *, const unsigned,
-				    const unsigned, const int);
+				    struct drbd_peer_request *, enum req_op,
+				    blk_opf_t, int);
 extern int drbd_free_peer_reqs(struct drbd_device *, struct list_head *);
 extern struct drbd_peer_request *drbd_alloc_peer_req(struct drbd_peer_device *, u64,
 						     sector_t, unsigned int,
drivers/block/drbd/drbd_receiver.c +6 -5
index 6762be53f409..caf646dd91ba 100644
@@ -1621,7 +1621,7 @@ static void drbd_issue_peer_discard_or_zero_out(struct drbd_device *device, stru
 /* TODO allocate from our own bio_set. */
 int drbd_submit_peer_request(struct drbd_device *device,
 			     struct drbd_peer_request *peer_req,
-			     const unsigned op, const unsigned op_flags,
+			     const enum req_op op, const blk_opf_t op_flags,
 			     const int fault_type)
 {
 	struct bio *bios = NULL;
@@ -2383,14 +2383,14 @@ static int wait_for_and_update_peer_seq(struct drbd_peer_device *peer_device, co
 /* see also bio_flags_to_wire()
  * DRBD_REQ_*, because we need to semantically map the flags to data packet
  * flags and back. We may replicate to other kernel versions. */
-static unsigned long wire_flags_to_bio_flags(u32 dpf)
+static blk_opf_t wire_flags_to_bio_flags(u32 dpf)
 {
 	return  (dpf & DP_RW_SYNC ? REQ_SYNC : 0) |
 		(dpf & DP_FUA ? REQ_FUA : 0) |
 		(dpf & DP_FLUSH ? REQ_PREFLUSH : 0);
 }
 
-static unsigned long wire_flags_to_bio_op(u32 dpf)
+static enum req_op wire_flags_to_bio_op(u32 dpf)
 {
 	if (dpf & DP_ZEROES)
 		return REQ_OP_WRITE_ZEROES;
@@ -2543,7 +2543,8 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
 	struct drbd_peer_request *peer_req;
 	struct p_data *p = pi->data;
 	u32 peer_seq = be32_to_cpu(p->seq_num);
-	int op, op_flags;
+	enum req_op op;
+	blk_opf_t op_flags;
 	u32 dp_flags;
 	int err, tp;
 
@@ -4951,7 +4952,7 @@ static int receive_rs_deallocated(struct drbd_connection *connection, struct pac
 
 	if (get_ldev(device)) {
 		struct drbd_peer_request *peer_req;
-		const int op = REQ_OP_WRITE_ZEROES;
+		const enum req_op op = REQ_OP_WRITE_ZEROES;
 
 		peer_req = drbd_alloc_peer_req(peer_device, ID_SYNCER, sector,
 					       size, 0, GFP_NOIO);
author reviewer
#14 lore raw

PATCH 13/51 um: Use enum req_op where appropriate

In reply to Bart Van Assche

Improve static type checking by using type enum req_op instead of int where appropriate.

Cc Richard Weinberger <[email protected]>
Cc Anton Ivanov <[email protected]>
---
 arch/um/drivers/ubd_kern.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/um/drivers/ubd_kern.c +2 -2
index c4344b67628d..e2a0ebe4872f 100644
@@ -1262,7 +1262,7 @@ static void ubd_map_req(struct ubd *dev, struct io_thread_req *io_req,
 	struct req_iterator iter;
 	int i = 0;
 	unsigned long byte_offset = io_req->offset;
-	int op = req_op(req);
+	enum req_op op = req_op(req);
 
 	if (op == REQ_OP_WRITE_ZEROES || op == REQ_OP_DISCARD) {
 		io_req->io_desc[0].buffer = NULL;
@@ -1325,7 +1325,7 @@ static int ubd_submit_request(struct ubd *dev, struct request *req)
 	int segs = 0;
 	struct io_thread_req *io_req;
 	int ret;
-	int op = req_op(req);
+	enum req_op op = req_op(req);
 
 	if (op == REQ_OP_FLUSH)
 		segs = 0;
author reviewer
#15 lore raw

PATCH 14/51 dm/core: Use the enum req_op and blk_opf_t types

In reply to Bart Van Assche

Improve static type checking by using the enum req_op type for variables that represent a request operation and the new blk_opf_t type for variables that represent request flags all or not combined with a request operation.

Cc Alasdair Kergon <[email protected]>
Cc Mike Snitzer <[email protected]>
---
 drivers/md/dm-io.c    | 18 ++++++++++--------
 drivers/md/dm.c       |  2 +-
 include/linux/dm-io.h |  5 +++--
 3 files changed, 14 insertions(+), 11 deletions(-)
drivers/md/dm-io.c +10 -8
index e4b95eaeec8c..29ff150634cd 100644
@@ -293,7 +293,7 @@ static void km_dp_init(struct dpages *dp, void *data)
 /*-----------------------------------------------------------------
  * IO routines that accept a list of pages.
  *---------------------------------------------------------------*/
-static void do_region(int op, int op_flags, unsigned region,
+static void do_region(enum req_op op, blk_opf_t op_flags, unsigned region,
 		      struct dm_io_region *where, struct dpages *dp,
 		      struct io *io)
 {
@@ -368,9 +368,9 @@ static void do_region(int op, int op_flags, unsigned region,
 	} while (remaining);
 }
 
-static void dispatch_io(int op, int op_flags, unsigned int num_regions,
-			struct dm_io_region *where, struct dpages *dp,
-			struct io *io, int sync)
+static void dispatch_io(enum req_op op, blk_opf_t op_flags,
+			unsigned int num_regions, struct dm_io_region *where,
+			struct dpages *dp, struct io *io, int sync)
 {
 	int i;
 	struct dpages old_pages = *dp;
@@ -411,8 +411,9 @@ static void sync_io_complete(unsigned long error, void *context)
 }
 
 static int sync_io(struct dm_io_client *client, unsigned int num_regions,
-		   struct dm_io_region *where, int op, int op_flags,
-		   struct dpages *dp, unsigned long *error_bits)
+		   struct dm_io_region *where, enum req_op op,
+		   blk_opf_t op_flags, struct dpages *dp,
+		   unsigned long *error_bits)
 {
 	struct io *io;
 	struct sync_io sio;
@@ -445,8 +446,9 @@ static int sync_io(struct dm_io_client *client, unsigned int num_regions,
 }
 
 static int async_io(struct dm_io_client *client, unsigned int num_regions,
-		    struct dm_io_region *where, int op, int op_flags,
-		    struct dpages *dp, io_notify_fn fn, void *context)
+		    struct dm_io_region *where, enum req_op op,
+		    blk_opf_t op_flags, struct dpages *dp, io_notify_fn fn,
+		    void *context)
 {
 	struct io *io;
 
drivers/md/dm.c +1 -1
index bed7ad573f79..ea0bbbd6837f 100644
@@ -1622,7 +1622,7 @@ static blk_status_t __split_and_process_bio(struct clone_info *ci)
 	 * Only support bio polling for normal IO, and the target io is
 	 * exactly inside the dm_io instance (verified in dm_poll_dm_io)
 	 */
-	ci->submit_as_polled = ci->bio->bi_opf & REQ_POLLED;
+	ci->submit_as_polled = !!(ci->bio->bi_opf & REQ_POLLED);
 
 	len = min_t(sector_t, max_io_len(ti, ci->sector), ci->sector_count);
 	setup_split_accounting(ci, len);
include/linux/dm-io.h +3 -2
index a52c6580cc9a..811f29ca4971 100644
@@ -13,6 +13,7 @@
 #ifdef __KERNEL__
 
 #include <linux/types.h>
+#include <linux/blk_types.h>
 
 struct dm_io_region {
 	struct block_device *bdev;
@@ -57,8 +58,8 @@ struct dm_io_notify {
  */
 struct dm_io_client;
 struct dm_io_request {
-	int bi_op;			/* REQ_OP */
-	int bi_op_flags;		/* req_flag_bits */
+	enum req_op bi_op;		/* REQ_OP */
+	blk_opf_t bi_op_flags;	/* req_flag_bits */
 	struct dm_io_memory mem;	/* Memory to use for io */
 	struct dm_io_notify notify;	/* Synchronous if notify.fn is NULL */
 	struct dm_io_client *client;	/* Client memory handler */
author reviewer
#16 lore raw

PATCH 15/51 dm/bufio: Change 'int rw' into 'enum req_op op'

In reply to Bart Van Assche

Improve static type checking by using type 'enum req_op' instead of 'int'. Make the role of the 'rw' arguments more clear by renaming these into 'op' (operation). This patch does not change any functionality.

Cc Alasdair Kergon <[email protected]>
Cc Mike Snitzer <[email protected]>
---
 drivers/md/dm-bufio.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)
drivers/md/dm-bufio.c +10 -9
index 5ffa1dcf84cf..666b36d043d4 100644
@@ -577,12 +577,12 @@ static void dmio_complete(unsigned long error, void *context)
 	b->end_io(b, unlikely(error != 0) ? BLK_STS_IOERR : 0);
 }
 
-static void use_dmio(struct dm_buffer *b, int rw, sector_t sector,
+static void use_dmio(struct dm_buffer *b, enum req_op op, sector_t sector,
 		     unsigned n_sectors, unsigned offset)
 {
 	int r;
 	struct dm_io_request io_req = {
-		.bi_op = rw,
+		.bi_op = op,
 		.bi_op_flags = 0,
 		.notify.fn = dmio_complete,
 		.notify.context = b,
@@ -616,7 +616,7 @@ static void bio_complete(struct bio *bio)
 	b->end_io(b, status);
 }
 
-static void use_bio(struct dm_buffer *b, int rw, sector_t sector,
+static void use_bio(struct dm_buffer *b, enum req_op op, sector_t sector,
 		    unsigned n_sectors, unsigned offset)
 {
 	struct bio *bio;
@@ -630,10 +630,10 @@ static void use_bio(struct dm_buffer *b, int rw, sector_t sector,
 	bio = bio_kmalloc(vec_size, GFP_NOWAIT | __GFP_NORETRY | __GFP_NOWARN);
 	if (!bio) {
 dmio:
-		use_dmio(b, rw, sector, n_sectors, offset);
+		use_dmio(b, op, sector, n_sectors, offset);
 		return;
 	}
-	bio_init(bio, b->c->bdev, bio->bi_inline_vecs, vec_size, rw);
+	bio_init(bio, b->c->bdev, bio->bi_inline_vecs, vec_size, op);
 	bio->bi_iter.bi_sector = sector;
 	bio->bi_end_io = bio_complete;
 	bio->bi_private = b;
@@ -669,7 +669,8 @@ static inline sector_t block_to_sector(struct dm_bufio_client *c, sector_t block
 	return sector;
 }
 
-static void submit_io(struct dm_buffer *b, int rw, void (*end_io)(struct dm_buffer *, blk_status_t))
+static void submit_io(struct dm_buffer *b, enum req_op op,
+		      void (*end_io)(struct dm_buffer *, blk_status_t))
 {
 	unsigned n_sectors;
 	sector_t sector;
@@ -679,7 +680,7 @@ static void submit_io(struct dm_buffer *b, int rw, void (*end_io)(struct dm_buff
 
 	sector = block_to_sector(b->c, b->block);
 
-	if (rw != REQ_OP_WRITE) {
+	if (op != REQ_OP_WRITE) {
 		n_sectors = b->c->block_size >> SECTOR_SHIFT;
 		offset = 0;
 	} else {
@@ -698,9 +699,9 @@ static void submit_io(struct dm_buffer *b, int rw, void (*end_io)(struct dm_buff
 	}
 
 	if (b->data_mode != DATA_MODE_VMALLOC)
-		use_bio(b, rw, sector, n_sectors, offset);
+		use_bio(b, op, sector, n_sectors, offset);
 	else
-		use_dmio(b, rw, sector, n_sectors, offset);
+		use_dmio(b, op, sector, n_sectors, offset);
 }
 
 /*----------------------------------------------------------------
author reviewer
#17 lore raw

PATCH 16/51 dm/kcopyd: Rename kcopyd_job.rw into kcopyd_job.op

In reply to Bart Van Assche

The code that assigns kcopyd_job.rw to the bio.op member shows that it represents a request operation type (REQ_OP_). Rename kcopyd_job.rw into kcopyd_job.op to make this clear and only assign REQ_OP_* constants to that structure member. This patch does not change any functionality since REQ_OP_READ = READ = 0 and REQ_OP_WRITE = WRITE = 1.

Cc Alasdair Kergon <[email protected]>
Cc Mike Snitzer <[email protected]>
---
 drivers/md/dm-kcopyd.c | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)
drivers/md/dm-kcopyd.c +13 -12
index 37b03ab7e5c9..a3d0d6ca95af 100644
@@ -350,9 +350,9 @@ struct kcopyd_job {
 	unsigned long write_err;
 
 	/*
-	 * Either READ or WRITE
+	 * REQ_OP_READ, REQ_OP_WRITE or REQ_OP_WRITE_ZEROES.
 	 */
-	int rw;
+	enum req_op op;
 	struct dm_io_region source;
 
 	/*
@@ -418,7 +418,8 @@ static struct kcopyd_job *pop_io_job(struct list_head *jobs,
 	 * constraint and sequential writes that are at the right position.
 	 */
 	list_for_each_entry(job, jobs, list) {
-		if (job->rw == READ || !(job->flags & BIT(DM_KCOPYD_WRITE_SEQ))) {
+		if (job->op == REQ_OP_READ ||
+		    !(job->flags & BIT(DM_KCOPYD_WRITE_SEQ))) {
 			list_del(&job->list);
 			return job;
 		}
@@ -518,7 +519,7 @@ static void complete_io(unsigned long error, void *context)
 	io_job_finish(kc->throttle);
 
 	if (error) {
-		if (op_is_write(job->rw))
+		if (op_is_write(job->op))
 			job->write_err |= error;
 		else
 			job->read_err = 1;
@@ -530,11 +531,11 @@ static void complete_io(unsigned long error, void *context)
 		}
 	}
 
-	if (op_is_write(job->rw))
+	if (op_is_write(job->op))
 		push(&kc->complete_jobs, job);
 
 	else {
-		job->rw = WRITE;
+		job->op = REQ_OP_WRITE;
 		push(&kc->io_jobs, job);
 	}
 
@@ -549,7 +550,7 @@ static int run_io_job(struct kcopyd_job *job)
 {
 	int r;
 	struct dm_io_request io_req = {
-		.bi_op = job->rw,
+		.bi_op = job->op,
 		.bi_op_flags = 0,
 		.mem.type = DM_IO_PAGE_LIST,
 		.mem.ptr.pl = job->pages,
@@ -571,7 +572,7 @@ static int run_io_job(struct kcopyd_job *job)
 
 	io_job_start(job->kc->throttle);
 
-	if (job->rw == READ)
+	if (job->op == REQ_OP_READ)
 		r = dm_io(&io_req, 1, &job->source, NULL);
 	else
 		r = dm_io(&io_req, job->num_dests, job->dests, NULL);
@@ -614,7 +615,7 @@ static int process_jobs(struct list_head *jobs, struct dm_kcopyd_client *kc,
 
 		if (r < 0) {
 			/* error this rogue job */
-			if (op_is_write(job->rw))
+			if (op_is_write(job->op))
 				job->write_err = (unsigned long) -1L;
 			else
 				job->read_err = 1;
@@ -817,7 +818,7 @@ void dm_kcopyd_copy(struct dm_kcopyd_client *kc, struct dm_io_region *from,
 	if (from) {
 		job->source = *from;
 		job->pages = NULL;
-		job->rw = READ;
+		job->op = REQ_OP_READ;
 	} else {
 		memset(&job->source, 0, sizeof job->source);
 		job->source.count = job->dests[0].count;
@@ -826,10 +827,10 @@ void dm_kcopyd_copy(struct dm_kcopyd_client *kc, struct dm_io_region *from,
 		/*
 		 * Use WRITE ZEROES to optimize zeroing if all dests support it.
 		 */
-		job->rw = REQ_OP_WRITE_ZEROES;
+		job->op = REQ_OP_WRITE_ZEROES;
 		for (i = 0; i < job->num_dests; i++)
 			if (!bdev_write_zeroes_sectors(job->dests[i].bdev)) {
-				job->rw = WRITE;
+				job->op = REQ_OP_WRITE;
 				break;
 			}
 	}
author reviewer
#18 lore raw

PATCH 17/51 dm/ebs: Change 'int rw' into 'enum req_op op'

In reply to Bart Van Assche

Improve static type checking by using type 'enum req_op' instead of 'int'. Make the role of the 'rw' arguments more clear by renaming these into 'op' (operation). This patch does not change any functionality since REQ_OP_READ = READ = 0 and REQ_OP_WRITE = WRITE = 1.

Cc Alasdair Kergon <[email protected]>
Cc Mike Snitzer <[email protected]>
Cc Heinz Mauelshagen <[email protected]>
---
 drivers/md/dm-ebs-target.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/md/dm-ebs-target.c +8 -7
index 0221fa63f888..223e8e1a7a13 100644
@@ -61,7 +61,8 @@ static inline bool __ebs_check_bs(unsigned int bs)
  *
  * copy blocks between bufio blocks and bio vector's (partial/overlapping) pages.
  */
-static int __ebs_rw_bvec(struct ebs_c *ec, int rw, struct bio_vec *bv, struct bvec_iter *iter)
+static int __ebs_rw_bvec(struct ebs_c *ec, enum req_op op, struct bio_vec *bv,
+			 struct bvec_iter *iter)
 {
 	int r = 0;
 	unsigned char *ba, *pa;
@@ -81,7 +82,7 @@ static int __ebs_rw_bvec(struct ebs_c *ec, int rw, struct bio_vec *bv, struct bv
 		cur_len = min(dm_bufio_get_block_size(ec->bufio) - buf_off, bv_len);
 
 		/* Avoid reading for writes in case bio vector's page overwrites block completely. */
-		if (rw == READ || buf_off || bv_len < dm_bufio_get_block_size(ec->bufio))
+		if (op == REQ_OP_READ || buf_off || bv_len < dm_bufio_get_block_size(ec->bufio))
 			ba = dm_bufio_read(ec->bufio, block, &b);
 		else
 			ba = dm_bufio_new(ec->bufio, block, &b);
@@ -95,7 +96,7 @@ static int __ebs_rw_bvec(struct ebs_c *ec, int rw, struct bio_vec *bv, struct bv
 		} else {
 			/* Copy data to/from bio to buffer if read/new was successful above. */
 			ba += buf_off;
-			if (rw == READ) {
+			if (op == REQ_OP_READ) {
 				memcpy(pa, ba, cur_len);
 				flush_dcache_page(bv->bv_page);
 			} else {
@@ -117,14 +118,14 @@ static int __ebs_rw_bvec(struct ebs_c *ec, int rw, struct bio_vec *bv, struct bv
 }
 
 /* READ/WRITE: iterate bio vector's copying between (partial) pages and bufio blocks. */
-static int __ebs_rw_bio(struct ebs_c *ec, int rw, struct bio *bio)
+static int __ebs_rw_bio(struct ebs_c *ec, enum req_op op, struct bio *bio)
 {
 	int r = 0, rr;
 	struct bio_vec bv;
 	struct bvec_iter iter;
 
 	bio_for_each_bvec(bv, bio, iter) {
-		rr = __ebs_rw_bvec(ec, rw, &bv, &iter);
+		rr = __ebs_rw_bvec(ec, op, &bv, &iter);
 		if (rr)
 			r = rr;
 	}
@@ -205,10 +206,10 @@ static void __ebs_process_bios(struct work_struct *ws)
 	bio_list_for_each(bio, &bios) {
 		r = -EIO;
 		if (bio_op(bio) == REQ_OP_READ)
-			r = __ebs_rw_bio(ec, READ, bio);
+			r = __ebs_rw_bio(ec, REQ_OP_READ, bio);
 		else if (bio_op(bio) == REQ_OP_WRITE) {
 			write = true;
-			r = __ebs_rw_bio(ec, WRITE, bio);
+			r = __ebs_rw_bio(ec, REQ_OP_WRITE, bio);
 		} else if (bio_op(bio) == REQ_OP_DISCARD) {
 			__ebs_forget_bio(ec, bio);
 			r = __ebs_discard_bio(ec, bio);
author reviewer
#19 lore raw

PATCH 18/51 dm/dm-flakey: Use the new blk_opf_t type

In reply to Bart Van Assche

Use the new blk_opf_t type for structure members that represent request flags.

Cc Alasdair Kergon <[email protected]>
Cc Mike Snitzer <[email protected]>
---
 drivers/md/dm-flakey.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/md/dm-flakey.c +6 -2
index f2305eb758a2..89fa7a68c6c4 100644
@@ -32,7 +32,7 @@ struct flakey_c {
 	unsigned corrupt_bio_byte;
 	unsigned corrupt_bio_rw;
 	unsigned corrupt_bio_value;
-	unsigned corrupt_bio_flags;
+	blk_opf_t corrupt_bio_flags;
 };
 
 enum feature_flag_bits {
@@ -145,7 +145,11 @@ static int parse_features(struct dm_arg_set *as, struct flakey_c *fc,
 			/*
 			 * Only corrupt bios with these flags set.
 			 */
-			r = dm_read_arg(_args + 3, as, &fc->corrupt_bio_flags, &ti->error);
+			BUILD_BUG_ON(sizeof(fc->corrupt_bio_flags) !=
+				     sizeof(unsigned int));
+			r = dm_read_arg(_args + 3, as,
+				(__force unsigned *)&fc->corrupt_bio_flags,
+				&ti->error);
 			if (r)
 				return r;
 			argc--;
author reviewer
#20 lore raw

PATCH 19/51 dm/dm-integrity: Use the enum req_op and blk_opf_t types

In reply to Bart Van Assche

Improve static type checking by using the enum req_op type for variables that represent a request operation and the new blk_opf_t type for variables that represent request flags.

Cc Alasdair Kergon <[email protected]>
Cc Mike Snitzer <[email protected]>
Cc Eric Biggers <[email protected]>
---
 drivers/md/dm-integrity.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/md/dm-integrity.c +8 -4
index 148978ad03a8..8bb0c7a88176 100644
@@ -551,7 +551,8 @@ static int sb_mac(struct dm_integrity_c *ic, bool wr)
 	return 0;
 }
 
-static int sync_rw_sb(struct dm_integrity_c *ic, int op, int op_flags)
+static int sync_rw_sb(struct dm_integrity_c *ic, enum req_op op,
+		      blk_opf_t op_flags)
 {
 	struct dm_io_request io_req;
 	struct dm_io_region io_loc;
@@ -1050,8 +1051,10 @@ static void complete_journal_io(unsigned long error, void *context)
 	complete_journal_op(comp);
 }
 
-static void rw_journal_sectors(struct dm_integrity_c *ic, int op, int op_flags,
-			       unsigned sector, unsigned n_sectors, struct journal_completion *comp)
+static void rw_journal_sectors(struct dm_integrity_c *ic, enum req_op op,
+			       blk_opf_t op_flags, unsigned sector,
+			       unsigned n_sectors,
+			       struct journal_completion *comp)
 {
 	struct dm_io_request io_req;
 	struct dm_io_region io_loc;
@@ -1096,7 +1099,8 @@ static void rw_journal_sectors(struct dm_integrity_c *ic, int op, int op_flags,
 	}
 }
 
-static void rw_journal(struct dm_integrity_c *ic, int op, int op_flags, unsigned section,
+static void rw_journal(struct dm_integrity_c *ic, enum req_op op,
+		       blk_opf_t op_flags, unsigned section,
 		       unsigned n_sections, struct journal_completion *comp)
 {
 	unsigned sector, n_sectors;
author reviewer
#21 lore raw

PATCH 20/51 dm/dm-snap: Use the enum req_op and blk_opf_t types

In reply to Bart Van Assche

Improve static type checking by using the enum req_op type for variables that represent a request operation and the new blk_opf_t type for variables that represent request flags.

Cc Alasdair Kergon <[email protected]>
Cc Mike Snitzer <[email protected]>
---
 drivers/md/dm-snap-persistent.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/md/dm-snap-persistent.c +3 -3
index 3bb5cff5d6fc..e536f6be63b3 100644
@@ -226,8 +226,8 @@ static void do_metadata(struct work_struct *work)
 /*
  * Read or write a chunk aligned and sized block of data from a device.
  */
-static int chunk_io(struct pstore *ps, void *area, chunk_t chunk, int op,
-		    int op_flags, int metadata)
+static int chunk_io(struct pstore *ps, void *area, chunk_t chunk,
+		    enum req_op op, blk_opf_t op_flags, int metadata)
 {
 	struct dm_io_region where = {
 		.bdev = dm_snap_cow(ps->store->snap)->bdev,
@@ -282,7 +282,7 @@ static void skip_metadata(struct pstore *ps)
  * Read or write a metadata area.  Remembering to skip the first
  * chunk which holds the header.
  */
-static int area_io(struct pstore *ps, int op, int op_flags)
+static int area_io(struct pstore *ps, enum req_op op, blk_opf_t op_flags)
 {
 	chunk_t chunk = area_location(ps, ps->current_area);
 
author reviewer
#22 lore raw

PATCH 21/51 dm/dm-zoned: Use the enum req_op type

In reply to Bart Van Assche

Improve static type checking by using the enum req_op type for arguments that represent a request operation.

Cc Alasdair Kergon <[email protected]>
Cc Mike Snitzer <[email protected]>
Cc Damien Le Moal <[email protected]>
---
 drivers/md/dm-zoned-metadata.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm-zoned-metadata.c +1 -1
index d1ea66114d14..9341c46e44b7 100644
@@ -737,7 +737,7 @@ static int dmz_write_mblock(struct dmz_metadata *zmd, struct dmz_mblock *mblk,
 /*
  * Read/write a metadata block.
  */
-static int dmz_rdwr_block(struct dmz_dev *dev, int op,
+static int dmz_rdwr_block(struct dmz_dev *dev, enum req_op op,
 			  sector_t block, struct page *page)
 {
 	struct bio *bio;
author reviewer
#24 lore raw

PATCH 22/51 md/core: Use the enum req_op and blk_opf_t types

In reply to Bart Van Assche

Improve static type checking by using the enum req_op type for variables that represent a request operation and the new blk_opf_t type for variables that represent request flags.

---
 drivers/md/md.c | 3 ++-
 drivers/md/md.h | 4 ++--
 2 files changed, 4 insertions(+), 3 deletions(-)
drivers/md/md.c +2 -1
index c7ecb0bffda0..d354faa95be7 100644
@@ -993,7 +993,8 @@ int md_super_wait(struct mddev *mddev)
 }
 
 int sync_page_io(struct md_rdev *rdev, sector_t sector, int size,
-		 struct page *page, int op, int op_flags, bool metadata_op)
+		 struct page *page, enum req_op op, blk_opf_t op_flags,
+		 bool metadata_op)
 {
 	struct bio bio;
 	struct bio_vec bvec;
drivers/md/md.h +2 -2
index cf2cbb17acbd..f93bf7396d86 100644
@@ -738,8 +738,8 @@ extern void md_super_write(struct mddev *mddev, struct md_rdev *rdev,
 			   sector_t sector, int size, struct page *page);
 extern int md_super_wait(struct mddev *mddev);
 extern int sync_page_io(struct md_rdev *rdev, sector_t sector, int size,
-			struct page *page, int op, int op_flags,
-			bool metadata_op);
+		struct page *page, enum req_op op, blk_opf_t op_flags,
+		bool metadata_op);
 extern void md_do_sync(struct md_thread *thread);
 extern void md_new_event(void);
 extern void md_allow_write(struct mddev *mddev);
author reviewer
#25 lore raw

PATCH 23/51 md/bcache: Use the enum req_op and blk_opf_t types

In reply to Bart Van Assche

Improve static type checking by using the enum req_op type for variables that represent a request operation and the new blk_opf_t type for variables that represent request flags.

---
 drivers/md/bcache/super.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/md/bcache/super.c +2 -2
index 3563d15dbaf2..93f18bae28cf 100644
@@ -414,7 +414,7 @@ static void uuid_io_unlock(struct closure *cl)
 	up(&c->uuid_write_mutex);
 }
 
-static void uuid_io(struct cache_set *c, int op, unsigned long op_flags,
+static void uuid_io(struct cache_set *c, enum req_op op, blk_opf_t op_flags,
 		    struct bkey *k, struct closure *parent)
 {
 	struct closure *cl = &c->uuid_write;
@@ -588,7 +588,7 @@ static void prio_endio(struct bio *bio)
 }
 
 static void prio_io(struct cache *ca, uint64_t bucket, int op,
-		    unsigned long op_flags)
+		    blk_opf_t op_flags)
 {
 	struct closure *cl = &ca->prio;
 	struct bio *bio = bch_bbio_alloc(ca->set);
author reviewer
#26 lore raw

PATCH 24/51 md/raid1: Use the new blk_opf_t type

In reply to Bart Van Assche

Improve static type checking by using the new blk_opf_t type for variables that represent request flags.

---
 drivers/md/raid1.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/raid1.c +1 -1
index 258d4eb2d63c..63b3f70abbc3 100644
@@ -1221,7 +1221,7 @@ static void raid1_read_request(struct mddev *mddev, struct bio *bio,
 	struct bio *read_bio;
 	struct bitmap *bitmap = mddev->bitmap;
 	const int op = bio_op(bio);
-	const unsigned long do_sync = (bio->bi_opf & REQ_SYNC);
+	const blk_opf_t do_sync = bio->bi_opf & REQ_SYNC;
 	int max_sectors;
 	int rdisk;
 	bool r1bio_existed = !!r1_bio;
author reviewer
#27 lore raw

PATCH 25/51 md/raid10: Use the new blk_opf_t type

In reply to Bart Van Assche

Improve static type checking by using the new blk_opf_t type for variables that represent a request flags.

---
 drivers/md/raid10.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/md/raid10.c +3 -3
index d589f823feb1..649635e04e38 100644
@@ -1137,7 +1137,7 @@ static void raid10_read_request(struct mddev *mddev, struct bio *bio,
 	struct r10conf *conf = mddev->private;
 	struct bio *read_bio;
 	const int op = bio_op(bio);
-	const unsigned long do_sync = (bio->bi_opf & REQ_SYNC);
+	const blk_opf_t do_sync = bio->bi_opf & REQ_SYNC;
 	int max_sectors;
 	struct md_rdev *rdev;
 	char b[BDEVNAME_SIZE];
@@ -1231,8 +1231,8 @@ static void raid10_write_one_disk(struct mddev *mddev, struct r10bio *r10_bio,
 				  int n_copy)
 {
 	const int op = bio_op(bio);
-	const unsigned long do_sync = (bio->bi_opf & REQ_SYNC);
-	const unsigned long do_fua = (bio->bi_opf & REQ_FUA);
+	const blk_opf_t do_sync = bio->bi_opf & REQ_SYNC;
+	const blk_opf_t do_fua = bio->bi_opf & REQ_FUA;
 	unsigned long flags;
 	struct blk_plug_cb *cb;
 	struct raid1_plug_cb *plug = NULL;
author reviewer
#28 lore raw

PATCH 26/51 md/raid5: Use the enum req_op and blk_opf_t types

In reply to Bart Van Assche

Improve static type checking by using the enum req_op type for variables that represent a request operation and the new blk_opf_t type for variables that represent request flags.

---
 drivers/md/raid5.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/md/raid5.c +3 -2
index 5d09256d7f81..b11d8b6a2dc2 100644
@@ -1082,7 +1082,8 @@ static void ops_run_io(struct stripe_head *sh, struct stripe_head_state *s)
 	should_defer = conf->batch_bio_dispatch && conf->group_cnt;
 
 	for (i = disks; i--; ) {
-		int op, op_flags = 0;
+		enum req_op op;
+		blk_opf_t op_flags = 0;
 		int replace_only = 0;
 		struct bio *bi, *rbi;
 		struct md_rdev *rdev, *rrdev = NULL;
@@ -5896,7 +5897,7 @@ static bool raid5_make_request(struct mddev *mddev, struct bio * bi)
 			(unsigned long long)logical_sector);
 
 		sh = raid5_get_active_stripe(conf, new_sector, previous,
-				       (bi->bi_opf & REQ_RAHEAD), 0);
+					     !!(bi->bi_opf & REQ_RAHEAD), 0);
 		if (sh) {
 			if (unlikely(previous)) {
 				/* expansion might have moved on while waiting for a
author reviewer
#29 lore raw

PATCH 27/51 nvme/host: Use the enum req_op and blk_opf_t types

In reply to Bart Van Assche

Improve static type checking by using the enum req_op type for variables that represent a request operation and the new blk_opf_t type for variables that represent request flags.

Cc Christoph Hellwig <[email protected]>
Cc Keith Busch <[email protected]>
Cc Sagi Grimberg <[email protected]>
---
 drivers/nvme/host/ioctl.c | 4 ++--
 drivers/nvme/host/nvme.h  | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/nvme/host/ioctl.c +2 -2
index a2e89db1cd63..27614bee7380 100644
@@ -68,7 +68,7 @@ static struct request *nvme_alloc_user_request(struct request_queue *q,
 		struct nvme_command *cmd, void __user *ubuffer,
 		unsigned bufflen, void __user *meta_buffer, unsigned meta_len,
 		u32 meta_seed, void **metap, unsigned timeout, bool vec,
-		unsigned int rq_flags, blk_mq_req_flags_t blk_flags)
+		blk_opf_t rq_flags, blk_mq_req_flags_t blk_flags)
 {
 	bool write = nvme_is_write(cmd);
 	struct nvme_ns *ns = q->queuedata;
@@ -407,7 +407,7 @@ static int nvme_uring_cmd_io(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
 	struct nvme_uring_data d;
 	struct nvme_command c;
 	struct request *req;
-	unsigned int rq_flags = 0;
+	blk_opf_t rq_flags = 0;
 	blk_mq_req_flags_t blk_flags = 0;
 	void *meta = NULL;
 
drivers/nvme/host/nvme.h +1 -1
index 0da94b233fed..ac9753674d5d 100644
@@ -733,7 +733,7 @@ void nvme_wait_freeze(struct nvme_ctrl *ctrl);
 int nvme_wait_freeze_timeout(struct nvme_ctrl *ctrl, long timeout);
 void nvme_start_freeze(struct nvme_ctrl *ctrl);
 
-static inline unsigned int nvme_req_op(struct nvme_command *cmd)
+static inline enum req_op nvme_req_op(struct nvme_command *cmd)
 {
 	return nvme_is_write(cmd) ? REQ_OP_DRV_OUT : REQ_OP_DRV_IN;
 }
author reviewer
#31 lore raw

PATCH 28/51 nvme/target: Use the new blk_opf_t type

In reply to Bart Van Assche

Improve static type checking by using the new blk_opf_t type for variables that represent a request operation combined with request flags.

Cc Christoph Hellwig <[email protected]>
Cc Sagi Grimberg <[email protected]>
Cc Chaitanya Kulkarni <[email protected]>
---
 drivers/nvme/target/io-cmd-bdev.c | 3 ++-
 drivers/nvme/target/zns.c         | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)
drivers/nvme/target/io-cmd-bdev.c +2 -1
index 27a72504d31c..306d97b3840f 100644
@@ -246,7 +246,8 @@ static void nvmet_bdev_execute_rw(struct nvmet_req *req)
 	struct scatterlist *sg;
 	struct blk_plug plug;
 	sector_t sector;
-	int op, i, rc;
+	blk_opf_t op;
+	int i, rc;
 	struct sg_mapping_iter prot_miter;
 	unsigned int iter_flags;
 	unsigned int total_len = nvmet_rw_data_len(req) + req->metadata_len;
drivers/nvme/target/zns.c +1 -1
index 62afb7936132..c5e315d57d60 100644
@@ -525,7 +525,7 @@ static void nvmet_bdev_zone_append_bio_done(struct bio *bio)
 void nvmet_bdev_execute_zone_append(struct nvmet_req *req)
 {
 	sector_t sect = nvmet_lba_to_sect(req->ns, req->cmd->rw.slba);
-	const unsigned int op = REQ_OP_ZONE_APPEND | REQ_SYNC | REQ_IDLE;
+	const blk_opf_t op = REQ_OP_ZONE_APPEND | REQ_SYNC | REQ_IDLE;
 	u16 status = NVME_SC_SUCCESS;
 	unsigned int total_len = 0;
 	struct scatterlist *sg;
author reviewer
#33 lore raw

PATCH 29/51 scsi/core: Improve static type checking

In reply to Bart Van Assche

Improve static type checking by using enum req_op where appropriate.

Cc Martin K. Petersen <[email protected]>
Cc John Garry <[email protected]>
Cc Mike Christie <[email protected]>
---
 drivers/scsi/scsi_lib.c  | 4 ++--
 include/scsi/scsi_cmnd.h | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/scsi/scsi_lib.c +2 -2
index 6ffc9e4258a8..6b6a7a4b0950 100644
@@ -1125,8 +1125,8 @@ static void scsi_initialize_rq(struct request *rq)
 	cmd->retries = 0;
 }
 
-struct request *scsi_alloc_request(struct request_queue *q,
-		unsigned int op, blk_mq_req_flags_t flags)
+struct request *scsi_alloc_request(struct request_queue *q, enum req_op op,
+				   blk_mq_req_flags_t flags)
 {
 	struct request *rq;
 
include/scsi/scsi_cmnd.h +1 -1
index 1e80e70dfa92..6df0af7dd508 100644
@@ -387,6 +387,6 @@ extern void scsi_build_sense(struct scsi_cmnd *scmd, int desc,
 			     u8 key, u8 asc, u8 ascq);
 
 struct request *scsi_alloc_request(struct request_queue *q,
-		unsigned int op, blk_mq_req_flags_t flags);
+		enum req_op op, blk_mq_req_flags_t flags);
 
 #endif /* _SCSI_SCSI_CMND_H */
author reviewer
#34 lore raw

PATCH 30/51 scsi/core: Change the return type of scsi_noretry_cmd() into bool

In reply to Bart Van Assche

This patch prepares for introducing the new blk_opf_t type in the SCSI core. Since the value returned by scsi_noretry_cmd() is only used in boolean expressions, this patch does not change any functionality.

Cc Martin K. Petersen <[email protected]>
Cc John Garry <[email protected]>
Cc Mike Christie <[email protected]>
---
 drivers/scsi/scsi_error.c | 10 +++++-----
 drivers/scsi/scsi_priv.h  |  2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/scsi/scsi_error.c +5 -5
index 49ef864df581..60bcb37acafd 100644
@@ -1779,7 +1779,7 @@ static void scsi_eh_offline_sdevs(struct list_head *work_q,
  * scsi_noretry_cmd - determine if command should be failed fast
  * @scmd:	SCSI cmd to examine.
  */
-int scsi_noretry_cmd(struct scsi_cmnd *scmd)
+bool scsi_noretry_cmd(struct scsi_cmnd *scmd)
 {
 	struct request *req = scsi_cmd_to_rq(scmd);
 
@@ -1794,14 +1794,14 @@ int scsi_noretry_cmd(struct scsi_cmnd *scmd)
 		return req->cmd_flags & REQ_FAILFAST_DEV;
 	case DID_ERROR:
 		if (get_status_byte(scmd) == SAM_STAT_RESERVATION_CONFLICT)
-			return 0;
+			return false;
 		fallthrough;
 	case DID_SOFT_ERROR:
 		return req->cmd_flags & REQ_FAILFAST_DRIVER;
 	}
 
 	if (!scsi_status_is_check_condition(scmd->result))
-		return 0;
+		return false;
 
 check_type:
 	/*
@@ -1809,9 +1809,9 @@ int scsi_noretry_cmd(struct scsi_cmnd *scmd)
 	 * the check condition was retryable.
 	 */
 	if (req->cmd_flags & REQ_FAILFAST_DEV || blk_rq_is_passthrough(req))
-		return 1;
+		return true;
 
-	return 0;
+	return false;
 }
 
 /**
drivers/scsi/scsi_priv.h +1 -1
index 5c4786310a31..90fbffca7eb0 100644
@@ -82,7 +82,7 @@ void scsi_eh_ready_devs(struct Scsi_Host *shost,
 			struct list_head *done_q);
 int scsi_eh_get_sense(struct list_head *work_q,
 		      struct list_head *done_q);
-int scsi_noretry_cmd(struct scsi_cmnd *scmd);
+bool scsi_noretry_cmd(struct scsi_cmnd *scmd);
 void scsi_eh_done(struct scsi_cmnd *scmd);
 
 /* scsi_lib.c */
author reviewer
#35 lore raw

PATCH 31/51 scsi/core: Use the new blk_opf_t type

In reply to Bart Van Assche

Use the new blk_opf_t type for arguments and variables that represent request flags. Use the !! operator in scsi_noretry_cmd() to convert the blk_opf_t type into a boolean. This patch does not change any functionality.

Cc Martin K. Petersen <[email protected]>
Cc John Garry <[email protected]>
Cc Mike Christie <[email protected]>
---
 drivers/scsi/scsi_error.c  | 6 +++---
 drivers/scsi/scsi_lib.c    | 6 +++---
 include/scsi/scsi_device.h | 2 +-
 3 files changed, 7 insertions(+), 7 deletions(-)
drivers/scsi/scsi_error.c +3 -3
index 60bcb37acafd..4b8686162ddd 100644
@@ -1789,15 +1789,15 @@ bool scsi_noretry_cmd(struct scsi_cmnd *scmd)
 	case DID_TIME_OUT:
 		goto check_type;
 	case DID_BUS_BUSY:
-		return req->cmd_flags & REQ_FAILFAST_TRANSPORT;
+		return !!(req->cmd_flags & REQ_FAILFAST_TRANSPORT);
 	case DID_PARITY:
-		return req->cmd_flags & REQ_FAILFAST_DEV;
+		return !!(req->cmd_flags & REQ_FAILFAST_DEV);
 	case DID_ERROR:
 		if (get_status_byte(scmd) == SAM_STAT_RESERVATION_CONFLICT)
 			return false;
 		fallthrough;
 	case DID_SOFT_ERROR:
-		return req->cmd_flags & REQ_FAILFAST_DRIVER;
+		return !!(req->cmd_flags & REQ_FAILFAST_DRIVER);
 	}
 
 	if (!scsi_status_is_check_condition(scmd->result))
drivers/scsi/scsi_lib.c +3 -3
index 6b6a7a4b0950..beff0015258a 100644
@@ -209,8 +209,8 @@ void scsi_queue_insert(struct scsi_cmnd *cmd, int reason)
 int __scsi_execute(struct scsi_device *sdev, const unsigned char *cmd,
 		 int data_direction, void *buffer, unsigned bufflen,
 		 unsigned char *sense, struct scsi_sense_hdr *sshdr,
-		 int timeout, int retries, u64 flags, req_flags_t rq_flags,
-		 int *resid)
+		 int timeout, int retries, blk_opf_t flags,
+		 req_flags_t rq_flags, int *resid)
 {
 	struct request *req;
 	struct scsi_cmnd *scmd;
@@ -633,7 +633,7 @@ static blk_status_t scsi_result_to_blk_status(struct scsi_cmnd *cmd, int result)
  */
 static unsigned int scsi_rq_err_bytes(const struct request *rq)
 {
-	unsigned int ff = rq->cmd_flags & REQ_FAILFAST_MASK;
+	blk_opf_t ff = rq->cmd_flags & REQ_FAILFAST_MASK;
 	unsigned int bytes = 0;
 	struct bio *bio;
 
include/scsi/scsi_device.h +1 -1
index 7cf5f3b7589f..2493bd65351a 100644
@@ -457,7 +457,7 @@ extern void scsi_sanitize_inquiry_string(unsigned char *s, int len);
 extern int __scsi_execute(struct scsi_device *sdev, const unsigned char *cmd,
 			int data_direction, void *buffer, unsigned bufflen,
 			unsigned char *sense, struct scsi_sense_hdr *sshdr,
-			int timeout, int retries, u64 flags,
+			int timeout, int retries, blk_opf_t flags,
 			req_flags_t rq_flags, int *resid);
 /* Make sure any sense buffer is the correct size. */
 #define scsi_execute(sdev, cmd, data_direction, buffer, bufflen, sense,	\
author reviewer
#36 lore raw

PATCH 32/51 scsi/device_handlers: Use the new blk_opf_t type

In reply to Bart Van Assche

Improve static type checking by using the new blk_opf_t type for variables that represent request flags.

---
 drivers/scsi/device_handler/scsi_dh_alua.c  | 4 ++--
 drivers/scsi/device_handler/scsi_dh_emc.c   | 2 +-
 drivers/scsi/device_handler/scsi_dh_hp_sw.c | 4 ++--
 drivers/scsi/device_handler/scsi_dh_rdac.c  | 2 +-
 4 files changed, 6 insertions(+), 6 deletions(-)
drivers/scsi/device_handler/scsi_dh_alua.c +2 -2
index 1d9be771f3ee..610a51538f03 100644
@@ -127,7 +127,7 @@ static int submit_rtpg(struct scsi_device *sdev, unsigned char *buff,
 		       int bufflen, struct scsi_sense_hdr *sshdr, int flags)
 {
 	u8 cdb[MAX_COMMAND_SIZE];
-	int req_flags = REQ_FAILFAST_DEV | REQ_FAILFAST_TRANSPORT |
+	blk_opf_t req_flags = REQ_FAILFAST_DEV | REQ_FAILFAST_TRANSPORT |
 		REQ_FAILFAST_DRIVER;
 
 	/* Prepare the command. */
@@ -157,7 +157,7 @@ static int submit_stpg(struct scsi_device *sdev, int group_id,
 	u8 cdb[MAX_COMMAND_SIZE];
 	unsigned char stpg_data[8];
 	int stpg_len = 8;
-	int req_flags = REQ_FAILFAST_DEV | REQ_FAILFAST_TRANSPORT |
+	blk_opf_t req_flags = REQ_FAILFAST_DEV | REQ_FAILFAST_TRANSPORT |
 		REQ_FAILFAST_DRIVER;
 
 	/* Prepare the data buffer */
drivers/scsi/device_handler/scsi_dh_emc.c +1 -1
index bd28ec6cfb72..2e21ab447873 100644
@@ -239,7 +239,7 @@ static int send_trespass_cmd(struct scsi_device *sdev,
 	unsigned char cdb[MAX_COMMAND_SIZE];
 	int err, res = SCSI_DH_OK, len;
 	struct scsi_sense_hdr sshdr;
-	u64 req_flags = REQ_FAILFAST_DEV | REQ_FAILFAST_TRANSPORT |
+	blk_opf_t req_flags = REQ_FAILFAST_DEV | REQ_FAILFAST_TRANSPORT |
 		REQ_FAILFAST_DRIVER;
 
 	if (csdev->flags & CLARIION_SHORT_TRESPASS) {
drivers/scsi/device_handler/scsi_dh_hp_sw.c +2 -2
index 4a3f7831a2d6..0d2cfa60aa06 100644
@@ -83,7 +83,7 @@ static int hp_sw_tur(struct scsi_device *sdev, struct hp_sw_dh_data *h)
 	unsigned char cmd[6] = { TEST_UNIT_READY };
 	struct scsi_sense_hdr sshdr;
 	int ret = SCSI_DH_OK, res;
-	u64 req_flags = REQ_FAILFAST_DEV | REQ_FAILFAST_TRANSPORT |
+	blk_opf_t req_flags = REQ_FAILFAST_DEV | REQ_FAILFAST_TRANSPORT |
 		REQ_FAILFAST_DRIVER;
 
 retry:
@@ -121,7 +121,7 @@ static int hp_sw_start_stop(struct hp_sw_dh_data *h)
 	struct scsi_device *sdev = h->sdev;
 	int res, rc = SCSI_DH_OK;
 	int retry_cnt = HP_SW_RETRIES;
-	u64 req_flags = REQ_FAILFAST_DEV | REQ_FAILFAST_TRANSPORT |
+	blk_opf_t req_flags = REQ_FAILFAST_DEV | REQ_FAILFAST_TRANSPORT |
 		REQ_FAILFAST_DRIVER;
 
 retry:
drivers/scsi/device_handler/scsi_dh_rdac.c +1 -1
index 66652ab409cc..bf8754741f85 100644
@@ -536,7 +536,7 @@ static void send_mode_select(struct work_struct *work)
 	unsigned char cdb[MAX_COMMAND_SIZE];
 	struct scsi_sense_hdr sshdr;
 	unsigned int data_size;
-	u64 req_flags = REQ_FAILFAST_DEV | REQ_FAILFAST_TRANSPORT |
+	blk_opf_t req_flags = REQ_FAILFAST_DEV | REQ_FAILFAST_TRANSPORT |
 		REQ_FAILFAST_DRIVER;
 
 	spin_lock(&ctlr->ms_lock);
author reviewer
#37 lore raw

PATCH 33/51 scsi/ufs: Rename a 'dir' argument into 'op'

In reply to Bart Van Assche

Improve consistency of the kernel code by renaming a request operation argument from 'dir' into 'op'.

Cc Martin K. Petersen <[email protected]>
Cc Avri Altman <[email protected]>
---
 drivers/ufs/core/ufshpb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/ufs/core/ufshpb.c +2 -2
index 24f1ee82c215..a1a7a1175a5a 100644
@@ -434,7 +434,7 @@ int ufshpb_prep(struct ufs_hba *hba, struct ufshcd_lrb *lrbp)
 }
 
 static struct ufshpb_req *ufshpb_get_req(struct ufshpb_lu *hpb, int rgn_idx,
-					 enum req_op dir, bool atomic)
+					 enum req_op op, bool atomic)
 {
 	struct ufshpb_req *rq;
 	struct request *req;
@@ -445,7 +445,7 @@ static struct ufshpb_req *ufshpb_get_req(struct ufshpb_lu *hpb, int rgn_idx,
 		return NULL;
 
 retry:
-	req = blk_mq_alloc_request(hpb->sdev_ufs_lu->request_queue, dir,
+	req = blk_mq_alloc_request(hpb->sdev_ufs_lu->request_queue, op,
 			      BLK_MQ_REQ_NOWAIT);
 
 	if (!atomic && (PTR_ERR(req) == -EWOULDBLOCK) && (--retries > 0)) {
author reviewer
#39 lore raw

PATCH 34/51 scsi/target: Use the new blk_opf_t type

In reply to Bart Van Assche

Improve static type checking by using the new blk_opf_t type for variables that represent a request operation combined with request flags.

---
 drivers/target/target_core_iblock.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/target/target_core_iblock.c +2 -2
index 378c80313a0f..5fef19af88df 100644
@@ -343,7 +343,7 @@ static void iblock_bio_done(struct bio *bio)
 }
 
 static struct bio *iblock_get_bio(struct se_cmd *cmd, sector_t lba, u32 sg_num,
-				  unsigned int opf)
+				  blk_opf_t opf)
 {
 	struct iblock_dev *ib_dev = IBLOCK_DEV(cmd->se_dev);
 	struct bio *bio;
@@ -719,7 +719,7 @@ iblock_execute_rw(struct se_cmd *cmd, struct scatterlist *sgl, u32 sgl_nents,
 	struct bio_list list;
 	struct scatterlist *sg;
 	u32 sg_num = sgl_nents;
-	unsigned int opf;
+	blk_opf_t opf;
 	unsigned bio_cnt;
 	int i, rc;
 	struct sg_mapping_iter prot_miter;
author reviewer
#40 lore raw

PATCH 35/51 mm: Use the new blk_opf_t type

In reply to Bart Van Assche

Improve static type checking by using the new blk_opf_t type for block layer request flags.

Cc Andrew Morton <[email protected]>
Cc Christoph Hellwig <[email protected]>
---
 include/linux/writeback.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/writeback.h +2 -2
index b8c9610c2313..3f045f6d6c4f 100644
@@ -101,9 +101,9 @@ struct writeback_control {
 #endif
 };
 
-static inline int wbc_to_write_flags(struct writeback_control *wbc)
+static inline blk_opf_t wbc_to_write_flags(struct writeback_control *wbc)
 {
-	int flags = 0;
+	blk_opf_t flags = 0;
 
 	if (wbc->punt_to_cgroup)
 		flags = REQ_CGROUP_PUNT;
author reviewer
#41 lore raw

PATCH 36/51 fs/buffer: Use the new blk_opf_t type

In reply to Bart Van Assche

Improve static type checking by using the new blk_opf_t type for block layer request flags. Change WRITE into REQ_OP_WRITE. This patch does not change any functionality since REQ_OP_WRITE == WRITE == 1.

Cc Christoph Hellwig <[email protected]>
Cc Matthew Wilcox <[email protected]>
Cc Jan Kara <[email protected]>
---
 fs/buffer.c                 | 21 +++++++++++----------
 include/linux/buffer_head.h |  9 +++++----
 2 files changed, 16 insertions(+), 14 deletions(-)
fs/buffer.c +11 -10
index 898c7f301b1b..4a00b61f35ec 100644
@@ -52,8 +52,8 @@
 #include "internal.h"
 
 static int fsync_buffers_list(spinlock_t *lock, struct list_head *list);
-static int submit_bh_wbc(int op, int op_flags, struct buffer_head *bh,
-			 struct writeback_control *wbc);
+static int submit_bh_wbc(enum req_op op, blk_opf_t op_flags,
+			 struct buffer_head *bh, struct writeback_control *wbc);
 
 #define BH_ENTRY(list) list_entry((list), struct buffer_head, b_assoc_buffers)
 
@@ -1716,7 +1716,7 @@ int __block_write_full_page(struct inode *inode, struct page *page,
 	struct buffer_head *bh, *head;
 	unsigned int blocksize, bbits;
 	int nr_underway = 0;
-	int write_flags = wbc_to_write_flags(wbc);
+	blk_opf_t write_flags = wbc_to_write_flags(wbc);
 
 	head = create_page_buffers(page, inode,
 					(1 << BH_Dirty)|(1 << BH_Uptodate));
@@ -2994,8 +2994,8 @@ static void end_bio_bh_io_sync(struct bio *bio)
 	bio_put(bio);
 }
 
-static int submit_bh_wbc(int op, int op_flags, struct buffer_head *bh,
-			 struct writeback_control *wbc)
+static int submit_bh_wbc(enum req_op op, blk_opf_t op_flags,
+			 struct buffer_head *bh, struct writeback_control *wbc)
 {
 	struct bio *bio;
 
@@ -3040,7 +3040,7 @@ static int submit_bh_wbc(int op, int op_flags, struct buffer_head *bh,
 	return 0;
 }
 
-int submit_bh(int op, int op_flags, struct buffer_head *bh)
+int submit_bh(enum req_op op, blk_opf_t op_flags, struct buffer_head *bh)
 {
 	return submit_bh_wbc(op, op_flags, bh, NULL);
 }
@@ -3072,7 +3072,8 @@ EXPORT_SYMBOL(submit_bh);
  * All of the buffers must be for the same device, and must also be a
  * multiple of the current approved size for the device.
  */
-void ll_rw_block(int op, int op_flags,  int nr, struct buffer_head *bhs[])
+void ll_rw_block(enum req_op op, blk_opf_t op_flags, int nr,
+		 struct buffer_head *bhs[])
 {
 	int i;
 
@@ -3081,7 +3082,7 @@ void ll_rw_block(int op, int op_flags,  int nr, struct buffer_head *bhs[])
 
 		if (!trylock_buffer(bh))
 			continue;
-		if (op == WRITE) {
+		if (op == REQ_OP_WRITE) {
 			if (test_clear_buffer_dirty(bh)) {
 				bh->b_end_io = end_buffer_write_sync;
 				get_bh(bh);
@@ -3101,7 +3102,7 @@ void ll_rw_block(int op, int op_flags,  int nr, struct buffer_head *bhs[])
 }
 EXPORT_SYMBOL(ll_rw_block);
 
-void write_dirty_buffer(struct buffer_head *bh, int op_flags)
+void write_dirty_buffer(struct buffer_head *bh, blk_opf_t op_flags)
 {
 	lock_buffer(bh);
 	if (!test_clear_buffer_dirty(bh)) {
@@ -3119,7 +3120,7 @@ EXPORT_SYMBOL(write_dirty_buffer);
  * and then start new I/O and then wait upon it.  The caller must have a ref on
  * the buffer_head.
  */
-int __sync_dirty_buffer(struct buffer_head *bh, int op_flags)
+int __sync_dirty_buffer(struct buffer_head *bh, blk_opf_t op_flags)
 {
 	int ret = 0;
 
include/linux/buffer_head.h +5 -4
index c9d1463bb20f..9795df9400bd 100644
@@ -9,6 +9,7 @@
 #define _LINUX_BUFFER_HEAD_H
 
 #include <linux/types.h>
+#include <linux/blk_types.h>
 #include <linux/fs.h>
 #include <linux/linkage.h>
 #include <linux/pagemap.h>
@@ -201,11 +202,11 @@ struct buffer_head *alloc_buffer_head(gfp_t gfp_flags);
 void free_buffer_head(struct buffer_head * bh);
 void unlock_buffer(struct buffer_head *bh);
 void __lock_buffer(struct buffer_head *bh);
-void ll_rw_block(int, int, int, struct buffer_head * bh[]);
+void ll_rw_block(enum req_op, blk_opf_t, int, struct buffer_head * bh[]);
 int sync_dirty_buffer(struct buffer_head *bh);
-int __sync_dirty_buffer(struct buffer_head *bh, int op_flags);
-void write_dirty_buffer(struct buffer_head *bh, int op_flags);
-int submit_bh(int, int, struct buffer_head *);
+int __sync_dirty_buffer(struct buffer_head *bh, blk_opf_t op_flags);
+void write_dirty_buffer(struct buffer_head *bh, blk_opf_t op_flags);
+int submit_bh(enum req_op, blk_opf_t, struct buffer_head *);
 void write_boundary_block(struct block_device *bdev,
 			sector_t bblock, unsigned blocksize);
 int bh_uptodate_or_lock(struct buffer_head *bh);
author reviewer
#42 lore raw

PATCH 37/51 fs/direct-io: Use the enum req_op and blk_opf_t types

In reply to Bart Van Assche

Improve static type checking by using the enum req_op type for block layer request operations and the new blk_opf_t type for block layer request flags.

Cc Al Viro <[email protected]>
Cc Christoph Hellwig <[email protected]>
---
 fs/direct-io.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/direct-io.c +2 -2
index 840752006f60..9cfbb37ec62a 100644
@@ -117,8 +117,8 @@ struct dio_submit {
 /* dio_state communicated between submission path and end_io */
 struct dio {
 	int flags;			/* doesn't change */
-	int op;
-	int op_flags;
+	enum req_op op;
+	blk_opf_t op_flags;
 	struct gendisk *bio_disk;
 	struct inode *inode;
 	loff_t i_size;			/* i_size when submitted */
author reviewer
#43 lore raw

PATCH 38/51 fs/mpage: Use the new blk_opf_t type

In reply to Bart Van Assche

Improve static type checking by using the new blk_opf_t type for the combination of a block layer request with block layer request flags.

Cc Al Viro <[email protected]>
Cc Christoph Hellwig <[email protected]>
---
 fs/mpage.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/mpage.c +1 -1
index 0d25f44f5707..5830705672dd 100644
@@ -145,7 +145,7 @@ static struct bio *do_mpage_readpage(struct mpage_readpage_args *args)
 	struct block_device *bdev = NULL;
 	int length;
 	int fully_mapped = 1;
-	int op = REQ_OP_READ;
+	blk_opf_t op = REQ_OP_READ;
 	unsigned nblocks;
 	unsigned relative_block;
 	gfp_t gfp = mapping_gfp_constraint(page->mapping, GFP_KERNEL);
author reviewer
#44 lore raw

PATCH 39/51 fs/btrfs: Use the enum req_op and blk_opf_t types

In reply to Bart Van Assche

Improve static type checking by using the enum req_op type for variables that represent a request operation and the new blk_opf_t type for variables that represent request flags.

Cc David Sterba <[email protected]>
Cc Josef Bacik <[email protected]>
---
 fs/btrfs/check-integrity.c |  4 ++--
 fs/btrfs/compression.c     |  6 +++---
 fs/btrfs/compression.h     |  2 +-
 fs/btrfs/extent_io.c       | 18 +++++++++---------
 fs/btrfs/inode.c           |  4 ++--
 fs/btrfs/raid56.c          |  4 ++--
 6 files changed, 19 insertions(+), 19 deletions(-)
fs/btrfs/check-integrity.c +2 -2
index 5d20137b7b67..98c6e5feab19 100644
@@ -152,7 +152,7 @@ struct btrfsic_block {
 	struct btrfsic_block *next_in_same_bio;
 	void *orig_bio_private;
 	bio_end_io_t *orig_bio_end_io;
-	int submit_bio_bh_rw;
+	blk_opf_t submit_bio_bh_rw;
 	u64 flush_gen; /* only valid if !never_written */
 };
 
@@ -1681,7 +1681,7 @@ static void btrfsic_process_written_block(struct btrfsic_dev_state *dev_state,
 					  u64 dev_bytenr, char **mapped_datav,
 					  unsigned int num_pages,
 					  struct bio *bio, int *bio_is_patched,
-					  int submit_bio_bh_rw)
+					  blk_opf_t submit_bio_bh_rw)
 {
 	int is_metadata;
 	struct btrfsic_block *block;
fs/btrfs/compression.c +3 -3
index f4564f32f6d9..a82b9f17f476 100644
@@ -455,7 +455,7 @@ static blk_status_t submit_compressed_bio(struct btrfs_fs_info *fs_info,
 
 
 static struct bio *alloc_compressed_bio(struct compressed_bio *cb, u64 disk_bytenr,
-					unsigned int opf, bio_end_io_t endio_func,
+					blk_opf_t opf, bio_end_io_t endio_func,
 					u64 *next_stripe_start)
 {
 	struct btrfs_fs_info *fs_info = btrfs_sb(cb->inode->i_sb);
@@ -505,7 +505,7 @@ blk_status_t btrfs_submit_compressed_write(struct btrfs_inode *inode, u64 start,
 				 unsigned int compressed_len,
 				 struct page **compressed_pages,
 				 unsigned int nr_pages,
-				 unsigned int write_flags,
+				 blk_opf_t write_flags,
 				 struct cgroup_subsys_state *blkcg_css,
 				 bool writeback)
 {
@@ -517,7 +517,7 @@ blk_status_t btrfs_submit_compressed_write(struct btrfs_inode *inode, u64 start,
 	blk_status_t ret;
 	int skip_sum = inode->flags & BTRFS_INODE_NODATASUM;
 	const bool use_append = btrfs_use_zone_append(inode, disk_start);
-	const unsigned int bio_op = use_append ? REQ_OP_ZONE_APPEND : REQ_OP_WRITE;
+	const enum req_op bio_op = use_append ? REQ_OP_ZONE_APPEND : REQ_OP_WRITE;
 
 	ASSERT(IS_ALIGNED(start, fs_info->sectorsize) &&
 	       IS_ALIGNED(len, fs_info->sectorsize));
fs/btrfs/compression.h +1 -1
index 2707404389a5..2b56d63e01ce 100644
@@ -99,7 +99,7 @@ blk_status_t btrfs_submit_compressed_write(struct btrfs_inode *inode, u64 start,
 				  unsigned int compressed_len,
 				  struct page **compressed_pages,
 				  unsigned int nr_pages,
-				  unsigned int write_flags,
+				  blk_opf_t write_flags,
 				  struct cgroup_subsys_state *blkcg_css,
 				  bool writeback);
 void btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
fs/btrfs/extent_io.c +9 -9
index 8f6b544ae616..10f8df7f883d 100644
@@ -3357,7 +3357,7 @@ static int calc_bio_boundaries(struct btrfs_bio_ctrl *bio_ctrl,
 static int alloc_new_bio(struct btrfs_inode *inode,
 			 struct btrfs_bio_ctrl *bio_ctrl,
 			 struct writeback_control *wbc,
-			 unsigned int opf,
+			 blk_opf_t opf,
 			 bio_end_io_t end_io_func,
 			 u64 disk_bytenr, u32 offset, u64 file_offset,
 			 enum btrfs_compression_type compress_type)
@@ -3437,7 +3437,7 @@ static int alloc_new_bio(struct btrfs_inode *inode,
  * @prev_bio_flags:  flags of previous bio to see if we can merge the current one
  * @compress_type:   compress type for current bio
  */
-static int submit_extent_page(unsigned int opf,
+static int submit_extent_page(blk_opf_t opf,
 			      struct writeback_control *wbc,
 			      struct btrfs_bio_ctrl *bio_ctrl,
 			      struct page *page, u64 disk_bytenr,
@@ -3615,7 +3615,7 @@ __get_extent_map(struct inode *inode, struct page *page, size_t pg_offset,
  */
 static int btrfs_do_readpage(struct page *page, struct extent_map **em_cached,
 		      struct btrfs_bio_ctrl *bio_ctrl,
-		      unsigned int read_flags, u64 *prev_em_start)
+		      blk_opf_t read_flags, u64 *prev_em_start)
 {
 	struct inode *inode = page->mapping->host;
 	struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
@@ -3983,8 +3983,8 @@ static noinline_for_stack int __extent_writepage_io(struct btrfs_inode *inode,
 	int saved_ret = 0;
 	int ret = 0;
 	int nr = 0;
-	u32 opf = REQ_OP_WRITE;
-	const unsigned int write_flags = wbc_to_write_flags(wbc);
+	enum req_op op = REQ_OP_WRITE;
+	const blk_opf_t write_flags = wbc_to_write_flags(wbc);
 	bool has_error = false;
 	bool compressed;
 
@@ -4058,7 +4058,7 @@ static noinline_for_stack int __extent_writepage_io(struct btrfs_inode *inode,
 		iosize = min(min(em_end, end + 1), dirty_range_end) - cur;
 
 		if (btrfs_use_zone_append(inode, em->block_start))
-			opf = REQ_OP_ZONE_APPEND;
+			op = REQ_OP_ZONE_APPEND;
 
 		free_extent_map(em);
 		em = NULL;
@@ -4094,7 +4094,7 @@ static noinline_for_stack int __extent_writepage_io(struct btrfs_inode *inode,
 		 */
 		btrfs_page_clear_dirty(fs_info, page, cur, iosize);
 
-		ret = submit_extent_page(opf | write_flags, wbc,
+		ret = submit_extent_page(op | write_flags, wbc,
 					 &epd->bio_ctrl, page,
 					 disk_bytenr, iosize,
 					 cur - page_offset(page),
@@ -4575,7 +4575,7 @@ static int write_one_subpage_eb(struct extent_buffer *eb,
 {
 	struct btrfs_fs_info *fs_info = eb->fs_info;
 	struct page *page = eb->pages[0];
-	unsigned int write_flags = wbc_to_write_flags(wbc) | REQ_META;
+	blk_opf_t write_flags = wbc_to_write_flags(wbc) | REQ_META;
 	bool no_dirty_ebs = false;
 	int ret;
 
@@ -4620,7 +4620,7 @@ static noinline_for_stack int write_one_eb(struct extent_buffer *eb,
 {
 	u64 disk_bytenr = eb->start;
 	int i, num_pages;
-	unsigned int write_flags = wbc_to_write_flags(wbc) | REQ_META;
+	blk_opf_t write_flags = wbc_to_write_flags(wbc) | REQ_META;
 	int ret = 0;
 
 	prepare_eb_write(eb);
fs/btrfs/inode.c +2 -2
index 81737eff92f3..724f8f7e3599 100644
@@ -485,7 +485,7 @@ struct async_chunk {
 	struct page *locked_page;
 	u64 start;
 	u64 end;
-	unsigned int write_flags;
+	blk_opf_t write_flags;
 	struct list_head extents;
 	struct cgroup_subsys_state *blkcg_css;
 	struct btrfs_work work;
@@ -1435,7 +1435,7 @@ static int cow_file_range_async(struct btrfs_inode *inode,
 	int i;
 	bool should_compress;
 	unsigned nofs_flag;
-	const unsigned int write_flags = wbc_to_write_flags(wbc);
+	const blk_opf_t write_flags = wbc_to_write_flags(wbc);
 
 	unlock_extent(&inode->io_tree, start, end);
 
fs/btrfs/raid56.c +2 -2
index a5b623ee6fac..c520412d1f86 100644
@@ -1136,7 +1136,7 @@ static int rbio_add_io_sector(struct btrfs_raid_bio *rbio,
 			      unsigned int stripe_nr,
 			      unsigned int sector_nr,
 			      unsigned long bio_max_len,
-			      unsigned int opf)
+			      enum req_op op)
 {
 	const u32 sectorsize = rbio->bioc->fs_info->sectorsize;
 	struct bio *last = bio_list->tail;
@@ -1181,7 +1181,7 @@ static int rbio_add_io_sector(struct btrfs_raid_bio *rbio,
 
 	/* put a new bio on the list */
 	bio = bio_alloc(stripe->dev->bdev, max(bio_max_len >> PAGE_SHIFT, 1UL),
-			opf, GFP_NOFS);
+			op, GFP_NOFS);
 	bio->bi_iter.bi_sector = disk_start >> 9;
 	bio->bi_private = rbio;
 
author reviewer
#45 lore raw

PATCH 40/51 fs/ext4: Use the new blk_opf_t type

In reply to Bart Van Assche

Improve static type checking by using the new blk_opf_t type for variables that represent request flags.

---
 fs/ext4/ext4.h        |  8 ++++----
 fs/ext4/fast_commit.c |  2 +-
 fs/ext4/super.c       | 14 +++++++-------
 3 files changed, 12 insertions(+), 12 deletions(-)
fs/ext4/ext4.h +4 -4
index 75b8d81b2469..29fc575a4eb6 100644
@@ -3058,14 +3058,14 @@ extern unsigned int ext4_list_backups(struct super_block *sb,
 
 /* super.c */
 extern struct buffer_head *ext4_sb_bread(struct super_block *sb,
-					 sector_t block, int op_flags);
+					 sector_t block, blk_opf_t op_flags);
 extern struct buffer_head *ext4_sb_bread_unmovable(struct super_block *sb,
 						   sector_t block);
-extern void ext4_read_bh_nowait(struct buffer_head *bh, int op_flags,
+extern void ext4_read_bh_nowait(struct buffer_head *bh, blk_opf_t op_flags,
 				bh_end_io_t *end_io);
-extern int ext4_read_bh(struct buffer_head *bh, int op_flags,
+extern int ext4_read_bh(struct buffer_head *bh, blk_opf_t op_flags,
 			bh_end_io_t *end_io);
-extern int ext4_read_bh_lock(struct buffer_head *bh, int op_flags, bool wait);
+extern int ext4_read_bh_lock(struct buffer_head *bh, blk_opf_t op_flags, bool wait);
 extern void ext4_sb_breadahead_unmovable(struct super_block *sb, sector_t block);
 extern int ext4_seq_options_show(struct seq_file *seq, void *offset);
 extern int ext4_calculate_overhead(struct super_block *sb);
fs/ext4/fast_commit.c +1 -1
index 795a60ad1897..de6c73d0f431 100644
@@ -658,7 +658,7 @@ void ext4_fc_track_range(handle_t *handle, struct inode *inode, ext4_lblk_t star
 
 static void ext4_fc_submit_bh(struct super_block *sb, bool is_tail)
 {
-	int write_flags = REQ_SYNC;
+	blk_opf_t write_flags = REQ_SYNC;
 	struct buffer_head *bh = EXT4_SB(sb)->s_fc_bh;
 
 	/* Add REQ_FUA | REQ_PREFLUSH only its tail */
fs/ext4/super.c +7 -7
index 845f2f8aee5f..1d7f65088ddc 100644
@@ -159,7 +159,7 @@ MODULE_ALIAS("ext3");
 #define IS_EXT3_SB(sb) ((sb)->s_bdev->bd_holder == &ext3_fs_type)
 
 
-static inline void __ext4_read_bh(struct buffer_head *bh, int op_flags,
+static inline void __ext4_read_bh(struct buffer_head *bh, blk_opf_t op_flags,
 				  bh_end_io_t *end_io)
 {
 	/*
@@ -174,7 +174,7 @@ static inline void __ext4_read_bh(struct buffer_head *bh, int op_flags,
 	submit_bh(REQ_OP_READ, op_flags, bh);
 }
 
-void ext4_read_bh_nowait(struct buffer_head *bh, int op_flags,
+void ext4_read_bh_nowait(struct buffer_head *bh, blk_opf_t op_flags,
 			 bh_end_io_t *end_io)
 {
 	BUG_ON(!buffer_locked(bh));
@@ -186,7 +186,7 @@ void ext4_read_bh_nowait(struct buffer_head *bh, int op_flags,
 	__ext4_read_bh(bh, op_flags, end_io);
 }
 
-int ext4_read_bh(struct buffer_head *bh, int op_flags, bh_end_io_t *end_io)
+int ext4_read_bh(struct buffer_head *bh, blk_opf_t op_flags, bh_end_io_t *end_io)
 {
 	BUG_ON(!buffer_locked(bh));
 
@@ -203,7 +203,7 @@ int ext4_read_bh(struct buffer_head *bh, int op_flags, bh_end_io_t *end_io)
 	return -EIO;
 }
 
-int ext4_read_bh_lock(struct buffer_head *bh, int op_flags, bool wait)
+int ext4_read_bh_lock(struct buffer_head *bh, blk_opf_t op_flags, bool wait)
 {
 	if (trylock_buffer(bh)) {
 		if (wait)
@@ -227,8 +227,8 @@ int ext4_read_bh_lock(struct buffer_head *bh, int op_flags, bool wait)
  * return.
  */
 static struct buffer_head *__ext4_sb_bread_gfp(struct super_block *sb,
-					       sector_t block, int op_flags,
-					       gfp_t gfp)
+					       sector_t block,
+					       blk_opf_t op_flags, gfp_t gfp)
 {
 	struct buffer_head *bh;
 	int ret;
@@ -248,7 +248,7 @@ static struct buffer_head *__ext4_sb_bread_gfp(struct super_block *sb,
 }
 
 struct buffer_head *ext4_sb_bread(struct super_block *sb, sector_t block,
-				   int op_flags)
+				   blk_opf_t op_flags)
 {
 	return __ext4_sb_bread_gfp(sb, block, op_flags, __GFP_MOVABLE);
 }
author reviewer
#46 lore raw

PATCH 41/51 fs/f2fs: Use the enum req_op and blk_opf_t types

In reply to Bart Van Assche

Improve static type checking by using the enum req_op type for variables that represent a request operation and the new blk_opf_t type for variables that represent request flags.

---
 fs/f2fs/data.c              | 11 ++++++-----
 fs/f2fs/f2fs.h              |  6 +++---
 fs/f2fs/node.c              |  2 +-
 fs/f2fs/segment.c           |  2 +-
 include/trace/events/f2fs.h | 28 +++++++++++++++-------------
 5 files changed, 26 insertions(+), 23 deletions(-)
fs/f2fs/data.c +6 -5
index 7fcbcf979737..5c13ee321940 100644
@@ -387,11 +387,11 @@ int f2fs_target_device_index(struct f2fs_sb_info *sbi, block_t blkaddr)
 	return 0;
 }
 
-static unsigned int f2fs_io_flags(struct f2fs_io_info *fio)
+static blk_opf_t f2fs_io_flags(struct f2fs_io_info *fio)
 {
 	unsigned int temp_mask = (1 << NR_TEMP_TYPE) - 1;
 	unsigned int fua_flag, meta_flag, io_flag;
-	unsigned int op_flags = 0;
+	blk_opf_t op_flags = 0;
 
 	if (fio->op != REQ_OP_WRITE)
 		return 0;
@@ -999,7 +999,7 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio)
 }
 
 static struct bio *f2fs_grab_read_bio(struct inode *inode, block_t blkaddr,
-				      unsigned nr_pages, unsigned op_flag,
+				      unsigned nr_pages, blk_opf_t op_flag,
 				      pgoff_t first_idx, bool for_write)
 {
 	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
@@ -1047,7 +1047,8 @@ static struct bio *f2fs_grab_read_bio(struct inode *inode, block_t blkaddr,
 
 /* This can handle encryption stuffs */
 static int f2fs_submit_page_read(struct inode *inode, struct page *page,
-				 block_t blkaddr, int op_flags, bool for_write)
+				 block_t blkaddr, blk_opf_t op_flags,
+				 bool for_write)
 {
 	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
 	struct bio *bio;
@@ -1181,7 +1182,7 @@ int f2fs_get_block(struct dnode_of_data *dn, pgoff_t index)
 }
 
 struct page *f2fs_get_read_data_page(struct inode *inode, pgoff_t index,
-						int op_flags, bool for_write)
+				     blk_opf_t op_flags, bool for_write)
 {
 	struct address_space *mapping = inode->i_mapping;
 	struct dnode_of_data dn;
fs/f2fs/f2fs.h +3 -3
index d9bbecd008d2..868170b72de9 100644
@@ -1183,8 +1183,8 @@ struct f2fs_io_info {
 	nid_t ino;		/* inode number */
 	enum page_type type;	/* contains DATA/NODE/META/META_FLUSH */
 	enum temp_type temp;	/* contains HOT/WARM/COLD */
-	int op;			/* contains REQ_OP_ */
-	int op_flags;		/* req_flag_bits */
+	enum req_op op;		/* contains REQ_OP_ */
+	blk_opf_t op_flags;	/* req_flag_bits */
 	block_t new_blkaddr;	/* new block address to be written */
 	block_t old_blkaddr;	/* old block address before Cow */
 	struct page *page;	/* page to be written */
@@ -3741,7 +3741,7 @@ int f2fs_reserve_new_block(struct dnode_of_data *dn);
 int f2fs_get_block(struct dnode_of_data *dn, pgoff_t index);
 int f2fs_reserve_block(struct dnode_of_data *dn, pgoff_t index);
 struct page *f2fs_get_read_data_page(struct inode *inode, pgoff_t index,
-			int op_flags, bool for_write);
+			blk_opf_t op_flags, bool for_write);
 struct page *f2fs_find_data_page(struct inode *inode, pgoff_t index);
 struct page *f2fs_get_lock_data_page(struct inode *inode, pgoff_t index,
 			bool for_write);
fs/f2fs/node.c +1 -1
index 836c79a20afc..c4f1e895ebd2 100644
@@ -1327,7 +1327,7 @@ struct page *f2fs_new_node_page(struct dnode_of_data *dn, unsigned int ofs)
  * 0: f2fs_put_page(page, 0)
  * LOCKED_PAGE or error: f2fs_put_page(page, 1)
  */
-static int read_node_page(struct page *page, int op_flags)
+static int read_node_page(struct page *page, blk_opf_t op_flags)
 {
 	struct f2fs_sb_info *sbi = F2FS_P_SB(page);
 	struct node_info ni;
fs/f2fs/segment.c +1 -1
index 874c1b9c41a2..c7afc588cf26 100644
@@ -1082,7 +1082,7 @@ static int __submit_discard_cmd(struct f2fs_sb_info *sbi,
 	struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info;
 	struct list_head *wait_list = (dpolicy->type == DPOLICY_FSTRIM) ?
 					&(dcc->fstrim_list) : &(dcc->wait_list);
-	int flag = dpolicy->sync ? REQ_SYNC : 0;
+	blk_opf_t flag = dpolicy->sync ? REQ_SYNC : 0;
 	block_t lstart, start, len, total_len;
 	int err = 0;
 
include/trace/events/f2fs.h +15 -13
index 513e889ef8aa..0f51b2e9c3d0 100644
@@ -66,7 +66,7 @@ TRACE_DEFINE_ENUM(CP_RESIZE);
 
 #define F2FS_OP_FLAGS (REQ_RAHEAD | REQ_SYNC | REQ_META | REQ_PRIO |	\
 			REQ_PREFLUSH | REQ_FUA)
-#define F2FS_BIO_FLAG_MASK(t)	(t & F2FS_OP_FLAGS)
+#define F2FS_BIO_FLAG_MASK(t) ((t) & (__force u32)F2FS_OP_FLAGS)
 
 #define show_bio_type(op,op_flags)	show_bio_op(op),		\
 						show_bio_op_flags(op_flags)
@@ -75,12 +75,12 @@ TRACE_DEFINE_ENUM(CP_RESIZE);
 
 #define show_bio_op_flags(flags)					\
 	__print_flags(F2FS_BIO_FLAG_MASK(flags), "|",			\
-		{ REQ_RAHEAD,		"R" },				\
-		{ REQ_SYNC,		"S" },				\
-		{ REQ_META,		"M" },				\
-		{ REQ_PRIO,		"P" },				\
-		{ REQ_PREFLUSH,		"PF" },				\
-		{ REQ_FUA,		"FUA" })
+		{ (__force u32)REQ_RAHEAD,	"R" },			\
+		{ (__force u32)REQ_SYNC,	"S" },			\
+		{ (__force u32)REQ_META,	"M" },			\
+		{ (__force u32)REQ_PRIO,	"P" },			\
+		{ (__force u32)REQ_PREFLUSH,	"PF" },			\
+		{ (__force u32)REQ_FUA,		"FUA" })
 
 #define show_data_type(type)						\
 	__print_symbolic(type,						\
@@ -1048,8 +1048,8 @@ DECLARE_EVENT_CLASS(f2fs__submit_page_bio,
 		__entry->index		= page->index;
 		__entry->old_blkaddr	= fio->old_blkaddr;
 		__entry->new_blkaddr	= fio->new_blkaddr;
-		__entry->op		= fio->op;
-		__entry->op_flags	= fio->op_flags;
+		__entry->op		= (__force int)fio->op;
+		__entry->op_flags	= (__force int)fio->op_flags;
 		__entry->temp		= fio->temp;
 		__entry->type		= fio->type;
 	),
@@ -1060,7 +1060,8 @@ DECLARE_EVENT_CLASS(f2fs__submit_page_bio,
 		(unsigned long)__entry->index,
 		(unsigned long long)__entry->old_blkaddr,
 		(unsigned long long)__entry->new_blkaddr,
-		show_bio_type(__entry->op, __entry->op_flags),
+		show_bio_type((__force enum req_op)__entry->op,
+			      __entry->op_flags),
 		show_block_temp(__entry->temp),
 		show_block_type(__entry->type))
 );
@@ -1102,8 +1103,8 @@ DECLARE_EVENT_CLASS(f2fs__bio,
 	TP_fast_assign(
 		__entry->dev		= sb->s_dev;
 		__entry->target		= bio_dev(bio);
-		__entry->op		= bio_op(bio);
-		__entry->op_flags	= bio->bi_opf;
+		__entry->op		= (__force int)bio_op(bio);
+		__entry->op_flags	= (__force int)bio->bi_opf;
 		__entry->type		= type;
 		__entry->sector		= bio->bi_iter.bi_sector;
 		__entry->size		= bio->bi_iter.bi_size;
@@ -1112,7 +1113,8 @@ DECLARE_EVENT_CLASS(f2fs__bio,
 	TP_printk("dev = (%d,%d)/(%d,%d), rw = %s(%s), %s, sector = %lld, size = %u",
 		show_dev(__entry->target),
 		show_dev(__entry->dev),
-		show_bio_type(__entry->op, __entry->op_flags),
+		show_bio_type((__force enum req_op)__entry->op,
+			      __entry->op_flags),
 		show_block_type(__entry->type),
 		(unsigned long long)__entry->sector,
 		__entry->size)
author reviewer
#47 lore raw

PATCH 42/51 fs/gfs2: Use the enum req_op and blk_opf_t types

In reply to Bart Van Assche

Improve static type checking by using the enum req_op type for variables that represent a request operation and the new blk_opf_t type for variables that represent request flags.

Cc Bob Peterson <[email protected]>
Cc Andreas Gruenbacher <[email protected]>
---
 fs/gfs2/log.c     | 4 ++--
 fs/gfs2/log.h     | 2 +-
 fs/gfs2/lops.c    | 4 ++--
 fs/gfs2/lops.h    | 2 +-
 fs/gfs2/meta_io.c | 6 +++---
 5 files changed, 9 insertions(+), 9 deletions(-)
fs/gfs2/log.c +2 -2
index f0ee3ff6f9a8..eec4159b08aa 100644
@@ -823,7 +823,7 @@ void gfs2_flush_revokes(struct gfs2_sbd *sdp)
 
 void gfs2_write_log_header(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
 			   u64 seq, u32 tail, u32 lblock, u32 flags,
-			   int op_flags)
+			   blk_opf_t op_flags)
 {
 	struct gfs2_log_header *lh;
 	u32 hash, crc;
@@ -905,7 +905,7 @@ void gfs2_write_log_header(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
 
 static void log_write_header(struct gfs2_sbd *sdp, u32 flags)
 {
-	int op_flags = REQ_PREFLUSH | REQ_FUA | REQ_META | REQ_SYNC;
+	blk_opf_t op_flags = REQ_PREFLUSH | REQ_FUA | REQ_META | REQ_SYNC;
 	enum gfs2_freeze_state state = atomic_read(&sdp->sd_freeze_state);
 
 	gfs2_assert_withdraw(sdp, (state != SFS_FROZEN));
fs/gfs2/log.h +1 -1
index fc905c2af53c..653cffcbf869 100644
@@ -82,7 +82,7 @@ extern void gfs2_log_reserve(struct gfs2_sbd *sdp, struct gfs2_trans *tr,
 			     unsigned int *extra_revokes);
 extern void gfs2_write_log_header(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
 				  u64 seq, u32 tail, u32 lblock, u32 flags,
-				  int op_flags);
+				  blk_opf_t op_flags);
 extern void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl,
 			   u32 type);
 extern void gfs2_log_commit(struct gfs2_sbd *sdp, struct gfs2_trans *trans);
fs/gfs2/lops.c +2 -2
index 6ba51cbb94cf..90a2d7bc91c4 100644
@@ -238,7 +238,7 @@ static void gfs2_end_log_write(struct bio *bio)
  * there is no pending bio, then this is a no-op.
  */
 
-void gfs2_log_submit_bio(struct bio **biop, int opf)
+void gfs2_log_submit_bio(struct bio **biop, blk_opf_t opf)
 {
 	struct bio *bio = *biop;
 	if (bio) {
@@ -292,7 +292,7 @@ static struct bio *gfs2_log_alloc_bio(struct gfs2_sbd *sdp, u64 blkno,
  */
 
 static struct bio *gfs2_log_get_bio(struct gfs2_sbd *sdp, u64 blkno,
-				    struct bio **biop, int op,
+				    struct bio **biop, enum req_op op,
 				    bio_end_io_t *end_io, bool flush)
 {
 	struct bio *bio = *biop;
fs/gfs2/lops.h +1 -1
index f707601597dc..1412ffba1d44 100644
@@ -16,7 +16,7 @@ extern u64 gfs2_log_bmap(struct gfs2_jdesc *jd, unsigned int lbn);
 extern void gfs2_log_write(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
 			   struct page *page, unsigned size, unsigned offset,
 			   u64 blkno);
-extern void gfs2_log_submit_bio(struct bio **biop, int opf);
+extern void gfs2_log_submit_bio(struct bio **biop, blk_opf_t opf);
 extern void gfs2_pin(struct gfs2_sbd *sdp, struct buffer_head *bh);
 extern int gfs2_find_jhead(struct gfs2_jdesc *jd,
 			   struct gfs2_log_header_host *head, bool keep_cache);
fs/gfs2/meta_io.c +3 -3
index 868dcc71b581..fe0fdec628ea 100644
@@ -34,7 +34,7 @@ static int gfs2_aspace_writepage(struct page *page, struct writeback_control *wb
 {
 	struct buffer_head *bh, *head;
 	int nr_underway = 0;
-	int write_flags = REQ_META | REQ_PRIO | wbc_to_write_flags(wbc);
+	blk_opf_t write_flags = REQ_META | REQ_PRIO | wbc_to_write_flags(wbc);
 
 	BUG_ON(!PageLocked(page));
 	BUG_ON(!page_has_buffers(page));
@@ -217,8 +217,8 @@ static void gfs2_meta_read_endio(struct bio *bio)
  * Submit several consecutive buffer head I/O requests as a single bio I/O
  * request.  (See submit_bh_wbc.)
  */
-static void gfs2_submit_bhs(int op, int op_flags, struct buffer_head *bhs[],
-			    int num)
+static void gfs2_submit_bhs(enum req_op op, blk_opf_t op_flags,
+			    struct buffer_head *bhs[], int num)
 {
 	while (num > 0) {
 		struct buffer_head *bh = *bhs;
author reviewer
#48 lore raw

PATCH 43/51 fs/hfsplus: Use the enum req_op and blk_opf_t types

In reply to Bart Van Assche

Improve static type checking by using the enum req_op type for variables that represent a request operation and the new blk_opf_t type for variables that represent request flags.

Cc Christoph Hellwig <[email protected]>
---
 fs/hfsplus/hfsplus_fs.h | 2 +-
 fs/hfsplus/wrapper.c    | 5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)
fs/hfsplus/hfsplus_fs.h +1 -1
index 396e73aa0961..ac93c2445b29 100644
@@ -525,7 +525,7 @@ int hfsplus_compare_dentry(const struct dentry *dentry, unsigned int len,
 
 /* wrapper.c */
 int hfsplus_submit_bio(struct super_block *sb, sector_t sector, void *buf,
-		       void **data, int op, int op_flags);
+		       void **data, enum req_op op, blk_opf_t op_flags);
 int hfsplus_read_wrapper(struct super_block *sb);
 
 /*
fs/hfsplus/wrapper.c +3 -2
index 0b8ad6586df5..bf5e89748df0 100644
@@ -45,7 +45,8 @@ struct hfsplus_wd {
  * will work correctly.
  */
 int hfsplus_submit_bio(struct super_block *sb, sector_t sector,
-		       void *buf, void **data, int op, int op_flags)
+		       void *buf, void **data, enum req_op op,
+		       blk_opf_t op_flags)
 {
 	struct bio *bio;
 	int ret = 0;
@@ -66,7 +67,7 @@ int hfsplus_submit_bio(struct super_block *sb, sector_t sector,
 	bio = bio_alloc(sb->s_bdev, 1, op | op_flags, GFP_NOIO);
 	bio->bi_iter.bi_sector = sector;
 
-	if (op != WRITE && data)
+	if (op != REQ_OP_WRITE && data)
 		*data = (u8 *)buf + offset;
 
 	while (io_size > 0) {
author reviewer
#49 lore raw

PATCH 44/51 fs/iomap: Use the new blk_opf_t type

In reply to Bart Van Assche

Improve static type checking by using the enum req_op type for variables that represent a request operation and the new blk_opf_t type for the combination of a request operation and request flags.

Cc Al Viro <[email protected]>
Cc Christoph Hellwig <[email protected]>
---
 fs/iomap/direct-io.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
fs/iomap/direct-io.c +4 -4
index 5d098adba443..18a3d9357dce 100644
@@ -52,7 +52,7 @@ struct iomap_dio {
 };
 
 static struct bio *iomap_dio_alloc_bio(const struct iomap_iter *iter,
-		struct iomap_dio *dio, unsigned short nr_vecs, unsigned int opf)
+		struct iomap_dio *dio, unsigned short nr_vecs, blk_opf_t opf)
 {
 	if (dio->dops && dio->dops->bio_set)
 		return bio_alloc_bioset(iter->iomap.bdev, nr_vecs, opf,
@@ -212,10 +212,10 @@ static void iomap_dio_zero(const struct iomap_iter *iter, struct iomap_dio *dio,
  * mapping, and whether or not we want FUA.  Note that we can end up
  * clearing the WRITE_FUA flag in the dio request.
  */
-static inline unsigned int iomap_dio_bio_opflags(struct iomap_dio *dio,
+static inline blk_opf_t iomap_dio_bio_opflags(struct iomap_dio *dio,
 		const struct iomap *iomap, bool use_fua)
 {
-	unsigned int opflags = REQ_SYNC | REQ_IDLE;
+	blk_opf_t opflags = REQ_SYNC | REQ_IDLE;
 
 	if (!(dio->flags & IOMAP_DIO_WRITE)) {
 		WARN_ON_ONCE(iomap->flags & IOMAP_F_ZONE_APPEND);
@@ -244,7 +244,7 @@ static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter,
 	unsigned int fs_block_size = i_blocksize(inode), pad;
 	loff_t length = iomap_length(iter);
 	loff_t pos = iter->pos;
-	unsigned int bio_opf;
+	blk_opf_t bio_opf;
 	struct bio *bio;
 	bool need_zeroout = false;
 	bool use_fua = false;
author reviewer
#50 lore raw

PATCH 45/51 fs/jbd2: Fix the documentation of the jbd2_write_superblock() callers

In reply to Bart Van Assche

Commit 2a222ca992c3 ("fs: have submit_bh users pass in op and flags separately") renamed the jbd2_write_superblock() 'write_op' argument into 'write_flags'. Propagate this change to the jbd2_write_superblock() callers. Additionally, change the type of 'write_flags' into blk_opf_t.

Cc Mike Christie <[email protected]>
Cc Theodore Ts'o <[email protected]>
---
 fs/jbd2/journal.c           | 15 ++++++++-------
 include/linux/jbd2.h        |  2 +-
 include/trace/events/jbd2.h | 12 ++++++------
 3 files changed, 15 insertions(+), 14 deletions(-)
fs/jbd2/journal.c +8 -7
index c0cbeeaec2d1..b1be8450c50c 100644
@@ -1602,7 +1602,7 @@ static int journal_reset(journal_t *journal)
  * This function expects that the caller will have locked the journal
  * buffer head, and will return with it unlocked
  */
-static int jbd2_write_superblock(journal_t *journal, int write_flags)
+static int jbd2_write_superblock(journal_t *journal, blk_opf_t write_flags)
 {
 	struct buffer_head *bh = journal->j_sb_buffer;
 	journal_superblock_t *sb = journal->j_superblock;
@@ -1659,13 +1659,14 @@ static int jbd2_write_superblock(journal_t *journal, int write_flags)
  * @journal: The journal to update.
  * @tail_tid: TID of the new transaction at the tail of the log
  * @tail_block: The first block of the transaction at the tail of the log
- * @write_op: With which operation should we write the journal sb
+ * @write_flags: Flags for the journal sb write operation
  *
  * Update a journal's superblock information about log tail and write it to
  * disk, waiting for the IO to complete.
  */
 int jbd2_journal_update_sb_log_tail(journal_t *journal, tid_t tail_tid,
-				     unsigned long tail_block, int write_op)
+				    unsigned long tail_block,
+				    blk_opf_t write_flags)
 {
 	journal_superblock_t *sb = journal->j_superblock;
 	int ret;
@@ -1685,7 +1686,7 @@ int jbd2_journal_update_sb_log_tail(journal_t *journal, tid_t tail_tid,
 	sb->s_sequence = cpu_to_be32(tail_tid);
 	sb->s_start    = cpu_to_be32(tail_block);
 
-	ret = jbd2_write_superblock(journal, write_op);
+	ret = jbd2_write_superblock(journal, write_flags);
 	if (ret)
 		goto out;
 
@@ -1702,12 +1703,12 @@ int jbd2_journal_update_sb_log_tail(journal_t *journal, tid_t tail_tid,
 /**
  * jbd2_mark_journal_empty() - Mark on disk journal as empty.
  * @journal: The journal to update.
- * @write_op: With which operation should we write the journal sb
+ * @write_flags: Flags for the journal sb write operation
  *
  * Update a journal's dynamic superblock fields to show that journal is empty.
  * Write updated superblock to disk waiting for IO to complete.
  */
-static void jbd2_mark_journal_empty(journal_t *journal, int write_op)
+static void jbd2_mark_journal_empty(journal_t *journal, blk_opf_t write_flags)
 {
 	journal_superblock_t *sb = journal->j_superblock;
 	bool had_fast_commit = false;
@@ -1733,7 +1734,7 @@ static void jbd2_mark_journal_empty(journal_t *journal, int write_op)
 		had_fast_commit = true;
 	}
 
-	jbd2_write_superblock(journal, write_op);
+	jbd2_write_superblock(journal, write_flags);
 
 	if (had_fast_commit)
 		jbd2_set_feature_fast_commit(journal);
include/linux/jbd2.h +1 -1
index e79d6e0b14e8..dc1724131300 100644
@@ -1557,7 +1557,7 @@ extern int	   jbd2_journal_wipe       (journal_t *, int);
 extern int	   jbd2_journal_skip_recovery	(journal_t *);
 extern void	   jbd2_journal_update_sb_errno(journal_t *);
 extern int	   jbd2_journal_update_sb_log_tail	(journal_t *, tid_t,
-				unsigned long, int);
+				unsigned long, blk_opf_t);
 extern void	   jbd2_journal_abort      (journal_t *, int);
 extern int	   jbd2_journal_errno      (journal_t *);
 extern void	   jbd2_journal_ack_err    (journal_t *);
include/trace/events/jbd2.h +6 -6
index a4dfe005983d..91dae1f678fe 100644
@@ -355,22 +355,22 @@ TRACE_EVENT(jbd2_update_log_tail,
 
 TRACE_EVENT(jbd2_write_superblock,
 
-	TP_PROTO(journal_t *journal, int write_op),
+	TP_PROTO(journal_t *journal, blk_opf_t write_flags),
 
-	TP_ARGS(journal, write_op),
+	TP_ARGS(journal, write_flags),
 
 	TP_STRUCT__entry(
 		__field(	dev_t,  dev			)
-		__field(	  int,  write_op		)
+		__field(          u32,  write_flags		)
 	),
 
 	TP_fast_assign(
 		__entry->dev		= journal->j_fs_dev->bd_dev;
-		__entry->write_op	= write_op;
+		__entry->write_flags	= (__force u32)write_flags;
 	),
 
-	TP_printk("dev %d,%d write_op %x", MAJOR(__entry->dev),
-		  MINOR(__entry->dev), __entry->write_op)
+	TP_printk("dev %d,%d write_flags %x", MAJOR(__entry->dev),
+		  MINOR(__entry->dev), __entry->write_flags)
 );
 
 TRACE_EVENT(jbd2_lock_buffer_stall,
author reviewer
#51 lore raw

PATCH 46/51 fs/nilfs: Use the enum req_op and blk_opf_t types

In reply to Bart Van Assche

Improve static type checking by using the enum req_op type for variables that represent a request operation and the new blk_opf_t type for variables that represent request flags.

---
 fs/nilfs2/btnode.c            | 4 ++--
 fs/nilfs2/btnode.h            | 5 +++--
 fs/nilfs2/mdt.c               | 3 ++-
 include/trace/events/nilfs2.h | 4 ++--
 4 files changed, 9 insertions(+), 7 deletions(-)
fs/nilfs2/btnode.c +2 -2
index ca611ac09f7c..13784cf169ca 100644
@@ -70,8 +70,8 @@ nilfs_btnode_create_block(struct address_space *btnc, __u64 blocknr)
 }
 
 int nilfs_btnode_submit_block(struct address_space *btnc, __u64 blocknr,
-			      sector_t pblocknr, int mode, int mode_flags,
-			      struct buffer_head **pbh, sector_t *submit_ptr)
+		sector_t pblocknr, enum req_op mode, blk_opf_t mode_flags,
+		struct buffer_head **pbh, sector_t *submit_ptr)
 {
 	struct buffer_head *bh;
 	struct inode *inode = btnc->host;
fs/nilfs2/btnode.h +3 -2
index bd5544e63a01..b7d2948dc74f 100644
@@ -34,8 +34,9 @@ void nilfs_init_btnc_inode(struct inode *btnc_inode);
 void nilfs_btnode_cache_clear(struct address_space *);
 struct buffer_head *nilfs_btnode_create_block(struct address_space *btnc,
 					      __u64 blocknr);
-int nilfs_btnode_submit_block(struct address_space *, __u64, sector_t, int,
-			      int, struct buffer_head **, sector_t *);
+int nilfs_btnode_submit_block(struct address_space *, __u64, sector_t,
+			      enum req_op, blk_opf_t, struct buffer_head **,
+			      sector_t *);
 void nilfs_btnode_delete(struct buffer_head *);
 int nilfs_btnode_prepare_change_key(struct address_space *,
 				    struct nilfs_btnode_chkey_ctxt *);
fs/nilfs2/mdt.c +2 -1
index d29a0f2b9c16..19d878f0e923 100644
@@ -112,7 +112,8 @@ static int nilfs_mdt_create_block(struct inode *inode, unsigned long block,
 
 static int
 nilfs_mdt_submit_block(struct inode *inode, unsigned long blkoff,
-		       int mode, int mode_flags, struct buffer_head **out_bh)
+		       enum req_op mode, blk_opf_t mode_flags,
+		       struct buffer_head **out_bh)
 {
 	struct buffer_head *bh;
 	__u64 blknum = 0;
include/trace/events/nilfs2.h +2 -2
index 84ee31fc04cc..05668a783042 100644
@@ -192,7 +192,7 @@ TRACE_EVENT(nilfs2_mdt_submit_block,
 	    TP_PROTO(struct inode *inode,
 		     unsigned long ino,
 		     unsigned long blkoff,
-		     int mode),
+		     enum req_op mode),
 
 	    TP_ARGS(inode, ino, blkoff, mode),
 
@@ -207,7 +207,7 @@ TRACE_EVENT(nilfs2_mdt_submit_block,
 		    __entry->inode = inode;
 		    __entry->ino = ino;
 		    __entry->blkoff = blkoff;
-		    __entry->mode = mode;
+		    __entry->mode = (__force int)mode;
 		    ),
 
 	    TP_printk("inode = %p ino = %lu blkoff = %lu mode = %x",
author reviewer
#55 lore raw

PATCH 47/51 fs/ntfs3: Use enum req_op where appropriate

In reply to Bart Van Assche

Improve static type checking by using enum req_op instead of u32 for block layer request operations.

Cc Konstantin Komarov <[email protected]>
---
 fs/ntfs3/fsntfs.c  | 2 +-
 fs/ntfs3/ntfs_fs.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
fs/ntfs3/fsntfs.c +1 -1
index 3de5700a9b83..1835e35199c2 100644
@@ -1448,7 +1448,7 @@ int ntfs_write_bh(struct ntfs_sb_info *sbi, struct NTFS_RECORD_HEADER *rhdr,
  */
 int ntfs_bio_pages(struct ntfs_sb_info *sbi, const struct runs_tree *run,
 		   struct page **pages, u32 nr_pages, u64 vbo, u32 bytes,
-		   u32 op)
+		   enum req_op op)
 {
 	int err = 0;
 	struct bio *new, *bio = NULL;
fs/ntfs3/ntfs_fs.h +1 -1
index 8de129a6419b..3a8abf13143e 100644
@@ -617,7 +617,7 @@ int ntfs_write_bh(struct ntfs_sb_info *sbi, struct NTFS_RECORD_HEADER *rhdr,
 		  struct ntfs_buffers *nb, int sync);
 int ntfs_bio_pages(struct ntfs_sb_info *sbi, const struct runs_tree *run,
 		   struct page **pages, u32 nr_pages, u64 vbo, u32 bytes,
-		   u32 op);
+		   enum req_op op);
 int ntfs_bio_fill_1(struct ntfs_sb_info *sbi, const struct runs_tree *run);
 int ntfs_vbo_to_lbo(struct ntfs_sb_info *sbi, const struct runs_tree *run,
 		    u64 vbo, u64 *lbo, u64 *bytes);
author reviewer
#56 lore raw

PATCH 48/51 fs/ocfs2: Use the enum req_op and blk_opf_t types

In reply to Bart Van Assche

Improve static type checking by using the enum req_op type for variables that represent a request operation and the new blk_opf_t type for variables that represent request flags.

Cc Mark Fasheh <[email protected]>
Cc Joel Becker <[email protected]>
Cc Joseph Qi <[email protected]>
---
 fs/ocfs2/cluster/heartbeat.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/ocfs2/cluster/heartbeat.c +2 -2
index ea0e70c0fce0..e955aca87936 100644
@@ -503,8 +503,8 @@ static void o2hb_bio_end_io(struct bio *bio)
 static struct bio *o2hb_setup_one_bio(struct o2hb_region *reg,
 				      struct o2hb_bio_wait_ctxt *wc,
 				      unsigned int *current_slot,
-				      unsigned int max_slots, int op,
-				      int op_flags)
+				      unsigned int max_slots, enum req_op op,
+				      blk_opf_t op_flags)
 {
 	int len, current_page;
 	unsigned int vec_len, vec_start;
author reviewer
#58 lore raw

PATCH 49/51 PM: Use the enum req_op and blk_opf_t types

In reply to Bart Van Assche

Improve static type checking by using the enum req_op type for variables that represent a request operation and the new blk_opf_t type for variables that represent request flags.

Cc Rafael J. Wysocki <[email protected]>
Cc Christoph Hellwig <[email protected]>
---
 kernel/power/swap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/power/swap.c +2 -2
index 91fffdd2c7fb..db01cac40a4c 100644
@@ -269,8 +269,8 @@ static void hib_end_io(struct bio *bio)
 	bio_put(bio);
 }
 
-static int hib_submit_io(int op, int op_flags, pgoff_t page_off, void *addr,
-		struct hib_bio_batch *hb)
+static int hib_submit_io(enum req_op op, blk_opf_t op_flags,
+			 pgoff_t page_off, void *addr, struct hib_bio_batch *hb)
 {
 	struct page *page = virt_to_page(addr);
 	struct bio *bio;
author reviewer
#60 lore raw

PATCH 50/51 fs/xfs: Use the enum req_op and blk_opf_t types

In reply to Bart Van Assche

Improve static type checking by using the enum req_op type for variables that represent a request operation and the new blk_opf_t type for the combination of a request operation with request flags.

Cc Darrick J. Wong <[email protected]>
Cc Christoph Hellwig <[email protected]>
---
 fs/xfs/xfs_bio_io.c      | 2 +-
 fs/xfs/xfs_buf.c         | 4 ++--
 fs/xfs/xfs_linux.h       | 2 +-
 fs/xfs/xfs_log_recover.c | 2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)
fs/xfs/xfs_bio_io.c +1 -1
index ae4345b37621..fe21c76f75b8 100644
@@ -15,7 +15,7 @@ xfs_rw_bdev(
 	sector_t		sector,
 	unsigned int		count,
 	char			*data,
-	unsigned int		op)
+	enum req_op		op)
 
 {
 	unsigned int		is_vmalloc = is_vmalloc_addr(data);
fs/xfs/xfs_buf.c +2 -2
index bf4e60871068..5e8f40d8c052 100644
@@ -1416,7 +1416,7 @@ xfs_buf_ioapply_map(
 	int		map,
 	int		*buf_offset,
 	int		*count,
-	int		op)
+	blk_opf_t	op)
 {
 	int		page_index;
 	unsigned int	total_nr_pages = bp->b_page_count;
@@ -1493,7 +1493,7 @@ _xfs_buf_ioapply(
 	struct xfs_buf	*bp)
 {
 	struct blk_plug	plug;
-	int		op;
+	blk_opf_t	op;
 	int		offset;
 	int		size;
 	int		i;
fs/xfs/xfs_linux.h +1 -1
index cb9105d667db..f9878021e7d0 100644
@@ -196,7 +196,7 @@ static inline uint64_t howmany_64(uint64_t x, uint32_t y)
 }
 
 int xfs_rw_bdev(struct block_device *bdev, sector_t sector, unsigned int count,
-		char *data, unsigned int op);
+		char *data, enum req_op op);
 
 #define ASSERT_ALWAYS(expr)	\
 	(likely(expr) ? (void)0 : assfail(NULL, #expr, __FILE__, __LINE__))
fs/xfs/xfs_log_recover.c +1 -1
index 5f7e4e6e33ce..940c8107cbd4 100644
@@ -122,7 +122,7 @@ xlog_do_io(
 	xfs_daddr_t		blk_no,
 	unsigned int		nbblks,
 	char			*data,
-	unsigned int		op)
+	enum req_op		op)
 {
 	int			error;
 
author reviewer
#62 lore raw

PATCH 51/51 fs/zonefs: Fix sparse warnings in tracing code

In reply to Bart Van Assche

Since __bitwise types are not supported by the tracing infrastructure, store the operation type as an int in the tracing event.

Cc Damien Le Moal <[email protected]>
Cc Naohiro Aota <[email protected]>
Cc Johannes Thumshirn <[email protected]>
---
 fs/zonefs/trace.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/zonefs/trace.h +3 -3
index 21501da764bd..8707e1c3023c 100644
@@ -32,15 +32,15 @@ TRACE_EVENT(zonefs_zone_mgmt,
 	    TP_fast_assign(
 			   __entry->dev = inode->i_sb->s_dev;
 			   __entry->ino = inode->i_ino;
-			   __entry->op = op;
+			   __entry->op = (__force int)op;
 			   __entry->sector = ZONEFS_I(inode)->i_zsector;
 			   __entry->nr_sectors =
 				   ZONEFS_I(inode)->i_zone_size >> SECTOR_SHIFT;
 	    ),
 	    TP_printk("bdev=(%d,%d), ino=%lu op=%s, sector=%llu, nr_sectors=%llu",
 		      show_dev(__entry->dev), (unsigned long)__entry->ino,
-		      blk_op_str(__entry->op), __entry->sector,
-		      __entry->nr_sectors
+		      blk_op_str((__force enum req_op)__entry->op),
+		      __entry->sector, __entry->nr_sectors
 	    )
 );
 
Reviewed-by on v1 21/51
#23 lore raw

Re: [PATCH 21/51] dm/dm-zoned: Use the enum req_op type

In reply to Bart Van Assche
Quoted 16 lines · Bart Van Assche

Improve static type checking by using the enum req_op type for arguments that represent a request operation.

Cc Alasdair Kergon <[email protected]>
Cc Mike Snitzer <[email protected]>
Cc Damien Le Moal <[email protected]>
---
 drivers/md/dm-zoned-metadata.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm-zoned-metadata.c +0 -0
index d1ea66114d14..9341c46e44b7 100644

drivers/md/dm-zoned-metadata.c static int dmz_write_mblock(struct dmz_metadata *zmd, struct dmz_mblock *mblk, · line 743

Quoted 8 lines
drivers/md/dm-zoned-metadata.c +1 -1
@@ -737,7 +737,7 @@ static int dmz_write_mblock(struct dmz_metadata *zmd, struct dmz_mblock *mblk,
 /*
  * Read/write a metadata block.
  */
-static int dmz_rdwr_block(struct dmz_dev *dev, int op,
+static int dmz_rdwr_block(struct dmz_dev *dev, enum req_op op,
 			  sector_t block, struct page *page)
 {
 	struct bio *bio;

Looks good.

Signature · 2 lines
Damien Le Moal
Western Digital Research
#63 lore raw

Re: [PATCH 51/51] fs/zonefs: Fix sparse warnings in tracing code

In reply to Bart Van Assche
Quoted 24 lines · Bart Van Assche

Since __bitwise types are not supported by the tracing infrastructure, store the operation type as an int in the tracing event.

Cc Damien Le Moal <[email protected]>
Cc Naohiro Aota <[email protected]>
Cc Johannes Thumshirn <[email protected]>
---
 fs/zonefs/trace.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/zonefs/trace.h +1 -1
index 21501da764bd..8707e1c3023c 100644
@@ -32,15 +32,15 @@ TRACE_EVENT(zonefs_zone_mgmt,
 	    TP_fast_assign(
 			   __entry->dev = inode->i_sb->s_dev;
 			   __entry->ino = inode->i_ino;
-			   __entry->op = op;
+			   __entry->op = (__force int)op;
 			   __entry->sector = ZONEFS_I(inode)->i_zsector;
 			   __entry->nr_sectors =
 				   ZONEFS_I(inode)->i_zone_size >> SECTOR_SHIFT;

fs/zonefs/trace.h TRACE_EVENT(zonefs_zone_mgmt, · line 46

Quoted 10 lines
fs/zonefs/trace.h +2 -2
 	    ),
 	    TP_printk("bdev=(%d,%d), ino=%lu op=%s, sector=%llu, nr_sectors=%llu",
 		      show_dev(__entry->dev), (unsigned long)__entry->ino,
-		      blk_op_str(__entry->op), __entry->sector,
-		      __entry->nr_sectors
+		      blk_op_str((__force enum req_op)__entry->op),
+		      __entry->sector, __entry->nr_sectors
 	    )
 );
 

How do you get the warning ? I always run sparse and have not seen any warning... Looks good anyway, will apply.

Signature · 2 lines
Damien Le Moal
Western Digital Research
author reviewer
#64 lore raw

Re: [PATCH 51/51] fs/zonefs: Fix sparse warnings in tracing code

Quoted 30 lines · Damien Le Moal
Quoted 29 lines · Bart Van Assche

Since __bitwise types are not supported by the tracing infrastructure, store the operation type as an int in the tracing event.

Cc Damien Le Moal <[email protected]>
Cc Naohiro Aota <[email protected]>
Cc Johannes Thumshirn <[email protected]>
---
  fs/zonefs/trace.h | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
fs/zonefs/trace.h +1 -3
index 21501da764bd..8707e1c3023c 100644
@@ -32,15 +32,15 @@ TRACE_EVENT(zonefs_zone_mgmt,
  	    TP_fast_assign(
  			   __entry->dev = inode->i_sb->s_dev;
  			   __entry->ino = inode->i_ino;
-			   __entry->op = op;
+			   __entry->op = (__force int)op;
  			   __entry->sector = ZONEFS_I(inode)->i_zsector;
  			   __entry->nr_sectors =
  				   ZONEFS_I(inode)->i_zone_size >> SECTOR_SHIFT;
  	    ),
  	    TP_printk("bdev=(%d,%d), ino=%lu op=%s, sector=%llu, nr_sectors=%llu",
  		      show_dev(__entry->dev), (unsigned long)__entry->ino,
-		      blk_op_str(__entry->op), __entry->sector,
-		      __entry->nr_sectors
Quoted 8 lines

fs/zonefs/trace.h TRACE_EVENT(zonefs_zone_mgmt, · line 46

Quoted 5 lines
fs/zonefs/trace.h +2 -0
+		      blk_op_str((__force enum req_op)__entry->op),
+		      __entry->sector, __entry->nr_sectors
  	    )
  );
 

How do you get the warning ? I always run sparse and have not seen any warning... Looks good anyway, will apply.

Hi Damien,

The warning fixed by this patch has been introduced by the patch that changes enum req_op from a regular enum into a bitwise enum. The warning does not occur with Jens' latest for-next branch.

Thanks,

Bart.

#65 lore raw

Re: [PATCH 51/51] fs/zonefs: Fix sparse warnings in tracing code

Quoted 40 lines · Bart Van Assche
Quoted 30 lines · Damien Le Moal
Quoted 29 lines · Bart Van Assche

Since __bitwise types are not supported by the tracing infrastructure, store the operation type as an int in the tracing event.

Cc Damien Le Moal <[email protected]>
Cc Naohiro Aota <[email protected]>
Cc Johannes Thumshirn <[email protected]>
---
  fs/zonefs/trace.h | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
fs/zonefs/trace.h +1 -3
index 21501da764bd..8707e1c3023c 100644
@@ -32,15 +32,15 @@ TRACE_EVENT(zonefs_zone_mgmt,
  	    TP_fast_assign(
  			   __entry->dev = inode->i_sb->s_dev;
  			   __entry->ino = inode->i_ino;
-			   __entry->op = op;
+			   __entry->op = (__force int)op;
  			   __entry->sector = ZONEFS_I(inode)->i_zsector;
  			   __entry->nr_sectors =
  				   ZONEFS_I(inode)->i_zone_size >> SECTOR_SHIFT;
  	    ),
  	    TP_printk("bdev=(%d,%d), ino=%lu op=%s, sector=%llu, nr_sectors=%llu",
  		      show_dev(__entry->dev), (unsigned long)__entry->ino,
-		      blk_op_str(__entry->op), __entry->sector,
-		      __entry->nr_sectors
Quoted 8 lines

fs/zonefs/trace.h TRACE_EVENT(zonefs_zone_mgmt, · line 46

Quoted 5 lines
fs/zonefs/trace.h +2 -0
+		      blk_op_str((__force enum req_op)__entry->op),
+		      __entry->sector, __entry->nr_sectors
  	    )
  );
 

How do you get the warning ? I always run sparse and have not seen any warning... Looks good anyway, will apply.

Quoted 5 lines

Hi Damien,

The warning fixed by this patch has been introduced by the patch that changes enum req_op from a regular enum into a bitwise enum. The warning does not occur with Jens' latest for-next branch.

I see. Thanks.

Quoted 6 lines

Thanks,

Bart.

Signature · 2 lines
Damien Le Moal
Western Digital Research
maintainer Acked-by on v1 48/51
#57 lore raw

Re: [PATCH 48/51] fs/ocfs2: Use the enum req_op and blk_opf_t types

In reply to Bart Van Assche
Quoted 8 lines · Bart Van Assche

Improve static type checking by using the enum req_op type for variables that represent a request operation and the new blk_opf_t type for variables that represent request flags.

Cc Mark Fasheh <[email protected]>
Cc Joel Becker <[email protected]>
Cc Joseph Qi <[email protected]>

Looks fine to me.

Quoted 19 lines
---
 fs/ocfs2/cluster/heartbeat.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/ocfs2/cluster/heartbeat.c +2 -2
index ea0e70c0fce0..e955aca87936 100644
@@ -503,8 +503,8 @@ static void o2hb_bio_end_io(struct bio *bio)
 static struct bio *o2hb_setup_one_bio(struct o2hb_region *reg,
 				      struct o2hb_bio_wait_ctxt *wc,
 				      unsigned int *current_slot,
-				      unsigned int max_slots, int op,
-				      int op_flags)
+				      unsigned int max_slots, enum req_op op,
+				      blk_opf_t op_flags)
 {
 	int len, current_page;
 	unsigned int vec_len, vec_start;
maintainer Acked-by on v1 46/51
#52 lore raw

Re: [PATCH 46/51] fs/nilfs: Use the enum req_op and blk_opf_t types

In reply to Bart Van Assche
Quoted 5 lines · Bart Van Assche

Improve static type checking by using the enum req_op type for variables that represent a request operation and the new blk_opf_t type for variables that represent request flags.

Quoted 8 lines
---
 fs/nilfs2/btnode.c            | 4 ++--
 fs/nilfs2/btnode.h            | 5 +++--
 fs/nilfs2/mdt.c               | 3 ++-
 include/trace/events/nilfs2.h | 4 ++--
 4 files changed, 9 insertions(+), 7 deletions(-)

I've checked this patch, picking up some of the block layer patches needed to understand this conversion from the list of linux-block.

Ryusuke Konishi

#66 lore raw

Re: [PATCH 51/51] fs/zonefs: Fix sparse warnings in tracing code

In reply to Bart Van Assche
Quoted 2 lines · Bart Van Assche

Since __bitwise types are not supported by the tracing infrastructure, store the operation type as an int in the tracing event.

Please give the field in the trace even the proper type instead of all the crazy casting.

maintainer Acked-by on v1 10/51
#11 lore raw

Re: [PATCH 10/51] block/drbd: Use the enum req_op and blk_opf_t types

In reply to Bart Van Assche

Am 23.06.22 um 20:04 schrieb Bart Van Assche:

Quoted 132 lines

Improve static type checking by using the enum req_op type for variables that represent a request operation and the new blk_opf_t type for variables that represent request flags.

Cc Lars Ellenberg <[email protected]>
Cc Philipp Reisner <[email protected]>
Cc Christoph Böhmwalder <[email protected]>
---
 drivers/block/drbd/drbd_actlog.c   |  9 +++++----
 drivers/block/drbd/drbd_bitmap.c   |  3 ++-
 drivers/block/drbd/drbd_int.h      |  6 +++---
 drivers/block/drbd/drbd_receiver.c | 11 ++++++-----
 4 files changed, 16 insertions(+), 13 deletions(-)
drivers/block/drbd/drbd_actlog.c +5 -4
index f5bcded3640d..e27478ae579c 100644
@@ -124,12 +124,13 @@ void wait_until_done_or_force_detached(struct drbd_device *device, struct drbd_b
 
 static int _drbd_md_sync_page_io(struct drbd_device *device,
 				 struct drbd_backing_dev *bdev,
-				 sector_t sector, int op)
+				 sector_t sector, enum req_op op)
 {
 	struct bio *bio;
 	/* we do all our meta data IO in aligned 4k blocks. */
 	const int size = 4096;
-	int err, op_flags = 0;
+	int err;
+	blk_opf_t op_flags = 0;
 
 	device->md_io.done = 0;
 	device->md_io.error = -ENODEV;
@@ -174,7 +175,7 @@ static int _drbd_md_sync_page_io(struct drbd_device *device,
 }
 
 int drbd_md_sync_page_io(struct drbd_device *device, struct drbd_backing_dev *bdev,
-			 sector_t sector, int op)
+			 sector_t sector, enum req_op op)
 {
 	int err;
 	D_ASSERT(device, atomic_read(&device->md_io.in_use) == 1);
@@ -385,7 +386,7 @@ static int __al_write_transaction(struct drbd_device *device, struct al_transact
 		write_al_updates = rcu_dereference(device->ldev->disk_conf)->al_updates;
 		rcu_read_unlock();
 		if (write_al_updates) {
-			if (drbd_md_sync_page_io(device, device->ldev, sector, WRITE)) {
+			if (drbd_md_sync_page_io(device, device->ldev, sector, REQ_OP_WRITE)) {
 				err = -EIO;
 				drbd_chk_io_error(device, 1, DRBD_META_IO_ERROR);
 			} else {
drivers/block/drbd/drbd_bitmap.c +2 -1
index bd2133ef6e0a..0845f28a48a7 100644
@@ -990,7 +990,8 @@ static inline sector_t drbd_md_last_bitmap_sector(struct drbd_backing_dev *bdev)
 static void bm_page_io_async(struct drbd_bm_aio_ctx *ctx, int page_nr) __must_hold(local)
 {
 	struct drbd_device *device = ctx->device;
-	unsigned int op = (ctx->flags & BM_AIO_READ) ? REQ_OP_READ : REQ_OP_WRITE;
+	const enum req_op op = ctx->flags & BM_AIO_READ ? REQ_OP_READ :
+		REQ_OP_WRITE;
 	struct drbd_bitmap *b = device->bitmap;
 	struct bio *bio;
 	struct page *page;
drivers/block/drbd/drbd_int.h +3 -3
index 4d3efaa20b7b..ecb2ecd8d67d 100644
@@ -1495,7 +1495,7 @@ extern int drbd_resync_finished(struct drbd_device *device);
 extern void *drbd_md_get_buffer(struct drbd_device *device, const char *intent);
 extern void drbd_md_put_buffer(struct drbd_device *device);
 extern int drbd_md_sync_page_io(struct drbd_device *device,
-		struct drbd_backing_dev *bdev, sector_t sector, int op);
+		struct drbd_backing_dev *bdev, sector_t sector, enum req_op op);
 extern void drbd_ov_out_of_sync_found(struct drbd_device *, sector_t, int);
 extern void wait_until_done_or_force_detached(struct drbd_device *device,
 		struct drbd_backing_dev *bdev, unsigned int *done);
@@ -1547,8 +1547,8 @@ extern bool drbd_rs_c_min_rate_throttle(struct drbd_device *device);
 extern bool drbd_rs_should_slow_down(struct drbd_device *device, sector_t sector,
 		bool throttle_if_app_is_waiting);
 extern int drbd_submit_peer_request(struct drbd_device *,
-				    struct drbd_peer_request *, const unsigned,
-				    const unsigned, const int);
+				    struct drbd_peer_request *, enum req_op,
+				    blk_opf_t, int);
 extern int drbd_free_peer_reqs(struct drbd_device *, struct list_head *);
 extern struct drbd_peer_request *drbd_alloc_peer_req(struct drbd_peer_device *, u64,
 						     sector_t, unsigned int,
drivers/block/drbd/drbd_receiver.c +5 -4
index 6762be53f409..caf646dd91ba 100644
@@ -1621,7 +1621,7 @@ static void drbd_issue_peer_discard_or_zero_out(struct drbd_device *device, stru
 /* TODO allocate from our own bio_set. */
 int drbd_submit_peer_request(struct drbd_device *device,
 			     struct drbd_peer_request *peer_req,
-			     const unsigned op, const unsigned op_flags,
+			     const enum req_op op, const blk_opf_t op_flags,
 			     const int fault_type)
 {
 	struct bio *bios = NULL;
@@ -2383,14 +2383,14 @@ static int wait_for_and_update_peer_seq(struct drbd_peer_device *peer_device, co
 /* see also bio_flags_to_wire()
  * DRBD_REQ_*, because we need to semantically map the flags to data packet
  * flags and back. We may replicate to other kernel versions. */
-static unsigned long wire_flags_to_bio_flags(u32 dpf)
+static blk_opf_t wire_flags_to_bio_flags(u32 dpf)
 {
 	return  (dpf & DP_RW_SYNC ? REQ_SYNC : 0) |
 		(dpf & DP_FUA ? REQ_FUA : 0) |
 		(dpf & DP_FLUSH ? REQ_PREFLUSH : 0);
 }
 
-static unsigned long wire_flags_to_bio_op(u32 dpf)
+static enum req_op wire_flags_to_bio_op(u32 dpf)
 {
 	if (dpf & DP_ZEROES)
 		return REQ_OP_WRITE_ZEROES;
@@ -2543,7 +2543,8 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
 	struct drbd_peer_request *peer_req;
 	struct p_data *p = pi->data;
 	u32 peer_seq = be32_to_cpu(p->seq_num);
-	int op, op_flags;
+	enum req_op op;
+	blk_opf_t op_flags;
 	u32 dp_flags;
 	int err, tp;
 

drivers/block/drbd/drbd_receiver.c static int receive_rs_deallocated(struct drbd_connection *connection, struct pac · line 4958

Quoted 8 lines
drivers/block/drbd/drbd_receiver.c +1 -1
@@ -4951,7 +4952,7 @@ static int receive_rs_deallocated(struct drbd_connection *connection, struct pac
 
 	if (get_ldev(device)) {
 		struct drbd_peer_request *peer_req;
-		const int op = REQ_OP_WRITE_ZEROES;
+		const enum req_op op = REQ_OP_WRITE_ZEROES;
 
 		peer_req = drbd_alloc_peer_req(peer_device, ID_SYNCER, sector,
 					       size, 0, GFP_NOIO);

LGTM, thanks.

Signature · 3 lines
Christoph Böhmwalder
LINBIT | Keeping the Digital World Running
DRBD HA —  Disaster Recovery — Software defined Storage
#89 lore raw
In reply to Bart Van Assche

Hi Bart,

I generally like this. Two thoughs:

- I suspect most places that currently pass a enum req_op might really want a blk_opf_t for future extensibility, exceptions are very low-level helpers like req_op() and bio_op() where the enum is very nice to force switch statements to handle all ops or have a default statements
- a lot of the flags printinting is a mess, and introduce the code smell of __force casts. It migh make sense to introduce a new %psomething format specifier first to print a blk_opf_t using printk/vsprintf/etc and switch everyone to that first instead of hand crafted printing.

#90 lore raw
Quoted 4 lines · Christoph Hellwig

Hi Bart,

I generally like this. Two thoughs:

Quoted 10 lines

- I suspect most places that currently pass a enum req_op might really want a blk_opf_t for future extensibility, exceptions are very low-level helpers like req_op() and bio_op() where the enum is very nice to force switch statements to handle all ops or have a default statements
- a lot of the flags printinting is a mess, and introduce the code smell of __force casts. It migh make sense to introduce a new %psomething format specifier first to print a blk_opf_t using printk/vsprintf/etc and switch everyone to that first instead of hand crafted printing.

Oh, and a third: there is still various places passing the op separately from the flags and/or using bio_set_op_attrs. This would be a good time to clean the rest of those up (I already did a lot of that gradually).

author reviewer
#67 lore raw

Re: [PATCH 51/51] fs/zonefs: Fix sparse warnings in tracing code

In reply to Christoph Hellwig
Quoted 6 lines · Christoph Hellwig
Quoted 2 lines · Bart Van Assche

Since __bitwise types are not supported by the tracing infrastructure, store the operation type as an int in the tracing event.

Please give the field in the trace even the proper type instead of all the crazy casting.

Hi Christoph,

I will do that. BTW, I discovered the code in the tracing infrastructure that makes sparse unhappy:

#define is_signed_type(type) (((type)(-1)) < (type)1)

Sparse reports four warnings for that expression if 'type' is a bitwise type. Two of these warnings can be suppressed by changing 'type' into '__force type'. I have not yet found a way to suppress all the sparse warnings triggered by the is_signed_type() macro for bitwise types.

Thanks,

Bart.

author reviewer
#53 lore raw

Re: [PATCH 46/51] fs/nilfs: Use the enum req_op and blk_opf_t types

In reply to Ryusuke Konishi
Quoted 15 lines · Ryusuke Konishi
Quoted 5 lines · Bart Van Assche

Improve static type checking by using the enum req_op type for variables that represent a request operation and the new blk_opf_t type for variables that represent request flags.

Quoted 8 lines
---
  fs/nilfs2/btnode.c            | 4 ++--
  fs/nilfs2/btnode.h            | 5 +++--
  fs/nilfs2/mdt.c               | 3 ++-
  include/trace/events/nilfs2.h | 4 ++--
  4 files changed, 9 insertions(+), 7 deletions(-)
Quoted 4 lines

I've checked this patch, picking up some of the block layer patches needed to understand this conversion from the list of linux-block.

Hi Ryusuke,

Thank you for the quick review.

Does "picking up" perhaps mean that you plan to send a subset of this patch series to Linus yourself? I prefer that the entire patch series is sent to Linus by a single kernel maintainer.

Thanks,

Bart.

maintainer
#54 lore raw

Re: [PATCH 46/51] fs/nilfs: Use the enum req_op and blk_opf_t types

Hi Bart,

Quoted 22 lines · Bart Van Assche
Quoted 15 lines · Ryusuke Konishi
Quoted 5 lines · Bart Van Assche

Improve static type checking by using the enum req_op type for variables that represent a request operation and the new blk_opf_t type for variables that represent request flags.

Quoted 8 lines
---
  fs/nilfs2/btnode.c            | 4 ++--
  fs/nilfs2/btnode.h            | 5 +++--
  fs/nilfs2/mdt.c               | 3 ++-
  include/trace/events/nilfs2.h | 4 ++--
  4 files changed, 9 insertions(+), 7 deletions(-)
Quoted 4 lines

I've checked this patch, picking up some of the block layer patches needed to understand this conversion from the list of linux-block.

Quoted 7 lines

Hi Ryusuke,

Thank you for the quick review.

Does "picking up" perhaps mean that you plan to send a subset of this patch series to Linus yourself? I prefer that the entire patch series is sent to Linus by a single kernel maintainer.

Sorry for the misleading wording.
That just means that I tracked and confirmed the related block layer patches in the series to properly review this patch. I recognize that the entire patch series should be sent through the same maintainer.

Regards,
Ryusuke Konishi

Acked-by on v1 50/51
#61 lore raw

Re: [PATCH 50/51] fs/xfs: Use the enum req_op and blk_opf_t types

In reply to Bart Van Assche

[+linux-xfs]

Quoted 7 lines · Bart Van Assche

Improve static type checking by using the enum req_op type for variables that represent a request operation and the new blk_opf_t type for the combination of a request operation with request flags.

Cc Darrick J. Wong <[email protected]>
Cc Christoph Hellwig <[email protected]>

Looks good to me, though I had to dig around to find out what these new types were.

--D

Quoted 68 lines
---
 fs/xfs/xfs_bio_io.c      | 2 +-
 fs/xfs/xfs_buf.c         | 4 ++--
 fs/xfs/xfs_linux.h       | 2 +-
 fs/xfs/xfs_log_recover.c | 2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)
fs/xfs/xfs_bio_io.c +1 -1
index ae4345b37621..fe21c76f75b8 100644
@@ -15,7 +15,7 @@ xfs_rw_bdev(
 	sector_t		sector,
 	unsigned int		count,
 	char			*data,
-	unsigned int		op)
+	enum req_op		op)
 
 {
 	unsigned int		is_vmalloc = is_vmalloc_addr(data);
fs/xfs/xfs_buf.c +2 -2
index bf4e60871068..5e8f40d8c052 100644
@@ -1416,7 +1416,7 @@ xfs_buf_ioapply_map(
 	int		map,
 	int		*buf_offset,
 	int		*count,
-	int		op)
+	blk_opf_t	op)
 {
 	int		page_index;
 	unsigned int	total_nr_pages = bp->b_page_count;
@@ -1493,7 +1493,7 @@ _xfs_buf_ioapply(
 	struct xfs_buf	*bp)
 {
 	struct blk_plug	plug;
-	int		op;
+	blk_opf_t	op;
 	int		offset;
 	int		size;
 	int		i;
fs/xfs/xfs_linux.h +1 -1
index cb9105d667db..f9878021e7d0 100644
@@ -196,7 +196,7 @@ static inline uint64_t howmany_64(uint64_t x, uint32_t y)
 }
 
 int xfs_rw_bdev(struct block_device *bdev, sector_t sector, unsigned int count,
-		char *data, unsigned int op);
+		char *data, enum req_op op);
 
 #define ASSERT_ALWAYS(expr)	\
 	(likely(expr) ? (void)0 : assfail(NULL, #expr, __FILE__, __LINE__))
fs/xfs/xfs_log_recover.c +1 -1
index 5f7e4e6e33ce..940c8107cbd4 100644
@@ -122,7 +122,7 @@ xlog_do_io(
 	xfs_daddr_t		blk_no,
 	unsigned int		nbblks,
 	char			*data,
-	unsigned int		op)
+	enum req_op		op)
 {
 	int			error;
 
#68 lore raw

Re: [PATCH 51/51] fs/zonefs: Fix sparse warnings in tracing code

In reply to Bart Van Assche
Quoted 13 lines · Bart Van Assche
Quoted 6 lines · Christoph Hellwig
Quoted 2 lines · Bart Van Assche

Since __bitwise types are not supported by the tracing infrastructure, store the operation type as an int in the tracing event.

Please give the field in the trace even the proper type instead of all the crazy casting.

Hi Christoph,

I will do that. BTW, I discovered the code in the tracing infrastructure that makes sparse unhappy:

Quoted 6 lines

#define is_signed_type(type) (((type)(-1)) < (type)1)

Sparse reports four warnings for that expression if 'type' is a bitwise type. Two of these warnings can be suppressed by changing 'type' into '__force type'. I have not yet found a way to suppress all the sparse warnings triggered by the is_signed_type() macro for bitwise types.

Yeah, that is a bit of a mess. Rasmus, Steven - any good idea how we can make the trace even macros fit for sparse? Maybe just drop the is_signed_type check for __CHECKER__ ?

author reviewer
#69 lore raw

Re: [PATCH 51/51] fs/zonefs: Fix sparse warnings in tracing code

Quoted 6 lines · Christoph Hellwig
Quoted 5 lines · Bart Van Assche

BTW, I discovered the code in the tracing infrastructure that makes sparse unhappy:

#define is_signed_type(type) (((type)(-1)) < (type)1)

Quoted 8 lines
Quoted 4 lines

Sparse reports four warnings for that expression if 'type' is a bitwise type. Two of these warnings can be suppressed by changing 'type' into '__force type'. I have not yet found a way to suppress all the sparse warnings triggered by the is_signed_type() macro for bitwise types.

Yeah, that is a bit of a mess. Rasmus, Steven - any good idea how we can make the trace even macros fit for sparse? Maybe just drop the is_signed_type check for __CHECKER__ ?

How about the patch below?

Subject: [PATCH] tracing: Suppress sparse warnings triggered by
is_signed_type()

Using a __bitwise type in a tracing __field() definition triggers four sparse warnings in stage 4 of expanding the TRACE_EVENT() macro. These warnings are triggered by the is_signed_type() macro implementation. Since there is no known way of checking signedness of a bitwise type without triggering sparse warnings, disable signedness checking when verifying code with sparse.

Cc Steven Rostedt <[email protected]>
Cc Rasmus Villemoes <[email protected]>
Cc Luc Van Oostenryck <[email protected]>
---
 include/linux/trace_events.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)
include/linux/trace_events.h +12 -0
index e6e95a9f07a5..f7b2a5467361 100644
@@ -814,7 +814,19 @@ extern int trace_add_event_call(struct trace_event_call *call);
 extern int trace_remove_event_call(struct trace_event_call *call);
 extern int trace_event_get_offsets(struct trace_event_call *call);
 
+/*
+ * There is no known way to check signedness of __bitwise types without
+ * triggering a sparse warning. Hence the #ifdef __CHECKER__.
+ *
+ * There is another definition of is_signed_type() in <linux/overflow.h>.
+ * Hence undefine is_signed_type() before redefining it.
+ */
+#undef is_signed_type
+#ifdef __CHECKER__
+#define is_signed_type(type)	0
+#else
 #define is_signed_type(type)	(((type)(-1)) < (type)1)
+#endif
 
 int ftrace_set_clr_event(struct trace_array *tr, char *buf, int set);
 int trace_set_clr_event(const char *system, const char *event, int set);
#70 lore raw

Re: [PATCH 51/51] fs/zonefs: Fix sparse warnings in tracing code

In reply to Bart Van Assche
Quoted 11 lines · Bart Van Assche
Quoted 10 lines · Christoph Hellwig
Quoted 9 lines · Bart Van Assche

BTW, I discovered the code in the tracing infrastructure that makes sparse unhappy:

#define is_signed_type(type) (((type)(-1)) < (type)1)

Sparse reports four warnings for that expression if 'type' is a bitwise type. Two of these warnings can be suppressed by changing 'type' into '__force type'. I have not yet found a way to suppress all the sparse warnings triggered by the is_signed_type() macro for bitwise types.

Yes, __bitwise is quite strict and only support the bitwise operations (&, |, ^ and).

Quoted 3 lines
Quoted 3 lines

Yeah, that is a bit of a mess. Rasmus, Steven - any good idea how we can make the trace even macros fit for sparse? Maybe just drop the is_signed_type check for __CHECKER__ ?

I would strongly advise against this:
-) the macro is sued elsewhere too (for overflow checking) -) sparse wouldn't check anymore the same code as the one seen by the
compiler

What about I would add to sparse something to strip away the bitwise/ recover the underlying type? Something like __unbitwiseof() or __underlying_typeof() (some better name is needed)?

Implementing directly what's needed here, something like __is_signed_type() would be possible too but is a bit too specialized and so much less useful.

-- Luc Van Oostenryck

author reviewer
#71 lore raw

Re: [PATCH 51/51] fs/zonefs: Fix sparse warnings in tracing code

Quoted 11 lines · Luc Van Oostenryck
Quoted 4 lines · Bart Van Assche
Quoted 3 lines · Christoph Hellwig

Yeah, that is a bit of a mess. Rasmus, Steven - any good idea how we can make the trace even macros fit for sparse? Maybe just drop the is_signed_type check for __CHECKER__ ?

I would strongly advise against this:

(quoted diff) +0 -2
-) the macro is sued elsewhere too (for overflow checking)
-) sparse wouldn't check anymore the same code as the one seen by the
    compiler
Quoted 6 lines

What about I would add to sparse something to strip away the bitwise/ recover the underlying type? Something like __unbitwiseof() or __underlying_typeof() (some better name is needed)?

Implementing directly what's needed here, something like __is_signed_type() would be possible too but is a bit too specialized and so much less useful.

Another question is how to keep the non-sparse build working. Does anyone want to comment on the following alternatives or propose another alternative?

(1) sparse implements __strip_bitwise as a macro.

(in compiler.h)

#ifndef __strip_bitwise
#define __strip_bitwise(type) type
#endif

(in trace_events.h)

#define is_signed_type(type) ((__strip_bitwise(type))(-1) < (__strip_bitwise(type))1)

(2) sparse implements __strip_bitwise as an operator that works on types.

#ifdef __CHECKER__
#define is_signed_type(type) ((__strip_bitwise(type))(-1) < (__strip_bitwise(type))1) #else
#define is_signed_type(type) (((type)(-1)) < (type)1)
#endif

(1) would work better than (2) for kernel developers who are using a version of sparse that does not support __strip_bitwise().

Thanks,

Bart.

#72 lore raw

Re: [PATCH 51/51] fs/zonefs: Fix sparse warnings in tracing code

Quoted 27 lines · Bart Van Assche
Quoted 11 lines · Luc Van Oostenryck
Quoted 4 lines · Bart Van Assche
Quoted 3 lines · Christoph Hellwig

Yeah, that is a bit of a mess. Rasmus, Steven - any good idea how we can make the trace even macros fit for sparse? Maybe just drop the is_signed_type check for __CHECKER__ ?

I would strongly advise against this:

(quoted diff) +0 -2
-) the macro is sued elsewhere too (for overflow checking)
-) sparse wouldn't check anymore the same code as the one seen by the
    compiler
Quoted 3 lines

What about I would add to sparse something to strip away the bitwise/ recover the underlying type? Something like __unbitwiseof() or __underlying_typeof() (some better name is needed)?

Another question is how to keep the non-sparse build working. Does anyone want to comment on the following alternatives or propose another alternative?

(1) sparse implements __strip_bitwise as a macro.

(in compiler.h)

#ifndef __strip_bitwise
#define __strip_bitwise(type) type
#endif

...

Quoted 2 lines

(1) would work better than (2) for kernel developers who are using a version of sparse that does not support __strip_bitwise().

Yes, sure. I was thinking about using (and adding) __has_feature() but the goal is the same.

[I prefer this because, internally, an operator is needed anyway and __has_feature() would be more general (but then it would need to be protected by its own #ifndef __has_feature).]

-- Luc

#73 lore raw

Re: [PATCH 51/51] fs/zonefs: Fix sparse warnings in tracing code

In reply to Luc Van Oostenryck
Quoted 4 lines · Luc Van Oostenryck

What about I would add to sparse something to strip away the bitwise/ recover the underlying type? Something like __unbitwiseof() or __underlying_typeof() (some better name is needed)?

Please no, we don't want to make random macros have to have sparse logic in them when it's not actually sparse-related.

I think it would be better if sparse just recognized some of these kinds of situation. In particular:

(a) for the casting part, I actually suspect we should drop the
warning about castign integers to restricted types.

Note that this is actually one of the main causes of "__force" use in the kernel, with code like

        VM_FAULT_OOM            = (__force vm_fault_t)0x000001,
        VM_FAULT_SIGBUS         = (__force vm_fault_t)0x000002,
        VM_FAULT_MAJOR          = (__force vm_fault_t)0x000004,
        VM_FAULT_WRITE          = (__force vm_fault_t)0x000008,

and I think that we could/should just say that "explicit casts of constants are ok".

That would remove two of the four warnings right there, and probably make bitwise types more convenient in general.

We already treat "0" as special (because for bitwise things, zero is kind of the universal constant), and we should continue to warn about _implicit_ casts of restricted types, but I think the use of "__force" in the kernel does show that the explicit casts are probably a bad idea.

(b) I think we could also recognize "comparison of constants" to be
something that doesn't necessarily require a warning.

And here in particular the "compare with zero" and "compare with all bits set" - which is exactly that "-1" case.

In fact, there's a very good argument that "-1" is as special as zero is ("all bits set" vs "all bits clear"), so for that (a) case, I think at a _minimum_ we shouldn't warn about that particular constant.

So I think we could silence this sparse warning entirely, without really introducing any new syntax, and actually improving on how bitwise works.

Linus

#74 lore raw

Re: [PATCH 51/51] fs/zonefs: Fix sparse warnings in tracing code

Quoted 3 lines · Linus Torvalds

(a) for the casting part, I actually suspect we should drop the
warning about castign integers to restricted types.

Heh. Trying that out, I find we seem to do this at the wrong point anyway.

I removed the check for "value of 0 is ok", and it continues to warn about casting "-1".

Because it does that before "-1" has even been simplified, so it actually sees it as an *expression* ("negate the constant 1") rather than as the *value* -1, and it warns.

That's a bit sad since really -1 and ~0 really both should be ok for the same reason plain zero is ok - regardless of the whole "do we just allow it for constants in general" thing.

I think the bitwise thing was always a bit half-baked. It was designed for detecting little-endian and big-endian issues, and "bitmask" types. And it's wonderful for the basics of that, but I think it was never really thought through for this kind of extended use where we end up having generic macros that do still make sense for them, but aren't that exact "avoid assigning bitwise values to other values"

Linus

maintainer
#88 lore raw

Re: [PATCH 51/51] fs/zonefs: Fix sparse warnings in tracing code

In reply to Christoph Hellwig
Quoted 3 lines · On Sat, 25 Jun 2022 11:23:49 +0200 Christoph Hellwig <[email protected]> wrote:

eah, that is a bit of a mess. Rasmus, Steven - any good idea how we can make the trace even macros fit for sparse? Maybe just drop the is_signed_type check for __CHECKER__ ?

I'm fine with whatever sparse folks come up with. If you want, I can test any updates to this macro to make sure it doesn't change the result in other use cases within trace events.

-- Steve

#76 lore raw

Re: [PATCH 51/51] fs/zonefs: Fix sparse warnings in tracing code

In reply to Linus Torvalds
Quoted 7 lines · Linus Torvalds
Quoted 4 lines · Luc Van Oostenryck

What about I would add to sparse something to strip away the bitwise/ recover the underlying type? Something like __unbitwiseof() or __underlying_typeof() (some better name is needed)?

Quoted 5 lines

Please no, we don't want to make random macros have to have sparse logic in them when it's not actually sparse-related.

I think it would be better if sparse just recognized some of these kinds of situation. In particular:

Yes, sure, it's ideal.

Quoted 10 lines

(a) for the casting part, I actually suspect we should drop the
warning about castign integers to restricted types.

Note that this is actually one of the main causes of "__force" use in the kernel, with code like

        VM_FAULT_OOM            = (__force vm_fault_t)0x000001,
        VM_FAULT_SIGBUS         = (__force vm_fault_t)0x000002,
        VM_FAULT_MAJOR          = (__force vm_fault_t)0x000004,
        VM_FAULT_WRITE          = (__force vm_fault_t)0x000008,

This example is about an enumeration. It's, IMO, a very special case in its own. Two years ago or so, I had proposed to have 'bitwise' enums where the cast was not needed. In itself is was very easy to do but there was a lot of subtle issues about type attributes. I think I've since solved these issues but on the way I've lost my motivation for these bitwise enums. I'll take a look at it again.

Quoted 2 lines

and I think that we could/should just say that "explicit casts of constants are ok".

I'm not convinced, for example when thinking about __be{16,32}. But on the principle, I fully agree: unneeded casts should be avoided.

Quoted 8 lines

That would remove two of the four warnings right there, and probably make bitwise types more convenient in general.

We already treat "0" as special (because for bitwise things, zero is kind of the universal constant), and we should continue to warn about _implicit_ casts of restricted types, but I think the use of "__force" in the kernel does show that the explicit casts are probably a bad idea.

Yes.

Quoted 6 lines

(b) I think we could also recognize "comparison of constants" to be
something that doesn't necessarily require a warning.

And here in particular the "compare with zero" and "compare with all bits set" - which is exactly that "-1" case.

Quoted 7 lines

In fact, there's a very good argument that "-1" is as special as zero is ("all bits set" vs "all bits clear"), so for that (a) case, I think at a _minimum_ we shouldn't warn about that particular constant.

So I think we could silence this sparse warning entirely, without really introducing any new syntax, and actually improving on how bitwise works.

Yes, indeed.

-- Luc

#75 lore raw

Re: [PATCH 51/51] fs/zonefs: Fix sparse warnings in tracing code

In reply to Linus Torvalds
Quoted 11 lines · Linus Torvalds
Quoted 3 lines · Linus Torvalds

(a) for the casting part, I actually suspect we should drop the
warning about castign integers to restricted types.

Heh. Trying that out, I find we seem to do this at the wrong point anyway.

I removed the check for "value of 0 is ok", and it continues to warn about casting "-1".

Quoted 7 lines

Because it does that before "-1" has even been simplified, so it actually sees it as an *expression* ("negate the constant 1") rather than as the *value* -1, and it warns.

That's a bit sad since really -1 and ~0 really both should be ok for the same reason plain zero is ok - regardless of the whole "do we just allow it for constants in general" thing.

Well, this "there is no negative constants, only minus positive ones" is kinda special. Maybe we can special-case this, just doing an early mini-expansion of PREOP('-', EXPR_VALUE). I'm not sure about all implications it would have on typechecking though.

Quoted 6 lines

I think the bitwise thing was always a bit half-baked. It was designed for detecting little-endian and big-endian issues, and "bitmask" types. And it's wonderful for the basics of that, but I think it was never really thought through for this kind of extended use where we end up having generic macros that do still make sense for them, but aren't that exact "avoid assigning bitwise values to other values"

Yes, I fully agree
Also, it's the only 'strong' type that sparse has (IIRC nocast was too weak), so it's used for everything. Allowing only the bitwise operators is often too restrictive. I think that often what people just need is an unique type that doesn't mix with other types but that can 1) mix with constants (certainly with 0, 1 and -1) and
2) can use the usual arithmetic operations (certainly the compares).

-- Luc

Acked-by on v1 49/51
#59 lore raw

Re: [PATCH 49/51] PM: Use the enum req_op and blk_opf_t types

In reply to Bart Van Assche
Quoted 7 lines · Bart Van Assche

Improve static type checking by using the enum req_op type for variables that represent a request operation and the new blk_opf_t type for variables that represent request flags.

Cc Rafael J. Wysocki <[email protected]>
Cc Christoph Hellwig <[email protected]>

Or if you want me to pick it up, please resend it with a CC to [email protected].

Thanks!

Quoted 19 lines
---
  kernel/power/swap.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
kernel/power/swap.c +2 -2
index 91fffdd2c7fb..db01cac40a4c 100644
@@ -269,8 +269,8 @@ static void hib_end_io(struct bio *bio)
  	bio_put(bio);
  }
 
-static int hib_submit_io(int op, int op_flags, pgoff_t page_off, void *addr,
-		struct hib_bio_batch *hb)
+static int hib_submit_io(enum req_op op, blk_opf_t op_flags,
+			 pgoff_t page_off, void *addr, struct hib_bio_batch *hb)
  {
  	struct page *page = virt_to_page(addr);
  	struct bio *bio;
#78 lore raw

PATCH 1/5 bitwise: add testcases

In reply to Luc Van Oostenryck

Currently bitwise types only support bitwise operations (&, |, ^ and ~) and the constant 0 (since this value is invariant for all bitwise operations and endianness conversion).

But the incoming series will relax this a little bit. So, add a few testcases for it.

---
 validation/bitwise-cmp.c         | 32 ++++++++++++++++++++++++++++++++
 validation/bitwise-is-signed.c   | 22 ++++++++++++++++++++++
 validation/linear/bitwise-cmps.c | 18 ++++++++++++++++++
 validation/linear/bitwise-cmpu.c | 18 ++++++++++++++++++
 4 files changed, 90 insertions(+)
 create mode 100644 validation/bitwise-cmp.c
 create mode 100644 validation/bitwise-is-signed.c
 create mode 100644 validation/linear/bitwise-cmps.c
 create mode 100644 validation/linear/bitwise-cmpu.c
validation/bitwise-cmp.c new file +32 -0
new file mode 100644
index 000000000000..ca12b5e51e8e
@@ -0,0 +1,32 @@
+#define M 0xffffffff
+
+typedef int __attribute__((bitwise)) b32;
+
+static int eq0(b32 x, b32 y)  { return (x == 0); }
+static int eqm(b32 x, b32 y)  { return (x == M); }
+static int eqx(b32 x, b32 y)  { return (x == y); }
+
+static int ne0(b32 x, b32 y)  { return (x != 0); }
+static int nem(b32 x, b32 y)  { return (x != M); }
+static int nex(b32 x, b32 y)  { return (x != y); }
+
+static int lt0(b32 x, b32 y)  { return (x <  0); }
+static int ltm(b32 x, b32 y)  { return (x <  M); }
+static int ltx(b32 x, b32 y)  { return (x <  y); }
+
+static int lte0(b32 x, b32 y) { return (x <= 0); }
+static int ltem(b32 x, b32 y) { return (x <= M); }
+static int ltex(b32 x, b32 y) { return (x <= y); }
+
+static int gte0(b32 x, b32 y) { return (x >= 0); }
+static int gtem(b32 x, b32 y) { return (x >= M); }
+static int gtex(b32 x, b32 y) { return (x >= y); }
+
+static int gt0(b32 x, b32 y)  { return (x >  0); }
+static int gtm(b32 x, b32 y)  { return (x >  M); }
+static int gtx(b32 x, b32 y)  { return (x >  y); }
+
+/*
+ * check-name: bitwise-cmp
+ * check-known-to-fail
+ */
validation/bitwise-is-signed.c new file +22 -0
new file mode 100644
index 000000000000..dd9c147173cd
@@ -0,0 +1,22 @@
+#define __bitwise __attribute__((bitwise))
+
+#define is_signed_type(type)  (((type)-1) <= 0)
+
+typedef   signed int __bitwise s;
+typedef unsigned int __bitwise u;
+
+int fos(void);
+int fou(void);
+
+
+int fos(void) { return  is_signed_type(s); }
+int fou(void) { return !is_signed_type(u); }
+
+/*
+ * check-name: bitwise-is-signed
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-returns: 1
+ */
validation/linear/bitwise-cmps.c new file +18 -0
new file mode 100644
index 000000000000..6122944a42c6
@@ -0,0 +1,18 @@
+typedef   signed int __attribute__((bitwise)) bs32;
+
+static int ltu(bs32 x, bs32 y)  { return (x <  y); }
+static int lteu(bs32 x, bs32 y) { return (x <= y); }
+static int gteu(bs32 x, bs32 y) { return (x >= y); }
+static int gtu(bs32 x, bs32 y)  { return (x >  y); }
+
+/*
+ * check-name: bitwise-cmps
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-excludes: setb\\.
+ * check-output-excludes: setbe\\.
+ * check-output-excludes: setae\\.
+ * check-output-excludes: seta\\.
+ */
validation/linear/bitwise-cmpu.c new file +18 -0
new file mode 100644
index 000000000000..8932436a7764
@@ -0,0 +1,18 @@
+typedef unsigned int __attribute__((bitwise)) bu32;
+
+static int ltu(bu32 x, bu32 y)  { return (x <  y); }
+static int lteu(bu32 x, bu32 y) { return (x <= y); }
+static int gteu(bu32 x, bu32 y) { return (x >= y); }
+static int gtu(bu32 x, bu32 y)  { return (x >  y); }
+
+/*
+ * check-name: bitwise-cmpu
+ * check-command: test-linearize -Wno-decl $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-excludes: setlt\\.
+ * check-output-excludes: setlte\\.
+ * check-output-excludes: setgte\\.
+ * check-output-excludes: setgt\\.
+ */
Signature · 1 line
2.36.1
#79 lore raw

PATCH 2/5 bitwise: accept all ones as non-restricted value

In reply to Luc Van Oostenryck

Currently, the only value bitwise types can act on is 0 because the this value is anyway invariant for all bitwise operations and endianness conversions.

But, a bit-pattern of all ones has the same properties and is also very often used.

So, accept all ones as a valid value for bitwise operations.

---
 evaluate.c                |  2 +-
 validation/bitwise-cast.c | 13 +++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)
evaluate.c +1 -1
index 61f59ee3908e..bcbcdf1ef0cc 100644
@@ -417,7 +417,7 @@ static int restricted_value(struct expression *v, struct symbol *type)
 {
 	if (v->type != EXPR_VALUE)
 		return 1;
-	if (v->value != 0)
+	if (v->value != 0 && v->value != bits_mask(type->bit_size))
 		return 1;
 	return 0;
 }
validation/bitwise-cast.c +13 -0
index 0583461cb745..1075a3e9410c 100644
@@ -35,6 +35,19 @@ static __be32 quuy(void)
 	return (__attribute__((force)) __be32) 1730;
 }
 
+/* Implicit casts of all ones, legal */
+static __be32 foo1(void)
+{
+	__be32 x = 0xffffffff;
+	return x;
+}
+
+/* Explicit cast of all ones, legal */
+static __be32 bar1(void)
+{
+	return (__be32)0xffffffff;
+}
+
 /*
  * check-name: conversions to bitwise types
  * check-command: sparse -Wbitwise $file
Signature · 1 line
2.36.1
#81 lore raw

PATCH 3/5 bitwise: allow compares for bitwise types

In reply to Luc Van Oostenryck

Currently, bitwise types are restricted to bitwise operations (&, |, ^ and ~) as well as equality comparisons.

This patch makes the others comparisons valid for bitwise types too.

Warning: This change make sense in the context of [1] but
doesn't make sense for the 'main' bitwise types:
__be32 and friends.

---
 evaluate.c                       | 4 ++++
 validation/bitwise-cmp.c         | 1 -
 validation/linear/bitwise-cmps.c | 1 -
 3 files changed, 4 insertions(+), 2 deletions(-)
evaluate.c +4 -0
index bcbcdf1ef0cc..bb8c0caa905a 100644
@@ -435,6 +435,10 @@ static int restricted_binop(int op, struct symbol *type)
 		case '^':
 		case '?':
 			return 2;	/* keep fouled */
+		case '<':
+		case '>':
+		case SPECIAL_LTE:
+		case SPECIAL_GTE:
 		case SPECIAL_EQUAL:
 		case SPECIAL_NOTEQUAL:
 			return 3;	/* warn if fouled */
validation/bitwise-cmp.c +0 -1
index ca12b5e51e8e..8c3e6894072d 100644
@@ -28,5 +28,4 @@ static int gtx(b32 x, b32 y)  { return (x >  y); }
 
 /*
  * check-name: bitwise-cmp
- * check-known-to-fail
  */
validation/linear/bitwise-cmps.c +0 -1
index 6122944a42c6..f83ab7fe47db 100644
@@ -8,7 +8,6 @@ static int gtu(bs32 x, bs32 y)  { return (x >  y); }
 /*
  * check-name: bitwise-cmps
  * check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
  *
  * check-output-ignore
  * check-output-excludes: setb\\.
Signature · 1 line
2.36.1
#77 lore raw

cover allow -1 and compares in bitwise types

In reply to Linus Torvalds

Allow using -1 and compare operators with bitwise types

This series is an experiment for allowing constants like -1 or ~0 with bitwise types, as well as using compares on them.
the motivation for allowing this is to avoid useless casts and warnings on using some generic macros on bitwise types. The case of interest here is:

	#define is_signed_type(T) (((T)(-1)) < (T)1)

for which Sparse reports four warnings when 'T' is a bitwise type. Two of these warnings can be suppressed by using '__force' in the casts. But the other two can't be worked around because explicitly reject using any constants other than 0 with bitwise type.

The changes in the series allow to use the following testcase without any warnings:

	#define __bitwise __attribute__((bitwise))
	typedef   signed int __bitwise s;
	typedef unsigned int __bitwise u;

	#define is_signed_type(type)  (((type)-1) <= 0)

	int fs(void) { return ((s)-1) <= 0; }
	int fu(void) { return ((u)-1) <= 0; }

and result in a modest but significant decrease in the number of warnings issued by sparse (x86 {def,all}config):
- 2736 2735 cast to restricted type
+ 774 792 cast truncates bits from constant value
- 3183 3152 incorrect type in assignment (different base types)

   -   162   159 incorrect type in initializer (different base types)
   -   789   661 restricted type degrades to integer

- 13002 12857 Total

@Linus,
This seems to work correctly and I think it correspond to what you wished (maybe modulo this 'early constant expansion' I added) and I think that accepting the -1/all-ones is fine. OTOH, I don't think we can allow the compares because they don't make any sense for the 'endian' types. Surely we want to catch things like:

	typedef unsigned int __bitwise __be32;
	__be32 x, y;
	...
	... (x < y)

@Bart,
Is there a good reason why the macro compares against 1 and not against 0? Is it just because of -Wtype-limits? If so, is it possible to use '<= 0' like here above?

The series is available for review and testing at:
https://git.kernel.org/pub/scm/devel/sparse/sparse.git bitwise-ones

Luc Van Oostenryck (5):
bitwise: add testcases
bitwise: accept all ones as non-restricted value
bitwise: allow compares for bitwise types
bitwise: do not remove the signedness of bitwise types
bitwise: early expansion of simple constants

 evaluate.c                       | 52 +++++++++++++++++++++++++++++++-
 parse.c                          |  1 -
 show-parse.c                     |  2 +-
 validation/bitwise-cast.c        | 26 ++++++++++++++++
 validation/bitwise-cmp.c         | 31 +++++++++++++++++++
 validation/bitwise-is-signed.c   | 21 +++++++++++++
 validation/linear/bitwise-cmps.c | 17 +++++++++++
 validation/linear/bitwise-cmpu.c | 17 +++++++++++
 8 files changed, 164 insertions(+), 3 deletions(-)
 create mode 100644 validation/bitwise-cmp.c
 create mode 100644 validation/bitwise-is-signed.c
 create mode 100644 validation/linear/bitwise-cmps.c
 create mode 100644 validation/linear/bitwise-cmpu.c
Signature · 1 line
2.36.1
#84 lore raw

PATCH 4/5 bitwise: do not remove the signedness of bitwise types

When bitwise types were added [1] the signedness modifiers were removed from them. More exactly, it was MOD_SPECIFIER which was removed. I suppose this was done because then MOD_SPECIFIER contained the signedness bits but also MOD_CHAR, MOD_LONG, ... and those had to be removed.

But currently MOD_SPECIFIER contains only MOD_SIGNEDNESS and the signedness info can be useful for bitwise types too.

So, do not removed anymore MOD_SPECIFIER from the bitwise types' modifiers.

[1] commit 032f492af0ac ("[PATCH] __attribute__((bitwise))")

---
 parse.c                          | 1 -
 show-parse.c                     | 2 +-
 validation/linear/bitwise-cmpu.c | 1 -
 3 files changed, 1 insertion(+), 3 deletions(-)
parse.c +0 -1
index 3d6fef7cb011..14fe9e15448a 100644
@@ -1586,7 +1586,6 @@ static struct token *declaration_specifiers(struct token *token, struct decl_sta
 		}
 		type = alloc_symbol(token->pos, SYM_BASETYPE);
 		*type = *ctx->ctype.base_type;
-		type->ctype.modifiers &= ~MOD_SPECIFIER;
 		type->ctype.base_type = ctx->ctype.base_type;
 		type->type = SYM_RESTRICT;
 		ctx->ctype.base_type = type;
show-parse.c +1 -1
index e2fc18bb4b3d..2ab2479b8181 100644
@@ -318,7 +318,7 @@ deeper:
 		if (as)
 			prepend(name, "%s ", show_as(as));
 
-		if (sym && (sym->type == SYM_BASETYPE || sym->type == SYM_ENUM))
+		if (sym && (sym->type == SYM_BASETYPE || sym->type == SYM_ENUM || sym->type == SYM_RESTRICT))
 			mod &= ~MOD_SPECIFIER;
 		s = modifier_string(mod);
 		len = strlen(s);
validation/linear/bitwise-cmpu.c +0 -1
index 8932436a7764..e151b9741fa3 100644
@@ -8,7 +8,6 @@ static int gtu(bu32 x, bu32 y)  { return (x >  y); }
 /*
  * check-name: bitwise-cmpu
  * check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
  *
  * check-output-ignore
  * check-output-excludes: setlt\\.
Signature · 1 line
2.36.1
#85 lore raw

PATCH 5/5 bitwise: early expansion of simple constants

In reply to Luc Van Oostenryck

C has only positive constants: -1 is really an expression, the unary '-' operator applied to the constant 1. '-1' as a constant value only exists after the expansion of constant expressions.

This is rather unfortunate since it inhibits easy testing of such constants in the evaluation phase, like here for restricted_value().

So, expand expressions like +CTE, -CTE or ~CTE before calling restricted_value().

---
 evaluate.c                     | 48 +++++++++++++++++++++++++++++++++-
 validation/bitwise-cast.c      | 13 +++++++++
 validation/bitwise-is-signed.c |  1 -
 3 files changed, 60 insertions(+), 2 deletions(-)
evaluate.c +47 -1
index bb8c0caa905a..33cc85c8d40f 100644
@@ -413,11 +413,56 @@ static struct symbol *bad_expr_type(struct expression *expr)
 	return expr->ctype = &bad_ctype;
 }
 
+static bool expand_simple_constant(struct expression *expr, struct symbol *type)
+{
+	unsigned long long val, mask;
+	struct expression *pre;
+	struct symbol *ctype;
+	unsigned size;
+
+	if (expr->type != EXPR_PREOP)
+		return false;
+	pre = expr->unop;
+	if (pre->type != EXPR_VALUE)
+		return false;
+
+	ctype = pre->ctype;
+	if (!ctype || ctype != type)
+		return false;
+
+	size = ctype->bit_size;
+	if (!size)
+		return false;
+
+	mask = sign_bit(size);
+	switch (expr->op) {
+	case '+':
+		val = pre->value;
+		break;
+	case '-':
+		val = pre->value;
+		if (val == mask && !(ctype->ctype.modifiers & MOD_UNSIGNED))
+			return false;
+		val = -val;
+		break;
+	case '~':
+		val = pre->value;
+		val = ~val;
+		break;
+	default:
+		return false;
+	}
+	expr->op = 0;
+	expr->type = EXPR_VALUE;
+	expr->value = val & bits_mask(size);
+	return true;
+}
+
 static int restricted_value(struct expression *v, struct symbol *type)
 {
 	if (v->type != EXPR_VALUE)
 		return 1;
-	if (v->value != 0 && v->value != bits_mask(type->bit_size))
+	if (v->value != 0 && v->value != bits_mask(v->ctype->bit_size))
 		return 1;
 	return 0;
 }
@@ -1919,6 +1964,7 @@ Normal:
 	if (!(class & TYPE_FLOAT)) {
 		ctype = integer_promotion(ctype);
 		expr->unop = cast_to(expr->unop, ctype);
+		expand_simple_constant(expr, ctype);
 	} else if (expr->op != '~') {
 		/* no conversions needed */
 	} else {
validation/bitwise-cast.c +13 -0
index 1075a3e9410c..01af56c73751 100644
@@ -48,6 +48,19 @@ static __be32 bar1(void)
 	return (__be32)0xffffffff;
 }
 
+/* Implicit casts of minus one, legal */
+static __be32 foom(void)
+{
+	__be32 x = -1;
+	return x;
+}
+
+/* Explicit cast of minus one, legal */
+static __be32 barm(void)
+{
+	return (__be32)-1;
+}
+
 /*
  * check-name: conversions to bitwise types
  * check-command: sparse -Wbitwise $file
validation/bitwise-is-signed.c +0 -1
index dd9c147173cd..99d16bd20f9b 100644
@@ -15,7 +15,6 @@ int fou(void) { return !is_signed_type(u); }
 /*
  * check-name: bitwise-is-signed
  * check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
  *
  * check-output-ignore
  * check-output-returns: 1
Signature · 1 line
2.36.1
#86 lore raw

Re: [PATCH 0/5] allow -1 and compares in bitwise types

In reply to Luc Van Oostenryck
Quoted 2 lines · Luc Van Oostenryck
        #define is_signed_type(type)  (((type)-1) <= 0)

Side note: the reason we *don't* use this form in the kernel is because broken compilers will complain about compares with zero in unsigned types.

Using "<=" like you do may be an acceptable way to avoid it (the most obvious thing is to use "< 0"), but it makes me nervous.

Regardless, I think you need the cast of the zero. I think "type" might be a pointer, and sparse should be complaining about the horrid use of a bare 0 as NULL.

Similar issues might happen for enums, where various compilers will complain about comparing an enum to a non-enum.

So I'm pretty sure you would want casts on both values, instead of assuming "it's an integer type, I don't need to cast 0".

But yeah, maybe

  #define is_signed_type(type)  (((type)-1) <= (type)0)

works fine and avoids warnings in all the cases.

Famous last words. Warnings can happen for almost anything, and I wonder if that use of "1" had some other reason.

Linus

author reviewer
#87 lore raw

Re: [PATCH 0/5] allow -1 and compares in bitwise types

In reply to Luc Van Oostenryck
Quoted 5 lines · Luc Van Oostenryck

Allow using -1 and compare operators with bitwise types

This series is an experiment for allowing constants like -1 or ~0 with bitwise types, as well as using compares on them.

Will these changes cause sparse to stop complaining about the following expression?

	cpu_to_le32(1) < cpu_to_le32(2)

Shouldn't sparse keep complaining about the above expression?

Quoted 3 lines

@Bart,
Is there a good reason why the macro compares against 1 and not against 0?

Maybe to prevent that gcc or clang issues the following
warning: "warning: comparison of unsigned expression in ‘< 0’ is always false"?

Thanks,

Bart.

#82 lore raw

Re: [PATCH 3/5] bitwise: allow compares for bitwise types

In reply to Luc Van Oostenryck
Quoted 10 lines · Luc Van Oostenryck

Currently, bitwise types are restricted to bitwise operations (&, |, ^ and ~) as well as equality comparisons.

This patch makes the others comparisons valid for bitwise types too.

Warning: This change make sense in the context of [1] but
doesn't make sense for the 'main' bitwise types:
__be32 and friends.

Yeah, this is wrong.

It will literally break one of the use-cases, which is endianness comparisons.

You cannot compare values in the wrong endianness for greater-than or less-than, because you will get the wrong answer - the ordering is different in different byte-orders.

But comparing for equality (and inequality) is fine, and we actually do that in the kernel (ie you can take a big-endian value, and compare it with another big-endian value for being equal, without converting it to the local CPU endianness).

Now, comparing the *constants* 0 and all-ones is fine. They are smaller than (and larger than) all other values, regardless of any byte/bit order issues.

So I think that really needs to check that one (or both) sides are the magic constants.

Linus

#83 lore raw

Re: [PATCH 3/5] bitwise: allow compares for bitwise types

In reply to Luc Van Oostenryck
Quoted 7 lines · Luc Van Oostenryck

Currently, bitwise types are restricted to bitwise operations (&, |, ^ and ~) as well as equality comparisons.

This patch makes the others comparisons valid for bitwise types too.

Warning: This change make sense in the context of [1] but

The [1] reference seems to be missing :)

ATB,
Ramsay Jones

Quoted 46 lines

doesn't make sense for the 'main' bitwise types:
__be32 and friends.

---
 evaluate.c                       | 4 ++++
 validation/bitwise-cmp.c         | 1 -
 validation/linear/bitwise-cmps.c | 1 -
 3 files changed, 4 insertions(+), 2 deletions(-)
evaluate.c +4 -0
index bcbcdf1ef0cc..bb8c0caa905a 100644
@@ -435,6 +435,10 @@ static int restricted_binop(int op, struct symbol *type)
 		case '^':
 		case '?':
 			return 2;	/* keep fouled */
+		case '<':
+		case '>':
+		case SPECIAL_LTE:
+		case SPECIAL_GTE:
 		case SPECIAL_EQUAL:
 		case SPECIAL_NOTEQUAL:
 			return 3;	/* warn if fouled */
validation/bitwise-cmp.c +0 -1
index ca12b5e51e8e..8c3e6894072d 100644
@@ -28,5 +28,4 @@ static int gtx(b32 x, b32 y)  { return (x >  y); }
 
 /*
  * check-name: bitwise-cmp
- * check-known-to-fail
  */
validation/linear/bitwise-cmps.c +0 -1
index 6122944a42c6..f83ab7fe47db 100644
@@ -8,7 +8,6 @@ static int gtu(bs32 x, bs32 y)  { return (x >  y); }
 /*
  * check-name: bitwise-cmps
  * check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
  *
  * check-output-ignore
  * check-output-excludes: setb\\.
#80 lore raw

Re: [PATCH 2/5] bitwise: accept all ones as non-restricted value

In reply to Luc Van Oostenryck
Quoted 2 lines · Luc Van Oostenryck

Currently, the only value bitwise types can act on is 0 because the this value is anyway invariant for all bitwise

s/the this/this/
s/anyway//

ATB,
Ramsay Jones

Quoted 50 lines

operations and endianness conversions.

But, a bit-pattern of all ones has the same properties and is also very often used.

So, accept all ones as a valid value for bitwise operations.

---
 evaluate.c                |  2 +-
 validation/bitwise-cast.c | 13 +++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)
evaluate.c +1 -1
index 61f59ee3908e..bcbcdf1ef0cc 100644
@@ -417,7 +417,7 @@ static int restricted_value(struct expression *v, struct symbol *type)
 {
 	if (v->type != EXPR_VALUE)
 		return 1;
-	if (v->value != 0)
+	if (v->value != 0 && v->value != bits_mask(type->bit_size))
 		return 1;
 	return 0;
 }
validation/bitwise-cast.c +13 -0
index 0583461cb745..1075a3e9410c 100644
@@ -35,6 +35,19 @@ static __be32 quuy(void)
 	return (__attribute__((force)) __be32) 1730;
 }
 
+/* Implicit casts of all ones, legal */
+static __be32 foo1(void)
+{
+	__be32 x = 0xffffffff;
+	return x;
+}
+
+/* Explicit cast of all ones, legal */
+static __be32 bar1(void)
+{
+	return (__be32)0xffffffff;
+}
+
 /*
  * check-name: conversions to bitwise types
  * check-command: sparse -Wbitwise $file
author reviewer
#92 lore raw
In reply to Christoph Hellwig
Quoted 7 lines · Christoph Hellwig

I generally like this. Two thoughs:

- I suspect most places that currently pass a enum req_op might really want a blk_opf_t for future extensibility, exceptions are very low-level helpers like req_op() and bio_op() where the enum is very nice to force switch statements to handle all ops or have a default statements

Agreed. I will use blk_opf_t where enum req_op is passed today but where request flags might be passed in addition to the request type in the future.

Quoted 5 lines

- a lot of the flags printinting is a mess, and introduce the code smell of __force casts. It migh make sense to introduce a new %psomething format specifier first to print a blk_opf_t using printk/vsprintf/etc and switch everyone to that first instead of hand crafted printing.

How about using blk_fill_rwbs() instead, a function that is already being used by the bcache tracing code?

No matter how tracing the request operation type and flags is unified, I'd like to defer this unification to a future patch series since this patch series is already too big.

Thanks,

Bart.

author reviewer
#91 lore raw
In reply to Christoph Hellwig
Quoted 4 lines · Christoph Hellwig

Oh, and a third: there is still various places passing the op separately from the flags and/or using bio_set_op_attrs. This would be a good time to clean the rest of those up (I already did a lot of that gradually).

I will look into combining 'op' and 'op_flags' arguments but I would like to postpone removing bio_set_op_attrs() since this patch series is already too big.

Thanks,

Bart.