patch-2.4.23 linux-2.4.23/fs/jfs/jfs_imap.c

Next file: linux-2.4.23/fs/jfs/jfs_incore.h
Previous file: linux-2.4.23/fs/jfs/jfs_filsys.h
Back to the patch index
Back to the overall index

diff -urN linux-2.4.22/fs/jfs/jfs_imap.c linux-2.4.23/fs/jfs/jfs_imap.c
@@ -1,5 +1,5 @@
 /*
- *   Copyright (c) International Business Machines Corp., 2000-2002
+ *   Copyright (C) International Business Machines Corp., 2000-2003
  *
  *   This program is free software;  you can redistribute it and/or modify
  *   it under the terms of the GNU General Public License as published by
@@ -120,8 +120,8 @@
  *
  * RETURN VALUES:
  *      0       - success
- *      ENOMEM  - insufficient free virtual memory.
- *      EIO  	- i/o error.
+ *      -ENOMEM  - insufficient free virtual memory.
+ *      -EIO  	- i/o error.
  */
 int diMount(struct inode *ipimap)
 {
@@ -137,7 +137,7 @@
 	imap = (struct inomap *) kmalloc(sizeof(struct inomap), GFP_KERNEL);
 	if (imap == NULL) {
 		jfs_err("diMount: kmalloc returned NULL!");
-		return (ENOMEM);
+		return -ENOMEM;
 	}
 
 	/* read the on-disk inode map control structure. */
@@ -147,7 +147,7 @@
 			   PSIZE, 0);
 	if (mp == NULL) {
 		kfree(imap);
-		return (EIO);
+		return -EIO;
 	}
 
 	/* copy the on-disk version to the in-memory version. */
@@ -206,8 +206,8 @@
  *
  * RETURN VALUES:
  *      0       - success
- *      ENOMEM  - insufficient free virtual memory.
- *      EIO  	- i/o error.
+ *      -ENOMEM  - insufficient free virtual memory.
+ *      -EIO  	- i/o error.
  */
 int diUnmount(struct inode *ipimap, int mounterror)
 {
@@ -253,7 +253,7 @@
 			  PSIZE, 0);
 	if (mp == NULL) {
 		jfs_err("diSync: get_metapage failed!");
-		return EIO;
+		return -EIO;
 	}
 
 	/* copy the in-memory version to the on-disk version */
@@ -318,8 +318,8 @@
  *
  * RETURN VALUES:
  *      0       - success
- *      EIO  	- i/o error.
- *      ENOMEM	- insufficient memory
+ *      -EIO  	- i/o error.
+ *      -ENOMEM	- insufficient memory
  *      
  */
 int diRead(struct inode *ip)
@@ -364,7 +364,7 @@
 	if ((lengthPXD(&iagp->inoext[extno]) != imap->im_nbperiext) ||
 	    (addressPXD(&iagp->inoext[extno]) == 0)) {
 		release_metapage(mp);
-		return ESTALE;
+		return -ESTALE;
 	}
 
 	/* get disk block number of the page within the inode extent
@@ -399,7 +399,7 @@
 	mp = read_metapage(ipimap, pageno << sbi->l2nbperpage, PSIZE, 1);
 	if (mp == 0) {
 		jfs_err("diRead: read_metapage failed");
-		return EIO;
+		return -EIO;
 	}
 
 	/* locate the the disk inode requested */
@@ -407,11 +407,10 @@
 	dp += rel_inode;
 
 	if (ip->i_ino != le32_to_cpu(dp->di_number)) {
-		jfs_err("diRead: i_ino != di_number");
-		updateSuper(ip->i_sb, FM_DIRTY);
-		rc = EIO;
+		jfs_error(ip->i_sb, "diRead: i_ino != di_number");
+		rc = -EIO;
 	} else if (le32_to_cpu(dp->di_nlink) == 0)
-		rc = ESTALE;
+		rc = -ESTALE;
 	else
 		/* copy the disk inode to the in-memory inode */
 		rc = copy_from_dinode(dp, ip);
@@ -617,7 +616,7 @@
  *
  * RETURN VALUES:
  *      0       - success
- *      EIO  	- i/o error.
+ *      -EIO  	- i/o error.
  */
 int diWrite(tid_t tid, struct inode *ip)
 {
@@ -645,9 +644,12 @@
 
 	ino = ip->i_ino & (INOSPERIAG - 1);
 
-	assert(lengthPXD(&(jfs_ip->ixpxd)) ==
-	       JFS_IP(ipimap)->i_imap->im_nbperiext);
-	assert(addressPXD(&(jfs_ip->ixpxd)));
+	if (!addressPXD(&(jfs_ip->ixpxd)) ||
+	    (lengthPXD(&(jfs_ip->ixpxd)) !=
+	     JFS_IP(ipimap)->i_imap->im_nbperiext)) {
+		jfs_error(ip->i_sb, "diWrite: ixpxd invalid");
+		return -EIO;
+	}
 
 	/*
 	 * read the page of disk inode containing the specified inode:
@@ -676,7 +678,7 @@
       retry:
 	mp = read_metapage(ipimap, pageno << sbi->l2nbperpage, PSIZE, 1);
 	if (mp == 0)
-		return (EIO);
+		return -EIO;
 
 	/* get the pointer to the disk inode */
 	dp = (struct dinode *) mp->data;
@@ -890,7 +892,7 @@
  *
  * RETURN VALUES:
  *      0       - success
- *      EIO  	- i/o error.
+ *      -EIO  	- i/o error.
  */
 int diFree(struct inode *ip)
 {
@@ -922,13 +924,12 @@
 	/* make sure that the iag is contained within 
 	 * the map.
 	 */
-	//assert(iagno < imap->im_nextiag);
 	if (iagno >= imap->im_nextiag) {
-		jfs_err("diFree: inum = %d, iagno = %d, nextiag = %d",
-			(uint) inum, iagno, imap->im_nextiag);
 		dump_mem("imap", imap, 32);
-		updateSuper(ip->i_sb, FM_DIRTY);
-		return EIO;
+		jfs_error(ip->i_sb,
+			  "diFree: inum = %d, iagno = %d, nextiag = %d",
+			  (uint) inum, iagno, imap->im_nextiag);
+		return -EIO;
 	}
 
 	/* get the allocation group for this ino.
@@ -961,23 +962,29 @@
 	bitno = ino & (INOSPEREXT - 1);
 	mask = HIGHORDER >> bitno;
 
-	assert(le32_to_cpu(iagp->wmap[extno]) & mask);
-#ifdef _STILL_TO_PORT
-	assert((le32_to_cpu(iagp->pmap[extno]) & mask) == 0);
-#endif				/*  _STILL_TO_PORT */
-	assert(addressPXD(&iagp->inoext[extno]));
+	if (!(le32_to_cpu(iagp->wmap[extno]) & mask)) {
+		jfs_error(ip->i_sb,
+			  "diFree: wmap shows inode already free");
+	}
+
+	if (!addressPXD(&iagp->inoext[extno])) {
+		release_metapage(mp);
+		IREAD_UNLOCK(ipimap);
+		AG_UNLOCK(imap, agno);
+		jfs_error(ip->i_sb, "diFree: invalid inoext");
+		return -EIO;
+	}
 
 	/* compute the bitmap for the extent reflecting the freed inode.
 	 */
 	bitmap = le32_to_cpu(iagp->wmap[extno]) & ~mask;
 
 	if (imap->im_agctl[agno].numfree > imap->im_agctl[agno].numinos) {
-		jfs_err("diFree: numfree > numinos");
 		release_metapage(mp);
 		IREAD_UNLOCK(ipimap);
 		AG_UNLOCK(imap, agno);
-		updateSuper(ip->i_sb, FM_DIRTY);
-		return EIO;
+		jfs_error(ip->i_sb, "diFree: numfree > numinos");
+		return -EIO;
 	}
 	/*
 	 *      inode extent still has some inodes or below low water mark:
@@ -1140,7 +1147,6 @@
 				if ((rc =
 				     diIAGRead(imap, inofreefwd, &cmp)))
 					goto error_out;
-				assert(cmp != NULL);
 				ciagp = (struct iag *) cmp->data;
 			}
 			assert(ciagp != NULL);
@@ -1155,7 +1161,6 @@
 				if ((rc =
 				     diIAGRead(imap, inofreeback, &dmp)))
 					goto error_out;
-				assert(dmp != NULL);
 				diagp = (struct iag *) dmp->data;
 			}
 			assert(diagp != NULL);
@@ -1228,7 +1233,9 @@
 	 * the permanent map should have been updated already 
 	 * for the inode being freed.
 	 */
-	assert(iagp->pmap[extno] == 0);
+	if (iagp->pmap[extno] != 0) {
+		jfs_error(ip->i_sb, "diFree: the pmap does not show inode free");
+	}
 	iagp->wmap[extno] = 0;
 	DBG_DIFREE(imap, inum);
 	PXDlength(&iagp->inoext[extno], 0);
@@ -1308,7 +1315,7 @@
 	iplist[1] = (struct inode *) (size_t)iagno;
 	iplist[2] = (struct inode *) (size_t)extno;
 
-	rc = txCommit(tid, 1, &iplist[0], COMMIT_FORCE);	// D233382
+	rc = txCommit(tid, 1, &iplist[0], COMMIT_FORCE);
 
 	txEnd(tid);
 
@@ -1367,8 +1374,8 @@
  *
  * RETURN VALUES:
  *      0       - success.
- *      ENOSPC 	- insufficient disk resources.
- *      EIO  	- i/o error.
+ *      -ENOSPC	- insufficient disk resources.
+ *      -EIO  	- i/o error.
  */
 int diAlloc(struct inode *pip, boolean_t dir, struct inode *ip)
 {
@@ -1438,6 +1445,7 @@
 	iagno = INOTOIAG(inum);
 	if ((rc = diIAGRead(imap, iagno, &mp))) {
 		IREAD_UNLOCK(ipimap);
+		AG_UNLOCK(imap, agno);
 		return (rc);
 	}
 	iagp = (struct iag *) mp->data;
@@ -1476,7 +1484,7 @@
 				rc = diAllocBit(imap, iagp, ino);
 				IREAD_UNLOCK(ipimap);
 				if (rc) {
-					assert(rc == EIO);
+					assert(rc == -EIO);
 				} else {
 					/* set the results of the allocation
 					 * and write the iag.
@@ -1540,10 +1548,16 @@
 				 */
 				rem = diFindFree(inosmap, 0);
 				extno = (sword << L2EXTSPERSUM) + rem;
-				rem =
-				    diFindFree(le32_to_cpu
-					       (iagp->wmap[extno]), 0);
-				assert(rem < INOSPEREXT);
+				rem = diFindFree(le32_to_cpu(iagp->wmap[extno]),
+						 0);
+				if (rem >= INOSPEREXT) {
+					IREAD_UNLOCK(ipimap);
+					AG_UNLOCK(imap, agno);
+					jfs_error(ip->i_sb,
+						  "diAlloc: can't find free bit "
+						  "in wmap");
+					return EIO;
+				}
 
 				/* determine the inode number within the
 				 * iag and allocate the inode from the
@@ -1552,9 +1566,9 @@
 				ino = (extno << L2INOSPEREXT) + rem;
 				rc = diAllocBit(imap, iagp, ino);
 				IREAD_UNLOCK(ipimap);
-				if (rc) {
-					assert(rc == EIO);
-				} else {
+				if (rc)
+					assert(rc == -EIO);
+				else {
 					/* set the results of the allocation
 					 * and write the iag.
 					 */
@@ -1589,10 +1603,10 @@
 					 * new extent, try to allocate the
 					 * disk inode from somewhere else.
 					 */
-					if (rc == ENOSPC)
+					if (rc == -ENOSPC)
 						break;
 
-					assert(rc == EIO);
+					assert(rc == -EIO);
 				} else {
 					/* set the results of the allocation
 					 * and write the iag.
@@ -1631,7 +1645,7 @@
 
 	AG_UNLOCK(imap, agno);
 
-	if (rc != ENOSPC)
+	if (rc != -ENOSPC)
 		return (rc);
 
 	/*
@@ -1667,8 +1681,8 @@
  *
  * RETURN VALUES:
  *      0       - success.
- *      ENOSPC 	- insufficient disk resources.
- *      EIO  	- i/o error.
+ *      -ENOSPC	- insufficient disk resources.
+ *      -EIO  	- i/o error.
  */
 static int
 diAllocAG(struct inomap * imap, int agno, boolean_t dir, struct inode *ip)
@@ -1682,9 +1696,8 @@
 	numinos = imap->im_agctl[agno].numinos;
 
 	if (numfree > numinos) {
-		jfs_err("diAllocAG: numfree > numinos");
-		updateSuper(ip->i_sb, FM_DIRTY);
-		return EIO;
+		jfs_error(ip->i_sb, "diAllocAG: numfree > numinos");
+		return -EIO;
 	}
 
 	/* determine if we should allocate a new extent of free inodes
@@ -1707,7 +1720,7 @@
 		 * below to allocate a free and existing (already backed)
 		 * inode from the ag.
 		 */
-		if ((rc = diAllocExt(imap, agno, ip)) != ENOSPC)
+		if ((rc = diAllocExt(imap, agno, ip)) != -ENOSPC)
 			return (rc);
 	}
 
@@ -1738,8 +1751,8 @@
  *
  * RETURN VALUES:
  *      0       - success.
- *      ENOSPC 	- insufficient disk resources.
- *      EIO  	- i/o error.
+ *      -ENOSPC	- insufficient disk resources.
+ *      -EIO  	- i/o error.
  */
 static int
 diAllocAny(struct inomap * imap, int agno, boolean_t dir, struct inode *ip)
@@ -1758,7 +1771,7 @@
 
 		AG_UNLOCK(imap, ag);
 
-		if (rc != ENOSPC)
+		if (rc != -ENOSPC)
 			return (rc);
 	}
 
@@ -1771,13 +1784,13 @@
 
 		AG_UNLOCK(imap, ag);
 
-		if (rc != ENOSPC)
+		if (rc != -ENOSPC)
 			return (rc);
 	}
 
 	/* no free disk inodes.
 	 */
-	return (ENOSPC);
+	return -ENOSPC;
 }
 
 
