[DRBD-cvs] svn commit by phil - r2273 - trunk/testing - First thoughts about testing DRBD's state mechanism.

drbd-cvs at lists.linbit.com drbd-cvs at lists.linbit.com
Wed Jul 12 18:44:42 CEST 2006


Author: phil
Date: 2006-07-12 18:44:41 +0200 (Wed, 12 Jul 2006)
New Revision: 2273

Added:
   trunk/testing/drbd_states.c
Modified:
   trunk/testing/Makefile
Log:
First thoughts about testing DRBD's state mechanism.


Modified: trunk/testing/Makefile
===================================================================
--- trunk/testing/Makefile	2006-07-12 09:51:26 UTC (rev 2272)
+++ trunk/testing/Makefile	2006-07-12 16:44:41 UTC (rev 2273)
@@ -7,3 +7,6 @@
 	rm -f $(PROGRAMS)
 
 distclean: clean
+
+drbd_states: drbd_states.o ../drbd/linux/drbd.h ../drbd/drbd_strings.o
+	gcc -o drbd_states drbd_states.o ../drbd/drbd_strings.o

Added: trunk/testing/drbd_states.c
===================================================================
--- trunk/testing/drbd_states.c	2006-07-12 09:51:26 UTC (rev 2272)
+++ trunk/testing/drbd_states.c	2006-07-12 16:44:41 UTC (rev 2273)
@@ -0,0 +1,117 @@
+/*
+ * A small program to enumerate all states considered by pre_state_checks() as
+ * valid, and to potentially improve that function.
+ */
+#include <stdio.h>
+#include <linux/drbd.h>
+
+#define STATIC static
+
+struct Drbd_Conf {
+	int dummy;
+};
+typedef struct Drbd_Conf drbd_dev;
+
+static void print_st(drbd_state_t ns, set_st_err_t rv)
+{
+	printf("{ cs:%s\tst:%s/%s\tds:%s/%s\t%c%c%c%c } = %s\n",
+	       conns_to_name(ns.conn),
+	       roles_to_name(ns.role),
+	       roles_to_name(ns.peer),
+	       disks_to_name(ns.disk),
+	       disks_to_name(ns.pdsk),
+	       ns.susp ? 's' : 'r',
+	       ns.aftr_isp ? 'a' : '-',
+	       ns.peer_isp ? 'p' : '-',
+	       ns.user_isp ? 'u' : '-',
+	       set_st_err_name(rv)
+	    );
+}
+
+
+STATIC int pre_state_checks(drbd_dev* mdev, drbd_state_t ns)
+{
+	/* See drbd_state_sw_errors in drbd_strings.c */
+
+	enum fencing_policy fp;
+	int rv=SS_Success;
+
+/*
+ 	fp = DontCare;
+	if(inc_local(mdev)) {
+		fp = mdev->bc->fencing;
+		dec_local(mdev);
+	}
+
+	if(inc_net(mdev)) {
+		if( !mdev->net_conf->two_primaries &&
+		    ns.role == Primary && ns.peer == Primary ) 
+			rv=SS_TowPrimaries;
+		dec_net(mdev);
+	}
+*/
+
+	if( rv <= 0 ) /* already found a reason to abort */;
+	else if( ns.role == Primary && ns.conn < Connected &&
+		 ns.disk < UpToDate ) rv=SS_NoUpToDateDisk;
+
+	else if( fp >= Resource &&
+		 ns.role == Primary && ns.conn < Connected &&
+		 ns.pdsk >= DUnknown ) rv=SS_PrimaryNOP;
+
+	else if( ns.role == Primary && ns.disk <= Inconsistent &&
+		 ns.pdsk <= Inconsistent ) rv=SS_NoUpToDateDisk;
+	
+	else if( ns.conn > Connected &&
+		 ns.disk < UpToDate && ns.pdsk < UpToDate ) 
+		rv=SS_BothInconsistent;
+
+	else if( ns.conn > Connected &&
+		 (ns.disk == Diskless || ns.pdsk == Diskless ) )
+		rv=SS_SyncingDiskless;
+
+	else if( (ns.conn == Connected ||
+		  ns.conn == SkippedSyncS ||
+		  ns.conn == WFBitMapS ||
+		  ns.conn == SyncSource ||
+		  ns.conn == PausedSyncS) &&
+		 ns.disk == Outdated ) rv=SS_ConnectedOutdates;
+
+	return rv;
+}
+
+
+int main(int argc, char **argv)
+{
+	drbd_role_t role, peer;
+	drbd_conns_t conn;
+	drbd_disks_t disk, pdsk;
+	drbd_state_t s;
+	int rv;
+	unsigned long all=0, valid=0;
+
+	for ( role = Primary ; role <= Secondary ; role++ ) {
+		for ( peer = Unknown ; peer <= Secondary ; peer++ ) {
+			for ( conn = StandAlone; conn <= PausedSyncT ; conn++ ) {
+				for ( disk = Diskless ; disk <= UpToDate ; disk++) {
+					for ( pdsk = Diskless ; pdsk <= UpToDate ; pdsk++) {
+						s = (drbd_state_t){{ role,peer,conn,disk,pdsk }};
+						rv = pre_state_checks(NULL,s);
+
+						all++;
+						if( rv == SS_Success ) {
+							print_st(s,rv);
+							valid++;
+						}
+					}
+				}
+			}
+		}
+	}
+
+	printf("states considered: %lu\n",all);
+	printf("valid(?) states: %lu\n",valid);
+
+	return 0;
+}
+



More information about the drbd-cvs mailing list