]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - fs/dlm/lockspace.c
[ARM] 4139/1: AACI record support
[linux-2.6-omap-h63xx.git] / fs / dlm / lockspace.c
index 9ed4b70348fb68886b6bca833119fbabc2b27673..59012b089e8d68ba77444a8ef0fd82f8743f5ca6 100644 (file)
@@ -22,6 +22,7 @@
 #include "memory.h"
 #include "lock.h"
 #include "recover.h"
+#include "requestqueue.h"
 
 #ifdef CONFIG_DLM_DEBUG
 int dlm_create_debug_file(struct dlm_ls *ls);
@@ -43,6 +44,10 @@ static ssize_t dlm_control_store(struct dlm_ls *ls, const char *buf, size_t len)
        ssize_t ret = len;
        int n = simple_strtol(buf, NULL, 0);
 
+       ls = dlm_find_lockspace_local(ls->ls_local_handle);
+       if (!ls)
+               return -EINVAL;
+
        switch (n) {
        case 0:
                dlm_ls_stop(ls);
@@ -53,6 +58,7 @@ static ssize_t dlm_control_store(struct dlm_ls *ls, const char *buf, size_t len)
        default:
                ret = -EINVAL;
        }
+       dlm_put_lockspace(ls);
        return ret;
 }
 
@@ -66,7 +72,7 @@ static ssize_t dlm_event_store(struct dlm_ls *ls, const char *buf, size_t len)
 
 static ssize_t dlm_id_show(struct dlm_ls *ls, char *buf)
 {
-       return sprintf(buf, "%u\n", ls->ls_global_id);
+       return snprintf(buf, PAGE_SIZE, "%u\n", ls->ls_global_id);
 }
 
 static ssize_t dlm_id_store(struct dlm_ls *ls, const char *buf, size_t len)
