[DRBD-cvs] drbd by phil; * one chunk of LGE's patch got lost in t...

drbd-user@lists.linbit.com drbd-user@lists.linbit.com
Tue, 15 Jun 2004 15:42:35 +0200 (CEST)


DRBD CVS committal

Author  : phil
Module  : drbd

Dir     : drbd/drbd


Modified Files:
      Tag: rel-0_7-branch
	drbd_actlog.c drbd_bitmap.c drbd_dsender.c drbd_int.h 


Log Message:
* one chunk of LGE's patch got lost in the merge process, applied
  this missing chunk (which deletes two functions)
* Added the drbd_bm_rs_done() thing again.
* Fixed the parameter types of drbd_bm_e_weight() and drbd_bm_e_set_all()
* Changed the __u64 to u64 in order to make it compile on the s390 arch.

===================================================================
RCS file: /var/lib/cvs/drbd/drbd/drbd/Attic/drbd_actlog.c,v
retrieving revision 1.1.2.105
retrieving revision 1.1.2.106
diff -u -3 -r1.1.2.105 -r1.1.2.106
--- drbd_actlog.c	15 Jun 2004 10:07:32 -0000	1.1.2.105
+++ drbd_actlog.c	15 Jun 2004 13:42:29 -0000	1.1.2.106
@@ -120,7 +120,7 @@
 	    sector > drbd_md_ss(mdev)+MD_BM_OFFSET+BM_SECT_TO_EXT(capacity)) {
 		ALERT("%s [%d]:%s(,%ld,%s) out of range md access!\n",
 		     current->comm, current->pid, __func__,
-		     sector, rw ? "WRITE" : "READ");
+		     (long)sector, rw ? "WRITE" : "READ");
 	}
 
 #ifdef BIO_RW_SYNC
@@ -517,105 +517,6 @@
 	}
 
 	wake_up(&mdev->al_wait);
-}
-
-/**
- * drbd_read_bm: Read the whole bitmap from its on disk location.
- */
-void drbd_read_bm(struct Drbd_Conf *mdev)
-{
-	unsigned long * buffer, * bm, word;
-	sector_t sector;
-	int want,bm_words,bm_i,buf_i;
-	unsigned long bits=0;
-	int so = 0;
-
-	bm_i = 0;
-	bm_words = mdev->mbds_id->size/sizeof(long);
-	bm = mdev->mbds_id->bm;
-
-	down(&mdev->md_io_mutex);
-	buffer = (unsigned long *)page_address(mdev->md_io_page);
-
-	while (1) {
-		want=min_t(int,512/sizeof(long),bm_words-bm_i);
-		if(want == 0) break;
-
-		sector = drbd_md_ss(mdev) + MD_BM_OFFSET + so;
-		so++;
-
-		if(!drbd_md_sync_page_io(mdev,sector,READ)) {
-			drbd_chk_io_error(mdev, 1);
-			drbd_io_error(mdev);
-			break;
-			//return 0; // FIXME error propagation...
-		}
-
-		for(buf_i=0;buf_i<want;buf_i++) {
-			word = lel_to_cpu(buffer[buf_i]);
-			bits += hweight_long(word);
-			bm[bm_i++] = word;
-		}
-	}
-
-	up(&mdev->md_io_mutex);
-
-	mdev->rs_total = (bits << (BM_BLOCK_SIZE_B - 9)) +
-		bm_end_of_dev_case(mdev->mbds_id);
-
-	INFO("%lu KB marked out-of-sync by on disk bit-map.\n",
-	     (unsigned long) (mdev->rs_total+1)>>1);
-}
-
-/**
- * drbd_update_on_disk_bm: Writes a piece of the bitmap to its
- * on disk location.
- *
- * @enr: The extent number of the bits we should write to disk.
- *       ATTENTION: Based on AL_EXTENT_SIZE, although the chunk
- *                  we write might represent more storage. 
- *                  ( actually AL_EXTENT_SIZE*EXTENTS_PER_SECTOR )
- */
-STATIC void drbd_update_on_disk_bm(struct Drbd_Conf *mdev,unsigned int enr)
-{
-	unsigned long * buffer, * bm;
-	unsigned int want,buf_i,bm_words,bm_i;
-	sector_t sector;
-
-	D_ASSERT(atomic_read(&mdev->local_cnt)>0);
-	enr = (enr & ~(EXTENTS_PER_SECTOR-1) );
-
-	bm = mdev->mbds_id->bm;
-	bm_words = mdev->mbds_id->size/sizeof(long);
-	bm_i = enr * BM_WORDS_PER_EXTENT ;
-
-	if(bm_i >= bm_words) {
-		if (DRBD_ratelimit(5*HZ,5)) {
-			ERR("%s:%d:%s: (bm_i=%u) >= (bm_words=%u)",
-			    __FILE__, __LINE__, __FUNCTION__,
-			    bm_i, bm_words);
-			dump_stack();
-		}
-		return;
-	}
-	want=min_t(unsigned int,512/sizeof(long),bm_words-bm_i);
-
-	down(&mdev->md_io_mutex); // protects md_io_buffer
-	buffer = (unsigned long *)page_address(mdev->md_io_page);
-
-	for(buf_i=0;buf_i<want;buf_i++) {
-		buffer[buf_i] = cpu_to_lel(bm[bm_i++]);
-	}
-
-	sector = drbd_md_ss(mdev) + MD_BM_OFFSET + enr/EXTENTS_PER_SECTOR;
-
-	if(!drbd_md_sync_page_io(mdev,sector,WRITE)) {
-		drbd_chk_io_error(mdev, 1);
-		drbd_io_error(mdev);
-	}
-	up(&mdev->md_io_mutex);
-
-	mdev->bm_writ_cnt++;
 }
 
 STATIC int w_update_odbm(drbd_dev *mdev, struct drbd_work *w, int unused)
===================================================================
RCS file: /var/lib/cvs/drbd/drbd/drbd/Attic/drbd_bitmap.c,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -3 -r1.1.2.1 -r1.1.2.2
--- drbd_bitmap.c	15 Jun 2004 07:58:02 -0000	1.1.2.1
+++ drbd_bitmap.c	15 Jun 2004 13:42:29 -0000	1.1.2.2
@@ -140,7 +140,8 @@
 
 
 /* long word offset of _bitmap_ sector */
-#define S2W(s)	((s)<<(12-LN2_BPL))
+//#define S2W(s)	((s)<<(12-LN2_BPL))
+#define S2W(s)	((s)<<(BM_EXT_SIZE_B-BM_BLOCK_SIZE_B-LN2_BPL))
 
 /*
  * actually most functions herein should take a struct drbd_bitmap*, not a
@@ -616,8 +617,7 @@
 	}
 	if (i >= b->bm_bits) {
 		i = -1UL;
-		/* we could easily add a second pass to assure all is in sync!
-		 * b->bm_fo = 0; */
+		b->bm_fo = 0;
 	} else {
 		b->bm_fo = i+1;
 	}
@@ -625,6 +625,11 @@
 	return i;
 }
 
+int drbd_bm_rs_done(drbd_dev *mdev)
+{
+	return mdev->bitmap->bm_fo == 0;
+}
+
 // THINK maybe the D_BUG_ON(i<0)s in set/clear/test should be not that strict?
 
 /* returns previous bit state
@@ -710,7 +715,7 @@
  * only cleared, not set, and typically only care for the case when the return
  * value is zero, or we already "locked" this "bitmap extent" by other means.
  *
- * sector is bm-extent number, since we chose to name one sector (512 bytes)
+ * enr is bm-extent number, since we chose to name one sector (512 bytes)
  * worth of the bitmap a "bitmap extent".
  *
  * TODO
@@ -718,7 +723,7 @@
  * reference count of some bitmap extent element from some lru instead...
  *
  */
-int drbd_bm_e_weight(drbd_dev *mdev, sector_t sector)
+int drbd_bm_e_weight(drbd_dev *mdev, unsigned int enr)
 {
 	struct drbd_bitmap *b = mdev->bitmap;
 	int count, s, e;
@@ -727,8 +732,8 @@
 	spin_lock_irq(&b->bm_lock);
 	BM_PARANOIA_CHECK();
 
-	s = S2W(sector);
-	e = min((size_t)S2W(sector+1),b->bm_words);
+	s = S2W(enr);
+	e = min((size_t)S2W(enr+1),b->bm_words);
 	count = 0;
 	if (s < b->bm_words) {
 		const unsigned long* w = b->bm+s;
@@ -739,13 +744,13 @@
 	}
 	spin_unlock_irq(&b->bm_lock);
 #if DUMP_MD >= 3
-	INFO("enr=%lu weight=%d e=%d s=%d\n", sector, count, e, s);
+	INFO("enr=%lu weight=%d e=%d s=%d\n", enr, count, e, s);
 #endif
 	return count;
 }
 
