connection.c (1e2b44e78eead7bcadfbf96f70d95773191541c9) connection.c (b7ff8b1036f0b0df1390ba6b5e9bc7ec458e857a)
1/*
2 * Copyright (c) 2006, 2018 Oracle and/or its affiliates. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:

--- 484 unchanged lines hidden (view full) ---

493 spin_lock_irqsave(&rds_conn_lock, flags);
494 rds_conn_count--;
495 spin_unlock_irqrestore(&rds_conn_lock, flags);
496}
497EXPORT_SYMBOL_GPL(rds_conn_destroy);
498
499static void __rds_inc_msg_cp(struct rds_incoming *inc,
500 struct rds_info_iterator *iter,
1/*
2 * Copyright (c) 2006, 2018 Oracle and/or its affiliates. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:

--- 484 unchanged lines hidden (view full) ---

493 spin_lock_irqsave(&rds_conn_lock, flags);
494 rds_conn_count--;
495 spin_unlock_irqrestore(&rds_conn_lock, flags);
496}
497EXPORT_SYMBOL_GPL(rds_conn_destroy);
498
499static void __rds_inc_msg_cp(struct rds_incoming *inc,
500 struct rds_info_iterator *iter,
501 void *saddr, void *daddr, int flip)
501 void *saddr, void *daddr, int flip, bool isv6)
502{
502{
503 rds_inc_info_copy(inc, iter, *(__be32 *)saddr,
504 *(__be32 *)daddr, flip);
503 if (isv6)
504 rds6_inc_info_copy(inc, iter, saddr, daddr, flip);
505 else
506 rds_inc_info_copy(inc, iter, *(__be32 *)saddr,
507 *(__be32 *)daddr, flip);
505}
506
507static void rds_conn_message_info_cmn(struct socket *sock, unsigned int len,
508 struct rds_info_iterator *iter,
509 struct rds_info_lengths *lens,
508}
509
510static void rds_conn_message_info_cmn(struct socket *sock, unsigned int len,
511 struct rds_info_iterator *iter,
512 struct rds_info_lengths *lens,
510 int want_send)
513 int want_send, bool isv6)
511{
512 struct hlist_head *head;
513 struct list_head *list;
514 struct rds_connection *conn;
515 struct rds_message *rm;
516 unsigned int total = 0;
517 unsigned long flags;
518 size_t i;
519 int j;
520
514{
515 struct hlist_head *head;
516 struct list_head *list;
517 struct rds_connection *conn;
518 struct rds_message *rm;
519 unsigned int total = 0;
520 unsigned long flags;
521 size_t i;
522 int j;
523
521 len /= sizeof(struct rds_info_message);
524 if (isv6)
525 len /= sizeof(struct rds6_info_message);
526 else
527 len /= sizeof(struct rds_info_message);
522
523 rcu_read_lock();
524
525 for (i = 0, head = rds_conn_hash; i < ARRAY_SIZE(rds_conn_hash);
526 i++, head++) {
527 hlist_for_each_entry_rcu(conn, head, c_hash_node) {
528 struct rds_conn_path *cp;
529 int npaths;
530
528
529 rcu_read_lock();
530
531 for (i = 0, head = rds_conn_hash; i < ARRAY_SIZE(rds_conn_hash);
532 i++, head++) {
533 hlist_for_each_entry_rcu(conn, head, c_hash_node) {
534 struct rds_conn_path *cp;
535 int npaths;
536
537 if (!isv6 && conn->c_isv6)
538 continue;
539
531 npaths = (conn->c_trans->t_mp_capable ?
532 RDS_MPATH_WORKERS : 1);
533
534 for (j = 0; j < npaths; j++) {
535 cp = &conn->c_path[j];
536 if (want_send)
537 list = &cp->cp_send_queue;
538 else

--- 4 unchanged lines hidden (view full) ---

543 /* XXX too lazy to maintain counts.. */
544 list_for_each_entry(rm, list, m_conn_item) {
545 total++;
546 if (total <= len)
547 __rds_inc_msg_cp(&rm->m_inc,
548 iter,
549 &conn->c_laddr,
550 &conn->c_faddr,
540 npaths = (conn->c_trans->t_mp_capable ?
541 RDS_MPATH_WORKERS : 1);
542
543 for (j = 0; j < npaths; j++) {
544 cp = &conn->c_path[j];
545 if (want_send)
546 list = &cp->cp_send_queue;
547 else

--- 4 unchanged lines hidden (view full) ---

552 /* XXX too lazy to maintain counts.. */
553 list_for_each_entry(rm, list, m_conn_item) {
554 total++;
555 if (total <= len)
556 __rds_inc_msg_cp(&rm->m_inc,
557 iter,
558 &conn->c_laddr,
559 &conn->c_faddr,
551 0);
560 0, isv6);
552 }
553
554 spin_unlock_irqrestore(&cp->cp_lock, flags);
555 }
556 }
557 }
558 rcu_read_unlock();
559
560 lens->nr = total;
561 }
562
563 spin_unlock_irqrestore(&cp->cp_lock, flags);
564 }
565 }
566 }
567 rcu_read_unlock();
568
569 lens->nr = total;
561 lens->each = sizeof(struct rds_info_message);
570 if (isv6)
571 lens->each = sizeof(struct rds6_info_message);
572 else
573 lens->each = sizeof(struct rds_info_message);
562}
563
564static void rds_conn_message_info(struct socket *sock, unsigned int len,
565 struct rds_info_iterator *iter,
566 struct rds_info_lengths *lens,
567 int want_send)
568{
574}
575
576static void rds_conn_message_info(struct socket *sock, unsigned int len,
577 struct rds_info_iterator *iter,
578 struct rds_info_lengths *lens,
579 int want_send)
580{
569 rds_conn_message_info_cmn(sock, len, iter, lens, want_send);
581 rds_conn_message_info_cmn(sock, len, iter, lens, want_send, false);
570}
571
582}
583
584static void rds6_conn_message_info(struct socket *sock, unsigned int len,
585 struct rds_info_iterator *iter,
586 struct rds_info_lengths *lens,
587 int want_send)
588{
589 rds_conn_message_info_cmn(sock, len, iter, lens, want_send, true);
590}
591
572static void rds_conn_message_info_send(struct socket *sock, unsigned int len,
573 struct rds_info_iterator *iter,
574 struct rds_info_lengths *lens)
575{
576 rds_conn_message_info(sock, len, iter, lens, 1);
577}
578
592static void rds_conn_message_info_send(struct socket *sock, unsigned int len,
593 struct rds_info_iterator *iter,
594 struct rds_info_lengths *lens)
595{
596 rds_conn_message_info(sock, len, iter, lens, 1);
597}
598
599static void rds6_conn_message_info_send(struct socket *sock, unsigned int len,
600 struct rds_info_iterator *iter,
601 struct rds_info_lengths *lens)
602{
603 rds6_conn_message_info(sock, len, iter, lens, 1);
604}
605
579static void rds_conn_message_info_retrans(struct socket *sock,
580 unsigned int len,
581 struct rds_info_iterator *iter,
582 struct rds_info_lengths *lens)
583{
584 rds_conn_message_info(sock, len, iter, lens, 0);
585}
586
606static void rds_conn_message_info_retrans(struct socket *sock,
607 unsigned int len,
608 struct rds_info_iterator *iter,
609 struct rds_info_lengths *lens)
610{
611 rds_conn_message_info(sock, len, iter, lens, 0);
612}
613
614static void rds6_conn_message_info_retrans(struct socket *sock,
615 unsigned int len,
616 struct rds_info_iterator *iter,
617 struct rds_info_lengths *lens)
618{
619 rds6_conn_message_info(sock, len, iter, lens, 0);
620}
621
587void rds_for_each_conn_info(struct socket *sock, unsigned int len,
588 struct rds_info_iterator *iter,
589 struct rds_info_lengths *lens,
590 int (*visitor)(struct rds_connection *, void *),
591 u64 *buffer,
592 size_t item_len)
593{
594 struct hlist_head *head;

--- 99 unchanged lines hidden (view full) ---

694 atomic_read(&cp->cp_state) == RDS_CONN_CONNECTING,
695 CONNECTING);
696 rds_conn_info_set(cinfo->flags,
697 atomic_read(&cp->cp_state) == RDS_CONN_UP,
698 CONNECTED);
699 return 1;
700}
701
622void rds_for_each_conn_info(struct socket *sock, unsigned int len,
623 struct rds_info_iterator *iter,
624 struct rds_info_lengths *lens,
625 int (*visitor)(struct rds_connection *, void *),
626 u64 *buffer,
627 size_t item_len)
628{
629 struct hlist_head *head;

--- 99 unchanged lines hidden (view full) ---

729 atomic_read(&cp->cp_state) == RDS_CONN_CONNECTING,
730 CONNECTING);
731 rds_conn_info_set(cinfo->flags,
732 atomic_read(&cp->cp_state) == RDS_CONN_UP,
733 CONNECTED);
734 return 1;
735}
736
737static int rds6_conn_info_visitor(struct rds_conn_path *cp, void *buffer)
738{
739 struct rds6_info_connection *cinfo6 = buffer;
740 struct rds_connection *conn = cp->cp_conn;
741
742 cinfo6->next_tx_seq = cp->cp_next_tx_seq;
743 cinfo6->next_rx_seq = cp->cp_next_rx_seq;
744 cinfo6->laddr = conn->c_laddr;
745 cinfo6->faddr = conn->c_faddr;
746 strncpy(cinfo6->transport, conn->c_trans->t_name,
747 sizeof(cinfo6->transport));
748 cinfo6->flags = 0;
749
750 rds_conn_info_set(cinfo6->flags, test_bit(RDS_IN_XMIT, &cp->cp_flags),
751 SENDING);
752 /* XXX Future: return the state rather than these funky bits */
753 rds_conn_info_set(cinfo6->flags,
754 atomic_read(&cp->cp_state) == RDS_CONN_CONNECTING,
755 CONNECTING);
756 rds_conn_info_set(cinfo6->flags,
757 atomic_read(&cp->cp_state) == RDS_CONN_UP,
758 CONNECTED);
759 /* Just return 1 as there is no error case. This is a helper function
760 * for rds_walk_conn_path_info() and it wants a return value.
761 */
762 return 1;
763}
764
702static void rds_conn_info(struct socket *sock, unsigned int len,
703 struct rds_info_iterator *iter,
704 struct rds_info_lengths *lens)
705{
706 u64 buffer[(sizeof(struct rds_info_connection) + 7) / 8];
707
708 rds_walk_conn_path_info(sock, len, iter, lens,
709 rds_conn_info_visitor,
710 buffer,
711 sizeof(struct rds_info_connection));
712}
713
765static void rds_conn_info(struct socket *sock, unsigned int len,
766 struct rds_info_iterator *iter,
767 struct rds_info_lengths *lens)
768{
769 u64 buffer[(sizeof(struct rds_info_connection) + 7) / 8];
770
771 rds_walk_conn_path_info(sock, len, iter, lens,
772 rds_conn_info_visitor,
773 buffer,
774 sizeof(struct rds_info_connection));
775}
776
777static void rds6_conn_info(struct socket *sock, unsigned int len,
778 struct rds_info_iterator *iter,
779 struct rds_info_lengths *lens)
780{
781 u64 buffer[(sizeof(struct rds6_info_connection) + 7) / 8];
782
783 rds_walk_conn_path_info(sock, len, iter, lens,
784 rds6_conn_info_visitor,
785 buffer,
786 sizeof(struct rds6_info_connection));
787}
788
714int rds_conn_init(void)
715{
716 int ret;
717
718 ret = rds_loop_net_init(); /* register pernet callback */
719 if (ret)
720 return ret;
721

--- 5 unchanged lines hidden (view full) ---

727 return -ENOMEM;
728 }
729
730 rds_info_register_func(RDS_INFO_CONNECTIONS, rds_conn_info);
731 rds_info_register_func(RDS_INFO_SEND_MESSAGES,
732 rds_conn_message_info_send);
733 rds_info_register_func(RDS_INFO_RETRANS_MESSAGES,
734 rds_conn_message_info_retrans);
789int rds_conn_init(void)
790{
791 int ret;
792
793 ret = rds_loop_net_init(); /* register pernet callback */
794 if (ret)
795 return ret;
796

--- 5 unchanged lines hidden (view full) ---

802 return -ENOMEM;
803 }
804
805 rds_info_register_func(RDS_INFO_CONNECTIONS, rds_conn_info);
806 rds_info_register_func(RDS_INFO_SEND_MESSAGES,
807 rds_conn_message_info_send);
808 rds_info_register_func(RDS_INFO_RETRANS_MESSAGES,
809 rds_conn_message_info_retrans);
810 rds_info_register_func(RDS6_INFO_CONNECTIONS, rds6_conn_info);
811 rds_info_register_func(RDS6_INFO_SEND_MESSAGES,
812 rds6_conn_message_info_send);
813 rds_info_register_func(RDS6_INFO_RETRANS_MESSAGES,
814 rds6_conn_message_info_retrans);
735
736 return 0;
737}
738
739void rds_conn_exit(void)
740{
741 rds_loop_net_exit(); /* unregister pernet callback */
742 rds_loop_exit();
743
744 WARN_ON(!hlist_empty(rds_conn_hash));
745
746 kmem_cache_destroy(rds_conn_slab);
747
748 rds_info_deregister_func(RDS_INFO_CONNECTIONS, rds_conn_info);
749 rds_info_deregister_func(RDS_INFO_SEND_MESSAGES,
750 rds_conn_message_info_send);
751 rds_info_deregister_func(RDS_INFO_RETRANS_MESSAGES,
752 rds_conn_message_info_retrans);
815
816 return 0;
817}
818
819void rds_conn_exit(void)
820{
821 rds_loop_net_exit(); /* unregister pernet callback */
822 rds_loop_exit();
823
824 WARN_ON(!hlist_empty(rds_conn_hash));
825
826 kmem_cache_destroy(rds_conn_slab);
827
828 rds_info_deregister_func(RDS_INFO_CONNECTIONS, rds_conn_info);
829 rds_info_deregister_func(RDS_INFO_SEND_MESSAGES,
830 rds_conn_message_info_send);
831 rds_info_deregister_func(RDS_INFO_RETRANS_MESSAGES,
832 rds_conn_message_info_retrans);
833 rds_info_deregister_func(RDS6_INFO_CONNECTIONS, rds6_conn_info);
834 rds_info_deregister_func(RDS6_INFO_SEND_MESSAGES,
835 rds6_conn_message_info_send);
836 rds_info_deregister_func(RDS6_INFO_RETRANS_MESSAGES,
837 rds6_conn_message_info_retrans);
753}
754
755/*
756 * Force a disconnect
757 */
758void rds_conn_path_drop(struct rds_conn_path *cp, bool destroy)
759{
760 atomic_set(&cp->cp_state, RDS_CONN_ERROR);

--- 54 unchanged lines hidden ---
838}
839
840/*
841 * Force a disconnect
842 */
843void rds_conn_path_drop(struct rds_conn_path *cp, bool destroy)
844{
845 atomic_set(&cp->cp_state, RDS_CONN_ERROR);

--- 54 unchanged lines hidden ---