diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2011-11-04 20:22:14 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-11-04 20:22:14 -0400 |
commit | 3d0a8d10cfb4cc3d1877c29a866ee7d8a46aa2fa (patch) | |
tree | 11a85044d1472f5972ae47ce10a2f446ad981e9f /drivers/block/xen-blkback | |
parent | b4fdcb02f1e39c27058a885905bd0277370ba441 (diff) | |
parent | a0eda62552eba4e1f92d5354bb65c68fb6b45f87 (diff) |
Merge branch 'for-3.2/drivers' of git://git.kernel.dk/linux-block
* 'for-3.2/drivers' of git://git.kernel.dk/linux-block: (30 commits)
virtio-blk: use ida to allocate disk index
hpsa: add small delay when using PCI Power Management to reset for kump
cciss: add small delay when using PCI Power Management to reset for kump
xen/blkback: Fix two races in the handling of barrier requests.
xen/blkback: Check for proper operation.
xen/blkback: Fix the inhibition to map pages when discarding sector ranges.
xen/blkback: Report VBD_WSECT (wr_sect) properly.
xen/blkback: Support 'feature-barrier' aka old-style BARRIER requests.
xen-blkfront: plug device number leak in xlblk_init() error path
xen-blkfront: If no barrier or flush is supported, use invalid operation.
xen-blkback: use kzalloc() in favor of kmalloc()+memset()
xen-blkback: fixed indentation and comments
xen-blkfront: fix a deadlock while handling discard response
xen-blkfront: Handle discard requests.
xen-blkback: Implement discard requests ('feature-discard')
xen-blkfront: add BLKIF_OP_DISCARD and discard request struct
drivers/block/loop.c: remove unnecessary bdev argument from loop_clr_fd()
drivers/block/loop.c: emit uevent on auto release
drivers/block/cpqarray.c: use pci_dev->revision
loop: always allow userspace partitions and optionally support automatic scanning
...
Fic up trivial header file includsion conflict in drivers/block/loop.c
Diffstat (limited to 'drivers/block/xen-blkback')
-rw-r--r-- | drivers/block/xen-blkback/blkback.c | 130 | ||||
-rw-r--r-- | drivers/block/xen-blkback/common.h | 98 | ||||
-rw-r--r-- | drivers/block/xen-blkback/xenbus.c | 76 |
3 files changed, 266 insertions, 38 deletions
diff --git a/drivers/block/xen-blkback/blkback.c b/drivers/block/xen-blkback/blkback.c index 1540792b1e54..15ec4db194d1 100644 --- a/drivers/block/xen-blkback/blkback.c +++ b/drivers/block/xen-blkback/blkback.c | |||
@@ -39,6 +39,9 @@ | |||
39 | #include <linux/list.h> | 39 | #include <linux/list.h> |
40 | #include <linux/delay.h> | 40 | #include <linux/delay.h> |
41 | #include <linux/freezer.h> | 41 | #include <linux/freezer.h> |
42 | #include <linux/loop.h> | ||
43 | #include <linux/falloc.h> | ||
44 | #include <linux/fs.h> | ||
42 | 45 | ||
43 | #include <xen/events.h> | 46 | #include <xen/events.h> |
44 | #include <xen/page.h> | 47 | #include <xen/page.h> |
@@ -258,13 +261,16 @@ irqreturn_t xen_blkif_be_int(int irq, void *dev_id) | |||
258 | 261 | ||
259 | static void print_stats(struct xen_blkif *blkif) | 262 | static void print_stats(struct xen_blkif *blkif) |
260 | { | 263 | { |
261 | pr_info("xen-blkback (%s): oo %3d | rd %4d | wr %4d | f %4d\n", | 264 | pr_info("xen-blkback (%s): oo %3d | rd %4d | wr %4d | f %4d" |
265 | " | ds %4d\n", | ||
262 | current->comm, blkif->st_oo_req, | 266 | current->comm, blkif->st_oo_req, |
263 | blkif->st_rd_req, blkif->st_wr_req, blkif->st_f_req); | 267 | blkif->st_rd_req, blkif->st_wr_req, |
268 | blkif->st_f_req, blkif->st_ds_req); | ||
264 | blkif->st_print = jiffies + msecs_to_jiffies(10 * 1000); | 269 | blkif->st_print = jiffies + msecs_to_jiffies(10 * 1000); |
265 | blkif->st_rd_req = 0; | 270 | blkif->st_rd_req = 0; |
266 | blkif->st_wr_req = 0; | 271 | blkif->st_wr_req = 0; |
267 | blkif->st_oo_req = 0; | 272 | blkif->st_oo_req = 0; |
273 | blkif->st_ds_req = 0; | ||
268 | } | 274 | } |
269 | 275 | ||
270 | int xen_blkif_schedule(void *arg) | 276 | int xen_blkif_schedule(void *arg) |
@@ -410,6 +416,59 @@ static int xen_blkbk_map(struct blkif_request *req, | |||
410 | return ret; | 416 | return ret; |
411 | } | 417 | } |
412 | 418 | ||
419 | static void xen_blk_discard(struct xen_blkif *blkif, struct blkif_request *req) | ||
420 | { | ||
421 | int err = 0; | ||
422 | int status = BLKIF_RSP_OKAY; | ||
423 | struct block_device *bdev = blkif->vbd.bdev; | ||
424 | |||
425 | if (blkif->blk_backend_type == BLKIF_BACKEND_PHY) | ||
426 | /* just forward the discard request */ | ||
427 | err = blkdev_issue_discard(bdev, | ||
428 | req->u.discard.sector_number, | ||
429 | req->u.discard.nr_sectors, | ||
430 | GFP_KERNEL, 0); | ||
431 | else if (blkif->blk_backend_type == BLKIF_BACKEND_FILE) { | ||
432 | /* punch a hole in the backing file */ | ||
433 | struct loop_device *lo = bdev->bd_disk->private_data; | ||
434 | struct file *file = lo->lo_backing_file; | ||
435 | |||
436 | if (file->f_op->fallocate) | ||
437 | err = file->f_op->fallocate(file, | ||
438 | FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE, | ||
439 | req->u.discard.sector_number << 9, | ||
440 | req->u.discard.nr_sectors << 9); | ||
441 | else | ||
442 | err = -EOPNOTSUPP; | ||
443 | } else | ||
444 | err = -EOPNOTSUPP; | ||
445 | |||
446 | if (err == -EOPNOTSUPP) { | ||
447 | pr_debug(DRV_PFX "discard op failed, not supported\n"); | ||
448 | status = BLKIF_RSP_EOPNOTSUPP; | ||
449 | } else if (err) | ||
450 | status = BLKIF_RSP_ERROR; | ||
451 | |||
452 | make_response(blkif, req->id, req->operation, status); | ||
453 | } | ||
454 | |||
455 | static void xen_blk_drain_io(struct xen_blkif *blkif) | ||
456 | { | ||
457 | atomic_set(&blkif->drain, 1); | ||
458 | do { | ||
459 | /* The initial value is one, and one refcnt taken at the | ||
460 | * start of the xen_blkif_schedule thread. */ | ||
461 | if (atomic_read(&blkif->refcnt) <= 2) | ||
462 | break; | ||
463 | wait_for_completion_interruptible_timeout( | ||
464 | &blkif->drain_complete, HZ); | ||
465 | |||
466 | if (!atomic_read(&blkif->drain)) | ||
467 | break; | ||
468 | } while (!kthread_should_stop()); | ||
469 | atomic_set(&blkif->drain, 0); | ||
470 | } | ||
471 | |||
413 | /* | 472 | /* |
414 | * Completion callback on the bio's. Called as bh->b_end_io() | 473 | * Completion callback on the bio's. Called as bh->b_end_io() |
415 | */ | 474 | */ |
@@ -422,6 +481,11 @@ static void __end_block_io_op(struct pending_req *pending_req, int error) | |||
422 | pr_debug(DRV_PFX "flush diskcache op failed, not supported\n"); | 481 | pr_debug(DRV_PFX "flush diskcache op failed, not supported\n"); |
423 | xen_blkbk_flush_diskcache(XBT_NIL, pending_req->blkif->be, 0); | 482 | xen_blkbk_flush_diskcache(XBT_NIL, pending_req->blkif->be, 0); |
424 | pending_req->status = BLKIF_RSP_EOPNOTSUPP; | 483 | pending_req->status = BLKIF_RSP_EOPNOTSUPP; |
484 | } else if ((pending_req->operation == BLKIF_OP_WRITE_BARRIER) && | ||
485 | (error == -EOPNOTSUPP)) { | ||
486 | pr_debug(DRV_PFX "write barrier op failed, not supported\n"); | ||
487 | xen_blkbk_barrier(XBT_NIL, pending_req->blkif->be, 0); | ||
488 | pending_req->status = BLKIF_RSP_EOPNOTSUPP; | ||
425 | } else if (error) { | 489 | } else if (error) { |
426 | pr_debug(DRV_PFX "Buffer not up-to-date at end of operation," | 490 | pr_debug(DRV_PFX "Buffer not up-to-date at end of operation," |
427 | " error=%d\n", error); | 491 | " error=%d\n", error); |
@@ -438,6 +502,10 @@ static void __end_block_io_op(struct pending_req *pending_req, int error) | |||
438 | make_response(pending_req->blkif, pending_req->id, | 502 | make_response(pending_req->blkif, pending_req->id, |
439 | pending_req->operation, pending_req->status); | 503 | pending_req->operation, pending_req->status); |
440 | xen_blkif_put(pending_req->blkif); | 504 | xen_blkif_put(pending_req->blkif); |
505 | if (atomic_read(&pending_req->blkif->refcnt) <= 2) { | ||
506 | if (atomic_read(&pending_req->blkif->drain)) | ||
507 | complete(&pending_req->blkif->drain_complete); | ||
508 | } | ||
441 | free_req(pending_req); | 509 | free_req(pending_req); |
442 | } | 510 | } |
443 | } | 511 | } |
@@ -532,7 +600,6 @@ do_block_io_op(struct xen_blkif *blkif) | |||
532 | 600 | ||
533 | return more_to_do; | 601 | return more_to_do; |
534 | } | 602 | } |
535 | |||
536 | /* | 603 | /* |
537 | * Transmutation of the 'struct blkif_request' to a proper 'struct bio' | 604 | * Transmutation of the 'struct blkif_request' to a proper 'struct bio' |
538 | * and call the 'submit_bio' to pass it to the underlying storage. | 605 | * and call the 'submit_bio' to pass it to the underlying storage. |
@@ -549,6 +616,7 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif, | |||
549 | int i, nbio = 0; | 616 | int i, nbio = 0; |
550 | int operation; | 617 | int operation; |
551 | struct blk_plug plug; | 618 | struct blk_plug plug; |
619 | bool drain = false; | ||
552 | 620 | ||
553 | switch (req->operation) { | 621 | switch (req->operation) { |
554 | case BLKIF_OP_READ: | 622 | case BLKIF_OP_READ: |
@@ -559,11 +627,16 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif, | |||
559 | blkif->st_wr_req++; | 627 | blkif->st_wr_req++; |
560 | operation = WRITE_ODIRECT; | 628 | operation = WRITE_ODIRECT; |
561 | break; | 629 | break; |
630 | case BLKIF_OP_WRITE_BARRIER: | ||
631 | drain = true; | ||
562 | case BLKIF_OP_FLUSH_DISKCACHE: | 632 | case BLKIF_OP_FLUSH_DISKCACHE: |
563 | blkif->st_f_req++; | 633 | blkif->st_f_req++; |
564 | operation = WRITE_FLUSH; | 634 | operation = WRITE_FLUSH; |
565 | break; | 635 | break; |
566 | case BLKIF_OP_WRITE_BARRIER: | 636 | case BLKIF_OP_DISCARD: |
637 | blkif->st_ds_req++; | ||
638 | operation = REQ_DISCARD; | ||
639 | break; | ||
567 | default: | 640 | default: |
568 | operation = 0; /* make gcc happy */ | 641 | operation = 0; /* make gcc happy */ |
569 | goto fail_response; | 642 | goto fail_response; |
@@ -572,7 +645,8 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif, | |||
572 | 645 | ||
573 | /* Check that the number of segments is sane. */ | 646 | /* Check that the number of segments is sane. */ |
574 | nseg = req->nr_segments; | 647 | nseg = req->nr_segments; |
575 | if (unlikely(nseg == 0 && operation != WRITE_FLUSH) || | 648 | if (unlikely(nseg == 0 && operation != WRITE_FLUSH && |
649 | operation != REQ_DISCARD) || | ||
576 | unlikely(nseg > BLKIF_MAX_SEGMENTS_PER_REQUEST)) { | 650 | unlikely(nseg > BLKIF_MAX_SEGMENTS_PER_REQUEST)) { |
577 | pr_debug(DRV_PFX "Bad number of segments in request (%d)\n", | 651 | pr_debug(DRV_PFX "Bad number of segments in request (%d)\n", |
578 | nseg); | 652 | nseg); |
@@ -621,16 +695,25 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif, | |||
621 | } | 695 | } |
622 | } | 696 | } |
623 | 697 | ||
698 | /* Wait on all outstanding I/O's and once that has been completed | ||
699 | * issue the WRITE_FLUSH. | ||
700 | */ | ||
701 | if (drain) | ||
702 | xen_blk_drain_io(pending_req->blkif); | ||
703 | |||
624 | /* | 704 | /* |
625 | * If we have failed at this point, we need to undo the M2P override, | 705 | * If we have failed at this point, we need to undo the M2P override, |
626 | * set gnttab_set_unmap_op on all of the grant references and perform | 706 | * set gnttab_set_unmap_op on all of the grant references and perform |
627 | * the hypercall to unmap the grants - that is all done in | 707 | * the hypercall to unmap the grants - that is all done in |
628 | * xen_blkbk_unmap. | 708 | * xen_blkbk_unmap. |
629 | */ | 709 | */ |
630 | if (xen_blkbk_map(req, pending_req, seg)) | 710 | if (operation != REQ_DISCARD && xen_blkbk_map(req, pending_req, seg)) |
631 | goto fail_flush; | 711 | goto fail_flush; |
632 | 712 | ||
633 | /* This corresponding xen_blkif_put is done in __end_block_io_op */ | 713 | /* |
714 | * This corresponding xen_blkif_put is done in __end_block_io_op, or | ||
715 | * below (in "!bio") if we are handling a BLKIF_OP_DISCARD. | ||
716 | */ | ||
634 | xen_blkif_get(blkif); | 717 | xen_blkif_get(blkif); |
635 | 718 | ||
636 | for (i = 0; i < nseg; i++) { | 719 | for (i = 0; i < nseg; i++) { |
@@ -654,18 +737,25 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif, | |||
654 | preq.sector_number += seg[i].nsec; | 737 | preq.sector_number += seg[i].nsec; |
655 | } | 738 | } |
656 | 739 | ||
657 | /* This will be hit if the operation was a flush. */ | 740 | /* This will be hit if the operation was a flush or discard. */ |
658 | if (!bio) { | 741 | if (!bio) { |
659 | BUG_ON(operation != WRITE_FLUSH); | 742 | BUG_ON(operation != WRITE_FLUSH && operation != REQ_DISCARD); |
660 | 743 | ||
661 | bio = bio_alloc(GFP_KERNEL, 0); | 744 | if (operation == WRITE_FLUSH) { |
662 | if (unlikely(bio == NULL)) | 745 | bio = bio_alloc(GFP_KERNEL, 0); |
663 | goto fail_put_bio; | 746 | if (unlikely(bio == NULL)) |
747 | goto fail_put_bio; | ||
664 | 748 | ||
665 | biolist[nbio++] = bio; | 749 | biolist[nbio++] = bio; |
666 | bio->bi_bdev = preq.bdev; | 750 | bio->bi_bdev = preq.bdev; |
667 | bio->bi_private = pending_req; | 751 | bio->bi_private = pending_req; |
668 | bio->bi_end_io = end_block_io_op; | 752 | bio->bi_end_io = end_block_io_op; |
753 | } else if (operation == REQ_DISCARD) { | ||
754 | xen_blk_discard(blkif, req); | ||
755 | xen_blkif_put(blkif); | ||
756 | free_req(pending_req); | ||
757 | return 0; | ||
758 | } | ||
669 | } | 759 | } |
670 | 760 | ||
671 | /* | 761 | /* |
@@ -685,7 +775,7 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif, | |||
685 | 775 | ||
686 | if (operation == READ) | 776 | if (operation == READ) |
687 | blkif->st_rd_sect += preq.nr_sects; | 777 | blkif->st_rd_sect += preq.nr_sects; |
688 | else if (operation == WRITE || operation == WRITE_FLUSH) | 778 | else if (operation & WRITE) |
689 | blkif->st_wr_sect += preq.nr_sects; | 779 | blkif->st_wr_sect += preq.nr_sects; |
690 | 780 | ||
691 | return 0; | 781 | return 0; |
@@ -765,9 +855,9 @@ static int __init xen_blkif_init(void) | |||
765 | 855 | ||
766 | mmap_pages = xen_blkif_reqs * BLKIF_MAX_SEGMENTS_PER_REQUEST; | 856 | mmap_pages = xen_blkif_reqs * BLKIF_MAX_SEGMENTS_PER_REQUEST; |
767 | 857 | ||
768 | blkbk->pending_reqs = kmalloc(sizeof(blkbk->pending_reqs[0]) * | 858 | blkbk->pending_reqs = kzalloc(sizeof(blkbk->pending_reqs[0]) * |
769 | xen_blkif_reqs, GFP_KERNEL); | 859 | xen_blkif_reqs, GFP_KERNEL); |
770 | blkbk->pending_grant_handles = kzalloc(sizeof(blkbk->pending_grant_handles[0]) * | 860 | blkbk->pending_grant_handles = kmalloc(sizeof(blkbk->pending_grant_handles[0]) * |
771 | mmap_pages, GFP_KERNEL); | 861 | mmap_pages, GFP_KERNEL); |
772 | blkbk->pending_pages = kzalloc(sizeof(blkbk->pending_pages[0]) * | 862 | blkbk->pending_pages = kzalloc(sizeof(blkbk->pending_pages[0]) * |
773 | mmap_pages, GFP_KERNEL); | 863 | mmap_pages, GFP_KERNEL); |
@@ -790,8 +880,6 @@ static int __init xen_blkif_init(void) | |||
790 | if (rc) | 880 | if (rc) |
791 | goto failed_init; | 881 | goto failed_init; |
792 | 882 | ||
793 | memset(blkbk->pending_reqs, 0, sizeof(blkbk->pending_reqs)); | ||
794 | |||
795 | INIT_LIST_HEAD(&blkbk->pending_free); | 883 | INIT_LIST_HEAD(&blkbk->pending_free); |
796 | spin_lock_init(&blkbk->pending_free_lock); | 884 | spin_lock_init(&blkbk->pending_free_lock); |
797 | init_waitqueue_head(&blkbk->pending_free_wq); | 885 | init_waitqueue_head(&blkbk->pending_free_wq); |
diff --git a/drivers/block/xen-blkback/common.h b/drivers/block/xen-blkback/common.h index c4bd34063ecc..de09f525d6c1 100644 --- a/drivers/block/xen-blkback/common.h +++ b/drivers/block/xen-blkback/common.h | |||
@@ -62,13 +62,26 @@ struct blkif_common_response { | |||
62 | 62 | ||
63 | /* i386 protocol version */ | 63 | /* i386 protocol version */ |
64 | #pragma pack(push, 4) | 64 | #pragma pack(push, 4) |
65 | |||
66 | struct blkif_x86_32_request_rw { | ||
67 | blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */ | ||
68 | struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST]; | ||
69 | }; | ||
70 | |||
71 | struct blkif_x86_32_request_discard { | ||
72 | blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */ | ||
73 | uint64_t nr_sectors; | ||
74 | }; | ||
75 | |||
65 | struct blkif_x86_32_request { | 76 | struct blkif_x86_32_request { |
66 | uint8_t operation; /* BLKIF_OP_??? */ | 77 | uint8_t operation; /* BLKIF_OP_??? */ |
67 | uint8_t nr_segments; /* number of segments */ | 78 | uint8_t nr_segments; /* number of segments */ |
68 | blkif_vdev_t handle; /* only for read/write requests */ | 79 | blkif_vdev_t handle; /* only for read/write requests */ |
69 | uint64_t id; /* private guest value, echoed in resp */ | 80 | uint64_t id; /* private guest value, echoed in resp */ |
70 | blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */ | 81 | union { |
71 | struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST]; | 82 | struct blkif_x86_32_request_rw rw; |
83 | struct blkif_x86_32_request_discard discard; | ||
84 | } u; | ||
72 | }; | 85 | }; |
73 | struct blkif_x86_32_response { | 86 | struct blkif_x86_32_response { |
74 | uint64_t id; /* copied from request */ | 87 | uint64_t id; /* copied from request */ |
@@ -78,13 +91,26 @@ struct blkif_x86_32_response { | |||
78 | #pragma pack(pop) | 91 | #pragma pack(pop) |
79 | 92 | ||
80 | /* x86_64 protocol version */ | 93 | /* x86_64 protocol version */ |
94 | |||
95 | struct blkif_x86_64_request_rw { | ||
96 | blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */ | ||
97 | struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST]; | ||
98 | }; | ||
99 | |||
100 | struct blkif_x86_64_request_discard { | ||
101 | blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */ | ||
102 | uint64_t nr_sectors; | ||
103 | }; | ||
104 | |||
81 | struct blkif_x86_64_request { | 105 | struct blkif_x86_64_request { |
82 | uint8_t operation; /* BLKIF_OP_??? */ | 106 | uint8_t operation; /* BLKIF_OP_??? */ |
83 | uint8_t nr_segments; /* number of segments */ | 107 | uint8_t nr_segments; /* number of segments */ |
84 | blkif_vdev_t handle; /* only for read/write requests */ | 108 | blkif_vdev_t handle; /* only for read/write requests */ |
85 | uint64_t __attribute__((__aligned__(8))) id; | 109 | uint64_t __attribute__((__aligned__(8))) id; |
86 | blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */ | 110 | union { |
87 | struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST]; | 111 | struct blkif_x86_64_request_rw rw; |
112 | struct blkif_x86_64_request_discard discard; | ||
113 | } u; | ||
88 | }; | 114 | }; |
89 | struct blkif_x86_64_response { | 115 | struct blkif_x86_64_response { |
90 | uint64_t __attribute__((__aligned__(8))) id; | 116 | uint64_t __attribute__((__aligned__(8))) id; |
@@ -112,6 +138,11 @@ enum blkif_protocol { | |||
112 | BLKIF_PROTOCOL_X86_64 = 3, | 138 | BLKIF_PROTOCOL_X86_64 = 3, |
113 | }; | 139 | }; |
114 | 140 | ||
141 | enum blkif_backend_type { | ||
142 | BLKIF_BACKEND_PHY = 1, | ||
143 | BLKIF_BACKEND_FILE = 2, | ||
144 | }; | ||
145 | |||
115 | struct xen_vbd { | 146 | struct xen_vbd { |
116 | /* What the domain refers to this vbd as. */ | 147 | /* What the domain refers to this vbd as. */ |
117 | blkif_vdev_t handle; | 148 | blkif_vdev_t handle; |
@@ -137,6 +168,7 @@ struct xen_blkif { | |||
137 | unsigned int irq; | 168 | unsigned int irq; |
138 | /* Comms information. */ | 169 | /* Comms information. */ |
139 | enum blkif_protocol blk_protocol; | 170 | enum blkif_protocol blk_protocol; |
171 | enum blkif_backend_type blk_backend_type; | ||
140 | union blkif_back_rings blk_rings; | 172 | union blkif_back_rings blk_rings; |
141 | struct vm_struct *blk_ring_area; | 173 | struct vm_struct *blk_ring_area; |
142 | /* The VBD attached to this interface. */ | 174 | /* The VBD attached to this interface. */ |
@@ -148,6 +180,9 @@ struct xen_blkif { | |||
148 | atomic_t refcnt; | 180 | atomic_t refcnt; |
149 | 181 | ||
150 | wait_queue_head_t wq; | 182 | wait_queue_head_t wq; |
183 | /* for barrier (drain) requests */ | ||
184 | struct completion drain_complete; | ||
185 | atomic_t drain; | ||
151 | /* One thread per one blkif. */ | 186 | /* One thread per one blkif. */ |
152 | struct task_struct *xenblkd; | 187 | struct task_struct *xenblkd; |
153 | unsigned int waiting_reqs; | 188 | unsigned int waiting_reqs; |
@@ -158,6 +193,7 @@ struct xen_blkif { | |||
158 | int st_wr_req; | 193 | int st_wr_req; |
159 | int st_oo_req; | 194 | int st_oo_req; |
160 | int st_f_req; | 195 | int st_f_req; |
196 | int st_ds_req; | ||
161 | int st_rd_sect; | 197 | int st_rd_sect; |
162 | int st_wr_sect; | 198 | int st_wr_sect; |
163 | 199 | ||
@@ -181,7 +217,7 @@ struct xen_blkif { | |||
181 | 217 | ||
182 | struct phys_req { | 218 | struct phys_req { |
183 | unsigned short dev; | 219 | unsigned short dev; |
184 | unsigned short nr_sects; | 220 | blkif_sector_t nr_sects; |
185 | struct block_device *bdev; | 221 | struct block_device *bdev; |
186 | blkif_sector_t sector_number; | 222 | blkif_sector_t sector_number; |
187 | }; | 223 | }; |
@@ -195,6 +231,8 @@ int xen_blkif_schedule(void *arg); | |||
195 | int xen_blkbk_flush_diskcache(struct xenbus_transaction xbt, | 231 | int xen_blkbk_flush_diskcache(struct xenbus_transaction xbt, |
196 | struct backend_info *be, int state); | 232 | struct backend_info *be, int state); |
197 | 233 | ||
234 | int xen_blkbk_barrier(struct xenbus_transaction xbt, | ||
235 | struct backend_info *be, int state); | ||
198 | struct xenbus_device *xen_blkbk_xenbus(struct backend_info *be); | 236 | struct xenbus_device *xen_blkbk_xenbus(struct backend_info *be); |
199 | 237 | ||
200 | static inline void blkif_get_x86_32_req(struct blkif_request *dst, | 238 | static inline void blkif_get_x86_32_req(struct blkif_request *dst, |
@@ -205,12 +243,25 @@ static inline void blkif_get_x86_32_req(struct blkif_request *dst, | |||
205 | dst->nr_segments = src->nr_segments; | 243 | dst->nr_segments = src->nr_segments; |
206 | dst->handle = src->handle; | 244 | dst->handle = src->handle; |
207 | dst->id = src->id; | 245 | dst->id = src->id; |
208 | dst->u.rw.sector_number = src->sector_number; | 246 | switch (src->operation) { |
209 | barrier(); | 247 | case BLKIF_OP_READ: |
210 | if (n > dst->nr_segments) | 248 | case BLKIF_OP_WRITE: |
211 | n = dst->nr_segments; | 249 | case BLKIF_OP_WRITE_BARRIER: |
212 | for (i = 0; i < n; i++) | 250 | case BLKIF_OP_FLUSH_DISKCACHE: |
213 | dst->u.rw.seg[i] = src->seg[i]; | 251 | dst->u.rw.sector_number = src->u.rw.sector_number; |
252 | barrier(); | ||
253 | if (n > dst->nr_segments) | ||
254 | n = dst->nr_segments; | ||
255 | for (i = 0; i < n; i++) | ||
256 | dst->u.rw.seg[i] = src->u.rw.seg[i]; | ||
257 | break; | ||
258 | case BLKIF_OP_DISCARD: | ||
259 | dst->u.discard.sector_number = src->u.discard.sector_number; | ||
260 | dst->u.discard.nr_sectors = src->u.discard.nr_sectors; | ||
261 | break; | ||
262 | default: | ||
263 | break; | ||
264 | } | ||
214 | } | 265 | } |
215 | 266 | ||
216 | static inline void blkif_get_x86_64_req(struct blkif_request *dst, | 267 | static inline void blkif_get_x86_64_req(struct blkif_request *dst, |
@@ -221,12 +272,25 @@ static inline void blkif_get_x86_64_req(struct blkif_request *dst, | |||
221 | dst->nr_segments = src->nr_segments; | 272 | dst->nr_segments = src->nr_segments; |
222 | dst->handle = src->handle; | 273 | dst->handle = src->handle; |
223 | dst->id = src->id; | 274 | dst->id = src->id; |
224 | dst->u.rw.sector_number = src->sector_number; | 275 | switch (src->operation) { |
225 | barrier(); | 276 | case BLKIF_OP_READ: |
226 | if (n > dst->nr_segments) | 277 | case BLKIF_OP_WRITE: |
227 | n = dst->nr_segments; | 278 | case BLKIF_OP_WRITE_BARRIER: |
228 | for (i = 0; i < n; i++) | 279 | case BLKIF_OP_FLUSH_DISKCACHE: |
229 | dst->u.rw.seg[i] = src->seg[i]; | 280 | dst->u.rw.sector_number = src->u.rw.sector_number; |
281 | barrier(); | ||
282 | if (n > dst->nr_segments) | ||
283 | n = dst->nr_segments; | ||
284 | for (i = 0; i < n; i++) | ||
285 | dst->u.rw.seg[i] = src->u.rw.seg[i]; | ||
286 | break; | ||
287 | case BLKIF_OP_DISCARD: | ||
288 | dst->u.discard.sector_number = src->u.discard.sector_number; | ||
289 | dst->u.discard.nr_sectors = src->u.discard.nr_sectors; | ||
290 | break; | ||
291 | default: | ||
292 | break; | ||
293 | } | ||
230 | } | 294 | } |
231 | 295 | ||
232 | #endif /* __XEN_BLKIF__BACKEND__COMMON_H__ */ | 296 | #endif /* __XEN_BLKIF__BACKEND__COMMON_H__ */ |
diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c index 5fd2010f7d2b..2c008afe63d9 100644 --- a/drivers/block/xen-blkback/xenbus.c +++ b/drivers/block/xen-blkback/xenbus.c | |||
@@ -114,6 +114,8 @@ static struct xen_blkif *xen_blkif_alloc(domid_t domid) | |||
114 | spin_lock_init(&blkif->blk_ring_lock); | 114 | spin_lock_init(&blkif->blk_ring_lock); |
115 | atomic_set(&blkif->refcnt, 1); | 115 | atomic_set(&blkif->refcnt, 1); |
116 | init_waitqueue_head(&blkif->wq); | 116 | init_waitqueue_head(&blkif->wq); |
117 | init_completion(&blkif->drain_complete); | ||
118 | atomic_set(&blkif->drain, 0); | ||
117 | blkif->st_print = jiffies; | 119 | blkif->st_print = jiffies; |
118 | init_waitqueue_head(&blkif->waiting_to_free); | 120 | init_waitqueue_head(&blkif->waiting_to_free); |
119 | 121 | ||
@@ -272,6 +274,7 @@ VBD_SHOW(oo_req, "%d\n", be->blkif->st_oo_req); | |||
272 | VBD_SHOW(rd_req, "%d\n", be->blkif->st_rd_req); | 274 | VBD_SHOW(rd_req, "%d\n", be->blkif->st_rd_req); |
273 | VBD_SHOW(wr_req, "%d\n", be->blkif->st_wr_req); | 275 | VBD_SHOW(wr_req, "%d\n", be->blkif->st_wr_req); |
274 | VBD_SHOW(f_req, "%d\n", be->blkif->st_f_req); | 276 | VBD_SHOW(f_req, "%d\n", be->blkif->st_f_req); |
277 | VBD_SHOW(ds_req, "%d\n", be->blkif->st_ds_req); | ||
275 | VBD_SHOW(rd_sect, "%d\n", be->blkif->st_rd_sect); | 278 | VBD_SHOW(rd_sect, "%d\n", be->blkif->st_rd_sect); |
276 | VBD_SHOW(wr_sect, "%d\n", be->blkif->st_wr_sect); | 279 | VBD_SHOW(wr_sect, "%d\n", be->blkif->st_wr_sect); |
277 | 280 | ||
@@ -280,6 +283,7 @@ static struct attribute *xen_vbdstat_attrs[] = { | |||
280 | &dev_attr_rd_req.attr, | 283 | &dev_attr_rd_req.attr, |
281 | &dev_attr_wr_req.attr, | 284 | &dev_attr_wr_req.attr, |
282 | &dev_attr_f_req.attr, | 285 | &dev_attr_f_req.attr, |
286 | &dev_attr_ds_req.attr, | ||
283 | &dev_attr_rd_sect.attr, | 287 | &dev_attr_rd_sect.attr, |
284 | &dev_attr_wr_sect.attr, | 288 | &dev_attr_wr_sect.attr, |
285 | NULL | 289 | NULL |
@@ -419,6 +423,73 @@ int xen_blkbk_flush_diskcache(struct xenbus_transaction xbt, | |||
419 | return err; | 423 | return err; |
420 | } | 424 | } |
421 | 425 | ||
426 | int xen_blkbk_discard(struct xenbus_transaction xbt, struct backend_info *be) | ||
427 | { | ||
428 | struct xenbus_device *dev = be->dev; | ||
429 | struct xen_blkif *blkif = be->blkif; | ||
430 | char *type; | ||
431 | int err; | ||
432 | int state = 0; | ||
433 | |||
434 | type = xenbus_read(XBT_NIL, dev->nodename, "type", NULL); | ||
435 | if (!IS_ERR(type)) { | ||
436 | if (strncmp(type, "file", 4) == 0) { | ||
437 | state = 1; | ||
438 | blkif->blk_backend_type = BLKIF_BACKEND_FILE; | ||
439 | } | ||
440 | if (strncmp(type, "phy", 3) == 0) { | ||
441 | struct block_device *bdev = be->blkif->vbd.bdev; | ||
442 | struct request_queue *q = bdev_get_queue(bdev); | ||
443 | if (blk_queue_discard(q)) { | ||
444 | err = xenbus_printf(xbt, dev->nodename, | ||
445 | "discard-granularity", "%u", | ||
446 | q->limits.discard_granularity); | ||
447 | if (err) { | ||
448 | xenbus_dev_fatal(dev, err, | ||
449 | "writing discard-granularity"); | ||
450 | goto kfree; | ||
451 | } | ||
452 | err = xenbus_printf(xbt, dev->nodename, | ||
453 | "discard-alignment", "%u", | ||
454 | q->limits.discard_alignment); | ||
455 | if (err) { | ||
456 | xenbus_dev_fatal(dev, err, | ||
457 | "writing discard-alignment"); | ||
458 | goto kfree; | ||
459 | } | ||
460 | state = 1; | ||
461 | blkif->blk_backend_type = BLKIF_BACKEND_PHY; | ||
462 | } | ||
463 | } | ||
464 | } else { | ||
465 | err = PTR_ERR(type); | ||
466 | xenbus_dev_fatal(dev, err, "reading type"); | ||
467 | goto out; | ||
468 | } | ||
469 | |||
470 | err = xenbus_printf(xbt, dev->nodename, "feature-discard", | ||
471 | "%d", state); | ||
472 | if (err) | ||
473 | xenbus_dev_fatal(dev, err, "writing feature-discard"); | ||
474 | kfree: | ||
475 | kfree(type); | ||
476 | out: | ||
477 | return err; | ||
478 | } | ||
479 | int xen_blkbk_barrier(struct xenbus_transaction xbt, | ||
480 | struct backend_info *be, int state) | ||
481 | { | ||
482 | struct xenbus_device *dev = be->dev; | ||
483 | int err; | ||
484 | |||
485 | err = xenbus_printf(xbt, dev->nodename, "feature-barrier", | ||
486 | "%d", state); | ||
487 | if (err) | ||
488 | xenbus_dev_fatal(dev, err, "writing feature-barrier"); | ||
489 | |||
490 | return err; | ||
491 | } | ||
492 | |||
422 | /* | 493 | /* |
423 | * Entry point to this code when a new device is created. Allocate the basic | 494 | * Entry point to this code when a new device is created. Allocate the basic |
424 | * structures, and watch the store waiting for the hotplug scripts to tell us | 495 | * structures, and watch the store waiting for the hotplug scripts to tell us |
@@ -650,6 +721,11 @@ again: | |||
650 | if (err) | 721 | if (err) |
651 | goto abort; | 722 | goto abort; |
652 | 723 | ||
724 | err = xen_blkbk_discard(xbt, be); | ||
725 | |||
726 | /* If we can't advertise it is OK. */ | ||
727 | err = xen_blkbk_barrier(xbt, be, be->blkif->vbd.flush_support); | ||
728 | |||
653 | err = xenbus_printf(xbt, dev->nodename, "sectors", "%llu", | 729 | err = xenbus_printf(xbt, dev->nodename, "sectors", "%llu", |
654 | (unsigned long long)vbd_sz(&be->blkif->vbd)); | 730 | (unsigned long long)vbd_sz(&be->blkif->vbd)); |
655 | if (err) { | 731 | if (err) { |