@@ -1803,8 +1816,8 @@
  *
  * RETURN VALUES:
  *      0       - success.
- *      ENOSPC 	- insufficient disk resources.
- *      EIO  	- i/o error.
+ *      -ENOSPC	- insufficient disk resources.
+ *      -EIO  	- i/o error.
  */
 static int diAllocIno(struct inomap * imap, int agno, struct inode *ip)
 {
@@ -1815,7 +1828,7 @@
 	/* check if there are iags on the ag's free inode list.
 	 */
 	if ((iagno = imap->im_agctl[agno].inofree) < 0)
-		return (ENOSPC);
+		return -ENOSPC;
 
 	/* obtain read lock on imap inode */
 	IREAD_LOCK(imap->im_ipimap);
@@ -1831,20 +1844,23 @@
 	/* better be free inodes in this iag if it is on the
 	 * list.
 	 */
-	//assert(iagp->nfreeinos);
 	if (!iagp->nfreeinos) {
-		jfs_err("diAllocIno: nfreeinos = 0, but iag on freelist");
-		jfs_err("  agno = %d, iagno = %d", agno, iagno);
-		dump_mem("iag", iagp, 64);
-		updateSuper(ip->i_sb, FM_DIRTY);
-		return EIO;
+		IREAD_UNLOCK(imap->im_ipimap);
+		jfs_error(ip->i_sb,
+			  "diAllocIno: nfreeinos = 0, but iag on freelist");
+		return -EIO;
 	}
 
 	/* scan the free inode summary map to find an extent
 	 * with free inodes.
 	 */
 	for (sword = 0;; sword++) {
-		assert(sword < SMAPSZ);
+		if (sword >= SMAPSZ) {
+			IREAD_UNLOCK(imap->im_ipimap);
+			jfs_error(ip->i_sb,
+				  "diAllocIno: free inode not found in summary map");
+			return -EIO;
+		}
 
 		if (~iagp->inosmap[sword])
 			break;
@@ -1854,13 +1870,21 @@
 	 * the extent number.
 	 */
 	rem = diFindFree(le32_to_cpu(iagp->inosmap[sword]), 0);
-	assert(rem < EXTSPERSUM);
+	if (rem >= EXTSPERSUM) {
+		IREAD_UNLOCK(imap->im_ipimap);
+		jfs_error(ip->i_sb, "diAllocIno: no free extent found");
+		return -EIO;
+	}
 	extno = (sword << L2EXTSPERSUM) + rem;
 
 	/* find the first free inode in the extent.
 	 */
 	rem = diFindFree(le32_to_cpu(iagp->wmap[extno]), 0);
-	assert(rem < INOSPEREXT);
+	if (rem >= INOSPEREXT) {
+		IREAD_UNLOCK(imap->im_ipimap);
+		jfs_error(ip->i_sb, "diAllocIno: free inode not found");
+		return -EIO;
+	}
 
 	/* compute the inode number within the iag. 
 	 */
@@ -1913,8 +1937,8 @@
  *
  * RETURN VALUES:
  *      0       - success.
- *      ENOSPC 	- insufficient disk resources.
- *      EIO  	- i/o error.
+ *      -ENOSPC	- insufficient disk resources.
+ *      -EIO  	- i/o error.
  */
 static int diAllocExt(struct inomap * imap, int agno, struct inode *ip)
 {
@@ -1943,7 +1967,9 @@
 		 */
 		IREAD_LOCK(imap->im_ipimap);
 		if ((rc = diIAGRead(imap, iagno, &mp))) {
-			assert(0);
+			IREAD_UNLOCK(imap->im_ipimap);
+			jfs_error(ip->i_sb, "diAllocExt: error reading iag");
+			return rc;
 		}
 		iagp = (struct iag *) mp->data;
 	}
@@ -1951,7 +1977,13 @@
 	/* using the free extent summary map, find a free extent.
 	 */
 	for (sword = 0;; sword++) {
-		assert(sword < SMAPSZ);
+		if (sword >= SMAPSZ) {
+			release_metapage(mp);
+			IREAD_UNLOCK(imap->im_ipimap);
+			jfs_error(ip->i_sb,
+				  "diAllocExt: free ext summary map not found");
+			return -EIO;
+		}
 		if (~iagp->extsmap[sword])
 			break;
 	}
@@ -1959,7 +1991,12 @@
 	/* determine the extent number of the free extent.
 	 */
 	rem = diFindFree(le32_to_cpu(iagp->extsmap[sword]), 0);
-	assert(rem < EXTSPERSUM);
+	if (rem >= EXTSPERSUM) {
+		release_metapage(mp);
+		IREAD_UNLOCK(imap->im_ipimap);
+		jfs_error(ip->i_sb, "diAllocExt: free extent not found");
+		return -EIO;
+	}
 	extno = (sword << L2EXTSPERSUM) + rem;
 
 	/* initialize the new extent.
@@ -2018,8 +2055,8 @@
  *
  * RETURN VALUES:
  *      0       - success.
- *      ENOSPC 	- insufficient disk resources.
- *      EIO  	- i/o error.
+ *      -ENOSPC	- insufficient disk resources.
+ *      -EIO  	- i/o error.
  */
 static int diAllocBit(struct inomap * imap, struct iag * iagp, int ino)
 {
@@ -2070,9 +2107,18 @@
 
 	/* the inode should be free and backed.
 	 */
-	assert((le32_to_cpu(iagp->pmap[extno]) & mask) == 0);
-	assert((le32_to_cpu(iagp->wmap[extno]) & mask) == 0);
-	assert(addressPXD(&iagp->inoext[extno]) != 0);
+	if (((le32_to_cpu(iagp->pmap[extno]) & mask) != 0) ||
+	    ((le32_to_cpu(iagp->wmap[extno]) & mask) != 0) ||
+	    (addressPXD(&iagp->inoext[extno]) == 0)) {
+		if (amp)
+			release_metapage(amp);
+		if (bmp)
+			release_metapage(bmp);
+
+		jfs_error(imap->im_ipimap->i_sb,
+			  "diAllocBit: iag inconsistent");
+		return -EIO;
+	}
 
 	/* mark the inode as allocated in the working map.
 	 */
@@ -2158,8 +2204,8 @@
  *
  * RETURN VALUES:
  *      0       - success.
- *      ENOSPC 	- insufficient disk resources.
- *      EIO  	- i/o error.
+ *      -ENOSPC	- insufficient disk resources.
+ *      -EIO  	- i/o error.
  */
 static int diNewExt(struct inomap * imap, struct iag * iagp, int extno)
 {
@@ -2176,7 +2222,10 @@
 
 	/* better have free extents.
 	 */
-	assert(iagp->nfreeexts);
+	if (!iagp->nfreeexts) {
+		jfs_error(imap->im_ipimap->i_sb, "diNewExt: no free extents");
+		return -EIO;
+	}
 
 	/* get the inode map inode.
 	 */
@@ -2244,7 +2293,12 @@
 					goto error_out;
 				ciagp = (struct iag *) cmp->data;
 			}
-			assert(ciagp != NULL);
+			if (ciagp == NULL) {
+				jfs_error(imap->im_ipimap->i_sb,
+					  "diNewExt: ciagp == NULL");
+				rc = -EIO;
+				goto error_out;
+			}
 		}
 	}
 
@@ -2272,7 +2326,7 @@
 		 */
 		dmp = get_metapage(ipimap, blkno + i, PSIZE, 1);
 		if (dmp == NULL) {
-			rc = EIO;
+			rc = -EIO;
 			goto error_out;
 		}
 		dp = (struct dinode *) dmp->data;
@@ -2418,8 +2472,8 @@
  *
  * RETURN VALUES:
  *      0       - success.
- *      ENOSPC 	- insufficient disk resources.
- *      EIO  	- i/o error.
+ *      -ENOSPC	- insufficient disk resources.
+ *      -EIO  	- i/o error.
  *
  * serialization: 
  *	AG lock held on entry/exit;
@@ -2478,7 +2532,14 @@
 		/* acquire inode map lock */
 		IWRITE_LOCK(ipimap);
 
-		assert(ipimap->i_size >> L2PSIZE == imap->im_nextiag + 1);
+		if (ipimap->i_size >> L2PSIZE != imap->im_nextiag + 1) {
+			IWRITE_UNLOCK(ipimap);
+			IAGFREE_UNLOCK(imap);
+			jfs_error(imap->im_ipimap->i_sb,
+				  "diNewIAG: ipimap->i_size is wrong");
+			return -EIO;
+		}
+
 
 		/* get the next avaliable iag number */
 		iagno = imap->im_nextiag;
@@ -2490,7 +2551,7 @@
 			/* release the inode map lock */
 			IWRITE_UNLOCK(ipimap);
 
-			rc = ENOSPC;
+			rc = -ENOSPC;
 			goto out;
 		}
 
@@ -2511,7 +2572,6 @@
 
 		/* assign a buffer for the page */
 		mp = get_metapage(ipimap, xaddr, PSIZE, 1);
-		//bp = bmAssign(ipimap, blkno, xaddr, PSIZE, bmREAD_PAGE);
 		if (!mp) {
 			/* Free the blocks allocated for the iag since it was
 			 * not successfully added to the inode map
@@ -2521,7 +2581,7 @@
 			/* release the inode map lock */
 			IWRITE_UNLOCK(ipimap);
 
-			rc = EIO;
+			rc = -EIO;
 			goto out;
 		}
 		iagp = (struct iag *) mp->data;
@@ -2553,7 +2613,7 @@
 			/* release the inode map lock */
 			IWRITE_UNLOCK(ipimap);
 
-			rc = EIO;
+			rc = -EIO;
 			goto out;
 		}
 
@@ -2619,7 +2679,7 @@
 	/* read the iag */
 	if ((rc = diIAGRead(imap, iagno, &mp))) {
 		IREAD_UNLOCK(ipimap);
-		rc = EIO;
+		rc = -EIO;
 		goto out;
 	}
 	iagp = (struct iag *) mp->data;
@@ -2658,7 +2718,7 @@
  *
  * RETURN VALUES:
  *      0       - success.
