From nobody Sun Feb 8 16:24:04 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1573753508; cv=none; d=zoho.com; s=zohoarc; b=Gp7WFx2bsb/M6vBK2mCs4PJanyAxqVbjC8ivqhT8+Hhe6eoOju69OJVgefg3sEsH7oQhTvpzK5WDkhkbvnjgsg9g4aECU/vZSSs1+1W6VoHqAG2CatZCxukrscmumUtvVYj3QVCSvpdrF/BOt2Y4ozJQ9GZxd+B1+u+g9XxkHBs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573753508; 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=VPp9Fs1GHVc6YonRtiEMqzibnoSjpnGM/pE/ntl0lWg=; b=MSI/zaSTzEScGjEkLnfI8QOtOiDe6uGnuB5ELlaL8MGXMbeSlebEiEe7XOJnL3xouBfdTWD/+1B27QZNDzj3QEJlWDwWbHUcjXlCpP6gXWOnt5zHig50BzbngFKXeFqplzL6eZctxEPWfy5U/3TTmeDkAVgCHTRrU7z6EeV0KAc= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1573753508016611.6000150154241; Thu, 14 Nov 2019 09:45:08 -0800 (PST) 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-327-bOWfbukfPm6jcaHwtfkM_g-1; Thu, 14 Nov 2019 12:45:03 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CFA2E100F2E1; Thu, 14 Nov 2019 17:44:57 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7E17C5F762; Thu, 14 Nov 2019 17:44:57 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 349D31832D6C; Thu, 14 Nov 2019 17:44:57 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xAEHisaR002267 for ; Thu, 14 Nov 2019 12:44:54 -0500 Received: by smtp.corp.redhat.com (Postfix) id 755BD2157F34; Thu, 14 Nov 2019 17:44:54 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7071E2157F36 for ; Thu, 14 Nov 2019 17:44:52 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 33C6680CDCF for ; Thu, 14 Nov 2019 17:44:52 +0000 (UTC) Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-229-q1Do_EwEP6O0Wxn8tbQb2w-1; Thu, 14 Nov 2019 12:44:50 -0500 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id xAEHYpRq038441 for ; Thu, 14 Nov 2019 12:44:49 -0500 Received: from e06smtp02.uk.ibm.com (e06smtp02.uk.ibm.com [195.75.94.98]) by mx0a-001b2d01.pphosted.com with ESMTP id 2w9a3jc153-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Nov 2019 12:44:48 -0500 Received: from localhost by e06smtp02.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 14 Nov 2019 17:44:46 -0000 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp02.uk.ibm.com (192.168.101.132) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Thu, 14 Nov 2019 17:44:43 -0000 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id xAEHigKu57802834 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 14 Nov 2019 17:44:42 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A9F2EAE053; Thu, 14 Nov 2019 17:44:42 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 73A29AE051; Thu, 14 Nov 2019 17:44:42 +0000 (GMT) Received: from marcibm.boeblingen.de.ibm.com (unknown [9.152.224.228]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 14 Nov 2019 17:44:42 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573753506; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=VPp9Fs1GHVc6YonRtiEMqzibnoSjpnGM/pE/ntl0lWg=; b=V7emqSK4ihTWLipGQT8Q+fb6YQxQIYV4B0+rgpW2L2+xoRt7WvcCIWx+MFvPdESkxv+uBK q5U0rLxTq+pXDIjSUaGdMoZWYfgG54UQ2QyMnxSc4XIzXXI1njd6KNIYRp1AbWRP3k/J2o cwIOJRVkH/NcPjtqo4Af9auxHjc9SII= From: Marc Hartmayer To: Date: Thu, 14 Nov 2019 18:44:25 +0100 In-Reply-To: <20191114174425.13583-1-mhartmay@linux.ibm.com> References: <20191114174425.13583-1-mhartmay@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 19111417-0008-0000-0000-0000032F0E7E X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19111417-0009-0000-0000-00004A4E1E58 Message-Id: <20191114174425.13583-8-mhartmay@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-11-14_05:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1910280000 definitions=main-1911140152 X-MC-Unique: q1Do_EwEP6O0Wxn8tbQb2w-1 X-MC-Unique: bOWfbukfPm6jcaHwtfkM_g-1 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id xAEHisaR002267 X-loop: libvir-list@redhat.com Cc: Peter Krempa , Pavel Hrdina Subject: [libvirt] [PATCH v4 7/7] remote/rpc: Use virNetServerGetProgram() to determine the program X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Use virNetServerGetProgram() to determine the virNetServerProgram instead of using hard coded global variables. This allows us to remove the global variables @remoteProgram and @qemuProgram as they're now no longer necessary. Signed-off-by: Marc Hartmayer --- src/libvirt_remote.syms | 1 + src/remote/remote_daemon.c | 4 +- src/remote/remote_daemon.h | 2 - src/remote/remote_daemon_dispatch.c | 238 ++++++++++++++++++---------- src/rpc/gendispatch.pl | 6 + src/rpc/virnetserver.c | 22 +++ src/rpc/virnetserver.h | 2 + 7 files changed, 187 insertions(+), 88 deletions(-) diff --git a/src/libvirt_remote.syms b/src/libvirt_remote.syms index 0493467f4603..a6883f373608 100644 --- a/src/libvirt_remote.syms +++ b/src/libvirt_remote.syms @@ -124,6 +124,7 @@ virNetServerGetCurrentUnauthClients; virNetServerGetMaxClients; virNetServerGetMaxUnauthClients; virNetServerGetName; +virNetServerGetProgram; virNetServerGetThreadPoolParameters; virNetServerHasClients; virNetServerNeedsAuth; diff --git a/src/remote/remote_daemon.c b/src/remote/remote_daemon.c index b400b1dd1059..a36b5449d5ae 100644 --- a/src/remote/remote_daemon.c +++ b/src/remote/remote_daemon.c @@ -73,8 +73,6 @@ VIR_LOG_INIT("daemon." DAEMON_NAME); #if WITH_SASL virNetSASLContextPtr saslCtxt =3D NULL; #endif -virNetServerProgramPtr remoteProgram =3D NULL; -virNetServerProgramPtr qemuProgram =3D NULL; =20 volatile bool driversInitialized =3D false; =20 @@ -996,6 +994,8 @@ int main(int argc, char **argv) { virNetServerPtr srv =3D NULL; virNetServerPtr srvAdm =3D NULL; virNetServerProgramPtr adminProgram =3D NULL; + virNetServerProgramPtr qemuProgram =3D NULL; + virNetServerProgramPtr remoteProgram =3D NULL; virNetServerProgramPtr lxcProgram =3D NULL; char *remote_config_file =3D NULL; int statuswrite =3D -1; diff --git a/src/remote/remote_daemon.h b/src/remote/remote_daemon.h index a2d9af403619..a3d6a220f868 100644 --- a/src/remote/remote_daemon.h +++ b/src/remote/remote_daemon.h @@ -97,5 +97,3 @@ struct daemonClientPrivate { #if WITH_SASL extern virNetSASLContextPtr saslCtxt; #endif -extern virNetServerProgramPtr remoteProgram; -extern virNetServerProgramPtr qemuProgram; diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon= _dispatch.c index 6ece51c2889d..7ebb97f49f3b 100644 --- a/src/remote/remote_daemon_dispatch.c +++ b/src/remote/remote_daemon_dispatch.c @@ -4164,9 +4164,9 @@ remoteDispatchNodeDeviceGetParent(virNetServerPtr ser= ver G_GNUC_UNUSED, } =20 static int -remoteDispatchConnectRegisterCloseCallback(virNetServerPtr server G_GNUC_U= NUSED, +remoteDispatchConnectRegisterCloseCallback(virNetServerPtr server, virNetServerClientPtr client, - virNetMessagePtr msg G_GNUC_UNU= SED, + virNetMessagePtr msg, virNetMessageErrorPtr rerr) { int rv =3D -1; @@ -4174,30 +4174,37 @@ remoteDispatchConnectRegisterCloseCallback(virNetSe= rverPtr server G_GNUC_UNUSED, struct daemonClientPrivate *priv =3D virNetServerClientGetPrivateData(client); virConnectPtr conn =3D remoteGetHypervisorConn(client); + virNetServerProgramPtr program; + + if (!(program =3D virNetServerGetProgram(server, msg))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("no matching progra= m found")); + goto cleanup; + } =20 virMutexLock(&priv->lock); =20 if (!conn) - goto cleanup; + goto cleanup_unlock; =20 if (VIR_ALLOC(callback) < 0) - goto cleanup; + goto cleanup_unlock; =20 callback->client =3D virObjectRef(client); - callback->program =3D virObjectRef(remoteProgram); + callback->program =3D virObjectRef(program); /* eventID, callbackID, and legacy are not used */ callback->eventID =3D -1; callback->callbackID =3D -1; if (virConnectRegisterCloseCallback(conn, remoteRelayConnectionClosedEvent, callback, remoteEventCallbackFree)= < 0) - goto cleanup; + goto cleanup_unlock; =20 priv->closeRegistered =3D true; rv =3D 0; =20 - cleanup: + cleanup_unlock: virMutexUnlock(&priv->lock); + cleanup: if (rv < 0) { remoteEventCallbackFree(callback); virNetMessageSaveError(rerr); @@ -4236,9 +4243,9 @@ remoteDispatchConnectUnregisterCloseCallback(virNetSe= rverPtr server G_GNUC_UNUSE } =20 static int -remoteDispatchConnectDomainEventRegister(virNetServerPtr server G_GNUC_UNU= SED, +remoteDispatchConnectDomainEventRegister(virNetServerPtr server, virNetServerClientPtr client, - virNetMessagePtr msg G_GNUC_UNUSE= D, + virNetMessagePtr msg, virNetMessageErrorPtr rerr G_GNUC= _UNUSED, remote_connect_domain_event_regis= ter_ret *ret G_GNUC_UNUSED) { @@ -4249,11 +4256,17 @@ remoteDispatchConnectDomainEventRegister(virNetServ= erPtr server G_GNUC_UNUSED, struct daemonClientPrivate *priv =3D virNetServerClientGetPrivateData(client); virConnectPtr conn =3D remoteGetHypervisorConn(client); + virNetServerProgramPtr program; + + if (!(program =3D virNetServerGetProgram(server, msg))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("no matching progra= m found")); + goto cleanup; + } =20 virMutexLock(&priv->lock); =20 if (!conn) - goto cleanup; + goto cleanup_unlock; =20 /* If we call register first, we could append a complete callback * to our array, but on OOM append failure, we'd have to then hope @@ -4264,9 +4277,9 @@ remoteDispatchConnectDomainEventRegister(virNetServer= Ptr server G_GNUC_UNUSED, * between 'ref' and 'callback'. */ if (VIR_ALLOC(callback) < 0) - goto cleanup; + goto cleanup_unlock; callback->client =3D virObjectRef(client); - callback->program =3D virObjectRef(remoteProgram); + callback->program =3D virObjectRef(program); callback->eventID =3D VIR_DOMAIN_EVENT_ID_LIFECYCLE; callback->callbackID =3D -1; callback->legacy =3D true; @@ -4274,7 +4287,7 @@ remoteDispatchConnectDomainEventRegister(virNetServer= Ptr server G_GNUC_UNUSED, if (VIR_APPEND_ELEMENT(priv->domainEventCallbacks, priv->ndomainEventCallbacks, callback) < 0) - goto cleanup; + goto cleanup_unlock; =20 if ((callbackID =3D virConnectDomainEventRegisterAny(conn, NULL, @@ -4285,15 +4298,16 @@ remoteDispatchConnectDomainEventRegister(virNetServ= erPtr server G_GNUC_UNUSED, VIR_SHRINK_N(priv->domainEventCallbacks, priv->ndomainEventCallbacks, 1); callback =3D ref; - goto cleanup; + goto cleanup_unlock; } =20 ref->callbackID =3D callbackID; =20 rv =3D 0; =20 - cleanup: + cleanup_unlock: virMutexUnlock(&priv->lock); + cleanup: remoteEventCallbackFree(callback); if (rv < 0) virNetMessageSaveError(rerr); @@ -4457,9 +4471,9 @@ remoteDispatchDomainGetState(virNetServerPtr server G= _GNUC_UNUSED, * VIR_DRV_SUPPORTS_FEATURE(VIR_DRV_FEATURE_REMOTE_EVENT_CALLBACK), * and must not mix the two styles. */ static int -remoteDispatchConnectDomainEventRegisterAny(virNetServerPtr server G_GNUC_= UNUSED, +remoteDispatchConnectDomainEventRegisterAny(virNetServerPtr server, virNetServerClientPtr client, - virNetMessagePtr msg G_GNUC_UN= USED, + virNetMessagePtr msg, virNetMessageErrorPtr rerr G_G= NUC_UNUSED, remote_connect_domain_event_re= gister_any_args *args) { @@ -4470,11 +4484,17 @@ remoteDispatchConnectDomainEventRegisterAny(virNetS= erverPtr server G_GNUC_UNUSED struct daemonClientPrivate *priv =3D virNetServerClientGetPrivateData(client); virConnectPtr conn =3D remoteGetHypervisorConn(client); + virNetServerProgramPtr program; + + if (!(program =3D virNetServerGetProgram(server, msg))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("no matching progra= m found")); + goto cleanup; + } =20 virMutexLock(&priv->lock); =20 if (!conn) - goto cleanup; + goto cleanup_unlock; =20 /* We intentionally do not use VIR_DOMAIN_EVENT_ID_LAST here; any * new domain events added after this point should only use the @@ -4483,7 +4503,7 @@ remoteDispatchConnectDomainEventRegisterAny(virNetSer= verPtr server G_GNUC_UNUSED args->eventID < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unsupported event ID %d"= ), args->eventID); - goto cleanup; + goto cleanup_unlock; } =20 /* If we call register first, we could append a complete callback @@ -4493,9 +4513,9 @@ remoteDispatchConnectDomainEventRegisterAny(virNetSer= verPtr server G_GNUC_UNUSED * our callback; but since VIR_APPEND_ELEMENT clears 'callback' on * success, we use 'ref' to save a copy of the pointer. */ if (VIR_ALLOC(callback) < 0) - goto cleanup; + goto cleanup_unlock; callback->client =3D virObjectRef(client); - callback->program =3D virObjectRef(remoteProgram); + callback->program =3D virObjectRef(program); callback->eventID =3D args->eventID; callback->callbackID =3D -1; callback->legacy =3D true; @@ -4503,7 +4523,7 @@ remoteDispatchConnectDomainEventRegisterAny(virNetSer= verPtr server G_GNUC_UNUSED if (VIR_APPEND_ELEMENT(priv->domainEventCallbacks, priv->ndomainEventCallbacks, callback) < 0) - goto cleanup; + goto cleanup_unlock; =20 if ((callbackID =3D virConnectDomainEventRegisterAny(conn, NULL, @@ -4514,15 +4534,16 @@ remoteDispatchConnectDomainEventRegisterAny(virNetS= erverPtr server G_GNUC_UNUSED VIR_SHRINK_N(priv->domainEventCallbacks, priv->ndomainEventCallbacks, 1); callback =3D ref; - goto cleanup; + goto cleanup_unlock; } =20 ref->callbackID =3D callbackID; =20 rv =3D 0; =20 - cleanup: + cleanup_unlock: virMutexUnlock(&priv->lock); + cleanup: remoteEventCallbackFree(callback); if (rv < 0) virNetMessageSaveError(rerr); @@ -4531,9 +4552,9 @@ remoteDispatchConnectDomainEventRegisterAny(virNetSer= verPtr server G_GNUC_UNUSED =20 =20 static int -remoteDispatchConnectDomainEventCallbackRegisterAny(virNetServerPtr server= G_GNUC_UNUSED, +remoteDispatchConnectDomainEventCallbackRegisterAny(virNetServerPtr server, virNetServerClientPtr = client, - virNetMessagePtr msg G= _GNUC_UNUSED, + virNetMessagePtr msg, virNetMessageErrorPtr = rerr G_GNUC_UNUSED, remote_connect_domain_= event_callback_register_any_args *args, remote_connect_domain_= event_callback_register_any_ret *ret) @@ -4546,20 +4567,26 @@ remoteDispatchConnectDomainEventCallbackRegisterAny= (virNetServerPtr server G_GNU virNetServerClientGetPrivateData(client); virDomainPtr dom =3D NULL; virConnectPtr conn =3D remoteGetHypervisorConn(client); + virNetServerProgramPtr program; + + if (!(program =3D virNetServerGetProgram(server, msg))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("no matching progra= m found")); + goto cleanup; + } =20 virMutexLock(&priv->lock); =20 if (!conn) - goto cleanup; + goto cleanup_unlock; =20 if (args->dom && !(dom =3D get_nonnull_domain(conn, *args->dom))) - goto cleanup; + goto cleanup_unlock; =20 if (args->eventID >=3D VIR_DOMAIN_EVENT_ID_LAST || args->eventID < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unsupported event ID %d"= ), args->eventID); - goto cleanup; + goto cleanup_unlock; } =20 /* If we call register first, we could append a complete callback @@ -4569,16 +4596,16 @@ remoteDispatchConnectDomainEventCallbackRegisterAny= (virNetServerPtr server G_GNU * our callback; but since VIR_APPEND_ELEMENT clears 'callback' on * success, we use 'ref' to save a copy of the pointer. */ if (VIR_ALLOC(callback) < 0) - goto cleanup; + goto cleanup_unlock; callback->client =3D virObjectRef(client); - callback->program =3D virObjectRef(remoteProgram); + callback->program =3D virObjectRef(program); callback->eventID =3D args->eventID; callback->callbackID =3D -1; ref =3D callback; if (VIR_APPEND_ELEMENT(priv->domainEventCallbacks, priv->ndomainEventCallbacks, callback) < 0) - goto cleanup; + goto cleanup_unlock; =20 if ((callbackID =3D virConnectDomainEventRegisterAny(conn, dom, @@ -4589,7 +4616,7 @@ remoteDispatchConnectDomainEventCallbackRegisterAny(v= irNetServerPtr server G_GNU VIR_SHRINK_N(priv->domainEventCallbacks, priv->ndomainEventCallbacks, 1); callback =3D ref; - goto cleanup; + goto cleanup_unlock; } =20 ref->callbackID =3D callbackID; @@ -4597,8 +4624,9 @@ remoteDispatchConnectDomainEventCallbackRegisterAny(v= irNetServerPtr server G_GNU =20 rv =3D 0; =20 - cleanup: + cleanup_unlock: virMutexUnlock(&priv->lock); + cleanup: remoteEventCallbackFree(callback); if (rv < 0) virNetMessageSaveError(rerr); @@ -5641,7 +5669,7 @@ remoteDispatchDomainMigratePrepare3Params(virNetServe= rPtr server G_GNUC_UNUSED, } =20 static int -remoteDispatchDomainMigratePrepareTunnel3Params(virNetServerPtr server G_G= NUC_UNUSED, +remoteDispatchDomainMigratePrepareTunnel3Params(virNetServerPtr server, virNetServerClientPtr clie= nt, virNetMessagePtr msg, virNetMessageErrorPtr rerr, @@ -5656,6 +5684,7 @@ remoteDispatchDomainMigratePrepareTunnel3Params(virNe= tServerPtr server G_GNUC_UN virStreamPtr st =3D NULL; daemonClientStreamPtr stream =3D NULL; virConnectPtr conn =3D remoteGetHypervisorConn(client); + virNetServerProgramPtr program; =20 if (!conn) goto cleanup; @@ -5672,8 +5701,13 @@ remoteDispatchDomainMigratePrepareTunnel3Params(virN= etServerPtr server G_GNUC_UN 0, ¶ms, &nparams) < 0) goto cleanup; =20 + if (!(program =3D virNetServerGetProgram(server, msg))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("no matching progra= m found")); + goto cleanup; + } + if (!(st =3D virStreamNew(conn, VIR_STREAM_NONBLOCK)) || - !(stream =3D daemonCreateClientStream(client, st, remoteProgram, + !(stream =3D daemonCreateClientStream(client, st, program, &msg->header, false))) goto cleanup; =20 @@ -6014,9 +6048,9 @@ static int remoteDispatchDomainCreateWithFiles(virNet= ServerPtr server G_GNUC_UNU =20 =20 static int -remoteDispatchConnectNetworkEventRegisterAny(virNetServerPtr server G_GNUC= _UNUSED, +remoteDispatchConnectNetworkEventRegisterAny(virNetServerPtr server, virNetServerClientPtr client, - virNetMessagePtr msg G_GNUC_U= NUSED, + virNetMessagePtr msg, virNetMessageErrorPtr rerr G_= GNUC_UNUSED, remote_connect_network_event_= register_any_args *args, remote_connect_network_event_= register_any_ret *ret) @@ -6029,20 +6063,26 @@ remoteDispatchConnectNetworkEventRegisterAny(virNet= ServerPtr server G_GNUC_UNUSE struct daemonClientPrivate *priv =3D virNetServerClientGetPrivateData(client); virConnectPtr conn =3D remoteGetNetworkConn(client); + virNetServerProgramPtr program; + + if (!(program =3D virNetServerGetProgram(server, msg))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("no matching progra= m found")); + goto cleanup; + } =20 virMutexLock(&priv->lock); =20 if (!conn) - goto cleanup; + goto cleanup_unlock; =20 if (args->net && !(net =3D get_nonnull_network(conn, *args->net))) - goto cleanup; + goto cleanup_unlock; =20 if (args->eventID >=3D VIR_NETWORK_EVENT_ID_LAST || args->eventID < 0)= { virReportError(VIR_ERR_INTERNAL_ERROR, _("unsupported network event ID %d"), args->eventID= ); - goto cleanup; + goto cleanup_unlock; } =20 /* If we call register first, we could append a complete callback @@ -6052,16 +6092,16 @@ remoteDispatchConnectNetworkEventRegisterAny(virNet= ServerPtr server G_GNUC_UNUSE * our callback; but since VIR_APPEND_ELEMENT clears 'callback' on * success, we use 'ref' to save a copy of the pointer. */ if (VIR_ALLOC(callback) < 0) - goto cleanup; + goto cleanup_unlock; callback->client =3D virObjectRef(client); - callback->program =3D virObjectRef(remoteProgram); + callback->program =3D virObjectRef(program); callback->eventID =3D args->eventID; callback->callbackID =3D -1; ref =3D callback; if (VIR_APPEND_ELEMENT(priv->networkEventCallbacks, priv->nnetworkEventCallbacks, callback) < 0) - goto cleanup; + goto cleanup_unlock; =20 if ((callbackID =3D virConnectNetworkEventRegisterAny(conn, net, @@ -6072,7 +6112,7 @@ remoteDispatchConnectNetworkEventRegisterAny(virNetSe= rverPtr server G_GNUC_UNUSE VIR_SHRINK_N(priv->networkEventCallbacks, priv->nnetworkEventCallbacks, 1); callback =3D ref; - goto cleanup; + goto cleanup_unlock; } =20 ref->callbackID =3D callbackID; @@ -6080,8 +6120,9 @@ remoteDispatchConnectNetworkEventRegisterAny(virNetSe= rverPtr server G_GNUC_UNUSE =20 rv =3D 0; =20 - cleanup: + cleanup_unlock: virMutexUnlock(&priv->lock); + cleanup: remoteEventCallbackFree(callback); if (rv < 0) virNetMessageSaveError(rerr); @@ -6135,9 +6176,9 @@ remoteDispatchConnectNetworkEventDeregisterAny(virNet= ServerPtr server G_GNUC_UNU } =20 static int -remoteDispatchConnectStoragePoolEventRegisterAny(virNetServerPtr server G_= GNUC_UNUSED, +remoteDispatchConnectStoragePoolEventRegisterAny(virNetServerPtr server, virNetServerClientPtr cli= ent, - virNetMessagePtr msg G_GN= UC_UNUSED, + virNetMessagePtr msg, virNetMessageErrorPtr rer= r G_GNUC_UNUSED, remote_connect_storage_po= ol_event_register_any_args *args, remote_connect_storage_po= ol_event_register_any_ret *ret) @@ -6150,20 +6191,26 @@ remoteDispatchConnectStoragePoolEventRegisterAny(vi= rNetServerPtr server G_GNUC_U virNetServerClientGetPrivateData(client); virStoragePoolPtr pool =3D NULL; virConnectPtr conn =3D remoteGetStorageConn(client); + virNetServerProgramPtr program; + + if (!(program =3D virNetServerGetProgram(server, msg))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("no matching progra= m found")); + goto cleanup; + } =20 virMutexLock(&priv->lock); =20 if (!conn) - goto cleanup; + goto cleanup_unlock; =20 if (args->pool && !(pool =3D get_nonnull_storage_pool(conn, *args->pool))) - goto cleanup; + goto cleanup_unlock; =20 if (args->eventID >=3D VIR_STORAGE_POOL_EVENT_ID_LAST || args->eventID= < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unsupported storage pool event ID %d"), args->ev= entID); - goto cleanup; + goto cleanup_unlock; } =20 /* If we call register first, we could append a complete callback @@ -6173,16 +6220,16 @@ remoteDispatchConnectStoragePoolEventRegisterAny(vi= rNetServerPtr server G_GNUC_U * our callback; but since VIR_APPEND_ELEMENT clears 'callback' on * success, we use 'ref' to save a copy of the pointer. */ if (VIR_ALLOC(callback) < 0) - goto cleanup; + goto cleanup_unlock; callback->client =3D virObjectRef(client); - callback->program =3D virObjectRef(remoteProgram); + callback->program =3D virObjectRef(program); callback->eventID =3D args->eventID; callback->callbackID =3D -1; ref =3D callback; if (VIR_APPEND_ELEMENT(priv->storageEventCallbacks, priv->nstorageEventCallbacks, callback) < 0) - goto cleanup; + goto cleanup_unlock; =20 if ((callbackID =3D virConnectStoragePoolEventRegisterAny(conn, pool, @@ -6193,7 +6240,7 @@ remoteDispatchConnectStoragePoolEventRegisterAny(virN= etServerPtr server G_GNUC_U VIR_SHRINK_N(priv->storageEventCallbacks, priv->nstorageEventCallbacks, 1); callback =3D ref; - goto cleanup; + goto cleanup_unlock; } =20 ref->callbackID =3D callbackID; @@ -6201,8 +6248,9 @@ remoteDispatchConnectStoragePoolEventRegisterAny(virN= etServerPtr server G_GNUC_U =20 rv =3D 0; =20 - cleanup: + cleanup_unlock: virMutexUnlock(&priv->lock); + cleanup: remoteEventCallbackFree(callback); if (rv < 0) virNetMessageSaveError(rerr); @@ -6255,9 +6303,9 @@ remoteDispatchConnectStoragePoolEventDeregisterAny(vi= rNetServerPtr server G_GNUC } =20 static int -remoteDispatchConnectNodeDeviceEventRegisterAny(virNetServerPtr server G_G= NUC_UNUSED, +remoteDispatchConnectNodeDeviceEventRegisterAny(virNetServerPtr server, virNetServerClientPtr clie= nt, - virNetMessagePtr msg G_GNU= C_UNUSED, + virNetMessagePtr msg, virNetMessageErrorPtr rerr= G_GNUC_UNUSED, remote_connect_node_device= _event_register_any_args *args, remote_connect_node_device= _event_register_any_ret *ret) @@ -6270,20 +6318,26 @@ remoteDispatchConnectNodeDeviceEventRegisterAny(vir= NetServerPtr server G_GNUC_UN virNetServerClientGetPrivateData(client); virNodeDevicePtr dev =3D NULL; virConnectPtr conn =3D remoteGetNodeDevConn(client); + virNetServerProgramPtr program; + + if (!(program =3D virNetServerGetProgram(server, msg))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("no matching progra= m found")); + goto cleanup; + } =20 virMutexLock(&priv->lock); =20 if (!conn) - goto cleanup; + goto cleanup_unlock; =20 if (args->dev && !(dev =3D get_nonnull_node_device(conn, *args->dev))) - goto cleanup; + goto cleanup_unlock; =20 if (args->eventID >=3D VIR_NODE_DEVICE_EVENT_ID_LAST || args->eventID = < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unsupported node device event ID %d"), args->eve= ntID); - goto cleanup; + goto cleanup_unlock; } =20 /* If we call register first, we could append a complete callback @@ -6293,16 +6347,16 @@ remoteDispatchConnectNodeDeviceEventRegisterAny(vir= NetServerPtr server G_GNUC_UN * our callback; but since VIR_APPEND_ELEMENT clears 'callback' on * success, we use 'ref' to save a copy of the pointer. */ if (VIR_ALLOC(callback) < 0) - goto cleanup; + goto cleanup_unlock; callback->client =3D virObjectRef(client); - callback->program =3D virObjectRef(remoteProgram); + callback->program =3D virObjectRef(program); callback->eventID =3D args->eventID; callback->callbackID =3D -1; ref =3D callback; if (VIR_APPEND_ELEMENT(priv->nodeDeviceEventCallbacks, priv->nnodeDeviceEventCallbacks, callback) < 0) - goto cleanup; + goto cleanup_unlock; =20 if ((callbackID =3D virConnectNodeDeviceEventRegisterAny(conn, dev, @@ -6313,7 +6367,7 @@ remoteDispatchConnectNodeDeviceEventRegisterAny(virNe= tServerPtr server G_GNUC_UN VIR_SHRINK_N(priv->nodeDeviceEventCallbacks, priv->nnodeDeviceEventCallbacks, 1); callback =3D ref; - goto cleanup; + goto cleanup_unlock; } =20 ref->callbackID =3D callbackID; @@ -6321,8 +6375,9 @@ remoteDispatchConnectNodeDeviceEventRegisterAny(virNe= tServerPtr server G_GNUC_UN =20 rv =3D 0; =20 - cleanup: + cleanup_unlock: virMutexUnlock(&priv->lock); + cleanup: remoteEventCallbackFree(callback); if (rv < 0) virNetMessageSaveError(rerr); @@ -6375,9 +6430,9 @@ remoteDispatchConnectNodeDeviceEventDeregisterAny(vir= NetServerPtr server G_GNUC_ } =20 static int -remoteDispatchConnectSecretEventRegisterAny(virNetServerPtr server G_GNUC_= UNUSED, +remoteDispatchConnectSecretEventRegisterAny(virNetServerPtr server, virNetServerClientPtr client, - virNetMessagePtr msg G_GNUC_UN= USED, + virNetMessagePtr msg, virNetMessageErrorPtr rerr G_G= NUC_UNUSED, remote_connect_secret_event_re= gister_any_args *args, remote_connect_secret_event_re= gister_any_ret *ret) @@ -6390,20 +6445,26 @@ remoteDispatchConnectSecretEventRegisterAny(virNetS= erverPtr server G_GNUC_UNUSED virNetServerClientGetPrivateData(client); virSecretPtr secret =3D NULL; virConnectPtr conn =3D remoteGetSecretConn(client); + virNetServerProgramPtr program; + + if (!(program =3D virNetServerGetProgram(server, msg))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("no matching progra= m found")); + goto cleanup; + } =20 virMutexLock(&priv->lock); =20 if (!conn) - goto cleanup; + goto cleanup_unlock; =20 if (args->secret && !(secret =3D get_nonnull_secret(conn, *args->secret))) - goto cleanup; + goto cleanup_unlock; =20 if (args->eventID >=3D VIR_SECRET_EVENT_ID_LAST || args->eventID < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unsupported secret event ID %d"), args->eventID); - goto cleanup; + goto cleanup_unlock; } =20 /* If we call register first, we could append a complete callback @@ -6413,16 +6474,16 @@ remoteDispatchConnectSecretEventRegisterAny(virNetS= erverPtr server G_GNUC_UNUSED * our callback; but since VIR_APPEND_ELEMENT clears 'callback' on * success, we use 'ref' to save a copy of the pointer. */ if (VIR_ALLOC(callback) < 0) - goto cleanup; + goto cleanup_unlock; callback->client =3D virObjectRef(client); - callback->program =3D virObjectRef(remoteProgram); + callback->program =3D virObjectRef(program); callback->eventID =3D args->eventID; callback->callbackID =3D -1; ref =3D callback; if (VIR_APPEND_ELEMENT(priv->secretEventCallbacks, priv->nsecretEventCallbacks, callback) < 0) - goto cleanup; + goto cleanup_unlock; =20 if ((callbackID =3D virConnectSecretEventRegisterAny(conn, secret, @@ -6433,7 +6494,7 @@ remoteDispatchConnectSecretEventRegisterAny(virNetSer= verPtr server G_GNUC_UNUSED VIR_SHRINK_N(priv->secretEventCallbacks, priv->nsecretEventCallbacks, 1); callback =3D ref; - goto cleanup; + goto cleanup_unlock; } =20 ref->callbackID =3D callbackID; @@ -6441,8 +6502,9 @@ remoteDispatchConnectSecretEventRegisterAny(virNetSer= verPtr server G_GNUC_UNUSED =20 rv =3D 0; =20 - cleanup: + cleanup_unlock: virMutexUnlock(&priv->lock); + cleanup: remoteEventCallbackFree(callback); if (rv < 0) virNetMessageSaveError(rerr); @@ -6495,9 +6557,9 @@ remoteDispatchConnectSecretEventDeregisterAny(virNetS= erverPtr server G_GNUC_UNUS } =20 static int -qemuDispatchConnectDomainMonitorEventRegister(virNetServerPtr server G_GNU= C_UNUSED, +qemuDispatchConnectDomainMonitorEventRegister(virNetServerPtr server, virNetServerClientPtr client, - virNetMessagePtr msg G_GNUC_= UNUSED, + virNetMessagePtr msg, virNetMessageErrorPtr rerr G= _GNUC_UNUSED, qemu_connect_domain_monitor_= event_register_args *args, qemu_connect_domain_monitor_= event_register_ret *ret) @@ -6511,15 +6573,21 @@ qemuDispatchConnectDomainMonitorEventRegister(virNe= tServerPtr server G_GNUC_UNUS virDomainPtr dom =3D NULL; const char *event =3D args->event ? *args->event : NULL; virConnectPtr conn =3D remoteGetHypervisorConn(client); + virNetServerProgramPtr program; + + if (!(program =3D virNetServerGetProgram(server, msg))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("no matching progra= m found")); + goto cleanup; + } =20 virMutexLock(&priv->lock); =20 if (!conn) - goto cleanup; + goto cleanup_unlock; =20 if (args->dom && !(dom =3D get_nonnull_domain(conn, *args->dom))) - goto cleanup; + goto cleanup_unlock; =20 /* If we call register first, we could append a complete callback * to our array, but on OOM append failure, we'd have to then hope @@ -6528,16 +6596,16 @@ qemuDispatchConnectDomainMonitorEventRegister(virNe= tServerPtr server G_GNUC_UNUS * our callback; but since VIR_APPEND_ELEMENT clears 'callback' on * success, we use 'ref' to save a copy of the pointer. */ if (VIR_ALLOC(callback) < 0) - goto cleanup; + goto cleanup_unlock; callback->client =3D virObjectRef(client); - callback->program =3D virObjectRef(qemuProgram); + callback->program =3D virObjectRef(program); callback->eventID =3D -1; callback->callbackID =3D -1; ref =3D callback; if (VIR_APPEND_ELEMENT(priv->qemuEventCallbacks, priv->nqemuEventCallbacks, callback) < 0) - goto cleanup; + goto cleanup_unlock; =20 if ((callbackID =3D virConnectDomainQemuMonitorEventRegister(conn, dom, @@ -6549,7 +6617,7 @@ qemuDispatchConnectDomainMonitorEventRegister(virNetS= erverPtr server G_GNUC_UNUS VIR_SHRINK_N(priv->qemuEventCallbacks, priv->nqemuEventCallbacks, 1); callback =3D ref; - goto cleanup; + goto cleanup_unlock; } =20 ref->callbackID =3D callbackID; @@ -6557,6 +6625,8 @@ qemuDispatchConnectDomainMonitorEventRegister(virNetS= erverPtr server G_GNUC_UNUS =20 rv =3D 0; =20 + cleanup_unlock: + virMutexUnlock(&priv->lock); cleanup: virMutexUnlock(&priv->lock); remoteEventCallbackFree(callback); diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl index 7c868191d19c..2b8795beec16 100755 --- a/src/rpc/gendispatch.pl +++ b/src/rpc/gendispatch.pl @@ -1052,6 +1052,7 @@ elsif ($mode eq "server") { if ($call->{streamflag} ne "none") { print " virStreamPtr st =3D NULL;\n"; print " daemonClientStreamPtr stream =3D NULL;\n"; + print " virNetServerProgramPtr remoteProgram;\n"; if ($call->{sparseflag} ne "none") { print " const bool sparse =3D args->flags & $call->{spa= rseflag};\n" } else { @@ -1093,6 +1094,11 @@ elsif ($mode eq "server") { print " if (!(st =3D virStreamNew($conn_var, VIR_STREAM_NON= BLOCK)))\n"; print " goto cleanup;\n"; print "\n"; + print " if (!(remoteProgram =3D virNetServerGetProgram(serv= er, msg))) {\n"; + print " virReportError(VIR_ERR_INTERNAL_ERROR, \"%s\", = _(\"no matching program found\"));\n"; + print " goto cleanup;\n"; + print " }\n"; + print "\n"; print " if (!(stream =3D daemonCreateClientStream(client, s= t, remoteProgram, &msg->header, sparse)))\n"; print " goto cleanup;\n"; print "\n"; diff --git a/src/rpc/virnetserver.c b/src/rpc/virnetserver.c index 41226368058f..787ace916c9d 100644 --- a/src/rpc/virnetserver.c +++ b/src/rpc/virnetserver.c @@ -187,6 +187,28 @@ virNetServerGetProgramLocked(virNetServerPtr srv, return NULL; } =20 +/** + * virNetServerGetProgram: + * @srv: server (must NOT be locked by the caller) + * @msg: message + * + * Searches @srv for the right program for a given message @msg. + * + * Returns a pointer to the server program or NULL if not found. + */ +virNetServerProgramPtr +virNetServerGetProgram(virNetServerPtr srv, + virNetMessagePtr msg) +{ + virNetServerProgramPtr ret; + + virObjectLock(srv); + ret =3D virNetServerGetProgramLocked(srv, msg); + virObjectUnlock(srv); + + return ret; +} + static void virNetServerDispatchNewMessage(virNetServerClientPtr client, virNetMessagePtr msg, diff --git a/src/rpc/virnetserver.h b/src/rpc/virnetserver.h index 260c99b22d5e..46ecb0e91077 100644 --- a/src/rpc/virnetserver.h +++ b/src/rpc/virnetserver.h @@ -90,6 +90,8 @@ int virNetServerAddProgram(virNetServerPtr srv, int virNetServerSetTLSContext(virNetServerPtr srv, virNetTLSContextPtr tls); =20 +virNetServerProgramPtr virNetServerGetProgram(virNetServerPtr srv, + virNetMessagePtr msg); =20 int virNetServerAddClient(virNetServerPtr srv, virNetServerClientPtr client); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list