aboutsummaryrefslogtreecommitdiffstats
path: root/fs/dlm/config.c
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2015-10-03 09:32:53 -0400
committerNicholas Bellinger <nab@linux-iscsi.org>2015-10-14 01:16:18 -0400
commit9ae0f367df5d0d7be09fad1e2e5b080f6a45ca6b (patch)
treec81a69b90b020c12b8b516277f06a5ec981e5915 /fs/dlm/config.c
parent0b4be4fa878780a15a953577499eb69839942956 (diff)
dlm: use per-attribute show and store methods
To simplify the configfs interface and remove boilerplate code that also causes binary bloat. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: David Teigland <teigland@redhat.com Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
Diffstat (limited to 'fs/dlm/config.c')
-rw-r--r--fs/dlm/config.c288
1 files changed, 74 insertions, 214 deletions
diff --git a/fs/dlm/config.c b/fs/dlm/config.c
index d521bddf876d..8e294fbbac39 100644
--- a/fs/dlm/config.c
+++ b/fs/dlm/config.c
@@ -61,35 +61,8 @@ static struct config_item *make_node(struct config_group *, const char *);
61static void drop_node(struct config_group *, struct config_item *); 61static void drop_node(struct config_group *, struct config_item *);
62static void release_node(struct config_item *); 62static void release_node(struct config_item *);
63 63
64static ssize_t show_cluster(struct config_item *i, struct configfs_attribute *a, 64static struct configfs_attribute *comm_attrs[];
65 char *buf); 65static struct configfs_attribute *node_attrs[];
66static ssize_t store_cluster(struct config_item *i,
67 struct configfs_attribute *a,
68 const char *buf, size_t len);
69static ssize_t show_comm(struct config_item *i, struct configfs_attribute *a,
70 char *buf);
71static ssize_t store_comm(struct config_item *i, struct configfs_attribute *a,
72 const char *buf, size_t len);
73static ssize_t show_node(struct config_item *i, struct configfs_attribute *a,
74 char *buf);
75static ssize_t store_node(struct config_item *i, struct configfs_attribute *a,
76 const char *buf, size_t len);
77
78static ssize_t comm_nodeid_read(struct dlm_comm *cm, char *buf);
79static ssize_t comm_nodeid_write(struct dlm_comm *cm, const char *buf,
80 size_t len);
81static ssize_t comm_local_read(struct dlm_comm *cm, char *buf);
82static ssize_t comm_local_write(struct dlm_comm *cm, const char *buf,
83 size_t len);
84static ssize_t comm_addr_write(struct dlm_comm *cm, const char *buf,
85 size_t len);
86static ssize_t comm_addr_list_read(struct dlm_comm *cm, char *buf);
87static ssize_t node_nodeid_read(struct dlm_node *nd, char *buf);
88static ssize_t node_nodeid_write(struct dlm_node *nd, const char *buf,
89 size_t len);
90static ssize_t node_weight_read(struct dlm_node *nd, char *buf);
91static ssize_t node_weight_write(struct dlm_node *nd, const char *buf,
92 size_t len);
93 66
94struct dlm_cluster { 67struct dlm_cluster {
95 struct config_group group; 68 struct config_group group;
@@ -108,6 +81,12 @@ struct dlm_cluster {
108 char cl_cluster_name[DLM_LOCKSPACE_LEN]; 81 char cl_cluster_name[DLM_LOCKSPACE_LEN];
109}; 82};
110 83
84static struct dlm_cluster *config_item_to_cluster(struct config_item *i)
85{
86 return i ? container_of(to_config_group(i), struct dlm_cluster, group) :
87 NULL;
88}
89
111enum { 90enum {
112 CLUSTER_ATTR_TCP_PORT = 0, 91 CLUSTER_ATTR_TCP_PORT = 0,
113 CLUSTER_ATTR_BUFFER_SIZE, 92 CLUSTER_ATTR_BUFFER_SIZE,
@@ -124,33 +103,24 @@ enum {
124 CLUSTER_ATTR_CLUSTER_NAME, 103 CLUSTER_ATTR_CLUSTER_NAME,
125}; 104};
126 105
127struct cluster_attribute { 106static ssize_t cluster_cluster_name_show(struct config_item *item, char *buf)
128 struct configfs_attribute attr;
129 ssize_t (*show)(struct dlm_cluster *, char *);
130 ssize_t (*store)(struct dlm_cluster *, const char *, size_t);
131};
132
133static ssize_t cluster_cluster_name_read(struct dlm_cluster *cl, char *buf)
134{ 107{
108 struct dlm_cluster *cl = config_item_to_cluster(item);
135 return sprintf(buf, "%s\n", cl->cl_cluster_name); 109 return sprintf(buf, "%s\n", cl->cl_cluster_name);
136} 110}
137 111
138static ssize_t cluster_cluster_name_write(struct dlm_cluster *cl, 112static ssize_t cluster_cluster_name_store(struct config_item *item,
139 const char *buf, size_t len) 113 const char *buf, size_t len)
140{ 114{
115 struct dlm_cluster *cl = config_item_to_cluster(item);
116
141 strlcpy(dlm_config.ci_cluster_name, buf, 117 strlcpy(dlm_config.ci_cluster_name, buf,
142 sizeof(dlm_config.ci_cluster_name)); 118 sizeof(dlm_config.ci_cluster_name));
143 strlcpy(cl->cl_cluster_name, buf, sizeof(cl->cl_cluster_name)); 119 strlcpy(cl->cl_cluster_name, buf, sizeof(cl->cl_cluster_name));
144 return len; 120 return len;
145} 121}
146 122
147static struct cluster_attribute cluster_attr_cluster_name = { 123CONFIGFS_ATTR(cluster_, cluster_name);
148 .attr = { .ca_owner = THIS_MODULE,
149 .ca_name = "cluster_name",
150 .ca_mode = S_IRUGO | S_IWUSR },
151 .show = cluster_cluster_name_read,
152 .store = cluster_cluster_name_write,
153};
154 124
155static ssize_t cluster_set(struct dlm_cluster *cl, unsigned int *cl_field, 125static ssize_t cluster_set(struct dlm_cluster *cl, unsigned int *cl_field,
156 int *info_field, int check_zero, 126 int *info_field, int check_zero,
@@ -175,17 +145,19 @@ static ssize_t cluster_set(struct dlm_cluster *cl, unsigned int *cl_field,
175} 145}
176 146
177#define CLUSTER_ATTR(name, check_zero) \ 147#define CLUSTER_ATTR(name, check_zero) \
178static ssize_t name##_write(struct dlm_cluster *cl, const char *buf, size_t len) \ 148static ssize_t cluster_##name##_store(struct config_item *item, \
149 const char *buf, size_t len) \
179{ \ 150{ \
151 struct dlm_cluster *cl = config_item_to_cluster(item); \
180 return cluster_set(cl, &cl->cl_##name, &dlm_config.ci_##name, \ 152 return cluster_set(cl, &cl->cl_##name, &dlm_config.ci_##name, \
181 check_zero, buf, len); \ 153 check_zero, buf, len); \
182} \ 154} \
183static ssize_t name##_read(struct dlm_cluster *cl, char *buf) \ 155static ssize_t cluster_##name##_show(struct config_item *item, char *buf) \
184{ \ 156{ \
157 struct dlm_cluster *cl = config_item_to_cluster(item); \
185 return snprintf(buf, PAGE_SIZE, "%u\n", cl->cl_##name); \ 158 return snprintf(buf, PAGE_SIZE, "%u\n", cl->cl_##name); \
186} \ 159} \
187static struct cluster_attribute cluster_attr_##name = \ 160CONFIGFS_ATTR(cluster_, name);
188__CONFIGFS_ATTR(name, 0644, name##_read, name##_write)
189 161
190CLUSTER_ATTR(tcp_port, 1); 162CLUSTER_ATTR(tcp_port, 1);
191CLUSTER_ATTR(buffer_size, 1); 163CLUSTER_ATTR(buffer_size, 1);
@@ -201,19 +173,19 @@ CLUSTER_ATTR(new_rsb_count, 0);
201CLUSTER_ATTR(recover_callbacks, 0); 173CLUSTER_ATTR(recover_callbacks, 0);
202 174
203static struct configfs_attribute *cluster_attrs[] = { 175static struct configfs_attribute *cluster_attrs[] = {
204 [CLUSTER_ATTR_TCP_PORT] = &cluster_attr_tcp_port.attr, 176 [CLUSTER_ATTR_TCP_PORT] = &cluster_attr_tcp_port,
205 [CLUSTER_ATTR_BUFFER_SIZE] = &cluster_attr_buffer_size.attr, 177 [CLUSTER_ATTR_BUFFER_SIZE] = &cluster_attr_buffer_size,
206 [CLUSTER_ATTR_RSBTBL_SIZE] = &cluster_attr_rsbtbl_size.attr, 178 [CLUSTER_ATTR_RSBTBL_SIZE] = &cluster_attr_rsbtbl_size,
207 [CLUSTER_ATTR_RECOVER_TIMER] = &cluster_attr_recover_timer.attr, 179 [CLUSTER_ATTR_RECOVER_TIMER] = &cluster_attr_recover_timer,
208 [CLUSTER_ATTR_TOSS_SECS] = &cluster_attr_toss_secs.attr, 180 [CLUSTER_ATTR_TOSS_SECS] = &cluster_attr_toss_secs,
209 [CLUSTER_ATTR_SCAN_SECS] = &cluster_attr_scan_secs.attr, 181 [CLUSTER_ATTR_SCAN_SECS] = &cluster_attr_scan_secs,
210 [CLUSTER_ATTR_LOG_DEBUG] = &cluster_attr_log_debug.attr, 182 [CLUSTER_ATTR_LOG_DEBUG] = &cluster_attr_log_debug,
211 [CLUSTER_ATTR_PROTOCOL] = &cluster_attr_protocol.attr, 183 [CLUSTER_ATTR_PROTOCOL] = &cluster_attr_protocol,
212 [CLUSTER_ATTR_TIMEWARN_CS] = &cluster_attr_timewarn_cs.attr, 184 [CLUSTER_ATTR_TIMEWARN_CS] = &cluster_attr_timewarn_cs,
213 [CLUSTER_ATTR_WAITWARN_US] = &cluster_attr_waitwarn_us.attr, 185 [CLUSTER_ATTR_WAITWARN_US] = &cluster_attr_waitwarn_us,
214 [CLUSTER_ATTR_NEW_RSB_COUNT] = &cluster_attr_new_rsb_count.attr, 186 [CLUSTER_ATTR_NEW_RSB_COUNT] = &cluster_attr_new_rsb_count,
215 [CLUSTER_ATTR_RECOVER_CALLBACKS] = &cluster_attr_recover_callbacks.attr, 187 [CLUSTER_ATTR_RECOVER_CALLBACKS] = &cluster_attr_recover_callbacks,
216 [CLUSTER_ATTR_CLUSTER_NAME] = &cluster_attr_cluster_name.attr, 188 [CLUSTER_ATTR_CLUSTER_NAME] = &cluster_attr_cluster_name,
217 NULL, 189 NULL,
218}; 190};
219 191
@@ -224,83 +196,11 @@ enum {
224 COMM_ATTR_ADDR_LIST, 196 COMM_ATTR_ADDR_LIST,
225}; 197};
226 198
227struct comm_attribute {
228 struct configfs_attribute attr;
229 ssize_t (*show)(struct dlm_comm *, char *);
230 ssize_t (*store)(struct dlm_comm *, const char *, size_t);
231};
232
233static struct comm_attribute comm_attr_nodeid = {
234 .attr = { .ca_owner = THIS_MODULE,
235 .ca_name = "nodeid",
236 .ca_mode = S_IRUGO | S_IWUSR },
237 .show = comm_nodeid_read,
238 .store = comm_nodeid_write,
239};
240
241static struct comm_attribute comm_attr_local = {
242 .attr = { .ca_owner = THIS_MODULE,
243 .ca_name = "local",
244 .ca_mode = S_IRUGO | S_IWUSR },
245 .show = comm_local_read,
246 .store = comm_local_write,
247};
248
249static struct comm_attribute comm_attr_addr = {
250 .attr = { .ca_owner = THIS_MODULE,
251 .ca_name = "addr",
252 .ca_mode = S_IWUSR },
253 .store = comm_addr_write,
254};
255
256static struct comm_attribute comm_attr_addr_list = {
257 .attr = { .ca_owner = THIS_MODULE,
258 .ca_name = "addr_list",
259 .ca_mode = S_IRUGO },
260 .show = comm_addr_list_read,
261};
262
263static struct configfs_attribute *comm_attrs[] = {
264 [COMM_ATTR_NODEID] = &comm_attr_nodeid.attr,
265 [COMM_ATTR_LOCAL] = &comm_attr_local.attr,
266 [COMM_ATTR_ADDR] = &comm_attr_addr.attr,
267 [COMM_ATTR_ADDR_LIST] = &comm_attr_addr_list.attr,
268 NULL,
269};
270
271enum { 199enum {
272 NODE_ATTR_NODEID = 0, 200 NODE_ATTR_NODEID = 0,
273 NODE_ATTR_WEIGHT, 201 NODE_ATTR_WEIGHT,
274}; 202};
275 203
276struct node_attribute {
277 struct configfs_attribute attr;
278 ssize_t (*show)(struct dlm_node *, char *);
279 ssize_t (*store)(struct dlm_node *, const char *, size_t);
280};
281
282static struct node_attribute node_attr_nodeid = {
283 .attr = { .ca_owner = THIS_MODULE,
284 .ca_name = "nodeid",
285 .ca_mode = S_IRUGO | S_IWUSR },
286 .show = node_nodeid_read,
287 .store = node_nodeid_write,
288};
289
290static struct node_attribute node_attr_weight = {
291 .attr = { .ca_owner = THIS_MODULE,
292 .ca_name = "weight",
293 .ca_mode = S_IRUGO | S_IWUSR },
294 .show = node_weight_read,
295 .store = node_weight_write,
296};
297
298static struct configfs_attribute *node_attrs[] = {
299 [NODE_ATTR_NODEID] = &node_attr_nodeid.attr,
300 [NODE_ATTR_WEIGHT] = &node_attr_weight.attr,
301 NULL,
302};
303
304struct dlm_clusters { 204struct dlm_clusters {
305 struct configfs_subsystem subsys; 205 struct configfs_subsystem subsys;
306}; 206};
@@ -349,8 +249,6 @@ static struct configfs_group_operations clusters_ops = {
349 249
350static struct configfs_item_operations cluster_ops = { 250static struct configfs_item_operations cluster_ops = {
351 .release = release_cluster, 251 .release = release_cluster,
352 .show_attribute = show_cluster,
353 .store_attribute = store_cluster,
354}; 252};
355 253
356static struct configfs_group_operations spaces_ops = { 254static struct configfs_group_operations spaces_ops = {
@@ -369,8 +267,6 @@ static struct configfs_group_operations comms_ops = {
369 267
370static struct configfs_item_operations comm_ops = { 268static struct configfs_item_operations comm_ops = {
371 .release = release_comm, 269 .release = release_comm,
372 .show_attribute = show_comm,
373 .store_attribute = store_comm,
374}; 270};
375 271
376static struct configfs_group_operations nodes_ops = { 272static struct configfs_group_operations nodes_ops = {
@@ -380,8 +276,6 @@ static struct configfs_group_operations nodes_ops = {
380 276
381static struct configfs_item_operations node_ops = { 277static struct configfs_item_operations node_ops = {
382 .release = release_node, 278 .release = release_node,
383 .show_attribute = show_node,
384 .store_attribute = store_node,
385}; 279};
386 280
387static struct config_item_type clusters_type = { 281static struct config_item_type clusters_type = {
@@ -427,12 +321,6 @@ static struct config_item_type node_type = {
427 .ct_owner = THIS_MODULE, 321 .ct_owner = THIS_MODULE,
428}; 322};
429 323
430static struct dlm_cluster *config_item_to_cluster(struct config_item *i)
431{
432 return i ? container_of(to_config_group(i), struct dlm_cluster, group) :
433 NULL;
434}
435
436static struct dlm_space *config_item_to_space(struct config_item *i) 324static struct dlm_space *config_item_to_space(struct config_item *i)
437{ 325{
438 return i ? container_of(to_config_group(i), struct dlm_space, group) : 326 return i ? container_of(to_config_group(i), struct dlm_space, group) :
@@ -687,66 +575,30 @@ void dlm_config_exit(void)
687 * Functions for user space to read/write attributes 575 * Functions for user space to read/write attributes
688 */ 576 */
689 577
690static ssize_t show_cluster(struct config_item *i, struct configfs_attribute *a, 578static ssize_t comm_nodeid_show(struct config_item *item, char *buf)
691 char *buf)
692{
693 struct dlm_cluster *cl = config_item_to_cluster(i);
694 struct cluster_attribute *cla =
695 container_of(a, struct cluster_attribute, attr);
696 return cla->show ? cla->show(cl, buf) : 0;
697}
698
699static ssize_t store_cluster(struct config_item *i,
700 struct configfs_attribute *a,
701 const char *buf, size_t len)
702{ 579{
703 struct dlm_cluster *cl = config_item_to_cluster(i); 580 return sprintf(buf, "%d\n", config_item_to_comm(item)->nodeid);
704 struct cluster_attribute *cla =
705 container_of(a, struct cluster_attribute, attr);
706 return cla->store ? cla->store(cl, buf, len) : -EINVAL;
707}
708
709static ssize_t show_comm(struct config_item *i, struct configfs_attribute *a,
710 char *buf)
711{
712 struct dlm_comm *cm = config_item_to_comm(i);
713 struct comm_attribute *cma =
714 container_of(a, struct comm_attribute, attr);
715 return cma->show ? cma->show(cm, buf) : 0;
716}
717
718static ssize_t store_comm(struct config_item *i, struct configfs_attribute *a,
719 const char *buf, size_t len)
720{
721 struct dlm_comm *cm = config_item_to_comm(i);
722 struct comm_attribute *cma =
723 container_of(a, struct comm_attribute, attr);
724 return cma->store ? cma->store(cm, buf, len) : -EINVAL;
725} 581}
726 582
727static ssize_t comm_nodeid_read(struct dlm_comm *cm, char *buf) 583static ssize_t comm_nodeid_store(struct config_item *item, const char *buf,
728{
729 return sprintf(buf, "%d\n", cm->nodeid);
730}
731
732static ssize_t comm_nodeid_write(struct dlm_comm *cm, const char *buf,
733 size_t len) 584 size_t len)
734{ 585{
735 int rc = kstrtoint(buf, 0, &cm->nodeid); 586 int rc = kstrtoint(buf, 0, &config_item_to_comm(item)->nodeid);
736 587
737 if (rc) 588 if (rc)
738 return rc; 589 return rc;
739 return len; 590 return len;
740} 591}
741 592
742static ssize_t comm_local_read(struct dlm_comm *cm, char *buf) 593static ssize_t comm_local_show(struct config_item *item, char *buf)
743{ 594{
744 return sprintf(buf, "%d\n", cm->local); 595 return sprintf(buf, "%d\n", config_item_to_comm(item)->local);
745} 596}
746 597
747static ssize_t comm_local_write(struct dlm_comm *cm, const char *buf, 598static ssize_t comm_local_store(struct config_item *item, const char *buf,
748 size_t len) 599 size_t len)
749{ 600{
601 struct dlm_comm *cm = config_item_to_comm(item);
750 int rc = kstrtoint(buf, 0, &cm->local); 602 int rc = kstrtoint(buf, 0, &cm->local);
751 603
752 if (rc) 604 if (rc)
@@ -756,8 +608,10 @@ static ssize_t comm_local_write(struct dlm_comm *cm, const char *buf,
756 return len; 608 return len;
757} 609}
758 610
759static ssize_t comm_addr_write(struct dlm_comm *cm, const char *buf, size_t len) 611static ssize_t comm_addr_store(struct config_item *item, const char *buf,
612 size_t len)
760{ 613{
614 struct dlm_comm *cm = config_item_to_comm(item);
761 struct sockaddr_storage *addr; 615 struct sockaddr_storage *addr;
762 int rv; 616 int rv;
763 617
@@ -783,8 +637,9 @@ static ssize_t comm_addr_write(struct dlm_comm *cm, const char *buf, size_t len)
783 return len; 637 return len;
784} 638}
785 639
786static ssize_t comm_addr_list_read(struct dlm_comm *cm, char *buf) 640static ssize_t comm_addr_list_show(struct config_item *item, char *buf)
787{ 641{
642 struct dlm_comm *cm = config_item_to_comm(item);
788 ssize_t s; 643 ssize_t s;
789 ssize_t allowance; 644 ssize_t allowance;
790 int i; 645 int i;
@@ -827,32 +682,28 @@ static ssize_t comm_addr_list_read(struct dlm_comm *cm, char *buf)
827 return 4096 - allowance; 682 return 4096 - allowance;
828} 683}
829 684
830static ssize_t show_node(struct config_item *i, struct configfs_attribute *a, 685CONFIGFS_ATTR(comm_, nodeid);
831 char *buf) 686CONFIGFS_ATTR(comm_, local);
832{ 687CONFIGFS_ATTR_WO(comm_, addr);
833 struct dlm_node *nd = config_item_to_node(i); 688CONFIGFS_ATTR_RO(comm_, addr_list);
834 struct node_attribute *nda =
835 container_of(a, struct node_attribute, attr);
836 return nda->show ? nda->show(nd, buf) : 0;
837}
838 689
839static ssize_t store_node(struct config_item *i, struct configfs_attribute *a, 690static struct configfs_attribute *comm_attrs[] = {
840 const char *buf, size_t len) 691 [COMM_ATTR_NODEID] = &comm_attr_nodeid,
841{ 692 [COMM_ATTR_LOCAL] = &comm_attr_local,
842 struct dlm_node *nd = config_item_to_node(i); 693 [COMM_ATTR_ADDR] = &comm_attr_addr,
843 struct node_attribute *nda = 694 [COMM_ATTR_ADDR_LIST] = &comm_attr_addr_list,
844 container_of(a, struct node_attribute, attr); 695 NULL,
845 return nda->store ? nda->store(nd, buf, len) : -EINVAL; 696};
846}
847 697
848static ssize_t node_nodeid_read(struct dlm_node *nd, char *buf) 698static ssize_t node_nodeid_show(struct config_item *item, char *buf)
849{ 699{
850 return sprintf(buf, "%d\n", nd->nodeid); 700 return sprintf(buf, "%d\n", config_item_to_node(item)->nodeid);
851} 701}
852 702
853static ssize_t node_nodeid_write(struct dlm_node *nd, const char *buf, 703static ssize_t node_nodeid_store(struct config_item *item, const char *buf,
854 size_t len) 704 size_t len)
855{ 705{
706 struct dlm_node *nd = config_item_to_node(item);
856 uint32_t seq = 0; 707 uint32_t seq = 0;
857 int rc = kstrtoint(buf, 0, &nd->nodeid); 708 int rc = kstrtoint(buf, 0, &nd->nodeid);
858 709
@@ -863,21 +714,30 @@ static ssize_t node_nodeid_write(struct dlm_node *nd, const char *buf,
863 return len; 714 return len;
864} 715}
865 716
866static ssize_t node_weight_read(struct dlm_node *nd, char *buf) 717static ssize_t node_weight_show(struct config_item *item, char *buf)
867{ 718{
868 return sprintf(buf, "%d\n", nd->weight); 719 return sprintf(buf, "%d\n", config_item_to_node(item)->weight);
869} 720}
870 721
871static ssize_t node_weight_write(struct dlm_node *nd, const char *buf, 722static ssize_t node_weight_store(struct config_item *item, const char *buf,
872 size_t len) 723 size_t len)
873{ 724{
874 int rc = kstrtoint(buf, 0, &nd->weight); 725 int rc = kstrtoint(buf, 0, &config_item_to_node(item)->weight);
875 726
876 if (rc) 727 if (rc)
877 return rc; 728 return rc;
878 return len; 729 return len;
879} 730}
880 731
732CONFIGFS_ATTR(node_, nodeid);
733CONFIGFS_ATTR(node_, weight);
734
735static struct configfs_attribute *node_attrs[] = {
736 [NODE_ATTR_NODEID] = &node_attr_nodeid,
737 [NODE_ATTR_WEIGHT] = &node_attr_weight,
738 NULL,
739};
740
881/* 741/*
882 * Functions for the dlm to get the info that's been configured 742 * Functions for the dlm to get the info that's been configured
883 */ 743 */