Skip to content

Commit d347739

Browse files
author
Miklos Szeredi
committed
fuse: always invalidate attributes after writes
Extend the fuse_write_update_attr() helper to invalidate cached attributes after a write. This has already been done in all cases except in fuse_notify_store(), so this is mostly a cleanup. fuse_direct_write_iter() calls fuse_direct_IO() which already calls fuse_write_update_attr(), so don't repeat that again in the former. Signed-off-by: Miklos Szeredi <[email protected]>
1 parent 27ae449 commit d347739

File tree

4 files changed

+15
-20
lines changed

4 files changed

+15
-20
lines changed

fs/fuse/dax.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -732,11 +732,8 @@ static ssize_t fuse_dax_direct_write(struct kiocb *iocb, struct iov_iter *from)
732732
ssize_t ret;
733733

734734
ret = fuse_direct_io(&io, from, &iocb->ki_pos, FUSE_DIO_WRITE);
735-
if (ret < 0)
736-
return ret;
737735

738-
fuse_invalidate_attr_mask(inode, FUSE_STATX_MODSIZE);
739-
fuse_write_update_attr(inode, iocb->ki_pos);
736+
fuse_write_update_attr(inode, iocb->ki_pos, ret);
740737
return ret;
741738
}
742739

fs/fuse/dev.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1591,7 +1591,7 @@ static int fuse_notify_store(struct fuse_conn *fc, unsigned int size,
15911591
end = outarg.offset + outarg.size;
15921592
if (end > file_size) {
15931593
file_size = end;
1594-
fuse_write_update_attr(inode, file_size);
1594+
fuse_write_update_attr(inode, file_size, outarg.size);
15951595
}
15961596

15971597
num = outarg.size;

fs/fuse/file.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,20 +1066,22 @@ static ssize_t fuse_send_write(struct fuse_io_args *ia, loff_t pos,
10661066
return err ?: ia->write.out.size;
10671067
}
10681068

1069-
bool fuse_write_update_attr(struct inode *inode, loff_t pos)
1069+
bool fuse_write_update_attr(struct inode *inode, loff_t pos, ssize_t written)
10701070
{
10711071
struct fuse_conn *fc = get_fuse_conn(inode);
10721072
struct fuse_inode *fi = get_fuse_inode(inode);
10731073
bool ret = false;
10741074

10751075
spin_lock(&fi->lock);
10761076
fi->attr_version = atomic64_inc_return(&fc->attr_version);
1077-
if (pos > inode->i_size) {
1077+
if (written > 0 && pos > inode->i_size) {
10781078
i_size_write(inode, pos);
10791079
ret = true;
10801080
}
10811081
spin_unlock(&fi->lock);
10821082

1083+
fuse_invalidate_attr_mask(inode, FUSE_STATX_MODSIZE);
1084+
10831085
return ret;
10841086
}
10851087

@@ -1262,11 +1264,8 @@ static ssize_t fuse_perform_write(struct kiocb *iocb,
12621264
kfree(ap->pages);
12631265
} while (!err && iov_iter_count(ii));
12641266

1265-
if (res > 0)
1266-
fuse_write_update_attr(inode, pos);
1267-
1267+
fuse_write_update_attr(inode, pos, res);
12681268
clear_bit(FUSE_I_SIZE_UNSTABLE, &fi->state);
1269-
fuse_invalidate_attr_mask(inode, FUSE_STATX_MODSIZE);
12701269

12711270
return res > 0 ? res : err;
12721271
}
@@ -1554,11 +1553,9 @@ static ssize_t fuse_direct_write_iter(struct kiocb *iocb, struct iov_iter *from)
15541553
} else {
15551554
res = fuse_direct_io(&io, from, &iocb->ki_pos,
15561555
FUSE_DIO_WRITE);
1556+
fuse_write_update_attr(inode, iocb->ki_pos, res);
15571557
}
15581558
}
1559-
fuse_invalidate_attr_mask(inode, FUSE_STATX_MODSIZE);
1560-
if (res > 0)
1561-
fuse_write_update_attr(inode, iocb->ki_pos);
15621559
inode_unlock(inode);
15631560

15641561
return res;
@@ -2900,9 +2897,8 @@ fuse_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
29002897
kref_put(&io->refcnt, fuse_io_release);
29012898

29022899
if (iov_iter_rw(iter) == WRITE) {
2903-
if (ret > 0)
2904-
fuse_write_update_attr(inode, pos);
2905-
else if (ret < 0 && offset + count > i_size)
2900+
fuse_write_update_attr(inode, pos, ret);
2901+
if (ret < 0 && offset + count > i_size)
29062902
fuse_do_truncate(file);
29072903
}
29082904

@@ -2990,7 +2986,8 @@ static long fuse_file_fallocate(struct file *file, int mode, loff_t offset,
29902986

29912987
/* we could have extended the file */
29922988
if (!(mode & FALLOC_FL_KEEP_SIZE)) {
2993-
bool changed = fuse_write_update_attr(inode, offset + length);
2989+
bool changed = fuse_write_update_attr(inode, offset + length,
2990+
length);
29942991

29952992
if (changed && fm->fc->writeback_cache)
29962993
file_update_time(file);
@@ -3108,7 +3105,8 @@ static ssize_t __fuse_copy_file_range(struct file *file_in, loff_t pos_in,
31083105
ALIGN(pos_out + outarg.size, PAGE_SIZE) - 1);
31093106

31103107
if (fc->writeback_cache) {
3111-
fuse_write_update_attr(inode_out, pos_out + outarg.size);
3108+
fuse_write_update_attr(inode_out, pos_out + outarg.size,
3109+
outarg.size);
31123110
file_update_time(file_out);
31133111
}
31143112

fs/fuse/fuse_i.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1217,7 +1217,7 @@ long fuse_ioctl_common(struct file *file, unsigned int cmd,
12171217
__poll_t fuse_file_poll(struct file *file, poll_table *wait);
12181218
int fuse_dev_release(struct inode *inode, struct file *file);
12191219

1220-
bool fuse_write_update_attr(struct inode *inode, loff_t pos);
1220+
bool fuse_write_update_attr(struct inode *inode, loff_t pos, ssize_t written);
12211221

12221222
int fuse_flush_times(struct inode *inode, struct fuse_file *ff);
12231223
int fuse_write_inode(struct inode *inode, struct writeback_control *wbc);

0 commit comments

Comments
 (0)