44 #define TIPC_NAMETBL_SIZE 1024
115 static int hash(
int x)
129 pr_warn(
"Publication creation failure, no memory\n");
138 publ->
ref = port_ref;
142 INIT_LIST_HEAD(&publ->
subscr.nodesub_list);
163 struct sub_seq *sseq = tipc_subseq_alloc(1);
165 if (!nseq || !sseq) {
166 pr_warn(
"Name sequence creation failed, no memory\n");
176 INIT_HLIST_NODE(&nseq->
ns_list);
178 hlist_add_head(&nseq->
ns_list, seq_head);
185 static void nameseq_delete_empty(
struct name_seq *seq)
207 while (low <= high) {
208 mid = (low +
high) / 2;
209 if (instance < sseqs[mid].lower)
211 else if (instance > sseqs[mid].upper)
228 static u32 nameseq_locate_subseq(
struct name_seq *nseq,
u32 instance)
235 while (low <= high) {
236 mid = (low +
high) / 2;
237 if (instance < sseqs[mid].lower)
239 else if (instance > sseqs[mid].upper)
259 int created_subseq = 0;
261 sseq = nameseq_find_subseq(nseq, lower);
265 if ((sseq->
lower != lower) || (sseq->
upper != upper)) {
266 pr_warn(
"Cannot publish {%u,%u,%u}, overlap error\n",
275 if ((publ->
ref == port) && (publ->
key == key) &&
276 (!publ->
node || (publ->
node == node)))
284 inspos = nameseq_locate_subseq(nseq, lower);
287 if ((inspos < nseq->first_free) &&
288 (upper >= nseq->
sseqs[inspos].lower)) {
289 pr_warn(
"Cannot publish {%u,%u,%u}, overlap error\n",
296 struct sub_seq *sseqs = tipc_subseq_alloc(nseq->
alloc * 2);
299 pr_warn(
"Cannot publish {%u,%u,%u}, no memory\n",
312 pr_warn(
"Cannot publish {%u,%u,%u}, no memory\n",
322 sseq = &nseq->
sseqs[inspos];
324 memmove(sseq + 1, sseq, (freesseq - sseq) *
sizeof(*sseq));
325 memset(sseq, 0,
sizeof(*sseq));
334 publ = publ_create(type, lower, upper, scope, node, port, key);
341 if (in_own_cluster(node)) {
346 if (in_own_node(node)) {
379 struct sub_seq *sseq = nameseq_find_subseq(nseq, inst);
383 int removed_subseq = 0;
392 if ((publ->
key == key) && (publ->
ref == ref) &&
393 (!publ->
node || (publ->
node == node)))
404 if (in_own_cluster(node)) {
410 if (in_own_node(node)) {
419 memmove(sseq, sseq + 1, (free - (sseq + 1)) *
sizeof(*sseq));
442 static void tipc_nameseq_subscribe(
struct name_seq *nseq,
481 if (ns->
type == type)
491 struct name_seq *seq = nametbl_find_seq(type);
495 pr_debug(
"Failed to publish illegal {%u,%u,%u} with scope %u\n",
496 type, lower, upper, scope);
501 seq = tipc_nameseq_create(type, &
table.types[
hash(type)]);
505 return tipc_nameseq_insert_publ(seq, type, lower, upper,
506 scope, node, port, key);
513 struct name_seq *seq = nametbl_find_seq(type);
518 publ = tipc_nameseq_remove_publ(seq, lower, node, ref, key);
519 nameseq_delete_empty(seq);
549 seq = nametbl_find_seq(type);
552 sseq = nameseq_find_subseq(seq, instance);
555 spin_lock_bh(&seq->
lock);
582 else if (*destnode == tipc_own_addr) {
588 }
else if (in_own_cluster_exact(*destnode)) {
603 spin_unlock_bh(&seq->
lock);
632 seq = nametbl_find_seq(type);
636 spin_lock_bh(&seq->
lock);
638 sseq = seq->
sseqs + nameseq_locate_subseq(seq, lower);
640 for (; sseq != sseq_stop; sseq++) {
643 if (sseq->
lower > upper)
648 if (publ->
scope <= limit)
656 spin_unlock_bh(&seq->
lock);
671 pr_warn(
"Publication failed, local publication limit reached (%u)\n",
678 tipc_own_addr, port_ref, key);
680 table.local_publ_count++;
697 table.local_publ_count--;
705 pr_err(
"Unable to remove local publication\n"
706 "(type=%u, lower=%u, ref=%u, key=%u)\n",
707 type, lower, ref, key);
720 seq = nametbl_find_seq(type);
722 seq = tipc_nameseq_create(type, &
table.types[
hash(type)]);
724 spin_lock_bh(&seq->
lock);
725 tipc_nameseq_subscribe(seq, s);
726 spin_unlock_bh(&seq->
lock);
728 pr_warn(
"Failed to create subscription for {%u,%u,%u}\n",
729 s->
seq.type, s->
seq.lower, s->
seq.upper);
742 seq = nametbl_find_seq(s->
seq.type);
744 spin_lock_bh(&seq->
lock);
746 spin_unlock_bh(&seq->
lock);
747 nameseq_delete_empty(seq);
760 const char *scope_str[] = {
"",
" zone",
" cluster",
" node"};
775 sprintf(portIdStr,
"<%u.%u.%u:%u>",
776 tipc_zone(publ->
node), tipc_cluster(publ->
node),
778 ret +=
tipc_snprintf(buf + ret, len - ret,
"%-26s ", portIdStr);
795 static int nameseq_list(
struct name_seq *seq,
char *buf,
int len,
u32 depth,
813 if ((lowbound <= sseq->upper) && (upbound >= sseq->
lower)) {
816 spin_lock_bh(&seq->
lock);
817 ret += subseq_list(sseq, buf + ret, len - ret,
819 spin_unlock_bh(&seq->
lock);
820 sprintf(typearea,
"%10s",
" ");
829 static int nametbl_header(
char *buf,
int len,
u32 depth)
843 for (i = 0; i <
depth; i++)
852 static int nametbl_list(
char *buf,
int len,
u32 depth_info,
871 ret += nametbl_header(buf, len, depth);
875 seq_head = &
table.types[
i];
877 ret += nameseq_list(seq, buf + ret, len - ret,
879 lowbound, upbound, i);
884 if (upbound < lowbound) {
886 "invalid name sequence specified\n");
889 ret += nametbl_header(buf + ret, len - ret, depth);
891 seq_head = &
table.types[
i];
893 if (seq->
type == type) {
894 ret += nameseq_list(seq, buf + ret, len - ret,
896 lowbound, upbound, i);
925 str_len = nametbl_list(pb, pb_len,
ntohl(argv->
depth),
943 table.local_publ_count = 0;
957 if (hlist_empty(&
table.types[i]))
959 pr_err(
"nametbl_stop(): orphaned hash chain detected\n");