[DRBD-cvs] drbd by phil; Splitted pending_cnt into ap_pending_cnt...

drbd-user@lists.linbit.com drbd-user@lists.linbit.com
Wed, 21 Jan 2004 15:59:06 +0100 (CET)


DRBD CVS committal

Author  : phil
Module  : drbd

Dir     : drbd/drbd


Modified Files:
      Tag: rel-0_7-branch
	drbd_dsender.c drbd_fs.c drbd_int.h drbd_main.c drbd_proc.c 
	drbd_receiver.c drbd_req-2.4.c 


Log Message:
Splitted pending_cnt into ap_pending_cnt and rs_pending_cnt.
Changed drbd_set_state() to allow primary<->secondary transitions
during resync.

===================================================================
RCS file: /var/lib/cvs/drbd/drbd/drbd/Attic/drbd_dsender.c,v
retrieving revision 1.1.2.56
retrieving revision 1.1.2.57
diff -u -3 -r1.1.2.56 -r1.1.2.57
--- drbd_dsender.c	18 Jan 2004 19:43:02 -0000	1.1.2.56
+++ drbd_dsender.c	21 Jan 2004 14:59:05 -0000	1.1.2.57
@@ -102,7 +102,7 @@
         number = SLEEP_TIME*mdev->sync_conf.rate / ((BM_BLOCK_SIZE/1024)*HZ);
 
         if(number > 1000) number=1000;  // Remove later
-	if (atomic_read(&mdev->pending_cnt)>1200) {
+	if (atomic_read(&mdev->rs_pending_cnt)>1200) {
 		// INFO("pending cnt high -- throttling resync.\n");
 		goto requeue;
 	}
@@ -128,10 +128,10 @@
 		list_add(&pr->w.list,&mdev->resync_reads);
 		spin_unlock(&mdev->pr_lock);
 
-		inc_pending(mdev);
+		inc_rs_pending(mdev);
 		ERR_IF(!drbd_send_drequest(mdev,RSDataRequest,
 					   sector,size,(unsigned long)pr)) {
-			dec_pending(mdev,HERE);
+			dec_rs_pending(mdev,HERE);
 			return 0; // FAILED. worker will abort!
 		}
 	}
@@ -189,7 +189,7 @@
 	int ok;
 
 	drbd_rs_complete_io(mdev,DRBD_BH_SECTOR(&e->pbh));
-	inc_pending(mdev);
+	inc_rs_pending(mdev);
 	ok=drbd_send_block(mdev, DataReply, e);
 	dec_unacked(mdev,HERE); // THINK unconditional?
 
===================================================================
RCS file: /var/lib/cvs/drbd/drbd/drbd/drbd_fs.c,v
retrieving revision 1.28.2.45
retrieving revision 1.28.2.46
diff -u -3 -r1.28.2.45 -r1.28.2.46
--- drbd_fs.c	18 Jan 2004 10:12:38 -0000	1.28.2.45
+++ drbd_fs.c	21 Jan 2004 14:59:05 -0000	1.28.2.46
@@ -406,30 +406,9 @@
 
 	fsync_dev(MKDEV(MAJOR_NR, minor));
 
-		/* Wait until nothing is on the fly :) */
-		/* PRI -> SEC : TL is empty || cstate < connected
-		   SEC -> PRI : ES is empty || cstate < connected
-		     -> this should be the case anyway, becuase the
-			other one should be already in SEC state
-
-		   FIXME:
-		     The current implementation is full of races.
-		     Will do the right thing in 2.4 (using a rw-semaphore),
-		     for now it is good enough. (Do not panic, these races
-		     are not harmfull)
-		*/
-		/*
-		printk(KERN_ERR DEVICE_NAME "%d: set_state(%d,%d,%d,%d,%d)\n",
-		       minor,
-		       mdev->state,
-		       mdev->pending_cnt,
-		       mdev->unacked_cnt,
-		       mdev->epoch_size);
-		*/
-
+	/* Wait until nothing is on the fly :) */
 	if ( wait_event_interruptible( mdev->state_wait,
-		       atomic_read(&mdev->pending_cnt) == 0 &&
-		       atomic_read(&mdev->unacked_cnt) == 0 ) ) {
+			atomic_read(&mdev->ap_pending_cnt) == 0 ) ) {
 		return -EINTR;
 	}
 
