Whamcloud - gitweb
LU-9010 obdclass: use static initializer macros where possible 27/24827/3
authorJohn L. Hammond <john.hammond@intel.com>
Wed, 11 Jan 2017 17:03:45 +0000 (11:03 -0600)
committerOleg Drokin <oleg.drokin@intel.com>
Thu, 23 Mar 2017 01:41:21 +0000 (01:41 +0000)
In lustre/ldlm/ replace module load time initialization of several
atomics, lists, locks, mutexes, wait queues, etc with static
initialization using the kernel provided macros.

Signed-off-by: John L. Hammond <john.hammond@intel.com>
Change-Id: I5514992762b95fb23a154970abebd34fb65d9be2
Reviewed-on: https://review.whamcloud.com/24827
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Steve Guminski <stephenx.guminski@intel.com>
Reviewed-by: Dmitry Eremin <dmitry.eremin@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/include/lu_object.h
lustre/include/obd_class.h
lustre/obdclass/class_obd.c
lustre/obdclass/genops.c
lustre/obdclass/local_storage.c
lustre/obdclass/lu_object.c
lustre/obdclass/lu_ref.c
lustre/obdclass/lustre_handles.c
lustre/obdclass/lustre_peer.c
lustre/obdclass/obd_config.c
lustre/obdclass/obd_mount_server.c

index 7817af9..24a8f7a 100644 (file)
@@ -335,12 +335,6 @@ struct lu_device_type {
          * Number of existing device type instances.
          */
        atomic_t                                ldt_device_nr;
-       /**
-        * Linkage into a global list of all device types.
-        *
-        * \see lu_device_types.
-        */
-       struct list_head                        ldt_linkage;
 };
 
 /**
index 7b6edec..2dd520a 100644 (file)
 #define OBD_STATFS_FOR_MDT0    0x0004  /* The statfs is only for retrieving
                                         * information from MDT0. */
 
-/* OBD Device Declarations */
-extern struct obd_device *obd_devs[MAX_OBD_DEVICES];
-extern struct list_head obd_types;
-extern spinlock_t obd_types_lock;
 extern rwlock_t obd_dev_lock;
 
 /* OBD Operations Declarations */
@@ -121,10 +117,6 @@ struct llog_rec_hdr;
 typedef int (*llog_cb_t)(const struct lu_env *, struct llog_handle *,
                         struct llog_rec_hdr *, void *);
 
-extern atomic_t         obd_stale_export_num;
-extern struct list_head obd_stale_exports;
-extern spinlock_t       obd_stale_export_lock;
-
 struct obd_export *obd_stale_export_get(void);
 void obd_stale_export_put(struct obd_export *exp);
 void obd_stale_export_adjust(struct obd_export *exp);
@@ -148,7 +140,6 @@ int class_config_llog_handler(const struct lu_env *env,
                              struct llog_handle *handle,
                              struct llog_rec_hdr *rec, void *data);
 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg);
-int class_add_uuid(const char *uuid, __u64 nid);
 
 #define CFG_F_START     0x01   /* Set when we start updating from a log */
 #define CFG_F_MARKER    0x02   /* We are within a maker */
@@ -1703,8 +1694,6 @@ int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
 int class_add_uuid(const char *uuid, __u64 nid);
 int class_del_uuid (const char *uuid);
 int class_check_uuid(struct obd_uuid *uuid, __u64 nid);
-void class_init_uuidlist(void);
-void class_exit_uuidlist(void);
 
 /* class_obd.c */
 extern char obd_jobid_node[];
index d70d496..f644a3f 100644 (file)
 #include <lustre_ioctl.h>
 #include "llog_internal.h"
 
-struct obd_device *obd_devs[MAX_OBD_DEVICES];
-struct list_head obd_types;
-DEFINE_RWLOCK(obd_dev_lock);
-
 #ifdef CONFIG_PROC_FS
 static __u64 obd_max_alloc;
 #else
