Hi, On 2019/1/23 21:50, Dominique Martinet wrote: > Hou Tao wrote on Wed, Jan 23, 2019: >>> write_end() has a comment that i_size cannot change under it because it >>> has the i_mutex, but it's obviously not sufficient given the stat2inode >>> code does not have it, so it needs to do the same dance as write_iter. >> >> OK, will do that in v3 After checking the code, i think v9fs_write_begin() truly doesn't need i_lock. Because it is used for LOOSE or FSCACHE cache mode and under these two modes the i_size will not updated at all (neither in v9fs_refresh_inode() nor v9fs_vfs_getattr()). And for v9fs_file_write_iter(), the i_lock is needed. >> >> How about adding a helper as shown in the following lines ? >> >> static inline void v9fs_i_size_write(struct inode *inode, loff_t i_size) >> { >> spin_lock(&inode->i_lock); >> i_size_write(inode, i_size); >> spin_unlock(&inode->i_lock); >> } > > Sure. I'm actually surprise no other part of the kernel has such helper, > cifs seems to be using that pattern a lot too. > Actually, looking a bit deeper fs/stack.c has this code: > /* > * If CONFIG_SMP or CONFIG_PREEMPT on 32-bit, it's vital for > * fsstack_copy_inode_size() to hold some lock around > * i_size_write(), otherwise i_size_read() may spin forever (see > * include/linux/fs.h). We don't necessarily hold i_mutex when this > * is called, so take i_lock for that case. > * > * And if CONFIG_LBDAF (on 32-bit), continue our effort to keep the > * two halves of i_blocks in sync despite SMP or PREEMPT: use i_lock > * for that case too, and do both at once by combining the tests. > * > * There is none of this locking overhead in the 64-bit case. > */ > if (sizeof(i_size) > sizeof(long) || sizeof(i_blocks) > sizeof(long)) > spin_lock(&dst->i_lock); > i_size_write(dst, i_size); > dst->i_blocks = i_blocks; > if (sizeof(i_size) > sizeof(long) || sizeof(i_blocks) > sizeof(long)) > spin_unlock(&dst->i_lock); > > It might make sense to do the same in our little helper ? OK. And there will be no performance loss in 64-bit case. > > (it looks like i_blocks has the same problem? speaking of which we > probably do not want to update i_blocks either in the KEEP_SIZE > case...?) > Yes, i_blocks may be corrupted under 32-bit case, and maybe it's appropriate to fix it in a separated patch. >>> As a nitpick I don't really like foo() vs foo_flags() as >>> foo-that-takes-extra-flags. >>> There are a few such examples in the kernel already but I think it does >>> not really convery information; it's better to have the base function >>> take flags and just use it, or if you want wrappers then just never >>> expose the flags but make a static _v9fs_stat2inode take flags, >>> v9fs_stat2inode behave as the old one and a new >>> v9fs_stat2inode_keepisize for the update with cache. >>> I'd personally go with the former are there only are four call sites. >> >> I agree with you. I will add a new flags parameter to v9fs_stat2inode() and use >> it directly instead of creating inline wrappers around it. > > Thanks. >