2006-01-18 16:30:29 +07:00
|
|
|
/******************************************************************************
|
|
|
|
*******************************************************************************
|
|
|
|
**
|
|
|
|
** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
|
2011-11-03 02:30:58 +07:00
|
|
|
** Copyright (C) 2004-2011 Red Hat, Inc. All rights reserved.
|
2006-01-18 16:30:29 +07:00
|
|
|
**
|
|
|
|
** 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/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/configfs.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 15:04:11 +07:00
|
|
|
#include <linux/slab.h>
|
2008-08-28 23:36:19 +07:00
|
|
|
#include <linux/in.h>
|
|
|
|
#include <linux/in6.h>
|
2011-11-03 02:30:58 +07:00
|
|
|
#include <linux/dlmconstants.h>
|
2008-08-28 23:36:19 +07:00
|
|
|
#include <net/ipv6.h>
|
2006-01-18 16:30:29 +07:00
|
|
|
#include <net/sock.h>
|
|
|
|
|
|
|
|
#include "config.h"
|
2006-04-28 21:50:41 +07:00
|
|
|
#include "lowcomms.h"
|
2006-01-18 16:30:29 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* /config/dlm/<cluster>/spaces/<space>/nodes/<node>/nodeid
|
|
|
|
* /config/dlm/<cluster>/spaces/<space>/nodes/<node>/weight
|
|
|
|
* /config/dlm/<cluster>/comms/<comm>/nodeid
|
|
|
|
* /config/dlm/<cluster>/comms/<comm>/local
|
2011-06-30 19:37:10 +07:00
|
|
|
* /config/dlm/<cluster>/comms/<comm>/addr (write only)
|
|
|
|
* /config/dlm/<cluster>/comms/<comm>/addr_list (read only)
|
2006-01-18 16:30:29 +07:00
|
|
|
* The <cluster> level is useless, but I haven't figured out how to avoid it.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static struct config_group *space_list;
|
|
|
|
static struct config_group *comm_list;
|
2008-07-31 21:31:53 +07:00
|
|
|
static struct dlm_comm *local_comm;
|
2011-11-03 02:30:58 +07:00
|
|
|
static uint32_t dlm_comm_count;
|
2006-01-18 16:30:29 +07:00
|
|
|
|
2008-07-31 21:31:53 +07:00
|
|
|
struct dlm_clusters;
|
|
|
|
struct dlm_cluster;
|
|
|
|
struct dlm_spaces;
|
|
|
|
struct dlm_space;
|
|
|
|
struct dlm_comms;
|
|
|
|
struct dlm_comm;
|
|
|
|
struct dlm_nodes;
|
|
|
|
struct dlm_node;
|
2006-01-18 16:30:29 +07:00
|
|
|
|
2008-07-18 04:53:48 +07:00
|
|
|
static struct config_group *make_cluster(struct config_group *, const char *);
|
2006-01-18 16:30:29 +07:00
|
|
|
static void drop_cluster(struct config_group *, struct config_item *);
|
|
|
|
static void release_cluster(struct config_item *);
|
2008-07-18 04:53:48 +07:00
|
|
|
static struct config_group *make_space(struct config_group *, const char *);
|
2006-01-18 16:30:29 +07:00
|
|
|
static void drop_space(struct config_group *, struct config_item *);
|
|
|
|
static void release_space(struct config_item *);
|
2008-07-18 04:53:48 +07:00
|
|
|
static struct config_item *make_comm(struct config_group *, const char *);
|
2006-01-18 16:30:29 +07:00
|
|
|
static void drop_comm(struct config_group *, struct config_item *);
|
|
|
|
static void release_comm(struct config_item *);
|
2008-07-18 04:53:48 +07:00
|
|
|
static struct config_item *make_node(struct config_group *, const char *);
|
2006-01-18 16:30:29 +07:00
|
|
|
static void drop_node(struct config_group *, struct config_item *);
|
|
|
|
static void release_node(struct config_item *);
|
|
|
|
|
2007-01-09 22:46:02 +07:00
|
|
|
static ssize_t show_cluster(struct config_item *i, struct configfs_attribute *a,
|
|
|
|
char *buf);
|
|
|
|
static ssize_t store_cluster(struct config_item *i,
|
|
|
|
struct configfs_attribute *a,
|
|
|
|
const char *buf, size_t len);
|
2006-01-18 16:30:29 +07:00
|
|
|
static ssize_t show_comm(struct config_item *i, struct configfs_attribute *a,
|
|
|
|
char *buf);
|
|
|
|
static ssize_t store_comm(struct config_item *i, struct configfs_attribute *a,
|
|
|
|
const char *buf, size_t len);
|
|
|
|
static ssize_t show_node(struct config_item *i, struct configfs_attribute *a,
|
|
|
|
char *buf);
|
|
|
|
static ssize_t store_node(struct config_item *i, struct configfs_attribute *a,
|
|
|
|
const char *buf, size_t len);
|
|
|
|
|
2008-07-31 21:31:53 +07:00
|
|
|
static ssize_t comm_nodeid_read(struct dlm_comm *cm, char *buf);
|
|
|
|
static ssize_t comm_nodeid_write(struct dlm_comm *cm, const char *buf,
|
|
|
|
size_t len);
|
|
|
|
static ssize_t comm_local_read(struct dlm_comm *cm, char *buf);
|
|
|
|
static ssize_t comm_local_write(struct dlm_comm *cm, const char *buf,
|
|
|
|
size_t len);
|
|
|
|
static ssize_t comm_addr_write(struct dlm_comm *cm, const char *buf,
|
|
|
|
size_t len);
|
2011-06-30 19:37:10 +07:00
|
|
|
static ssize_t comm_addr_list_read(struct dlm_comm *cm, char *buf);
|
2008-07-31 21:31:53 +07:00
|
|
|
static ssize_t node_nodeid_read(struct dlm_node *nd, char *buf);
|
|
|
|
static ssize_t node_nodeid_write(struct dlm_node *nd, const char *buf,
|
|
|
|
size_t len);
|
|
|
|
static ssize_t node_weight_read(struct dlm_node *nd, char *buf);
|
|
|
|
static ssize_t node_weight_write(struct dlm_node *nd, const char *buf,
|
|
|
|
size_t len);
|
|
|
|
|
|
|
|
struct dlm_cluster {
|
2007-01-09 22:46:02 +07:00
|
|
|
struct config_group group;
|
|
|
|
unsigned int cl_tcp_port;
|
|
|
|
unsigned int cl_buffer_size;
|
|
|
|
unsigned int cl_rsbtbl_size;
|
|
|
|
unsigned int cl_recover_timer;
|
|
|
|
unsigned int cl_toss_secs;
|
|
|
|
unsigned int cl_scan_secs;
|
|
|
|
unsigned int cl_log_debug;
|
2007-04-17 21:39:57 +07:00
|
|
|
unsigned int cl_protocol;
|
2007-05-18 20:59:31 +07:00
|
|
|
unsigned int cl_timewarn_cs;
|
2011-03-29 02:17:26 +07:00
|
|
|
unsigned int cl_waitwarn_us;
|
2011-07-08 02:05:03 +07:00
|
|
|
unsigned int cl_new_rsb_count;
|
2011-11-03 02:30:58 +07:00
|
|
|
unsigned int cl_recover_callbacks;
|
|
|
|
char cl_cluster_name[DLM_LOCKSPACE_LEN];
|
2007-01-09 22:46:02 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
CLUSTER_ATTR_TCP_PORT = 0,
|
|
|
|
CLUSTER_ATTR_BUFFER_SIZE,
|
|
|
|
CLUSTER_ATTR_RSBTBL_SIZE,
|
|
|
|
CLUSTER_ATTR_RECOVER_TIMER,
|
|
|
|
CLUSTER_ATTR_TOSS_SECS,
|
|
|
|
CLUSTER_ATTR_SCAN_SECS,
|
|
|
|
CLUSTER_ATTR_LOG_DEBUG,
|
2007-04-17 21:39:57 +07:00
|
|
|
CLUSTER_ATTR_PROTOCOL,
|
2007-05-18 20:59:31 +07:00
|
|
|
CLUSTER_ATTR_TIMEWARN_CS,
|
2011-03-29 02:17:26 +07:00
|
|
|
CLUSTER_ATTR_WAITWARN_US,
|
2011-07-08 02:05:03 +07:00
|
|
|
CLUSTER_ATTR_NEW_RSB_COUNT,
|
2011-11-03 02:30:58 +07:00
|
|
|
CLUSTER_ATTR_RECOVER_CALLBACKS,
|
|
|
|
CLUSTER_ATTR_CLUSTER_NAME,
|
2007-01-09 22:46:02 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct cluster_attribute {
|
|
|
|
struct configfs_attribute attr;
|
2008-07-31 21:31:53 +07:00
|
|
|
ssize_t (*show)(struct dlm_cluster *, char *);
|
|
|
|
ssize_t (*store)(struct dlm_cluster *, const char *, size_t);
|
2007-01-09 22:46:02 +07:00
|
|
|
};
|
|
|
|
|
2011-11-03 02:30:58 +07:00
|
|
|
static ssize_t cluster_cluster_name_read(struct dlm_cluster *cl, char *buf)
|
|
|
|
{
|
|
|
|
return sprintf(buf, "%s\n", cl->cl_cluster_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t cluster_cluster_name_write(struct dlm_cluster *cl,
|
|
|
|
const char *buf, size_t len)
|
|
|
|
{
|
2013-06-20 17:59:51 +07:00
|
|
|
strlcpy(dlm_config.ci_cluster_name, buf,
|
|
|
|
sizeof(dlm_config.ci_cluster_name));
|
|
|
|
strlcpy(cl->cl_cluster_name, buf, sizeof(cl->cl_cluster_name));
|
2011-11-03 02:30:58 +07:00
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct cluster_attribute cluster_attr_cluster_name = {
|
|
|
|
.attr = { .ca_owner = THIS_MODULE,
|
|
|
|
.ca_name = "cluster_name",
|
|
|
|
.ca_mode = S_IRUGO | S_IWUSR },
|
|
|
|
.show = cluster_cluster_name_read,
|
|
|
|
.store = cluster_cluster_name_write,
|
|
|
|
};
|
|
|
|
|
2008-07-31 21:31:53 +07:00
|
|
|
static ssize_t cluster_set(struct dlm_cluster *cl, unsigned int *cl_field,
|
2008-02-14 07:54:29 +07:00
|
|
|
int *info_field, int check_zero,
|
2007-01-09 22:46:02 +07:00
|
|
|
const char *buf, size_t len)
|
|
|
|
{
|
|
|
|
unsigned int x;
|
2014-06-07 04:38:24 +07:00
|
|
|
int rc;
|
2007-01-09 22:46:02 +07:00
|
|
|
|
|
|
|
if (!capable(CAP_SYS_ADMIN))
|
2013-02-20 09:13:55 +07:00
|
|
|
return -EPERM;
|
2014-06-07 04:38:24 +07:00
|
|
|
rc = kstrtouint(buf, 0, &x);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
2007-01-09 22:46:02 +07:00
|
|
|
|
|
|
|
if (check_zero && !x)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
*cl_field = x;
|
|
|
|
*info_field = x;
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CLUSTER_ATTR(name, check_zero) \
|
2008-07-31 21:31:53 +07:00
|
|
|
static ssize_t name##_write(struct dlm_cluster *cl, const char *buf, size_t len) \
|
2007-01-09 22:46:02 +07:00
|
|
|
{ \
|
|
|
|
return cluster_set(cl, &cl->cl_##name, &dlm_config.ci_##name, \
|
|
|
|
check_zero, buf, len); \
|
|
|
|
} \
|
2008-07-31 21:31:53 +07:00
|
|
|
static ssize_t name##_read(struct dlm_cluster *cl, char *buf) \
|
2007-01-09 22:46:02 +07:00
|
|
|
{ \
|
|
|
|
return snprintf(buf, PAGE_SIZE, "%u\n", cl->cl_##name); \
|
|
|
|
} \
|
|
|
|
static struct cluster_attribute cluster_attr_##name = \
|
|
|
|
__CONFIGFS_ATTR(name, 0644, name##_read, name##_write)
|
|
|
|
|
|
|
|
CLUSTER_ATTR(tcp_port, 1);
|
|
|
|
CLUSTER_ATTR(buffer_size, 1);
|
|
|
|
CLUSTER_ATTR(rsbtbl_size, 1);
|
|
|
|
CLUSTER_ATTR(recover_timer, 1);
|
|
|
|
CLUSTER_ATTR(toss_secs, 1);
|
|
|
|
CLUSTER_ATTR(scan_secs, 1);
|
|
|
|
CLUSTER_ATTR(log_debug, 0);
|
2007-04-17 21:39:57 +07:00
|
|
|
CLUSTER_ATTR(protocol, 0);
|
2007-05-18 20:59:31 +07:00
|
|
|
CLUSTER_ATTR(timewarn_cs, 1);
|
2011-03-29 02:17:26 +07:00
|
|
|
CLUSTER_ATTR(waitwarn_us, 0);
|
2011-07-08 02:05:03 +07:00
|
|
|
CLUSTER_ATTR(new_rsb_count, 0);
|
2011-11-03 02:30:58 +07:00
|
|
|
CLUSTER_ATTR(recover_callbacks, 0);
|
2007-01-09 22:46:02 +07:00
|
|
|
|
|
|
|
static struct configfs_attribute *cluster_attrs[] = {
|
|
|
|
[CLUSTER_ATTR_TCP_PORT] = &cluster_attr_tcp_port.attr,
|
|
|
|
[CLUSTER_ATTR_BUFFER_SIZE] = &cluster_attr_buffer_size.attr,
|
|
|
|
[CLUSTER_ATTR_RSBTBL_SIZE] = &cluster_attr_rsbtbl_size.attr,
|
|
|
|
[CLUSTER_ATTR_RECOVER_TIMER] = &cluster_attr_recover_timer.attr,
|
|
|
|
[CLUSTER_ATTR_TOSS_SECS] = &cluster_attr_toss_secs.attr,
|
|
|
|
[CLUSTER_ATTR_SCAN_SECS] = &cluster_attr_scan_secs.attr,
|
|
|
|
[CLUSTER_ATTR_LOG_DEBUG] = &cluster_attr_log_debug.attr,
|
2007-04-17 21:39:57 +07:00
|
|
|
[CLUSTER_ATTR_PROTOCOL] = &cluster_attr_protocol.attr,
|
2007-05-18 20:59:31 +07:00
|
|
|
[CLUSTER_ATTR_TIMEWARN_CS] = &cluster_attr_timewarn_cs.attr,
|
2011-03-29 02:17:26 +07:00
|
|
|
[CLUSTER_ATTR_WAITWARN_US] = &cluster_attr_waitwarn_us.attr,
|
2011-07-08 02:05:03 +07:00
|
|
|
[CLUSTER_ATTR_NEW_RSB_COUNT] = &cluster_attr_new_rsb_count.attr,
|
2011-11-03 02:30:58 +07:00
|
|
|
[CLUSTER_ATTR_RECOVER_CALLBACKS] = &cluster_attr_recover_callbacks.attr,
|
|
|
|
[CLUSTER_ATTR_CLUSTER_NAME] = &cluster_attr_cluster_name.attr,
|
2007-01-09 22:46:02 +07:00
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
2006-01-18 16:30:29 +07:00
|
|
|
enum {
|
|
|
|
COMM_ATTR_NODEID = 0,
|
|
|
|
COMM_ATTR_LOCAL,
|
|
|
|
COMM_ATTR_ADDR,
|
2011-06-30 19:37:10 +07:00
|
|
|
COMM_ATTR_ADDR_LIST,
|
2006-01-18 16:30:29 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct comm_attribute {
|
|
|
|
struct configfs_attribute attr;
|
2008-07-31 21:31:53 +07:00
|
|
|
ssize_t (*show)(struct dlm_comm *, char *);
|
|
|
|
ssize_t (*store)(struct dlm_comm *, const char *, size_t);
|
2006-01-18 16:30:29 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct comm_attribute comm_attr_nodeid = {
|
|
|
|
.attr = { .ca_owner = THIS_MODULE,
|
|
|
|
.ca_name = "nodeid",
|
|
|
|
.ca_mode = S_IRUGO | S_IWUSR },
|
|
|
|
.show = comm_nodeid_read,
|
|
|
|
.store = comm_nodeid_write,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct comm_attribute comm_attr_local = {
|
|
|
|
.attr = { .ca_owner = THIS_MODULE,
|
|
|
|
.ca_name = "local",
|
|
|
|
.ca_mode = S_IRUGO | S_IWUSR },
|
|
|
|
.show = comm_local_read,
|
|
|
|
.store = comm_local_write,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct comm_attribute comm_attr_addr = {
|
|
|
|
.attr = { .ca_owner = THIS_MODULE,
|
|
|
|
.ca_name = "addr",
|
2011-06-30 19:37:10 +07:00
|
|
|
.ca_mode = S_IWUSR },
|
2006-01-18 16:30:29 +07:00
|
|
|
.store = comm_addr_write,
|
|
|
|
};
|
|
|
|
|
2011-06-30 19:37:10 +07:00
|
|
|
static struct comm_attribute comm_attr_addr_list = {
|
|
|
|
.attr = { .ca_owner = THIS_MODULE,
|
|
|
|
.ca_name = "addr_list",
|
|
|
|
.ca_mode = S_IRUGO },
|
|
|
|
.show = comm_addr_list_read,
|
|
|
|
};
|
|
|
|
|
2006-01-18 16:30:29 +07:00
|
|
|
static struct configfs_attribute *comm_attrs[] = {
|
|
|
|
[COMM_ATTR_NODEID] = &comm_attr_nodeid.attr,
|
|
|
|
[COMM_ATTR_LOCAL] = &comm_attr_local.attr,
|
|
|
|
[COMM_ATTR_ADDR] = &comm_attr_addr.attr,
|
2011-06-30 19:37:10 +07:00
|
|
|
[COMM_ATTR_ADDR_LIST] = &comm_attr_addr_list.attr,
|
2006-01-18 16:30:29 +07:00
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
NODE_ATTR_NODEID = 0,
|
|
|
|
NODE_ATTR_WEIGHT,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct node_attribute {
|
|
|
|
struct configfs_attribute attr;
|
2008-07-31 21:31:53 +07:00
|
|
|
ssize_t (*show)(struct dlm_node *, char *);
|
|
|
|
ssize_t (*store)(struct dlm_node *, const char *, size_t);
|
2006-01-18 16:30:29 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct node_attribute node_attr_nodeid = {
|
|
|
|
.attr = { .ca_owner = THIS_MODULE,
|
|
|
|
.ca_name = "nodeid",
|
|
|
|
.ca_mode = S_IRUGO | S_IWUSR },
|
|
|
|
.show = node_nodeid_read,
|
|
|
|
.store = node_nodeid_write,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct node_attribute node_attr_weight = {
|
|
|
|
.attr = { .ca_owner = THIS_MODULE,
|
|
|
|
.ca_name = "weight",
|
|
|
|
.ca_mode = S_IRUGO | S_IWUSR },
|
|
|
|
.show = node_weight_read,
|
|
|
|
.store = node_weight_write,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct configfs_attribute *node_attrs[] = {
|
|
|
|
[NODE_ATTR_NODEID] = &node_attr_nodeid.attr,
|
|
|
|
[NODE_ATTR_WEIGHT] = &node_attr_weight.attr,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
2008-07-31 21:31:53 +07:00
|
|
|
struct dlm_clusters {
|
2006-01-18 16:30:29 +07:00
|
|
|
struct configfs_subsystem subsys;
|
|
|
|
};
|
|
|
|
|
2008-07-31 21:31:53 +07:00
|
|
|
struct dlm_spaces {
|
2006-01-18 16:30:29 +07:00
|
|
|
struct config_group ss_group;
|
|
|
|
};
|
|
|
|
|
2008-07-31 21:31:53 +07:00
|
|
|
struct dlm_space {
|
2006-01-18 16:30:29 +07:00
|
|
|
struct config_group group;
|
|
|
|
struct list_head members;
|
2006-01-20 15:47:07 +07:00
|
|
|
struct mutex members_lock;
|
2006-01-18 16:30:29 +07:00
|
|
|
int members_count;
|
|
|
|
};
|
|
|
|
|
2008-07-31 21:31:53 +07:00
|
|
|
struct dlm_comms {
|
2006-01-18 16:30:29 +07:00
|
|
|
struct config_group cs_group;
|
|
|
|
};
|
|
|
|
|
2008-07-31 21:31:53 +07:00
|
|
|
struct dlm_comm {
|
2006-01-18 16:30:29 +07:00
|
|
|
struct config_item item;
|
2011-11-03 02:30:58 +07:00
|
|
|
int seq;
|
2006-01-18 16:30:29 +07:00
|
|
|
int nodeid;
|
|
|
|
int local;
|
|
|
|
int addr_count;
|
|
|
|
struct sockaddr_storage *addr[DLM_MAX_ADDR_COUNT];
|
|
|
|
};
|
|
|
|
|
2008-07-31 21:31:53 +07:00
|
|
|
struct dlm_nodes {
|
2006-01-18 16:30:29 +07:00
|
|
|
struct config_group ns_group;
|
|
|
|
};
|
|
|
|
|
2008-07-31 21:31:53 +07:00
|
|
|
struct dlm_node {
|
2006-01-18 16:30:29 +07:00
|
|
|
struct config_item item;
|
|
|
|
struct list_head list; /* space->members */
|
|
|
|
int nodeid;
|
|
|
|
int weight;
|
2008-03-19 02:22:11 +07:00
|
|
|
int new;
|
2011-11-03 02:30:58 +07:00
|
|
|
int comm_seq; /* copy of cm->seq when nd->nodeid is set */
|
2006-01-18 16:30:29 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct configfs_group_operations clusters_ops = {
|
|
|
|
.make_group = make_cluster,
|
|
|
|
.drop_item = drop_cluster,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct configfs_item_operations cluster_ops = {
|
|
|
|
.release = release_cluster,
|
2007-01-09 22:46:02 +07:00
|
|
|
.show_attribute = show_cluster,
|
|
|
|
.store_attribute = store_cluster,
|
2006-01-18 16:30:29 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct configfs_group_operations spaces_ops = {
|
|
|
|
.make_group = make_space,
|
|
|
|
.drop_item = drop_space,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct configfs_item_operations space_ops = {
|
|
|
|
.release = release_space,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct configfs_group_operations comms_ops = {
|
|
|
|
.make_item = make_comm,
|
|
|
|
.drop_item = drop_comm,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct configfs_item_operations comm_ops = {
|
|
|
|
.release = release_comm,
|
|
|
|
.show_attribute = show_comm,
|
|
|
|
.store_attribute = store_comm,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct configfs_group_operations nodes_ops = {
|
|
|
|
.make_item = make_node,
|
|
|
|
.drop_item = drop_node,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct configfs_item_operations node_ops = {
|
|
|
|
.release = release_node,
|
|
|
|
.show_attribute = show_node,
|
|
|
|
.store_attribute = store_node,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct config_item_type clusters_type = {
|
|
|
|
.ct_group_ops = &clusters_ops,
|
|
|
|
.ct_owner = THIS_MODULE,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct config_item_type cluster_type = {
|
|
|
|
.ct_item_ops = &cluster_ops,
|
2007-01-09 22:46:02 +07:00
|
|
|
.ct_attrs = cluster_attrs,
|
2006-01-18 16:30:29 +07:00
|
|
|
.ct_owner = THIS_MODULE,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct config_item_type spaces_type = {
|
|
|
|
.ct_group_ops = &spaces_ops,
|
|
|
|
.ct_owner = THIS_MODULE,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct config_item_type space_type = {
|
|
|
|
.ct_item_ops = &space_ops,
|
|
|
|
.ct_owner = THIS_MODULE,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct config_item_type comms_type = {
|
|
|
|
.ct_group_ops = &comms_ops,
|
|
|
|
.ct_owner = THIS_MODULE,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct config_item_type comm_type = {
|
|
|
|
.ct_item_ops = &comm_ops,
|
|
|
|
.ct_attrs = comm_attrs,
|
|
|
|
.ct_owner = THIS_MODULE,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct config_item_type nodes_type = {
|
|
|
|
.ct_group_ops = &nodes_ops,
|
|
|
|
.ct_owner = THIS_MODULE,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct config_item_type node_type = {
|
|
|
|
.ct_item_ops = &node_ops,
|
|
|
|
.ct_attrs = node_attrs,
|
|
|
|
.ct_owner = THIS_MODULE,
|
|
|
|
};
|
|
|
|
|
2008-09-05 20:42:08 +07:00
|
|
|
static struct dlm_cluster *config_item_to_cluster(struct config_item *i)
|
2006-01-18 16:30:29 +07:00
|
|
|
{
|
2008-07-31 21:31:53 +07:00
|
|
|
return i ? container_of(to_config_group(i), struct dlm_cluster, group) :
|
|
|
|
NULL;
|
2006-01-18 16:30:29 +07:00
|
|
|
}
|
|
|
|
|
2008-09-05 20:42:08 +07:00
|
|
|
static struct dlm_space *config_item_to_space(struct config_item *i)
|
2006-01-18 16:30:29 +07:00
|
|
|
{
|
2008-07-31 21:31:53 +07:00
|
|
|
return i ? container_of(to_config_group(i), struct dlm_space, group) :
|
|
|
|
NULL;
|
2006-01-18 16:30:29 +07:00
|
|
|
}
|
|
|
|
|
2008-09-05 20:42:08 +07:00
|
|
|
static struct dlm_comm *config_item_to_comm(struct config_item *i)
|
2006-01-18 16:30:29 +07:00
|
|
|
{
|
2008-07-31 21:31:53 +07:00
|
|
|
return i ? container_of(i, struct dlm_comm, item) : NULL;
|
2006-01-18 16:30:29 +07:00
|
|
|
}
|
|
|
|
|
2008-09-05 20:42:08 +07:00
|
|
|
static struct dlm_node *config_item_to_node(struct config_item *i)
|
2006-01-18 16:30:29 +07:00
|
|
|
{
|
2008-07-31 21:31:53 +07:00
|
|
|
return i ? container_of(i, struct dlm_node, item) : NULL;
|
2006-01-18 16:30:29 +07:00
|
|
|
}
|
|
|
|
|
2008-07-18 04:53:48 +07:00
|
|
|
static struct config_group *make_cluster(struct config_group *g,
|
|
|
|
const char *name)
|
2006-01-18 16:30:29 +07:00
|
|
|
{
|
2008-07-31 21:31:53 +07:00
|
|
|
struct dlm_cluster *cl = NULL;
|
|
|
|
struct dlm_spaces *sps = NULL;
|
|
|
|
struct dlm_comms *cms = NULL;
|
2006-01-18 16:30:29 +07:00
|
|
|
void *gps = NULL;
|
|
|
|
|
2009-12-01 05:34:43 +07:00
|
|
|
cl = kzalloc(sizeof(struct dlm_cluster), GFP_NOFS);
|
|
|
|
gps = kcalloc(3, sizeof(struct config_group *), GFP_NOFS);
|
|
|
|
sps = kzalloc(sizeof(struct dlm_spaces), GFP_NOFS);
|
|
|
|
cms = kzalloc(sizeof(struct dlm_comms), GFP_NOFS);
|
2006-01-18 16:30:29 +07:00
|
|
|
|
|
|
|
if (!cl || !gps || !sps || !cms)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
config_group_init_type_name(&cl->group, name, &cluster_type);
|
|
|
|
config_group_init_type_name(&sps->ss_group, "spaces", &spaces_type);
|
|
|
|
config_group_init_type_name(&cms->cs_group, "comms", &comms_type);
|
|
|
|
|
|
|
|
cl->group.default_groups = gps;
|
|
|
|
cl->group.default_groups[0] = &sps->ss_group;
|
|
|
|
cl->group.default_groups[1] = &cms->cs_group;
|
|
|
|
cl->group.default_groups[2] = NULL;
|
|
|
|
|
2007-01-09 22:46:02 +07:00
|
|
|
cl->cl_tcp_port = dlm_config.ci_tcp_port;
|
|
|
|
cl->cl_buffer_size = dlm_config.ci_buffer_size;
|
|
|
|
cl->cl_rsbtbl_size = dlm_config.ci_rsbtbl_size;
|
|
|
|
cl->cl_recover_timer = dlm_config.ci_recover_timer;
|
|
|
|
cl->cl_toss_secs = dlm_config.ci_toss_secs;
|
|
|
|
cl->cl_scan_secs = dlm_config.ci_scan_secs;
|
|
|
|
cl->cl_log_debug = dlm_config.ci_log_debug;
|
2007-05-29 20:47:51 +07:00
|
|
|
cl->cl_protocol = dlm_config.ci_protocol;
|
2007-05-29 20:44:23 +07:00
|
|
|
cl->cl_timewarn_cs = dlm_config.ci_timewarn_cs;
|
2011-03-29 02:17:26 +07:00
|
|
|
cl->cl_waitwarn_us = dlm_config.ci_waitwarn_us;
|
2011-07-08 02:05:03 +07:00
|
|
|
cl->cl_new_rsb_count = dlm_config.ci_new_rsb_count;
|
2011-11-03 02:30:58 +07:00
|
|
|
cl->cl_recover_callbacks = dlm_config.ci_recover_callbacks;
|
|
|
|
memcpy(cl->cl_cluster_name, dlm_config.ci_cluster_name,
|
|
|
|
DLM_LOCKSPACE_LEN);
|
2007-01-09 22:46:02 +07:00
|
|
|
|
2006-01-18 16:30:29 +07:00
|
|
|
space_list = &sps->ss_group;
|
|
|
|
comm_list = &cms->cs_group;
|
2008-07-18 04:53:48 +07:00
|
|
|
return &cl->group;
|
2006-01-18 16:30:29 +07:00
|
|
|
|
|
|
|
fail:
|
|
|
|
kfree(cl);
|
|
|
|
kfree(gps);
|
|
|
|
kfree(sps);
|
|
|
|
kfree(cms);
|
2008-07-18 05:21:29 +07:00
|
|
|
return ERR_PTR(-ENOMEM);
|
2006-01-18 16:30:29 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void drop_cluster(struct config_group *g, struct config_item *i)
|
|
|
|
{
|
2008-09-05 20:42:08 +07:00
|
|
|
struct dlm_cluster *cl = config_item_to_cluster(i);
|
2006-01-18 16:30:29 +07:00
|
|
|
struct config_item *tmp;
|
|
|
|
int j;
|
|
|
|
|
|
|
|
for (j = 0; cl->group.default_groups[j]; j++) {
|
|
|
|
tmp = &cl->group.default_groups[j]->cg_item;
|
|
|
|
cl->group.default_groups[j] = NULL;
|
|
|
|
config_item_put(tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
space_list = NULL;
|
|
|
|
comm_list = NULL;
|
|
|
|
|
|
|
|
config_item_put(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void release_cluster(struct config_item *i)
|
|
|
|
{
|
2008-09-05 20:42:08 +07:00
|
|
|
struct dlm_cluster *cl = config_item_to_cluster(i);
|
2006-01-18 16:30:29 +07:00
|
|
|
kfree(cl->group.default_groups);
|
|
|
|
kfree(cl);
|
|
|
|
}
|
|
|
|
|
2008-07-18 04:53:48 +07:00
|
|
|
static struct config_group *make_space(struct config_group *g, const char *name)
|
2006-01-18 16:30:29 +07:00
|
|
|
{
|
2008-07-31 21:31:53 +07:00
|
|
|
struct dlm_space *sp = NULL;
|
|
|
|
struct dlm_nodes *nds = NULL;
|
2006-01-18 16:30:29 +07:00
|
|
|
void *gps = NULL;
|
|
|
|
|
2009-12-01 05:34:43 +07:00
|
|
|
sp = kzalloc(sizeof(struct dlm_space), GFP_NOFS);
|
|
|
|
gps = kcalloc(2, sizeof(struct config_group *), GFP_NOFS);
|
|
|
|
nds = kzalloc(sizeof(struct dlm_nodes), GFP_NOFS);
|
2006-01-18 16:30:29 +07:00
|
|
|
|
|
|
|
if (!sp || !gps || !nds)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
config_group_init_type_name(&sp->group, name, &space_type);
|
|
|
|
config_group_init_type_name(&nds->ns_group, "nodes", &nodes_type);
|
|
|
|
|
|
|
|
sp->group.default_groups = gps;
|
|
|
|
sp->group.default_groups[0] = &nds->ns_group;
|
|
|
|
sp->group.default_groups[1] = NULL;
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&sp->members);
|
2006-01-20 15:47:07 +07:00
|
|
|
mutex_init(&sp->members_lock);
|
2006-01-18 16:30:29 +07:00
|
|
|
sp->members_count = 0;
|
2008-07-18 04:53:48 +07:00
|
|
|
return &sp->group;
|
2006-01-18 16:30:29 +07:00
|
|
|
|
|
|
|
fail:
|
|
|
|
kfree(sp);
|
|
|
|
kfree(gps);
|
|
|
|
kfree(nds);
|
2008-07-18 05:21:29 +07:00
|
|
|
return ERR_PTR(-ENOMEM);
|
2006-01-18 16:30:29 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void drop_space(struct config_group *g, struct config_item *i)
|
|
|
|
{
|
2008-09-05 20:42:08 +07:00
|
|
|
struct dlm_space *sp = config_item_to_space(i);
|
2006-01-18 16:30:29 +07:00
|
|
|
struct config_item *tmp;
|
|
|
|
int j;
|
|
|
|
|
|
|
|
/* assert list_empty(&sp->members) */
|
|
|
|
|
|
|
|
for (j = 0; sp->group.default_groups[j]; j++) {
|
|
|
|
tmp = &sp->group.default_groups[j]->cg_item;
|
|
|
|
sp->group.default_groups[j] = NULL;
|
|
|
|
config_item_put(tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
config_item_put(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void release_space(struct config_item *i)
|
|
|
|
{
|
2008-09-05 20:42:08 +07:00
|
|
|
struct dlm_space *sp = config_item_to_space(i);
|
2006-01-18 16:30:29 +07:00
|
|
|
kfree(sp->group.default_groups);
|
|
|
|
kfree(sp);
|
|
|
|
}
|
|
|
|
|
2008-07-18 04:53:48 +07:00
|
|
|
static struct config_item *make_comm(struct config_group *g, const char *name)
|
2006-01-18 16:30:29 +07:00
|
|
|
{
|
2008-07-31 21:31:53 +07:00
|
|
|
struct dlm_comm *cm;
|
2006-01-18 16:30:29 +07:00
|
|
|
|
2009-12-01 05:34:43 +07:00
|
|
|
cm = kzalloc(sizeof(struct dlm_comm), GFP_NOFS);
|
2006-01-18 16:30:29 +07:00
|
|
|
if (!cm)
|
2008-07-18 05:21:29 +07:00
|
|
|
return ERR_PTR(-ENOMEM);
|
2006-01-18 16:30:29 +07:00
|
|
|
|
|
|
|
config_item_init_type_name(&cm->item, name, &comm_type);
|
2011-11-03 02:30:58 +07:00
|
|
|
|
|
|
|
cm->seq = dlm_comm_count++;
|
|
|
|
if (!cm->seq)
|
|
|
|
cm->seq = dlm_comm_count++;
|
|
|
|
|
2006-01-18 16:30:29 +07:00
|
|
|
cm->nodeid = -1;
|
|
|
|
cm->local = 0;
|
|
|
|
cm->addr_count = 0;
|
2008-07-18 04:53:48 +07:00
|
|
|
return &cm->item;
|
2006-01-18 16:30:29 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void drop_comm(struct config_group *g, struct config_item *i)
|
|
|
|
{
|
2008-09-05 20:42:08 +07:00
|
|
|
struct dlm_comm *cm = config_item_to_comm(i);
|
2006-01-18 16:30:29 +07:00
|
|
|
if (local_comm == cm)
|
|
|
|
local_comm = NULL;
|
2006-04-28 21:50:41 +07:00
|
|
|
dlm_lowcomms_close(cm->nodeid);
|
2006-01-18 16:30:29 +07:00
|
|
|
while (cm->addr_count--)
|
|
|
|
kfree(cm->addr[cm->addr_count]);
|
|
|
|
config_item_put(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void release_comm(struct config_item *i)
|
|
|
|
{
|
2008-09-05 20:42:08 +07:00
|
|
|
struct dlm_comm *cm = config_item_to_comm(i);
|
2006-01-18 16:30:29 +07:00
|
|
|
kfree(cm);
|
|
|
|
}
|
|
|
|
|
2008-07-18 04:53:48 +07:00
|
|
|
static struct config_item *make_node(struct config_group *g, const char *name)
|
2006-01-18 16:30:29 +07:00
|
|
|
{
|
2008-09-05 20:42:08 +07:00
|
|
|
struct dlm_space *sp = config_item_to_space(g->cg_item.ci_parent);
|
2008-07-31 21:31:53 +07:00
|
|
|
struct dlm_node *nd;
|
2006-01-18 16:30:29 +07:00
|
|
|
|
2009-12-01 05:34:43 +07:00
|
|
|
nd = kzalloc(sizeof(struct dlm_node), GFP_NOFS);
|
2006-01-18 16:30:29 +07:00
|
|
|
if (!nd)
|
2008-07-18 05:21:29 +07:00
|
|
|
return ERR_PTR(-ENOMEM);
|
2006-01-18 16:30:29 +07:00
|
|
|
|
|
|
|
config_item_init_type_name(&nd->item, name, &node_type);
|
|
|
|
nd->nodeid = -1;
|
|
|
|
nd->weight = 1; /* default weight of 1 if none is set */
|
2008-03-19 02:22:11 +07:00
|
|
|
nd->new = 1; /* set to 0 once it's been read by dlm_nodeid_list() */
|
2006-01-18 16:30:29 +07:00
|
|
|
|
2006-01-20 15:47:07 +07:00
|
|
|
mutex_lock(&sp->members_lock);
|
2006-01-18 16:30:29 +07:00
|
|
|
list_add(&nd->list, &sp->members);
|
|
|
|
sp->members_count++;
|
2006-01-20 15:47:07 +07:00
|
|
|
mutex_unlock(&sp->members_lock);
|
2006-01-18 16:30:29 +07:00
|
|
|
|
2008-07-18 04:53:48 +07:00
|
|
|
return &nd->item;
|
2006-01-18 16:30:29 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void drop_node(struct config_group *g, struct config_item *i)
|
|
|
|
{
|
2008-09-05 20:42:08 +07:00
|
|
|
struct dlm_space *sp = config_item_to_space(g->cg_item.ci_parent);
|
|
|
|
struct dlm_node *nd = config_item_to_node(i);
|
2006-01-18 16:30:29 +07:00
|
|
|
|
2006-01-20 15:47:07 +07:00
|
|
|
mutex_lock(&sp->members_lock);
|
2006-01-18 16:30:29 +07:00
|
|
|
list_del(&nd->list);
|
|
|
|
sp->members_count--;
|
2006-01-20 15:47:07 +07:00
|
|
|
mutex_unlock(&sp->members_lock);
|
2006-01-18 16:30:29 +07:00
|
|
|
|
|
|
|
config_item_put(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void release_node(struct config_item *i)
|
|
|
|
{
|
2008-09-05 20:42:08 +07:00
|
|
|
struct dlm_node *nd = config_item_to_node(i);
|
2006-01-18 16:30:29 +07:00
|
|
|
kfree(nd);
|
|
|
|
}
|
|
|
|
|
2008-07-31 21:31:53 +07:00
|
|
|
static struct dlm_clusters clusters_root = {
|
2006-01-18 16:30:29 +07:00
|
|
|
.subsys = {
|
|
|
|
.su_group = {
|
|
|
|
.cg_item = {
|
|
|
|
.ci_namebuf = "dlm",
|
|
|
|
.ci_type = &clusters_type,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2008-02-02 00:53:46 +07:00
|
|
|
int __init dlm_config_init(void)
|
2006-01-18 16:30:29 +07:00
|
|
|
{
|
|
|
|
config_group_init(&clusters_root.subsys.su_group);
|
2007-07-07 13:33:17 +07:00
|
|
|
mutex_init(&clusters_root.subsys.su_mutex);
|
2006-01-18 16:30:29 +07:00
|
|
|
return configfs_register_subsystem(&clusters_root.subsys);
|
|
|
|
}
|
|
|
|
|
|
|
|
void dlm_config_exit(void)
|
|
|
|
{
|
|
|
|
configfs_unregister_subsystem(&clusters_root.subsys);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Functions for user space to read/write attributes
|
|
|
|
*/
|
|
|
|
|
2007-01-09 22:46:02 +07:00
|
|
|
static ssize_t show_cluster(struct config_item *i, struct configfs_attribute *a,
|
|
|
|
char *buf)
|
|
|
|
{
|
2008-09-05 20:42:08 +07:00
|
|
|
struct dlm_cluster *cl = config_item_to_cluster(i);
|
2007-01-09 22:46:02 +07:00
|
|
|
struct cluster_attribute *cla =
|
|
|
|
container_of(a, struct cluster_attribute, attr);
|
|
|
|
return cla->show ? cla->show(cl, buf) : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t store_cluster(struct config_item *i,
|
|
|
|
struct configfs_attribute *a,
|
|
|
|
const char *buf, size_t len)
|
|
|
|
{
|
2008-09-05 20:42:08 +07:00
|
|
|
struct dlm_cluster *cl = config_item_to_cluster(i);
|
2007-01-09 22:46:02 +07:00
|
|
|
struct cluster_attribute *cla =
|
|
|
|
container_of(a, struct cluster_attribute, attr);
|
|
|
|
return cla->store ? cla->store(cl, buf, len) : -EINVAL;
|
|
|
|
}
|
|
|
|
|
2006-01-18 16:30:29 +07:00
|
|
|
static ssize_t show_comm(struct config_item *i, struct configfs_attribute *a,
|
|
|
|
char *buf)
|
|
|
|
{
|
2008-09-05 20:42:08 +07:00
|
|
|
struct dlm_comm *cm = config_item_to_comm(i);
|
2006-01-18 16:30:29 +07:00
|
|
|
struct comm_attribute *cma =
|
|
|
|
container_of(a, struct comm_attribute, attr);
|
|
|
|
return cma->show ? cma->show(cm, buf) : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t store_comm(struct config_item *i, struct configfs_attribute *a,
|
|
|
|
const char *buf, size_t len)
|
|
|
|
{
|
2008-09-05 20:42:08 +07:00
|
|
|
struct dlm_comm *cm = config_item_to_comm(i);
|
2006-01-18 16:30:29 +07:00
|
|
|
struct comm_attribute *cma =
|
|
|
|
container_of(a, struct comm_attribute, attr);
|
|
|
|
return cma->store ? cma->store(cm, buf, len) : -EINVAL;
|
|
|
|
}
|
|
|
|
|
2008-07-31 21:31:53 +07:00
|
|
|
static ssize_t comm_nodeid_read(struct dlm_comm *cm, char *buf)
|
2006-01-18 16:30:29 +07:00
|
|
|
{
|
|
|
|
return sprintf(buf, "%d\n", cm->nodeid);
|
|
|
|
}
|
|
|
|
|
2008-07-31 21:31:53 +07:00
|
|
|
static ssize_t comm_nodeid_write(struct dlm_comm *cm, const char *buf,
|
|
|
|
size_t len)
|
2006-01-18 16:30:29 +07:00
|
|
|
{
|
2014-06-07 04:38:24 +07:00
|
|
|
int rc = kstrtoint(buf, 0, &cm->nodeid);
|
|
|
|
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
2006-01-18 16:30:29 +07:00
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2008-07-31 21:31:53 +07:00
|
|
|
static ssize_t comm_local_read(struct dlm_comm *cm, char *buf)
|
2006-01-18 16:30:29 +07:00
|
|
|
{
|
|
|
|
return sprintf(buf, "%d\n", cm->local);
|
|
|
|
}
|
|
|
|
|
2008-07-31 21:31:53 +07:00
|
|
|
static ssize_t comm_local_write(struct dlm_comm *cm, const char *buf,
|
|
|
|
size_t len)
|
2006-01-18 16:30:29 +07:00
|
|
|
{
|
2014-06-07 04:38:24 +07:00
|
|
|
int rc = kstrtoint(buf, 0, &cm->local);
|
|
|
|
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
2006-01-18 16:30:29 +07:00
|
|
|
if (cm->local && !local_comm)
|
|
|
|
local_comm = cm;
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2008-07-31 21:31:53 +07:00
|
|
|
static ssize_t comm_addr_write(struct dlm_comm *cm, const char *buf, size_t len)
|
2006-01-18 16:30:29 +07:00
|
|
|
{
|
|
|
|
struct sockaddr_storage *addr;
|
2012-07-27 00:44:30 +07:00
|
|
|
int rv;
|
2006-01-18 16:30:29 +07:00
|
|
|
|
|
|
|
if (len != sizeof(struct sockaddr_storage))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (cm->addr_count >= DLM_MAX_ADDR_COUNT)
|
|
|
|
return -ENOSPC;
|
|
|
|
|
2009-12-01 05:34:43 +07:00
|
|
|
addr = kzalloc(sizeof(*addr), GFP_NOFS);
|
2006-01-18 16:30:29 +07:00
|
|
|
if (!addr)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
memcpy(addr, buf, len);
|
2012-07-27 00:44:30 +07:00
|
|
|
|
|
|
|
rv = dlm_lowcomms_addr(cm->nodeid, addr, len);
|
|
|
|
if (rv) {
|
|
|
|
kfree(addr);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2006-01-18 16:30:29 +07:00
|
|
|
cm->addr[cm->addr_count++] = addr;
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2011-06-30 19:37:10 +07:00
|
|
|
static ssize_t comm_addr_list_read(struct dlm_comm *cm, char *buf)
|
|
|
|
{
|
|
|
|
ssize_t s;
|
|
|
|
ssize_t allowance;
|
|
|
|
int i;
|
|
|
|
struct sockaddr_storage *addr;
|
|
|
|
struct sockaddr_in *addr_in;
|
|
|
|
struct sockaddr_in6 *addr_in6;
|
|
|
|
|
|
|
|
/* Taken from ip6_addr_string() defined in lib/vsprintf.c */
|
|
|
|
char buf0[sizeof("AF_INET6 xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255\n")];
|
|
|
|
|
|
|
|
|
|
|
|
/* Derived from SIMPLE_ATTR_SIZE of fs/configfs/file.c */
|
|
|
|
allowance = 4096;
|
|
|
|
buf[0] = '\0';
|
|
|
|
|
|
|
|
for (i = 0; i < cm->addr_count; i++) {
|
|
|
|
addr = cm->addr[i];
|
|
|
|
|
|
|
|
switch(addr->ss_family) {
|
|
|
|
case AF_INET:
|
|
|
|
addr_in = (struct sockaddr_in *)addr;
|
|
|
|
s = sprintf(buf0, "AF_INET %pI4\n", &addr_in->sin_addr.s_addr);
|
|
|
|
break;
|
|
|
|
case AF_INET6:
|
|
|
|
addr_in6 = (struct sockaddr_in6 *)addr;
|
|
|
|
s = sprintf(buf0, "AF_INET6 %pI6\n", &addr_in6->sin6_addr);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
s = sprintf(buf0, "%s\n", "<UNKNOWN>");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
allowance -= s;
|
|
|
|
if (allowance >= 0)
|
|
|
|
strcat(buf, buf0);
|
|
|
|
else {
|
|
|
|
allowance += s;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 4096 - allowance;
|
|
|
|
}
|
|
|
|
|
2006-01-18 16:30:29 +07:00
|
|
|
static ssize_t show_node(struct config_item *i, struct configfs_attribute *a,
|
|
|
|
char *buf)
|
|
|
|
{
|
2008-09-05 20:42:08 +07:00
|
|
|
struct dlm_node *nd = config_item_to_node(i);
|
2006-01-18 16:30:29 +07:00
|
|
|
struct node_attribute *nda =
|
|
|
|
container_of(a, struct node_attribute, attr);
|
|
|
|
return nda->show ? nda->show(nd, buf) : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t store_node(struct config_item *i, struct configfs_attribute *a,
|
|
|
|
const char *buf, size_t len)
|
|
|
|
{
|
2008-09-05 20:42:08 +07:00
|
|
|
struct dlm_node *nd = config_item_to_node(i);
|
2006-01-18 16:30:29 +07:00
|
|
|
struct node_attribute *nda =
|
|
|
|
container_of(a, struct node_attribute, attr);
|
|
|
|
return nda->store ? nda->store(nd, buf, len) : -EINVAL;
|
|
|
|
}
|
|
|
|
|
2008-07-31 21:31:53 +07:00
|
|
|
static ssize_t node_nodeid_read(struct dlm_node *nd, char *buf)
|
2006-01-18 16:30:29 +07:00
|
|
|
{
|
|
|
|
return sprintf(buf, "%d\n", nd->nodeid);
|
|
|
|
}
|
|
|
|
|
2008-07-31 21:31:53 +07:00
|
|
|
static ssize_t node_nodeid_write(struct dlm_node *nd, const char *buf,
|
|
|
|
size_t len)
|
2006-01-18 16:30:29 +07:00
|
|
|
{
|
2011-11-03 02:30:58 +07:00
|
|
|
uint32_t seq = 0;
|
2014-06-07 04:38:24 +07:00
|
|
|
int rc = kstrtoint(buf, 0, &nd->nodeid);
|
|
|
|
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
2011-11-03 02:30:58 +07:00
|
|
|
dlm_comm_seq(nd->nodeid, &seq);
|
|
|
|
nd->comm_seq = seq;
|
2006-01-18 16:30:29 +07:00
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2008-07-31 21:31:53 +07:00
|
|
|
static ssize_t node_weight_read(struct dlm_node *nd, char *buf)
|
2006-01-18 16:30:29 +07:00
|
|
|
{
|
|
|
|
return sprintf(buf, "%d\n", nd->weight);
|
|
|
|
}
|
|
|
|
|
2008-07-31 21:31:53 +07:00
|
|
|
static ssize_t node_weight_write(struct dlm_node *nd, const char *buf,
|
|
|
|
size_t len)
|
2006-01-18 16:30:29 +07:00
|
|
|
{
|
2014-06-07 04:38:24 +07:00
|
|
|
int rc = kstrtoint(buf, 0, &nd->weight);
|
|
|
|
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
2006-01-18 16:30:29 +07:00
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Functions for the dlm to get the info that's been configured
|
|
|
|
*/
|
|
|
|
|
2008-07-31 21:31:53 +07:00
|
|
|
static struct dlm_space *get_space(char *name)
|
2006-01-18 16:30:29 +07:00
|
|
|
{
|
2007-05-08 15:18:58 +07:00
|
|
|
struct config_item *i;
|
|
|
|
|
2006-01-18 16:30:29 +07:00
|
|
|
if (!space_list)
|
|
|
|
return NULL;
|
2007-05-08 15:18:58 +07:00
|
|
|
|
2007-07-07 13:33:17 +07:00
|
|
|
mutex_lock(&space_list->cg_subsys->su_mutex);
|
[PATCH] configfs+dlm: Rename config_group_find_obj and state semantics clearly
Configfs being based upon sysfs code, config_group_find_obj() is probably
so named because of the similar kset_find_obj() in sysfs. However,
"kobject"s in sysfs become "config_item"s in configfs, so let's call it
config_group_find_item() instead, for sake of uniformity, and make
corresponding change in the users of this function.
BTW a crucial difference between kset_find_obj and config_group_find_item
is in locking expectations. kset_find_obj does its locking by itself, but
config_group_find_item expects the *caller* to do the locking. The reason
for this: kset's have their own locks, config_group's don't but instead
rely on the subsystem mutex. And, subsystem needn't necessarily be around
when config_group_find_item() is called.
So let's state these locking semantics explicitly, and rectify the comment,
otherwise bugs could continue to occur in future, as they did in the past
(refer commit d82b8191e238 in gfs2-2.6-fixes.git).
[ I also took the opportunity to fix some bad whitespace and
double-empty lines. --Joel ]
[ Conflict in fs/dlm/config.c with commit
3168b0780d06ace875696f8a648d04d6089654e5 manually resolved. --Mark ]
Signed-off-by: Satyam Sharma <ssatyam@cse.iitk.ac.in>
Cc: David Teigland <teigland@redhat.com>
Signed-off-by: Joel Becker <joel.becker@oracle.com>
Signed-off-by: Mark Fasheh <mark.fasheh@oracle.com>
2007-07-04 18:07:16 +07:00
|
|
|
i = config_group_find_item(space_list, name);
|
2007-07-07 13:33:17 +07:00
|
|
|
mutex_unlock(&space_list->cg_subsys->su_mutex);
|
2007-05-08 15:18:58 +07:00
|
|
|
|
2008-09-05 20:42:08 +07:00
|
|
|
return config_item_to_space(i);
|
2006-01-18 16:30:29 +07:00
|
|
|
}
|
|
|
|
|
2008-07-31 21:31:53 +07:00
|
|
|
static void put_space(struct dlm_space *sp)
|
2006-01-18 16:30:29 +07:00
|
|
|
{
|
|
|
|
config_item_put(&sp->group.cg_item);
|
|
|
|
}
|
|
|
|
|
2012-07-27 00:44:30 +07:00
|
|
|
static struct dlm_comm *get_comm(int nodeid)
|
2006-01-18 16:30:29 +07:00
|
|
|
{
|
|
|
|
struct config_item *i;
|
2008-07-31 21:31:53 +07:00
|
|
|
struct dlm_comm *cm = NULL;
|
2006-01-18 16:30:29 +07:00
|
|
|
int found = 0;
|
|
|
|
|
|
|
|
if (!comm_list)
|
|
|
|
return NULL;
|
|
|
|
|
2007-07-07 13:33:17 +07:00
|
|
|
mutex_lock(&clusters_root.subsys.su_mutex);
|
2006-01-18 16:30:29 +07:00
|
|
|
|
|
|
|
list_for_each_entry(i, &comm_list->cg_children, ci_entry) {
|
2008-09-05 20:42:08 +07:00
|
|
|
cm = config_item_to_comm(i);
|
2006-01-18 16:30:29 +07:00
|
|
|
|
2012-07-27 00:44:30 +07:00
|
|
|
if (cm->nodeid != nodeid)
|
|
|
|
continue;
|
|
|
|
found = 1;
|
|
|
|
config_item_get(i);
|
|
|
|
break;
|
2006-01-18 16:30:29 +07:00
|
|
|
}
|
2007-07-07 13:33:17 +07:00
|
|
|
mutex_unlock(&clusters_root.subsys.su_mutex);
|
2006-01-18 16:30:29 +07:00
|
|
|
|
2007-05-08 15:18:58 +07:00
|
|
|
if (!found)
|
2006-01-18 16:30:29 +07:00
|
|
|
cm = NULL;
|
|
|
|
return cm;
|
|
|
|
}
|
|
|
|
|
2008-07-31 21:31:53 +07:00
|
|
|
static void put_comm(struct dlm_comm *cm)
|
2006-01-18 16:30:29 +07:00
|
|
|
{
|
|
|
|
config_item_put(&cm->item);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* caller must free mem */
|
2011-11-03 02:30:58 +07:00
|
|
|
int dlm_config_nodes(char *lsname, struct dlm_config_node **nodes_out,
|
|
|
|
int *count_out)
|
2006-01-18 16:30:29 +07:00
|
|
|
{
|
2008-07-31 21:31:53 +07:00
|
|
|
struct dlm_space *sp;
|
|
|
|
struct dlm_node *nd;
|
2011-11-03 02:30:58 +07:00
|
|
|
struct dlm_config_node *nodes, *node;
|
|
|
|
int rv, count;
|
2006-01-18 16:30:29 +07:00
|
|
|
|
|
|
|
sp = get_space(lsname);
|
|
|
|
if (!sp)
|
|
|
|
return -EEXIST;
|
|
|
|
|
2006-01-20 15:47:07 +07:00
|
|
|
mutex_lock(&sp->members_lock);
|
2006-01-18 16:30:29 +07:00
|
|
|
if (!sp->members_count) {
|
2008-03-19 02:22:11 +07:00
|
|
|
rv = -EINVAL;
|
|
|
|
printk(KERN_ERR "dlm: zero members_count\n");
|
2006-01-18 16:30:29 +07:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2011-11-03 02:30:58 +07:00
|
|
|
count = sp->members_count;
|
2008-03-19 02:22:11 +07:00
|
|
|
|
2011-11-03 02:30:58 +07:00
|
|
|
nodes = kcalloc(count, sizeof(struct dlm_config_node), GFP_NOFS);
|
|
|
|
if (!nodes) {
|
2006-01-18 16:30:29 +07:00
|
|
|
rv = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2011-11-03 02:30:58 +07:00
|
|
|
node = nodes;
|
2008-03-19 02:22:11 +07:00
|
|
|
list_for_each_entry(nd, &sp->members, list) {
|
2011-11-03 02:30:58 +07:00
|
|
|
node->nodeid = nd->nodeid;
|
|
|
|
node->weight = nd->weight;
|
|
|
|
node->new = nd->new;
|
|
|
|
node->comm_seq = nd->comm_seq;
|
|
|
|
node++;
|
2008-03-19 02:22:11 +07:00
|
|
|
|
2011-11-03 02:30:58 +07:00
|
|
|
nd->new = 0;
|
2008-03-19 02:22:11 +07:00
|
|
|
}
|
2006-01-18 16:30:29 +07:00
|
|
|
|
2011-11-03 02:30:58 +07:00
|
|
|
*count_out = count;
|
|
|
|
*nodes_out = nodes;
|
|
|
|
rv = 0;
|
2006-01-18 16:30:29 +07:00
|
|
|
out:
|
2006-01-20 15:47:07 +07:00
|
|
|
mutex_unlock(&sp->members_lock);
|
2006-01-18 16:30:29 +07:00
|
|
|
put_space(sp);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2011-11-03 02:30:58 +07:00
|
|
|
int dlm_comm_seq(int nodeid, uint32_t *seq)
|
2006-01-18 16:30:29 +07:00
|
|
|
{
|
2012-07-27 00:44:30 +07:00
|
|
|
struct dlm_comm *cm = get_comm(nodeid);
|
2011-11-03 02:30:58 +07:00
|
|
|
if (!cm)
|
|
|
|
return -EEXIST;
|
|
|
|
*seq = cm->seq;
|
|
|
|
put_comm(cm);
|
|
|
|
return 0;
|
2006-01-18 16:30:29 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
int dlm_our_nodeid(void)
|
|
|
|
{
|
|
|
|
return local_comm ? local_comm->nodeid : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* num 0 is first addr, num 1 is second addr */
|
|
|
|
int dlm_our_addr(struct sockaddr_storage *addr, int num)
|
|
|
|
{
|
|
|
|
if (!local_comm)
|
|
|
|
return -1;
|
|
|
|
if (num + 1 > local_comm->addr_count)
|
|
|
|
return -1;
|
|
|
|
memcpy(addr, local_comm->addr[num], sizeof(*addr));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Config file defaults */
|
|
|
|
#define DEFAULT_TCP_PORT 21064
|
|
|
|
#define DEFAULT_BUFFER_SIZE 4096
|
2011-03-11 02:07:17 +07:00
|
|
|
#define DEFAULT_RSBTBL_SIZE 1024
|
2006-01-18 16:30:29 +07:00
|
|
|
#define DEFAULT_RECOVER_TIMER 5
|
|
|
|
#define DEFAULT_TOSS_SECS 10
|
|
|
|
#define DEFAULT_SCAN_SECS 5
|
2007-01-09 22:44:01 +07:00
|
|
|
#define DEFAULT_LOG_DEBUG 0
|
2007-04-17 21:39:57 +07:00
|
|
|
#define DEFAULT_PROTOCOL 0
|
2007-05-18 20:59:31 +07:00
|
|
|
#define DEFAULT_TIMEWARN_CS 500 /* 5 sec = 500 centiseconds */
|
2011-03-29 02:17:26 +07:00
|
|
|
#define DEFAULT_WAITWARN_US 0
|
2011-07-08 02:05:03 +07:00
|
|
|
#define DEFAULT_NEW_RSB_COUNT 128
|
2011-11-03 02:30:58 +07:00
|
|
|
#define DEFAULT_RECOVER_CALLBACKS 0
|
|
|
|
#define DEFAULT_CLUSTER_NAME ""
|
2006-01-18 16:30:29 +07:00
|
|
|
|
|
|
|
struct dlm_config_info dlm_config = {
|
2007-01-09 22:41:48 +07:00
|
|
|
.ci_tcp_port = DEFAULT_TCP_PORT,
|
|
|
|
.ci_buffer_size = DEFAULT_BUFFER_SIZE,
|
|
|
|
.ci_rsbtbl_size = DEFAULT_RSBTBL_SIZE,
|
|
|
|
.ci_recover_timer = DEFAULT_RECOVER_TIMER,
|
|
|
|
.ci_toss_secs = DEFAULT_TOSS_SECS,
|
2007-01-09 22:44:01 +07:00
|
|
|
.ci_scan_secs = DEFAULT_SCAN_SECS,
|
2007-04-17 21:39:57 +07:00
|
|
|
.ci_log_debug = DEFAULT_LOG_DEBUG,
|
2007-05-18 20:59:31 +07:00
|
|
|
.ci_protocol = DEFAULT_PROTOCOL,
|
2011-03-29 02:17:26 +07:00
|
|
|
.ci_timewarn_cs = DEFAULT_TIMEWARN_CS,
|
2011-07-08 02:05:03 +07:00
|
|
|
.ci_waitwarn_us = DEFAULT_WAITWARN_US,
|
2011-11-03 02:30:58 +07:00
|
|
|
.ci_new_rsb_count = DEFAULT_NEW_RSB_COUNT,
|
|
|
|
.ci_recover_callbacks = DEFAULT_RECOVER_CALLBACKS,
|
|
|
|
.ci_cluster_name = DEFAULT_CLUSTER_NAME
|
2006-01-18 16:30:29 +07:00
|
|
|
};
|
|
|
|
|