^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * Copyright (c) 2006, 2018 Oracle and/or its affiliates. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * This software is available to you under a choice of one of two
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * licenses. You may choose to be licensed under the terms of the GNU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * General Public License (GPL) Version 2, available from the file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * COPYING in the main directory of this source tree, or the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * OpenIB.org BSD license below:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Redistribution and use in source and binary forms, with or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * without modification, are permitted provided that the following
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * conditions are met:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * - Redistributions of source code must retain the above
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * copyright notice, this list of conditions and the following
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * disclaimer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * - Redistributions in binary form must reproduce the above
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * copyright notice, this list of conditions and the following
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * disclaimer in the documentation and/or other materials
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * provided with the distribution.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * SOFTWARE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <net/ipv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <net/inet6_hashtables.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <net/addrconf.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #include "rds.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #include "loop.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #define RDS_CONNECTION_HASH_BITS 12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #define RDS_CONNECTION_HASH_ENTRIES (1 << RDS_CONNECTION_HASH_BITS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define RDS_CONNECTION_HASH_MASK (RDS_CONNECTION_HASH_ENTRIES - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) /* converting this to RCU is a chore for another day.. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) static DEFINE_SPINLOCK(rds_conn_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) static unsigned long rds_conn_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) static struct hlist_head rds_conn_hash[RDS_CONNECTION_HASH_ENTRIES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) static struct kmem_cache *rds_conn_slab;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) static struct hlist_head *rds_conn_bucket(const struct in6_addr *laddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) const struct in6_addr *faddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) static u32 rds6_hash_secret __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) static u32 rds_hash_secret __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) u32 lhash, fhash, hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) net_get_random_once(&rds_hash_secret, sizeof(rds_hash_secret));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) net_get_random_once(&rds6_hash_secret, sizeof(rds6_hash_secret));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) lhash = (__force u32)laddr->s6_addr32[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) #if IS_ENABLED(CONFIG_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) fhash = __ipv6_addr_jhash(faddr, rds6_hash_secret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) fhash = (__force u32)faddr->s6_addr32[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) hash = __inet_ehashfn(lhash, 0, fhash, 0, rds_hash_secret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) return &rds_conn_hash[hash & RDS_CONNECTION_HASH_MASK];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) #define rds_conn_info_set(var, test, suffix) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) if (test) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) var |= RDS_INFO_CONNECTION_FLAG_##suffix; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) /* rcu read lock must be held or the connection spinlock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) static struct rds_connection *rds_conn_lookup(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) struct hlist_head *head,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) const struct in6_addr *laddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) const struct in6_addr *faddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) struct rds_transport *trans,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) u8 tos, int dev_if)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) struct rds_connection *conn, *ret = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) hlist_for_each_entry_rcu(conn, head, c_hash_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) if (ipv6_addr_equal(&conn->c_faddr, faddr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) ipv6_addr_equal(&conn->c_laddr, laddr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) conn->c_trans == trans &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) conn->c_tos == tos &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) net == rds_conn_net(conn) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) conn->c_dev_if == dev_if) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) ret = conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) rdsdebug("returning conn %p for %pI6c -> %pI6c\n", ret,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) laddr, faddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) * This is called by transports as they're bringing down a connection.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) * It clears partial message state so that the transport can start sending
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * and receiving over this connection again in the future. It is up to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * the transport to have serialized this call with its send and recv.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static void rds_conn_path_reset(struct rds_conn_path *cp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) struct rds_connection *conn = cp->cp_conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) rdsdebug("connection %pI6c to %pI6c reset\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) &conn->c_laddr, &conn->c_faddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) rds_stats_inc(s_conn_reset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) rds_send_path_reset(cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) cp->cp_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) /* Do not clear next_rx_seq here, else we cannot distinguish
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) * retransmitted packets from new packets, and will hand all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) * of them to the application. That is not consistent with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) * reliability guarantees of RDS. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) static void __rds_conn_path_init(struct rds_connection *conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) struct rds_conn_path *cp, bool is_outgoing)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) spin_lock_init(&cp->cp_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) cp->cp_next_tx_seq = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) init_waitqueue_head(&cp->cp_waitq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) INIT_LIST_HEAD(&cp->cp_send_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) INIT_LIST_HEAD(&cp->cp_retrans);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) cp->cp_conn = conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) atomic_set(&cp->cp_state, RDS_CONN_DOWN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) cp->cp_send_gen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) cp->cp_reconnect_jiffies = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) cp->cp_conn->c_proposed_version = RDS_PROTOCOL_VERSION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) INIT_DELAYED_WORK(&cp->cp_send_w, rds_send_worker);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) INIT_DELAYED_WORK(&cp->cp_recv_w, rds_recv_worker);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) INIT_DELAYED_WORK(&cp->cp_conn_w, rds_connect_worker);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) INIT_WORK(&cp->cp_down_w, rds_shutdown_worker);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) mutex_init(&cp->cp_cm_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) cp->cp_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) * There is only every one 'conn' for a given pair of addresses in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) * system at a time. They contain messages to be retransmitted and so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) * span the lifetime of the actual underlying transport connections.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) * For now they are not garbage collected once they're created. They
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) * are torn down as the module is removed, if ever.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) static struct rds_connection *__rds_conn_create(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) const struct in6_addr *laddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) const struct in6_addr *faddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) struct rds_transport *trans,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) gfp_t gfp, u8 tos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) int is_outgoing,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) int dev_if)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) struct rds_connection *conn, *parent = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) struct hlist_head *head = rds_conn_bucket(laddr, faddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) struct rds_transport *loop_trans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) int ret, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) int npaths = (trans->t_mp_capable ? RDS_MPATH_WORKERS : 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) conn = rds_conn_lookup(net, head, laddr, faddr, trans, tos, dev_if);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) if (conn &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) conn->c_loopback &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) conn->c_trans != &rds_loop_transport &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) ipv6_addr_equal(laddr, faddr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) !is_outgoing) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) /* This is a looped back IB connection, and we're
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) * called by the code handling the incoming connect.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) * We need a second connection object into which we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) * can stick the other QP. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) parent = conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) conn = parent->c_passive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) if (conn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) conn = kmem_cache_zalloc(rds_conn_slab, gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) if (!conn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) conn = ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) conn->c_path = kcalloc(npaths, sizeof(struct rds_conn_path), gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) if (!conn->c_path) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) kmem_cache_free(rds_conn_slab, conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) conn = ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) INIT_HLIST_NODE(&conn->c_hash_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) conn->c_laddr = *laddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) conn->c_isv6 = !ipv6_addr_v4mapped(laddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) conn->c_faddr = *faddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) conn->c_dev_if = dev_if;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) conn->c_tos = tos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) #if IS_ENABLED(CONFIG_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) /* If the local address is link local, set c_bound_if to be the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) * index used for this connection. Otherwise, set it to 0 as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) * the socket is not bound to an interface. c_bound_if is used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) * to look up a socket when a packet is received
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) if (ipv6_addr_type(laddr) & IPV6_ADDR_LINKLOCAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) conn->c_bound_if = dev_if;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) conn->c_bound_if = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) rds_conn_net_set(conn, net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) ret = rds_cong_get_maps(conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) kfree(conn->c_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) kmem_cache_free(rds_conn_slab, conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) conn = ERR_PTR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) * This is where a connection becomes loopback. If *any* RDS sockets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) * can bind to the destination address then we'd rather the messages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) * flow through loopback rather than either transport.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) loop_trans = rds_trans_get_preferred(net, faddr, conn->c_dev_if);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) if (loop_trans) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) rds_trans_put(loop_trans);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) conn->c_loopback = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) if (trans->t_prefer_loopback) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) if (likely(is_outgoing)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) /* "outgoing" connection to local address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) * Protocol says it wants the connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) * handled by the loopback transport.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) * This is what TCP does.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) trans = &rds_loop_transport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) /* No transport currently in use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) * should end up here, but if it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) * does, reset/destroy the connection.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) kfree(conn->c_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) kmem_cache_free(rds_conn_slab, conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) conn = ERR_PTR(-EOPNOTSUPP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) conn->c_trans = trans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) init_waitqueue_head(&conn->c_hs_waitq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) for (i = 0; i < npaths; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) __rds_conn_path_init(conn, &conn->c_path[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) is_outgoing);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) conn->c_path[i].cp_index = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) if (rds_destroy_pending(conn))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) ret = -ENETDOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) ret = trans->conn_alloc(conn, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) kfree(conn->c_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) kmem_cache_free(rds_conn_slab, conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) conn = ERR_PTR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) rdsdebug("allocated conn %p for %pI6c -> %pI6c over %s %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) conn, laddr, faddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) strnlen(trans->t_name, sizeof(trans->t_name)) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) trans->t_name : "[unknown]", is_outgoing ? "(outgoing)" : "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) * Since we ran without holding the conn lock, someone could
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) * have created the same conn (either normal or passive) in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) * interim. We check while holding the lock. If we won, we complete
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) * init and return our conn. If we lost, we rollback and return the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) * other one.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) spin_lock_irqsave(&rds_conn_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) if (parent) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) /* Creating passive conn */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) if (parent->c_passive) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) trans->conn_free(conn->c_path[0].cp_transport_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) kfree(conn->c_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) kmem_cache_free(rds_conn_slab, conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) conn = parent->c_passive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) parent->c_passive = conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) rds_cong_add_conn(conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) rds_conn_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) /* Creating normal conn */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) struct rds_connection *found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) found = rds_conn_lookup(net, head, laddr, faddr, trans,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) tos, dev_if);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) if (found) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) struct rds_conn_path *cp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) for (i = 0; i < npaths; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) cp = &conn->c_path[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) /* The ->conn_alloc invocation may have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) * allocated resource for all paths, so all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) * of them may have to be freed here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) if (cp->cp_transport_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) trans->conn_free(cp->cp_transport_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) kfree(conn->c_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) kmem_cache_free(rds_conn_slab, conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) conn = found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) conn->c_my_gen_num = rds_gen_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) conn->c_peer_gen_num = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) hlist_add_head_rcu(&conn->c_hash_node, head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) rds_cong_add_conn(conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) rds_conn_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) spin_unlock_irqrestore(&rds_conn_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) return conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) struct rds_connection *rds_conn_create(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) const struct in6_addr *laddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) const struct in6_addr *faddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) struct rds_transport *trans, u8 tos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) gfp_t gfp, int dev_if)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) return __rds_conn_create(net, laddr, faddr, trans, gfp, tos, 0, dev_if);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) EXPORT_SYMBOL_GPL(rds_conn_create);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) struct rds_connection *rds_conn_create_outgoing(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) const struct in6_addr *laddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) const struct in6_addr *faddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) struct rds_transport *trans,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) u8 tos, gfp_t gfp, int dev_if)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) return __rds_conn_create(net, laddr, faddr, trans, gfp, tos, 1, dev_if);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) EXPORT_SYMBOL_GPL(rds_conn_create_outgoing);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) void rds_conn_shutdown(struct rds_conn_path *cp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) struct rds_connection *conn = cp->cp_conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) /* shut it down unless it's down already */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) if (!rds_conn_path_transition(cp, RDS_CONN_DOWN, RDS_CONN_DOWN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) * Quiesce the connection mgmt handlers before we start tearing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) * things down. We don't hold the mutex for the entire
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) * duration of the shutdown operation, else we may be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) * deadlocking with the CM handler. Instead, the CM event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) * handler is supposed to check for state DISCONNECTING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) mutex_lock(&cp->cp_cm_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) if (!rds_conn_path_transition(cp, RDS_CONN_UP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) RDS_CONN_DISCONNECTING) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) !rds_conn_path_transition(cp, RDS_CONN_ERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) RDS_CONN_DISCONNECTING)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) rds_conn_path_error(cp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) "shutdown called in state %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) atomic_read(&cp->cp_state));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) mutex_unlock(&cp->cp_cm_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) mutex_unlock(&cp->cp_cm_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) wait_event(cp->cp_waitq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) !test_bit(RDS_IN_XMIT, &cp->cp_flags));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) wait_event(cp->cp_waitq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) !test_bit(RDS_RECV_REFILL, &cp->cp_flags));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) conn->c_trans->conn_path_shutdown(cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) rds_conn_path_reset(cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) if (!rds_conn_path_transition(cp, RDS_CONN_DISCONNECTING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) RDS_CONN_DOWN) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) !rds_conn_path_transition(cp, RDS_CONN_ERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) RDS_CONN_DOWN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) /* This can happen - eg when we're in the middle of tearing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) * down the connection, and someone unloads the rds module.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) * Quite reproducible with loopback connections.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) * Mostly harmless.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) * Note that this also happens with rds-tcp because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) * we could have triggered rds_conn_path_drop in irq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) * mode from rds_tcp_state change on the receipt of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) * a FIN, thus we need to recheck for RDS_CONN_ERROR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) * here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) rds_conn_path_error(cp, "%s: failed to transition "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) "to state DOWN, current state "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) "is %d\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) atomic_read(&cp->cp_state));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) /* Then reconnect if it's still live.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) * The passive side of an IB loopback connection is never added
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) * to the conn hash, so we never trigger a reconnect on this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) * conn - the reconnect is always triggered by the active peer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) cancel_delayed_work_sync(&cp->cp_conn_w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) if (!hlist_unhashed(&conn->c_hash_node)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) rds_queue_reconnect(cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) /* destroy a single rds_conn_path. rds_conn_destroy() iterates over
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) * all paths using rds_conn_path_destroy()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) static void rds_conn_path_destroy(struct rds_conn_path *cp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) struct rds_message *rm, *rtmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) if (!cp->cp_transport_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) /* make sure lingering queued work won't try to ref the conn */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) cancel_delayed_work_sync(&cp->cp_send_w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) cancel_delayed_work_sync(&cp->cp_recv_w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) rds_conn_path_drop(cp, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) flush_work(&cp->cp_down_w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) /* tear down queued messages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) list_for_each_entry_safe(rm, rtmp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) &cp->cp_send_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) m_conn_item) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) list_del_init(&rm->m_conn_item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) BUG_ON(!list_empty(&rm->m_sock_item));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) rds_message_put(rm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) if (cp->cp_xmit_rm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) rds_message_put(cp->cp_xmit_rm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) WARN_ON(delayed_work_pending(&cp->cp_send_w));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) WARN_ON(delayed_work_pending(&cp->cp_recv_w));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) WARN_ON(delayed_work_pending(&cp->cp_conn_w));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) WARN_ON(work_pending(&cp->cp_down_w));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) cp->cp_conn->c_trans->conn_free(cp->cp_transport_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) * Stop and free a connection.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) * This can only be used in very limited circumstances. It assumes that once
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) * the conn has been shutdown that no one else is referencing the connection.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) * We can only ensure this in the rmmod path in the current code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) void rds_conn_destroy(struct rds_connection *conn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) struct rds_conn_path *cp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) int npaths = (conn->c_trans->t_mp_capable ? RDS_MPATH_WORKERS : 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) rdsdebug("freeing conn %p for %pI4 -> "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) "%pI4\n", conn, &conn->c_laddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) &conn->c_faddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) /* Ensure conn will not be scheduled for reconnect */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) spin_lock_irq(&rds_conn_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) hlist_del_init_rcu(&conn->c_hash_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) spin_unlock_irq(&rds_conn_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) synchronize_rcu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) /* shut the connection down */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) for (i = 0; i < npaths; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) cp = &conn->c_path[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) rds_conn_path_destroy(cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) BUG_ON(!list_empty(&cp->cp_retrans));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) * The congestion maps aren't freed up here. They're
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) * freed by rds_cong_exit() after all the connections
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) * have been freed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) rds_cong_remove_conn(conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) kfree(conn->c_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) kmem_cache_free(rds_conn_slab, conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) spin_lock_irqsave(&rds_conn_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) rds_conn_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) spin_unlock_irqrestore(&rds_conn_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) EXPORT_SYMBOL_GPL(rds_conn_destroy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) static void __rds_inc_msg_cp(struct rds_incoming *inc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) struct rds_info_iterator *iter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) void *saddr, void *daddr, int flip, bool isv6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) #if IS_ENABLED(CONFIG_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) if (isv6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) rds6_inc_info_copy(inc, iter, saddr, daddr, flip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) rds_inc_info_copy(inc, iter, *(__be32 *)saddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) *(__be32 *)daddr, flip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) static void rds_conn_message_info_cmn(struct socket *sock, unsigned int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) struct rds_info_iterator *iter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) struct rds_info_lengths *lens,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) int want_send, bool isv6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) struct hlist_head *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) struct list_head *list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) struct rds_connection *conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) struct rds_message *rm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) unsigned int total = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) size_t i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) int j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) if (isv6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) len /= sizeof(struct rds6_info_message);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) len /= sizeof(struct rds_info_message);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) for (i = 0, head = rds_conn_hash; i < ARRAY_SIZE(rds_conn_hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) i++, head++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) hlist_for_each_entry_rcu(conn, head, c_hash_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) struct rds_conn_path *cp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) int npaths;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) if (!isv6 && conn->c_isv6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) npaths = (conn->c_trans->t_mp_capable ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) RDS_MPATH_WORKERS : 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) for (j = 0; j < npaths; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) cp = &conn->c_path[j];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) if (want_send)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) list = &cp->cp_send_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) list = &cp->cp_retrans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) spin_lock_irqsave(&cp->cp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) /* XXX too lazy to maintain counts.. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) list_for_each_entry(rm, list, m_conn_item) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) total++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) if (total <= len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) __rds_inc_msg_cp(&rm->m_inc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) iter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) &conn->c_laddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) &conn->c_faddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 0, isv6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) spin_unlock_irqrestore(&cp->cp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) lens->nr = total;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) if (isv6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) lens->each = sizeof(struct rds6_info_message);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) lens->each = sizeof(struct rds_info_message);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) static void rds_conn_message_info(struct socket *sock, unsigned int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) struct rds_info_iterator *iter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) struct rds_info_lengths *lens,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) int want_send)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) rds_conn_message_info_cmn(sock, len, iter, lens, want_send, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) #if IS_ENABLED(CONFIG_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) static void rds6_conn_message_info(struct socket *sock, unsigned int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) struct rds_info_iterator *iter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) struct rds_info_lengths *lens,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) int want_send)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) rds_conn_message_info_cmn(sock, len, iter, lens, want_send, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) static void rds_conn_message_info_send(struct socket *sock, unsigned int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) struct rds_info_iterator *iter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) struct rds_info_lengths *lens)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) rds_conn_message_info(sock, len, iter, lens, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) #if IS_ENABLED(CONFIG_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) static void rds6_conn_message_info_send(struct socket *sock, unsigned int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) struct rds_info_iterator *iter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) struct rds_info_lengths *lens)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) rds6_conn_message_info(sock, len, iter, lens, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) static void rds_conn_message_info_retrans(struct socket *sock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) unsigned int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) struct rds_info_iterator *iter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) struct rds_info_lengths *lens)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) rds_conn_message_info(sock, len, iter, lens, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) #if IS_ENABLED(CONFIG_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) static void rds6_conn_message_info_retrans(struct socket *sock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) unsigned int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) struct rds_info_iterator *iter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) struct rds_info_lengths *lens)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) rds6_conn_message_info(sock, len, iter, lens, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) void rds_for_each_conn_info(struct socket *sock, unsigned int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) struct rds_info_iterator *iter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) struct rds_info_lengths *lens,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) int (*visitor)(struct rds_connection *, void *),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) u64 *buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) size_t item_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) struct hlist_head *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) struct rds_connection *conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) size_t i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) lens->nr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) lens->each = item_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) for (i = 0, head = rds_conn_hash; i < ARRAY_SIZE(rds_conn_hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) i++, head++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) hlist_for_each_entry_rcu(conn, head, c_hash_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) /* XXX no c_lock usage.. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) if (!visitor(conn, buffer))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) /* We copy as much as we can fit in the buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) * but we count all items so that the caller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) * can resize the buffer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) if (len >= item_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) rds_info_copy(iter, buffer, item_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) len -= item_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) lens->nr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) EXPORT_SYMBOL_GPL(rds_for_each_conn_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) static void rds_walk_conn_path_info(struct socket *sock, unsigned int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) struct rds_info_iterator *iter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) struct rds_info_lengths *lens,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) int (*visitor)(struct rds_conn_path *, void *),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) u64 *buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) size_t item_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) struct hlist_head *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) struct rds_connection *conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) size_t i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) lens->nr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) lens->each = item_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) for (i = 0, head = rds_conn_hash; i < ARRAY_SIZE(rds_conn_hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) i++, head++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) hlist_for_each_entry_rcu(conn, head, c_hash_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) struct rds_conn_path *cp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) /* XXX We only copy the information from the first
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) * path for now. The problem is that if there are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) * more than one underlying paths, we cannot report
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) * information of all of them using the existing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) * API. For example, there is only one next_tx_seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) * which path's next_tx_seq should we report? It is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) * a bug in the design of MPRDS.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) cp = conn->c_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) /* XXX no cp_lock usage.. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) if (!visitor(cp, buffer))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) /* We copy as much as we can fit in the buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) * but we count all items so that the caller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) * can resize the buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) if (len >= item_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) rds_info_copy(iter, buffer, item_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) len -= item_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) lens->nr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) static int rds_conn_info_visitor(struct rds_conn_path *cp, void *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) struct rds_info_connection *cinfo = buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) struct rds_connection *conn = cp->cp_conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) if (conn->c_isv6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) cinfo->next_tx_seq = cp->cp_next_tx_seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) cinfo->next_rx_seq = cp->cp_next_rx_seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) cinfo->laddr = conn->c_laddr.s6_addr32[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) cinfo->faddr = conn->c_faddr.s6_addr32[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) cinfo->tos = conn->c_tos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) strncpy(cinfo->transport, conn->c_trans->t_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) sizeof(cinfo->transport));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) cinfo->flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) rds_conn_info_set(cinfo->flags, test_bit(RDS_IN_XMIT, &cp->cp_flags),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) SENDING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) /* XXX Future: return the state rather than these funky bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) rds_conn_info_set(cinfo->flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) atomic_read(&cp->cp_state) == RDS_CONN_CONNECTING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) CONNECTING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) rds_conn_info_set(cinfo->flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) atomic_read(&cp->cp_state) == RDS_CONN_UP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) CONNECTED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) #if IS_ENABLED(CONFIG_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) static int rds6_conn_info_visitor(struct rds_conn_path *cp, void *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) struct rds6_info_connection *cinfo6 = buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) struct rds_connection *conn = cp->cp_conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) cinfo6->next_tx_seq = cp->cp_next_tx_seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) cinfo6->next_rx_seq = cp->cp_next_rx_seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) cinfo6->laddr = conn->c_laddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) cinfo6->faddr = conn->c_faddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) strncpy(cinfo6->transport, conn->c_trans->t_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) sizeof(cinfo6->transport));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) cinfo6->flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) rds_conn_info_set(cinfo6->flags, test_bit(RDS_IN_XMIT, &cp->cp_flags),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) SENDING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) /* XXX Future: return the state rather than these funky bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) rds_conn_info_set(cinfo6->flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) atomic_read(&cp->cp_state) == RDS_CONN_CONNECTING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) CONNECTING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) rds_conn_info_set(cinfo6->flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) atomic_read(&cp->cp_state) == RDS_CONN_UP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) CONNECTED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) /* Just return 1 as there is no error case. This is a helper function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) * for rds_walk_conn_path_info() and it wants a return value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) static void rds_conn_info(struct socket *sock, unsigned int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) struct rds_info_iterator *iter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) struct rds_info_lengths *lens)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) u64 buffer[(sizeof(struct rds_info_connection) + 7) / 8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) rds_walk_conn_path_info(sock, len, iter, lens,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) rds_conn_info_visitor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) sizeof(struct rds_info_connection));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) #if IS_ENABLED(CONFIG_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) static void rds6_conn_info(struct socket *sock, unsigned int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) struct rds_info_iterator *iter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) struct rds_info_lengths *lens)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) u64 buffer[(sizeof(struct rds6_info_connection) + 7) / 8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) rds_walk_conn_path_info(sock, len, iter, lens,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) rds6_conn_info_visitor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) sizeof(struct rds6_info_connection));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) int rds_conn_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) ret = rds_loop_net_init(); /* register pernet callback */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) rds_conn_slab = kmem_cache_create("rds_connection",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) sizeof(struct rds_connection),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) 0, 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) if (!rds_conn_slab) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) rds_loop_net_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) rds_info_register_func(RDS_INFO_CONNECTIONS, rds_conn_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) rds_info_register_func(RDS_INFO_SEND_MESSAGES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) rds_conn_message_info_send);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) rds_info_register_func(RDS_INFO_RETRANS_MESSAGES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) rds_conn_message_info_retrans);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) #if IS_ENABLED(CONFIG_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) rds_info_register_func(RDS6_INFO_CONNECTIONS, rds6_conn_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) rds_info_register_func(RDS6_INFO_SEND_MESSAGES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) rds6_conn_message_info_send);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) rds_info_register_func(RDS6_INFO_RETRANS_MESSAGES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) rds6_conn_message_info_retrans);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) void rds_conn_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) rds_loop_net_exit(); /* unregister pernet callback */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) rds_loop_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) WARN_ON(!hlist_empty(rds_conn_hash));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) kmem_cache_destroy(rds_conn_slab);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) rds_info_deregister_func(RDS_INFO_CONNECTIONS, rds_conn_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) rds_info_deregister_func(RDS_INFO_SEND_MESSAGES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) rds_conn_message_info_send);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) rds_info_deregister_func(RDS_INFO_RETRANS_MESSAGES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) rds_conn_message_info_retrans);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) #if IS_ENABLED(CONFIG_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) rds_info_deregister_func(RDS6_INFO_CONNECTIONS, rds6_conn_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) rds_info_deregister_func(RDS6_INFO_SEND_MESSAGES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) rds6_conn_message_info_send);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) rds_info_deregister_func(RDS6_INFO_RETRANS_MESSAGES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) rds6_conn_message_info_retrans);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) * Force a disconnect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) void rds_conn_path_drop(struct rds_conn_path *cp, bool destroy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) atomic_set(&cp->cp_state, RDS_CONN_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) if (!destroy && rds_destroy_pending(cp->cp_conn)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) queue_work(rds_wq, &cp->cp_down_w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) EXPORT_SYMBOL_GPL(rds_conn_path_drop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) void rds_conn_drop(struct rds_connection *conn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) WARN_ON(conn->c_trans->t_mp_capable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) rds_conn_path_drop(&conn->c_path[0], false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) EXPORT_SYMBOL_GPL(rds_conn_drop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) * If the connection is down, trigger a connect. We may have scheduled a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) * delayed reconnect however - in this case we should not interfere.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) void rds_conn_path_connect_if_down(struct rds_conn_path *cp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) if (rds_destroy_pending(cp->cp_conn)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) if (rds_conn_path_state(cp) == RDS_CONN_DOWN &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) !test_and_set_bit(RDS_RECONNECT_PENDING, &cp->cp_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) queue_delayed_work(rds_wq, &cp->cp_conn_w, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) EXPORT_SYMBOL_GPL(rds_conn_path_connect_if_down);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) /* Check connectivity of all paths
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) void rds_check_all_paths(struct rds_connection *conn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) rds_conn_path_connect_if_down(&conn->c_path[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) } while (++i < conn->c_npaths);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) void rds_conn_connect_if_down(struct rds_connection *conn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) WARN_ON(conn->c_trans->t_mp_capable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) rds_conn_path_connect_if_down(&conn->c_path[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) EXPORT_SYMBOL_GPL(rds_conn_connect_if_down);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) __rds_conn_path_error(struct rds_conn_path *cp, const char *fmt, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) va_list ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) va_start(ap, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) vprintk(fmt, ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) va_end(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) rds_conn_path_drop(cp, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) }