1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-25 23:21:54 +03:00
samba-mirror/ctdb/server/ctdb_serverids.c
Ronnie Sahlberg 6681da31df add an initial implementation of a service_id structure and three
controls to  register/unregister/check a server id.

a server id consists of TYPE:VNN:ID    where type is specific to the 
application.  VNN is the node where the serverid was registered and ID 
might be a node unique identifier such as a pid or similar.


Clients can register a server id for themself at the local ctdb daemon.
When a client dissappears   or when the domain socket connection for the 
client drops  then any and all server ids registered across that domain 
socket will also be automatically removed from the store.

clients can register as many server_ids as they want at the same time    
but each TYPE:VNN:ID must be globally unique.

Clients have the option of explicitely unregister a server id by using 
the UNREGISTER control.


Registration and unregistration can only be done by clients to the local 
daemon. clients can not register their server id to a remote node.


clients can check if a server id does exist on any ctdb node in the 
network by using the check control

(This used to be ctdb commit d44798feec26147c5cc05922cb2186f0ef0307be)
2007-08-24 15:53:41 +10:00

114 lines
3.1 KiB
C

/*
ctdb_control protocol code to manage server ids
Copyright (C) Ronnie Sahlberg 2007
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include "includes.h"
#include "../include/ctdb_private.h"
#include "../common/rb_tree.h"
#define SERVER_ID_KEY_SIZE 3
static uint32_t *get_server_id_key(struct ctdb_server_id *server_id)
{
static uint32_t key[SERVER_ID_KEY_SIZE];
key[0] = server_id->type;
key[1] = server_id->vnn;
key[2] = server_id->server_id;
return &key[0];
}
/* add a server_id to the tree.
if we had already 'data' in the tree then this is a duplicate and we can
just talloc_free the structure in parm and leave data in the tree.
othervise if this is a new node we return parm and that is inserted
into the tree.
*/
static void *add_server_id_callback(void *parm, void *data)
{
if (data) {
talloc_free(parm);
return data;
}
return parm;
}
/*
register a server id
a serverid that is registered with ctdb will be automatically unregistered
once the client domain socket dissappears.
*/
int32_t ctdb_control_register_server_id(struct ctdb_context *ctdb,
uint32_t client_id,
TDB_DATA indata)
{
struct ctdb_server_id *server_id;
struct ctdb_client *client = ctdb_reqid_find(ctdb, client_id, struct ctdb_client);
if (client == NULL) {
DEBUG(0,(__location__ " Could not find client parent structure. You can not send this control to a remote node\n"));
return 1;
}
/* hang the server_id structure off client before storing it in the
tree so that is will be automatically destroyed when client
is destroyed.
when the structure is free'd it will be automatically
removed from the tree
*/
server_id = talloc_memdup(client, indata.dptr, indata.dsize);
CTDB_NO_MEMORY(ctdb, server_id);
trbt_insertarray32_callback(ctdb->server_ids, SERVER_ID_KEY_SIZE,
get_server_id_key(server_id),
add_server_id_callback, server_id);
return 0;
}
/*
check whether a server id exists
*/
int32_t ctdb_control_check_server_id(struct ctdb_context *ctdb,
TDB_DATA indata)
{
struct ctdb_server_id *server_id = (struct ctdb_server_id *)indata.dptr;
return (int32_t)trbt_lookuparray32(ctdb->server_ids,
SERVER_ID_KEY_SIZE,
get_server_id_key(server_id));
}
/*
unregisters a server id
*/
int32_t ctdb_control_unregister_server_id(struct ctdb_context *ctdb,
TDB_DATA indata)
{
struct ctdb_server_id *server_id = (struct ctdb_server_id *)indata.dptr;
talloc_free(trbt_lookuparray32(ctdb->server_ids,
SERVER_ID_KEY_SIZE,
get_server_id_key(server_id)));
return 0;
}