-/* set all bits in the bitmap */
-unsigned long drbd_bm_e_set_all(drbd_dev *mdev, sector_t sector)
+/* set all bits covered by the bm-extent enr */
+unsigned long drbd_bm_e_set_all(drbd_dev *mdev, unsigned int enr)
 {
 	struct drbd_bitmap *b = mdev->bitmap;
 	unsigned long weight;
@@ -758,8 +763,8 @@
 	BM_PARANOIA_CHECK();
 	weight = b->bm_set;
 
-	s = S2W(sector);
-	e = min((size_t)S2W(sector+1),b->bm_words);
+	s = S2W(enr);
+	e = min((size_t)S2W(enr+1),b->bm_words);
 	count = 0;
 	if (s < b->bm_words) {
 		const unsigned long* w = b->bm+s;
===================================================================
RCS file: /var/lib/cvs/drbd/drbd/drbd/Attic/drbd_dsender.c,v
retrieving revision 1.1.2.120
retrieving revision 1.1.2.121
diff -u -3 -r1.1.2.120 -r1.1.2.121
--- drbd_dsender.c	15 Jun 2004 10:07:32 -0000	1.1.2.120
+++ drbd_dsender.c	15 Jun 2004 13:42:29 -0000	1.1.2.121
@@ -503,6 +503,11 @@
 		}
 	}
 
+	if(drbd_bm_rs_done(mdev)) {
+		mdev->resync_work.cb = w_resync_inactive;
+		return 1;
+	}
+
  requeue:
 	mod_timer(&mdev->resync_timer, jiffies + SLEEP_TIME);
 	return 1;
===================================================================
RCS file: /var/lib/cvs/drbd/drbd/drbd/drbd_int.h,v
retrieving revision 1.58.2.171
retrieving revision 1.58.2.172
diff -u -3 -r1.58.2.171 -r1.58.2.172
--- drbd_int.h	15 Jun 2004 10:07:32 -0000	1.58.2.171
+++ drbd_int.h	15 Jun 2004 13:42:29 -0000	1.58.2.172
@@ -841,7 +841,7 @@
 #define BM_BLOCK_SIZE    (1<<BM_BLOCK_SIZE_B)
 /* (9+3) : 512 bytes @ 8 bits; representing 16M storage
  * per sector of on disk bitmap */
-#define BM_EXT_SIZE_B    (BM_BLOCK_SIZE_B + 9+3)
+#define BM_EXT_SIZE_B    (BM_BLOCK_SIZE_B + 9+3)  // = 24
 #define BM_EXT_SIZE      (1<<BM_EXT_SIZE_B)
 
 /* thus many _storage_ sectors are described by one bit */
@@ -888,15 +888,16 @@
 extern int  drbd_bm_set_bit   (drbd_dev *mdev, unsigned long bitnr);
 extern int  drbd_bm_test_bit  (drbd_dev *mdev, unsigned long bitnr);
 extern int  drbd_bm_clear_bit (drbd_dev *mdev, unsigned long bitnr);
-extern int  drbd_bm_e_weight  (drbd_dev *mdev, unsigned long enr);
+extern int  drbd_bm_e_weight  (drbd_dev *mdev, unsigned int enr);
 extern int  drbd_bm_read_sect (drbd_dev *mdev, sector_t offset);
 extern int  drbd_bm_write_sect(drbd_dev *mdev, sector_t offset);
 extern void drbd_bm_read      (drbd_dev *mdev);
 extern void drbd_bm_write     (drbd_dev *mdev);
-extern unsigned long drbd_bm_e_set_all   (drbd_dev *mdev, unsigned long enr);
+extern unsigned long drbd_bm_e_set_all   (drbd_dev *mdev, unsigned int enr);
 extern size_t        drbd_bm_words       (drbd_dev *mdev);
 extern unsigned long drbd_bm_find_next   (drbd_dev *mdev);
 extern unsigned long drbd_bm_total_weight(drbd_dev *mdev);
+extern int drbd_bm_rs_done(drbd_dev *mdev);
 // for receive_bitmap
 extern void drbd_bm_merge_lel (drbd_dev *mdev, size_t offset, size_t number,
 				unsigned long* buffer);
@@ -1369,7 +1370,7 @@
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
 // this is a direct copy from 2.6.6 include/linux/bitops.h
 
-static inline unsigned long generic_hweight64(__u64 w)
+static inline unsigned long generic_hweight64(u64 w)
 {
 #if BITS_PER_LONG < 64
 	return generic_hweight32((unsigned int)(w >> 32)) +