From nobody Mon Dec 15 23:29:16 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=linux.ibm.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1530617901172525.5413727324576; Tue, 3 Jul 2018 04:38:21 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 84EA5308A95A; Tue, 3 Jul 2018 11:38:19 +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 3FEDD60177; Tue, 3 Jul 2018 11:38:19 +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 AF09F18037F2; Tue, 3 Jul 2018 11:38:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w63Bc9JA000945 for ; Tue, 3 Jul 2018 07:38:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5EB2B8C9C0; Tue, 3 Jul 2018 11:38:09 +0000 (UTC) Received: from mx1.redhat.com (ext-mx01.extmail.prod.ext.phx2.redhat.com [10.5.110.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 56FFC8C9BE for ; Tue, 3 Jul 2018 11:38:06 +0000 (UTC) Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A8B1781E05 for ; Tue, 3 Jul 2018 11:38:05 +0000 (UTC) Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w63Bb4wC084878 for ; Tue, 3 Jul 2018 07:38:05 -0400 Received: from e06smtp04.uk.ibm.com (e06smtp04.uk.ibm.com [195.75.94.100]) by mx0b-001b2d01.pphosted.com with ESMTP id 2k07yt15tb-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 03 Jul 2018 07:38:04 -0400 Received: from localhost by e06smtp04.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 3 Jul 2018 12:38:03 +0100 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp04.uk.ibm.com (192.168.101.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Tue, 3 Jul 2018 12:38:00 +0100 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w63Bbxq832702512 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 3 Jul 2018 11:37:59 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 201FD52063; Tue, 3 Jul 2018 14:38:25 +0100 (BST) Received: from marc-ibm.boeblingen.de.ibm.com (unknown [9.152.224.50]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id EC4D252065; Tue, 3 Jul 2018 14:38:24 +0100 (BST) From: Marc Hartmayer To: Date: Tue, 3 Jul 2018 13:37:34 +0200 In-Reply-To: <20180703113738.3425-1-mhartmay@linux.ibm.com> References: <20180703113738.3425-1-mhartmay@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18070311-0016-0000-0000-000001E2E0AB X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18070311-0017-0000-0000-000032373E46 Message-Id: <20180703113738.3425-3-mhartmay@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-07-03_04:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=3 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-1806210000 definitions=main-1807030134 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 207 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 03 Jul 2018 11:38:05 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 03 Jul 2018 11:38:05 +0000 (UTC) for IP:'148.163.158.5' DOMAIN:'mx0b-001b2d01.pphosted.com' HELO:'mx0a-001b2d01.pphosted.com' FROM:'mhartmay@linux.ibm.com' RCPT:'' X-RedHat-Spam-Score: -0.701 (RCVD_IN_DNSWL_LOW, SPF_PASS) 148.163.158.5 mx0b-001b2d01.pphosted.com 148.163.158.5 mx0b-001b2d01.pphosted.com X-Scanned-By: MIMEDefang 2.83 on 10.5.110.25 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Cc: Erik Skultety Subject: [libvirt] [PATCH v2 2/6] rpc: Initialize a worker pool for max_workers=0 as well 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Tue, 03 Jul 2018 11:38:20 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Semantically, there is no difference between an uninitialized worker pool and an initialized worker pool with zero workers. Let's allow the worker pool to be initialized for max_workers=3D0 as well then which makes the API more symmetric and simplifies code. Validity of the worker pool is delegated to virThreadPoolGetMaxWorkersLocked instead. This patch fixes segmentation faults in virNetServerGetThreadPoolParameters and virNetServerSetThreadPoolParameters for the case when no worker pool is actually initialized (max_workers=3D0). Signed-off-by: Marc Hartmayer Reviewed-by: Boris Fiuczynski Reviewed-by: Bjoern Walk --- src/libvirt_private.syms | 4 +++ src/rpc/virnetserver.c | 13 ++++----- src/util/virthreadpool.c | 73 ++++++++++++++++++++++++++++++++++++--------= ---- src/util/virthreadpool.h | 8 ++++++ 4 files changed, 73 insertions(+), 25 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index ffe5dfd19b11..aa496ddf8012 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3005,11 +3005,15 @@ virThreadPoolGetCurrentWorkers; virThreadPoolGetFreeWorkers; virThreadPoolGetJobQueueDepth; virThreadPoolGetMaxWorkers; +virThreadPoolGetMaxWorkersLocked; virThreadPoolGetMinWorkers; virThreadPoolGetPriorityWorkers; +virThreadPoolLock; virThreadPoolNewFull; virThreadPoolSendJob; +virThreadPoolSendJobLocked; virThreadPoolSetParameters; +virThreadPoolUnlock; =20 =20 # util/virtime.h diff --git a/src/rpc/virnetserver.c b/src/rpc/virnetserver.c index 091e3ef23406..fdee08fee7cd 100644 --- a/src/rpc/virnetserver.c +++ b/src/rpc/virnetserver.c @@ -203,7 +203,8 @@ virNetServerDispatchNewMessage(virNetServerClientPtr cl= ient, * of disposing @srv */ virObjectUnlock(srv); =20 - if (srv->workers) { + virThreadPoolLock(srv->workers); + if (virThreadPoolGetMaxWorkersLocked(srv->workers) > 0) { virNetServerJobPtr job; =20 if (VIR_ALLOC(job) < 0) @@ -218,7 +219,7 @@ virNetServerDispatchNewMessage(virNetServerClientPtr cl= ient, } =20 virObjectRef(client); - if (virThreadPoolSendJob(srv->workers, priority, job) < 0) { + if (virThreadPoolSendJobLocked(srv->workers, priority, job) < 0) { virObjectUnref(client); VIR_FREE(job); virObjectUnref(prog); @@ -228,10 +229,12 @@ virNetServerDispatchNewMessage(virNetServerClientPtr = client, if (virNetServerProcessMsg(srv, client, prog, msg) < 0) goto error; } + virThreadPoolUnlock(srv->workers); =20 return; =20 error: + virThreadPoolUnlock(srv->workers); virNetMessageFree(msg); virNetServerClientClose(client); } @@ -363,8 +366,7 @@ virNetServerPtr virNetServerNew(const char *name, if (!(srv =3D virObjectLockableNew(virNetServerClass))) return NULL; =20 - if (max_workers && - !(srv->workers =3D virThreadPoolNew(min_workers, max_workers, + if (!(srv->workers =3D virThreadPoolNew(min_workers, max_workers, priority_workers, virNetServerHandleJob, srv))) @@ -575,21 +577,18 @@ virJSONValuePtr virNetServerPreExecRestart(virNetServ= erPtr srv) goto error; =20 if (virJSONValueObjectAppendNumberUint(object, "min_workers", - srv->workers =3D=3D NULL ? 0 : virThreadPoolGetMinWorkers(srv-= >workers)) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Cannot set min_workers data in JSON document")); goto error; } if (virJSONValueObjectAppendNumberUint(object, "max_workers", - srv->workers =3D=3D NULL ? 0 : virThreadPoolGetMaxWorkers(srv-= >workers)) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Cannot set max_workers data in JSON document")); goto error; } if (virJSONValueObjectAppendNumberUint(object, "priority_workers", - srv->workers =3D=3D NULL ? 0 : virThreadPoolGetPriorityWorkers= (srv->workers)) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Cannot set priority_workers data in JSON documen= t")); diff --git a/src/util/virthreadpool.c b/src/util/virthreadpool.c index 10f2bd2c3a03..f18eafb35deb 100644 --- a/src/util/virthreadpool.c +++ b/src/util/virthreadpool.c @@ -318,17 +318,27 @@ size_t virThreadPoolGetMinWorkers(virThreadPoolPtr po= ol) return ret; } =20 -size_t virThreadPoolGetMaxWorkers(virThreadPoolPtr pool) + +size_t +virThreadPoolGetMaxWorkersLocked(virThreadPoolPtr pool) +{ + return pool->maxWorkers; +} + + +size_t +virThreadPoolGetMaxWorkers(virThreadPoolPtr pool) { size_t ret; =20 virMutexLock(&pool->mutex); - ret =3D pool->maxWorkers; + ret =3D virThreadPoolGetMaxWorkersLocked(pool); virMutexUnlock(&pool->mutex); =20 return ret; } =20 + size_t virThreadPoolGetPriorityWorkers(virThreadPoolPtr pool) { size_t ret; @@ -373,27 +383,38 @@ size_t virThreadPoolGetJobQueueDepth(virThreadPoolPtr= pool) return ret; } =20 -/* - * @priority - job priority - * Return: 0 on success, -1 otherwise - */ -int virThreadPoolSendJob(virThreadPoolPtr pool, - unsigned int priority, - void *jobData) + +void +virThreadPoolLock(virThreadPoolPtr pool) +{ + virMutexLock(&pool->mutex); +} + + +void +virThreadPoolUnlock(virThreadPoolPtr pool) +{ + virMutexUnlock(&pool->mutex); +} + + +int +virThreadPoolSendJobLocked(virThreadPoolPtr pool, + unsigned int priority, + void *jobData) { virThreadPoolJobPtr job; =20 - virMutexLock(&pool->mutex); if (pool->quit) - goto error; + return -1; =20 if (pool->freeWorkers - pool->jobQueueDepth <=3D 0 && pool->nWorkers < pool->maxWorkers && virThreadPoolExpand(pool, 1, false) < 0) - goto error; + return -1; =20 if (VIR_ALLOC(job) < 0) - goto error; + return -1; =20 job->data =3D jobData; job->priority =3D priority; @@ -415,14 +436,30 @@ int virThreadPoolSendJob(virThreadPoolPtr pool, if (priority) virCondSignal(&pool->prioCond); =20 - virMutexUnlock(&pool->mutex); return 0; - - error: - virMutexUnlock(&pool->mutex); - return -1; } =20 + +/* + * @priority - job priority + * Return: 0 on success, -1 otherwise + */ +int +virThreadPoolSendJob(virThreadPoolPtr pool, + unsigned int priority, + void *jobData) +{ + int ret; + + virMutexLock(&pool->mutex); + ret =3D virThreadPoolSendJobLocked(pool, + priority, + jobData); + virMutexUnlock(&pool->mutex); + return ret; +} + + int virThreadPoolSetParameters(virThreadPoolPtr pool, long long int minWorkers, diff --git a/src/util/virthreadpool.h b/src/util/virthreadpool.h index e1f362f5bb60..2d65c2bc4ac3 100644 --- a/src/util/virthreadpool.h +++ b/src/util/virthreadpool.h @@ -45,6 +45,7 @@ virThreadPoolPtr virThreadPoolNewFull(size_t minWorkers, =20 size_t virThreadPoolGetMinWorkers(virThreadPoolPtr pool); size_t virThreadPoolGetMaxWorkers(virThreadPoolPtr pool); +size_t virThreadPoolGetMaxWorkersLocked(virThreadPoolPtr pool); size_t virThreadPoolGetPriorityWorkers(virThreadPoolPtr pool); size_t virThreadPoolGetCurrentWorkers(virThreadPoolPtr pool); size_t virThreadPoolGetFreeWorkers(virThreadPoolPtr pool); @@ -52,10 +53,17 @@ size_t virThreadPoolGetJobQueueDepth(virThreadPoolPtr p= ool); =20 void virThreadPoolFree(virThreadPoolPtr pool); =20 +void virThreadPoolLock(virThreadPoolPtr pool); +void virThreadPoolUnlock(virThreadPoolPtr pool); + int virThreadPoolSendJob(virThreadPoolPtr pool, unsigned int priority, void *jobdata) ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK; +int virThreadPoolSendJobLocked(virThreadPoolPtr pool, + unsigned int priority, + void *jobData) ATTRIBUTE_NONNULL(1) + ATTRIBUTE_RETURN_CHECK; =20 int virThreadPoolSetParameters(virThreadPoolPtr pool, long long int minWorkers, --=20 2.13.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list