lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Tue,  4 Jul 2023 14:21:28 +0200
From:   Jan Kara <jack@...e.cz>
To:     <linux-block@...r.kernel.org>
Cc:     <linux-fsdevel@...r.kernel.org>, Jens Axboe <axboe@...nel.dk>,
        Christoph Hellwig <hch@...radead.org>, Jan Kara <jack@...e.cz>,
        Alasdair Kergon <agk@...hat.com>,
        Andrew Morton <akpm@...ux-foundation.org>,
        Anna Schumaker <anna@...nel.org>, Chao Yu <chao@...nel.org>,
        Christian Borntraeger <borntraeger@...ux.ibm.com>,
        "Darrick J. Wong" <djwong@...nel.org>,
        Dave Kleikamp <shaggy@...nel.org>,
        David Sterba <dsterba@...e.com>, dm-devel@...hat.com,
        drbd-dev@...ts.linbit.com, Gao Xiang <xiang@...nel.org>,
        Jack Wang <jinpu.wang@...os.com>,
        Jaegeuk Kim <jaegeuk@...nel.org>,
        jfs-discussion@...ts.sourceforge.net,
        Joern Engel <joern@...ybastard.org>,
        Joseph Qi <joseph.qi@...ux.alibaba.com>,
        Kent Overstreet <kent.overstreet@...il.com>,
        linux-bcache@...r.kernel.org, linux-btrfs@...r.kernel.org,
        linux-erofs@...ts.ozlabs.org, linux-ext4@...r.kernel.org,
        linux-f2fs-devel@...ts.sourceforge.net, linux-mm@...ck.org,
        linux-mtd@...ts.infradead.org, linux-nfs@...r.kernel.org,
        linux-nilfs@...r.kernel.org, linux-nvme@...ts.infradead.org,
        linux-pm@...r.kernel.org, linux-raid@...r.kernel.org,
        linux-s390@...r.kernel.org, linux-scsi@...r.kernel.org,
        linux-xfs@...r.kernel.org,
        "Md. Haris Iqbal" <haris.iqbal@...os.com>,
        Mike Snitzer <snitzer@...nel.org>,
        Minchan Kim <minchan@...nel.org>, ocfs2-devel@....oracle.com,
        reiserfs-devel@...r.kernel.org,
        Sergey Senozhatsky <senozhatsky@...omium.org>,
        Song Liu <song@...nel.org>,
        Sven Schnelle <svens@...ux.ibm.com>,
        target-devel@...r.kernel.org, Ted Tso <tytso@....edu>,
        Trond Myklebust <trond.myklebust@...merspace.com>,
        xen-devel@...ts.xenproject.org
Subject: [PATCH 01/32] block: Provide blkdev_get_handle_* functions

Create struct bdev_handle that contains all parameters that need to be
passed to blkdev_put() and provide blkdev_get_handle_* functions that
return this structure instead of plain bdev pointer. This will
eventually allow us to pass one more argument to blkdev_put() without
too much hassle.

CC: Alasdair Kergon <agk@...hat.com>
CC: Andrew Morton <akpm@...ux-foundation.org>
CC: Anna Schumaker <anna@...nel.org>
CC: Chao Yu <chao@...nel.org>
CC: Christian Borntraeger <borntraeger@...ux.ibm.com>
CC: Coly Li <colyli@...e.de
CC: "Darrick J. Wong" <djwong@...nel.org>
CC: Dave Kleikamp <shaggy@...nel.org>
CC: David Sterba <dsterba@...e.com>
CC: dm-devel@...hat.com
CC: drbd-dev@...ts.linbit.com
CC: Gao Xiang <xiang@...nel.org>
CC: Jack Wang <jinpu.wang@...os.com>
CC: Jaegeuk Kim <jaegeuk@...nel.org>
CC: jfs-discussion@...ts.sourceforge.net
CC: Joern Engel <joern@...ybastard.org>
CC: Joseph Qi <joseph.qi@...ux.alibaba.com>
CC: Kent Overstreet <kent.overstreet@...il.com>
CC: linux-bcache@...r.kernel.org
CC: linux-btrfs@...r.kernel.org
CC: linux-erofs@...ts.ozlabs.org
CC: <linux-ext4@...r.kernel.org>
CC: linux-f2fs-devel@...ts.sourceforge.net
CC: linux-mm@...ck.org
CC: linux-mtd@...ts.infradead.org
CC: linux-nfs@...r.kernel.org
CC: linux-nilfs@...r.kernel.org
CC: linux-nvme@...ts.infradead.org
CC: linux-pm@...r.kernel.org
CC: linux-raid@...r.kernel.org
CC: linux-s390@...r.kernel.org
CC: linux-scsi@...r.kernel.org
CC: linux-xfs@...r.kernel.org
CC: "Md. Haris Iqbal" <haris.iqbal@...os.com>
CC: Mike Snitzer <snitzer@...nel.org>
CC: Minchan Kim <minchan@...nel.org>
CC: ocfs2-devel@....oracle.com
CC: reiserfs-devel@...r.kernel.org
CC: Sergey Senozhatsky <senozhatsky@...omium.org>
CC: Song Liu <song@...nel.org>
CC: Sven Schnelle <svens@...ux.ibm.com>
CC: target-devel@...r.kernel.org
CC: Ted Tso <tytso@....edu>
CC: Trond Myklebust <trond.myklebust@...merspace.com>
CC: xen-devel@...ts.xenproject.org
Signed-off-by: Jan Kara <jack@...e.cz>
---
 block/bdev.c           | 47 ++++++++++++++++++++++++++++++++++++++++++
 include/linux/blkdev.h | 10 +++++++++
 2 files changed, 57 insertions(+)

