Skip to content

Commit efb9fa9

Browse files
Maxim PatlasovMiklos Szeredi
authored andcommitted
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>
1 parent 439ee5f commit efb9fa9

3 files changed

Lines changed: 32 additions & 10 deletions

File tree

‎fs/fuse/dir.c‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,10 +1562,9 @@ void fuse_release_nowrite(struct inode *inode)
15621562
* vmtruncate() doesn't allow for this case, so do the rlimit checking
15631563
* and the actual truncation by hand.
15641564
*/
1565-
static int fuse_do_setattr(struct dentry *entry, struct iattr *attr,
1566-
struct file *file)
1565+
int fuse_do_setattr(struct inode *inode, struct iattr *attr,
1566+
struct file *file)
15671567
{
1568-
struct inode *inode = entry->d_inode;
15691568
struct fuse_conn *fc = get_fuse_conn(inode);
15701569
struct fuse_req *req;
15711570
struct fuse_setattr_in inarg;
@@ -1574,9 +1573,6 @@ static int fuse_do_setattr(struct dentry *entry, struct iattr *attr,
15741573
loff_t oldsize;
15751574
int err;
15761575

1577-
if (!fuse_allow_current_process(fc))
1578-
return -EACCES;
1579-
15801576
if (!(fc->flags & FUSE_DEFAULT_PERMISSIONS))
15811577
attr->ia_valid |= ATTR_FORCE;
15821578

@@ -1671,10 +1667,15 @@ static int fuse_do_setattr(struct dentry *entry, struct iattr *attr,
16711667

16721668
static int fuse_setattr(struct dentry *entry, struct iattr *attr)
16731669
{
1670+
struct inode *inode = entry->d_inode;
1671+
1672+
if (!fuse_allow_current_process(get_fuse_conn(inode)))
1673+
return -EACCES;
1674+
16741675
if (attr->ia_valid & ATTR_FILE)
1675-
return fuse_do_setattr(entry, attr, attr->ia_file);
1676+
return fuse_do_setattr(inode, attr, attr->ia_file);
16761677
else
1677-
return fuse_do_setattr(entry, attr, NULL);
1678+
return fuse_do_setattr(inode, attr, NULL);
16781679
}
16791680

16801681
static int fuse_getattr(struct vfsmount *mnt, struct dentry *entry,

‎fs/fuse/file.c‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2352,6 +2352,20 @@ int fuse_notify_poll_wakeup(struct fuse_conn *fc,
23522352
return 0;
23532353
}
23542354

2355+
static void fuse_do_truncate(struct file *file)
2356+
{
2357+
struct inode *inode = file->f_mapping->host;
2358+
struct iattr attr;
2359+
2360+
attr.ia_valid = ATTR_SIZE;
2361+
attr.ia_size = i_size_read(inode);
2362+
2363+
attr.ia_file = file;
2364+
attr.ia_valid |= ATTR_FILE;
2365+
2366+
fuse_do_setattr(inode, &attr, file);
2367+
}
2368+
23552369
static ssize_t
23562370
fuse_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov,
23572371
loff_t offset, unsigned long nr_segs)
@@ -2419,8 +2433,12 @@ fuse_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov,
24192433
kfree(io);
24202434
}
24212435

2422-
if (rw == WRITE && ret > 0)
2423-
fuse_write_update_size(inode, pos);
2436+
if (rw == WRITE) {
2437+
if (ret > 0)
2438+
fuse_write_update_size(inode, pos);
2439+
else if (ret < 0 && offset + count > i_size)
2440+
fuse_do_truncate(file);
2441+
}
24242442

24252443
return ret;
24262444
}

‎fs/fuse/fuse_i.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,4 +863,7 @@ int fuse_dev_release(struct inode *inode, struct file *file);
863863

864864
void fuse_write_update_size(struct inode *inode, loff_t pos);
865865

866+
int fuse_do_setattr(struct inode *inode, struct iattr *attr,
867+
struct file *file);
868+
866869
#endif /* _FS_FUSE_I_H */

0 commit comments

Comments
 (0)