Skip to content

Commit

Permalink
nfs/blocklayout: Convert to use bdev_open_by_dev/path()
Browse files Browse the repository at this point in the history
Convert block device handling to use bdev_open_by_dev/path() and pass
the handle around.

CC: [email protected]
CC: Trond Myklebust <[email protected]>
CC: Anna Schumaker <[email protected]>
Acked-by: Christoph Hellwig <[email protected]>
Reviewed-by: Christian Brauner <[email protected]>
Signed-off-by: Jan Kara <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Christian Brauner <[email protected]>
  • Loading branch information
jankara authored and brauner committed Oct 28, 2023
1 parent 898c57f commit 3fe5d9f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 40 deletions.
2 changes: 1 addition & 1 deletion fs/nfs/blocklayout/blocklayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ struct pnfs_block_dev {
struct pnfs_block_dev *children;
u64 chunk_size;

struct block_device *bdev;
struct bdev_handle *bdev_handle;
u64 disk_offset;

u64 pr_key;
Expand Down
76 changes: 37 additions & 39 deletions fs/nfs/blocklayout/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ bl_free_device(struct pnfs_block_dev *dev)
} else {
if (dev->pr_registered) {
const struct pr_ops *ops =
dev->bdev->bd_disk->fops->pr_ops;
dev->bdev_handle->bdev->bd_disk->fops->pr_ops;
int error;

error = ops->pr_register(dev->bdev, dev->pr_key, 0,
false);
error = ops->pr_register(dev->bdev_handle->bdev,
dev->pr_key, 0, false);
if (error)
pr_err("failed to unregister PR key.\n");
}

if (dev->bdev)
blkdev_put(dev->bdev, NULL);
if (dev->bdev_handle)
bdev_release(dev->bdev_handle);
}
}

Expand Down Expand Up @@ -169,7 +169,7 @@ static bool bl_map_simple(struct pnfs_block_dev *dev, u64 offset,
map->start = dev->start;
map->len = dev->len;
map->disk_offset = dev->disk_offset;
map->bdev = dev->bdev;
map->bdev = dev->bdev_handle->bdev;
return true;
}

Expand Down Expand Up @@ -236,28 +236,26 @@ bl_parse_simple(struct nfs_server *server, struct pnfs_block_dev *d,
struct pnfs_block_volume *volumes, int idx, gfp_t gfp_mask)
{
struct pnfs_block_volume *v = &volumes[idx];
struct block_device *bdev;
struct bdev_handle *bdev_handle;
dev_t dev;

dev = bl_resolve_deviceid(server, v, gfp_mask);
if (!dev)
return -EIO;

bdev = blkdev_get_by_dev(dev, BLK_OPEN_READ | BLK_OPEN_WRITE, NULL,
NULL);
if (IS_ERR(bdev)) {
bdev_handle = bdev_open_by_dev(dev, BLK_OPEN_READ | BLK_OPEN_WRITE,
NULL, NULL);
if (IS_ERR(bdev_handle)) {
printk(KERN_WARNING "pNFS: failed to open device %d:%d (%ld)\n",
MAJOR(dev), MINOR(dev), PTR_ERR(bdev));
return PTR_ERR(bdev);
MAJOR(dev), MINOR(dev), PTR_ERR(bdev_handle));
return PTR_ERR(bdev_handle);
}
d->bdev = bdev;


d->len = bdev_nr_bytes(d->bdev);
d->bdev_handle = bdev_handle;
d->len = bdev_nr_bytes(bdev_handle->bdev);
d->map = bl_map_simple;

printk(KERN_INFO "pNFS: using block device %s\n",
d->bdev->bd_disk->disk_name);
bdev_handle->bdev->bd_disk->disk_name);
return 0;
}

Expand Down Expand Up @@ -302,34 +300,34 @@ bl_validate_designator(struct pnfs_block_volume *v)
}
}

static struct block_device *
static struct bdev_handle *
bl_open_path(struct pnfs_block_volume *v, const char *prefix)
{
struct block_device *bdev;
struct bdev_handle *bdev_handle;
const char *devname;

devname = kasprintf(GFP_KERNEL, "/dev/disk/by-id/%s%*phN",
prefix, v->scsi.designator_len, v->scsi.designator);
if (!devname)
return ERR_PTR(-ENOMEM);

bdev = blkdev_get_by_path(devname, BLK_OPEN_READ | BLK_OPEN_WRITE, NULL,
NULL);
if (IS_ERR(bdev)) {
bdev_handle = bdev_open_by_path(devname, BLK_OPEN_READ | BLK_OPEN_WRITE,
NULL, NULL);
if (IS_ERR(bdev_handle)) {
pr_warn("pNFS: failed to open device %s (%ld)\n",
devname, PTR_ERR(bdev));
devname, PTR_ERR(bdev_handle));
}

kfree(devname);
return bdev;
return bdev_handle;
}

static int
bl_parse_scsi(struct nfs_server *server, struct pnfs_block_dev *d,
struct pnfs_block_volume *volumes, int idx, gfp_t gfp_mask)
{
struct pnfs_block_volume *v = &volumes[idx];
struct block_device *bdev;
struct bdev_handle *bdev_handle;
const struct pr_ops *ops;
int error;

Expand All @@ -342,40 +340,40 @@ bl_parse_scsi(struct nfs_server *server, struct pnfs_block_dev *d,
* On other distributions like Debian, the default SCSI by-id path will
* point to the dm-multipath device if one exists.
*/
bdev = bl_open_path(v, "dm-uuid-mpath-0x");
if (IS_ERR(bdev))
bdev = bl_open_path(v, "wwn-0x");
if (IS_ERR(bdev))
return PTR_ERR(bdev);
d->bdev = bdev;

d->len = bdev_nr_bytes(d->bdev);
bdev_handle = bl_open_path(v, "dm-uuid-mpath-0x");
if (IS_ERR(bdev_handle))
bdev_handle = bl_open_path(v, "wwn-0x");
if (IS_ERR(bdev_handle))
return PTR_ERR(bdev_handle);
d->bdev_handle = bdev_handle;

d->len = bdev_nr_bytes(d->bdev_handle->bdev);
d->map = bl_map_simple;
d->pr_key = v->scsi.pr_key;

pr_info("pNFS: using block device %s (reservation key 0x%llx)\n",
d->bdev->bd_disk->disk_name, d->pr_key);
d->bdev_handle->bdev->bd_disk->disk_name, d->pr_key);

ops = d->bdev->bd_disk->fops->pr_ops;
ops = d->bdev_handle->bdev->bd_disk->fops->pr_ops;
if (!ops) {
pr_err("pNFS: block device %s does not support reservations.",
d->bdev->bd_disk->disk_name);
d->bdev_handle->bdev->bd_disk->disk_name);
error = -EINVAL;
goto out_blkdev_put;
}

error = ops->pr_register(d->bdev, 0, d->pr_key, true);
error = ops->pr_register(d->bdev_handle->bdev, 0, d->pr_key, true);
if (error) {
pr_err("pNFS: failed to register key for block device %s.",
d->bdev->bd_disk->disk_name);
d->bdev_handle->bdev->bd_disk->disk_name);
goto out_blkdev_put;
}

d->pr_registered = true;
return 0;

out_blkdev_put:
blkdev_put(d->bdev, NULL);
bdev_release(d->bdev_handle);
return error;
}

Expand Down

0 comments on commit 3fe5d9f

Please sign in to comment.