diff --git a/blk-virtio.c b/blk-virtio.c index 1995a40..3b4f641 100644 --- a/blk-virtio.c +++ b/blk-virtio.c @@ -146,6 +146,7 @@ static bool blk_virtio_out(struct kvm *self, uint16_t port, void *data, int size uint32_t dst_len; uint8_t *status; void *dst; + int err; queue_index = ioport__read16(data); @@ -177,17 +178,12 @@ static bool blk_virtio_out(struct kvm *self, uint16_t port, void *data, int size status = guest_flat_to_host(self, desc->addr); - if (self->disk_image) { - int err; + err = disk_image__read_sector(self->disk_image, req->sector, dst, dst_len); - err = disk_image__read_sector(self->disk_image, req->sector, dst, dst_len); - - if (err) - *status = VIRTIO_BLK_S_IOERR; - else - *status = VIRTIO_BLK_S_OK; - } else + if (err) *status = VIRTIO_BLK_S_IOERR; + else + *status = VIRTIO_BLK_S_OK; queue->vring.used->idx++; @@ -235,8 +231,10 @@ static struct pci_device_header blk_virtio_pci_device = { void blk_virtio__init(struct kvm *self) { - if (self->disk_image) - device.blk_config.capacity = self->disk_image->size; + if (!self->disk_image) + return; + + device.blk_config.capacity = self->disk_image->size; pci__register(&blk_virtio_pci_device, 1); diff --git a/main.c b/main.c index 09c17c6..69977b3 100644 --- a/main.c +++ b/main.c @@ -53,7 +53,6 @@ int main(int argc, char *argv[]) const char *kernel_cmdline = NULL; const char *kvm_dev = "/dev/kvm"; unsigned long ram_size = 64UL << 20; - bool enable_virtio = false; bool single_step = false; int i; @@ -78,9 +77,6 @@ int main(int argc, char *argv[]) } else if (option_matches(argv[i], "--single-step")) { single_step = true; continue; - } else if (option_matches(argv[i], "--enable-virtio")) { - enable_virtio = true; - continue; } else if (option_matches(argv[i], "--mem=")) { unsigned long val = atol(&argv[i][6]) << 20; if (val < ram_size) @@ -133,8 +129,7 @@ int main(int argc, char *argv[]) early_printk__init(); pci__init(); - if (enable_virtio) - blk_virtio__init(kvm); + blk_virtio__init(kvm); for (;;) { kvm__run(kvm);