Buffer head async write

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I am trying to  mark a buffer for async write, but I am  having a race condition
to unlock the buffer. I am doing.

      bh = getbmapst(bdev, nsect); //this function calls bread
      if (!bh) {
              printk(KERN_ALERT "I/O error, bitmap cannot be trusted\n");
              return -1;
      }

      lock_buffer(bh);

      byte = bh->b_data + byteoffset;
      *byte |= 1 << bitoffset;
      lock_page(bh->b_page);
      mark_page_accessed(bh->b_page);
      __set_page_dirty_nobuffers(bh->b_page);
      unlock_page(bh->b_page);
      set_buffer_uptodate(bh);
      mark_buffer_dirty(bh);
      mark_buffer_async_write(bh);
      unlock_buffer(bh);
      brelse(bh);

What I want is the buffer head not to write synchronously when I do
the brelse, to
coalesce writes on it. It works normally, but this code has some form
of race condition.
The problem is that (in some circumstances, for example while using a
loop device against a file) this makes the fs/buffer.c:603
BUG_ON break. I am using the latest version of the kernel with SMP on a machine
with 4 processors.

Can anybody tell me what am I doing wrong?. I tried some other schemes, like
bit_spin_locking the BH_Uptodate_Lock, but they didn't work either.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux