Public functions */
| 55 | |
| 56 | /* Public functions */ |
| 57 | rte_node_t |
| 58 | __rte_node_register(const struct rte_node_register *reg) |
| 59 | { |
| 60 | struct node *node; |
| 61 | rte_edge_t i; |
| 62 | size_t sz; |
| 63 | |
| 64 | /* Limit Node specific metadata to one cacheline on 64B CL machine */ |
| 65 | RTE_BUILD_BUG_ON((offsetof(struct rte_node, nodes) - |
| 66 | offsetof(struct rte_node, ctx)) != |
| 67 | RTE_CACHE_LINE_MIN_SIZE); |
| 68 | |
| 69 | graph_spinlock_lock(); |
| 70 | |
| 71 | /* Check sanity */ |
| 72 | if (reg == NULL || reg->process == NULL) { |
| 73 | rte_errno = EINVAL; |
| 74 | goto fail; |
| 75 | } |
| 76 | |
| 77 | /* Check for duplicate name */ |
| 78 | if (node_has_duplicate_entry(reg->name)) |
| 79 | goto fail; |
| 80 | |
| 81 | sz = sizeof(struct node) + (reg->nb_edges * RTE_NODE_NAMESIZE); |
| 82 | node = calloc(1, sz); |
| 83 | if (node == NULL) { |
| 84 | rte_errno = ENOMEM; |
| 85 | goto fail; |
| 86 | } |
| 87 | |
| 88 | /* Initialize the node */ |
| 89 | if (rte_strscpy(node->name, reg->name, RTE_NODE_NAMESIZE) < 0) |
| 90 | goto free; |
| 91 | node->flags = reg->flags; |
| 92 | node->process = reg->process; |
| 93 | node->init = reg->init; |
| 94 | node->fini = reg->fini; |
| 95 | node->nb_edges = reg->nb_edges; |
| 96 | node->parent_id = reg->parent_id; |
| 97 | for (i = 0; i < reg->nb_edges; i++) { |
| 98 | if (rte_strscpy(node->next_nodes[i], reg->next_nodes[i], |
| 99 | RTE_NODE_NAMESIZE) < 0) |
| 100 | goto free; |
| 101 | } |
| 102 | |
| 103 | node->lcore_id = RTE_MAX_LCORE; |
| 104 | node->id = node_id++; |
| 105 | |
| 106 | /* Add the node at tail */ |
| 107 | STAILQ_INSERT_TAIL(&node_list, node, next); |
| 108 | graph_spinlock_unlock(); |
| 109 | |
| 110 | return node->id; |
| 111 | free: |
| 112 | free(node); |
| 113 | fail: |
| 114 | graph_spinlock_unlock(); |
no test coverage detected