2 * Copyright (c) 2011-2017 Red Hat, Inc.
6 * Author: Jan Friesse (jfriesse@redhat.com)
8 * This software licensed under BSD license, the text of which follows:
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
13 * - Redistributions of source code must retain the above copyright notice,
14 * this list of conditions and the following disclaimer.
15 * - Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 * - Neither the name of the Red Hat, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived from this
20 * software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32 * THE POSSIBILITY OF SUCH DAMAGE.
41 #include <sys/types.h>
45 #include <corosync/corotypes.h>
46 #include <corosync/corodefs.h>
47 #include <corosync/hdb.h>
48 #include <qb/qbipcc.h>
50 #include <corosync/cmap.h>
51 #include <corosync/ipc_cmap.h>
58 qb_ipcc_connection_t
*c
;
62 struct cmap_track_inst
{
64 cmap_notify_fn_t notify_fn
;
65 qb_ipcc_connection_t
*c
;
66 cmap_track_handle_t track_handle
;
69 static void cmap_inst_free (void *inst
);
71 DECLARE_HDB_DATABASE(cmap_handle_t_db
, cmap_inst_free
);
72 DECLARE_HDB_DATABASE(cmap_track_handle_t_db
,NULL
);
77 static cs_error_t
cmap_get_int(
82 cmap_value_types_t type
);
84 static cs_error_t
cmap_adjust_int(cmap_handle_t handle
, const char *key_name
, int32_t step
);
87 * Function implementations
89 cs_error_t
cmap_initialize (cmap_handle_t
*handle
)
92 struct cmap_inst
*cmap_inst
;
94 error
= hdb_error_to_cs(hdb_handle_create(&cmap_handle_t_db
, sizeof(*cmap_inst
), handle
));
96 goto error_no_destroy
;
99 error
= hdb_error_to_cs(hdb_handle_get(&cmap_handle_t_db
, *handle
, (void *)&cmap_inst
));
100 if (error
!= CS_OK
) {
105 cmap_inst
->finalize
= 0;
106 cmap_inst
->c
= qb_ipcc_connect("cmap", IPC_REQUEST_SIZE
);
107 if (cmap_inst
->c
== NULL
) {
108 error
= qb_to_cs_error(-errno
);
109 goto error_put_destroy
;
112 (void)hdb_handle_put(&cmap_handle_t_db
, *handle
);
117 (void)hdb_handle_put(&cmap_handle_t_db
, *handle
);
119 (void)hdb_handle_destroy(&cmap_handle_t_db
, *handle
);
124 cs_error_t
cmap_initialize_map (cmap_handle_t
*handle
,
129 struct cmap_inst
*cmap_inst
;
130 struct req_lib_cmap_set_current_map req_lib_cmap_set_current_map
;
131 struct qb_ipc_response_header res_lib_cmap_set_current_map
;
133 error
= cmap_initialize(handle
);
135 if (error
== CS_OK
) {
136 error
= hdb_error_to_cs(hdb_handle_get (&cmap_handle_t_db
, *handle
, (void *)&cmap_inst
));
137 if (error
!= CS_OK
) {
141 memset(&req_lib_cmap_set_current_map
, 0, sizeof(req_lib_cmap_set_current_map
));
142 req_lib_cmap_set_current_map
.header
.size
= sizeof(req_lib_cmap_set_current_map
);
143 req_lib_cmap_set_current_map
.header
.id
= MESSAGE_REQ_CMAP_SET_CURRENT_MAP
;
144 req_lib_cmap_set_current_map
.map
= map
;
146 iov
[0].iov_base
= (char *)&req_lib_cmap_set_current_map
;
147 iov
[0].iov_len
= sizeof(req_lib_cmap_set_current_map
);
149 error
= qb_to_cs_error(qb_ipcc_sendv_recv(
153 &res_lib_cmap_set_current_map
,
154 sizeof (res_lib_cmap_set_current_map
), CS_IPC_TIMEOUT_MS
));
156 if (error
== CS_OK
) {
157 error
= res_lib_cmap_set_current_map
.error
;
160 (void)hdb_handle_put (&cmap_handle_t_db
, *handle
);
167 static void cmap_inst_free (void *inst
)
169 struct cmap_inst
*cmap_inst
= (struct cmap_inst
*)inst
;
170 qb_ipcc_disconnect(cmap_inst
->c
);
173 cs_error_t
cmap_finalize(cmap_handle_t handle
)
175 struct cmap_inst
*cmap_inst
;
177 hdb_handle_t track_inst_handle
= 0;
178 struct cmap_track_inst
*cmap_track_inst
;
180 error
= hdb_error_to_cs(hdb_handle_get(&cmap_handle_t_db
, handle
, (void *)&cmap_inst
));
181 if (error
!= CS_OK
) {
185 if (cmap_inst
->finalize
) {
186 (void)hdb_handle_put (&cmap_handle_t_db
, handle
);
187 return (CS_ERR_BAD_HANDLE
);
189 cmap_inst
->finalize
= 1;
192 * Destroy all track instances for given connection
194 hdb_iterator_reset(&cmap_track_handle_t_db
);
195 while (hdb_iterator_next(&cmap_track_handle_t_db
,
196 (void*)&cmap_track_inst
, &track_inst_handle
) == 0) {
198 if (cmap_track_inst
->c
== cmap_inst
->c
) {
199 (void)hdb_handle_destroy(&cmap_track_handle_t_db
, track_inst_handle
);
202 (void)hdb_handle_put (&cmap_track_handle_t_db
, track_inst_handle
);
205 (void)hdb_handle_destroy(&cmap_handle_t_db
, handle
);
207 (void)hdb_handle_put(&cmap_handle_t_db
, handle
);
212 cs_error_t
cmap_fd_get(cmap_handle_t handle
, int *fd
)
215 struct cmap_inst
*cmap_inst
;
217 error
= hdb_error_to_cs(hdb_handle_get (&cmap_handle_t_db
, handle
, (void *)&cmap_inst
));
218 if (error
!= CS_OK
) {
222 error
= qb_to_cs_error (qb_ipcc_fd_get (cmap_inst
->c
, fd
));
224 (void)hdb_handle_put (&cmap_handle_t_db
, handle
);
229 cs_error_t
cmap_dispatch (
230 cmap_handle_t handle
,
231 cs_dispatch_flags_t dispatch_types
)
235 int cont
= 1; /* always continue do loop except when set to 0 */
236 struct cmap_inst
*cmap_inst
;
237 struct qb_ipc_response_header
*dispatch_data
;
238 char dispatch_buf
[IPC_DISPATCH_SIZE
];
239 struct res_lib_cmap_notify_callback
*res_lib_cmap_notify_callback
;
240 struct cmap_track_inst
*cmap_track_inst
;
241 struct cmap_notify_value old_val
;
242 struct cmap_notify_value new_val
;
244 error
= hdb_error_to_cs(hdb_handle_get (&cmap_handle_t_db
, handle
, (void *)&cmap_inst
));
245 if (error
!= CS_OK
) {
250 * Timeout instantly for CS_DISPATCH_ONE_NONBLOCKING or CS_DISPATCH_ALL and
251 * wait indefinately for CS_DISPATCH_ONE or CS_DISPATCH_BLOCKING
253 if (dispatch_types
== CS_DISPATCH_ALL
|| dispatch_types
== CS_DISPATCH_ONE_NONBLOCKING
) {
257 dispatch_data
= (struct qb_ipc_response_header
*)dispatch_buf
;
259 error
= qb_to_cs_error(qb_ipcc_event_recv (
265 if (error
== CS_ERR_BAD_HANDLE
) {
269 if (error
== CS_ERR_TRY_AGAIN
) {
270 if (dispatch_types
== CS_DISPATCH_ONE_NONBLOCKING
) {
277 if (dispatch_types
== CS_DISPATCH_ALL
) {
278 break; /* exit do while cont is 1 loop */
280 continue; /* next poll */
284 if (error
!= CS_OK
) {
289 * Dispatch incoming message
291 switch (dispatch_data
->id
) {
292 case MESSAGE_RES_CMAP_NOTIFY_CALLBACK
:
293 res_lib_cmap_notify_callback
= (struct res_lib_cmap_notify_callback
*)dispatch_data
;
295 error
= hdb_error_to_cs(hdb_handle_get(&cmap_track_handle_t_db
,
296 res_lib_cmap_notify_callback
->track_inst_handle
,
297 (void *)&cmap_track_inst
));
298 if (error
== CS_ERR_BAD_HANDLE
) {
300 * User deleted tracker -> ignore error
304 if (error
!= CS_OK
) {
308 new_val
.type
= res_lib_cmap_notify_callback
->new_value_type
;
309 old_val
.type
= res_lib_cmap_notify_callback
->old_value_type
;
310 new_val
.len
= res_lib_cmap_notify_callback
->new_value_len
;
311 old_val
.len
= res_lib_cmap_notify_callback
->old_value_len
;
312 new_val
.data
= res_lib_cmap_notify_callback
->new_value
;
313 old_val
.data
= (((const char *)res_lib_cmap_notify_callback
->new_value
) + new_val
.len
);
315 cmap_track_inst
->notify_fn(handle
,
316 cmap_track_inst
->track_handle
,
317 res_lib_cmap_notify_callback
->event
,
318 (char *)res_lib_cmap_notify_callback
->key_name
.value
,
321 cmap_track_inst
->user_data
);
323 (void)hdb_handle_put(&cmap_track_handle_t_db
, res_lib_cmap_notify_callback
->track_inst_handle
);
326 error
= CS_ERR_LIBRARY
;
330 if (cmap_inst
->finalize
) {
332 * If the finalize has been called then get out of the dispatch.
334 error
= CS_ERR_BAD_HANDLE
;
339 * Determine if more messages should be processed
341 if (dispatch_types
== CS_DISPATCH_ONE
|| dispatch_types
== CS_DISPATCH_ONE_NONBLOCKING
) {
347 (void)hdb_handle_put (&cmap_handle_t_db
, handle
);
352 cs_error_t
cmap_context_get (
353 cmap_handle_t handle
,
354 const void **context
)
357 struct cmap_inst
*cmap_inst
;
359 error
= hdb_error_to_cs(hdb_handle_get(&cmap_handle_t_db
, handle
, (void *)&cmap_inst
));
360 if (error
!= CS_OK
) {
364 *context
= cmap_inst
->context
;
366 (void)hdb_handle_put (&cmap_handle_t_db
, handle
);
371 cs_error_t
cmap_context_set (
372 cmap_handle_t handle
,
376 struct cmap_inst
*cmap_inst
;
378 error
= hdb_error_to_cs(hdb_handle_get (&cmap_handle_t_db
, handle
, (void *)&cmap_inst
));
379 if (error
!= CS_OK
) {
383 cmap_inst
->context
= context
;
385 (void)hdb_handle_put (&cmap_handle_t_db
, handle
);
390 cs_error_t
cmap_set (
391 cmap_handle_t handle
,
392 const char *key_name
,
395 cmap_value_types_t type
)
399 struct cmap_inst
*cmap_inst
;
400 struct req_lib_cmap_set req_lib_cmap_set
;
401 struct res_lib_cmap_set res_lib_cmap_set
;
403 if (key_name
== NULL
|| value
== NULL
) {
404 return (CS_ERR_INVALID_PARAM
);
407 if (strlen(key_name
) >= CS_MAX_NAME_LENGTH
) {
408 return (CS_ERR_NAME_TOO_LONG
);
411 error
= hdb_error_to_cs(hdb_handle_get (&cmap_handle_t_db
, handle
, (void *)&cmap_inst
));
412 if (error
!= CS_OK
) {
416 memset(&req_lib_cmap_set
, 0, sizeof(req_lib_cmap_set
));
417 req_lib_cmap_set
.header
.size
= sizeof(req_lib_cmap_set
) + value_len
;
418 req_lib_cmap_set
.header
.id
= MESSAGE_REQ_CMAP_SET
;
420 memcpy(req_lib_cmap_set
.key_name
.value
, key_name
, strlen(key_name
));
421 req_lib_cmap_set
.key_name
.length
= strlen(key_name
);
423 req_lib_cmap_set
.value_len
= value_len
;
424 req_lib_cmap_set
.type
= type
;
426 iov
[0].iov_base
= (char *)&req_lib_cmap_set
;
427 iov
[0].iov_len
= sizeof(req_lib_cmap_set
);
428 iov
[1].iov_base
= (void *)value
;
429 iov
[1].iov_len
= value_len
;
431 error
= qb_to_cs_error(qb_ipcc_sendv_recv(
436 sizeof (struct res_lib_cmap_set
), CS_IPC_TIMEOUT_MS
));
438 if (error
== CS_OK
) {
439 error
= res_lib_cmap_set
.header
.error
;
442 (void)hdb_handle_put (&cmap_handle_t_db
, handle
);
447 cs_error_t
cmap_set_int8(cmap_handle_t handle
, const char *key_name
, int8_t value
)
449 return (cmap_set(handle
, key_name
, &value
, sizeof(value
), CMAP_VALUETYPE_INT8
));
452 cs_error_t
cmap_set_uint8(cmap_handle_t handle
, const char *key_name
, uint8_t value
)
454 return (cmap_set(handle
, key_name
, &value
, sizeof(value
), CMAP_VALUETYPE_UINT8
));
457 cs_error_t
cmap_set_int16(cmap_handle_t handle
, const char *key_name
, int16_t value
)
459 return (cmap_set(handle
, key_name
, &value
, sizeof(value
), CMAP_VALUETYPE_INT16
));
462 cs_error_t
cmap_set_uint16(cmap_handle_t handle
, const char *key_name
, uint16_t value
)
464 return (cmap_set(handle
, key_name
, &value
, sizeof(value
), CMAP_VALUETYPE_UINT16
));
467 cs_error_t
cmap_set_int32(cmap_handle_t handle
, const char *key_name
, int32_t value
)
469 return (cmap_set(handle
, key_name
, &value
, sizeof(value
), CMAP_VALUETYPE_INT32
));
472 cs_error_t
cmap_set_uint32(cmap_handle_t handle
, const char *key_name
, uint32_t value
)
474 return (cmap_set(handle
, key_name
, &value
, sizeof(value
), CMAP_VALUETYPE_UINT32
));
477 cs_error_t
cmap_set_int64(cmap_handle_t handle
, const char *key_name
, int64_t value
)
479 return (cmap_set(handle
, key_name
, &value
, sizeof(value
), CMAP_VALUETYPE_INT64
));
482 cs_error_t
cmap_set_uint64(cmap_handle_t handle
, const char *key_name
, uint64_t value
)
484 return (cmap_set(handle
, key_name
, &value
, sizeof(value
), CMAP_VALUETYPE_UINT64
));
487 cs_error_t
cmap_set_float(cmap_handle_t handle
, const char *key_name
, float value
)
489 return (cmap_set(handle
, key_name
, &value
, sizeof(value
), CMAP_VALUETYPE_FLOAT
));
492 cs_error_t
cmap_set_double(cmap_handle_t handle
, const char *key_name
, double value
)
494 return (cmap_set(handle
, key_name
, &value
, sizeof(value
), CMAP_VALUETYPE_DOUBLE
));
497 cs_error_t
cmap_set_string(cmap_handle_t handle
, const char *key_name
, const char *value
)
501 return (CS_ERR_INVALID_PARAM
);
504 return (cmap_set(handle
, key_name
, value
, strlen(value
), CMAP_VALUETYPE_STRING
));
507 cs_error_t
cmap_delete(cmap_handle_t handle
, const char *key_name
)
511 struct cmap_inst
*cmap_inst
;
512 struct req_lib_cmap_delete req_lib_cmap_delete
;
513 struct res_lib_cmap_delete res_lib_cmap_delete
;
515 if (key_name
== NULL
) {
516 return (CS_ERR_INVALID_PARAM
);
518 if (strlen(key_name
) >= CS_MAX_NAME_LENGTH
) {
519 return (CS_ERR_NAME_TOO_LONG
);
522 error
= hdb_error_to_cs(hdb_handle_get (&cmap_handle_t_db
, handle
, (void *)&cmap_inst
));
523 if (error
!= CS_OK
) {
527 memset(&req_lib_cmap_delete
, 0, sizeof(req_lib_cmap_delete
));
528 req_lib_cmap_delete
.header
.size
= sizeof(req_lib_cmap_delete
);
529 req_lib_cmap_delete
.header
.id
= MESSAGE_REQ_CMAP_DELETE
;
531 memcpy(req_lib_cmap_delete
.key_name
.value
, key_name
, strlen(key_name
));
532 req_lib_cmap_delete
.key_name
.length
= strlen(key_name
);
534 iov
.iov_base
= (char *)&req_lib_cmap_delete
;
535 iov
.iov_len
= sizeof(req_lib_cmap_delete
);
537 error
= qb_to_cs_error(qb_ipcc_sendv_recv(
541 &res_lib_cmap_delete
,
542 sizeof (struct res_lib_cmap_delete
), CS_IPC_TIMEOUT_MS
));
544 if (error
== CS_OK
) {
545 error
= res_lib_cmap_delete
.header
.error
;
548 (void)hdb_handle_put (&cmap_handle_t_db
, handle
);
554 cmap_handle_t handle
,
555 const char *key_name
,
558 cmap_value_types_t
*type
)
561 struct cmap_inst
*cmap_inst
;
563 struct req_lib_cmap_get req_lib_cmap_get
;
564 struct res_lib_cmap_get
*res_lib_cmap_get
;
567 if (key_name
== NULL
) {
568 return (CS_ERR_INVALID_PARAM
);
570 if (strlen(key_name
) >= CS_MAX_NAME_LENGTH
) {
571 return (CS_ERR_NAME_TOO_LONG
);
574 if (value
!= NULL
&& value_len
== NULL
) {
575 return (CS_ERR_INVALID_PARAM
);
578 error
= hdb_error_to_cs(hdb_handle_get (&cmap_handle_t_db
, handle
, (void *)&cmap_inst
));
579 if (error
!= CS_OK
) {
583 memset(&req_lib_cmap_get
, 0, sizeof(req_lib_cmap_get
));
584 req_lib_cmap_get
.header
.size
= sizeof(req_lib_cmap_get
);
585 req_lib_cmap_get
.header
.id
= MESSAGE_REQ_CMAP_GET
;
587 memcpy(req_lib_cmap_get
.key_name
.value
, key_name
, strlen(key_name
));
588 req_lib_cmap_get
.key_name
.length
= strlen(key_name
);
590 if (value
!= NULL
&& value_len
!= NULL
) {
591 req_lib_cmap_get
.value_len
= *value_len
;
593 req_lib_cmap_get
.value_len
= 0;
596 iov
.iov_base
= (char *)&req_lib_cmap_get
;
597 iov
.iov_len
= sizeof(req_lib_cmap_get
);
599 res_size
= sizeof(struct res_lib_cmap_get
) + req_lib_cmap_get
.value_len
;
601 res_lib_cmap_get
= malloc(res_size
);
602 if (res_lib_cmap_get
== NULL
) {
603 return (CS_ERR_NO_MEMORY
);
606 error
= qb_to_cs_error(qb_ipcc_sendv_recv(
611 res_size
, CS_IPC_TIMEOUT_MS
));
613 if (error
== CS_OK
) {
614 error
= res_lib_cmap_get
->header
.error
;
617 if (error
== CS_OK
) {
619 *type
= res_lib_cmap_get
->type
;
622 if (value_len
!= NULL
) {
623 *value_len
= res_lib_cmap_get
->value_len
;
626 if (value
!= NULL
&& value_len
!= NULL
) {
627 memcpy(value
, res_lib_cmap_get
->value
, res_lib_cmap_get
->value_len
);
631 free(res_lib_cmap_get
);
633 (void)hdb_handle_put (&cmap_handle_t_db
, handle
);
638 static cs_error_t
cmap_get_int(
639 cmap_handle_t handle
,
640 const char *key_name
,
643 cmap_value_types_t type
)
649 cmap_value_types_t key_type
;
651 key_size
= sizeof(key_value
);
652 memset(key_value
, 0, key_size
);
654 err
= cmap_get(handle
, key_name
, key_value
, &key_size
, &key_type
);
658 if (key_type
!= type
) {
659 return (CS_ERR_INVALID_PARAM
);
662 memcpy(value
, key_value
, value_size
);
667 cs_error_t
cmap_get_int8(cmap_handle_t handle
, const char *key_name
, int8_t *i8
)
670 return (cmap_get_int(handle
, key_name
, i8
, sizeof(*i8
), CMAP_VALUETYPE_INT8
));
673 cs_error_t
cmap_get_uint8(cmap_handle_t handle
, const char *key_name
, uint8_t *u8
)
676 return (cmap_get_int(handle
, key_name
, u8
, sizeof(*u8
), CMAP_VALUETYPE_UINT8
));
679 cs_error_t
cmap_get_int16(cmap_handle_t handle
, const char *key_name
, int16_t *i16
)
682 return (cmap_get_int(handle
, key_name
, i16
, sizeof(*i16
), CMAP_VALUETYPE_INT16
));
685 cs_error_t
cmap_get_uint16(cmap_handle_t handle
, const char *key_name
, uint16_t *u16
)
688 return (cmap_get_int(handle
, key_name
, u16
, sizeof(*u16
), CMAP_VALUETYPE_UINT16
));
691 cs_error_t
cmap_get_int32(cmap_handle_t handle
, const char *key_name
, int32_t *i32
)
694 return (cmap_get_int(handle
, key_name
, i32
, sizeof(*i32
), CMAP_VALUETYPE_INT32
));
697 cs_error_t
cmap_get_uint32(cmap_handle_t handle
, const char *key_name
, uint32_t *u32
)
700 return (cmap_get_int(handle
, key_name
, u32
, sizeof(*u32
), CMAP_VALUETYPE_UINT32
));
703 cs_error_t
cmap_get_int64(cmap_handle_t handle
, const char *key_name
, int64_t *i64
)
706 return (cmap_get_int(handle
, key_name
, i64
, sizeof(*i64
), CMAP_VALUETYPE_INT64
));
709 cs_error_t
cmap_get_uint64(cmap_handle_t handle
, const char *key_name
, uint64_t *u64
)
712 return (cmap_get_int(handle
, key_name
, u64
, sizeof(*u64
), CMAP_VALUETYPE_UINT64
));
715 cs_error_t
cmap_get_float(cmap_handle_t handle
, const char *key_name
, float *flt
)
718 return (cmap_get_int(handle
, key_name
, flt
, sizeof(*flt
), CMAP_VALUETYPE_FLOAT
));
721 cs_error_t
cmap_get_double(cmap_handle_t handle
, const char *key_name
, double *dbl
)
724 return (cmap_get_int(handle
, key_name
, dbl
, sizeof(*dbl
), CMAP_VALUETYPE_DOUBLE
));
727 cs_error_t
cmap_get_string(cmap_handle_t handle
, const char *key_name
, char **str
)
731 cmap_value_types_t type
;
733 res
= cmap_get(handle
, key_name
, NULL
, &str_len
, &type
);
735 if (res
!= CS_OK
|| type
!= CMAP_VALUETYPE_STRING
) {
737 res
= CS_ERR_INVALID_PARAM
;
743 *str
= malloc(str_len
);
745 res
= CS_ERR_NO_MEMORY
;
750 res
= cmap_get(handle
, key_name
, *str
, &str_len
, &type
);
763 static cs_error_t
cmap_adjust_int(cmap_handle_t handle
, const char *key_name
, int32_t step
)
767 struct cmap_inst
*cmap_inst
;
768 struct req_lib_cmap_adjust_int req_lib_cmap_adjust_int
;
769 struct res_lib_cmap_adjust_int res_lib_cmap_adjust_int
;
771 if (key_name
== NULL
) {
772 return (CS_ERR_INVALID_PARAM
);
774 if (strlen(key_name
) >= CS_MAX_NAME_LENGTH
) {
775 return (CS_ERR_NAME_TOO_LONG
);
778 error
= hdb_error_to_cs(hdb_handle_get (&cmap_handle_t_db
, handle
, (void *)&cmap_inst
));
779 if (error
!= CS_OK
) {
783 memset(&req_lib_cmap_adjust_int
, 0, sizeof(req_lib_cmap_adjust_int
));
784 req_lib_cmap_adjust_int
.header
.size
= sizeof(req_lib_cmap_adjust_int
);
785 req_lib_cmap_adjust_int
.header
.id
= MESSAGE_REQ_CMAP_ADJUST_INT
;
787 memcpy(req_lib_cmap_adjust_int
.key_name
.value
, key_name
, strlen(key_name
));
788 req_lib_cmap_adjust_int
.key_name
.length
= strlen(key_name
);
790 req_lib_cmap_adjust_int
.step
= step
;
792 iov
.iov_base
= (char *)&req_lib_cmap_adjust_int
;
793 iov
.iov_len
= sizeof(req_lib_cmap_adjust_int
);
795 error
= qb_to_cs_error(qb_ipcc_sendv_recv(
799 &res_lib_cmap_adjust_int
,
800 sizeof (struct res_lib_cmap_adjust_int
), CS_IPC_TIMEOUT_MS
));
802 if (error
== CS_OK
) {
803 error
= res_lib_cmap_adjust_int
.header
.error
;
806 (void)hdb_handle_put (&cmap_handle_t_db
, handle
);
811 cs_error_t
cmap_inc(cmap_handle_t handle
, const char *key_name
)
814 return (cmap_adjust_int(handle
, key_name
, 1));
817 cs_error_t
cmap_dec(cmap_handle_t handle
, const char *key_name
)
820 return (cmap_adjust_int(handle
, key_name
, -1));
823 cs_error_t
cmap_iter_init(
824 cmap_handle_t handle
,
826 cmap_iter_handle_t
*cmap_iter_handle
)
830 struct cmap_inst
*cmap_inst
;
831 struct req_lib_cmap_iter_init req_lib_cmap_iter_init
;
832 struct res_lib_cmap_iter_init res_lib_cmap_iter_init
;
834 if (cmap_iter_handle
== NULL
) {
835 return (CS_ERR_INVALID_PARAM
);
838 error
= hdb_error_to_cs(hdb_handle_get (&cmap_handle_t_db
, handle
, (void *)&cmap_inst
));
839 if (error
!= CS_OK
) {
843 memset(&req_lib_cmap_iter_init
, 0, sizeof(req_lib_cmap_iter_init
));
844 req_lib_cmap_iter_init
.header
.size
= sizeof(req_lib_cmap_iter_init
);
845 req_lib_cmap_iter_init
.header
.id
= MESSAGE_REQ_CMAP_ITER_INIT
;
848 if (strlen(prefix
) >= CS_MAX_NAME_LENGTH
) {
849 return (CS_ERR_NAME_TOO_LONG
);
851 memcpy(req_lib_cmap_iter_init
.prefix
.value
, prefix
, strlen(prefix
));
852 req_lib_cmap_iter_init
.prefix
.length
= strlen(prefix
);
855 iov
.iov_base
= (char *)&req_lib_cmap_iter_init
;
856 iov
.iov_len
= sizeof(req_lib_cmap_iter_init
);
858 error
= qb_to_cs_error(qb_ipcc_sendv_recv(
862 &res_lib_cmap_iter_init
,
863 sizeof (struct res_lib_cmap_iter_init
), CS_IPC_TIMEOUT_MS
));
865 if (error
== CS_OK
) {
866 error
= res_lib_cmap_iter_init
.header
.error
;
869 if (error
== CS_OK
) {
870 *cmap_iter_handle
= res_lib_cmap_iter_init
.iter_handle
;
873 (void)hdb_handle_put (&cmap_handle_t_db
, handle
);
878 cs_error_t
cmap_iter_next(
879 cmap_handle_t handle
,
880 cmap_iter_handle_t iter_handle
,
883 cmap_value_types_t
*type
)
887 struct cmap_inst
*cmap_inst
;
888 struct req_lib_cmap_iter_next req_lib_cmap_iter_next
;
889 struct res_lib_cmap_iter_next res_lib_cmap_iter_next
;
891 if (key_name
== NULL
) {
892 return (CS_ERR_INVALID_PARAM
);
895 error
= hdb_error_to_cs(hdb_handle_get (&cmap_handle_t_db
, handle
, (void *)&cmap_inst
));
896 if (error
!= CS_OK
) {
900 memset(&req_lib_cmap_iter_next
, 0, sizeof(req_lib_cmap_iter_next
));
901 req_lib_cmap_iter_next
.header
.size
= sizeof(req_lib_cmap_iter_next
);
902 req_lib_cmap_iter_next
.header
.id
= MESSAGE_REQ_CMAP_ITER_NEXT
;
903 req_lib_cmap_iter_next
.iter_handle
= iter_handle
;
905 iov
.iov_base
= (char *)&req_lib_cmap_iter_next
;
906 iov
.iov_len
= sizeof(req_lib_cmap_iter_next
);
908 error
= qb_to_cs_error(qb_ipcc_sendv_recv(
912 &res_lib_cmap_iter_next
,
913 sizeof (struct res_lib_cmap_iter_next
), CS_IPC_TIMEOUT_MS
));
915 if (error
== CS_OK
) {
916 error
= res_lib_cmap_iter_next
.header
.error
;
919 if (error
== CS_OK
) {
920 memcpy(key_name
, (const char *)res_lib_cmap_iter_next
.key_name
.value
,
921 res_lib_cmap_iter_next
.key_name
.length
);
922 key_name
[res_lib_cmap_iter_next
.key_name
.length
] = '\0';
924 if (value_len
!= NULL
) {
925 *value_len
= res_lib_cmap_iter_next
.value_len
;
929 *type
= res_lib_cmap_iter_next
.type
;
933 (void)hdb_handle_put (&cmap_handle_t_db
, handle
);
938 cs_error_t
cmap_iter_finalize(
939 cmap_handle_t handle
,
940 cmap_iter_handle_t iter_handle
)
944 struct cmap_inst
*cmap_inst
;
945 struct req_lib_cmap_iter_finalize req_lib_cmap_iter_finalize
;
946 struct res_lib_cmap_iter_finalize res_lib_cmap_iter_finalize
;
948 error
= hdb_error_to_cs(hdb_handle_get (&cmap_handle_t_db
, handle
, (void *)&cmap_inst
));
949 if (error
!= CS_OK
) {
953 memset(&req_lib_cmap_iter_finalize
, 0, sizeof(req_lib_cmap_iter_finalize
));
954 req_lib_cmap_iter_finalize
.header
.size
= sizeof(req_lib_cmap_iter_finalize
);
955 req_lib_cmap_iter_finalize
.header
.id
= MESSAGE_REQ_CMAP_ITER_FINALIZE
;
956 req_lib_cmap_iter_finalize
.iter_handle
= iter_handle
;
958 iov
.iov_base
= (char *)&req_lib_cmap_iter_finalize
;
959 iov
.iov_len
= sizeof(req_lib_cmap_iter_finalize
);
961 error
= qb_to_cs_error(qb_ipcc_sendv_recv(
965 &res_lib_cmap_iter_finalize
,
966 sizeof (struct res_lib_cmap_iter_finalize
), CS_IPC_TIMEOUT_MS
));
968 if (error
== CS_OK
) {
969 error
= res_lib_cmap_iter_finalize
.header
.error
;
972 (void)hdb_handle_put (&cmap_handle_t_db
, handle
);
977 cs_error_t
cmap_track_add(
978 cmap_handle_t handle
,
979 const char *key_name
,
981 cmap_notify_fn_t notify_fn
,
983 cmap_track_handle_t
*cmap_track_handle
)
987 struct cmap_inst
*cmap_inst
;
988 struct req_lib_cmap_track_add req_lib_cmap_track_add
;
989 struct res_lib_cmap_track_add res_lib_cmap_track_add
;
990 struct cmap_track_inst
*cmap_track_inst
;
991 cmap_track_handle_t cmap_track_inst_handle
;
993 if (cmap_track_handle
== NULL
|| notify_fn
== NULL
) {
994 return (CS_ERR_INVALID_PARAM
);
997 error
= hdb_error_to_cs(hdb_handle_get (&cmap_handle_t_db
, handle
, (void *)&cmap_inst
));
998 if (error
!= CS_OK
) {
1002 error
= hdb_error_to_cs(hdb_handle_create(&cmap_track_handle_t_db
,
1003 sizeof(*cmap_track_inst
), &cmap_track_inst_handle
));
1004 if (error
!= CS_OK
) {
1008 error
= hdb_error_to_cs(hdb_handle_get(&cmap_track_handle_t_db
,
1009 cmap_track_inst_handle
, (void *)&cmap_track_inst
));
1010 if (error
!= CS_OK
) {
1011 goto error_put_destroy
;
1014 cmap_track_inst
->user_data
= user_data
;
1015 cmap_track_inst
->notify_fn
= notify_fn
;
1016 cmap_track_inst
->c
= cmap_inst
->c
;
1018 memset(&req_lib_cmap_track_add
, 0, sizeof(req_lib_cmap_track_add
));
1019 req_lib_cmap_track_add
.header
.size
= sizeof(req_lib_cmap_track_add
);
1020 req_lib_cmap_track_add
.header
.id
= MESSAGE_REQ_CMAP_TRACK_ADD
;
1023 if (strlen(key_name
) >= CS_MAX_NAME_LENGTH
) {
1024 return (CS_ERR_NAME_TOO_LONG
);
1026 memcpy(req_lib_cmap_track_add
.key_name
.value
, key_name
, strlen(key_name
));
1027 req_lib_cmap_track_add
.key_name
.length
= strlen(key_name
);
1030 req_lib_cmap_track_add
.track_type
= track_type
;
1031 req_lib_cmap_track_add
.track_inst_handle
= cmap_track_inst_handle
;
1033 iov
.iov_base
= (char *)&req_lib_cmap_track_add
;
1034 iov
.iov_len
= sizeof(req_lib_cmap_track_add
);
1036 error
= qb_to_cs_error(qb_ipcc_sendv_recv(
1040 &res_lib_cmap_track_add
,
1041 sizeof (struct res_lib_cmap_track_add
), CS_IPC_TIMEOUT_MS
));
1043 if (error
== CS_OK
) {
1044 error
= res_lib_cmap_track_add
.header
.error
;
1047 if (error
== CS_OK
) {
1048 *cmap_track_handle
= res_lib_cmap_track_add
.track_handle
;
1049 cmap_track_inst
->track_handle
= *cmap_track_handle
;
1052 (void)hdb_handle_put (&cmap_track_handle_t_db
, cmap_track_inst_handle
);
1054 (void)hdb_handle_put (&cmap_handle_t_db
, handle
);
1059 (void)hdb_handle_put (&cmap_track_handle_t_db
, cmap_track_inst_handle
);
1060 (void)hdb_handle_destroy (&cmap_track_handle_t_db
, cmap_track_inst_handle
);
1063 (void)hdb_handle_put (&cmap_handle_t_db
, handle
);
1068 cs_error_t
cmap_track_delete(
1069 cmap_handle_t handle
,
1070 cmap_track_handle_t track_handle
)
1074 struct cmap_inst
*cmap_inst
;
1075 struct cmap_track_inst
*cmap_track_inst
;
1076 struct req_lib_cmap_track_delete req_lib_cmap_track_delete
;
1077 struct res_lib_cmap_track_delete res_lib_cmap_track_delete
;
1079 error
= hdb_error_to_cs(hdb_handle_get (&cmap_handle_t_db
, handle
, (void *)&cmap_inst
));
1080 if (error
!= CS_OK
) {
1084 memset(&req_lib_cmap_track_delete
, 0, sizeof(req_lib_cmap_track_delete
));
1085 req_lib_cmap_track_delete
.header
.size
= sizeof(req_lib_cmap_track_delete
);
1086 req_lib_cmap_track_delete
.header
.id
= MESSAGE_REQ_CMAP_TRACK_DELETE
;
1087 req_lib_cmap_track_delete
.track_handle
= track_handle
;
1089 iov
.iov_base
= (char *)&req_lib_cmap_track_delete
;
1090 iov
.iov_len
= sizeof(req_lib_cmap_track_delete
);
1092 error
= qb_to_cs_error(qb_ipcc_sendv_recv(
1096 &res_lib_cmap_track_delete
,
1097 sizeof (struct res_lib_cmap_track_delete
), CS_IPC_TIMEOUT_MS
));
1099 if (error
== CS_OK
) {
1100 error
= res_lib_cmap_track_delete
.header
.error
;
1103 if (error
== CS_OK
) {
1104 error
= hdb_error_to_cs(hdb_handle_get(&cmap_track_handle_t_db
,
1105 res_lib_cmap_track_delete
.track_inst_handle
,
1106 (void *)&cmap_track_inst
));
1107 if (error
!= CS_OK
) {
1111 (void)hdb_handle_put(&cmap_track_handle_t_db
, res_lib_cmap_track_delete
.track_inst_handle
);
1112 (void)hdb_handle_destroy(&cmap_track_handle_t_db
, res_lib_cmap_track_delete
.track_inst_handle
);
1116 (void)hdb_handle_put (&cmap_handle_t_db
, handle
);