block: replace fmode_t with a block-specific type for block open flags
The only overlap between the block open flags mapped into the fmode_t and
other uses of fmode_t are FMODE_READ and FMODE_WRITE. Define a new
blk_mode_t instead for use in blkdev_get_by_{dev,path}, ->open and
->ioctl and stop abusing fmode_t.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Acked-by: Jack Wang <jinpu.wang@ionos.com> [rnbd]
Reviewed-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Christian Brauner <brauner@kernel.org>
Link: https://lore.kernel.org/r/20230608110258.189493-28-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
parent
5e4ea83467
commit
05bdb99653
82 changed files with 334 additions and 315 deletions
|
|
@ -112,6 +112,19 @@ struct blk_integrity {
|
|||
unsigned char tag_size;
|
||||
};
|
||||
|
||||
typedef unsigned int __bitwise blk_mode_t;
|
||||
|
||||
/* open for reading */
|
||||
#define BLK_OPEN_READ ((__force blk_mode_t)(1 << 0))
|
||||
/* open for writing */
|
||||
#define BLK_OPEN_WRITE ((__force blk_mode_t)(1 << 1))
|
||||
/* open exclusively (vs other exclusive openers */
|
||||
#define BLK_OPEN_EXCL ((__force blk_mode_t)(1 << 2))
|
||||
/* opened with O_NDELAY */
|
||||
#define BLK_OPEN_NDELAY ((__force blk_mode_t)(1 << 3))
|
||||
/* open for "writes" only for ioctls (specialy hack for floppy.c) */
|
||||
#define BLK_OPEN_WRITE_IOCTL ((__force blk_mode_t)(1 << 4))
|
||||
|
||||
struct gendisk {
|
||||
/*
|
||||
* major/first_minor/minors should not be set by any new driver, the
|
||||
|
|
@ -187,6 +200,7 @@ struct gendisk {
|
|||
struct badblocks *bb;
|
||||
struct lockdep_map lockdep_map;
|
||||
u64 diskseq;
|
||||
blk_mode_t open_mode;
|
||||
|
||||
/*
|
||||
* Independent sector access ranges. This is always NULL for
|
||||
|
|
@ -1363,10 +1377,12 @@ struct block_device_operations {
|
|||
void (*submit_bio)(struct bio *bio);
|
||||
int (*poll_bio)(struct bio *bio, struct io_comp_batch *iob,
|
||||
unsigned int flags);
|
||||
int (*open)(struct gendisk *disk, fmode_t mode);
|
||||
int (*open)(struct gendisk *disk, blk_mode_t mode);
|
||||
void (*release)(struct gendisk *disk);
|
||||
int (*ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
|
||||
int (*compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
|
||||
int (*ioctl)(struct block_device *bdev, blk_mode_t mode,
|
||||
unsigned cmd, unsigned long arg);
|
||||
int (*compat_ioctl)(struct block_device *bdev, blk_mode_t mode,
|
||||
unsigned cmd, unsigned long arg);
|
||||
unsigned int (*check_events) (struct gendisk *disk,
|
||||
unsigned int clearing);
|
||||
void (*unlock_native_capacity) (struct gendisk *);
|
||||
|
|
@ -1393,7 +1409,7 @@ struct block_device_operations {
|
|||
};
|
||||
|
||||
#ifdef CONFIG_COMPAT
|
||||
extern int blkdev_compat_ptr_ioctl(struct block_device *, fmode_t,
|
||||
extern int blkdev_compat_ptr_ioctl(struct block_device *, blk_mode_t,
|
||||
unsigned int, unsigned long);
|
||||
#else
|
||||
#define blkdev_compat_ptr_ioctl NULL
|
||||
|
|
@ -1455,11 +1471,11 @@ struct blk_holder_ops {
|
|||
* as stored in sb->s_flags.
|
||||
*/
|
||||
#define sb_open_mode(flags) \
|
||||
(FMODE_READ | (((flags) & SB_RDONLY) ? 0 : FMODE_WRITE))
|
||||
(BLK_OPEN_READ | (((flags) & SB_RDONLY) ? 0 : BLK_OPEN_WRITE))
|
||||
|
||||
struct block_device *blkdev_get_by_dev(dev_t dev, fmode_t mode, void *holder,
|
||||
struct block_device *blkdev_get_by_dev(dev_t dev, blk_mode_t mode, void *holder,
|
||||
const struct blk_holder_ops *hops);
|
||||
struct block_device *blkdev_get_by_path(const char *path, fmode_t mode,
|
||||
struct block_device *blkdev_get_by_path(const char *path, blk_mode_t mode,
|
||||
void *holder, const struct blk_holder_ops *hops);
|
||||
int bd_prepare_to_claim(struct block_device *bdev, void *holder,
|
||||
const struct blk_holder_ops *hops);
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
#include <linux/fs.h> /* not really needed, later.. */
|
||||
#include <linux/list.h>
|
||||
#include <linux/blkdev.h>
|
||||
#include <scsi/scsi_common.h>
|
||||
#include <uapi/linux/cdrom.h>
|
||||
|
||||
|
|
@ -101,7 +102,7 @@ int cdrom_read_tocentry(struct cdrom_device_info *cdi,
|
|||
struct cdrom_tocentry *entry);
|
||||
|
||||
/* the general block_device operations structure: */
|
||||
int cdrom_open(struct cdrom_device_info *cdi, fmode_t mode);
|
||||
int cdrom_open(struct cdrom_device_info *cdi, blk_mode_t mode);
|
||||
void cdrom_release(struct cdrom_device_info *cdi);
|
||||
int cdrom_ioctl(struct cdrom_device_info *cdi, struct block_device *bdev,
|
||||
unsigned int cmd, unsigned long arg);
|
||||
|
|
|
|||
|
|
@ -166,7 +166,7 @@ void dm_error(const char *message);
|
|||
struct dm_dev {
|
||||
struct block_device *bdev;
|
||||
struct dax_device *dax_dev;
|
||||
fmode_t mode;
|
||||
blk_mode_t mode;
|
||||
char name[16];
|
||||
};
|
||||
|
||||
|
|
@ -174,7 +174,7 @@ struct dm_dev {
|
|||
* Constructors should call these functions to ensure destination devices
|
||||
* are opened/closed correctly.
|
||||
*/
|
||||
int dm_get_device(struct dm_target *ti, const char *path, fmode_t mode,
|
||||
int dm_get_device(struct dm_target *ti, const char *path, blk_mode_t mode,
|
||||
struct dm_dev **result);
|
||||
void dm_put_device(struct dm_target *ti, struct dm_dev *d);
|
||||
|
||||
|
|
@ -543,7 +543,7 @@ int dm_set_geometry(struct mapped_device *md, struct hd_geometry *geo);
|
|||
/*
|
||||
* First create an empty table.
|
||||
*/
|
||||
int dm_table_create(struct dm_table **result, fmode_t mode,
|
||||
int dm_table_create(struct dm_table **result, blk_mode_t mode,
|
||||
unsigned int num_targets, struct mapped_device *md);
|
||||
|
||||
/*
|
||||
|
|
@ -586,7 +586,7 @@ void dm_sync_table(struct mapped_device *md);
|
|||
* Queries
|
||||
*/
|
||||
sector_t dm_table_get_size(struct dm_table *t);
|
||||
fmode_t dm_table_get_mode(struct dm_table *t);
|
||||
blk_mode_t dm_table_get_mode(struct dm_table *t);
|
||||
struct mapped_device *dm_table_get_md(struct dm_table *t);
|
||||
const char *dm_table_device_name(struct dm_table *t);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue