aboutsummaryrefslogtreecommitdiffstats
path: root/block
diff options
context:
space:
mode:
Diffstat (limited to 'block')
-rw-r--r--block/blk-merge.c19
-rw-r--r--block/blk-mq.c41
-rw-r--r--block/ioprio.c14
-rw-r--r--block/scsi_ioctl.c8
4 files changed, 57 insertions, 25 deletions
diff --git a/block/blk-merge.c b/block/blk-merge.c
index b3ac40aef46b..89b97b5e0881 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -97,19 +97,22 @@ void blk_recalc_rq_segments(struct request *rq)
97 97
98void blk_recount_segments(struct request_queue *q, struct bio *bio) 98void blk_recount_segments(struct request_queue *q, struct bio *bio)
99{ 99{
100 bool no_sg_merge = !!test_bit(QUEUE_FLAG_NO_SG_MERGE, 100 unsigned short seg_cnt;
101 &q->queue_flags); 101
102 bool merge_not_need = bio->bi_vcnt < queue_max_segments(q); 102 /* estimate segment number by bi_vcnt for non-cloned bio */
103 if (bio_flagged(bio, BIO_CLONED))
104 seg_cnt = bio_segments(bio);
105 else
106 seg_cnt = bio->bi_vcnt;
103 107
104 if (no_sg_merge && !bio_flagged(bio, BIO_CLONED) && 108 if (test_bit(QUEUE_FLAG_NO_SG_MERGE, &q->queue_flags) &&
105 merge_not_need) 109 (seg_cnt < queue_max_segments(q)))
106 bio->bi_phys_segments = bio->bi_vcnt; 110 bio->bi_phys_segments = seg_cnt;
107 else { 111 else {
108 struct bio *nxt = bio->bi_next; 112 struct bio *nxt = bio->bi_next;
109 113
110 bio->bi_next = NULL; 114 bio->bi_next = NULL;
111 bio->bi_phys_segments = __blk_recalc_rq_segments(q, bio, 115 bio->bi_phys_segments = __blk_recalc_rq_segments(q, bio, false);
112 no_sg_merge && merge_not_need);
113 bio->bi_next = nxt; 116 bio->bi_next = nxt;
114 } 117 }
115 118
diff --git a/block/blk-mq.c b/block/blk-mq.c
index b5896d436fc9..92ceef0d2ab9 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -107,11 +107,7 @@ static void blk_mq_usage_counter_release(struct percpu_ref *ref)
107 wake_up_all(&q->mq_freeze_wq); 107 wake_up_all(&q->mq_freeze_wq);
108} 108}
109 109
110/* 110static void blk_mq_freeze_queue_start(struct request_queue *q)
111 * Guarantee no request is in use, so we can change any data structure of
112 * the queue afterward.
113 */
114void blk_mq_freeze_queue(struct request_queue *q)
115{ 111{
116 bool freeze; 112 bool freeze;
117 113
@@ -123,9 +119,23 @@ void blk_mq_freeze_queue(struct request_queue *q)
123 percpu_ref_kill(&q->mq_usage_counter); 119 percpu_ref_kill(&q->mq_usage_counter);
124 blk_mq_run_queues(q, false); 120 blk_mq_run_queues(q, false);
125 } 121 }
122}
123
124static void blk_mq_freeze_queue_wait(struct request_queue *q)
125{
126 wait_event(q->mq_freeze_wq, percpu_ref_is_zero(&q->mq_usage_counter)); 126 wait_event(q->mq_freeze_wq, percpu_ref_is_zero(&q->mq_usage_counter));
127} 127}
128 128
129/*
130 * Guarantee no request is in use, so we can change any data structure of
131 * the queue afterward.
132 */
133void blk_mq_freeze_queue(struct request_queue *q)
134{
135 blk_mq_freeze_queue_start(q);
136 blk_mq_freeze_queue_wait(q);
137}
138
129static void blk_mq_unfreeze_queue(struct request_queue *q) 139static void blk_mq_unfreeze_queue(struct request_queue *q)
130{ 140{
131 bool wake; 141 bool wake;
@@ -1921,7 +1931,7 @@ void blk_mq_free_queue(struct request_queue *q)
1921/* Basically redo blk_mq_init_queue with queue frozen */ 1931/* Basically redo blk_mq_init_queue with queue frozen */
1922static void blk_mq_queue_reinit(struct request_queue *q) 1932static void blk_mq_queue_reinit(struct request_queue *q)
1923{ 1933{
1924 blk_mq_freeze_queue(q); 1934 WARN_ON_ONCE(!q->mq_freeze_depth);
1925 1935
1926 blk_mq_sysfs_unregister(q); 1936 blk_mq_sysfs_unregister(q);
1927 1937
@@ -1936,8 +1946,6 @@ static void blk_mq_queue_reinit(struct request_queue *q)
1936 blk_mq_map_swqueue(q); 1946 blk_mq_map_swqueue(q);
1937 1947
1938 blk_mq_sysfs_register(q); 1948 blk_mq_sysfs_register(q);
1939
1940 blk_mq_unfreeze_queue(q);
1941} 1949}
1942 1950
1943static int blk_mq_queue_reinit_notify(struct notifier_block *nb, 1951static int blk_mq_queue_reinit_notify(struct notifier_block *nb,
@@ -1956,8 +1964,25 @@ static int blk_mq_queue_reinit_notify(struct notifier_block *nb,
1956 return NOTIFY_OK; 1964 return NOTIFY_OK;
1957 1965
1958 mutex_lock(&all_q_mutex); 1966 mutex_lock(&all_q_mutex);
1967
1968 /*
1969 * We need to freeze and reinit all existing queues. Freezing
1970 * involves synchronous wait for an RCU grace period and doing it
1971 * one by one may take a long time. Start freezing all queues in
1972 * one swoop and then wait for the completions so that freezing can
1973 * take place in parallel.
1974 */
1975 list_for_each_entry(q, &all_q_list, all_q_node)
1976 blk_mq_freeze_queue_start(q);
1977 list_for_each_entry(q, &all_q_list, all_q_node)
1978 blk_mq_freeze_queue_wait(q);
1979
1959 list_for_each_entry(q, &all_q_list, all_q_node) 1980 list_for_each_entry(q, &all_q_list, all_q_node)
1960 blk_mq_queue_reinit(q); 1981 blk_mq_queue_reinit(q);
1982
1983 list_for_each_entry(q, &all_q_list, all_q_node)
1984 blk_mq_unfreeze_queue(q);
1985
1961 mutex_unlock(&all_q_mutex); 1986 mutex_unlock(&all_q_mutex);
1962 return NOTIFY_OK; 1987 return NOTIFY_OK;
1963} 1988}
diff --git a/block/ioprio.c b/block/ioprio.c
index e50170ca7c33..31666c92b46a 100644
--- a/block/ioprio.c
+++ b/block/ioprio.c
@@ -157,14 +157,16 @@ out:
157 157
158int ioprio_best(unsigned short aprio, unsigned short bprio) 158int ioprio_best(unsigned short aprio, unsigned short bprio)
159{ 159{
160 unsigned short aclass = IOPRIO_PRIO_CLASS(aprio); 160 unsigned short aclass;
161 unsigned short bclass = IOPRIO_PRIO_CLASS(bprio); 161 unsigned short bclass;
162 162
163 if (aclass == IOPRIO_CLASS_NONE) 163 if (!ioprio_valid(aprio))
164 aclass = IOPRIO_CLASS_BE; 164 aprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, IOPRIO_NORM);
165 if (bclass == IOPRIO_CLASS_NONE) 165 if (!ioprio_valid(bprio))
166 bclass = IOPRIO_CLASS_BE; 166 bprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, IOPRIO_NORM);
167 167
168 aclass = IOPRIO_PRIO_CLASS(aprio);
169 bclass = IOPRIO_PRIO_CLASS(bprio);
168 if (aclass == bclass) 170 if (aclass == bclass)
169 return min(aprio, bprio); 171 return min(aprio, bprio);
170 if (aclass > bclass) 172 if (aclass > bclass)
diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
index c7bbc190f16f..28163fad3c5d 100644
--- a/block/scsi_ioctl.c
+++ b/block/scsi_ioctl.c
@@ -458,7 +458,7 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
458 rq = blk_get_request(q, in_len ? WRITE : READ, __GFP_WAIT); 458 rq = blk_get_request(q, in_len ? WRITE : READ, __GFP_WAIT);
459 if (IS_ERR(rq)) { 459 if (IS_ERR(rq)) {
460 err = PTR_ERR(rq); 460 err = PTR_ERR(rq);
461 goto error; 461 goto error_free_buffer;
462 } 462 }
463 blk_rq_set_block_pc(rq); 463 blk_rq_set_block_pc(rq);
464 464
@@ -531,9 +531,11 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
531 } 531 }
532 532
533error: 533error:
534 blk_put_request(rq);
535
536error_free_buffer:
534 kfree(buffer); 537 kfree(buffer);
535 if (rq) 538
536 blk_put_request(rq);
537 return err; 539 return err;
538} 540}
539EXPORT_SYMBOL_GPL(sg_scsi_ioctl); 541EXPORT_SYMBOL_GPL(sg_scsi_ioctl);