塊裝置請求的具體實現(MTD)

來源:互聯網
上載者:User

<1>填充塊裝置資料結構

static void mtd_blktrans_request(struct request_queue *rq)
{
 struct mtd_blktrans_ops *tr = rq->queuedata;
 wake_up_process(tr->blkcore_priv->thread);
}

 

tr->blkcore_priv->rq = blk_init_queue(mtd_blktrans_request, &tr->blkcore_priv->queue_lock);

 

 

<2>請求的具體實現

static int mtd_blktrans_thread(void *arg)
{
 struct mtd_blktrans_ops *tr = arg;
 struct request_queue *rq = tr->blkcore_priv->rq;

 /* we might get involved when memory gets low, so use PF_MEMALLOC */
 current->flags |= PF_MEMALLOC;

 spin_lock_irq(rq->queue_lock);
 while (!kthread_should_stop()) { //當kthread_stop被調用時,迴圈推出
  struct request *req;
  struct mtd_blktrans_dev *dev;
  int res = 0;

  req = elv_next_request(rq);

  if (!req) {
   set_current_state(TASK_INTERRUPTIBLE);
   spin_unlock_irq(rq->queue_lock);
   schedule();  //調度
   spin_lock_irq(rq->queue_lock);
   continue;
  }

  dev = req->rq_disk->private_data;
  tr = dev->tr;

  spin_unlock_irq(rq->queue_lock);

  mutex_lock(&dev->lock);
  res = do_blktrans_request(tr, dev, req);
  mutex_unlock(&dev->lock);

  spin_lock_irq(rq->queue_lock);

  end_request(req, res);
 }
 spin_unlock_irq(rq->queue_lock);

 return 0;
}

 

<3>註冊核心線程

 tr->blkcore_priv->thread = kthread_run(mtd_blktrans_thread, tr,
   "%sd", tr->name);

 

 

<4>停止kthread

 /* Clean up the kernel thread */
 kthread_stop(tr->blkcore_priv->thread);

 

 

 

 

---------------------------------------------------

FAT

 

static const struct address_space_operations fat_aops = {
 .readpage = fat_readpage,
 .readpages = fat_readpages,
 .writepage = fat_writepage,
 .writepages = fat_writepages,
 .sync_page = block_sync_page,
 .write_begin = fat_write_begin,
 .write_end = fat_write_end,
 .direct_IO = fat_direct_IO,
 .bmap  = _fat_bmap
};

 

 

fat_readpage->mpage_bio_submit->submit_bio->generic_make_request

->__generic_make_request->q->make_request_fn(q, bio)->__generic_unplug_device->q->request_fn(q)->mtd_blktrans_request

 

 

註:

blk_queue_make_request(q, __make_request);設定函數__make_request為make_request_fn

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.