@@ -497,40 +493,34 @@ static int obd_init_checks(void)
 
 static int __init obdclass_init(void)
 {
-       int i, err;
-
-       spin_lock_init(&obd_stale_export_lock);
-       INIT_LIST_HEAD(&obd_stale_exports);
-       atomic_set(&obd_stale_export_num, 0);
+       int err;
 
        LCONSOLE_INFO("Lustre: Build Version: "LUSTRE_VERSION_STRING"\n");
 
-       spin_lock_init(&obd_types_lock);
-       obd_zombie_impexp_init();
+       err = obd_init_checks();
+       if (err == -EOVERFLOW)
+               return err;
+
 #ifdef CONFIG_PROC_FS
        obd_memory = lprocfs_alloc_stats(OBD_STATS_NUM,
                                         LPROCFS_STATS_FLAG_NONE |
                                         LPROCFS_STATS_FLAG_IRQ_SAFE);
        if (obd_memory == NULL) {
                CERROR("kmalloc of 'obd_memory' failed\n");
-               err = -ENOMEM;
-               goto cleanup_zombie_impexp;
+               return -ENOMEM;
        }
 
        lprocfs_counter_init(obd_memory, OBD_MEMORY_STAT,
                             LPROCFS_CNTR_AVGMINMAX,
                             "memused", "bytes");
 #endif
-       err = obd_init_checks();
-       if (err == -EOVERFLOW)
-               goto cleanup_zombie_impexp;
+       err = obd_zombie_impexp_init();
+       if (err)
+               goto cleanup_obd_memory;
 
-       class_init_uuidlist();
        err = class_handle_init();
        if (err)
-               goto cleanup_uuidlist;
-
-       INIT_LIST_HEAD(&obd_types);
+               goto cleanup_zombie_impexp;
 
        err = misc_register(&obd_psdev);
        if (err) {
@@ -538,10 +528,6 @@ static int __init obdclass_init(void)
                goto cleanup_class_handle;
        }
 
-       /* This struct is already zeroed for us (static global) */
-       for (i = 0; i < class_devno_max(); i++)
-               obd_devs[i] = NULL;
-
        /* Default the dirty page cache cap to 1/2 of system memory.
         * For clients with less memory, a larger fraction is needed
         * for other purposes (mostly for BGL). */
@@ -598,7 +584,7 @@ static int __init obdclass_init(void)
        if (err)
                goto cleanup_llog_info;
 
-       goto out_success;
+       return 0;
 
 cleanup_llog_info:
        llog_info_fini();
@@ -630,13 +616,14 @@ cleanup_deregister:
 cleanup_class_handle:
        class_handle_cleanup();
 
-cleanup_uuidlist:
-       class_exit_uuidlist();
-
 cleanup_zombie_impexp:
        obd_zombie_impexp_stop();
 
-out_success:
+cleanup_obd_memory:
+#ifdef CONFIG_PROC_FS
+       lprocfs_free_stats(&obd_memory);
+#endif
+
        return err;
 }
 
@@ -669,8 +656,10 @@ __u64 obd_memory_max(void)
 
 static void __exit obdclass_exit(void)
 {
+#ifdef CONFIG_PROC_FS
        __u64 memory_leaked;
        __u64 memory_max;
+#endif /* CONFIG_PROC_FS */
        ENTRY;
 
        lustre_unregister_fs();
@@ -690,20 +679,20 @@ static void __exit obdclass_exit(void)
         class_procfs_clean();
 
         class_handle_cleanup();
-        class_exit_uuidlist();
+       class_del_uuid(NULL); /* Delete all UUIDs. */
         obd_zombie_impexp_stop();
-       LASSERT(list_empty(&obd_stale_exports));
-
-        memory_leaked = obd_memory_sum();
 
-        memory_max = obd_memory_max();
+#ifdef CONFIG_PROC_FS
+       memory_leaked = obd_memory_sum();
+       memory_max = obd_memory_max();
 
-        lprocfs_free_stats(&obd_memory);
-        CDEBUG((memory_leaked) ? D_ERROR : D_INFO,
+       lprocfs_free_stats(&obd_memory);
+       CDEBUG((memory_leaked) ? D_ERROR : D_INFO,
               "obd_memory max: %llu, leaked: %llu\n",
-               memory_max, memory_leaked);
+              memory_max, memory_leaked);
+#endif /* CONFIG_PROC_FS */
 
-        EXIT;
+       EXIT;
 }
 
 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
index 9857a57..91b9b81 100644 (file)
 #include <lustre_disk.h>
 #include <lustre_kernelcomm.h>
 
-spinlock_t obd_types_lock;
+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];
 
 static struct kmem_cache *obd_device_cachep;
 struct kmem_cache *obdo_cachep;
 EXPORT_SYMBOL(obdo_cachep);
 static struct kmem_cache *import_cachep;
 
-static struct list_head obd_zombie_imports;
-static struct list_head obd_zombie_exports;
-static spinlock_t  obd_zombie_impexp_lock;
+static LIST_HEAD(obd_zombie_imports);
+static LIST_HEAD(obd_zombie_exports);
+static DEFINE_SPINLOCK(obd_zombie_impexp_lock);
 
 static void obd_zombie_impexp_notify(void);
 static void obd_zombie_export_add(struct obd_export *exp);
