From: Pekka Enberg Date: Wed, 5 Jan 2011 20:47:28 +0000 (+0200) Subject: kvm: Use disk image API from virtio block device X-Git-Tag: next-20110824~3^2~528^2~31 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=d5433c991cb7c513561f62674130945879c23756;p=karo-tx-linux.git kvm: Use disk image API from virtio block device Signed-off-by: Pekka Enberg --- diff --git a/tools/kvm/blk-virtio.c b/tools/kvm/blk-virtio.c index 36f064bb2c15..a284e3085cb7 100644 --- a/tools/kvm/blk-virtio.c +++ b/tools/kvm/blk-virtio.c @@ -3,6 +3,7 @@ #include "kvm/virtio_ring.h" #include "kvm/virtio_blk.h" #include "kvm/virtio_pci.h" +#include "kvm/disk-image.h" #include "kvm/ioport.h" #include "kvm/util.h" #include "kvm/kvm.h" @@ -139,6 +140,9 @@ static bool blk_virtio_out(struct kvm *self, uint16_t port, void *data, int size struct vring_desc *desc; uint16_t queue_index; uint16_t desc_ndx; + uint32_t dst_len; + uint8_t *status; + void *dst; queue_index = ioport__read16(data); @@ -154,11 +158,38 @@ static bool blk_virtio_out(struct kvm *self, uint16_t port, void *data, int size break; } + /* header */ desc = &queue->vring.desc[desc_ndx]; req = guest_flat_to_host(self, desc->addr); + /* block */ + desc = &queue->vring.desc[desc->next]; + + dst = guest_flat_to_host(self, desc->addr); + dst_len = desc->len; + + /* status */ + desc = &queue->vring.desc[desc->next]; + + 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); + + if (err) + *status = VIRTIO_BLK_S_IOERR; + else + *status = VIRTIO_BLK_S_OK; + } else + *status = VIRTIO_BLK_S_IOERR; + + queue->vring.used->idx++; + kvm__irq_line(self, VIRTIO_BLK_IRQ, 1); + break; } case VIRTIO_PCI_STATUS: diff --git a/tools/kvm/disk-image.c b/tools/kvm/disk-image.c index 92aa83f68ce5..fad6f6fde5f1 100644 --- a/tools/kvm/disk-image.c +++ b/tools/kvm/disk-image.c @@ -56,14 +56,14 @@ void disk_image__close(struct disk_image *self) free(self); } -int disk_image__read_sector(struct disk_image *self, uint64_t sector, void *dst) +int disk_image__read_sector(struct disk_image *self, uint64_t sector, void *dst, uint32_t dst_len) { uint64_t offset = sector << SECTOR_SHIFT; - if (offset + SECTOR_SIZE > self->size) + if (offset + dst_len > self->size) return -1; - memcpy(dst, self->mmap + offset, SECTOR_SIZE); + memcpy(dst, self->mmap + offset, dst_len); return 0; } diff --git a/tools/kvm/include/kvm/disk-image.h b/tools/kvm/include/kvm/disk-image.h index a7698f1d632f..6cba338d4fba 100644 --- a/tools/kvm/include/kvm/disk-image.h +++ b/tools/kvm/include/kvm/disk-image.h @@ -11,6 +11,6 @@ struct disk_image { struct disk_image *disk_image__open(const char *filename); void disk_image__close(struct disk_image *self); -int disk_image__read_sector(struct disk_image *self, uint64_t sector, void *dst); +int disk_image__read_sector(struct disk_image *self, uint64_t sector, void *dst, uint32_t dst_len); #endif /* KVM__DISK_IMAGE_H */ diff --git a/tools/kvm/main.c b/tools/kvm/main.c index 89c194e17165..e87eb8fbf76a 100644 --- a/tools/kvm/main.c +++ b/tools/kvm/main.c @@ -114,7 +114,7 @@ int main(int argc, char *argv[]) kvm__setup_cpuid(kvm); - strcpy(real_cmdline, "notsc nolapic nosmp noacpi pci=conf1 earlyprintk=ttyS0,keep "); + strcpy(real_cmdline, "notsc nolapic nosmp noacpi pci=conf1 earlyprintk=ttyS0,keep root=fc00 "); if (kernel_cmdline) { strlcat(real_cmdline, kernel_cmdline, sizeof(real_cmdline)); real_cmdline[sizeof(real_cmdline)-1] = '\0';