fireHydrantDataOperation.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Functions related to segment and merge handling
  3. */
  4. #include <linux/kernel.h>
  5. #include <linux/module.h>
  6. #include <linux/bio.h>
  7. #include <linux/blkdev.h>
  8. #include <linux/scatterlist.h>
  9. #include "blk.h"
  10. static unsigned int __blk_recalc_rq_segments(struct request_queue *q,
  11. struct bio *bio)
  12. {
  13. struct bio_vec *bv, *bvprv = NULL;
  14. int cluster, i, high, highprv = 1;
  15. unsigned int seg_size, nr_phys_segs;
  16. struct bio *fbio, *bbio;
  17. if (!bio)
  18. return 0;
  19. fbio = bio;
  20. cluster = blk_queue_cluster(q);
  21. seg_size = 0;
  22. nr_phys_segs = 0;
  23. for_each_bio(bio) {
  24. bio_for_each_segment(bv, bio, i) {
  25. /*
  26. * the trick here is making sure that a high page is
  27. * never considered part of another segment, since that
  28. * might change with the bounce page.
  29. */
  30. high = page_to_pfn(bv->bv_page) > queue_bounce_pfn(q);
  31. if (high || highprv)
  32. goto new_segment;
  33. if (cluster) {
  34. if (seg_size + bv->bv_len
  35. > queue_max_segment_size(q))
  36. goto new_segment;
  37. if (!BIOVEC_PHYS_MERGEABLE(bvprv, bv))
  38. goto new_segment;
  39. if (!BIOVEC_SEG_BOUNDARY(q, bvprv, bv))
  40. goto new_segment;
  41. seg_size += bv->bv_len;
  42. bvprv = bv;
  43. continue;
  44. }
  45. new_segment:
  46. if (nr_phys_segs == 1 && seg_size >
  47. fbio->bi_seg_front_size)
  48. fbio->bi_seg_front_size = seg_size;
  49. nr_phys_segs++;
  50. bvprv = bv;
  51. seg_size = bv->bv_len;
  52. highprv = high;
  53. }
  54. bbio = bio;
  55. }
  56. if (nr_phys_segs == 1 && seg_size > fbio->bi_seg_front_size)
  57. fbio->bi_seg_front_size = seg_size;
  58. if (seg_size > bbio->bi_seg_back_size)
  59. bbio->bi_seg_back_size = seg_size;
  60. return nr_phys_segs;
  61. }
  62. void blk_recalc_rq_segments(struct request *rq)
  63. {
  64. rq->nr_phys_segments = __blk_recalc_rq_segments(rq->q, rq->bio);
  65. }
  66. void blk_recount_segments(struct request_queue *q, struct bio *bio)
  67. {
  68. struct bio *nxt = bio->bi_next;
  69. bio->bi_next = NULL;
  70. bio->bi_phys_segments = __blk_recalc_rq_segments(q, bio);
  71. bio->bi_next = nxt;
  72. bio->bi_flags |= (1 << BIO_SEG_VALID);
  73. }
  74. EXPORT_SYMBOL(blk_recount_segments);
  75. static int blk_phys_contig_segment(struct request_queue *q, struct bio *bio,
  76. struct bio *nxt)
  77. {
  78. if (!blk_queue_cluster(q))
  79. return 0;
  80. if (bio->bi_seg_back_size + nxt->bi_seg_front_size >
  81. queue_max_segment_size(q))
  82. return 0;
  83. if (!bio_has_data(bio))
  84. return 1;
  85. if (!BIOVEC_PHYS_MERGEABLE(__BVEC_END(bio), __BVEC_START(nxt)))
  86. return 0;
  87. /*
  88. * bio and nxt are contiguous in memory; check if the queue allows
  89. * these two to be merged into one
  90. */
  91. if (BIO_SEG_BOUNDARY(q, bio, nxt))
  92. return 1;
  93. return 0;
  94. }
  95. static void
  96. __blk_segment_map_sg(struct request_queue *q, struct bio_vec *bvec,