From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.5 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_PASS,USER_AGENT_MUTT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5A05C282C0 for ; Wed, 23 Jan 2019 13:51:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B6DBB2184B for ; Wed, 23 Jan 2019 13:51:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726143AbfAWNvH (ORCPT ); Wed, 23 Jan 2019 08:51:07 -0500 Received: from nautica.notk.org ([91.121.71.147]:50400 "EHLO nautica.notk.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726127AbfAWNvH (ORCPT ); Wed, 23 Jan 2019 08:51:07 -0500 Received: by nautica.notk.org (Postfix, from userid 1001) id 502FBC009; Wed, 23 Jan 2019 14:51:04 +0100 (CET) Date: Wed, 23 Jan 2019 14:50:49 +0100 From: Dominique Martinet To: Hou Tao 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() Message-ID: <20190123135049.GA23963@nautica> References: <20190118111716.60013-1-houtao1@huawei.com> <20190123022830.GB32614@nautica> <4edb8165-d6a0-b355-2b9d-13d0d88664db@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <4edb8165-d6a0-b355-2b9d-13d0d88664db@huawei.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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