Received: by 2002:ac0:a679:0:0:0:0:0 with SMTP id p54csp404340imp; Wed, 20 Feb 2019 02:19:21 -0800 (PST) X-Google-Smtp-Source: AHgI3IaQVj0F0MCOzt1doj6eZEvu483vJKWR2hP8seSh4kpjcoEvMUS3U3hvpkx6X9Z636/RF5hU X-Received: by 2002:a17:902:9a02:: with SMTP id v2mr32789942plp.201.1550657961035; Wed, 20 Feb 2019 02:19:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550657961; cv=none; d=google.com; s=arc-20160816; b=JMEbAmcFaLIqOXCzHM8B/NIZvd93aIUJgLp5bRaUSQtssfuOZX8AFwxQhMVFgJBW6b aAE41IrEKr7hYRPHvTaHXCRNmVrT8oy/n2nqHaySTpVCBs904rr+xVEO3L0XjMMmL1E7 xsDF/m07ViHC7tcgnulgteeCQ4nyS2HyDl6Z3h+y5Ne7kOxiKW0FI3bvPEPntYkY2ulx Lkz7qcQHoZBAE2LP3gLk75JTyGyeFwaLfKtKOHAHxRI4gVgZhMhpgf3iCCHxB40+vp9q ZMw0ttJZ1ipZYH+GgVoXjfCis4A0P2q2EbwLFfecgTQZlhZ86JyUBmSkwfeh/Jdt015+ UgtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=GlbJ3FEEM9J930uD95WoPLNtCy9udsNB7NjdLX16byc=; b=kDZJeIOcyA4D6mrFQ3nC2E4L9X7/IvFaZROc58oyRCbqTg+VsuUrdJojx4hZjOvQD0 hYt/SX0w9SsGagK1/PBwzYnOQgB0OJ+bOlsO78lHE9yHrwYmbd9F6zmWW4W8g13IBMfT 7xSJQ6Jij+cDc/4c9nl97bJDhmmm5wuTpGuhnJ/6Hlo8g3Id7bABRBwrw77dAFdS5afd 8pVP6gxl3Ifzq+m9xHM97lXu8aven1yli6uNM1RaUOo53usV8JOcHk2RkIcqmrr+Rx+K Ri0OxMG1zbRQH5m8Cl6A0PnBIp/hHztHLbjoMvXjrGPsy0bnsCIzmvshmcm5ubqjP7Zv X4nA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d65si18592341pfc.201.2019.02.20.02.19.06; Wed, 20 Feb 2019 02:19:21 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727315AbfBTKR1 (ORCPT + 99 others); Wed, 20 Feb 2019 05:17:27 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:41180 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726000AbfBTKR1 (ORCPT ); Wed, 20 Feb 2019 05:17:27 -0500 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: CC: David Woodhouse , Richard Weinberger , , 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 Content-Type: text/plain X-Originating-IP: [10.90.53.225] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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; } -- 2.16.2.dirty