lkml.org 
[lkml]   [2015]   [Apr]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 1/6] block: export blkdev_reread_part()
> +/*
> + * 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.


\
 
 \ /
  Last update: 2015-04-05 18:21    [W:0.206 / U:0.048 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site