CMAP_SET(3)

πŸ’Ύ CMAP_SET(3) β€” the Corosync Cluster Engine Programmer's Manual one

okay bestie, welcome to the <corosync/cmap.h> girlies' corner of the Corosync Cluster Engine Programmer's Manual πŸ’– this is cmap_set, page 3 of the manual, and she's here to help you store a value in CMAP. iconic behavior, truly.


✨ NAME ✨

cmap_set β€” Store value in CMAP 🫢


πŸ“œ SYNOPSIS πŸ“œ

First up, the main character:

#include <corosync/cmap.h>

cs_error_t cmap_set (cmap_handle_t handle, const char *key_name, const
void *value, size_t value_len, cmap_value_types_t type);

Also shortcuts for different types are defined πŸ‘‘ β€” yes queen, one per type, because typing casts is not the vibe:

cs_error_t cmap_set_int8(cmap_handle_t handle, const char *key_name,
int8_t value);

cs_error_t cmap_set_uint8(cmap_handle_t handle, const char *key_name,
uint8_t value);

cs_error_t cmap_set_int16(cmap_handle_t handle, const char *key_name,
int16_t value);

cs_error_t cmap_set_uint16(cmap_handle_t handle, const char *key_name,
uint16_t value);

cs_error_t cmap_set_int32(cmap_handle_t handle, const char *key_name,
int32_t value);

cs_error_t cmap_set_uint32(cmap_handle_t handle, const char *key_name,
uint32_t value);

cs_error_t cmap_set_int64(cmap_handle_t handle, const char *key_name,
int64_t value);

cs_error_t cmap_set_uint64(cmap_handle_t handle, const char *key_name,
uint64_t value);

cs_error_t cmap_set_float(cmap_handle_t handle, const char *key_name,
float value);

cs_error_t cmap_set_double(cmap_handle_t handle, const char *key_name,
double value);

cs_error_t cmap_set_string(cmap_handle_t handle, const char *key_name,
const char *value);

πŸ’… DESCRIPTION πŸ’…

so the cmap_set function is the one that stores a key inside cmap. simple. elegant. she serves. ✨

let's break down her little ensemble:

  • handle β€” this is your connection to the CMAP database, and you got it by calling cmap_initialize(3). no handle, no entry, periodt.
  • key_name β€” the name of the key you're setting a value for. and bestie, she has rules: the key name is limited by a minimal length (CMAP_KEYNAME_MINLEN, currently 3) and a maximal length (CMAP_KEYNAME_MAXLEN, currently 255). also, the key can contain only a limited set of characters, expressed by this regexp: [a-zA-Z0-9._-/:]*. that's the whole guest list, nobody else gets in πŸŽ€
  • value β€” a pointer to the allocated data that will be stored inside CMAP. yes, allocated. we love a responsible memory moment.
  • value_len β€” the length of value, measured in number of bytes. byte count, not vibes count.
  • type β€” the last parameter, and she tells CMAP what kind of value this is. it may be one of:
    • CMAP_VALUETYPE_INT8 β€” 8-bit signed integer
    • CMAP_VALUETYPE_UINT8 β€” 8-bit unsigned integer
    • CMAP_VALUETYPE_INT16 β€” 16-bit signed integer
    • CMAP_VALUETYPE_UINT16 β€” 16-bit unsigned integer
    • CMAP_VALUETYPE_INT32 β€” 32-bit signed integer
    • CMAP_VALUETYPE_UINT32 β€” 32-bit unsigned integer
    • CMAP_VALUETYPE_INT64 β€” 64-bit signed integer
    • CMAP_VALUETYPE_UINT64 β€” 64-bit unsigned integer
    • CMAP_VALUETYPE_FLOAT β€” Float value
    • CMAP_VALUETYPE_DOUBLE β€” Double value
    • CMAP_VALUETYPE_STRING β€” C-style string
    • CMAP_VALUETYPE_BINARY β€” Binary data, byte with zero value has no special meaning

🚨 RETURN VALUE 🚨

okay so this call returns the CS_OK value if it's successful β€” that's your green flag, your little win, your slay 🌈

but sometimes she says no, and here's the whole tea:

  • If value or key_name are unspecified, CS_ERR_INVALID_PARAM is returned. like, you have to actually give her something, bestie 😭
  • Too short or too long key_name returns the CS_ERR_NAME_TOO_LONG error code. respect the length limits or get gently rejected.
  • Some of keys may be tagged read-only directly in corosync, and setting such a key will result in a CS_ERR_ACCESS error. no means no, that key is not accepting edits today πŸ’€

πŸ‘€ SEE ALSO πŸ‘€

go read these next, iykyk:

and here's the full error-code lineup, in case your call comes back looking a little different:

  • CS_ERR_TRY_AGAIN β€” Resource temporarily unavailable
  • CS_ERR_INVALID_PARAM β€” Invalid argument
  • CS_ERR_ACCESS β€” Permission denied
  • CS_ERR_LIBRARY β€” The connection failed
  • CS_ERR_INTERRUPT β€” System call interrupted by a signal
  • CS_ERR_NOT_SUPPORTED β€” The requested protocol/functionality not supported
  • CS_ERR_MESSAGE_ERROR β€” Incorrect auth message received
  • CS_ERR_NO_MEMORY β€” Not enough memory to complete the requested task

and that's the whole page, bestie 🧚 this was the corosync Man Page, dated 23/01/2012 β€” yes, she's an elder but she still eats πŸ’œ go set some keys, and remember: check your return codes. mwah. πŸ’…βœ¨

πŸ“¦ where this page comes from