mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@osdl.org>
To: "Gorka Guardiola" <paurealkml@gmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: Buffer head async write
Date: Wed, 30 Aug 2006 16:59:24 -0700	[thread overview]
Message-ID: <20060830165924.2955d8d1.akpm@osdl.org> (raw)
In-Reply-To: <dc081bb90608300935h1d5346fbj742920754f4b4680@mail.gmail.com>

On Wed, 30 Aug 2006 11:35:44 -0500
"Gorka Guardiola" <paurealkml@gmail.com> wrote:

> 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);

There are rather a lot of mistakes in there.

More like this:

	lock_page(bh->b_page);
	lock_buffer(bh);
	byte = bh->b_data + byteoffset;
	*byte |= 1 << bitoffset;
	mark_buffer_dirty(bh);
	unlock_buffer(bh);
	flush_dcache_page(page);
	unlock_page(page);
	put_bh(bh);

now, the buffer is dirty and will be written back by pdflush, sync, etc.

If you really want to start async IO against that buffer now, do

	ll_rw_block(WRITE, 1, &bh);

just before the final put_bh().

	

  reply	other threads:[~2006-08-30 23:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-30 16:35 Gorka Guardiola
2006-08-30 23:59 ` Andrew Morton [this message]
2006-08-30 18:54 Gorka Guardiola

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060830165924.2955d8d1.akpm@osdl.org \
    --to=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paurealkml@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®