Commit 69886e67 authored by Richard Weinberger's avatar Richard Weinberger

hostfs: hostfs_file_open: Switch to data locking model

Instead of serializing hostfs_file_open() we can use
a per inode mutex to protect ->mode.
Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
parent bc465aa9
...@@ -24,6 +24,7 @@ struct hostfs_inode_info { ...@@ -24,6 +24,7 @@ struct hostfs_inode_info {
int fd; int fd;
fmode_t mode; fmode_t mode;
struct inode vfs_inode; struct inode vfs_inode;
struct mutex open_mutex;
}; };
static inline struct hostfs_inode_info *HOSTFS_I(struct inode *inode) static inline struct hostfs_inode_info *HOSTFS_I(struct inode *inode)
...@@ -225,6 +226,7 @@ static struct inode *hostfs_alloc_inode(struct super_block *sb) ...@@ -225,6 +226,7 @@ static struct inode *hostfs_alloc_inode(struct super_block *sb)
hi->fd = -1; hi->fd = -1;
hi->mode = 0; hi->mode = 0;
inode_init_once(&hi->vfs_inode); inode_init_once(&hi->vfs_inode);
mutex_init(&hi->open_mutex);
return &hi->vfs_inode; return &hi->vfs_inode;
} }
...@@ -295,7 +297,6 @@ static int hostfs_readdir(struct file *file, struct dir_context *ctx) ...@@ -295,7 +297,6 @@ static int hostfs_readdir(struct file *file, struct dir_context *ctx)
static int hostfs_file_open(struct inode *ino, struct file *file) static int hostfs_file_open(struct inode *ino, struct file *file)
{ {
static DEFINE_MUTEX(open_mutex);
char *name; char *name;
fmode_t mode = 0; fmode_t mode = 0;
int err; int err;
...@@ -324,15 +325,15 @@ static int hostfs_file_open(struct inode *ino, struct file *file) ...@@ -324,15 +325,15 @@ static int hostfs_file_open(struct inode *ino, struct file *file)
if (fd < 0) if (fd < 0)
return fd; return fd;
mutex_lock(&open_mutex); mutex_lock(&HOSTFS_I(ino)->open_mutex);
/* somebody else had handled it first? */ /* somebody else had handled it first? */
if ((mode & HOSTFS_I(ino)->mode) == mode) { if ((mode & HOSTFS_I(ino)->mode) == mode) {
mutex_unlock(&open_mutex); mutex_unlock(&HOSTFS_I(ino)->open_mutex);
return 0; return 0;
} }
if ((mode | HOSTFS_I(ino)->mode) != mode) { if ((mode | HOSTFS_I(ino)->mode) != mode) {
mode |= HOSTFS_I(ino)->mode; mode |= HOSTFS_I(ino)->mode;
mutex_unlock(&open_mutex); mutex_unlock(&HOSTFS_I(ino)->open_mutex);
close_file(&fd); close_file(&fd);
goto retry; goto retry;
} }
...@@ -342,12 +343,12 @@ static int hostfs_file_open(struct inode *ino, struct file *file) ...@@ -342,12 +343,12 @@ static int hostfs_file_open(struct inode *ino, struct file *file)
err = replace_file(fd, HOSTFS_I(ino)->fd); err = replace_file(fd, HOSTFS_I(ino)->fd);
close_file(&fd); close_file(&fd);
if (err < 0) { if (err < 0) {
mutex_unlock(&open_mutex); mutex_unlock(&HOSTFS_I(ino)->open_mutex);
return err; return err;
} }
} }
HOSTFS_I(ino)->mode = mode; HOSTFS_I(ino)->mode = mode;
mutex_unlock(&open_mutex); mutex_unlock(&HOSTFS_I(ino)->open_mutex);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment