Revert "change the hash function to use the much better Jenkins hash"
[metze/ctdb/wip.git] / common / ctdb_util.c
index 0b34f2adda427180ec1b640ba92d25c1763147bb..4acfa3f33e1badaa0b1108e07d6377f62436717a 100644 (file)
@@ -18,7 +18,7 @@
 */
 
 #include "includes.h"
-#include "lib/events/events.h"
+#include "lib/tevent/tevent.h"
 #include "lib/tdb/include/tdb.h"
 #include "system/network.h"
 #include "system/filesys.h"
@@ -123,46 +123,14 @@ static void *_idr_find_type(struct idr_context *idp, int id, const char *type, c
        return p;
 }
 
-
-/*
-  update a max latency number
- */
-void ctdb_latency(struct ctdb_db_context *ctdb_db, const char *name, double *latency, struct timeval t)
-{
-       double l = timeval_elapsed(&t);
-       if (l > *latency) {
-               *latency = l;
-       }
-
-       if (ctdb_db->ctdb->tunable.log_latency_ms !=0) {
-               if (l*1000 > ctdb_db->ctdb->tunable.log_latency_ms) {
-                       DEBUG(DEBUG_WARNING, ("High latency %fs for operation %s on database %s\n", l*1000000, name, ctdb_db->db_name));
-               }
-       }
-}
-
-/*
-  update a reclock latency number
- */
-void ctdb_reclock_latency(struct ctdb_context *ctdb, const char *name, double *latency, double l)
-{
-       if (l > *latency) {
-               *latency = l;
-       }
-
-       if (ctdb->tunable.reclock_latency_ms !=0) {
-               if (l*1000 > ctdb->tunable.reclock_latency_ms) {
-                       DEBUG(DEBUG_ERR, ("High RECLOCK latency %fs for operation %s\n", l, name));
-               }
-       }
-}
-
 uint32_t ctdb_reqid_new(struct ctdb_context *ctdb, void *state)
 {
-       uint32_t id;
-
-       id  = ctdb->idr_cnt++ & 0xFFFF;
-       id |= (idr_get_new(ctdb->idr, state, 0xFFFF)<<16);
+       int id = idr_get_new_above(ctdb->idr, state, ctdb->lastid+1, INT_MAX);
+       if (id < 0) {
+               DEBUG(DEBUG_NOTICE, ("Reqid wrap!\n"));
+               id = idr_get_new(ctdb->idr, state, INT_MAX);
+       }
+       ctdb->lastid = id;
        return id;
 }
 
@@ -170,7 +138,7 @@ void *_ctdb_reqid_find(struct ctdb_context *ctdb, uint32_t reqid, const char *ty
 {
        void *p;
 
-       p = _idr_find_type(ctdb->idr, (reqid>>16)&0xFFFF, type, location);
+       p = _idr_find_type(ctdb->idr, reqid, type, location);
        if (p == NULL) {
                DEBUG(DEBUG_WARNING, ("Could not find idr:%u\n",reqid));
        }
@@ -183,7 +151,7 @@ void ctdb_reqid_remove(struct ctdb_context *ctdb, uint32_t reqid)
 {
        int ret;
 
-       ret = idr_remove(ctdb->idr, (reqid>>16)&0xFFFF);
+       ret = idr_remove(ctdb->idr, reqid);
        if (ret != 0) {
                DEBUG(DEBUG_ERR, ("Removing idr that does not exist\n"));
        }
@@ -339,6 +307,18 @@ void ctdb_high_priority(struct ctdb_context *ctdb)
        }
 }
 
+/*
+  make ourselves slightly nicer: eg. a ctdb child.
+ */
+void ctdb_reduce_priority(struct ctdb_context *ctdb)
+{
+       errno = 0;
+       if (nice(10) == -1 && errno != 0) {
+               DEBUG(DEBUG_WARNING,("Unable to lower priority: %s\n",
+                                    strerror(errno)));
+       }
+}
+
 void set_nonblocking(int fd)
 {
        unsigned v;
@@ -367,7 +347,7 @@ bool parse_ipv4(const char *s, unsigned port, struct sockaddr_in *sin)
        return true;
 }
 
-static bool parse_ipv6(const char *s, const char *iface, unsigned port, ctdb_sock_addr *saddr)
+static bool parse_ipv6(const char *s, const char *ifaces, unsigned port, ctdb_sock_addr *saddr)
 {
        saddr->ip6.sin6_family   = AF_INET6;
        saddr->ip6.sin6_port     = htons(port);
@@ -379,8 +359,14 @@ static bool parse_ipv6(const char *s, const char *iface, unsigned port, ctdb_soc
                return false;
        }
 
-       if (iface && IN6_IS_ADDR_LINKLOCAL(&saddr->ip6.sin6_addr)) {
-               saddr->ip6.sin6_scope_id = if_nametoindex(iface);
+       if (ifaces && IN6_IS_ADDR_LINKLOCAL(&saddr->ip6.sin6_addr)) {
+               if (strchr(ifaces, ',')) {
+                       DEBUG(DEBUG_ERR, (__location__ " Link local address %s "
+                                         "is specified for multiple ifaces %s\n",
+                                         s, ifaces));
+                       return false;
+               }
+               saddr->ip6.sin6_scope_id = if_nametoindex(ifaces);
        }
 
        return true;
@@ -430,7 +416,7 @@ bool parse_ip_port(const char *addr, ctdb_sock_addr *saddr)
 /*
   parse an ip
  */
-bool parse_ip(const char *addr, const char *iface, unsigned port, ctdb_sock_addr *saddr)
+bool parse_ip(const char *addr, const char *ifaces, unsigned port, ctdb_sock_addr *saddr)
 {
        char *p;
        bool ret;
@@ -440,7 +426,7 @@ bool parse_ip(const char *addr, const char *iface, unsigned port, ctdb_sock_addr
        if (p == NULL) {
                ret = parse_ipv4(addr, port, &saddr->ip);
        } else {
-               ret = parse_ipv6(addr, iface, port, saddr);
+               ret = parse_ipv6(addr, ifaces, port, saddr);
        }
 
        return ret;
@@ -449,7 +435,7 @@ bool parse_ip(const char *addr, const char *iface, unsigned port, ctdb_sock_addr
 /*
   parse a ip/mask pair
  */
-bool parse_ip_mask(const char *str, const char *iface, ctdb_sock_addr *addr, unsigned *mask)
+bool parse_ip_mask(const char *str, const char *ifaces, ctdb_sock_addr *addr, unsigned *mask)
 {
        TALLOC_CTX *tmp_ctx = talloc_new(NULL);
        char *s, *p;
@@ -482,7 +468,7 @@ bool parse_ip_mask(const char *str, const char *iface, ctdb_sock_addr *addr, uns
 
 
        /* now is this a ipv4 or ipv6 address ?*/
-       ret = parse_ip(s, iface, 0, addr);
+       ret = parse_ip(s, ifaces, 0, addr);
 
        talloc_free(tmp_ctx);
        return ret;
@@ -653,6 +639,8 @@ void ctdb_lockdown_memory(struct ctdb_context *ctdb)
 }
 
 const char *ctdb_eventscript_call_names[] = {
+       "init",
+       "setup",
        "startup",
        "startrecovery",
        "recovered",
@@ -662,5 +650,7 @@ const char *ctdb_eventscript_call_names[] = {
        "monitor",
        "status",
        "shutdown",
-       "reload"
+       "reload",
+       "updateip",
+       "ipreallocated"
 };