Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/teigland/dlm
[pandora-kernel.git] / fs / dlm / lockspace.c
index 14cbf40..a1d8f1a 100644 (file)
@@ -15,7 +15,6 @@
 #include "lockspace.h"
 #include "member.h"
 #include "recoverd.h"
-#include "ast.h"
 #include "dir.h"
 #include "lowcomms.h"
 #include "config.h"
@@ -24,6 +23,7 @@
 #include "recover.h"
 #include "requestqueue.h"
 #include "user.h"
+#include "ast.h"
 
 static int                     ls_count;
 static struct mutex            ls_lock;
@@ -359,17 +359,10 @@ static int threads_start(void)
 {
        int error;
 
-       /* Thread which process lock requests for all lockspace's */
-       error = dlm_astd_start();
-       if (error) {
-               log_print("cannot start dlm_astd thread %d", error);
-               goto fail;
-       }
-
        error = dlm_scand_start();
        if (error) {
                log_print("cannot start dlm_scand thread %d", error);
-               goto astd_fail;
+               goto fail;
        }
 
        /* Thread for sending/receiving messages for all lockspace's */
@@ -383,8 +376,6 @@ static int threads_start(void)
 
  scand_fail:
        dlm_scand_stop();
- astd_fail:
-       dlm_astd_stop();
  fail:
        return error;
 }
