David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 1 | /* |
| 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 Whitehouse | e9fc2aa | 2006-09-01 11:05:15 -0400 | [diff] [blame] | 7 | * of the GNU General Public License version 2. |
David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 8 | */ |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 9 | |
| 10 | #include <linux/ctype.h> |
| 11 | #include <linux/stat.h> |
| 12 | |
| 13 | #include "lock_dlm.h" |
| 14 | |
David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 15 | static ssize_t proto_name_show(struct gdlm_ls *ls, char *buf) |
| 16 | { |
| 17 | return sprintf(buf, "%s\n", gdlm_ops.lm_proto_name); |
| 18 | } |
| 19 | |
| 20 | static ssize_t block_show(struct gdlm_ls *ls, char *buf) |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 21 | { |
| 22 | ssize_t ret; |
| 23 | int val = 0; |
| 24 | |
| 25 | if (test_bit(DFL_BLOCK_LOCKS, &ls->flags)) |
| 26 | val = 1; |
| 27 | ret = sprintf(buf, "%d\n", val); |
| 28 | return ret; |
| 29 | } |
| 30 | |
David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 31 | static ssize_t block_store(struct gdlm_ls *ls, const char *buf, size_t len) |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 32 | { |
| 33 | ssize_t ret = len; |
| 34 | int val; |
| 35 | |
| 36 | val = simple_strtol(buf, NULL, 0); |
| 37 | |
| 38 | if (val == 1) |
| 39 | set_bit(DFL_BLOCK_LOCKS, &ls->flags); |
| 40 | else if (val == 0) { |
| 41 | clear_bit(DFL_BLOCK_LOCKS, &ls->flags); |
| 42 | gdlm_submit_delayed(ls); |
Steven Whitehouse | 62f140c | 2006-09-07 09:54:55 -0400 | [diff] [blame] | 43 | } else { |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 44 | ret = -EINVAL; |
Steven Whitehouse | 62f140c | 2006-09-07 09:54:55 -0400 | [diff] [blame] | 45 | } |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 46 | return ret; |
| 47 | } |
| 48 | |
David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 49 | static ssize_t withdraw_show(struct gdlm_ls *ls, char *buf) |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 50 | { |
| 51 | ssize_t ret; |
| 52 | int val = 0; |
| 53 | |
| 54 | if (test_bit(DFL_WITHDRAW, &ls->flags)) |
| 55 | val = 1; |
| 56 | ret = sprintf(buf, "%d\n", val); |
| 57 | return ret; |
| 58 | } |
| 59 | |
David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 60 | static ssize_t withdraw_store(struct gdlm_ls *ls, const char *buf, size_t len) |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 61 | { |
| 62 | ssize_t ret = len; |
| 63 | int val; |
| 64 | |
| 65 | val = simple_strtol(buf, NULL, 0); |
| 66 | |
| 67 | if (val == 1) |
| 68 | set_bit(DFL_WITHDRAW, &ls->flags); |
| 69 | else |
| 70 | ret = -EINVAL; |
| 71 | wake_up(&ls->wait_control); |
| 72 | return ret; |
| 73 | } |
| 74 | |
David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 75 | static ssize_t id_show(struct gdlm_ls *ls, char *buf) |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 76 | { |
David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 77 | return sprintf(buf, "%u\n", ls->id); |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 78 | } |
| 79 | |
David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 80 | static ssize_t jid_show(struct gdlm_ls *ls, char *buf) |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 81 | { |
David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 82 | return sprintf(buf, "%d\n", ls->jid); |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 83 | } |
| 84 | |
David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 85 | static ssize_t first_show(struct gdlm_ls *ls, char *buf) |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 86 | { |
David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 87 | return sprintf(buf, "%d\n", ls->first); |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 88 | } |
| 89 | |
David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 90 | static ssize_t first_done_show(struct gdlm_ls *ls, char *buf) |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 91 | { |
| 92 | return sprintf(buf, "%d\n", ls->first_done); |
| 93 | } |
| 94 | |
David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 95 | static ssize_t recover_show(struct gdlm_ls *ls, char *buf) |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 96 | { |
David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 97 | return sprintf(buf, "%d\n", ls->recover_jid); |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 98 | } |
| 99 | |
David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 100 | static ssize_t recover_store(struct gdlm_ls *ls, const char *buf, size_t len) |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 101 | { |
| 102 | ls->recover_jid = simple_strtol(buf, NULL, 0); |
Steven Whitehouse | 1c089c3 | 2006-09-07 15:50:20 -0400 | [diff] [blame] | 103 | ls->fscb(ls->sdp, LM_CB_NEED_RECOVERY, &ls->recover_jid); |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 104 | return len; |
| 105 | } |
| 106 | |
David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 107 | static ssize_t recover_done_show(struct gdlm_ls *ls, char *buf) |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 108 | { |
David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 109 | return sprintf(buf, "%d\n", ls->recover_jid_done); |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 110 | } |
| 111 | |
David Teigland | 6bd70ab | 2006-04-26 15:56:35 -0400 | [diff] [blame] | 112 | static ssize_t recover_status_show(struct gdlm_ls *ls, char *buf) |
| 113 | { |
| 114 | return sprintf(buf, "%d\n", ls->recover_jid_status); |
| 115 | } |
| 116 | |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 117 | struct gdlm_attr { |
| 118 | struct attribute attr; |
| 119 | ssize_t (*show)(struct gdlm_ls *, char *); |
| 120 | ssize_t (*store)(struct gdlm_ls *, const char *, size_t); |
| 121 | }; |
| 122 | |
David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 123 | #define GDLM_ATTR(_name,_mode,_show,_store) \ |
| 124 | static struct gdlm_attr gdlm_attr_##_name = __ATTR(_name,_mode,_show,_store) |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 125 | |
David Teigland | 6bd70ab | 2006-04-26 15:56:35 -0400 | [diff] [blame] | 126 | GDLM_ATTR(proto_name, 0444, proto_name_show, NULL); |
| 127 | GDLM_ATTR(block, 0644, block_show, block_store); |
| 128 | GDLM_ATTR(withdraw, 0644, withdraw_show, withdraw_store); |
| 129 | GDLM_ATTR(id, 0444, id_show, NULL); |
| 130 | GDLM_ATTR(jid, 0444, jid_show, NULL); |
| 131 | GDLM_ATTR(first, 0444, first_show, NULL); |
| 132 | GDLM_ATTR(first_done, 0444, first_done_show, NULL); |
| 133 | GDLM_ATTR(recover, 0644, recover_show, recover_store); |
| 134 | GDLM_ATTR(recover_done, 0444, recover_done_show, NULL); |
| 135 | GDLM_ATTR(recover_status, 0444, recover_status_show, NULL); |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 136 | |
| 137 | static struct attribute *gdlm_attrs[] = { |
David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 138 | &gdlm_attr_proto_name.attr, |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 139 | &gdlm_attr_block.attr, |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 140 | &gdlm_attr_withdraw.attr, |
David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 141 | &gdlm_attr_id.attr, |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 142 | &gdlm_attr_jid.attr, |
| 143 | &gdlm_attr_first.attr, |
| 144 | &gdlm_attr_first_done.attr, |
| 145 | &gdlm_attr_recover.attr, |
| 146 | &gdlm_attr_recover_done.attr, |
David Teigland | 6bd70ab | 2006-04-26 15:56:35 -0400 | [diff] [blame] | 147 | &gdlm_attr_recover_status.attr, |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 148 | NULL, |
| 149 | }; |
| 150 | |
| 151 | static ssize_t gdlm_attr_show(struct kobject *kobj, struct attribute *attr, |
| 152 | char *buf) |
| 153 | { |
| 154 | struct gdlm_ls *ls = container_of(kobj, struct gdlm_ls, kobj); |
| 155 | struct gdlm_attr *a = container_of(attr, struct gdlm_attr, attr); |
| 156 | return a->show ? a->show(ls, buf) : 0; |
| 157 | } |
| 158 | |
| 159 | static ssize_t gdlm_attr_store(struct kobject *kobj, struct attribute *attr, |
| 160 | const char *buf, size_t len) |
| 161 | { |
| 162 | struct gdlm_ls *ls = container_of(kobj, struct gdlm_ls, kobj); |
| 163 | struct gdlm_attr *a = container_of(attr, struct gdlm_attr, attr); |
| 164 | return a->store ? a->store(ls, buf, len) : len; |
| 165 | } |
| 166 | |
| 167 | static struct sysfs_ops gdlm_attr_ops = { |
| 168 | .show = gdlm_attr_show, |
| 169 | .store = gdlm_attr_store, |
| 170 | }; |
| 171 | |
| 172 | static struct kobj_type gdlm_ktype = { |
| 173 | .default_attrs = gdlm_attrs, |
| 174 | .sysfs_ops = &gdlm_attr_ops, |
| 175 | }; |
| 176 | |
Greg Kroah-Hartman | 136a275 | 2007-10-29 20:13:17 +0100 | [diff] [blame] | 177 | static struct kset *gdlm_kset; |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 178 | |
David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 179 | int gdlm_kobject_setup(struct gdlm_ls *ls, struct kobject *fskobj) |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 180 | { |
| 181 | int error; |
| 182 | |
Greg Kroah-Hartman | 136a275 | 2007-10-29 20:13:17 +0100 | [diff] [blame] | 183 | ls->kobj.kset = gdlm_kset; |
Greg Kroah-Hartman | 901195e | 2007-12-17 15:54:39 -0400 | [diff] [blame] | 184 | error = kobject_init_and_add(&ls->kobj, &gdlm_ktype, fskobj, |
| 185 | "lock_module"); |
David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 186 | if (error) |
| 187 | log_error("can't register kobj %d", error); |
Greg Kroah-Hartman | 901195e | 2007-12-17 15:54:39 -0400 | [diff] [blame] | 188 | kobject_uevent(&ls->kobj, KOBJ_ADD); |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 189 | |
David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 190 | return error; |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | void gdlm_kobject_release(struct gdlm_ls *ls) |
| 194 | { |
Greg Kroah-Hartman | 197b12d | 2007-12-20 08:13:05 -0800 | [diff] [blame] | 195 | kobject_put(&ls->kobj); |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | int gdlm_sysfs_init(void) |
| 199 | { |
Greg Kroah-Hartman | 0ff21e4 | 2007-11-06 10:36:58 -0800 | [diff] [blame] | 200 | gdlm_kset = kset_create_and_add("lock_dlm", NULL, kernel_kobj); |
Greg Kroah-Hartman | 136a275 | 2007-10-29 20:13:17 +0100 | [diff] [blame] | 201 | if (!gdlm_kset) { |
Harvey Harrison | 8e24eea | 2008-04-30 00:55:09 -0700 | [diff] [blame] | 202 | printk(KERN_WARNING "%s: can not create kset\n", __func__); |
Greg Kroah-Hartman | 136a275 | 2007-10-29 20:13:17 +0100 | [diff] [blame] | 203 | return -ENOMEM; |
| 204 | } |
| 205 | return 0; |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | void gdlm_sysfs_exit(void) |
| 209 | { |
Greg Kroah-Hartman | 136a275 | 2007-10-29 20:13:17 +0100 | [diff] [blame] | 210 | kset_unregister(gdlm_kset); |
David Teigland | 29b7998 | 2006-01-16 16:52:38 +0000 | [diff] [blame] | 211 | } |
| 212 | |