These changes are the raw update to linux-4.4.6-rt14. Kernel sources
[kvmfornfv.git] / kernel / drivers / staging / lustre / lustre / ldlm / ldlm_lockd.c
index 08a91f5..ca11511 100644 (file)
@@ -58,6 +58,10 @@ MODULE_PARM_DESC(ldlm_cpts, "CPU partitions ldlm threads should run on");
 static struct mutex    ldlm_ref_mutex;
 static int ldlm_refcount;
 
+static struct kobject *ldlm_kobj;
+struct kset *ldlm_ns_kset;
+static struct kset *ldlm_svc_kset;
+
 struct ldlm_cb_async_args {
        struct ldlm_cb_set_arg *ca_set_arg;
        struct ldlm_lock       *ca_lock;
@@ -67,20 +71,6 @@ struct ldlm_cb_async_args {
 
 static struct ldlm_state *ldlm_state;
 
-inline unsigned long round_timeout(unsigned long timeout)
-{
-       return cfs_time_seconds((int)cfs_duration_sec(cfs_time_sub(timeout, 0)) + 1);
-}
-
-/* timeout for initial callback (AST) reply (bz10399) */
-static inline unsigned int ldlm_get_rq_timeout(void)
-{
-       /* Non-AT value */
-       unsigned int timeout = min(ldlm_timeout, obd_timeout / 3);
-
-       return timeout < 1 ? 1 : timeout;
-}
-
 #define ELT_STOPPED   0
 #define ELT_READY     1
 #define ELT_TERMINATE 2
@@ -121,19 +111,6 @@ struct ldlm_bl_work_item {
        int                  blwi_mem_pressure;
 };
 
-
-int ldlm_del_waiting_lock(struct ldlm_lock *lock)
-{
-       return 0;
-}
-
-int ldlm_refresh_waiting_lock(struct ldlm_lock *lock, int timeout)
-{
-       return 0;
-}
-
-
-
 /**
  * Callback handler for receiving incoming blocking ASTs.
  *
@@ -220,8 +197,8 @@ static void ldlm_handle_cp_callback(struct ptlrpc_request *req,
                                                     * variable length */
                        void *lvb_data;
 
-                       OBD_ALLOC(lvb_data, lvb_len);
-                       if (lvb_data == NULL) {
+                       lvb_data = kzalloc(lvb_len, GFP_NOFS);
+                       if (!lvb_data) {
                                LDLM_ERROR(lock, "No memory: %d.\n", lvb_len);
                                rc = -ENOMEM;
                                goto out;
@@ -448,8 +425,8 @@ static int ldlm_bl_to_thread(struct ldlm_namespace *ns,
        if (cancel_flags & LCF_ASYNC) {
                struct ldlm_bl_work_item *blwi;
 
-               OBD_ALLOC(blwi, sizeof(*blwi));
-               if (blwi == NULL)
+               blwi = kzalloc(sizeof(*blwi), GFP_NOFS);
+               if (!blwi)
                        return -ENOMEM;
                init_blwi(blwi, ns, ld, cancels, count, lock, cancel_flags);
 
@@ -466,7 +443,6 @@ static int ldlm_bl_to_thread(struct ldlm_namespace *ns,
        }
 }
 
-
 int ldlm_bl_to_thread_lock(struct ldlm_namespace *ns, struct ldlm_lock_desc *ld,
                           struct ldlm_lock *lock)
 {
@@ -718,7 +694,6 @@ static int ldlm_callback_handler(struct ptlrpc_request *req)
        return 0;
 }
 
-
 static struct ldlm_bl_work_item *ldlm_bl_get_work(struct ldlm_bl_pool *blp)
 {
        struct ldlm_bl_work_item *blwi = NULL;
@@ -849,7 +824,7 @@ static int ldlm_bl_thread_main(void *arg)
                        memory_pressure_clr();
 
                if (blwi->blwi_flags & LCF_ASYNC)
-                       OBD_FREE(blwi, sizeof(*blwi));
+                       kfree(blwi);
                else
                        complete(&blwi->blwi_comp);
        }
@@ -860,7 +835,6 @@ static int ldlm_bl_thread_main(void *arg)
        return 0;
 }
 
-
 static int ldlm_setup(void);
 static int ldlm_cleanup(void);
 
@@ -897,110 +871,42 @@ void ldlm_put_ref(void)
 }
 EXPORT_SYMBOL(ldlm_put_ref);
 
-/*
- * Export handle<->lock hash operations.
- */
-static unsigned
-ldlm_export_lock_hash(struct cfs_hash *hs, const void *key, unsigned mask)
-{
-       return cfs_hash_u64_hash(((struct lustre_handle *)key)->cookie, mask);
-}
+extern unsigned int ldlm_cancel_unused_locks_before_replay;
 
-static void *
-ldlm_export_lock_key(struct hlist_node *hnode)
+static ssize_t cancel_unused_locks_before_replay_show(struct kobject *kobj,
+                                                     struct attribute *attr,
+                                                     char *buf)
 {
-       struct ldlm_lock *lock;
-
-       lock = hlist_entry(hnode, struct ldlm_lock, l_exp_hash);
-       return &lock->l_remote_handle;
+       return sprintf(buf, "%d\n", ldlm_cancel_unused_locks_before_replay);
 }
 
-static void
-ldlm_export_lock_keycpy(struct hlist_node *hnode, void *key)
-{
-       struct ldlm_lock     *lock;
-
-       lock = hlist_entry(hnode, struct ldlm_lock, l_exp_hash);
-       lock->l_remote_handle = *(struct lustre_handle *)key;
-}
-
-static int
-ldlm_export_lock_keycmp(const void *key, struct hlist_node *hnode)
-{
-       return lustre_handle_equal(ldlm_export_lock_key(hnode), key);
-}
-
-static void *
-ldlm_export_lock_object(struct hlist_node *hnode)
-{
-       return hlist_entry(hnode, struct ldlm_lock, l_exp_hash);
-}
-
-static void
-ldlm_export_lock_get(struct cfs_hash *hs, struct hlist_node *hnode)
-{
-       struct ldlm_lock *lock;
-
-       lock = hlist_entry(hnode, struct ldlm_lock, l_exp_hash);
-       LDLM_LOCK_GET(lock);
-}
-
-static void
-ldlm_export_lock_put(struct cfs_hash *hs, struct hlist_node *hnode)
-{
-       struct ldlm_lock *lock;
-
-       lock = hlist_entry(hnode, struct ldlm_lock, l_exp_hash);
-       LDLM_LOCK_RELEASE(lock);
-}
-
-static cfs_hash_ops_t ldlm_export_lock_ops = {
-       .hs_hash        = ldlm_export_lock_hash,
-       .hs_key  = ldlm_export_lock_key,
-       .hs_keycmp      = ldlm_export_lock_keycmp,
-       .hs_keycpy      = ldlm_export_lock_keycpy,
-       .hs_object      = ldlm_export_lock_object,
-       .hs_get  = ldlm_export_lock_get,
-       .hs_put  = ldlm_export_lock_put,
-       .hs_put_locked  = ldlm_export_lock_put,
-};
-
-int ldlm_init_export(struct obd_export *exp)
+static ssize_t cancel_unused_locks_before_replay_store(struct kobject *kobj,
+                                                      struct attribute *attr,
+                                                      const char *buffer,
+                                                      size_t count)
 {
        int rc;
+       unsigned long val;
 
-       exp->exp_lock_hash =
-               cfs_hash_create(obd_uuid2str(&exp->exp_client_uuid),
-                               HASH_EXP_LOCK_CUR_BITS,
-                               HASH_EXP_LOCK_MAX_BITS,
-                               HASH_EXP_LOCK_BKT_BITS, 0,
-                               CFS_HASH_MIN_THETA, CFS_HASH_MAX_THETA,
-                               &ldlm_export_lock_ops,
-                               CFS_HASH_DEFAULT | CFS_HASH_REHASH_KEY |
-                               CFS_HASH_NBLK_CHANGE);
-
-       if (!exp->exp_lock_hash)
-               return -ENOMEM;
-
-       rc = ldlm_init_flock_export(exp);
+       rc = kstrtoul(buffer, 10, &val);
        if (rc)
-               goto err;
+               return rc;
 
-       return 0;
-err:
-       ldlm_destroy_export(exp);
-       return rc;
+       ldlm_cancel_unused_locks_before_replay = val;
+
+       return count;
 }
-EXPORT_SYMBOL(ldlm_init_export);
+LUSTRE_RW_ATTR(cancel_unused_locks_before_replay);
 
-void ldlm_destroy_export(struct obd_export *exp)
-{
-       cfs_hash_putref(exp->exp_lock_hash);
-       exp->exp_lock_hash = NULL;
+/* These are for root of /sys/fs/lustre/ldlm */
+static struct attribute *ldlm_attrs[] = {
+       &lustre_attr_cancel_unused_locks_before_replay.attr,
+       NULL,
+};
 
-       ldlm_destroy_flock_export(exp);
-}
-EXPORT_SYMBOL(ldlm_destroy_export);
+static struct attribute_group ldlm_attr_group = {
+       .attrs = ldlm_attrs,
+};
 
 static int ldlm_setup(void)
 {
@@ -1012,11 +918,33 @@ static int ldlm_setup(void)
        if (ldlm_state != NULL)
                return -EALREADY;
 
-       OBD_ALLOC(ldlm_state, sizeof(*ldlm_state));
-       if (ldlm_state == NULL)
+       ldlm_state = kzalloc(sizeof(*ldlm_state), GFP_NOFS);
+       if (!ldlm_state)
                return -ENOMEM;
 
-       rc = ldlm_proc_setup();
+       ldlm_kobj = kobject_create_and_add("ldlm", lustre_kobj);
+       if (!ldlm_kobj) {
+               rc = -ENOMEM;
+               goto out;
+       }
+
+       rc = sysfs_create_group(ldlm_kobj, &ldlm_attr_group);
+       if (rc)
+               goto out;
+
+       ldlm_ns_kset = kset_create_and_add("namespaces", NULL, ldlm_kobj);
+       if (!ldlm_ns_kset) {
+               rc = -ENOMEM;
+               goto out;
+       }
+
+       ldlm_svc_kset = kset_create_and_add("services", NULL, ldlm_kobj);
+       if (!ldlm_svc_kset) {
+               rc = -ENOMEM;
+               goto out;
+       }
+
+       rc = ldlm_debugfs_setup();
        if (rc != 0)
                goto out;
 
@@ -1050,7 +978,8 @@ static int ldlm_setup(void)
                },
        };
        ldlm_state->ldlm_cb_service =
-                       ptlrpc_register_service(&conf, ldlm_svc_proc_dir);
+                       ptlrpc_register_service(&conf, ldlm_svc_kset,
+                                               ldlm_svc_debugfs_dir);
        if (IS_ERR(ldlm_state->ldlm_cb_service)) {
                CERROR("failed to start service\n");
                rc = PTR_ERR(ldlm_state->ldlm_cb_service);
@@ -1058,9 +987,8 @@ static int ldlm_setup(void)
                goto out;
        }
 
-
-       OBD_ALLOC(blp, sizeof(*blp));
-       if (blp == NULL) {
+       blp = kzalloc(sizeof(*blp), GFP_NOFS);
+       if (!blp) {
                rc = -ENOMEM;
                goto out;
        }
@@ -1088,7 +1016,6 @@ static int ldlm_setup(void)
                        goto out;
        }
 
-
        rc = ldlm_pools_init();
        if (rc) {
                CERROR("Failed to initialize LDLM pools: %d\n", rc);
@@ -1129,16 +1056,22 @@ static int ldlm_cleanup(void)
                        wait_for_completion(&blp->blp_comp);
                }
 
-               OBD_FREE(blp, sizeof(*blp));
+               kfree(blp);
        }
 
        if (ldlm_state->ldlm_cb_service != NULL)
                ptlrpc_unregister_service(ldlm_state->ldlm_cb_service);
 
-       ldlm_proc_cleanup();
+       if (ldlm_ns_kset)
+               kset_unregister(ldlm_ns_kset);
+       if (ldlm_svc_kset)
+               kset_unregister(ldlm_svc_kset);
+       if (ldlm_kobj)
+               kobject_put(ldlm_kobj);
 
+       ldlm_debugfs_cleanup();
 
-       OBD_FREE(ldlm_state, sizeof(*ldlm_state));
+       kfree(ldlm_state);
        ldlm_state = NULL;
 
        return 0;