[DRBD-cvs] drbd by phil; * atomic_dec(&mdev->ap_bio_cnt) -> dec_a...

drbd-user@lists.linbit.com drbd-user@lists.linbit.com
Fri, 21 May 2004 10:49:55 +0200 (CEST)


DRBD CVS committal

Author  : phil
Module  : drbd

Dir     : drbd/drbd


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


Log Message:
* atomic_dec(&mdev->ap_bio_cnt) -> dec_ap_bio(mdev)
  atomic_inc(&mdev->ap_bio_cnt) -> inc_ap_bio(mdev)

  The decrement inline is also does also do a wakeup on the cstate wait...

* Some comments describing what the counters are good for

* Added the wait_event( , ap_bio_cnt == 0 ) before sending the bitmap.

===================================================================
RCS file: /var/lib/cvs/drbd/drbd/drbd/Attic/drbd_dsender.c,v
retrieving revision 1.1.2.112
retrieving revision 1.1.2.113
diff -u -3 -r1.1.2.112 -r1.1.2.113
--- drbd_dsender.c	19 May 2004 16:58:08 -0000	1.1.2.112
+++ drbd_dsender.c	21 May 2004 08:49:50 -0000	1.1.2.113
@@ -175,7 +175,7 @@
 	} else {
 	pass_on:
 		req->master_bio->b_end_io(req->master_bio,uptodate);
-		atomic_dec(&mdev->ap_bio_cnt);
+		dec_ap_bio(mdev);
 
 		INVALIDATE_MAGIC(req);
 		mempool_free(req,drbd_request_mempool);
@@ -332,7 +332,7 @@
 	} else {
 	pass_on:
 		bio_endio(req->master_bio,req->master_bio->bi_size,error);
-		atomic_dec(&mdev->ap_bio_cnt);
+		dec_ap_bio(mdev);
 
 		INVALIDATE_MAGIC(req);
 		mempool_free(req,drbd_request_mempool);
@@ -371,7 +371,7 @@
 	     test_bit(PARTNER_DISKLESS,&mdev->flags) ) {
 		ERR("WE ARE LOST. Local IO failure, no peer.\n");
 		drbd_bio_endio(req->master_bio,0);
-		atomic_dec(&mdev->ap_bio_cnt);
+		dec_ap_bio(mdev);
 		mempool_free(req,drbd_request_mempool);
 		// TODO: Do something like panic() or shut_down_cluster().
 		return 1;
===================================================================
RCS file: /var/lib/cvs/drbd/drbd/drbd/drbd_int.h,v
retrieving revision 1.58.2.164
retrieving revision 1.58.2.165
diff -u -3 -r1.58.2.164 -r1.58.2.165
--- drbd_int.h	19 May 2004 16:58:09 -0000	1.58.2.164
+++ drbd_int.h	21 May 2004 08:49:50 -0000	1.58.2.165
@@ -682,11 +682,11 @@
 	unsigned int writ_cnt;
 	unsigned int al_writ_cnt;
 	unsigned int bm_writ_cnt;
-	atomic_t ap_bio_cnt;
-	atomic_t ap_pending_cnt;
-	atomic_t rs_pending_cnt;
-	atomic_t unacked_cnt;
-	atomic_t local_cnt;
+	atomic_t ap_bio_cnt;     // Requests we need to complete
+	atomic_t ap_pending_cnt; // AP data packes on the wire, ack expected
+	atomic_t rs_pending_cnt; // RS request/data packes onthe wire
+	atomic_t unacked_cnt;    // Need to send replys for
+	atomic_t local_cnt;      // Waiting for local disk to signal completion
 	spinlock_t req_lock;
 	spinlock_t tl_lock;
 	struct drbd_barrier* newest_barrier;
@@ -1186,6 +1186,19 @@
 	}
 
 	D_ASSERT(atomic_read(&mdev->local_cnt)>=0);
