From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49872) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XFo9N-0003j4-Q2 for qemu-devel@nongnu.org; Fri, 08 Aug 2014 13:40:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XFo9F-0006Vn-Vr for qemu-devel@nongnu.org; Fri, 08 Aug 2014 13:40:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:62044) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XFo9F-0006VU-MF for qemu-devel@nongnu.org; Fri, 08 Aug 2014 13:40:13 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s78HeD0i005720 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 8 Aug 2014 13:40:13 -0400 From: Kevin Wolf Date: Fri, 8 Aug 2014 19:39:04 +0200 Message-Id: <1407519603-6635-4-git-send-email-kwolf@redhat.com> In-Reply-To: <1407519603-6635-1-git-send-email-kwolf@redhat.com> References: <1407519603-6635-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PULL 03/62] nbd: Follow the BDS' AIO context List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com From: Max Reitz Keep the NBD server always in the same AIO context as the exported BDS by calling bdrv_add_aio_context_notifier() and implementing the required callbacks. Signed-off-by: Max Reitz Reviewed-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- nbd.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/nbd.c b/nbd.c index 210b6d5..770c3d3 100644 --- a/nbd.c +++ b/nbd.c @@ -929,6 +929,34 @@ static void nbd_request_put(NBDRequest *req) nbd_client_put(client); } +static void bs_aio_attached(AioContext *ctx, void *opaque) +{ + NBDExport *exp = opaque; + NBDClient *client; + + TRACE("Export %s: Attaching clients to AIO context %p\n", exp->name, ctx); + + exp->ctx = ctx; + + QTAILQ_FOREACH(client, &exp->clients, next) { + nbd_set_handlers(client); + } +} + +static void bs_aio_detach(void *opaque) +{ + NBDExport *exp = opaque; + NBDClient *client; + + TRACE("Export %s: Detaching clients from AIO context %p\n", exp->name, exp->ctx); + + QTAILQ_FOREACH(client, &exp->clients, next) { + nbd_unset_handlers(client); + } + + exp->ctx = NULL; +} + NBDExport *nbd_export_new(BlockDriverState *bs, off_t dev_offset, off_t size, uint32_t nbdflags, void (*close)(NBDExport *)) @@ -943,6 +971,7 @@ NBDExport *nbd_export_new(BlockDriverState *bs, off_t dev_offset, exp->close = close; exp->ctx = bdrv_get_aio_context(bs); bdrv_ref(bs); + bdrv_add_aio_context_notifier(bs, bs_aio_attached, bs_aio_detach, exp); return exp; } @@ -990,6 +1019,8 @@ void nbd_export_close(NBDExport *exp) nbd_export_set_name(exp, NULL); nbd_export_put(exp); if (exp->bs) { + bdrv_remove_aio_context_notifier(exp->bs, bs_aio_attached, + bs_aio_detach, exp); bdrv_unref(exp->bs); exp->bs = NULL; } -- 1.8.3.1