Skip to content

Commit 4b2cfbd

Browse files
committed
nfs: port block device access to files
Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Jan Kara <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent ac4e78b commit 4b2cfbd

File tree

2 files changed

+35
-35
lines changed

2 files changed

+35
-35
lines changed

fs/nfs/blocklayout/blocklayout.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ struct pnfs_block_dev {
108108
struct pnfs_block_dev *children;
109109
u64 chunk_size;
110110

111-
struct bdev_handle *bdev_handle;
111+
struct file *bdev_file;
112112
u64 disk_offset;
113113

114114
u64 pr_key;

fs/nfs/blocklayout/dev.c

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@ bl_free_device(struct pnfs_block_dev *dev)
2525
} else {
2626
if (dev->pr_registered) {
2727
const struct pr_ops *ops =
28-
dev->bdev_handle->bdev->bd_disk->fops->pr_ops;
28+
file_bdev(dev->bdev_file)->bd_disk->fops->pr_ops;
2929
int error;
3030

31-
error = ops->pr_register(dev->bdev_handle->bdev,
31+
error = ops->pr_register(file_bdev(dev->bdev_file),
3232
dev->pr_key, 0, false);
3333
if (error)
3434
pr_err("failed to unregister PR key.\n");
3535
}
3636

37-
if (dev->bdev_handle)
38-
bdev_release(dev->bdev_handle);
37+
if (dev->bdev_file)
38+
fput(dev->bdev_file);
3939
}
4040
}
4141

@@ -169,7 +169,7 @@ static bool bl_map_simple(struct pnfs_block_dev *dev, u64 offset,
169169
map->start = dev->start;
170170
map->len = dev->len;
171171
map->disk_offset = dev->disk_offset;
172-
map->bdev = dev->bdev_handle->bdev;
172+
map->bdev = file_bdev(dev->bdev_file);
173173
return true;
174174
}
175175

@@ -236,26 +236,26 @@ bl_parse_simple(struct nfs_server *server, struct pnfs_block_dev *d,
236236
struct pnfs_block_volume *volumes, int idx, gfp_t gfp_mask)
237237
{
238238
struct pnfs_block_volume *v = &volumes[idx];
239-
struct bdev_handle *bdev_handle;
239+
struct file *bdev_file;
240240
dev_t dev;
241241

242242
dev = bl_resolve_deviceid(server, v, gfp_mask);
243243
if (!dev)
244244
return -EIO;
245245

246-
bdev_handle = bdev_open_by_dev(dev, BLK_OPEN_READ | BLK_OPEN_WRITE,
246+
bdev_file = bdev_file_open_by_dev(dev, BLK_OPEN_READ | BLK_OPEN_WRITE,
247247
NULL, NULL);
248-
if (IS_ERR(bdev_handle)) {
248+
if (IS_ERR(bdev_file)) {
249249
printk(KERN_WARNING "pNFS: failed to open device %d:%d (%ld)\n",
250-
MAJOR(dev), MINOR(dev), PTR_ERR(bdev_handle));
251-
return PTR_ERR(bdev_handle);
250+
MAJOR(dev), MINOR(dev), PTR_ERR(bdev_file));
251+
return PTR_ERR(bdev_file);
252252
}
253-
d->bdev_handle = bdev_handle;
254-
d->len = bdev_nr_bytes(bdev_handle->bdev);
253+
d->bdev_file = bdev_file;
254+
d->len = bdev_nr_bytes(file_bdev(bdev_file));
255255
d->map = bl_map_simple;
256256

257257
printk(KERN_INFO "pNFS: using block device %s\n",
258-
bdev_handle->bdev->bd_disk->disk_name);
258+
file_bdev(bdev_file)->bd_disk->disk_name);
259259
return 0;
260260
}
261261

@@ -300,34 +300,34 @@ bl_validate_designator(struct pnfs_block_volume *v)
300300
}
301301
}
302302