@@ -78,7 +84,12 @@ static ssize_t dlm_id_store(struct dlm_ls *ls, const char *buf, size_t len)
 static ssize_t dlm_recover_status_show(struct dlm_ls *ls, char *buf)
 {
        uint32_t status = dlm_recover_status(ls);
-       return sprintf(buf, "%x\n", status);
+       return snprintf(buf, PAGE_SIZE, "%x\n", status);
+}
+
+static ssize_t dlm_recover_nodeid_show(struct dlm_ls *ls, char *buf)
+{
+       return snprintf(buf, PAGE_SIZE, "%d\n", ls->ls_recover_nodeid);
 }
 
 struct dlm_attr {
@@ -108,11 +119,17 @@ static struct dlm_attr dlm_attr_recover_status = {
        .show  = dlm_recover_status_show
 };
 
+static struct dlm_attr dlm_attr_recover_nodeid = {
+       .attr  = {.name = "recover_nodeid", .mode = S_IRUGO},
+       .show  = dlm_recover_nodeid_show
+};
+
 static struct attribute *dlm_attrs[] = {
        &dlm_attr_control.attr,
        &dlm_attr_event.attr,
        &dlm_attr_id.attr,
        &dlm_attr_recover_status.attr,
+       &dlm_attr_recover_nodeid.attr,
        NULL,
 };
 
@@ -132,6 +149,12 @@ static ssize_t dlm_attr_store(struct kobject *kobj, struct attribute *attr,
        return a->store ? a->store(ls, buf, len) : len;
 }
 
+static void lockspace_kobj_release(struct kobject *k)
+{
+       struct dlm_ls *ls  = container_of(k, struct dlm_ls, ls_kobj);
+       kfree(ls);
+}
+
 static struct sysfs_ops dlm_attr_ops = {
        .show  = dlm_attr_show,
        .store = dlm_attr_store,
@@ -140,6 +163,7 @@ static struct sysfs_ops dlm_attr_ops = {
 static struct kobj_type dlm_ktype = {
        .default_attrs = dlm_attrs,
        .sysfs_ops     = &dlm_attr_ops,
+       .release       = lockspace_kobj_release,
 };
 
 static struct kset dlm_kset = {
@@ -270,12 +294,36 @@ struct dlm_ls *dlm_find_lockspace_global(uint32_t id)
        return ls;
 }
 
-struct dlm_ls *dlm_find_lockspace_local(void *id)
+struct dlm_ls *dlm_find_lockspace_local(dlm_lockspace_t *lockspace)
 {
-       struct dlm_ls *ls = id;
+       struct dlm_ls *ls;
 
        spin_lock(&lslist_lock);
-       ls->ls_count++;
+       list_for_each_entry(ls, &lslist, ls_list) {
+               if (ls->ls_local_handle == lockspace) {
+                       ls->ls_count++;
+                       goto out;
+               }
+       }
+       ls = NULL;
+ out:
+       spin_unlock(&lslist_lock);
+       return ls;
+}
+
+struct dlm_ls *dlm_find_lockspace_device(int minor)
+{
+       struct dlm_ls *ls;
+
+       spin_lock(&lslist_lock);
+       list_for_each_entry(ls, &lslist, ls_list) {
+               if (ls->ls_device.minor == minor) {
+                       ls->ls_count++;
+                       goto out;
+               }
+       }
+       ls = NULL;
+ out:
        spin_unlock(&lslist_lock);
        return ls;
 }
@@ -422,7 +470,8 @@ static int new_lockspace(char *name, int namelen, void **lockspace,
        memset(&ls->ls_stub_rsb, 0, sizeof(struct dlm_rsb));
        ls->ls_stub_rsb.res_ls = ls;
 
-       ls->ls_debug_dentry = NULL;
+       ls->ls_debug_rsb_dentry = NULL;
+       ls->ls_debug_waiters_dentry = NULL;
 
        init_waitqueue_head(&ls->ls_uevent_wait);
        ls->ls_uevent_result = 0;
@@ -430,12 +479,15 @@ static int new_lockspace(char *name, int namelen, void **lockspace,
        ls->ls_recoverd_task = NULL;
        mutex_init(&ls->ls_recoverd_active);
        spin_lock_init(&ls->ls_recover_lock);
+       spin_lock_init(&ls->ls_rcom_spin);
+       get_random_bytes(&ls->ls_rcom_seq, sizeof(uint64_t));
        ls->ls_recover_status = 0;
        ls->ls_recover_seq = 0;
        ls->ls_recover_args = NULL;
        init_rwsem(&ls->ls_in_recovery);
        INIT_LIST_HEAD(&ls->ls_requestqueue);
        mutex_init(&ls->ls_requestqueue_mutex);
+       mutex_init(&ls->ls_clear_proc_locks);
 
        ls->ls_recover_buf = kmalloc(dlm_config.buffer_size, GFP_KERNEL);
        if (!ls->ls_recover_buf)
@@ -444,22 +496,24 @@ static int new_lockspace(char *name, int namelen, void **lockspace,
        INIT_LIST_HEAD(&ls->ls_recover_list);
        spin_lock_init(&ls->ls_recover_list_lock);
        ls->ls_recover_list_count = 0;
+       ls->ls_local_handle = ls;
        init_waitqueue_head(&ls->ls_wait_general);
        INIT_LIST_HEAD(&ls->ls_root_list);
        init_rwsem(&ls->ls_root_sem);
 
        down_write(&ls->ls_in_recovery);
 
+       spin_lock(&lslist_lock);
+       list_add(&ls->ls_list, &lslist);
+       spin_unlock(&lslist_lock);
+
+       /* 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_rcomfree;
        }
 
-       spin_lock(&lslist_lock);
-       list_add(&ls->ls_list, &lslist);
-       spin_unlock(&lslist_lock);
-
        dlm_create_debug_file(ls);
 
        error = kobject_setup(ls);
@@ -481,11 +535,11 @@ static int new_lockspace(char *name, int namelen, void **lockspace,
        kobject_unregister(&ls->ls_kobj);
  out_del:
        dlm_delete_debug_file(ls);
+       dlm_recoverd_stop(ls);
+ out_rcomfree:
        spin_lock(&lslist_lock);
        list_del(&ls->ls_list);
        spin_unlock(&lslist_lock);
-       dlm_recoverd_stop(ls);
- out_rcomfree:
        kfree(ls->ls_recover_buf);
  out_dirfree:
        kfree(ls->ls_dirtbl);
@@ -633,13 +687,14 @@ static int release_lockspace(struct dlm_ls *ls, int force)
         * Free structures on any other lists
         */
 
+       dlm_purge_requestqueue(ls);
        kfree(ls->ls_recover_args);
        dlm_clear_free_entries(ls);
        dlm_clear_members(ls);
        dlm_clear_members_gone(ls);
        kfree(ls->ls_node_array);
        kobject_unregister(&ls->ls_kobj);
-       kfree(ls);
+        /* The ls structure will be freed when the kobject is done with */
 
        mutex_lock(&ls_lock);
        ls_count--;