diff options
Diffstat (limited to 'block')
-rw-r--r-- | block/blk-merge.c | 18 | ||||
-rw-r--r-- | block/blk-mq.c | 41 | ||||
-rw-r--r-- | block/elevator.c | 4 | ||||
-rw-r--r-- | block/ioprio.c | 14 | ||||
-rw-r--r-- | block/scsi_ioctl.c | 11 |
5 files changed, 61 insertions, 27 deletions
diff --git a/block/blk-merge.c b/block/blk-merge.c index ba99351c0f58..89b97b5e0881 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c | |||
@@ -97,18 +97,22 @@ void blk_recalc_rq_segments(struct request *rq) | |||
97 | 97 | ||
98 | void blk_recount_segments(struct request_queue *q, struct bio *bio) | 98 | void 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 | /* 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; | ||
102 | 107 | ||
103 | if (no_sg_merge && !bio_flagged(bio, BIO_CLONED) && | 108 | if (test_bit(QUEUE_FLAG_NO_SG_MERGE, &q->queue_flags) && |
104 | bio->bi_vcnt < queue_max_segments(q)) | 109 | (seg_cnt < queue_max_segments(q))) |
105 | bio->bi_phys_segments = bio->bi_vcnt; | 110 | bio->bi_phys_segments = seg_cnt; |
106 | else { | 111 | else { |
107 | struct bio *nxt = bio->bi_next; | 112 | struct bio *nxt = bio->bi_next; |
108 | 113 | ||
109 | bio->bi_next = NULL; | 114 | bio->bi_next = NULL; |
110 | bio->bi_phys_segments = __blk_recalc_rq_segments(q, bio, | 115 | bio->bi_phys_segments = __blk_recalc_rq_segments(q, bio, false); |
111 | no_sg_merge); | ||
112 | bio->bi_next = nxt; | 116 | bio->bi_next = nxt; |
113 | } | 117 | } |
114 | 118 | ||
diff --git a/block/blk-mq.c b/block/blk-mq.c index 68929bad9a6a..1d016fc9a8b6 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 | /* | 110 | static 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 | */ | ||
114 | void 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 | |||
124 | static 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 | */ | ||
133 | void 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 | |||
129 | static void blk_mq_unfreeze_queue(struct request_queue *q) | 139 | static 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 */ |
1922 | static void blk_mq_queue_reinit(struct request_queue *q) | 1932 | static 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 | ||
1943 | static int blk_mq_queue_reinit_notify(struct notifier_block *nb, | 1951 | static 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/elevator.c b/block/elevator.c index 24c28b659bb3..afa3b037a17c 100644 --- a/block/elevator.c +++ b/block/elevator.c | |||
@@ -229,7 +229,9 @@ int elevator_init(struct request_queue *q, char *name) | |||
229 | } | 229 | } |
230 | 230 | ||
231 | err = e->ops.elevator_init_fn(q, e); | 231 | err = e->ops.elevator_init_fn(q, e); |
232 | return 0; | 232 | if (err) |
233 | elevator_put(e); | ||
234 | return err; | ||
233 | } | 235 | } |
234 | EXPORT_SYMBOL(elevator_init); | 236 | EXPORT_SYMBOL(elevator_init); |
235 | 237 | ||
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 | ||
158 | int ioprio_best(unsigned short aprio, unsigned short bprio) | 158 | int 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 abb2e65b24cc..b0c2a616c8f9 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 | ||
@@ -508,7 +508,7 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode, | |||
508 | 508 | ||
509 | if (bytes && blk_rq_map_kern(q, rq, buffer, bytes, __GFP_WAIT)) { | 509 | if (bytes && blk_rq_map_kern(q, rq, buffer, bytes, __GFP_WAIT)) { |
510 | err = DRIVER_ERROR << 24; | 510 | err = DRIVER_ERROR << 24; |
511 | goto out; | 511 | goto error; |
512 | } | 512 | } |
513 | 513 | ||
514 | memset(sense, 0, sizeof(sense)); | 514 | memset(sense, 0, sizeof(sense)); |
@@ -517,7 +517,6 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode, | |||
517 | 517 | ||
518 | blk_execute_rq(q, disk, rq, 0); | 518 | blk_execute_rq(q, disk, rq, 0); |
519 | 519 | ||
520 | out: | ||
521 | err = rq->errors & 0xff; /* only 8 bit SCSI status */ | 520 | err = rq->errors & 0xff; /* only 8 bit SCSI status */ |
522 | if (err) { | 521 | if (err) { |
523 | if (rq->sense_len && rq->sense) { | 522 | if (rq->sense_len && rq->sense) { |
@@ -532,9 +531,11 @@ out: | |||
532 | } | 531 | } |
533 | 532 | ||
534 | error: | 533 | error: |
534 | blk_put_request(rq); | ||
535 | |||
536 | error_free_buffer: | ||
535 | kfree(buffer); | 537 | kfree(buffer); |
536 | if (rq) | 538 | |
537 | blk_put_request(rq); | ||
538 | return err; | 539 | return err; |
539 | } | 540 | } |
540 | EXPORT_SYMBOL_GPL(sg_scsi_ioctl); | 541 | EXPORT_SYMBOL_GPL(sg_scsi_ioctl); |