Author: tridge Date: 2007-08-08 03:18:51 +0000 (Wed, 08 Aug 2007) New Revision: 24274
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=24274 Log: - merge from ctdb bzr tree - use ctdb_attach() instead of ctdb_db_handle() - make ctdb_attach() return an existing db handle if it exists Modified: branches/SAMBA_4_0/source/cluster/ctdb/client/ctdb_client.c branches/SAMBA_4_0/source/cluster/ctdb/common/cmdline.c branches/SAMBA_4_0/source/cluster/ctdb/common/ctdb_util.c branches/SAMBA_4_0/source/cluster/ctdb/configure.ac branches/SAMBA_4_0/source/cluster/ctdb/include/ctdb.h branches/SAMBA_4_0/source/cluster/ctdb/include/ctdb_private.h branches/SAMBA_4_0/source/cluster/ctdb/opendb_ctdb.c branches/SAMBA_4_0/source/cluster/ctdb/packaging/RPM/ctdb.spec Changeset: Modified: branches/SAMBA_4_0/source/cluster/ctdb/client/ctdb_client.c =================================================================== --- branches/SAMBA_4_0/source/cluster/ctdb/client/ctdb_client.c 2007-08-08 02:41:12 UTC (rev 24273) +++ branches/SAMBA_4_0/source/cluster/ctdb/client/ctdb_client.c 2007-08-08 03:18:51 UTC (rev 24274) @@ -1432,6 +1432,11 @@ int ret; int32_t res; + ctdb_db = ctdb_db_handle(ctdb, name); + if (ctdb_db) { + return ctdb_db; + } + ctdb_db = talloc_zero(ctdb, struct ctdb_db_context); CTDB_NO_MEMORY_NULL(ctdb, ctdb_db); @@ -2095,6 +2100,59 @@ /* + kill a tcp connection + */ +int ctdb_ctrl_killtcp(struct ctdb_context *ctdb, + struct timeval timeout, + uint32_t destnode, + struct ctdb_control_killtcp *killtcp) +{ + TDB_DATA data; + int32_t res; + int ret; + + data.dsize = sizeof(struct ctdb_control_killtcp); + data.dptr = (unsigned char *)killtcp; + + ret = ctdb_control(ctdb, destnode, 0, CTDB_CONTROL_KILL_TCP, 0, data, NULL, + NULL, &res, &timeout, NULL); + if (ret != 0 || res != 0) { + DEBUG(0,(__location__ " ctdb_control for killtcp failed\n")); + return -1; + } + + return 0; +} + +/* + get a list of all tcp tickles that a node knows about for a particular vnn + */ +int ctdb_ctrl_get_tcp_tickles(struct ctdb_context *ctdb, + struct timeval timeout, uint32_t destnode, + TALLOC_CTX *mem_ctx, uint32_t vnn, + struct ctdb_control_tcp_tickle_list **list) +{ + int ret; + TDB_DATA data, outdata; + int32_t status; + + data.dptr = (uint8_t*)&vnn; + data.dsize = sizeof(vnn); + + ret = ctdb_control(ctdb, destnode, 0, + CTDB_CONTROL_GET_TCP_TICKLE_LIST, 0, data, + mem_ctx, &outdata, &status, NULL, NULL); + if (ret != 0) { + DEBUG(0,(__location__ " ctdb_control for get tcp tickles failed\n")); + return -1; + } + + *list = (struct ctdb_control_tcp_tickle_list *)outdata.dptr; + + return status; +} + +/* initialise the ctdb daemon for client applications NOTE: In current code the daemon does not fork. This is for testing purposes only @@ -2109,6 +2167,8 @@ ctdb->idr = idr_init(ctdb); CTDB_NO_MEMORY_NULL(ctdb, ctdb->idr); + ctdb_set_socketname(ctdb, CTDB_PATH); + return ctdb; } Modified: branches/SAMBA_4_0/source/cluster/ctdb/common/cmdline.c =================================================================== --- branches/SAMBA_4_0/source/cluster/ctdb/common/cmdline.c 2007-08-08 02:41:12 UTC (rev 24273) +++ branches/SAMBA_4_0/source/cluster/ctdb/common/cmdline.c 2007-08-08 03:18:51 UTC (rev 24274) @@ -102,20 +102,20 @@ /* initialise ctdb */ ctdb = ctdb_init(ev); if (ctdb == NULL) { - printf("Failed to init ctdb\n"); + fprintf(stderr, "Failed to init ctdb\n"); exit(1); } /* tell ctdb the socket address */ ret = ctdb_set_socketname(ctdb, ctdb_cmdline.socketname); if (ret == -1) { - printf("ctdb_set_socketname failed - %s\n", ctdb_errstr(ctdb)); + fprintf(stderr, "ctdb_set_socketname failed - %s\n", ctdb_errstr(ctdb)); exit(1); } ret = ctdb_socket_connect(ctdb); if (ret != 0) { - DEBUG(0,(__location__ " Failed to connect to daemon\n")); + fprintf(stderr, __location__ " Failed to connect to daemon\n"); talloc_free(ctdb); return NULL; } Modified: branches/SAMBA_4_0/source/cluster/ctdb/common/ctdb_util.c =================================================================== --- branches/SAMBA_4_0/source/cluster/ctdb/common/ctdb_util.c 2007-08-08 02:41:12 UTC (rev 24273) +++ branches/SAMBA_4_0/source/cluster/ctdb/common/ctdb_util.c 2007-08-08 03:18:51 UTC (rev 24274) @@ -192,24 +192,46 @@ /* if possible, make this task real time */ -void ctdb_set_realtime(bool enable) +void ctdb_set_scheduler(struct ctdb_context *ctdb) { -#if HAVE_SCHED_SETSCHEDULER +#if HAVE_SCHED_SETSCHEDULER struct sched_param p; - p.__sched_priority = 1; + if (ctdb->saved_scheduler_param == NULL) { + ctdb->saved_scheduler_param = talloc_size(ctdb, sizeof(p)); + } + + if (sched_getparam(0, (struct sched_param *)ctdb->saved_scheduler_param) == -1) { + DEBUG(0,("Unable to get old scheduler params\n")); + return; + } - if (enable) { - if (sched_setscheduler(getpid(), SCHED_FIFO, &p) == -1) { - DEBUG(0,("Unable to set scheduler to SCHED_FIFO (%s)\n", strerror(errno))); - } else { - DEBUG(0,("Set scheduler to SCHED_FIFO\n")); - } + p = *(struct sched_param *)ctdb->saved_scheduler_param; + p.sched_priority = 1; + + if (sched_setscheduler(0, SCHED_FIFO, &p) == -1) { + DEBUG(0,("Unable to set scheduler to SCHED_FIFO (%s)\n", + strerror(errno))); } else { - sched_setscheduler(getpid(), SCHED_OTHER, &p); + DEBUG(0,("Set scheduler to SCHED_FIFO\n")); } #endif } +/* + restore previous scheduler parameters + */ +void ctdb_restore_scheduler(struct ctdb_context *ctdb) +{ +#if HAVE_SCHED_SETSCHEDULER + if (ctdb->saved_scheduler_param == NULL) { + ctdb_fatal(ctdb, "No saved scheduler parameters\n"); + } + if (sched_setscheduler(0, SCHED_OTHER, (struct sched_param *)ctdb->saved_scheduler_param) == -1) { + ctdb_fatal(ctdb, "Unable to restore old scheduler parameters\n"); + } +#endif +} + void set_nonblocking(int fd) { unsigned v; Modified: branches/SAMBA_4_0/source/cluster/ctdb/configure.ac =================================================================== --- branches/SAMBA_4_0/source/cluster/ctdb/configure.ac 2007-08-08 02:41:12 UTC (rev 24273) +++ branches/SAMBA_4_0/source/cluster/ctdb/configure.ac 2007-08-08 03:18:51 UTC (rev 24274) @@ -14,6 +14,23 @@ AC_INIT(ctdb.h) AC_CONFIG_SRCDIR([server/ctdbd.c]) +case `uname` in + Linux*) + CTDB_SYSTEM_OBJ=common/system_linux.o + CTDB_SCSI_IO=bin/scsi_io + CTDB_PCAP_LDFLAGS= + ;; + AIX*) + CTDB_SYSTEM_OBJ=common/system_aix.o + CTDB_SCSI_IO= + CTDB_PCAP_LDFLAGS=-lpcap + ;; + *) + echo unknown system cant configure + exit + ;; +esac + AC_LIBREPLACE_ALL_CHECKS if test "$ac_cv_prog_gcc" = yes; then @@ -44,5 +61,8 @@ fi AC_SUBST(EXTRA_OBJ) +AC_SUBST(CTDB_SYSTEM_OBJ) +AC_SUBST(CTDB_SCSI_IO) +AC_SUBST(CTDB_PCAP_LDFLAGS) AC_OUTPUT(Makefile) Modified: branches/SAMBA_4_0/source/cluster/ctdb/include/ctdb.h =================================================================== --- branches/SAMBA_4_0/source/cluster/ctdb/include/ctdb.h 2007-08-08 02:41:12 UTC (rev 24273) +++ branches/SAMBA_4_0/source/cluster/ctdb/include/ctdb.h 2007-08-08 03:18:51 UTC (rev 24274) @@ -367,4 +367,6 @@ uint32_t destnode, uint32_t set, uint32_t clear); +int ctdb_socket_connect(struct ctdb_context *ctdb); + #endif Modified: branches/SAMBA_4_0/source/cluster/ctdb/include/ctdb_private.h =================================================================== --- branches/SAMBA_4_0/source/cluster/ctdb/include/ctdb_private.h 2007-08-08 02:41:12 UTC (rev 24273) +++ branches/SAMBA_4_0/source/cluster/ctdb/include/ctdb_private.h 2007-08-08 03:18:51 UTC (rev 24274) @@ -37,6 +37,35 @@ #define CTDB_NULL_FUNC 0xFF000001 #define CTDB_FETCH_FUNC 0xFF000002 +/* + a tcp connection description + */ +struct ctdb_tcp_connection { + struct sockaddr_in saddr; + struct sockaddr_in daddr; +}; + +/* the wire representation for a tcp tickle array */ +struct ctdb_tcp_wire_array { + uint32_t num; + struct ctdb_tcp_connection connections[1]; +}; + +/* the list of tcp tickles used by get/set tcp tickle list */ +struct ctdb_control_tcp_tickle_list { + uint32_t vnn; + struct ctdb_tcp_wire_array tickles; +}; + +/* + array of tcp connections + */ +struct ctdb_tcp_array { + uint32_t num; + struct ctdb_tcp_connection *connections; +}; + + /* all tunable variables go in here */ struct ctdb_tunable { uint32_t max_redirect_count; @@ -51,6 +80,7 @@ uint32_t election_timeout; uint32_t takeover_timeout; uint32_t monitor_interval; + uint32_t tickle_update_interval; uint32_t script_timeout; uint32_t recovery_grace_period; uint32_t recovery_ban_period; @@ -139,6 +169,13 @@ /* the node number that has taken over this nodes public address, if any. If not taken over, then set to -1 */ int32_t takeover_vnn; + + /* List of clients to tickle for this public address */ + struct ctdb_tcp_array *tcp_array; + + /* whether we need to update the other nodes with changes to our list + of connected clients */ + bool tcp_update_needed; }; /* @@ -274,6 +311,7 @@ uint32_t recovery_mode; uint32_t monitoring_mode; TALLOC_CTX *monitor_context; + TALLOC_CTX *tickle_update_context; struct ctdb_tunable tunable; enum ctdb_freeze_mode freeze_mode; struct ctdb_freeze_handle *freeze_handle; @@ -305,8 +343,10 @@ uint32_t recovery_master; struct ctdb_call_state *pending_calls; struct ctdb_takeover takeover; - struct ctdb_tcp_list *tcp_list; struct ctdb_client_ip *client_ip_list; + bool do_setsched; + void *saved_scheduler_param; + struct ctdb_kill_tcp *killtcp; }; struct ctdb_db_context { @@ -406,6 +446,9 @@ CTDB_CONTROL_GET_PUBLIC_IPS = 51, CTDB_CONTROL_MODIFY_FLAGS = 52, CTDB_CONTROL_GET_ALL_TUNABLES = 53, + CTDB_CONTROL_KILL_TCP = 54, + CTDB_CONTROL_GET_TCP_TICKLE_LIST = 55, + CTDB_CONTROL_SET_TCP_TICKLE_LIST = 56, }; /* @@ -442,6 +485,14 @@ }; /* + struct for kill_tcp control + */ +struct ctdb_control_killtcp { + struct sockaddr_in src; + struct sockaddr_in dst; +}; + +/* struct for tcp_add and tcp_remove controls */ struct ctdb_control_tcp_vnn { @@ -931,6 +982,7 @@ void ctdb_stop_monitoring(struct ctdb_context *ctdb); void ctdb_start_monitoring(struct ctdb_context *ctdb); +void ctdb_start_tcp_tickle_update(struct ctdb_context *ctdb); void ctdb_send_keepalive(struct ctdb_context *ctdb, uint32_t destnode); void ctdb_daemon_cancel_controls(struct ctdb_context *ctdb, struct ctdb_node *node); @@ -947,7 +999,8 @@ uint32_t destnode, uint32_t db_id, uint64_t rsn); int ctdb_ctrl_delete_low_rsn(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t db_id, uint64_t rsn); -void ctdb_set_realtime(bool enable); +void ctdb_set_scheduler(struct ctdb_context *ctdb); +void ctdb_restore_scheduler(struct ctdb_context *ctdb); int32_t ctdb_control_takeover_ip(struct ctdb_context *ctdb, struct ctdb_req_control *c, TDB_DATA indata, @@ -980,22 +1033,23 @@ /* from takeover/system.c */ int ctdb_sys_send_arp(const struct sockaddr_in *saddr, const char *iface); bool ctdb_sys_have_ip(const char *ip); -int ctdb_sys_send_tcp(const struct sockaddr_in *dest, +int ctdb_sys_send_tcp(int fd, + const struct sockaddr_in *dest, const struct sockaddr_in *src, uint32_t seq, uint32_t ack, int rst); -int ctdb_sys_kill_tcp(struct event_context *ev, - const struct sockaddr_in *dest, - const struct sockaddr_in *src); int ctdb_set_public_addresses(struct ctdb_context *ctdb, const char *alist); int ctdb_set_event_script(struct ctdb_context *ctdb, const char *script); int ctdb_takeover_run(struct ctdb_context *ctdb, struct ctdb_node_map *nodemap); int32_t ctdb_control_tcp_client(struct ctdb_context *ctdb, uint32_t client_id, - uint32_t srcnode, TDB_DATA indata); + TDB_DATA indata); int32_t ctdb_control_tcp_add(struct ctdb_context *ctdb, TDB_DATA indata); int32_t ctdb_control_tcp_remove(struct ctdb_context *ctdb, TDB_DATA indata); int32_t ctdb_control_startup(struct ctdb_context *ctdb, uint32_t vnn); +int32_t ctdb_control_kill_tcp(struct ctdb_context *ctdb, TDB_DATA indata); +int32_t ctdb_control_get_tcp_tickle_list(struct ctdb_context *ctdb, TDB_DATA indata, TDB_DATA *outdata); +int32_t ctdb_control_set_tcp_tickle_list(struct ctdb_context *ctdb, TDB_DATA indata); void ctdb_takeover_client_destructor_hook(struct ctdb_client *client); int ctdb_event_script(struct ctdb_context *ctdb, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3); @@ -1032,4 +1086,22 @@ bool parse_ip_port(const char *s, struct sockaddr_in *ip); +int ctdb_sys_open_capture_socket(const char *iface, void **private_data); +int ctdb_sys_close_capture_socket(void *private_data); +int ctdb_sys_open_sending_socket(void); +int ctdb_sys_read_tcp_packet(int s, void *private_data, struct sockaddr_in *src, struct sockaddr_in *dst, + uint32_t *ack_seq, uint32_t *seq); + +int ctdb_ctrl_killtcp(struct ctdb_context *ctdb, + struct timeval timeout, + uint32_t destnode, + struct ctdb_control_killtcp *killtcp); + +int ctdb_ctrl_get_tcp_tickles(struct ctdb_context *ctdb, + struct timeval timeout, + uint32_t destnode, + TALLOC_CTX *mem_ctx, + uint32_t vnn, + struct ctdb_control_tcp_tickle_list **list); + #endif Modified: branches/SAMBA_4_0/source/cluster/ctdb/opendb_ctdb.c =================================================================== --- branches/SAMBA_4_0/source/cluster/ctdb/opendb_ctdb.c 2007-08-08 02:41:12 UTC (rev 24273) +++ branches/SAMBA_4_0/source/cluster/ctdb/opendb_ctdb.c 2007-08-08 03:18:51 UTC (rev 24274) @@ -86,7 +86,7 @@ } odb->ctdb = ctdb; - odb->ctdb_db = ctdb_db_handle(ctdb, "opendb"); + odb->ctdb_db = ctdb_attach(ctdb, "opendb"); if (!odb->ctdb_db) { DEBUG(0,("Failed to get attached ctdb db handle for opendb\n")); talloc_free(odb); Modified: branches/SAMBA_4_0/source/cluster/ctdb/packaging/RPM/ctdb.spec =================================================================== --- branches/SAMBA_4_0/source/cluster/ctdb/packaging/RPM/ctdb.spec 2007-08-08 02:41:12 UTC (rev 24273) +++ branches/SAMBA_4_0/source/cluster/ctdb/packaging/RPM/ctdb.spec 2007-08-08 03:18:51 UTC (rev 24274) @@ -5,7 +5,7 @@ Packager: Samba Team <[EMAIL PROTECTED]> Name: ctdb Version: 1.0 -Release: 7 +Release: 8 Epoch: 0 License: GNU GPL version 3 Group: System Environment/Daemons @@ -102,6 +102,7 @@ %{_sysconfdir}/ctdb/statd-callout %{_sbindir}/ctdbd %{_bindir}/ctdb +%{_bindir}/smnotify %{_bindir}/onnode.ssh %{_bindir}/onnode.rsh %{_bindir}/onnode