===================================================================
RCS file: /var/lib/cvs/drbd/drbd/drbd/drbd_int.h,v
retrieving revision 1.58.2.99
retrieving revision 1.58.2.100
diff -u -3 -r1.58.2.99 -r1.58.2.100
--- drbd_int.h	18 Jan 2004 19:04:52 -0000	1.58.2.99
+++ drbd_int.h	21 Jan 2004 14:59:05 -0000	1.58.2.100
@@ -690,7 +690,8 @@
 	unsigned int writ_cnt;
 	unsigned int al_writ_cnt;
 	unsigned int bm_writ_cnt;
-	atomic_t pending_cnt;
+	atomic_t ap_pending_cnt;
+	atomic_t rs_pending_cnt;
 	atomic_t unacked_cnt;
 	spinlock_t req_lock;
 	spinlock_t tl_lock;
@@ -1075,20 +1076,35 @@
 	_drbd_thread_stop(thi,TRUE,FALSE);
 }
 
-static inline void inc_pending(drbd_dev* mdev)
+static inline void inc_ap_pending(drbd_dev* mdev)
 {
-	atomic_inc(&mdev->pending_cnt);
+	atomic_inc(&mdev->ap_pending_cnt);
 }
 
-static inline void dec_pending(drbd_dev* mdev, const char* where)
+static inline void dec_ap_pending(drbd_dev* mdev, const char* where)
 {
-	if(atomic_dec_and_test(&mdev->pending_cnt))
+	if(atomic_dec_and_test(&mdev->ap_pending_cnt))
 		wake_up_interruptible(&mdev->state_wait);
 
-	if(atomic_read(&mdev->pending_cnt)<0) /* CHK */
+	if(atomic_read(&mdev->ap_pending_cnt)<0)
 		ERR("in %s: pending_cnt = %d < 0 !\n",
 		    where,
-		    atomic_read(&mdev->pending_cnt));
+		    atomic_read(&mdev->ap_pending_cnt));
+}
+
+static inline void inc_rs_pending(drbd_dev* mdev)
+{
+	atomic_inc(&mdev->rs_pending_cnt);
+}
+
+static inline void dec_rs_pending(drbd_dev* mdev, const char* where)
+{
+	atomic_dec(&mdev->rs_pending_cnt);
+
+	if(atomic_read(&mdev->rs_pending_cnt)<0) 
+		ERR("in %s: rs_pending_cnt = %d < 0 !\n",
+		    where,
+		    atomic_read(&mdev->unacked_cnt));
 }
 
 static inline void inc_unacked(drbd_dev* mdev)
@@ -1098,10 +1114,9 @@
 
 static inline void dec_unacked(drbd_dev* mdev,const char* where)
 {
-	if(atomic_dec_and_test(&mdev->unacked_cnt))
-		wake_up_interruptible(&mdev->state_wait);
+	atomic_dec(&mdev->unacked_cnt);
 
-	if(atomic_read(&mdev->unacked_cnt)<0)  /* CHK */
+	if(atomic_read(&mdev->unacked_cnt)<0)
 		ERR("in %s: unacked_cnt = %d < 0 !\n",
 		    where,
 		    atomic_read(&mdev->unacked_cnt));
===================================================================
RCS file: /var/lib/cvs/drbd/drbd/drbd/drbd_main.c,v
retrieving revision 1.73.2.101
retrieving revision 1.73.2.102
diff -u -3 -r1.73.2.101 -r1.73.2.102
--- drbd_main.c	18 Jan 2004 19:04:52 -0000	1.73.2.101
+++ drbd_main.c	21 Jan 2004 14:59:05 -0000	1.73.2.102
@@ -33,18 +33,6 @@
 
  */
 
-
-/*
-  By introducing a "Shared" state beside "Primary" and "Secondary" for
-  use with GFS at least the following items need to be done.
-  *) transfer_log and epoch_set reside in the same memory now.
-  *) writes on the receiver side must be done with a temporary
-     buffer_head directly to the lower level device.
-     Otherwise we would get in an endless loop sending the same
-     block over all the time.
-  *) All occurences of "Primary" or "Secondary" must be reviewed.
-*/
-
 #ifdef HAVE_AUTOCONF
 #include <linux/autoconf.h>
 #endif
@@ -601,9 +589,9 @@
 	/* tl_add_barrier() must be called with the sock_mutex aquired */
 	p.barrier=tl_add_barrier(mdev);
 
-	inc_pending(mdev);
+	inc_ap_pending(mdev);
 	ok = _drbd_send_cmd(mdev,mdev->data.socket,Barrier,(Drbd_Header*)&p,sizeof(p),0);
-	if (!ok) dec_pending(mdev,HERE);
+	if (!ok) dec_ap_pending(mdev,HERE);
 	return ok;
 }
 
@@ -1003,7 +991,8 @@
 	mdev->o_state              = Unknown;
 	mdev->cstate               = Unconfigured;
 
