From patchwork Fri Apr 19 13:37:32 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: fred.konrad@greensocs.com X-Patchwork-Id: 237943 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 2302F2C0217 for ; Fri, 19 Apr 2013 23:38:28 +1000 (EST) Received: from localhost ([::1]:35695 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UTBWE-0003XB-BM for incoming@patchwork.ozlabs.org; Fri, 19 Apr 2013 09:38:26 -0400 Received: from eggs.gnu.org ([208.118.235.92]:50787) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UTBVi-0003UA-R6 for qemu-devel@nongnu.org; Fri, 19 Apr 2013 09:37:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UTBVh-0003Zp-34 for qemu-devel@nongnu.org; Fri, 19 Apr 2013 09:37:54 -0400 Received: from greensocs.com ([87.106.252.221]:57051 helo=s15328186.onlinehome-server.info) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UTBVg-0003Zj-Q6 for qemu-devel@nongnu.org; Fri, 19 Apr 2013 09:37:53 -0400 Received: from localhost (unknown [127.0.0.1]) by s15328186.onlinehome-server.info (Postfix) with ESMTP id 4032540EC61; Fri, 19 Apr 2013 13:37:52 +0000 (UTC) Received: from s15328186.onlinehome-server.info ([127.0.0.1]) by localhost (s15328186.onlinehome-server.info [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id C4b+L3zYIaGe; Fri, 19 Apr 2013 15:37:50 +0200 (CEST) Received: by s15328186.onlinehome-server.info (Postfix, from userid 491) id 569D640EC60; Fri, 19 Apr 2013 15:37:50 +0200 (CEST) Received: from compaq.katmai.xl.cx.katmai.xl.cx (lan31-11-83-155-143-136.fbx.proxad.net [83.155.143.136]) by s15328186.onlinehome-server.info (Postfix) with ESMTPSA id A2E3440EC61; Fri, 19 Apr 2013 15:37:49 +0200 (CEST) From: fred.konrad@greensocs.com To: qemu-devel@nongnu.org, aliguori@us.ibm.com Date: Fri, 19 Apr 2013 15:37:32 +0200 Message-Id: <1366378655-23722-2-git-send-email-fred.konrad@greensocs.com> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1366378655-23722-1-git-send-email-fred.konrad@greensocs.com> References: <1366378655-23722-1-git-send-email-fred.konrad@greensocs.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 87.106.252.221 Cc: peter.maydell@linaro.org, mark.burton@greensocs.com, "Aneesh Kumar K.V" , fred.konrad@greensocs.com Subject: [Qemu-devel] [PATCH RESEND v3 1/4] virtio-9p: add the virtio-9p device. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: KONRAD Frederic Create virtio-9p which extends virtio-device, so it can be connected on virtio-bus. Signed-off-by: KONRAD Frederic --- hw/9pfs/virtio-9p-device.c | 73 +++++++++++++++++++++++++++++++++++++++++----- hw/9pfs/virtio-9p.h | 9 ++++++ hw/virtio/virtio-pci.c | 3 +- 3 files changed, 76 insertions(+), 9 deletions(-) diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c index b476b81..7f00a45 100644 --- a/hw/9pfs/virtio-9p-device.c +++ b/hw/9pfs/virtio-9p-device.c @@ -46,19 +46,30 @@ static void virtio_9p_get_config(VirtIODevice *vdev, uint8_t *config) g_free(cfg); } -VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf) +static VirtIODevice *virtio_9p_common_init(DeviceState *dev, V9fsConf *conf, + V9fsState **ps) { - V9fsState *s; + V9fsState *s = *ps; int i, len; struct stat stat; FsDriverEntry *fse; V9fsPath path; - s = (V9fsState *)virtio_common_init("virtio-9p", - VIRTIO_ID_9P, - sizeof(struct virtio_9p_config)+ - MAX_TAG_LEN, - sizeof(V9fsState)); + /* + * We have two cases here: the old virtio-9p-pci device, and the + * refactored virtio-9p. + */ + + if (s == NULL) { + s = (V9fsState *)virtio_common_init("virtio-9p", + VIRTIO_ID_9P, + sizeof(struct virtio_9p_config)+ + MAX_TAG_LEN, + sizeof(V9fsState)); + } else { + virtio_init(VIRTIO_DEVICE(s), "virtio-9p", VIRTIO_ID_9P, + sizeof(struct virtio_9p_config) + MAX_TAG_LEN); + } /* initialize pdu allocator */ QLIST_INIT(&s->free_list); QLIST_INIT(&s->active_list); @@ -136,3 +147,51 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf) return &s->vdev; } + +VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf) +{ + V9fsState *s = NULL; + return virtio_9p_common_init(dev, conf, &s); +} + +/* virtio-9p device */ + +static int virtio_9p_device_init(VirtIODevice *vdev) +{ + DeviceState *qdev = DEVICE(vdev); + V9fsState *s = VIRTIO_9P(vdev); + V9fsConf *fsconf = &(s->fsconf); + if (virtio_9p_common_init(qdev, fsconf, &s) == NULL) { + return -1; + } + return 0; +} + +static Property virtio_9p_properties[] = { + DEFINE_VIRTIO_9P_PROPERTIES(V9fsState, fsconf), + DEFINE_PROP_END_OF_LIST(), +}; + +static void virtio_9p_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass); + dc->props = virtio_9p_properties; + vdc->init = virtio_9p_device_init; + vdc->get_features = virtio_9p_get_features; + vdc->get_config = virtio_9p_get_config; +} + +static const TypeInfo virtio_device_info = { + .name = TYPE_VIRTIO_9P, + .parent = TYPE_VIRTIO_DEVICE, + .instance_size = sizeof(V9fsState), + .class_init = virtio_9p_class_init, +}; + +static void virtio_9p_register_types(void) +{ + type_register_static(&virtio_device_info); +} + +type_init(virtio_9p_register_types) diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h index 95a8ec3..1389271 100644 --- a/hw/9pfs/virtio-9p.h +++ b/hw/9pfs/virtio-9p.h @@ -225,6 +225,7 @@ typedef struct V9fsState CoRwlock rename_lock; int32_t root_fid; Error *migration_blocker; + V9fsConf fsconf; } V9fsState; typedef struct V9fsStatState { @@ -401,4 +402,12 @@ extern int v9fs_name_to_path(V9fsState *s, V9fsPath *dirpath, #define pdu_unmarshal(pdu, offset, fmt, args...) \ v9fs_unmarshal(pdu->elem.out_sg, pdu->elem.out_num, offset, 1, fmt, ##args) +#define TYPE_VIRTIO_9P "virtio-9p" +#define VIRTIO_9P(obj) \ + OBJECT_CHECK(V9fsState, (obj), TYPE_VIRTIO_9P) + +#define DEFINE_VIRTIO_9P_PROPERTIES(_state, _field) \ + DEFINE_PROP_STRING("mount_tag", _state, _field.tag), \ + DEFINE_PROP_STRING("fsdev", _state, _field.fsdev_id) + #endif diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index e2d1693..d000d1b 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -1040,8 +1040,7 @@ static Property virtio_9p_properties[] = { DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true), DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2), DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features), - DEFINE_PROP_STRING("mount_tag", VirtIOPCIProxy, fsconf.tag), - DEFINE_PROP_STRING("fsdev", VirtIOPCIProxy, fsconf.fsdev_id), + DEFINE_VIRTIO_9P_PROPERTIES(VirtIOPCIProxy, fsconf), DEFINE_PROP_END_OF_LIST(), };