| .. | .. |
|---|
| 231 | 231 | struct dm_target *ti; /* Only set if a pool target is bound */ |
|---|
| 232 | 232 | |
|---|
| 233 | 233 | struct mapped_device *pool_md; |
|---|
| 234 | + struct block_device *data_dev; |
|---|
| 234 | 235 | struct block_device *md_dev; |
|---|
| 235 | 236 | struct dm_pool_metadata *pmd; |
|---|
| 236 | 237 | |
|---|
| .. | .. |
|---|
| 281 | 282 | struct dm_bio_prison_cell **cell_sort_array; |
|---|
| 282 | 283 | |
|---|
| 283 | 284 | mempool_t mapping_pool; |
|---|
| 285 | + |
|---|
| 286 | + struct bio flush_bio; |
|---|
| 284 | 287 | }; |
|---|
| 285 | 288 | |
|---|
| 286 | 289 | static void metadata_operation_failed(struct pool *pool, const char *op, int r); |
|---|
| .. | .. |
|---|
| 323 | 326 | struct pool *pool; |
|---|
| 324 | 327 | struct dm_dev *data_dev; |
|---|
| 325 | 328 | struct dm_dev *metadata_dev; |
|---|
| 326 | | - struct dm_target_callbacks callbacks; |
|---|
| 327 | 329 | |
|---|
| 328 | 330 | dm_block_t low_water_blocks; |
|---|
| 329 | 331 | struct pool_features requested_pf; /* Features requested during table load */ |
|---|
| .. | .. |
|---|
| 355 | 357 | * Ensures the thin is not destroyed until the worker has finished |
|---|
| 356 | 358 | * iterating the active_thins list. |
|---|
| 357 | 359 | */ |
|---|
| 358 | | - atomic_t refcount; |
|---|
| 360 | + refcount_t refcount; |
|---|
| 359 | 361 | struct completion can_destroy; |
|---|
| 360 | 362 | }; |
|---|
| 361 | 363 | |
|---|
| .. | .. |
|---|
| 609 | 611 | blk_status_t error) |
|---|
| 610 | 612 | { |
|---|
| 611 | 613 | struct bio_list bios; |
|---|
| 612 | | - unsigned long flags; |
|---|
| 613 | 614 | |
|---|
| 614 | 615 | bio_list_init(&bios); |
|---|
| 615 | 616 | |
|---|
| 616 | | - spin_lock_irqsave(&tc->lock, flags); |
|---|
| 617 | + spin_lock_irq(&tc->lock); |
|---|
| 617 | 618 | __merge_bio_list(&bios, master); |
|---|
| 618 | | - spin_unlock_irqrestore(&tc->lock, flags); |
|---|
| 619 | + spin_unlock_irq(&tc->lock); |
|---|
| 619 | 620 | |
|---|
| 620 | 621 | error_bio_list(&bios, error); |
|---|
| 621 | 622 | } |
|---|
| .. | .. |
|---|
| 623 | 624 | static void requeue_deferred_cells(struct thin_c *tc) |
|---|
| 624 | 625 | { |
|---|
| 625 | 626 | struct pool *pool = tc->pool; |
|---|
| 626 | | - unsigned long flags; |
|---|
| 627 | 627 | struct list_head cells; |
|---|
| 628 | 628 | struct dm_bio_prison_cell *cell, *tmp; |
|---|
| 629 | 629 | |
|---|
| 630 | 630 | INIT_LIST_HEAD(&cells); |
|---|
| 631 | 631 | |
|---|
| 632 | | - spin_lock_irqsave(&tc->lock, flags); |
|---|
| 632 | + spin_lock_irq(&tc->lock); |
|---|
| 633 | 633 | list_splice_init(&tc->deferred_cells, &cells); |
|---|
| 634 | | - spin_unlock_irqrestore(&tc->lock, flags); |
|---|
| 634 | + spin_unlock_irq(&tc->lock); |
|---|
| 635 | 635 | |
|---|
| 636 | 636 | list_for_each_entry_safe(cell, tmp, &cells, user_list) |
|---|
| 637 | 637 | cell_requeue(pool, cell); |
|---|
| .. | .. |
|---|
| 640 | 640 | static void requeue_io(struct thin_c *tc) |
|---|
| 641 | 641 | { |
|---|
| 642 | 642 | struct bio_list bios; |
|---|
| 643 | | - unsigned long flags; |
|---|
| 644 | 643 | |
|---|
| 645 | 644 | bio_list_init(&bios); |
|---|
| 646 | 645 | |
|---|
| 647 | | - spin_lock_irqsave(&tc->lock, flags); |
|---|
| 646 | + spin_lock_irq(&tc->lock); |
|---|
| 648 | 647 | __merge_bio_list(&bios, &tc->deferred_bio_list); |
|---|
| 649 | 648 | __merge_bio_list(&bios, &tc->retry_on_resume_list); |
|---|
| 650 | | - spin_unlock_irqrestore(&tc->lock, flags); |
|---|
| 649 | + spin_unlock_irq(&tc->lock); |
|---|
| 651 | 650 | |
|---|
| 652 | 651 | error_bio_list(&bios, BLK_STS_DM_REQUEUE); |
|---|
| 653 | 652 | requeue_deferred_cells(tc); |
|---|
| .. | .. |
|---|
| 756 | 755 | static void issue(struct thin_c *tc, struct bio *bio) |
|---|
| 757 | 756 | { |
|---|
| 758 | 757 | struct pool *pool = tc->pool; |
|---|
| 759 | | - unsigned long flags; |
|---|
| 760 | 758 | |
|---|
| 761 | 759 | if (!bio_triggers_commit(tc, bio)) { |
|---|
| 762 | | - generic_make_request(bio); |
|---|
| 760 | + submit_bio_noacct(bio); |
|---|
| 763 | 761 | return; |
|---|
| 764 | 762 | } |
|---|
| 765 | 763 | |
|---|
| .. | .. |
|---|
| 777 | 775 | * Batch together any bios that trigger commits and then issue a |
|---|
| 778 | 776 | * single commit for them in process_deferred_bios(). |
|---|
| 779 | 777 | */ |
|---|
| 780 | | - spin_lock_irqsave(&pool->lock, flags); |
|---|
| 778 | + spin_lock_irq(&pool->lock); |
|---|
| 781 | 779 | bio_list_add(&pool->deferred_flush_bios, bio); |
|---|
| 782 | | - spin_unlock_irqrestore(&pool->lock, flags); |
|---|
| 780 | + spin_unlock_irq(&pool->lock); |
|---|
| 783 | 781 | } |
|---|
| 784 | 782 | |
|---|
| 785 | 783 | static void remap_to_origin_and_issue(struct thin_c *tc, struct bio *bio) |
|---|
| .. | .. |
|---|
| 886 | 884 | { |
|---|
| 887 | 885 | struct pool *pool = tc->pool; |
|---|
| 888 | 886 | unsigned long flags; |
|---|
| 887 | + int has_work; |
|---|
| 889 | 888 | |
|---|
| 890 | 889 | spin_lock_irqsave(&tc->lock, flags); |
|---|
| 891 | 890 | cell_release_no_holder(pool, cell, &tc->deferred_bio_list); |
|---|
| 891 | + has_work = !bio_list_empty(&tc->deferred_bio_list); |
|---|
| 892 | 892 | spin_unlock_irqrestore(&tc->lock, flags); |
|---|
| 893 | 893 | |
|---|
| 894 | | - wake_worker(pool); |
|---|
| 894 | + if (has_work) |
|---|
| 895 | + wake_worker(pool); |
|---|
| 895 | 896 | } |
|---|
| 896 | 897 | |
|---|
| 897 | 898 | static void thin_defer_bio(struct thin_c *tc, struct bio *bio); |
|---|
| .. | .. |
|---|
| 960 | 961 | static void complete_overwrite_bio(struct thin_c *tc, struct bio *bio) |
|---|
| 961 | 962 | { |
|---|
| 962 | 963 | struct pool *pool = tc->pool; |
|---|
| 963 | | - unsigned long flags; |
|---|
| 964 | 964 | |
|---|
| 965 | 965 | /* |
|---|
| 966 | 966 | * If the bio has the REQ_FUA flag set we must commit the metadata |
|---|
| .. | .. |
|---|
| 985 | 985 | * Batch together any bios that trigger commits and then issue a |
|---|
| 986 | 986 | * single commit for them in process_deferred_bios(). |
|---|
| 987 | 987 | */ |
|---|
| 988 | | - spin_lock_irqsave(&pool->lock, flags); |
|---|
| 988 | + spin_lock_irq(&pool->lock); |
|---|
| 989 | 989 | bio_list_add(&pool->deferred_flush_completions, bio); |
|---|
| 990 | | - spin_unlock_irqrestore(&pool->lock, flags); |
|---|
| 990 | + spin_unlock_irq(&pool->lock); |
|---|
| 991 | 991 | } |
|---|
| 992 | 992 | |
|---|
| 993 | 993 | static void process_prepared_mapping(struct dm_thin_new_mapping *m) |
|---|
| .. | .. |
|---|
| 1226 | 1226 | static void process_prepared(struct pool *pool, struct list_head *head, |
|---|
| 1227 | 1227 | process_mapping_fn *fn) |
|---|
| 1228 | 1228 | { |
|---|
| 1229 | | - unsigned long flags; |
|---|
| 1230 | 1229 | struct list_head maps; |
|---|
| 1231 | 1230 | struct dm_thin_new_mapping *m, *tmp; |
|---|
| 1232 | 1231 | |
|---|
| 1233 | 1232 | INIT_LIST_HEAD(&maps); |
|---|
| 1234 | | - spin_lock_irqsave(&pool->lock, flags); |
|---|
| 1233 | + spin_lock_irq(&pool->lock); |
|---|
| 1235 | 1234 | list_splice_init(head, &maps); |
|---|
| 1236 | | - spin_unlock_irqrestore(&pool->lock, flags); |
|---|
| 1235 | + spin_unlock_irq(&pool->lock); |
|---|
| 1237 | 1236 | |
|---|
| 1238 | 1237 | list_for_each_entry_safe(m, tmp, &maps, list) |
|---|
| 1239 | 1238 | (*fn)(m); |
|---|
| .. | .. |
|---|
| 1510 | 1509 | |
|---|
| 1511 | 1510 | static void check_low_water_mark(struct pool *pool, dm_block_t free_blocks) |
|---|
| 1512 | 1511 | { |
|---|
| 1513 | | - unsigned long flags; |
|---|
| 1514 | | - |
|---|
| 1515 | 1512 | if (free_blocks <= pool->low_water_blocks && !pool->low_water_triggered) { |
|---|
| 1516 | 1513 | DMWARN("%s: reached low water mark for data device: sending event.", |
|---|
| 1517 | 1514 | dm_device_name(pool->pool_md)); |
|---|
| 1518 | | - spin_lock_irqsave(&pool->lock, flags); |
|---|
| 1515 | + spin_lock_irq(&pool->lock); |
|---|
| 1519 | 1516 | pool->low_water_triggered = true; |
|---|
| 1520 | | - spin_unlock_irqrestore(&pool->lock, flags); |
|---|
| 1517 | + spin_unlock_irq(&pool->lock); |
|---|
| 1521 | 1518 | dm_table_event(pool->ti->table); |
|---|
| 1522 | 1519 | } |
|---|
| 1523 | 1520 | } |
|---|
| .. | .. |
|---|
| 1593 | 1590 | { |
|---|
| 1594 | 1591 | struct dm_thin_endio_hook *h = dm_per_bio_data(bio, sizeof(struct dm_thin_endio_hook)); |
|---|
| 1595 | 1592 | struct thin_c *tc = h->tc; |
|---|
| 1596 | | - unsigned long flags; |
|---|
| 1597 | 1593 | |
|---|
| 1598 | | - spin_lock_irqsave(&tc->lock, flags); |
|---|
| 1594 | + spin_lock_irq(&tc->lock); |
|---|
| 1599 | 1595 | bio_list_add(&tc->retry_on_resume_list, bio); |
|---|
| 1600 | | - spin_unlock_irqrestore(&tc->lock, flags); |
|---|
| 1596 | + spin_unlock_irq(&tc->lock); |
|---|
| 1601 | 1597 | } |
|---|
| 1602 | 1598 | |
|---|
| 1603 | 1599 | static blk_status_t should_error_unserviceable_bio(struct pool *pool) |
|---|
| .. | .. |
|---|
| 2170 | 2166 | static void process_thin_deferred_bios(struct thin_c *tc) |
|---|
| 2171 | 2167 | { |
|---|
| 2172 | 2168 | struct pool *pool = tc->pool; |
|---|
| 2173 | | - unsigned long flags; |
|---|
| 2174 | 2169 | struct bio *bio; |
|---|
| 2175 | 2170 | struct bio_list bios; |
|---|
| 2176 | 2171 | struct blk_plug plug; |
|---|
| .. | .. |
|---|
| 2184 | 2179 | |
|---|
| 2185 | 2180 | bio_list_init(&bios); |
|---|
| 2186 | 2181 | |
|---|
| 2187 | | - spin_lock_irqsave(&tc->lock, flags); |
|---|
| 2182 | + spin_lock_irq(&tc->lock); |
|---|
| 2188 | 2183 | |
|---|
| 2189 | 2184 | if (bio_list_empty(&tc->deferred_bio_list)) { |
|---|
| 2190 | | - spin_unlock_irqrestore(&tc->lock, flags); |
|---|
| 2185 | + spin_unlock_irq(&tc->lock); |
|---|
| 2191 | 2186 | return; |
|---|
| 2192 | 2187 | } |
|---|
| 2193 | 2188 | |
|---|
| .. | .. |
|---|
| 2196 | 2191 | bio_list_merge(&bios, &tc->deferred_bio_list); |
|---|
| 2197 | 2192 | bio_list_init(&tc->deferred_bio_list); |
|---|
| 2198 | 2193 | |
|---|
| 2199 | | - spin_unlock_irqrestore(&tc->lock, flags); |
|---|
| 2194 | + spin_unlock_irq(&tc->lock); |
|---|
| 2200 | 2195 | |
|---|
| 2201 | 2196 | blk_start_plug(&plug); |
|---|
| 2202 | 2197 | while ((bio = bio_list_pop(&bios))) { |
|---|
| .. | .. |
|---|
| 2206 | 2201 | * prepared mappings to process. |
|---|
| 2207 | 2202 | */ |
|---|
| 2208 | 2203 | if (ensure_next_mapping(pool)) { |
|---|
| 2209 | | - spin_lock_irqsave(&tc->lock, flags); |
|---|
| 2204 | + spin_lock_irq(&tc->lock); |
|---|
| 2210 | 2205 | bio_list_add(&tc->deferred_bio_list, bio); |
|---|
| 2211 | 2206 | bio_list_merge(&tc->deferred_bio_list, &bios); |
|---|
| 2212 | | - spin_unlock_irqrestore(&tc->lock, flags); |
|---|
| 2207 | + spin_unlock_irq(&tc->lock); |
|---|
| 2213 | 2208 | break; |
|---|
| 2214 | 2209 | } |
|---|
| 2215 | 2210 | |
|---|
| .. | .. |
|---|
| 2222 | 2217 | throttle_work_update(&pool->throttle); |
|---|
| 2223 | 2218 | dm_pool_issue_prefetches(pool->pmd); |
|---|
| 2224 | 2219 | } |
|---|
| 2220 | + cond_resched(); |
|---|
| 2225 | 2221 | } |
|---|
| 2226 | 2222 | blk_finish_plug(&plug); |
|---|
| 2227 | 2223 | } |
|---|
| .. | .. |
|---|
| 2264 | 2260 | static void process_thin_deferred_cells(struct thin_c *tc) |
|---|
| 2265 | 2261 | { |
|---|
| 2266 | 2262 | struct pool *pool = tc->pool; |
|---|
| 2267 | | - unsigned long flags; |
|---|
| 2268 | 2263 | struct list_head cells; |
|---|
| 2269 | 2264 | struct dm_bio_prison_cell *cell; |
|---|
| 2270 | 2265 | unsigned i, j, count; |
|---|
| 2271 | 2266 | |
|---|
| 2272 | 2267 | INIT_LIST_HEAD(&cells); |
|---|
| 2273 | 2268 | |
|---|
| 2274 | | - spin_lock_irqsave(&tc->lock, flags); |
|---|
| 2269 | + spin_lock_irq(&tc->lock); |
|---|
| 2275 | 2270 | list_splice_init(&tc->deferred_cells, &cells); |
|---|
| 2276 | | - spin_unlock_irqrestore(&tc->lock, flags); |
|---|
| 2271 | + spin_unlock_irq(&tc->lock); |
|---|
| 2277 | 2272 | |
|---|
| 2278 | 2273 | if (list_empty(&cells)) |
|---|
| 2279 | 2274 | return; |
|---|
| .. | .. |
|---|
| 2294 | 2289 | for (j = i; j < count; j++) |
|---|
| 2295 | 2290 | list_add(&pool->cell_sort_array[j]->user_list, &cells); |
|---|
| 2296 | 2291 | |
|---|
| 2297 | | - spin_lock_irqsave(&tc->lock, flags); |
|---|
| 2292 | + spin_lock_irq(&tc->lock); |
|---|
| 2298 | 2293 | list_splice(&cells, &tc->deferred_cells); |
|---|
| 2299 | | - spin_unlock_irqrestore(&tc->lock, flags); |
|---|
| 2294 | + spin_unlock_irq(&tc->lock); |
|---|
| 2300 | 2295 | return; |
|---|
| 2301 | 2296 | } |
|---|
| 2302 | 2297 | |
|---|
| .. | .. |
|---|
| 2305 | 2300 | else |
|---|
| 2306 | 2301 | pool->process_cell(tc, cell); |
|---|
| 2307 | 2302 | } |
|---|
| 2303 | + cond_resched(); |
|---|
| 2308 | 2304 | } while (!list_empty(&cells)); |
|---|
| 2309 | 2305 | } |
|---|
| 2310 | 2306 | |
|---|
| .. | .. |
|---|
| 2349 | 2345 | |
|---|
| 2350 | 2346 | static void process_deferred_bios(struct pool *pool) |
|---|
| 2351 | 2347 | { |
|---|
| 2352 | | - unsigned long flags; |
|---|
| 2353 | 2348 | struct bio *bio; |
|---|
| 2354 | 2349 | struct bio_list bios, bio_completions; |
|---|
| 2355 | 2350 | struct thin_c *tc; |
|---|
| .. | .. |
|---|
| 2368 | 2363 | bio_list_init(&bios); |
|---|
| 2369 | 2364 | bio_list_init(&bio_completions); |
|---|
| 2370 | 2365 | |
|---|
| 2371 | | - spin_lock_irqsave(&pool->lock, flags); |
|---|
| 2366 | + spin_lock_irq(&pool->lock); |
|---|
| 2372 | 2367 | bio_list_merge(&bios, &pool->deferred_flush_bios); |
|---|
| 2373 | 2368 | bio_list_init(&pool->deferred_flush_bios); |
|---|
| 2374 | 2369 | |
|---|
| 2375 | 2370 | bio_list_merge(&bio_completions, &pool->deferred_flush_completions); |
|---|
| 2376 | 2371 | bio_list_init(&pool->deferred_flush_completions); |
|---|
| 2377 | | - spin_unlock_irqrestore(&pool->lock, flags); |
|---|
| 2372 | + spin_unlock_irq(&pool->lock); |
|---|
| 2378 | 2373 | |
|---|
| 2379 | 2374 | if (bio_list_empty(&bios) && bio_list_empty(&bio_completions) && |
|---|
| 2380 | 2375 | !(dm_pool_changed_this_transaction(pool->pmd) && need_commit_due_to_time(pool))) |
|---|
| .. | .. |
|---|
| 2392 | 2387 | while ((bio = bio_list_pop(&bio_completions))) |
|---|
| 2393 | 2388 | bio_endio(bio); |
|---|
| 2394 | 2389 | |
|---|
| 2395 | | - while ((bio = bio_list_pop(&bios))) |
|---|
| 2396 | | - generic_make_request(bio); |
|---|
| 2390 | + while ((bio = bio_list_pop(&bios))) { |
|---|
| 2391 | + /* |
|---|
| 2392 | + * The data device was flushed as part of metadata commit, |
|---|
| 2393 | + * so complete redundant flushes immediately. |
|---|
| 2394 | + */ |
|---|
| 2395 | + if (bio->bi_opf & REQ_PREFLUSH) |
|---|
| 2396 | + bio_endio(bio); |
|---|
| 2397 | + else |
|---|
| 2398 | + submit_bio_noacct(bio); |
|---|
| 2399 | + } |
|---|
| 2397 | 2400 | } |
|---|
| 2398 | 2401 | |
|---|
| 2399 | 2402 | static void do_worker(struct work_struct *ws) |
|---|
| .. | .. |
|---|
| 2657 | 2660 | */ |
|---|
| 2658 | 2661 | static void thin_defer_bio(struct thin_c *tc, struct bio *bio) |
|---|
| 2659 | 2662 | { |
|---|
| 2660 | | - unsigned long flags; |
|---|
| 2661 | 2663 | struct pool *pool = tc->pool; |
|---|
| 2662 | 2664 | |
|---|
| 2663 | | - spin_lock_irqsave(&tc->lock, flags); |
|---|
| 2665 | + spin_lock_irq(&tc->lock); |
|---|
| 2664 | 2666 | bio_list_add(&tc->deferred_bio_list, bio); |
|---|
| 2665 | | - spin_unlock_irqrestore(&tc->lock, flags); |
|---|
| 2667 | + spin_unlock_irq(&tc->lock); |
|---|
| 2666 | 2668 | |
|---|
| 2667 | 2669 | wake_worker(pool); |
|---|
| 2668 | 2670 | } |
|---|
| .. | .. |
|---|
| 2678 | 2680 | |
|---|
| 2679 | 2681 | static void thin_defer_cell(struct thin_c *tc, struct dm_bio_prison_cell *cell) |
|---|
| 2680 | 2682 | { |
|---|
| 2681 | | - unsigned long flags; |
|---|
| 2682 | 2683 | struct pool *pool = tc->pool; |
|---|
| 2683 | 2684 | |
|---|
| 2684 | 2685 | throttle_lock(&pool->throttle); |
|---|
| 2685 | | - spin_lock_irqsave(&tc->lock, flags); |
|---|
| 2686 | + spin_lock_irq(&tc->lock); |
|---|
| 2686 | 2687 | list_add_tail(&cell->user_list, &tc->deferred_cells); |
|---|
| 2687 | | - spin_unlock_irqrestore(&tc->lock, flags); |
|---|
| 2688 | + spin_unlock_irq(&tc->lock); |
|---|
| 2688 | 2689 | throttle_unlock(&pool->throttle); |
|---|
| 2689 | 2690 | |
|---|
| 2690 | 2691 | wake_worker(pool); |
|---|
| .. | .. |
|---|
| 2796 | 2797 | } |
|---|
| 2797 | 2798 | } |
|---|
| 2798 | 2799 | |
|---|
| 2799 | | -static int pool_is_congested(struct dm_target_callbacks *cb, int bdi_bits) |
|---|
| 2800 | | -{ |
|---|
| 2801 | | - struct pool_c *pt = container_of(cb, struct pool_c, callbacks); |
|---|
| 2802 | | - struct request_queue *q; |
|---|
| 2803 | | - |
|---|
| 2804 | | - if (get_pool_mode(pt->pool) == PM_OUT_OF_DATA_SPACE) |
|---|
| 2805 | | - return 1; |
|---|
| 2806 | | - |
|---|
| 2807 | | - q = bdev_get_queue(pt->data_dev->bdev); |
|---|
| 2808 | | - return bdi_congested(q->backing_dev_info, bdi_bits); |
|---|
| 2809 | | -} |
|---|
| 2810 | | - |
|---|
| 2811 | 2800 | static void requeue_bios(struct pool *pool) |
|---|
| 2812 | 2801 | { |
|---|
| 2813 | | - unsigned long flags; |
|---|
| 2814 | 2802 | struct thin_c *tc; |
|---|
| 2815 | 2803 | |
|---|
| 2816 | 2804 | rcu_read_lock(); |
|---|
| 2817 | 2805 | list_for_each_entry_rcu(tc, &pool->active_thins, list) { |
|---|
| 2818 | | - spin_lock_irqsave(&tc->lock, flags); |
|---|
| 2806 | + spin_lock_irq(&tc->lock); |
|---|
| 2819 | 2807 | bio_list_merge(&tc->deferred_bio_list, &tc->retry_on_resume_list); |
|---|
| 2820 | 2808 | bio_list_init(&tc->retry_on_resume_list); |
|---|
| 2821 | | - spin_unlock_irqrestore(&tc->lock, flags); |
|---|
| 2809 | + spin_unlock_irq(&tc->lock); |
|---|
| 2822 | 2810 | } |
|---|
| 2823 | 2811 | rcu_read_unlock(); |
|---|
| 2824 | 2812 | } |
|---|
| .. | .. |
|---|
| 2921 | 2909 | dm_bio_prison_destroy(pool->prison); |
|---|
| 2922 | 2910 | dm_kcopyd_client_destroy(pool->copier); |
|---|
| 2923 | 2911 | |
|---|
| 2912 | + cancel_delayed_work_sync(&pool->waker); |
|---|
| 2913 | + cancel_delayed_work_sync(&pool->no_space_timeout); |
|---|
| 2924 | 2914 | if (pool->wq) |
|---|
| 2925 | 2915 | destroy_workqueue(pool->wq); |
|---|
| 2926 | 2916 | |
|---|
| 2927 | 2917 | if (pool->next_mapping) |
|---|
| 2928 | 2918 | mempool_free(pool->next_mapping, &pool->mapping_pool); |
|---|
| 2929 | 2919 | mempool_exit(&pool->mapping_pool); |
|---|
| 2920 | + bio_uninit(&pool->flush_bio); |
|---|
| 2930 | 2921 | dm_deferred_set_destroy(pool->shared_read_ds); |
|---|
| 2931 | 2922 | dm_deferred_set_destroy(pool->all_io_ds); |
|---|
| 2932 | 2923 | kfree(pool); |
|---|
| .. | .. |
|---|
| 2936 | 2927 | |
|---|
| 2937 | 2928 | static struct pool *pool_create(struct mapped_device *pool_md, |
|---|
| 2938 | 2929 | struct block_device *metadata_dev, |
|---|
| 2930 | + struct block_device *data_dev, |
|---|
| 2939 | 2931 | unsigned long block_size, |
|---|
| 2940 | 2932 | int read_only, char **error) |
|---|
| 2941 | 2933 | { |
|---|
| .. | .. |
|---|
| 3006 | 2998 | pool->low_water_triggered = false; |
|---|
| 3007 | 2999 | pool->suspended = true; |
|---|
| 3008 | 3000 | pool->out_of_data_space = false; |
|---|
| 3001 | + bio_init(&pool->flush_bio, NULL, 0); |
|---|
| 3009 | 3002 | |
|---|
| 3010 | 3003 | pool->shared_read_ds = dm_deferred_set_create(); |
|---|
| 3011 | 3004 | if (!pool->shared_read_ds) { |
|---|
| .. | .. |
|---|
| 3043 | 3036 | pool->last_commit_jiffies = jiffies; |
|---|
| 3044 | 3037 | pool->pool_md = pool_md; |
|---|
| 3045 | 3038 | pool->md_dev = metadata_dev; |
|---|
| 3039 | + pool->data_dev = data_dev; |
|---|
| 3046 | 3040 | __pool_table_insert(pool); |
|---|
| 3047 | 3041 | |
|---|
| 3048 | 3042 | return pool; |
|---|
| .. | .. |
|---|
| 3084 | 3078 | |
|---|
| 3085 | 3079 | static struct pool *__pool_find(struct mapped_device *pool_md, |
|---|
| 3086 | 3080 | struct block_device *metadata_dev, |
|---|
| 3081 | + struct block_device *data_dev, |
|---|
| 3087 | 3082 | unsigned long block_size, int read_only, |
|---|
| 3088 | 3083 | char **error, int *created) |
|---|
| 3089 | 3084 | { |
|---|
| .. | .. |
|---|
| 3094 | 3089 | *error = "metadata device already in use by a pool"; |
|---|
| 3095 | 3090 | return ERR_PTR(-EBUSY); |
|---|
| 3096 | 3091 | } |
|---|
| 3092 | + if (pool->data_dev != data_dev) { |
|---|
| 3093 | + *error = "data device already in use by a pool"; |
|---|
| 3094 | + return ERR_PTR(-EBUSY); |
|---|
| 3095 | + } |
|---|
| 3097 | 3096 | __pool_inc(pool); |
|---|
| 3098 | 3097 | |
|---|
| 3099 | 3098 | } else { |
|---|
| 3100 | 3099 | pool = __pool_table_lookup(pool_md); |
|---|
| 3101 | 3100 | if (pool) { |
|---|
| 3102 | | - if (pool->md_dev != metadata_dev) { |
|---|
| 3101 | + if (pool->md_dev != metadata_dev || pool->data_dev != data_dev) { |
|---|
| 3103 | 3102 | *error = "different pool cannot replace a pool"; |
|---|
| 3104 | 3103 | return ERR_PTR(-EINVAL); |
|---|
| 3105 | 3104 | } |
|---|
| 3106 | 3105 | __pool_inc(pool); |
|---|
| 3107 | 3106 | |
|---|
| 3108 | 3107 | } else { |
|---|
| 3109 | | - pool = pool_create(pool_md, metadata_dev, block_size, read_only, error); |
|---|
| 3108 | + pool = pool_create(pool_md, metadata_dev, data_dev, block_size, read_only, error); |
|---|
| 3110 | 3109 | *created = 1; |
|---|
| 3111 | 3110 | } |
|---|
| 3112 | 3111 | } |
|---|
| .. | .. |
|---|
| 3190 | 3189 | dm_device_name(pool->pool_md)); |
|---|
| 3191 | 3190 | |
|---|
| 3192 | 3191 | dm_table_event(pool->ti->table); |
|---|
| 3192 | +} |
|---|
| 3193 | + |
|---|
| 3194 | +/* |
|---|
| 3195 | + * We need to flush the data device **before** committing the metadata. |
|---|
| 3196 | + * |
|---|
| 3197 | + * This ensures that the data blocks of any newly inserted mappings are |
|---|
| 3198 | + * properly written to non-volatile storage and won't be lost in case of a |
|---|
| 3199 | + * crash. |
|---|
| 3200 | + * |
|---|
| 3201 | + * Failure to do so can result in data corruption in the case of internal or |
|---|
| 3202 | + * external snapshots and in the case of newly provisioned blocks, when block |
|---|
| 3203 | + * zeroing is enabled. |
|---|
| 3204 | + */ |
|---|
| 3205 | +static int metadata_pre_commit_callback(void *context) |
|---|
| 3206 | +{ |
|---|
| 3207 | + struct pool *pool = context; |
|---|
| 3208 | + struct bio *flush_bio = &pool->flush_bio; |
|---|
| 3209 | + |
|---|
| 3210 | + bio_reset(flush_bio); |
|---|
| 3211 | + bio_set_dev(flush_bio, pool->data_dev); |
|---|
| 3212 | + flush_bio->bi_opf = REQ_OP_WRITE | REQ_PREFLUSH; |
|---|
| 3213 | + |
|---|
| 3214 | + return submit_bio_wait(flush_bio); |
|---|
| 3193 | 3215 | } |
|---|
| 3194 | 3216 | |
|---|
| 3195 | 3217 | static sector_t get_dev_size(struct block_device *bdev) |
|---|
| .. | .. |
|---|
| 3335 | 3357 | goto out; |
|---|
| 3336 | 3358 | } |
|---|
| 3337 | 3359 | |
|---|
| 3338 | | - pool = __pool_find(dm_table_get_md(ti->table), metadata_dev->bdev, |
|---|
| 3360 | + pool = __pool_find(dm_table_get_md(ti->table), metadata_dev->bdev, data_dev->bdev, |
|---|
| 3339 | 3361 | block_size, pf.mode == PM_READ_ONLY, &ti->error, &pool_created); |
|---|
| 3340 | 3362 | if (IS_ERR(pool)) { |
|---|
| 3341 | 3363 | r = PTR_ERR(pool); |
|---|
| .. | .. |
|---|
| 3361 | 3383 | pt->low_water_blocks = low_water_blocks; |
|---|
| 3362 | 3384 | pt->adjusted_pf = pt->requested_pf = pf; |
|---|
| 3363 | 3385 | ti->num_flush_bios = 1; |
|---|
| 3386 | + ti->limit_swap_bios = true; |
|---|
| 3364 | 3387 | |
|---|
| 3365 | 3388 | /* |
|---|
| 3366 | 3389 | * Only need to enable discards if the pool should pass |
|---|
| .. | .. |
|---|
| 3383 | 3406 | calc_metadata_threshold(pt), |
|---|
| 3384 | 3407 | metadata_low_callback, |
|---|
| 3385 | 3408 | pool); |
|---|
| 3386 | | - if (r) |
|---|
| 3409 | + if (r) { |
|---|
| 3410 | + ti->error = "Error registering metadata threshold"; |
|---|
| 3387 | 3411 | goto out_flags_changed; |
|---|
| 3412 | + } |
|---|
| 3388 | 3413 | |
|---|
| 3389 | | - pt->callbacks.congested_fn = pool_is_congested; |
|---|
| 3390 | | - dm_table_add_target_callbacks(ti->table, &pt->callbacks); |
|---|
| 3414 | + dm_pool_register_pre_commit_callback(pool->pmd, |
|---|
| 3415 | + metadata_pre_commit_callback, pool); |
|---|
| 3391 | 3416 | |
|---|
| 3392 | 3417 | mutex_unlock(&dm_thin_pool_table.mutex); |
|---|
| 3393 | 3418 | |
|---|
| .. | .. |
|---|
| 3412 | 3437 | int r; |
|---|
| 3413 | 3438 | struct pool_c *pt = ti->private; |
|---|
| 3414 | 3439 | struct pool *pool = pt->pool; |
|---|
| 3415 | | - unsigned long flags; |
|---|
| 3416 | 3440 | |
|---|
| 3417 | 3441 | /* |
|---|
| 3418 | 3442 | * As this is a singleton target, ti->begin is always zero. |
|---|
| 3419 | 3443 | */ |
|---|
| 3420 | | - spin_lock_irqsave(&pool->lock, flags); |
|---|
| 3444 | + spin_lock_irq(&pool->lock); |
|---|
| 3421 | 3445 | bio_set_dev(bio, pt->data_dev->bdev); |
|---|
| 3422 | 3446 | r = DM_MAPIO_REMAPPED; |
|---|
| 3423 | | - spin_unlock_irqrestore(&pool->lock, flags); |
|---|
| 3447 | + spin_unlock_irq(&pool->lock); |
|---|
| 3424 | 3448 | |
|---|
| 3425 | 3449 | return r; |
|---|
| 3426 | 3450 | } |
|---|
| .. | .. |
|---|
| 3547 | 3571 | */ |
|---|
| 3548 | 3572 | r = bind_control_target(pool, ti); |
|---|
| 3549 | 3573 | if (r) |
|---|
| 3550 | | - return r; |
|---|
| 3574 | + goto out; |
|---|
| 3551 | 3575 | |
|---|
| 3552 | 3576 | r = maybe_resize_data_dev(ti, &need_commit1); |
|---|
| 3553 | 3577 | if (r) |
|---|
| 3554 | | - return r; |
|---|
| 3578 | + goto out; |
|---|
| 3555 | 3579 | |
|---|
| 3556 | 3580 | r = maybe_resize_metadata_dev(ti, &need_commit2); |
|---|
| 3557 | 3581 | if (r) |
|---|
| 3558 | | - return r; |
|---|
| 3582 | + goto out; |
|---|
| 3559 | 3583 | |
|---|
| 3560 | 3584 | if (need_commit1 || need_commit2) |
|---|
| 3561 | 3585 | (void) commit(pool); |
|---|
| 3586 | +out: |
|---|
| 3587 | + /* |
|---|
| 3588 | + * When a thin-pool is PM_FAIL, it cannot be rebuilt if |
|---|
| 3589 | + * bio is in deferred list. Therefore need to return 0 |
|---|
| 3590 | + * to allow pool_resume() to flush IO. |
|---|
| 3591 | + */ |
|---|
| 3592 | + if (r && get_pool_mode(pool) == PM_FAIL) |
|---|
| 3593 | + r = 0; |
|---|
| 3562 | 3594 | |
|---|
| 3563 | | - return 0; |
|---|
| 3595 | + return r; |
|---|
| 3564 | 3596 | } |
|---|
| 3565 | 3597 | |
|---|
| 3566 | 3598 | static void pool_suspend_active_thins(struct pool *pool) |
|---|
| .. | .. |
|---|
| 3591 | 3623 | { |
|---|
| 3592 | 3624 | struct pool_c *pt = ti->private; |
|---|
| 3593 | 3625 | struct pool *pool = pt->pool; |
|---|
| 3594 | | - unsigned long flags; |
|---|
| 3595 | 3626 | |
|---|
| 3596 | 3627 | /* |
|---|
| 3597 | 3628 | * Must requeue active_thins' bios and then resume |
|---|
| .. | .. |
|---|
| 3600 | 3631 | requeue_bios(pool); |
|---|
| 3601 | 3632 | pool_resume_active_thins(pool); |
|---|
| 3602 | 3633 | |
|---|
| 3603 | | - spin_lock_irqsave(&pool->lock, flags); |
|---|
| 3634 | + spin_lock_irq(&pool->lock); |
|---|
| 3604 | 3635 | pool->low_water_triggered = false; |
|---|
| 3605 | 3636 | pool->suspended = false; |
|---|
| 3606 | | - spin_unlock_irqrestore(&pool->lock, flags); |
|---|
| 3637 | + spin_unlock_irq(&pool->lock); |
|---|
| 3607 | 3638 | |
|---|
| 3608 | 3639 | do_waker(&pool->waker.work); |
|---|
| 3609 | 3640 | } |
|---|
| .. | .. |
|---|
| 3612 | 3643 | { |
|---|
| 3613 | 3644 | struct pool_c *pt = ti->private; |
|---|
| 3614 | 3645 | struct pool *pool = pt->pool; |
|---|
| 3615 | | - unsigned long flags; |
|---|
| 3616 | 3646 | |
|---|
| 3617 | | - spin_lock_irqsave(&pool->lock, flags); |
|---|
| 3647 | + spin_lock_irq(&pool->lock); |
|---|
| 3618 | 3648 | pool->suspended = true; |
|---|
| 3619 | | - spin_unlock_irqrestore(&pool->lock, flags); |
|---|
| 3649 | + spin_unlock_irq(&pool->lock); |
|---|
| 3620 | 3650 | |
|---|
| 3621 | 3651 | pool_suspend_active_thins(pool); |
|---|
| 3622 | 3652 | } |
|---|
| .. | .. |
|---|
| 3625 | 3655 | { |
|---|
| 3626 | 3656 | struct pool_c *pt = ti->private; |
|---|
| 3627 | 3657 | struct pool *pool = pt->pool; |
|---|
| 3628 | | - unsigned long flags; |
|---|
| 3629 | 3658 | |
|---|
| 3630 | 3659 | pool_resume_active_thins(pool); |
|---|
| 3631 | 3660 | |
|---|
| 3632 | | - spin_lock_irqsave(&pool->lock, flags); |
|---|
| 3661 | + spin_lock_irq(&pool->lock); |
|---|
| 3633 | 3662 | pool->suspended = false; |
|---|
| 3634 | | - spin_unlock_irqrestore(&pool->lock, flags); |
|---|
| 3663 | + spin_unlock_irq(&pool->lock); |
|---|
| 3635 | 3664 | } |
|---|
| 3636 | 3665 | |
|---|
| 3637 | 3666 | static void pool_postsuspend(struct dm_target *ti) |
|---|
| .. | .. |
|---|
| 4077 | 4106 | .name = "thin-pool", |
|---|
| 4078 | 4107 | .features = DM_TARGET_SINGLETON | DM_TARGET_ALWAYS_WRITEABLE | |
|---|
| 4079 | 4108 | DM_TARGET_IMMUTABLE, |
|---|
| 4080 | | - .version = {1, 20, 0}, |
|---|
| 4109 | + .version = {1, 22, 0}, |
|---|
| 4081 | 4110 | .module = THIS_MODULE, |
|---|
| 4082 | 4111 | .ctr = pool_ctr, |
|---|
| 4083 | 4112 | .dtr = pool_dtr, |
|---|
| .. | .. |
|---|
| 4098 | 4127 | *--------------------------------------------------------------*/ |
|---|
| 4099 | 4128 | static void thin_get(struct thin_c *tc) |
|---|
| 4100 | 4129 | { |
|---|
| 4101 | | - atomic_inc(&tc->refcount); |
|---|
| 4130 | + refcount_inc(&tc->refcount); |
|---|
| 4102 | 4131 | } |
|---|
| 4103 | 4132 | |
|---|
| 4104 | 4133 | static void thin_put(struct thin_c *tc) |
|---|
| 4105 | 4134 | { |
|---|
| 4106 | | - if (atomic_dec_and_test(&tc->refcount)) |
|---|
| 4135 | + if (refcount_dec_and_test(&tc->refcount)) |
|---|
| 4107 | 4136 | complete(&tc->can_destroy); |
|---|
| 4108 | 4137 | } |
|---|
| 4109 | 4138 | |
|---|
| 4110 | 4139 | static void thin_dtr(struct dm_target *ti) |
|---|
| 4111 | 4140 | { |
|---|
| 4112 | 4141 | struct thin_c *tc = ti->private; |
|---|
| 4113 | | - unsigned long flags; |
|---|
| 4114 | 4142 | |
|---|
| 4115 | | - spin_lock_irqsave(&tc->pool->lock, flags); |
|---|
| 4143 | + spin_lock_irq(&tc->pool->lock); |
|---|
| 4116 | 4144 | list_del_rcu(&tc->list); |
|---|
| 4117 | | - spin_unlock_irqrestore(&tc->pool->lock, flags); |
|---|
| 4145 | + spin_unlock_irq(&tc->pool->lock); |
|---|
| 4118 | 4146 | synchronize_rcu(); |
|---|
| 4119 | 4147 | |
|---|
| 4120 | 4148 | thin_put(tc); |
|---|
| .. | .. |
|---|
| 4150 | 4178 | struct thin_c *tc; |
|---|
| 4151 | 4179 | struct dm_dev *pool_dev, *origin_dev; |
|---|
| 4152 | 4180 | struct mapped_device *pool_md; |
|---|
| 4153 | | - unsigned long flags; |
|---|
| 4154 | 4181 | |
|---|
| 4155 | 4182 | mutex_lock(&dm_thin_pool_table.mutex); |
|---|
| 4156 | 4183 | |
|---|
| .. | .. |
|---|
| 4233 | 4260 | goto bad; |
|---|
| 4234 | 4261 | |
|---|
| 4235 | 4262 | ti->num_flush_bios = 1; |
|---|
| 4263 | + ti->limit_swap_bios = true; |
|---|
| 4236 | 4264 | ti->flush_supported = true; |
|---|
| 4237 | 4265 | ti->per_io_data_size = sizeof(struct dm_thin_endio_hook); |
|---|
| 4238 | 4266 | |
|---|
| .. | .. |
|---|
| 4240 | 4268 | if (tc->pool->pf.discard_enabled) { |
|---|
| 4241 | 4269 | ti->discards_supported = true; |
|---|
| 4242 | 4270 | ti->num_discard_bios = 1; |
|---|
| 4243 | | - ti->split_discard_bios = false; |
|---|
| 4244 | 4271 | } |
|---|
| 4245 | 4272 | |
|---|
| 4246 | 4273 | mutex_unlock(&dm_thin_pool_table.mutex); |
|---|
| 4247 | 4274 | |
|---|
| 4248 | | - spin_lock_irqsave(&tc->pool->lock, flags); |
|---|
| 4275 | + spin_lock_irq(&tc->pool->lock); |
|---|
| 4249 | 4276 | if (tc->pool->suspended) { |
|---|
| 4250 | | - spin_unlock_irqrestore(&tc->pool->lock, flags); |
|---|
| 4277 | + spin_unlock_irq(&tc->pool->lock); |
|---|
| 4251 | 4278 | mutex_lock(&dm_thin_pool_table.mutex); /* reacquire for __pool_dec */ |
|---|
| 4252 | 4279 | ti->error = "Unable to activate thin device while pool is suspended"; |
|---|
| 4253 | 4280 | r = -EINVAL; |
|---|
| 4254 | 4281 | goto bad; |
|---|
| 4255 | 4282 | } |
|---|
| 4256 | | - atomic_set(&tc->refcount, 1); |
|---|
| 4283 | + refcount_set(&tc->refcount, 1); |
|---|
| 4257 | 4284 | init_completion(&tc->can_destroy); |
|---|
| 4258 | 4285 | list_add_tail_rcu(&tc->list, &tc->pool->active_thins); |
|---|
| 4259 | | - spin_unlock_irqrestore(&tc->pool->lock, flags); |
|---|
| 4286 | + spin_unlock_irq(&tc->pool->lock); |
|---|
| 4260 | 4287 | /* |
|---|
| 4261 | 4288 | * This synchronize_rcu() call is needed here otherwise we risk a |
|---|
| 4262 | 4289 | * wake_worker() call finding no bios to process (because the newly |
|---|
| .. | .. |
|---|
| 4457 | 4484 | |
|---|
| 4458 | 4485 | static struct target_type thin_target = { |
|---|
| 4459 | 4486 | .name = "thin", |
|---|
| 4460 | | - .version = {1, 20, 0}, |
|---|
| 4487 | + .version = {1, 22, 0}, |
|---|
| 4461 | 4488 | .module = THIS_MODULE, |
|---|
| 4462 | 4489 | .ctr = thin_ctr, |
|---|
| 4463 | 4490 | .dtr = thin_dtr, |
|---|