123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- #include <linux/module.h>
- #include <linux/errno.h>
- #include <linux/fs.h>
- #include <linux/sched.h>
- #include <linux/parser.h>
- #include <linux/idr.h>
- #include <linux/slab.h>
- #include <net/9p/9p.h>
- struct p9_idpool {
- spinlock_t lock;
- struct idr pool;
- };
- struct p9_idpool *p9_idpool_create(void)
- {
- struct p9_idpool *p;
- p = kmalloc(sizeof(struct p9_idpool), GFP_KERNEL);
- if (!p)
- return ERR_PTR(-ENOMEM);
- spin_lock_init(&p->lock);
- idr_init(&p->pool);
- return p;
- }
- EXPORT_SYMBOL(p9_idpool_create);
- void p9_idpool_destroy(struct p9_idpool *p)
- {
- idr_destroy(&p->pool);
- kfree(p);
- }
- EXPORT_SYMBOL(p9_idpool_destroy);
- int p9_idpool_get(struct p9_idpool *p)
- {
- int i;
- unsigned long flags;
- idr_preload(GFP_NOFS);
- spin_lock_irqsave(&p->lock, flags);
-
- i = idr_alloc(&p->pool, p, 0, 0, GFP_NOWAIT);
- spin_unlock_irqrestore(&p->lock, flags);
- idr_preload_end();
- if (i < 0)
- return -1;
- p9_debug(P9_DEBUG_MUX, " id %d pool %p\n", i, p);
- return i;
- }
- EXPORT_SYMBOL(p9_idpool_get);
- void p9_idpool_put(int id, struct p9_idpool *p)
- {
- unsigned long flags;
- p9_debug(P9_DEBUG_MUX, " id %d pool %p\n", id, p);
- spin_lock_irqsave(&p->lock, flags);
- idr_remove(&p->pool, id);
- spin_unlock_irqrestore(&p->lock, flags);
- }
- EXPORT_SYMBOL(p9_idpool_put);
- int p9_idpool_check(int id, struct p9_idpool *p)
- {
- return idr_find(&p->pool, id) != NULL;
- }
- EXPORT_SYMBOL(p9_idpool_check);
|