patch-2.3.43 linux/fs/block_dev.c

Next file: linux/fs/buffer.c
Previous file: linux/fs/binfmt_elf.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.3.42/linux/fs/block_dev.c linux/fs/block_dev.c
@@ -70,39 +70,53 @@
 			if (chars != blocksize)
 				fn = bread;
 			bh = fn(dev, block, blocksize);
+			if (!bh)
+				return written ? written : -EIO;
+			if (!buffer_uptodate(bh))
+				wait_on_buffer(bh);
 		}
 #else
 		bh = getblk(dev, block, blocksize);
+		if (!bh)
+			return written ? written : -EIO;
 
-		if (chars != blocksize && !buffer_uptodate(bh)) {
-		  if(!filp->f_reada ||
-		     !read_ahead[MAJOR(dev)]) {
-		    /* We do this to force the read of a single buffer */
-		    brelse(bh);
-		    bh = bread(dev,block,blocksize);
-		  } else {
-		    /* Read-ahead before write */
-		    blocks = read_ahead[MAJOR(dev)] / (blocksize >> 9) / 2;
-		    if (block + blocks > size) blocks = size - block;
-		    if (blocks > NBUF) blocks=NBUF;
+		if (!buffer_uptodate(bh))
+		{
+		  if (chars == blocksize)
+		    wait_on_buffer(bh);
+		  else
+		  {
 		    bhlist[0] = bh;
-		    for(i=1; i<blocks; i++){
-		      bhlist[i] = getblk (dev, block+i, blocksize);
-		      if(!bhlist[i]){
-			while(i >= 0) brelse(bhlist[i--]);
-			return written ? written : -EIO;
-		      };
-		    };
+		    if (!filp->f_reada || !read_ahead[MAJOR(dev)]) {
+		      /* We do this to force the read of a single buffer */
+		      blocks = 1;
+		    } else {
+		      /* Read-ahead before write */
+		      blocks = read_ahead[MAJOR(dev)] / (blocksize >> 9) / 2;
+		      if (block + blocks > size) blocks = size - block;
+		      if (blocks > NBUF) blocks=NBUF;
+		      if (!blocks) blocks = 1;
+		      for(i=1; i<blocks; i++)
+		      {
+		        bhlist[i] = getblk (dev, block+i, blocksize);
+		        if (!bhlist[i])
+			{
+			  while(i >= 0) brelse(bhlist[i--]);
+			  return written ? written : -EIO;
+		        }
+		      }
+		    }
 		    ll_rw_block(READ, blocks, bhlist);
 		    for(i=1; i<blocks; i++) brelse(bhlist[i]);
 		    wait_on_buffer(bh);
-		      
+		    if (!buffer_uptodate(bh)) {
+			  brelse(bh);
+			  return written ? written : -EIO;
+		    }
 		  };
 		};
 #endif
 		block++;
-		if (!bh)
-			return written ? written : -EIO;
 		p = offset + bh->b_data;
 		offset = 0;
 		*ppos += chars;
@@ -522,7 +536,7 @@
 	if (sb && invalidate_inodes(sb))
 		printk("VFS: busy inodes on changed media.\n");
 
-	invalidate_buffers(dev);
+	destroy_buffers(dev);
 
 	if (bdops->revalidate)
 		bdops->revalidate(dev);

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