From patchwork Wed Jan 3 17:56:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 13510371 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 398581CA94 for ; Wed, 3 Jan 2024 17:56:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Ixm5k4vR" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704304608; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=X9ONvcfJyLN5our8dTlejS4UNNUUzsB23ZlmBnM/EMg=; b=Ixm5k4vRhRQosPOVmx5nD9tewwbSfALbd7UU0IE56aKj2mefrkw2h5+Fl0bRoFVm6dAR7W QFatxpmWfZim1xKyITwLBxOpbYwy+caiz0MgX0jol/OhxsYvEqIDMpUBIwUWcuNg1ZcgRm N9GphuHZNYugPinqVTrTPvP8SCbm1C4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-50-scSdU737NZikkV24iTWwMQ-1; Wed, 03 Jan 2024 12:56:44 -0500 X-MC-Unique: scSdU737NZikkV24iTWwMQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0B3CD88CDCB; Wed, 3 Jan 2024 17:56:44 +0000 (UTC) Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (bmarzins-01.fast.eng.rdu2.dc.redhat.com [10.6.23.12]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F365E2166B31; Wed, 3 Jan 2024 17:56:43 +0000 (UTC) Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (localhost [127.0.0.1]) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.1/8.17.1) with ESMTPS id 403HuhvW018469 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 3 Jan 2024 12:56:43 -0500 Received: (from bmarzins@localhost) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.1/8.17.1/Submit) id 403HuhVw018468; Wed, 3 Jan 2024 12:56:43 -0500 From: Benjamin Marzinski To: Christophe Varoqui Cc: device-mapper development , Martin Wilck Subject: [PATCH v2 01/18] multipathd: remove nopath flushing code from flush_map() Date: Wed, 3 Jan 2024 12:56:26 -0500 Message-ID: <20240103175643.18438-2-bmarzins@redhat.com> In-Reply-To: <20240103175643.18438-1-bmarzins@redhat.com> References: <20240103175643.18438-1-bmarzins@redhat.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Instead of flush_map() handling both user requested flushes and automatic flushes when the last path has been deleted, make flush_map_nopaths() handle the automatic flushes itself, since a later patch will change the behavior of flush_map(). Reviewed-by: Martin Wilck Signed-off-by: Benjamin Marzinski --- multipathd/cli_handlers.c | 2 +- multipathd/main.c | 45 +++++++++++++++++---------------------- multipathd/main.h | 2 +- 3 files changed, 21 insertions(+), 28 deletions(-) diff --git a/multipathd/cli_handlers.c b/multipathd/cli_handlers.c index cf448b67..2d90f0fe 100644 --- a/multipathd/cli_handlers.c +++ b/multipathd/cli_handlers.c @@ -775,7 +775,7 @@ cli_del_maps (void *v, struct strbuf *reply, void *data) condlog(2, "remove maps (operator)"); vector_foreach_slot(vecs->mpvec, mpp, i) { - if (flush_map(mpp, vecs, 0)) + if (flush_map(mpp, vecs)) ret++; else i--; diff --git a/multipathd/main.c b/multipathd/main.c index de1c9058..4a7e0ba1 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -583,12 +583,11 @@ int update_multipath (struct vectors *vecs, char *mapname) static bool flush_map_nopaths(struct multipath *mpp, struct vectors *vecs) { - char alias[WWID_SIZE]; + int r; /* * flush_map will fail if the device is open */ - strlcpy(alias, mpp->alias, WWID_SIZE); if (mpp->flush_on_last_del == FLUSH_ENABLED) { condlog(2, "%s Last path deleted, disabling queueing", mpp->alias); @@ -598,11 +597,20 @@ flush_map_nopaths(struct multipath *mpp, struct vectors *vecs) { mpp->stat_map_failures++; dm_queue_if_no_path(mpp, 0); } - if (!flush_map(mpp, vecs, 1)) { - condlog(2, "%s: removed map after removing all paths", alias); - return true; + r = dm_flush_map_nopaths(mpp->alias, mpp->deferred_remove); + if (r) { + if (r == 1) + condlog(0, "%s: can't flush", mpp->alias); + else { + condlog(2, "%s: devmap deferred remove", mpp->alias); + mpp->deferred_remove = DEFERRED_REMOVE_IN_PROGRESS; + } + return false; } - return false; + + condlog(2, "%s: map flushed after removing all paths", mpp->alias); + remove_map_and_stop_waiter(mpp, vecs); + return true; } static void @@ -778,30 +786,15 @@ sync_maps_state(vector mpvec) } int -flush_map(struct multipath * mpp, struct vectors * vecs, int nopaths) +flush_map(struct multipath * mpp, struct vectors * vecs) { - int r; - - if (nopaths) - r = dm_flush_map_nopaths(mpp->alias, mpp->deferred_remove); - else - r = dm_flush_map(mpp->alias); - /* - * clear references to this map before flushing so we can ignore - * the spurious uevent we may generate with the dm_flush_map call below - */ + int r = dm_flush_map(mpp->alias); if (r) { - if (r == 1) - condlog(0, "%s: can't flush", mpp->alias); - else { - condlog(2, "%s: devmap deferred remove", mpp->alias); - mpp->deferred_remove = DEFERRED_REMOVE_IN_PROGRESS; - } + condlog(0, "%s: can't flush", mpp->alias); return r; } - else - condlog(2, "%s: map flushed", mpp->alias); + condlog(2, "%s: map flushed", mpp->alias); remove_map_and_stop_waiter(mpp, vecs); return 0; @@ -956,7 +949,7 @@ ev_remove_map (char * devname, char * alias, int minor, struct vectors * vecs) mpp->alias, mpp->dmi.minor, minor); return 1; } - return flush_map(mpp, vecs, 0); + return flush_map(mpp, vecs); } static void diff --git a/multipathd/main.h b/multipathd/main.h index 194f8776..e050b5c5 100644 --- a/multipathd/main.h +++ b/multipathd/main.h @@ -40,7 +40,7 @@ int ev_add_path (struct path *, struct vectors *, int); int ev_remove_path (struct path *, struct vectors *, int); int ev_add_map (char *, const char *, struct vectors *); int ev_remove_map (char *, char *, int, struct vectors *); -int flush_map(struct multipath *, struct vectors *, int); +int flush_map(struct multipath *, struct vectors *); void handle_signals(bool); int refresh_multipath(struct vectors * vecs, struct multipath * mpp); From patchwork Wed Jan 3 17:56:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 13510383 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D413C1D52B for ; Wed, 3 Jan 2024 17:56:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="e0a06xOc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704304612; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FYyoABWT3x0JD7trEIFiW7Wltp0dabbBEnKyvhAEAog=; b=e0a06xOcE6zDY8vjZLNDS0opgvLZXUkWDuElZhYX/TdkD4Sp8nKW1wFkBUhC1DrxzFFB4V rSLVMG58HQrvy1LYUXkJY4vrnoRr0ltICG4/svYtRwifAlLq17zMIWqfXjpu4zZOj+FfVt ctVsIngwhXOuVsaOxBYGkGfr+IWQ2Ro= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-497-FJncusPXM8KbpjoGLdsCxQ-1; Wed, 03 Jan 2024 12:56:44 -0500 X-MC-Unique: FJncusPXM8KbpjoGLdsCxQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2FBFC859B83; Wed, 3 Jan 2024 17:56:44 +0000 (UTC) Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (unknown [10.6.23.12]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 29E382026D66; Wed, 3 Jan 2024 17:56:44 +0000 (UTC) Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (localhost [127.0.0.1]) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.1/8.17.1) with ESMTPS id 403Huhfs018473 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 3 Jan 2024 12:56:44 -0500 Received: (from bmarzins@localhost) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.1/8.17.1/Submit) id 403Huhih018472; Wed, 3 Jan 2024 12:56:43 -0500 From: Benjamin Marzinski To: Christophe Varoqui Cc: device-mapper development , Martin Wilck Subject: [PATCH v2 02/18] multipathd: make flush_map() delete maps like the multipath command Date: Wed, 3 Jan 2024 12:56:27 -0500 Message-ID: <20240103175643.18438-3-bmarzins@redhat.com> In-Reply-To: <20240103175643.18438-1-bmarzins@redhat.com> References: <20240103175643.18438-1-bmarzins@redhat.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com When the multipath command tries to delete a multipath device, it first disables queueing and then suspends the device to force the IOs to get flushed. Then it attempts to delete the device and any kpartx partitions. multipathd, on the other hand, simply tries to delete the device and kpartx partitions, without disabling queueing or suspending. If there are no paths but there is outstanding IO, multipathd will hang trying to delete the last kpartx device. This is because it must be the last opener of the multipath device (multipath won't try to delete the device if it has any openers besides the kpartx devices) and the kernel will not allow the last opener of a block device to close until all the outstanding IO is flushed. This hang can be avoided if multipathd calls dm_suspend_and_flush_map() like the multipath command does, instead of dm_flush_map(). Reviewed-by: Martin Wilck Signed-off-by: Benjamin Marzinski --- multipathd/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/multipathd/main.c b/multipathd/main.c index 4a7e0ba1..6b66a5ee 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -788,7 +788,7 @@ sync_maps_state(vector mpvec) int flush_map(struct multipath * mpp, struct vectors * vecs) { - int r = dm_flush_map(mpp->alias); + int r = dm_suspend_and_flush_map(mpp->alias, 0); if (r) { condlog(0, "%s: can't flush", mpp->alias); return r; From patchwork Wed Jan 3 17:56:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 13510369 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE9001CA9B for ; Wed, 3 Jan 2024 17:56:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="McqHqizD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704304607; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6DuKHOcdY90mx0/ZLPqPWb1ZXgcL4Gug1gzRunbTHmI=; b=McqHqizDdYasYBvwwXWFJCZcdS+sgaQuFtxmWRH74PtJwDO5fB4eEfwxBDHs7a+fGjk+0b 2BrUBpFPtn4ZhNuk5qKI6znDPCj8OuMlS6PWLhrzEebWoIqCGLDwcKznk3gVCWSef3AQTt aLB4S2v7tv4Kmo2/zo3xI7cMV4DDUOg= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-7-rZousqCbPh2AMbqd4L2_Qw-1; Wed, 03 Jan 2024 12:56:44 -0500 X-MC-Unique: rZousqCbPh2AMbqd4L2_Qw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 58313185A780; Wed, 3 Jan 2024 17:56:44 +0000 (UTC) Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (bmarzins-01.fast.eng.rdu2.dc.redhat.com [10.6.23.12]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 522302026D66; Wed, 3 Jan 2024 17:56:44 +0000 (UTC) Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (localhost [127.0.0.1]) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.1/8.17.1) with ESMTPS id 403HuiY1018477 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 3 Jan 2024 12:56:44 -0500 Received: (from bmarzins@localhost) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.1/8.17.1/Submit) id 403Hui1G018476; Wed, 3 Jan 2024 12:56:44 -0500 From: Benjamin Marzinski To: Christophe Varoqui Cc: device-mapper development , Martin Wilck Subject: [PATCH v2 03/18] multipathd: disable queueing when removing unknown maps Date: Wed, 3 Jan 2024 12:56:28 -0500 Message-ID: <20240103175643.18438-4-bmarzins@redhat.com> In-Reply-To: <20240103175643.18438-1-bmarzins@redhat.com> References: <20240103175643.18438-1-bmarzins@redhat.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Make cli_del_maps() call dm_suspend_and_flush_map() for the unknown multipath devices as well. After this change, all callers of cli_del_maps() set need_suspend, so simplify dm_flush_maps(). Signed-off-by: Benjamin Marzinski --- libmultipath/devmapper.c | 7 ++----- libmultipath/devmapper.h | 2 +- multipath/main.c | 2 +- multipathd/cli_handlers.c | 2 +- 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 36b9d274..1646110b 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -1159,7 +1159,7 @@ dm_flush_map_nopaths(const char * mapname, #endif -int dm_flush_maps (int need_suspend, int retries) +int dm_flush_maps (int retries) { int r = 1; struct dm_task *dmt; @@ -1184,10 +1184,7 @@ int dm_flush_maps (int need_suspend, int retries) goto out; do { - if (need_suspend) - r |= dm_suspend_and_flush_map(names->name, retries); - else - r |= dm_flush_map(names->name); + r |= dm_suspend_and_flush_map(names->name, retries); next = names->next; names = (void *) names + next; } while (next); diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h index d1790df5..1eacd966 100644 --- a/libmultipath/devmapper.h +++ b/libmultipath/devmapper.h @@ -55,7 +55,7 @@ int dm_flush_map_nopaths(const char * mapname, int deferred_remove); #define dm_suspend_and_flush_map(mapname, retries) \ _dm_flush_map(mapname, 1, 0, 1, retries) int dm_cancel_deferred_remove(struct multipath *mpp); -int dm_flush_maps (int need_suspend, int retries); +int dm_flush_maps (int retries); int dm_fail_path(const char * mapname, char * path); int dm_reinstate_path(const char * mapname, char * path); int dm_queue_if_no_path(struct multipath *mpp, int enable); diff --git a/multipath/main.c b/multipath/main.c index 9e1c5052..c51884f2 100644 --- a/multipath/main.c +++ b/multipath/main.c @@ -1075,7 +1075,7 @@ main (int argc, char *argv[]) goto out; } else if (cmd == CMD_FLUSH_ALL) { - r = dm_flush_maps(1, retries) ? RTVL_FAIL : RTVL_OK; + r = dm_flush_maps(retries) ? RTVL_FAIL : RTVL_OK; goto out; } while ((r = configure(conf, cmd, dev_type, dev)) == RTVL_RETRY) diff --git a/multipathd/cli_handlers.c b/multipathd/cli_handlers.c index 2d90f0fe..dc547be8 100644 --- a/multipathd/cli_handlers.c +++ b/multipathd/cli_handlers.c @@ -781,7 +781,7 @@ cli_del_maps (void *v, struct strbuf *reply, void *data) i--; } /* flush any multipath maps that aren't currently known by multipathd */ - ret |= dm_flush_maps(0, 0); + ret |= dm_flush_maps(0); return ret; } From patchwork Wed Jan 3 17:56:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 13510370 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E1B211CA9C for ; Wed, 3 Jan 2024 17:56:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="BdWGDlN/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704304607; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3JQhRIgfNmm6bH8JEDh0rB/ptYoc8GXWm+PEyrni458=; b=BdWGDlN/ckhJ4F/BlkoxulscRmfbwEj9mAjFbWLisrzEDHotUklZchuWjfE3b+tfNLNw08 vOeM0nOvlFbMWO8HS3/aZrLm0ekNG+ylCwSOjvI5vN5vZdoLnrYvuQvXy0i/SmteOqi+WV mriHLOExHJ/CjN5wh+Xq24uAFuvrF4g= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-596-qrVBs3AvO8e74JhL36yRsw-1; Wed, 03 Jan 2024 12:56:44 -0500 X-MC-Unique: qrVBs3AvO8e74JhL36yRsw-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8088D101A555; Wed, 3 Jan 2024 17:56:44 +0000 (UTC) Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (unknown [10.6.23.12]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7B21B492BE6; Wed, 3 Jan 2024 17:56:44 +0000 (UTC) Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (localhost [127.0.0.1]) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.1/8.17.1) with ESMTPS id 403HuiQi018483 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 3 Jan 2024 12:56:44 -0500 Received: (from bmarzins@localhost) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.1/8.17.1/Submit) id 403Huiqh018482; Wed, 3 Jan 2024 12:56:44 -0500 From: Benjamin Marzinski To: Christophe Varoqui Cc: device-mapper development , Martin Wilck Subject: [PATCH v2 04/18] multipathd: simplify cli_del_map() Date: Wed, 3 Jan 2024 12:56:29 -0500 Message-ID: <20240103175643.18438-5-bmarzins@redhat.com> In-Reply-To: <20240103175643.18438-1-bmarzins@redhat.com> References: <20240103175643.18438-1-bmarzins@redhat.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com cli_del_map() does a lot of unnecessary work to match the arguments of ev_remove_map(), of which it is the only caller. Then ev_remove_map() does more unnecessary work to verify the arguments passed in. remove ev_remove_map() and make cli_del_map() get the mpp like the rest of the client handlers do. Reviewed-by: Martin Wilck Signed-off-by: Benjamin Marzinski --- multipathd/cli_handlers.c | 23 ++++++----------------- multipathd/main.c | 21 --------------------- multipathd/main.h | 1 - 3 files changed, 6 insertions(+), 39 deletions(-) diff --git a/multipathd/cli_handlers.c b/multipathd/cli_handlers.c index dc547be8..9a0cd065 100644 --- a/multipathd/cli_handlers.c +++ b/multipathd/cli_handlers.c @@ -742,28 +742,17 @@ cli_del_map (void * v, struct strbuf *reply, void * data) { struct vectors * vecs = (struct vectors *)data; char * param = get_keyparam(v, KEY_MAP); - int major, minor; - char *alias; - int rc; + struct multipath *mpp; param = convert_dev(param, 0); condlog(2, "%s: remove map (operator)", param); - if (dm_get_major_minor(param, &major, &minor) < 0) { - condlog(2, "%s: not a device mapper table", param); - return 1; - } - alias = dm_mapname(major, minor); - if (!alias) { - condlog(2, "%s: mapname not found for %d:%d", - param, major, minor); + + mpp = find_mp_by_str(vecs->mpvec, param); + + if (!mpp) return 1; - } - rc = ev_remove_map(param, alias, minor, vecs); - if (rc == 2) - append_strbuf_str(reply, "delayed\n"); - free(alias); - return rc; + return flush_map(mpp, vecs); } static int diff --git a/multipathd/main.c b/multipathd/main.c index 6b66a5ee..17468985 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -931,27 +931,6 @@ out: return 0; } -/* Called from CLI handler */ -int -ev_remove_map (char * devname, char * alias, int minor, struct vectors * vecs) -{ - struct multipath * mpp; - - mpp = find_mp_by_minor(vecs->mpvec, minor); - - if (!mpp) { - condlog(2, "%s: devmap not registered, can't remove", - devname); - return 1; - } - if (strcmp(mpp->alias, alias)) { - condlog(2, "%s: minor number mismatch (map %d, event %d)", - mpp->alias, mpp->dmi.minor, minor); - return 1; - } - return flush_map(mpp, vecs); -} - static void rescan_path(struct udev_device *ud) { diff --git a/multipathd/main.h b/multipathd/main.h index e050b5c5..4fcd6402 100644 --- a/multipathd/main.h +++ b/multipathd/main.h @@ -39,7 +39,6 @@ int need_to_delay_reconfig (struct vectors *); int ev_add_path (struct path *, struct vectors *, int); int ev_remove_path (struct path *, struct vectors *, int); int ev_add_map (char *, const char *, struct vectors *); -int ev_remove_map (char *, char *, int, struct vectors *); int flush_map(struct multipath *, struct vectors *); void handle_signals(bool); From patchwork Wed Jan 3 17:56:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 13510367 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1CBAA1CA93 for ; Wed, 3 Jan 2024 17:56:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="VsVf2eQR" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704304606; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yhxCBgSLZHPX3qlWPiq1/Uy2w4KV5yaLt7JUXumxbS8=; b=VsVf2eQRR3eRvufmdyYTxEK+25XnMJGlGIHES7xTr+52JuWjDYRNCWZJ67VQUPl5307Yrm jHo5aXKYwjQ6+g7vLmyAd3YEK6BHovVDp7dB9bwbd7c9oMJrj7jHnj8R+I5Y97Xt2dSNHf 92wZa+sblKBIiTnGvbDYVtZvMY5K6Gw= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-62-qWY9kGBLPe-KIdAdQkIOSw-1; Wed, 03 Jan 2024 12:56:45 -0500 X-MC-Unique: qWY9kGBLPe-KIdAdQkIOSw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A85DD3806736; Wed, 3 Jan 2024 17:56:44 +0000 (UTC) Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (bmarzins-01.fast.eng.rdu2.dc.redhat.com [10.6.23.12]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A1A6CC15968; Wed, 3 Jan 2024 17:56:44 +0000 (UTC) Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (localhost [127.0.0.1]) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.1/8.17.1) with ESMTPS id 403Hui3J018487 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 3 Jan 2024 12:56:44 -0500 Received: (from bmarzins@localhost) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.1/8.17.1/Submit) id 403Huigu018486; Wed, 3 Jan 2024 12:56:44 -0500 From: Benjamin Marzinski To: Christophe Varoqui Cc: device-mapper development , Martin Wilck Subject: [PATCH v2 05/18] libmultipath: make _dm_flush_map() return an enum Date: Wed, 3 Jan 2024 12:56:30 -0500 Message-ID: <20240103175643.18438-6-bmarzins@redhat.com> In-Reply-To: <20240103175643.18438-1-bmarzins@redhat.com> References: <20240103175643.18438-1-bmarzins@redhat.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com A future patch will add an additional return code, so make this an enum instead of just using numbers. Reviewed-by: Martin Wilck Signed-off-by: Benjamin Marzinski --- libmultipath/devmapper.c | 18 +++++++++--------- libmultipath/devmapper.h | 7 +++++++ multipath/main.c | 2 +- multipathd/main.c | 12 ++++++------ 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 1646110b..f5b4f4c0 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -1071,7 +1071,7 @@ int _dm_flush_map (const char * mapname, int need_sync, int deferred_remove, char *params = NULL; if (dm_is_mpath(mapname) != 1) - return 0; /* nothing to do */ + return DM_FLUSH_OK; /* nothing to do */ /* if the device currently has no partitions, do not run kpartx on it if you fail to delete it */ @@ -1081,7 +1081,7 @@ int _dm_flush_map (const char * mapname, int need_sync, int deferred_remove, /* If you aren't doing a deferred remove, make sure that no * devices are in use */ if (!do_deferred(deferred_remove) && partmap_in_use(mapname, NULL)) - return 1; + return DM_FLUSH_FAIL; if (need_suspend && dm_get_map(mapname, &mapsize, ¶ms) == DMP_OK && @@ -1096,11 +1096,11 @@ int _dm_flush_map (const char * mapname, int need_sync, int deferred_remove, params = NULL; if (dm_remove_partmaps(mapname, need_sync, deferred_remove)) - return 1; + return DM_FLUSH_FAIL; if (!do_deferred(deferred_remove) && dm_get_opencount(mapname)) { condlog(2, "%s: map in use", mapname); - return 1; + return DM_FLUSH_FAIL; } do { @@ -1114,14 +1114,14 @@ int _dm_flush_map (const char * mapname, int need_sync, int deferred_remove, && dm_map_present(mapname)) { condlog(4, "multipath map %s remove deferred", mapname); - return 2; + return DM_FLUSH_DEFERRED; } condlog(4, "multipath map %s removed", mapname); - return 0; + return DM_FLUSH_OK; } else if (dm_is_mpath(mapname) != 1) { condlog(4, "multipath map %s removed externally", mapname); - return 0; /*we raced with someone else removing it */ + return DM_FLUSH_OK; /* raced. someone else removed it */ } else { condlog(2, "failed to remove multipath map %s", mapname); @@ -1137,7 +1137,7 @@ int _dm_flush_map (const char * mapname, int need_sync, int deferred_remove, if (queue_if_no_path == 1) _dm_queue_if_no_path(mapname, 1); - return 1; + return DM_FLUSH_FAIL; } #ifdef LIBDM_API_DEFERRED @@ -1184,7 +1184,7 @@ int dm_flush_maps (int retries) goto out; do { - r |= dm_suspend_and_flush_map(names->name, retries); + r |= dm_suspend_and_flush_map(names->name, retries) != DM_FLUSH_OK; next = names->next; names = (void *) names + next; } while (next); diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h index 1eacd966..9d484dab 100644 --- a/libmultipath/devmapper.h +++ b/libmultipath/devmapper.h @@ -48,6 +48,13 @@ int dm_get_map(const char *, unsigned long long *, char **); int dm_get_status(const char *, char **); int dm_type(const char *, char *); int dm_is_mpath(const char *); + +enum { + DM_FLUSH_OK = 0, + DM_FLUSH_FAIL, + DM_FLUSH_DEFERRED, +}; + int _dm_flush_map (const char *, int, int, int, int); int dm_flush_map_nopaths(const char * mapname, int deferred_remove); #define dm_flush_map(mapname) _dm_flush_map(mapname, 1, 0, 0, 0) diff --git a/multipath/main.c b/multipath/main.c index c51884f2..00302087 100644 --- a/multipath/main.c +++ b/multipath/main.c @@ -1070,7 +1070,7 @@ main (int argc, char *argv[]) r = RTVL_FAIL; goto out; } - r = dm_suspend_and_flush_map(dev, retries) ? + r = (dm_suspend_and_flush_map(dev, retries) != DM_FLUSH_OK) ? RTVL_FAIL : RTVL_OK; goto out; } diff --git a/multipathd/main.c b/multipathd/main.c index 17468985..ed543caa 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -598,13 +598,13 @@ flush_map_nopaths(struct multipath *mpp, struct vectors *vecs) { dm_queue_if_no_path(mpp, 0); } r = dm_flush_map_nopaths(mpp->alias, mpp->deferred_remove); - if (r) { - if (r == 1) - condlog(0, "%s: can't flush", mpp->alias); - else { + if (r != DM_FLUSH_OK) { + if (r == DM_FLUSH_DEFERRED) { condlog(2, "%s: devmap deferred remove", mpp->alias); mpp->deferred_remove = DEFERRED_REMOVE_IN_PROGRESS; } + else + condlog(0, "%s: can't flush", mpp->alias); return false; } @@ -746,7 +746,7 @@ coalesce_maps(struct vectors *vecs, vector nmpv) * remove all current maps not allowed by the * current configuration */ - if (dm_flush_map(ompp->alias)) { + if (dm_flush_map(ompp->alias) != DM_FLUSH_OK) { condlog(0, "%s: unable to flush devmap", ompp->alias); /* @@ -789,7 +789,7 @@ int flush_map(struct multipath * mpp, struct vectors * vecs) { int r = dm_suspend_and_flush_map(mpp->alias, 0); - if (r) { + if (r != DM_FLUSH_OK) { condlog(0, "%s: can't flush", mpp->alias); return r; } From patchwork Wed Jan 3 17:56:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 13510372 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E9751CA92 for ; Wed, 3 Jan 2024 17:56:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="DGHtVU7v" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704304608; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KGYNS4zat8gK4T/ximc2sUVpztjHmYVWb3SfSrG272g=; b=DGHtVU7vVT3smJXXqXOJuqWVXdfkQtX7LZgZm4lpprJfldP9AAFOj0RJE0AjAy+hN0NViT XHDm1Kt97EWzRlx4Kf0gpAsObOXxRf0OSGlqgACenfnJHuuhoW66ewCLCCJKAfQ6Xo1PY6 xRuqfljGuJ28Xg9vodcIG/OS1dtMwxk= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-649-lZBXUJF1PmqYpo6BeQgzVw-1; Wed, 03 Jan 2024 12:56:45 -0500 X-MC-Unique: lZBXUJF1PmqYpo6BeQgzVw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D82003C02746; Wed, 3 Jan 2024 17:56:44 +0000 (UTC) Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (unknown [10.6.23.12]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D0E7351D5; Wed, 3 Jan 2024 17:56:44 +0000 (UTC) Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (localhost [127.0.0.1]) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.1/8.17.1) with ESMTPS id 403HuiDP018491 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 3 Jan 2024 12:56:44 -0500 Received: (from bmarzins@localhost) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.1/8.17.1/Submit) id 403HuiUa018490; Wed, 3 Jan 2024 12:56:44 -0500 From: Benjamin Marzinski To: Christophe Varoqui Cc: device-mapper development , Martin Wilck Subject: [PATCH v2 06/18] libmultipath: make dm_remove_partmaps() a static function Date: Wed, 3 Jan 2024 12:56:31 -0500 Message-ID: <20240103175643.18438-7-bmarzins@redhat.com> In-Reply-To: <20240103175643.18438-1-bmarzins@redhat.com> References: <20240103175643.18438-1-bmarzins@redhat.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com dm_remove_partmaps() is only used in devmapper.c, so make it static. It does need to be declared early, since remove_partmaps() and it call eachother. Reviewed-by: Martin Wilck Signed-off-by: Benjamin Marzinski --- libmultipath/devmapper.c | 4 +++- libmultipath/devmapper.h | 2 -- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index f5b4f4c0..73bb6fe7 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -53,6 +53,8 @@ static int dm_cancel_remove_partmaps(const char * mapname); #define __DR_UNUSED__ __attribute__((unused)) #endif +static int dm_remove_partmaps (const char * mapname, int need_sync, + int deferred_remove); static int do_foreach_partmaps(const char * mapname, int (*partmap_func)(const char *, void *), void *data); @@ -1544,7 +1546,7 @@ remove_partmap(const char *name, void *data) return 0; } -int +static int dm_remove_partmaps (const char * mapname, int need_sync, int deferred_remove) { struct remove_data rd = { need_sync, deferred_remove }; diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h index 9d484dab..3fc8473b 100644 --- a/libmultipath/devmapper.h +++ b/libmultipath/devmapper.h @@ -74,8 +74,6 @@ int dm_geteventnr (const char *name); int dm_is_suspended(const char *name); int dm_get_major_minor (const char *name, int *major, int *minor); char * dm_mapname(int major, int minor); -int dm_remove_partmaps (const char * mapname, int need_sync, - int deferred_remove); int dm_get_uuid(const char *name, char *uuid, int uuid_len); bool has_dm_info(const struct multipath *mpp); int dm_get_info (const char * mapname, struct dm_info *dmi); From patchwork Wed Jan 3 17:56:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 13510373 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5D2451CA9E for ; Wed, 3 Jan 2024 17:56:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="cvx+1nVZ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704304608; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xBhYSdcldw5FB+Ye9MZgYqTbal81qJbUvbq75C2zRJQ=; b=cvx+1nVZ/Z8FDssgmhmBAGCyUqHzeF5gI2BWR8sPFEVjzdwjwioM18gaBDS2KzclDtsa9M KYoLG/ngXvGcmFLBJgKHVFzx1Ha05Lx6SeWApQmHwsVsDS70ShG/sUftzUYo3DZ8/5oaNr A41olT+jl+anhLwEnbFPEw+jqtY2aWA= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-20-rR4SapXfNhCShRLl0QF0ag-1; Wed, 03 Jan 2024 12:56:45 -0500 X-MC-Unique: rR4SapXfNhCShRLl0QF0ag-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 04B1D882081; Wed, 3 Jan 2024 17:56:45 +0000 (UTC) Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (bmarzins-01.fast.eng.rdu2.dc.redhat.com [10.6.23.12]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F33E851D5; Wed, 3 Jan 2024 17:56:44 +0000 (UTC) Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (localhost [127.0.0.1]) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.1/8.17.1) with ESMTPS id 403HuiNV018495 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 3 Jan 2024 12:56:44 -0500 Received: (from bmarzins@localhost) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.1/8.17.1/Submit) id 403Hui3Q018494; Wed, 3 Jan 2024 12:56:44 -0500 From: Benjamin Marzinski To: Christophe Varoqui Cc: device-mapper development , Martin Wilck Subject: [PATCH v2 07/18] multipathd: always start failure replies with "fail\n" Date: Wed, 3 Jan 2024 12:56:32 -0500 Message-ID: <20240103175643.18438-8-bmarzins@redhat.com> In-Reply-To: <20240103175643.18438-1-bmarzins@redhat.com> References: <20240103175643.18438-1-bmarzins@redhat.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com When multipathd interactive commands fail for certain reasons, like timing out or incorrect permissions, they do not reply with "fail\n". Currently, multipath and multipathc expect that a reply other than "fail\n" means success. Instead, prefix all failure replies with "fail\n", and adapt multipath and multipathc to return failure for any reply starting with "fail\n". Signed-off-by: Benjamin Marzinski --- libdmmp/libdmmp.c | 6 +++--- multipath/main.c | 13 ++++++++++--- multipathd/uxclnt.c | 9 +++++++-- multipathd/uxlsnr.c | 12 +++++------- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/libdmmp/libdmmp.c b/libdmmp/libdmmp.c index 0025e66d..77f8a6a0 100644 --- a/libdmmp/libdmmp.c +++ b/libdmmp/libdmmp.c @@ -321,7 +321,7 @@ invoke: } } if ((*output != NULL) && - (strncmp(*output, "timeout", strlen("timeout")) == 0)) + (strncmp(*output, "fail\ntimeout", strlen("fail\ntimeout")) == 0)) flag_check_tmo = true; if (flag_check_tmo == true) { @@ -364,8 +364,8 @@ invoke: } if ((*output != NULL) && - strncmp(*output, "permission deny", - strlen("permission deny")) == 0) { + strncmp(*output, "fail\npermission deny", + strlen("fail\npermission deny")) == 0) { _error(ctx, "Permission deny, need to be root"); rc = DMMP_ERR_PERMISSION_DENY; goto out; diff --git a/multipath/main.c b/multipath/main.c index 00302087..48d684e3 100644 --- a/multipath/main.c +++ b/multipath/main.c @@ -804,10 +804,17 @@ int delegate_to_multipathd(enum mpath_cmds cmd, } if (reply != NULL && *reply != '\0') { - if (strcmp(reply, "fail\n")) + if (strncmp(reply, "fail\n", 5)) r = DELEGATE_OK; - if (r != NOT_DELEGATED && strcmp(reply, "ok\n")) - printf("%s", reply); + if (r != NOT_DELEGATED && strcmp(reply, "ok\n")) { + /* If there is additional failure information, skip the + * initial 'fail' */ + if (strncmp(reply, "fail\n", 5) == 0 && + strlen(reply) > 5) + printf("%s", reply + 5); + else + printf("%s", reply); + } } out: diff --git a/multipathd/uxclnt.c b/multipathd/uxclnt.c index c3ae5db6..16133a88 100644 --- a/multipathd/uxclnt.c +++ b/multipathd/uxclnt.c @@ -30,8 +30,13 @@ static int process_req(int fd, char * inbuf, unsigned int timeout) printf("error %d receiving packet\n", ret); return 1; } else { - printf("%s", reply); - ret = (strcmp(reply, "fail\n") == 0); + ret = (strncmp(reply, "fail\n", 5) == 0); + /* If there is additional failure information, skip the + * initial 'fail' */ + if (ret && strlen(reply) > 5) + printf("%s", reply + 5); + else + printf("%s", reply); free(reply); return ret; } diff --git a/multipathd/uxlsnr.c b/multipathd/uxlsnr.c index 4d6f258c..4df01666 100644 --- a/multipathd/uxlsnr.c +++ b/multipathd/uxlsnr.c @@ -392,6 +392,11 @@ static void drain_idle_fd(int fd) void default_reply(struct client *c, int r) { + if (r == 0) { + append_strbuf_str(&c->reply, "ok\n"); + return; + } + append_strbuf_str(&c->reply, "fail\n"); switch(r) { case -EINVAL: case -ESRCH: @@ -406,13 +411,6 @@ void default_reply(struct client *c, int r) case -ETIMEDOUT: append_strbuf_str(&c->reply, "timeout\n"); break; - case 0: - append_strbuf_str(&c->reply, "ok\n"); - break; - default: - /* cli_handler functions return 1 on unspecified error */ - append_strbuf_str(&c->reply, "fail\n"); - break; } } From patchwork Wed Jan 3 17:56:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 13510374 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AB2D71CA9F for ; Wed, 3 Jan 2024 17:56:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="g1zQwgNx" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704304608; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qVBCq0r1r1X7ROm+Wh0M0dhgIBpKXO/cvyxNEUWj0SA=; b=g1zQwgNxyq7EDOavvalYupelidxrBQq2vj0z9dZ4czfN5Yc5JufMzTme8PF+6SV9BOsWa1 qbbdTOre6CJgmP9cNvhT7Fe3GuaCZ+HhOddmc1qOPQSqU5R1MQ/tFGk2y4dtXKYZwu0BhB v/a/9/BVzoVvGI85+TWXwLtBkFELyKQ= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-365-IZSPBgdTOQuAu5gy-FsN8w-1; Wed, 03 Jan 2024 12:56:45 -0500 X-MC-Unique: IZSPBgdTOQuAu5gy-FsN8w-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3070885A58A; Wed, 3 Jan 2024 17:56:45 +0000 (UTC) Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (unknown [10.6.23.12]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2A05D2026D66; Wed, 3 Jan 2024 17:56:45 +0000 (UTC) Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (localhost [127.0.0.1]) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.1/8.17.1) with ESMTPS id 403HuiTh018499 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 3 Jan 2024 12:56:45 -0500 Received: (from bmarzins@localhost) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.1/8.17.1/Submit) id 403HuioI018498; Wed, 3 Jan 2024 12:56:44 -0500 From: Benjamin Marzinski To: Christophe Varoqui Cc: device-mapper development , Martin Wilck Subject: [PATCH v2 08/18] multipathd: print extra default reply msg for busy devices Date: Wed, 3 Jan 2024 12:56:33 -0500 Message-ID: <20240103175643.18438-9-bmarzins@redhat.com> In-Reply-To: <20240103175643.18438-1-bmarzins@redhat.com> References: <20240103175643.18438-1-bmarzins@redhat.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com If removing a multipath device fails because the device is in use, return DM_FLUSH_BUSY from remove_functions, which causes cli_del_map() to return -EBUSY, which will now print extra information in default_reply(). Reviewed-by: Martin Wilck Signed-off-by: Benjamin Marzinski --- libmultipath/devmapper.c | 14 +++++++------- libmultipath/devmapper.h | 1 + multipathd/cli_handlers.c | 9 ++++++++- multipathd/uxlsnr.c | 3 +++ 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 73bb6fe7..6bbe784d 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -1083,7 +1083,7 @@ int _dm_flush_map (const char * mapname, int need_sync, int deferred_remove, /* If you aren't doing a deferred remove, make sure that no * devices are in use */ if (!do_deferred(deferred_remove) && partmap_in_use(mapname, NULL)) - return DM_FLUSH_FAIL; + return DM_FLUSH_BUSY; if (need_suspend && dm_get_map(mapname, &mapsize, ¶ms) == DMP_OK && @@ -1097,12 +1097,12 @@ int _dm_flush_map (const char * mapname, int need_sync, int deferred_remove, free(params); params = NULL; - if (dm_remove_partmaps(mapname, need_sync, deferred_remove)) - return DM_FLUSH_FAIL; + if ((r = dm_remove_partmaps(mapname, need_sync, deferred_remove))) + return r; if (!do_deferred(deferred_remove) && dm_get_opencount(mapname)) { condlog(2, "%s: map in use", mapname); - return DM_FLUSH_FAIL; + return DM_FLUSH_BUSY; } do { @@ -1506,7 +1506,7 @@ do_foreach_partmaps (const char * mapname, (p = strstr(params, dev_t)) && !isdigit(*(p + strlen(dev_t))) ) { - if (partmap_func(names->name, data) != 0) + if ((r = partmap_func(names->name, data)) != 0) goto out; } @@ -1538,12 +1538,12 @@ remove_partmap(const char *name, void *data) if (!do_deferred(rd->deferred_remove) && dm_get_opencount(name)) { condlog(2, "%s: map in use", name); - return 1; + return DM_FLUSH_BUSY; } } condlog(4, "partition map %s removed", name); dm_device_remove(name, rd->need_sync, rd->deferred_remove); - return 0; + return DM_FLUSH_OK; } static int diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h index 3fc8473b..fa9c6114 100644 --- a/libmultipath/devmapper.h +++ b/libmultipath/devmapper.h @@ -53,6 +53,7 @@ enum { DM_FLUSH_OK = 0, DM_FLUSH_FAIL, DM_FLUSH_DEFERRED, + DM_FLUSH_BUSY, }; int _dm_flush_map (const char *, int, int, int, int); diff --git a/multipathd/cli_handlers.c b/multipathd/cli_handlers.c index 9a0cd065..b49bc73a 100644 --- a/multipathd/cli_handlers.c +++ b/multipathd/cli_handlers.c @@ -31,6 +31,7 @@ #include "foreign.h" #include "strbuf.h" #include "cli_handlers.h" +#include "devmapper.h" static int show_paths (struct strbuf *reply, struct vectors *vecs, char *style, int pretty) @@ -743,6 +744,7 @@ cli_del_map (void * v, struct strbuf *reply, void * data) struct vectors * vecs = (struct vectors *)data; char * param = get_keyparam(v, KEY_MAP); struct multipath *mpp; + int r; param = convert_dev(param, 0); condlog(2, "%s: remove map (operator)", param); @@ -752,7 +754,12 @@ cli_del_map (void * v, struct strbuf *reply, void * data) if (!mpp) return 1; - return flush_map(mpp, vecs); + r = flush_map(mpp, vecs); + if (r == DM_FLUSH_OK) + return 0; + else if (r == DM_FLUSH_BUSY) + return -EBUSY; + return 1; } static int diff --git a/multipathd/uxlsnr.c b/multipathd/uxlsnr.c index 4df01666..707ed396 100644 --- a/multipathd/uxlsnr.c +++ b/multipathd/uxlsnr.c @@ -411,6 +411,9 @@ void default_reply(struct client *c, int r) case -ETIMEDOUT: append_strbuf_str(&c->reply, "timeout\n"); break; + case -EBUSY: + append_strbuf_str(&c->reply, "map or partition in use\n"); + break; } } From patchwork Wed Jan 3 17:56:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 13510375 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 005351CAA1 for ; Wed, 3 Jan 2024 17:56:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="iweLhq6a" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704304608; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ombRiu7Dq+zCsEA/IMbGWcQEYF7RlL4qaz5togIAiH4=; b=iweLhq6aAFJJ8gvFsFnWh90gDuhilgVMepHCRaE8ZCSvSOex31sKeiLYTyqLVRxriL6r7Y QdPU4vQ06ZidGyuvri8TMsjrk2C+9oJ/e7n3lKwRtVn2Ev5lTT7x3E0Sw7tziXlVVbemQF TEYitc514lye+5Ci5ipx1KKvlsulr6U= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-113-kghPIZVLO7CXPEH1Sdb2uQ-1; Wed, 03 Jan 2024 12:56:45 -0500 X-MC-Unique: kghPIZVLO7CXPEH1Sdb2uQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 570E2882082; Wed, 3 Jan 2024 17:56:45 +0000 (UTC) Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (bmarzins-01.fast.eng.rdu2.dc.redhat.com [10.6.23.12]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 511EE51D5; Wed, 3 Jan 2024 17:56:45 +0000 (UTC) Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (localhost [127.0.0.1]) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.1/8.17.1) with ESMTPS id 403Huj8V018503 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 3 Jan 2024 12:56:45 -0500 Received: (from bmarzins@localhost) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.1/8.17.1/Submit) id 403HujMm018502; Wed, 3 Jan 2024 12:56:45 -0500 From: Benjamin Marzinski To: Christophe Varoqui Cc: device-mapper development , Martin Wilck Subject: [PATCH v2 09/18] multipathd: handle busy devices in cli_del_maps() Date: Wed, 3 Jan 2024 12:56:34 -0500 Message-ID: <20240103175643.18438-10-bmarzins@redhat.com> In-Reply-To: <20240103175643.18438-1-bmarzins@redhat.com> References: <20240103175643.18438-1-bmarzins@redhat.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Make cli_del_maps() return -EBUSY like cli_del_map() if it fails because a device is in use and it doesn't run into any other type of failures. Reviewed-by: Martin Wilck Signed-off-by: Benjamin Marzinski --- libmultipath/devmapper.c | 10 +++++++--- multipath/main.c | 3 ++- multipathd/cli_handlers.c | 19 +++++++++++++------ 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 6bbe784d..e970e71b 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -1163,7 +1163,7 @@ dm_flush_map_nopaths(const char * mapname, int dm_flush_maps (int retries) { - int r = 1; + int r = DM_FLUSH_FAIL; struct dm_task *dmt; struct dm_names *names; unsigned next = 0; @@ -1181,12 +1181,16 @@ int dm_flush_maps (int retries) if (!(names = dm_task_get_names (dmt))) goto out; - r = 0; + r = DM_FLUSH_OK; if (!names->dev) goto out; do { - r |= dm_suspend_and_flush_map(names->name, retries) != DM_FLUSH_OK; + int ret; + ret = dm_suspend_and_flush_map(names->name, retries); + if (ret == DM_FLUSH_FAIL || + (r != DM_FLUSH_FAIL && ret == DM_FLUSH_BUSY)) + r = ret; next = names->next; names = (void *) names + next; } while (next); diff --git a/multipath/main.c b/multipath/main.c index 48d684e3..664f7b97 100644 --- a/multipath/main.c +++ b/multipath/main.c @@ -1082,7 +1082,8 @@ main (int argc, char *argv[]) goto out; } else if (cmd == CMD_FLUSH_ALL) { - r = dm_flush_maps(retries) ? RTVL_FAIL : RTVL_OK; + r = (dm_flush_maps(retries) != DM_FLUSH_OK) ? + RTVL_FAIL : RTVL_OK; goto out; } while ((r = configure(conf, cmd, dev_type, dev)) == RTVL_RETRY) diff --git a/multipathd/cli_handlers.c b/multipathd/cli_handlers.c index b49bc73a..af211a6b 100644 --- a/multipathd/cli_handlers.c +++ b/multipathd/cli_handlers.c @@ -767,18 +767,25 @@ cli_del_maps (void *v, struct strbuf *reply, void *data) { struct vectors * vecs = (struct vectors *)data; struct multipath *mpp; - int i, ret = 0; + int i, ret, r = 0; condlog(2, "remove maps (operator)"); vector_foreach_slot(vecs->mpvec, mpp, i) { - if (flush_map(mpp, vecs)) - ret++; - else + ret = flush_map(mpp, vecs); + if (ret == DM_FLUSH_OK) i--; + else if (ret == DM_FLUSH_BUSY && r != 1) + r = -EBUSY; + else + r = 1; } /* flush any multipath maps that aren't currently known by multipathd */ - ret |= dm_flush_maps(0); - return ret; + ret = dm_flush_maps(0); + if (ret == DM_FLUSH_BUSY && r != 1) + r = -EBUSY; + else if (ret != DM_FLUSH_OK) + r = 1; + return r; } static int From patchwork Wed Jan 3 17:56:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 13510382 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 041FD1CFBD for ; Wed, 3 Jan 2024 17:56:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="i9dm43wG" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704304612; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GAUx19JmRE/uMkubjUxEoWlwKTGdaXfBNQiV6IstKvc=; b=i9dm43wGDk7LL3VVt+PSYykuzGX7hLx3Rz/QCjXHCmniu95hBg6jwSNPCk4JZOPa/3Ex+V 9Ckdf28AMSkVcCnY+EH6OlrrYBDWkBByc6YAAUy/d166zSP/QRvB/EgDrmIT/UzBg24N3p 9/i0x46tPbRS6RJi8mGIIsPY0yKJYyM= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-367-3w3AMG_nMC29Cdectykyrg-1; Wed, 03 Jan 2024 12:56:45 -0500 X-MC-Unique: 3w3AMG_nMC29Cdectykyrg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 80B2E2823F62; Wed, 3 Jan 2024 17:56:45 +0000 (UTC) Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (unknown [10.6.23.12]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7B0251C060AF; Wed, 3 Jan 2024 17:56:45 +0000 (UTC) Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (localhost [127.0.0.1]) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.1/8.17.1) with ESMTPS id 403HujuI018507 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 3 Jan 2024 12:56:45 -0500 Received: (from bmarzins@localhost) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.1/8.17.1/Submit) id 403Huj1h018506; Wed, 3 Jan 2024 12:56:45 -0500 From: Benjamin Marzinski To: Christophe Varoqui Cc: device-mapper development , Martin Wilck Subject: [PATCH v2 10/18] libmultipath: print error when find_mp_by_str() fails. Date: Wed, 3 Jan 2024 12:56:35 -0500 Message-ID: <20240103175643.18438-11-bmarzins@redhat.com> In-Reply-To: <20240103175643.18438-1-bmarzins@redhat.com> References: <20240103175643.18438-1-bmarzins@redhat.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com None of the callers of find_mp_by_str() print any message if they fail because the map name is invalid. Print one in find_mp_by_str() to save the effort of adding it to all the callers. Signed-off-by: Benjamin Marzinski --- libmultipath/structs.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libmultipath/structs.c b/libmultipath/structs.c index 1b305fd1..74e31a13 100644 --- a/libmultipath/structs.c +++ b/libmultipath/structs.c @@ -480,11 +480,16 @@ struct multipath * find_mp_by_str (const struct _vector *mpvec, const char * str) { int minor; + struct multipath *mpp; if (sscanf(str, "dm-%d", &minor) == 1) - return find_mp_by_minor(mpvec, minor); + mpp = find_mp_by_minor(mpvec, minor); else - return find_mp_by_alias(mpvec, str); + mpp = find_mp_by_alias(mpvec, str); + + if (!mpp) + condlog(2, "%s: invalid map name.", str); + return mpp; } struct path * From patchwork Wed Jan 3 17:56:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 13510376 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E56A1CAA8 for ; Wed, 3 Jan 2024 17:56:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="erFWvBhk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704304609; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=D1vfM914ox/W2LeZJt2N5yFmgYa7TQ27CAuUDIP0ezw=; b=erFWvBhk9Ixh6GNTbszdGiymIMkrbQO8ii2DmNzEwD/vf8fAIs31f21WRRfXA9CNxr3Y36 OfsiyromQX/2eMqdT8Oly3wubeJVjhyoVZBPo7olxol0In+QL1R0r+Plq5AlcLsSNF+Qkl 29rVOH6oWS3zN+cwFlppUZNsdDgk8uM= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-644-yMpFUY2ANGW_yVfPM4XbxQ-1; Wed, 03 Jan 2024 12:56:46 -0500 X-MC-Unique: yMpFUY2ANGW_yVfPM4XbxQ-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A632B859B81; Wed, 3 Jan 2024 17:56:45 +0000 (UTC) Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (bmarzins-01.fast.eng.rdu2.dc.redhat.com [10.6.23.12]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A07A9492BC6; Wed, 3 Jan 2024 17:56:45 +0000 (UTC) Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (localhost [127.0.0.1]) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.1/8.17.1) with ESMTPS id 403HujOd018511 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 3 Jan 2024 12:56:45 -0500 Received: (from bmarzins@localhost) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.1/8.17.1/Submit) id 403Hujp7018510; Wed, 3 Jan 2024 12:56:45 -0500 From: Benjamin Marzinski To: Christophe Varoqui Cc: device-mapper development , Martin Wilck Subject: [PATCH v2 11/18] multipathd: don't open code find_mp_by_str() in client handers Date: Wed, 3 Jan 2024 12:56:36 -0500 Message-ID: <20240103175643.18438-12-bmarzins@redhat.com> In-Reply-To: <20240103175643.18438-1-bmarzins@redhat.com> References: <20240103175643.18438-1-bmarzins@redhat.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com multiple client handlers simply open coded find_mp_by_str(). Just use the function instead. Reviewed-by: Martin Wilck Signed-off-by: Benjamin Marzinski --- multipathd/cli_handlers.c | 53 +++++++++------------------------------ 1 file changed, 12 insertions(+), 41 deletions(-) diff --git a/multipathd/cli_handlers.c b/multipathd/cli_handlers.c index af211a6b..21fb9dd3 100644 --- a/multipathd/cli_handlers.c +++ b/multipathd/cli_handlers.c @@ -794,19 +794,14 @@ cli_reload(void *v, struct strbuf *reply, void *data) struct vectors * vecs = (struct vectors *)data; char * mapname = get_keyparam(v, KEY_MAP); struct multipath *mpp; - int minor; mapname = convert_dev(mapname, 0); condlog(2, "%s: reload map (operator)", mapname); - if (sscanf(mapname, "dm-%d", &minor) == 1) - mpp = find_mp_by_minor(vecs->mpvec, minor); - else - mpp = find_mp_by_alias(vecs->mpvec, mapname); + mpp = find_mp_by_str(vecs->mpvec, mapname); - if (!mpp) { - condlog(0, "%s: invalid map name. cannot reload", mapname); + if (!mpp) return 1; - } + if (mpp->wait_for_udev) { condlog(2, "%s: device not fully created, failing reload", mpp->alias); @@ -822,7 +817,6 @@ cli_resize(void *v, struct strbuf *reply, void *data) struct vectors * vecs = (struct vectors *)data; char * mapname = get_keyparam(v, KEY_MAP); struct multipath *mpp; - int minor; unsigned long long size = 0; struct pathgroup *pgp; struct path *pp; @@ -831,15 +825,10 @@ cli_resize(void *v, struct strbuf *reply, void *data) mapname = convert_dev(mapname, 0); condlog(2, "%s: resize map (operator)", mapname); - if (sscanf(mapname, "dm-%d", &minor) == 1) - mpp = find_mp_by_minor(vecs->mpvec, minor); - else - mpp = find_mp_by_alias(vecs->mpvec, mapname); + mpp = find_mp_by_str(vecs->mpvec, mapname); - if (!mpp) { - condlog(0, "%s: invalid map name. cannot resize", mapname); + if (!mpp) return 1; - } if (mpp->wait_for_udev) { condlog(2, "%s: device not fully created, failing resize", @@ -916,20 +905,14 @@ cli_restore_queueing(void *v, struct strbuf *reply, void *data) struct vectors * vecs = (struct vectors *)data; char * mapname = get_keyparam(v, KEY_MAP); struct multipath *mpp; - int minor; struct config *conf; mapname = convert_dev(mapname, 0); condlog(2, "%s: restore map queueing (operator)", mapname); - if (sscanf(mapname, "dm-%d", &minor) == 1) - mpp = find_mp_by_minor(vecs->mpvec, minor); - else - mpp = find_mp_by_alias(vecs->mpvec, mapname); + mpp = find_mp_by_str(vecs->mpvec, mapname); - if (!mpp) { - condlog(0, "%s: invalid map name, cannot restore queueing", mapname); + if (!mpp) return 1; - } if (mpp->disable_queueing) { mpp->disable_queueing = 0; @@ -973,19 +956,13 @@ cli_disable_queueing(void *v, struct strbuf *reply, void *data) struct vectors * vecs = (struct vectors *)data; char * mapname = get_keyparam(v, KEY_MAP); struct multipath *mpp; - int minor; mapname = convert_dev(mapname, 0); condlog(2, "%s: disable map queueing (operator)", mapname); - if (sscanf(mapname, "dm-%d", &minor) == 1) - mpp = find_mp_by_minor(vecs->mpvec, minor); - else - mpp = find_mp_by_alias(vecs->mpvec, mapname); + mpp = find_mp_by_str(vecs->mpvec, mapname); - if (!mpp) { - condlog(0, "%s: invalid map name, cannot disable queueing", mapname); + if (!mpp) return 1; - } if (count_active_paths(mpp) == 0) mpp->stat_map_failures++; @@ -1462,22 +1439,16 @@ static int cli_unset_all_marginal(void * v, struct strbuf *reply, void * data) struct pathgroup * pgp; struct path * pp; unsigned int i, j; - int minor; mapname = convert_dev(mapname, 0); condlog(2, "%s: unset all marginal paths (operator)", mapname); - if (sscanf(mapname, "dm-%d", &minor) == 1) - mpp = find_mp_by_minor(vecs->mpvec, minor); - else - mpp = find_mp_by_alias(vecs->mpvec, mapname); + mpp = find_mp_by_str(vecs->mpvec, mapname); - if (!mpp) { - condlog(0, "%s: invalid map name. " - "cannot unset marginal paths", mapname); + if (!mpp) return 1; - } + if (mpp->wait_for_udev) { condlog(2, "%s: device not fully created, " "failing unset all marginal", mpp->alias); From patchwork Wed Jan 3 17:56:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 13510377 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7F51C1CA93 for ; Wed, 3 Jan 2024 17:56:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="DtXRsTdB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704304609; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bvvWiv4tpC/ql7wtECdaLVX/NaYMRvjb8zNOyEYy4Q0=; b=DtXRsTdB87cnQjPoelaQ2HgtPqlHspKpfEkGnE+Mh4YIeFSXgPfAzjrjF3W302ddhqgvk6 qQK4AF6sNCxvc3e6zBQeZ1s2ZIVlRU76z5QDYAgYw3fIZZPTVlCGb7SgLP6IeHifJuou6G YMAuATOowiaduAYkVIg/UgREI/WemkQ= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-606-gLbqcypYOyWw4S_Ie5E00g-1; Wed, 03 Jan 2024 12:56:46 -0500 X-MC-Unique: gLbqcypYOyWw4S_Ie5E00g-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D0662882083; Wed, 3 Jan 2024 17:56:45 +0000 (UTC) Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (unknown [10.6.23.12]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CA93C2026D66; Wed, 3 Jan 2024 17:56:45 +0000 (UTC) Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (localhost [127.0.0.1]) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.1/8.17.1) with ESMTPS id 403HujnK018515 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 3 Jan 2024 12:56:45 -0500 Received: (from bmarzins@localhost) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.1/8.17.1/Submit) id 403Huj1b018514; Wed, 3 Jan 2024 12:56:45 -0500 From: Benjamin Marzinski To: Christophe Varoqui Cc: device-mapper development , Martin Wilck Subject: [PATCH v2 12/18] multipathd: make cli_handlers check for paths by dev and devt Date: Wed, 3 Jan 2024 12:56:37 -0500 Message-ID: <20240103175643.18438-13-bmarzins@redhat.com> In-Reply-To: <20240103175643.18438-1-bmarzins@redhat.com> References: <20240103175643.18438-1-bmarzins@redhat.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Some of the client handlers checked for paths by both dev and devt, but not all. Also, many of the client handlers don't print anything if they failed to find a path. Make all the client handlers which work on path devices use a new function, find_path_by_str(), which will try both methods to find a path, and can print out an error message if none is found. Signed-off-by: Benjamin Marzinski --- multipathd/cli_handlers.c | 40 ++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/multipathd/cli_handlers.c b/multipathd/cli_handlers.c index 21fb9dd3..6d5d53bc 100644 --- a/multipathd/cli_handlers.c +++ b/multipathd/cli_handlers.c @@ -33,6 +33,20 @@ #include "cli_handlers.h" #include "devmapper.h" +static struct path * +find_path_by_str(const struct _vector *pathvec, const char *str, + const char *action_str) +{ + struct path *pp; + + if (!(pp = find_path_by_devt(pathvec, str))) + pp = find_path_by_dev(pathvec, str); + + if (!pp && action_str) + condlog(2, "%s: invalid path name. cannot %s", str, action_str); + return pp; +} + static int show_paths (struct strbuf *reply, struct vectors *vecs, char *style, int pretty) { @@ -241,7 +255,7 @@ cli_list_path (void *v, struct strbuf *reply, void *data) param = convert_dev(param, 1); condlog(3, "%s: list path (operator)", param); - pp = find_path_by_dev(vecs->pathvec, param); + pp = find_path_by_str(vecs->pathvec, param, "list path"); if (!pp) return 1; @@ -556,7 +570,7 @@ cli_add_path (void *v, struct strbuf *reply, void *data) if (invalid) goto blacklisted; - pp = find_path_by_dev(vecs->pathvec, param); + pp = find_path_by_str(vecs->pathvec, param, NULL); if (pp && pp->initialized != INIT_REMOVED) { condlog(2, "%s: path already in pathvec", param); @@ -665,7 +679,7 @@ cli_del_path (void * v, struct strbuf *reply, void * data) param = convert_dev(param, 1); condlog(2, "%s: remove path (operator)", param); - pp = find_path_by_dev(vecs->pathvec, param); + pp = find_path_by_str(vecs->pathvec, param, NULL); if (!pp) { condlog(0, "%s: path already removed", param); return 1; @@ -1092,10 +1106,7 @@ cli_reinstate(void * v, struct strbuf *reply, void * data) struct path * pp; param = convert_dev(param, 1); - pp = find_path_by_dev(vecs->pathvec, param); - - if (!pp) - pp = find_path_by_devt(vecs->pathvec, param); + pp = find_path_by_str(vecs->pathvec, param, "reinstate path"); if (!pp || !pp->mpp || !pp->mpp->alias) return 1; @@ -1140,10 +1151,7 @@ cli_fail(void * v, struct strbuf *reply, void * data) int r; param = convert_dev(param, 1); - pp = find_path_by_dev(vecs->pathvec, param); - - if (!pp) - pp = find_path_by_devt(vecs->pathvec, param); + pp = find_path_by_str(vecs->pathvec, param, "fail path"); if (!pp || !pp->mpp || !pp->mpp->alias) return 1; @@ -1384,10 +1392,7 @@ static int cli_set_marginal(void * v, struct strbuf *reply, void * data) struct path * pp; param = convert_dev(param, 1); - pp = find_path_by_dev(vecs->pathvec, param); - - if (!pp) - pp = find_path_by_devt(vecs->pathvec, param); + pp = find_path_by_str(vecs->pathvec, param, "set marginal path"); if (!pp || !pp->mpp || !pp->mpp->alias) return 1; @@ -1411,10 +1416,7 @@ static int cli_unset_marginal(void * v, struct strbuf *reply, void * data) struct path * pp; param = convert_dev(param, 1); - pp = find_path_by_dev(vecs->pathvec, param); - - if (!pp) - pp = find_path_by_devt(vecs->pathvec, param); + pp = find_path_by_str(vecs->pathvec, param, "unset marginal path"); if (!pp || !pp->mpp || !pp->mpp->alias) return 1; From patchwork Wed Jan 3 17:56:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 13510368 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AF72D1CA97 for ; Wed, 3 Jan 2024 17:56:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Ie4kDgEf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704304607; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Z57tUbs0BXiG5sMi6MqdcM/tVeQWDTFYJW+WdHSDBe0=; b=Ie4kDgEfdMu93uviKcxAksnsZYa4+KVQLze+W6YWizmKGXxb8DxG3akAumm8rCGs/r/A/S DjlIpQccM5P+UwhIIwYwqjQbPhWjX0emm8GxLCtADUbWZYGRSv0RgRXCEwZCqqYILsPbQt ebNNTW0NMP2c0vElf0xw2CWMrOkIZGs= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-67-jE30Os3sNu2WZfuoc7RIPQ-1; Wed, 03 Jan 2024 12:56:46 -0500 X-MC-Unique: jE30Os3sNu2WZfuoc7RIPQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 031A785A58B; Wed, 3 Jan 2024 17:56:46 +0000 (UTC) Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (bmarzins-01.fast.eng.rdu2.dc.redhat.com [10.6.23.12]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F16E02026D66; Wed, 3 Jan 2024 17:56:45 +0000 (UTC) Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (localhost [127.0.0.1]) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.1/8.17.1) with ESMTPS id 403HujXp018519 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 3 Jan 2024 12:56:45 -0500 Received: (from bmarzins@localhost) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.1/8.17.1/Submit) id 403Hujrh018518; Wed, 3 Jan 2024 12:56:45 -0500 From: Benjamin Marzinski To: Christophe Varoqui Cc: device-mapper development , Martin Wilck Subject: [PATCH v2 13/18] multipathd: add cli_handler reply message for missing devs Date: Wed, 3 Jan 2024 12:56:38 -0500 Message-ID: <20240103175643.18438-14-bmarzins@redhat.com> In-Reply-To: <20240103175643.18438-1-bmarzins@redhat.com> References: <20240103175643.18438-1-bmarzins@redhat.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com When the cli_handlers cannot find the requested map or path, they will now return -ENODEV, which prints extra information in default_reply(). Reviewed-by: Martin Wilck Signed-off-by: Benjamin Marzinski --- multipathd/cli_handlers.c | 56 ++++++++++++++++++++++++--------------- multipathd/uxlsnr.c | 2 ++ 2 files changed, 36 insertions(+), 22 deletions(-) diff --git a/multipathd/cli_handlers.c b/multipathd/cli_handlers.c index 6d5d53bc..117570e1 100644 --- a/multipathd/cli_handlers.c +++ b/multipathd/cli_handlers.c @@ -257,7 +257,7 @@ cli_list_path (void *v, struct strbuf *reply, void *data) pp = find_path_by_str(vecs->pathvec, param, "list path"); if (!pp) - return 1; + return -ENODEV; return show_path(reply, vecs, pp, "%o"); } @@ -277,7 +277,7 @@ cli_list_map_topology (void *v, struct strbuf *reply, void *data) mpp = find_mp_by_str(vecs->mpvec, param); if (!mpp) - return 1; + return -ENODEV; condlog(3, "list multipath %s (operator)", param); @@ -305,7 +305,7 @@ cli_list_map_json (void *v, struct strbuf *reply, void *data) mpp = find_mp_by_str(vecs->mpvec, param); if (!mpp) - return 1; + return -ENODEV; condlog(3, "list multipath json %s (operator)", param); @@ -434,7 +434,7 @@ cli_list_map_fmt (void *v, struct strbuf *reply, void *data) param = convert_dev(param, 0); mpp = find_mp_by_str(vecs->mpvec, param); if (!mpp) - return 1; + return -ENODEV; condlog(3, "list map %s fmt %s (operator)", param, fmt); @@ -515,7 +515,7 @@ cli_reset_map_stats (void *v, struct strbuf *reply, void *data) mpp = find_mp_by_str(vecs->mpvec, param); if (!mpp) - return 1; + return -ENODEV; condlog(3, "reset multipath %s stats (operator)", param); reset_stats(mpp); @@ -682,7 +682,7 @@ cli_del_path (void * v, struct strbuf *reply, void * data) pp = find_path_by_str(vecs->pathvec, param, NULL); if (!pp) { condlog(0, "%s: path already removed", param); - return 1; + return -ENODEV; } ret = ev_remove_path(pp, vecs, 1); if (ret == REMOVE_PATH_DELAY) @@ -766,7 +766,7 @@ cli_del_map (void * v, struct strbuf *reply, void * data) mpp = find_mp_by_str(vecs->mpvec, param); if (!mpp) - return 1; + return -ENODEV; r = flush_map(mpp, vecs); if (r == DM_FLUSH_OK) @@ -814,7 +814,7 @@ cli_reload(void *v, struct strbuf *reply, void *data) mpp = find_mp_by_str(vecs->mpvec, mapname); if (!mpp) - return 1; + return -ENODEV; if (mpp->wait_for_udev) { condlog(2, "%s: device not fully created, failing reload", @@ -842,7 +842,7 @@ cli_resize(void *v, struct strbuf *reply, void *data) mpp = find_mp_by_str(vecs->mpvec, mapname); if (!mpp) - return 1; + return -ENODEV; if (mpp->wait_for_udev) { condlog(2, "%s: device not fully created, failing resize", @@ -926,7 +926,7 @@ cli_restore_queueing(void *v, struct strbuf *reply, void *data) mpp = find_mp_by_str(vecs->mpvec, mapname); if (!mpp) - return 1; + return -ENODEV; if (mpp->disable_queueing) { mpp->disable_queueing = 0; @@ -976,7 +976,7 @@ cli_disable_queueing(void *v, struct strbuf *reply, void *data) mpp = find_mp_by_str(vecs->mpvec, mapname); if (!mpp) - return 1; + return -ENODEV; if (count_active_paths(mpp) == 0) mpp->stat_map_failures++; @@ -1108,7 +1108,10 @@ cli_reinstate(void * v, struct strbuf *reply, void * data) param = convert_dev(param, 1); pp = find_path_by_str(vecs->pathvec, param, "reinstate path"); - if (!pp || !pp->mpp || !pp->mpp->alias) + if (!pp) + return -ENODEV; + + if (!pp->mpp || !pp->mpp->alias) return 1; condlog(2, "%s: reinstate path %s (operator)", @@ -1153,7 +1156,10 @@ cli_fail(void * v, struct strbuf *reply, void * data) param = convert_dev(param, 1); pp = find_path_by_str(vecs->pathvec, param, "fail path"); - if (!pp || !pp->mpp || !pp->mpp->alias) + if (!pp) + return -ENODEV; + + if (!pp->mpp || !pp->mpp->alias) return 1; condlog(2, "%s: fail path %s (operator)", @@ -1250,7 +1256,7 @@ cli_getprstatus (void * v, struct strbuf *reply, void * data) mpp = find_mp_by_str(vecs->mpvec, param); if (!mpp) - return 1; + return -ENODEV; append_strbuf_str(reply, prflag_str[mpp->prflag]); @@ -1270,7 +1276,7 @@ cli_setprstatus(void * v, struct strbuf *reply, void * data) mpp = find_mp_by_str(vecs->mpvec, param); if (!mpp) - return 1; + return -ENODEV; if (mpp->prflag != PRFLAG_SET) { mpp->prflag = PRFLAG_SET; @@ -1292,7 +1298,7 @@ cli_unsetprstatus(void * v, struct strbuf *reply, void * data) mpp = find_mp_by_str(vecs->mpvec, param); if (!mpp) - return 1; + return -ENODEV; if (mpp->prflag != PRFLAG_UNSET) { mpp->prflag = PRFLAG_UNSET; @@ -1315,7 +1321,7 @@ cli_getprkey(void * v, struct strbuf *reply, void * data) mpp = find_mp_by_str(vecs->mpvec, mapname); if (!mpp) - return 1; + return -ENODEV; key = get_be64(mpp->reservation_key); if (!key) { @@ -1343,7 +1349,7 @@ cli_unsetprkey(void * v, struct strbuf *reply, void * data) mpp = find_mp_by_str(vecs->mpvec, mapname); if (!mpp) - return 1; + return -ENODEV; conf = get_multipath_config(); pthread_cleanup_push(put_multipath_config, conf); @@ -1370,7 +1376,7 @@ cli_setprkey(void * v, struct strbuf *reply, void * data) mpp = find_mp_by_str(vecs->mpvec, mapname); if (!mpp) - return 1; + return -ENODEV; if (parse_prkey_flags(keyparam, &prkey, &flags) != 0) { condlog(0, "%s: invalid prkey : '%s'", mapname, keyparam); @@ -1394,7 +1400,10 @@ static int cli_set_marginal(void * v, struct strbuf *reply, void * data) param = convert_dev(param, 1); pp = find_path_by_str(vecs->pathvec, param, "set marginal path"); - if (!pp || !pp->mpp || !pp->mpp->alias) + if (!pp) + return -ENODEV; + + if (!pp->mpp || !pp->mpp->alias) return 1; condlog(2, "%s: set marginal path %s (operator)", @@ -1418,7 +1427,10 @@ static int cli_unset_marginal(void * v, struct strbuf *reply, void * data) param = convert_dev(param, 1); pp = find_path_by_str(vecs->pathvec, param, "unset marginal path"); - if (!pp || !pp->mpp || !pp->mpp->alias) + if (!pp) + return -ENODEV; + + if (!pp->mpp || !pp->mpp->alias) return 1; condlog(2, "%s: unset marginal path %s (operator)", @@ -1449,7 +1461,7 @@ static int cli_unset_all_marginal(void * v, struct strbuf *reply, void * data) mpp = find_mp_by_str(vecs->mpvec, mapname); if (!mpp) - return 1; + return -ENODEV; if (mpp->wait_for_udev) { condlog(2, "%s: device not fully created, " diff --git a/multipathd/uxlsnr.c b/multipathd/uxlsnr.c index 707ed396..185e0a0a 100644 --- a/multipathd/uxlsnr.c +++ b/multipathd/uxlsnr.c @@ -414,6 +414,8 @@ void default_reply(struct client *c, int r) case -EBUSY: append_strbuf_str(&c->reply, "map or partition in use\n"); break; + case -ENODEV: + append_strbuf_str(&c->reply, "device not found\n"); } } From patchwork Wed Jan 3 17:56:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 13510378 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F2AA1CAAC for ; Wed, 3 Jan 2024 17:56:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="EXpZBttg" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704304609; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Aff1zwaXEGFmrdc0zU3OfJTMHtYqr3RD135zu6+CG/E=; b=EXpZBttg6x+9Nu5Kptk1UQR9PbM/jFJc+wZYACpSsFOxHRii6OCcKplOqfRSKyERVjtoES ulDqD5wuR88IL5PDGBaaCr71jDuXvGOVhJoF5jZsAuUpUUn1z2cpq95iLn4jvfn8Ic53QO kLKOwp7AtXBwLN2oNeQDWFxECyXQrB0= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-477-oqnkDXQdMY6eEJHHWPHbcQ-1; Wed, 03 Jan 2024 12:56:46 -0500 X-MC-Unique: oqnkDXQdMY6eEJHHWPHbcQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2DCFA3C02746; Wed, 3 Jan 2024 17:56:46 +0000 (UTC) Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (unknown [10.6.23.12]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 26DBF24ED; Wed, 3 Jan 2024 17:56:46 +0000 (UTC) Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (localhost [127.0.0.1]) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.1/8.17.1) with ESMTPS id 403HujLe018523 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 3 Jan 2024 12:56:46 -0500 Received: (from bmarzins@localhost) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.1/8.17.1/Submit) id 403HujeG018522; Wed, 3 Jan 2024 12:56:45 -0500 From: Benjamin Marzinski To: Christophe Varoqui Cc: device-mapper development , Martin Wilck , Gris Ge Subject: [PATCH v2 14/18] libdmmp: handle failures in _process_cmd Date: Wed, 3 Jan 2024 12:56:39 -0500 Message-ID: <20240103175643.18438-15-bmarzins@redhat.com> In-Reply-To: <20240103175643.18438-1-bmarzins@redhat.com> References: <20240103175643.18438-1-bmarzins@redhat.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com currently, most of the callers of _process_cmd() do not gracefully handle the case where multipathd returns "fail\n". dmmp_flush_mpath() does, but it does extra work to try to figure out after the fact why the flush command failed. Instead, handle fail replies in _process_cmd() using the appropriate DMMP error codes. Cc: Gris Ge Reviewed-by: Martin Wilck Signed-off-by: Benjamin Marzinski --- libdmmp/libdmmp.c | 69 +++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 41 deletions(-) diff --git a/libdmmp/libdmmp.c b/libdmmp/libdmmp.c index 77f8a6a0..fcfba06e 100644 --- a/libdmmp/libdmmp.c +++ b/libdmmp/libdmmp.c @@ -354,22 +354,36 @@ invoke: _debug(ctx, "IPC timeout, but user requested timeout has not " "reached yet, still have %u milliseconds", ipc_tmo); goto invoke; - } else { - if ((*output == NULL) || (strlen(*output) == 0)) { - _error(ctx, "IPC return empty reply for command %s", - cmd); - rc = DMMP_ERR_IPC_ERROR; - goto out; - } } - - if ((*output != NULL) && - strncmp(*output, "fail\npermission deny", - strlen("fail\npermission deny")) == 0) { - _error(ctx, "Permission deny, need to be root"); - rc = DMMP_ERR_PERMISSION_DENY; + if ((*output == NULL) || (strlen(*output) == 0)) { + _error(ctx, "IPC return empty reply for command %s", + cmd); + rc = DMMP_ERR_IPC_ERROR; goto out; } + if (strncmp(*output, "fail\n", 5) == 0) { + if (strncmp(*output, "fail\npermission deny", + strlen("fail\npermission deny")) == 0) { + _error(ctx, "Permission deny, need to be root"); + rc = DMMP_ERR_PERMISSION_DENY; + goto out; + } + else if (strncmp(*output, "fail\nmap or partition in use", + strlen("fail\nmap or partition in use")) == 0) { + _error(ctx, "Specified mpath is in use"); + rc = DMMP_ERR_MPATH_BUSY; + goto out; + } + else if (strncmp(*output, "fail\ndevice not found", + strlen("fail\ndevice not found")) == 0) { + _error(ctx, "Specified mpath not found"); + rc = DMMP_ERR_MPATH_NOT_FOUND; + goto out; + } + _error(ctx, "Got unexpected error for cmd '%s': '%s'", + cmd, *output); + rc = DMMP_ERR_BUG; + } out: if (rc != DMMP_OK) { @@ -411,10 +425,6 @@ static int _ipc_connect(struct dmmp_context *ctx, int *fd) int dmmp_flush_mpath(struct dmmp_context *ctx, const char *mpath_name) { int rc = DMMP_OK; - struct dmmp_mpath **dmmp_mps = NULL; - uint32_t dmmp_mp_count = 0; - uint32_t i = 0; - bool found = false; int ipc_fd = -1; char cmd[_IPC_MAX_CMD_LEN]; char *output = NULL; @@ -433,29 +443,7 @@ int dmmp_flush_mpath(struct dmmp_context *ctx, const char *mpath_name) _good(_process_cmd(ctx, ipc_fd, cmd, &output), rc, out); /* _process_cmd() already make sure output is not NULL */ - - if (strncmp(output, "fail", strlen("fail")) == 0) { - /* Check whether specified mpath exits */ - _good(dmmp_mpath_array_get(ctx, &dmmp_mps, &dmmp_mp_count), - rc, out); - - for (i = 0; i < dmmp_mp_count; ++i) { - if (strcmp(dmmp_mpath_name_get(dmmp_mps[i]), - mpath_name) == 0) { - found = true; - break; - } - } - - if (found == false) { - rc = DMMP_ERR_MPATH_NOT_FOUND; - _error(ctx, "Specified mpath %s not found", mpath_name); - goto out; - } - - rc = DMMP_ERR_MPATH_BUSY; - _error(ctx, "Specified mpath is in use"); - } else if (strncmp(output, "ok", strlen("ok")) != 0) { + if (strncmp(output, "ok", strlen("ok")) != 0) { rc = DMMP_ERR_BUG; _error(ctx, "Got unexpected output for cmd '%s': '%s'", cmd, output); @@ -464,7 +452,6 @@ int dmmp_flush_mpath(struct dmmp_context *ctx, const char *mpath_name) out: if (ipc_fd >= 0) mpath_disconnect(ipc_fd); - dmmp_mpath_array_free(dmmp_mps, dmmp_mp_count); free(output); return rc; } From patchwork Wed Jan 3 17:56:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 13510381 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 86DAD1CFB6 for ; Wed, 3 Jan 2024 17:56:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="UmqHVa/U" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704304611; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=B+sya2l9P8r4JAApSXqmekbAz+o9L+g8LY/pYgUrhS0=; b=UmqHVa/Um2D6JHkCp/TxCG8YKeatHn2rNooNfqy85BuaKdfRvW+7zZE2kx9QKyfTgR3JmT 0NQJVME2A3kBf9zZZy++bmgsOJDMahifRLbG2dYK0dLDBjHaEyvcUx1BgwkDmdF5BlZiP3 tvFXi46/9/3XccnCCVFj/C7LzEN4Kt4= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-647-lCrIVPMiP5iXLIJpkWeajA-1; Wed, 03 Jan 2024 12:56:46 -0500 X-MC-Unique: lCrIVPMiP5iXLIJpkWeajA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 545973C02747; Wed, 3 Jan 2024 17:56:46 +0000 (UTC) Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (bmarzins-01.fast.eng.rdu2.dc.redhat.com [10.6.23.12]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4EE7359A; Wed, 3 Jan 2024 17:56:46 +0000 (UTC) Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (localhost [127.0.0.1]) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.1/8.17.1) with ESMTPS id 403HukHu018527 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 3 Jan 2024 12:56:46 -0500 Received: (from bmarzins@localhost) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.1/8.17.1/Submit) id 403Hukxr018526; Wed, 3 Jan 2024 12:56:46 -0500 From: Benjamin Marzinski To: Christophe Varoqui Cc: device-mapper development , Martin Wilck Subject: [PATCH v2 15/18] multipath: get rid of unnecessary retries variable Date: Wed, 3 Jan 2024 12:56:40 -0500 Message-ID: <20240103175643.18438-16-bmarzins@redhat.com> In-Reply-To: <20240103175643.18438-1-bmarzins@redhat.com> References: <20240103175643.18438-1-bmarzins@redhat.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com the -R option can just set conf->remove_retries directly. It has the same effect. Signed-off-by: Benjamin Marzinski --- multipath/main.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/multipath/main.c b/multipath/main.c index 664f7b97..d3b46f3e 100644 --- a/multipath/main.c +++ b/multipath/main.c @@ -834,7 +834,6 @@ main (int argc, char *argv[]) enum devtypes dev_type = DEV_NONE; char *dev = NULL; struct config *conf; - int retries = -1; bool enable_foreign = false; libmultipath_init(); @@ -944,7 +943,7 @@ main (int argc, char *argv[]) cmd = CMD_ADD_WWID; break; case 'R': - retries = atoi(optarg); + conf->remove_retries = atoi(optarg); break; case 'e': enable_foreign = true; @@ -1069,20 +1068,18 @@ main (int argc, char *argv[]) vector_free(curmp); goto out; } - if (retries < 0) - retries = conf->remove_retries; if (cmd == CMD_FLUSH_ONE) { if (dm_is_mpath(dev) != 1) { condlog(0, "%s is not a multipath device", dev); r = RTVL_FAIL; goto out; } - r = (dm_suspend_and_flush_map(dev, retries) != DM_FLUSH_OK) ? + r = (dm_suspend_and_flush_map(dev, conf->remove_retries) != DM_FLUSH_OK) ? RTVL_FAIL : RTVL_OK; goto out; } else if (cmd == CMD_FLUSH_ALL) { - r = (dm_flush_maps(retries) != DM_FLUSH_OK) ? + r = (dm_flush_maps(conf->remove_retries) != DM_FLUSH_OK) ? RTVL_FAIL : RTVL_OK; goto out; } From patchwork Wed Jan 3 17:56:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 13510380 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8022A1CF8F for ; Wed, 3 Jan 2024 17:56:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ebNybJUv" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704304610; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cLy/d9muCNEcWzMofb5efXrkIquHgUkmHHJliJ99pNA=; b=ebNybJUviEGMNgqd1KOHKj26l39I2NzZRWEkRtq7HnkESjNm3+FEenbPwBOTvDKZylbmGF 6iTpbE8WZ9B+JeFz5PUn6Mix4PmK4rS8lGEK7/pywRhh4jjazpbC6gDBEhlaZCTM9cDvs1 J9aNTarRkd27gpY8Jeuf0Kv84REwDwo= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-140-8InfbbjfMBCnKKfPcPYi-g-1; Wed, 03 Jan 2024 12:56:47 -0500 X-MC-Unique: 8InfbbjfMBCnKKfPcPYi-g-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7EB96185A784; Wed, 3 Jan 2024 17:56:46 +0000 (UTC) Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (unknown [10.6.23.12]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 789382166B31; Wed, 3 Jan 2024 17:56:46 +0000 (UTC) Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (localhost [127.0.0.1]) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.1/8.17.1) with ESMTPS id 403Hukqx018531 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 3 Jan 2024 12:56:46 -0500 Received: (from bmarzins@localhost) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.1/8.17.1/Submit) id 403Hukcn018530; Wed, 3 Jan 2024 12:56:46 -0500 From: Benjamin Marzinski To: Christophe Varoqui Cc: device-mapper development , Martin Wilck Subject: [PATCH v2 16/18] multipath: Don't locally retry deletgated remove failures Date: Wed, 3 Jan 2024 12:56:41 -0500 Message-ID: <20240103175643.18438-17-bmarzins@redhat.com> In-Reply-To: <20240103175643.18438-1-bmarzins@redhat.com> References: <20240103175643.18438-1-bmarzins@redhat.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Now that multipathd is running the same code to remove devices as multipath, multipath doesn't need to automatically retry the remove failures. Instead it now repeatedly calls delegate_to_multipathd() to handle any retries. Signed-off-by: Benjamin Marzinski --- multipath/main.c | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/multipath/main.c b/multipath/main.c index d3b46f3e..83dca8c0 100644 --- a/multipath/main.c +++ b/multipath/main.c @@ -741,15 +741,16 @@ get_dev_type(char *dev) { * It is safer to use equivalent multipathd client commands instead. */ enum { - DELEGATE_OK = 0, - DELEGATE_ERROR = -1, - NOT_DELEGATED = 1, + DELEGATE_OK, + DELEGATE_ERROR, + DELEGATE_RETRY, + NOT_DELEGATED, }; int delegate_to_multipathd(enum mpath_cmds cmd, __attribute__((unused)) const char *dev, __attribute__((unused)) enum devtypes dev_type, - const struct config *conf) + struct config *conf) { int fd; char command[1024], *p, *reply = NULL; @@ -767,17 +768,17 @@ int delegate_to_multipathd(enum mpath_cmds cmd, } else if (cmd == CMD_FLUSH_ONE && dev && dev_type == DEV_DEVMAP) { p += snprintf(p, n, "del map %s", dev); - /* multipathd doesn't try as hard, to avoid potentially - * hanging. If it fails, retry with the regular multipath - * command */ - r = NOT_DELEGATED; + if (conf->remove_retries > 0) { + r = DELEGATE_RETRY; + conf->remove_retries--; + } } else if (cmd == CMD_FLUSH_ALL) { p += snprintf(p, n, "del maps"); - /* multipathd doesn't try as hard, to avoid potentially - * hanging. If it fails, retry with the regular multipath - * command */ - r = NOT_DELEGATED; + if (conf->remove_retries > 0) { + r = DELEGATE_RETRY; + conf->remove_retries--; + } } /* Add other translations here */ @@ -806,7 +807,7 @@ int delegate_to_multipathd(enum mpath_cmds cmd, if (reply != NULL && *reply != '\0') { if (strncmp(reply, "fail\n", 5)) r = DELEGATE_OK; - if (r != NOT_DELEGATED && strcmp(reply, "ok\n")) { + if (r != DELEGATE_RETRY && strcmp(reply, "ok\n")) { /* If there is additional failure information, skip the * initial 'fail' */ if (strncmp(reply, "fail\n", 5) == 0 && @@ -1021,13 +1022,17 @@ main (int argc, char *argv[]) goto out; } - switch(delegate_to_multipathd(cmd, dev, dev_type, conf)) { - case DELEGATE_OK: - exit(RTVL_OK); - case DELEGATE_ERROR: - exit(RTVL_FAIL); - case NOT_DELEGATED: - break; + while (1) { + int ret = delegate_to_multipathd(cmd, dev, dev_type, conf); + + if (ret == DELEGATE_OK) + exit(RTVL_OK); + if (ret == DELEGATE_ERROR) + exit(RTVL_FAIL); + if (ret == DELEGATE_RETRY) + sleep(1); + else /* NOT_DELEGATED */ + break; } if (check_alias_settings(conf)) { From patchwork Wed Jan 3 17:56:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 13510384 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5947B1D52A for ; Wed, 3 Jan 2024 17:56:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Do/N93hy" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704304615; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bmSzjumFydib4cisLjjAa7aFI+P40nxKspcZwBTHxw4=; b=Do/N93hyPJTyHSxyQHMItr4jg5Zy/THms7OSlJyqb6EKw/feQ5HasY7bJjnMtzuXgdTOAC wFDxAH3rReRqJOd6aU6zLA2fTKmo0mAjFZz1EbU3RlgF0z8b7JYEVIXWbQkIOU80hvaTkA SPYkBO65PzzzAIvqO0CbWB3yaf/sVJ0= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-150-hL000VXFPfGE06-xfTf-vg-1; Wed, 03 Jan 2024 12:56:47 -0500 X-MC-Unique: hL000VXFPfGE06-xfTf-vg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A78EE185A781; Wed, 3 Jan 2024 17:56:46 +0000 (UTC) Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (bmarzins-01.fast.eng.rdu2.dc.redhat.com [10.6.23.12]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A21EE2166B31; Wed, 3 Jan 2024 17:56:46 +0000 (UTC) Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (localhost [127.0.0.1]) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.1/8.17.1) with ESMTPS id 403HukN4018535 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 3 Jan 2024 12:56:46 -0500 Received: (from bmarzins@localhost) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.1/8.17.1/Submit) id 403HukeQ018534; Wed, 3 Jan 2024 12:56:46 -0500 From: Benjamin Marzinski To: Christophe Varoqui Cc: device-mapper development , Martin Wilck Subject: [PATCH v2 17/18] multipath: if delegation times out mark as not delegated Date: Wed, 3 Jan 2024 12:56:42 -0500 Message-ID: <20240103175643.18438-18-bmarzins@redhat.com> In-Reply-To: <20240103175643.18438-1-bmarzins@redhat.com> References: <20240103175643.18438-1-bmarzins@redhat.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com If either mpath_process_cmd fails with ETIMEDOUT or the reply is "fail\ntimeout\n", failback to multipath local commands. Signed-off-by: Benjamin Marzinski --- multipath/main.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/multipath/main.c b/multipath/main.c index 83dca8c0..8cdc2f7d 100644 --- a/multipath/main.c +++ b/multipath/main.c @@ -799,6 +799,8 @@ int delegate_to_multipathd(enum mpath_cmds cmd, if (mpath_process_cmd(fd, command, &reply, conf->uxsock_timeout) == -1) { + if (errno == ETIMEDOUT) + r = NOT_DELEGATED; condlog(1, "error in multipath command %s: %s", command, strerror(errno)); goto out; @@ -807,6 +809,10 @@ int delegate_to_multipathd(enum mpath_cmds cmd, if (reply != NULL && *reply != '\0') { if (strncmp(reply, "fail\n", 5)) r = DELEGATE_OK; + else if (strcmp(reply, "fail\ntimeout\n") == 0) { + r = NOT_DELEGATED; + goto out; + } if (r != DELEGATE_RETRY && strcmp(reply, "ok\n")) { /* If there is additional failure information, skip the * initial 'fail' */ From patchwork Wed Jan 3 17:56:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 13510379 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 53BA41CF82 for ; Wed, 3 Jan 2024 17:56:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="CMrZ6z6W" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704304610; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RMdKCKGjPkyCzkE7JEj1b1nAr33Ea69zwS0wG2vkrAY=; b=CMrZ6z6WXetSeAbr/XZeBwi/qwH1FHY7AhzjRi+QlDSP556U2Lx1TAu5H9+k4A5Ds0rq3z TMk+SF7vPkR72DD7qFZJYSHA6K9ryLg3RyoUEFoVBrsfnQJlTO8Do4AvVadj/t382WAo3B pQlew3yvRaupOIz54sFZ0nkfcKliY08= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-159-rjXgLc8wNXasBpjgurvkaQ-1; Wed, 03 Jan 2024 12:56:47 -0500 X-MC-Unique: rjXgLc8wNXasBpjgurvkaQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CFA523C0274A; Wed, 3 Jan 2024 17:56:46 +0000 (UTC) Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (unknown [10.6.23.12]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C99D251D5; Wed, 3 Jan 2024 17:56:46 +0000 (UTC) Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (localhost [127.0.0.1]) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.1/8.17.1) with ESMTPS id 403HukO9018539 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 3 Jan 2024 12:56:46 -0500 Received: (from bmarzins@localhost) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.1/8.17.1/Submit) id 403Hukof018538; Wed, 3 Jan 2024 12:56:46 -0500 From: Benjamin Marzinski To: Christophe Varoqui Cc: device-mapper development , Martin Wilck Subject: [PATCH v2 18/18] multipathd: sync features on flush_map failure corner case Date: Wed, 3 Jan 2024 12:56:43 -0500 Message-ID: <20240103175643.18438-19-bmarzins@redhat.com> In-Reply-To: <20240103175643.18438-1-bmarzins@redhat.com> References: <20240103175643.18438-1-bmarzins@redhat.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com If dm_suspend_and_flush_map() disables queueing on a device, and then fails both to flush the device and restore queueing, the device will still have queue_if_no_path set in mpp->features, but not in reality. Fix this. Signed-off-by: Benjamin Marzinski --- libmultipath/devmapper.c | 4 ++-- libmultipath/devmapper.h | 1 + libmultipath/libmultipath.version | 3 ++- multipathd/main.c | 2 ++ 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index e970e71b..373d2e6c 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -1136,8 +1136,8 @@ int _dm_flush_map (const char * mapname, int need_sync, int deferred_remove, sleep(1); } while (retries-- > 0); - if (queue_if_no_path == 1) - _dm_queue_if_no_path(mapname, 1); + if (queue_if_no_path == 1 && _dm_queue_if_no_path(mapname, 1) != 0) + return DM_FLUSH_FAIL_CANT_RESTORE; return DM_FLUSH_FAIL; } diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h index fa9c6114..a7d66604 100644 --- a/libmultipath/devmapper.h +++ b/libmultipath/devmapper.h @@ -52,6 +52,7 @@ int dm_is_mpath(const char *); enum { DM_FLUSH_OK = 0, DM_FLUSH_FAIL, + DM_FLUSH_FAIL_CANT_RESTORE, DM_FLUSH_DEFERRED, DM_FLUSH_BUSY, }; diff --git a/libmultipath/libmultipath.version b/libmultipath/libmultipath.version index 8ab7c802..df2c0fff 100644 --- a/libmultipath/libmultipath.version +++ b/libmultipath/libmultipath.version @@ -43,7 +43,7 @@ LIBMPATHCOMMON_1.0.0 { put_multipath_config; }; -LIBMULTIPATH_22.0.0 { +LIBMULTIPATH_23.0.0 { global: /* symbols referenced by multipath and multipathd */ add_foreign; @@ -151,6 +151,7 @@ global: _print_multipath_topology; reinstate_paths; remember_wwid; + remove_feature; remove_map; remove_map_by_alias; remove_map_callback; diff --git a/multipathd/main.c b/multipathd/main.c index ed543caa..13cb404d 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -790,6 +790,8 @@ flush_map(struct multipath * mpp, struct vectors * vecs) { int r = dm_suspend_and_flush_map(mpp->alias, 0); if (r != DM_FLUSH_OK) { + if (DM_FLUSH_FAIL_CANT_RESTORE) + remove_feature(&mpp->features, "queue_if_no_path"); condlog(0, "%s: can't flush", mpp->alias); return r; }