From patchwork Thu May 5 10:24:29 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 756412 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.3) with ESMTP id p45AP1oD009152 for ; Thu, 5 May 2011 10:25:02 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753743Ab1EEKY6 (ORCPT ); Thu, 5 May 2011 06:24:58 -0400 Received: from mail-wy0-f174.google.com ([74.125.82.174]:40073 "EHLO mail-wy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753715Ab1EEKY5 (ORCPT ); Thu, 5 May 2011 06:24:57 -0400 Received: by wya21 with SMTP id 21so1485243wya.19 for ; Thu, 05 May 2011 03:24:56 -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; bh=t4XsYq5VHcvG4cslaKAPCUMexMilxwDak5pllcjwcVA=; b=th+OMBV6QD6Tqp9PzpO1WG4fAeL5MOc+Z+AoMCaIsmFp5QCRxyToyybXImJOG/54fC /RrWpE+YDLZ/G/rQlHT6ff8g37li0CHpo2Z0EiKXYc/8Gs0ifST95NSwNA1hgbKN6w7s whA/J2qxUyzkaFAZ00cBV+0QWdQdNIe6EY2CM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; b=TUJ2YoPNNvC8rOoV/Sf80V6oXl9jQbHF+e5Cut5yvuPF5WD8palbh7LlJIytVgwRtx GLl/+Aqkm7mY14hhOzFVvJmB8RMSbUB4m9fcCBdQNRe1murorkR8zCYT849w//Jp0wGR D6Asrmz7aOcZ9oF2eay5HmrkJvmUmO9BRcdcU= Received: by 10.216.69.3 with SMTP id m3mr2550830wed.9.1304591096437; Thu, 05 May 2011 03:24:56 -0700 (PDT) Received: from localhost.localdomain (bzq-79-183-199-149.red.bezeqint.net [79.183.199.149]) by mx.google.com with ESMTPS id n2sm1009192wej.22.2011.05.05.03.24.51 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 05 May 2011 03:24:55 -0700 (PDT) From: Sasha Levin To: penberg@kernel.org Cc: mingo@elte.hu, asias.hejun@gmail.com, gorcunov@gmail.com, prasadjoshi124@gmail.com, kvm@vger.kernel.org, Sasha Levin Subject: [PATCH 1/3 V3] kvm tools: Move disk_image into virtio-blk Date: Thu, 5 May 2011 13:24:29 +0300 Message-Id: <1304591071-27074-1-git-send-email-levinsasha928@gmail.com> X-Mailer: git-send-email 1.7.5.rc3 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 (demeter2.kernel.org [140.211.167.43]); Thu, 05 May 2011 10:25:02 +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);