diff --git a/block/bdev.c b/block/bdev.c
index 979e28a46b98..c75de5cac2bc 100644
--- a/block/bdev.c
+++ b/block/bdev.c
@@ -846,6 +846,24 @@ struct block_device *blkdev_get_by_dev(dev_t dev, blk_mode_t mode, void *holder,
 }
 EXPORT_SYMBOL(blkdev_get_by_dev);
 
+struct bdev_handle *blkdev_get_handle_by_dev(dev_t dev, blk_mode_t mode,
+		void *holder, const struct blk_holder_ops *hops)
+{
+	struct bdev_handle *handle = kmalloc(sizeof(struct bdev_handle),
+					     GFP_KERNEL);
+	struct block_device *bdev;
+
+	if (!handle)
+		return ERR_PTR(-ENOMEM);
+	bdev = blkdev_get_by_dev(dev, mode, holder, hops);
+	if (IS_ERR(bdev))
+		return ERR_CAST(bdev);
+	handle->bdev = bdev;
+	handle->holder = holder;
+	return handle;
+}
+EXPORT_SYMBOL(blkdev_get_handle_by_dev);
+
 /**
  * blkdev_get_by_path - open a block device by name
  * @path: path to the block device to open
@@ -884,6 +902,28 @@ struct block_device *blkdev_get_by_path(const char *path, blk_mode_t mode,
 }
 EXPORT_SYMBOL(blkdev_get_by_path);
 
+struct bdev_handle *blkdev_get_handle_by_path(const char *path, blk_mode_t mode,
+		void *holder, const struct blk_holder_ops *hops)
+{
+	struct bdev_handle *handle;
+	dev_t dev;
+	int error;
+
+	error = lookup_bdev(path, &dev);
+	if (error)
+		return ERR_PTR(error);
+
+	handle = blkdev_get_handle_by_dev(dev, mode, holder, hops);
+	if (!IS_ERR(handle) && (mode & BLK_OPEN_WRITE) &&
+	    bdev_read_only(handle->bdev)) {
+		blkdev_handle_put(handle);
+		return ERR_PTR(-EACCES);
+	}
+
+	return handle;
+}
+EXPORT_SYMBOL(blkdev_get_handle_by_path);
+
 void blkdev_put(struct block_device *bdev, void *holder)
 {
 	struct gendisk *disk = bdev->bd_disk;
@@ -920,6 +960,13 @@ void blkdev_put(struct block_device *bdev, void *holder)
 }
 EXPORT_SYMBOL(blkdev_put);
 
+void blkdev_handle_put(struct bdev_handle *handle)
+{
+	blkdev_put(handle->bdev, handle->holder);
+	kfree(handle);
+}
+EXPORT_SYMBOL(blkdev_handle_put);
+
 /**
  * lookup_bdev() - Look up a struct block_device by name.
  * @pathname: Name of the block device in the filesystem.
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index ed44a997f629..a910e9997ddd 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1471,14 +1471,24 @@ struct blk_holder_ops {
 #define sb_open_mode(flags) \
 	(BLK_OPEN_READ | (((flags) & SB_RDONLY) ? 0 : BLK_OPEN_WRITE))
 
+struct bdev_handle {
+	struct block_device *bdev;
+	void *holder;
+};
+
 struct block_device *blkdev_get_by_dev(dev_t dev, blk_mode_t mode, void *holder,
 		const struct blk_holder_ops *hops);
 struct block_device *blkdev_get_by_path(const char *path, blk_mode_t mode,
 		void *holder, const struct blk_holder_ops *hops);
+struct bdev_handle *blkdev_get_handle_by_dev(dev_t dev, blk_mode_t mode,
+		void *holder, const struct blk_holder_ops *hops);
+struct bdev_handle *blkdev_get_handle_by_path(const char *path, blk_mode_t mode,
+		void *holder, const struct blk_holder_ops *hops);
 int bd_prepare_to_claim(struct block_device *bdev, void *holder,
 		const struct blk_holder_ops *hops);
 void bd_abort_claiming(struct block_device *bdev, void *holder);
 void blkdev_put(struct block_device *bdev, void *holder);
+void blkdev_handle_put(struct bdev_handle *handle);
 
 /* just for blk-cgroup, don't use elsewhere */
 struct block_device *blkdev_get_no_open(dev_t dev);
-- 
2.35.3

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