Thanks! I have another question if it is possible to rewrite the data transfer function avoiding the bio complexity? Yun Zhang(张云) > On Mar 20, 2016, at 8:13 AM, Dongli Zhang <dongli.zhang0129@xxxxxxxxxxx> wrote: > > Please refer to https://github.com/21cnbao/training/tree/50506cf04bc5616e0c3f3285dbb006c54deb1c53/kernel/drivers/vmem_disk > > Dongli Zhang (张东立) > http://finallyjustice.github.io > > > ________________________________ >> From: zyunone@xxxxxxx >> Subject: How to rewrite sbull_request in ldd3 for current kernel? >> Date: Sat, 19 Mar 2016 21:22:19 +0800 >> To: kernelnewbies@xxxxxxxxxxxxxxxxx >> >> 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. >> >> _______________________________________________ Kernelnewbies mailing >> list Kernelnewbies@xxxxxxxxxxxxxxxxx >> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies > > _______________________________________________ > Kernelnewbies mailing list > Kernelnewbies@xxxxxxxxxxxxxxxxx > http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies _______________________________________________ Kernelnewbies mailing list Kernelnewbies@xxxxxxxxxxxxxxxxx http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies