Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
kernel block IO coding question
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware
View previous topic :: View next topic  
Author Message
redgsturbo
Apprentice
Apprentice


Joined: 24 Jun 2005
Posts: 283

PostPosted: Wed Oct 31, 2007 4:44 pm    Post subject: kernel block IO coding question Reply with quote

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
View user's profile Send private message
eyoung100
Veteran
Veteran


Joined: 23 Jan 2004
Posts: 1428

PostPosted: Thu Nov 01, 2007 5:05 pm    Post subject: Reply with quote

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
View user's profile Send private message
tageiru
n00b
n00b


Joined: 26 Oct 2002
Posts: 46

PostPosted: Thu Nov 01, 2007 8:53 pm    Post subject: Reply with quote

[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
View user's profile Send private message
redgsturbo
Apprentice
Apprentice


Joined: 24 Jun 2005
Posts: 283

PostPosted: Fri Nov 02, 2007 2:40 pm    Post subject: Reply with quote

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
View user's profile Send private message
redgsturbo
Apprentice
Apprentice


Joined: 24 Jun 2005
Posts: 283

PostPosted: Fri Nov 02, 2007 2:42 pm    Post subject: Reply with quote

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
View user's profile Send private message
eyoung100
Veteran
Veteran


Joined: 23 Jan 2004
Posts: 1428

PostPosted: Tue Nov 06, 2007 2:24 pm    Post subject: Reply with quote

Before you take on too much, learn what each step is doing. I found the site below since no one has answered you in awhile.

Write a program in C to read and display the bio-data using structure ?

There are 17 programs on that site using bio struct. These should get you started.
_________________
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
View user's profile Send private message
redgsturbo
Apprentice
Apprentice


Joined: 24 Jun 2005
Posts: 283

PostPosted: Tue Nov 06, 2007 7:56 pm    Post subject: Reply with quote

eyoung100 wrote:
Before you take on too much, learn what each step is doing. I found the site below since no one has answered you in awhile.

Write a program in C to read and display the bio-data using structure ?

There are 17 programs on that site using bio struct. These should get you started.


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
View user's profile Send private message
sundialsvc4
Guru
Guru


Joined: 10 Nov 2005
Posts: 436

PostPosted: Wed Nov 07, 2007 12:45 am    Post subject: Reply with quote

When I read this, I immediately wonder why you've chosen to do this at the kernel level...
Back to top
View user's profile Send private message
redgsturbo
Apprentice
Apprentice


Joined: 24 Jun 2005
Posts: 283

PostPosted: Wed Nov 07, 2007 2:38 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum