linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christian Brauner <brauner@kernel.org>
To: Jan Kara <jack@suse.cz>, Christoph Hellwig <hch@lst.de>,
	 Jens Axboe <axboe@kernel.dk>
Cc: "Darrick J. Wong" <djwong@kernel.org>,
	linux-fsdevel@vger.kernel.org,  linux-block@vger.kernel.org,
	Christian Brauner <brauner@kernel.org>
Subject: [PATCH RFC 09/34] pktcdvd: port block device access to file
Date: Wed, 03 Jan 2024 13:55:07 +0100	[thread overview]
Message-ID: <20240103-vfs-bdev-file-v1-9-6c8ee55fb6ef@kernel.org> (raw)
In-Reply-To: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org>

Signed-off-by: Christian Brauner <brauner@kernel.org>
---
 drivers/block/pktcdvd.c | 68 ++++++++++++++++++++++++-------------------------
 include/linux/pktcdvd.h |  4 +--
 2 files changed, 36 insertions(+), 36 deletions(-)

diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index d56d972aadb3..02ab52e55229 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -340,8 +340,8 @@ static ssize_t device_map_show(const struct class *c, const struct class_attribu
 		n += sysfs_emit_at(data, n, "%s %u:%u %u:%u\n",
 			pd->disk->disk_name,
 			MAJOR(pd->pkt_dev), MINOR(pd->pkt_dev),
-			MAJOR(pd->bdev_handle->bdev->bd_dev),
-			MINOR(pd->bdev_handle->bdev->bd_dev));
+			MAJOR(F_BDEV(pd->f_bdev)->bd_dev),
+			MINOR(F_BDEV(pd->f_bdev)->bd_dev));
 	}
 	mutex_unlock(&ctl_mutex);
 	return n;