@@ -61,9 +64,9 @@ static void obd_zombie_import_add(struct obd_import *imp);
 static void print_export_data(struct obd_export *exp,
                               const char *status, int locks, int debug_level);
 
-struct list_head obd_stale_exports;
-spinlock_t       obd_stale_export_lock;
-atomic_t         obd_stale_export_num;
+static LIST_HEAD(obd_stale_exports);
+static DEFINE_SPINLOCK(obd_stale_export_lock);
+static atomic_t obd_stale_export_num = ATOMIC_INIT(0);
 
 int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
 EXPORT_SYMBOL(ptlrpc_put_connection_superhack);
@@ -1665,11 +1668,11 @@ void obd_zombie_impexp_cull(void)
        EXIT;
 }
 
-static struct completion       obd_zombie_start;
-static struct completion       obd_zombie_stop;
-static unsigned long           obd_zombie_flags;
-static wait_queue_head_t       obd_zombie_waitq;
-static pid_t                   obd_zombie_pid;
+static DECLARE_COMPLETION(obd_zombie_start);
+static DECLARE_COMPLETION(obd_zombie_stop);
+static unsigned long obd_zombie_flags;
+static DECLARE_WAIT_QUEUE_HEAD(obd_zombie_waitq);
+static pid_t obd_zombie_pid;
 
 enum {
        OBD_ZOMBIE_STOP         = 0x0001,
@@ -1870,15 +1873,6 @@ int obd_zombie_impexp_init(void)
 {
        struct task_struct *task;
 
-       INIT_LIST_HEAD(&obd_zombie_imports);
-
-       INIT_LIST_HEAD(&obd_zombie_exports);
-       spin_lock_init(&obd_zombie_impexp_lock);
-       init_completion(&obd_zombie_start);
-       init_completion(&obd_zombie_stop);
-       init_waitqueue_head(&obd_zombie_waitq);
-       obd_zombie_pid = 0;
-
        task = kthread_run(obd_zombie_impexp_thread, NULL, "obd_zombid");
        if (IS_ERR(task))
                RETURN(PTR_ERR(task));
@@ -1894,6 +1888,7 @@ void obd_zombie_impexp_stop(void)
        set_bit(OBD_ZOMBIE_STOP, &obd_zombie_flags);
         obd_zombie_impexp_notify();
        wait_for_completion(&obd_zombie_stop);
+       LASSERT(list_empty(&obd_stale_exports));
 }
 
 /***** Kernel-userspace comm helpers *******/
index c15624e..453bedc 100644 (file)
@@ -35,7 +35,7 @@
 #include "local_storage.h"
 
 /* all initialized local storages on this node are linked on this */
-static struct list_head ls_list_head = LIST_HEAD_INIT(ls_list_head);
+static LIST_HEAD(ls_list_head);
 static DEFINE_MUTEX(ls_list_mutex);
 
 static int ls_object_init(const struct lu_env *env, struct lu_object *o,
index b633d26..56fa109 100644 (file)
@@ -831,35 +831,20 @@ struct lu_object *lu_object_find_slice(const struct lu_env *env,
 }
 EXPORT_SYMBOL(lu_object_find_slice);
 
-/**
- * Global list of all device types.
- */
-static struct list_head lu_device_types;
-
 int lu_device_type_init(struct lu_device_type *ldt)
 {
        int result = 0;
 
        atomic_set(&ldt->ldt_device_nr, 0);
-       INIT_LIST_HEAD(&ldt->ldt_linkage);
        if (ldt->ldt_ops->ldto_init)
                result = ldt->ldt_ops->ldto_init(ldt);
 
-       if (result == 0) {
-               spin_lock(&obd_types_lock);
-               list_add(&ldt->ldt_linkage, &lu_device_types);
-               spin_unlock(&obd_types_lock);
-       }
-
        return result;
 }
 EXPORT_SYMBOL(lu_device_type_init);
 
 void lu_device_type_fini(struct lu_device_type *ldt)
 {
-       spin_lock(&obd_types_lock);
-       list_del_init(&ldt->ldt_linkage);
-       spin_unlock(&obd_types_lock);
        if (ldt->ldt_ops->ldto_fini)
                ldt->ldt_ops->ldto_fini(ldt);
 }
@@ -868,8 +853,8 @@ EXPORT_SYMBOL(lu_device_type_fini);
 /**
  * Global list of all sites on this node
  */
-static struct list_head lu_sites;
-static struct rw_semaphore lu_sites_guard;
+static LIST_HEAD(lu_sites);
+static DECLARE_RWSEM(lu_sites_guard);
 
 /**
  * Global environment used by site shrinker.
@@ -1594,7 +1579,7 @@ EXPORT_SYMBOL(lu_context_key_get);
 /**
  * List of remembered contexts. XXX document me.
  */
-static struct list_head lu_context_remembered;
+static LIST_HEAD(lu_context_remembered);
 
 /**
  * Destroy \a key in all remembered contexts. This is used to destroy key
@@ -2148,11 +2133,6 @@ int lu_global_init(void)
 
         CDEBUG(D_INFO, "Lustre LU module (%p).\n", &lu_keys);
 
-       INIT_LIST_HEAD(&lu_device_types);
-       INIT_LIST_HEAD(&lu_context_remembered);
-       INIT_LIST_HEAD(&lu_sites);
-       init_rwsem(&lu_sites_guard);
-
         result = lu_ref_global_init();
         if (result != 0)
                 return result;
index 6edaf9f..bef2903 100644 (file)
@@ -80,8 +80,8 @@ static struct lu_kmem_descr lu_ref_caches[] = {
  *
  * Protected by lu_ref_refs_guard.
  */
-static struct list_head lu_ref_refs;
-static spinlock_t lu_ref_refs_guard;
+static LIST_HEAD(lu_ref_refs);
+static DEFINE_SPINLOCK(lu_ref_refs_guard);
 static struct lu_ref lu_ref_marker = {
        .lf_guard       = __SPIN_LOCK_UNLOCKED(lu_ref_marker.lf_guard),
        .lf_list        = LIST_HEAD_INIT(lu_ref_marker.lf_list),
@@ -419,8 +419,6 @@ int lu_ref_global_init(void)
        CDEBUG(D_CONSOLE,
               "lu_ref tracking is enabled. Performance isn't.\n");
 
-       INIT_LIST_HEAD(&lu_ref_refs);
-       spin_lock_init(&lu_ref_refs_guard);
         result = lu_kmem_init(lu_ref_caches);
 
 #ifdef CONFIG_PROC_FS
index dcdc4fa..bd149dd 100644 (file)
@@ -43,7 +43,7 @@
 
 static __u64 handle_base;
 #define HANDLE_INCR 7
-static spinlock_t handle_base_lock;
+static DEFINE_SPINLOCK(handle_base_lock);
 
 static struct handle_bucket {
        spinlock_t       lock;
@@ -207,7 +207,6 @@ int class_handle_init(void)
         if (handle_hash == NULL)
                 return -ENOMEM;
 
-       spin_lock_init(&handle_base_lock);
        for (bucket = handle_hash + HANDLE_HASH_SIZE - 1; bucket >= handle_hash;
             bucket--) {
                INIT_LIST_HEAD(&bucket->head);
index 507bee2..95716e1 100644 (file)
@@ -50,20 +50,8 @@ struct uuid_nid_data {
 };
 
 /* FIXME: This should probably become more elegant than a global linked list */
-static struct list_head        g_uuid_list;
-static spinlock_t      g_uuid_lock;
-
-void class_init_uuidlist(void)
-{
-       INIT_LIST_HEAD(&g_uuid_list);
-       spin_lock_init(&g_uuid_lock);
-}
-
-void class_exit_uuidlist(void)
-{
-        /* delete all */
-        class_del_uuid(NULL);
-}
+static LIST_HEAD(g_uuid_list);
+static DEFINE_SPINLOCK(g_uuid_lock);
 
 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index)
 {
index 34c5711..1535999 100644 (file)
@@ -833,8 +833,7 @@ static int class_del_conn(struct obd_device *obd, struct lustre_cfg *lcfg)
         RETURN(rc);
 }
 
-static struct list_head lustre_profile_list =
-       LIST_HEAD_INIT(lustre_profile_list);
+static LIST_HEAD(lustre_profile_list);
 static DEFINE_SPINLOCK(lustre_profile_list_lock);
 
 struct lustre_profile *class_get_profile(const char * prof)
index 79c54cd..8cbdbbd 100644 (file)
@@ -64,8 +64,7 @@
 /*********** mount lookup *********/
 
 static DEFINE_MUTEX(lustre_mount_info_lock);
-static struct list_head server_mount_info_list =
-       LIST_HEAD_INIT(server_mount_info_list);
+static LIST_HEAD(server_mount_info_list);
 
 static struct lustre_mount_info *server_find_mount(const char *name)
 {
@@ -383,8 +382,7 @@ cleanup:
 }
 EXPORT_SYMBOL(tgt_name2lwp_name);
 
-static struct list_head lwp_register_list =
-       LIST_HEAD_INIT(lwp_register_list);
+static LIST_HEAD(lwp_register_list);
 static DEFINE_SPINLOCK(lwp_register_list_lock);
 
 static void lustre_put_lwp_item(struct lwp_register_item *lri)