mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-01-16 09:56:46 +00:00
block: Provide bdev_open_* functions
Create struct bdev_handle that contains all parameters that need to be passed to blkdev_put() and provide bdev_open_* functions that return this structure instead of plain bdev pointer. This will eventually allow us to pass one more argument to blkdev_put() (renamed to bdev_release()) without too much hassle. Acked-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Christian Brauner <brauner@kernel.org> Signed-off-by: Jan Kara <jack@suse.cz> Link: https://lore.kernel.org/r/20230927093442.25915-1-jack@suse.cz Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
parent
05d3ef8bba
commit
e719b4d156
48
block/bdev.c
48
block/bdev.c
@ -829,6 +829,25 @@ put_blkdev:
|
||||
}
|
||||
EXPORT_SYMBOL(blkdev_get_by_dev);
|
||||
|
||||
struct bdev_handle *bdev_open_by_dev(dev_t dev, blk_mode_t mode, void *holder,
|
||||
const struct blk_holder_ops *hops)
|
||||
{
|
||||
struct bdev_handle *handle = kmalloc(sizeof(*handle), GFP_KERNEL);
|
||||
struct block_device *bdev;
|
||||
|
||||
if (!handle)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
bdev = blkdev_get_by_dev(dev, mode, holder, hops);
|
||||
if (IS_ERR(bdev)) {
|
||||
kfree(handle);
|
||||
return ERR_CAST(bdev);
|
||||
}
|
||||
handle->bdev = bdev;
|
||||
handle->holder = holder;
|
||||
return handle;
|
||||
}
|
||||
EXPORT_SYMBOL(bdev_open_by_dev);
|
||||
|
||||
/**
|
||||
* blkdev_get_by_path - open a block device by name
|
||||
* @path: path to the block device to open
|
||||
@ -867,6 +886,28 @@ struct block_device *blkdev_get_by_path(const char *path, blk_mode_t mode,
|
||||
}
|
||||
EXPORT_SYMBOL(blkdev_get_by_path);
|
||||
|
||||
struct bdev_handle *bdev_open_by_path(const char *path, blk_mode_t mode,
|
||||
void *holder, const struct blk_holder_ops *hops)
|
||||
{
|
||||
struct bdev_handle *handle;
|
||||
dev_t dev;
|
||||
int error;
|
||||
|
||||
error = lookup_bdev(path, &dev);
|
||||
if (error)
|
||||
return ERR_PTR(error);
|
||||
|
||||
handle = bdev_open_by_dev(dev, mode, holder, hops);
|
||||
if (!IS_ERR(handle) && (mode & BLK_OPEN_WRITE) &&
|
||||
bdev_read_only(handle->bdev)) {
|
||||
bdev_release(handle);
|
||||
return ERR_PTR(-EACCES);
|
||||
}
|
||||
|
||||
return handle;
|
||||
}
|
||||
EXPORT_SYMBOL(bdev_open_by_path);
|
||||
|
||||
void blkdev_put(struct block_device *bdev, void *holder)
|
||||
{
|
||||
struct gendisk *disk = bdev->bd_disk;
|
||||
@ -903,6 +944,13 @@ void blkdev_put(struct block_device *bdev, void *holder)
|
||||
}
|
||||
EXPORT_SYMBOL(blkdev_put);
|
||||
|
||||
void bdev_release(struct bdev_handle *handle)
|
||||
{
|
||||
blkdev_put(handle->bdev, handle->holder);
|
||||
kfree(handle);
|
||||
}
|
||||
EXPORT_SYMBOL(bdev_release);
|
||||
|
||||
/**
|
||||
* lookup_bdev() - Look up a struct block_device by name.
|
||||
* @pathname: Name of the block device in the filesystem.
|
||||
|
@ -1479,14 +1479,24 @@ extern const struct blk_holder_ops fs_holder_ops;
|
||||
#define sb_open_mode(flags) \
|
||||
(BLK_OPEN_READ | (((flags) & SB_RDONLY) ? 0 : BLK_OPEN_WRITE))
|
||||
|
||||
struct bdev_handle {
|
||||
struct block_device *bdev;
|
||||
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, blk_mode_t mode,
|
||||
void *holder, const struct blk_holder_ops *hops);
|
||||
struct bdev_handle *bdev_open_by_dev(dev_t dev, blk_mode_t mode, void *holder,
|
||||
const struct blk_holder_ops *hops);
|
||||
struct bdev_handle *bdev_open_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);
|
||||
void bd_abort_claiming(struct block_device *bdev, void *holder);
|
||||
void blkdev_put(struct block_device *bdev, void *holder);
|
||||
void bdev_release(struct bdev_handle *handle);
|
||||
|
||||
/* just for blk-cgroup, don't use elsewhere */
|
||||
struct block_device *blkdev_get_no_open(dev_t dev);
|
||||
|
Loading…
x
Reference in New Issue
Block a user