Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tipc: refactor name table updates out of named packet receive routine

We need to perform the same actions when processing deferred name
table updates, so this functionality is moved to a separate
function.

Signed-off-by: Erik Hugne <erik.hugne@ericsson.com>
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Acked-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Erik Hugne and committed by
David S. Miller
f4ad8a4b 1764bcd9

+38 -36
+38 -36
net/tipc/name_distr.c
··· 263 263 } 264 264 265 265 /** 266 + * tipc_update_nametbl - try to process a nametable update and notify 267 + * subscribers 268 + * 269 + * tipc_nametbl_lock must be held. 270 + * Returns the publication item if successful, otherwise NULL. 271 + */ 272 + struct publication *tipc_update_nametbl(struct distr_item *i, u32 node, 273 + u32 dtype) 274 + { 275 + struct publication *publ = NULL; 276 + 277 + if (dtype == PUBLICATION) { 278 + publ = tipc_nametbl_insert_publ(ntohl(i->type), ntohl(i->lower), 279 + ntohl(i->upper), 280 + TIPC_CLUSTER_SCOPE, node, 281 + ntohl(i->ref), ntohl(i->key)); 282 + if (publ) { 283 + tipc_nodesub_subscribe(&publ->subscr, node, publ, 284 + (net_ev_handler) 285 + named_purge_publ); 286 + } 287 + } else if (dtype == WITHDRAWAL) { 288 + publ = tipc_nametbl_remove_publ(ntohl(i->type), ntohl(i->lower), 289 + node, ntohl(i->ref), 290 + ntohl(i->key)); 291 + if (publ) { 292 + tipc_nodesub_unsubscribe(&publ->subscr); 293 + kfree(publ); 294 + } 295 + } else { 296 + pr_warn("Unrecognized name table message received\n"); 297 + } 298 + return publ; 299 + } 300 + 301 + /** 266 302 * tipc_named_rcv - process name table update message sent by another node 267 303 */ 268 304 void tipc_named_rcv(struct sk_buff *buf) 269 305 { 270 - struct publication *publ; 271 306 struct tipc_msg *msg = buf_msg(buf); 272 307 struct distr_item *item = (struct distr_item *)msg_data(msg); 273 308 u32 count = msg_data_sz(msg) / ITEM_SIZE; 274 309 275 310 write_lock_bh(&tipc_nametbl_lock); 276 311 while (count--) { 277 - if (msg_type(msg) == PUBLICATION) { 278 - publ = tipc_nametbl_insert_publ(ntohl(item->type), 279 - ntohl(item->lower), 280 - ntohl(item->upper), 281 - TIPC_CLUSTER_SCOPE, 282 - msg_orignode(msg), 283 - ntohl(item->ref), 284 - ntohl(item->key)); 285 - if (publ) { 286 - tipc_nodesub_subscribe(&publ->subscr, 287 - msg_orignode(msg), 288 - publ, 289 - (net_ev_handler) 290 - named_purge_publ); 291 - } 292 - } else if (msg_type(msg) == WITHDRAWAL) { 293 - publ = tipc_nametbl_remove_publ(ntohl(item->type), 294 - ntohl(item->lower), 295 - msg_orignode(msg), 296 - ntohl(item->ref), 297 - ntohl(item->key)); 298 - 299 - if (publ) { 300 - tipc_nodesub_unsubscribe(&publ->subscr); 301 - kfree(publ); 302 - } else { 303 - pr_err("Unable to remove publication by node 0x%x\n" 304 - " (type=%u, lower=%u, ref=%u, key=%u)\n", 305 - msg_orignode(msg), ntohl(item->type), 306 - ntohl(item->lower), ntohl(item->ref), 307 - ntohl(item->key)); 308 - } 309 - } else { 310 - pr_warn("Unrecognized name table message received\n"); 311 - } 312 + tipc_update_nametbl(item, msg_orignode(msg), 313 + msg_type(msg)); 312 314 item++; 313 315 } 314 316 write_unlock_bh(&tipc_nametbl_lock);