文章目錄
- 1.總結
- 2.各類函數
- 2.1 分配一個倉庫
- 2.2 銷毀倉庫
- 2.3 從倉庫里面分配一個整數id
- 2.4 將上面分配的整數id從倉庫里面刪除
- 2.5 在指定范圍內分配一個id
1.總結
ida使用起來很簡單,就是先分配一個倉庫一樣的實例,再從這個倉庫里面分配一個獨一無二的整數id
2.各類函數
2.1 分配一個倉庫
靜態定義一個類似于倉庫一樣的
51 static DEFINE_IDA(host_index_ida);
2.2 銷毀倉庫
606 void scsi_exit_hosts(void)
607 {
608 class_unregister(&shost_class);
609 ida_destroy(&host_index_ida);
610 }
2.3 從倉庫里面分配一個整數id
394 int index;
...
414 index = ida_simple_get(&host_index_ida, 0, 0, GFP_KERNEL);
415 if (index < 0) {
416 kfree(shost);
417 return NULL;
418 }
419 shost->host_no = index;
...
2.4 將上面分配的整數id從倉庫里面刪除
365 ida_simple_remove(&host_index_ida, shost->host_no);
其實就是調用ida_free
301 #define ida_simple_remove(ida, id) ida_free(ida, id)
2.5 在指定范圍內分配一個id
534 int ida_alloc_range(struct ida *ida, unsigned int min, unsigned int max, gfp_t gfp)