From patchwork Thu Sep 24 13:40:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11797471 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 70AEA92C for ; Thu, 24 Sep 2020 13:45:17 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0E81D2344C for ; Thu, 24 Sep 2020 13:45:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0E81D2344C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=tempfail smtp.mailfrom=dm-devel-bounces@redhat.com 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-63-alLdc3hcONmUemmFxHA9QA-1; Thu, 24 Sep 2020 09:45:13 -0400 X-MC-Unique: alLdc3hcONmUemmFxHA9QA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 23BDF188C12C; Thu, 24 Sep 2020 13:45:05 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 05B0C61177; Thu, 24 Sep 2020 13:45:05 +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 CAB698C7A6; Thu, 24 Sep 2020 13:45:04 +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 08ODfjc3026812 for ; Thu, 24 Sep 2020 09:41:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id A12EF2166B27; Thu, 24 Sep 2020 13:41:45 +0000 (UTC) Delivered-To: dm-devel@redhat.com 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 994AC2166BA0 for ; Thu, 24 Sep 2020 13:41:43 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) (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 2A13B900C65 for ; Thu, 24 Sep 2020 13:41:43 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-40-lxbF0UjWO9GBWM_JTCRKRg-1; Thu, 24 Sep 2020 09:41:38 -0400 X-MC-Unique: lxbF0UjWO9GBWM_JTCRKRg-1 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id D9BB7B083; Thu, 24 Sep 2020 13:41:36 +0000 (UTC) From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Thu, 24 Sep 2020 15:40:32 +0200 Message-Id: <20200924134054.14632-2-mwilck@suse.com> In-Reply-To: <20200924134054.14632-1-mwilck@suse.com> References: <20200924134054.14632-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false 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 08ODfjc3026812 X-loop: dm-devel@redhat.com Cc: lixiaokeng@huawei.com, dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH 01/23] multipathd: uxlsnr: avoid deadlock on exit X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dm-devel-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com From: Martin Wilck The uxlsnr wouldn't always release the client lock when cancelled, causing a deadlock in uxsock_cleanup(). While this hasn't been caused by commit 3d611a2, the deadlock seems to have become much more likely after that patch. Solving this means that we have to treat reallocation failure of the pollfd array differently. We will now just ignore any clients above the last valid pfd index. That's a minor problem, as we're in an OOM situation anyway. Moreover, client_lock is not a "struct lock", but a plain pthread_mutex_t. Fixes: 3d611a2 ("multipathd: cancel threads early during shutdown") Signed-off-by: Martin Wilck --- multipathd/uxlsnr.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/multipathd/uxlsnr.c b/multipathd/uxlsnr.c index 1c5ce9d..d47ba1a 100644 --- a/multipathd/uxlsnr.c +++ b/multipathd/uxlsnr.c @@ -35,6 +35,7 @@ #include "config.h" #include "mpath_cmd.h" #include "time-util.h" +#include "util.h" #include "main.h" #include "cli.h" @@ -116,7 +117,7 @@ static void _dead_client(struct client *c) static void dead_client(struct client *c) { - pthread_cleanup_push(cleanup_lock, &client_lock); + pthread_cleanup_push(cleanup_mutex, &client_lock); pthread_mutex_lock(&client_lock); _dead_client(c); pthread_cleanup_pop(1); @@ -306,6 +307,7 @@ void * uxsock_listen(uxsock_trigger_fn uxsock_trigger, long ux_sock, /* setup for a poll */ pthread_mutex_lock(&client_lock); + pthread_cleanup_push(cleanup_mutex, &client_lock); num_clients = 0; list_for_each_entry(c, &clients, node) { num_clients++; @@ -322,14 +324,13 @@ void * uxsock_listen(uxsock_trigger_fn uxsock_trigger, long ux_sock, sizeof(struct pollfd)); } if (!new) { - pthread_mutex_unlock(&client_lock); condlog(0, "%s: failed to realloc %d poll fds", "uxsock", 2 + num_clients); - sched_yield(); - continue; + num_clients = old_clients; + } else { + old_clients = num_clients; + polls = new; } - old_clients = num_clients; - polls = new; } polls[0].fd = ux_sock; polls[0].events = POLLIN; @@ -347,8 +348,10 @@ void * uxsock_listen(uxsock_trigger_fn uxsock_trigger, long ux_sock, polls[i].fd = c->fd; polls[i].events = POLLIN; i++; + if (i >= 2 + num_clients) + break; } - pthread_mutex_unlock(&client_lock); + pthread_cleanup_pop(1); /* most of our life is spent in this call */ poll_count = ppoll(polls, i, &sleep_time, &mask); From patchwork Thu Sep 24 13:40:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11797451 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6210A139A for ; Thu, 24 Sep 2020 13:44:36 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 076092344C for ; Thu, 24 Sep 2020 13:44:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 076092344C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=tempfail smtp.mailfrom=dm-devel-bounces@redhat.com 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-44-7ufAuGFDNvC8jNeIw0zFug-1; Thu, 24 Sep 2020 09:44:32 -0400 X-MC-Unique: 7ufAuGFDNvC8jNeIw0zFug-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CA462800475; Thu, 24 Sep 2020 13:44:27 +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 678F760BF3; Thu, 24 Sep 2020 13:44:27 +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 7AFAC1826D2B; Thu, 24 Sep 2020 13:44:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 08ODfj7Z026792 for ; Thu, 24 Sep 2020 09:41:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0C3AE114119; Thu, 24 Sep 2020 13:41:45 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 040D7110E8C for ; Thu, 24 Sep 2020 13:41:41 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (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 74366803535 for ; Thu, 24 Sep 2020 13:41:41 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-374--NihKX_yPhSZZOh3XbalaA-1; Thu, 24 Sep 2020 09:41:38 -0400 X-MC-Unique: -NihKX_yPhSZZOh3XbalaA-1 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 2BA66AD19; Thu, 24 Sep 2020 13:41:37 +0000 (UTC) From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Thu, 24 Sep 2020 15:40:33 +0200 Message-Id: <20200924134054.14632-3-mwilck@suse.com> In-Reply-To: <20200924134054.14632-1-mwilck@suse.com> References: <20200924134054.14632-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 08ODfj7Z026792 X-loop: dm-devel@redhat.com Cc: lixiaokeng@huawei.com, dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH 02/23] multipathd: Fix liburcu memory leak X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dm-devel-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com From: Martin Wilck Fix this leak in multipathd, reported by valgrind, that messes up multipathd's otherwise clean leak report: ==23823== 336 bytes in 1 blocks are possibly lost in loss record 3 of 3 ==23823== at 0x483AB65: calloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) ==23823== by 0x4012F16: _dl_allocate_tls (in /lib64/ld-2.31.so) ==23823== by 0x493BB8E: pthread_create@@GLIBC_2.2.5 (in /lib64/libpthread-2.31.so) ==23823== by 0x492A9A9: call_rcu_data_init (urcu-call-rcu-impl.h:437) ==23823== by 0x492AD2F: UnknownInlinedFun (urcu-call-rcu-impl.h:492) ==23823== by 0x492AD2F: create_call_rcu_data_memb (urcu-call-rcu-impl.h:504) ==23823== by 0x1164E3: child.constprop.0.isra.0 (main.c:2915) ==23823== by 0x10F50C: main (main.c:3335) ==23823== ==23823== LEAK SUMMARY: ==23823== definitely lost: 0 bytes in 0 blocks ==23823== indirectly lost: 0 bytes in 0 blocks ==23823== possibly lost: 336 bytes in 1 blocks The problem is caused by using liburcu's default RCU call handler, which liburcu refuses to stop/join. See comments in the code. Signed-off-by: Martin Wilck --- multipathd/main.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/multipathd/main.c b/multipathd/main.c index c5c374b..be1b5ae 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -2889,6 +2889,47 @@ set_oom_adj (void) condlog(0, "couldn't adjust oom score"); } +/* + * Use a non-default call_rcu_data for child(). + * + * We do this to avoid a memory leak from liburcu. + * liburcu never frees the default rcu handler (see comments on + * call_rcu_data_free() in urcu-call-rcu-impl.h), its thread + * can't be joined with pthread_join(), leaving a memory leak. + * + * Therefore we create our own, which can be destroyed and joined. + */ +static struct call_rcu_data *setup_rcu(void) +{ + struct call_rcu_data *crdp; + + rcu_init(); + rcu_register_thread(); + crdp = create_call_rcu_data(0UL, -1); + if (crdp != NULL) + set_thread_call_rcu_data(crdp); + return crdp; +} + +static void cleanup_rcu(int dummy __attribute__((unused)), void *arg) +{ + struct call_rcu_data *crdp = arg; + pthread_t rcu_thread; + + /* Wait for any pending RCU calls */ + rcu_barrier(); + if (crdp != NULL) { + rcu_thread = get_call_rcu_thread(crdp); + /* detach this thread from the RCU thread */ + set_thread_call_rcu_data(NULL); + synchronize_rcu(); + /* tell RCU thread to exit */ + call_rcu_data_free(crdp); + pthread_join(rcu_thread, NULL); + } + rcu_unregister_thread(); +} + static int child (__attribute__((unused)) void *param) { @@ -2903,10 +2944,12 @@ child (__attribute__((unused)) void *param) char *envp; int queue_without_daemon; enum daemon_status state; + struct call_rcu_data *crdp; mlockall(MCL_CURRENT | MCL_FUTURE); signal_init(); - rcu_init(); + crdp = setup_rcu(); + on_exit(cleanup_rcu, crdp); setup_thread_attr(&misc_attr, 64 * 1024, 0); setup_thread_attr(&uevent_attr, DEFAULT_UEVENT_STACKSIZE * 1024, 0); From patchwork Thu Sep 24 13:40:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11797469 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6256C92C for ; Thu, 24 Sep 2020 13:45:12 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 023162344C for ; Thu, 24 Sep 2020 13:45:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 023162344C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=tempfail smtp.mailfrom=dm-devel-bounces@redhat.com 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-60-x878ooscMtCLLgV6XhNYyw-1; Thu, 24 Sep 2020 09:45:07 -0400 X-MC-Unique: x878ooscMtCLLgV6XhNYyw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 192F364146; Thu, 24 Sep 2020 13:45:03 +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 E8FBD19D7C; Thu, 24 Sep 2020 13:45:02 +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 B94F61826D34; Thu, 24 Sep 2020 13:45:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 08ODfjYY026794 for ; Thu, 24 Sep 2020 09:41:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id 11DDC114102; Thu, 24 Sep 2020 13:41:45 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 071FB1140FD for ; Thu, 24 Sep 2020 13:41:41 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) (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 C81D11021F60 for ; Thu, 24 Sep 2020 13:41:41 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-54-1khuxTr-P1uEtexqTtyoVw-1; Thu, 24 Sep 2020 09:41:38 -0400 X-MC-Unique: 1khuxTr-P1uEtexqTtyoVw-1 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 704A4B10B; Thu, 24 Sep 2020 13:41:37 +0000 (UTC) From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Thu, 24 Sep 2020 15:40:34 +0200 Message-Id: <20200924134054.14632-4-mwilck@suse.com> In-Reply-To: <20200924134054.14632-1-mwilck@suse.com> References: <20200924134054.14632-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 08ODfjYY026794 X-loop: dm-devel@redhat.com Cc: lixiaokeng@huawei.com, dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH 03/23] multipathd: move handling of io_err_stat_attr into libmultipath X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dm-devel-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com From: Martin Wilck This thread attribute can be dynamically initialized and destroyed. No need to carry it along in multipathd. Removal of the symbol requires a new ABI version. Signed-off-by: Martin Wilck --- libmultipath/io_err_stat.c | 7 +++++-- libmultipath/libmultipath.version | 23 ++++++++--------------- multipathd/main.c | 2 -- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/libmultipath/io_err_stat.c b/libmultipath/io_err_stat.c index 58bc1dd..5363049 100644 --- a/libmultipath/io_err_stat.c +++ b/libmultipath/io_err_stat.c @@ -34,6 +34,7 @@ #include "lock.h" #include "time-util.h" #include "io_err_stat.h" +#include "util.h" #define TIMEOUT_NO_IO_NSEC 10000000 /*10ms = 10000000ns*/ #define FLAKY_PATHFAIL_THRESHOLD 2 @@ -70,8 +71,7 @@ struct io_err_stat_path { int err_rate_threshold; }; -pthread_t io_err_stat_thr; -pthread_attr_t io_err_stat_attr; +static pthread_t io_err_stat_thr; static pthread_mutex_t io_err_thread_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_cond_t io_err_thread_cond = PTHREAD_COND_INITIALIZER; @@ -727,6 +727,7 @@ static void *io_err_stat_loop(void *data) int start_io_err_stat_thread(void *data) { int ret; + pthread_attr_t io_err_stat_attr; if (uatomic_read(&io_err_thread_running) == 1) return 0; @@ -739,6 +740,7 @@ int start_io_err_stat_thread(void *data) if (!paths) goto destroy_ctx; + setup_thread_attr(&io_err_stat_attr, 32 * 1024, 0); pthread_mutex_lock(&io_err_thread_lock); pthread_cleanup_push(cleanup_unlock, &io_err_thread_lock); @@ -750,6 +752,7 @@ int start_io_err_stat_thread(void *data) &io_err_thread_lock) == 0); pthread_cleanup_pop(1); + pthread_attr_destroy(&io_err_stat_attr); if (ret) { io_err_stat_log(0, "cannot create io_error statistic thread"); diff --git a/libmultipath/libmultipath.version b/libmultipath/libmultipath.version index 2e531ef..9abdb22 100644 --- a/libmultipath/libmultipath.version +++ b/libmultipath/libmultipath.version @@ -1,4 +1,4 @@ -LIBMULTIPATH_0.8.4.1 { +LIBMULTIPATH_0.8.4.5 { global: /* symbols referenced by multipath and multipathd */ add_foreign; @@ -88,7 +88,6 @@ global: init_checkers; init_foreign; init_prio; - io_err_stat_attr; io_err_stat_handle_pathfail; is_path_valid; is_quote; @@ -209,30 +208,24 @@ global: free_scandir_result; sysfs_attr_get_value; -local: - *; -}; - -LIBMULTIPATH_0.8.4.2 { -global: + /* added in 0.8.4.2 */ libmp_dm_task_run; cleanup_mutex; -} LIBMULTIPATH_0.8.4.1; -LIBMULTIPATH_0.8.4.3 { -global: + /* added in 0.8.4.3 */ libmp_get_multipath_config; get_multipath_config; libmp_put_multipath_config; put_multipath_config; init_config; uninit_config; -} LIBMULTIPATH_0.8.4.2; -LIBMULTIPATH_0.8.4.4 { -global: + /* added in 0.8.4.4 */ udev; logsink; libmultipath_init; libmultipath_exit; -} LIBMULTIPATH_0.8.4.3; + +local: + *; +}; diff --git a/multipathd/main.c b/multipathd/main.c index be1b5ae..4d714e8 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -2954,7 +2954,6 @@ child (__attribute__((unused)) void *param) setup_thread_attr(&misc_attr, 64 * 1024, 0); setup_thread_attr(&uevent_attr, DEFAULT_UEVENT_STACKSIZE * 1024, 0); setup_thread_attr(&waiter_attr, 32 * 1024, 1); - setup_thread_attr(&io_err_stat_attr, 32 * 1024, 0); if (logsink == 1) { setup_thread_attr(&log_attr, 64 * 1024, 0); @@ -3164,7 +3163,6 @@ child (__attribute__((unused)) void *param) rcu_assign_pointer(multipath_conf, NULL); call_rcu(&conf->rcu, rcu_free_config); pthread_attr_destroy(&waiter_attr); - pthread_attr_destroy(&io_err_stat_attr); #ifdef _DEBUG_ dbg_free_final(NULL); #endif From patchwork Thu Sep 24 13:40:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11797485 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2BB73139F for ; Thu, 24 Sep 2020 13:46:14 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D17E6206B2 for ; Thu, 24 Sep 2020 13:46:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D17E6206B2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=tempfail smtp.mailfrom=dm-devel-bounces@redhat.com 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-516-Uq8vv0ijMviWHpyWmxbOoQ-1; Thu, 24 Sep 2020 09:46:07 -0400 X-MC-Unique: Uq8vv0ijMviWHpyWmxbOoQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 83D541891EAB; Thu, 24 Sep 2020 13:46:01 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 63C8719652; Thu, 24 Sep 2020 13:46:01 +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 335B98C7A2; Thu, 24 Sep 2020 13:46:01 +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 08ODfjiO026811 for ; Thu, 24 Sep 2020 09:41:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id A16022166BD9; Thu, 24 Sep 2020 13:41:45 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9A7F62166BA3 for ; Thu, 24 Sep 2020 13:41:44 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.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 EFF67811E83 for ; Thu, 24 Sep 2020 13:41:43 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-5-t40eFgyDPfqD1FgV8tIrNg-1; Thu, 24 Sep 2020 09:41:40 -0400 X-MC-Unique: t40eFgyDPfqD1FgV8tIrNg-1 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id B6509B118; Thu, 24 Sep 2020 13:41:37 +0000 (UTC) From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Thu, 24 Sep 2020 15:40:35 +0200 Message-Id: <20200924134054.14632-5-mwilck@suse.com> In-Reply-To: <20200924134054.14632-1-mwilck@suse.com> References: <20200924134054.14632-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false 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 08ODfjiO026811 X-loop: dm-devel@redhat.com Cc: lixiaokeng@huawei.com, dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH 04/23] multipathd: move vecs desctruction into cleanup function X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dm-devel-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com From: Martin Wilck This will make it easer to move the stuff around later. The only functional change is that map destuction now happens after joining all threads, which should actually improve robustness. Signed-off-by: Martin Wilck --- multipathd/main.c | 64 +++++++++++++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 24 deletions(-) diff --git a/multipathd/main.c b/multipathd/main.c index 4d714e8..2642570 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -148,7 +148,7 @@ int should_exit(void) /* * global copy of vecs for use in sig handlers */ -struct vectors * gvecs; +static struct vectors * gvecs; struct config *multipath_conf; @@ -2889,6 +2889,44 @@ set_oom_adj (void) condlog(0, "couldn't adjust oom score"); } +static void cleanup_maps(struct vectors *vecs) +{ + int queue_without_daemon, i; + struct multipath *mpp; + struct config *conf; + + conf = get_multipath_config(); + queue_without_daemon = conf->queue_without_daemon; + put_multipath_config(conf); + if (queue_without_daemon == QUE_NO_DAEMON_OFF) + vector_foreach_slot(vecs->mpvec, mpp, i) + dm_queue_if_no_path(mpp->alias, 0); + remove_maps_and_stop_waiters(vecs); + vecs->mpvec = NULL; +} + +static void cleanup_paths(struct vectors *vecs) +{ + free_pathvec(vecs->pathvec, FREE_PATHS); + vecs->pathvec = NULL; +} + +static void cleanup_vecs(void) +{ + if (!gvecs) + return; + /* + * We can't take the vecs lock here, because exit() may + * have been called from the child() thread, holding the lock already. + * Anyway, by the time we get here, all threads that might access + * vecs should have been joined already (in cleanup_threads). + */ + cleanup_maps(gvecs); + cleanup_paths(gvecs); + pthread_mutex_destroy(&gvecs->lock.mutex); + FREE(gvecs); +} + /* * Use a non-default call_rcu_data for child(). * @@ -2936,13 +2974,10 @@ child (__attribute__((unused)) void *param) pthread_t check_thr, uevent_thr, uxlsnr_thr, uevq_thr, dmevent_thr; pthread_attr_t log_attr, misc_attr, uevent_attr; struct vectors * vecs; - struct multipath * mpp; - int i; int rc; int pid_fd = -1; struct config *conf; char *envp; - int queue_without_daemon; enum daemon_status state; struct call_rcu_data *crdp; @@ -3108,17 +3143,6 @@ child (__attribute__((unused)) void *param) if (poll_dmevents) pthread_cancel(dmevent_thr); - conf = get_multipath_config(); - queue_without_daemon = conf->queue_without_daemon; - put_multipath_config(conf); - - lock(&vecs->lock); - if (queue_without_daemon == QUE_NO_DAEMON_OFF) - vector_foreach_slot(vecs->mpvec, mpp, i) - dm_queue_if_no_path(mpp->alias, 0); - remove_maps_and_stop_waiters(vecs); - unlock(&vecs->lock); - pthread_join(check_thr, NULL); pthread_join(uevent_thr, NULL); pthread_join(uxlsnr_thr, NULL); @@ -3128,15 +3152,7 @@ child (__attribute__((unused)) void *param) stop_io_err_stat_thread(); - lock(&vecs->lock); - free_pathvec(vecs->pathvec, FREE_PATHS); - vecs->pathvec = NULL; - unlock(&vecs->lock); - - pthread_mutex_destroy(&vecs->lock.mutex); - FREE(vecs); - vecs = NULL; - + cleanup_vecs(); cleanup_foreign(); cleanup_checkers(); cleanup_prio(); From patchwork Thu Sep 24 13:40:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11797457 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 17451139A for ; Thu, 24 Sep 2020 13:44:50 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A72592344C for ; Thu, 24 Sep 2020 13:44:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A72592344C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=tempfail smtp.mailfrom=dm-devel-bounces@redhat.com 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-93-_XzBThx3P1mIBmUOvsATIg-1; Thu, 24 Sep 2020 09:44:45 -0400 X-MC-Unique: _XzBThx3P1mIBmUOvsATIg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 913F41084D87; Thu, 24 Sep 2020 13:44:40 +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 7204819D7C; Thu, 24 Sep 2020 13:44:40 +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 4928F1826D2C; Thu, 24 Sep 2020 13:44:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 08ODfjrK026815 for ; Thu, 24 Sep 2020 09:41:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id CC89C110E8C; Thu, 24 Sep 2020 13:41:45 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C7D391140F7 for ; Thu, 24 Sep 2020 13:41:45 +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 AF5C7801184 for ; Thu, 24 Sep 2020 13:41:45 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-437-OmvDQjyrPQOAqu8tYrMR-g-1; Thu, 24 Sep 2020 09:41:40 -0400 X-MC-Unique: OmvDQjyrPQOAqu8tYrMR-g-1 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 0821EB119; Thu, 24 Sep 2020 13:41:38 +0000 (UTC) From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Thu, 24 Sep 2020 15:40:36 +0200 Message-Id: <20200924134054.14632-6-mwilck@suse.com> In-Reply-To: <20200924134054.14632-1-mwilck@suse.com> References: <20200924134054.14632-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 08ODfjrK026815 X-loop: dm-devel@redhat.com Cc: lixiaokeng@huawei.com, dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH 05/23] multipathd: make some globals static X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dm-devel-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com From: Martin Wilck Signed-off-by: Martin Wilck --- multipathd/main.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/multipathd/main.c b/multipathd/main.c index 2642570..1cdbff1 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -116,19 +116,19 @@ struct mpath_event_param }; int uxsock_timeout; -int verbosity; -int bindings_read_only; +static int verbosity; +static int bindings_read_only; int ignore_new_devs; #ifdef NO_DMEVENTS_POLL -int poll_dmevents = 0; +static int poll_dmevents = 0; #else -int poll_dmevents = 1; +static int poll_dmevents = 1; #endif /* Don't access this variable without holding config_lock */ -volatile enum daemon_status running_state = DAEMON_INIT; +static volatile enum daemon_status running_state = DAEMON_INIT; pid_t daemon_pid; -pthread_mutex_t config_lock = PTHREAD_MUTEX_INITIALIZER; -pthread_cond_t config_cond; +static pthread_mutex_t config_lock = PTHREAD_MUTEX_INITIALIZER; +static pthread_cond_t config_cond; static inline enum daemon_status get_running_state(void) { From patchwork Thu Sep 24 13:40:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11797453 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4E2A8618 for ; Thu, 24 Sep 2020 13:44:44 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id ED03C2344C for ; Thu, 24 Sep 2020 13:44:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org ED03C2344C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=tempfail smtp.mailfrom=dm-devel-bounces@redhat.com 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-592-LekO0PjsNQyFYpDZOnwudQ-1; Thu, 24 Sep 2020 09:44:40 -0400 X-MC-Unique: LekO0PjsNQyFYpDZOnwudQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 25224188C122; Thu, 24 Sep 2020 13:44:36 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 02EB319D7C; Thu, 24 Sep 2020 13:44:36 +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 CB9D48C7A2; Thu, 24 Sep 2020 13:44:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 08ODfjFb026791 for ; Thu, 24 Sep 2020 09:41:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0732C1140FF; Thu, 24 Sep 2020 13:41:45 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F34291140F6 for ; Thu, 24 Sep 2020 13:41:43 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.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 AE42F1869B94 for ; Thu, 24 Sep 2020 13:41:43 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-437-a1mTR2gcOkCZveheyndVhQ-1; Thu, 24 Sep 2020 09:41:40 -0400 X-MC-Unique: a1mTR2gcOkCZveheyndVhQ-1 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 4F078B122; Thu, 24 Sep 2020 13:41:38 +0000 (UTC) From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Thu, 24 Sep 2020 15:40:37 +0200 Message-Id: <20200924134054.14632-7-mwilck@suse.com> In-Reply-To: <20200924134054.14632-1-mwilck@suse.com> References: <20200924134054.14632-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 08ODfjFb026791 X-loop: dm-devel@redhat.com Cc: lixiaokeng@huawei.com, dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH 06/23] multipathd: move threads destruction into separate function X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dm-devel-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com From: Martin Wilck Also, introduce booleans that indicate a certain thread has been started successfully. Using these booleans, we can avoid crashing by cancelling threads that have never been started. Signed-off-by: Martin Wilck --- multipathd/main.c | 76 +++++++++++++++++++++++++++++++---------------- 1 file changed, 51 insertions(+), 25 deletions(-) diff --git a/multipathd/main.c b/multipathd/main.c index 1cdbff1..8b9df55 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -129,6 +129,9 @@ static volatile enum daemon_status running_state = DAEMON_INIT; pid_t daemon_pid; static pthread_mutex_t config_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_cond_t config_cond; +static pthread_t check_thr, uevent_thr, uxlsnr_thr, uevq_thr, dmevent_thr; +static bool check_thr_started, uevent_thr_started, uxlsnr_thr_started, + uevq_thr_started, dmevent_thr_started; static inline enum daemon_status get_running_state(void) { @@ -2927,6 +2930,39 @@ static void cleanup_vecs(void) FREE(gvecs); } +static void cleanup_threads(void) +{ + stop_io_err_stat_thread(); + + if (check_thr_started) + pthread_cancel(check_thr); + if (uevent_thr_started) + pthread_cancel(uevent_thr); + if (uxlsnr_thr_started) + pthread_cancel(uxlsnr_thr); + if (uevq_thr_started) + pthread_cancel(uevq_thr); + if (dmevent_thr_started) + pthread_cancel(dmevent_thr); + + if (check_thr_started) + pthread_join(check_thr, NULL); + if (uevent_thr_started) + pthread_join(uevent_thr, NULL); + if (uxlsnr_thr_started) + pthread_join(uxlsnr_thr, NULL); + if (uevq_thr_started) + pthread_join(uevq_thr, NULL); + if (dmevent_thr_started) + pthread_join(dmevent_thr, NULL); + + /* + * As all threads are joined now, and we're in DAEMON_SHUTDOWN + * state, no new waiter threads will be created any more. + */ + pthread_attr_destroy(&waiter_attr); +} + /* * Use a non-default call_rcu_data for child(). * @@ -2971,7 +3007,6 @@ static void cleanup_rcu(int dummy __attribute__((unused)), void *arg) static int child (__attribute__((unused)) void *param) { - pthread_t check_thr, uevent_thr, uxlsnr_thr, uevq_thr, dmevent_thr; pthread_attr_t log_attr, misc_attr, uevent_attr; struct vectors * vecs; int rc; @@ -3070,9 +3105,12 @@ child (__attribute__((unused)) void *param) condlog(0, "failed to create cli listener: %d", rc); goto failed; } - else if (state != DAEMON_CONFIGURE) { - condlog(0, "cli listener failed to start"); - goto failed; + else { + uxlsnr_thr_started = true; + if (state != DAEMON_CONFIGURE) { + condlog(0, "cli listener failed to start"); + goto failed; + } } if (poll_dmevents) { @@ -3085,7 +3123,8 @@ child (__attribute__((unused)) void *param) condlog(0, "failed to create dmevent waiter thread: %d", rc); goto failed; - } + } else + dmevent_thr_started = true; } /* @@ -3094,7 +3133,8 @@ child (__attribute__((unused)) void *param) if ((rc = pthread_create(&uevent_thr, &uevent_attr, ueventloop, udev))) { condlog(0, "failed to create uevent thread: %d", rc); goto failed; - } + } else + uevent_thr_started = true; pthread_attr_destroy(&uevent_attr); /* @@ -3103,11 +3143,13 @@ child (__attribute__((unused)) void *param) if ((rc = pthread_create(&check_thr, &misc_attr, checkerloop, vecs))) { condlog(0,"failed to create checker loop thread: %d", rc); goto failed; - } + } else + check_thr_started = true; if ((rc = pthread_create(&uevq_thr, &misc_attr, uevqloop, vecs))) { condlog(0, "failed to create uevent dispatcher: %d", rc); goto failed; - } + } else + uevq_thr_started = true; pthread_attr_destroy(&misc_attr); while (1) { @@ -3136,22 +3178,7 @@ child (__attribute__((unused)) void *param) } } - pthread_cancel(check_thr); - pthread_cancel(uevent_thr); - pthread_cancel(uxlsnr_thr); - pthread_cancel(uevq_thr); - if (poll_dmevents) - pthread_cancel(dmevent_thr); - - pthread_join(check_thr, NULL); - pthread_join(uevent_thr, NULL); - pthread_join(uxlsnr_thr, NULL); - pthread_join(uevq_thr, NULL); - if (poll_dmevents) - pthread_join(dmevent_thr, NULL); - - stop_io_err_stat_thread(); - + cleanup_threads(); cleanup_vecs(); cleanup_foreign(); cleanup_checkers(); @@ -3178,7 +3205,6 @@ child (__attribute__((unused)) void *param) conf = rcu_dereference(multipath_conf); rcu_assign_pointer(multipath_conf, NULL); call_rcu(&conf->rcu, rcu_free_config); - pthread_attr_destroy(&waiter_attr); #ifdef _DEBUG_ dbg_free_final(NULL); #endif From patchwork Thu Sep 24 13:40:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11797483 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C34ED92C for ; Thu, 24 Sep 2020 13:46:13 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5A37C206B2 for ; Thu, 24 Sep 2020 13:46:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5A37C206B2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=tempfail smtp.mailfrom=dm-devel-bounces@redhat.com 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-144-YjcGFiolN6KF1dvLJDR5JA-1; Thu, 24 Sep 2020 09:46:09 -0400 X-MC-Unique: YjcGFiolN6KF1dvLJDR5JA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EAC001891E8A; Thu, 24 Sep 2020 13:46:04 +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 CBB1473693; Thu, 24 Sep 2020 13:46:04 +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 9D4AD1826D30; Thu, 24 Sep 2020 13:46:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 08ODfkcf026838 for ; Thu, 24 Sep 2020 09:41:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8143511921BB; Thu, 24 Sep 2020 13:41:46 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 75C281009BBD for ; Thu, 24 Sep 2020 13:41:43 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (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 7C9F6811E82 for ; Thu, 24 Sep 2020 13:41:43 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-380-E3U_g6EJNS6hwdRwGYzC4A-1; Thu, 24 Sep 2020 09:41:40 -0400 X-MC-Unique: E3U_g6EJNS6hwdRwGYzC4A-1 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 971B2B123; Thu, 24 Sep 2020 13:41:38 +0000 (UTC) From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Thu, 24 Sep 2020 15:40:38 +0200 Message-Id: <20200924134054.14632-8-mwilck@suse.com> In-Reply-To: <20200924134054.14632-1-mwilck@suse.com> References: <20200924134054.14632-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 08ODfkcf026838 X-loop: dm-devel@redhat.com Cc: lixiaokeng@huawei.com, dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH 07/23] multipathd: move conf destruction into separate function X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dm-devel-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com From: Martin Wilck Also removing the comment about dlog() and dm_write_log(). dlog() can cope with get_multipath_config() returning NULL, and dm_write_log() hasn't accessed the configuration for a while. Signed-off-by: Martin Wilck --- multipathd/main.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/multipathd/main.c b/multipathd/main.c index 8b9df55..4d5b40b 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -2892,6 +2892,16 @@ set_oom_adj (void) condlog(0, "couldn't adjust oom score"); } +static void cleanup_conf(void) { + struct config *conf; + + conf = rcu_dereference(multipath_conf); + if (!conf) + return; + rcu_assign_pointer(multipath_conf, NULL); + call_rcu(&conf->rcu, rcu_free_config); +} + static void cleanup_maps(struct vectors *vecs) { int queue_without_daemon, i; @@ -3194,17 +3204,11 @@ child (__attribute__((unused)) void *param) condlog(2, "--------shut down-------"); - if (logsink == 1) + if (logsink == 1) { + logsink = 0; log_thread_stop(); - - /* - * Freeing config must be done after condlog() and dm_lib_exit(), - * because logging functions like dlog() and dm_write_log() - * reference the config. - */ - conf = rcu_dereference(multipath_conf); - rcu_assign_pointer(multipath_conf, NULL); - call_rcu(&conf->rcu, rcu_free_config); + } + cleanup_conf(); #ifdef _DEBUG_ dbg_free_final(NULL); #endif From patchwork Thu Sep 24 13:40:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11797467 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 55B9C92C for ; Thu, 24 Sep 2020 13:45:09 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E14352344C for ; Thu, 24 Sep 2020 13:45:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E14352344C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=tempfail smtp.mailfrom=dm-devel-bounces@redhat.com 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-206-zvAOYfBKPLGGz9UXp6JCMQ-1; Thu, 24 Sep 2020 09:45:05 -0400 X-MC-Unique: zvAOYfBKPLGGz9UXp6JCMQ-1 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 DF7C8801001; Thu, 24 Sep 2020 13:45:00 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C1AA31002C07; Thu, 24 Sep 2020 13:45:00 +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 956B98C7A5; Thu, 24 Sep 2020 13:45:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 08ODfjqX026793 for ; Thu, 24 Sep 2020 09:41:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0C74311411A; Thu, 24 Sep 2020 13:41:45 +0000 (UTC) Delivered-To: dm-devel@redhat.com 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 02A3711410F for ; Thu, 24 Sep 2020 13:41:43 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (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 B6FEB900C69 for ; Thu, 24 Sep 2020 13:41:43 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-19-bYzflhKENhunyH4PW0pkqQ-1; Thu, 24 Sep 2020 09:41:40 -0400 X-MC-Unique: bYzflhKENhunyH4PW0pkqQ-1 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id DD5D7B127; Thu, 24 Sep 2020 13:41:38 +0000 (UTC) From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Thu, 24 Sep 2020 15:40:39 +0200 Message-Id: <20200924134054.14632-9-mwilck@suse.com> In-Reply-To: <20200924134054.14632-1-mwilck@suse.com> References: <20200924134054.14632-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 08ODfjqX026793 X-loop: dm-devel@redhat.com Cc: lixiaokeng@huawei.com, dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH 08/23] multipathd: move pid destruction into separate function X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dm-devel-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com From: Martin Wilck Signed-off-by: Martin Wilck --- multipathd/main.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/multipathd/main.c b/multipathd/main.c index 4d5b40b..3db051b 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -2892,6 +2892,12 @@ set_oom_adj (void) condlog(0, "couldn't adjust oom score"); } +static void cleanup_pidfile(void) +{ + condlog(3, "unlink pidfile"); + unlink(DEFAULT_PIDFILE); +} + static void cleanup_conf(void) { struct config *conf; @@ -3199,9 +3205,7 @@ child (__attribute__((unused)) void *param) dm_lib_exit(); /* We're done here */ - condlog(3, "unlink pidfile"); - unlink(DEFAULT_PIDFILE); - + cleanup_pidfile(); condlog(2, "--------shut down-------"); if (logsink == 1) { From patchwork Thu Sep 24 13:40:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11797473 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1EC9F139F for ; Thu, 24 Sep 2020 13:45:18 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B7E9D2344C for ; Thu, 24 Sep 2020 13:45:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B7E9D2344C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=tempfail smtp.mailfrom=dm-devel-bounces@redhat.com 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-153-7qzjsqxnNA2kCVUylVxJQA-1; Thu, 24 Sep 2020 09:45:13 -0400 X-MC-Unique: 7qzjsqxnNA2kCVUylVxJQA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 47A7581F03F; Thu, 24 Sep 2020 13:45:07 +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 21D0E1972B; Thu, 24 Sep 2020 13:45:07 +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 E0C001826D33; Thu, 24 Sep 2020 13:45:06 +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 08ODfjFb026813 for ; Thu, 24 Sep 2020 09:41:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id B455C2166BA3; Thu, 24 Sep 2020 13:41:45 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AFB362166BA0 for ; Thu, 24 Sep 2020 13:41:45 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (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 97306186E146 for ; Thu, 24 Sep 2020 13:41:45 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-254-hO37630DM3m72nv9VnBRKg-1; Thu, 24 Sep 2020 09:41:41 -0400 X-MC-Unique: hO37630DM3m72nv9VnBRKg-1 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 2D3D7B128; Thu, 24 Sep 2020 13:41:39 +0000 (UTC) From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Thu, 24 Sep 2020 15:40:40 +0200 Message-Id: <20200924134054.14632-10-mwilck@suse.com> In-Reply-To: <20200924134054.14632-1-mwilck@suse.com> References: <20200924134054.14632-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false 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 08ODfjFb026813 X-loop: dm-devel@redhat.com Cc: lixiaokeng@huawei.com, dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH 09/23] multipathd: close pidfile on exit X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dm-devel-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com From: Martin Wilck It seems we've been doing this only in the failure case, for ages. Signed-off-by: Martin Wilck --- multipathd/main.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/multipathd/main.c b/multipathd/main.c index 3db051b..44c1bd1 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -132,6 +132,7 @@ static pthread_cond_t config_cond; static pthread_t check_thr, uevent_thr, uxlsnr_thr, uevq_thr, dmevent_thr; static bool check_thr_started, uevent_thr_started, uxlsnr_thr_started, uevq_thr_started, dmevent_thr_started; +static int pid_fd = -1; static inline enum daemon_status get_running_state(void) { @@ -2894,6 +2895,8 @@ set_oom_adj (void) static void cleanup_pidfile(void) { + if (pid_fd >= 0) + close(pid_fd); condlog(3, "unlink pidfile"); unlink(DEFAULT_PIDFILE); } @@ -3026,7 +3029,6 @@ child (__attribute__((unused)) void *param) pthread_attr_t log_attr, misc_attr, uevent_attr; struct vectors * vecs; int rc; - int pid_fd = -1; struct config *conf; char *envp; enum daemon_status state; From patchwork Thu Sep 24 13:40:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11797509 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7EA39139A for ; Thu, 24 Sep 2020 13:56:12 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 26E4220888 for ; Thu, 24 Sep 2020 13:56:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 26E4220888 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=tempfail smtp.mailfrom=dm-devel-bounces@redhat.com 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-416-KNJ1TJhsNN-YLGEZu8Qyew-1; Thu, 24 Sep 2020 09:56:07 -0400 X-MC-Unique: KNJ1TJhsNN-YLGEZu8Qyew-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5675264146; Thu, 24 Sep 2020 13:56:03 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 000B919D7C; Thu, 24 Sep 2020 13:56:02 +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 57DA78C7A1; Thu, 24 Sep 2020 13:56:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 08ODfkRR026837 for ; Thu, 24 Sep 2020 09:41:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8309E11921D8; Thu, 24 Sep 2020 13:41:46 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7AC9C118DF5D for ; Thu, 24 Sep 2020 13:41:43 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (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 A8121811E7A for ; Thu, 24 Sep 2020 13:41:43 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-254-bUCmMBcIOBGC2G6b44lieQ-1; Thu, 24 Sep 2020 09:41:41 -0400 X-MC-Unique: bUCmMBcIOBGC2G6b44lieQ-1 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 7341CB126; Thu, 24 Sep 2020 13:41:39 +0000 (UTC) From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Thu, 24 Sep 2020 15:40:41 +0200 Message-Id: <20200924134054.14632-11-mwilck@suse.com> In-Reply-To: <20200924134054.14632-1-mwilck@suse.com> References: <20200924134054.14632-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 08ODfkRR026837 X-loop: dm-devel@redhat.com X-Mailman-Approved-At: Thu, 24 Sep 2020 09:56:00 -0400 Cc: lixiaokeng@huawei.com, dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH 10/23] multipathd: add helper for systemd notification at exit X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dm-devel-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com From: Martin Wilck Add sd_notify_exit(). Signed-off-by: Martin Wilck --- multipathd/main.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/multipathd/main.c b/multipathd/main.c index 44c1bd1..e742aa5 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -3023,6 +3023,17 @@ static void cleanup_rcu(int dummy __attribute__((unused)), void *arg) rcu_unregister_thread(); } +static int sd_notify_exit(int err) +{ +#ifdef USE_SYSTEMD + char msg[24]; + + snprintf(msg, sizeof(msg), "ERRNO=%d", err); + sd_notify(0, msg); +#endif + return err; +} + static int child (__attribute__((unused)) void *param) { @@ -3218,19 +3229,12 @@ child (__attribute__((unused)) void *param) #ifdef _DEBUG_ dbg_free_final(NULL); #endif - -#ifdef USE_SYSTEMD - sd_notify(0, "ERRNO=0"); -#endif - exit(0); + exit(sd_notify_exit(0)); failed: -#ifdef USE_SYSTEMD - sd_notify(0, "ERRNO=1"); -#endif if (pid_fd >= 0) close(pid_fd); - exit(1); + exit(sd_notify_exit(1)); } static int From patchwork Thu Sep 24 13:40:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11797493 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 87D8192C for ; Thu, 24 Sep 2020 13:46:24 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1E472206B2 for ; Thu, 24 Sep 2020 13:46:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1E472206B2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=tempfail smtp.mailfrom=dm-devel-bounces@redhat.com 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-583-0IUEGa67PKORaoKvHNk0Hw-1; Thu, 24 Sep 2020 09:46:18 -0400 X-MC-Unique: 0IUEGa67PKORaoKvHNk0Hw-1 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 028901091074; Thu, 24 Sep 2020 13:46:09 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D627878831; Thu, 24 Sep 2020 13:46:08 +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 A86E98C7A4; Thu, 24 Sep 2020 13:46:08 +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 08ODfl33026858 for ; Thu, 24 Sep 2020 09:41:47 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8E5C72157F24; Thu, 24 Sep 2020 13:41:47 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 89ED62166B27 for ; Thu, 24 Sep 2020 13:41:47 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.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 706E5101A540 for ; Thu, 24 Sep 2020 13:41:47 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-157-VkRZrgWiPxGKZd6KtU-xCw-1; Thu, 24 Sep 2020 09:41:42 -0400 X-MC-Unique: VkRZrgWiPxGKZd6KtU-xCw-1 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id BEB49B12A; Thu, 24 Sep 2020 13:41:39 +0000 (UTC) From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Thu, 24 Sep 2020 15:40:42 +0200 Message-Id: <20200924134054.14632-12-mwilck@suse.com> In-Reply-To: <20200924134054.14632-1-mwilck@suse.com> References: <20200924134054.14632-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false 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 08ODfl33026858 X-loop: dm-devel@redhat.com Cc: lixiaokeng@huawei.com, dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH 11/23] multipathd: child(): call cleanups in failure case, too X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dm-devel-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com From: Martin Wilck So far we haven't called any cleanup code if child() failed. Fix it. Signed-off-by: Martin Wilck --- multipathd/main.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/multipathd/main.c b/multipathd/main.c index e742aa5..3c8f893 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -3044,6 +3044,7 @@ child (__attribute__((unused)) void *param) char *envp; enum daemon_status state; struct call_rcu_data *crdp; + int exit_code = 1; mlockall(MCL_CURRENT | MCL_FUTURE); signal_init(); @@ -3207,6 +3208,8 @@ child (__attribute__((unused)) void *param) } } + exit_code = 0; +failed: cleanup_threads(); cleanup_vecs(); cleanup_foreign(); @@ -3229,12 +3232,7 @@ child (__attribute__((unused)) void *param) #ifdef _DEBUG_ dbg_free_final(NULL); #endif - exit(sd_notify_exit(0)); - -failed: - if (pid_fd >= 0) - close(pid_fd); - exit(sd_notify_exit(1)); + return sd_notify_exit(exit_code); } static int From patchwork Thu Sep 24 13:40:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11797491 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 17D8392C for ; Thu, 24 Sep 2020 13:46:23 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AE47D206B2 for ; Thu, 24 Sep 2020 13:46:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AE47D206B2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=tempfail smtp.mailfrom=dm-devel-bounces@redhat.com 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-391-mAdCWbk4NCmjshKoORVEdQ-1; Thu, 24 Sep 2020 09:46:18 -0400 X-MC-Unique: mAdCWbk4NCmjshKoORVEdQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DEFDF1091066; Thu, 24 Sep 2020 13:46:10 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BE8B67369B; Thu, 24 Sep 2020 13:46:10 +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 92FB28C7A7; Thu, 24 Sep 2020 13:46:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 08ODfmke026887 for ; Thu, 24 Sep 2020 09:41:48 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7B247110E8C; Thu, 24 Sep 2020 13:41:48 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 75BD311410F for ; Thu, 24 Sep 2020 13:41:45 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (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 4D7ED186E136 for ; Thu, 24 Sep 2020 13:41:45 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-230-25BM-IfhNRuwi4JQI-it8A-1; Thu, 24 Sep 2020 09:41:42 -0400 X-MC-Unique: 25BM-IfhNRuwi4JQI-it8A-1 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 18847B12B; Thu, 24 Sep 2020 13:41:40 +0000 (UTC) From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Thu, 24 Sep 2020 15:40:43 +0200 Message-Id: <20200924134054.14632-13-mwilck@suse.com> In-Reply-To: <20200924134054.14632-1-mwilck@suse.com> References: <20200924134054.14632-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 08ODfmke026887 X-loop: dm-devel@redhat.com Cc: lixiaokeng@huawei.com, dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH 12/23] multipathd: unwatch_all_dmevents: check if waiter is initialized X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dm-devel-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com From: Martin Wilck Signed-off-by: Martin Wilck --- multipathd/dmevents.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/multipathd/dmevents.c b/multipathd/dmevents.c index b561cbf..f52f597 100644 --- a/multipathd/dmevents.c +++ b/multipathd/dmevents.c @@ -257,6 +257,8 @@ void unwatch_all_dmevents(void) struct dev_event *dev_evt; int i; + if (!waiter) + return; pthread_mutex_lock(&waiter->events_lock); vector_foreach_slot(waiter->events, dev_evt, i) free(dev_evt); From patchwork Thu Sep 24 13:40:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11797477 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0AFC4139F for ; Thu, 24 Sep 2020 13:45:20 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9D74323741 for ; Thu, 24 Sep 2020 13:45:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9D74323741 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=tempfail smtp.mailfrom=dm-devel-bounces@redhat.com 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-182-Q1jMOeDPN5KIASqDPdWBSw-1; Thu, 24 Sep 2020 09:45:16 -0400 X-MC-Unique: Q1jMOeDPN5KIASqDPdWBSw-1 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 720ED188C13C; Thu, 24 Sep 2020 13:45:09 +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 526E955790; Thu, 24 Sep 2020 13:45:09 +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 208211826D36; Thu, 24 Sep 2020 13:45:09 +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 08ODflQi026868 for ; Thu, 24 Sep 2020 09:41:48 -0400 Received: by smtp.corp.redhat.com (Postfix) id CB7F52157F26; Thu, 24 Sep 2020 13:41:47 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C6D122166B27 for ; Thu, 24 Sep 2020 13:41:47 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (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 B24C9101A540 for ; Thu, 24 Sep 2020 13:41:47 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-57-6O-YFvUPP7OcFaoQZqmdFA-1; Thu, 24 Sep 2020 09:41:42 -0400 X-MC-Unique: 6O-YFvUPP7OcFaoQZqmdFA-1 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 6815EB12C; Thu, 24 Sep 2020 13:41:40 +0000 (UTC) From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Thu, 24 Sep 2020 15:40:44 +0200 Message-Id: <20200924134054.14632-14-mwilck@suse.com> In-Reply-To: <20200924134054.14632-1-mwilck@suse.com> References: <20200924134054.14632-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false 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 08ODflQi026868 X-loop: dm-devel@redhat.com Cc: lixiaokeng@huawei.com, dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH 13/23] multipathd: print error message if config can't be loaded X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dm-devel-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com From: Martin Wilck Signed-off-by: Martin Wilck --- multipathd/main.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/multipathd/main.c b/multipathd/main.c index 3c8f893..483b3c7 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -3074,8 +3074,10 @@ child (__attribute__((unused)) void *param) condlog(2, "read " DEFAULT_CONFIGFILE); conf = load_config(DEFAULT_CONFIGFILE); - if (!conf) + if (!conf) { + condlog(0, "failed to load configuration"); goto failed; + } if (verbosity) conf->verbosity = verbosity; From patchwork Thu Sep 24 13:40:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11797487 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0CCA7139A for ; Thu, 24 Sep 2020 13:46:16 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A7B86206B2 for ; Thu, 24 Sep 2020 13:46:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A7B86206B2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=tempfail smtp.mailfrom=dm-devel-bounces@redhat.com 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-376-9wz1zYidNYCpt9eB_-Bkqg-1; Thu, 24 Sep 2020 09:46:11 -0400 X-MC-Unique: 9wz1zYidNYCpt9eB_-Bkqg-1 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id E8779109108D; Thu, 24 Sep 2020 13:46:06 +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 C92419CBA; Thu, 24 Sep 2020 13:46:06 +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 968991826D31; Thu, 24 Sep 2020 13:46:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 08ODflbd026857 for ; Thu, 24 Sep 2020 09:41:47 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7D20B1006180; Thu, 24 Sep 2020 13:41:47 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7964E1009BAD for ; Thu, 24 Sep 2020 13:41:47 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (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 61EDE811E82 for ; Thu, 24 Sep 2020 13:41:47 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-566-zM3CflFYM3WJZbG-LjWGyw-1; Thu, 24 Sep 2020 09:41:42 -0400 X-MC-Unique: zM3CflFYM3WJZbG-LjWGyw-1 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id B00EAB12F; Thu, 24 Sep 2020 13:41:40 +0000 (UTC) From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Thu, 24 Sep 2020 15:40:45 +0200 Message-Id: <20200924134054.14632-15-mwilck@suse.com> In-Reply-To: <20200924134054.14632-1-mwilck@suse.com> References: <20200924134054.14632-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 08ODflbd026857 X-loop: dm-devel@redhat.com Cc: lixiaokeng@huawei.com, dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH 14/23] libmultipath: add libmp_dm_exit() X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dm-devel-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com From: Martin Wilck This function prepares for calling dm_lib_exit() on program exit. It undoes changes to libdm internals done by libmultipath. It doesn't call dm_lib_exit(), as the caller may want to keep libdm active. Signed-off-by: Martin Wilck --- libmultipath/config.c | 1 + libmultipath/config.h | 2 ++ libmultipath/devmapper.c | 10 ++++++++++ libmultipath/devmapper.h | 1 + 4 files changed, 14 insertions(+) diff --git a/libmultipath/config.c b/libmultipath/config.c index fbb66b3..8097838 100644 --- a/libmultipath/config.c +++ b/libmultipath/config.c @@ -65,6 +65,7 @@ int libmultipath_init(void) static void _libmultipath_exit(void) { libmultipath_exit_called = true; + libmp_dm_exit(); udev_unref(udev); } diff --git a/libmultipath/config.h b/libmultipath/config.h index dac4e8f..fc614f0 100644 --- a/libmultipath/config.h +++ b/libmultipath/config.h @@ -270,6 +270,8 @@ int libmultipath_init(void); * * This function un-initializes libmultipath data structures. * It is recommended to call this function at program exit. + * If the application also calls dm_lib_exit(), it should do so + * after libmultipath_exit(). * * Calls to libmultipath_init() after libmultipath_exit() will fail * (in other words, libmultipath can't be re-initialized). diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 2e3ae8a..5a2e1e7 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -333,6 +333,16 @@ void libmp_udev_set_sync_support(int on) libmp_dm_udev_sync = !!on; } +void libmp_dm_exit(void) +{ + /* switch back to default libdm logging */ + dm_log_init(NULL); +#ifdef LIBDM_API_HOLD_CONTROL + /* make sure control fd is closed in dm_lib_release() */ + dm_hold_control_dev(0); +#endif +} + static void libmp_dm_init(void) { struct config *conf; diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h index 158057e..ecf2e66 100644 --- a/libmultipath/devmapper.h +++ b/libmultipath/devmapper.h @@ -35,6 +35,7 @@ enum { int dm_prereq(unsigned int *v); void skip_libmp_dm_init(void); +void libmp_dm_exit(void); void libmp_udev_set_sync_support(int on); struct dm_task *libmp_dm_task_create(int task); int dm_simplecmd_flush (int, const char *, uint16_t); From patchwork Thu Sep 24 13:40:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11797459 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 744B2139A for ; Thu, 24 Sep 2020 13:44:51 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 178A52344C for ; Thu, 24 Sep 2020 13:44:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 178A52344C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=tempfail smtp.mailfrom=dm-devel-bounces@redhat.com 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-472-QrwpDLHEMhyAINn-86WjgQ-1; Thu, 24 Sep 2020 09:44:47 -0400 X-MC-Unique: QrwpDLHEMhyAINn-86WjgQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8C2391084D8A; Thu, 24 Sep 2020 13:44:42 +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 7033D5D9D3; Thu, 24 Sep 2020 13:44:42 +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 459851826D31; Thu, 24 Sep 2020 13:44:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 08ODfmDG026879 for ; Thu, 24 Sep 2020 09:41:48 -0400 Received: by smtp.corp.redhat.com (Postfix) id 321DC1006180; Thu, 24 Sep 2020 13:41:48 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2C4F61009BB2 for ; Thu, 24 Sep 2020 13:41:48 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (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 E6BC0803526 for ; Thu, 24 Sep 2020 13:41:47 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-356-3G01PACwOkqy7rKt-VHD_w-1; Thu, 24 Sep 2020 09:41:43 -0400 X-MC-Unique: 3G01PACwOkqy7rKt-VHD_w-1 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 00D7CB135; Thu, 24 Sep 2020 13:41:41 +0000 (UTC) From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Thu, 24 Sep 2020 15:40:46 +0200 Message-Id: <20200924134054.14632-16-mwilck@suse.com> In-Reply-To: <20200924134054.14632-1-mwilck@suse.com> References: <20200924134054.14632-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 08ODfmDG026879 X-loop: dm-devel@redhat.com Cc: lixiaokeng@huawei.com, dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH 15/23] multipathd: fixup libdm deinitialization X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dm-devel-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com From: Martin Wilck With libmp_dm_exit() in place, we can make sure that the calls are made in the right order. Signed-off-by: Martin Wilck --- multipathd/main.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/multipathd/main.c b/multipathd/main.c index 483b3c7..f9749e5 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -3220,8 +3220,6 @@ failed: if (poll_dmevents) cleanup_dmevent_waiter(); - dm_lib_exit(); - /* We're done here */ cleanup_pidfile(); condlog(2, "--------shut down-------"); @@ -3320,6 +3318,9 @@ main (int argc, char *argv[]) pthread_cond_init_mono(&config_cond); + if (atexit(dm_lib_exit)) + condlog(3, "failed to register exit handler for libdm"); + libmultipath_init(); if (atexit(libmultipath_exit)) condlog(3, "failed to register exit handler for libmultipath"); From patchwork Thu Sep 24 13:40:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11797475 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CF125139A for ; Thu, 24 Sep 2020 13:45:19 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 700582344C for ; Thu, 24 Sep 2020 13:45:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 700582344C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=tempfail smtp.mailfrom=dm-devel-bounces@redhat.com 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-354-0xsx25qrNSyavtp56e8S3w-1; Thu, 24 Sep 2020 09:45:16 -0400 X-MC-Unique: 0xsx25qrNSyavtp56e8S3w-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 87B6788127C; Thu, 24 Sep 2020 13:45:11 +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 6B36E7369F; Thu, 24 Sep 2020 13:45:11 +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 3B8271826D36; Thu, 24 Sep 2020 13:45:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 08ODfm91026874 for ; Thu, 24 Sep 2020 09:41:48 -0400 Received: by smtp.corp.redhat.com (Postfix) id 06500200A7CD; Thu, 24 Sep 2020 13:41:48 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 01DDC2028DCC for ; Thu, 24 Sep 2020 13:41:47 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (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 E1CC31021F81 for ; Thu, 24 Sep 2020 13:41:47 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-356-mk7plYGaNAmEW1PiZ9Qljw-1; Thu, 24 Sep 2020 09:41:43 -0400 X-MC-Unique: mk7plYGaNAmEW1PiZ9Qljw-1 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 53D23B137; Thu, 24 Sep 2020 13:41:41 +0000 (UTC) From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Thu, 24 Sep 2020 15:40:47 +0200 Message-Id: <20200924134054.14632-17-mwilck@suse.com> In-Reply-To: <20200924134054.14632-1-mwilck@suse.com> References: <20200924134054.14632-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 08ODfm91026874 X-loop: dm-devel@redhat.com Cc: lixiaokeng@huawei.com, dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH 16/23] libmultipath: log_thread_stop(): check if logarea is initialized X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dm-devel-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com From: Martin Wilck Signed-off-by: Martin Wilck --- libmultipath/log_pthread.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libmultipath/log_pthread.c b/libmultipath/log_pthread.c index 15baef8..0c327ff 100644 --- a/libmultipath/log_pthread.c +++ b/libmultipath/log_pthread.c @@ -112,6 +112,9 @@ void log_thread_reset (void) void log_thread_stop (void) { + if (!la) + return; + logdbg(stderr,"enter log_thread_stop\n"); pthread_mutex_lock(&logev_lock); From patchwork Thu Sep 24 13:40:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11797461 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 175FE618 for ; Thu, 24 Sep 2020 13:44:55 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AEF7E2344C for ; Thu, 24 Sep 2020 13:44:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AEF7E2344C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=tempfail smtp.mailfrom=dm-devel-bounces@redhat.com 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-237-ikyoF_ptOqaviuj5s0CtkA-1; Thu, 24 Sep 2020 09:44:50 -0400 X-MC-Unique: ikyoF_ptOqaviuj5s0CtkA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7B2801008559; Thu, 24 Sep 2020 13:44:44 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 603F873693; Thu, 24 Sep 2020 13:44:44 +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 391948C7A4; Thu, 24 Sep 2020 13:44:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 08ODfm5w026900 for ; Thu, 24 Sep 2020 09:41:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id C39E21140EC; Thu, 24 Sep 2020 13:41:48 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BF6131140EB for ; Thu, 24 Sep 2020 13:41:48 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (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 A7AB5101A540 for ; Thu, 24 Sep 2020 13:41:48 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-396-RPdS8xpxOm2UTrWEhAVvnw-1; Thu, 24 Sep 2020 09:41:43 -0400 X-MC-Unique: RPdS8xpxOm2UTrWEhAVvnw-1 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 9B132B13B; Thu, 24 Sep 2020 13:41:41 +0000 (UTC) From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Thu, 24 Sep 2020 15:40:48 +0200 Message-Id: <20200924134054.14632-18-mwilck@suse.com> In-Reply-To: <20200924134054.14632-1-mwilck@suse.com> References: <20200924134054.14632-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 08ODfm5w026900 X-loop: dm-devel@redhat.com Cc: lixiaokeng@huawei.com, dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH 17/23] multipathd: add cleanup_child() exit handler X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dm-devel-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com From: Martin Wilck cleanup_child() calls all cleanups in the right order, in an exit handler. Signed-off-by: Martin Wilck --- multipathd/main.c | 48 +++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/multipathd/main.c b/multipathd/main.c index f9749e5..e7b479a 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -3023,6 +3023,28 @@ static void cleanup_rcu(int dummy __attribute__((unused)), void *arg) rcu_unregister_thread(); } +static void cleanup_child(void) +{ + cleanup_threads(); + cleanup_vecs(); + cleanup_foreign(); + cleanup_checkers(); + cleanup_prio(); + if (poll_dmevents) + cleanup_dmevent_waiter(); + + cleanup_pidfile(); + if (logsink == 1) { + logsink = 0; + log_thread_stop(); + } + cleanup_conf(); + +#ifdef _DEBUG_ + dbg_free_final(NULL); +#endif +} + static int sd_notify_exit(int err) { #ifdef USE_SYSTEMD @@ -3049,7 +3071,11 @@ child (__attribute__((unused)) void *param) mlockall(MCL_CURRENT | MCL_FUTURE); signal_init(); crdp = setup_rcu(); - on_exit(cleanup_rcu, crdp); + + if (on_exit(cleanup_rcu, crdp) || + atexit(cleanup_child)) { + fprintf(stderr, "failed to register cleanup handlers\n"); + } setup_thread_attr(&misc_attr, 64 * 1024, 0); setup_thread_attr(&uevent_attr, DEFAULT_UEVENT_STACKSIZE * 1024, 0); @@ -3212,26 +3238,8 @@ child (__attribute__((unused)) void *param) exit_code = 0; failed: - cleanup_threads(); - cleanup_vecs(); - cleanup_foreign(); - cleanup_checkers(); - cleanup_prio(); - if (poll_dmevents) - cleanup_dmevent_waiter(); - - /* We're done here */ - cleanup_pidfile(); condlog(2, "--------shut down-------"); - - if (logsink == 1) { - logsink = 0; - log_thread_stop(); - } - cleanup_conf(); -#ifdef _DEBUG_ - dbg_free_final(NULL); -#endif + /* All cleanup is done in the cleanup_child() exit handler */ return sd_notify_exit(exit_code); } From patchwork Thu Sep 24 13:40:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11797489 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1368D92C for ; Thu, 24 Sep 2020 13:46:22 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B2EB1206B2 for ; Thu, 24 Sep 2020 13:46:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B2EB1206B2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=tempfail smtp.mailfrom=dm-devel-bounces@redhat.com 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-398-vjmnAcLhPi2A5GrbqzrduQ-1; Thu, 24 Sep 2020 09:46:17 -0400 X-MC-Unique: vjmnAcLhPi2A5GrbqzrduQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1EFF9800493; Thu, 24 Sep 2020 13:46:13 +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 AB30C5D9D3; Thu, 24 Sep 2020 13:46:12 +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 7BD0E1826D2C; Thu, 24 Sep 2020 13:46:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 08ODfmQ4026894 for ; Thu, 24 Sep 2020 09:41:48 -0400 Received: by smtp.corp.redhat.com (Postfix) id 93CBC10064E1; Thu, 24 Sep 2020 13:41:48 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8E7F5100619B for ; Thu, 24 Sep 2020 13:41:48 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (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 765E5811E94 for ; Thu, 24 Sep 2020 13:41:48 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-40-hmMZwNuSOCiJpx4O-5mGeg-1; Thu, 24 Sep 2020 09:41:43 -0400 X-MC-Unique: hmMZwNuSOCiJpx4O-5mGeg-1 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id EEDD2B183; Thu, 24 Sep 2020 13:41:41 +0000 (UTC) From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Thu, 24 Sep 2020 15:40:49 +0200 Message-Id: <20200924134054.14632-19-mwilck@suse.com> In-Reply-To: <20200924134054.14632-1-mwilck@suse.com> References: <20200924134054.14632-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 08ODfmQ4026894 X-loop: dm-devel@redhat.com Cc: lixiaokeng@huawei.com, dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH 18/23] libmultipath: fix log_thread startup and teardown X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dm-devel-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com From: Martin Wilck This fixes several issues with the log_thread. First, the running flag logq_running should be set by the thread itself, not by log_thread_start()/_stop(). Second, the thread was both cancelled and terminated via a flag (again, logq_running). It's sufficient, and better, to just cancel it and use logq_running as indication for successful termination. Third, the locking wasn't cancel-safe in some places. Forth, log_thread_start() and log_thread_stop() didn't wait for startup/teardown properly. Fifth, using (pthread_t)0 is wrong (pthread_t is opaque; there's no guarantee that 0 is not a valid pthread_t value). Finally, pthread_cancel() was called under logq_lock, which doesn't make sense to me at all. Signed-off-by: Martin Wilck --- libmultipath/log_pthread.c | 59 ++++++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 15 deletions(-) diff --git a/libmultipath/log_pthread.c b/libmultipath/log_pthread.c index 0c327ff..5825e66 100644 --- a/libmultipath/log_pthread.c +++ b/libmultipath/log_pthread.c @@ -13,6 +13,7 @@ #include "log_pthread.h" #include "log.h" #include "lock.h" +#include "util.h" static pthread_t log_thr; @@ -56,28 +57,45 @@ static void flush_logqueue (void) } while (empty == 0); } +static void cleanup_log_thread(__attribute((unused)) void *arg) +{ + logdbg(stderr, "log thread exiting"); + pthread_mutex_lock(&logev_lock); + logq_running = 0; + pthread_cond_signal(&logev_cond); + pthread_mutex_unlock(&logev_lock); +} + static void * log_thread (__attribute__((unused)) void * et) { int running; pthread_mutex_lock(&logev_lock); - logq_running = 1; + running = logq_running; + if (!running) + logq_running = 1; + pthread_cond_signal(&logev_cond); pthread_mutex_unlock(&logev_lock); + if (running) + /* already started */ + return NULL; + pthread_cleanup_push(cleanup_log_thread, NULL); mlockall(MCL_CURRENT | MCL_FUTURE); logdbg(stderr,"enter log_thread\n"); while (1) { pthread_mutex_lock(&logev_lock); - if (logq_running && !log_messages_pending) + pthread_cleanup_push(cleanup_mutex, &logev_lock); + while (!log_messages_pending) + /* this is a cancellation point */ pthread_cond_wait(&logev_cond, &logev_lock); log_messages_pending = 0; - running = logq_running; - pthread_mutex_unlock(&logev_lock); - if (!running) - break; + pthread_cleanup_pop(1); + flush_logqueue(); } + pthread_cleanup_pop(1); return NULL; } @@ -98,6 +116,12 @@ void log_thread_start (pthread_attr_t *attr) exit(1); } + pthread_mutex_lock(&logev_lock); + pthread_cleanup_push(cleanup_mutex, &logev_lock); + /* wait for thread startup */ + while (!logq_running) + pthread_cond_wait(&logev_cond, &logev_lock); + pthread_cleanup_pop(1); return; } @@ -112,21 +136,26 @@ void log_thread_reset (void) void log_thread_stop (void) { + int running; + if (!la) return; - logdbg(stderr,"enter log_thread_stop\n"); pthread_mutex_lock(&logev_lock); - logq_running = 0; - pthread_cond_signal(&logev_cond); - pthread_mutex_unlock(&logev_lock); + pthread_cleanup_push(cleanup_mutex, &logev_lock); + running = logq_running; + if (running) { + pthread_cancel(log_thr); + pthread_cond_signal(&logev_cond); + } + while (logq_running) + pthread_cond_wait(&logev_cond, &logev_lock); + pthread_cleanup_pop(1); + + if (running) + pthread_join(log_thr, NULL); - pthread_mutex_lock(&logq_lock); - pthread_cancel(log_thr); - pthread_mutex_unlock(&logq_lock); - pthread_join(log_thr, NULL); - log_thr = (pthread_t)0; flush_logqueue(); From patchwork Thu Sep 24 13:40:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11797481 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6A44B139F for ; Thu, 24 Sep 2020 13:45:24 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0A6792344C for ; Thu, 24 Sep 2020 13:45:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0A6792344C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=tempfail smtp.mailfrom=dm-devel-bounces@redhat.com 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-465-UqlVTDMEOE-7fN9wWGHwwA-1; Thu, 24 Sep 2020 09:45:19 -0400 X-MC-Unique: UqlVTDMEOE-7fN9wWGHwwA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 82F7D1008550; Thu, 24 Sep 2020 13:45:13 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6504360C04; Thu, 24 Sep 2020 13:45:13 +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 3A1638C7A6; Thu, 24 Sep 2020 13:45:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 08ODfmcv026895 for ; Thu, 24 Sep 2020 09:41:48 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9784F200A7CD; Thu, 24 Sep 2020 13:41:48 +0000 (UTC) Delivered-To: dm-devel@redhat.com 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 92AAD2026F94 for ; Thu, 24 Sep 2020 13:41:48 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (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 794FD900C67 for ; Thu, 24 Sep 2020 13:41:48 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-389-M8PPCDbiOzmpmoUtJX6JpQ-1; Thu, 24 Sep 2020 09:41:43 -0400 X-MC-Unique: M8PPCDbiOzmpmoUtJX6JpQ-1 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 3AA08B18D; Thu, 24 Sep 2020 13:41:42 +0000 (UTC) From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Thu, 24 Sep 2020 15:40:50 +0200 Message-Id: <20200924134054.14632-20-mwilck@suse.com> In-Reply-To: <20200924134054.14632-1-mwilck@suse.com> References: <20200924134054.14632-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 08ODfmcv026895 X-loop: dm-devel@redhat.com Cc: lixiaokeng@huawei.com, dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH 19/23] multipathd: move cleanup_{prio, checkers, foreign} to libmultipath_exit X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dm-devel-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com From: Martin Wilck Signed-off-by: Martin Wilck --- libmpathpersist/mpath_persist.c | 2 -- libmultipath/config.c | 4 ++++ libmultipath/libmultipath.version | 5 +---- multipathd/main.c | 3 --- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/libmpathpersist/mpath_persist.c b/libmpathpersist/mpath_persist.c index 873b419..af56a95 100644 --- a/libmpathpersist/mpath_persist.c +++ b/libmpathpersist/mpath_persist.c @@ -78,8 +78,6 @@ mpath_lib_init (void) static void libmpathpersist_cleanup(void) { - cleanup_prio(); - cleanup_checkers(); libmultipath_exit(); dm_lib_exit(); } diff --git a/libmultipath/config.c b/libmultipath/config.c index 8097838..f115ac2 100644 --- a/libmultipath/config.c +++ b/libmultipath/config.c @@ -26,6 +26,7 @@ #include "devmapper.h" #include "mpath_cmd.h" #include "propsel.h" +#include "foreign.h" /* * We don't support re-initialization after @@ -65,6 +66,9 @@ int libmultipath_init(void) static void _libmultipath_exit(void) { libmultipath_exit_called = true; + cleanup_foreign(); + cleanup_checkers(); + cleanup_prio(); libmp_dm_exit(); udev_unref(udev); } diff --git a/libmultipath/libmultipath.version b/libmultipath/libmultipath.version index 9abdb22..80f1950 100644 --- a/libmultipath/libmultipath.version +++ b/libmultipath/libmultipath.version @@ -1,4 +1,4 @@ -LIBMULTIPATH_0.8.4.5 { +LIBMULTIPATH_0.8.4.6 { global: /* symbols referenced by multipath and multipathd */ add_foreign; @@ -18,10 +18,7 @@ global: checker_name; checker_state_name; check_foreign; - cleanup_checkers; - cleanup_foreign; cleanup_lock; - cleanup_prio; close_fd; coalesce_paths; convert_dev; diff --git a/multipathd/main.c b/multipathd/main.c index e7b479a..efed56e 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -3027,9 +3027,6 @@ static void cleanup_child(void) { cleanup_threads(); cleanup_vecs(); - cleanup_foreign(); - cleanup_checkers(); - cleanup_prio(); if (poll_dmevents) cleanup_dmevent_waiter(); From patchwork Thu Sep 24 13:40:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11797495 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 367C1139A for ; Thu, 24 Sep 2020 13:46:27 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D2079206B2 for ; Thu, 24 Sep 2020 13:46:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D2079206B2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=tempfail smtp.mailfrom=dm-devel-bounces@redhat.com 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-265-Ppcdu06INqemE6U3BBNHAQ-1; Thu, 24 Sep 2020 09:46:21 -0400 X-MC-Unique: Ppcdu06INqemE6U3BBNHAQ-1 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id B2C9280EF84; Thu, 24 Sep 2020 13:46:14 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9886078827; Thu, 24 Sep 2020 13:46:14 +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 6CB0E8C7A4; Thu, 24 Sep 2020 13:46:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 08ODfmP2026902 for ; Thu, 24 Sep 2020 09:41:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id D395A1006180; Thu, 24 Sep 2020 13:41:48 +0000 (UTC) Delivered-To: dm-devel@redhat.com 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 CF41F112D170 for ; Thu, 24 Sep 2020 13:41:48 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (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 B47F1900C63 for ; Thu, 24 Sep 2020 13:41:48 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-288-dZWD9eYIM9GW990dekTTsA-1; Thu, 24 Sep 2020 09:41:43 -0400 X-MC-Unique: dZWD9eYIM9GW990dekTTsA-1 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 8306DB190; Thu, 24 Sep 2020 13:41:42 +0000 (UTC) From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Thu, 24 Sep 2020 15:40:51 +0200 Message-Id: <20200924134054.14632-21-mwilck@suse.com> In-Reply-To: <20200924134054.14632-1-mwilck@suse.com> References: <20200924134054.14632-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 08ODfmP2026902 X-loop: dm-devel@redhat.com Cc: lixiaokeng@huawei.com, dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH 20/23] multipath: use atexit() for cleanup handlers X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dm-devel-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com From: Martin Wilck Signed-off-by: Martin Wilck --- multipath/main.c | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/multipath/main.c b/multipath/main.c index 9ae46ed..049a36f 100644 --- a/multipath/main.c +++ b/multipath/main.c @@ -452,13 +452,21 @@ static bool released_to_systemd(void) return ret; } +static void cleanup_vecs(__attribute__((unused)) int dummy, void *arg) +{ + struct vectors *vecs = arg; + + free_multipathvec(vecs->mpvec, KEEP_PATHS); + free_pathvec(vecs->pathvec, FREE_PATHS); +} + static int configure (struct config *conf, enum mpath_cmds cmd, enum devtypes dev_type, char *devpath) { vector curmp = NULL; vector pathvec = NULL; - struct vectors vecs; + static struct vectors vecs; int r = RTVL_FAIL, rc; int di_flag = 0; char * refwwid = NULL; @@ -469,6 +477,7 @@ configure (struct config *conf, enum mpath_cmds cmd, */ curmp = vector_alloc(); pathvec = vector_alloc(); + on_exit(cleanup_vecs, &vecs); if (!curmp || !pathvec) { condlog(0, "can not allocate memory"); @@ -580,9 +589,6 @@ out: if (refwwid) FREE(refwwid); - free_multipathvec(curmp, KEEP_PATHS); - free_pathvec(pathvec, FREE_PATHS); - return r; } @@ -808,9 +814,13 @@ main (int argc, char *argv[]) bool enable_foreign = false; libmultipath_init(); + if (atexit(dm_lib_exit) || atexit(libmultipath_exit)) + condlog(1, "failed to register cleanup handler for libmultipath: %m"); logsink = 0; if (init_config(DEFAULT_CONFIGFILE)) exit(RTVL_FAIL); + if (atexit(uninit_config)) + condlog(1, "failed to register cleanup handler for config: %m"); conf = get_multipath_config(); conf->retrigger_tries = 0; conf->force_sync = 1; @@ -887,7 +897,7 @@ main (int argc, char *argv[]) break; case 't': r = dump_config(conf, NULL, NULL) ? RTVL_FAIL : RTVL_OK; - goto out_free_config; + goto out; case 'T': cmd = CMD_DUMP_CONFIG; break; @@ -1048,26 +1058,13 @@ main (int argc, char *argv[]) condlog(3, "restart multipath configuration process"); out: - dm_lib_exit(); - - cleanup_foreign(); - cleanup_prio(); - cleanup_checkers(); + put_multipath_config(conf); + if (dev) + FREE(dev); if (dev_type == DEV_UEVENT) closelog(); -out_free_config: - /* - * Freeing config must be done after dm_lib_exit(), because - * the logging function (dm_write_log()), which is called there, - * references the config. - */ - put_multipath_config(conf); - uninit_config(); - libmultipath_exit(); - if (dev) - FREE(dev); #ifdef _DEBUG_ dbg_free_final(NULL); #endif From patchwork Thu Sep 24 13:40:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11797479 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E48A692C for ; Thu, 24 Sep 2020 13:45:23 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8A1872344C for ; Thu, 24 Sep 2020 13:45:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8A1872344C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=tempfail smtp.mailfrom=dm-devel-bounces@redhat.com 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-208-5vPQIYFWPNqn5zUX4LZ2mQ-1; Thu, 24 Sep 2020 09:45:20 -0400 X-MC-Unique: 5vPQIYFWPNqn5zUX4LZ2mQ-1 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 6EA0B188C126; Thu, 24 Sep 2020 13:45:15 +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 50ABB1002C08; Thu, 24 Sep 2020 13:45:15 +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 24BAA1826D34; Thu, 24 Sep 2020 13:45:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 08ODfpjA026958 for ; Thu, 24 Sep 2020 09:41:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id C7EAB1140F6; Thu, 24 Sep 2020 13:41:51 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C39D71140EC for ; Thu, 24 Sep 2020 13:41:49 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (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 1016D101A53F for ; Thu, 24 Sep 2020 13:41:49 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-145-kwU73vanMf2gh0eSD2lk_w-1; Thu, 24 Sep 2020 09:41:44 -0400 X-MC-Unique: kwU73vanMf2gh0eSD2lk_w-1 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id CA0BFB1AE; Thu, 24 Sep 2020 13:41:42 +0000 (UTC) From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Thu, 24 Sep 2020 15:40:52 +0200 Message-Id: <20200924134054.14632-22-mwilck@suse.com> In-Reply-To: <20200924134054.14632-1-mwilck@suse.com> References: <20200924134054.14632-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 08ODfpjA026958 X-loop: dm-devel@redhat.com Cc: lixiaokeng@huawei.com, dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH 21/23] mpathpersist: use atexit() for cleanup handlers X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dm-devel-bounces@redhat.com X-Mimecast-Spam-Score: 0.002 X-Mimecast-Originator: redhat.com From: Martin Wilck Signed-off-by: Martin Wilck --- mpathpersist/main.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mpathpersist/main.c b/mpathpersist/main.c index 3c2e657..14245cc 100644 --- a/mpathpersist/main.c +++ b/mpathpersist/main.c @@ -641,11 +641,10 @@ int main(int argc, char *argv[]) if (libmpathpersist_init()) { exit(1); } + if (atexit((void(*)(void))libmpathpersist_exit)) + fprintf(stderr, "failed to register cleanup handler for libmpathpersist: %m"); ret = handle_args(argc, argv, 0); - - libmpathpersist_exit(); - return (ret >= 0) ? ret : MPATH_PR_OTHER; } From patchwork Thu Sep 24 13:40:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11797463 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 961E7139A for ; Thu, 24 Sep 2020 13:45:00 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 29F562344C for ; Thu, 24 Sep 2020 13:45:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 29F562344C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=tempfail smtp.mailfrom=dm-devel-bounces@redhat.com 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-517-ydud-OJeP82cR3oSht-r7w-1; Thu, 24 Sep 2020 09:44:52 -0400 X-MC-Unique: ydud-OJeP82cR3oSht-r7w-1 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 5F8E7188C126; Thu, 24 Sep 2020 13:44:46 +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 42FE455786; Thu, 24 Sep 2020 13:44:46 +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 1760E1826D31; Thu, 24 Sep 2020 13:44:46 +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 08ODfn8s026923 for ; Thu, 24 Sep 2020 09:41:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4C61B2157F26; Thu, 24 Sep 2020 13:41:49 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 479812157F24 for ; Thu, 24 Sep 2020 13:41:47 +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 7DB5D801184 for ; Thu, 24 Sep 2020 13:41:47 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-439-AFLA0PrAP_ayNDdmMDLHaw-1; Thu, 24 Sep 2020 09:41:44 -0400 X-MC-Unique: AFLA0PrAP_ayNDdmMDLHaw-1 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 1F5B3B1E9; Thu, 24 Sep 2020 13:41:43 +0000 (UTC) From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Thu, 24 Sep 2020 15:40:53 +0200 Message-Id: <20200924134054.14632-23-mwilck@suse.com> In-Reply-To: <20200924134054.14632-1-mwilck@suse.com> References: <20200924134054.14632-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false 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 08ODfn8s026923 X-loop: dm-devel@redhat.com Cc: lixiaokeng@huawei.com, dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH 22/23] multipath: fix leaks in check_path_valid() X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dm-devel-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com From: Martin Wilck There were two leaks in check_path_valid(): if path status was successfully determined before calling store_pathvec(), free_path() wasn't called. Also, if an error exit occured, neither cleanup function was called. This patch fixes both, at the cost of using "static" for the pp and pathvec variables. Signed-off-by: Martin Wilck --- multipath/main.c | 55 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 12 deletions(-) diff --git a/multipath/main.c b/multipath/main.c index 049a36f..9974993 100644 --- a/multipath/main.c +++ b/multipath/main.c @@ -93,7 +93,7 @@ void rcu_register_thread_memb(void) {} void rcu_unregister_thread_memb(void) {} static int -filter_pathvec (vector pathvec, char * refwwid) +filter_pathvec (vector pathvec, const char *refwwid) { int i; struct path * pp; @@ -592,12 +592,37 @@ out: return r; } +static void cleanup_pathvec(__attribute__((unused)) int dummy, void *arg) +{ + vector *ppv = arg; + + if (ppv && *ppv) { + free_pathvec(*ppv, FREE_PATHS); + *ppv = NULL; + } +} + +static void cleanup_path(__attribute__((unused)) int dummy, void *arg) +{ + struct path **ppp = arg; + + if (ppp && *ppp) { + free_path(*ppp); + *ppp = NULL; + } +} + static int check_path_valid(const char *name, struct config *conf, bool is_uevent) { int fd, r = PATH_IS_ERROR; - struct path *pp = NULL; - vector pathvec = NULL; + static struct path *pp = NULL; + static vector pathvec = NULL; + const char *wwid; + + /* register these as exit handlers in case we exit irregularly */ + on_exit(cleanup_path, &pp); + on_exit(cleanup_pathvec, &pathvec); pp = alloc_path(); if (!pp) @@ -667,13 +692,17 @@ check_path_valid(const char *name, struct config *conf, bool is_uevent) if (store_path(pathvec, pp) != 0) { free_path(pp); goto fail; + } else { + /* make sure path isn't freed twice */ + wwid = pp->wwid; + pp = NULL; } /* For find_multipaths = SMART, if there is more than one path * matching the refwwid, then the path is valid */ if (path_discovery(pathvec, DI_SYSFS | DI_WWID) < 0) goto fail; - filter_pathvec(pathvec, pp->wwid); + filter_pathvec(pathvec, wwid); if (VECTOR_SIZE(pathvec) > 1) r = PATH_IS_VALID; else @@ -681,21 +710,23 @@ check_path_valid(const char *name, struct config *conf, bool is_uevent) out: r = print_cmd_valid(r, pathvec, conf); - free_pathvec(pathvec, FREE_PATHS); /* * multipath -u must exit with status 0, otherwise udev won't * import its output. */ if (!is_uevent && r == PATH_IS_NOT_VALID) - return RTVL_FAIL; - return RTVL_OK; + r = RTVL_FAIL; + else + r = RTVL_OK; + goto cleanup; fail: - if (pathvec) - free_pathvec(pathvec, FREE_PATHS); - else - free_path(pp); - return RTVL_FAIL; + r = RTVL_FAIL; + +cleanup: + cleanup_path(0, &pp); + cleanup_pathvec(0, &pathvec); + return r; } static int From patchwork Thu Sep 24 13:40:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11797497 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8F5CA139F for ; Thu, 24 Sep 2020 13:46:27 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 38465206B2 for ; Thu, 24 Sep 2020 13:46:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 38465206B2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=tempfail smtp.mailfrom=dm-devel-bounces@redhat.com 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-594-AinJLGxDNlCD2gaKPctlmA-1; Thu, 24 Sep 2020 09:46:23 -0400 X-MC-Unique: AinJLGxDNlCD2gaKPctlmA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 933A1801001; Thu, 24 Sep 2020 13:46:16 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 73F1519728; Thu, 24 Sep 2020 13:46:16 +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 4A38C8C7A7; Thu, 24 Sep 2020 13:46:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 08ODfnLI026933 for ; Thu, 24 Sep 2020 09:41:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id A4D3D100619B; Thu, 24 Sep 2020 13:41:49 +0000 (UTC) Delivered-To: dm-devel@redhat.com 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 9FC061006180 for ; Thu, 24 Sep 2020 13:41:49 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (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 87BA5900C65 for ; Thu, 24 Sep 2020 13:41:49 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-22-H9LM60DoMleIDtwOno-R0Q-1; Thu, 24 Sep 2020 09:41:44 -0400 X-MC-Unique: H9LM60DoMleIDtwOno-R0Q-1 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 63933B1EB; Thu, 24 Sep 2020 13:41:43 +0000 (UTC) From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Thu, 24 Sep 2020 15:40:54 +0200 Message-Id: <20200924134054.14632-24-mwilck@suse.com> In-Reply-To: <20200924134054.14632-1-mwilck@suse.com> References: <20200924134054.14632-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 08ODfnLI026933 X-loop: dm-devel@redhat.com Cc: lixiaokeng@huawei.com, dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH 23/23] multipath-tools: mpath-tools.supp: file with valgrind suppressions X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dm-devel-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com From: Martin Wilck These leaks are caused by other libraries (libsystemd, glibc, libgcrypt) and should be ignored when debugging with valgrind Usage example: valgrind --suppressions=mpath-tools.supp \ --leak-check=full --show-leak-kinds=all $COMMAND Signed-off-by: Martin Wilck --- third-party/valgrind/mpath-tools.supp | 33 +++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 third-party/valgrind/mpath-tools.supp diff --git a/third-party/valgrind/mpath-tools.supp b/third-party/valgrind/mpath-tools.supp new file mode 100644 index 0000000..621463a --- /dev/null +++ b/third-party/valgrind/mpath-tools.supp @@ -0,0 +1,33 @@ +{ + glibc _dlerror_run leak: https://stackoverflow.com/questions/1542457/memory-leak-reported-by-valgrind-in-dlopen + Memcheck:Leak + match-leak-kinds: reachable + fun:calloc + fun:_dlerror_run + fun:dlopen* +} + +{ + systemd mempools are never freed: https://bugzilla.redhat.com/show_bug.cgi?id=1215670 + Memcheck:Leak + match-leak-kinds: reachable + fun:malloc + fun:mempool_alloc_tile + fun:mempool_alloc0_tile + fun:hashmap_base_new + fun:hashmap_base_ensure_allocated +} + +{ + libgcrypt library initialization + Memcheck:Leak + match-leak-kinds: reachable + fun:malloc + ... + fun:_gcry_xmalloc + ... + fun:global_init.* + ... + fun:_dl_init +} +