blob: 56a530996a4a797207fa88cd4cde8f9c3bd5e8d3 [file] [log] [blame]
Andy Grover0fbc78c2009-02-24 15:30:21 +00001/*
2 * Copyright (c) 2006 Oracle. 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:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 *
32 */
33#include <linux/kernel.h>
34#include <linux/module.h>
35#include <linux/in.h>
36
37#include "rds.h"
38#include "loop.h"
39
40static LIST_HEAD(rds_transports);
41static DECLARE_RWSEM(rds_trans_sem);
42
43int rds_trans_register(struct rds_transport *trans)
44{
45 BUG_ON(strlen(trans->t_name) + 1 > TRANSNAMSIZ);
46
47 down_write(&rds_trans_sem);
48
49 list_add_tail(&trans->t_item, &rds_transports);
50 printk(KERN_INFO "Registered RDS/%s transport\n", trans->t_name);
51
52 up_write(&rds_trans_sem);
53
54 return 0;
55}
Andy Grover616b7572009-08-21 12:28:32 +000056EXPORT_SYMBOL_GPL(rds_trans_register);
Andy Grover0fbc78c2009-02-24 15:30:21 +000057
58void rds_trans_unregister(struct rds_transport *trans)
59{
60 down_write(&rds_trans_sem);
61
62 list_del_init(&trans->t_item);
63 printk(KERN_INFO "Unregistered RDS/%s transport\n", trans->t_name);
64
65 up_write(&rds_trans_sem);
66}
Andy Grover616b7572009-08-21 12:28:32 +000067EXPORT_SYMBOL_GPL(rds_trans_unregister);
Andy Grover0fbc78c2009-02-24 15:30:21 +000068
69struct rds_transport *rds_trans_get_preferred(__be32 addr)
70{
71 struct rds_transport *trans;
72 struct rds_transport *ret = NULL;
73
74 if (IN_LOOPBACK(ntohl(addr)))
75 return &rds_loop_transport;
76
77 down_read(&rds_trans_sem);
78 list_for_each_entry(trans, &rds_transports, t_item) {
79 if (trans->laddr_check(addr) == 0) {
80 ret = trans;
81 break;
82 }
83 }
84 up_read(&rds_trans_sem);
85
86 return ret;
87}
88
89/*
90 * This returns the number of stats entries in the snapshot and only
91 * copies them using the iter if there is enough space for them. The
92 * caller passes in the global stats so that we can size and copy while
93 * holding the lock.
94 */
95unsigned int rds_trans_stats_info_copy(struct rds_info_iterator *iter,
96 unsigned int avail)
97
98{
99 struct rds_transport *trans;
100 unsigned int total = 0;
101 unsigned int part;
102
103 rds_info_iter_unmap(iter);
104 down_read(&rds_trans_sem);
105
106 list_for_each_entry(trans, &rds_transports, t_item) {
107 if (trans->stats_info_copy == NULL)
108 continue;
109
110 part = trans->stats_info_copy(iter, avail);
111 avail -= min(avail, part);
112 total += part;
113 }
114
115 up_read(&rds_trans_sem);
116
117 return total;
118}
119