Unverified Commit e6aafdc8 authored by Jan Kara's avatar Jan Kara Committed by Christian Brauner
Browse files

scsi: target: Convert to bdev_open_by_path()



Convert iblock and pscsi drivers to use bdev_open_by_path() and pass the
handle around.

CC: target-devel@vger.kernel.org
CC: linux-scsi@vger.kernel.org
Acked-by: default avatarChristoph Hellwig <hch@lst.de>
Acked-by: default avatarChristian Brauner <brauner@kernel.org>
Signed-off-by: default avatarJan Kara <jack@suse.cz>
Link: https://lore.kernel.org/r/20230927093442.25915-15-jack@suse.cz


Reviewed-by: default avatar"Martin K. Petersen" <martin.petersen@oracle.com>
Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
parent a8ab90ff
Loading
Loading
Loading
Loading
+11 −8
Original line number Diff line number Diff line
@@ -91,7 +91,8 @@ static int iblock_configure_device(struct se_device *dev)
{
	struct iblock_dev *ib_dev = IBLOCK_DEV(dev);
	struct request_queue *q;
	struct block_device *bd = NULL;
	struct bdev_handle *bdev_handle;
	struct block_device *bd;
	struct blk_integrity *bi;
	blk_mode_t mode = BLK_OPEN_READ;
	unsigned int max_write_zeroes_sectors;
@@ -116,12 +117,14 @@ static int iblock_configure_device(struct se_device *dev)
	else
		dev->dev_flags |= DF_READ_ONLY;

	bd = blkdev_get_by_path(ib_dev->ibd_udev_path, mode, ib_dev, NULL);
	if (IS_ERR(bd)) {
		ret = PTR_ERR(bd);
	bdev_handle = bdev_open_by_path(ib_dev->ibd_udev_path, mode, ib_dev,
					NULL);
	if (IS_ERR(bdev_handle)) {
		ret = PTR_ERR(bdev_handle);
		goto out_free_bioset;
	}
	ib_dev->ibd_bd = bd;
	ib_dev->ibd_bdev_handle = bdev_handle;
	ib_dev->ibd_bd = bd = bdev_handle->bdev;

	q = bdev_get_queue(bd);

@@ -177,7 +180,7 @@ static int iblock_configure_device(struct se_device *dev)
	return 0;

out_blkdev_put:
	blkdev_put(ib_dev->ibd_bd, ib_dev);
	bdev_release(ib_dev->ibd_bdev_handle);
out_free_bioset:
	bioset_exit(&ib_dev->ibd_bio_set);
out:
@@ -202,8 +205,8 @@ static void iblock_destroy_device(struct se_device *dev)
{
	struct iblock_dev *ib_dev = IBLOCK_DEV(dev);

	if (ib_dev->ibd_bd != NULL)
		blkdev_put(ib_dev->ibd_bd, ib_dev);
	if (ib_dev->ibd_bdev_handle)
		bdev_release(ib_dev->ibd_bdev_handle);
	bioset_exit(&ib_dev->ibd_bio_set);
}

+1 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ struct iblock_dev {
	u32	ibd_flags;
	struct bio_set	ibd_bio_set;
	struct block_device *ibd_bd;
	struct bdev_handle *ibd_bdev_handle;
	bool ibd_readonly;
	struct iblock_dev_plug *ibd_plug;
} ____cacheline_aligned;
+13 −13
Original line number Diff line number Diff line
@@ -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_dev_virt *pdv = PSCSI_DEV(dev);
	struct Scsi_Host *sh = sd->host;
	struct block_device *bd;
	struct bdev_handle *bdev_handle;
	int ret;

	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
	 * for TYPE_DISK and TYPE_ZBC using supplied udev_path
	 */
	bd = blkdev_get_by_path(dev->udev_path, BLK_OPEN_WRITE | BLK_OPEN_READ,
				pdv, NULL);
	if (IS_ERR(bd)) {
		pr_err("pSCSI: blkdev_get_by_path() failed\n");
	bdev_handle = bdev_open_by_path(dev->udev_path,
				BLK_OPEN_WRITE | BLK_OPEN_READ, pdv, NULL);
	if (IS_ERR(bdev_handle)) {
		pr_err("pSCSI: bdev_open_by_path() failed\n");
		scsi_device_put(sd);
		return PTR_ERR(bd);
		return PTR_ERR(bdev_handle);
	}
	pdv->pdv_bd = bd;
	pdv->pdv_bdev_handle = bdev_handle;

	ret = pscsi_add_device_to_list(dev, sd);
	if (ret) {
		blkdev_put(pdv->pdv_bd, pdv);
		bdev_release(bdev_handle);
		scsi_device_put(sd);
		return ret;
	}
@@ -564,9 +564,9 @@ static void pscsi_destroy_device(struct se_device *dev)
		 * from pscsi_create_type_disk()
		 */
		if ((sd->type == TYPE_DISK || sd->type == TYPE_ZBC) &&
		    pdv->pdv_bd) {
			blkdev_put(pdv->pdv_bd, pdv);
			pdv->pdv_bd = NULL;
		    pdv->pdv_bdev_handle) {
			bdev_release(pdv->pdv_bdev_handle);
			pdv->pdv_bdev_handle = NULL;
		}
		/*
		 * 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);

	if (pdv->pdv_bd)
		return bdev_nr_sectors(pdv->pdv_bd);
	if (pdv->pdv_bdev_handle)
		return bdev_nr_sectors(pdv->pdv_bdev_handle->bdev);
	return 0;
}

+1 −1
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ struct pscsi_dev_virt {
	int	pdv_channel_id;
	int	pdv_target_id;
	int	pdv_lun_id;
	struct block_device *pdv_bd;
	struct bdev_handle *pdv_bdev_handle;
	struct scsi_device *pdv_sd;
	struct Scsi_Host *pdv_lld_host;
} ____cacheline_aligned;