[DRBD-cvs] svn commit by phil - r2425 - in trunk: drbd drbd/linux user - * Fixed the attach process to a connected device pair.

drbd-cvs at lists.linbit.com drbd-cvs at lists.linbit.com
Fri Sep 15 11:43:54 CEST 2006


Author: phil
Date: 2006-09-15 11:43:51 +0200 (Fri, 15 Sep 2006)
New Revision: 2425

Modified:
   trunk/drbd/drbd_int.h
   trunk/drbd/drbd_main.c
   trunk/drbd/drbd_nl.c
   trunk/drbd/drbd_receiver.c
   trunk/drbd/drbd_strings.c
   trunk/drbd/linux/drbd.h
   trunk/user/drbdsetup.c
Log:
* Fixed the attach process to a connected device pair. In order to avoid
  that the disk state goes to "Consistent" or "UpToDate" temporaritly,
  I introduced a new disk state called "Negotiating". 
  Now the Disk state advances in the connected case like this: 
  Diskless -> Attaching -> Negotiating -> [ UpToDate | Inconsistent ... ]
  If there will be a resync we start this directly from the Negotiating
  state.

* If 'drbdsetup /dev/drbdX secondary' of a 'drbdsetup /dev/drbdX down'
  failes, fail the whole down command.



Modified: trunk/drbd/drbd_int.h
===================================================================
--- trunk/drbd/drbd_int.h	2006-09-14 15:04:05 UTC (rev 2424)
+++ trunk/drbd/drbd_int.h	2006-09-15 09:43:51 UTC (rev 2425)
@@ -782,6 +782,7 @@
 	struct timer_list resync_timer;
 	struct timer_list md_sync_timer;
 
+	drbd_state_t new_state_tmp; // Used after attach while negotiating new disk state.
 	drbd_state_t state;
 	wait_queue_head_t cstate_wait; // TODO Rename into "misc_wait".
 	wait_queue_head_t rq_wait;

Modified: trunk/drbd/drbd_main.c
===================================================================
--- trunk/drbd/drbd_main.c	2006-09-14 15:04:05 UTC (rev 2424)
+++ trunk/drbd/drbd_main.c	2006-09-15 09:43:51 UTC (rev 2425)
@@ -678,6 +678,12 @@
 		}
 	}
 
+	/* Connection breaks down before we finished "Negotiating" */
+	if (ns.conn < Connected && ns.disk == Negotiating ) {
+		ns.disk = mdev->new_state_tmp.disk;
+		ns.pdsk = mdev->new_state_tmp.pdsk;
+	}
+
 	if( fp == Stonith ) {
 		if(ns.role == Primary &&
 		   ns.conn < Connected &&
@@ -872,6 +878,13 @@
 		}
 	}
 
