ReadOnly: Add helper functions to manipulate a TDB_DATA as a bitmap for nodes that...
authorRonnie Sahlberg <ronniesahlberg@gmail.com>
Wed, 20 Jul 2011 01:39:50 +0000 (11:39 +1000)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Tue, 23 Aug 2011 00:09:42 +0000 (10:09 +1000)
common/ctdb_ltdb.c
include/ctdb_private.h

index 0dc8711c7d82c111224e0d66f070f0c52a311d9e..bc17b47e6a892734e634fb39fd937e85ca66eca8 100644 (file)
@@ -2,6 +2,7 @@
    ctdb ltdb code
 
    Copyright (C) Andrew Tridgell  2006
+   Copyright (C) Ronnie sahlberg  2011
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -216,3 +217,48 @@ int ctdb_ltdb_delete(struct ctdb_db_context *ctdb_db, TDB_DATA key)
        }
        return 0;
 }
+
+int ctdb_trackingdb_add_pnn(struct ctdb_context *ctdb, TDB_DATA *data, uint32_t pnn)
+{
+       int byte_pos = pnn / 8;
+       int bit_mask   = 1 << (pnn % 8);
+
+       if (byte_pos + 1 > data->dsize) {
+               char *buf;
+
+               buf = malloc(byte_pos + 1);
+               memset(buf, 0, byte_pos + 1);
+               if (buf == NULL) {
+                       DEBUG(DEBUG_ERR, ("Out of memory when allocating buffer of %d bytes for trackingdb\n", byte_pos + 1));
+                       return -1;
+               }
+               if (data->dptr != NULL) {
+                       memcpy(buf, data->dptr, data->dsize);
+                       free(data->dptr);
+               }
+               data->dptr  = (uint8_t *)buf;
+               data->dsize = byte_pos + 1;
+       }
+
+       data->dptr[byte_pos] |= bit_mask;
+       return 0;
+}
+
+void ctdb_trackingdb_traverse(struct ctdb_context *ctdb, TDB_DATA data, ctdb_trackingdb_cb cb, void *private_data)
+{
+       int i;
+
+       for(i = 0; i < data.dsize; i++) {
+               int j;
+
+               for (j=0; j<8; j++) {
+                       int mask = 1<<j;
+
+                       if (data.dptr[i] & mask) {
+                               cb(ctdb, i * 8 + j, private_data);
+                       }
+               }
+       }
+}
+
+
index 37f8a7344ad1ede654aeecf58f82964f556b6794..833cdc95d3f4fececad961b1f3b923c589659214 100644 (file)
@@ -1443,5 +1443,10 @@ void ctdb_takeover_run_core(struct ctdb_context *ctdb,
                            struct ctdb_node_map *nodemap,
                            struct ctdb_public_ip_list **all_ips_p);
 
+int ctdb_trackingdb_add_pnn(struct ctdb_context *ctdb, TDB_DATA *data, uint32_t pnn);
+
+typedef void (*ctdb_trackingdb_cb)(struct ctdb_context *ctdb, uint32_t pnn, void *private_data);
+
+void ctdb_trackingdb_traverse(struct ctdb_context *ctdb, TDB_DATA data, ctdb_trackingdb_cb cb, void *private_data);
 
 #endif