From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752774AbbDEQMp (ORCPT ); Sun, 5 Apr 2015 12:12:45 -0400 Received: from bombadil.infradead.org ([198.137.202.9]:46925 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752295AbbDEQMo (ORCPT ); Sun, 5 Apr 2015 12:12:44 -0400 Date: Sun, 5 Apr 2015 09:12:41 -0700 From: Christoph Hellwig To: Ming Lei Cc: Jens Axboe , linux-kernel@vger.kernel.org, Christoph Hellwig , Tejun Heo , Andrew Morton , Alexander Viro , Jarod Wilson , David Herrmann , Markus Pargmann , nbd-general@lists.sourceforge.net, Stefan Haberland , Sebastian Ott , Fabian Frederick , linux-s390@vger.kernel.org Subject: Re: [PATCH 1/6] block: export blkdev_reread_part() Message-ID: <20150405161241.GB16886@infradead.org> References: <1428218688-4092-1-git-send-email-ming.lei@canonical.com> <1428218688-4092-2-git-send-email-ming.lei@canonical.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1428218688-4092-2-git-send-email-ming.lei@canonical.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > +/* > + * 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.