[DRBD-cvs] svn commit by phil - r2445 - in trunk: . drbd drbd/linux scripts user - * renamed the after-sb-handler panic-primary etc... to

drbd-cvs at lists.linbit.com drbd-cvs at lists.linbit.com
Thu Sep 21 15:52:31 CEST 2006


Author: phil
Date: 2006-09-21 15:52:30 +0200 (Thu, 21 Sep 2006)
New Revision: 2445

Modified:
   trunk/ROADMAP
   trunk/drbd/drbd_nl.c
   trunk/drbd/drbd_receiver.c
   trunk/drbd/linux/drbd.h
   trunk/drbd/linux/drbd_nl.h
   trunk/scripts/drbd.conf
   trunk/user/drbdsetup.c
Log:
* renamed the after-sb-handler panic-primary etc... to 
  "call-pri-lost-after-sb". 
* Imrpoved the "events" mechanism to communicate all those
  places where we call user space helpers as well.
* removed two calls of drbd_panic()    


Modified: trunk/ROADMAP
===================================================================
--- trunk/ROADMAP	2006-09-21 12:03:54 UTC (rev 2444)
+++ trunk/ROADMAP	2006-09-21 13:52:30 UTC (rev 2445)
@@ -58,17 +58,23 @@
                       the current secondary's data. Otherwise disconnect.
      "discard-secondary"     
                       discard the version of the secondary.
-     "panic-primary"  Always honour the outcome of the "after-sb-2sc"
+     "call-pri-lost-after-sb"    
+                      Always honour the outcome of the "after-sb-2sc"
                       algorithm. In case it decides that the current
                       secondary has the right data, it tries to make
                       the current primary secondary, if that fails 
-                      it panics the current primary.
+                      it calls the "pri-lost-after-sb" helper program
+                      on the current primary. That helper program is
+                      expected to halt the machine.
 
   In case both nodes are primary you control DRBD's strategy by
   the "after-sb-2pri" option.
      "disconnect" ... Go to StandAlone mode on both sides.
-     "panic"      ... Honor the outcome of the "after-sb-0pri" algorithm
-                      and panic the other node.
+     "call-pri-lost-after-sb"
+	              Honor the outcome of the "after-sb-0pri" algorithm
+                      and calls the "pri-lost-after-sb" program on the
+		      other node. That helper program is expected to
+                      halt the machine.
 
   Defaults:
   after-sb-0pri = disconnect;

Modified: trunk/drbd/drbd_nl.c
===================================================================
--- trunk/drbd/drbd_nl.c	2006-09-21 12:03:54 UTC (rev 2444)
+++ trunk/drbd/drbd_nl.c	2006-09-21 13:52:30 UTC (rev 2445)
@@ -117,6 +117,7 @@
 
 
 extern void drbd_init_set_defaults(drbd_dev *mdev);
+void drbd_bcast_ev_helper(drbd_dev *mdev, char* helper_name);
 void drbd_nl_send_reply(struct cn_msg *, int);
 
 
@@ -130,6 +131,8 @@
 				NULL };
 
 	snprintf(mb,12,"minor-%d",mdev_to_minor(mdev));
+
+	drbd_bcast_ev_helper(mdev,cmd);
 	return call_usermodehelper("/sbin/drbdadm",argv,envp,1);
 }
 
@@ -1507,6 +1510,7 @@
 	}
 	reply = (struct drbd_nl_cfg_reply*) cn_reply->data;
 
+	reply->packet_type = cm->reply_body_size ? nlp->packet_type : P_nl_after_last_packet;
 	reply->minor = nlp->drbd_minor;
 	reply->ret_code = NoError; // Might by modified by cm->function.
 	// reply->tag_list; might be modified by cm->fucntion.
@@ -1531,6 +1535,8 @@
 	module_put(THIS_MODULE);
 }
 
+atomic_t drbd_nl_seq = ATOMIC_INIT(2); // two.
+
 void drbd_bcast_state(drbd_dev *mdev)
 {
 	char buffer[sizeof(struct cn_msg)+
@@ -1539,7 +1545,6 @@
 	struct cn_msg *cn_reply = (struct cn_msg *) buffer;
 	struct drbd_nl_cfg_reply* reply = (struct drbd_nl_cfg_reply*)cn_reply->data;
 	unsigned short *tl = reply->tag_list;
-	static atomic_t seq = ATOMIC_INIT(2); // two.
 
 	// WARN("drbd_bcast_state() got called\n");
 
@@ -1549,18 +1554,54 @@
 	cn_reply->id.idx = CN_IDX_DRBD;
 	cn_reply->id.val = CN_VAL_DRBD;
 
-	cn_reply->seq = atomic_add_return(1,&seq);
+	cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
 	cn_reply->ack = 0; // not used here.
 	cn_reply->len = sizeof(struct drbd_nl_cfg_reply) + 
 		(int)((char*)tl - (char*)reply->tag_list);
 	cn_reply->flags = 0;
 
+	reply->packet_type = P_get_state;
 	reply->minor = mdev_to_minor(mdev);
 	reply->ret_code = NoError;
 
 	cn_netlink_send(cn_reply, CN_IDX_DRBD, GFP_KERNEL);
 }
 
+void drbd_bcast_ev_helper(drbd_dev *mdev, char* helper_name)
+{
+	char buffer[sizeof(struct cn_msg)+
+		    sizeof(struct drbd_nl_cfg_reply)+
+		    sizeof(struct call_helper_tag_len_struct)];
+	struct cn_msg *cn_reply = (struct cn_msg *) buffer;
+	struct drbd_nl_cfg_reply* reply = (struct drbd_nl_cfg_reply*)cn_reply->data;
+	unsigned short *tl = reply->tag_list;
+	int str_len;
+
+	// WARN("drbd_bcast_state() got called\n");
+
+	str_len = strlen(helper_name)+1;
+	*tl++ = T_helper;
+	*tl++ = str_len;
+	memcpy(tl,helper_name,str_len);
+	tl=(unsigned short*)((char*)tl + str_len);
+	*tl++ = TT_END; /* Close the tag list */
+
+	cn_reply->id.idx = CN_IDX_DRBD;
+	cn_reply->id.val = CN_VAL_DRBD;
+
+	cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
+	cn_reply->ack = 0; // not used here.
+	cn_reply->len = sizeof(struct drbd_nl_cfg_reply) + 
+		(int)((char*)tl - (char*)reply->tag_list);
+	cn_reply->flags = 0;
+
+	reply->packet_type = P_call_helper;
+	reply->minor = mdev_to_minor(mdev);
+	reply->ret_code = NoError;
+
+	cn_netlink_send(cn_reply, CN_IDX_DRBD, GFP_KERNEL);
+}
+
 #ifdef NETLINK_ROUTE6 
 int __init cn_init(void);
 void __exit cn_fini(void);

Modified: trunk/drbd/drbd_receiver.c
===================================================================
--- trunk/drbd/drbd_receiver.c	2006-09-21 12:03:54 UTC (rev 2444)
+++ trunk/drbd/drbd_receiver.c	2006-09-21 13:52:30 UTC (rev 2445)
@@ -1544,7 +1544,7 @@
 	switch ( mdev->net_conf->after_sb_0p ) {
 	case Consensus:
 	case DiscardSecondary:
-	case PanicPrimary:
+	case CallHelper:
 		ERR("Configuration error.\n");
 		break;
 	case Disconnect:
@@ -1611,13 +1611,12 @@
 		break;
 	case DiscardSecondary:
 		return mdev->state.role==Primary ? 1 : -1;
-	case PanicPrimary:
+	case CallHelper:
 		hg = drbd_asb_recover_0p(mdev);
 		if( hg == -1 && mdev->state.role==Primary) {
 			self = drbd_set_role(mdev,Secondary,0);
 			if (self != SS_Success) {
 				drbd_khelper(mdev,"pri-lost-after-sb");
-				drbd_panic("Panic by after-sb-1pri handler\n");
 			} else {
 				WARN("Sucessfully gave up primary role.\n");
 				rv = hg;
@@ -1646,13 +1645,12 @@
 		break;
 	case Disconnect:
 		break;
-	case PanicPrimary:
+	case CallHelper:
 		hg = drbd_asb_recover_0p(mdev);
 		if( hg == -1 ) {
 			self = drbd_set_role(mdev,Secondary,0);
 			if (self != SS_Success) {
 				drbd_khelper(mdev,"pri-lost-after-sb");
-				drbd_panic("Panic by after-sb-2pri handler\n");
 			} else {
 				WARN("Sucessfully gave up primary role.\n");
 				rv = hg;

Modified: trunk/drbd/linux/drbd.h
===================================================================
--- trunk/drbd/linux/drbd.h	2006-09-21 12:03:54 UTC (rev 2444)
+++ trunk/drbd/linux/drbd.h	2006-09-21 13:52:30 UTC (rev 2445)
@@ -60,7 +60,7 @@
 	DiscardRemote,
 	Consensus,
 	DiscardSecondary,
-	PanicPrimary
+	CallHelper
 };
 
 /* KEEP the order, do not delete or insert!
@@ -260,6 +260,7 @@
 };
 
 struct drbd_nl_cfg_reply {
+	int packet_type;
 	int minor;
 	int ret_code; // enum ret_code or set_st_err_t
 	unsigned short tag_list[]; // only used with get_* calls

Modified: trunk/drbd/linux/drbd_nl.h
===================================================================
--- trunk/drbd/linux/drbd_nl.h	2006-09-21 12:03:54 UTC (rev 2444)
+++ trunk/drbd/linux/drbd_nl.h	2006-09-21 13:52:30 UTC (rev 2445)
@@ -83,6 +83,10 @@
 	BIT(		36,	T_MAY_IGNORE,	use_degraded)
 )
 
+PACKET(call_helper,
+	STRING(		38,	T_MAY_IGNORE,	helper,		32)
+)
+
 #undef PACKET
 #undef INTEGER
 #undef INT64

Modified: trunk/scripts/drbd.conf
===================================================================
--- trunk/scripts/drbd.conf	2006-09-21 12:03:54 UTC (rev 2444)
+++ trunk/scripts/drbd.conf	2006-09-21 13:52:30 UTC (rev 2445)
@@ -136,11 +136,11 @@
   handlers {
     # what should be done in case the node is primary, degraded
     # (=no connection) and has inconsistent data.
-    pri-on-incon-degr "halt -f";
+    pri-on-incon-degr "echo O > /proc/sysrq-trigger ; halt -f";
 
     # The node is currently primary, but lost the after split brain
     # auto recovery procedure. As as consequence it should go away.
-    pri-lost-after-sb "halt -f";
+    pri-lost-after-sb "echo O > /proc/sysrq-trigger ; halt -f";
 
     # Commands to run in case we need to downgrade the peer's disk 
     # state to "Outdated". Should be implemented by the superior

Modified: trunk/user/drbdsetup.c
===================================================================
--- trunk/user/drbdsetup.c	2006-09-21 12:03:54 UTC (rev 2444)
+++ trunk/user/drbdsetup.c	2006-09-21 13:52:30 UTC (rev 2445)
@@ -179,9 +179,9 @@
 void show_string(struct drbd_option *od, unsigned short* tp);
 
 // sub functions for events_cmd
-int print_state(unsigned int seq, int minor, drbd_state_t ns);
-int w_connected_state(unsigned int seq, int minor, drbd_state_t ns);
-int w_synced_state(unsigned int seq, int minor, drbd_state_t ns);
+int print_state(unsigned int seq, struct drbd_nl_cfg_reply *reply);
+int w_connected_state(unsigned int seq, struct drbd_nl_cfg_reply *reply);
+int w_synced_state(unsigned int seq, struct drbd_nl_cfg_reply *reply);
 
 const char *on_error[] = {
 	[PassOn] = "pass_on",
@@ -208,12 +208,12 @@
 	[Disconnect]        = "disconnect",
 	[Consensus]         = "consensus",
 	[DiscardSecondary]  = "discard-secondary",
-	[PanicPrimary]      = "panic-primary"
+	[CallHelper]        = "call-pri-lost-after-sb"
 };
 
 const char *asb2p_n[] = {
 	[Disconnect]        = "disconnect",
-	[PanicPrimary]      = "panic"
+	[CallHelper]        = "call-pri-lost-after-sb"
 };
 
 struct option wait_cmds_options[] = {
@@ -1103,42 +1103,66 @@
 	return rv;
 }
 
-int print_state(unsigned int seq, int minor, drbd_state_t ns)
+int print_state(unsigned int seq, struct drbd_nl_cfg_reply *reply)
 {
-	/*char stime[20];
-	  time_t now;
-	  time(&now);
-	  strftime(stime,20,"%a %e %T",gmtime(&now)); */
+	drbd_state_t state;
+	char* str;
 
-	printf("%u ST %d { cs:%s st:%s/%s ds:%s/%s %c%c%c%c }\n",
-	       seq,
-	       minor,
-	       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' : '-' );
+	switch (reply->packet_type) {
+	case P_get_state:
+		if(consume_tag_int(T_state_i,reply->tag_list,(int*)&state.i)) {
+			printf("%u ST %d { cs:%s st:%s/%s ds:%s/%s %c%c%c%c }\n",
+			       seq,
+			       reply->minor,
+			       conns_to_name(state.conn),
+			       roles_to_name(state.role),
+			       roles_to_name(state.peer),
+			       disks_to_name(state.disk),
+			       disks_to_name(state.pdsk),
+			       state.susp ? 's' : 'r',
+			       state.aftr_isp ? 'a' : '-',
+			       state.peer_isp ? 'p' : '-',
+			       state.user_isp ? 'u' : '-' );
+		} else fprintf(stderr,"Missing tag !?\n");
+		break;
+	case P_call_helper:
+		if(consume_tag_string(T_helper,reply->tag_list,&str)) {
+			printf("%u UH %d %s\n", seq, reply->minor, str);
+		} else fprintf(stderr,"Missing tag !?\n");
+		break;
+	default:
+		printf("%u ?? %d <other message>\n",seq, reply->minor);
+		break;
+	}
 
 	return 1;
 }
 
-int w_connected_state(unsigned int seq __attribute((unused)), 
-		      int minor __attribute((unused)), 
-		      drbd_state_t ns)
+int w_connected_state(unsigned int seq __attribute((unused)),
+		      struct drbd_nl_cfg_reply *reply)
 {
-	if(ns.conn >= Connected) return 0;
+	drbd_state_t state;
+
+	if(reply->packet_type == P_get_state) {
+		if(consume_tag_int(T_state_i,reply->tag_list,(int*)&state.i)) {
+			if(state.conn >= Connected) return 0;
+		} else fprintf(stderr,"Missing tag !?\n");
+	}
+
 	return 1;
 }
 
 int w_synced_state(unsigned int seq __attribute((unused)), 
-		   int minor __attribute((unused)), 
-		   drbd_state_t ns)
+		   struct drbd_nl_cfg_reply *reply)
 {
-	if(ns.conn == Connected || ns.conn < Unconnected ) return 0;
+	drbd_state_t state;
+
+	if(reply->packet_type == P_get_state) {
+		if(consume_tag_int(T_state_i,reply->tag_list,(int*)&state.i)) {
+			if(state.conn == Connected || state.conn < Unconnected ) 
+				return 0;
+		} else fprintf(stderr,"Missing tag !?\n");
+	}
 	return 1;
 }
 
@@ -1151,7 +1175,6 @@
 	struct option *lo;
 	unsigned int seq=0;
 	int sk_nl,c,cont=1,rr;
-	drbd_state_t state;
 	int unfiltered=0, all_devices=0;
 	int wfc_timeout=0, degr_wfc_timeout=0,timeout_ms;
 	struct pollfd pfd;
@@ -1233,21 +1256,8 @@
 		if(!unfiltered && cn_reply->seq <= seq) continue;
 		seq = cn_reply->seq;
 
-		if(!consume_tag_int(T_state_i,reply->tag_list,(int*)&state.i)) {
-			if( all_devices || minor == reply->minor ) {
-				printf("%u ?? %d <other message>\n",cn_reply->seq,
-				       reply->minor);
-			}
-			continue;
-		}
-
-		if(dump_tag_list(reply->tag_list)) {
-			printf("# Found unknown tags, you should update your\n"
-			       "# userland tools\n");
-		}
-
 		if( all_devices || minor == reply->minor ) {
-			cont=cm->ep.proc_event(cn_reply->seq, reply->minor, state);
+			cont=cm->ep.proc_event(cn_reply->seq, reply);
 		}
 	} while(cont);
 



More information about the drbd-cvs mailing list