Skip to content

Commit 04d82db

Browse files
author
Miklos Szeredi
committed
fuse: move reverting attributes to fuse_change_attributes()
In case of writeback_cache fuse_fillattr() would revert the queried attributes to the cached version. Move this to fuse_change_attributes() in order to manage the writeback logic in a central helper. This will be necessary for patches that follow. Only fuse_do_getattr() -> fuse_fillattr() uses the attributes after calling fuse_change_attributes(), so this should not change behavior. Signed-off-by: Miklos Szeredi <[email protected]>
1 parent c15016b commit 04d82db

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

fs/fuse/dir.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -944,15 +944,6 @@ static void fuse_fillattr(struct inode *inode, struct fuse_attr *attr,
944944
unsigned int blkbits;
945945
struct fuse_conn *fc = get_fuse_conn(inode);
946946

947-
/* see the comment in fuse_change_attributes() */
948-
if (fc->writeback_cache && S_ISREG(inode->i_mode)) {
949-
attr->size = i_size_read(inode);
950-
attr->mtime = inode->i_mtime.tv_sec;
951-
attr->mtimensec = inode->i_mtime.tv_nsec;
952-
attr->ctime = inode->i_ctime.tv_sec;
953-
attr->ctimensec = inode->i_ctime.tv_nsec;
954-
}
955-
956947
stat->dev = inode->i_sb->s_dev;
957948
stat->ino = attr->ino;
958949
stat->mode = (inode->i_mode & S_IFMT) | (attr->mode & 07777);

fs/fuse/inode.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,19 @@ void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr,
228228
struct timespec64 old_mtime;
229229

230230
spin_lock(&fi->lock);
231+
/*
232+
* In case of writeback_cache enabled, writes update mtime, ctime and
233+
* may update i_size. In these cases trust the cached value in the
234+
* inode.
235+
*/
236+
if (is_wb) {
237+
attr->size = i_size_read(inode);
238+
attr->mtime = inode->i_mtime.tv_sec;
239+
attr->mtimensec = inode->i_mtime.tv_nsec;
240+
attr->ctime = inode->i_ctime.tv_sec;
241+
attr->ctimensec = inode->i_ctime.tv_nsec;
242+
}
243+
231244
if ((attr_version != 0 && fi->attr_version > attr_version) ||
232245
test_bit(FUSE_I_SIZE_UNSTABLE, &fi->state)) {
233246
spin_unlock(&fi->lock);

0 commit comments

Comments
 (0)