cluster/cmirror/src cluster.c functions.c func ...
CVSROOT: /cvs/cluster
Module name: cluster
Branch: RHEL5
Changes by: jbrassow at sourceware.org 2008-01-14 22:52:17
Modified files:
cmirror/src : cluster.c functions.c functions.h link_mon.c
link_mon.h local.c logging.h queues.c queues.h rbtree.c
Log message:
- Several small bug fixes
-- More correct method of leaving CPG (on suspend) -- close log file desc after finished using
-- fix problem with overlapping recoveries
-- clean-up postsuspend so remote requests do not get lost -- missing 'break' statement causing seg fault -- better error checking
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/cmirror/src/cluster.c.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.1.2.7&r2=1.1.2.8
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/cmirror/src/functions.c.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.1.2.6&r2=1.1.2.7
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/cmirror/src/functions.h.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.1.2.2&r2=1.1.2.3
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/cmirror/src/link_mon.c.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.1.2.2&r2=1.1.2.3
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/cmirror/src/link_mon.h.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.1.2.1&r2=1.1.2.2
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/cmirror/src/local.c.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.1.2.5&r2=1.1.2.6
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/cmirror/src/logging.h.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.1.2.2&r2=1.1.2.3
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/cmirror/src/queues.c.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.1.2.1&r2=1.1.2.2
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/cmirror/src/queues.h.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.1.2.1&r2=1.1.2.2
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/cmirror/src/rbtree.c.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.1.2.2&r2=1.1.2.3
cmirror/src/Attic/cluster.c +55 -20
@@ -162,7 +162,7 @@* Errors from previous functions are in the tfr struct. */ -LOG_DBG ("Sending respose to %u on cluster: [%s/%llu]" , +LOG_DBG ("Sending response to %u on cluster: [%s/%llu]" , tfr->originator,RQ_TYPE (tfr->request_type & ~DM_CLOG_RESPONSE ), tfr->seq);
@@ -704,6 +704,12 @@if (!match->valid) {LOG_DBG ("Log not valid yet, storing request" ); startup_tfr =queue_remove (free_queue); +if (!startup_tfr) { +LOG_ERROR ("Supply of transfer structs exhausted" ); + r = -ENOMEM ;/* FIXME: Better error #? */ + goto out; + } +memcpy (startup_tfr, tfr,sizeof (*tfr) + tfr->data_size);queue_add_tail (startup_tfr, match->startup_queue); goto out;
@@ -724,7 +730,7 @@ struct cpg_address *left_list, int left_list_entries, struct cpg_address *joined_list, int joined_list_entries) { - int i, j; + int i, j, fd;int my_pid =getpid ();int found =0 ;struct clog_cpg *match, *tmp;
@@ -740,8 +746,8 @@LOG_PRINT ("* MEMBERS (%d):" , member_list_entries);for (i =0 ; i < member_list_entries; i++) -LOG_PRINT ("* [%d] nodeid: %d, pid: %d" , - i, member_list[i].nodeid, member_list[i].pid); +LOG_PRINT ("* nodeid: %d, pid: %d" , + member_list[i].nodeid, member_list[i].pid);LOG_PRINT ("* LEAVING (%d):" , left_list_entries);for (i =0 ; i < left_list_entries; i++)
@@ -768,6 +774,46 @@ goto out; } +/* Am I leaving? */ +for (i =0 ; i < left_list_entries; i++) +if (my_cluster_id == left_list[i].nodeid) { +struct clog_tfr *tfr; + +LOG_DBG ("Finalizing leave..." ); +list_del_init (&match->list); + +cpg_fd_get (match->handle, &fd); +links_unregister (fd); + +cluster_postsuspend (match->name.value); + +while (!queue_empty (cluster_queue)) { + tfr =queue_remove (cluster_queue); + +/* +* A postsuspend is place directly into +* the cluster_queue, without going out +* to the cluster. This means that only +* our postsuspend will ever exist in the +* cluster_queue. +*/ +if (tfr->request_type ==DM_CLOG_POSTSUSPEND ) +kernel_send (tfr); +else +queue_add (tfr, free_queue); + } + +cpg_finalize (match->handle); + +if (match->startup_queue->count) +LOG_ERROR ("Startup items remain in cluster log" ); + +free (match->startup_queue); +free (match); + + goto out; + } +/* Am I the very first to join? */ if (!left_list_entries && (member_list_entries == 1) && (joined_list_entries == 1) &&
@@ -887,7 +933,7 @@/* FIXME: better variable */ cpg_fd_get (new->handle, &r); -links_register (r, do_cluster_work,NULL ); +links_register (r,"cluster" , do_cluster_work,NULL );EXIT ();return 0 ;
@@ -895,26 +941,15 @@int destroy_cluster_cpg (char *str) { -int fd; +int r;struct clog_cpg *del, *tmp;ENTER ();list_for_each_entry_safe (del, tmp, &clog_cpg_list, list)if (!strncmp (del->name.value, str,CPG_MAX_NAME_LENGTH )) { -list_del_init (&del->list); - -cpg_fd_get (del->handle, &fd); -links_unregister (fd); - -cpg_leave (del->handle, &del->name); -cpg_finalize (del->handle); - -if (del->startup_queue->count) -LOG_ERROR ("Startup items remain in cluster log" ); - -free (del->startup_queue); -free (del); - + r =cpg_leave (del->handle, &del->name); +if (r !=CPG_OK ) +LOG_ERROR ("Error leaving CPG!" );break ; }
cmirror/src/Attic/functions.c +142 -60
442 lines not on this page · raw message
cmirror/src/Attic/functions.h +1 -0
@@ -7,6 +7,7 @@#define LOG_SUSPENDED 2int local_resume (struct clog_tfr *tfr); +int cluster_postsuspend (char *);int do_request (struct clog_tfr *tfr);int commit_log (struct clog_tfr *tfr);int store_bits (const char *uuid,const char *which,char **buf);
cmirror/src/Attic/link_mon.c +29 -7
@@ -6,7 +6,7 @@struct link_callback {int fd; - +char *name;void *data;int (*callback)(void *data);
@@ -18,7 +18,7 @@static struct pollfd *pfds =NULL ;static struct link_callback *callbacks =NULL ; -int links_register (int fd,int (*callback)(void *data),void *data) +int links_register (int fd,char *name,int (*callback)(void *data),void *data) {int i;struct link_callback *lc;
@@ -40,6 +40,7 @@ } lc->fd = fd; + lc->name = name; lc->data = data; lc->callback = callback;
@@ -64,6 +65,9 @@ lc->next = callbacks; callbacks = lc; +LOG_DBG ("Adding %s/%d" , lc->name, lc->fd); +LOG_DBG (" used_pfds = %d, free_pfds = %d" , + used_pfds, free_pfds);EXIT ();return 0 ;
@@ -72,14 +76,27 @@int links_unregister (int fd) {int i; +struct link_callback *p, *c; -for (i =0 ; i < used_pfds; i++) { +for (i =0 ; i < used_pfds; i++)if (fd == pfds[i].fd) { - pfds[i].fd = pfds[used_pfds -1 ].fd; +/* entire struct is copied (overwritten) */ + pfds[i] = pfds[used_pfds -1 ]; used_pfds--; free_pfds++; } - } + +for (p =NULL , c = callbacks; c; p = c, c = c->next) +if (fd == c->fd) { +LOG_DBG ("Freeing up %s/%d" , c->name, c->fd); +LOG_DBG (" used_pfds = %d, free_pfds = %d" , + used_pfds, free_pfds); +if (p) + p->next = c->next; +else + callbacks = c->next; +free (c); + }return 0 ; }
@@ -102,6 +119,8 @@/* FIXME: handle POLLHUP */ for (i =0 ; i < used_pfds; i++)if (pfds[i].revents &POLLIN ) { +LOG_DBG ("Data ready on %d" , pfds[i].fd); +/* FIXME: Add this back return 1;*/ r++; }
@@ -118,10 +137,13 @@if (pfds[i].revents &POLLIN )for (lc = callbacks; lc; lc = lc->next)if (pfds[i].fd == lc->fd) { +LOG_DBG ("Issuing callback on %s/%d" , + lc->name, lc->fd); r = lc->callback (lc->data);if (r) -LOG_ERROR ("Bad callback on file desc, %d" , - lc->fd); +LOG_ERROR ("Bad callback on %s/%d" , + lc->name, lc->fd); +break ; }return 0 ; }
cmirror/src/Attic/link_mon.h +1 -1
@@ -1,7 +1,7 @@#ifndef __LINK_MON_DOT_H__#define __LINK_MON_DOT_H__ -int links_register (int fd,int (*callback)(void *data),void *data); +int links_register (int fd,char *name,int (*callback)(void *data),void *data);int links_unregister (int fd);int links_monitor (void );int links_issue_callbacks (void );
cmirror/src/Attic/local.c +19 -2
@@ -84,7 +84,7 @@return -ENOMEM ; } -memset (*tfr,0 ,sizeof (struct clog_tfr )); +memset (*tfr,0 ,DM_CLOG_TFR_SIZE ); r =kernel_recv_helper (*tfr,DM_CLOG_TFR_SIZE );if (r) {
@@ -158,6 +158,7 @@case DM_CLOG_DTR :case DM_CLOG_STATUS_INFO :case DM_CLOG_STATUS_TABLE : +case DM_CLOG_PRESUSPEND : r =do_request (tfr);if (r) LOG_DBG("Returning failed request to kernel [%s]",
@@ -168,6 +169,19 @@ RQ_TYPE(tfr->request_type));break ; +case DM_CLOG_POSTSUSPEND : + r =do_request (tfr); +if (r) { +LOG_DBG ("Returning failed request to kernel [%s]" , +RQ_TYPE (tfr->request_type)); + r =kernel_send (tfr); +if (r) +LOG_ERROR ("Failed to respond to kernel [%s]" , +RQ_TYPE (tfr->request_type)); + } +queue_add_tail (tfr, cluster_queue); + +break ;case DM_CLOG_RESUME :/* * Resume is a special case that requires a local
@@ -189,6 +203,9 @@/* Add before send_to_cluster, so cluster code can find it */ queue_add_tail (tfr, cluster_queue); r =cluster_send (tfr); +if (r) +LOG_ERROR ("Unable to send request to cluster: %s" , +strerror (-r));break ; }
@@ -298,7 +315,7 @@r = fcntl(cn_fd, F_SETFL, FNDELAY); */ -links_register (cn_fd, do_local_work,NULL ); +links_register (cn_fd,"local" , do_local_work,NULL );EXIT ();return 0 ;
cmirror/src/Attic/logging.h +3 -0
@@ -4,6 +4,9 @@#include <stdio.h> #include <syslog.h> +/* SHORT_UUID - print last 8 chars of a string */ +#define SHORT_UUID (x) ((x) + (strlen(x) - 8)) +extern int log_tabbing;extern int log_is_open;
cmirror/src/Attic/queues.c +11 -0
@@ -81,7 +81,18 @@int queue_status (void ) { +int i=1 ; +struct clog_tfr *tfr; +struct list_head *p, *n; +LOG_PRINT ("cluster_queue: %d" , cluster_queue->count); +list_for_each_safe (p, n, &cluster_queue->list) { + tfr = (struct clog_tfr *)p; +LOG_PRINT (" %d) %s, originator = %u" , + i++,RQ_TYPE (tfr->request_type), + tfr->originator); + } +LOG_PRINT ("free_queue : %d" , free_queue->count);return cluster_queue->count;
cmirror/src/Attic/queues.h +1 -1
@@ -24,6 +24,6 @@int (*f)(struct clog_tfr *,struct clog_tfr *), struct clog_tfr *tfr_cmp);void queue_remove_all (struct list_head *l,struct queue *q); -int queue_emtpy (struct queue *q); +int queue_empty (struct queue *q);#endif /* __CLUSTER_LOG_QUEUES_DOT_H__ */
cmirror/src/Attic/rbtree.c +27 -3
@@ -51,6 +51,13 @@ {struct rb_node *tmp; +if (RIGHT (axis) ==NIL (t)) { +LOG_ERROR ("Tree error: unable to left rotate" ); +return axis; + } + +LOG_DBG ("TREE[0x%p]: left_rotate [axis = %llu]" , + t, *((uint64_t *)KEY (axis))); tmp =RIGHT (axis);RIGHT (axis) =LEFT (tmp);if (LEFT (tmp) !=NIL (t))
@@ -74,6 +81,13 @@ {struct rb_node *tmp; +if (LEFT (axis) ==NIL (t)) { +LOG_ERROR ("Tree error: unable to right rotate" ); +return axis; + } + +LOG_DBG ("TREE[0x%p]: right_rotate [axis = %llu]" , + t, *((uint64_t *)KEY (axis))); tmp =LEFT (axis);LEFT (axis) =RIGHT (tmp);if (RIGHT (tmp) !=NIL (t))
@@ -128,9 +142,13 @@ t->in_use_nodes++;if (t->in_use_nodes > t->max_nodes) { t->max_nodes = t->in_use_nodes; -LOG_DBG ("Maximum tree nodes now at %d" , t->max_nodes); +LOG_PRINT ("TREE[0x%p]: Maximum tree nodes now at %d" , + t, t->max_nodes); } +LOG_DBG ("TREE[0x%p]: allocating node (in_use_nodes = %d, max_nodes = %d)" , + t, t->in_use_nodes, t->max_nodes); +if (t->free_list) { new = t->free_list; t->free_list = new->rb_next;
@@ -150,6 +168,9 @@ d->rb_next = t->free_list; t->free_list = d; +LOG_DBG ("TREE[0x%p]: freeing node (in_use_nodes = %d, max_nodes = %d)" , + t, t->in_use_nodes, t->max_nodes); +/* FIXME: We never free any nodes */ }
@@ -157,7 +178,8 @@ {struct rb_node *tmp; -LOG_DBG ("TREE: insert %llu" , *((uint64_t *)KEY (new))); +LOG_DBG ("TREE[0x%p]: inserting %llu" , + t, *((uint64_t *)KEY (new)));if (!t || !new) { errno =EINVAL ;return -1 ;
@@ -221,6 +243,7 @@left_rotate (t,PARENT (x)); w =RIGHT (PARENT (x)); } +if ((COLOR (LEFT (w)) ==BLACK ) && (COLOR (RIGHT (w)) ==BLACK )) {COLOR (w) =RED ; x =PARENT (x);
@@ -296,7 +319,8 @@ {struct rb_node *x, *y; -LOG_DBG ("TREE: remove %llu" , *((uint64_t *)KEY (del))); +LOG_DBG ("TREE[0x%p]: removing %llu" , + t, *((uint64_t *)KEY (del)));if ((LEFT (del) ==NIL (t)) || (RIGHT (del) ==NIL (t))) y = del;else