[DRBD-cvs] drbd by phil; There was a bug in bm_fill_bm() that cou...

drbd-user@lists.linbit.com drbd-user@lists.linbit.com
Sat, 6 Mar 2004 21:32:04 +0100 (CET)


DRBD CVS committal

Author  : phil
Module  : drbd

Dir     : drbd/drbd


Modified Files:
      Tag: rel-0_7-branch
	drbd_main.c 


Log Message:
There was a bug in bm_fill_bm() that could cause a 
"Unable to handle kernel paging request" in some rare cases.
Fixed.
 Slowly I get addicted to debugging by reading OOPS messages. I start
 to like it. -- [Is this a sign of madness?]

===================================================================
RCS file: /var/lib/cvs/drbd/drbd/drbd/drbd_main.c,v
retrieving revision 1.73.2.138
retrieving revision 1.73.2.139
diff -u -3 -r1.73.2.138 -r1.73.2.139
--- drbd_main.c	6 Mar 2004 13:28:13 -0000	1.73.2.138
+++ drbd_main.c	6 Mar 2004 20:31:59 -0000	1.73.2.139
@@ -1892,16 +1892,19 @@
 void bm_fill_bm(struct BitMap* sbm,int value)
 {
 	unsigned long* bm;
-	unsigned long bnr;
+	unsigned long bnr,o;
 
 	spin_lock(&sbm->bm_lock);
 	bm = sbm->bm;
 
-	memset(sbm->bm,value,sbm->size);
+	memset(bm,value,sbm->size);
 
 	// Special case at end of device...
 	bnr = sbm->dev_size / BM_BPS + ( sbm->dev_size % BM_BPS ? 1 : 0 );
-	bm[bnr / BITS_PER_LONG] &= ( ( 1 << (bnr % BITS_PER_LONG) ) - 1 );
+	o = bnr / BITS_PER_LONG;
+	if ( o < sbm->size/sizeof(long) ) { // e.g. is wrong if dev_size == 1G 
+		bm[ o ] &= ( ( 1 << (bnr % BITS_PER_LONG) ) - 1 );
+	}
 
 	spin_unlock(&sbm->bm_lock);
 }