Skip to contentSkip to conversation

sg.c: sg_rb_correct4mmap

DISCUSSION Chip Coldwell 1 participant 1 message Mar 21, 2006 SCSI

lore
Share & tools
lore
#0 lore raw

I'm trying to understand the purpose of this function in the SCSI generic driver (sg.c):

sg_rb_correct4mmap(Sg_scatter_hold * rsv_schp, int startFinish)

{
        struct scatterlist *sg = rsv_schp->buffer;
        struct page *page;
        int k, m;

        SCSI_LOG_TIMEOUT(3, printk("sg_rb_correct4mmap: startFinish=%d, scatg=%d\n",
                                   startFinish, rsv_schp->k_use_sg));
        /* N.B. correction _not_ applied to base page of each allocation */
        for (k = 0; k < rsv_schp->k_use_sg; ++k, ++sg) {
                for (m = PAGE_SIZE; m < sg->length; m += PAGE_SIZE) {
                        page = sg->page;
                        if (startFinish)
                                get_page(page);
                        else {
                                if (page_count(page) > 0)
                                        __put_page(page);
                        }
                }
        }
}

Judging from the comment, it would seem that the intention is to get/put every page in a scatterlist except the first one. But that isn't what it does; if 2*PAGE_SIZE <= sg->length < N*PAGE_SIZE, then this logic will call get_page (or __put_page) N-2 times on the same page, rather than once on each of the N-2 pages after the first.

More generally, why is this operation needed at all, when the sg_vma_nopage function will presumably do the required get_page?

Chip

Signature · 3 lines
Charles M. "Chip" Coldwell
Senior Software Engineer
Red Hat, Inc