mirror of
https://github.com/samba-team/samba.git
synced 2024-12-22 13:34:15 +03:00
moved system specific ip code to system.c
(This used to be ctdb commit 9de9e4ccda9665108baac12a8716b189d26340b1)
This commit is contained in:
parent
750ae1a35b
commit
cc4d8102cd
@ -666,9 +666,10 @@ static void force_election(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, uint3
|
||||
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);
|
||||
}
|
||||
|
@ -894,6 +894,8 @@ int ctdb_ctrl_release_ip(struct ctdb_context *ctdb, struct timeval timeout,
|
||||
|
||||
/* 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);
|
||||
|
||||
|
@ -73,16 +73,16 @@ int32_t ctdb_control_takeover_ip(struct ctdb_context *ctdb, TDB_DATA indata)
|
||||
{
|
||||
int ret;
|
||||
struct sockaddr_in *sin = (struct sockaddr_in *)indata.dptr;
|
||||
char *cmdstr;
|
||||
struct ctdb_takeover_arp *arp;
|
||||
char *ip = inet_ntoa(sin->sin_addr);
|
||||
|
||||
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);
|
||||
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_takeover_ip(struct ctdb_context *ctdb, TDB_DATA indata)
|
||||
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
|
||||
|
@ -126,3 +126,35 @@ int ctdb_sys_send_arp(const struct sockaddr_in *saddr, const char *iface)
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user