From patchwork Tue Feb 19 00:09:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NeilBrown X-Patchwork-Id: 10819043 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5AF516C2 for ; Tue, 19 Feb 2019 00:12:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 44DCB2BDE4 for ; Tue, 19 Feb 2019 00:12:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 397FC2BDEC; Tue, 19 Feb 2019 00:12:10 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from pdx1-mailman02.dreamhost.com (pdx1-mailman02.dreamhost.com [64.90.62.194]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D17812BDE4 for ; Tue, 19 Feb 2019 00:12:09 +0000 (UTC) Received: from pdx1-mailman02.dreamhost.com (localhost [IPv6:::1]) by pdx1-mailman02.dreamhost.com (Postfix) with ESMTP id 971DA21FE1F; Mon, 18 Feb 2019 16:12:09 -0800 (PST) X-Original-To: lustre-devel@lists.lustre.org Delivered-To: lustre-devel-lustre.org@pdx1-mailman02.dreamhost.com Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) by pdx1-mailman02.dreamhost.com (Postfix) with ESMTP id D0BF021FB0D for ; Mon, 18 Feb 2019 16:12:07 -0800 (PST) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 1179DAF57; Tue, 19 Feb 2019 00:12:07 +0000 (UTC) From: NeilBrown To: James Simmons , Andreas Dilger , Oleg Drokin Date: Tue, 19 Feb 2019 11:09:05 +1100 Message-ID: <155053494516.24125.10480743535229018309.stgit@noble.brown> In-Reply-To: <155053473693.24125.6976971762921761309.stgit@noble.brown> References: <155053473693.24125.6976971762921761309.stgit@noble.brown> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Subject: [lustre-devel] [PATCH 06/37] lustre: obd_type: discard obd_types linked list. X-BeenThere: lustre-devel@lists.lustre.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "For discussing Lustre software development." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lustre Development List Errors-To: lustre-devel-bounces@lists.lustre.org Sender: "lustre-devel" X-Virus-Scanned: ClamAV using ClamSMTP As all obd_types are kobjects in the lustre_kset kset, they are linked together in that kset and don't need any extra linkage. As kset_find_obj() returns a counted reference, we need to put that reference when done. Signed-off-by: NeilBrown --- drivers/staging/lustre/lustre/include/obd.h | 1 - drivers/staging/lustre/lustre/obdclass/genops.c | 41 +++++++++++------------ 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h index 3aa9cc889949..50f33f400075 100644 --- a/drivers/staging/lustre/lustre/include/obd.h +++ b/drivers/staging/lustre/lustre/include/obd.h @@ -99,7 +99,6 @@ struct obd_info { }; struct obd_type { - struct list_head typ_chain; struct obd_ops *typ_dt_ops; struct md_ops *typ_md_ops; struct dentry *typ_debugfs_entry; diff --git a/drivers/staging/lustre/lustre/obdclass/genops.c b/drivers/staging/lustre/lustre/obdclass/genops.c index 32581f1a92ac..775e4fa4f6a8 100644 --- a/drivers/staging/lustre/lustre/obdclass/genops.c +++ b/drivers/staging/lustre/lustre/obdclass/genops.c @@ -42,8 +42,6 @@ #include #include -static DEFINE_SPINLOCK(obd_types_lock); -static LIST_HEAD(obd_types); DEFINE_RWLOCK(obd_dev_lock); static struct obd_device *obd_devs[MAX_OBD_DEVICES]; @@ -88,22 +86,19 @@ static void obd_device_free(struct obd_device *obd) static struct obd_type *class_search_type(const char *name) { - struct obd_type *type; + struct kobject *kobj = kset_find_obj(lustre_kset, name); + + if (kobj) + return container_of(kobj, struct obd_type, typ_kobj); - spin_lock(&obd_types_lock); - list_for_each_entry(type, &obd_types, typ_chain) { - if (strcmp(type->typ_name, name) == 0) { - spin_unlock(&obd_types_lock); - return type; - } - } - spin_unlock(&obd_types_lock); return NULL; } static struct obd_type *class_get_type(const char *name) { - struct obd_type *type = class_search_type(name); + struct obd_type *type; + + type = class_search_type(name); if (!type) { const char *modname = name; @@ -121,6 +116,11 @@ static struct obd_type *class_get_type(const char *name) type->typ_refcnt++; try_module_get(type->typ_dt_ops->owner); spin_unlock(&type->obd_type_lock); + /* class_search_type() returned a counted reference, + * but we don't need that count any more as + * we have one through typ_refcnt. + */ + kobject_put(&type->typ_kobj); } return type; } @@ -143,10 +143,6 @@ static void class_sysfs_release(struct kobject *kobj) if (type->typ_lu) lu_device_type_fini(type->typ_lu); - spin_lock(&obd_types_lock); - list_del(&type->typ_chain); - spin_unlock(&obd_types_lock); - kfree(type->typ_md_ops); kfree(type->typ_dt_ops); kfree(type); @@ -169,8 +165,10 @@ int class_register_type(struct obd_ops *dt_ops, struct md_ops *md_ops, /* sanity check */ LASSERT(strnlen(name, CLASS_MAX_NAME) < CLASS_MAX_NAME); - if (class_search_type(name)) { + type = class_search_type(name); + if (type) { CDEBUG(D_IOCTL, "Type %s already registered\n", name); + kobject_put(&type->typ_kobj); return -EEXIST; } @@ -181,7 +179,6 @@ int class_register_type(struct obd_ops *dt_ops, struct md_ops *md_ops, type->typ_kobj.kset = lustre_kset; kobject_init(&type->typ_kobj, &class_ktype); - INIT_LIST_HEAD(&type->typ_chain); type->typ_dt_ops = kzalloc(sizeof(*type->typ_dt_ops), GFP_NOFS); type->typ_md_ops = kzalloc(sizeof(*type->typ_md_ops), GFP_NOFS); @@ -210,10 +207,6 @@ int class_register_type(struct obd_ops *dt_ops, struct md_ops *md_ops, goto failed; } - spin_lock(&obd_types_lock); - list_add(&type->typ_chain, &obd_types); - spin_unlock(&obd_types_lock); - return 0; failed: @@ -238,9 +231,13 @@ int class_unregister_type(const char *name) /* Remove ops, but leave the name for debugging */ kfree(type->typ_dt_ops); kfree(type->typ_md_ops); + kobject_put(&type->typ_kobj); return -EBUSY; } + /* Put the ref returned by class_search_type() */ + kobject_put(&type->typ_kobj); + /* Put the final ref */ kobject_put(&type->typ_kobj); return 0;