View previous topic :: View next topic |
Author |
Message |
redgsturbo Apprentice
Joined: 24 Jun 2005 Posts: 283
|
Posted: Wed Oct 31, 2007 4:44 pm Post subject: kernel block IO coding question |
|
|
Suppose I'm handling a block IO request in a function. I want to go ahead and satisfy this IO operation which describes a read request from one block device. I want to immediately take the resulting read data and allocate another block IO request (bio) and write that same sector to another block device different from the one read from. How do I do this? The bio struct seems to be destroyed after a generic_make_request call, and so I get a kernel panic when I try to do anything with it. |
|
Back to top |
|
|
eyoung100 Veteran
Joined: 23 Jan 2004 Posts: 1428
|
Posted: Thu Nov 01, 2007 5:05 pm Post subject: |
|
|
I have no Idea what language you are writing this call in, but you may want to add a few more steps
1. Copy from first Device
2. Write Block to RAM
3 Close first device
4. Open second Device
5. Fetch RAM in #2 and write to second Device.
6. Overwrite RAM to free up space
7. Repeat process until all blocks are copied.
Writing each block to RAM and then copying it ensures that the data is copied to device 2 without overwriting previously copied blocks. _________________ The Birth and Growth of Science is the Death and Atrophy of Art -- Unknown
Registerd Linux User #363735
Adopt a Post | Strip Comments| Emerge Wrapper |
|
Back to top |
|
|
tageiru n00b
Joined: 26 Oct 2002 Posts: 46
|
Posted: Thu Nov 01, 2007 8:53 pm Post subject: |
|
|
[disclaimer]I am not all that familiar with the block io system in Linux, so this might be completely useless.[/disclaimer]
Do you mean that the struct bio * returned in bio->bi_end_io is destroyed? It shouldn't be unless there is some spurious bio_put() in your code. |
|
Back to top |
|
|
redgsturbo Apprentice
Joined: 24 Jun 2005 Posts: 283
|
Posted: Fri Nov 02, 2007 2:40 pm Post subject: |
|
|
eyoung100 wrote: | I have no Idea what language you are writing this call in, but you may want to add a few more steps
1. Copy from first Device
2. Write Block to RAM
3 Close first device
4. Open second Device
5. Fetch RAM in #2 and write to second Device.
6. Overwrite RAM to free up space
7. Repeat process until all blocks are copied.
Writing each block to RAM and then copying it ensures that the data is copied to device 2 without overwriting previously copied blocks. |
Its written in C of course |
|
Back to top |
|
|
redgsturbo Apprentice
Joined: 24 Jun 2005 Posts: 283
|
Posted: Fri Nov 02, 2007 2:42 pm Post subject: |
|
|
tageiru wrote: | [disclaimer]I am not all that familiar with the block io system in Linux, so this might be completely useless.[/disclaimer]
Do you mean that the struct bio * returned in bio->bi_end_io is destroyed? It shouldn't be unless there is some spurious bio_put() in your code. |
Perhaps I am confused. Could you describe how to properly work with the bio's passed to a md device driver... I am basically using the md device drivers as a guide, but I don't exactly know what I'm doing . You seem to, so could you give me a brief overview of what I am supposed to do with a bio in order to satisfy a block io request? |
|
Back to top |
|
|
eyoung100 Veteran
Joined: 23 Jan 2004 Posts: 1428
|
|
Back to top |
|
|
redgsturbo Apprentice
Joined: 24 Jun 2005 Posts: 283
|
Posted: Tue Nov 06, 2007 7:56 pm Post subject: |
|
|
Its never too much
I'm talking about working with block IO structs... not sure what that link was exactly.
My current issue is with ending a bio request. When I take over the bi_end_io function I don't seem to be ending the IO properly as I get a core dump. Once a bio read request is complete I need to take the read data and write it to another device. Any thoughts? Something along the lines of this needs to take place immediatly after a read is complete:
Code: | void cache_update( cache_conf_t *conf, struct bio *bio )
{
struct bio *cbio;
int rw = (1<<BIO_RW);
cbio = bio_alloc( GFP_NOIO, 1 );
cbio->bi_bdev = conf->disks[CACHE_DEVICE].rdev->bdev;
cbio->bi_sector = cache_placement( conf, bio );
cbio->bi_private = bio;
cbio->bi_rw = rw;
cbio->bi_io_vec = bio->bi_io_vec;
conf->cache_tags[ cbio->bi_sector ] = bio->bi_sector<<1;
printk( "cache: cache_update: submitting bio for sector %llu to %llu of cache\n", bio->bi_sector, cbio->bi_sector );
generic_make_request( cbio );
} |
somewhere in here I need to snag bio's data and put it in the cbio struct to be written back to the cached device. How do I find the data read, and where do I put it? Also, how do I close a bio out asmy "bio_endio( bio, bio->bi_size, 0 ); doesn't seem to work. |
|
Back to top |
|
|
sundialsvc4 Guru
Joined: 10 Nov 2005 Posts: 436
|
Posted: Wed Nov 07, 2007 12:45 am Post subject: |
|
|
When I read this, I immediately wonder why you've chosen to do this at the kernel level... |
|
Back to top |
|
|
redgsturbo Apprentice
Joined: 24 Jun 2005 Posts: 283
|
Posted: Wed Nov 07, 2007 2:38 pm Post subject: |
|
|
sundialsvc4 wrote: | When I read this, I immediately wonder why you've chosen to do this at the kernel level... |
because I'm doing disk IO in a kernel module and thus, it has to be in kernel space |
|
Back to top |
|
|
|