blob: a7336b909c61730432184e3fa622fa4130474066 [file] [log] [blame]
David Teigland869d81d2006-01-17 08:47:12 +00001/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
4 *
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
Steven Whitehousee9fc2aa2006-09-01 11:05:15 -04007 * of the GNU General Public License version 2.
David Teigland869d81d2006-01-17 08:47:12 +00008 */
David Teigland29b79982006-01-16 16:52:38 +00009
10#include <linux/ctype.h>
11#include <linux/stat.h>
12
13#include "lock_dlm.h"
14
David Teigland869d81d2006-01-17 08:47:12 +000015extern struct lm_lockops gdlm_ops;
16
17static ssize_t proto_name_show(struct gdlm_ls *ls, char *buf)
18{
19 return sprintf(buf, "%s\n", gdlm_ops.lm_proto_name);
20}
21
22static ssize_t block_show(struct gdlm_ls *ls, char *buf)
David Teigland29b79982006-01-16 16:52:38 +000023{
24 ssize_t ret;
25 int val = 0;
26
27 if (test_bit(DFL_BLOCK_LOCKS, &ls->flags))
28 val = 1;
29 ret = sprintf(buf, "%d\n", val);
30 return ret;
31}
32
David Teigland869d81d2006-01-17 08:47:12 +000033static ssize_t block_store(struct gdlm_ls *ls, const char *buf, size_t len)
David Teigland29b79982006-01-16 16:52:38 +000034{
35 ssize_t ret = len;
36 int val;
37
38 val = simple_strtol(buf, NULL, 0);
39
40 if (val == 1)
41 set_bit(DFL_BLOCK_LOCKS, &ls->flags);
42 else if (val == 0) {
43 clear_bit(DFL_BLOCK_LOCKS, &ls->flags);
44 gdlm_submit_delayed(ls);
Steven Whitehouse62f140c2006-09-07 09:54:55 -040045 } else {
David Teigland29b79982006-01-16 16:52:38 +000046 ret = -EINVAL;
Steven Whitehouse62f140c2006-09-07 09:54:55 -040047 }
David Teigland29b79982006-01-16 16:52:38 +000048 return ret;
49}
50
David Teigland869d81d2006-01-17 08:47:12 +000051static ssize_t withdraw_show(struct gdlm_ls *ls, char *buf)
David Teigland29b79982006-01-16 16:52:38 +000052{
53 ssize_t ret;
54 int val = 0;
55
56 if (test_bit(DFL_WITHDRAW, &ls->flags))
57 val = 1;
58 ret = sprintf(buf, "%d\n", val);
59 return ret;
60}
61
David Teigland869d81d2006-01-17 08:47:12 +000062static ssize_t withdraw_store(struct gdlm_ls *ls, const char *buf, size_t len)
David Teigland29b79982006-01-16 16:52:38 +000063{
64 ssize_t ret = len;
65 int val;
66
67 val = simple_strtol(buf, NULL, 0);
68
69 if (val == 1)
70 set_bit(DFL_WITHDRAW, &ls->flags);
71 else
72 ret = -EINVAL;
73 wake_up(&ls->wait_control);
74 return ret;
75}
76
David Teigland869d81d2006-01-17 08:47:12 +000077static ssize_t id_show(struct gdlm_ls *ls, char *buf)
David Teigland29b79982006-01-16 16:52:38 +000078{
David Teigland869d81d2006-01-17 08:47:12 +000079 return sprintf(buf, "%u\n", ls->id);
David Teigland29b79982006-01-16 16:52:38 +000080}
81
David Teigland869d81d2006-01-17 08:47:12 +000082static ssize_t jid_show(struct gdlm_ls *ls, char *buf)
David Teigland29b79982006-01-16 16:52:38 +000083{
David Teigland869d81d2006-01-17 08:47:12 +000084 return sprintf(buf, "%d\n", ls->jid);
David Teigland29b79982006-01-16 16:52:38 +000085}
86
David Teigland869d81d2006-01-17 08:47:12 +000087static ssize_t first_show(struct gdlm_ls *ls, char *buf)
David Teigland29b79982006-01-16 16:52:38 +000088{
David Teigland869d81d2006-01-17 08:47:12 +000089 return sprintf(buf, "%d\n", ls->first);
David Teigland29b79982006-01-16 16:52:38 +000090}
91
David Teigland869d81d2006-01-17 08:47:12 +000092static ssize_t first_done_show(struct gdlm_ls *ls, char *buf)
David Teigland29b79982006-01-16 16:52:38 +000093{
94 return sprintf(buf, "%d\n", ls->first_done);
95}
96
David Teigland869d81d2006-01-17 08:47:12 +000097static ssize_t recover_show(struct gdlm_ls *ls, char *buf)
David Teigland29b79982006-01-16 16:52:38 +000098{
David Teigland869d81d2006-01-17 08:47:12 +000099 return sprintf(buf, "%d\n", ls->recover_jid);
David Teigland29b79982006-01-16 16:52:38 +0000100}
101
David Teigland869d81d2006-01-17 08:47:12 +0000102static ssize_t recover_store(struct gdlm_ls *ls, const char *buf, size_t len)
David Teigland29b79982006-01-16 16:52:38 +0000103{
104 ls->recover_jid = simple_strtol(buf, NULL, 0);
Steven Whitehouse1c089c32006-09-07 15:50:20 -0400105 ls->fscb(ls->sdp, LM_CB_NEED_RECOVERY, &ls->recover_jid);
David Teigland29b79982006-01-16 16:52:38 +0000106 return len;
107}
108
David Teigland869d81d2006-01-17 08:47:12 +0000109static ssize_t recover_done_show(struct gdlm_ls *ls, char *buf)
David Teigland29b79982006-01-16 16:52:38 +0000110{
David Teigland869d81d2006-01-17 08:47:12 +0000111 return sprintf(buf, "%d\n", ls->recover_jid_done);
David Teigland29b79982006-01-16 16:52:38 +0000112}
113
David Teigland6bd70ab2006-04-26 15:56:35 -0400114static ssize_t recover_status_show(struct gdlm_ls *ls, char *buf)
115{
116 return sprintf(buf, "%d\n", ls->recover_jid_status);
117}
118
David Teiglandee32e4f2007-01-25 14:24:04 -0600119static ssize_t drop_count_show(struct gdlm_ls *ls, char *buf)
120{
121 return sprintf(buf, "%d\n", ls->drop_locks_count);
122}
123
124static ssize_t drop_count_store(struct gdlm_ls *ls, const char *buf, size_t len)
125{
126 ls->drop_locks_count = simple_strtol(buf, NULL, 0);
127 return len;
128}
129
David Teigland29b79982006-01-16 16:52:38 +0000130struct gdlm_attr {
131 struct attribute attr;
132 ssize_t (*show)(struct gdlm_ls *, char *);
133 ssize_t (*store)(struct gdlm_ls *, const char *, size_t);
134};
135
David Teigland869d81d2006-01-17 08:47:12 +0000136#define GDLM_ATTR(_name,_mode,_show,_store) \
137static struct gdlm_attr gdlm_attr_##_name = __ATTR(_name,_mode,_show,_store)
David Teigland29b79982006-01-16 16:52:38 +0000138
David Teigland6bd70ab2006-04-26 15:56:35 -0400139GDLM_ATTR(proto_name, 0444, proto_name_show, NULL);
140GDLM_ATTR(block, 0644, block_show, block_store);
141GDLM_ATTR(withdraw, 0644, withdraw_show, withdraw_store);
142GDLM_ATTR(id, 0444, id_show, NULL);
143GDLM_ATTR(jid, 0444, jid_show, NULL);
144GDLM_ATTR(first, 0444, first_show, NULL);
145GDLM_ATTR(first_done, 0444, first_done_show, NULL);
146GDLM_ATTR(recover, 0644, recover_show, recover_store);
147GDLM_ATTR(recover_done, 0444, recover_done_show, NULL);
148GDLM_ATTR(recover_status, 0444, recover_status_show, NULL);
David Teiglandee32e4f2007-01-25 14:24:04 -0600149GDLM_ATTR(drop_count, 0644, drop_count_show, drop_count_store);
David Teigland29b79982006-01-16 16:52:38 +0000150
151static struct attribute *gdlm_attrs[] = {
David Teigland869d81d2006-01-17 08:47:12 +0000152 &gdlm_attr_proto_name.attr,
David Teigland29b79982006-01-16 16:52:38 +0000153 &gdlm_attr_block.attr,
David Teigland29b79982006-01-16 16:52:38 +0000154 &gdlm_attr_withdraw.attr,
David Teigland869d81d2006-01-17 08:47:12 +0000155 &gdlm_attr_id.attr,
David Teigland29b79982006-01-16 16:52:38 +0000156 &gdlm_attr_jid.attr,
157 &gdlm_attr_first.attr,
158 &gdlm_attr_first_done.attr,
159 &gdlm_attr_recover.attr,
160 &gdlm_attr_recover_done.attr,
David Teigland6bd70ab2006-04-26 15:56:35 -0400161 &gdlm_attr_recover_status.attr,
David Teiglandee32e4f2007-01-25 14:24:04 -0600162 &gdlm_attr_drop_count.attr,
David Teigland29b79982006-01-16 16:52:38 +0000163 NULL,
164};
165
166static ssize_t gdlm_attr_show(struct kobject *kobj, struct attribute *attr,
167 char *buf)
168{
169 struct gdlm_ls *ls = container_of(kobj, struct gdlm_ls, kobj);
170 struct gdlm_attr *a = container_of(attr, struct gdlm_attr, attr);
171 return a->show ? a->show(ls, buf) : 0;
172}
173
174static ssize_t gdlm_attr_store(struct kobject *kobj, struct attribute *attr,
175 const char *buf, size_t len)
176{
177 struct gdlm_ls *ls = container_of(kobj, struct gdlm_ls, kobj);
178 struct gdlm_attr *a = container_of(attr, struct gdlm_attr, attr);
179 return a->store ? a->store(ls, buf, len) : len;
180}
181
182static struct sysfs_ops gdlm_attr_ops = {
183 .show = gdlm_attr_show,
184 .store = gdlm_attr_store,
185};
186
187static struct kobj_type gdlm_ktype = {
188 .default_attrs = gdlm_attrs,
189 .sysfs_ops = &gdlm_attr_ops,
190};
191
Greg Kroah-Hartman136a2752007-10-29 20:13:17 +0100192static struct kset *gdlm_kset;
David Teigland29b79982006-01-16 16:52:38 +0000193
David Teigland869d81d2006-01-17 08:47:12 +0000194int gdlm_kobject_setup(struct gdlm_ls *ls, struct kobject *fskobj)
David Teigland29b79982006-01-16 16:52:38 +0000195{
196 int error;
197
Greg Kroah-Hartman136a2752007-10-29 20:13:17 +0100198 ls->kobj.kset = gdlm_kset;
Greg Kroah-Hartman901195e2007-12-17 15:54:39 -0400199 error = kobject_init_and_add(&ls->kobj, &gdlm_ktype, fskobj,
200 "lock_module");
David Teigland869d81d2006-01-17 08:47:12 +0000201 if (error)
202 log_error("can't register kobj %d", error);
Greg Kroah-Hartman901195e2007-12-17 15:54:39 -0400203 kobject_uevent(&ls->kobj, KOBJ_ADD);
David Teigland29b79982006-01-16 16:52:38 +0000204
David Teigland869d81d2006-01-17 08:47:12 +0000205 return error;
David Teigland29b79982006-01-16 16:52:38 +0000206}
207
208void gdlm_kobject_release(struct gdlm_ls *ls)
209{
210 kobject_unregister(&ls->kobj);
211}
212
213int gdlm_sysfs_init(void)
214{
Greg Kroah-Hartman0ff21e42007-11-06 10:36:58 -0800215 gdlm_kset = kset_create_and_add("lock_dlm", NULL, kernel_kobj);
Greg Kroah-Hartman136a2752007-10-29 20:13:17 +0100216 if (!gdlm_kset) {
217 printk(KERN_WARNING "%s: can not create kset\n", __FUNCTION__);
218 return -ENOMEM;
219 }
220 return 0;
David Teigland29b79982006-01-16 16:52:38 +0000221}
222
223void gdlm_sysfs_exit(void)
224{
Greg Kroah-Hartman136a2752007-10-29 20:13:17 +0100225 kset_unregister(gdlm_kset);
David Teigland29b79982006-01-16 16:52:38 +0000226}
227