From patchwork Wed Sep 5 08:32:03 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 1406661 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 F3ED0DF264 for ; Wed, 5 Sep 2012 08:36:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758206Ab2IEIgh (ORCPT ); Wed, 5 Sep 2012 04:36:37 -0400 Received: from mail-wg0-f42.google.com ([74.125.82.42]:45128 "EHLO mail-wg0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758177Ab2IEIge (ORCPT ); Wed, 5 Sep 2012 04:36:34 -0400 Received: by wgbfm10 with SMTP id fm10so3895944wgb.1 for ; Wed, 05 Sep 2012 01:36:33 -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=C77S+Uvt8JZbPuFiUOa5aKhmBYdYO1gIgdl+arufQWU=; b=AreCRZaaqIQE3I3DujoDzzblEYaL95jOcwgzKG7nCPCnkMoLMXNSMVhNrsKNjjuDPO g+ikC5bege6Bh43os/ePmJxcXjVgu25JWz2Lf6AhJvNjyLtgqFERcj6COpMPi/y0+nOK dZFqkZ1tslNVa3iZoW/CbZouRXzjdWsdxChOZBtmGLrDzPVCkQ8n+z92qawCG3m/9luu mOnpDu7jRXCnMYiZ95I2ojuGIMst3xu3oAblZ5CACT/u5RwR91A60fPF3c/qGlaYHbHp CRcrNNUHGHYOX1UOaDG+2aJwdnPM+WFx5FzNTCDgC7Cj5P3SO6ESwOKr1NpVVN+wFVMV 4wKw== Received: by 10.216.195.229 with SMTP id p79mr12594498wen.109.1346834193184; Wed, 05 Sep 2012 01:36:33 -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.36.31 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 05 Sep 2012 01:36:32 -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 29/33] kvm tools: virtio-9p cleanup Date: Wed, 5 Sep 2012 10:32:03 +0200 Message-Id: <1346833927-15740-30-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 Sort out init/exit calls, move parser into the 9p code and make sure rootfs config is initialized before virtio-9p (or any other init func) is called. Signed-off-by: Sasha Levin --- tools/kvm/builtin-run.c | 67 ++++++-------------------------------- tools/kvm/include/kvm/virtio-9p.h | 3 ++ tools/kvm/virtio/9p.c | 68 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 58 deletions(-) diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c index 6e6fbf5..183aa42 100644 --- a/tools/kvm/builtin-run.c +++ b/tools/kvm/builtin-run.c @@ -77,42 +77,12 @@ static int img_name_parser(const struct option *opt, const char *arg, int unset) { char path[PATH_MAX]; struct stat st; - struct kvm *kvm = opt->ptr; - - if (stat(arg, &st) == 0 && - S_ISDIR(st.st_mode)) { - char tmp[PATH_MAX]; - - if (kvm->cfg.using_rootfs) - die("Please use only one rootfs directory atmost"); - - if (realpath(arg, tmp) == 0 || - virtio_9p__register(kvm, tmp, "/dev/root") < 0) - die("Unable to initialize virtio 9p"); - kvm->cfg.using_rootfs = 1; - return 0; - } snprintf(path, PATH_MAX, "%s%s", kvm__get_dir(), arg); - if (stat(path, &st) == 0 && - S_ISDIR(st.st_mode)) { - char tmp[PATH_MAX]; - - if (kvm->cfg.using_rootfs) - die("Please use only one rootfs directory atmost"); - - if (realpath(path, tmp) == 0 || - virtio_9p__register(kvm, tmp, "/dev/root") < 0) - die("Unable to initialize virtio 9p"); - if (virtio_9p__register(kvm, "/", "hostfs") < 0) - die("Unable to initialize virtio 9p"); - kvm_setup_resolv(arg); - kvm->cfg.using_rootfs = kvm->cfg.custom_rootfs = 1; - kvm->cfg.custom_rootfs_name = arg; - return 0; - } - + if ((stat(arg, &st) == 0 && S_ISDIR(st.st_mode)) || + (stat(path, &st) == 0 && S_ISDIR(st.st_mode))) + return virtio_9p_img_name_parser(opt, arg, unset); return disk_img_name_parser(opt, arg, unset); } @@ -121,29 +91,6 @@ void kvm_run_set_wrapper_sandbox(void) kvm_run_wrapper = KVM_RUN_SANDBOX; } -static int virtio_9p_rootdir_parser(const struct option *opt, const char *arg, int unset) -{ - char *tag_name; - char tmp[PATH_MAX]; - - /* - * 9p dir can be of the form dirname,tag_name or - * just dirname. In the later case we use the - * default tag name - */ - tag_name = strstr(arg, ","); - if (tag_name) { - *tag_name = '\0'; - tag_name++; - } - if (realpath(arg, tmp)) { - if (virtio_9p__register(kvm, tmp, tag_name) < 0) - die("Unable to initialize virtio 9p"); - } else - die("Failed resolving 9p path"); - return 0; -} - #define BUILD_OPTIONS(name, cfg, kvm) \ struct option name[] = { \ OPT_GROUP("Basic options:"), \ @@ -167,7 +114,7 @@ static int virtio_9p_rootdir_parser(const struct option *opt, const char *arg, i 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, NULL), \ + guest", virtio_9p_rootdir_parser, kvm), \ OPT_STRING('\0', "console", &(cfg)->console, "serial, virtio or \ hv", "Console to use"), \ OPT_STRING('\0', "dev", &(cfg)->dev, "device_file", \ @@ -792,7 +739,11 @@ static int kvm_cmd_run_init(int argc, const char **argv) goto fail; } - virtio_9p__init(kvm); + r = virtio_9p__init(kvm); + if (r < 0) { + pr_err("virtio_9p__init() failed with error %d\n", r); + goto fail; + } r = virtio_net__init(kvm); if (r < 0) { diff --git a/tools/kvm/include/kvm/virtio-9p.h b/tools/kvm/include/kvm/virtio-9p.h index cb590d1..19ffe50 100644 --- a/tools/kvm/include/kvm/virtio-9p.h +++ b/tools/kvm/include/kvm/virtio-9p.h @@ -3,6 +3,7 @@ #include "kvm/virtio.h" #include "kvm/pci.h" #include "kvm/threadpool.h" +#include "kvm/parse-options.h" #include #include @@ -65,6 +66,8 @@ struct p9_pdu { struct kvm; +int virtio_9p_rootdir_parser(const struct option *opt, const char *arg, int unset); +int virtio_9p_img_name_parser(const struct option *opt, const char *arg, int unset); int virtio_9p__register(struct kvm *kvm, const char *root, const char *tag_name); int virtio_9p__init(struct kvm *kvm); int virtio_p9_pdu_readf(struct p9_pdu *pdu, const char *fmt, ...); diff --git a/tools/kvm/virtio/9p.c b/tools/kvm/virtio/9p.c index c3f5280..0705d79 100644 --- a/tools/kvm/virtio/9p.c +++ b/tools/kvm/virtio/9p.c @@ -5,6 +5,7 @@ #include "kvm/irq.h" #include "kvm/virtio-9p.h" #include "kvm/guest_compat.h" +#include "kvm/builtin-setup.h" #include #include @@ -1325,6 +1326,73 @@ struct virtio_ops p9_dev_virtio_ops = (struct virtio_ops) { .get_size_vq = get_size_vq, }; +int virtio_9p_rootdir_parser(const struct option *opt, const char *arg, int unset) +{ + char *tag_name; + char tmp[PATH_MAX]; + struct kvm *kvm = opt->ptr; + + /* + * 9p dir can be of the form dirname,tag_name or + * just dirname. In the later case we use the + * default tag name + */ + tag_name = strstr(arg, ","); + if (tag_name) { + *tag_name = '\0'; + tag_name++; + } + if (realpath(arg, tmp)) { + if (virtio_9p__register(kvm, tmp, tag_name) < 0) + die("Unable to initialize virtio 9p"); + } else + die("Failed resolving 9p path"); + return 0; +} + +int virtio_9p_img_name_parser(const struct option *opt, const char *arg, int unset) +{ + char path[PATH_MAX]; + struct stat st; + struct kvm *kvm = opt->ptr; + + if (stat(arg, &st) == 0 && + S_ISDIR(st.st_mode)) { + char tmp[PATH_MAX]; + + if (kvm->cfg.using_rootfs) + die("Please use only one rootfs directory atmost"); + + if (realpath(arg, tmp) == 0 || + virtio_9p__register(kvm, tmp, "/dev/root") < 0) + die("Unable to initialize virtio 9p"); + kvm->cfg.using_rootfs = 1; + return 0; + } + + snprintf(path, PATH_MAX, "%s%s", kvm__get_dir(), arg); + + if (stat(path, &st) == 0 && + S_ISDIR(st.st_mode)) { + char tmp[PATH_MAX]; + + if (kvm->cfg.using_rootfs) + die("Please use only one rootfs directory atmost"); + + if (realpath(path, tmp) == 0 || + virtio_9p__register(kvm, tmp, "/dev/root") < 0) + die("Unable to initialize virtio 9p"); + if (virtio_9p__register(kvm, "/", "hostfs") < 0) + die("Unable to initialize virtio 9p"); + kvm_setup_resolv(arg); + kvm->cfg.using_rootfs = kvm->cfg.custom_rootfs = 1; + kvm->cfg.custom_rootfs_name = arg; + return 0; + } + + return -1; +} + int virtio_9p__init(struct kvm *kvm) { struct p9_dev *p9dev;