From: Dominique Martinet <asmadeus@codewreck.org>
To: Hou Tao <houtao1@huawei.com>
Cc: v9fs-developer@lists.sourceforge.net, lucho@ionkov.net,
ericvh@gmail.com, linux-fsdevel@vger.kernel.org,
xingaopeng@huawei.com
Subject: Re: [PATCH v2] 9p: use inode->i_lock to protect i_size_write()
Date: Wed, 23 Jan 2019 14:50:49 +0100 [thread overview]
Message-ID: <20190123135049.GA23963@nautica> (raw)
In-Reply-To: <4edb8165-d6a0-b355-2b9d-13d0d88664db@huawei.com>
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
>
> 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 ?
(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...?)
> > 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.
--
Dominique
next prev parent reply other threads:[~2019-01-23 13:51 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-18 11:17 [PATCH v2] 9p: use inode->i_lock to protect i_size_write() Hou Tao
2019-01-22 14:05 ` Hou Tao
2019-01-23 2:28 ` Dominique Martinet
2019-01-23 13:40 ` Hou Tao
2019-01-23 13:50 ` Dominique Martinet [this message]
2019-01-24 3:21 ` Hou Tao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190123135049.GA23963@nautica \
--to=asmadeus@codewreck.org \
--cc=ericvh@gmail.com \
--cc=houtao1@huawei.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=lucho@ionkov.net \
--cc=v9fs-developer@lists.sourceforge.net \
--cc=xingaopeng@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).