From patchwork Wed May 4 13:45:17 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 753812 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 p44DjdoM019712 for ; Wed, 4 May 2011 13:45:39 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753860Ab1EDNpf (ORCPT ); Wed, 4 May 2011 09:45:35 -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 S1753657Ab1EDNpd (ORCPT ); Wed, 4 May 2011 09:45:33 -0400 Received: by mail-ww0-f44.google.com with SMTP id 36so1239442wwa.1 for ; Wed, 04 May 2011 06:45:33 -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=S1HahXWzbUTshH48hmHDF2j3fMjz87H70t9WruuQrRY=; b=l/Su2JGMnaXuwH/54OXOlOgNRA4V0CeCoMY4/SQoWSGowzDfnK/ma7MCpYnAlvOKES 6h5jvmia8BFeq+IZnqUGZd2HA9M+1Spv2lnJPQRpyK8fKbbzBMs+O+Z6qSmdLSjmQQyI 6Khfs/q2V8UxGvXbSjKPuSj1ITdXjyw6UH1yg= 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=WQ877cpc2IJMuugMZM/avYslH5o1XaThRnZrrxBs+eZAq+kenKa+4t0+pGctvC8Fmx oCYuI5dMgSctDCvkZRsH0FaRD17b6J4TM9puQ0wRVlTl3nN24rgHe79brDsK5O+ZjTRf cJK/2cKVz5Uj9VHMtH3al2RfbAV63dBRuq5/0= Received: by 10.227.195.68 with SMTP id eb4mr1183253wbb.51.1304516733206; Wed, 04 May 2011 06:45:33 -0700 (PDT) Received: from localhost.localdomain ([77.124.181.142]) by mx.google.com with ESMTPS id x13sm226068wby.42.2011.05.04.06.45.31 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 04 May 2011 06:45:32 -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 3/3 V2] kvm tools: Add cmdline options for loading multiple images Date: Wed, 4 May 2011 16:45:17 +0300 Message-Id: <1304516717-24512-4-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 (demeter2.kernel.org [140.211.167.43]); Wed, 04 May 2011 13:45:39 +0000 (UTC) This is a simple cmdline addition to allow loading multiple images. perf's cmdline parser doesn't support having multiple args with the same name (i.e. --image --image ), so we have to choose either to extend the parser, or find a diiferent way to assign multiple images. Sample cmdline for loading 2 images: ./kvm run --image=image1.raw --readonly --image2=image2.raw --readonly2 NOTE NOTE NOTE - If testing, Please take notice of the --readonly param changes so you won't destroy your image/disk. Signed-off-by: Sasha Levin --- tools/kvm/kvm-run.c | 36 ++++++++++++++++++++++++------------ 1 files changed, 24 insertions(+), 12 deletions(-) diff --git a/tools/kvm/kvm-run.c b/tools/kvm/kvm-run.c index b92232d..5182735 100644 --- a/tools/kvm/kvm-run.c +++ b/tools/kvm/kvm-run.c @@ -42,6 +42,7 @@ #define MB_SHIFT (20) #define MIN_RAM_SIZE_MB (64ULL) #define MIN_RAM_SIZE_BYTE (MIN_RAM_SIZE_MB << MB_SHIFT) +#define MAX_DISK_IMAGES 4 static struct kvm *kvm; static struct kvm_cpu *kvm_cpus[KVM_NR_CPUS]; @@ -51,7 +52,7 @@ static u64 ram_size = MIN_RAM_SIZE_MB; static const char *kernel_cmdline; static const char *kernel_filename; static const char *initrd_filename; -static const char *image_filename; +static const char *image_filename[MAX_DISK_IMAGES]; static const char *console; static const char *kvm_dev; static const char *network; @@ -59,7 +60,7 @@ static const char *host_ip_addr; static const char *guest_mac; static const char *script; static bool single_step; -static bool readonly_image; +static bool readonly_image[MAX_DISK_IMAGES]; static bool virtio_rng; extern bool ioport_debug; extern int active_console; @@ -75,8 +76,17 @@ static const struct option options[] = { OPT_GROUP("Basic options:"), OPT_INTEGER('\0', "cpus", &nrcpus, "Number of CPUs"), OPT_U64('m', "mem", &ram_size, "Virtual machine memory size in MiB."), - OPT_STRING('i', "image", &image_filename, "image", "Disk image"), - OPT_BOOLEAN('\0', "readonly", &readonly_image, + OPT_STRING('i', "image", &image_filename[0], "image", "Disk image"), + OPT_BOOLEAN('\0', "readonly", &readonly_image[0], + "Don't write changes back to disk image"), + OPT_STRING('\0', "image2", &image_filename[1], "image", "Disk image"), + OPT_BOOLEAN('\0', "readonly2", &readonly_image[1], + "Don't write changes back to disk image"), + OPT_STRING('\0', "image3", &image_filename[2], "image", "Disk image"), + OPT_BOOLEAN('\0', "readonly3", &readonly_image[2], + "Don't write changes back to disk image"), + OPT_STRING('\0', "image4", &image_filename[3], "image", "Disk image"), + OPT_BOOLEAN('\0', "readonly4", &readonly_image[3], "Don't write changes back to disk image"), OPT_STRING('c', "console", &console, "serial or virtio", "Console to use"), @@ -397,23 +407,25 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix) strlcat(real_cmdline, kernel_cmdline, sizeof(real_cmdline)); hi = NULL; - if (!image_filename) { + if (!image_filename[0]) { hi = host_image(real_cmdline, sizeof(real_cmdline)); if (hi) { - image_filename = hi; - readonly_image = true; + image_filename[0] = hi; + readonly_image[0] = true; } } if (!strstr(real_cmdline, "root=")) strlcat(real_cmdline, " root=/dev/vda rw ", sizeof(real_cmdline)); - if (image_filename) { - struct disk_image *disk = disk_image__open(image_filename, readonly_image); - if (!disk) - die("unable to load disk image %s", image_filename); + for (i = 0; i < MAX_DISK_IMAGES; i++) { + if (image_filename[i]) { + struct disk_image *disk = disk_image__open(image_filename[i], readonly_image[i]); + if (!disk) + die("unable to load disk image %s", image_filename[i]); - virtio_blk__init(kvm, disk); + virtio_blk__init(kvm, disk); + } } free(hi);