[lkml]   [2003]   [Jan]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: How to setup a buffer_head in a driver
I wrote:
> 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().

Andrew Morton wrote:
>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

Thanks, that's exactly the sort of thing I was looking for.

>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.

Fair enough, that seems like the right thing to do so I'll look into it.



To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

 \ /
  Last update: 2005-03-22 13:32    [W:0.070 / U:4.196 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site