From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 4E6D4A0C44; Mon, 12 Apr 2021 09:48:35 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id DAD054069C; Mon, 12 Apr 2021 09:48:34 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mails.dpdk.org (Postfix) with ESMTP id B661340698 for ; Mon, 12 Apr 2021 09:48:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618213712; 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: in-reply-to:in-reply-to:references:references; bh=fNOtHw9EG46jr9TcjsrZf9XqBucpzNAy+/5oJxHrAMQ=; b=MSvo0tmPOUOItpWrbG2eJF18dJAaQlsnf87mQHAoe1Pif/wWJBM6WzbsBJIMdoS/PpaJeV 5ggKziSPB4hNDlKlfrkQmlwLNcVN4YHLt3f47otn37Qi7TNtjCduHv221/B+3AMEkq6PJ0 8SFelweuRWihMIqLPgm1Ow6L+69fjqo= Received: from mail-vs1-f71.google.com (mail-vs1-f71.google.com [209.85.217.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-467-n_lFOSBFNli47o_71UnyGQ-1; Mon, 12 Apr 2021 03:48:31 -0400 X-MC-Unique: n_lFOSBFNli47o_71UnyGQ-1 Received: by mail-vs1-f71.google.com with SMTP id u65so579398vsb.12 for ; Mon, 12 Apr 2021 00:48:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=fNOtHw9EG46jr9TcjsrZf9XqBucpzNAy+/5oJxHrAMQ=; b=MvzOQyMkD0Nr5ZWoPBcFfXvGG75mMokY7M4AH7AygVQBMIGse836YMo1GxStic/prV pETV0xRPxeToHPG+an/7FZXyeS+lkiIg7kdvyXLIdNk9fceWfW5lMhPnAOqvwbv+Y3xz BPhPplL0p+Q3CzTATj6VhQnHVLiKQqFSqNs5iArWUR4cXuyc60vqzFaysAy1UDzGVW0Q juvn+HusL8S9j5LyUtLI7gq6Av1BTooY2FvZa9nA2VyibRmJ03jBmUrnTKV4AVFofkQP hDtoHX7CmPrHqdM/Fb4Mhee4UKtmkxn3piTFRB1mbkwhfW8SM5yfhKQqXPpzoLy59Ckt iSWw== X-Gm-Message-State: AOAM532PaOKs1K3ZOpTwWN28ZDASlwAFR0vYc3bKYVyDMFxiAb1lL7p+ k4qvAc7V9fEgZMjTNQeSvIDCFhZE0Kg9/an6cvSpuHf7nNLt4NbsqMti8iFhH0pTg7H4UBDCGWV R9pKOwmGQqbC2TK48XBc= X-Received: by 2002:a67:de08:: with SMTP id q8mr696778vsk.5.1618213710777; Mon, 12 Apr 2021 00:48:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxo6mHq/EPGkKi8FZtnhChOm0xAqysBQZuRb0kqoubrCklEodV3mfIUzJsdZS6bc7OTollEnW0dACJZ67kSpFQ= X-Received: by 2002:a67:de08:: with SMTP id q8mr696766vsk.5.1618213710510; Mon, 12 Apr 2021 00:48:30 -0700 (PDT) MIME-Version: 1.0 References: <1618051453-21264-1-git-send-email-humin29@huawei.com> <1618187540-55614-1-git-send-email-humin29@huawei.com> <1618187540-55614-2-git-send-email-humin29@huawei.com> In-Reply-To: <1618187540-55614-2-git-send-email-humin29@huawei.com> From: David Marchand Date: Mon, 12 Apr 2021 09:48:19 +0200 Message-ID: To: "Min Hu (Connor)" Cc: dev , "Yigit, Ferruh" , Ciara Power , "Pattan, Reshma" Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dmarchan@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Subject: Re: [dpdk-dev] [PATCH v2 1/2] telemetry: fix missing check for thread creation X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On Mon, Apr 12, 2021 at 2:32 AM Min Hu (Connor) wrote: > > From: Chengwen Feng > > Add result check and message print out for thread creation after > failure. Ah, I was looking at this code too, while looking at your other series :-). > > Fixes: b80fe1805eee ("telemetry: introduce backward compatibility") > Cc: stable@dpdk.org > > Signed-off-by: Chengwen Feng > Signed-off-by: Min Hu (Connor) > --- > lib/librte_telemetry/telemetry.c | 28 +++++++++++++++++++++++++--- > lib/librte_telemetry/telemetry_legacy.c | 10 ++++++++-- > 2 files changed, 33 insertions(+), 5 deletions(-) > > diff --git a/lib/librte_telemetry/telemetry.c b/lib/librte_telemetry/telemetry.c > index 7e08afd..3f1a4c4 100644 > --- a/lib/librte_telemetry/telemetry.c > +++ b/lib/librte_telemetry/telemetry.c > @@ -350,6 +350,7 @@ socket_listener(void *socket) > { > while (1) { > pthread_t th; > + int rc; > struct socket *s = (struct socket *)socket; > int s_accepted = accept(s->sock, NULL, NULL); > if (s_accepted < 0) { > @@ -366,7 +367,14 @@ socket_listener(void *socket) > __atomic_add_fetch(s->num_clients, 1, > __ATOMIC_RELAXED); > } > - pthread_create(&th, NULL, s->fn, (void *)(uintptr_t)s_accepted); > + rc = pthread_create(&th, NULL, s->fn, > + (void *)(uintptr_t)s_accepted); > + if (rc) { Either you use this rc variable (adding strerror(rc) in the log message below) or you can remove it. This comment applies to others updates below. > + TMTY_LOG(ERR, "Error with create thread, telemetry thread quitting\n"); > + close(s_accepted); > + return NULL; > + } > + > pthread_detach(th); > } > return NULL; > @@ -425,6 +433,7 @@ static int > telemetry_legacy_init(void) > { > pthread_t t_old; > + int rc; > > if (num_legacy_callbacks == 1) { > TMTY_LOG(WARNING, "No legacy callbacks, legacy socket not created\n"); > @@ -440,7 +449,13 @@ Fixes: 3b3757bda3c3 ("net/ice: get VF hardware index in DCF") (void) > v1_socket.sock = create_socket(v1_socket.path); > if (v1_socket.sock < 0) > return -1; > - pthread_create(&t_old, NULL, socket_listener, &v1_socket); > + rc = pthread_create(&t_old, NULL, socket_listener, &v1_socket); > + if (rc) { > + TMTY_LOG(ERR, "Error with create thread\n"); > + unlink_sockets(); Before this patch, v2 mode could be working fine with v1 ko. I think it was intended since telemetry_legacy_init return value is not checked and unlink_sockets() checks whether the v1 and v2 sockets have been created. Plus, in this error handling, the v1 socket fd is left open. How about: + ret = pthread_create(&t_old, NULL, socket_listener, &v1_socket); + if (ret != 0) { + TMTY_LOG(DEBUG, "Failed to create handler for legacy socket: %s\n", + strerror(ret)); + close(v1_socket.sock); + v1_socket.sock = -1; + if (v1_socket.path[0]) { + unlink(v1_socket.path); + v1_socket.path[0] = '\0'; + } + return -1; + } > + return -1; > + } > + > pthread_setaffinity_np(t_old, sizeof(*thread_cpuset), thread_cpuset); > > TMTY_LOG(DEBUG, "Legacy telemetry socket initialized ok\n"); > @@ -451,6 +466,7 @@ static int > telemetry_v2_init(void) > { > pthread_t t_new; > + int rc; > > v2_socket.num_clients = &v2_clients; > rte_telemetry_register_cmd("/", list_commands, > @@ -469,7 +485,13 @@ telemetry_v2_init(void) > v2_socket.sock = create_socket(v2_socket.path); > if (v2_socket.sock < 0) > return -1; > - pthread_create(&t_new, NULL, socket_listener, &v2_socket); > + rc = pthread_create(&t_new, NULL, socket_listener, &v2_socket); > + if (rc) { > + TMTY_LOG(ERR, "Error with create thread\n"); > + unlink_sockets(); > + return -1; > + } > + Missing a close on v2 socket, > pthread_setaffinity_np(t_new, sizeof(*thread_cpuset), thread_cpuset); > atexit(unlink_sockets); > > diff --git a/lib/librte_telemetry/telemetry_legacy.c b/lib/librte_telemetry/telemetry_legacy.c > index 5e9af37..9587bfe 100644 > --- a/lib/librte_telemetry/telemetry_legacy.c > +++ b/lib/librte_telemetry/telemetry_legacy.c > @@ -83,6 +83,7 @@ register_client(const char *cmd __rte_unused, const char *params, > pthread_t th; > char data[BUF_SIZE]; > int fd; > + int rc; > struct sockaddr_un addrs; > #endif /* !RTE_EXEC_ENV_WINDOWS */ > > @@ -112,8 +113,13 @@ register_client(const char *cmd __rte_unused, const char *params, > close(fd); > return -1; > } > - pthread_create(&th, NULL, &legacy_client_handler, > - (void *)(uintptr_t)fd); > + rc = pthread_create(&th, NULL, &legacy_client_handler, > + (void *)(uintptr_t)fd); > + if (rc) { > + fprintf(stderr, "Failed to create thread\n"); > + close(fd); > + return -1; > + } > #endif /* !RTE_EXEC_ENV_WINDOWS */ > return 0; > } > -- > 2.7.4 > -- David Marchand