MCPcopy Create free account
hub / github.com/corosync/corosync / cpg_zcb_alloc

Function cpg_zcb_alloc

lib/cpg.c:947–1011  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

945}
946
947cs_error_t cpg_zcb_alloc (
948 cpg_handle_t handle,
949 size_t size,
950 void **buffer)
951{
952 void *buf = NULL;
953 char path[PATH_MAX];
954 mar_req_coroipcc_zc_alloc_t req_coroipcc_zc_alloc;
955 struct qb_ipc_response_header res_coroipcs_zc_alloc;
956 size_t map_size;
957 struct iovec iovec;
958 struct coroipcs_zc_header *hdr;
959 cs_error_t error;
960 struct cpg_inst *cpg_inst;
961
962 error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst));
963 if (error != CS_OK) {
964 return (error);
965 }
966
967 map_size = size + sizeof (struct req_lib_cpg_mcast) + sizeof (struct coroipcs_zc_header);
968 assert(memory_map (path, "corosync_zerocopy-XXXXXX", &buf, map_size) != -1);
969
970 if (strlen(path) >= CPG_ZC_PATH_LEN) {
971 unlink(path);
972 munmap (buf, map_size);
973 return (CS_ERR_NAME_TOO_LONG);
974 }
975
976 req_coroipcc_zc_alloc.header.size = sizeof (mar_req_coroipcc_zc_alloc_t);
977 req_coroipcc_zc_alloc.header.id = MESSAGE_REQ_CPG_ZC_ALLOC;
978 req_coroipcc_zc_alloc.map_size = map_size;
979 strcpy (req_coroipcc_zc_alloc.path_to_file, path);
980
981 iovec.iov_base = (void *)&req_coroipcc_zc_alloc;
982 iovec.iov_len = sizeof (mar_req_coroipcc_zc_alloc_t);
983
984 error = coroipcc_msg_send_reply_receive (
985 cpg_inst->c,
986 &iovec,
987 1,
988 &res_coroipcs_zc_alloc,
989 sizeof (struct qb_ipc_response_header));
990
991 if (error != CS_OK) {
992 goto error_exit;
993 }
994
995 hdr = (struct coroipcs_zc_header *)buf;
996 hdr->map_size = map_size;
997 *buffer = ((char *)buf) + sizeof (struct coroipcs_zc_header) + sizeof (struct req_lib_cpg_mcast);
998
999error_exit:
1000 hdb_handle_put (&cpg_handle_t_db, handle);
1001 /*
1002 * Coverity correctly reports an error here. We cannot safely munmap and unlink the file, because
1003 * the timing of the failure is the key issue: if a failure occurs before the IPC reply,
1004 * the file should be deleted.

Callers 4

mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85

Calls 5

hdb_error_to_csFunction · 0.85
hdb_handle_getFunction · 0.85
hdb_handle_putFunction · 0.85
memory_mapFunction · 0.70

Tested by 2

mainFunction · 0.68
mainFunction · 0.68