[libvirt] [PATCH 2/2] rpc: Fix segmentation fault when no worker pool is available

Marc Hartmayer mhartmay at linux.ibm.com
Fri Jun 15 13:31:34 UTC 2018


On Fri, Jun 15, 2018 at 01:39 PM +0200, Marc Hartmayer <mhartmay at linux.ibm.com> wrote:
> If srv->workers is a NULL pointer, as it is the case if there are no
> workers, then don't try to dereference it.
>
> Signed-off-by: Marc Hartmayer <mhartmay at linux.ibm.com>
> Reviewed-by: Boris Fiuczynski <fiuczy at linux.ibm.com>
> ---
>  src/rpc/virnetserver.c | 22 +++++++++++++++-------
>  1 file changed, 15 insertions(+), 7 deletions(-)
>
> diff --git a/src/rpc/virnetserver.c b/src/rpc/virnetserver.c
> index 5ae809e372..be6f610880 100644
> --- a/src/rpc/virnetserver.c
> +++ b/src/rpc/virnetserver.c
> @@ -933,13 +933,21 @@ virNetServerGetThreadPoolParameters(virNetServerPtr srv,
>                                      size_t *jobQueueDepth)
>  {
>      virObjectLock(srv);
> -
> -    *minWorkers = virThreadPoolGetMinWorkers(srv->workers);
> -    *maxWorkers = virThreadPoolGetMaxWorkers(srv->workers);
> -    *freeWorkers = virThreadPoolGetFreeWorkers(srv->workers);
> -    *nWorkers = virThreadPoolGetCurrentWorkers(srv->workers);
> -    *nPrioWorkers = virThreadPoolGetPriorityWorkers(srv->workers);
> -    *jobQueueDepth = virThreadPoolGetJobQueueDepth(srv->workers);
> +    if (srv->workers) {
> +        *minWorkers = virThreadPoolGetMinWorkers(srv->workers);
> +        *maxWorkers = virThreadPoolGetMaxWorkers(srv->workers);
> +        *freeWorkers = virThreadPoolGetFreeWorkers(srv->workers);
> +        *nWorkers = virThreadPoolGetCurrentWorkers(srv->workers);
> +        *nPrioWorkers = virThreadPoolGetPriorityWorkers(srv->workers);
> +        *jobQueueDepth = virThreadPoolGetJobQueueDepth(srv->workers);
> +    } else {
> +        *minWorkers = 0;
> +        *maxWorkers = 0;
> +        *freeWorkers = 0;
> +        *nWorkers = 0;
> +        *nPrioWorkers = 0;
> +        *jobQueueDepth = 0;
> +    }
>
>      virObjectUnlock(srv);
>      return 0;
> --
> 2.13.6

After thinking again it probably makes more sense (and the code more
beautiful) to initialize the worker pool even for maxworker=0 (within
virNetServerNew) (=> we'll have to adapt virNetServerDispatchNewMessage
as well). BTW, there is also a segmentation fault in
virThreadPoolSetParameters… And currently it’s not possible to start
with maxworkers set to 0 and then increase it via
virThreadPoolSetParameters. These problems would all be fixed if we
would initialize a thread pool for max_workers = 0. Shall I revise this
patch this way?

Beste Grüße / Kind regards
   Marc Hartmayer

IBM Deutschland Research & Development GmbH
Vorsitzende des Aufsichtsrats: Martina Koederitz
Geschäftsführung: Dirk Wittkopp
Sitz der Gesellschaft: Böblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294





More information about the libvir-list mailing list