Skip to content

Commit 0c9d708

Browse files
amir73ilMiklos Szeredi
authored andcommitted
fuse: factor out helper fuse_truncate_update_attr()
fuse_finish_open() is called from fuse_open_common() and from fuse_create_open(). In the latter case, the O_TRUNC flag is always cleared in finish_open()m before calling into fuse_finish_open(). Move the bits that update attribute cache post O_TRUNC open into a helper and call this helper from fuse_open_common() directly. Signed-off-by: Amir Goldstein <[email protected]> Signed-off-by: Miklos Szeredi <[email protected]>
1 parent 9bbb671 commit 0c9d708

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

fs/fuse/file.c

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -205,30 +205,31 @@ void fuse_finish_open(struct inode *inode, struct file *file)
205205
else if (ff->open_flags & FOPEN_NONSEEKABLE)
206206
nonseekable_open(inode, file);
207207

208-
if (fc->atomic_o_trunc && (file->f_flags & O_TRUNC)) {
209-
struct fuse_inode *fi = get_fuse_inode(inode);
210-
211-
spin_lock(&fi->lock);
212-
fi->attr_version = atomic64_inc_return(&fc->attr_version);
213-
i_size_write(inode, 0);
214-
spin_unlock(&fi->lock);
215-
file_update_time(file);
216-
fuse_invalidate_attr_mask(inode, FUSE_STATX_MODSIZE);
217-
}
218208
if ((file->f_mode & FMODE_WRITE) && fc->writeback_cache)
219209
fuse_link_write_file(file);
220210
}
221211

212+
static void fuse_truncate_update_attr(struct inode *inode, struct file *file)
213+
{
214+
struct fuse_conn *fc = get_fuse_conn(inode);
215+
struct fuse_inode *fi = get_fuse_inode(inode);
216+
217+
spin_lock(&fi->lock);
218+
fi->attr_version = atomic64_inc_return(&fc->attr_version);
219+
i_size_write(inode, 0);
220+
spin_unlock(&fi->lock);
221+
file_update_time(file);
222+
fuse_invalidate_attr_mask(inode, FUSE_STATX_MODSIZE);
223+
}
224+
222225
int fuse_open_common(struct inode *inode, struct file *file, bool isdir)
223226
{
224227
struct fuse_mount *fm = get_fuse_mount(inode);
225228
struct fuse_conn *fc = fm->fc;
226229
int err;
227-
bool is_wb_truncate = (file->f_flags & O_TRUNC) &&
228-
fc->atomic_o_trunc &&
229-
fc->writeback_cache;
230-
bool dax_truncate = (file->f_flags & O_TRUNC) &&
231-
fc->atomic_o_trunc && FUSE_IS_DAX(inode);
230+
bool is_truncate = (file->f_flags & O_TRUNC) && fc->atomic_o_trunc;
231+
bool is_wb_truncate = is_truncate && fc->writeback_cache;
232+
bool dax_truncate = is_truncate && FUSE_IS_DAX(inode);
232233

233234
if (fuse_is_bad(inode))
234235
return -EIO;
@@ -251,15 +252,18 @@ int fuse_open_common(struct inode *inode, struct file *file, bool isdir)
251252
fuse_set_nowrite(inode);
252253

253254
err = fuse_do_open(fm, get_node_id(inode), file, isdir);
254-
if (!err)
255+
if (!err) {
255256
fuse_finish_open(inode, file);
257+
if (is_truncate)
258+
fuse_truncate_update_attr(inode, file);
259+
}
256260

257261
if (is_wb_truncate || dax_truncate)
258262
fuse_release_nowrite(inode);
259263
if (!err) {
260264
struct fuse_file *ff = file->private_data;
261265

262-
if (fc->atomic_o_trunc && (file->f_flags & O_TRUNC))
266+
if (is_truncate)
263267
truncate_pagecache(inode, 0);
264268
else if (!(ff->open_flags & FOPEN_KEEP_CACHE))
265269
invalidate_inode_pages2(inode->i_mapping);

0 commit comments

Comments
 (0)