From patchwork Wed Feb 20 10:21:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hou Tao X-Patchwork-Id: 1045247 X-Patchwork-Delegate: richard@nod.at Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Lm5h1i5G"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 444D7s6bHXz9s1B for ; Wed, 20 Feb 2019 21:18:01 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Jkw8YbH7ey3S2v6xW28nyww0tBiRkXFC8awCarUkbsQ=; b=Lm5h1i5GH8j+Y0 Bnwr1zK6Pikyjp1xgqHWCMeN3s+Xbes/PEA9gJ/tCx1mDcVVykfc5KkU3IZu5q9peS7MF+lZk41bQ B07XnYFNsy+bAkZYBdFdmsm6iUKQyJFxsM+x1BJi1JaUnODgnnVL6ioRyCVQJg9Pv9H8k8IEXPVTv atY7bO1PQ/FDA8RzQIBt3Ggb8gkK+PVL4LkEUsXDj9tYAWFs7rxpsCqKSCl/NN4Wadg35K8Br4jCy UeyX3R7h7RjODwjXUuCc+bltXBWkcqvM1zryMQMyOmK2Vrk8F+JpI1oq5zLhnzeWG4rf8F7mz1L1O ehM9PrByxGsKWscBUzxw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gwOwu-00085K-Se; Wed, 20 Feb 2019 10:17:57 +0000 Received: from szxga06-in.huawei.com ([45.249.212.32] helo=huawei.com) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gwOwV-0007TP-0O for linux-mtd@lists.infradead.org; Wed, 20 Feb 2019 10:17:34 +0000 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 78F2AC69D46C9B889770; Wed, 20 Feb 2019 18:17:25 +0800 (CST) Received: from huawei.com (10.90.53.225) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.408.0; Wed, 20 Feb 2019 18:17:16 +0800 From: Hou Tao To: Subject: [PATCH 1/2] jffs2: reset pino_nlink to 0 when inode creation failed Date: Wed, 20 Feb 2019 18:21:32 +0800 Message-ID: <20190220102133.7878-2-houtao1@huawei.com> X-Mailer: git-send-email 2.16.2.dirty In-Reply-To: <20190220102133.7878-1-houtao1@huawei.com> References: <20190220102133.7878-1-houtao1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.90.53.225] X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190220_021731_612353_FD41F09B X-CRM114-Status: GOOD ( 10.84 ) X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium trust [45.249.212.32 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Weinberger , David Woodhouse , linux-kernel@vger.kernel.org, houtao1@huawei.com Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org So jffs2_do_clear_inode() could mark all flash nodes used by the inode as obsolete and GC procedure will reclaim these flash nodes, else these flash spaces will not be reclaimable forever. Cc: stable@vger.kernel.org Signed-off-by: Hou Tao --- fs/jffs2/dir.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/fs/jffs2/dir.c b/fs/jffs2/dir.c index f20cff1194bb..e02f85e516cb 100644 --- a/fs/jffs2/dir.c +++ b/fs/jffs2/dir.c @@ -156,6 +156,26 @@ static int jffs2_readdir(struct file *file, struct dir_context *ctx) /***********************************************************************/ +static void jffs2_iget_failed(struct jffs2_sb_info *c, struct inode *inode) +{ + struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode); + + /* + * Reset pino_nlink to zero, so jffs2_do_clear_inode() will mark + * all flash nodes used by the inode as obsolete and GC procedure + * will reclaim these flash nodes, else these flash spaces will be + * unreclaimable forever. + * + * Update pino_nlink under inocache_lock, because no proceses could + * get the inode due to I_NEW flag, and only GC procedure may try to + * read pino_nlink under inocache_lock. + */ + spin_lock(&c->inocache_lock); + f->inocache->pino_nlink = 0; + spin_unlock(&c->inocache_lock); + + iget_failed(inode); +} static int jffs2_create(struct inode *dir_i, struct dentry *dentry, umode_t mode, bool excl) @@ -213,7 +233,7 @@ static int jffs2_create(struct inode *dir_i, struct dentry *dentry, return 0; fail: - iget_failed(inode); + jffs2_iget_failed(c, inode); jffs2_free_raw_inode(ri); return ret; } @@ -433,7 +453,7 @@ static int jffs2_symlink (struct inode *dir_i, struct dentry *dentry, const char return 0; fail: - iget_failed(inode); + jffs2_iget_failed(c, inode); return ret; } @@ -577,7 +597,7 @@ static int jffs2_mkdir (struct inode *dir_i, struct dentry *dentry, umode_t mode return 0; fail: - iget_failed(inode); + jffs2_iget_failed(c, inode); return ret; } @@ -748,7 +768,7 @@ static int jffs2_mknod (struct inode *dir_i, struct dentry *dentry, umode_t mode return 0; fail: - iget_failed(inode); + jffs2_iget_failed(c, inode); return ret; }