From patchwork Wed May 4 13:45:15 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 753792 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p44Dja61020883 for ; Wed, 4 May 2011 13:45:36 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753864Ab1EDNpc (ORCPT ); Wed, 4 May 2011 09:45:32 -0400 Received: from mail-ww0-f44.google.com ([74.125.82.44]:52675 "EHLO mail-ww0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753736Ab1EDNpb (ORCPT ); Wed, 4 May 2011 09:45:31 -0400 Received: by wwa36 with SMTP id 36so1239442wwa.1 for ; Wed, 04 May 2011 06:45:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=t4XsYq5VHcvG4cslaKAPCUMexMilxwDak5pllcjwcVA=; b=Ihizxfx/CcEL3RXxsiMKn6IUZ+imoX1g3j+LBIYcoQzLCbjgMrOmdKcDOeXiVA6QNh l24cOCWnqWIokUQQAakus4rDB279rJpa4z5r3PI8iv36Nqjuwr3aHsQedoVBRg6l7JIH MpB4/FqhN2rVG+dvGgH14zt1NEpZfs4AKM4WM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=eJyze+jYaShF28Og7jsc1WQSK5sFYFc9wwKyxy8eGlnaCcXryvdBu42NvtCPIfiMtt 1ux041WxfeJvxrHQ6mcqE1M1FQOQYAS6SLTQz0iPynCpVwzubhJoDhBqCIV2by27Wbc7 yyEbBscxXcMEXOgxJj3pkBFC9o5JI/2V6KtaQ= Received: by 10.216.142.35 with SMTP id h35mr889880wej.31.1304516729833; Wed, 04 May 2011 06:45:29 -0700 (PDT) Received: from localhost.localdomain ([77.124.181.142]) by mx.google.com with ESMTPS id x13sm226068wby.42.2011.05.04.06.45.28 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 04 May 2011 06:45:29 -0700 (PDT) From: Sasha Levin To: penberg@kernel.org, kvm@vger.kernel.org Cc: mingo@elte.hu, asias.hejun@gmail.com, gorcunov@gmail.com, prasadjoshi124@gmail.com, Sasha Levin Subject: [PATCH 1/3 V2] kvm tools: Move disk_image into virtio-blk Date: Wed, 4 May 2011 16:45:15 +0300 Message-Id: <1304516717-24512-2-git-send-email-levinsasha928@gmail.com> X-Mailer: git-send-email 1.7.5.rc3 In-Reply-To: <1304516717-24512-1-git-send-email-levinsasha928@gmail.com> References: <1304516717-24512-1-git-send-email-levinsasha928@gmail.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Wed, 04 May 2011 13:45:36 +0000 (UTC) There may be multiple disk images on a running guest, each associated with a virtio-blk. Move disk_image into virtio-blk in preperation for multiple disk images. Signed-off-by: Sasha Levin --- tools/kvm/include/kvm/kvm.h | 1 - tools/kvm/include/kvm/virtio-blk.h | 4 +++- tools/kvm/kvm-run.c | 9 ++++----- tools/kvm/virtio-blk.c | 13 ++++++++----- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/tools/kvm/include/kvm/kvm.h b/tools/kvm/include/kvm/kvm.h index 327a1ab..d239f49 100644 --- a/tools/kvm/include/kvm/kvm.h +++ b/tools/kvm/include/kvm/kvm.h @@ -16,7 +16,6 @@ struct kvm { int nrcpus; /* Number of cpus to run */ - struct disk_image *disk_image; uint64_t ram_size; void *ram_start; diff --git a/tools/kvm/include/kvm/virtio-blk.h b/tools/kvm/include/kvm/virtio-blk.h index f82bbc7..f21a0e4 100644 --- a/tools/kvm/include/kvm/virtio-blk.h +++ b/tools/kvm/include/kvm/virtio-blk.h @@ -1,8 +1,10 @@ #ifndef KVM__BLK_VIRTIO_H #define KVM__BLK_VIRTIO_H +#include "kvm/disk-image.h" + struct kvm; -void virtio_blk__init(struct kvm *self); +void virtio_blk__init(struct kvm *self, struct disk_image *disk); #endif /* KVM__BLK_VIRTIO_H */ diff --git a/tools/kvm/kvm-run.c b/tools/kvm/kvm-run.c index 6fd46ed..b92232d 100644 --- a/tools/kvm/kvm-run.c +++ b/tools/kvm/kvm-run.c @@ -409,9 +409,11 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix) strlcat(real_cmdline, " root=/dev/vda rw ", sizeof(real_cmdline)); if (image_filename) { - kvm->disk_image = disk_image__open(image_filename, readonly_image); - if (!kvm->disk_image) + struct disk_image *disk = disk_image__open(image_filename, readonly_image); + if (!disk) die("unable to load disk image %s", image_filename); + + virtio_blk__init(kvm, disk); } free(hi); @@ -429,8 +431,6 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix) pci__init(); - virtio_blk__init(kvm); - virtio_console__init(kvm); if (virtio_rng) @@ -487,7 +487,6 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix) exit_code = 1; } - disk_image__close(kvm->disk_image); kvm__delete(kvm); if (!exit_code) diff --git a/tools/kvm/virtio-blk.c b/tools/kvm/virtio-blk.c index 9034abd..d7bda5f 100644 --- a/tools/kvm/virtio-blk.c +++ b/tools/kvm/virtio-blk.c @@ -28,6 +28,7 @@ struct blk_device { pthread_mutex_t mutex; struct virtio_blk_config blk_config; + struct disk_image *disk; uint32_t host_features; uint32_t guest_features; uint16_t config_vector; @@ -130,11 +131,11 @@ static bool virtio_blk_do_io_request(struct kvm *self, struct virt_queue *queue) switch (req->type) { case VIRTIO_BLK_T_IN: - block_cnt = disk_image__read_sector_iov(self->disk_image, req->sector, iov + 1, in + out - 2); + block_cnt = disk_image__read_sector_iov(blk_device.disk, req->sector, iov + 1, in + out - 2); break; case VIRTIO_BLK_T_OUT: - block_cnt = disk_image__write_sector_iov(self->disk_image, req->sector, iov + 1, in + out - 2); + block_cnt = disk_image__write_sector_iov(blk_device.disk, req->sector, iov + 1, in + out - 2); break; @@ -243,12 +244,14 @@ static struct pci_device_header virtio_blk_pci_device = { #define PCI_VIRTIO_BLK_DEVNUM 1 -void virtio_blk__init(struct kvm *self) +void virtio_blk__init(struct kvm *self, struct disk_image *disk) { - if (!self->disk_image) + if (!disk) return; - blk_device.blk_config.capacity = self->disk_image->size / SECTOR_SIZE; + blk_device.disk = disk; + + blk_device.blk_config.capacity = disk->size / SECTOR_SIZE; pci__register(&virtio_blk_pci_device, PCI_VIRTIO_BLK_DEVNUM);