+	/* Last part of the attaching process ... */
+	if ( os.disk == Attaching && ns.disk == Negotiating ) {
+		drbd_send_sizes(mdev);  // to start sync...
+		drbd_send_uuids(mdev);
+		drbd_send_state(mdev);
+	}
+
 	/* We want to pause resync, tell peer. */
 	if (  ( os.aftr_isp == 0 && ns.aftr_isp == 1 ) ||
 	      ( os.user_isp == 0 && ns.user_isp == 1 ) ) {
@@ -1192,7 +1205,7 @@
 	Drbd_GenCnt_Packet p;
 	int i;
 
-	if(!inc_local(mdev)) return 1; // ok
+	if(!inc_local_if_state(mdev,Negotiating)) return 1; // ok.
 
 	for (i = Current; i < UUID_SIZE; i++) {
 		/* FIXME howto handle diskless ? */
@@ -1227,7 +1240,7 @@
 	int q_order_type;
 	int ok;
 
-	if(inc_local(mdev)) {
+	if(inc_local_if_state(mdev,Negotiating)) {
 		D_ASSERT(mdev->bc->backing_bdev);
 		d_size = drbd_get_max_capacity(mdev->bc);
 		u_size = mdev->bc->dc.disk_size;

Modified: trunk/drbd/drbd_nl.c
===================================================================
--- trunk/drbd/drbd_nl.c	2006-09-14 15:04:05 UTC (rev 2424)
+++ trunk/drbd/drbd_nl.c	2006-09-15 09:43:51 UTC (rev 2425)
@@ -821,53 +821,54 @@
 	     FIXME wipe out on disk al!
 	} */
 
-
-	if(mdev->state.conn == Connected) {
-		drbd_send_sizes(mdev);  // to start sync...
-		drbd_send_uuids(mdev);
-		drbd_send_state(mdev);
-	} else {
-		spin_lock_irq(&mdev->req_lock);
-		os = mdev->state;
-		ns.i = os.i;
-		/* If MDF_Consistent is not set go into inconsistent state, 
-		   otherwise investige MDF_WasUpToDate...
-		   If MDF_WasUpToDate is not set go into Outdated disk state, 
-		   otherwise into Consistent state.
-		*/
-		if(drbd_md_test_flag(mdev->bc,MDF_Consistent)) {
-			if(drbd_md_test_flag(mdev->bc,MDF_WasUpToDate)) {
-				ns.disk = Consistent;
-			} else {
-				ns.disk = Outdated;
-			}
+	spin_lock_irq(&mdev->req_lock);
+	os = mdev->state;
+	ns.i = os.i;
+	/* If MDF_Consistent is not set go into inconsistent state, 
+	   otherwise investige MDF_WasUpToDate...
+	   If MDF_WasUpToDate is not set go into Outdated disk state, 
+	   otherwise into Consistent state.
+	*/
+	if(drbd_md_test_flag(mdev->bc,MDF_Consistent)) {
+		if(drbd_md_test_flag(mdev->bc,MDF_WasUpToDate)) {
+			ns.disk = Consistent;
 		} else {
-			ns.disk = Inconsistent;
+			ns.disk = Outdated;
 		}
+	} else {
+		ns.disk = Inconsistent;
+	}
+	
+	if(drbd_md_test_flag(mdev->bc,MDF_PeerOutDated)) {
+		ns.pdsk = Outdated;
+	}
+	
+	if( ns.disk == Consistent && 
+	    ( ns.pdsk == Outdated || nbc->dc.fencing == DontCare ) ) {
+		ns.disk = UpToDate;
+	}
 
-		if(drbd_md_test_flag(mdev->bc,MDF_PeerOutDated)) {
-			ns.pdsk = Outdated;
-		}
+	/* All tests on MDF_PrimaryInd, MDF_ConnectedInd, 
+	   MDF_Consistent and MDF_WasUpToDate must happen before 
+	   this point, because drbd_request_state() modifies these
+	   flags. */
 
-		if( ns.disk == Consistent && 
-		    ( ns.pdsk == Outdated || nbc->dc.fencing == DontCare ) ) {
-			ns.disk = UpToDate;
-		}
-		
-		/* All tests on MDF_PrimaryInd, MDF_ConnectedInd, 
-		   MDF_Consistent and MDF_WasUpToDate must happen before 
-		   this point, because drbd_request_state() modifies these
-		   flags. */
+	/* In case we are Connected postpony any desicion on the new disk
+	   state after the negotiatin phase. */
+	if(mdev->state.conn == Connected) {
+		mdev->new_state_tmp.i = ns.i;
+		ns.i = os.i;
+		ns.disk = Negotiating;
+	}
 
-		rv = _drbd_set_state(mdev, ns, ChgStateVerbose);
-		ns = mdev->state;
-		spin_unlock_irq(&mdev->req_lock);
-		after_state_ch(mdev,os,ns,ChgStateVerbose);
+	rv = _drbd_set_state(mdev, ns, ChgStateVerbose);
+	ns = mdev->state;
+	spin_unlock_irq(&mdev->req_lock);
+	if (rv==SS_Success) after_state_ch(mdev,os,ns,ChgStateVerbose);
 
-		if(rv < SS_Success ) {
-			drbd_bm_unlock(mdev);
-			goto  release_bdev3_fail;
-		}
+	if(rv < SS_Success ) {
+		drbd_bm_unlock(mdev);
+		goto  release_bdev3_fail;
 	}
 
 	drbd_bm_unlock(mdev);

Modified: trunk/drbd/drbd_receiver.c
===================================================================
--- trunk/drbd/drbd_receiver.c	2006-09-14 15:04:05 UTC (rev 2424)
+++ trunk/drbd/drbd_receiver.c	2006-09-15 09:43:51 UTC (rev 2425)
@@ -2130,7 +2130,8 @@
 
 	peer_state.i = be32_to_cpu(p->state);
 
-	if (mdev->p_uuid && mdev->state.conn <= Connected && inc_local(mdev) ) {
+	if (mdev->p_uuid && mdev->state.conn <= Connected && 
+	    inc_local_if_state(mdev,Negotiating) ) {
 		nconn=drbd_sync_handshake(mdev,peer_state.role,peer_state.disk);
 		dec_local(mdev);
 
@@ -2145,11 +2146,13 @@
 		}
 	}
 
-        if ( peer_state.disk == Attaching && nconn == Connected ) {
-		// Peer should promote from Attaching to UpToDate.
+	/*
+        if ( peer_state.disk == Negotiating && nconn == Connected ) {
+		// Peer should promote from Negotiating to UpToDate.
 		drbd_send_state(mdev);
 		peer_state.disk = UpToDate;
 	}
+	*/
 
 	spin_lock_irq(&mdev->req_lock);
 	os = mdev->state;
@@ -2158,7 +2161,7 @@
 	ns.peer = peer_state.role;
 	ns.pdsk = peer_state.disk;
 	ns.peer_isp = ( peer_state.aftr_isp | peer_state.user_isp );
-	if(nconn == Connected && ns.disk == Consistent) ns.disk = UpToDate;
+	if(nconn == Connected && ns.disk == Negotiating ) ns.disk = UpToDate;
 	rv = _drbd_set_state(mdev,ns,ChgStateVerbose | ChgStateHard);
 	spin_unlock_irq(&mdev->req_lock);
 	if (rv==SS_Success) {

Modified: trunk/drbd/drbd_strings.c
===================================================================
--- trunk/drbd/drbd_strings.c	2006-09-14 15:04:05 UTC (rev 2424)
+++ trunk/drbd/drbd_strings.c	2006-09-15 09:43:51 UTC (rev 2425)
@@ -50,12 +50,13 @@
 };
 
 static const char *drbd_disk_s_names[] = {
-	[DUnknown]     = "DUnknown",
 	[Diskless]     = "Diskless",
+	[Attaching]    = "Attaching",
 	[Failed]       = "Failed",
-	[Attaching]    = "Attaching",
+	[Negotiating]  = "Negotiating",
 	[Inconsistent] = "Inconsistent",
 	[Outdated]     = "Outdated",
+	[DUnknown]     = "DUnknown",
 	[Consistent]   = "Consistent",
 	[UpToDate]     = "UpToDate",
 };

Modified: trunk/drbd/linux/drbd.h
===================================================================
--- trunk/drbd/linux/drbd.h	2006-09-14 15:04:05 UTC (rev 2424)
+++ trunk/drbd/linux/drbd.h	2006-09-15 09:43:51 UTC (rev 2425)
@@ -155,6 +155,7 @@
 	Attaching,      /* In the process of reading the meta-data */
 	Failed,         /* Becomes Diskless as soon as we told it the peer */
 			/* when >= Failed it is legal to access mdev->bc */
+	Negotiating,    /* Late attaching state, we need to talk to the peer... */
 	Inconsistent,
 	Outdated,
 	DUnknown,       /* Only used for the peer, never for myself */

Modified: trunk/user/drbdsetup.c
===================================================================
--- trunk/user/drbdsetup.c	2006-09-14 15:04:05 UTC (rev 2424)
+++ trunk/user/drbdsetup.c	2006-09-15 09:43:51 UTC (rev 2425)
@@ -1085,14 +1085,15 @@
 
 int down_cmd(struct drbd_cmd *cm, int minor, int argc, char **argv)
 {
-	int rv = 0;
+	int rv;
 
 	if(argc > 1) {
 		fprintf(stderr,"Ignoring excess arguments\n");	
 	}
 
 	cm = find_cmd_by_name("secondary");
-	rv |= cm->function(cm,minor,argc,argv);
+	rv = cm->function(cm,minor,argc,argv);
+	if( rv ) return rv;
 	cm = find_cmd_by_name("disconnect");
 	rv |= cm->function(cm,minor,argc,argv);
 	cm = find_cmd_by_name("detach");



More information about the drbd-cvs mailing list