Skip to content

Commit 05fb1db

Browse files
committed
pktcdvd: port block device access to file
Link: https://lore.kernel.org/r/20240123-vfs-bdev-file-v2-9-adbd023e19cc@kernel.org Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 20e6a8d commit 05fb1db

2 files changed

Lines changed: 36 additions & 36 deletions

File tree

drivers/block/pktcdvd.c

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,8 @@ static ssize_t device_map_show(const struct class *c, const struct class_attribu
340340
n += sysfs_emit_at(data, n, "%s %u:%u %u:%u\n",
341341
pd->disk->disk_name,
342342
MAJOR(pd->pkt_dev), MINOR(pd->pkt_dev),
343-
MAJOR(pd->bdev_handle->bdev->bd_dev),
344-
MINOR(pd->bdev_handle->bdev->bd_dev));
343+
MAJOR(file_bdev(pd->bdev_file)->bd_dev),
344+
MINOR(file_bdev(pd->bdev_file)->bd_dev));
345345
}
346346
mutex_unlock(&ctl_mutex);
347347
return n;
@@ -438,7 +438,7 @@ static int pkt_seq_show(struct seq_file *m, void *p)
438438
int states[PACKET_NUM_STATES];
439439

440440
seq_printf(m, "Writer %s mapped to %pg:\n", pd->disk->disk_name,
441-
pd->bdev_handle->bdev);
441+
file_bdev(pd->bdev_file));
442442

