kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
* Reading disks sectors
@ 2016-03-29 12:39 François
  0 siblings, 0 replies; 2+ messages in thread
From: François @ 2016-03-29 12:39 UTC (permalink / raw)
  To: kernelnewbies

Hello,

I'm trying to read raw disks sectors using bio requests.
I found a sample in a stackoverflow answer which seems to do exactly
what I'm trying to : http://stackoverflow.com/a/17527300/51760
Reading this, a few questions came to me:


1/ The API is outdated, and bio struct no longer have bi_sector for instance.
Those fields are now in bvec_iter (see
http://lxr.free-electrons.com/source/include/linux/blk_types.h?v=3.19).

bio struct do have  bi_iter field, so I was wondering wether it's safe
to populate the bi_iter directly ie:

- bio->bi_sector = sector;
+ bio->bi_iter.bi_sector = sector;

2/ There is a generic bi_endio function in bio.c.
What should readComplete implement? IMO it should just complete the
"event" (of type struct completion), and then I can just call the
bio_endio function provided by bio.c. Is that correct?

Thanks in advance!

---
Fran?ois

^ permalink raw reply	[flat|nested] 2+ messages in thread
* Reading disks sectors
@ 2016-03-30  5:27 Manoj Nayak
  0 siblings, 0 replies; 2+ messages in thread
From: Manoj Nayak @ 2016-03-30  5:27 UTC (permalink / raw)
  To: kernelnewbies

mm/page_io.c

static struct bio *get_swap_bio(gfp_t gfp_flags,
                                struct page *page, bio_end_io_t end_io)
{
        bio = bio_alloc(gfp_flags, 1);
        if (bio) {
                bio->bi_iter.bi_sector = map_swap_page(page, &bio->bi_bdev);
                bio->bi_iter.bi_sector <<= PAGE_SHIFT - 9;
                bio->bi_iter.bi_size = PAGE_SIZE;
                bio->bi_end_io = end_io;
        }
        return bio;
}


bi_endio() calls bio->bi_end_io. One should assign a routine to
bio->bi_end_io.
One can wake up the thread waiting for IO in bi_end_io. For example: direct
IO
has assigned dio_bio_end_io routine to bio->bi_end_io

fs/direct-io.c

/*
 * The BIO completion handler simply queues the BIO up for the
process-context
 * handler.
 *
 * During I/O bi_private points at the dio.  After I/O, bi_private is used
to
 * implement a singly-linked list of completed BIOs, at dio->bio_list.
 */
static void dio_bio_end_io(struct bio *bio, int error)
{
        struct dio *dio = bio->bi_private;

        bio->bi_private = dio->bio_list;
        dio->bio_list = bio;
        if (--dio->refcount == 1 && dio->waiter)
                wake_up_process(dio->waiter);
}


Regards
Manoj Nayak
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20160330/b0bc3b49/attachment.html 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-03-30  5:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-29 12:39 Reading disks sectors François
  -- strict thread matches above, loose matches on Subject: below --
2016-03-30  5:27 Manoj Nayak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).