target: port block device access to file

Link: https://lore.kernel.org/r/20240123-vfs-bdev-file-v2-17-adbd023e19cc@kernel.org
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
Christian Brauner 2024-01-23 14:26:34 +01:00
parent c8e108d80c
commit 034f0cf8fd
No known key found for this signature in database
GPG Key ID: 91C61BC06578DCA2
4 changed files with 22 additions and 22 deletions

View File

@ -91,7 +91,7 @@ static int iblock_configure_device(struct se_device *dev)
{ {
struct iblock_dev *ib_dev = IBLOCK_DEV(dev); struct iblock_dev *ib_dev = IBLOCK_DEV(dev);
struct request_queue *q; struct request_queue *q;
struct bdev_handle *bdev_handle; struct file *bdev_file;
struct block_device *bd; struct block_device *bd;
struct blk_integrity *bi; struct blk_integrity *bi;
blk_mode_t mode = BLK_OPEN_READ; blk_mode_t mode = BLK_OPEN_READ;
@ -117,14 +117,14 @@ static int iblock_configure_device(struct se_device *dev)
else else
dev->dev_flags |= DF_READ_ONLY; dev->dev_flags |= DF_READ_ONLY;
bdev_handle = bdev_open_by_path(ib_dev->ibd_udev_path, mode, ib_dev, bdev_file = bdev_file_open_by_path(ib_dev->ibd_udev_path, mode, ib_dev,
NULL); NULL);
if (IS_ERR(bdev_handle)) { if (IS_ERR(bdev_file)) {
ret = PTR_ERR(bdev_handle); ret = PTR_ERR(bdev_file);
goto out_free_bioset; goto out_free_bioset;
} }
ib_dev->ibd_bdev_handle = bdev_handle; ib_dev->ibd_bdev_file = bdev_file;
ib_dev->ibd_bd = bd = bdev_handle->bdev; ib_dev->ibd_bd = bd = file_bdev(bdev_file);
q = bdev_get_queue(bd); q = bdev_get_queue(bd);
@ -180,7 +180,7 @@ static int iblock_configure_device(struct se_device *dev)
return 0; return 0;
out_blkdev_put: out_blkdev_put:
bdev_release(ib_dev->ibd_bdev_handle); fput(ib_dev->ibd_bdev_file);
out_free_bioset: out_free_bioset:
bioset_exit(&ib_dev->ibd_bio_set); bioset_exit(&ib_dev->ibd_bio_set);
out: out:
@ -205,8 +205,8 @@ static void iblock_destroy_device(struct se_device *dev)
{ {
struct iblock_dev *ib_dev = IBLOCK_DEV(dev); struct iblock_dev *ib_dev = IBLOCK_DEV(dev);
if (ib_dev->ibd_bdev_handle) if (ib_dev->ibd_bdev_file)
bdev_release(ib_dev->ibd_bdev_handle); fput(ib_dev->ibd_bdev_file);
bioset_exit(&ib_dev->ibd_bio_set); bioset_exit(&ib_dev->ibd_bio_set);
} }

View File

@ -32,7 +32,7 @@ struct iblock_dev {
u32 ibd_flags; u32 ibd_flags;
struct bio_set ibd_bio_set; struct bio_set ibd_bio_set;
struct block_device *ibd_bd; struct block_device *ibd_bd;
struct bdev_handle *ibd_bdev_handle; struct file *ibd_bdev_file;
bool ibd_readonly; bool ibd_readonly;
struct iblock_dev_plug *ibd_plug; struct iblock_dev_plug *ibd_plug;
} ____cacheline_aligned; } ____cacheline_aligned;

View File

@ -352,7 +352,7 @@ static int pscsi_create_type_disk(struct se_device *dev, struct scsi_device *sd)
struct pscsi_hba_virt *phv = dev->se_hba->hba_ptr; struct pscsi_hba_virt *phv = dev->se_hba->hba_ptr;
struct pscsi_dev_virt *pdv = PSCSI_DEV(dev); struct pscsi_dev_virt *pdv = PSCSI_DEV(dev);
struct Scsi_Host *sh = sd->host; struct Scsi_Host *sh = sd->host;
struct bdev_handle *bdev_handle; struct file *bdev_file;
int ret; int ret;
if (scsi_device_get(sd)) { if (scsi_device_get(sd)) {
@ -366,18 +366,18 @@ static int pscsi_create_type_disk(struct se_device *dev, struct scsi_device *sd)
* Claim exclusive struct block_device access to struct scsi_device * Claim exclusive struct block_device access to struct scsi_device
* for TYPE_DISK and TYPE_ZBC using supplied udev_path * for TYPE_DISK and TYPE_ZBC using supplied udev_path
*/ */
bdev_handle = bdev_open_by_path(dev->udev_path, bdev_file = bdev_file_open_by_path(dev->udev_path,
BLK_OPEN_WRITE | BLK_OPEN_READ, pdv, NULL); BLK_OPEN_WRITE | BLK_OPEN_READ, pdv, NULL);
if (IS_ERR(bdev_handle)) { if (IS_ERR(bdev_file)) {
pr_err("pSCSI: bdev_open_by_path() failed\n"); pr_err("pSCSI: bdev_open_by_path() failed\n");
scsi_device_put(sd); scsi_device_put(sd);
return PTR_ERR(bdev_handle); return PTR_ERR(bdev_file);
} }
pdv->pdv_bdev_handle = bdev_handle; pdv->pdv_bdev_file = bdev_file;
ret = pscsi_add_device_to_list(dev, sd); ret = pscsi_add_device_to_list(dev, sd);
if (ret) { if (ret) {
bdev_release(bdev_handle); fput(bdev_file);
scsi_device_put(sd); scsi_device_put(sd);
return ret; return ret;
} }
@ -564,9 +564,9 @@ static void pscsi_destroy_device(struct se_device *dev)
* from pscsi_create_type_disk() * from pscsi_create_type_disk()
*/ */
if ((sd->type == TYPE_DISK || sd->type == TYPE_ZBC) && if ((sd->type == TYPE_DISK || sd->type == TYPE_ZBC) &&
pdv->pdv_bdev_handle) { pdv->pdv_bdev_file) {
bdev_release(pdv->pdv_bdev_handle); fput(pdv->pdv_bdev_file);
pdv->pdv_bdev_handle = NULL; pdv->pdv_bdev_file = NULL;
} }
/* /*
* For HBA mode PHV_LLD_SCSI_HOST_NO, release the reference * For HBA mode PHV_LLD_SCSI_HOST_NO, release the reference
@ -994,8 +994,8 @@ static sector_t pscsi_get_blocks(struct se_device *dev)
{ {
struct pscsi_dev_virt *pdv = PSCSI_DEV(dev); struct pscsi_dev_virt *pdv = PSCSI_DEV(dev);
if (pdv->pdv_bdev_handle) if (pdv->pdv_bdev_file)
return bdev_nr_sectors(pdv->pdv_bdev_handle->bdev); return bdev_nr_sectors(file_bdev(pdv->pdv_bdev_file));
return 0; return 0;
} }

View File

@ -37,7 +37,7 @@ struct pscsi_dev_virt {
int pdv_channel_id; int pdv_channel_id;
int pdv_target_id; int pdv_target_id;
int pdv_lun_id; int pdv_lun_id;
struct bdev_handle *pdv_bdev_handle; struct file *pdv_bdev_file;
struct scsi_device *pdv_sd; struct scsi_device *pdv_sd;
struct Scsi_Host *pdv_lld_host; struct Scsi_Host *pdv_lld_host;
} ____cacheline_aligned; } ____cacheline_aligned;