waterTankDataOperation.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Functions related to io context handling
  3. */
  4. #include <linux/kernel.h>
  5. #include <linux/module.h>
  6. #include <linux/init.h>
  7. #include <linux/bio.h>
  8. #include <linux/blkdev.h>
  9. #include <linux/bootmem.h> /* for max_pfn/max_low_pfn */
  10. #include <linux/slab.h>
  11. #include "blk.h"
  12. /*
  13. * For io context allocations
  14. */
  15. static struct kmem_cache *iocontext_cachep;
  16. /**
  17. * get_io_context - increment reference count to io_context
  18. * @ioc: io_context to get
  19. *
  20. * Increment reference count to @ioc.
  21. */
  22. void get_io_context(struct io_context *ioc)
  23. {
  24. BUG_ON(atomic_long_read(&ioc->refcount) <= 0);
  25. atomic_long_inc(&ioc->refcount);
  26. }
  27. EXPORT_SYMBOL(get_io_context);
  28. static void icq_free_icq_rcu(struct rcu_head *head)
  29. {
  30. struct io_cq *icq = container_of(head, struct io_cq, __rcu_head);
  31. kmem_cache_free(icq->__rcu_icq_cache, icq);
  32. }
  33. /* Exit an icq. Called with both ioc and q locked. */
  34. static void ioc_exit_icq(struct io_cq *icq)
  35. {
  36. struct elevator_type *et = icq->q->elevator->type;
  37. if (icq->flags & ICQ_EXITED)
  38. return;
  39. if (et->ops.elevator_exit_icq_fn)
  40. et->ops.elevator_exit_icq_fn(icq);
  41. icq->flags |= ICQ_EXITED;
  42. }
  43. /* Release an icq. Called with both ioc and q locked. */
  44. static void ioc_destroy_icq(struct io_cq *icq)
  45. {
  46. struct io_context *ioc = icq->ioc;
  47. struct request_queue *q = icq->q;
  48. struct elevator_type *et = q->elevator->type;
  49. lockdep_assert_held(&ioc->lock);
  50. lockdep_assert_held(q->queue_lock);
  51. radix_tree_delete(&ioc->icq_tree, icq->q->id);
  52. hlist_del_init(&icq->ioc_node);
  53. list_del_init(&icq->q_node);
  54. /*
  55. * Both setting lookup hint to and clearing it from @icq are done
  56. * under queue_lock. If it's not pointing to @icq now, it never
  57. * will. Hint assignment itself can race safely.
  58. */
  59. if (rcu_dereference_raw(ioc->icq_hint) == icq)
  60. rcu_assign_pointer(ioc->icq_hint, NULL);
  61. ioc_exit_icq(icq);
  62. /*