| 183 | } |
| 184 | |
| 185 | cs_error_t cpg_model_initialize ( |
| 186 | cpg_handle_t *handle, |
| 187 | cpg_model_t model, |
| 188 | cpg_model_data_t *model_data, |
| 189 | void *context) |
| 190 | { |
| 191 | cs_error_t error; |
| 192 | struct cpg_inst *cpg_inst; |
| 193 | |
| 194 | if (model != CPG_MODEL_V1) { |
| 195 | error = CS_ERR_INVALID_PARAM; |
| 196 | goto error_no_destroy; |
| 197 | } |
| 198 | |
| 199 | error = hdb_error_to_cs (hdb_handle_create (&cpg_handle_t_db, sizeof (struct cpg_inst), handle)); |
| 200 | if (error != CS_OK) { |
| 201 | goto error_no_destroy; |
| 202 | } |
| 203 | |
| 204 | error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, *handle, (void *)&cpg_inst)); |
| 205 | if (error != CS_OK) { |
| 206 | goto error_destroy; |
| 207 | } |
| 208 | |
| 209 | cpg_inst->c = qb_ipcc_connect ("cpg", IPC_REQUEST_SIZE); |
| 210 | if (cpg_inst->c == NULL) { |
| 211 | error = qb_to_cs_error(-errno); |
| 212 | goto error_put_destroy; |
| 213 | } |
| 214 | |
| 215 | if (model_data != NULL) { |
| 216 | switch (model) { |
| 217 | case CPG_MODEL_V1: |
| 218 | memcpy (&cpg_inst->model_v1_data, model_data, sizeof (cpg_model_v1_data_t)); |
| 219 | if ((cpg_inst->model_v1_data.flags & ~(CPG_MODEL_V1_DELIVER_INITIAL_TOTEM_CONF)) != 0) { |
| 220 | error = CS_ERR_INVALID_PARAM; |
| 221 | |
| 222 | goto error_destroy; |
| 223 | } |
| 224 | break; |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | /* Allow space for corosync internal headers */ |
| 229 | cpg_inst->max_msg_size = IPC_REQUEST_SIZE - 1024; |
| 230 | cpg_inst->model_data.model = model; |
| 231 | cpg_inst->context = context; |
| 232 | |
| 233 | qb_list_init(&cpg_inst->iteration_list_head); |
| 234 | |
| 235 | qb_list_init(&cpg_inst->assembly_list_head); |
| 236 | |
| 237 | hdb_handle_put (&cpg_handle_t_db, *handle); |
| 238 | |
| 239 | return (CS_OK); |
| 240 | |
| 241 | error_put_destroy: |
| 242 | hdb_handle_put (&cpg_handle_t_db, *handle); |