Re: direct-to-BIO for O_DIRECT

From: Ingo Oeser (ingo.oeser@informatik.tu-chemnitz.de)
Date: Tue Jul 09 2002 - 03:16:15 EST


On Mon, Jul 08, 2002 at 09:26:48PM -0700, Andrew Morton wrote:
> > > It would be nice if we could just map a set of user pages
> > > to a scatterlist.
> >
> > After disabling kiobufs in sg I would like such a drop
> > in replacement.
>
> Ben had lightweight sg structures called `kvecs' and `kveclets'. And
> library functions to map pages into them. And code to attach them
> to BIOs. So we'll be looking at getting that happening.

BIOs are for BLOCK devices we want sth. like this for CHARACTER
devices.

I just want sth. along the lines of this:

/* Pin down (COMPLETE!) user pages and put them into a scatter gather list */
int sg_map_user_pages(struct scatterlist *sgl, const unsigned int nr_pages,
                unsigned long uaddr, int rw) {
        int res, i;
        struct page *pages[nr_pages];

        down_read(&current->mm->mmap_sem);
        res = get_user_pages(
                        current,
                        current->mm,
                        uaddr,
                        nr_pages,
                        rw == READ, /* logic is perversed^Wreversed here :-( */
                        0, /* don't force */
                        &pages[0],
                        NULL);
        up_read(&current->mm->mmap_sem);

        /* Errors and no page mapped should return here */
        if (res <= 0) return res;

        for (i=1; i < res; i++) {
                sgl[i].page = pages[i];
        }
        return res;
}

/* And unmap them... */
int sg_unmap_user_pages(struct scatterlist *sgl, const unsigned int nr_pages) {
        int i;

        for (i=0; i < nr_pages; i++)
                page_cache_release(sgl[i].page);

        return 0;
}

Possibly more complicated and less error prone, but you get the
idea ;-)

Regards

Ingo Oeser

-- 
Science is what we can tell a computer. Art is everything else. --- D.E.Knuth
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Mon Jul 15 2002 - 22:00:14 EST