<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">Hi,</p><div class="">My memory disk block driver was compiled successfully.</div><div class="">But when I insmod my module, initialisation stall at add_disk in setup_dev function.</div><div class=""><br class=""></div><div class="">What’s wrong with my gendisk setup code?</div><div class="">Thanks.</div><div class=""><br class=""></div><div class=""><span style="font-family: Menlo; font-size: 11px;" class="">static void setup_dev(struct blkplay_dev *dev, int which)</span></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">{</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> // setup disk size</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> memset(dev, 0, sizeof(struct blkplay_dev));</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> dev->size = nsectors * hardsect_size;</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> dev->data = vmalloc(dev->size);</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> if (dev->data == NULL) {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> printk(KERN_NOTICE "vmalloc failure.\n");</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> return;</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> // init request queue</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> spin_lock_init(&dev->lock);</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> dev->queue = blk_init_queue(blkplay_request, &dev->lock);</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> if (dev->queue == NULL) {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> printk(KERN_NOTICE "init queue failure.\n");</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> goto out_vfree;</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> //blk_queue_logical_block_size(dev->queue, hardsect_size);</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> dev->queue->queuedata = dev;</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> dev->gd = alloc_disk(BLKPLAY_MINORS);</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> if (!dev->gd) {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> printk(KERN_NOTICE "alloc_disk failure!\n");</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> goto out_vfree;</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> dev->gd->major = major;</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> dev->gd->first_minor = which * BLKPLAY_MINORS;</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> dev->gd->fops = &blkplay_ops;</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> dev->gd->queue = dev->queue;</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> dev->gd->private_data = dev;</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> snprintf(dev->gd->disk_name, 32, "blkplay%c", which + 'a');</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> set_capacity(dev->gd, nsectors * (hardsect_size/KERNEL_SECTOR_SIZE));</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">printk(KERN_ALERT "5\n”);</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">// *********************************************</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">// initialisation stall at the statement below.</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">// *********************************************</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> add_disk(dev->gd);</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">printk(KERN_ALERT "6\n");</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> return;</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">out_vfree:</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> if (dev->data)</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> vfree(dev->data); </div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</div></div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><br class=""></p><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><br class=""></p><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><br class=""></p><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">The whole module code:</p><div class=""><br class=""></div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">#include <linux/module.h></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">#include <linux/init.h></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">#include <linux/blkdev.h></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">#include <linux/genhd.h></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">#include <linux/bio.h></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">#include <linux/kernel.h></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">#include <linux/slab.h></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">#include <linux/vmalloc.h></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">#include "debug.h"</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">#define BLKPLAY_MINORS 16</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">#define KERNEL_SECTOR_SIZE 512</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">#define DEVICE_NUMBER 1</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">int major = 0;</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">int nsectors = 1024;</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">int hardsect_size = 512;</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">static const char *module_name = "blkplay";</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">struct blkplay_dev {</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> int size;</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> uint8_t *data;</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> spinlock_t lock;</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> struct request_queue *queue;</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> struct gendisk *gd;</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">};</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">struct blkplay_dev * devices;</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""> </p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">int blkplay_open(struct block_device *dev, fmode_t mode)</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">{</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> return 0;</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">void blkplay_release(struct gendisk *disk, fmode_t mode)</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">{</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">/*</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> * Handle an I/O request.</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> */</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">static void blkplay_transfer(struct blkplay_dev *dev, unsigned long sector, unsigned long nsect, char *buffer, int write)</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">{</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>unsigned long offset = sector*KERNEL_SECTOR_SIZE;</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>unsigned long nbytes = nsect*KERNEL_SECTOR_SIZE;</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>if ((offset + nbytes) > dev->size) {</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span class="Apple-tab-span" style="white-space:pre">                </span>printk (KERN_NOTICE "Beyond-end write (%ld %ld)\n", offset, nbytes);</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span class="Apple-tab-span" style="white-space:pre">                </span>return;</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>if (write)</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span class="Apple-tab-span" style="white-space:pre">                </span>memcpy(dev->data + offset, buffer, nbytes);</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>else</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span class="Apple-tab-span" style="white-space:pre">                </span>memcpy(buffer, dev->data + offset, nbytes);</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">/*</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> * Transfer a single BIO.</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> */</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">static int vmem_disk_xfer_bio(struct blkplay_dev *dev, struct bio *bio)</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">{</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> struct bio_vec bvec;</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> struct bvec_iter iter;</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> sector_t sector = bio->bi_iter.bi_sector;</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> bio_for_each_segment(bvec, bio, iter) {</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> char *buffer = __bio_kmap_atomic(bio, iter);</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> blkplay_transfer(dev, sector, bio_cur_bytes(bio) >> 9,</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> buffer, bio_data_dir(bio) == WRITE);</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> sector += bio_cur_bytes(bio) >> 9;</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> __bio_kunmap_atomic(buffer);</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> }</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> return 0;</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">void blkplay_request(struct request_queue *q)</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">{</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> struct request *req;</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> struct bio *bio;</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> while (!blk_queue_stopped(q) && </p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> (req = blk_peek_request(q)) != NULL) {</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> struct blkplay_dev *dev = req->rq_disk->private_data;</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> blk_start_request(req);</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> if (req->cmd_type != REQ_TYPE_FS) {</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> printk (KERN_NOTICE "Skip non-fs request\n");</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> blk_end_request_all(req, -EIO);</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> continue;</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> }</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""> </p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> __rq_for_each_bio(bio, req)</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> vmem_disk_xfer_bio(dev, bio);</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> blk_end_request_all(req, 0);</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> }</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">const struct block_device_operations blkplay_ops = {</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> //.owner = THIS_MODULE,</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> //.open = blkplay_open,</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> //.release = blkplay_release,</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">};</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">static void release_dev(struct blkplay_dev *dev)</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">{</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> del_gendisk(dev->gd);</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> put_disk(dev->gd);</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> blk_cleanup_queue(dev->queue);</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> vfree(dev->data);</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">static void setup_dev(struct blkplay_dev *dev, int which)</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">{</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> // setup disk size</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> memset(dev, 0, sizeof(struct blkplay_dev));</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> dev->size = nsectors * hardsect_size;</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> dev->data = vmalloc(dev->size);</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> if (dev->data == NULL) {</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> printk(KERN_NOTICE "vmalloc failure.\n");</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> return;</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> }</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> // init request queue</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> spin_lock_init(&dev->lock);</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> dev->queue = blk_init_queue(blkplay_request, &dev->lock);</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> if (dev->queue == NULL) {</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> printk(KERN_NOTICE "init queue failure.\n");</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> goto out_vfree;</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> }</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> //blk_queue_logical_block_size(dev->queue, hardsect_size);</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> dev->queue->queuedata = dev;</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> dev->gd = alloc_disk(BLKPLAY_MINORS);</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> if (!dev->gd) {</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> printk(KERN_NOTICE "alloc_disk failure!\n");</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> goto out_vfree;</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> }</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> dev->gd->major = major;</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> dev->gd->first_minor = which * BLKPLAY_MINORS;</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> dev->gd->fops = &blkplay_ops;</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> dev->gd->queue = dev->queue;</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> dev->gd->private_data = dev;</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> snprintf(dev->gd->disk_name, 32, "blkplay%c", which + 'a');</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> set_capacity(dev->gd, nsectors * (hardsect_size/KERNEL_SECTOR_SIZE));</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">printk(KERN_ALERT "5\n");</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> add_disk(dev->gd);</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">printk(KERN_ALERT "6\n");</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> return;</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">out_vfree:</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> if (dev->data)</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> vfree(dev->data); </p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">static int __init blkplay_init(void)</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">{</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> int i;</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> int ret;</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> major = register_blkdev(major, module_name);</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> if (0 >= major )</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> {</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> goto reg_blkplay_fail;</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> } else {</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> printk(KERN_ALERT "Allocate major number %d\n", major);</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> }</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> PDEBUG("Init success!\n");</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> devices = kmalloc(DEVICE_NUMBER * sizeof(struct blkplay_dev), GFP_KERNEL);</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> if (devices == NULL) {</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> printk(KERN_ALERT "Allocate memory for devices failure.\n");</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> }</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> for (i = 0; i < DEVICE_NUMBER; i++)</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> {</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> printk(KERN_ALERT "Set up device for %d\n", i);</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> setup_dev(devices + i, i);</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> }</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> return 0;</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">reg_blkplay_fail:</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> PDEBUG("Init Error!\n");</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> return ret;</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">static void __exit blkplay_exit(void)</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">{</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> int i;</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> for (i = 0; i < DEVICE_NUMBER; i++)</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> {</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> release_dev(&devices[i]);</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> }</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> unregister_blkdev(major, module_name);</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> kfree(devices);</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> PDEBUG("Exit.\n");</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">module_init(blkplay_init);</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">module_exit(blkplay_exit);</p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">MODULE_LICENSE("Dual GPL/BSD");</p></body></html>