link ctdb with libctdb and connect to the daemon both the old way and by using libctdb
authorRonnie Sahlberg <ronniesahlberg@gmail.com>
Wed, 2 Jun 2010 00:37:00 +0000 (10:37 +1000)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Wed, 2 Jun 2010 00:37:00 +0000 (10:37 +1000)
update the function "control_pnn()" to use libctdb to ask the daemon for the pnn

Makefile.in
tools/ctdb.c

index b72e90eecc755f2fde890911dce0ebfad6d33b55..dd7864ea5230a40a64e4d79dfd1d62f7b4077da6 100755 (executable)
@@ -118,9 +118,9 @@ bin/scsi_io: $(CTDB_CLIENT_OBJ) utils/scsi_io/scsi_io.o
        @echo Linking $@
        @$(CC) $(CFLAGS) -o $@ utils/scsi_io/scsi_io.o $(CTDB_CLIENT_OBJ) $(LIB_FLAGS)
 
-bin/ctdb: $(CTDB_CLIENT_OBJ) tools/ctdb.o tools/ctdb_vacuum.o
+bin/ctdb: $(CTDB_CLIENT_OBJ) tools/ctdb.o tools/ctdb_vacuum.o libctdb/libctdb.a
        @echo Linking $@
-       @$(CC) $(CFLAGS) -o $@ tools/ctdb.o tools/ctdb_vacuum.o $(CTDB_CLIENT_OBJ) $(LIB_FLAGS)
+       @$(CC) $(CFLAGS) -o $@ tools/ctdb.o tools/ctdb_vacuum.o $(CTDB_CLIENT_OBJ) $(LIB_FLAGS) libctdb/libctdb.a
 
 bin/smnotify: utils/smnotify/gen_xdr.o utils/smnotify/gen_smnotify.o utils/smnotify/smnotify.o $(POPT_OBJ)
        @echo Linking $@
index 3fad1e1639fb04402e654d3a78c492ad3eaa2248..69908513e3312c1bf2f59ce8b2b5e9cea653dc2f 100644 (file)
@@ -26,6 +26,7 @@
 #include "system/locale.h"
 #include "popt.h"
 #include "cmdline.h"
+#include "../include/ctdb.h"
 #include "../include/ctdb_client.h"
 #include "../include/ctdb_private.h"
 #include "../common/rb_tree.h"
@@ -35,6 +36,8 @@
 #define ERR_NONODE     21      /* node does not exist */
 #define ERR_DISNODE    22      /* node is disconnected */
 
+struct ctdb_connection *ctdb_connection;
+
 static void usage(void);
 
 static struct {
@@ -365,11 +368,12 @@ static int control_uptime(struct ctdb_context *ctdb, int argc, const char **argv
  */
 static int control_pnn(struct ctdb_context *ctdb, int argc, const char **argv)
 {
-       int mypnn;
+       uint32_t mypnn;
+       int ret;
 
-       mypnn = ctdb_ctrl_getpnn(ctdb, TIMELIMIT(), options.pnn);
-       if (mypnn == -1) {
-               DEBUG(DEBUG_ERR, ("Unable to get pnn from local node."));
+       ret = ctdb_getpnn(ctdb_connection, options.pnn, &mypnn);
+       if (ret != 0) {
+               DEBUG(DEBUG_ERR, ("Unable to get pnn from node."));
                return -1;
        }
 
@@ -4536,6 +4540,7 @@ int main(int argc, const char *argv[])
        for (i=0;i<ARRAY_SIZE(ctdb_commands);i++) {
                if (strcmp(control, ctdb_commands[i].name) == 0) {
                        int j;
+                       const char *socket_name;
 
                        if (ctdb_commands[i].without_daemon == true) {
                                close(2);
@@ -4544,6 +4549,14 @@ int main(int argc, const char *argv[])
                        /* initialise ctdb */
                        ctdb = ctdb_cmdline_client(ev);
 
+                       /* initialize a libctdb connection as well */
+                       socket_name = ctdb_get_socketname(ctdb);
+                       ctdb_connection = ctdb_connect(socket_name);
+                       if (ctdb_connection == NULL) {
+                               fprintf(stderr, "Failed to connect to daemon from libctdb\n");
+                               exit(1);
+                       }                               
+                       
                        if (ctdb_commands[i].without_daemon == false) {
                                if (ctdb == NULL) {
                                        DEBUG(DEBUG_ERR, ("Failed to init ctdb\n"));