diff options
| author | Rusty Russell <rusty@rustcorp.com.au> | 2015-02-10 23:45:12 -0500 |
|---|---|---|
| committer | Rusty Russell <rusty@rustcorp.com.au> | 2015-02-11 01:17:38 -0500 |
| commit | 5051654764d55a101747b5b2a695bcecae75fa4c (patch) | |
| tree | 154ce710d11735cb226daf86b9ad4b350e7623fb /tools | |
| parent | 8e70946943961cf5bb9be3a0cf12bd0da7a7cb0d (diff) | |
lguest: Convert block device to virtio 1.0 PCI.
We remove SCSI support (which was removed for 1.0) and VIRTIO_BLK_F_FLUSH
feature flag (removed too, since it's compulsory for 1.0).
The rest is mainly mechanical.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/lguest/lguest.c | 30 |
1 files changed, 9 insertions, 21 deletions
diff --git a/tools/lguest/lguest.c b/tools/lguest/lguest.c index c8930bc5ce99..d4a79f6ddfbd 100644 --- a/tools/lguest/lguest.c +++ b/tools/lguest/lguest.c | |||
| @@ -64,11 +64,12 @@ typedef uint8_t u8; | |||
| 64 | /*:*/ | 64 | /*:*/ |
| 65 | 65 | ||
| 66 | #define VIRTIO_PCI_NO_LEGACY | 66 | #define VIRTIO_PCI_NO_LEGACY |
| 67 | #define VIRTIO_BLK_NO_LEGACY | ||
| 67 | 68 | ||
| 68 | /* Use in-kernel ones, which defines VIRTIO_F_VERSION_1 */ | 69 | /* Use in-kernel ones, which defines VIRTIO_F_VERSION_1 */ |
| 69 | #include "../../include/uapi/linux/virtio_config.h" | 70 | #include "../../include/uapi/linux/virtio_config.h" |
| 70 | #include <linux/virtio_net.h> | 71 | #include <linux/virtio_net.h> |
| 71 | #include <linux/virtio_blk.h> | 72 | #include "../../include/uapi/linux/virtio_blk.h" |
| 72 | #include <linux/virtio_console.h> | 73 | #include <linux/virtio_console.h> |
| 73 | #include <linux/virtio_rng.h> | 74 | #include <linux/virtio_rng.h> |
| 74 | #include <linux/virtio_ring.h> | 75 | #include <linux/virtio_ring.h> |
| @@ -2224,7 +2225,6 @@ static void init_pci_config(struct pci_config *pci, u16 type, | |||
| 2224 | * eg : | 2225 | * eg : |
| 2225 | * VIRTIO_ID_CONSOLE: class = 0x07, subclass = 0x00 | 2226 | * VIRTIO_ID_CONSOLE: class = 0x07, subclass = 0x00 |
| 2226 | * VIRTIO_ID_NET: class = 0x02, subclass = 0x00 | 2227 | * VIRTIO_ID_NET: class = 0x02, subclass = 0x00 |
| 2227 | * VIRTIO_ID_BLOCK: class = 0x01, subclass = 0x80 | ||
| 2228 | * VIRTIO_ID_RNG: class = 0xff, subclass = 0 | 2228 | * VIRTIO_ID_RNG: class = 0xff, subclass = 0 |
| 2229 | */ | 2229 | */ |
| 2230 | pci->class = class; | 2230 | pci->class = class; |
| @@ -2663,15 +2663,7 @@ static void blk_request(struct virtqueue *vq) | |||
| 2663 | */ | 2663 | */ |
| 2664 | off = out.sector * 512; | 2664 | off = out.sector * 512; |
| 2665 | 2665 | ||
| 2666 | /* | 2666 | if (out.type & VIRTIO_BLK_T_OUT) { |
| 2667 | * In general the virtio block driver is allowed to try SCSI commands. | ||
| 2668 | * It'd be nice if we supported eject, for example, but we don't. | ||
| 2669 | */ | ||
| 2670 | if (out.type & VIRTIO_BLK_T_SCSI_CMD) { | ||
| 2671 | fprintf(stderr, "Scsi commands unsupported\n"); | ||
| 2672 | *in = VIRTIO_BLK_S_UNSUPP; | ||
| 2673 | wlen = sizeof(*in); | ||
| 2674 | } else if (out.type & VIRTIO_BLK_T_OUT) { | ||
| 2675 | /* | 2667 | /* |
| 2676 | * Write | 2668 | * Write |
| 2677 | * | 2669 | * |
| @@ -2735,11 +2727,11 @@ static void setup_block_file(const char *filename) | |||
| 2735 | struct vblk_info *vblk; | 2727 | struct vblk_info *vblk; |
| 2736 | struct virtio_blk_config conf; | 2728 | struct virtio_blk_config conf; |
| 2737 | 2729 | ||
| 2738 | /* Creat the device. */ | 2730 | /* Create the device. */ |
| 2739 | dev = new_device("block", VIRTIO_ID_BLOCK); | 2731 | dev = new_pci_device("block", VIRTIO_ID_BLOCK, 0x01, 0x80); |
| 2740 | 2732 | ||
| 2741 | /* The device has one virtqueue, where the Guest places requests. */ | 2733 | /* The device has one virtqueue, where the Guest places requests. */ |
| 2742 | add_virtqueue(dev, VIRTQUEUE_NUM, blk_request); | 2734 | add_pci_virtqueue(dev, blk_request); |
| 2743 | 2735 | ||
| 2744 | /* Allocate the room for our own bookkeeping */ | 2736 | /* Allocate the room for our own bookkeeping */ |
| 2745 | vblk = dev->priv = malloc(sizeof(*vblk)); | 2737 | vblk = dev->priv = malloc(sizeof(*vblk)); |
| @@ -2748,9 +2740,6 @@ static void setup_block_file(const char *filename) | |||
| 2748 | vblk->fd = open_or_die(filename, O_RDWR|O_LARGEFILE); | 2740 | vblk->fd = open_or_die(filename, O_RDWR|O_LARGEFILE); |
| 2749 | vblk->len = lseek64(vblk->fd, 0, SEEK_END); | 2741 | vblk->len = lseek64(vblk->fd, 0, SEEK_END); |
| 2750 | 2742 | ||
| 2751 | /* We support FLUSH. */ | ||
| 2752 | add_feature(dev, VIRTIO_BLK_F_FLUSH); | ||
| 2753 | |||
| 2754 | /* Tell Guest how many sectors this device has. */ | 2743 | /* Tell Guest how many sectors this device has. */ |
| 2755 | conf.capacity = cpu_to_le64(vblk->len / 512); | 2744 | conf.capacity = cpu_to_le64(vblk->len / 512); |
| 2756 | 2745 | ||
| @@ -2758,14 +2747,13 @@ static void setup_block_file(const char *filename) | |||
| 2758 | * Tell Guest not to put in too many descriptors at once: two are used | 2747 | * Tell Guest not to put in too many descriptors at once: two are used |
| 2759 | * for the in and out elements. | 2748 | * for the in and out elements. |
| 2760 | */ | 2749 | */ |
| 2761 | add_feature(dev, VIRTIO_BLK_F_SEG_MAX); | 2750 | add_pci_feature(dev, VIRTIO_BLK_F_SEG_MAX); |
| 2762 | conf.seg_max = cpu_to_le32(VIRTQUEUE_NUM - 2); | 2751 | conf.seg_max = cpu_to_le32(VIRTQUEUE_NUM - 2); |
| 2763 | 2752 | ||
| 2764 | /* Don't try to put whole struct: we have 8 bit limit. */ | 2753 | set_device_config(dev, &conf, sizeof(struct virtio_blk_config)); |
| 2765 | set_config(dev, offsetof(struct virtio_blk_config, geometry), &conf); | ||
| 2766 | 2754 | ||
| 2767 | verbose("device %u: virtblock %llu sectors\n", | 2755 | verbose("device %u: virtblock %llu sectors\n", |
| 2768 | ++devices.device_num, le64_to_cpu(conf.capacity)); | 2756 | devices.device_num, le64_to_cpu(conf.capacity)); |
| 2769 | } | 2757 | } |
| 2770 | 2758 | ||
| 2771 | /*L:211 | 2759 | /*L:211 |
