Rev 122: partial merge from volker (some overlaps removed) in http://samba.org/~tridge/ctdb

tridge at samba.org tridge at samba.org
Tue Apr 17 01:26:59 GMT 2007


------------------------------------------------------------
revno: 122
revision-id: tridge at samba.org-20070417012659-f05788b9fd8c5d2e
parent: tridge at samba.org-20070417012000-dd8a85395a077110
committer: Andrew Tridgell <tridge at samba.org>
branch nick: tridge
timestamp: Tue 2007-04-17 11:26:59 +1000
message:
  partial merge from volker (some overlaps removed)
modified:
  common/ctdb_daemon.c           ctdb_daemon.c-20070409200331-3el1kqgdb9m4ib0g-1
  common/ctdb_lockwait.c         ctdb_lockwait.c-20070416214118-n1aeonljj3vpdd9q-1
=== modified file 'common/ctdb_daemon.c'
--- a/common/ctdb_daemon.c	2007-04-14 21:41:35 +0000
+++ b/common/ctdb_daemon.c	2007-04-17 01:26:59 +0000
@@ -186,6 +186,24 @@
 	struct client_fetch_lock_data *fl_data;
 
 	ctdb_db = find_ctdb_db(client->ctdb, f->db_id);
+	if (ctdb_db == NULL) {
+		struct ctdb_reply_fetch_lock r;
+
+		ZERO_STRUCT(r);
+		r.hdr.length       = sizeof(r);
+		r.hdr.ctdb_magic   = CTDB_MAGIC;
+		r.hdr.ctdb_version = CTDB_VERSION;
+		r.hdr.operation    = CTDB_REPLY_FETCH_LOCK;
+		r.hdr.reqid        = f->hdr.reqid;
+		r.state            = -1;
+
+		/*
+		 * Ignore the result, there's not much we can do anyway.
+		 */
+		ctdb_queue_send(client->queue, (uint8_t *)&r.hdr,
+				r.hdr.length);
+		return;
+	}
 
 	key.dsize = f->keylen;
 	key.dptr = &f->key[0];
@@ -220,6 +238,12 @@
 	int res;
 
 	ctdb_db = find_ctdb_db(client->ctdb, f->db_id);
+	if (ctdb_db == NULL) {
+		ctdb_set_error(client->ctdb, "Could not find database %i",
+			       f->db_id);
+		res = -1;
+		goto done;
+	}
 
 	/* write the data to ltdb */
 	key.dsize = f->keylen;

=== modified file 'common/ctdb_lockwait.c'
--- a/common/ctdb_lockwait.c	2007-04-16 23:14:52 +0000
+++ b/common/ctdb_lockwait.c	2007-04-17 01:26:59 +0000
@@ -71,48 +71,54 @@
  */
 struct lockwait_handle *ctdb_lockwait(struct ctdb_db_context *ctdb_db,
 				      TDB_DATA key,
-				      void (*callback)(void *), void *private_data)
+				      void (*callback)(void *private_data),
+				      void *private_data)
 {
-	struct lockwait_handle *h;
+	struct lockwait_handle *result;
 	int ret;
 
-	h = talloc_zero(ctdb_db, struct lockwait_handle);
-	if (h == NULL) {
+	if (!(result = talloc_zero(ctdb_db, struct lockwait_handle))) {
 		return NULL;
 	}
 
-	ret = pipe(h->fd);
+	ret = pipe(result->fd);
+
 	if (ret != 0) {
-		talloc_free(h);
-		return NULL;
-	}
-
-	h->child = fork();
-	if (h->child == (pid_t)-1) {
-		close(h->fd[0]);
-		close(h->fd[1]);
-		talloc_free(h);
-		return NULL;
-	}
-
-	h->callback = callback;
-	h->private_data = private_data;
-
-	if (h->child == 0) {
-		struct tdb_context *tdb = ctdb_db->ltdb->tdb;
-		/* in child */
-		tdb_chainlock(tdb, key);
-		_exit(0);
-	}
-
-	close(h->fd[1]);
-	talloc_set_destructor(h, lockwait_destructor);
-
-	h->fde = event_add_fd(ctdb_db->ctdb->ev, h, h->fd[0], EVENT_FD_READ, lockwait_handler, h);
-	if (h->fde == NULL) {
-		talloc_free(h);
-		return NULL;
-	}
-
-	return h;
+		talloc_free(result);
+		return NULL;
+	}
+
+	result->child = fork();
+
+	if (result->child == (pid_t)-1) {
+		close(result->fd[0]);
+		close(result->fd[1]);
+		talloc_free(result);
+		return NULL;
+	}
+
+	result->callback = callback;
+	result->private_data = private_data;
+
+	if (result->child == 0) {
+		close(result->fd[0]);
+		/*
+		 * Do we need a tdb_reopen here?
+		 */
+		tdb_chainlock(ctdb_db->ltdb->tdb, key);
+		exit(0);
+	}
+
+	close(result->fd[1]);
+	talloc_set_destructor(result, lockwait_destructor);
+
+	result->fde = event_add_fd(ctdb_db->ctdb->ev, result, result->fd[0],
+				   EVENT_FD_READ, lockwait_handler,
+				   (void *)result);
+	if (result->fde == NULL) {
+		talloc_free(result);
+		return NULL;
+	}
+
+	return result;
 }



More information about the samba-cvs mailing list