]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - net/rds/transport.c
Merge tag 'efi-urgent' of git://git.kernel.org/pub/scm/linux/kernel/git/efi/efi into...
[mirror_ubuntu-artful-kernel.git] / net / rds / transport.c
CommitLineData
0fbc78cb
AG
1/*
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
335776bd 40static struct rds_transport *transports[RDS_TRANS_COUNT];
0fbc78cb
AG
41static DECLARE_RWSEM(rds_trans_sem);
42
a8d63a53 43void rds_trans_register(struct rds_transport *trans)
0fbc78cb
AG
44{
45 BUG_ON(strlen(trans->t_name) + 1 > TRANSNAMSIZ);
46
47 down_write(&rds_trans_sem);
48
335776bd
AG
49 if (transports[trans->t_type])
50 printk(KERN_ERR "RDS Transport type %d already registered\n",
51 trans->t_type);
52 else {
53 transports[trans->t_type] = trans;
54 printk(KERN_INFO "Registered RDS/%s transport\n", trans->t_name);
55 }
0fbc78cb
AG
56
57 up_write(&rds_trans_sem);
0fbc78cb 58}
616b757a 59EXPORT_SYMBOL_GPL(rds_trans_register);
0fbc78cb
AG
60
61void rds_trans_unregister(struct rds_transport *trans)
62{
63 down_write(&rds_trans_sem);
64
335776bd 65 transports[trans->t_type] = NULL;
0fbc78cb
AG
66 printk(KERN_INFO "Unregistered RDS/%s transport\n", trans->t_name);
67
68 up_write(&rds_trans_sem);
69}
616b757a 70EXPORT_SYMBOL_GPL(rds_trans_unregister);
0fbc78cb 71
5adb5bc6
ZB
72void rds_trans_put(struct rds_transport *trans)
73{
f6e1c916 74 if (trans)
5adb5bc6
ZB
75 module_put(trans->t_owner);
76}
77
d5a8ac28 78struct rds_transport *rds_trans_get_preferred(struct net *net, __be32 addr)
0fbc78cb 79{
0fbc78cb 80 struct rds_transport *ret = NULL;
5adb5bc6
ZB
81 struct rds_transport *trans;
82 unsigned int i;
0fbc78cb
AG
83
84 if (IN_LOOPBACK(ntohl(addr)))
85 return &rds_loop_transport;
86
87 down_read(&rds_trans_sem);
5adb5bc6
ZB
88 for (i = 0; i < RDS_TRANS_COUNT; i++) {
89 trans = transports[i];
90
d5a8ac28 91 if (trans && (trans->laddr_check(net, addr) == 0) &&
5adb5bc6
ZB
92 (!trans->t_owner || try_module_get(trans->t_owner))) {
93 ret = trans;
0fbc78cb
AG
94 break;
95 }
96 }
97 up_read(&rds_trans_sem);
98
99 return ret;
100}
101
d97dac54
SV
102struct rds_transport *rds_trans_get(int t_type)
103{
104 struct rds_transport *ret = NULL;
105 struct rds_transport *trans;
106 unsigned int i;
107
108 down_read(&rds_trans_sem);
109 for (i = 0; i < RDS_TRANS_COUNT; i++) {
110 trans = transports[i];
111
112 if (trans && trans->t_type == t_type &&
113 (!trans->t_owner || try_module_get(trans->t_owner))) {
114 ret = trans;
115 break;
116 }
117 }
118 up_read(&rds_trans_sem);
119
120 return ret;
121}
122
0fbc78cb
AG
123/*
124 * This returns the number of stats entries in the snapshot and only
125 * copies them using the iter if there is enough space for them. The
126 * caller passes in the global stats so that we can size and copy while
127 * holding the lock.
128 */
129unsigned int rds_trans_stats_info_copy(struct rds_info_iterator *iter,
130 unsigned int avail)
131
132{
133 struct rds_transport *trans;
134 unsigned int total = 0;
135 unsigned int part;
335776bd 136 int i;
0fbc78cb
AG
137
138 rds_info_iter_unmap(iter);
139 down_read(&rds_trans_sem);
140
5c3da57d 141 for (i = 0; i < RDS_TRANS_COUNT; i++) {
335776bd
AG
142 trans = transports[i];
143 if (!trans || !trans->stats_info_copy)
0fbc78cb
AG
144 continue;
145
146 part = trans->stats_info_copy(iter, avail);
147 avail -= min(avail, part);
148 total += part;
149 }
150
151 up_read(&rds_trans_sem);
152
153 return total;
154}
155