- *      EIO  	- i/o error.
+ *      -EIO  	- i/o error.
  */
 static int diIAGRead(struct inomap * imap, int iagno, struct metapage ** mpp)
 {
@@ -2671,7 +2731,7 @@
 	/* read the iag. */
 	*mpp = read_metapage(ipimap, blkno, PSIZE, 0);
 	if (*mpp == NULL) {
-		return (EIO);
+		return -EIO;
 	}
 
 	return (0);
@@ -2718,7 +2778,8 @@
  *	is_free	- If TRUE indicates inode should be marked freed, otherwise
  *		  indicates inode should be marked allocated.
  *
- * RETURNS: 0 for success
+ * RETURN VALUES: 
+ *		0 for success
  */
 int
 diUpdatePMap(struct inode *ipimap,
@@ -2737,7 +2798,11 @@
 	/* get the iag number containing the inode */
 	iagno = INOTOIAG(inum);
 	/* make sure that the iag is contained within the map */
-	assert(iagno < imap->im_nextiag);
+	if (iagno >= imap->im_nextiag) {
+		jfs_error(ipimap->i_sb,
+			  "diUpdatePMap: the iag is outside the map");
+		return -EIO;
+	}
 	/* read the iag */
 	IREAD_LOCK(ipimap);
 	rc = diIAGRead(imap, iagno, &mp);
@@ -2762,14 +2827,14 @@
 		 * of last reference release;
 		 */
 		if (!(le32_to_cpu(iagp->wmap[extno]) & mask)) {
-			jfs_err("diUpdatePMap: inode %ld not marked as "
-				"allocated in wmap!", inum);
-			updateSuper(ipimap->i_sb, FM_DIRTY);
+			jfs_error(ipimap->i_sb, 
+				  "diUpdatePMap: inode %ld not marked as "
+				  "allocated in wmap!", inum);
 		}
 		if (!(le32_to_cpu(iagp->pmap[extno]) & mask)) {
-			jfs_err("diUpdatePMap: inode %ld not marked as "
-				"allocated in pmap!", inum);
-			updateSuper(ipimap->i_sb, FM_DIRTY);
+			jfs_error(ipimap->i_sb,
+				  "diUpdatePMap: inode %ld not marked as "
+				  "allocated in pmap!", inum);
 		}
 		/* update the bitmap for the extent of the freed inode */
 		iagp->pmap[extno] &= cpu_to_le32(~mask);
@@ -2781,8 +2846,18 @@
 		/* The inode should be already allocated in the working map
 		 * and should be free in persistent map;
 		 */
-		assert(le32_to_cpu(iagp->wmap[extno]) & mask);
-		assert((le32_to_cpu(iagp->pmap[extno]) & mask) == 0);
+		if (!(le32_to_cpu(iagp->wmap[extno]) & mask)) {
+			jfs_error(ipimap->i_sb,
+				  "diUpdatePMap: the inode is not allocated in "
+				  "the working map");
+			return -EIO;
+		}
+		if ((le32_to_cpu(iagp->pmap[extno]) & mask) != 0) {
+			jfs_error(ipimap->i_sb,
+				  "diUpdatePMap: the inode is not free in the "
+				  "persistent map");
+			return -EIO;
+		}
 		/* update the bitmap for the extent of the allocated inode */
 		iagp->pmap[extno] |= cpu_to_le32(mask);
 	}
@@ -2821,7 +2896,6 @@
 		mp->clsn = tblk->clsn;
 		LOGSYNC_UNLOCK(log);
 	}
