Commit 436d3705 authored by Jan Kara's avatar Jan Kara Committed by Christian Brauner

xen/blkback: Convert to bdev_open_by_dev()

Convert xen/blkback to use bdev_open_by_dev() and pass the
handle around.

CC: xen-devel@lists.xenproject.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-7-jack@suse.czSigned-off-by: default avatarChristian Brauner <brauner@kernel.org>
parent c2114f11
...@@ -465,7 +465,7 @@ static int xen_vbd_translate(struct phys_req *req, struct xen_blkif *blkif, ...@@ -465,7 +465,7 @@ static int xen_vbd_translate(struct phys_req *req, struct xen_blkif *blkif,
} }
req->dev = vbd->pdevice; req->dev = vbd->pdevice;
req->bdev = vbd->bdev; req->bdev = vbd->bdev_handle->bdev;
rc = 0; rc = 0;
out: out:
...@@ -969,7 +969,7 @@ static int dispatch_discard_io(struct xen_blkif_ring *ring, ...@@ -969,7 +969,7 @@ static int dispatch_discard_io(struct xen_blkif_ring *ring,
int err = 0; int err = 0;
int status = BLKIF_RSP_OKAY; int status = BLKIF_RSP_OKAY;
struct xen_blkif *blkif = ring->blkif; struct xen_blkif *blkif = ring->blkif;
struct block_device *bdev = blkif->vbd.bdev; struct block_device *bdev = blkif->vbd.bdev_handle->bdev;
struct phys_req preq; struct phys_req preq;
xen_blkif_get(blkif); xen_blkif_get(blkif);
......
...@@ -221,7 +221,7 @@ struct xen_vbd { ...@@ -221,7 +221,7 @@ struct xen_vbd {
unsigned char type; unsigned char type;
/* phys device that this vbd maps to. */ /* phys device that this vbd maps to. */
u32 pdevice; u32 pdevice;
struct block_device *bdev; struct bdev_handle *bdev_handle;
/* Cached size parameter. */ /* Cached size parameter. */
sector_t size; sector_t size;
unsigned int flush_support:1; unsigned int flush_support:1;
...@@ -360,7 +360,7 @@ struct pending_req { ...@@ -360,7 +360,7 @@ struct pending_req {
}; };
#define vbd_sz(_v) bdev_nr_sectors((_v)->bdev) #define vbd_sz(_v) bdev_nr_sectors((_v)->bdev_handle->bdev)
#define xen_blkif_get(_b) (atomic_inc(&(_b)->refcnt)) #define xen_blkif_get(_b) (atomic_inc(&(_b)->refcnt))
#define xen_blkif_put(_b) \ #define xen_blkif_put(_b) \
......
...@@ -81,7 +81,7 @@ static void xen_update_blkif_status(struct xen_blkif *blkif) ...@@ -81,7 +81,7 @@ static void xen_update_blkif_status(struct xen_blkif *blkif)
int i; int i;
/* Not ready to connect? */ /* Not ready to connect? */
if (!blkif->rings || !blkif->rings[0].irq || !blkif->vbd.bdev) if (!blkif->rings || !blkif->rings[0].irq || !blkif->vbd.bdev_handle)
return; return;
/* Already connected? */ /* Already connected? */
...@@ -99,12 +99,13 @@ static void xen_update_blkif_status(struct xen_blkif *blkif) ...@@ -99,12 +99,13 @@ static void xen_update_blkif_status(struct xen_blkif *blkif)
return; return;
} }
err = sync_blockdev(blkif->vbd.bdev); err = sync_blockdev(blkif->vbd.bdev_handle->bdev);
if (err) { if (err) {
xenbus_dev_error(blkif->be->dev, err, "block flush"); xenbus_dev_error(blkif->be->dev, err, "block flush");
return; return;
} }
invalidate_inode_pages2(blkif->vbd.bdev->bd_inode->i_mapping); invalidate_inode_pages2(
blkif->vbd.bdev_handle->bdev->bd_inode->i_mapping);
for (i = 0; i < blkif->nr_rings; i++) { for (i = 0; i < blkif->nr_rings; i++) {
ring = &blkif->rings[i]; ring = &blkif->rings[i];
...@@ -472,9 +473,9 @@ static void xenvbd_sysfs_delif(struct xenbus_device *dev) ...@@ -472,9 +473,9 @@ static void xenvbd_sysfs_delif(struct xenbus_device *dev)
static void xen_vbd_free(struct xen_vbd *vbd) static void xen_vbd_free(struct xen_vbd *vbd)
{ {
if (vbd->bdev) if (vbd->bdev_handle)
blkdev_put(vbd->bdev, NULL); bdev_release(vbd->bdev_handle);
vbd->bdev = NULL; vbd->bdev_handle = NULL;
} }
static int xen_vbd_create(struct xen_blkif *blkif, blkif_vdev_t handle, static int xen_vbd_create(struct xen_blkif *blkif, blkif_vdev_t handle,
...@@ -482,7 +483,7 @@ static int xen_vbd_create(struct xen_blkif *blkif, blkif_vdev_t handle, ...@@ -482,7 +483,7 @@ static int xen_vbd_create(struct xen_blkif *blkif, blkif_vdev_t handle,
int cdrom) int cdrom)
{ {
struct xen_vbd *vbd; struct xen_vbd *vbd;
struct block_device *bdev; struct bdev_handle *bdev_handle;
vbd = &blkif->vbd; vbd = &blkif->vbd;
vbd->handle = handle; vbd->handle = handle;
...@@ -491,17 +492,17 @@ static int xen_vbd_create(struct xen_blkif *blkif, blkif_vdev_t handle, ...@@ -491,17 +492,17 @@ static int xen_vbd_create(struct xen_blkif *blkif, blkif_vdev_t handle,
vbd->pdevice = MKDEV(major, minor); vbd->pdevice = MKDEV(major, minor);
bdev = blkdev_get_by_dev(vbd->pdevice, vbd->readonly ? bdev_handle = bdev_open_by_dev(vbd->pdevice, vbd->readonly ?
BLK_OPEN_READ : BLK_OPEN_WRITE, NULL, NULL); BLK_OPEN_READ : BLK_OPEN_WRITE, NULL, NULL);
if (IS_ERR(bdev)) { if (IS_ERR(bdev_handle)) {
pr_warn("xen_vbd_create: device %08x could not be opened\n", pr_warn("xen_vbd_create: device %08x could not be opened\n",
vbd->pdevice); vbd->pdevice);
return -ENOENT; return -ENOENT;
} }
vbd->bdev = bdev; vbd->bdev_handle = bdev_handle;
if (vbd->bdev->bd_disk == NULL) { if (vbd->bdev_handle->bdev->bd_disk == NULL) {
pr_warn("xen_vbd_create: device %08x doesn't exist\n", pr_warn("xen_vbd_create: device %08x doesn't exist\n",
vbd->pdevice); vbd->pdevice);
xen_vbd_free(vbd); xen_vbd_free(vbd);
...@@ -509,14 +510,14 @@ static int xen_vbd_create(struct xen_blkif *blkif, blkif_vdev_t handle, ...@@ -509,14 +510,14 @@ static int xen_vbd_create(struct xen_blkif *blkif, blkif_vdev_t handle,
} }
vbd->size = vbd_sz(vbd); vbd->size = vbd_sz(vbd);
if (cdrom || disk_to_cdi(vbd->bdev->bd_disk)) if (cdrom || disk_to_cdi(vbd->bdev_handle->bdev->bd_disk))
vbd->type |= VDISK_CDROM; vbd->type |= VDISK_CDROM;
if (vbd->bdev->bd_disk->flags & GENHD_FL_REMOVABLE) if (vbd->bdev_handle->bdev->bd_disk->flags & GENHD_FL_REMOVABLE)
vbd->type |= VDISK_REMOVABLE; vbd->type |= VDISK_REMOVABLE;
if (bdev_write_cache(bdev)) if (bdev_write_cache(bdev_handle->bdev))
vbd->flush_support = true; vbd->flush_support = true;
if (bdev_max_secure_erase_sectors(bdev)) if (bdev_max_secure_erase_sectors(bdev_handle->bdev))
vbd->discard_secure = true; vbd->discard_secure = true;
pr_debug("Successful creation of handle=%04x (dom=%u)\n", pr_debug("Successful creation of handle=%04x (dom=%u)\n",
...@@ -569,7 +570,7 @@ static void xen_blkbk_discard(struct xenbus_transaction xbt, struct backend_info ...@@ -569,7 +570,7 @@ static void xen_blkbk_discard(struct xenbus_transaction xbt, struct backend_info
struct xen_blkif *blkif = be->blkif; struct xen_blkif *blkif = be->blkif;
int err; int err;
int state = 0; int state = 0;
struct block_device *bdev = be->blkif->vbd.bdev; struct block_device *bdev = be->blkif->vbd.bdev_handle->bdev;
if (!xenbus_read_unsigned(dev->nodename, "discard-enable", 1)) if (!xenbus_read_unsigned(dev->nodename, "discard-enable", 1))
return; return;
...@@ -930,15 +931,16 @@ static void connect(struct backend_info *be) ...@@ -930,15 +931,16 @@ static void connect(struct backend_info *be)
goto abort; goto abort;
} }
err = xenbus_printf(xbt, dev->nodename, "sector-size", "%lu", err = xenbus_printf(xbt, dev->nodename, "sector-size", "%lu",
(unsigned long) (unsigned long)bdev_logical_block_size(
bdev_logical_block_size(be->blkif->vbd.bdev)); be->blkif->vbd.bdev_handle->bdev));
if (err) { if (err) {
xenbus_dev_fatal(dev, err, "writing %s/sector-size", xenbus_dev_fatal(dev, err, "writing %s/sector-size",
dev->nodename); dev->nodename);
goto abort; goto abort;
} }
err = xenbus_printf(xbt, dev->nodename, "physical-sector-size", "%u", err = xenbus_printf(xbt, dev->nodename, "physical-sector-size", "%u",
bdev_physical_block_size(be->blkif->vbd.bdev)); bdev_physical_block_size(
be->blkif->vbd.bdev_handle->bdev));
if (err) if (err)
xenbus_dev_error(dev, err, "writing %s/physical-sector-size", xenbus_dev_error(dev, err, "writing %s/physical-sector-size",
dev->nodename); dev->nodename);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment