From patchwork Mon Dec 9 20:48:23 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 299221 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id D58E42C00A2 for ; Tue, 10 Dec 2013 09:24:06 +1100 (EST) Received: from localhost ([::1]:45878 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vq7tx-0003SJ-Qo for incoming@patchwork.ozlabs.org; Mon, 09 Dec 2013 15:58:01 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51464) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vq7lx-0006Sr-8Y for qemu-devel@nongnu.org; Mon, 09 Dec 2013 15:49:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vq7lr-0003tX-Ml for qemu-devel@nongnu.org; Mon, 09 Dec 2013 15:49:45 -0500 Received: from mail-ee0-x234.google.com ([2a00:1450:4013:c00::234]:38546) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vq7lr-0003tL-G9 for qemu-devel@nongnu.org; Mon, 09 Dec 2013 15:49:39 -0500 Received: by mail-ee0-f52.google.com with SMTP id d17so1799014eek.25 for ; Mon, 09 Dec 2013 12:49:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=B2UDILTAUR3BE/SZPpZ50M33ExRL/yQNiovI352Reuw=; b=wBh9UsPBjWVtys2XM7yKV0diMYxefwAhN6MgOcsVZEUb1+AsdAUczn8yoprkNegIJv DB/9Lj1HF2P29v3SJoyQUrBS32HPZLCb2DTIXH3fDdKUcshfJXvEOieq2SJecOJRYKCI 8w0oUmOB3ivrCcgJHBDPwFCygihgV/wJiGVhVI7ZEUIT1WX6s4ir0H30zHux38gjDDO0 mpUrKZPdv4ref4dzQRgAZ/B/zxnfXYc/frqOouf44pO+lrYdM9Kc76NbzS8+BvWQpwym UUlsH5+Io7eR02uHaDWP5pPiur/wqC+OGscnGpB3v89w3mKtvwuSssIQseZPxO8/YMFg qKKg== X-Received: by 10.14.193.132 with SMTP id k4mr32475358een.55.1386622178640; Mon, 09 Dec 2013 12:49:38 -0800 (PST) Received: from yakj.lan (net-2-35-202-54.cust.dsl.vodafone.it. [2.35.202.54]) by mx.google.com with ESMTPSA id a45sm33003002eem.6.2013.12.09.12.49.36 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Dec 2013 12:49:37 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 9 Dec 2013 21:48:23 +0100 Message-Id: <1386622112-27257-22-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.4.2 In-Reply-To: <1386622112-27257-1-git-send-email-pbonzini@redhat.com> References: <1386622112-27257-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4013:c00::234 Cc: cornelia.huck@de.ibm.com, afaerber@suse.de, mst@redhat.com Subject: [Qemu-devel] [PULL 21/30] virtio: Start converting VirtioDevice to QOM realize 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: Andreas Färber Temporarily allow either VirtioDeviceClass::init or VirtioDeviceClass::realize. Introduce VirtioDeviceClass::unrealize for symmetry. Signed-off-by: Andreas Färber Signed-off-by: Paolo Bonzini --- hw/virtio/virtio.c | 42 +++++++++++++++++++++++++++--------------- include/hw/virtio/virtio.h | 4 +++- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 965b2c0..4070b37 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -1150,40 +1150,52 @@ void virtio_device_set_child_bus_name(VirtIODevice *vdev, char *bus_name) } } -static int virtio_device_init(DeviceState *qdev) -{ - VirtIODevice *vdev = VIRTIO_DEVICE(qdev); - VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(qdev); - assert(k->init != NULL); - if (k->init(vdev) < 0) { - return -1; +static void virtio_device_realize(DeviceState *dev, Error **errp) +{ + VirtIODevice *vdev = VIRTIO_DEVICE(dev); + VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(dev); + Error *err = NULL; + + assert(vdc->init != NULL || vdc->realize != NULL); + if (vdc->realize != NULL) { + vdc->realize(dev, &err); + if (err != NULL) { + error_propagate(errp, err); + return; + } + } else { + if (vdc->init(vdev) < 0) { + error_setg(errp, "Device initialization failed."); + return; + } } virtio_bus_device_plugged(vdev); - return 0; } -static int virtio_device_exit(DeviceState *qdev) +static void virtio_device_unrealize(DeviceState *dev, Error **errp) { - VirtIODevice *vdev = VIRTIO_DEVICE(qdev); - VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(qdev); + VirtIODevice *vdev = VIRTIO_DEVICE(dev); + VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(dev); virtio_bus_device_unplugged(vdev); - if (k->exit) { + + if (k->exit != NULL) { k->exit(vdev); } + if (vdev->bus_name) { g_free(vdev->bus_name); vdev->bus_name = NULL; } - return 0; } static void virtio_device_class_init(ObjectClass *klass, void *data) { /* Set the default value here. */ DeviceClass *dc = DEVICE_CLASS(klass); - dc->init = virtio_device_init; - dc->exit = virtio_device_exit; + + dc->realize = virtio_device_realize; + dc->unrealize = virtio_device_unrealize; dc->bus_type = TYPE_VIRTIO_BUS; } diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 59756c2..54c5efe 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -124,10 +124,12 @@ struct VirtIODevice }; typedef struct VirtioDeviceClass { - /* This is what a VirtioDevice must implement */ DeviceClass parent; + + /* This is what a VirtioDevice must implement */ int (*init)(VirtIODevice *vdev); void (*exit)(VirtIODevice *vdev); + DeviceRealize realize; uint32_t (*get_features)(VirtIODevice *vdev, uint32_t requested_features); uint32_t (*bad_features)(VirtIODevice *vdev); void (*set_features)(VirtIODevice *vdev, uint32_t val);