|
@@ -1,21 +1,25 @@
|
|
|
-/******************************************************************************
|
|
|
-*******************************************************************************
|
|
|
-**
|
|
|
-** Copyright (C) 2005 Red Hat, Inc. All rights reserved.
|
|
|
-**
|
|
|
-** This copyrighted material is made available to anyone wishing to use,
|
|
|
-** modify, copy, or redistribute it subject to the terms and conditions
|
|
|
-** of the GNU General Public License v.2.
|
|
|
-**
|
|
|
-*******************************************************************************
|
|
|
-******************************************************************************/
|
|
|
+/*
|
|
|
+ * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
|
|
|
+ * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
|
|
|
+ *
|
|
|
+ * This copyrighted material is made available to anyone wishing to use,
|
|
|
+ * modify, copy, or redistribute it subject to the terms and conditions
|
|
|
+ * of the GNU General Public License v.2.
|
|
|
+ */
|
|
|
|
|
|
#include <linux/ctype.h>
|
|
|
#include <linux/stat.h>
|
|
|
|
|
|
#include "lock_dlm.h"
|
|
|
|
|
|
-static ssize_t gdlm_block_show(struct gdlm_ls *ls, char *buf)
|
|
|
+extern struct lm_lockops gdlm_ops;
|
|
|
+
|
|
|
+static ssize_t proto_name_show(struct gdlm_ls *ls, char *buf)
|
|
|
+{
|
|
|
+ return sprintf(buf, "%s\n", gdlm_ops.lm_proto_name);
|
|
|
+}
|
|
|
+
|
|
|
+static ssize_t block_show(struct gdlm_ls *ls, char *buf)
|
|
|
{
|
|
|
ssize_t ret;
|
|
|
int val = 0;
|
|
@@ -26,7 +30,7 @@ static ssize_t gdlm_block_show(struct gdlm_ls *ls, char *buf)
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
-static ssize_t gdlm_block_store(struct gdlm_ls *ls, const char *buf, size_t len)
|
|
|
+static ssize_t block_store(struct gdlm_ls *ls, const char *buf, size_t len)
|
|
|
{
|
|
|
ssize_t ret = len;
|
|
|
int val;
|
|
@@ -43,43 +47,7 @@ static ssize_t gdlm_block_store(struct gdlm_ls *ls, const char *buf, size_t len)
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
-static ssize_t gdlm_mounted_show(struct gdlm_ls *ls, char *buf)
|
|
|
-{
|
|
|
- ssize_t ret;
|
|
|
- int val = -2;
|
|
|
-
|
|
|
- if (test_bit(DFL_TERMINATE, &ls->flags))
|
|
|
- val = -1;
|
|
|
- else if (test_bit(DFL_LEAVE_DONE, &ls->flags))
|
|
|
- val = 0;
|
|
|
- else if (test_bit(DFL_JOIN_DONE, &ls->flags))
|
|
|
- val = 1;
|
|
|
- ret = sprintf(buf, "%d\n", val);
|
|
|
- return ret;
|
|
|
-}
|
|
|
-
|
|
|
-static ssize_t gdlm_mounted_store(struct gdlm_ls *ls, const char *buf, size_t len)
|
|
|
-{
|
|
|
- ssize_t ret = len;
|
|
|
- int val;
|
|
|
-
|
|
|
- val = simple_strtol(buf, NULL, 0);
|
|
|
-
|
|
|
- if (val == 1)
|
|
|
- set_bit(DFL_JOIN_DONE, &ls->flags);
|
|
|
- else if (val == 0)
|
|
|
- set_bit(DFL_LEAVE_DONE, &ls->flags);
|
|
|
- else if (val == -1) {
|
|
|
- set_bit(DFL_TERMINATE, &ls->flags);
|
|
|
- set_bit(DFL_JOIN_DONE, &ls->flags);
|
|
|
- set_bit(DFL_LEAVE_DONE, &ls->flags);
|
|
|
- } else
|
|
|
- ret = -EINVAL;
|
|
|
- wake_up(&ls->wait_control);
|
|
|
- return ret;
|
|
|
-}
|
|
|
-
|
|
|
-static ssize_t gdlm_withdraw_show(struct gdlm_ls *ls, char *buf)
|
|
|
+static ssize_t withdraw_show(struct gdlm_ls *ls, char *buf)
|
|
|
{
|
|
|
ssize_t ret;
|
|
|
int val = 0;
|
|
@@ -90,7 +58,7 @@ static ssize_t gdlm_withdraw_show(struct gdlm_ls *ls, char *buf)
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
-static ssize_t gdlm_withdraw_store(struct gdlm_ls *ls, const char *buf, size_t len)
|
|
|
+static ssize_t withdraw_store(struct gdlm_ls *ls, const char *buf, size_t len)
|
|
|
{
|
|
|
ssize_t ret = len;
|
|
|
int val;
|
|
@@ -105,67 +73,41 @@ static ssize_t gdlm_withdraw_store(struct gdlm_ls *ls, const char *buf, size_t l
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
-static ssize_t gdlm_jid_show(struct gdlm_ls *ls, char *buf)
|
|
|
-{
|
|
|
- return sprintf(buf, "%u\n", ls->jid);
|
|
|
-}
|
|
|
-
|
|
|
-static ssize_t gdlm_jid_store(struct gdlm_ls *ls, const char *buf, size_t len)
|
|
|
+static ssize_t id_show(struct gdlm_ls *ls, char *buf)
|
|
|
{
|
|
|
- ls->jid = simple_strtol(buf, NULL, 0);
|
|
|
- return len;
|
|
|
+ return sprintf(buf, "%u\n", ls->id);
|
|
|
}
|
|
|
|
|
|
-static ssize_t gdlm_first_show(struct gdlm_ls *ls, char *buf)
|
|
|
+static ssize_t jid_show(struct gdlm_ls *ls, char *buf)
|
|
|
{
|
|
|
- return sprintf(buf, "%u\n", ls->first);
|
|
|
+ return sprintf(buf, "%d\n", ls->jid);
|
|
|
}
|
|
|
|
|
|
-static ssize_t gdlm_first_store(struct gdlm_ls *ls, const char *buf, size_t len)
|
|
|
+static ssize_t first_show(struct gdlm_ls *ls, char *buf)
|
|
|
{
|
|
|
- ls->first = simple_strtol(buf, NULL, 0);
|
|
|
- return len;
|
|
|
+ return sprintf(buf, "%d\n", ls->first);
|
|
|
}
|
|
|
|
|
|
-static ssize_t gdlm_first_done_show(struct gdlm_ls *ls, char *buf)
|
|
|
+static ssize_t first_done_show(struct gdlm_ls *ls, char *buf)
|
|
|
{
|
|
|
return sprintf(buf, "%d\n", ls->first_done);
|
|
|
}
|
|
|
|
|
|
-static ssize_t gdlm_recover_show(struct gdlm_ls *ls, char *buf)
|
|
|
+static ssize_t recover_show(struct gdlm_ls *ls, char *buf)
|
|
|
{
|
|
|
- return sprintf(buf, "%u\n", ls->recover_jid);
|
|
|
+ return sprintf(buf, "%d\n", ls->recover_jid);
|
|
|
}
|
|
|
|
|
|
-static ssize_t gdlm_recover_store(struct gdlm_ls *ls, const char *buf, size_t len)
|
|
|
+static ssize_t recover_store(struct gdlm_ls *ls, const char *buf, size_t len)
|
|
|
{
|
|
|
ls->recover_jid = simple_strtol(buf, NULL, 0);
|
|
|
ls->fscb(ls->fsdata, LM_CB_NEED_RECOVERY, &ls->recover_jid);
|
|
|
return len;
|
|
|
}
|
|
|
|
|
|
-static ssize_t gdlm_recover_done_show(struct gdlm_ls *ls, char *buf)
|
|
|
-{
|
|
|
- ssize_t ret;
|
|
|
- ret = sprintf(buf, "%d\n", ls->recover_done);
|
|
|
- return ret;
|
|
|
-}
|
|
|
-
|
|
|
-static ssize_t gdlm_cluster_show(struct gdlm_ls *ls, char *buf)
|
|
|
-{
|
|
|
- ssize_t ret;
|
|
|
- ret = sprintf(buf, "%s\n", ls->clustername);
|
|
|
- return ret;
|
|
|
-}
|
|
|
-
|
|
|
-static ssize_t gdlm_options_show(struct gdlm_ls *ls, char *buf)
|
|
|
+static ssize_t recover_done_show(struct gdlm_ls *ls, char *buf)
|
|
|
{
|
|
|
- ssize_t ret = 0;
|
|
|
-
|
|
|
- if (ls->fsflags & LM_MFLAG_SPECTATOR)
|
|
|
- ret += sprintf(buf, "spectator ");
|
|
|
-
|
|
|
- return ret;
|
|
|
+ return sprintf(buf, "%d\n", ls->recover_jid_done);
|
|
|
}
|
|
|
|
|
|
struct gdlm_attr {
|
|
@@ -174,73 +116,29 @@ struct gdlm_attr {
|
|
|
ssize_t (*store)(struct gdlm_ls *, const char *, size_t);
|
|
|
};
|
|
|
|
|
|
-static struct gdlm_attr gdlm_attr_block = {
|
|
|
- .attr = {.name = "block", .mode = S_IRUGO | S_IWUSR},
|
|
|
- .show = gdlm_block_show,
|
|
|
- .store = gdlm_block_store
|
|
|
-};
|
|
|
-
|
|
|
-static struct gdlm_attr gdlm_attr_mounted = {
|
|
|
- .attr = {.name = "mounted", .mode = S_IRUGO | S_IWUSR},
|
|
|
- .show = gdlm_mounted_show,
|
|
|
- .store = gdlm_mounted_store
|
|
|
-};
|
|
|
-
|
|
|
-static struct gdlm_attr gdlm_attr_withdraw = {
|
|
|
- .attr = {.name = "withdraw", .mode = S_IRUGO | S_IWUSR},
|
|
|
- .show = gdlm_withdraw_show,
|
|
|
- .store = gdlm_withdraw_store
|
|
|
-};
|
|
|
-
|
|
|
-static struct gdlm_attr gdlm_attr_jid = {
|
|
|
- .attr = {.name = "jid", .mode = S_IRUGO | S_IWUSR},
|
|
|
- .show = gdlm_jid_show,
|
|
|
- .store = gdlm_jid_store
|
|
|
-};
|
|
|
-
|
|
|
-static struct gdlm_attr gdlm_attr_first = {
|
|
|
- .attr = {.name = "first", .mode = S_IRUGO | S_IWUSR},
|
|
|
- .show = gdlm_first_show,
|
|
|
- .store = gdlm_first_store
|
|
|
-};
|
|
|
-
|
|
|
-static struct gdlm_attr gdlm_attr_first_done = {
|
|
|
- .attr = {.name = "first_done", .mode = S_IRUGO},
|
|
|
- .show = gdlm_first_done_show,
|
|
|
-};
|
|
|
-
|
|
|
-static struct gdlm_attr gdlm_attr_recover = {
|
|
|
- .attr = {.name = "recover", .mode = S_IRUGO | S_IWUSR},
|
|
|
- .show = gdlm_recover_show,
|
|
|
- .store = gdlm_recover_store
|
|
|
-};
|
|
|
-
|
|
|
-static struct gdlm_attr gdlm_attr_recover_done = {
|
|
|
- .attr = {.name = "recover_done", .mode = S_IRUGO | S_IWUSR},
|
|
|
- .show = gdlm_recover_done_show,
|
|
|
-};
|
|
|
-
|
|
|
-static struct gdlm_attr gdlm_attr_cluster = {
|
|
|
- .attr = {.name = "cluster", .mode = S_IRUGO | S_IWUSR},
|
|
|
- .show = gdlm_cluster_show,
|
|
|
-};
|
|
|
+#define GDLM_ATTR(_name,_mode,_show,_store) \
|
|
|
+static struct gdlm_attr gdlm_attr_##_name = __ATTR(_name,_mode,_show,_store)
|
|
|
|
|
|
-static struct gdlm_attr gdlm_attr_options = {
|
|
|
- .attr = {.name = "options", .mode = S_IRUGO | S_IWUSR},
|
|
|
- .show = gdlm_options_show,
|
|
|
-};
|
|
|
+GDLM_ATTR(proto_name, 0444, proto_name_show, NULL);
|
|
|
+GDLM_ATTR(block, 0644, block_show, block_store);
|
|
|
+GDLM_ATTR(withdraw, 0644, withdraw_show, withdraw_store);
|
|
|
+GDLM_ATTR(id, 0444, id_show, NULL);
|
|
|
+GDLM_ATTR(jid, 0444, jid_show, NULL);
|
|
|
+GDLM_ATTR(first, 0444, first_show, NULL);
|
|
|
+GDLM_ATTR(first_done, 0444, first_done_show, NULL);
|
|
|
+GDLM_ATTR(recover, 0644, recover_show, recover_store);
|
|
|
+GDLM_ATTR(recover_done, 0444, recover_done_show, NULL);
|
|
|
|
|
|
static struct attribute *gdlm_attrs[] = {
|
|
|
+ &gdlm_attr_proto_name.attr,
|
|
|
&gdlm_attr_block.attr,
|
|
|
- &gdlm_attr_mounted.attr,
|
|
|
&gdlm_attr_withdraw.attr,
|
|
|
+ &gdlm_attr_id.attr,
|
|
|
&gdlm_attr_jid.attr,
|
|
|
&gdlm_attr_first.attr,
|
|
|
&gdlm_attr_first_done.attr,
|
|
|
&gdlm_attr_recover.attr,
|
|
|
&gdlm_attr_recover_done.attr,
|
|
|
- &gdlm_attr_cluster.attr,
|
|
|
- &gdlm_attr_options.attr,
|
|
|
NULL,
|
|
|
};
|
|
|
|
|
@@ -276,20 +174,25 @@ static struct kset gdlm_kset = {
|
|
|
.ktype = &gdlm_ktype,
|
|
|
};
|
|
|
|
|
|
-int gdlm_kobject_setup(struct gdlm_ls *ls)
|
|
|
+int gdlm_kobject_setup(struct gdlm_ls *ls, struct kobject *fskobj)
|
|
|
{
|
|
|
int error;
|
|
|
|
|
|
- error = kobject_set_name(&ls->kobj, "%s", ls->fsname);
|
|
|
- if (error)
|
|
|
+ error = kobject_set_name(&ls->kobj, "%s", "lock_module");
|
|
|
+ if (error) {
|
|
|
+ log_error("can't set kobj name %d", error);
|
|
|
return error;
|
|
|
+ }
|
|
|
|
|
|
ls->kobj.kset = &gdlm_kset;
|
|
|
ls->kobj.ktype = &gdlm_ktype;
|
|
|
+ ls->kobj.parent = fskobj;
|
|
|
|
|
|
error = kobject_register(&ls->kobj);
|
|
|
+ if (error)
|
|
|
+ log_error("can't register kobj %d", error);
|
|
|
|
|
|
- return 0;
|
|
|
+ return error;
|
|
|
}
|
|
|
|
|
|
void gdlm_kobject_release(struct gdlm_ls *ls)
|