merge status code changes from samba4 ctdb
[vlendec/samba-autobuild/.git] / ctdb / include / ctdb_private.h
index b58d55d8ac1d1fdb226e4bf1d70206a97cb96019..977206f400cc781b1b830fa5fcfc0f5f446ddcd9 100644 (file)
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 
+#ifndef _CTDB_PRIVATE_H
+#define _CTDB_PRIVATE_H
+
+#include "ctdb.h"
 
 /*
   an installed ctdb remote call
@@ -55,6 +59,7 @@ struct ctdb_methods {
        int (*start)(struct ctdb_context *); /* start protocol processing */    
        int (*add_node)(struct ctdb_node *); /* setup a new node */     
        int (*queue_pkt)(struct ctdb_node *, uint8_t *data, uint32_t length);
+       void *(*allocate_pkt)(struct ctdb_context *, size_t );
 };
 
 /*
@@ -84,10 +89,11 @@ struct ctdb_context {
        struct ctdb_node **nodes; /* array of nodes in the cluster - indexed by vnn */
        struct ctdb_registered_call *calls; /* list of registered calls */
        char *err_msg;
-       struct tdb_context *ltdb;
+       struct tdb_wrap *ltdb;
        const struct ctdb_methods *methods; /* transport methods */
        const struct ctdb_upcalls *upcalls; /* transport upcalls */
        void *private; /* private to transport */
+       unsigned max_lacount;
 };
 
 #define CTDB_NO_MEMORY(ctdb, p) do { if (!(p)) { \
@@ -98,12 +104,20 @@ struct ctdb_context {
           ctdb_set_error(ctdb, "Out of memory at %s:%d", __FILE__, __LINE__); \
          return NULL; }} while (0)
 
+#define CTDB_NO_MEMORY_FATAL(ctdb, p) do { if (!(p)) { \
+          ctdb_fatal(ctdb, "Out of memory in " __location__ ); \
+         }} while (0)
+
 /* arbitrary maximum timeout for ctdb operations */
 #define CTDB_REQ_TIMEOUT 10
 
 /* max number of redirects before we ask the lmaster */
 #define CTDB_MAX_REDIRECT 2
 
+/* number of consecutive calls from the same node before we give them
+   the record */
+#define CTDB_DEFAULT_MAX_LACOUNT 7
+
 /*
   the extended header for records in the ltdb
 */
@@ -143,20 +157,21 @@ struct ctdb_req_call {
        uint32_t callid;
        uint32_t keylen;
        uint32_t calldatalen;
-       uint8_t data[0]; /* key[] followed by calldata[] */
+       uint8_t data[1]; /* key[] followed by calldata[] */
 };
 
 struct ctdb_reply_call {
        struct ctdb_req_header hdr;
+       uint32_t status;
        uint32_t datalen;
-       uint8_t  data[0];
+       uint8_t  data[1];
 };
 
 struct ctdb_reply_error {
        struct ctdb_req_header hdr;
        uint32_t status;
        uint32_t msglen;
-       uint8_t  msg[0];
+       uint8_t  msg[1];
 };
 
 struct ctdb_reply_redirect {
@@ -164,21 +179,40 @@ struct ctdb_reply_redirect {
        uint32_t dmaster;
 };
 
+struct ctdb_req_dmaster {
+       struct ctdb_req_header hdr;
+       uint32_t dmaster;
+       uint32_t keylen;
+       uint32_t datalen;
+       uint8_t  data[1];
+};
+
+struct ctdb_reply_dmaster {
+       struct ctdb_req_header hdr;
+       uint32_t datalen;
+       uint8_t  data[1];
+};
+
 /* internal prototypes */
-void ctdb_set_error(struct ctdb_context *ctdb, const char *fmt, ...);
+void ctdb_set_error(struct ctdb_context *ctdb, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
+void ctdb_fatal(struct ctdb_context *ctdb, const char *msg);
 bool ctdb_same_address(struct ctdb_address *a1, struct ctdb_address *a2);
 int ctdb_parse_address(struct ctdb_context *ctdb,
                       TALLOC_CTX *mem_ctx, const char *str,
                       struct ctdb_address *address);
-uint32_t ctdb_hash(TDB_DATA *key);
+uint32_t ctdb_hash(const TDB_DATA *key);
 void ctdb_request_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
+void ctdb_request_dmaster(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
+void ctdb_reply_dmaster(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
 void ctdb_reply_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
 void ctdb_reply_error(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
+void ctdb_reply_redirect(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
 
-uint32_t ctdb_lmaster(struct ctdb_context *ctdb, TDB_DATA key);
+uint32_t ctdb_lmaster(struct ctdb_context *ctdb, const TDB_DATA *key);
 int ctdb_ltdb_fetch(struct ctdb_context *ctdb, 
                    TDB_DATA key, struct ctdb_ltdb_header *header, TDB_DATA *data);
 int ctdb_ltdb_store(struct ctdb_context *ctdb, TDB_DATA key, 
                    struct ctdb_ltdb_header *header, TDB_DATA data);
 
 
+#endif