-	atomic_set(&mdev->pending_cnt,0);
+	atomic_set(&mdev->ap_pending_cnt,0);
+	atomic_set(&mdev->rs_pending_cnt,0);
 	atomic_set(&mdev->unacked_cnt,0);
 
 	init_MUTEX(&mdev->device_mutex);
===================================================================
RCS file: /var/lib/cvs/drbd/drbd/drbd/drbd_proc.c,v
retrieving revision 1.8.2.15
retrieving revision 1.8.2.16
diff -u -3 -r1.8.2.15 -r1.8.2.16
--- drbd_proc.c	12 Dec 2003 09:59:36 -0000	1.8.2.15
+++ drbd_proc.c	21 Jan 2004 14:59:05 -0000	1.8.2.16
@@ -184,7 +184,8 @@
 			   drbd_conf[i].read_cnt/2,
 			   drbd_conf[i].al_writ_cnt,
  			   drbd_conf[i].bm_writ_cnt,
- 			   atomic_read(&drbd_conf[i].pending_cnt),
+			   atomic_read(&drbd_conf[i].ap_pending_cnt) +
+			   atomic_read(&drbd_conf[i].rs_pending_cnt),
 			   atomic_read(&drbd_conf[i].unacked_cnt)
 			);
 
===================================================================
RCS file: /var/lib/cvs/drbd/drbd/drbd/drbd_receiver.c,v
retrieving revision 1.97.2.88
retrieving revision 1.97.2.89
diff -u -3 -r1.97.2.88 -r1.97.2.89
--- drbd_receiver.c	18 Jan 2004 10:12:38 -0000	1.97.2.88
+++ drbd_receiver.c	21 Jan 2004 14:59:05 -0000	1.97.2.89
@@ -885,7 +885,7 @@
 	ok=(rr==data_size);
 	bh->b_end_io(bh,ok);
 
-	dec_pending(mdev,HERE);
+	dec_ap_pending(mdev,HERE);
 	return ok;
 }
 
@@ -917,7 +917,7 @@
 	list_add(&e->w.list,&mdev->sync_ee);
 	spin_unlock_irq(&mdev->ee_lock);
 
-	dec_pending(mdev,HERE);
+	dec_rs_pending(mdev,HERE);
 	inc_unacked(mdev);
 
 	generic_make_request(WRITE,&e->pbh);
@@ -968,7 +968,8 @@
 	list_add(&e->w.list,&mdev->sync_ee);
 	spin_unlock_irq(&mdev->ee_lock);
 
-	dec_pending(mdev,HERE);
+	dec_rs_pending(mdev,HERE);
+	dec_ap_pending(mdev,HERE);
 	inc_unacked(mdev);
 
 	generic_make_request(WRITE,&e->pbh);
@@ -995,8 +996,6 @@
 	drbd_put_ee(mdev,e);
 	spin_unlock_irq(&mdev->ee_lock);
 
-	dec_pending(mdev,HERE);
-
 	return TRUE;
 }
 
@@ -1409,7 +1408,16 @@
 		list_del(le);
 
 		bh->b_end_io(bh,0);
-		dec_pending(mdev,HERE);
+		switch(pr->cause) {
+		case Application:
+			dec_ap_pending(mdev,HERE);
+			break;
+		case AppAndResync:
+			dec_ap_pending(mdev,HERE);
+		case Resync:
+			dec_rs_pending(mdev,HERE);
+		case Discard:
+		}
 
 		INVALIDATE_MAGIC(pr);
 		mempool_free(pr,drbd_pr_mempool);
@@ -1573,22 +1581,17 @@
 
 	drbd_fail_pending_reads(mdev);
 
