Skip to content

Commit fa5eee5

Browse files
author
Miklos Szeredi
committed
fuse: selective attribute invalidation
Only invalidate attributes that the operation might have changed. Introduce two constants for common combinations of changed attributes: FUSE_STATX_MODIFY: file contents are modified but not size FUSE_STATX_MODSIZE: size and/or file contents modified Signed-off-by: Miklos Szeredi <[email protected]>
1 parent 97f044f commit fa5eee5

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

fs/fuse/dax.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ static ssize_t fuse_dax_direct_write(struct kiocb *iocb, struct iov_iter *from)
735735
if (ret < 0)
736736
return ret;
737737

738-
fuse_invalidate_attr(inode);
738+
fuse_invalidate_attr_mask(inode, FUSE_STATX_MODSIZE);
739739
fuse_write_update_size(inode, iocb->ki_pos);
740740
return ret;
741741
}

fs/fuse/dir.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ u64 entry_attr_timeout(struct fuse_entry_out *o)
116116
return time_to_jiffies(o->attr_valid, o->attr_valid_nsec);
117117
}
118118

119-
static void fuse_invalidate_attr_mask(struct inode *inode, u32 mask)
119+
void fuse_invalidate_attr_mask(struct inode *inode, u32 mask)
120120
{
121121
set_mask_bits(&get_fuse_inode(inode)->inval_mask, 0, mask);
122122
}
@@ -756,7 +756,7 @@ static void fuse_update_ctime_in_cache(struct inode *inode)
756756

757757
void fuse_update_ctime(struct inode *inode)
758758
{
759-
fuse_invalidate_attr(inode);
759+
fuse_invalidate_attr_mask(inode, STATX_CTIME);
760760
fuse_update_ctime_in_cache(inode);
761761
}
762762

fs/fuse/file.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ void fuse_finish_open(struct inode *inode, struct file *file)
211211
i_size_write(inode, 0);
212212
spin_unlock(&fi->lock);
213213
truncate_pagecache(inode, 0);
214-
fuse_invalidate_attr(inode);
214+
fuse_invalidate_attr_mask(inode, FUSE_STATX_MODSIZE);
215215
if (fc->writeback_cache)
216216
file_update_time(file);
217217
} else if (!(ff->open_flags & FOPEN_KEEP_CACHE)) {
@@ -515,7 +515,7 @@ static int fuse_flush(struct file *file, fl_owner_t id)
515515
* enabled, i_blocks from cached attr may not be accurate.
516516
*/
517517
if (!err && fm->fc->writeback_cache)
518-
fuse_invalidate_attr(inode);
518+
fuse_invalidate_attr_mask(inode, STATX_BLOCKS);
519519
return err;
520520
}
521521

@@ -1266,7 +1266,7 @@ static ssize_t fuse_perform_write(struct kiocb *iocb,
12661266
fuse_write_update_size(inode, pos);
12671267

12681268
clear_bit(FUSE_I_SIZE_UNSTABLE, &fi->state);
1269-
fuse_invalidate_attr(inode);
1269+
fuse_invalidate_attr_mask(inode, FUSE_STATX_MODSIZE);
12701270

12711271
return res > 0 ? res : err;
12721272
}
@@ -1556,7 +1556,7 @@ static ssize_t fuse_direct_write_iter(struct kiocb *iocb, struct iov_iter *from)
15561556
FUSE_DIO_WRITE);
15571557
}
15581558
}
1559-
fuse_invalidate_attr(inode);
1559+
fuse_invalidate_attr_mask(inode, FUSE_STATX_MODSIZE);
15601560
if (res > 0)
15611561
fuse_write_update_size(inode, iocb->ki_pos);
15621562
inode_unlock(inode);
@@ -1769,7 +1769,7 @@ static void fuse_writepage_end(struct fuse_mount *fm, struct fuse_args *args,
17691769
* is enabled, we trust local ctime/mtime.
17701770
*/
17711771
if (!fc->writeback_cache)
1772-
fuse_invalidate_attr(inode);
1772+
fuse_invalidate_attr_mask(inode, FUSE_STATX_MODIFY);
17731773
spin_lock(&fi->lock);
17741774
rb_erase(&wpa->writepages_entry, &fi->writepages);
17751775
while (wpa->next) {
@@ -2875,7 +2875,7 @@ fuse_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
28752875

28762876
if (iov_iter_rw(iter) == WRITE) {
28772877
ret = fuse_direct_io(io, iter, &pos, FUSE_DIO_WRITE);
2878-
fuse_invalidate_attr(inode);
2878+
fuse_invalidate_attr_mask(inode, FUSE_STATX_MODSIZE);
28792879
} else {
28802880
ret = __fuse_direct_read(io, iter, &pos);
28812881
}
@@ -2996,7 +2996,7 @@ static long fuse_file_fallocate(struct file *file, int mode, loff_t offset,
29962996
if (mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_ZERO_RANGE))
29972997
truncate_pagecache_range(inode, offset, offset + length - 1);
29982998

2999-
fuse_invalidate_attr(inode);
2999+
fuse_invalidate_attr_mask(inode, FUSE_STATX_MODSIZE);
30003000

30013001
out:
30023002
if (!(mode & FALLOC_FL_KEEP_SIZE))
@@ -3109,7 +3109,7 @@ static ssize_t __fuse_copy_file_range(struct file *file_in, loff_t pos_in,
31093109
file_update_time(file_out);
31103110
}
31113111

3112-
fuse_invalidate_attr(inode_out);
3112+
fuse_invalidate_attr_mask(inode_out, FUSE_STATX_MODSIZE);
31133113

31143114
err = outarg.size;
31153115
out:

fs/fuse/fuse_i.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,15 @@ void fuse_wait_aborted(struct fuse_conn *fc);
10651065
/**
10661066
* Invalidate inode attributes
10671067
*/
1068+
1069+
/* Attributes possibly changed on data modification */
1070+
#define FUSE_STATX_MODIFY (STATX_MTIME | STATX_CTIME | STATX_BLOCKS)
1071+
1072+
/* Attributes possibly changed on data and/or size modification */
1073+
#define FUSE_STATX_MODSIZE (FUSE_STATX_MODIFY | STATX_SIZE)
1074+
10681075
void fuse_invalidate_attr(struct inode *inode);
1076+
void fuse_invalidate_attr_mask(struct inode *inode, u32 mask);
10691077

10701078
void fuse_invalidate_entry_cache(struct dentry *entry);
10711079

0 commit comments

Comments
 (0)