From patchwork Thu Feb 2 17:34:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 9552703 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C3F0060405 for ; Thu, 2 Feb 2017 17:36:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B93E528437 for ; Thu, 2 Feb 2017 17:36:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AE22728456; Thu, 2 Feb 2017 17:36:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 39EAA28437 for ; Thu, 2 Feb 2017 17:36:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752361AbdBBRgI (ORCPT ); Thu, 2 Feb 2017 12:36:08 -0500 Received: from mx2.suse.de ([195.135.220.15]:45491 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752338AbdBBRgF (ORCPT ); Thu, 2 Feb 2017 12:36:05 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 050CBADBB; Thu, 2 Feb 2017 17:36:01 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 4D20F1E105C; Thu, 2 Feb 2017 18:35:54 +0100 (CET) From: Jan Kara To: Cc: Christoph Hellwig , linux-block@vger.kernel.org, Jan Kara Subject: [PATCH 03/24] block: Unregister bdi on last reference drop Date: Thu, 2 Feb 2017 18:34:01 +0100 Message-Id: <20170202173422.3240-4-jack@suse.cz> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20170202173422.3240-1-jack@suse.cz> References: <20170202173422.3240-1-jack@suse.cz> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Most users will want to unregister bdi when dropping last reference to a bdi. Only a few users (like block devices) want to play more complex tricks with bdi registration and unregistration. So unregister bdi when the last reference to bdi is dropped and just make sure we don't unregister the bdi the second time if it is already unregistered. Signed-off-by: Jan Kara --- include/linux/backing-dev-defs.h | 3 ++- mm/backing-dev.c | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/include/linux/backing-dev-defs.h b/include/linux/backing-dev-defs.h index ad955817916d..2ecafc8a2d06 100644 --- a/include/linux/backing-dev-defs.h +++ b/include/linux/backing-dev-defs.h @@ -146,7 +146,8 @@ struct backing_dev_info { char *name; struct kref refcnt; /* Reference counter for the structure */ - unsigned int capabilities; /* Device capabilities */ + unsigned int registered:1; /* Is bdi registered? */ + unsigned int capabilities:31; /* Device capabilities */ unsigned int min_ratio; unsigned int max_ratio, max_prop_frac; diff --git a/mm/backing-dev.c b/mm/backing-dev.c index d59571023df7..82fee0f52d06 100644 --- a/mm/backing-dev.c +++ b/mm/backing-dev.c @@ -843,6 +843,7 @@ int bdi_register_va(struct backing_dev_info *bdi, struct device *parent, spin_lock_bh(&bdi_lock); list_add_tail_rcu(&bdi->bdi_list, &bdi_list); + bdi->registered = 1; spin_unlock_bh(&bdi_lock); trace_writeback_bdi_register(bdi); @@ -897,6 +898,14 @@ static void bdi_remove_from_list(struct backing_dev_info *bdi) void bdi_unregister(struct backing_dev_info *bdi) { + spin_lock_bh(&bdi_lock); + if (!bdi->registered) { + spin_unlock_bh(&bdi_lock); + return; + } + bdi->registered = 0; + spin_unlock_bh(&bdi_lock); + /* make sure nobody finds us on the bdi_list anymore */ bdi_remove_from_list(bdi); wb_shutdown(&bdi->wb); @@ -925,6 +934,7 @@ static void release_bdi(struct kref *ref) struct backing_dev_info *bdi = container_of(ref, struct backing_dev_info, refcnt); + bdi_unregister(bdi); bdi_exit(bdi); kfree(bdi); }