All of lore.kernel.org
 help / color / mirror / Atom feed
* [Patch 2/2] tabled: check for duplicate NID
@ 2009-09-17  6:23 Pete Zaitcev
  2009-09-17  7:12 ` Jeff Garzik
  0 siblings, 1 reply; 2+ messages in thread
From: Pete Zaitcev @ 2009-09-17  6:23 UTC (permalink / raw)
  To: Jeff Garzik; +Cc: Project Hail List

Check for duplicate NID. I left XXX in and forgot about it. The result
is tabled adding all available nodes every minute if left running.

We still don't have the correct removal, because it needs refcounting.
This is a more of an urgent fix.

Signed-off-by: Pete Zaitcev <zaitcev@redhat.com>

diff --git a/server/storage.c b/server/storage.c
index b2160ac..6d830e2 100644
--- a/server/storage.c
+++ b/server/storage.c
@@ -310,16 +310,24 @@ bool stor_obj_test(struct open_chunk *cep, uint64_t key)
 	return true;
 }
 
-void stor_add_node(uint32_t nid, const char *hostname, const char *portstr,
-		   struct geo *locp)
+static struct storage_node *stor_node_by_nid(uint32_t nid)
+{
+	struct storage_node *sn;
+
+	list_for_each_entry(sn, &tabled_srv.all_stor, all_link) {
+		if (sn->id == nid)
+			return sn;
+	}
+	return NULL;
+}
+
+static int stor_add_node_addr(struct storage_node *sn,
+			      const char *hostname, const char *portstr)
 {
 	struct addrinfo hints;
 	struct addrinfo *res, *res0;
-	struct storage_node *sn;
 	int rc;
 
-	/* XXX FIXME search all_stor for dup NIDs */
-
 	memset(&hints, 0, sizeof(struct addrinfo));
 	hints.ai_family = PF_UNSPEC;
 	hints.ai_socktype = SOCK_DGRAM;
@@ -328,7 +336,7 @@ void stor_add_node(uint32_t nid, const char *hostname, const char *portstr,
 	if (rc) {
 		applog(LOG_WARNING, "getaddrinfo(%s:%s) failed: %s",
 		       hostname, portstr, gai_strerror(rc));
-		return;
+		return -1;
 	}
 
 	for (res = res0; res; res = res->ai_next) {
@@ -338,25 +346,10 @@ void stor_add_node(uint32_t nid, const char *hostname, const char *portstr,
 		if (res->ai_addrlen > ADDRSIZE)		/* should not happen */
 			continue;
 
-		if ((sn = malloc(sizeof(struct storage_node))) == NULL) {
-			applog(LOG_WARNING, "No core (%ld)",
-			       (long) sizeof(struct storage_node));
-			break;
-		}
-		memset(sn, 0, sizeof(struct storage_node));
-
-		sn->id = nid;
-
 		memcpy(&sn->addr, res->ai_addr, res->ai_addrlen);
 		sn->addr_af = res->ai_family;
 		sn->alen = res->ai_addrlen;
 
-		if ((sn->hostname = strdup(hostname)) == NULL) {
-			applog(LOG_WARNING, "No core");
-			free(sn);
-			break;
-		}
-
 		if (debugging) {
 			char nhost[41];
 			char nport[6];
@@ -371,12 +364,49 @@ void stor_add_node(uint32_t nid, const char *hostname, const char *portstr,
 			}
 		}
 
-		list_add(&sn->all_link, &tabled_srv.all_stor);
-		tabled_srv.num_stor++;
+		/* Use just the first address for now. */
+		freeaddrinfo(res0);
+		return 0;
 	}
 
 	freeaddrinfo(res0);
-	return;
+
+	applog(LOG_WARNING, "No useful addresses for host %s port %s",
+	       hostname, portstr);
+	return -1;
+}
+
+void stor_add_node(uint32_t nid, const char *hostname, const char *portstr,
+		   struct geo *locp)
+{
+	struct storage_node *sn;
+
+	sn = stor_node_by_nid(nid);
+	if (sn) {
+		stor_add_node_addr(sn, hostname, portstr);
+	} else {
+		if ((sn = malloc(sizeof(struct storage_node))) == NULL) {
+			applog(LOG_WARNING, "No core (%ld)",
+			       (long) sizeof(struct storage_node));
+			return;
+		}
+		memset(sn, 0, sizeof(struct storage_node));
+		sn->id = nid;
+
+		if ((sn->hostname = strdup(hostname)) == NULL) {
+			applog(LOG_WARNING, "No core");
+			free(sn);
+			return;
+		}
+
+		if (stor_add_node_addr(sn, hostname, portstr)) {
+			free(sn);
+			return;
+		}
+
+		list_add(&sn->all_link, &tabled_srv.all_stor);
+		tabled_srv.num_stor++;
+	}
 }
 
 /* Return 0 if the node checks out ok */

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-09-17  7:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-09-17  6:23 [Patch 2/2] tabled: check for duplicate NID Pete Zaitcev
2009-09-17  7:12 ` Jeff Garzik

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.