Cluster Project branch, master, updated. cluster-2.99.06-5-g7b2e7da

ccaulfield@sourceware.org ccaulfield@sourceware.org
Wed Jul 16 08:06:00 GMT 2008


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Cluster Project".

http://sources.redhat.com/git/gitweb.cgi?p=cluster.git;a=commitdiff;h=7b2e7daf60cd57c13e391372a835cf4b22146f1b

The branch, master has been updated
       via  7b2e7daf60cd57c13e391372a835cf4b22146f1b (commit)
      from  d33f543aefb4e99638e5bd5568b59bde8f865c1d (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 7b2e7daf60cd57c13e391372a835cf4b22146f1b
Author: Christine Caulfield <ccaulfie@redhat.com>
Date:   Wed Jul 16 09:03:58 2008 +0100

    [CCS] Fold ccs_test into ccs_tool and tidy
    
    Move all the code from ccs_test into ccs_tool and make it
    switch depending on argv[0]. Also add ccs_tool query that
    does full XPath queries on confdb.
    
    When build with LEGACY_CODE set ccs_tool will behave as it
    used to, talking to ccsd. Without that it will use the
    new confdb system and assume that ccsd is NOT used for
    distribution of cluster configurations.
    
    Signed-off-by: Christine Caulfield <ccaulfie@redhat.com>

-----------------------------------------------------------------------

Summary of changes:
 ccs/ccs_tool/Makefile     |   15 +-
 ccs/ccs_tool/ccs_tool.c   |  235 ++++++++++++++--
 ccs/ccs_tool/old_parser.c |  688 ---------------------------------------------
 ccs/ccs_tool/old_parser.h |   64 -----
 ccs/ccs_tool/upgrade.c    |  259 -----------------
 ccs/ccs_tool/upgrade.h    |    6 -
 6 files changed, 225 insertions(+), 1042 deletions(-)
 delete mode 100644 ccs/ccs_tool/old_parser.c
 delete mode 100644 ccs/ccs_tool/old_parser.h
 delete mode 100644 ccs/ccs_tool/upgrade.c
 delete mode 100644 ccs/ccs_tool/upgrade.h

diff --git a/ccs/ccs_tool/Makefile b/ccs/ccs_tool/Makefile
index f58f6cd..058fe02 100644
--- a/ccs/ccs_tool/Makefile
+++ b/ccs/ccs_tool/Makefile
@@ -12,19 +12,24 @@ include $(OBJDIR)/make/uninstall.mk
 
 OBJS=	ccs_tool.o \
 	update.o \
-	upgrade.o \
-	old_parser.o \
 	editconf.o
 
 CFLAGS += -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
 CFLAGS += -I${cmanincdir} `xml2-config --cflags`
-CFLAGS += -I$(S)/../libccscompat -I$(S)/../include
+CFLAGS += -I${ccslibdir} -I$(S)/../include
+CFLAGS += -I$(S)/../libccscompat
 CFLAGS += -I${incdir}
+ifdef LEGACY_CODE
+CFLAGS += -DLEGACY_CODE
+endif
 
-LDFLAGS += -L../libccscompat -lccscompat
 LDFLAGS += -L${cmanlibdir} -lcman
 LDFLAGS += `xml2-config --libs` -L${libdir}
-
+ifdef OLD_CCS_CODE
+LDFLAGS += -L../libccscompat -lccscompat
+else
+LDFLAGS += -L${ccslibdir} -lccs
+endif
 
 ${TARGET}: ${OBJS}
 	$(CC) -o $@ $^ $(LDFLAGS)
diff --git a/ccs/ccs_tool/ccs_tool.c b/ccs/ccs_tool/ccs_tool.c
index fea59c4..b63b576 100644
--- a/ccs/ccs_tool/ccs_tool.c
+++ b/ccs/ccs_tool/ccs_tool.c
@@ -2,22 +2,181 @@
 #include <stdlib.h>
 #include <getopt.h>
 #include <string.h>
+#include <errno.h>
 
 #include "copyright.cf"
 #include "update.h"
-#include "upgrade.h"
 #include "editconf.h"
+#ifdef LEGACY_CODE
+#include "libccscompat.h"
+#else
+#include "ccs.h"
+#endif
 
-static void print_usage(FILE *stream);
+static void tool_print_usage(FILE *stream);
 
 int globalverbose=0;
 
-int main(int argc, char *argv[])
+#ifdef LEGACY_CODE
+static void test_print_usage(FILE *stream);
+
+static int test_main(int argc, char *argv[]){
+  int desc=0;
+  int i=0;
+  int error = 0;
+  int force = 0, blocking = 0;
+  char *str=NULL;
+  char *cluster_name = NULL;
+
+  if(argc <= 1){
+    test_print_usage(stderr);
+    exit(EXIT_FAILURE);
+  }
+
+  for(i=1; i < argc; i++){
+    if(!strcmp(argv[i], "-h")){
+      test_print_usage(stdout);
+      exit(EXIT_SUCCESS);
+    }
+    if(!strcmp(argv[i], "-V")){
+      printf("%s %s (built %s %s)\n", argv[0], RELEASE_VERSION, __DATE__, __TIME__);
+      printf("%s\n", REDHAT_COPYRIGHT);
+      exit(EXIT_SUCCESS);
+    }
+  }
+
+  if(!strcmp(argv[1], "connect")){
+    for(i=2; i < argc; i++){
+      if(!strcmp(argv[i], "force")){
+	printf("Force is set.\n");
+	force = 1;
+      } else if(!strcmp(argv[i], "block")){
+	printf("Blocking is set.\n");
+	blocking = 1;
+      } else {
+	cluster_name = argv[i];
+	printf("Setting cluster name to %s\n", cluster_name);
+      }
+    }
+    if(blocking && !force){
+      fprintf(stderr, "Blocking can only be used with \"force\".\n");
+      exit(EXIT_FAILURE);
+    }
+    if(force){
+      desc = ccs_force_connect(cluster_name, blocking);
+    } else {
+      if(cluster_name){
+	fprintf(stderr, "A cluster name can only be specified when using 'force'.\n");
+	exit(EXIT_FAILURE);
+      }
+      desc = ccs_connect();
+    }
+    if(desc < 0){
+      fprintf(stderr, "ccs_connect failed: %s\n", strerror(-desc));
+      exit(EXIT_FAILURE);
+    } else {
+      printf("Connect successful.\n");
+      printf(" Connection descriptor = %d\n", desc);
+      ccs_disconnect(desc);
+    }
+  }
+  else if(!strcmp(argv[1], "ccs_disconnect")){
+    if(argc < 3){
+      fprintf(stderr, "Wrong number of arguments.\n");
+      exit(EXIT_FAILURE);
+    }
+    desc = ccs_connect();
+    if((error = ccs_disconnect(desc))){
+      fprintf(stderr, "ccs_ccs_disconnect failed: %s\n", strerror(-error));
+      exit(EXIT_FAILURE);
+    } else {
+      printf("Ccs_Disconnect successful.\n");
+    }
+  }
+  else if(!strcmp(argv[1], "get")){
+    if(argc < 4){
+      fprintf(stderr, "Wrong number of arguments.\n");
+      exit(EXIT_FAILURE);
+    }
+    desc = ccs_connect();
+    if((desc < 0) || (error = ccs_get(desc, argv[3], &str))){
+      fprintf(stderr, "ccs_get failed: %s\n", strerror(-error));
+      exit(EXIT_FAILURE);
+    } else {
+      printf("Get successful.\n");
+      printf(" Value = <%s>\n", str);
+      if(str)free(str);
+      ccs_disconnect(desc);
+    }
+  }
+  else {
+    fprintf(stderr, "Unknown command: %s\n", argv[1]);
+    exit(EXIT_FAILURE);
+  }
+
+  exit(EXIT_SUCCESS);
+}
+
+
+static void test_print_usage(FILE *stream){
+  fprintf(stream,
+	  "Usage:\n"
+	  "\n"
+	  "ccs_test [Options] <Command>\n"
+	  "\n"
+	  "Options:\n"
+	  "  -h                        Print usage.\n"
+	  "  -V                        Print version information.\n"
+	  "\n"
+	  "Commands:\n"
+	  "  connect <force> <block>   Connect to CCS and return connection descriptor.\n"
+	  "  ccs_disconnect <desc>     Disconnect from CCS.\n"
+	  "  get <desc> <request>      Get a value from CCS.\n"
+	  );
+}
+#else
+static int xpath_query(int argc, char **argv)
+{
+	int handle;
+	char *ret;
+	int i;
+
+	if (argc < 2) {
+		fprintf(stderr,
+			"Usage:\n"
+			"\n"
+			"ccs_tool query <xpath query>\n");
+		return 1;
+	}
+
+	/* Tell the library we want full XPath parsing */
+	fullxpath = 1;
+
+	handle = ccs_connect();
+
+	/* Process all the queries on the command-line */
+	for (i=1; i<argc; i++) {
+		if (!ccs_get(handle, argv[1], &ret)) {
+			printf("%s\n", ret);
+			free(ret);
+		}
+		else {
+			printf("Query failed: %s\n", strerror(errno));
+			ccs_disconnect(handle);
+			return -1;
+		}
+	}
+	ccs_disconnect(handle);
+	return 0;
+}
+#endif
+
+static int tool_main(int argc, char *argv[])
 {
   optind = 1;
 
   if (argc < 2 || !strcmp(argv[optind], "-h")) {
-      print_usage(stdout);
+      tool_print_usage(stdout);
       exit(EXIT_SUCCESS);
   }
   if (!strcmp(argv[optind], "-V")) {
@@ -33,9 +192,11 @@ int main(int argc, char *argv[])
       globalverbose=1;
     }
     if(!strcmp(argv[optind], "help")){
-      print_usage(stdout);
+      tool_print_usage(stdout);
       exit(EXIT_SUCCESS);
     }
+#ifdef LEGACY_CODE
+    /* Update is meaningless now */
     else if(!strcmp(argv[optind], "update")){
       if(optind+1 >= argc){
 	fprintf(stderr, "Too few arguments.\n"
@@ -48,18 +209,26 @@ int main(int argc, char *argv[])
       }
       printf("\nUpdate complete.\n");
     }
-    else if(!strcmp(argv[optind], "upgrade")){
-      if(optind+1 >= argc){
-	fprintf(stderr, "Too few arguments.\n"
-		"Try 'ccs_tool help' for help.\n");
-	exit(EXIT_FAILURE);
-      }
-      if(upgrade(argv[optind+1])){
-	fprintf(stderr, "\nFailed to upgrade CCS configuration information.\n");
-	exit(EXIT_FAILURE);
-      }
-    }
+    /* Do old ccs queries */
+    else if(!strcmp(argv[optind], "query")){
+	    char *new_argv[argc+2];
+	    int i;
+
+	    new_argv[0] = "ccs_test";
+	    new_argv[1] = "get";
+	    new_argv[2] = "0"; /* Dummy connection ID */
+	    for (i=2; i<argc; i++)
+		    new_argv[1+i] = argv[i];
 
+	    test_main(argc+1, new_argv);
+	    exit(EXIT_SUCCESS);
+    }
+#else
+    else if(!strcmp(argv[optind], "query")){
+	    xpath_query(argc-1, argv+1);
+	    exit(EXIT_SUCCESS);
+    }
+#endif
     else if(!strcmp(argv[optind], "addnode")){
 	    add_node(argc-1, argv+1);
 	    exit(EXIT_SUCCESS);
@@ -106,9 +275,9 @@ int main(int argc, char *argv[])
   exit(EXIT_SUCCESS);
 }
 
-static void print_usage(FILE *stream){
+static void tool_print_usage(FILE *stream){
   fprintf(stream,
-	  "Usage::\n"
+	  "Usage:\n"
 	  "  ccs_tool [options] <command>\n"
 	  "\n"
 	  "Options:\n"
@@ -118,8 +287,12 @@ static void print_usage(FILE *stream){
 	  "\n"
 	  "Commands:\n"
 	  "  help                Print this usage and exit.\n"
-	  "  update <xml file>   Tells ccsd to upgrade to new config file.\n"
-	  "  upgrade <location>  Upgrade old CCS format to new xml format.\n"
+#ifdef LEGACY_CODE
+	  "  update <xml file>   Tells ccsd to upgrade to new config file version.\n"
+	  "  query <ccs query>   Query the cluster configuration.\n"
+#else
+	  "  query <xpath query> Query the cluster configuration.\n"
+#endif
 	  "  addnode <node>      Add a node\n"
           "  delnode <node>      Delete a node\n"
           "  lsnode              List nodes\n"
@@ -130,3 +303,25 @@ static void print_usage(FILE *stream){
 	  "  addnodeids          Assign node ID numbers to all nodes\n"
 	  "\n");
 }
+
+
+int main(int argc, char *argv[])
+{
+#ifdef LEGACY_CODE
+	/* basename() can alter its argument */
+	char *name = strdup(argv[0]);
+
+	/*
+	 * Don't be anal about the binary name.
+	 * We expect either 'ccs_tool' or 'ccs_test',
+	 * but interpret anything other than 'ccs_test'
+	 * as 'ccs_tool'.
+	 * That's not a bug, it's a feature.
+	 */
+
+	if (strcmp(basename(name), "ccs_test") == 0)
+		return test_main(argc, argv);
+	else
+#endif
+		return tool_main(argc, argv);
+}
diff --git a/ccs/ccs_tool/old_parser.c b/ccs/ccs_tool/old_parser.c
deleted file mode 100644
index 58ef18b..0000000
--- a/ccs/ccs_tool/old_parser.c
+++ /dev/null
@@ -1,688 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <errno.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include "old_parser.h"
-
-enum {
-	TOK_INT,
-	TOK_FLOAT,
-	TOK_STRING,
-	TOK_EQ,
-	TOK_SECTION_B,
-	TOK_SECTION_E,
-	TOK_ARRAY_B,
-	TOK_ARRAY_E,
-	TOK_IDENTIFIER,
-	TOK_COMMA,
-	TOK_EOF
-};
-
-
-typedef struct parser {
-  const char *data;		/* data and data limits */
-  const char *db, *de;
-
-  int t;			/* token limits and type */
-  const char *tb, *te;
-
-  int line;			/* line we're on */
-} parser_t;
-
-
-static void _get_token(struct parser *p);
-static void _eat_space(struct parser *p);
-static ccs_node_t *_file(struct parser *p);
-static ccs_node_t *_section(struct parser *p);
-static ccs_value_t *_value(struct parser *p);
-static ccs_value_t *_type(struct parser *p);
-static int _match_aux(struct parser *p, int t);
-static ccs_value_t *_create_value(void);
-static ccs_node_t *_create_node(void);
-static char *_dup_tok(struct parser *p);
-
-
-#define match(t) do {\
-   if (!_match_aux(p, (t))) {\
-      fprintf(stderr, \
-      	            "Parse error at line %d: unexpected token\n",  p->line); \
-      return 0;\
-   } \
-} while(0);
-
-
-static void free_ccs_value(ccs_value_t *cv){
-  if(cv->next)
-    free_ccs_value(cv->next);
-  if(cv->type == CCS_STRING && cv->v.str)
-    free(cv->v.str);
-  free(cv);
-}
-
-void free_ccs_node(ccs_node_t *cn){
-  ccs_node_t *tmp, *sib_end;
-
-  for(tmp = cn; tmp->sib; tmp = tmp->sib);
-  sib_end = tmp;
-    
-  for(tmp = cn; tmp; tmp = tmp->sib){
-    if(tmp->child){
-      sib_end->sib = tmp->child;
-      tmp->child = NULL;
-      while(sib_end->sib){
-	sib_end = sib_end->sib;
-      }
-    }
-  }
-
-  while(cn){
-    tmp = cn;
-    cn = cn->sib;
-    if(tmp->v){
-      free_ccs_value(tmp->v);
-    }
-    if(tmp->key){
-      free(tmp->key);
-    }
-    free(tmp);
-  }
-}
-
-static int isidchar(char c){
-  if ( (c >= 'a' && c <= 'z') || /* [a-z] */
-       (c >= 'A' && c <= 'Z') || /* [A-Z] */
-       (c >= '0' && c <= '9') || /* [0-9] */
-       (c == '_' ) ||
-       (c == '$' ) ||
-       (c == '-' ) ||
-       (c == '.' ) )
-	  return 1;
-  else
-	  return 0;
-}
-
-static void _get_token(struct parser *p){
-  int number_valid = 1;
-
-  p->tb = p->te;
-  _eat_space(p);
-  if (p->tb == p->de){
-    p->t = TOK_EOF;
-    return;
-  }
-  
-  p->t = TOK_INT;         /* fudge so the fall through for
-			     floats works */
-  switch (*p->te) {
-  case '{':
-    p->t = TOK_SECTION_B;
-    p->te++;
-    break;
-    
-  case '}':
-    p->t = TOK_SECTION_E;
-    p->te++;
-    break;
-
-  case '[':
-    p->t = TOK_ARRAY_B;
-    p->te++;
-    break;
-
-  case ']':
-    p->t = TOK_ARRAY_E;
-    p->te++;
-    break;
-
-  case ',':
-    p->t = TOK_COMMA;
-    p->te++;
-    break;
-
-  case '=':
-    p->t = TOK_EQ;
-    p->te++;
-    break;
-
-  case '"':
-    p->t = TOK_STRING;
-    p->te++;
-    while ((p->te != p->de) && (*p->te != '"')) {
-      /* $ is reserved */
-      if (*p->te == '$') 
-      {
-	      /* set token to EOF due to parse error */
-	      p->t = TOK_EOF;
-	      break;
-      }
-      
-      if ((*p->te == '\\') && (p->te + 1 != p->de))
-	p->te++;
-      p->te++;
-    }
-    
-    if (p->te != p->de)
-      p->te++;
-    break;
-
-  case '\'':
-    p->t = TOK_STRING;
-    p->te++;
-    while ((p->te != p->de) && (*p->te != '\'')) {
-      p->te++;
-    }
-    
-    if (p->te != p->de)
-      p->te++;
-    break;
-
-  case '.':
-    p->t = TOK_FLOAT;
-  case '-':
-  case '+':
-    number_valid = 0;
-  case '0':
-  case '1':
-  case '2':
-  case '3':
-  case '4':
-  case '5':
-  case '6':
-  case '7':
-  case '8':
-  case '9':
-    p->te++;
-    while (p->te != p->de) {
-      if (*p->te == '.') {
-	if (p->t == TOK_FLOAT)
-	  break;
-	p->t = TOK_FLOAT;
-      } else if (!isdigit((int) *p->te)){
-	break;
-      }
-      number_valid = 1;
-      p->te++;
-    }
-    if (!number_valid){
-      p->t = TOK_EOF;
-    } else if(!isidchar(*p->te)){
-      break;
-    }
-  default:
-
-
-    /* NOTE:  at this point, [-.0-9] have already been checked.  This means
-     * that valid identifiers can begin with [$_a-zA-Z] */
-    if (isidchar(*p->te))
-    {
-      p->t = TOK_IDENTIFIER;
-      while ((p->te != p->de) && !isspace(*p->te) &&
-	     (isidchar(*p->te)) && (*p->te != '#') && (*p->te != '='))
-         p->te++;
-    }else
-      p->t = TOK_EOF;
-
-    break;
-  }
-}
-
-
-static void _eat_space(struct parser *p){
-  while (p->tb != p->de) {
-    if (*p->te == '#') {
-      while ((p->te != p->de) && (*p->te != '\n'))
-	p->te++;
-      /*      p->line++;
-	      since != \n, the \n will be picked up by else if */
-    }
-
-    else if (isspace(*p->te)) {
-      while ((p->te != p->de) && isspace(*p->te)) {
-	if (*p->te == '\n')
-	  p->line++;
-	p->te++;
-      }
-    }
-
-    else
-      return;
-
-    p->tb = p->te;
-  }
-}
-
-
-static ccs_node_t *_file(struct parser *p){
-  ccs_node_t *root = NULL, *n, *l = NULL;
-
-  while (p->t != TOK_EOF) {
-    if (!(n = _section(p))) {
-      return 0;
-    }
-    
-    if (!root)
-      root = n;
-    else
-      l->sib = n;
-    l = n;
-  }
-  return root;
-}
-
-
-static ccs_node_t *_section(struct parser *p){
-  /* IDENTIFIER '{' VALUE* '}' */
-  ccs_node_t *root, *n, *l = NULL;
-
-  if (!(root = _create_node())) {
-    return 0;
-  }
-
-  if (!(root->key = _dup_tok(p))) {
-    free_ccs_node(root);
-    return 0;
-  }
-
-  match(TOK_IDENTIFIER);
-
-  if (p->t == TOK_SECTION_B) {
-    match(TOK_SECTION_B);
-    while (p->t != TOK_SECTION_E) {
-      if (!(n = _section(p))) {
-	free_ccs_node(root);
-	return 0;
-      }
-
-      if (!root->child)
-	root->child = n;
-      else
-	l->sib = n;
-      l = n;
-    }
-    match(TOK_SECTION_E);
-  } else {
-    match(TOK_EQ);
-    if (!(root->v = _value(p))) {
-      free_ccs_node(root);
-      return 0;
-    }
-  }
-
-  return root;
-}
-
-
-static ccs_value_t *_value(struct parser *p){
-  /* '[' TYPE* ']' | TYPE */
-  ccs_value_t *h = 0, *l, *ll = 0;
-  if (p->t == TOK_ARRAY_B) {
-    match(TOK_ARRAY_B);
-    while (p->t != TOK_ARRAY_E) {
-      if (!(l = _type(p))) {
-	return 0;
-      }
-      
-      if (!h)
-	h = l;
-      else
-	ll->next = l;
-      ll = l;
-      
-      if (p->t == TOK_COMMA)
-	match(TOK_COMMA);
-    }
-    match(TOK_ARRAY_E);
-  } else
-    h = _type(p);
-  
-  return h;
-}
-
-
-static ccs_value_t *_type(struct parser *p){
-  /* [0-9]+ | [0-9]*\.[0-9]* | ".*" */
-  ccs_value_t *v;
-
-  if(!(v = _create_value())){
-    return NULL;
-  }
-
-  switch (p->t) {
-  case TOK_INT:
-    v->type = CCS_INT;
-    v->v.i = strtol(p->tb, 0, 0);   /* FIXME: check error */
-    match(TOK_INT);
-    break;
-
-#ifndef __KERNEL__
-  case TOK_FLOAT:
-    v->type = CCS_FLOAT;
-    v->v.r = strtod(p->tb, 0);      /* FIXME: check error */
-    match(TOK_FLOAT);
-    break;
-#endif
-
-  case TOK_STRING:
-    v->type = CCS_STRING;
-
-    p->tb++, p->te--;       /* strip double-quotes */
-    if (!(v->v.str = _dup_tok(p))) {
-      free_ccs_value(v);
-      return NULL;
-    } else {
-      char *tmp;
-      /* strip \'s */
-      while((tmp = strstr(v->v.str, "\\"))){
-	strcpy(tmp, tmp+1);
-      }
-    }
-    p->te++;
-    match(TOK_STRING);
-    break;
-
-  default:
-    fprintf(stderr, "Error on line %d\n", p->line);
-    free_ccs_value(v);
-    return NULL;
-  }
-  return v;
-}
-
-
-static int _match_aux(struct parser *p, int t){
-  if (p->t != t){
-    return 0;
-  }
-  _get_token(p);
-
-  return 1;
-}
-
-
-static ccs_value_t *_create_value(void){
-  ccs_value_t *v = (ccs_value_t *)malloc(sizeof(ccs_value_t));
-  if(v){
-    memset(v, 0, sizeof(ccs_value_t));
-    return v;
-  }
-  return NULL;
-}
-
-
-static ccs_node_t *_create_node(void){
-  ccs_node_t *n = (ccs_node_t *)malloc(sizeof(ccs_node_t));
-  if(n){
-    memset(n, 0, sizeof(ccs_node_t));
-    return n;
-  }
-  return NULL;
-}
-
-
-static char *_dup_tok(struct parser *p){
-  int len = p->te - p->tb;
-  char *str = (char *)malloc(len + 1);
-  if (!str) {
-    return NULL;
-  }
-  strncpy(str, p->tb, len);
-  str[len] = '\0';
-  return str;
-}
-
-
-static int get_ccs_file(int fd, char **file_data, char *filename){
-  int error = 0;
-  int size;
-  char *data=NULL;
-  char *beginning, *end;
-  char search_str[128];
-
-  if((size = lseek(fd, 0, SEEK_END)) < 0){
-    fprintf(stderr, "Unable to seek to end of archive: %s\n", strerror(errno));
-    error = -errno;
-    goto fail;
-  }
-
-  if(lseek(fd, 0, SEEK_SET) < 0){
-    fprintf(stderr, "Bad lseek on archive: %s\n", strerror(errno));
-    error = -errno;
-    goto fail;
-  }
-
-  size++;
-  data = malloc(size);
-  memset(data, 0, size);
-  size--;
-
-  if(read(fd, data, size) != size){
-    fprintf(stderr, "Unable to read entire archive.\n");
-    error = -EIO;
-    goto fail;
-  }
-
-  sprintf(search_str, "#nigeb=%s mtime=", filename);
-  beginning = strstr(data, search_str);
-  if(!beginning){
-    fprintf(stderr, "Unable to find %s in the archive.\n", filename);
-    error = -ENOENT;
-    goto fail;
-  }
-  beginning = strstr(beginning, "\n");
-  if(!beginning){
-    fprintf(stderr, "Unable to find %s in the archive.\n", filename);
-    error = -ENOENT;
-    goto fail;
-  }
-  beginning++; /* skip newline */
-
-  sprintf(search_str, "#dne=%s", filename);
-  end = strstr(beginning, search_str);
-  if(!end){
-    fprintf(stderr, "Unable to find the end of %s in the archive.\n", filename);
-    error = -ENOENT;
-    goto fail;
-  }
-
-  size = end - beginning;
-
-  *file_data = malloc(size+1);
-  if(!file_data){
-    fprintf(stderr, "Unable to allocate memory for CCS file.\n");
-    error = -ENOMEM;
-    goto fail;
-  }
-  memset(*file_data, 0, size+1);
-
-  memcpy(*file_data, beginning, size);
-
- fail:
-  if(data) free(data);
-  return error;
-}
-
-
-static int parse_filedata(ccs_node_t **cn, char *filedata){
-  int error=0;
-  parser_t p;
-
-  memset(&p, 0, sizeof(p));
-  if(!filedata){
-    error = -ENODATA;
-    goto fail;
-  }
-  p.db = p.data = filedata;
-  p.line =1;
-  p.de = (char *)(filedata + strlen(filedata));
-
-  p.tb = p.te = p.db;
-  _get_token(&p);
-  if(!(*cn = _file(&p))){
-    error = -EPARSE;
-  }
-
- fail:
-  return error;
-}
-
-
-/*
- * parse_ccs_file
- * @cf:
- *
- * Returns: 0 on success, -EXXX on error
- */
-int parse_ccs_file(int fd, ccs_node_t **cn, char *filename){
-  int error;
-  char *file_data = NULL;
-
-  error = get_ccs_file(fd, &file_data, filename);
-  if(error < 0){
-    goto fail;
-  }
-  /* This is where the magic happens */
-  error = parse_filedata(cn, file_data);
-
- fail:
-  if(file_data) free(file_data);
-  return error;
-}
-
-
-static int _tok_match(const char *str, const char *b, const char *e)
-{
-  while (*str && (b != e)) {
-    if (*str++ != *b++)
-      return 0;
-  }
-
-  return !(*str || (b != e));
-}
-
-
-ccs_node_t *find_ccs_node(ccs_node_t *cn,
-			  const char *path,
-			  char sep){
-  const char *e;
-  while (cn) {
-    /* trim any leading slashes */
-    while (*path && (*path == sep))
-      path++;
-
-    /* find the end of this segment */
-    for (e = path; *e && (*e != sep); e++) ;
-
-    /* hunt for the node */
-    while (cn) {
-      if (_tok_match(cn->key, path, e))
-	break;
-
-      cn = cn->sib;
-    }
-
-    if (cn && *e)
-      cn = cn->child;
-    else
-      break;  /* don't move into the last node */
-    
-    path = e;
-  }
-
-  return cn;
-}
-
-
-const char *find_ccs_str(ccs_node_t *cn,
-			 const char *path,
-			 char sep,
-			 const char *fail){
-  ccs_node_t *n = find_ccs_node(cn, path, sep);
-
-  if (n && n->v && n->v->type == CCS_STRING) {
-    return n->v->v.str;
-  }
-
-  return fail;
-}
-
-
-int find_ccs_int(ccs_node_t *cn,
-		 const char *path,
-		 char sep,
-		 int fail){
-  ccs_node_t *n = find_ccs_node(cn, path, sep);
-
-  if (n && n->v && n->v->type == CCS_INT) {
-    return n->v->v.i;
-  }
-
-  return fail;
-}
-
-#ifndef __KERNEL__
-float find_ccs_float(ccs_node_t *cn,
-		     const char *path,
-		     char sep,
-		     float fail){
-  ccs_node_t *n = find_ccs_node(cn, path, sep);
-  
-  if (n && n->v && n->v->type == CCS_FLOAT) {
-    return n->v->v.r;
-  }
-
-  return fail;
-}
-#endif
-
-static int _str_in_array(const char *str, const char *values[]){
-  int i;
-
-  for (i = 0; values[i]; i++){
-    if (!strcasecmp(str, values[i]))
-      return 1;
-  }
-  return 0;
-}
-
-
-static int _str_to_bool(const char *str, int fail){
-  static const char *_true_values[]  = { "y", "yes", "on", "true",  NULL };
-  static const char *_false_values[] = { "n", "no", "off", "false", NULL };
-
-  if (_str_in_array(str, _true_values))
-    return 1;
-
-  if (_str_in_array(str, _false_values))
-    return 0;
-
-  return fail;
-}
-
-int find_ccs_bool(ccs_node_t *cn,
-		  const char *path,
-		  char sep,
-		  int fail){
-  ccs_node_t *n = find_ccs_node(cn, path, sep);
-  ccs_value_t *v;
-
-  if (!n)
-    return fail;
-
-  v = n->v;
-
-  if(!v)
-    return fail;
-
-  switch (v->type) {
-  case CCS_INT:
-    return v->v.i ? 1 : 0;
-
-  case CCS_STRING:
-    return _str_to_bool(v->v.str, fail);
-  }
-
-  return fail;
-}
diff --git a/ccs/ccs_tool/old_parser.h b/ccs/ccs_tool/old_parser.h
deleted file mode 100644
index 275dcd7..0000000
--- a/ccs/ccs_tool/old_parser.h
+++ /dev/null
@@ -1,64 +0,0 @@
-#ifndef __OLD_PARSER_H__
-#define __OLD_PARSER_H__
-
-/* A special error number for CCS.  This error indicates that there was **
-** an error while parsing data.  This number should not collide with    **
-** other Linux error numbers, however, if someone has a better errno in **
-** mind, please let me know............................................ */
-#define EPARSE 2050
-
-enum {
-  CCS_STRING,
-  CCS_FLOAT,
-  CCS_INT,
-};
-
-
-typedef struct ccs_value {
-  int type;
-  union {
-    int i;
-    float r;
-    char *str;
-  } v;
-  struct ccs_value *next; /* for arrays */
-} ccs_value_t;
-
-typedef struct ccs_node_s{
-  char *key;
-  struct ccs_node_s *sib, *child;
-  struct ccs_value *v;
-} ccs_node_t;
-
-
-void free_ccs_node(ccs_node_t *cn);
-
-int parse_ccs_file(int fd, ccs_node_t **cn, char *filename);
-
-ccs_node_t *find_ccs_node(ccs_node_t *cn,
-                          const char *path,
-                          char seperator);
-
-const char *find_ccs_str(ccs_node_t *cn,
-                         const char *path,
-                         char sep,
-                         const char *fail);
-
-int find_ccs_int(ccs_node_t *cn,
-                 const char *path,
-                 char sep,
-                 int fail);
-
-#ifndef __KERNEL__
-float find_ccs_float(ccs_node_t *cn,
-                     const char *path,
-                     char sep,
-                     float fail);
-#endif
-
-int find_ccs_bool(ccs_node_t *cn,
-                  const char *path,
-                  char sep,
-                  int fail);
-
-#endif /* __OLD_PARSER_H__ */
diff --git a/ccs/ccs_tool/upgrade.c b/ccs/ccs_tool/upgrade.c
deleted file mode 100644
index a8a2314..0000000
--- a/ccs/ccs_tool/upgrade.c
+++ /dev/null
@@ -1,259 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-
-#include <endian.h>
-#include <byteswap.h>
-
-#include "old_parser.h"
-
-#define DEFAULT_BBS 16384 /* default basic block size */
-
-
-static int upgrade_file_archive(char *location);
-static int upgrade_device_archive(char *location);
-
-int upgrade(char *location){
-  struct stat stat_buf;
-
-  if(stat(location, &stat_buf)){
-    fprintf(stderr, "Unable to stat %s: %s\n", location, strerror(errno));
-    return -errno;
-  }
-
-  if(S_ISBLK(stat_buf.st_mode)){
-    return upgrade_device_archive(location);
-  } else {
-    return upgrade_file_archive(location);
-  }
-}
-
-static int _upgrade_file_archive(int fd){
-  int error = 0;
-  ccs_node_t *cluster_cn = NULL;
-  ccs_node_t *fence_cn = NULL;
-  ccs_node_t *nodes_cn = NULL;
-  ccs_node_t *tmp_cn;
-
-  if((error = parse_ccs_file(fd, &cluster_cn, "cluster.ccs"))){
-    return error;
-  }
-
-  if((error = parse_ccs_file(fd, &nodes_cn, "nodes.ccs"))){
-    return error;
-  }
-
-  if((error = parse_ccs_file(fd, &fence_cn, "fence.ccs"))){
-    return error;
-  }
-
-  tmp_cn = find_ccs_node(cluster_cn, "cluster/name", '/');
-  if(!tmp_cn || !tmp_cn->v){
-    fprintf(stderr, "Unable to find cluster name.\n");
-    error = -EINVAL;
-    goto fail;
-  }
-
-  printf("<cluster name=\"%s\" config_version=\"1\">\n", tmp_cn->v->v.str);
-
-  /* No cman on upgrade
-  printf("\n<cman>\n");
-  printf("</cman>\n");
-  */
-
-  tmp_cn = find_ccs_node(cluster_cn, "cluster/lock_gulm/servers", '/');
-  printf("\n<gulm>\n");
-  if(tmp_cn && tmp_cn->v){
-    ccs_value_t *server;
-    for(server = tmp_cn->v; server; server = server->next)
-      printf("    <lockserver name=\"%s\"/>\n", server->v.str);
-  }
-  printf("</gulm>\n");
-
-  printf("\n<clusternodes>\n");
-
-  for(tmp_cn = nodes_cn->child; tmp_cn; tmp_cn = tmp_cn->sib){
-    ccs_node_t *fence, *method, *device, *params;
-
-    printf("\n  <clusternode name=\"%s\" votes=\"1\">\n", tmp_cn->key);
-    for(fence = tmp_cn->child; fence; fence = fence->sib){
-      if(!strcmp(fence->key, "fence")){
-	printf("    <fence>\n");
-	for(method = fence->child; method; method = method->sib){
-	  printf("      <method name=\"%s\">\n", method->key);
-	  for(device = method->child; device; device=device->sib){
-	    printf("        <device name=\"%s\"", device->key);
-	    for(params = device->child; params; params = params->sib){
-	      if (params->v->type == CCS_STRING)
-		printf(" %s=\"%s\"", params->key, params->v->v.str);
-	      else if (params->v->type == CCS_INT)
-		printf(" %s=\"%d\"", params->key, params->v->v.i);
-	      else if (params->v->type == CCS_FLOAT)
-		printf(" %s=[DECIMAL NOT CONVERTED]", params->key);
-	      else
-		printf(" %s=[BAD TYPE CONVERSION]", params->key);
-	    }
-	    printf("/>\n");
-	  }
-	  printf("      </method>\n");
-	}
-	printf("    </fence>\n");
-      }
-    }
-    printf("  </clusternode>\n");
-  }
-
-  printf("\n</clusternodes>\n");
-
-  printf("\n<fencedevices>\n");
-  for(tmp_cn = fence_cn->child; tmp_cn; tmp_cn = tmp_cn->sib){
-    ccs_node_t *params;
-
-    printf("  <fencedevice name=\"%s\"", tmp_cn->key);
-    for(params = tmp_cn->child; params; params = params->sib){
-      printf(" %s=\"%s\"", params->key, params->v->v.str);
-    }
-    printf("/>\n");
-  }
-
-  printf("\n</fencedevices>\n");
-
-  printf("</cluster>\n");
-
- fail:
-  if(cluster_cn) free_ccs_node(cluster_cn);
-  if(fence_cn) free_ccs_node(fence_cn);
-  if(nodes_cn) free_ccs_node(nodes_cn);
-  return error;
-}
-
-static int upgrade_file_archive(char *location){
-  int error = 0;
-  int fd=-1;
-  
-  if((fd = open(location, O_RDONLY)) < 0){
-    fprintf(stderr, "Unable to open %s: %s\n", location, strerror(errno));
-    error = -errno;
-    goto fail;
-  }
-  
-  error = _upgrade_file_archive(fd);
-
- fail:
-  if(fd >= 0) close(fd);
-  return error;
-}
-
-
-#define CCS_DH_MAGIC  0x122473
-
-/* CCS Device Header */
-typedef struct ccs_dh_s {
-  u_int32_t dh_magic;
-  u_int32_t dh_format;
-  u_int32_t dh_generation;
-  u_int32_t dh_active;
-  u_int32_t dh_size;     /* Size of archive on disk */
-  u_int32_t dh_maxsize;
-  char   dh_reserved[64];
-} ccs_dh_t;
-
-static void ccs_dh_in(ccs_dh_t *dh, char *buf){
-  ccs_dh_t *tmp = (ccs_dh_t *)buf;
-
-#if __BYTE_ORDER == __BIG_ENDIAN
-  dh->dh_magic   = tmp->dh_magic;
-  dh->dh_active  = tmp->dh_active;
-  dh->dh_size    = tmp->dh_size;
-  dh->dh_maxsize = tmp->dh_maxsize;
-#else
-  dh->dh_magic   = bswap_32(tmp->dh_magic);
-  dh->dh_active  = bswap_32(tmp->dh_active);
-  dh->dh_size    = bswap_32(tmp->dh_size);
-  dh->dh_maxsize = bswap_32(tmp->dh_maxsize);
-#endif
-}
-
-static int upgrade_device_archive(char *location){
-  int error = 0;
-  int dev_fd=-1, tmp_fd=-1;
-  char tmp_file[64];
-  void *buffer = NULL;
-  char *buffer_p;
-  ccs_dh_t dev_header;
-
-  if(posix_memalign(&buffer, DEFAULT_BBS, DEFAULT_BBS)){
-    fprintf(stderr, "Unable to allocate aligned memory.\n");
-    return -ENOMEM;
-  }
-  buffer_p = (char *)buffer;
-
-  if((dev_fd = open(location, O_RDONLY | O_DIRECT)) < 0){
-    fprintf(stderr, "Unable to open %s: %s\n", location, strerror(errno));
-    error = -errno;
-    goto fail;
-  }
-
-  if(read(dev_fd, buffer_p, DEFAULT_BBS) < DEFAULT_BBS){
-    fprintf(stderr, "Unable to read %s: %s\n", location, strerror(errno));
-    error = -errno;
-    goto fail;
-  }
-
-  ccs_dh_in(&dev_header, buffer_p);
-  if(dev_header.dh_magic == CCS_DH_MAGIC){
-    if(!dev_header.dh_active){
-      if(lseek(dev_fd, dev_header.dh_maxsize, SEEK_SET)< 0){
-	fprintf(stderr, "Unable to lseek in %s: %s\n", location, strerror(errno));
-	error = -errno;
-	goto fail;
-      }
-    }
-  } else {
-    fprintf(stderr, "The specified device does not contain a CCS archive.\n");
-    error = -EINVAL;
-    goto fail;
-  }
-
-  sprintf(tmp_file, "/tmp/tmp_%d", getpid());
-
-  tmp_fd = open(tmp_file, O_RDWR | O_CREAT |O_TRUNC, S_IRUSR|S_IWUSR);
-  if(tmp_fd < 0){
-    fprintf(stderr, "Unable to create temporary archive: %s\n", strerror(errno));
-    error = -errno;
-    goto fail;
-  }
-  unlink(tmp_file);
-
-  while(dev_header.dh_size){
-    int write_size;
-    if(read(dev_fd, buffer_p, DEFAULT_BBS) < DEFAULT_BBS){
-      fprintf(stderr, "Bad read on %s: %s.\n", location, strerror(errno));
-      error = -errno;
-      goto fail;
-    }
-    write_size = (dev_header.dh_size < DEFAULT_BBS) ? 
-      dev_header.dh_size : DEFAULT_BBS;
-    if(write(tmp_fd, buffer_p, write_size) < write_size){
-      fprintf(stderr, "Unable to write to temporary archive: %s.\n", strerror(errno));
-      error = -errno;
-      goto fail;
-    }
-    dev_header.dh_size -= write_size;
-  }
-  lseek(tmp_fd, 0, SEEK_SET);
-
-  error = _upgrade_file_archive(tmp_fd);
-  
- fail:
-  if(buffer_p) free(buffer_p);
-  if(dev_fd >= 0) close(dev_fd);
-  if(tmp_fd >= 0) close(tmp_fd);
-  return error;
-}
-
diff --git a/ccs/ccs_tool/upgrade.h b/ccs/ccs_tool/upgrade.h
deleted file mode 100644
index 6f784c1..0000000
--- a/ccs/ccs_tool/upgrade.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef __UPGRADE_DOT_H__
-#define __UPGRADE_DOT_H__
-
-int upgrade(char *location);
-
-#endif /* __UPGRADE_DOT_H__ */


hooks/post-receive
--
Cluster Project



More information about the Cluster-cvs mailing list