How to rewrite sbull_request in ldd3 for current kernel?

张云 zyunone at 163.com
Sat Mar 19 09:22:19 EDT 2016


Hi,
I am reading the book, Linux Driver Development 3.
In the chapter on block driver of this book,  I need some help to rewriting the sbull_request since the kernel’s block API was changed. 

The sbull_request code:
/*
 * The simple form of the request function.
 */
static void sbull_request(request_queue_t *q)
{
    struct request *req;

    while ((req = elv_next_request(q)) != NULL) {
        struct sbull_dev *dev = req->rq_disk->private_data;
        if (! blk_fs_request(req)) {
            printk (KERN_NOTICE "Skip non-fs request\n");
            end_request(req, 0);
            continue;
        }
        sbull_transfer(dev, req->sector, req->current_nr_sectors,
                req->buffer, rq_data_dir(req));
        end_request(req, 1);
    }
}

I have rewritten the code above into:

/*
 * The simple form of the request function.
 */
void blkplay_request(struct request_queue *q)
{
    struct request *req;

    while (!blk_queue_stopped(q) && 
            (req = blk_peek_request(q)) != NULL) {
        struct blkplay_dev *dev = req->rq_disk->private_data;
        blk_start_request(req);
        if (req->cmd_type != REQ_TYPE_FS) {
            printk (KERN_NOTICE "Skip non-fs request\n");
            blk_end_request(req, -EIO, 0);
            continue;
        }

	/* I don’t know how to write the statement below */
        blkplay_transfer(dev, req->sector, req->current_nr_sectors,
                req->buffer, rq_data_dir(req));

        blk_end_request_cur(req, 0);
    }
}

Is the rewrite proper?
 
The compiler can’t compile it because the request struct no longer has 
the field of ‘sector’ and ‘current_nr_sectors’. I have read the kernel code
about the request struct, the  kernel code said the __data_len and __sector field of
request struct is internal so that we shouldn’t access them directly.

How could I rewrite it ?  Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20160319/2de11324/attachment.html 


More information about the Kernelnewbies mailing list