diff options
author | Tejun Heo <tj@kernel.org> | 2010-11-13 05:55:17 -0500 |
---|---|---|
committer | Tejun Heo <tj@kernel.org> | 2010-11-13 05:55:17 -0500 |
commit | e525fd89d380c4a94c0d63913a1dd1a593ed25e7 (patch) | |
tree | d226ef40d3f99e42fcf272ad432585cbd641ebec /include/linux/fs.h | |
parent | e09b457bdb7e8d23fc54dcef0930ac697d8de895 (diff) |
block: make blkdev_get/put() handle exclusive access
Over time, block layer has accumulated a set of APIs dealing with bdev
open, close, claim and release.
* blkdev_get/put() are the primary open and close functions.
* bd_claim/release() deal with exclusive open.
* open/close_bdev_exclusive() are combination of open and claim and
the other way around, respectively.
* bd_link/unlink_disk_holder() to create and remove holder/slave
symlinks.
* open_by_devnum() wraps bdget() + blkdev_get().
The interface is a bit confusing and the decoupling of open and claim
makes it impossible to properly guarantee exclusive access as
in-kernel open + claim sequence can disturb the existing exclusive
open even before the block layer knows the current open if for another
exclusive access. Reorganize the interface such that,
* blkdev_get() is extended to include exclusive access management.
@holder argument is added and, if is @FMODE_EXCL specified, it will
gain exclusive access atomically w.r.t. other exclusive accesses.
* blkdev_put() is similarly extended. It now takes @mode argument and
if @FMODE_EXCL is set, it releases an exclusive access. Also, when
the last exclusive claim is released, the holder/slave symlinks are
removed automatically.
* bd_claim/release() and close_bdev_exclusive() are no longer
necessary and either made static or removed.
* bd_link_disk_holder() remains the same but bd_unlink_disk_holder()
is no longer necessary and removed.
* open_bdev_exclusive() becomes a simple wrapper around lookup_bdev()
and blkdev_get(). It also has an unexpected extra bdev_read_only()
test which probably should be moved into blkdev_get().
* open_by_devnum() is modified to take @holder argument and pass it to
blkdev_get().
Most of bdev open/close operations are unified into blkdev_get/put()
and most exclusive accesses are tested atomically at the open time (as
it should). This cleans up code and removes some, both valid and
invalid, but unnecessary all the same, corner cases.
open_bdev_exclusive() and open_by_devnum() can use further cleanup -
rename to blkdev_get_by_path() and blkdev_get_by_devt() and drop
special features. Well, let's leave them for another day.
Most conversions are straight-forward. drbd conversion is a bit more
involved as there was some reordering, but the logic should stay the
same.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Neil Brown <neilb@suse.de>
Acked-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Acked-by: Mike Snitzer <snitzer@redhat.com>
Acked-by: Philipp Reisner <philipp.reisner@linbit.com>
Cc: Peter Osterlund <petero2@telia.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andreas Dilger <adilger.kernel@dilger.ca>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Cc: Mark Fasheh <mfasheh@suse.com>
Cc: Joel Becker <joel.becker@oracle.com>
Cc: Alex Elder <aelder@sgi.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: dm-devel@redhat.com
Cc: drbd-dev@lists.linbit.com
Cc: Leo Chen <leochen@broadcom.com>
Cc: Scott Branden <sbranden@broadcom.com>
Cc: Chris Mason <chris.mason@oracle.com>
Cc: Steven Whitehouse <swhiteho@redhat.com>
Cc: Dave Kleikamp <shaggy@linux.vnet.ibm.com>
Cc: Joern Engel <joern@logfs.org>
Cc: reiserfs-devel@vger.kernel.org
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'include/linux/fs.h')
-rw-r--r-- | include/linux/fs.h | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/include/linux/fs.h b/include/linux/fs.h index 66b7f2c5d7e9..1a033e8ebe4c 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h | |||
@@ -2006,7 +2006,8 @@ extern struct block_device *bdgrab(struct block_device *bdev); | |||
2006 | extern void bd_set_size(struct block_device *, loff_t size); | 2006 | extern void bd_set_size(struct block_device *, loff_t size); |
2007 | extern void bd_forget(struct inode *inode); | 2007 | extern void bd_forget(struct inode *inode); |
2008 | extern void bdput(struct block_device *); | 2008 | extern void bdput(struct block_device *); |
2009 | extern struct block_device *open_by_devnum(dev_t, fmode_t); | 2009 | extern struct block_device *open_by_devnum(dev_t dev, fmode_t mode, |
2010 | void *holder); | ||
2010 | extern void invalidate_bdev(struct block_device *); | 2011 | extern void invalidate_bdev(struct block_device *); |
2011 | extern int sync_blockdev(struct block_device *bdev); | 2012 | extern int sync_blockdev(struct block_device *bdev); |
2012 | extern struct super_block *freeze_bdev(struct block_device *); | 2013 | extern struct super_block *freeze_bdev(struct block_device *); |
@@ -2037,22 +2038,16 @@ extern const struct file_operations def_fifo_fops; | |||
2037 | extern int ioctl_by_bdev(struct block_device *, unsigned, unsigned long); | 2038 | extern int ioctl_by_bdev(struct block_device *, unsigned, unsigned long); |
2038 | extern int blkdev_ioctl(struct block_device *, fmode_t, unsigned, unsigned long); | 2039 | extern int blkdev_ioctl(struct block_device *, fmode_t, unsigned, unsigned long); |
2039 | extern long compat_blkdev_ioctl(struct file *, unsigned, unsigned long); | 2040 | extern long compat_blkdev_ioctl(struct file *, unsigned, unsigned long); |
2040 | extern int blkdev_get(struct block_device *, fmode_t); | 2041 | extern int blkdev_get(struct block_device *bdev, fmode_t mode, void *holder); |
2041 | extern int blkdev_put(struct block_device *, fmode_t); | 2042 | extern int blkdev_put(struct block_device *bdev, fmode_t mode); |
2042 | extern int bd_claim(struct block_device *, void *); | ||
2043 | extern void bd_release(struct block_device *); | ||
2044 | #ifdef CONFIG_SYSFS | 2043 | #ifdef CONFIG_SYSFS |
2045 | extern int bd_link_disk_holder(struct block_device *bdev, struct gendisk *disk); | 2044 | extern int bd_link_disk_holder(struct block_device *bdev, struct gendisk *disk); |
2046 | extern void bd_unlink_disk_holder(struct block_device *bdev); | ||
2047 | #else | 2045 | #else |
2048 | static inline int bd_link_disk_holder(struct block_device *bdev, | 2046 | static inline int bd_link_disk_holder(struct block_device *bdev, |
2049 | struct gendisk *disk) | 2047 | struct gendisk *disk) |
2050 | { | 2048 | { |
2051 | return 0; | 2049 | return 0; |
2052 | } | 2050 | } |
2053 | static inline void bd_unlink_disk_holder(struct block_device *bdev) | ||
2054 | { | ||
2055 | } | ||
2056 | #endif | 2051 | #endif |
2057 | #endif | 2052 | #endif |
2058 | 2053 | ||
@@ -2089,7 +2084,6 @@ extern const char *__bdevname(dev_t, char *buffer); | |||
2089 | extern const char *bdevname(struct block_device *bdev, char *buffer); | 2084 | extern const char *bdevname(struct block_device *bdev, char *buffer); |
2090 | extern struct block_device *lookup_bdev(const char *); | 2085 | extern struct block_device *lookup_bdev(const char *); |
2091 | extern struct block_device *open_bdev_exclusive(const char *, fmode_t, void *); | 2086 | extern struct block_device *open_bdev_exclusive(const char *, fmode_t, void *); |
2092 | extern void close_bdev_exclusive(struct block_device *, fmode_t); | ||
2093 | extern void blkdev_show(struct seq_file *,off_t); | 2087 | extern void blkdev_show(struct seq_file *,off_t); |
2094 | 2088 | ||
2095 | #else | 2089 | #else |