1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-22 22:04:08 +03:00

ctdb-common: Refactor code to convert TDB_DATA key to aligned uint32 array

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
This commit is contained in:
Amitay Isaacs 2014-08-15 13:22:29 +10:00 committed by Martin Schwenke
parent 13d5af48ac
commit bd13389467
2 changed files with 20 additions and 0 deletions

View File

@ -490,3 +490,21 @@ void ctdb_set_runstate(struct ctdb_context *ctdb, enum ctdb_runstate runstate)
runstate_to_string(runstate), runstate));
ctdb->runstate = runstate;
}
/* Convert arbitrary data to 4-byte boundary padded uint32 array */
uint32_t *ctdb_key_to_idkey(TALLOC_CTX *mem_ctx, TDB_DATA key)
{
uint32_t idkey_size, *k;
idkey_size = 1 + (key.dsize + sizeof(uint32_t)-1) / sizeof(uint32_t);
k = talloc_zero_array(mem_ctx, uint32_t, idkey_size);
if (k == NULL) {
return NULL;
}
k[0] = idkey_size;
memcpy(&k[1], key.dptr, key.dsize);
return k;
}

View File

@ -731,6 +731,8 @@ int ctdb_parse_address(struct ctdb_context *ctdb,
bool ctdb_same_ip(const ctdb_sock_addr *ip1, const ctdb_sock_addr *ip2);
bool ctdb_same_sockaddr(const ctdb_sock_addr *ip1, const ctdb_sock_addr *ip2);
uint32_t ctdb_hash(const TDB_DATA *key);
uint32_t *ctdb_key_to_idkey(TALLOC_CTX *mem_ctx, TDB_DATA key);
void ctdb_request_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
void ctdb_request_dmaster(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
void ctdb_request_message(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);