@@ -438,7 +438,7 @@ static int pkt_seq_show(struct seq_file *m, void *p)
 	int states[PACKET_NUM_STATES];
 
 	seq_printf(m, "Writer %s mapped to %pg:\n", pd->disk->disk_name,
-		   pd->bdev_handle->bdev);
+		   F_BDEV(pd->f_bdev));
 
 	seq_printf(m, "\nSettings:\n");
 	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
  */
 static int pkt_generic_packet(struct pktcdvd_device *pd, struct packet_command *cgc)
 {
-	struct request_queue *q = bdev_get_queue(pd->bdev_handle->bdev);
+	struct request_queue *q = bdev_get_queue(F_BDEV(pd->f_bdev));
 	struct scsi_cmnd *scmd;
 	struct request *rq;
 	int ret = 0;
@@ -1048,7 +1048,7 @@ static void pkt_gather_data(struct pktcdvd_device *pd, struct packet_data *pkt)
 			continue;
 
 		bio = pkt->r_bios[f];
-		bio_init(bio, pd->bdev_handle->bdev, bio->bi_inline_vecs, 1,
+		bio_init(bio, F_BDEV(pd->f_bdev), bio->bi_inline_vecs, 1,
 			 REQ_OP_READ);
 		bio->bi_iter.bi_sector = pkt->sector + f * (CD_FRAMESIZE >> 9);
 		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)
 	struct device *ddev = disk_to_dev(pd->disk);
 	int f;
 
-	bio_init(pkt->w_bio, pd->bdev_handle->bdev, pkt->w_bio->bi_inline_vecs,
+	bio_init(pkt->w_bio, F_BDEV(pd->f_bdev), pkt->w_bio->bi_inline_vecs,
 		 pkt->frames, REQ_OP_WRITE);
 	pkt->w_bio->bi_iter.bi_sector = pkt->sector;
 	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)
 	int ret;
 	long lba;
 	struct request_queue *q;
-	struct bdev_handle *bdev_handle;
+	struct file *f_bdev;
 
 	/*
 	 * We need to re-open the cdrom device without O_NONBLOCK to be able
 	 * to read/write from/to it. It is already opened in O_NONBLOCK mode
 	 * so open should not fail.
 	 */
-	bdev_handle = bdev_open_by_dev(pd->bdev_handle->bdev->bd_dev,
+	f_bdev = bdev_file_open_by_dev(F_BDEV(pd->f_bdev)->bd_dev,
 				       BLK_OPEN_READ, pd, NULL);
-	if (IS_ERR(bdev_handle)) {
-		ret = PTR_ERR(bdev_handle);
+	if (IS_ERR(f_bdev)) {
+		ret = PTR_ERR(f_bdev);
 		goto out;
 	}
-	pd->open_bdev_handle = bdev_handle;
+	pd->f_open_bdev = f_bdev;
 
 	ret = pkt_get_last_written(pd, &lba);
 	if (ret) {
@@ -2184,9 +2184,9 @@ static int pkt_open_dev(struct pktcdvd_device *pd, bool write)
 	}
 
 	set_capacity(pd->disk, lba << 2);
-	set_capacity_and_notify(pd->bdev_handle->bdev->bd_disk, lba << 2);
+	set_capacity_and_notify(F_BDEV(pd->f_bdev)->bd_disk, lba << 2);
 
-	q = bdev_get_queue(pd->bdev_handle->bdev);
+	q = bdev_get_queue(F_BDEV(pd->f_bdev));
 	if (write) {
 		ret = pkt_open_write(pd);
 		if (ret)
@@ -2218,7 +2218,7 @@ static int pkt_open_dev(struct pktcdvd_device *pd, bool write)
 	return 0;
 
 out_putdev:
-	bdev_release(bdev_handle);
+	fput(f_bdev);
 out:
 	return ret;
 }
@@ -2237,8 +2237,8 @@ static void pkt_release_dev(struct pktcdvd_device *pd, int flush)
 	pkt_lock_door(pd, 0);
 
 	pkt_set_speed(pd, MAX_SPEED, MAX_SPEED);
-	bdev_release(pd->open_bdev_handle);
-	pd->open_bdev_handle = NULL;
+	fput(pd->f_open_bdev);
+	pd->f_open_bdev = NULL;
 
 	pkt_shrink_pktlist(pd);
 }
@@ -2326,7 +2326,7 @@ static void pkt_end_io_read_cloned(struct bio *bio)
 
 static void pkt_make_request_read(struct pktcdvd_device *pd, struct bio *bio)
 {
-	struct bio *cloned_bio = bio_alloc_clone(pd->bdev_handle->bdev, bio,
+	struct bio *cloned_bio = bio_alloc_clone(F_BDEV(pd->f_bdev), bio,
 		GFP_NOIO, &pkt_bio_set);
 	struct packet_stacked_data *psd = mempool_alloc(&psd_pool, GFP_NOIO);
 
@@ -2497,7 +2497,7 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev)
 {
 	struct device *ddev = disk_to_dev(pd->disk);
 	int i;
-	struct bdev_handle *bdev_handle;
+	struct file *f_bdev;
 	struct scsi_device *sdev;
 
 	if (pd->pkt_dev == dev) {
@@ -2508,9 +2508,9 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev)
 		struct pktcdvd_device *pd2 = pkt_devs[i];
 		if (!pd2)
 			continue;
-		if (pd2->bdev_handle->bdev->bd_dev == dev) {
+		if (F_BDEV(pd2->f_bdev)->bd_dev == dev) {
 			dev_err(ddev, "%pg already setup\n",
-				pd2->bdev_handle->bdev);
+				F_BDEV(pd2->f_bdev));
 			return -EBUSY;
 		}
 		if (pd2->pkt_dev == dev) {
@@ -2519,13 +2519,13 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev)
 		}
 	}
 
-	bdev_handle = bdev_open_by_dev(dev, BLK_OPEN_READ | BLK_OPEN_NDELAY,
+	f_bdev = bdev_file_open_by_dev(dev, BLK_OPEN_READ | BLK_OPEN_NDELAY,
 				       NULL, NULL);
-	if (IS_ERR(bdev_handle))
-		return PTR_ERR(bdev_handle);
-	sdev = scsi_device_from_queue(bdev_handle->bdev->bd_disk->queue);
+	if (IS_ERR(f_bdev))
+		return PTR_ERR(f_bdev);
+	sdev = scsi_device_from_queue(F_BDEV(f_bdev)->bd_disk->queue);
 	if (!sdev) {
-		bdev_release(bdev_handle);
+		fput(f_bdev);
 		return -EINVAL;
 	}
 	put_device(&sdev->sdev_gendev);
@@ -2533,8 +2533,8 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev)
 	/* This is safe, since we have a reference from open(). */
 	__module_get(THIS_MODULE);
 
-	pd->bdev_handle = bdev_handle;
-	set_blocksize(bdev_handle->bdev, CD_FRAMESIZE);
+	pd->f_bdev = f_bdev;
+	set_blocksize(F_BDEV(f_bdev), CD_FRAMESIZE);
 
 	pkt_init_queue(pd);
 
@@ -2546,11 +2546,11 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev)
 	}
 
 	proc_create_single_data(pd->disk->disk_name, 0, pkt_proc, pkt_seq_show, pd);
