From patchwork Fri May 20 18:41:48 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prasad Joshi X-Patchwork-Id: 804482 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 p4KIfvLv031810 for ; Fri, 20 May 2011 18:41:58 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934865Ab1ETSly (ORCPT ); Fri, 20 May 2011 14:41:54 -0400 Received: from mail-wy0-f174.google.com ([74.125.82.174]:34951 "EHLO mail-wy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933900Ab1ETSlx (ORCPT ); Fri, 20 May 2011 14:41:53 -0400 Received: by wya21 with SMTP id 21so2935241wya.19 for ; Fri, 20 May 2011 11:41:52 -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=3CMJ8QClOmBRZ7HKwPrc3Xg5dxVLVEfuCGgIFHiJHjs=; b=JVmYwsqsLgWqI7ExzmEIg+C0JyrCilW6+JVWUiwWDH3Hm34TUwWSl0t+qX1uXA+2SS fIAyjHU5lrCiUBLL1FKhwgsaLcUI8mvvX56YE5N2+dGXuaIQkEx/JNreXGnNTBDy1/o/ 2qZqRXsGNyIcYKohsU9FGd8KokceYpO/589jw= 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=TvVpzL/P3llG+gm7UCyTcdmYWLoz0Q8AJSsacBYnOIyfmT0QRqgbTHTk+6tHbfCdoT h0fnzV1kyX5fT2MG6MPuY0XmTtUFo5halI0dzOx3xJnQfgRL/BiZj8qZs/d3VknqvpPR OcjEw72TSst4UsyN0nvlKkF9wjPn7g8I9WtvY= Received: by 10.227.55.134 with SMTP id u6mr4545815wbg.62.1305916912445; Fri, 20 May 2011 11:41:52 -0700 (PDT) Received: from prasad-kvm.localdomain (pineapple.rdg.ac.uk [134.225.206.123]) by mx.google.com with ESMTPS id k2sm2460952wby.34.2011.05.20.11.41.50 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 20 May 2011 11:41:51 -0700 (PDT) Received: by prasad-kvm.localdomain (Postfix, from userid 1000) id 979A426E004C; Fri, 20 May 2011 19:41:50 +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 v3 3/4] kvm tools: Add a wrapper function to initialize all virtio block devices Date: Fri, 20 May 2011 19:41:48 +0100 Message-Id: <1305916909-21734-3-git-send-email-prasadjoshi124@gmail.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1305916909-21734-1-git-send-email-prasadjoshi124@gmail.com> References: <1305916909-21734-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 (demeter1.kernel.org [140.211.167.41]); Fri, 20 May 2011 18:41:58 +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 32b34fe..6c96337 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 all disk images."); 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]); +}