From patchwork Mon Oct 12 08:01:14 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zheng Liu X-Patchwork-Id: 7372661 Return-Path: X-Original-To: patchwork-v9fs-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id BF262BEEA4 for ; Mon, 12 Oct 2015 07:43:16 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DB110208BA for ; Mon, 12 Oct 2015 07:43:15 +0000 (UTC) Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D3AA020711 for ; Mon, 12 Oct 2015 07:43:13 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=sfs-ml-1.v29.ch3.sourceforge.com) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1ZlXlH-0003yW-6e; Mon, 12 Oct 2015 07:43:11 +0000 Received: from sog-mx-1.v43.ch3.sourceforge.com ([172.29.43.191] helo=mx.sourceforge.net) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1ZlXlG-0003yR-20 for v9fs-developer@lists.sourceforge.net; Mon, 12 Oct 2015 07:43:10 +0000 Received-SPF: pass (sog-mx-1.v43.ch3.sourceforge.com: domain of gmail.com designates 209.85.220.42 as permitted sender) client-ip=209.85.220.42; envelope-from=gnehzuil.liu@gmail.com; helo=mail-pa0-f42.google.com; Received: from mail-pa0-f42.google.com ([209.85.220.42]) by sog-mx-1.v43.ch3.sourceforge.com with esmtps (TLSv1:RC4-SHA:128) (Exim 4.76) id 1ZlXlE-0002K6-RV for v9fs-developer@lists.sourceforge.net; Mon, 12 Oct 2015 07:43:10 +0000 Received: by pabve7 with SMTP id ve7so89236871pab.2 for ; Mon, 12 Oct 2015 00:43:03 -0700 (PDT) X-Received: by 10.66.253.99 with SMTP id zz3mr8916632pac.38.1444635783161; Mon, 12 Oct 2015 00:43:03 -0700 (PDT) Received: from alpha.hz.ali.com ([202.55.20.10]) by smtp.gmail.com with ESMTPSA id uc1sm16614168pab.20.2015.10.12.00.43.01 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Oct 2015 00:43:02 -0700 (PDT) From: Zheng Liu X-Google-Original-From: Zheng Liu To: linux-unionfs@vger.kernel.org, v9fs-developer@lists.sourceforge.net Date: Mon, 12 Oct 2015 16:01:14 +0800 Message-Id: <1444636874-16886-1-git-send-email-wenqing.lz@taobao.com> X-Mailer: git-send-email 2.4.0.rc3.3.g6eb1401 X-Spam-Score: -1.6 (-) X-Headers-End: 1ZlXlE-0002K6-RV Cc: Zheng Liu , Miklos Szeredi Subject: [V9fs-developer] [RFC][PATCH] ovl: count subdirs to get the correct link count X-BeenThere: v9fs-developer@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: v9fs-developer-bounces@lists.sourceforge.net X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,RCVD_IN_DNSWL_HI,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Zheng Liu This patch makes overlayfs count subdirs to get the correct link count because 9pfs needs this. Otherwise, we will get a warning message from inc_nlink() because inode->i_nlink == 0 and inode->i_state w/o I_LINKABLE flag in a virtualization environment. The warning message looks like as below. ------------[ cut here ]------------ WARNING: CPU: 0 PID: 27343 at ../fs/inode.c:330 inc_nlink+0x32/0x50() Modules linked in: CPU: 0 PID: 27343 Comm: mkdir Tainted: G W 4.1.6+ #1 ffffffff81540a0e ffff88046b103da8 ffffffff8120d849 ffff88046b103db8 ffffffff8120d897 ffff88046b103df8 ffffffff81044bbd ffff88046b2a0403 ffff88046b936d68 0000000000000000 ffff88046b936d68 ffff88046b2a9300 Call Trace: [] __dump_stack+0x19/0x20 [] dump_stack+0x47/0x60 [] warn_slowpath_common+0xad/0xe0 [] warn_slowpath_null+0x1a/0x20 [] inc_nlink+0x32/0x50 [] v9fs_vfs_mkdir_dotl+0x269/0x2b0 [] vfs_mkdir+0x89/0xd0 [] SyS_mkdirat+0x82/0xd0 [] SyS_mkdir+0x19/0x20 [] system_call_fastpath+0x12/0x6a ---[ end trace dd0930847ec4e6d2 ]--- The root cause is that overlayfs doesn't count subdirs and it reports a wrong link count. From the output of stat(1) we can seen that the 'Links' of a directory is 1, but at least it should be 2. When creating a directory in 9pfs, the parent directory's inode->i_nlink is 0 and a WARN_ON will be triggered. This warning can be reproduced by the following steps. [In host os] 1. build a ROOTFS for booting up a vm using 9pfs 2. mount -t overlay -olowerdir=${lower},upperdir=${upper},workdir={work} none ${ROOTFS}/mnt 3. run a vm using 9pfs e.g. http://www.linux-kvm.org/page/9p_virtio [In guest os] 4. cd /mnt 5. mkdir 1 6. rm -rf 1; mkdir 1 Cc: Miklos Szeredi Signed-off-by: Zheng Liu --- fs/overlayfs/dir.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/fs/overlayfs/dir.c b/fs/overlayfs/dir.c index 692ceda..fbeb841 100644 --- a/fs/overlayfs/dir.c +++ b/fs/overlayfs/dir.c @@ -147,14 +147,6 @@ static int ovl_dir_getattr(struct vfsmount *mnt, struct dentry *dentry, stat->dev = dentry->d_sb->s_dev; stat->ino = dentry->d_inode->i_ino; - /* - * It's probably not worth it to count subdirs to get the - * correct link count. nlink=1 seems to pacify 'find' and - * other utilities. - */ - if (OVL_TYPE_MERGE(type)) - stat->nlink = 1; - return 0; }