server: add a ctdb_set_single_public_ip() helper function
authorStefan Metzmacher <metze@samba.org>
Mon, 14 Dec 2009 18:33:35 +0000 (19:33 +0100)
committerStefan Metzmacher <metze@samba.org>
Wed, 20 Jan 2010 10:10:57 +0000 (11:10 +0100)
metze

include/ctdb_private.h
server/ctdb_takeover.c
server/ctdbd.c

index 68c61c9cd283b391d2ddfbfcfd89d582434c30fe..729837239d762b7131b6892b96b1d014736624a5 100644 (file)
@@ -1317,6 +1317,9 @@ int ctdb_sys_send_tcp(const ctdb_sock_addr *dest,
                      uint32_t seq, uint32_t ack, int rst);
 
 int ctdb_set_public_addresses(struct ctdb_context *ctdb, const char *alist);
+int ctdb_set_single_public_ip(struct ctdb_context *ctdb,
+                             const char *iface,
+                             const char *ip);
 int ctdb_set_event_script(struct ctdb_context *ctdb, const char *script);
 int ctdb_set_event_script_dir(struct ctdb_context *ctdb, const char *script_dir);
 int ctdb_set_notification_script(struct ctdb_context *ctdb, const char *script);
index 7357c0ca54184e17d9f95e4851d55d75a3cb9573..ae4cf4dba1a1fe46146a002533a99ebcf3e84706 100644 (file)
@@ -542,8 +542,28 @@ int ctdb_set_public_addresses(struct ctdb_context *ctdb, const char *alist)
        return 0;
 }
 
+int ctdb_set_single_public_ip(struct ctdb_context *ctdb,
+                             const char *iface,
+                             const char *ip)
+{
+       struct ctdb_vnn *svnn;
+       bool ok;
+
+       svnn = talloc_zero(ctdb, struct ctdb_vnn);
+       CTDB_NO_MEMORY(ctdb, svnn);
 
+       svnn->iface = talloc_strdup(svnn, iface);
+       CTDB_NO_MEMORY(ctdb, svnn->iface);
 
+       ok = parse_ip(ip, iface, 0, &svnn->public_address);
+       if (!ok) {
+               talloc_free(svnn);
+               return -1;
+       }
+
+       ctdb->single_ip_vnn = svnn;
+       return 0;
+}
 
 struct ctdb_public_ip_list {
        struct ctdb_public_ip_list *next;
index 9fb63d745d6ce91c7537a03c652ba5a14395ed04..2e707f243a5b92377f9867e4634985771392c324 100644 (file)
@@ -282,24 +282,14 @@ int main(int argc, const char *argv[])
        }
 
        if (options.single_public_ip) {
-               struct ctdb_vnn *svnn;
-
                if (options.public_interface == NULL) {
                        DEBUG(DEBUG_ALERT,("--single_public_ip used but --public_interface is not specified. You must specify the public interface when using single public ip. Exiting\n"));
                        exit(10);
                }
 
-               svnn = talloc_zero(ctdb, struct ctdb_vnn);
-               CTDB_NO_MEMORY(ctdb, svnn);
-
-               ctdb->single_ip_vnn = svnn;
-               svnn->iface = talloc_strdup(svnn, options.public_interface);
-               CTDB_NO_MEMORY(ctdb, svnn->iface);
-
-               if (parse_ip(options.single_public_ip, 
-                               svnn->iface,
-                               0,
-                               &svnn->public_address) == 0) {
+               ret = ctdb_set_single_public_ip(ctdb, options.public_interface,
+                                               options.single_public_ip);
+               if (ret != 0) {
                        DEBUG(DEBUG_ALERT,("Invalid --single-public-ip argument : %s . This is not a valid ip address. Exiting.\n", options.single_public_ip));
                        exit(10);
                }