From patchwork Thu Mar 20 14:06:32 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 332183 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 0BE442C009E for ; Fri, 21 Mar 2014 01:14:21 +1100 (EST) Received: from localhost ([::1]:47271 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WQdje-0003E1-LW for incoming@patchwork.ozlabs.org; Thu, 20 Mar 2014 10:14:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38134) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WQdiK-00026m-BT for qemu-devel@nongnu.org; Thu, 20 Mar 2014 10:13:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WQdiE-00008L-B7 for qemu-devel@nongnu.org; Thu, 20 Mar 2014 10:12:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:18481) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WQdiE-00008A-2S for qemu-devel@nongnu.org; Thu, 20 Mar 2014 10:12:50 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s2KECgOv023397 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 20 Mar 2014 10:12:47 -0400 Received: from localhost (ovpn-112-26.ams2.redhat.com [10.36.112.26]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s2KE6enp004366; Thu, 20 Mar 2014 10:06:41 -0400 From: Stefan Hajnoczi To: Date: Thu, 20 Mar 2014 15:06:32 +0100 Message-Id: <1395324392-2142-3-git-send-email-stefanha@redhat.com> In-Reply-To: <1395324392-2142-1-git-send-email-stefanha@redhat.com> References: <1395324392-2142-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Kevin Wolf , Paolo Bonzini , Stefan Hajnoczi , Christian Borntraeger Subject: [Qemu-devel] [PATCH for-2.0 2/2] dataplane: replace iothread object_add() with embedded instance 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 Before IOThread was its own object, each virtio-blk device would create its own internal thread. We need to preserve this behavior for backwards compatibility when users do not specify -device virtio-blk-pci,iothread=. This patch changes how the internal IOThread object is created. Previously we used the monitor object_add() function, which is really a layering violation. The problem is that this needs to assign a name but we don't have a name for this internal object. Generating names for internal objects is a pain but even worse is that they may collide with user-defined names. Paolo Bonzini suggested that the internal IOThread object should not be named. This way the conflict cannot happen and we no longer need object_add(). One gotcha is that internal IOThread objects will not be listed by the query-iothreads command since they are not named. This is okay though because query-iothreads is new and the internal IOThread is just for backwards compatibility. New users should explicitly define IOThread objects. Reported-by: Christian Borntraeger Signed-off-by: Stefan Hajnoczi --- hw/block/dataplane/virtio-blk.c | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-blk.c index f558b45..70b8a5a 100644 --- a/hw/block/dataplane/virtio-blk.c +++ b/hw/block/dataplane/virtio-blk.c @@ -23,7 +23,7 @@ #include "virtio-blk.h" #include "block/aio.h" #include "hw/virtio/virtio-bus.h" -#include "monitor/monitor.h" /* for object_add() */ +#include "qom/object_interfaces.h" enum { SEG_MAX = 126, /* maximum number of I/O segments */ @@ -59,7 +59,7 @@ struct VirtIOBlockDataPlane { * use it). */ IOThread *iothread; - bool internal_iothread; + IOThread internal_iothread_obj; AioContext *ctx; EventNotifier io_notifier; /* Linux AIO completion */ EventNotifier host_notifier; /* doorbell */ @@ -391,23 +391,19 @@ void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *blk, s->blk = blk; if (blk->iothread) { - s->internal_iothread = false; s->iothread = blk->iothread; + object_ref(OBJECT(s->iothread)); } else { - /* Create per-device IOThread if none specified */ - Error *local_err = NULL; - - s->internal_iothread = true; - object_add(TYPE_IOTHREAD, vdev->name, NULL, NULL, &local_err); - if (error_is_set(&local_err)) { - error_propagate(errp, local_err); - g_free(s); - return; - } - s->iothread = iothread_find(vdev->name); - assert(s->iothread); + /* Create per-device IOThread if none specified. This is for + * x-data-plane option compatibility. If x-data-plane is removed we + * can drop this. + */ + object_initialize(&s->internal_iothread_obj, + sizeof(s->internal_iothread_obj), + TYPE_IOTHREAD); + user_creatable_complete(OBJECT(&s->internal_iothread_obj), &error_abort); + s->iothread = &s->internal_iothread_obj; } - object_ref(OBJECT(s->iothread)); s->ctx = iothread_get_aio_context(s->iothread); /* Prevent block operations that conflict with data plane thread */ @@ -426,9 +422,6 @@ void virtio_blk_data_plane_destroy(VirtIOBlockDataPlane *s) virtio_blk_data_plane_stop(s); bdrv_set_in_use(s->blk->conf.bs, 0); object_unref(OBJECT(s->iothread)); - if (s->internal_iothread) { - object_unparent(OBJECT(s->iothread)); - } g_free(s); }