-	switch(mdev->state) {
-	case Primary:
-		tl_clear(mdev);
-		clear_bit(ISSUE_BARRIER,&mdev->flags);
+	tl_clear(mdev);
+	clear_bit(ISSUE_BARRIER,&mdev->flags);
+	drbd_wait_ee(mdev,&mdev->active_ee);
+	drbd_wait_ee(mdev,&mdev->sync_ee);
+	drbd_clear_done_ee(mdev);
+	mdev->epoch_size=0;
+
+	if (mdev->state == Primary) {
 		if(!test_bit(DO_NOT_INC_CONCNT,&mdev->flags))
 			drbd_md_inc(mdev,ConnectedCnt);
 		drbd_md_write(mdev);
-		break;
-	case Secondary:
-		drbd_wait_ee(mdev,&mdev->active_ee);
-		drbd_wait_ee(mdev,&mdev->sync_ee);
-		drbd_clear_done_ee(mdev);
-		mdev->epoch_size=0;
-		break;
-	default:
-		D_ASSERT(0);
 	}
 
 	if(atomic_read(&mdev->unacked_cnt)) {
@@ -1598,7 +1601,8 @@
 
 	/* Since syncer's blocks are also counted, there is no hope that
 	   pending_cnt is zero. */
-	atomic_set(&mdev->pending_cnt,0);
+	atomic_set(&mdev->ap_pending_cnt,0);
+	atomic_set(&mdev->rs_pending_cnt,0);
 	wake_up_interruptible(&mdev->state_wait);
 
 	clear_bit(DO_NOT_INC_CONCNT,&mdev->flags);
@@ -1691,11 +1695,12 @@
 	    be32_to_cpu(p->blksize));*/
 
 	// TODO: Make sure that the block is in an active epoch!!
-	if(mdev->conf.wire_protocol != DRBD_PROT_A ||
-	   is_syncer_blk(mdev,p->block_id)) {
-		dec_pending(mdev,HERE);
+	if(is_syncer_blk(mdev,p->block_id)) {
+		dec_rs_pending(mdev,HERE);
+	} else {
+		D_ASSERT(mdev->conf.wire_protocol != DRBD_PROT_A);
+		dec_ap_pending(mdev,HERE);
 	}
-
 	return TRUE;
 }
 
@@ -1704,7 +1709,7 @@
 	Drbd_BarrierAck_Packet *p = (Drbd_BarrierAck_Packet*)h;
 
 	tl_release(mdev,p->barrier,be32_to_cpu(p->set_size));
-	dec_pending(mdev,HERE);
+	dec_ap_pending(mdev,HERE);
 
 	return TRUE;
 }
===================================================================
RCS file: /var/lib/cvs/drbd/drbd/drbd/drbd_req-2.4.c,v
retrieving revision 1.33.2.38
retrieving revision 1.33.2.39
diff -u -3 -r1.33.2.38 -r1.33.2.39
--- drbd_req-2.4.c	16 Jan 2004 13:26:43 -0000	1.33.2.38
+++ drbd_req-2.4.c	21 Jan 2004 14:59:05 -0000	1.33.2.39
@@ -140,12 +140,15 @@
 	SET_MAGIC(pr);
 
 	pr->d.bh = bh;
+	// TODO: should only issue AppAndResnc if it is out of sync!
 	pr->cause = mdev->cstate == SyncTarget ? AppAndResync : Application;
 	spin_lock(&mdev->pr_lock);
 	list_add(&pr->w.list,&mdev->app_reads);
 	spin_unlock(&mdev->pr_lock);
-	inc_pending(mdev);
-	drbd_send_drequest(mdev, mdev->cstate == SyncTarget ? RSDataRequest : DataRequest,
+	inc_ap_pending(mdev);
+	if(pr->cause == AppAndResync) inc_rs_pending(mdev);
+	drbd_send_drequest(mdev, 
+			   pr->cause==AppAndResync ? RSDataRequest:DataRequest,
 			   bh->b_rsector, bh->b_size,
 			   (unsigned long)pr);
 }
@@ -183,7 +186,7 @@
 			req->bh=bh;
 
 			if(mdev->conf.wire_protocol != DRBD_PROT_A) {
-				inc_pending(mdev);
+				inc_ap_pending(mdev);
 			}
 			drbd_send_dblock(mdev,req); // FIXME error check?
 		} else { // rw == READ || rw == READA
@@ -203,6 +206,7 @@
 				ERR("Will discard a resync_read\n");
 				pr->cause = Discard;
 				// list del as well ?
+				dec_rs_pending(mdev,HERE);
 			}
 			spin_unlock(&mdev->pr_lock);
 
@@ -216,6 +220,7 @@
 				ERR("Upgraded a resync read to an app read\n");
 
 				pr->cause |= Application;
+				inc_ap_pending(mdev);
 				pr->d.bh=bh;
 				list_del(&pr->w.list);
 				list_add(&pr->w.list,&mdev->app_reads);
@@ -281,7 +286,7 @@
 
 	send_ok=drbd_send_dblock(mdev,req);
 	// FIXME we could remove the send_ok cases, the are redundant to tl_clear()
-	if(send_ok && mdev->conf.wire_protocol!=DRBD_PROT_A) inc_pending(mdev);
+	if(send_ok && mdev->conf.wire_protocol!=DRBD_PROT_A) inc_ap_pending(mdev);
 	if(mdev->conf.wire_protocol==DRBD_PROT_A || (!send_ok) ) {
 				/* If sending failed, we can not expect
 				   an ack packet. */