+ case RCU_JA_NULL:
+ return -ENOSPC;
+ default:
+ assert(0);
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+/*
+ * ja_node_recompact_add: recompact a node, adding a new child.
+ * TODO: for pool type, take selection bit(s) into account.
+ */
+static
+int ja_node_recompact_add(struct cds_ja *ja,
+ unsigned int old_type_index,
+ const struct cds_ja_type *old_type,
+ struct cds_ja_node *old_node,
+ struct cds_ja_shadow_node **shadow_node,
+ struct cds_ja_node_flag **old_node_flag, uint8_t n,
+ struct cds_ja_node_flag *child_node_flag)
+{
+ unsigned int new_type_index;
+ struct cds_ja_node *new_node;
+ const struct cds_ja_type *new_type;
+ struct cds_ja_node_flag *new_node_flag;
+ int ret;
+
+ if (*shadow_node == NULL) {
+ new_type_index = 0;
+ } else {
+ new_type_index = old_type_index + 1;
+ }
+ new_type = &ja_types[new_type_index];
+ new_node = alloc_cds_ja_node(new_type);
+ if (!new_node)
+ return -ENOMEM;
+ new_node_flag = ja_node_flag(new_node, new_type_index);
+
+ ret = rcuja_shadow_set(ja->ht, new_node, *shadow_node);
+ if (ret)
+ return ret;
+
+ if (*shadow_node == NULL) {
+ *shadow_node = rcuja_shadow_lookup_lock(ja->ht, new_node);
+ assert(*shadow_node);
+ }
+
+ /*
+ * We need to clear nr_child, because it will be re-incremented
+ * by _ja_node_set_nth().
+ */
+ (*shadow_node)->nr_child = 0;
+
+ assert(old_type->type_class != RCU_JA_PIGEON);
+ switch (old_type->type_class) {
+ case RCU_JA_LINEAR:
+ {
+ uint8_t nr_child =
+ ja_linear_node_get_nr_child(old_type, old_node);
+ unsigned int i;
+
+ for (i = 0; i < nr_child; i++) {
+ struct cds_ja_node_flag *iter;
+ uint8_t v;
+
+ ja_linear_node_get_ith_pos(old_type, old_node, i, &v, &iter);
+ if (!iter)
+ continue;
+ ret = _ja_node_set_nth(new_type, new_node, *shadow_node,
+ v, iter);
+ assert(!ret);
+ }
+ break;
+ }
+ case RCU_JA_POOL:
+ {
+ unsigned int pool_nr;
+
+ for (pool_nr = 0; pool_nr < (1U << old_type->nr_pool_order); pool_nr++) {
+ struct cds_ja_node *pool =
+ ja_pool_node_get_ith_pool(old_type,
+ old_node, pool_nr);
+ uint8_t nr_child =
+ ja_linear_node_get_nr_child(old_type, pool);
+ unsigned int j;
+
+ for (j = 0; j < nr_child; j++) {
+ struct cds_ja_node_flag *iter;
+ uint8_t v;
+
+ ja_linear_node_get_ith_pos(old_type, pool,
+ j, &v, &iter);
+ if (!iter)
+ continue;
+ ret = _ja_node_set_nth(new_type, new_node, *shadow_node,
+ v, iter);
+ assert(!ret);
+ }
+ }
+ break;
+ }
+ case RCU_JA_PIGEON: