aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ocfs2/cluster/nodemanager.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/ocfs2/cluster/nodemanager.c')
-rw-r--r--fs/ocfs2/cluster/nodemanager.c161
1 files changed, 161 insertions, 0 deletions
diff --git a/fs/ocfs2/cluster/nodemanager.c b/fs/ocfs2/cluster/nodemanager.c
index dd4aefa11b3d..234f83f2897f 100644
--- a/fs/ocfs2/cluster/nodemanager.c
+++ b/fs/ocfs2/cluster/nodemanager.c
@@ -532,6 +532,161 @@ static struct o2nm_node_group *to_o2nm_node_group(struct config_group *group)
532} 532}
533#endif 533#endif
534 534
535struct o2nm_cluster_attribute {
536 struct configfs_attribute attr;
537 ssize_t (*show)(struct o2nm_cluster *, char *);
538 ssize_t (*store)(struct o2nm_cluster *, const char *, size_t);
539};
540
541static ssize_t o2nm_cluster_attr_write(const char *page, ssize_t count,
542 unsigned int *val)
543{
544 unsigned long tmp;
545 char *p = (char *)page;
546
547 tmp = simple_strtoul(p, &p, 0);
548 if (!p || (*p && (*p != '\n')))
549 return -EINVAL;
550
551 if (tmp == 0)
552 return -EINVAL;
553 if (tmp >= (u32)-1)
554 return -ERANGE;
555
556 *val = tmp;
557
558 return count;
559}
560
561static ssize_t o2nm_cluster_attr_idle_timeout_ms_read(
562 struct o2nm_cluster *cluster, char *page)
563{
564 return sprintf(page, "%u\n", cluster->cl_idle_timeout_ms);
565}
566
567static ssize_t o2nm_cluster_attr_idle_timeout_ms_write(
568 struct o2nm_cluster *cluster, const char *page, size_t count)
569{
570 ssize_t ret;
571 unsigned int val;
572
573 ret = o2nm_cluster_attr_write(page, count, &val);
574
575 if (ret > 0) {
576 if (val <= cluster->cl_keepalive_delay_ms) {
577 mlog(ML_NOTICE, "o2net: idle timeout must be larger "
578 "than keepalive delay\n");
579 return -EINVAL;
580 }
581 cluster->cl_idle_timeout_ms = val;
582 }
583
584 return ret;
585}
586
587static ssize_t o2nm_cluster_attr_keepalive_delay_ms_read(
588 struct o2nm_cluster *cluster, char *page)
589{
590 return sprintf(page, "%u\n", cluster->cl_keepalive_delay_ms);
591}
592
593static ssize_t o2nm_cluster_attr_keepalive_delay_ms_write(
594 struct o2nm_cluster *cluster, const char *page, size_t count)
595{
596 ssize_t ret;
597 unsigned int val;
598
599 ret = o2nm_cluster_attr_write(page, count, &val);
600
601 if (ret > 0) {
602 if (val >= cluster->cl_idle_timeout_ms) {
603 mlog(ML_NOTICE, "o2net: keepalive delay must be "
604 "smaller than idle timeout\n");
605 return -EINVAL;
606 }
607 cluster->cl_keepalive_delay_ms = val;
608 }
609
610 return ret;
611}
612
613static ssize_t o2nm_cluster_attr_reconnect_delay_ms_read(
614 struct o2nm_cluster *cluster, char *page)
615{
616 return sprintf(page, "%u\n", cluster->cl_reconnect_delay_ms);
617}
618
619static ssize_t o2nm_cluster_attr_reconnect_delay_ms_write(
620 struct o2nm_cluster *cluster, const char *page, size_t count)
621{
622 return o2nm_cluster_attr_write(page, count,
623 &cluster->cl_reconnect_delay_ms);
624}
625static struct o2nm_cluster_attribute o2nm_cluster_attr_idle_timeout_ms = {
626 .attr = { .ca_owner = THIS_MODULE,
627 .ca_name = "idle_timeout_ms",
628 .ca_mode = S_IRUGO | S_IWUSR },
629 .show = o2nm_cluster_attr_idle_timeout_ms_read,
630 .store = o2nm_cluster_attr_idle_timeout_ms_write,
631};
632
633static struct o2nm_cluster_attribute o2nm_cluster_attr_keepalive_delay_ms = {
634 .attr = { .ca_owner = THIS_MODULE,
635 .ca_name = "keepalive_delay_ms",
636 .ca_mode = S_IRUGO | S_IWUSR },
637 .show = o2nm_cluster_attr_keepalive_delay_ms_read,
638 .store = o2nm_cluster_attr_keepalive_delay_ms_write,
639};
640
641static struct o2nm_cluster_attribute o2nm_cluster_attr_reconnect_delay_ms = {
642 .attr = { .ca_owner = THIS_MODULE,
643 .ca_name = "reconnect_delay_ms",
644 .ca_mode = S_IRUGO | S_IWUSR },
645 .show = o2nm_cluster_attr_reconnect_delay_ms_read,
646 .store = o2nm_cluster_attr_reconnect_delay_ms_write,
647};
648
649static struct configfs_attribute *o2nm_cluster_attrs[] = {
650 &o2nm_cluster_attr_idle_timeout_ms.attr,
651 &o2nm_cluster_attr_keepalive_delay_ms.attr,
652 &o2nm_cluster_attr_reconnect_delay_ms.attr,
653 NULL,
654};
655static ssize_t o2nm_cluster_show(struct config_item *item,
656 struct configfs_attribute *attr,
657 char *page)
658{
659 struct o2nm_cluster *cluster = to_o2nm_cluster(item);
660 struct o2nm_cluster_attribute *o2nm_cluster_attr =
661 container_of(attr, struct o2nm_cluster_attribute, attr);
662 ssize_t ret = 0;
663
664 if (o2nm_cluster_attr->show)
665 ret = o2nm_cluster_attr->show(cluster, page);
666 return ret;
667}
668
669static ssize_t o2nm_cluster_store(struct config_item *item,
670 struct configfs_attribute *attr,
671 const char *page, size_t count)
672{
673 struct o2nm_cluster *cluster = to_o2nm_cluster(item);
674 struct o2nm_cluster_attribute *o2nm_cluster_attr =
675 container_of(attr, struct o2nm_cluster_attribute, attr);
676 ssize_t ret;
677
678 if (o2nm_cluster_attr->store == NULL) {
679 ret = -EINVAL;
680 goto out;
681 }
682
683 ret = o2nm_cluster_attr->store(cluster, page, count);
684 if (ret < count)
685 goto out;
686out:
687 return ret;
688}
689
535static struct config_item *o2nm_node_group_make_item(struct config_group *group, 690static struct config_item *o2nm_node_group_make_item(struct config_group *group,
536 const char *name) 691 const char *name)
537{ 692{
@@ -613,10 +768,13 @@ static void o2nm_cluster_release(struct config_item *item)
613 768
614static struct configfs_item_operations o2nm_cluster_item_ops = { 769static struct configfs_item_operations o2nm_cluster_item_ops = {
615 .release = o2nm_cluster_release, 770 .release = o2nm_cluster_release,
771 .show_attribute = o2nm_cluster_show,
772 .store_attribute = o2nm_cluster_store,
616}; 773};
617 774
618static struct config_item_type o2nm_cluster_type = { 775static struct config_item_type o2nm_cluster_type = {
619 .ct_item_ops = &o2nm_cluster_item_ops, 776 .ct_item_ops = &o2nm_cluster_item_ops,
777 .ct_attrs = o2nm_cluster_attrs,
620 .ct_owner = THIS_MODULE, 778 .ct_owner = THIS_MODULE,
621}; 779};
622 780
@@ -667,6 +825,9 @@ static struct config_group *o2nm_cluster_group_make_group(struct config_group *g
667 cluster->cl_group.default_groups[2] = NULL; 825 cluster->cl_group.default_groups[2] = NULL;
668 rwlock_init(&cluster->cl_nodes_lock); 826 rwlock_init(&cluster->cl_nodes_lock);
669 cluster->cl_node_ip_tree = RB_ROOT; 827 cluster->cl_node_ip_tree = RB_ROOT;
828 cluster->cl_reconnect_delay_ms = O2NET_RECONNECT_DELAY_MS_DEFAULT;
829 cluster->cl_idle_timeout_ms = O2NET_IDLE_TIMEOUT_MS_DEFAULT;
830 cluster->cl_keepalive_delay_ms = O2NET_KEEPALIVE_DELAY_MS_DEFAULT;
670 831
671 ret = &cluster->cl_group; 832 ret = &cluster->cl_group;
672 o2nm_single_cluster = cluster; 833 o2nm_single_cluster = cluster;