+}
+
+static inline void inc_ap_bio(drbd_dev* mdev)
+{
+	atomic_inc(&mdev->ap_bio_cnt);
+}
+
+static inline void dec_ap_bio(drbd_dev* mdev)
+{
+	if(atomic_dec_and_test(&mdev->ap_bio_cnt))
+		wake_up(&mdev->cstate_wait);
+
+	D_ASSERT(atomic_read(&mdev->ap_bio_cnt)>=0);
 }
 
 static inline void drbd_set_out_of_sync(drbd_dev* mdev,
===================================================================
RCS file: /var/lib/cvs/drbd/drbd/drbd/drbd_receiver.c,v
retrieving revision 1.97.2.161
retrieving revision 1.97.2.162
diff -u -3 -r1.97.2.161 -r1.97.2.162
--- drbd_receiver.c	19 May 2004 16:58:09 -0000	1.97.2.161
+++ drbd_receiver.c	21 May 2004 08:49:50 -0000	1.97.2.162
@@ -835,7 +835,7 @@
 
 	ok=(rr==data_size);
 	drbd_bio_endio(bio,ok);
-	atomic_dec(&mdev->ap_bio_cnt);
+	dec_ap_bio(mdev);
 
 	dec_ap_pending(mdev,HERE);
 	return ok;
@@ -1245,21 +1245,10 @@
 
 		if( sync ) {
 			if(have_good == 1) {
-				/*
-				 * receiver expects the whole bitmap in one go.
-				 * so get the data.mutex here.
-				 * set_cstate within the mutex to avoid a race
-				 * between up() and the
-				 * wait_event(cstate != WFBitMap*) condition
-				 * above.
-				 */
-				down(&mdev->data.mutex);
 				set_cstate(mdev,WFBitMapS);
-				/* FIXME, here we actually have to wait for
-				 * ap_bio_cnt == 0 and/or local_cnt == 0
-				 */
-				_drbd_send_bitmap(mdev);
-				up(&mdev->data.mutex);
+				wait_event(mdev->cstate_wait,
+				     atomic_read(&mdev->ap_bio_cnt)==0);
+				drbd_send_bitmap(mdev);
 			} else { // have_good == -1
 				if ( (mdev->state == Primary) &&
 				     (mdev->gen_cnt[Flags] & MDF_Consistent) ) {
@@ -1402,7 +1391,7 @@
 		bio = req->master_bio;
 
 		drbd_bio_IO_error(bio);
-		atomic_dec(&mdev->ap_bio_cnt);
+		dec_ap_bio(mdev);
 		dec_ap_pending(mdev,HERE);
 
 		INVALIDATE_MAGIC(req);
===================================================================
RCS file: /var/lib/cvs/drbd/drbd/drbd/drbd_req-2.4.c,v
retrieving revision 1.33.2.81
retrieving revision 1.33.2.82
diff -u -3 -r1.33.2.81 -r1.33.2.82
--- drbd_req-2.4.c	19 May 2004 16:58:09 -0000	1.33.2.81
+++ drbd_req-2.4.c	21 May 2004 08:49:50 -0000	1.33.2.82
@@ -85,7 +85,7 @@
 		// the other side!  See w_io_error()
 
 		drbd_bio_endio(req->master_bio,1);
-		atomic_dec(&mdev->ap_bio_cnt);
+		dec_ap_bio(mdev);
 		// The assumption is that we wrote it on the peer.
 
 // FIXME proto A and diskless :)
@@ -98,7 +98,7 @@
 	}
 
 	drbd_bio_endio(req->master_bio,uptodate);
-	atomic_dec(&mdev->ap_bio_cnt);
+	dec_ap_bio(mdev);
 
 	INVALIDATE_MAGIC(req);
 	mempool_free(req,drbd_request_mempool);
@@ -196,7 +196,9 @@
 
 	// down_read(mdev->device_lock);
 
-	wait_event( mdev->cstate_wait, (volatile int)(mdev->cstate < WFBitMapS || mdev->cstate > WFBitMapT) );
+	wait_event( mdev->cstate_wait,
+		    (volatile int)(mdev->cstate < WFBitMapS || 
+				   mdev->cstate > WFBitMapT) );
 
 	local = inc_local(mdev);
 	// FIXME special case handling of READA ??
@@ -251,7 +253,7 @@
 	/* we need to plug ALWAYS since we possibly need to kick lo_dev */
 	drbd_plug_device(mdev);
 
-	atomic_inc(&mdev->ap_bio_cnt);
+	inc_ap_bio(mdev);
 	if (remote) {
 		/* either WRITE and Connected,
 		 * or READ, and no local disk,