Commit d2c487f1 authored by Amir Goldstein's avatar Amir Goldstein Committed by Miklos Szeredi

fuse: prepare for failing open response

In preparation for inode io modes, a server open response could fail due to
conflicting inode io modes.

Allow returning an error from fuse_finish_open() and handle the error in
the callers.

fuse_finish_open() is used as the callback of finish_open(), so that
FMODE_OPENED will not be set if fuse_finish_open() fails.
Signed-off-by: default avatarAmir Goldstein <amir73il@gmail.com>
Signed-off-by: default avatarMiklos Szeredi <mszeredi@redhat.com>
parent 7de64d52
...@@ -692,13 +692,15 @@ static int fuse_create_open(struct inode *dir, struct dentry *entry, ...@@ -692,13 +692,15 @@ static int fuse_create_open(struct inode *dir, struct dentry *entry,
d_instantiate(entry, inode); d_instantiate(entry, inode);
fuse_change_entry_timeout(entry, &outentry); fuse_change_entry_timeout(entry, &outentry);
fuse_dir_changed(dir); fuse_dir_changed(dir);
err = finish_open(file, entry, generic_file_open); err = generic_file_open(inode, file);
if (!err) {
file->private_data = ff;
err = finish_open(file, entry, fuse_finish_open);
}
if (err) { if (err) {
fi = get_fuse_inode(inode); fi = get_fuse_inode(inode);
fuse_sync_release(fi, ff, flags); fuse_sync_release(fi, ff, flags);
} else { } else {
file->private_data = ff;
fuse_finish_open(inode, file);
if (fm->fc->atomic_o_trunc && trunc) if (fm->fc->atomic_o_trunc && trunc)
truncate_pagecache(inode, 0); truncate_pagecache(inode, 0);
else if (!(ff->open_flags & FOPEN_KEEP_CACHE)) else if (!(ff->open_flags & FOPEN_KEEP_CACHE))
......
...@@ -200,7 +200,7 @@ static void fuse_link_write_file(struct file *file) ...@@ -200,7 +200,7 @@ static void fuse_link_write_file(struct file *file)
spin_unlock(&fi->lock); spin_unlock(&fi->lock);
} }
void fuse_finish_open(struct inode *inode, struct file *file) int fuse_finish_open(struct inode *inode, struct file *file)
{ {
struct fuse_file *ff = file->private_data; struct fuse_file *ff = file->private_data;
struct fuse_conn *fc = get_fuse_conn(inode); struct fuse_conn *fc = get_fuse_conn(inode);
...@@ -212,6 +212,8 @@ void fuse_finish_open(struct inode *inode, struct file *file) ...@@ -212,6 +212,8 @@ void fuse_finish_open(struct inode *inode, struct file *file)
if ((file->f_mode & FMODE_WRITE) && fc->writeback_cache) if ((file->f_mode & FMODE_WRITE) && fc->writeback_cache)
fuse_link_write_file(file); fuse_link_write_file(file);
return 0;
} }
static void fuse_truncate_update_attr(struct inode *inode, struct file *file) static void fuse_truncate_update_attr(struct inode *inode, struct file *file)
...@@ -230,7 +232,9 @@ static void fuse_truncate_update_attr(struct inode *inode, struct file *file) ...@@ -230,7 +232,9 @@ static void fuse_truncate_update_attr(struct inode *inode, struct file *file)
static int fuse_open(struct inode *inode, struct file *file) static int fuse_open(struct inode *inode, struct file *file)
{ {
struct fuse_mount *fm = get_fuse_mount(inode); struct fuse_mount *fm = get_fuse_mount(inode);
struct fuse_inode *fi = get_fuse_inode(inode);
struct fuse_conn *fc = fm->fc; struct fuse_conn *fc = fm->fc;
struct fuse_file *ff;
int err; int err;
bool is_truncate = (file->f_flags & O_TRUNC) && fc->atomic_o_trunc; bool is_truncate = (file->f_flags & O_TRUNC) && fc->atomic_o_trunc;
bool is_wb_truncate = is_truncate && fc->writeback_cache; bool is_wb_truncate = is_truncate && fc->writeback_cache;
...@@ -258,16 +262,17 @@ static int fuse_open(struct inode *inode, struct file *file) ...@@ -258,16 +262,17 @@ static int fuse_open(struct inode *inode, struct file *file)
err = fuse_do_open(fm, get_node_id(inode), file, false); err = fuse_do_open(fm, get_node_id(inode), file, false);
if (!err) { if (!err) {
fuse_finish_open(inode, file); ff = file->private_data;
if (is_truncate) err = fuse_finish_open(inode, file);
if (err)
fuse_sync_release(fi, ff, file->f_flags);
else if (is_truncate)
fuse_truncate_update_attr(inode, file); fuse_truncate_update_attr(inode, file);
} }
if (is_wb_truncate || dax_truncate) if (is_wb_truncate || dax_truncate)
fuse_release_nowrite(inode); fuse_release_nowrite(inode);
if (!err) { if (!err) {
struct fuse_file *ff = file->private_data;
if (is_truncate) if (is_truncate)
truncate_pagecache(inode, 0); truncate_pagecache(inode, 0);
else if (!(ff->open_flags & FOPEN_KEEP_CACHE)) else if (!(ff->open_flags & FOPEN_KEEP_CACHE))
......
...@@ -1033,7 +1033,7 @@ void fuse_read_args_fill(struct fuse_io_args *ia, struct file *file, loff_t pos, ...@@ -1033,7 +1033,7 @@ void fuse_read_args_fill(struct fuse_io_args *ia, struct file *file, loff_t pos,
struct fuse_file *fuse_file_alloc(struct fuse_mount *fm, bool release); struct fuse_file *fuse_file_alloc(struct fuse_mount *fm, bool release);
void fuse_file_free(struct fuse_file *ff); void fuse_file_free(struct fuse_file *ff);
void fuse_finish_open(struct inode *inode, struct file *file); int fuse_finish_open(struct inode *inode, struct file *file);
void fuse_sync_release(struct fuse_inode *fi, struct fuse_file *ff, void fuse_sync_release(struct fuse_inode *fi, struct fuse_file *ff,
unsigned int flags); unsigned int flags);
......
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