s3: Do not connect to ctdb if it is blocked for some reason
authorVolker Lendecke <vl@samba.org>
Mon, 16 Nov 2009 11:03:24 +0000 (12:03 +0100)
committerMichael Adam <obnox@samba.org>
Wed, 10 Mar 2010 12:22:19 +0000 (13:22 +0100)
source3/lib/ctdbd_conn.c

index 291fa3c8e4e972b5846f2df4e1ce96a0b4e90f66..9101bd429cbda0c80c01aa0a0d39ee9ee5ba5cc4 100644 (file)
@@ -104,6 +104,59 @@ static NTSTATUS get_cluster_vnn(struct ctdbd_connection *conn, uint32 *vnn)
        return status;
 }
 
+/*
+ * Are we active (i.e. not banned or stopped?)
+ */
+static bool ctdbd_working(struct ctdbd_connection *conn, uint32_t vnn)
+{
+       int32_t cstatus=-1;
+       NTSTATUS status;
+       TDB_DATA outdata;
+       struct ctdb_node_map *m;
+       uint32_t failure_flags;
+       bool ret = false;
+       int i;
+
+       status = ctdbd_control(conn, CTDB_CURRENT_NODE,
+                              CTDB_CONTROL_GET_NODEMAP, 0, 0,
+                              tdb_null, talloc_tos(), &outdata, &cstatus);
+       if (!NT_STATUS_IS_OK(status)) {
+               cluster_fatal("ctdbd_control failed\n");
+       }
+       if ((cstatus != 0) || (outdata.dptr == NULL)) {
+               DEBUG(2, ("Received invalid ctdb data\n"));
+               return false;
+       }
+
+       m = (struct ctdb_node_map *)outdata.dptr;
+
+       for (i=0; i<m->num; i++) {
+               if (vnn == m->nodes[i].pnn) {
+                       break;
+               }
+       }
+
+       if (i == m->num) {
+               DEBUG(2, ("Did not find ourselves (node %d) in nodemap\n",
+                         (int)vnn));
+               goto fail;
+       }
+
+       failure_flags = NODE_FLAGS_BANNED | NODE_FLAGS_DISCONNECTED
+               | NODE_FLAGS_PERMANENTLY_DISABLED | NODE_FLAGS_STOPPED;
+
+       if ((m->nodes[i].flags & failure_flags) != 0) {
+               DEBUG(2, ("Node has status %x, not active\n",
+                         (int)m->nodes[i].flags));
+               goto fail;
+       }
+
+       ret = true;
+fail:
+       TALLOC_FREE(outdata.dptr);
+       return ret;;
+}
+
 uint32 ctdbd_vnn(const struct ctdbd_connection *conn)
 {
        return conn->our_vnn;
@@ -448,6 +501,11 @@ NTSTATUS ctdbd_init_connection(TALLOC_CTX *mem_ctx,
                goto fail;
        }
 
+       if (!ctdbd_working(conn, conn->our_vnn)) {
+               DEBUG(2, ("Node is not working, can not connect\n"));
+               goto fail;
+       }
+
        generate_random_buffer((unsigned char *)&conn->rand_srvid,
                               sizeof(conn->rand_srvid));