443443
seq_printf(m, "\nSettings:\n");
444444
seq_printf(m, "\tpacket size:\t\t%dkB\n", pd->settings.size / 2);
@@ -715,7 +715,7 @@ static void pkt_rbtree_insert(struct pktcdvd_device *pd, struct pkt_rb_node *nod
715715
*/
716716
static int pkt_generic_packet(struct pktcdvd_device *pd, struct packet_command *cgc)
717717
{
718-
struct request_queue *q = bdev_get_queue(pd->bdev_handle->bdev);
718+
struct request_queue *q = bdev_get_queue(file_bdev(pd->bdev_file));
719719
struct scsi_cmnd *scmd;
720720
struct request *rq;
721721
int ret = 0;
@@ -1048,7 +1048,7 @@ static void pkt_gather_data(struct pktcdvd_device *pd, struct packet_data *pkt)
10481048
continue;
10491049

10501050
bio = pkt->r_bios[f];
1051-
bio_init(bio, pd->bdev_handle->bdev, bio->bi_inline_vecs, 1,
1051+
bio_init(bio, file_bdev(pd->bdev_file), bio->bi_inline_vecs, 1,
10521052
REQ_OP_READ);
10531053
bio->bi_iter.bi_sector = pkt->sector + f * (CD_FRAMESIZE >> 9);
10541054
bio->bi_end_io = pkt_end_io_read;
@@ -1264,7 +1264,7 @@ static void pkt_start_write(struct pktcdvd_device *pd, struct packet_data *pkt)
12641264
struct device *ddev = disk_to_dev(pd->disk);
12651265
int f;
12661266

1267-
bio_init(pkt->w_bio, pd->bdev_handle->bdev, pkt->w_bio->bi_inline_vecs,
1267+
bio_init(pkt->w_bio, file_bdev(pd->bdev_file), pkt->w_bio->bi_inline_vecs,
12681268
pkt->frames, REQ_OP_WRITE);
12691269
pkt->w_bio->bi_iter.bi_sector = pkt->sector;
12701270
pkt->w_bio->bi_end_io = pkt_end_io_packet_write;
@@ -2162,20 +2162,20 @@ static int pkt_open_dev(struct pktcdvd_device *pd, bool write)
21622162
int ret;
21632163
long lba;
21642164
struct request_queue *q;
2165-
struct bdev_handle *bdev_handle;
2165+
struct file *bdev_file;
21662166

21672167
/*
21682168
* We need to re-open the cdrom device without O_NONBLOCK to be able
21692169
* to read/write from/to it. It is already opened in O_NONBLOCK mode
21702170
* so open should not fail.
21712171
*/
2172-
bdev_handle = bdev_open_by_dev(pd->bdev_handle->bdev->bd_dev,
2172+
bdev_file = bdev_file_open_by_dev(file_bdev(pd->bdev_file)->bd_dev,
21732173
BLK_OPEN_READ, pd, NULL);
2174-
if (IS_ERR(bdev_handle)) {
2175-
ret = PTR_ERR(bdev_handle);
2174+
if (IS_ERR(bdev_file)) {
2175+
ret = PTR_ERR(bdev_file);
21762176
goto out;
21772177
}
2178-
pd->open_bdev_handle = bdev_handle;
2178+
pd->f_open_bdev = bdev_file;
21792179

21802180
ret = pkt_get_last_written(pd, &lba);
21812181
if (ret) {
@@ -2184,9 +2184,9 @@ static int pkt_open_dev(struct pktcdvd_device *pd, bool write)
21842184
}
21852185

21862186
set_capacity(pd->disk, lba << 2);
2187-
set_capacity_and_notify(pd->bdev_handle->bdev->bd_disk, lba << 2);
2187+
set_capacity_and_notify(file_bdev(pd->bdev_file)->bd_disk, lba << 2);
21882188

2189-
q = bdev_get_queue(pd->bdev_handle->bdev);
2189+
q = bdev_get_queue(file_bdev(pd->bdev_file));
21902190
if (write) {
21912191
ret = pkt_open_write(pd);
21922192
if (ret)
@@ -2218,7 +2218,7 @@ static int pkt_open_dev(struct pktcdvd_device *pd, bool write)
22182218
return 0;
22192219

22202220
out_putdev:
2221-
bdev_release(bdev_handle);
2221+
fput(bdev_file);
22222222
out:
22232223
return ret;
22242224
}
@@ -2237,8 +2237,8 @@ static void pkt_release_dev(struct pktcdvd_device *pd, int flush)
22372237
pkt_lock_door(pd, 0);
22382238

22392239
pkt_set_speed(pd, MAX_SPEED, MAX_SPEED);
2240-
bdev_release(pd->open_bdev_handle);
2241-
pd->open_bdev_handle = NULL;
2240+
fput(pd->f_open_bdev);
2241+
pd->f_open_bdev = NULL;
22422242

22432243
pkt_shrink_pktlist(pd);
22442244
}
@@ -2326,7 +2326,7 @@ static void pkt_end_io_read_cloned(struct bio *bio)
23262326

23272327
static void pkt_make_request_read(struct pktcdvd_device *pd, struct bio *bio)
23282328
{
2329-
struct bio *cloned_bio = bio_alloc_clone(pd->bdev_handle->bdev, bio,
2329+
struct bio *cloned_bio = bio_alloc_clone(file_bdev(pd->bdev_file), bio,
23302330
GFP_NOIO, &pkt_bio_set);
23312331
struct packet_stacked_data *psd = mempool_alloc(&psd_pool, GFP_NOIO);
23322332

@@ -2497,7 +2497,7 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev)
24972497
{
24982498
struct device *ddev = disk_to_dev(pd->disk);
24992499
int i;
2500-
struct bdev_handle *bdev_handle;
2500+
struct file *bdev_file;
25012501
struct scsi_device *sdev;
25022502

25032503
if (pd->pkt_dev == dev) {
@@ -2508,9 +2508,9 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev)
25082508
struct pktcdvd_device *pd2 = pkt_devs[i];
25092509
if (!pd2)
25102510
continue;
2511-
if (pd2->bdev_handle->bdev->bd_dev == dev) {
2511+
if (file_bdev(pd2->bdev_file)->bd_dev == dev) {
25122512
dev_err(ddev, "%pg already setup\n",
2513-
pd2->bdev_handle->bdev);
2513+
file_bdev(pd2->bdev_file));
25142514
return -EBUSY;
25152515
}
25162516
if (pd2->pkt_dev == dev) {
@@ -2519,22 +2519,22 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev)
25192519
}
25202520
}
25212521

2522-
bdev_handle = bdev_open_by_dev(dev, BLK_OPEN_READ | BLK_OPEN_NDELAY,
2522+
bdev_file = bdev_file_open_by_dev(dev, BLK_OPEN_READ | BLK_OPEN_NDELAY,
25232523
NULL, NULL);
2524-
if (IS_ERR(bdev_handle))
2525-
return PTR_ERR(bdev_handle);
2526-
sdev = scsi_device_from_queue(bdev_handle->bdev->bd_disk->queue);
2524+
if (IS_ERR(bdev_file))
2525+
return PTR_ERR(bdev_file);
2526+
sdev = scsi_device_from_queue(file_bdev(bdev_file)->bd_disk->queue);
25272527
if (!sdev) {
2528-
bdev_release(bdev_handle);
2528+
fput(bdev_file);
25292529
return -EINVAL;
25302530
}
25312531
put_device(&sdev->sdev_gendev);
25322532

25332533
/* This is safe, since we have a reference from open(). */
25342534
__module_get(THIS_MODULE);
25352535

2536-
pd->bdev_handle = bdev_handle;
2537-
set_blocksize(bdev_handle->bdev, CD_FRAMESIZE);
2536+
pd->bdev_file = bdev_file;
2537+
set_blocksize(file_bdev(bdev_file), CD_FRAMESIZE);
25382538

25392539
pkt_init_queue(pd);
25402540

@@ -2546,11 +2546,11 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev)
25462546
}
25472547

25482548
proc_create_single_data(pd->disk->disk_name, 0, pkt_proc, pkt_seq_show, pd);
2549-
dev_notice(ddev, "writer mapped to %pg\n", bdev_handle->bdev);
2549+
dev_notice(ddev, "writer mapped to %pg\n", file_bdev(bdev_file));
25502550
return 0;
25512551

25522552
out_mem:
2553-
bdev_release(bdev_handle);
2553+
fput(bdev_file);
25542554
/* This is safe: open() is still holding a reference. */
25552555
module_put(THIS_MODULE);
25562556
return -ENOMEM;
@@ -2605,9 +2605,9 @@ static unsigned int pkt_check_events(struct gendisk *disk,
26052605

26062606
if (!pd)
26072607
return 0;
2608-
if (!pd->bdev_handle)
2608+
if (!pd->bdev_file)
26092609
return 0;
2610-
attached_disk = pd->bdev_handle->bdev->bd_disk;
2610+
attached_disk = file_bdev(pd->bdev_file)->bd_disk;
26112611
if (!attached_disk || !attached_disk->fops->check_events)
26122612
return 0;
26132613
return attached_disk->fops->check_events(attached_disk, clearing);
@@ -2692,7 +2692,7 @@ static int pkt_setup_dev(dev_t dev, dev_t* pkt_dev)
26922692
goto out_mem2;
26932693

26942694
/* inherit events of the host device */
2695-
disk->events = pd->bdev_handle->bdev->bd_disk->events;
2695+
disk->events = file_bdev(pd->bdev_file)->bd_disk->events;
26962696

26972697
ret = add_disk(disk);
26982698
if (ret)
@@ -2757,7 +2757,7 @@ static int pkt_remove_dev(dev_t pkt_dev)
27572757
pkt_debugfs_dev_remove(pd);
27582758
pkt_sysfs_dev_remove(pd);
27592759

2760-
bdev_release(pd->bdev_handle);
2760+
fput(pd->bdev_file);
27612761

27622762
remove_proc_entry(pd->disk->disk_name, pkt_proc);
27632763
dev_notice(ddev, "writer unmapped\n");
@@ -2784,7 +2784,7 @@ static void pkt_get_status(struct pkt_ctrl_command *ctrl_cmd)
27842784

27852785
pd = pkt_find_dev_from_minor(ctrl_cmd->dev_index);
27862786
if (pd) {
2787-
ctrl_cmd->dev = new_encode_dev(pd->bdev_handle->bdev->bd_dev);
2787+
ctrl_cmd->dev = new_encode_dev(file_bdev(pd->bdev_file)->bd_dev);
27882788
ctrl_cmd->pkt_dev = new_encode_dev(pd->pkt_dev);
27892789
} else {
27902790
ctrl_cmd->dev = 0;

include/linux/pktcdvd.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,9 @@ struct packet_stacked_data
154154

155155
struct pktcdvd_device
156156
{
157-
struct bdev_handle *bdev_handle; /* dev attached */
157+
struct file *bdev_file; /* dev attached */
158158
/* handle acquired for bdev during pkt_open_dev() */
159-
struct bdev_handle *open_bdev_handle;
159+
struct file *f_open_bdev;
160160
dev_t pkt_dev; /* our dev */
161161
struct packet_settings settings;
162162
struct packet_stats stats;

0 commit comments

Comments
 (0)