From patchwork Mon Apr 13 13:35:44 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kinglong Mee X-Patchwork-Id: 6209241 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 78AB89F1AC for ; Mon, 13 Apr 2015 13:36:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 91EA020253 for ; Mon, 13 Apr 2015 13:36:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A8BDE202DD for ; Mon, 13 Apr 2015 13:35:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754099AbbDMNfz (ORCPT ); Mon, 13 Apr 2015 09:35:55 -0400 Received: from mail-pd0-f172.google.com ([209.85.192.172]:34825 "EHLO mail-pd0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754047AbbDMNfw (ORCPT ); Mon, 13 Apr 2015 09:35:52 -0400 Received: by pddn5 with SMTP id n5so107434243pdd.2; Mon, 13 Apr 2015 06:35:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=IJwPlck50vlhy8B2DkMIWE26mJT+VEwI9Ml3Y6u84kk=; b=MFPTy+uX0ewltbv6JnK/X/qt2JDuHf2MAXKdpP/U2xZj+W7TaqOE+gW3Y4dd2FDbYh 07rrFukDsBL7vHE3KB0RB7um6qeHv9GAmcfuCykmW9cDAgFIyV98QCbE1+Oxq1w3DUGm /0jeY+IpXXY6FWwcEUnOWn+XvcIyB8LIu5RXR5m3oL7Hv0zBHO0lRVz2orxitZnecfJj lNA9bW9ArRYfMAzlGtbUoaWEJQHBvZnR2nRF7a3oIb0H9C8JraIxl3Vvnp3GD3TUIr56 Z8mIBnvFUM5izZBZmBuluOE/EGEFYXQLBITIMUwiVEyxG6tnWUeTr1TgdXitiIqGySwU +01g== X-Received: by 10.70.37.239 with SMTP id b15mr26275448pdk.37.1428932151319; Mon, 13 Apr 2015 06:35:51 -0700 (PDT) Received: from [192.168.99.6] ([104.143.41.79]) by mx.google.com with ESMTPSA id t13sm4095582pdi.95.2015.04.13.06.35.48 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Apr 2015 06:35:50 -0700 (PDT) Message-ID: <552BC630.20906@gmail.com> Date: Mon, 13 Apr 2015 21:35:44 +0800 From: Kinglong Mee User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: David Howells CC: linux-fsdevel@vger.kernel.org, "linux-nfs@vger.kernel.org" Subject: [PATCH v3 1/2] FSCACHE: Increase reference of parent after registering, netfs success References: <552BBE2E.5050903@gmail.com> <552BB530.50405@gmail.com> <5527C9A0.6030502@gmail.com> <30571.1428924822@warthog.procyon.org.uk> <32264.1428929064@warthog.procyon.org.uk> <1961.1428930759@warthog.procyon.org.uk> In-Reply-To: <1961.1428930759@warthog.procyon.org.uk> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 If netfs exist, fscache should not increase the reference of parent's usage and n_children, otherwise, never be decreased. v2: thanks David's suggest, move increasing reference of parent if success use kmem_cache_free() freeing primary_index directly v3: don't move "netfs->primary_index->parent = &fscache_fsdef_index;" Signed-off-by: Kinglong Mee --- fs/fscache/netfs.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/fs/fscache/netfs.c b/fs/fscache/netfs.c index 6d941f5..458cc96 100644 --- a/fs/fscache/netfs.c +++ b/fs/fscache/netfs.c @@ -47,9 +47,6 @@ int __fscache_register_netfs(struct fscache_netfs *netfs) netfs->primary_index->netfs_data = netfs; netfs->primary_index->flags = 1 << FSCACHE_COOKIE_ENABLED; - atomic_inc(&netfs->primary_index->parent->usage); - atomic_inc(&netfs->primary_index->parent->n_children); - spin_lock_init(&netfs->primary_index->lock); INIT_HLIST_HEAD(&netfs->primary_index->backing_objects); @@ -62,6 +59,9 @@ int __fscache_register_netfs(struct fscache_netfs *netfs) goto already_registered; } + atomic_inc(&netfs->primary_index->parent->usage); + atomic_inc(&netfs->primary_index->parent->n_children); + list_add(&netfs->link, &fscache_netfs_list); ret = 0; @@ -71,8 +71,7 @@ already_registered: up_write(&fscache_addremove_sem); if (ret < 0) { - netfs->primary_index->parent = NULL; - __fscache_cookie_put(netfs->primary_index); + kmem_cache_free(fscache_cookie_jar, netfs->primary_index); netfs->primary_index = NULL; }