Re: 2.4.11-pre2 fs/buffer.c: invalidate: busy buffer

From: Neil Brown (neilb@cse.unsw.edu.au)
Date: Wed Oct 03 2001 - 02:13:37 EST


On Wednesday October 3, viro@math.psu.edu wrote:
>
>
> On Wed, 3 Oct 2001, Neil Brown wrote:
>
> > On Wednesday October 3, adilger@turbolabs.com wrote:
>
> > > 3) Rewrite to do I/O directly via pagecache?
> >
> > 4) Rewrite to do I/O directly via generic_make_request just like it
> > does for all other I/O to underlying devices.
> > It is on my (mental) todo list, but doesn't have a high priority.
> > At the same time, it would be good to get write_disk_sb to notice
> > if the write failed.....
>
> Folks, there's a problem aside of set_blocksize(). You are doing memset
> and memcpy on unlocked buffer returned by getblk(). That's a race -
> if that buffer is currently being read into, we will get a random crap.
> And write it to disk afterwards.
>
> General rule: don't modify buffer you've got from getblk() unless you've
> locked it and mark it uptodate before you unlock. We had the same
> bug in ext2, BTW.

What I am saying is "don't use the buffer cache at all" or any cache.
Don't use getblk.
Just:
   bh = kmalloc(sizeof(*bh));
   bh->b_data = rdev->sb; /* it is always one page */
   bh->b_rdev = rdev->dev;
   bh->b_rsector = sb_offset*2;
   bh->b_end_io = md_just_set_a_flag_and_call_wakeup;
   init_wait_queue_head(&bh->b_wait);
   bh->b_flags = 1<<B_Locked;

   generic_make_request(WRITE,bh);
   wait_disk_event((bh->b_flags & (1<<B_Locked)), bh->b_wait);

   err = bh->b_flags & (1<<B_Uptodate);
   kfree(bh);
   return err;

with typos corrected and a fairly obvious definition of
 md_just_set_a_flag_and_call_wakeup
fairly similar to end_buffer_io_sync.

NeilBrown
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Sun Oct 07 2001 - 21:00:26 EST