-	dev_notice(ddev, "writer mapped to %pg\n", bdev_handle->bdev);
+	dev_notice(ddev, "writer mapped to %pg\n", F_BDEV(f_bdev));
 	return 0;
 
 out_mem:
-	bdev_release(bdev_handle);
+	fput(f_bdev);
 	/* This is safe: open() is still holding a reference. */
 	module_put(THIS_MODULE);
 	return -ENOMEM;
@@ -2605,9 +2605,9 @@ static unsigned int pkt_check_events(struct gendisk *disk,
 
 	if (!pd)
 		return 0;
-	if (!pd->bdev_handle)
+	if (!pd->f_bdev)
 		return 0;
-	attached_disk = pd->bdev_handle->bdev->bd_disk;
+	attached_disk = F_BDEV(pd->f_bdev)->bd_disk;
 	if (!attached_disk || !attached_disk->fops->check_events)
 		return 0;
 	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)
 		goto out_mem2;
 
 	/* inherit events of the host device */
-	disk->events = pd->bdev_handle->bdev->bd_disk->events;
+	disk->events = F_BDEV(pd->f_bdev)->bd_disk->events;
 
 	ret = add_disk(disk);
 	if (ret)
@@ -2757,7 +2757,7 @@ static int pkt_remove_dev(dev_t pkt_dev)
 	pkt_debugfs_dev_remove(pd);
 	pkt_sysfs_dev_remove(pd);
 
-	bdev_release(pd->bdev_handle);
+	fput(pd->f_bdev);
 
 	remove_proc_entry(pd->disk->disk_name, pkt_proc);
 	dev_notice(ddev, "writer unmapped\n");
