Skip to content

Commit 97f044f

Browse files
author
Miklos Szeredi
committed
fuse: don't increment nlink in link()
The fuse_iget() call in create_new_entry() already updated the inode with all the new attributes and incremented the attribute version. Incrementing the nlink will result in the wrong count. This wasn't noticed because the attributes were invalidated right after this. Updating ctime is still needed for the writeback case when the ctime is not refreshed. Signed-off-by: Miklos Szeredi <[email protected]>
1 parent cefd1b8 commit 97f044f

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

fs/fuse/dir.c

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -745,16 +745,21 @@ void fuse_flush_time_update(struct inode *inode)
745745
mapping_set_error(inode->i_mapping, err);
746746
}
747747

748-
void fuse_update_ctime(struct inode *inode)
748+
static void fuse_update_ctime_in_cache(struct inode *inode)
749749
{
750-
fuse_invalidate_attr(inode);
751750
if (!IS_NOCMTIME(inode)) {
752751
inode->i_ctime = current_time(inode);
753752
mark_inode_dirty_sync(inode);
754753
fuse_flush_time_update(inode);
755754
}
756755
}
757756

757+
void fuse_update_ctime(struct inode *inode)
758+
{
759+
fuse_invalidate_attr(inode);
760+
fuse_update_ctime_in_cache(inode);
761+
}
762+
758763
static void fuse_entry_unlinked(struct dentry *entry)
759764
{
760765
struct inode *inode = d_inode(entry);
@@ -925,24 +930,11 @@ static int fuse_link(struct dentry *entry, struct inode *newdir,
925930
args.in_args[1].size = newent->d_name.len + 1;
926931
args.in_args[1].value = newent->d_name.name;
927932
err = create_new_entry(fm, &args, newdir, newent, inode->i_mode);
928-
/* Contrary to "normal" filesystems it can happen that link
929-
makes two "logical" inodes point to the same "physical"
930-
inode. We invalidate the attributes of the old one, so it
931-
will reflect changes in the backing inode (link count,
932-
etc.)
933-
*/
934-
if (!err) {
935-
struct fuse_inode *fi = get_fuse_inode(inode);
936-
937-
spin_lock(&fi->lock);
938-
fi->attr_version = atomic64_inc_return(&fm->fc->attr_version);
939-
if (likely(inode->i_nlink < UINT_MAX))
940-
inc_nlink(inode);
941-
spin_unlock(&fi->lock);
942-
fuse_update_ctime(inode);
943-
} else if (err == -EINTR) {
933+
if (!err)
934+
fuse_update_ctime_in_cache(inode);
935+
else if (err == -EINTR)
944936
fuse_invalidate_attr(inode);
945-
}
937+
946938
return err;
947939
}
948940

0 commit comments

Comments
 (0)