struct io_cq

来源:互联网 发布:如何用qq注册淘宝账号 编辑:程序博客网 时间:2024/06/03 15:44


struct io_cq *ioc_create_icq(struct io_context *ioc, struct request_queue *q,     gfp_t gfp_mask){struct elevator_type *et = q->elevator->type;struct io_cq *icq;/* allocate stuff */icq = kmem_cache_alloc_node(et->icq_cache, gfp_mask | __GFP_ZERO,    q->node);if (!icq)return NULL;if (radix_tree_maybe_preload(gfp_mask) < 0) {kmem_cache_free(et->icq_cache, icq);return NULL;}icq->ioc = ioc;icq->q = q;INIT_LIST_HEAD(&icq->q_node);INIT_HLIST_NODE(&icq->ioc_node);/* lock both q and ioc and try to link @icq */spin_lock_irq(q->queue_lock);spin_lock(&ioc->lock);if (likely(!radix_tree_insert(&ioc->icq_tree, q->id, icq))) {hlist_add_head(&icq->ioc_node, &ioc->icq_list);list_add(&icq->q_node, &q->icq_list);if (et->ops.elevator_init_icq_fn)et->ops.elevator_init_icq_fn(icq);} else {kmem_cache_free(et->icq_cache, icq);icq = ioc_lookup_icq(ioc, q);if (!icq)printk(KERN_ERR "cfq: icq link failed!\n");}spin_unlock(&ioc->lock);spin_unlock_irq(q->queue_lock);radix_tree_preload_end();return icq;}
/** * ioc_lookup_icq - lookup io_cq from ioc * @ioc: the associated io_context * @q: the associated request_queue * * Look up io_cq associated with @ioc - @q pair from @ioc.  Must be called * with @q->queue_lock held. */struct io_cq *ioc_lookup_icq(struct io_context *ioc, struct request_queue *q){struct io_cq *icq;lockdep_assert_held(q->queue_lock);/* * icq's are indexed from @ioc using radix tree and hint pointer, * both of which are protected with RCU.  All removals are done * holding both q and ioc locks, and we're holding q lock - if we * find a icq which points to us, it's guaranteed to be valid. */rcu_read_lock();icq = rcu_dereference(ioc->icq_hint);if (icq && icq->q == q)goto out;icq = radix_tree_lookup(&ioc->icq_tree, q->id);if (icq && icq->q == q)rcu_assign_pointer(ioc->icq_hint, icq);/* allowed to race */elseicq = NULL;out:rcu_read_unlock();return icq;}


0 0
原创粉丝点击