Move some common functions to common/ctdb_ltdb.c
authorMartin Schwenke <martin@meltin.net>
Fri, 11 Nov 2011 02:56:46 +0000 (13:56 +1100)
committerMartin Schwenke <martin@meltin.net>
Fri, 11 Nov 2011 03:31:50 +0000 (14:31 +1100)
Move identical copies of ctdb_null_func(), ctdb_fetch_func(),
ctdb_fetch_with_header_func() from ctdb_client.c and
ctdb_ltdb_server.c to somewhere common.

This is in the context of wanting to run CCAN-style tests where most
of the ctdbd code is just included in the test program.

Signed-off-by: Martin Schwenke <martin@meltin.net>
client/ctdb_client.c
common/ctdb_ltdb.c
include/ctdb_private.h
server/ctdb_ltdb_server.c

index 870edaa58279e50958bee73848064a409c03e955..9705c28858f14c18b958f0af9a316c31a12c512c 100644 (file)
@@ -1883,44 +1883,6 @@ int ctdb_statistics_reset(struct ctdb_context *ctdb, uint32_t destnode)
        return 0;
 }
 
-/*
-  this is the dummy null procedure that all databases support
-*/
-static int ctdb_null_func(struct ctdb_call_info *call)
-{
-       return 0;
-}
-
-/*
-  this is a plain fetch procedure that all databases support
-*/
-static int ctdb_fetch_func(struct ctdb_call_info *call)
-{
-       call->reply_data = &call->record_data;
-       return 0;
-}
-
-/*
-  this is a plain fetch procedure that all databases support
-  this returns the full record including the ltdb header
-*/
-static int ctdb_fetch_with_header_func(struct ctdb_call_info *call)
-{
-       call->reply_data = talloc(call, TDB_DATA);
-       if (call->reply_data == NULL) {
-               return -1;
-       }
-       call->reply_data->dsize = sizeof(struct ctdb_ltdb_header) + call->record_data.dsize;
-       call->reply_data->dptr  = talloc_size(call->reply_data, call->reply_data->dsize);
-       if (call->reply_data->dptr == NULL) {
-               return -1;
-       }
-       memcpy(call->reply_data->dptr, call->header, sizeof(struct ctdb_ltdb_header));
-       memcpy(&call->reply_data->dptr[sizeof(struct ctdb_ltdb_header)], call->record_data.dptr, call->record_data.dsize);
-
-       return 0;
-}
-
 /*
   attach to a specific database - client call
 */
index e4662ac37fd294e481ca35b0f3e83a094a88e37b..565a89986b88415a0031134d226e4c2585a5e3bf 100644 (file)
@@ -295,4 +295,41 @@ void ctdb_trackingdb_traverse(struct ctdb_context *ctdb, TDB_DATA data, ctdb_tra
        }
 }
 
+/*
+  this is the dummy null procedure that all databases support
+*/
+int ctdb_null_func(struct ctdb_call_info *call)
+{
+       return 0;
+}
+
+/*
+  this is a plain fetch procedure that all databases support
+*/
+int ctdb_fetch_func(struct ctdb_call_info *call)
+{
+       call->reply_data = &call->record_data;
+       return 0;
+}
+
+/*
+  this is a plain fetch procedure that all databases support
+  this returns the full record including the ltdb header
+*/
+int ctdb_fetch_with_header_func(struct ctdb_call_info *call)
+{
+       call->reply_data = talloc(call, TDB_DATA);
+       if (call->reply_data == NULL) {
+               return -1;
+       }
+       call->reply_data->dsize = sizeof(struct ctdb_ltdb_header) + call->record_data.dsize;
+       call->reply_data->dptr  = talloc_size(call->reply_data, call->reply_data->dsize);
+       if (call->reply_data->dptr == NULL) {
+               return -1;
+       }
+       memcpy(call->reply_data->dptr, call->header, sizeof(struct ctdb_ltdb_header));
+       memcpy(&call->reply_data->dptr[sizeof(struct ctdb_ltdb_header)], call->record_data.dptr, call->record_data.dsize);
+
+       return 0;
+}
 
index f1818b98dec7c8af44797d48dbec61bdf520fe5d..5fbe81806c010fc625f27f30d54b515d75e82b42 100644 (file)
@@ -1472,4 +1472,10 @@ int ctdb_add_revoke_deferred_call(struct ctdb_context *ctdb, struct ctdb_db_cont
 
 int ctdb_set_db_readonly(struct ctdb_context *ctdb, struct ctdb_db_context *ctdb_db);
 
+int ctdb_null_func(struct ctdb_call_info *call);
+
+int ctdb_fetch_func(struct ctdb_call_info *call);
+
+int ctdb_fetch_with_header_func(struct ctdb_call_info *call);
+
 #endif
index b1f29d77ec31bceef351d47e9893ec471af91ec3..8423388433e5d45723f3a612324cf5054d83fd9b 100644 (file)
 
 #define PERSISTENT_HEALTH_TDB "persistent_health.tdb"
 
-/*
-  this is the dummy null procedure that all databases support
-*/
-static int ctdb_null_func(struct ctdb_call_info *call)
-{
-       return 0;
-}
-
-/*
-  this is a plain fetch procedure that all databases support
-*/
-static int ctdb_fetch_func(struct ctdb_call_info *call)
-{
-       call->reply_data = &call->record_data;
-       return 0;
-}
-
-/*
-  this is a plain fetch procedure that all databases support
-  this returns the full record including the ltdb header
-*/
-static int ctdb_fetch_with_header_func(struct ctdb_call_info *call)
-{
-       call->reply_data = talloc(call, TDB_DATA);
-       if (call->reply_data == NULL) {
-               return -1;
-       }
-       call->reply_data->dsize = sizeof(struct ctdb_ltdb_header) + call->record_data.dsize;
-       call->reply_data->dptr  = talloc_size(call->reply_data, call->reply_data->dsize);
-       if (call->reply_data->dptr == NULL) {
-               return -1;
-       }
-       memcpy(call->reply_data->dptr, call->header, sizeof(struct ctdb_ltdb_header));
-       memcpy(&call->reply_data->dptr[sizeof(struct ctdb_ltdb_header)], call->record_data.dptr, call->record_data.dsize);
-
-       return 0;
-}
-
-
 /**
  * write a record to a normal database
  *