mirror of https://gitee.com/openkylin/linux.git
fuse: truncate file if async dio failed
The patch improves error handling in fuse_direct_IO(): if we successfully submitted several fuse requests on behalf of synchronous direct write extending file and some of them failed, let's try to do our best to clean-up. Changed in v2: reuse fuse_do_setattr(). Thanks to Brian for suggestion. Signed-off-by: Maxim Patlasov <mpatlasov@parallels.com> Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
This commit is contained in:
parent
439ee5f0c5
commit
efb9fa9e91
|
@ -1562,10 +1562,9 @@ void fuse_release_nowrite(struct inode *inode)
|
||||||
* vmtruncate() doesn't allow for this case, so do the rlimit checking
|
* vmtruncate() doesn't allow for this case, so do the rlimit checking
|
||||||
* and the actual truncation by hand.
|
* and the actual truncation by hand.
|
||||||
*/
|
*/
|
||||||
static int fuse_do_setattr(struct dentry *entry, struct iattr *attr,
|
int fuse_do_setattr(struct inode *inode, struct iattr *attr,
|
||||||
struct file *file)
|
struct file *file)
|
||||||
{
|
{
|
||||||
struct inode *inode = entry->d_inode;
|
|
||||||
struct fuse_conn *fc = get_fuse_conn(inode);
|
struct fuse_conn *fc = get_fuse_conn(inode);
|
||||||
struct fuse_req *req;
|
struct fuse_req *req;
|
||||||
struct fuse_setattr_in inarg;
|
struct fuse_setattr_in inarg;
|
||||||
|
@ -1574,9 +1573,6 @@ static int fuse_do_setattr(struct dentry *entry, struct iattr *attr,
|
||||||
loff_t oldsize;
|
loff_t oldsize;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (!fuse_allow_current_process(fc))
|
|
||||||
return -EACCES;
|
|
||||||
|
|
||||||
if (!(fc->flags & FUSE_DEFAULT_PERMISSIONS))
|
if (!(fc->flags & FUSE_DEFAULT_PERMISSIONS))
|
||||||
attr->ia_valid |= ATTR_FORCE;
|
attr->ia_valid |= ATTR_FORCE;
|
||||||
|
|
||||||
|
@ -1671,10 +1667,15 @@ static int fuse_do_setattr(struct dentry *entry, struct iattr *attr,
|
||||||
|
|
||||||
static int fuse_setattr(struct dentry *entry, struct iattr *attr)
|
static int fuse_setattr(struct dentry *entry, struct iattr *attr)
|
||||||
{
|
{
|
||||||
|
struct inode *inode = entry->d_inode;
|
||||||
|
|
||||||
|
if (!fuse_allow_current_process(get_fuse_conn(inode)))
|
||||||
|
return -EACCES;
|
||||||
|
|
||||||
if (attr->ia_valid & ATTR_FILE)
|
if (attr->ia_valid & ATTR_FILE)
|
||||||
return fuse_do_setattr(entry, attr, attr->ia_file);
|
return fuse_do_setattr(inode, attr, attr->ia_file);
|
||||||
else
|
else
|
||||||
return fuse_do_setattr(entry, attr, NULL);
|
return fuse_do_setattr(inode, attr, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int fuse_getattr(struct vfsmount *mnt, struct dentry *entry,
|
static int fuse_getattr(struct vfsmount *mnt, struct dentry *entry,
|
||||||
|
|
|
@ -2352,6 +2352,20 @@ int fuse_notify_poll_wakeup(struct fuse_conn *fc,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void fuse_do_truncate(struct file *file)
|
||||||
|
{
|
||||||
|
struct inode *inode = file->f_mapping->host;
|
||||||
|
struct iattr attr;
|
||||||
|
|
||||||
|
attr.ia_valid = ATTR_SIZE;
|
||||||
|
attr.ia_size = i_size_read(inode);
|
||||||
|
|
||||||
|
attr.ia_file = file;
|
||||||
|
attr.ia_valid |= ATTR_FILE;
|
||||||
|
|
||||||
|
fuse_do_setattr(inode, &attr, file);
|
||||||
|
}
|
||||||
|
|
||||||
static ssize_t
|
static ssize_t
|
||||||
fuse_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov,
|
fuse_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov,
|
||||||
loff_t offset, unsigned long nr_segs)
|
loff_t offset, unsigned long nr_segs)
|
||||||
|
@ -2419,8 +2433,12 @@ fuse_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov,
|
||||||
kfree(io);
|
kfree(io);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rw == WRITE && ret > 0)
|
if (rw == WRITE) {
|
||||||
|
if (ret > 0)
|
||||||
fuse_write_update_size(inode, pos);
|
fuse_write_update_size(inode, pos);
|
||||||
|
else if (ret < 0 && offset + count > i_size)
|
||||||
|
fuse_do_truncate(file);
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -863,4 +863,7 @@ int fuse_dev_release(struct inode *inode, struct file *file);
|
||||||
|
|
||||||
void fuse_write_update_size(struct inode *inode, loff_t pos);
|
void fuse_write_update_size(struct inode *inode, loff_t pos);
|
||||||
|
|
||||||
|
int fuse_do_setattr(struct inode *inode, struct iattr *attr,
|
||||||
|
struct file *file);
|
||||||
|
|
||||||
#endif /* _FS_FUSE_I_H */
|
#endif /* _FS_FUSE_I_H */
|
||||||
|
|
Loading…
Reference in New Issue