diff options
author | Allan Stephens <allan.stephens@windriver.com> | 2011-10-06 15:28:44 -0400 |
---|---|---|
committer | Paul Gortmaker <paul.gortmaker@windriver.com> | 2011-12-27 11:13:05 -0500 |
commit | 706767da1bd0726d8fbc62e4818cb29193676a74 (patch) | |
tree | f2df46f9850bfb984e64f44ec6c8fca0bf249922 /net/tipc/bearer.c | |
parent | 2060a5774452e35b4a1dc4371abbb5ffd691355f (diff) |
tipc: Register new media using pre-compiled structure
Speeds up the registration of TIPC media types by passing in a structure
containing the required information, rather than by passing in the various
fields describing the media type individually.
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Diffstat (limited to 'net/tipc/bearer.c')
-rw-r--r-- | net/tipc/bearer.c | 70 |
1 files changed, 25 insertions, 45 deletions
diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c index e2202de3d93e..75af271b9cfa 100644 --- a/net/tipc/bearer.c +++ b/net/tipc/bearer.c | |||
@@ -86,21 +86,8 @@ static struct media *media_find(const char *name) | |||
86 | * Bearers for this media type must be activated separately at a later stage. | 86 | * Bearers for this media type must be activated separately at a later stage. |
87 | */ | 87 | */ |
88 | 88 | ||
89 | int tipc_register_media(u32 media_type, | 89 | int tipc_register_media(struct media *m_ptr) |
90 | char *name, | ||
91 | int (*enable)(struct tipc_bearer *), | ||
92 | void (*disable)(struct tipc_bearer *), | ||
93 | int (*send_msg)(struct sk_buff *, | ||
94 | struct tipc_bearer *, | ||
95 | struct tipc_media_addr *), | ||
96 | char *(*addr2str)(struct tipc_media_addr *a, | ||
97 | char *str_buf, int str_size), | ||
98 | struct tipc_media_addr *bcast_addr, | ||
99 | const u32 bearer_priority, | ||
100 | const u32 link_tolerance, /* [ms] */ | ||
101 | const u32 send_window_limit) | ||
102 | { | 90 | { |
103 | struct media *m_ptr; | ||
104 | u32 media_id; | 91 | u32 media_id; |
105 | u32 i; | 92 | u32 i; |
106 | int res = -EINVAL; | 93 | int res = -EINVAL; |
@@ -108,62 +95,55 @@ int tipc_register_media(u32 media_type, | |||
108 | write_lock_bh(&tipc_net_lock); | 95 | write_lock_bh(&tipc_net_lock); |
109 | 96 | ||
110 | if (tipc_mode != TIPC_NET_MODE) { | 97 | if (tipc_mode != TIPC_NET_MODE) { |
111 | warn("Media <%s> rejected, not in networked mode yet\n", name); | 98 | warn("Media <%s> rejected, not in networked mode yet\n", |
99 | m_ptr->name); | ||
112 | goto exit; | 100 | goto exit; |
113 | } | 101 | } |
114 | if (!media_name_valid(name)) { | 102 | if (!media_name_valid(m_ptr->name)) { |
115 | warn("Media <%s> rejected, illegal name\n", name); | 103 | warn("Media <%s> rejected, illegal name\n", m_ptr->name); |
116 | goto exit; | 104 | goto exit; |
117 | } | 105 | } |
118 | if (!bcast_addr) { | 106 | if (m_ptr->bcast_addr.type != htonl(m_ptr->type_id)) { |
119 | warn("Media <%s> rejected, no broadcast address\n", name); | 107 | warn("Media <%s> rejected, illegal broadcast address\n", |
108 | m_ptr->name); | ||
120 | goto exit; | 109 | goto exit; |
121 | } | 110 | } |
122 | if ((bearer_priority < TIPC_MIN_LINK_PRI) || | 111 | if ((m_ptr->priority < TIPC_MIN_LINK_PRI) || |
123 | (bearer_priority > TIPC_MAX_LINK_PRI)) { | 112 | (m_ptr->priority > TIPC_MAX_LINK_PRI)) { |
124 | warn("Media <%s> rejected, illegal priority (%u)\n", name, | 113 | warn("Media <%s> rejected, illegal priority (%u)\n", |
125 | bearer_priority); | 114 | m_ptr->name, m_ptr->priority); |
126 | goto exit; | 115 | goto exit; |
127 | } | 116 | } |
128 | if ((link_tolerance < TIPC_MIN_LINK_TOL) || | 117 | if ((m_ptr->tolerance < TIPC_MIN_LINK_TOL) || |
129 | (link_tolerance > TIPC_MAX_LINK_TOL)) { | 118 | (m_ptr->tolerance > TIPC_MAX_LINK_TOL)) { |
130 | warn("Media <%s> rejected, illegal tolerance (%u)\n", name, | 119 | warn("Media <%s> rejected, illegal tolerance (%u)\n", |
131 | link_tolerance); | 120 | m_ptr->name, m_ptr->tolerance); |
132 | goto exit; | 121 | goto exit; |
133 | } | 122 | } |
134 | 123 | ||
135 | media_id = media_count++; | 124 | media_id = media_count++; |
136 | if (media_id >= MAX_MEDIA) { | 125 | if (media_id >= MAX_MEDIA) { |
137 | warn("Media <%s> rejected, media limit reached (%u)\n", name, | 126 | warn("Media <%s> rejected, media limit reached (%u)\n", |
138 | MAX_MEDIA); | 127 | m_ptr->name, MAX_MEDIA); |
139 | media_count--; | 128 | media_count--; |
140 | goto exit; | 129 | goto exit; |
141 | } | 130 | } |
142 | for (i = 0; i < media_id; i++) { | 131 | for (i = 0; i < media_id; i++) { |
143 | if (media_list[i].type_id == media_type) { | 132 | if (media_list[i].type_id == m_ptr->type_id) { |
144 | warn("Media <%s> rejected, duplicate type (%u)\n", name, | 133 | warn("Media <%s> rejected, duplicate type (%u)\n", |
145 | media_type); | 134 | m_ptr->name, m_ptr->type_id); |
146 | media_count--; | 135 | media_count--; |
147 | goto exit; | 136 | goto exit; |
148 | } | 137 | } |
149 | if (!strcmp(name, media_list[i].name)) { | 138 | if (!strcmp(m_ptr->name, media_list[i].name)) { |
150 | warn("Media <%s> rejected, duplicate name\n", name); | 139 | warn("Media <%s> rejected, duplicate name\n", |
140 | m_ptr->name); | ||
151 | media_count--; | 141 | media_count--; |
152 | goto exit; | 142 | goto exit; |
153 | } | 143 | } |
154 | } | 144 | } |
155 | 145 | ||
156 | m_ptr = &media_list[media_id]; | 146 | media_list[media_id] = *m_ptr; |
157 | m_ptr->type_id = media_type; | ||
158 | m_ptr->send_msg = send_msg; | ||
159 | m_ptr->enable_bearer = enable; | ||
160 | m_ptr->disable_bearer = disable; | ||
161 | m_ptr->addr2str = addr2str; | ||
162 | memcpy(&m_ptr->bcast_addr, bcast_addr, sizeof(*bcast_addr)); | ||
163 | strcpy(m_ptr->name, name); | ||
164 | m_ptr->priority = bearer_priority; | ||
165 | m_ptr->tolerance = link_tolerance; | ||
166 | m_ptr->window = send_window_limit; | ||
167 | res = 0; | 147 | res = 0; |
168 | exit: | 148 | exit: |
169 | write_unlock_bh(&tipc_net_lock); | 149 | write_unlock_bh(&tipc_net_lock); |