@@ -2784,7 +2784,7 @@ static void pkt_get_status(struct pkt_ctrl_command *ctrl_cmd)
 
 	pd = pkt_find_dev_from_minor(ctrl_cmd->dev_index);
 	if (pd) {
-		ctrl_cmd->dev = new_encode_dev(pd->bdev_handle->bdev->bd_dev);
+		ctrl_cmd->dev = new_encode_dev(F_BDEV(pd->f_bdev)->bd_dev);
 		ctrl_cmd->pkt_dev = new_encode_dev(pd->pkt_dev);
 	} else {
 		ctrl_cmd->dev = 0;
diff --git a/include/linux/pktcdvd.h b/include/linux/pktcdvd.h
index 79594aeb160d..e202ec04b7e0 100644
--- a/include/linux/pktcdvd.h
+++ b/include/linux/pktcdvd.h
@@ -154,9 +154,9 @@ struct packet_stacked_data
 
 struct pktcdvd_device
 {
-	struct bdev_handle	*bdev_handle;	/* dev attached */
+	struct file		*f_bdev;	/* dev attached */
 	/* handle acquired for bdev during pkt_open_dev() */
-	struct bdev_handle	*open_bdev_handle;
+	struct file		*f_open_bdev;
 	dev_t			pkt_dev;	/* our dev */
 	struct packet_settings	settings;
 	struct packet_stats	stats;

-- 
2.42.0


  parent reply	other threads:[~2024-01-03 12:55 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-03 12:54 [PATCH RFC 00/34] Open block devices as files & a bd_inode proposal Christian Brauner
2024-01-03 12:54 ` [PATCH RFC 01/34] bdev: open block device as files Christian Brauner
2024-01-08  5:37   ` Dave Chinner
2024-01-08 11:34     ` Christian Brauner
2024-01-17 15:31   ` Jan Kara
2024-01-18 17:22     ` Christian Brauner
2024-01-03 12:55 ` [PATCH RFC 02/34] block/ioctl: port blkdev_bszset() to file Christian Brauner
2024-01-03 12:55 ` [PATCH RFC 03/34] block/genhd: port disk_scan_partitions() " Christian Brauner
2024-01-03 12:55 ` [PATCH RFC 04/34] md: port block device access " Christian Brauner
2024-01-03 12:55 ` [PATCH RFC 05/34] swap: port block device usage " Christian Brauner
2024-01-03 12:55 ` [PATCH RFC 06/34] power: port block device access " Christian Brauner
2024-01-03 12:55 ` [PATCH RFC 07/34] xfs: port block device access to files Christian Brauner
2024-01-08  5:34   ` Dave Chinner
2024-01-08 11:34     ` Christian Brauner
2024-01-03 12:55 ` [PATCH RFC 08/34] drbd: port block device access to file Christian Brauner
2024-01-03 12:55 ` Christian Brauner [this message]
2024-01-03 12:55 ` [PATCH RFC 10/34] rnbd: " Christian Brauner
2024-01-03 12:55 ` [PATCH RFC 11/34] xen: " Christian Brauner
2024-01-03 12:55 ` [PATCH RFC 12/34] zram: " Christian Brauner
2024-01-03 12:55 ` [PATCH RFC 13/34] bcache: port block device access to files Christian Brauner
2024-01-03 12:55 ` [PATCH RFC 14/34] block2mtd: port " Christian Brauner
2024-01-03 12:55 ` [PATCH RFC 15/34] nvme: port block device access to file Christian Brauner
2024-01-03 12:55 ` [PATCH RFC 16/34] s390: " Christian Brauner
2024-01-03 12:55 ` [PATCH RFC 17/34] target: " Christian Brauner
2024-01-03 12:55 ` [PATCH RFC 18/34] bcachefs: " Christian Brauner
2024-01-03 12:55 ` [PATCH RFC 19/34] btrfs: port " Christian Brauner
2024-01-03 12:55 ` [PATCH RFC 20/34] erofs: " Christian Brauner
2024-01-03 12:55 ` [PATCH RFC 21/34] ext4: port block " Christian Brauner
2024-01-03 12:55 ` [PATCH RFC 22/34] f2fs: port block device access to files Christian Brauner
2024-01-03 12:55 ` [PATCH RFC 23/34] jfs: port block device access to file Christian Brauner
2024-01-03 12:55 ` [PATCH RFC 24/34] nfs: port block device access to files Christian Brauner
2024-01-03 12:55 ` [PATCH RFC 25/34] ocfs2: port block device access to file Christian Brauner
2024-01-03 12:55 ` [PATCH RFC 26/34] reiserfs: " Christian Brauner
2024-01-03 12:55 ` [PATCH RFC 27/34] bdev: remove bdev_open_by_path() Christian Brauner
2024-01-03 12:55 ` [PATCH RFC 28/34] bdev: make bdev_release() private to block layer Christian Brauner
2024-01-03 12:55 ` [PATCH RFC 29/34] bdev: make struct bdev_handle private to the " Christian Brauner
2024-01-03 12:55 ` [PATCH RFC 30/34] bdev: rework bdev_open_by_dev() Christian Brauner
2024-01-03 12:55 ` [PATCH RFC 31/34] ext4: rely on sb->f_bdev only Christian Brauner
2024-01-03 12:55 ` [PATCH RFC 32/34] block: expose bdev_file_inode() Christian Brauner
2024-01-03 12:55 ` [PATCH RFC 33/34] ext4: use bdev_file_inode() Christian Brauner
2024-01-03 12:55 ` [PATCH DRAFT RFC 34/34] buffer: port block device access to files and get rid of bd_inode access Christian Brauner
2024-01-08  5:52   ` Dave Chinner
2024-01-17 16:15     ` Jan Kara
2024-01-17 16:24       ` Christoph Hellwig
2024-01-17 16:33         ` Jan Kara
2024-01-18 17:39           ` Christian Brauner
2024-01-17 16:32   ` Jan Kara
2024-01-18 17:41     ` Christian Brauner
2024-01-08 16:26 ` [PATCH RFC 00/34] Open block devices as files & a bd_inode proposal Christoph Hellwig
2024-01-09  8:46   ` Jan Kara
2024-01-15 14:24     ` Christian Brauner
2024-01-17 16:46 ` Jan Kara

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240103-vfs-bdev-file-v1-9-6c8ee55fb6ef@kernel.org \
    --to=brauner@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=djwong@kernel.org \
    --cc=hch@lst.de \
    --cc=jack@suse.cz \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).