| 119 | } |
| 120 | |
| 121 | int cl_request_sync(str *capability, int cluster_id, int from_cb) |
| 122 | { |
| 123 | cluster_info_t *cluster; |
| 124 | struct local_cap *lcap; |
| 125 | int source_id; |
| 126 | int rc = -1; |
| 127 | |
| 128 | LM_DBG("requesting %.*s sync in cluster %d\n", |
| 129 | capability->len, capability->s, cluster_id); |
| 130 | |
| 131 | if (!from_cb) |
| 132 | lock_start_read(cl_list_lock); |
| 133 | |
| 134 | cluster = get_cluster_by_id(cluster_id); |
| 135 | if (!cluster) { |
| 136 | LM_ERR("Unknown cluster [%d]\n", cluster_id); |
| 137 | goto end; |
| 138 | } |
| 139 | |
| 140 | for (lcap = cluster->capabilities; lcap; lcap = lcap->next) |
| 141 | if (!str_strcmp(capability, &lcap->reg.name)) |
| 142 | break; |
| 143 | if (!lcap) { |
| 144 | LM_ERR("Request sync for unknown capability: %.*s\n", |
| 145 | capability->len, capability->s); |
| 146 | goto end; |
| 147 | } |
| 148 | |
| 149 | lock_get(cluster->lock); |
| 150 | if (lcap->flags & CAP_SYNC_PENDING) { |
| 151 | lock_release(cluster->lock); |
| 152 | LM_DBG("Sync request already pending\n"); |
| 153 | rc = 0; |
| 154 | goto end; |
| 155 | } |
| 156 | if (lcap->flags & CAP_SYNC_IN_PROGRESS) { |
| 157 | lock_release(cluster->lock); |
| 158 | LM_DBG("Sync already in progress\n"); |
| 159 | rc = 1; |
| 160 | goto end; |
| 161 | } |
| 162 | |
| 163 | if (!(lcap->flags & CAP_STATE_ENABLED)) { |
| 164 | lock_release(cluster->lock); |
| 165 | LM_DBG("Capability disabled, skip send sync request\n"); |
| 166 | rc = 0; |
| 167 | goto end; |
| 168 | } |
| 169 | |
| 170 | lcap->sync_total_chunks_cnt = 0; |
| 171 | lcap->sync_cur_chunks_cnt = 0; |
| 172 | |
| 173 | /* node is no longer OK for this capability if it previously were */ |
| 174 | if (lcap->flags & CAP_STATE_OK) { |
| 175 | lcap->flags &= ~CAP_STATE_OK; |
| 176 | lock_release(cluster->lock); |
| 177 | send_single_cap_update(cluster, lcap, 0); |
| 178 | } else |
nothing calls this directly
no test coverage detected