Skip to content

Commit cf576c5

Browse files
eryugeyMiklos Szeredi
authored andcommitted
fuse: invalidate inode attr in writeback cache mode
Under writeback mode, inode->i_blocks is not updated, making utils du read st.blocks as 0. For example, when using virtiofs (cache=always & nondax mode) with writeback_cache enabled, writing a new file and check its disk usage with du, du reports 0 usage. # uname -r 5.6.0-rc6+ # mount -t virtiofs virtiofs /mnt/virtiofs # rm -f /mnt/virtiofs/testfile # create new file and do extend write # xfs_io -fc "pwrite 0 4k" /mnt/virtiofs/testfile wrote 4096/4096 bytes at offset 0 4 KiB, 1 ops; 0.0001 sec (28.103 MiB/sec and 7194.2446 ops/sec) # du -k /mnt/virtiofs/testfile 0 <==== disk usage is 0 # stat -c %s,%b /mnt/virtiofs/testfile 4096,0 <==== i_size is correct, but st_blocks is 0 Fix it by invalidating attr in fuse_flush(), so we get up-to-date attr from server on next getattr. Signed-off-by: Eryu Guan <[email protected]> Signed-off-by: Miklos Szeredi <[email protected]>
1 parent 75d8925 commit cf576c5

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

fs/fuse/file.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,8 +445,9 @@ static int fuse_flush(struct file *file, fl_owner_t id)
445445
if (is_bad_inode(inode))
446446
return -EIO;
447447

448+
err = 0;
448449
if (fc->no_flush)
449-
return 0;
450+
goto inval_attr_out;
450451

451452
err = write_inode_now(inode, 1);
452453
if (err)
@@ -475,6 +476,14 @@ static int fuse_flush(struct file *file, fl_owner_t id)
475476
fc->no_flush = 1;
476477
err = 0;
477478
}
479+
480+
inval_attr_out:
481+
/*
482+
* In memory i_blocks is not maintained by fuse, if writeback cache is
483+
* enabled, i_blocks from cached attr may not be accurate.
484+
*/
485+
if (!err && fc->writeback_cache)
486+
fuse_invalidate_attr(inode);
478487
return err;
479488
}
480489

0 commit comments

Comments
 (0)