From patchwork Fri May 20 15:02:39 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prasad Joshi X-Patchwork-Id: 803872 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 p4KF38u6027736 for ; Fri, 20 May 2011 15:03:08 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756276Ab1ETPDE (ORCPT ); Fri, 20 May 2011 11:03:04 -0400 Received: from mail-wy0-f174.google.com ([74.125.82.174]:55767 "EHLO mail-wy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755296Ab1ETPDD (ORCPT ); Fri, 20 May 2011 11:03:03 -0400 Received: by wya21 with SMTP id 21so2795363wya.19 for ; Fri, 20 May 2011 08:03:01 -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=tkHzUmMijTKb2v5YmSaaT5vMHxWNpJFYehkELGEXViQ=; b=q/ITRBuf+us04YfoZ+/erT2HjWM1qWecyGDe+AEvirP9i/48Ak3AQgLpUm/Yg9PlPr HZbCS7WPDY0U8bfwEGKdQ3jGtzT5sR9sokGZkz5ZMfyjqCWZVmj+AhOAmIYbrvkWRKRU 8NK+NRpI7BMRe6RyPdgzSatWoddFogbuVtknY= 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=we8qBP/eCiWMG8Stft8KMdIQ14LfAFy50fz85+m5b11djkYWCY41UMj1c8k1e412OX 8+gV9vgDP6sbK5WC3S3JpOld/jLk0nr4O7lUpHI0LK0gKaqb3TrrOUdE/Bpk4xvHt9Ec VD9/8eRVNC7ys1p/9X0dJwi3Fvvf43gTF+X3I= Received: by 10.216.120.129 with SMTP id p1mr4437780weh.81.1305903781077; Fri, 20 May 2011 08:03:01 -0700 (PDT) Received: from prasad-kvm.localdomain (pineapple.rdg.ac.uk [134.225.206.123]) by mx.google.com with ESMTPS id s40sm1894400weq.28.2011.05.20.08.02.44 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 20 May 2011 08:02:51 -0700 (PDT) Received: by prasad-kvm.localdomain (Postfix, from userid 1000) id 4CA4026E004E; Fri, 20 May 2011 16:02:41 +0100 (BST) From: Prasad Joshi To: prasadjoshi124@gmail.com Cc: mingo@elte.hu, kvm@vger.kernel.org, penberg@kernel.org, asias.hejun@gmail.com, gorcunov@gmail.com, levinsasha928@gmail.com, chaitanyakulkarni15@gmail.com, ashwini.kulkarni@gmail.com Subject: [PATCH v2 3/4] kvm tools: Add a wrapper function to initialize all virtio block devices Date: Fri, 20 May 2011 16:02:39 +0100 Message-Id: <1305903760-7804-3-git-send-email-prasadjoshi124@gmail.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1305903760-7804-1-git-send-email-prasadjoshi124@gmail.com> References: <1305903760-7804-1-git-send-email-prasadjoshi124@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 (demeter2.kernel.org [140.211.167.43]); Fri, 20 May 2011 15:03:08 +0000 (UTC) The patch moves the code for initialization of all of the virtio block devices to virtio subsystem. Signed-off-by: Prasad Joshi --- tools/kvm/include/kvm/kvm.h | 1 + tools/kvm/include/kvm/virtio-blk.h | 1 + tools/kvm/kvm-run.c | 4 ++-- tools/kvm/virtio/blk.c | 8 ++++++++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/tools/kvm/include/kvm/kvm.h b/tools/kvm/include/kvm/kvm.h index f419634..9592ce7 100644 --- a/tools/kvm/include/kvm/kvm.h +++ b/tools/kvm/include/kvm/kvm.h @@ -33,6 +33,7 @@ struct kvm { const char *vmlinux; struct disk_image **disks; + int ndisks; }; struct kvm *kvm__init(const char *kvm_dev, unsigned long ram_size); diff --git a/tools/kvm/include/kvm/virtio-blk.h b/tools/kvm/include/kvm/virtio-blk.h index 22983e8..72f6491 100644 --- a/tools/kvm/include/kvm/virtio-blk.h +++ b/tools/kvm/include/kvm/virtio-blk.h @@ -6,5 +6,6 @@ struct kvm; void virtio_blk__init(struct kvm *kvm, struct disk_image *disk); +void virtio_blk__init_all(struct kvm *kvm); #endif /* KVM__BLK_VIRTIO_H */ diff --git a/tools/kvm/kvm-run.c b/tools/kvm/kvm-run.c index 9bfe8fe..6b0c1fd 100644 --- a/tools/kvm/kvm-run.c +++ b/tools/kvm/kvm-run.c @@ -529,14 +529,14 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix) if (!strstr(real_cmdline, "root=")) strlcat(real_cmdline, " root=/dev/vda rw ", sizeof(real_cmdline)); + kvm->ndisks = image_count; kvm->disks = disk_image__open_all(image_filename, readonly_image, image_count); if (!kvm->disks) die("unable to load disk image"); free(hi); - for (i = 0; i < image_count; i++) - virtio_blk__init(kvm, kvm->disks[i]); + virtio_blk__init_all(kvm); printf(" # kvm run -k %s -m %Lu -c %d\n", kernel_filename, ram_size / 1024 / 1024, nrcpus); diff --git a/tools/kvm/virtio/blk.c b/tools/kvm/virtio/blk.c index c5d1bb8..2ee5854 100644 --- a/tools/kvm/virtio/blk.c +++ b/tools/kvm/virtio/blk.c @@ -320,3 +320,11 @@ void virtio_blk__init(struct kvm *kvm, struct disk_image *disk) ioport__register(blk_dev_base_addr, &virtio_blk_io_ops, IOPORT_VIRTIO_BLK_SIZE); } + +void virtio_blk__init_all(struct kvm *kvm) +{ + int i; + + for (i = 0; i < kvm->ndisks; i++) + virtio_blk__init(kvm, kvm->disks[i]); +}