2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
7 * of the GNU General Public License version 2.
10 #include <linux/ctype.h>
11 #include <linux/stat.h>
15 extern struct lm_lockops gdlm_ops
;
17 static ssize_t
proto_name_show(struct gdlm_ls
*ls
, char *buf
)
19 return sprintf(buf
, "%s\n", gdlm_ops
.lm_proto_name
);
22 static ssize_t
block_show(struct gdlm_ls
*ls
, char *buf
)
27 if (test_bit(DFL_BLOCK_LOCKS
, &ls
->flags
))
29 ret
= sprintf(buf
, "%d\n", val
);
33 static ssize_t
block_store(struct gdlm_ls
*ls
, const char *buf
, size_t len
)
38 val
= simple_strtol(buf
, NULL
, 0);
41 set_bit(DFL_BLOCK_LOCKS
, &ls
->flags
);
43 clear_bit(DFL_BLOCK_LOCKS
, &ls
->flags
);
44 gdlm_submit_delayed(ls
);
51 static ssize_t
withdraw_show(struct gdlm_ls
*ls
, char *buf
)
56 if (test_bit(DFL_WITHDRAW
, &ls
->flags
))
58 ret
= sprintf(buf
, "%d\n", val
);
62 static ssize_t
withdraw_store(struct gdlm_ls
*ls
, const char *buf
, size_t len
)
67 val
= simple_strtol(buf
, NULL
, 0);
70 set_bit(DFL_WITHDRAW
, &ls
->flags
);
73 wake_up(&ls
->wait_control
);
77 static ssize_t
id_show(struct gdlm_ls
*ls
, char *buf
)
79 return sprintf(buf
, "%u\n", ls
->id
);
82 static ssize_t
jid_show(struct gdlm_ls
*ls
, char *buf
)
84 return sprintf(buf
, "%d\n", ls
->jid
);
87 static ssize_t
first_show(struct gdlm_ls
*ls
, char *buf
)
89 return sprintf(buf
, "%d\n", ls
->first
);
92 static ssize_t
first_done_show(struct gdlm_ls
*ls
, char *buf
)
94 return sprintf(buf
, "%d\n", ls
->first_done
);
97 static ssize_t
recover_show(struct gdlm_ls
*ls
, char *buf
)
99 return sprintf(buf
, "%d\n", ls
->recover_jid
);
102 static ssize_t
recover_store(struct gdlm_ls
*ls
, const char *buf
, size_t len
)
104 ls
->recover_jid
= simple_strtol(buf
, NULL
, 0);
105 ls
->fscb(ls
->sdp
, LM_CB_NEED_RECOVERY
, &ls
->recover_jid
);
109 static ssize_t
recover_done_show(struct gdlm_ls
*ls
, char *buf
)
111 return sprintf(buf
, "%d\n", ls
->recover_jid_done
);
114 static ssize_t
recover_status_show(struct gdlm_ls
*ls
, char *buf
)
116 return sprintf(buf
, "%d\n", ls
->recover_jid_status
);
119 static ssize_t
drop_count_show(struct gdlm_ls
*ls
, char *buf
)
121 return sprintf(buf
, "%d\n", ls
->drop_locks_count
);
124 static ssize_t
drop_count_store(struct gdlm_ls
*ls
, const char *buf
, size_t len
)
126 ls
->drop_locks_count
= simple_strtol(buf
, NULL
, 0);
131 struct attribute attr
;
132 ssize_t (*show
)(struct gdlm_ls
*, char *);
133 ssize_t (*store
)(struct gdlm_ls
*, const char *, size_t);
136 #define GDLM_ATTR(_name,_mode,_show,_store) \
137 static struct gdlm_attr gdlm_attr_##_name = __ATTR(_name,_mode,_show,_store)
139 GDLM_ATTR(proto_name
, 0444, proto_name_show
, NULL
);
140 GDLM_ATTR(block
, 0644, block_show
, block_store
);
141 GDLM_ATTR(withdraw
, 0644, withdraw_show
, withdraw_store
);
142 GDLM_ATTR(id
, 0444, id_show
, NULL
);
143 GDLM_ATTR(jid
, 0444, jid_show
, NULL
);
144 GDLM_ATTR(first
, 0444, first_show
, NULL
);
145 GDLM_ATTR(first_done
, 0444, first_done_show
, NULL
);
146 GDLM_ATTR(recover
, 0644, recover_show
, recover_store
);
147 GDLM_ATTR(recover_done
, 0444, recover_done_show
, NULL
);
148 GDLM_ATTR(recover_status
, 0444, recover_status_show
, NULL
);
149 GDLM_ATTR(drop_count
, 0644, drop_count_show
, drop_count_store
);
151 static struct attribute
*gdlm_attrs
[] = {
152 &gdlm_attr_proto_name
.attr
,
153 &gdlm_attr_block
.attr
,
154 &gdlm_attr_withdraw
.attr
,
157 &gdlm_attr_first
.attr
,
158 &gdlm_attr_first_done
.attr
,
159 &gdlm_attr_recover
.attr
,
160 &gdlm_attr_recover_done
.attr
,
161 &gdlm_attr_recover_status
.attr
,
162 &gdlm_attr_drop_count
.attr
,
166 static ssize_t
gdlm_attr_show(struct kobject
*kobj
, struct attribute
*attr
,
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;
174 static ssize_t
gdlm_attr_store(struct kobject
*kobj
, struct attribute
*attr
,
175 const char *buf
, size_t len
)
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
;
182 static struct sysfs_ops gdlm_attr_ops
= {
183 .show
= gdlm_attr_show
,
184 .store
= gdlm_attr_store
,
187 static struct kobj_type gdlm_ktype
= {
188 .default_attrs
= gdlm_attrs
,
189 .sysfs_ops
= &gdlm_attr_ops
,
192 static struct kset gdlm_kset
= {
193 .kobj
= {.name
= "lock_dlm",},
194 .ktype
= &gdlm_ktype
,
197 int gdlm_kobject_setup(struct gdlm_ls
*ls
, struct kobject
*fskobj
)
201 error
= kobject_set_name(&ls
->kobj
, "%s", "lock_module");
203 log_error("can't set kobj name %d", error
);
207 ls
->kobj
.kset
= &gdlm_kset
;
208 ls
->kobj
.ktype
= &gdlm_ktype
;
209 ls
->kobj
.parent
= fskobj
;
211 error
= kobject_register(&ls
->kobj
);
213 log_error("can't register kobj %d", error
);
218 void gdlm_kobject_release(struct gdlm_ls
*ls
)
220 kobject_unregister(&ls
->kobj
);
223 int gdlm_sysfs_init(void)
227 kobj_set_kset_s(&gdlm_kset
, kernel_subsys
);
228 error
= kset_register(&gdlm_kset
);
230 printk("lock_dlm: cannot register kset %d\n", error
);
235 void gdlm_sysfs_exit(void)
237 kset_unregister(&gdlm_kset
);