CPG_M...ALIZE(3)
π CPG_MODEL_INITIALIZE β¨
okay bestie, this is the cpg_model_initialize(3) page from the Corosync Cluster Engine Programmer's Manual β yes it's a whole manual, and yes you're gonna read it, because I love you and I want you to slay π«Ά
πΈ NAME πΈ
cpg_model_initialize β Create a new connection to the CPG service
π SYNOPSIS π
#include <corosync/cpg.h>
cs_error_t cpg_model_initialize(cpg_handle_t *handle, cpg_model_t model,
cpg_model_data_t *model_data, void *context);
π¦ DESCRIPTION π¦
So like, cpg_model_initialize is the function you call to set up a connection to the closed process groups API. It's giving "hello CPG service, it's me" energy. β¨
Your app can have several connections to the CPG API at once β not just one, bestie, we're multitasking. And the way you tell them apart is the handle argument. That's your lil ID badge. You pass handle into all the other function calls later so everyone knows which connection you're talking about when you're chatting with the CPG service. π
Then there's the model argument, which is how you explicitly pick your set of callbacks and internal parameters. Right now only model CPG_MODEL_V1 is defined, so that's your only option, no cap.
The callbacks and internal parameters get passed through the model_data argument. It's a casted pointer (same idea as the sockaddr situation, iykyk) pointing at one of the structures that matches whichever model you chose. And again β currently only cpg_model_v1_data_t is needed.
π MODEL_V1 π
MODEL_V1 is backwards compatible with the original callbacks you'd set up with cpg_initialize, but it also defines a brand new callback: cpg_totem_confchg_fn. Glow up moment. β¨
Every single time a CPG event happens inside the joined group, one of the callbacks you specified in the callbacks argument gets called. Here are those callback functions as type definitions, verbatim, don't touch them:
typedef void (*cpg_deliver_fn_t) (
cpg_handle_t handle,
const struct cpg_name *group_name,
uint32_t nodeid,
uint32_t pid,
const void *msg,
size_t msg_len);
typedef void (*cpg_confchg_fn_t) (
cpg_handle_t handle,
const struct cpg_name *group_name,
const struct cpg_address *member_list, size_t member_list_entries,
const struct cpg_address *left_list, size_t left_list_entries,
const struct cpg_address *joined_list, size_t joined_list_entries);
typedef void (*cpg_totem_confchg_fn_t) (
cpg_handle_t handle,
struct cpg_ring_id ring_id,
uint32_t member_list_entries,
const uint32_t *member_list);
And the cpg_model_v1_data_t structure is defined like this:
typedef struct {
cpg_model_t model;
cpg_deliver_fn_t cpg_deliver_fn;
cpg_confchg_fn_t cpg_confchg_fn;
cpg_totem_confchg_fn_t cpg_totem_confchg_fn;
unsigned int flags;
} cpg_model_v1_data_t;
Okay so here's the tea on when each one fires β β when a configuration change happens or a message needs delivering, one of these callbacks gets called from the cpg_dispatch() function:
- config change goes down? β
cpg_confchg_fngets called - message delivery goes down? β
cpg_deliver_fngets called - totem membership change goes down? β
cpg_totem_confchg_fngets called
And here's a lil trick, bestie: you can OR the CPG_MODEL_V1_DELIVER_INITIAL_TOTEM_CONF constant into flags and you'll get the callback after the first confchg event. π
Now the cpg_address structure, defined as:
struct cpg_address {
unsigned int nodeid;
unsigned int pid;
unsigned int reason;
};
where:
nodeidis a 32 bit unique node identifierpidis the process ID of the process that has joined/left the group or sent the messagereasonis an integer code indicating why the node joined/left the group (β οΈ heads up: this value is not set for themember_listitems)
The possible reason values, and what they mean:
CPG_REASON_JOINβ the process joined a group usingcpg_join().CPG_REASON_LEAVEβ the process left a group usingcpg_leave()CPG_REASON_NODEDOWNβ the process left a group because the node left the cluster.CPG_REASON_NODEUPβ the process joined a group because it was already a member of a group on a node that has just joined the clusterCPG_REASON_PROCDOWNβ the process left a group without callingcpg_leave()CPG_REASON_UNDEFINEDβ a special value used for themember_listitems
And finally the cpg_ring_id structure, defined as:
struct cpg_ring_id {
uint32_t nodeid;
uint64_t seq;
};
where nodeid is the current Totem leader and seq is an increasing number. π
π RETURN VALUE π
If it works, this call returns the CS_OK value. If it doesn't... it returns an error instead. That's it, that's the deal. π
π ERRORS π
ngl bestie, the errors are undocumented. That's literally what it says. We don't know. Nobody wrote it down. π
π SEE ALSO π
Go read these next, queen π
cpg_overview(3), cpg_initialize(3), cpg_finalize(3), cpg_fd_get(3), cpg_dispatch(3), cpg_join(3), cpg_leave(3), cpg_mcast_joined(3), cpg_membership_get(3) cpg_zcb_alloc(3) cpg_zcb_free(3) cpg_zcb_mcast_joined(3) cpg_context_get(3) cpg_context_set(3) cpg_local_get(3) cpg_model_initialize(3)
And here are the error codes that show up around these parts:
CS_ERR_TRY_AGAINβ Resource temporarily unavailableCS_ERR_INVALID_PARAMβ Invalid argumentCS_ERR_ACCESSβ Permission deniedCS_ERR_LIBRARYβ The connection failedCS_ERR_INTERRUPTβ System call interrupted by a signalCS_ERR_NOT_SUPPORTEDβ The requested protocol/functionality not supportedCS_ERR_MESSAGE_ERRORβ Incorrect auth message receivedCS_ERR_NO_MEMORYβ Not enough memory to complete the requested task
okay that's the whole page, you ate that π this was the corosync Man Page, dated 2024-07-15 β mwah, go forth and initialize your connections, bestie π
ππ
π¦ where this page comes from
- debian trixie: libcpg-dev 3.1.9-2+deb13u1 Β· BSD-3-Clause
- epel 9: corosynclib-devel 3.1.10-0.2.el9.1 Β· BSD-3-Clause
- fedora 43: corosynclib-devel 3.1.10-3.fc43 Β· BSD-3-Clause
- fedora 43: corosynclib-devel 3.1.10-3.fc43 Β· BSD-3-Clause
- fedora 43: corosynclib-devel 3.1.9-5.fc43 Β· BSD-3-Clause
- fedora 43: corosynclib-devel 3.1.9-5.fc43 Β· BSD-3-Clause
- fedora 44: corosynclib-devel 3.1.10-4.fc44 Β· BSD-3-Clause
- fedora 44: corosynclib-devel 3.1.10-4.fc44 Β· BSD-3-Clause
- fedora 44: corosynclib-devel 3.1.10-6.fc44 Β· BSD-3-Clause
- fedora 44: corosynclib-devel 3.1.10-6.fc44 Β· BSD-3-Clause
- nixos 26.05: corosync 3.1.9
- nixpkgs unstable: corosync 3.1.9
- opensuse-leap 16.0: corosync-devel 3.1.9-160000.4.1 Β· BSD-3-Clause
- opensuse-leap 16.0: corosync-devel 3.1.9-160000.4.1 Β· BSD-3-Clause
- opensuse-leap 16.0: corosync-devel 3.1.9-160000.4.1 Β· BSD-3-Clause
- opensuse-leap 16.0: corosync-devel 3.1.9-160000.4.1 Β· BSD-3-Clause
- ubuntu questing: libcpg-dev 3.1.9-2ubuntu1
- ubuntu questing: libcpg-dev 3.1.9-2ubuntu1.1
- ubuntu resolute: libcpg-dev 3.1.9-2ubuntu3 Β· BSD-3-Clause
- ubuntu stonking: libcpg-dev 3.1.10-3ubuntu1 Β· BSD-3-Clause
- Copyright (c) 2010-2024 Red Hat, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms