Skip to content

Commit

Permalink
[PATCH] propagate mode through open_bdev_excl/close_bdev_excl
Browse files Browse the repository at this point in the history
replace open_bdev_excl/close_bdev_excl with variants taking fmode_t.
superblock gets the value used to mount it stored in sb->s_mode

Signed-off-by: Al Viro <[email protected]>
  • Loading branch information
Al Viro committed Oct 21, 2008
1 parent 9a1c354 commit 30c40d2
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 24 deletions.
4 changes: 2 additions & 2 deletions drivers/mtd/devices/block2mtd.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ static void block2mtd_free_device(struct block2mtd_dev *dev)
if (dev->blkdev) {
invalidate_mapping_pages(dev->blkdev->bd_inode->i_mapping,
0, -1);
close_bdev_excl(dev->blkdev);
close_bdev_exclusive(dev->blkdev, FMODE_READ|FMODE_WRITE);
}

kfree(dev);
Expand All @@ -246,7 +246,7 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size)
return NULL;

/* Get a handle on the device */
bdev = open_bdev_excl(devname, O_RDWR, NULL);
bdev = open_bdev_exclusive(devname, FMODE_READ|FMODE_WRITE, NULL);
#ifndef MODULE
if (IS_ERR(bdev)) {

Expand Down
24 changes: 11 additions & 13 deletions fs/block_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1309,32 +1309,29 @@ struct block_device *lookup_bdev(const char *path)
EXPORT_SYMBOL(lookup_bdev);

/**
* open_bdev_excl - open a block device by name and set it up for use
* open_bdev_exclusive - open a block device by name and set it up for use
*
* @path: special file representing the block device
* @flags: %MS_RDONLY for opening read-only
* @mode: FMODE_... combination to pass be used
* @holder: owner for exclusion
*
* Open the blockdevice described by the special file at @path, claim it
* for the @holder.
*/
struct block_device *open_bdev_excl(const char *path, int flags, void *holder)
struct block_device *open_bdev_exclusive(const char *path, fmode_t mode, void *holder)
{
struct block_device *bdev;
fmode_t mode = FMODE_READ;
int error = 0;

bdev = lookup_bdev(path);
if (IS_ERR(bdev))
return bdev;

if (!(flags & MS_RDONLY))
mode |= FMODE_WRITE;
error = blkdev_get(bdev, mode, 0);
if (error)
return ERR_PTR(error);
error = -EACCES;
if (!(flags & MS_RDONLY) && bdev_read_only(bdev))
if ((mode & FMODE_WRITE) && bdev_read_only(bdev))
goto blkdev_put;
error = bd_claim(bdev, holder);
if (error)
Expand All @@ -1347,22 +1344,23 @@ struct block_device *open_bdev_excl(const char *path, int flags, void *holder)
return ERR_PTR(error);
}

EXPORT_SYMBOL(open_bdev_excl);
EXPORT_SYMBOL(open_bdev_exclusive);

/**
* close_bdev_excl - release a blockdevice openen by open_bdev_excl()
* close_bdev_exclusive - close a blockdevice opened by open_bdev_exclusive()
*
* @bdev: blockdevice to close
* @mode: mode, must match that used to open.
*
* This is the counterpart to open_bdev_excl().
* This is the counterpart to open_bdev_exclusive().
*/
void close_bdev_excl(struct block_device *bdev)
void close_bdev_exclusive(struct block_device *bdev, fmode_t mode)
{
bd_release(bdev);
blkdev_put(bdev, 0); /* move up in the next patches */
blkdev_put(bdev, mode);
}

EXPORT_SYMBOL(close_bdev_excl);
EXPORT_SYMBOL(close_bdev_exclusive);

int __invalidate_device(struct block_device *bdev)
{
Expand Down
3 changes: 2 additions & 1 deletion fs/reiserfs/journal.c
Original file line number Diff line number Diff line change
Expand Up @@ -2628,7 +2628,8 @@ static int journal_init_dev(struct super_block *super,
return 0;
}

journal->j_dev_bd = open_bdev_excl(jdev_name, 0, journal);
journal->j_dev_bd = open_bdev_exclusive(jdev_name,
FMODE_READ|FMODE_WRITE, journal);
if (IS_ERR(journal->j_dev_bd)) {
result = PTR_ERR(journal->j_dev_bd);
journal->j_dev_bd = NULL;
Expand Down
14 changes: 10 additions & 4 deletions fs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -760,9 +760,13 @@ int get_sb_bdev(struct file_system_type *fs_type,
{
struct block_device *bdev;
struct super_block *s;
fmode_t mode = FMODE_READ;
int error = 0;

bdev = open_bdev_excl(dev_name, flags, fs_type);
if (!(flags & MS_RDONLY))
mode |= FMODE_WRITE;

bdev = open_bdev_exclusive(dev_name, mode, fs_type);
if (IS_ERR(bdev))
return PTR_ERR(bdev);

Expand All @@ -785,11 +789,12 @@ int get_sb_bdev(struct file_system_type *fs_type,
goto error_bdev;
}

close_bdev_excl(bdev);
close_bdev_exclusive(bdev, mode);
} else {
char b[BDEVNAME_SIZE];

s->s_flags = flags;
s->s_mode = mode;
strlcpy(s->s_id, bdevname(bdev, b), sizeof(s->s_id));
sb_set_blocksize(s, block_size(bdev));
error = fill_super(s, data, flags & MS_SILENT ? 1 : 0);
Expand All @@ -807,7 +812,7 @@ int get_sb_bdev(struct file_system_type *fs_type,
error_s:
error = PTR_ERR(s);
error_bdev:
close_bdev_excl(bdev);
close_bdev_exclusive(bdev, mode);
error:
return error;
}
Expand All @@ -817,10 +822,11 @@ EXPORT_SYMBOL(get_sb_bdev);
void kill_block_super(struct super_block *sb)
{
struct block_device *bdev = sb->s_bdev;
fmode_t mode = sb->s_mode;

generic_shutdown_super(sb);
sync_blockdev(bdev);
close_bdev_excl(bdev);
close_bdev_exclusive(bdev, mode);
}

EXPORT_SYMBOL(kill_block_super);
Expand Down
4 changes: 2 additions & 2 deletions fs/xfs/linux-2.6/xfs_super.c
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ xfs_blkdev_get(
{
int error = 0;

*bdevp = open_bdev_excl(name, 0, mp);
*bdevp = open_bdev_exclusive(name, FMODE_READ|FMODE_WRITE, mp);
if (IS_ERR(*bdevp)) {
error = PTR_ERR(*bdevp);
printk("XFS: Invalid device [%s], error=%d\n", name, error);
Expand All @@ -603,7 +603,7 @@ xfs_blkdev_put(
struct block_device *bdev)
{
if (bdev)
close_bdev_excl(bdev);
close_bdev_exclusive(bdev, FMODE_READ|FMODE_WRITE);
}

/*
Expand Down
6 changes: 4 additions & 2 deletions include/linux/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,7 @@ struct super_block {
char s_id[32]; /* Informational name */

void *s_fs_info; /* Filesystem private info */
fmode_t s_mode;

/*
* The next field is for VFS *only*. No filesystems have any business
Expand Down Expand Up @@ -1753,9 +1754,10 @@ extern void chrdev_show(struct seq_file *,off_t);
extern const char *__bdevname(dev_t, char *buffer);
extern const char *bdevname(struct block_device *bdev, char *buffer);
extern struct block_device *lookup_bdev(const char *);
extern struct block_device *open_bdev_excl(const char *, int, void *);
extern void close_bdev_excl(struct block_device *);
extern struct block_device *open_bdev_exclusive(const char *, fmode_t, void *);
extern void close_bdev_exclusive(struct block_device *, fmode_t);
extern void blkdev_show(struct seq_file *,off_t);

#else
#define BLKDEV_MAJOR_HASH_SIZE 0
#endif
Expand Down

0 comments on commit 30c40d2

Please sign in to comment.