From patchwork Thu Mar 25 16:43:36 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Aneesh Kumar K.V" X-Patchwork-Id: 48579 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 32922B7067 for ; Fri, 26 Mar 2010 05:28:45 +1100 (EST) Received: from localhost ([127.0.0.1]:34121 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NurnM-0001eq-BI for incoming@patchwork.ozlabs.org; Thu, 25 Mar 2010 14:28:40 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NuqBB-0007M2-Qg for qemu-devel@nongnu.org; Thu, 25 Mar 2010 12:45:09 -0400 Received: from [140.186.70.92] (port=50823 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NuqAz-0007Iv-MH for qemu-devel@nongnu.org; Thu, 25 Mar 2010 12:45:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NuqAq-0005FC-7n for qemu-devel@nongnu.org; Thu, 25 Mar 2010 12:44:57 -0400 Received: from e23smtp02.au.ibm.com ([202.81.31.144]:52143) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NuqAo-0005Et-KP for qemu-devel@nongnu.org; Thu, 25 Mar 2010 12:44:48 -0400 Received: from d23relay03.au.ibm.com (d23relay03.au.ibm.com [202.81.31.245]) by e23smtp02.au.ibm.com (8.14.3/8.13.1) with ESMTP id o2PGfRFT007355 for ; Fri, 26 Mar 2010 03:41:27 +1100 Received: from d23av03.au.ibm.com (d23av03.au.ibm.com [9.190.234.97]) by d23relay03.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o2PGijX81519798 for ; Fri, 26 Mar 2010 03:44:45 +1100 Received: from d23av03.au.ibm.com (loopback [127.0.0.1]) by d23av03.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id o2PGiiiu031806 for ; Fri, 26 Mar 2010 03:44:45 +1100 Received: from localhost.localdomain ([9.77.125.24]) by d23av03.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVin) with ESMTP id o2PGhgP3030935; Fri, 26 Mar 2010 03:44:42 +1100 From: "Aneesh Kumar K.V" To: qemu-devel@nongnu.org Date: Thu, 25 Mar 2010 22:13:36 +0530 Message-Id: <1269535420-31206-29-git-send-email-aneesh.kumar@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.0.2.323.g0d092 In-Reply-To: <1269535420-31206-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> References: <1269535420-31206-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: ericvh@gmail.com, aliguori@us.ibm.com, "Aneesh Kumar K.V" , Gautham R Shenoy Subject: [Qemu-devel] [PATCH -V3 28/32] virtio-9p: Handle the fsdev command line options. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Gautham R Shenoy This patch handles: - Parsing of fsdev commandline options. - Maintaining a list of fsdev entries. - Providing callbacks for the other subsystems to obtain FsTypeEntries for a given fsdev based on it's id. This will be used later to decouple the share_path attribute from the virtio-9p device. Signed-off-by: Gautham R Shenoy Signed-off-by: Aneesh Kumar K.V --- Makefile.objs | 5 +++- fsdev/qemu-fsdev.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++ fsdev/qemu-fsdev.h | 53 +++++++++++++++++++++++++++++++++++++ hw/virtio-9p-local.c | 4 +- vl.c | 18 +++++++++++++ 5 files changed, 147 insertions(+), 3 deletions(-) create mode 100644 fsdev/qemu-fsdev.c create mode 100644 fsdev/qemu-fsdev.h diff --git a/Makefile.objs b/Makefile.objs index 281f7a6..2adfdff 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -35,6 +35,9 @@ net-nested-$(CONFIG_SLIRP) += slirp.o net-nested-$(CONFIG_VDE) += vde.o net-obj-y += $(addprefix net/, $(net-nested-y)) +fsdev-nested-y = qemu-fsdev.o +fsdev-obj-y += $(addprefix fsdev/, $(fsdev-nested-y)) + ###################################################################### # libqemu_common.a: Target independent part of system emulation. The # long term path is to suppress *all* target specific code in case of @@ -44,8 +47,8 @@ net-obj-y += $(addprefix net/, $(net-nested-y)) common-obj-y = $(block-obj-y) common-obj-y += $(net-obj-y) common-obj-y += $(qobject-obj-y) +common-obj-y += $(fsdev-obj-y) common-obj-y += readline.o console.o async.o qemu-error.o - common-obj-y += tcg-runtime.o host-utils.o common-obj-y += irq.o ioport.o input.o common-obj-$(CONFIG_PTIMER) += ptimer.o diff --git a/fsdev/qemu-fsdev.c b/fsdev/qemu-fsdev.c new file mode 100644 index 0000000..cf1629a --- /dev/null +++ b/fsdev/qemu-fsdev.c @@ -0,0 +1,70 @@ +/* + * Virtio 9p + * + * Copyright IBM, Corp. 2010 + * + * Authors: + * Gautham R Shenoy + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + * + */ +#include +#include +#include "qemu-fsdev.h" +#include "qemu-queue.h" +#include "osdep.h" +#include "qemu-common.h" + +static QTAILQ_HEAD(FsTypeEntry_head, FsTypeListEntry) fstype_entries = + QTAILQ_HEAD_INITIALIZER(fstype_entries); + +extern FileOperations local_ops; +static FsTypeTable FsTypes[] = { + { .name ="local", .ops = &local_ops}, +}; + +int qemu_fsdev_add(QemuOpts *opts) +{ + struct FsTypeListEntry *fsle; + int i; + + if (qemu_opts_id(opts) == NULL) { + fprintf(stderr, "fsdev: No id specified\n"); + return -1; + } + + for (i = 0; i < ARRAY_SIZE(FsTypes); i++) { + if (strcmp(FsTypes[i].name, qemu_opt_get(opts, "fstype")) == 0) + break; + } + + if (i == ARRAY_SIZE(FsTypes)) { + fprintf(stderr, "fsdev: fstype %s not found\n", + qemu_opt_get(opts, "fstype")); + return -1; + } + + fsle =qemu_malloc(sizeof(*fsle)); + + fsle->fse.fsdev_id = qemu_strdup(qemu_opts_id(opts)); + fsle->fse.path = qemu_strdup(qemu_opt_get(opts, "path")); + fsle->fse.ops = FsTypes[i].ops; + + QTAILQ_INSERT_TAIL(&fstype_entries, fsle, next); + return 0; + +} + +FsTypeEntry * get_fsdev_fsentry(char *id) +{ + struct FsTypeListEntry *fsle; + + QTAILQ_FOREACH(fsle, &fstype_entries, next) { + if (strcmp(fsle->fse.fsdev_id, id) == 0) { + return &fsle->fse; + } + } + return NULL; +} diff --git a/fsdev/qemu-fsdev.h b/fsdev/qemu-fsdev.h new file mode 100644 index 0000000..db280bb --- /dev/null +++ b/fsdev/qemu-fsdev.h @@ -0,0 +1,53 @@ +/* + * Virtio 9p + * + * Copyright IBM, Corp. 2010 + * + * Authors: + * Gautham R Shenoy + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + * + */ +#ifndef QEMU_FSDEV_H +#define QEMU_FSDEV_H +#include "qemu-option.h" +#include "hw/file-op.h" + + +/* + * A table to store the various file systems and their callback operations. + * ----------------- + * fstype | ops + * ----------------- + * local | local_ops + * . | + * . | + * . | + * . | + * ----------------- + * etc + */ +typedef struct FsTypeTable { + const char *name; + FileOperations *ops; +} FsTypeTable; + +/* + * Structure to store the various fsdev's passed through command line. + */ +typedef struct FsTypeEntry { + char *fsdev_id; + char *path; + FileOperations *ops; +} FsTypeEntry; + +typedef struct FsTypeListEntry { + FsTypeEntry fse; + QTAILQ_ENTRY(FsTypeListEntry) next; +} FsTypeListEntry; + +extern int qemu_fsdev_add(QemuOpts *opts); +extern FsTypeEntry *get_fsdev_fsentry(char *id); +#endif diff --git a/hw/virtio-9p-local.c b/hw/virtio-9p-local.c index 690ba3f..aae82d2 100644 --- a/hw/virtio-9p-local.c +++ b/hw/virtio-9p-local.c @@ -254,7 +254,7 @@ static int local_fsync(FsContext *s, int fd) return fsync(fd); } -static FileOperations ops = { +FileOperations local_ops = { .lstat = local_lstat, .setuid = local_setuid, .readlink = local_readlink, @@ -287,5 +287,5 @@ static FileOperations ops = { FileOperations *virtio_9p_init_local(const char *path) { - return &ops; + return &local_ops; } diff --git a/vl.c b/vl.c index d69250c..0228045 100644 --- a/vl.c +++ b/vl.c @@ -150,6 +150,7 @@ int main(int argc, char **argv) #include "qemu-option.h" #include "qemu-config.h" #include "qemu-objects.h" +#include "fsdev/qemu-fsdev.h" #include "disas.h" @@ -3461,6 +3462,14 @@ static int chardev_init_func(QemuOpts *opts, void *opaque) return 0; } +static int fsdev_init_func(QemuOpts *opts, void *opaque) +{ + int ret; + ret = qemu_fsdev_add(opts); + + return ret; +} + static int mon_init_func(QemuOpts *opts, void *opaque) { CharDriverState *chr; @@ -4256,6 +4265,13 @@ int main(int argc, char **argv, char **envp) exit(1); } break; + case QEMU_OPTION_fsdev: + opts = qemu_opts_parse(&qemu_fsdev_opts, optarg, 1); + if (!opts) { + fprintf(stderr, "parse error: %s\n", optarg); + exit(1); + } + break; case QEMU_OPTION_serial: add_device_config(DEV_SERIAL, optarg); default_serial = 0; @@ -4625,6 +4641,8 @@ int main(int argc, char **argv, char **envp) if (qemu_opts_foreach(&qemu_chardev_opts, chardev_init_func, NULL, 1) != 0) exit(1); + if (qemu_opts_foreach(&qemu_fsdev_opts, fsdev_init_func, NULL, 1) != 0) + exit(1); #ifndef _WIN32 if (daemonize) {