-//      bmLazyWrite(mp, log->flag & JFS_COMMIT);
 	write_metapage(mp);
 	return (0);
 }
@@ -2876,7 +2950,12 @@
 			continue;
 		}
 		iagp = (struct iag *) bp->data;
-		assert(le32_to_cpu(iagp->iagnum) == i);
+		if (le32_to_cpu(iagp->iagnum) != i) {
+			release_metapage(bp);
+			jfs_error(ipimap->i_sb,
+				  "diExtendFs: unexpected value of iagnum");
+			return -EIO;
+		}
 
 		/* leave free iag in the free iag list */
 		if (iagp->nfreeexts == cpu_to_le32(EXTSPERIAG)) {  
@@ -2888,9 +2967,6 @@
 		agstart = le64_to_cpu(iagp->agstart);
 		/* iagp->agstart = agstart & ~(mp->db_agsize - 1); */
 		n = agstart >> mp->db_agl2size;
-/*
-printf("diExtendFS: iag:%d agstart:%Ld agno:%d\n", i, agstart, n);
-*/
 
 		/* compute backed inodes */
 		numinos = (EXTSPERIAG - le32_to_cpu(iagp->nfreeexts))
@@ -2951,8 +3027,12 @@
 		write_metapage(bp);
 	}
 
-	ASSERT(xnuminos == atomic_read(&imap->im_numinos) &&
-	       xnumfree == atomic_read(&imap->im_numfree));
+	if (xnuminos != atomic_read(&imap->im_numinos) ||
+	    xnumfree != atomic_read(&imap->im_numfree)) {
+		jfs_error(ipimap->i_sb,
+			  "diExtendFs: numinos or numfree incorrect");
+		return -EIO;
+	}
 
 	return rcx;
 }
@@ -3016,7 +3096,7 @@
  *
  * RETURN VALUES:
  *      0       - success
- *      ENOMEM	- insufficient memory
+ *      -ENOMEM	- insufficient memory
  */
 static int copy_from_dinode(struct dinode * dip, struct inode *ip)
 {

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)