From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47192) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V4iSm-0003Pr-09 for qemu-devel@nongnu.org; Wed, 31 Jul 2013 22:18:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V4iSf-0006Ho-IW for qemu-devel@nongnu.org; Wed, 31 Jul 2013 22:17:59 -0400 Received: from cantor2.suse.de ([195.135.220.15]:60976 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V4iSf-0006HL-76 for qemu-devel@nongnu.org; Wed, 31 Jul 2013 22:17:53 -0400 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Thu, 1 Aug 2013 04:17:28 +0200 Message-Id: <1375323463-32747-8-git-send-email-afaerber@suse.de> In-Reply-To: <1375323463-32747-1-git-send-email-afaerber@suse.de> References: <1375323463-32747-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH for-next v2 07/22] virtio-9p: Convert to QOM realize List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Anthony Liguori , =?UTF-8?q?Andreas=20F=C3=A4rber?= , "Aneesh Kumar K.V" Signed-off-by: Andreas F=C3=A4rber --- hw/9pfs/virtio-9p-device.c | 44 +++++++++++++++++++++++-----------------= ---- hw/9pfs/virtio-9p.h | 2 ++ 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c index ea21655..7d2990b 100644 --- a/hw/9pfs/virtio-9p-device.c +++ b/hw/9pfs/virtio-9p-device.c @@ -41,9 +41,11 @@ static void virtio_9p_get_config(VirtIODevice *vdev, u= int8_t *config) g_free(cfg); } =20 -static int virtio_9p_device_init(VirtIODevice *vdev) +static void virtio_9p_device_realize(DeviceState *dev, Error **errp) { - V9fsState *s =3D VIRTIO_9P(vdev); + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + V9fsState *s =3D VIRTIO_9P(dev); + DeviceClass *parent_dc =3D DEVICE_CLASS(VIRTIO_9P_GET_PARENT_CLASS(d= ev)); int i, len; struct stat stat; FsDriverEntry *fse; @@ -67,16 +69,16 @@ static int virtio_9p_device_init(VirtIODevice *vdev) =20 if (!fse) { /* We don't have a fsdev identified by fsdev_id */ - fprintf(stderr, "Virtio-9p device couldn't find fsdev with the " - "id =3D %s\n", - s->fsconf.fsdev_id ? s->fsconf.fsdev_id : "NULL"); + error_setg(errp, "Virtio-9p device couldn't find fsdev with the = " + "id =3D %s", + s->fsconf.fsdev_id ? s->fsconf.fsdev_id : "NULL"); goto out; } =20 if (!s->fsconf.tag) { /* we haven't specified a mount_tag */ - fprintf(stderr, "fsdev with id %s needs mount_tag arguments\n", - s->fsconf.fsdev_id); + error_setg(errp, "fsdev with id %s needs mount_tag arguments", + s->fsconf.fsdev_id); goto out; } =20 @@ -85,8 +87,8 @@ static int virtio_9p_device_init(VirtIODevice *vdev) s->ctx.exops.get_st_gen =3D NULL; len =3D strlen(s->fsconf.tag); if (len > MAX_TAG_LEN - 1) { - fprintf(stderr, "mount tag '%s' (%d bytes) is longer than " - "maximum (%d bytes)", s->fsconf.tag, len, MAX_TAG_LEN - = 1); + error_setg(errp, "mount tag '%s' (%d bytes) is longer than " + "maximum (%d bytes)", s->fsconf.tag, len, MAX_TAG_LEN= - 1); goto out; } =20 @@ -99,12 +101,12 @@ static int virtio_9p_device_init(VirtIODevice *vdev) qemu_co_rwlock_init(&s->rename_lock); =20 if (s->ops->init(&s->ctx) < 0) { - fprintf(stderr, "Virtio-9p Failed to initialize fs-driver with i= d:%s" - " and export path:%s\n", s->fsconf.fsdev_id, s->ctx.fs_r= oot); + error_setg(errp, "Virtio-9p Failed to initialize fs-driver with = id:%s" + " and export path:%s", s->fsconf.fsdev_id, s->ctx.fs_= root); goto out; } if (v9fs_init_worker_threads() < 0) { - fprintf(stderr, "worker thread initialization failed\n"); + error_setg(errp, "worker thread initialization failed"); goto out; } =20 @@ -114,28 +116,27 @@ static int virtio_9p_device_init(VirtIODevice *vdev= ) * use co-routines here. */ if (s->ops->name_to_path(&s->ctx, NULL, "/", &path) < 0) { - fprintf(stderr, - "error in converting name to path %s", strerror(errno)); + error_setg(errp, + "error in converting name to path %s", strerror(errno= )); goto out; } if (s->ops->lstat(&s->ctx, &path, &stat)) { - fprintf(stderr, "share path %s does not exist\n", fse->path); + error_setg(errp, "share path %s does not exist", fse->path); goto out; } else if (!S_ISDIR(stat.st_mode)) { - fprintf(stderr, "share path %s is not a directory\n", fse->path)= ; + error_setg(errp, "share path %s is not a directory", fse->path); goto out; } v9fs_path_free(&path); =20 - return 0; + parent_dc->realize(dev, errp); + + return; out: g_free(s->ctx.fs_root); g_free(s->tag); virtio_cleanup(vdev); v9fs_path_free(&path); - - return -1; - } =20 /* virtio-9p device */ @@ -149,9 +150,10 @@ static void virtio_9p_class_init(ObjectClass *klass,= void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_CLASS(klass); + + dc->realize =3D virtio_9p_device_realize; dc->props =3D virtio_9p_properties; set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); - vdc->init =3D virtio_9p_device_init; vdc->get_features =3D virtio_9p_get_features; vdc->get_config =3D virtio_9p_get_config; } diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h index 1d6eedb..51df6c8 100644 --- a/hw/9pfs/virtio-9p.h +++ b/hw/9pfs/virtio-9p.h @@ -404,6 +404,8 @@ extern int v9fs_name_to_path(V9fsState *s, V9fsPath *= dirpath, #define TYPE_VIRTIO_9P "virtio-9p-device" #define VIRTIO_9P(obj) \ OBJECT_CHECK(V9fsState, (obj), TYPE_VIRTIO_9P) +#define VIRTIO_9P_GET_PARENT_CLASS(obj) \ + OBJECT_GET_PARENT_CLASS(obj, TYPE_VIRTIO_9P) =20 #define DEFINE_VIRTIO_9P_PROPERTIES(_state, _field) \ DEFINE_PROP_STRING("mount_tag", _state, _field.tag), \ --=20 1.8.1.4