diff options
Diffstat (limited to 'fs/dlm/config.c')
-rw-r--r-- | fs/dlm/config.c | 77 |
1 files changed, 53 insertions, 24 deletions
diff --git a/fs/dlm/config.c b/fs/dlm/config.c index 89d2fb7b991a..fd9859f92fad 100644 --- a/fs/dlm/config.c +++ b/fs/dlm/config.c | |||
@@ -14,6 +14,9 @@ | |||
14 | #include <linux/kernel.h> | 14 | #include <linux/kernel.h> |
15 | #include <linux/module.h> | 15 | #include <linux/module.h> |
16 | #include <linux/configfs.h> | 16 | #include <linux/configfs.h> |
17 | #include <linux/in.h> | ||
18 | #include <linux/in6.h> | ||
19 | #include <net/ipv6.h> | ||
17 | #include <net/sock.h> | 20 | #include <net/sock.h> |
18 | 21 | ||
19 | #include "config.h" | 22 | #include "config.h" |
@@ -377,24 +380,24 @@ static struct config_item_type node_type = { | |||
377 | .ct_owner = THIS_MODULE, | 380 | .ct_owner = THIS_MODULE, |
378 | }; | 381 | }; |
379 | 382 | ||
380 | static struct dlm_cluster *to_cluster(struct config_item *i) | 383 | static struct dlm_cluster *config_item_to_cluster(struct config_item *i) |
381 | { | 384 | { |
382 | return i ? container_of(to_config_group(i), struct dlm_cluster, group) : | 385 | return i ? container_of(to_config_group(i), struct dlm_cluster, group) : |
383 | NULL; | 386 | NULL; |
384 | } | 387 | } |
385 | 388 | ||
386 | static struct dlm_space *to_space(struct config_item *i) | 389 | static struct dlm_space *config_item_to_space(struct config_item *i) |
387 | { | 390 | { |
388 | return i ? container_of(to_config_group(i), struct dlm_space, group) : | 391 | return i ? container_of(to_config_group(i), struct dlm_space, group) : |
389 | NULL; | 392 | NULL; |
390 | } | 393 | } |
391 | 394 | ||
392 | static struct dlm_comm *to_comm(struct config_item *i) | 395 | static struct dlm_comm *config_item_to_comm(struct config_item *i) |
393 | { | 396 | { |
394 | return i ? container_of(i, struct dlm_comm, item) : NULL; | 397 | return i ? container_of(i, struct dlm_comm, item) : NULL; |
395 | } | 398 | } |
396 | 399 | ||
397 | static struct dlm_node *to_node(struct config_item *i) | 400 | static struct dlm_node *config_item_to_node(struct config_item *i) |
398 | { | 401 | { |
399 | return i ? container_of(i, struct dlm_node, item) : NULL; | 402 | return i ? container_of(i, struct dlm_node, item) : NULL; |
400 | } | 403 | } |
@@ -450,7 +453,7 @@ static struct config_group *make_cluster(struct config_group *g, | |||
450 | 453 | ||
451 | static void drop_cluster(struct config_group *g, struct config_item *i) | 454 | static void drop_cluster(struct config_group *g, struct config_item *i) |
452 | { | 455 | { |
453 | struct dlm_cluster *cl = to_cluster(i); | 456 | struct dlm_cluster *cl = config_item_to_cluster(i); |
454 | struct config_item *tmp; | 457 | struct config_item *tmp; |
455 | int j; | 458 | int j; |
456 | 459 | ||
@@ -468,7 +471,7 @@ static void drop_cluster(struct config_group *g, struct config_item *i) | |||
468 | 471 | ||
469 | static void release_cluster(struct config_item *i) | 472 | static void release_cluster(struct config_item *i) |
470 | { | 473 | { |
471 | struct dlm_cluster *cl = to_cluster(i); | 474 | struct dlm_cluster *cl = config_item_to_cluster(i); |
472 | kfree(cl->group.default_groups); | 475 | kfree(cl->group.default_groups); |
473 | kfree(cl); | 476 | kfree(cl); |
474 | } | 477 | } |
@@ -507,7 +510,7 @@ static struct config_group *make_space(struct config_group *g, const char *name) | |||
507 | 510 | ||
508 | static void drop_space(struct config_group *g, struct config_item *i) | 511 | static void drop_space(struct config_group *g, struct config_item *i) |
509 | { | 512 | { |
510 | struct dlm_space *sp = to_space(i); | 513 | struct dlm_space *sp = config_item_to_space(i); |
511 | struct config_item *tmp; | 514 | struct config_item *tmp; |
512 | int j; | 515 | int j; |
513 | 516 | ||
@@ -524,7 +527,7 @@ static void drop_space(struct config_group *g, struct config_item *i) | |||
524 | 527 | ||
525 | static void release_space(struct config_item *i) | 528 | static void release_space(struct config_item *i) |
526 | { | 529 | { |
527 | struct dlm_space *sp = to_space(i); | 530 | struct dlm_space *sp = config_item_to_space(i); |
528 | kfree(sp->group.default_groups); | 531 | kfree(sp->group.default_groups); |
529 | kfree(sp); | 532 | kfree(sp); |
530 | } | 533 | } |
@@ -546,7 +549,7 @@ static struct config_item *make_comm(struct config_group *g, const char *name) | |||
546 | 549 | ||
547 | static void drop_comm(struct config_group *g, struct config_item *i) | 550 | static void drop_comm(struct config_group *g, struct config_item *i) |
548 | { | 551 | { |
549 | struct dlm_comm *cm = to_comm(i); | 552 | struct dlm_comm *cm = config_item_to_comm(i); |
550 | if (local_comm == cm) | 553 | if (local_comm == cm) |
551 | local_comm = NULL; | 554 | local_comm = NULL; |
552 | dlm_lowcomms_close(cm->nodeid); | 555 | dlm_lowcomms_close(cm->nodeid); |
@@ -557,13 +560,13 @@ static void drop_comm(struct config_group *g, struct config_item *i) | |||
557 | 560 | ||
558 | static void release_comm(struct config_item *i) | 561 | static void release_comm(struct config_item *i) |
559 | { | 562 | { |
560 | struct dlm_comm *cm = to_comm(i); | 563 | struct dlm_comm *cm = config_item_to_comm(i); |
561 | kfree(cm); | 564 | kfree(cm); |
562 | } | 565 | } |
563 | 566 | ||
564 | static struct config_item *make_node(struct config_group *g, const char *name) | 567 | static struct config_item *make_node(struct config_group *g, const char *name) |
565 | { | 568 | { |
566 | struct dlm_space *sp = to_space(g->cg_item.ci_parent); | 569 | struct dlm_space *sp = config_item_to_space(g->cg_item.ci_parent); |
567 | struct dlm_node *nd; | 570 | struct dlm_node *nd; |
568 | 571 | ||
569 | nd = kzalloc(sizeof(struct dlm_node), GFP_KERNEL); | 572 | nd = kzalloc(sizeof(struct dlm_node), GFP_KERNEL); |
@@ -585,8 +588,8 @@ static struct config_item *make_node(struct config_group *g, const char *name) | |||
585 | 588 | ||
586 | static void drop_node(struct config_group *g, struct config_item *i) | 589 | static void drop_node(struct config_group *g, struct config_item *i) |
587 | { | 590 | { |
588 | struct dlm_space *sp = to_space(g->cg_item.ci_parent); | 591 | struct dlm_space *sp = config_item_to_space(g->cg_item.ci_parent); |
589 | struct dlm_node *nd = to_node(i); | 592 | struct dlm_node *nd = config_item_to_node(i); |
590 | 593 | ||
591 | mutex_lock(&sp->members_lock); | 594 | mutex_lock(&sp->members_lock); |
592 | list_del(&nd->list); | 595 | list_del(&nd->list); |
@@ -598,7 +601,7 @@ static void drop_node(struct config_group *g, struct config_item *i) | |||
598 | 601 | ||
599 | static void release_node(struct config_item *i) | 602 | static void release_node(struct config_item *i) |
600 | { | 603 | { |
601 | struct dlm_node *nd = to_node(i); | 604 | struct dlm_node *nd = config_item_to_node(i); |
602 | kfree(nd); | 605 | kfree(nd); |
603 | } | 606 | } |
604 | 607 | ||
@@ -632,7 +635,7 @@ void dlm_config_exit(void) | |||
632 | static ssize_t show_cluster(struct config_item *i, struct configfs_attribute *a, | 635 | static ssize_t show_cluster(struct config_item *i, struct configfs_attribute *a, |
633 | char *buf) | 636 | char *buf) |
634 | { | 637 | { |
635 | struct dlm_cluster *cl = to_cluster(i); | 638 | struct dlm_cluster *cl = config_item_to_cluster(i); |
636 | struct cluster_attribute *cla = | 639 | struct cluster_attribute *cla = |
637 | container_of(a, struct cluster_attribute, attr); | 640 | container_of(a, struct cluster_attribute, attr); |
638 | return cla->show ? cla->show(cl, buf) : 0; | 641 | return cla->show ? cla->show(cl, buf) : 0; |
@@ -642,7 +645,7 @@ static ssize_t store_cluster(struct config_item *i, | |||
642 | struct configfs_attribute *a, | 645 | struct configfs_attribute *a, |
643 | const char *buf, size_t len) | 646 | const char *buf, size_t len) |
644 | { | 647 | { |
645 | struct dlm_cluster *cl = to_cluster(i); | 648 | struct dlm_cluster *cl = config_item_to_cluster(i); |
646 | struct cluster_attribute *cla = | 649 | struct cluster_attribute *cla = |
647 | container_of(a, struct cluster_attribute, attr); | 650 | container_of(a, struct cluster_attribute, attr); |
648 | return cla->store ? cla->store(cl, buf, len) : -EINVAL; | 651 | return cla->store ? cla->store(cl, buf, len) : -EINVAL; |
@@ -651,7 +654,7 @@ static ssize_t store_cluster(struct config_item *i, | |||
651 | static ssize_t show_comm(struct config_item *i, struct configfs_attribute *a, | 654 | static ssize_t show_comm(struct config_item *i, struct configfs_attribute *a, |
652 | char *buf) | 655 | char *buf) |
653 | { | 656 | { |
654 | struct dlm_comm *cm = to_comm(i); | 657 | struct dlm_comm *cm = config_item_to_comm(i); |
655 | struct comm_attribute *cma = | 658 | struct comm_attribute *cma = |
656 | container_of(a, struct comm_attribute, attr); | 659 | container_of(a, struct comm_attribute, attr); |
657 | return cma->show ? cma->show(cm, buf) : 0; | 660 | return cma->show ? cma->show(cm, buf) : 0; |
@@ -660,7 +663,7 @@ static ssize_t show_comm(struct config_item *i, struct configfs_attribute *a, | |||
660 | static ssize_t store_comm(struct config_item *i, struct configfs_attribute *a, | 663 | static ssize_t store_comm(struct config_item *i, struct configfs_attribute *a, |
661 | const char *buf, size_t len) | 664 | const char *buf, size_t len) |
662 | { | 665 | { |
663 | struct dlm_comm *cm = to_comm(i); | 666 | struct dlm_comm *cm = config_item_to_comm(i); |
664 | struct comm_attribute *cma = | 667 | struct comm_attribute *cma = |
665 | container_of(a, struct comm_attribute, attr); | 668 | container_of(a, struct comm_attribute, attr); |
666 | return cma->store ? cma->store(cm, buf, len) : -EINVAL; | 669 | return cma->store ? cma->store(cm, buf, len) : -EINVAL; |
@@ -714,7 +717,7 @@ static ssize_t comm_addr_write(struct dlm_comm *cm, const char *buf, size_t len) | |||
714 | static ssize_t show_node(struct config_item *i, struct configfs_attribute *a, | 717 | static ssize_t show_node(struct config_item *i, struct configfs_attribute *a, |
715 | char *buf) | 718 | char *buf) |
716 | { | 719 | { |
717 | struct dlm_node *nd = to_node(i); | 720 | struct dlm_node *nd = config_item_to_node(i); |
718 | struct node_attribute *nda = | 721 | struct node_attribute *nda = |
719 | container_of(a, struct node_attribute, attr); | 722 | container_of(a, struct node_attribute, attr); |
720 | return nda->show ? nda->show(nd, buf) : 0; | 723 | return nda->show ? nda->show(nd, buf) : 0; |
@@ -723,7 +726,7 @@ static ssize_t show_node(struct config_item *i, struct configfs_attribute *a, | |||
723 | static ssize_t store_node(struct config_item *i, struct configfs_attribute *a, | 726 | static ssize_t store_node(struct config_item *i, struct configfs_attribute *a, |
724 | const char *buf, size_t len) | 727 | const char *buf, size_t len) |
725 | { | 728 | { |
726 | struct dlm_node *nd = to_node(i); | 729 | struct dlm_node *nd = config_item_to_node(i); |
727 | struct node_attribute *nda = | 730 | struct node_attribute *nda = |
728 | container_of(a, struct node_attribute, attr); | 731 | container_of(a, struct node_attribute, attr); |
729 | return nda->store ? nda->store(nd, buf, len) : -EINVAL; | 732 | return nda->store ? nda->store(nd, buf, len) : -EINVAL; |
@@ -768,7 +771,7 @@ static struct dlm_space *get_space(char *name) | |||
768 | i = config_group_find_item(space_list, name); | 771 | i = config_group_find_item(space_list, name); |
769 | mutex_unlock(&space_list->cg_subsys->su_mutex); | 772 | mutex_unlock(&space_list->cg_subsys->su_mutex); |
770 | 773 | ||
771 | return to_space(i); | 774 | return config_item_to_space(i); |
772 | } | 775 | } |
773 | 776 | ||
774 | static void put_space(struct dlm_space *sp) | 777 | static void put_space(struct dlm_space *sp) |
@@ -776,6 +779,33 @@ static void put_space(struct dlm_space *sp) | |||
776 | config_item_put(&sp->group.cg_item); | 779 | config_item_put(&sp->group.cg_item); |
777 | } | 780 | } |
778 | 781 | ||
782 | static int addr_compare(struct sockaddr_storage *x, struct sockaddr_storage *y) | ||
783 | { | ||
784 | switch (x->ss_family) { | ||
785 | case AF_INET: { | ||
786 | struct sockaddr_in *sinx = (struct sockaddr_in *)x; | ||
787 | struct sockaddr_in *siny = (struct sockaddr_in *)y; | ||
788 | if (sinx->sin_addr.s_addr != siny->sin_addr.s_addr) | ||
789 | return 0; | ||
790 | if (sinx->sin_port != siny->sin_port) | ||
791 | return 0; | ||
792 | break; | ||
793 | } | ||
794 | case AF_INET6: { | ||
795 | struct sockaddr_in6 *sinx = (struct sockaddr_in6 *)x; | ||
796 | struct sockaddr_in6 *siny = (struct sockaddr_in6 *)y; | ||
797 | if (!ipv6_addr_equal(&sinx->sin6_addr, &siny->sin6_addr)) | ||
798 | return 0; | ||
799 | if (sinx->sin6_port != siny->sin6_port) | ||
800 | return 0; | ||
801 | break; | ||
802 | } | ||
803 | default: | ||
804 | return 0; | ||
805 | } | ||
806 | return 1; | ||
807 | } | ||
808 | |||
779 | static struct dlm_comm *get_comm(int nodeid, struct sockaddr_storage *addr) | 809 | static struct dlm_comm *get_comm(int nodeid, struct sockaddr_storage *addr) |
780 | { | 810 | { |
781 | struct config_item *i; | 811 | struct config_item *i; |
@@ -788,7 +818,7 @@ static struct dlm_comm *get_comm(int nodeid, struct sockaddr_storage *addr) | |||
788 | mutex_lock(&clusters_root.subsys.su_mutex); | 818 | mutex_lock(&clusters_root.subsys.su_mutex); |
789 | 819 | ||
790 | list_for_each_entry(i, &comm_list->cg_children, ci_entry) { | 820 | list_for_each_entry(i, &comm_list->cg_children, ci_entry) { |
791 | cm = to_comm(i); | 821 | cm = config_item_to_comm(i); |
792 | 822 | ||
793 | if (nodeid) { | 823 | if (nodeid) { |
794 | if (cm->nodeid != nodeid) | 824 | if (cm->nodeid != nodeid) |
@@ -797,8 +827,7 @@ static struct dlm_comm *get_comm(int nodeid, struct sockaddr_storage *addr) | |||
797 | config_item_get(i); | 827 | config_item_get(i); |
798 | break; | 828 | break; |
799 | } else { | 829 | } else { |
800 | if (!cm->addr_count || | 830 | if (!cm->addr_count || !addr_compare(cm->addr[0], addr)) |
801 | memcmp(cm->addr[0], addr, sizeof(*addr))) | ||
802 | continue; | 831 | continue; |
803 | found = 1; | 832 | found = 1; |
804 | config_item_get(i); | 833 | config_item_get(i); |