From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mail19.linbit.com (LINBIT Mail Daemon) with ESMTP id CA106420356 for ; Tue, 4 Jul 2023 18:34:51 +0200 (CEST) Date: Tue, 4 Jul 2023 10:28:36 -0600 From: Keith Busch To: Jan Kara Message-ID: References: <20230629165206.383-1-jack@suse.cz> <20230704122224.16257-1-jack@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230704122224.16257-1-jack@suse.cz> Cc: Dave Kleikamp , jfs-discussion@lists.sourceforge.net, "Darrick J. Wong" , linux-nvme@lists.infradead.org, Joseph Qi , dm-devel@redhat.com, target-devel@vger.kernel.org, linux-mtd@lists.infradead.org, Jack Wang , Alasdair Kergon , drbd-dev@lists.linbit.com, linux-s390@vger.kernel.org, linux-nilfs@vger.kernel.org, linux-scsi@vger.kernel.org, Sergey Senozhatsky , Christoph Hellwig , xen-devel@lists.xenproject.org, Gao Xiang , Christian Borntraeger , Kent Overstreet , Sven Schnelle , linux-pm@vger.kernel.org, Mike Snitzer , Chao Yu , Joern Engel , reiserfs-devel@vger.kernel.org, linux-block@vger.kernel.org, linux-bcache@vger.kernel.org, David Sterba , Jaegeuk Kim , Trond Myklebust , Jens Axboe , linux-raid@vger.kernel.org, linux-nfs@vger.kernel.org, linux-ext4@vger.kernel.org, Ted Tso , linux-mm@kvack.org, Song Liu , linux-f2fs-devel@lists.sourceforge.net, linux-xfs@vger.kernel.org, Minchan Kim , ocfs2-devel@oss.oracle.com, Anna Schumaker , linux-fsdevel@vger.kernel.org, "Md. Haris Iqbal" , Andrew Morton , linux-erofs@lists.ozlabs.org, linux-btrfs@vger.kernel.org Subject: Re: [Drbd-dev] [PATCH 01/32] block: Provide blkdev_get_handle_* functions List-Id: "*Coordination* of development, patches, contributions -- *Questions* \(even to developers\) go to drbd-user, please." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , On Tue, Jul 04, 2023 at 02:21:28PM +0200, Jan Kara wrote: > +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); I believe 'sizeof(*handle)' is the preferred style. > + 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); Need a 'kfree(handle)' before the error return. Or would it be simpler to get the bdev first so you can check the mode settings against a read-only bdev prior to the kmalloc? > + 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);