303-
static struct bdev_handle *
303+
static struct file *
304304
bl_open_path(struct pnfs_block_volume *v, const char *prefix)
305305
{
306-
struct bdev_handle *bdev_handle;
306+
struct file *bdev_file;
307307
const char *devname;
308308

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

314-
bdev_handle = bdev_open_by_path(devname, BLK_OPEN_READ | BLK_OPEN_WRITE,
314+
bdev_file = bdev_file_open_by_path(devname, BLK_OPEN_READ | BLK_OPEN_WRITE,
315315
NULL, NULL);
316-
if (IS_ERR(bdev_handle)) {
316+
if (IS_ERR(bdev_file)) {
317317
pr_warn("pNFS: failed to open device %s (%ld)\n",
318-
devname, PTR_ERR(bdev_handle));
318+
devname, PTR_ERR(bdev_file));
319319
}
320320

321321
kfree(devname);
322-
return bdev_handle;
322+
return bdev_file;
323323
}
324324

325325
static int
326326
bl_parse_scsi(struct nfs_server *server, struct pnfs_block_dev *d,
327327
struct pnfs_block_volume *volumes, int idx, gfp_t gfp_mask)
328328
{
329329
struct pnfs_block_volume *v = &volumes[idx];
330-
struct bdev_handle *bdev_handle;
330+
struct file *bdev_file;
331331
const struct pr_ops *ops;
332332
int error;
333333

@@ -340,43 +340,43 @@ bl_parse_scsi(struct nfs_server *server, struct pnfs_block_dev *d,
340340
* On other distributions like Debian, the default SCSI by-id path will
341341
* point to the dm-multipath device if one exists.
342342
*/
343-
bdev_handle = bl_open_path(v, "dm-uuid-mpath-0x");
344-
if (IS_ERR(bdev_handle))
345-
bdev_handle = bl_open_path(v, "wwn-0x");
346-
if (IS_ERR(bdev_handle))
347-
return PTR_ERR(bdev_handle);
348-
d->bdev_handle = bdev_handle;
349-
350-
d->len = bdev_nr_bytes(d->bdev_handle->bdev);
343+
bdev_file = bl_open_path(v, "dm-uuid-mpath-0x");
344+
if (IS_ERR(bdev_file))
345+
bdev_file = bl_open_path(v, "wwn-0x");
346+
if (IS_ERR(bdev_file))
347+
return PTR_ERR(bdev_file);
348+
d->bdev_file = bdev_file;
349+
350+
d->len = bdev_nr_bytes(file_bdev(d->bdev_file));
351351
d->map = bl_map_simple;
352352
d->pr_key = v->scsi.pr_key;
353353

354354
if (d->len == 0)
355355
return -ENODEV;
356356

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

360-
ops = d->bdev_handle->bdev->bd_disk->fops->pr_ops;
360+
ops = file_bdev(d->bdev_file)->bd_disk->fops->pr_ops;
361361
if (!ops) {
362362
pr_err("pNFS: block device %s does not support reservations.",
363-
d->bdev_handle->bdev->bd_disk->disk_name);
363+
file_bdev(d->bdev_file)->bd_disk->disk_name);
364364
error = -EINVAL;
365365
goto out_blkdev_put;
366366
}
367367

368-
error = ops->pr_register(d->bdev_handle->bdev, 0, d->pr_key, true);
368+
error = ops->pr_register(file_bdev(d->bdev_file), 0, d->pr_key, true);
369369
if (error) {
370370
pr_err("pNFS: failed to register key for block device %s.",
371-
d->bdev_handle->bdev->bd_disk->disk_name);
371+
file_bdev(d->bdev_file)->bd_disk->disk_name);
372372
goto out_blkdev_put;
373373
}
374374

375375
d->pr_registered = true;
376376
return 0;
377377

378378
out_blkdev_put:
379-
bdev_release(d->bdev_handle);
379+
fput(d->bdev_file);
380380
return error;
381381
}
382382

0 commit comments

Comments
 (0)