Re: [Nbd] [PATCH 1/6] block: export blkdev_reread_part()
- To: Ming Lei <ming.lei@...1301...>
- Cc: Jens Axboe <axboe@...161...>, nbd-general@lists.sourceforge.net, linux-s390@...25..., Stefan Haberland <stefan.haberland@...1296...>, Sebastian Ott <sebott@...1294...>, linux-kernel@...25..., Jarod Wilson <jarod@...696...>, Christoph Hellwig <hch@...1270...>, Fabian Frederick <fabf@...1980...>, Alexander Viro <viro@...1300...>, David Herrmann <dh.herrmann@...17...>, Tejun Heo <tj@...1285...>, Andrew Morton <akpm@...133...>
- Subject: Re: [Nbd] [PATCH 1/6] block: export blkdev_reread_part()
- From: Christoph Hellwig <hch@...1270...>
- Date: Sun, 5 Apr 2015 09:12:41 -0700
- Message-id: <20150405161241.GB16886@...1270...>
- In-reply-to: <1428218688-4092-2-git-send-email-ming.lei@...1301...>
- References: <1428218688-4092-1-git-send-email-ming.lei@...1301...> <1428218688-4092-2-git-send-email-ming.lei@...1301...>
> +/*
> + * This is exported as API for block driver, can be called
> + * with requiring bd_mutex or not.
> + */
> +int __blkdev_reread_part(struct block_device *bdev, bool lock)
> {
> struct gendisk *disk = bdev->bd_disk;
> int res;
> @@ -159,12 +163,14 @@ static int blkdev_reread_part(struct block_device *bdev)
> return -EINVAL;
> if (!capable(CAP_SYS_ADMIN))
> return -EACCES;
> - if (!mutex_trylock(&bdev->bd_mutex))
> + if (lock && !mutex_trylock(&bdev->bd_mutex))
> return -EBUSY;
Please don't add funtions that do conditional locking, instead move
all the code into blkdev_reread_part_nolock, and then wrap it:
int blkdev_reread_part(struct block_device *bdev)
{
if (!mutex_trylock(&bdev->bd_mutex))
return -EBUSY;
blkdev_reread_part_nolock(bdev);
mutex_unlock(&bdev->bd_mutex);
}
Please also add a lockdep_assert_held to blkdev_reread_part_nolock to
ensure callers actually do hold the lock.
Reply to: