------------------------------------------------------------ revno: 349 revision-id: [EMAIL PROTECTED] parent: [EMAIL PROTECTED] committer: Andrew Tridgell <[EMAIL PROTECTED]> branch nick: tridge timestamp: Sat 2007-05-26 14:01:08 +1000 message: moved system specific ip code to system.c modified: common/ctdb_recoverd.c recoverd.c-20070503213540-bvxuyd9jm1f7ig90-1 include/ctdb_private.h ctdb_private.h-20061117234101-o3qt14umlg9en8z0-13 takeover/ctdb_takeover.c ctdb_takeover.c-20070525071636-a5n1ihghjtppy08r-2 takeover/system.c system.c-20070525071636-a5n1ihghjtppy08r-3 === modified file 'common/ctdb_recoverd.c' --- a/common/ctdb_recoverd.c 2007-05-25 14:05:30 +0000 +++ b/common/ctdb_recoverd.c 2007-05-26 04:01:08 +0000 @@ -666,9 +666,10 @@ return; } - /* wait for one second to collect all responses */ + /* wait for a few seconds to collect all responses */ timed_out = 0; - event_add_timed(ctdb->ev, mem_ctx, CONTROL_TIMEOUT(), timeout_func, ctdb); + event_add_timed(ctdb->ev, mem_ctx, timeval_current_ofs(3, 0), + timeout_func, ctdb); while (!timed_out) { event_loop_once(ctdb->ev); }
=== modified file 'include/ctdb_private.h' --- a/include/ctdb_private.h 2007-05-25 11:27:26 +0000 +++ b/include/ctdb_private.h 2007-05-26 04:01:08 +0000 @@ -894,6 +894,8 @@ /* from takeover/system.c */ int ctdb_sys_send_arp(const struct sockaddr_in *saddr, const char *iface); +int ctdb_sys_take_ip(const char *ip, const char *interface); +int ctdb_sys_release_ip(const char *ip, const char *interface); int ctdb_set_public_addresses(struct ctdb_context *ctdb, const char *alist); === modified file 'takeover/ctdb_takeover.c' --- a/takeover/ctdb_takeover.c 2007-05-25 14:21:07 +0000 +++ b/takeover/ctdb_takeover.c 2007-05-26 04:01:08 +0000 @@ -73,16 +73,16 @@ { int ret; struct sockaddr_in *sin = (struct sockaddr_in *)indata.dptr; - char *cmdstr; struct ctdb_takeover_arp *arp; - - cmdstr = talloc_asprintf(ctdb, "ip addr add %s/32 dev %s 2> /dev/null", - inet_ntoa(sin->sin_addr), ctdb->takeover.interface); - CTDB_NO_MEMORY(ctdb, cmdstr); - - DEBUG(0,("Taking over IP : %s\n", cmdstr)); - system(cmdstr); - talloc_free(cmdstr); + char *ip = inet_ntoa(sin->sin_addr); + + DEBUG(0,("Takover of IP %s on interface %s\n", ip, ctdb->takeover.interface)); + ret = ctdb_sys_take_ip(ip, ctdb->takeover.interface); + if (ret != 0) { + DEBUG(0,(__location__ " Failed to takeover IP %s on interface %s\n", + ip, ctdb->takeover.interface)); + return -1; + } if (!ctdb->takeover.last_ctx) { ctdb->takeover.last_ctx = talloc_new(ctdb); @@ -107,21 +107,22 @@ int32_t ctdb_control_release_ip(struct ctdb_context *ctdb, TDB_DATA indata) { struct sockaddr_in *sin = (struct sockaddr_in *)indata.dptr; - char *cmdstr; TDB_DATA data; char *ip = inet_ntoa(sin->sin_addr); + int ret; + + DEBUG(0,("Release of IP %s on interface %s\n", ip, ctdb->takeover.interface)); /* stop any previous arps */ talloc_free(ctdb->takeover.last_ctx); ctdb->takeover.last_ctx = NULL; - cmdstr = talloc_asprintf(ctdb, "ip addr del %s/32 dev %s 2> /dev/null", - ip, ctdb->takeover.interface); - - DEBUG(0,("Releasing IP : %s\n", cmdstr)); - system(cmdstr); - - talloc_free(cmdstr); + ret = ctdb_sys_release_ip(ip, ctdb->takeover.interface); + if (ret != 0) { + DEBUG(0,(__location__ " Failed to release IP %s on interface %s\n", + ip, ctdb->takeover.interface)); + return -1; + } /* send a message to all clients of this node telling them that the cluster has been reconfigured and they should === modified file 'takeover/system.c' --- a/takeover/system.c 2007-05-25 07:16:50 +0000 +++ b/takeover/system.c 2007-05-26 04:01:08 +0000 @@ -126,3 +126,35 @@ close(s); return 0; } + +/* + takeover an IP on an interface + */ +int ctdb_sys_take_ip(const char *ip, const char *interface) +{ + char *cmdstr; + cmdstr = talloc_asprintf(NULL, "/sbin/ip addr add %s/32 dev %s 2> /dev/null", + ip, interface); + if (cmdstr == NULL) { + return -1; + } + system(cmdstr); + talloc_free(cmdstr); + return 0; +} + +/* + release an IP on an interface + */ +int ctdb_sys_release_ip(const char *ip, const char *interface) +{ + char *cmdstr; + cmdstr = talloc_asprintf(NULL, "/sbin/ip addr del %s/32 dev %s 2> /dev/null", + ip, interface); + if (cmdstr == NULL) { + return -1; + } + system(cmdstr); + talloc_free(cmdstr); + return 0; +}