From nobody Wed Apr 16 03:53:26 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1583930548; cv=none; d=zohomail.com; s=zohoarc; b=CETnyluCiLnKTfem/TVa2VWWAl5ZMBLBAOcEIsAvgmXJK8eLvAk79y8Ub69dEzL1z7Hb9vkEBt9mOKflBMeIeLdd/Ofhk3dk7l2XwlNeaLL4JvwqRM3OveRyJbZl0iZYufIGcDE8JwKRfaNdQwQ/W5HSNWoeCn49uxxsaIdh8mE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583930548; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ZaawQ9CCgw9+6/uP2kS2YGY8JFyJ+jcvITPBVKrP3F4=; b=e1hS1WPLi0TaEbGNlFIXg+KfOgwis4mBOgXWVIR655XN1KM+1SlXvBiCKR/nhcZNDQdYvNkDB4mo7PboiFdCCHpxaNMwlldaL/26h1VZAuJjvXfWQ5hieoUIVq8dwJFj5maSHPJTsijuLdJE0jiXbt1fI9WueMWvDVCBLNkVm3g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1583930548413180.99152086458923; Wed, 11 Mar 2020 05:42:28 -0700 (PDT) Received: from localhost ([::1]:51138 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jC0gs-0000H5-Bg for importer@patchew.org; Wed, 11 Mar 2020 08:42:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46984) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jC0fs-0006yP-FG for qemu-devel@nongnu.org; Wed, 11 Mar 2020 08:41:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jC0fq-0000It-6Z for qemu-devel@nongnu.org; Wed, 11 Mar 2020 08:41:23 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:46452 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jC0fq-0000Ih-3c for qemu-devel@nongnu.org; Wed, 11 Mar 2020 08:41:22 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-167-DNLYj92pMkOEAp924vfxXw-1; Wed, 11 Mar 2020 08:41:18 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2E660100550E; Wed, 11 Mar 2020 12:41:16 +0000 (UTC) Received: from localhost (unknown [10.36.118.127]) by smtp.corp.redhat.com (Postfix) with ESMTP id B6A4D10013A1; Wed, 11 Mar 2020 12:41:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583930481; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZaawQ9CCgw9+6/uP2kS2YGY8JFyJ+jcvITPBVKrP3F4=; b=gtqXph4IwPmRBSjwm8l75JcsYhF22hJa94F8mFJGlwL9uSCDk+9DZ7LP9ihrWIvGGqeGpP O6NHNg8/pg6YP1IPUKxsiMwkHtq3O4CngqjKn7ggnhuLR7H/yWVL/K+qDTNzIytUnOFhSE E/Gzlb7NNSIcHMMA4ZKkeQKNgKpo+OA= X-MC-Unique: DNLYj92pMkOEAp924vfxXw-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PULL 6/9] aio-posix: simplify FDMonOps->update() prototype Date: Wed, 11 Mar 2020 12:40:42 +0000 Message-Id: <20200311124045.277969-7-stefanha@redhat.com> In-Reply-To: <20200311124045.277969-1-stefanha@redhat.com> References: <20200311124045.277969-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Peter Maydell , qemu-block@nongnu.org, Max Reitz , Stefan Hajnoczi , Paolo Bonzini , Kevin Wolf Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The AioHandler *node, bool is_new arguments are more complicated to think about than simply being given AioHandler *old_node, AioHandler *new_node. Furthermore, the new Linux io_uring file descriptor monitoring mechanism added by the new patch requires access to both the old and the new nodes. Make this change now in preparation. Signed-off-by: Stefan Hajnoczi Link: https://lore.kernel.org/r/20200305170806.1313245-5-stefanha@redhat.com Message-Id: <20200305170806.1313245-5-stefanha@redhat.com> --- include/block/aio.h | 13 ++++++------- util/aio-posix.c | 7 +------ util/fdmon-epoll.c | 21 ++++++++++++--------- util/fdmon-poll.c | 4 +++- 4 files changed, 22 insertions(+), 23 deletions(-) diff --git a/include/block/aio.h b/include/block/aio.h index 90e07d7507..bd76b08f1a 100644 --- a/include/block/aio.h +++ b/include/block/aio.h @@ -57,17 +57,16 @@ typedef struct { /* * update: * @ctx: the AioContext - * @node: the handler - * @is_new: is the file descriptor already being monitored? + * @old_node: the existing handler or NULL if this file descriptor is = being + * monitored for the first time + * @new_node: the new handler or NULL if this file descriptor is being + * removed * - * Add/remove/modify a monitored file descriptor. There are three cas= es: - * 1. node->pfd.events =3D=3D 0 means remove the file descriptor. - * 2. !is_new means modify an already monitored file descriptor. - * 3. is_new means add a new file descriptor. + * Add/remove/modify a monitored file descriptor. * * Called with ctx->list_lock acquired. */ - void (*update)(AioContext *ctx, AioHandler *node, bool is_new); + void (*update)(AioContext *ctx, AioHandler *old_node, AioHandler *new_= node); =20 /* * wait: diff --git a/util/aio-posix.c b/util/aio-posix.c index bc0b86547c..028b2abded 100644 --- a/util/aio-posix.c +++ b/util/aio-posix.c @@ -139,12 +139,7 @@ void aio_set_fd_handler(AioContext *ctx, atomic_set(&ctx->poll_disable_cnt, atomic_read(&ctx->poll_disable_cnt) + poll_disable_change); =20 - if (new_node) { - ctx->fdmon_ops->update(ctx, new_node, is_new); - } else if (node) { - /* Unregister deleted fd_handler */ - ctx->fdmon_ops->update(ctx, node, false); - } + ctx->fdmon_ops->update(ctx, node, new_node); qemu_lockcnt_unlock(&ctx->list_lock); aio_notify(ctx); =20 diff --git a/util/fdmon-epoll.c b/util/fdmon-epoll.c index 29c1454469..d56b69468b 100644 --- a/util/fdmon-epoll.c +++ b/util/fdmon-epoll.c @@ -30,21 +30,24 @@ static inline int epoll_events_from_pfd(int pfd_events) (pfd_events & G_IO_ERR ? EPOLLERR : 0); } =20 -static void fdmon_epoll_update(AioContext *ctx, AioHandler *node, bool is_= new) +static void fdmon_epoll_update(AioContext *ctx, + AioHandler *old_node, + AioHandler *new_node) { - struct epoll_event event; + struct epoll_event event =3D { + .data.ptr =3D new_node, + .events =3D new_node ? epoll_events_from_pfd(new_node->pfd.events)= : 0, + }; int r; - int ctl; =20 - if (!node->pfd.events) { - ctl =3D EPOLL_CTL_DEL; + if (!new_node) { + r =3D epoll_ctl(ctx->epollfd, EPOLL_CTL_DEL, old_node->pfd.fd, &ev= ent); + } else if (!old_node) { + r =3D epoll_ctl(ctx->epollfd, EPOLL_CTL_ADD, new_node->pfd.fd, &ev= ent); } else { - event.data.ptr =3D node; - event.events =3D epoll_events_from_pfd(node->pfd.events); - ctl =3D is_new ? EPOLL_CTL_ADD : EPOLL_CTL_MOD; + r =3D epoll_ctl(ctx->epollfd, EPOLL_CTL_MOD, new_node->pfd.fd, &ev= ent); } =20 - r =3D epoll_ctl(ctx->epollfd, ctl, node->pfd.fd, &event); if (r) { fdmon_epoll_disable(ctx); } diff --git a/util/fdmon-poll.c b/util/fdmon-poll.c index 67992116b8..28114a0f39 100644 --- a/util/fdmon-poll.c +++ b/util/fdmon-poll.c @@ -93,7 +93,9 @@ static int fdmon_poll_wait(AioContext *ctx, AioHandlerLis= t *ready_list, return ret; } =20 -static void fdmon_poll_update(AioContext *ctx, AioHandler *node, bool is_n= ew) +static void fdmon_poll_update(AioContext *ctx, + AioHandler *old_node, + AioHandler *new_node) { /* Do nothing, AioHandler already contains the state we'll need */ } --=20 2.24.1