analysisOfLiquidLevelDataOperation.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Functions related to tagged command queuing
  3. */
  4. #include <linux/kernel.h>
  5. #include <linux/module.h>
  6. #include <linux/bio.h>
  7. #include <linux/blkdev.h>
  8. #include <linux/slab.h>
  9. #include "blk.h"
  10. /**
  11. * blk_queue_find_tag - find a request by its tag and queue
  12. * @q: The request queue for the device
  13. * @tag: The tag of the request
  14. *
  15. * Notes:
  16. * Should be used when a device returns a tag and you want to match
  17. * it with a request.
  18. *
  19. * no locks need be held.
  20. **/
  21. struct request *blk_queue_find_tag(struct request_queue *q, int tag)
  22. {
  23. return blk_map_queue_find_tag(q->queue_tags, tag);
  24. }
  25. EXPORT_SYMBOL(blk_queue_find_tag);
  26. /**
  27. * __blk_free_tags - release a given set of tag maintenance info
  28. * @bqt: the tag map to free
  29. *
  30. * Tries to free the specified @bqt. Returns true if it was
  31. * actually freed and false if there are still references using it
  32. */
  33. static int __blk_free_tags(struct blk_queue_tag *bqt)
  34. {
  35. int retval;
  36. retval = atomic_dec_and_test(&bqt->refcnt);
  37. if (retval) {
  38. BUG_ON(find_first_bit(bqt->tag_map, bqt->max_depth) <
  39. bqt->max_depth);
  40. kfree(bqt->tag_index);
  41. bqt->tag_index = NULL;
  42. kfree(bqt->tag_map);
  43. bqt->tag_map = NULL;
  44. kfree(bqt);
  45. }
  46. return retval;
  47. }
  48. /**
  49. * __blk_queue_free_tags - release tag maintenance info
  50. * @q: the request queue for the device
  51. *
  52. * Notes:
  53. * blk_cleanup_queue() will take care of calling this function, if tagging
  54. * has been used. So there's no need to call this directly.
  55. **/
  56. void __blk_queue_free_tags(struct request_queue *q)
  57. {
  58. struct blk_queue_tag *bqt = q->queue_tags;
  59. if (!bqt)
  60. return;
  61. __blk_free_tags(bqt);
  62. q->queue_tags = NULL;
  63. queue_flag_clear_unlocked(QUEUE_FLAG_QUEUED, q);
  64. }