From patchwork Wed Sep 5 08:31:43 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 1406471 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id B0551DF264 for ; Wed, 5 Sep 2012 08:32:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757952Ab2IEIcU (ORCPT ); Wed, 5 Sep 2012 04:32:20 -0400 Received: from mail-we0-f174.google.com ([74.125.82.174]:57885 "EHLO mail-we0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750999Ab2IEIcN (ORCPT ); Wed, 5 Sep 2012 04:32:13 -0400 Received: by mail-we0-f174.google.com with SMTP id x8so220187wey.19 for ; Wed, 05 Sep 2012 01:32:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=Dtm+KuTzOKK+1JOVDfziFxmblORKjlDdoAJcxkSe5DA=; b=otZq5ljdbDDDjef4ftF9SEFI0ECk/QMGYjvVFkwEwuuwWMlzjd/t5eHqGT0TPRyjvb ZE7h6xDV4c8hQ7AoxAXqjbElPe7IzU+wP+PQf+ShILh9RXN7DWQK/hJkz9+Ta/r49Djm PnzPT6AInnT63+oD+idQ3o5alHmrRiJyw3CGekZI3OqpC8KbjxZ7eRPGdKydD/pbO0Xi kmaG7QnuK8SUveUi3CDryxYCYOAoCxZ6in/W4UXum9J0fFVmPLHhK5M+rldlQKPUNMrz BGnhNyAYVpubrb5rcRmBQP9R2i89onHSTG7XMWjtjdI2jFAO15j10kou57IYTIKUA0K+ bc2w== Received: by 10.216.95.10 with SMTP id o10mr4790730wef.213.1346833932881; Wed, 05 Sep 2012 01:32:12 -0700 (PDT) Received: from lappy.capriciverd.com (20.Red-80-59-140.staticIP.rima-tde.net. [80.59.140.20]) by mx.google.com with ESMTPS id q4sm27971068wix.9.2012.09.05.01.32.09 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 05 Sep 2012 01:32:11 -0700 (PDT) From: Sasha Levin To: penberg@kernel.org Cc: asias.hejun@gmail.com, mingo@elte.hu, gorcunov@openvz.org, kvm@vger.kernel.org, Sasha Levin Subject: [PATCH 09/33] kvm tools: add private ptr to option parser Date: Wed, 5 Sep 2012 10:31:43 +0200 Message-Id: <1346833927-15740-10-git-send-email-levinsasha928@gmail.com> X-Mailer: git-send-email 1.7.12 In-Reply-To: <1346833927-15740-1-git-send-email-levinsasha928@gmail.com> References: <1346833927-15740-1-git-send-email-levinsasha928@gmail.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Support passing a private ptr to CALLBACK options. This will make it possible assigning options into specific struct kvms by passing them directly to parsers. Signed-off-by: Sasha Levin --- tools/kvm/builtin-run.c | 13 +++++++------ tools/kvm/include/kvm/parse-options.h | 16 ++++++++++------ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c index 2b4315b..52e0190 100644 --- a/tools/kvm/builtin-run.c +++ b/tools/kvm/builtin-run.c @@ -417,9 +417,10 @@ static int shmem_parser(const struct option *opt, const char *arg, int unset) OPT_CALLBACK('\0', "shmem", NULL, \ "[pci:]:[:handle=][:create]", \ "Share host shmem with guest via pci device", \ - shmem_parser), \ - OPT_CALLBACK('d', "disk", NULL, "image or rootfs_dir", "Disk \ - image or rootfs directory", img_name_parser), \ + shmem_parser, NULL), \ + OPT_CALLBACK('d', "disk", kvm, "image or rootfs_dir", "Disk \ + image or rootfs directory", img_name_parser, \ + NULL), \ OPT_BOOLEAN('\0', "balloon", &(cfg)->balloon, "Enable virtio \ balloon"), \ OPT_BOOLEAN('\0', "vnc", &(cfg)->vnc, "Enable VNC framebuffer"),\ @@ -428,14 +429,14 @@ static int shmem_parser(const struct option *opt, const char *arg, int unset) Number Generator"), \ OPT_CALLBACK('\0', "9p", NULL, "dir_to_share,tag_name", \ "Enable virtio 9p to share files between host and \ - guest", virtio_9p_rootdir_parser), \ + guest", virtio_9p_rootdir_parser, NULL), \ OPT_STRING('\0', "console", &(cfg)->console, "serial, virtio or \ hv", "Console to use"), \ OPT_STRING('\0', "dev", &(cfg)->dev, "device_file", \ "KVM device file"), \ OPT_CALLBACK('\0', "tty", NULL, "tty id", \ "Remap guest TTY into a pty on the host", \ - tty_parser), \ + tty_parser, NULL), \ OPT_STRING('\0', "sandbox", &(cfg)->sandbox, "script", \ "Run this script when booting into custom \ rootfs"), \ @@ -455,7 +456,7 @@ static int shmem_parser(const struct option *opt, const char *arg, int unset) OPT_GROUP("Networking options:"), \ OPT_CALLBACK_DEFAULT('n', "network", NULL, "network params", \ "Create a new guest NIC", \ - netdev_parser, NULL), \ + netdev_parser, NULL, NULL), \ OPT_BOOLEAN('\0', "no-dhcp", &(cfg)->no_dhcp, "Disable kernel DHCP\ in rootfs mode"), \ \ diff --git a/tools/kvm/include/kvm/parse-options.h b/tools/kvm/include/kvm/parse-options.h index 7886ff7..a8a25d0 100644 --- a/tools/kvm/include/kvm/parse-options.h +++ b/tools/kvm/include/kvm/parse-options.h @@ -89,6 +89,7 @@ const char *long_name; void *value; const char *argh; const char *help; +void *ptr; int flags; parse_opt_cb *callback; @@ -150,7 +151,7 @@ intptr_t defval; .help = (h) \ } -#define OPT_CALLBACK(s, l, v, a, h, f) \ +#define OPT_CALLBACK(s, l, v, a, h, f, p) \ { \ .type = OPTION_CALLBACK, \ .short_name = (s), \ @@ -158,10 +159,11 @@ intptr_t defval; .value = (v), \ (a), \ .help = (h), \ - .callback = (f) \ + .callback = (f), \ + .ptr = (p), \ } -#define OPT_CALLBACK_NOOPT(s, l, v, a, h, f) \ +#define OPT_CALLBACK_NOOPT(s, l, v, a, h, f, p) \ { \ .type = OPTION_CALLBACK, \ .short_name = (s), \ @@ -170,10 +172,11 @@ intptr_t defval; (a), \ .help = (h), \ .callback = (f), \ - .flags = PARSE_OPT_NOARG \ + .flags = PARSE_OPT_NOARG, \ + .ptr = (p), \ } -#define OPT_CALLBACK_DEFAULT(s, l, v, a, h, f, d) \ +#define OPT_CALLBACK_DEFAULT(s, l, v, a, h, f, d, p) \ { \ .type = OPTION_CALLBACK, \ .short_name = (s), \ @@ -182,7 +185,8 @@ intptr_t defval; .help = (h), \ .callback = (f), \ .defval = (intptr_t)d, \ - .flags = PARSE_OPT_LASTARG_DEFAULT \ + .flags = PARSE_OPT_LASTARG_DEFAULT, \ + .ptr = (p) \ } #define OPT_END() { .type = OPTION_END }