@@ -393,7 +384,6 @@ static void threads_stop(void)
 {
        dlm_scand_stop();
        dlm_lowcomms_stop();
-       dlm_astd_stop();
 }
 
 static int new_lockspace(const char *name, int namelen, void **lockspace,
@@ -463,7 +453,7 @@ static int new_lockspace(const char *name, int namelen, void **lockspace,
        size = dlm_config.ci_rsbtbl_size;
        ls->ls_rsbtbl_size = size;
 
-       ls->ls_rsbtbl = kmalloc(sizeof(struct dlm_rsbtable) * size, GFP_NOFS);
+       ls->ls_rsbtbl = vmalloc(sizeof(struct dlm_rsbtable) * size);
        if (!ls->ls_rsbtbl)
                goto out_lsfree;
        for (i = 0; i < size; i++) {
@@ -472,22 +462,13 @@ static int new_lockspace(const char *name, int namelen, void **lockspace,
                spin_lock_init(&ls->ls_rsbtbl[i].lock);
        }
 
-       size = dlm_config.ci_lkbtbl_size;
-       ls->ls_lkbtbl_size = size;
-
-       ls->ls_lkbtbl = kmalloc(sizeof(struct dlm_lkbtable) * size, GFP_NOFS);
-       if (!ls->ls_lkbtbl)
-               goto out_rsbfree;
-       for (i = 0; i < size; i++) {
-               INIT_LIST_HEAD(&ls->ls_lkbtbl[i].list);
-               rwlock_init(&ls->ls_lkbtbl[i].lock);
-               ls->ls_lkbtbl[i].counter = 1;
-       }
+       idr_init(&ls->ls_lkbidr);
+       spin_lock_init(&ls->ls_lkbidr_spin);
 
        size = dlm_config.ci_dirtbl_size;
        ls->ls_dirtbl_size = size;
 
-       ls->ls_dirtbl = kmalloc(sizeof(struct dlm_dirtable) * size, GFP_NOFS);
+       ls->ls_dirtbl = vmalloc(sizeof(struct dlm_dirtable) * size);
        if (!ls->ls_dirtbl)
                goto out_lkbfree;
        for (i = 0; i < size; i++) {
@@ -502,6 +483,9 @@ static int new_lockspace(const char *name, int namelen, void **lockspace,
        INIT_LIST_HEAD(&ls->ls_timeout);
        mutex_init(&ls->ls_timeout_mutex);
 
+       INIT_LIST_HEAD(&ls->ls_new_rsb);
+       spin_lock_init(&ls->ls_new_rsb_spin);
+
        INIT_LIST_HEAD(&ls->ls_nodes);
        INIT_LIST_HEAD(&ls->ls_nodes_gone);
        ls->ls_num_nodes = 0;
@@ -520,6 +504,9 @@ static int new_lockspace(const char *name, int namelen, void **lockspace,
        init_completion(&ls->ls_members_done);
        ls->ls_members_result = -1;
 
+       mutex_init(&ls->ls_cb_mutex);
+       INIT_LIST_HEAD(&ls->ls_cb_delay);
+
        ls->ls_recoverd_task = NULL;
        mutex_init(&ls->ls_recoverd_active);
        spin_lock_init(&ls->ls_recover_lock);
@@ -553,18 +540,26 @@ static int new_lockspace(const char *name, int namelen, void **lockspace,
        list_add(&ls->ls_list, &lslist);
        spin_unlock(&lslist_lock);
 
+       if (flags & DLM_LSFL_FS) {
+               error = dlm_callback_start(ls);
+               if (error) {
+                       log_error(ls, "can't start dlm_callback %d", error);
+                       goto out_delist;
+               }
+       }
+
        /* needs to find ls in lslist */
        error = dlm_recoverd_start(ls);
        if (error) {
                log_error(ls, "can't start dlm_recoverd %d", error);
-               goto out_delist;
+               goto out_callback;
        }
 
        ls->ls_kobj.kset = dlm_kset;
        error = kobject_init_and_add(&ls->ls_kobj, &dlm_ktype, NULL,
                                     "%s", ls->ls_name);
        if (error)
-               goto out_stop;
+               goto out_recoverd;
        kobject_uevent(&ls->ls_kobj, KOBJ_ADD);
 
        /* let kobject handle freeing of ls if there's an error */
@@ -578,7 +573,7 @@ static int new_lockspace(const char *name, int namelen, void **lockspace,
 
        error = do_uevent(ls, 1);
        if (error)
-               goto out_stop;
+               goto out_recoverd;
 
        wait_for_completion(&ls->ls_members_done);
        error = ls->ls_members_result;
@@ -595,19 +590,20 @@ static int new_lockspace(const char *name, int namelen, void **lockspace,
        do_uevent(ls, 0);
        dlm_clear_members(ls);
        kfree(ls->ls_node_array);
- out_stop:
+ out_recoverd:
        dlm_recoverd_stop(ls);
+ out_callback:
+       dlm_callback_stop(ls);
  out_delist:
        spin_lock(&lslist_lock);
        list_del(&ls->ls_list);
        spin_unlock(&lslist_lock);
        kfree(ls->ls_recover_buf);
  out_dirfree:
-       kfree(ls->ls_dirtbl);
+       vfree(ls->ls_dirtbl);
  out_lkbfree:
-       kfree(ls->ls_lkbtbl);
- out_rsbfree:
-       kfree(ls->ls_rsbtbl);
+       idr_destroy(&ls->ls_lkbidr);
+       vfree(ls->ls_rsbtbl);
  out_lsfree:
        if (do_unreg)
                kobject_put(&ls->ls_kobj);
@@ -641,50 +637,64 @@ int dlm_new_lockspace(const char *name, int namelen, void **lockspace,
        return error;
 }
 
-/* Return 1 if the lockspace still has active remote locks,
- *        2 if the lockspace still has active local locks.
- */
-static int lockspace_busy(struct dlm_ls *ls)
-{
-       int i, lkb_found = 0;
-       struct dlm_lkb *lkb;
-
-       /* NOTE: We check the lockidtbl here rather than the resource table.
-          This is because there may be LKBs queued as ASTs that have been
-          unlinked from their RSBs and are pending deletion once the AST has
-          been delivered */
-
-       for (i = 0; i < ls->ls_lkbtbl_size; i++) {
-               read_lock(&ls->ls_lkbtbl[i].lock);
-               if (!list_empty(&ls->ls_lkbtbl[i].list)) {
-                       lkb_found = 1;
-                       list_for_each_entry(lkb, &ls->ls_lkbtbl[i].list,
-                                           lkb_idtbl_list) {
-                               if (!lkb->lkb_nodeid) {
-                                       read_unlock(&ls->ls_lkbtbl[i].lock);
-                                       return 2;
-                               }
-                       }
-               }
-               read_unlock(&ls->ls_lkbtbl[i].lock);
+static int lkb_idr_is_local(int id, void *p, void *data)
+{
+       struct dlm_lkb *lkb = p;
+
+       if (!lkb->lkb_nodeid)
+               return 1;
+       return 0;
+}
+
+static int lkb_idr_is_any(int id, void *p, void *data)
+{
+       return 1;
+}
+
+static int lkb_idr_free(int id, void *p, void *data)
+{
+       struct dlm_lkb *lkb = p;
+
+       if (lkb->lkb_lvbptr && lkb->lkb_flags & DLM_IFL_MSTCPY)
+               dlm_free_lvb(lkb->lkb_lvbptr);
+
+       dlm_free_lkb(lkb);
+       return 0;
+}
+
+/* NOTE: We check the lkbidr here rather than the resource table.
+   This is because there may be LKBs queued as ASTs that have been unlinked
+   from their RSBs and are pending deletion once the AST has been delivered */
+
+static int lockspace_busy(struct dlm_ls *ls, int force)
+{
+       int rv;
+
+       spin_lock(&ls->ls_lkbidr_spin);
+       if (force == 0) {
+               rv = idr_for_each(&ls->ls_lkbidr, lkb_idr_is_any, ls);
+       } else if (force == 1) {
+               rv = idr_for_each(&ls->ls_lkbidr, lkb_idr_is_local, ls);
+       } else {
+               rv = 0;
        }
-       return lkb_found;
+       spin_unlock(&ls->ls_lkbidr_spin);
+       return rv;
 }
 
 static int release_lockspace(struct dlm_ls *ls, int force)
 {
-       struct dlm_lkb *lkb;
        struct dlm_rsb *rsb;
        struct list_head *head;
        int i, busy, rv;
 
-       busy = lockspace_busy(ls);
+       busy = lockspace_busy(ls, force);
 
        spin_lock(&lslist_lock);
        if (ls->ls_create_count == 1) {
-               if (busy > force)
+               if (busy) {
                        rv = -EBUSY;
-               else {
+               else {
                        /* remove_lockspace takes ls off lslist */
                        ls->ls_create_count = 0;
                        rv = 0;
@@ -708,12 +718,12 @@ static int release_lockspace(struct dlm_ls *ls, int force)
 
        dlm_recoverd_stop(ls);
 
+       dlm_callback_stop(ls);
+
        remove_lockspace(ls);
 
        dlm_delete_debug_file(ls);
 
-       dlm_astd_suspend();
-
        kfree(ls->ls_recover_buf);
 
        /*
@@ -721,31 +731,15 @@ static int release_lockspace(struct dlm_ls *ls, int force)
         */
 
        dlm_dir_clear(ls);
-       kfree(ls->ls_dirtbl);
+       vfree(ls->ls_dirtbl);
 
        /*
-        * Free all lkb's on lkbtbl[] lists.
+        * Free all lkb's in idr
         */
 
-       for (i = 0; i < ls->ls_lkbtbl_size; i++) {
-               head = &ls->ls_lkbtbl[i].list;
-               while (!list_empty(head)) {
-                       lkb = list_entry(head->next, struct dlm_lkb,
-                                        lkb_idtbl_list);
-
-                       list_del(&lkb->lkb_idtbl_list);
-
-                       dlm_del_ast(lkb);
-
-                       if (lkb->lkb_lvbptr && lkb->lkb_flags & DLM_IFL_MSTCPY)
-                               dlm_free_lvb(lkb->lkb_lvbptr);
-
-                       dlm_free_lkb(lkb);
-               }
-       }
-       dlm_astd_resume();
-
-       kfree(ls->ls_lkbtbl);
+       idr_for_each(&ls->ls_lkbidr, lkb_idr_free, ls);
+       idr_remove_all(&ls->ls_lkbidr);
+       idr_destroy(&ls->ls_lkbidr);
 
        /*
         * Free all rsb's on rsbtbl[] lists
@@ -770,7 +764,14 @@ static int release_lockspace(struct dlm_ls *ls, int force)
                }
        }
 
-       kfree(ls->ls_rsbtbl);
+       vfree(ls->ls_rsbtbl);
+
+       while (!list_empty(&ls->ls_new_rsb)) {
+               rsb = list_first_entry(&ls->ls_new_rsb, struct dlm_rsb,
+                                      res_hashchain);
+               list_del(&rsb->res_hashchain);
+               dlm_free_rsb(rsb);
+       }
 
        /*
         * Free structures on any other lists