public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@digeo.com>
To: Brian Kelly <bkelly@sulaco.com>, linux-kernel@vger.kernel.org
Subject: Re: How to setup a buffer_head in a driver
Date: Tue, 14 Jan 2003 15:14:35 -0800	[thread overview]
Message-ID: <200301141514.35825.akpm@digeo.com> (raw)
In-Reply-To: <200301142235.RAA23806@temetra.com>

On Tuesday 14 January 2003 02:35 pm, Brian Kelly wrote:
>
> Hi,
> I'm writing a device driver that among other things needs to write data,
> manufactured by the driver itself, to a block device.
> 
> I have this data in block sized kmalloc()'d chunks. So what I'm doing is
> allocating a struct buffer_head, initialising it, fill out it's various
> fields and send it to generic_make_request().

It's probably better to use submit_bh().  Set the BH_Lock and BH_Mapped bits,
also set up b_end_io.  Then do a wait_on_buffer(), wait for the IO to
complete.  There's some similar code in
fs/jbd/journal.c:journal_write_metadata_buffer().

However, what you're doing is an odd thing.  If there is already pagecache
against that block device then the kernel doesn't know that you've changed
the bytes on-disk and will cheerfully proceed to use (and write out) the
cached data.  You'll lose your modifications..

It would be better to use sb_getblk() or bread(), to lock the returned
buffer_head, then copy your data into it and to then write it back with
submit_bh() or ll_rw_block().  Or just leave it dirty and let the kernel
write it out in due course.




  reply	other threads:[~2003-01-14 23:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-01-14 22:35 How to setup a buffer_head in a driver Brian Kelly
2003-01-14 23:14 ` Andrew Morton [this message]
2003-01-16  6:59   ` Brian Kelly

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=200301141514.35825.akpm@digeo.com \
    --to=akpm@digeo.com \
    --cc=bkelly@sulaco.com \
    --cc=linux-kernel@vger.kernel.org \
    /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