From patchwork Fri Nov 22 21:11:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 13883620 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 DD1C24A0C for ; Fri, 22 Nov 2024 21:11:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732309901; cv=none; b=eJbzN3DS2Xl5QIXyNEt4OS/ECsU2ErVK3fGW0lBLBOQbkzj4gmjodg5njBcB0OdOCTuCGws4qBJ76JE7yjDN3Q9uBuQx1dBlZyy1pvPqrIZG+lqZQt0LxS28tAJz05dvblld1glrV3yJQ/jisAtxjh2fkYfZx2lYXpEqOJI7/Bo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732309901; c=relaxed/simple; bh=BIbleTl1rALtb1vpdiNnnt4ohbS+0rCK+99XAsi+Zyc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:content-type; b=CQlPsHA9J9Emi5jvnBUDonwkv5G7ZkQvq4MehGAdpV5QWv+1AjtzWdRUXJziN2NbAYW2xc6961BQKxeiCDXaJyDQ5AG6VlbLtlP0dfsQY+aKZ2jMqrz6rWLALkWpbKvGNRmIITZCjH2Af+muAUeEvQz5lM4WZzQFXh1J+nXoSaA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=FEGkOGMv; arc=none smtp.client-ip=170.10.133.124 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="FEGkOGMv" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732309898; 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=QggajM37qtosVAK+KZun23dB0z86nzctjqfIzCivRmg=; b=FEGkOGMv6HWmA5Zmj8kAbiiuiPkHU3+h2QYYsPjkrIU4YXLkJ9kTK7Ka3/bwaC6xIEgLHf gY92zxxFTtQMSwwiKzU/ogH5lEz/+/cPrQe/sLmaseD5mefRM3DuNPP5+75HYsPeEAb1Lk 7QzsVFtzSGBaPSgcltM0KXVfMNYHkZA= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-568-vi-pRilMNPKphfjsuZB7jA-1; Fri, 22 Nov 2024 16:11:37 -0500 X-MC-Unique: vi-pRilMNPKphfjsuZB7jA-1 X-Mimecast-MFC-AGG-ID: vi-pRilMNPKphfjsuZB7jA Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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 mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id F39CF19560BD; Fri, 22 Nov 2024 21:11:35 +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 mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 771511955F3E; Fri, 22 Nov 2024 21:11:35 +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.2/8.17.1) with ESMTPS id 4AMLBYWT718887 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 22 Nov 2024 16:11:34 -0500 Received: (from bmarzins@localhost) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.2/8.17.2/Submit) id 4AMLBY5S718886; Fri, 22 Nov 2024 16:11:34 -0500 From: Benjamin Marzinski To: Christophe Varoqui Cc: device-mapper development , Martin Wilck Subject: [PATCH v2 01/13] libmultipath: signal device with no table in libmp_mapinfo Date: Fri, 22 Nov 2024 16:11:21 -0500 Message-ID: <20241122211133.718861-2-bmarzins@redhat.com> In-Reply-To: <20241122211133.718861-1-bmarzins@redhat.com> References: <20241122211133.718861-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.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 1C1WeDFpc8DD7d5UKEa5be42FDlixSndkCAtCHH7n1k_1732309896 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true if libmp_mapinfo() is run on a device that has no active table, it will now return with a new exit code, DMP_EMPTY, to signal this. Currently all code paths treat this identically to DMP_NOT_FOUND. Signed-off-by: Benjamin Marzinski --- libmultipath/devmapper.c | 6 ++++-- libmultipath/devmapper.h | 7 ++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 224be512..33425d02 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -86,6 +86,7 @@ const char *dmp_errstr(int rc) [DMP_OK] = "success", [DMP_NOT_FOUND] = "not found", [DMP_NO_MATCH] = "target type mismatch", + [DMP_EMPTY] = "no target", [DMP_LAST__] = "**invalid**", }; if (rc < 0 || rc > DMP_LAST__) @@ -747,9 +748,9 @@ static int libmp_mapinfo__(int flags, mapid_t id, mapinfo_t info, const char *ma condlog(lvl, "%s: map %s has multiple targets", fname__, map_id); return DMP_NO_MATCH; } - if (!params) { + if (!params || !target_type) { condlog(lvl, "%s: map %s has no targets", fname__, map_id); - return DMP_NOT_FOUND; + return DMP_EMPTY; } if (flags & MAPINFO_TGT_TYPE__) { const char *tgt_type = flags & MAPINFO_MPATH_ONLY ? TGT_MPATH : TGT_PART; @@ -873,6 +874,7 @@ int dm_is_mpath(const char *name) return DM_IS_MPATH_YES; case DMP_NOT_FOUND: case DMP_NO_MATCH: + case DMP_EMPTY: return DM_IS_MPATH_NO; case DMP_ERR: default: diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h index 6b3bbad9..23926e3f 100644 --- a/libmultipath/devmapper.h +++ b/libmultipath/devmapper.h @@ -35,6 +35,7 @@ enum { DMP_OK, DMP_NOT_FOUND, DMP_NO_MATCH, + DMP_EMPTY, DMP_LAST__, }; @@ -105,7 +106,11 @@ typedef struct libmp_map_info { * @returns: * DMP_OK if successful. * DMP_NOT_FOUND if the map wasn't found, or has no or multiple targets. - * DMP_NO_MATCH if the map didn't match @tgt_type (see above). + * DMP_NO_MATCH if the map didn't match @tgt_type (see above) or didn't + * have a multipath uuid prefix. + * DMP_EMPTY if the map has no table. Note. The check for matching uuid + * prefix will happen first, but the check for matching + * tgt_type will happen afterwards. * DMP_ERR if some other error occurred. * * This function obtains the requested information for the device-mapper map From patchwork Fri Nov 22 21:11:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 13883628 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 A05DF18784C for ; Fri, 22 Nov 2024 21:11:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732309904; cv=none; b=OvJW1KK2DUo4pDYB+p1NP6VpGr9AGBoS0cgx4D8UbMllm6FXtv0++UCs0L3KyfUc42VeYj1TlIQWzOzjGwfgUfz8toGtoNBWpb3Ow1GTtDJqvWVs0eRbHRWcB12PKynHo28VC6NwZqgD7433Lk54itmmxXAj1D52q0agCmv5+Rg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732309904; c=relaxed/simple; bh=P8I73uIvErG1CVcnSjIv84jZCfTY/0oo7ixlvdEfgIc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:content-type; b=WHidvoWKHoJ5fNKhoieBated9eW6rR3+tSUkz7DUCbcprT+2fGRwPtG/2zJBg8vqHXuE687JwXm3W4CPHESJYlwKdDPTVZhHQwRl2Zy36mXG9K1eTAl6fxi8mKMXjWkoWVkFH4miankuFYMKqeG1db6T6p3z/ZtwHX61yVz3XUk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=JgqZnVub; arc=none smtp.client-ip=170.10.129.124 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="JgqZnVub" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732309900; 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=KtO4U6DgST+uXeO+I3VPivYpV51EwBMvYq0UBnZN7d8=; b=JgqZnVub+euGTMhhc1hdi9kaWpQDQsUcgi8kqyMW6xrWz2tnWclIJsKN3wYDBFlOSnoB9R NLk7r6Kq/kyGN8uxGR3Xq+LYbY7h/nUDlXURF7FB5tjADGCj0RjmCq3nzKShrKi3BSECig 9qbTjRCxQrJqNFWw1d2Udk3bsLvPEOM= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-29-NxYjii1XNj6g2oR85OvXgw-1; Fri, 22 Nov 2024 16:11:37 -0500 X-MC-Unique: NxYjii1XNj6g2oR85OvXgw-1 X-Mimecast-MFC-AGG-ID: NxYjii1XNj6g2oR85OvXgw Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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 mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 42F42195609E; Fri, 22 Nov 2024 21:11:36 +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 mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BBE0E1955F43; Fri, 22 Nov 2024 21:11:35 +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.2/8.17.1) with ESMTPS id 4AMLBYTf718891 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 22 Nov 2024 16:11:34 -0500 Received: (from bmarzins@localhost) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.2/8.17.2/Submit) id 4AMLBYW1718890; Fri, 22 Nov 2024 16:11:34 -0500 From: Benjamin Marzinski To: Christophe Varoqui Cc: device-mapper development , Martin Wilck , Martin Wilck Subject: [PATCH v2 02/13] multipath-tools tests: fix mapinfo tests Date: Fri, 22 Nov 2024 16:11:22 -0500 Message-ID: <20241122211133.718861-3-bmarzins@redhat.com> In-Reply-To: <20241122211133.718861-1-bmarzins@redhat.com> References: <20241122211133.718861-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.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: P5Ts7rbOgnv-LYWnlSNwVuadPUPUXA7W0MX96eqRFoQ_1732309896 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true From: Martin Wilck Add tests for the check for empty table introduced in ("libmultipath: signal device with no table in libmp_mapinfo"). Signed-off-by: Martin Wilck Signed-off-by: Benjamin Marzinski --- tests/mapinfo.c | 49 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/tests/mapinfo.c b/tests/mapinfo.c index 4362cdb0..ee487989 100644 --- a/tests/mapinfo.c +++ b/tests/mapinfo.c @@ -47,11 +47,13 @@ static const struct dm_info __attribute__((unused)) MPATH_DMI_02 = { .exists = 1, .live_table = 0, .open_count = 1, - .target_count = 1, + .target_count = 0, .major = 254, .minor = 123, }; +#define TGT_ANY "any" + static const char MPATH_NAME_01[] = "mpathx"; static const char MPATH_UUID_01[] = "mpath-3600a098038302d414b2b4d4453474f62"; static const char MPATH_TARGET_01[] = @@ -858,7 +860,7 @@ static void test_mapinfo_good_size(void **state) mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 1, 0); WRAP_DM_TASK_GET_INFO(1); WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); - mock_dm_get_next_target(12345, NULL, MPATH_TARGET_01, NULL); + mock_dm_get_next_target(12345, TGT_ANY, MPATH_TARGET_01, NULL); rc = libmp_mapinfo(DM_MAP_BY_NAME, (mapid_t) { .str = "foo", }, (mapinfo_t) { .size = &size }); @@ -889,13 +891,13 @@ static void test_mapinfo_bad_next_target_02(void **state) mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 1, 0); WRAP_DM_TASK_GET_INFO(1); - WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_02); /* no targets */ - mock_dm_get_next_target(12345, NULL, NULL, NULL); + mock_dm_get_next_target(0, NULL, NULL, NULL); rc = libmp_mapinfo(DM_MAP_BY_NAME, (mapid_t) { .str = "foo", }, (mapinfo_t) { .size = &size }); - assert_int_equal(rc, DMP_NOT_FOUND); + assert_int_equal(rc, DMP_EMPTY); } /* libmp_mapinfo needs to do a DM_DEVICE_STATUS ioctl */ @@ -1049,6 +1051,39 @@ static void test_mapinfo_good_target_type_04(void **state) assert_true(!strcmp(uuid, MPATH_UUID_01)); } +static void test_mapinfo_no_table_01(void **state) +{ + int rc; + struct dm_info dmi = { .suspended = 0 }; + + mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + /* DMI with no live table, MAPINFO_CHECK_UUID not set */ + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_02); + mock_dm_get_next_target(0, NULL, NULL, NULL); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .dmi = &dmi }); + assert_int_equal(rc, DMP_EMPTY); +} + +static void test_mapinfo_no_table_02(void **state) +{ + int rc; + struct dm_info dmi = { .suspended = 0 }; + + mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + /* DMI with no live table, MAPINFO_CHECK_UUID set */ + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_02); + mock_dm_get_next_target(0, NULL, NULL, NULL); + will_return(__wrap_dm_task_get_uuid, MPATH_UUID_01); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_CHECK_UUID | MAPINFO_MPATH_ONLY, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .dmi = &dmi }); + assert_int_equal(rc, DMP_EMPTY); +} + static void test_mapinfo_good_status_01(void **state) { int rc; @@ -1142,7 +1177,7 @@ static void test_mapinfo_bad_task_run_11(void **state) mock_mapinfo_name_1(DM_DEVICE_TABLE, 1, "foo", 1, 1, 0); WRAP_DM_TASK_GET_INFO(1); WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); - mock_dm_get_next_target(12345, NULL, MPATH_TARGET_01, NULL); + mock_dm_get_next_target(12345, TGT_ANY, MPATH_TARGET_01, NULL); will_return(__wrap_strdup, 1); /* error in 2nd dm_task_run */ mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 0, EINVAL); @@ -1384,6 +1419,8 @@ static int test_mapinfo(void) cmocka_unit_test(test_mapinfo_good_target_type_02), cmocka_unit_test(test_mapinfo_good_target_type_03), cmocka_unit_test(test_mapinfo_good_target_type_04), + cmocka_unit_test(test_mapinfo_no_table_01), + cmocka_unit_test(test_mapinfo_no_table_02), cmocka_unit_test(test_mapinfo_good_status_01), cmocka_unit_test(test_mapinfo_bad_get_name_01), cmocka_unit_test(test_mapinfo_bad_get_uuid_01), From patchwork Fri Nov 22 21:11:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 13883624 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 B5802188580 for ; Fri, 22 Nov 2024 21:11:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732309903; cv=none; b=M1GQzO1POk/wNsqrfFTqLBbme6ib37/EdqEX5FbPPxUIVXVvEzWvBs09QKYKIAploTmyxKiO4CBOV3Ho2YSTh2Sas/jE+yIhFeTJRiGJOd5SIXvKNPn4XNHjMcsMaA0li0uCCqfKhXVmdjx8lrwvjo447lrz3d0TJm28KtpM8CY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732309903; c=relaxed/simple; bh=boR0IuzyuEJgNxHS9xoJA8fjjWDRC7sh01IvZcjq3OA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:content-type; b=mF2RaZV//RTkxeky6E82KNrKqv2Kur5m5DtXgeVUxOGtTaWKnyWXSf08xckx0Jdnq0Ykk2ZCIjCVvrU9zDnAoiquKr17SjLN/QFyFvMFAT0o1kyy18n+0yfy3Y6n4+Xk374PJLLpXLORqlwwSsaBLvQbOoaGevMGLS1N+mASEiA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=RGnrdAEC; arc=none smtp.client-ip=170.10.133.124 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="RGnrdAEC" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732309900; 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=HsSn7sfJM5IeHahWerf39KGIgkGEeVssK5uEoVLqQ+0=; b=RGnrdAEC4kMvggO+h85FVO9ROX5WUb+wzj0y9So3oErjnFqKR3AEZKmbD3n9Ojt1tj9vQ+ vATuXEpDw0fGWzu0aijz//UmwJnUcavmllRItH5FGZfnzplNglbo8uuwQWqXykqGQAtPBS Dpr6BP6ks0qLOQbp/GYV9ImxxUq6yF0= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-436-c5lA03i2MCeTXi-xmve4cA-1; Fri, 22 Nov 2024 16:11:37 -0500 X-MC-Unique: c5lA03i2MCeTXi-xmve4cA-1 X-Mimecast-MFC-AGG-ID: c5lA03i2MCeTXi-xmve4cA Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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 mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5E56C19560B1; Fri, 22 Nov 2024 21:11:36 +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 mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EE1AA1956086; Fri, 22 Nov 2024 21:11:35 +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.2/8.17.1) with ESMTPS id 4AMLBYvH718895 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 22 Nov 2024 16:11:34 -0500 Received: (from bmarzins@localhost) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.2/8.17.2/Submit) id 4AMLBYh1718894; Fri, 22 Nov 2024 16:11:34 -0500 From: Benjamin Marzinski To: Christophe Varoqui Cc: device-mapper development , Martin Wilck Subject: [PATCH v2 03/13] libmultipath: fix removing device after failed creation Date: Fri, 22 Nov 2024 16:11:23 -0500 Message-ID: <20241122211133.718861-4-bmarzins@redhat.com> In-Reply-To: <20241122211133.718861-1-bmarzins@redhat.com> References: <20241122211133.718861-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.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: NxJjICLati02DB9_qvh4u9HUJbbH4IIyvrmuhoBTus0_1732309896 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true dm_flush_nap_nosync() only removes a device if it has a multipath table. On failed removes, there is no table, so this function does nothing. Instead, if libmp_mapinfo() returns DMP_EMPTY, then there is an empty map, and it is removed using dm_device_remove(). Also, since there are no longer any callers of dm_flush_map_nosync(), remove it. Signed-off-by: Benjamin Marzinski --- libmultipath/devmapper.c | 7 +++++-- libmultipath/devmapper.h | 1 - 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 33425d02..42176667 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -557,9 +557,12 @@ int dm_addmap_create (struct multipath *mpp, char * params) * Failing the second part leaves an empty map. Clean it up. */ err = errno; - if (dm_map_present(mpp->alias)) { + if (libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY | + MAPINFO_CHECK_UUID, + (mapid_t) { .str = mpp->alias }, + (mapinfo_t) { .uuid = NULL }) == DMP_EMPTY) { condlog(3, "%s: failed to load map (a path might be in use)", mpp->alias); - dm_flush_map_nosync(mpp->alias); + dm_device_remove(mpp->alias, 0); } if (err != EROFS) { condlog(3, "%s: failed to load map, error %d", diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h index 23926e3f..0bd2b907 100644 --- a/libmultipath/devmapper.h +++ b/libmultipath/devmapper.h @@ -174,7 +174,6 @@ enum { int dm_flush_map__ (const char *mapname, int flags, int retries); #define dm_flush_map(mapname) dm_flush_map__(mapname, DMFL_NEED_SYNC, 0) -#define dm_flush_map_nosync(mapname) dm_flush_map__(mapname, DMFL_NONE, 0) #define dm_suspend_and_flush_map(mapname, retries) \ dm_flush_map__(mapname, DMFL_NEED_SYNC|DMFL_SUSPEND, retries) int dm_flush_map_nopaths(const char * mapname, int deferred_remove); From patchwork Fri Nov 22 21:11:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 13883626 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 A053C185936 for ; Fri, 22 Nov 2024 21:11:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732309903; cv=none; b=tblHI+L305K2Ze7LXX502XU1wRquQ1ux45gPcfisRPs3n7yA4qhr7Yk2g6Lh0HH/3xDrk27ZLKPeN/O5izh2oEV6VL0wniLPbMr6Apsg1eCR2IlBdzzoHiIAKNbgFudW4CudRrRaLCKSBsrssUrg1itwZg1dQUStlVjyh6Y32o0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732309903; c=relaxed/simple; bh=ZHEbH2zltBPlRUp9gFe/V7HuDPN8hjq5jMF0vgHfHIw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:content-type; b=Js2gqBxU6vk+E/Ytkv76icUQBfQpnI3a1nVMVyqF/q9GSofC0zMT0oWcMLshmwjVa4Cek1giqrKwk6Sv91CsIZZHnctwBCmMgEcy2L58qMgep2ijxmr58CP8IzYassA1QTcihgjZnVTwoXAP3SGghMtwSacN0m+U6UhKOp+GIeY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=RGTVexd2; arc=none smtp.client-ip=170.10.129.124 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="RGTVexd2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732309900; 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=0cBUyxg/lEmULLdMvyTi1lemOd67kYzhAOdr5NaelIo=; b=RGTVexd2y9wQRaDZAhd0kp7jJsSL6zc1DRuGueP0j/xwJfHkUbVC6eHtAbcogD9RsAuHXb KInuuo2Yxf4SsOjsfFnIU8yqdDB8OVLepZd1dMNxBq9pGmWjRjmePCYNJTTMyTwBljkcs8 ozoRlYZOygPLSOoqiygEFRwoiZfAfQQ= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-611-p_QZr7g1MbyvjFHg6y3Atw-1; Fri, 22 Nov 2024 16:11:37 -0500 X-MC-Unique: p_QZr7g1MbyvjFHg6y3Atw-1 X-Mimecast-MFC-AGG-ID: p_QZr7g1MbyvjFHg6y3Atw Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.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 mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 573BB1955F41; Fri, 22 Nov 2024 21:11:36 +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 mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 139D230000DF; Fri, 22 Nov 2024 21:11:35 +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.2/8.17.1) with ESMTPS id 4AMLBYHp718899 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 22 Nov 2024 16:11:34 -0500 Received: (from bmarzins@localhost) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.2/8.17.2/Submit) id 4AMLBY8J718898; Fri, 22 Nov 2024 16:11:34 -0500 From: Benjamin Marzinski To: Christophe Varoqui Cc: device-mapper development , Martin Wilck Subject: [PATCH v2 04/13] libmultipath: set uuid, name, and dmi if a device is found Date: Fri, 22 Nov 2024 16:11:24 -0500 Message-ID: <20241122211133.718861-5-bmarzins@redhat.com> In-Reply-To: <20241122211133.718861-1-bmarzins@redhat.com> References: <20241122211133.718861-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.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 1DfCS5X_QfDj0_suIEst4jvyf4DFWeSoCe7wmLekC8E_1732309896 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true Instead of only setting the uuid, name, and dmi on DMP_OK, return them whenever we find a device, even if that device doesn't match. To make the code simpler, we set these values before checks that could possibly return DMP_ERR. The only caller of libmp_mapinfo() that could update a multipath value incorrectly because of this is update_multipath_table(). Fix that. Signed-off-by: Benjamin Marzinski --- libmultipath/devmapper.c | 47 +++++++++++++++++++------------------- libmultipath/devmapper.h | 5 +++- libmultipath/structs_vec.c | 5 +++- tests/mapinfo.c | 45 +++++++++++++++++++++++++----------- 4 files changed, 63 insertions(+), 39 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 42176667..38c49bd5 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -736,6 +736,29 @@ static int libmp_mapinfo__(int flags, mapid_t id, mapinfo_t info, const char *ma && !(uuid = dm_task_get_uuid(dmt)))) return DMP_ERR; + if (info.name) { + strlcpy(info.name, name, WWID_SIZE); + condlog(4, "%s: %s: name: \"%s\"", fname__, map_id, info.name); + } + if (info.uuid) { + strlcpy(info.uuid, uuid, DM_UUID_LEN); + condlog(4, "%s: %s: uuid: \"%s\"", fname__, map_id, info.uuid); + } + + if (info.dmi) { + memcpy(info.dmi, &dmi, sizeof(*info.dmi)); + condlog(4, "%s: %s %d:%d, %d targets, %s table, %s, %s, %d opened, %u events", + fname__, map_id, + info.dmi->major, info.dmi->minor, + info.dmi->target_count, + info.dmi->live_table ? "live" : + info.dmi->inactive_table ? "inactive" : "no", + info.dmi->suspended ? "suspended" : "active", + info.dmi->read_only ? "ro" : "rw", + info.dmi->open_count, + info.dmi->event_nr); + } + if (flags & MAPINFO_CHECK_UUID && ((flags & MAPINFO_PART_ONLY && !is_mpath_part_uuid(uuid, NULL)) || (!(flags & MAPINFO_PART_ONLY) && !is_mpath_uuid(uuid)))) { @@ -768,40 +791,16 @@ static int libmp_mapinfo__(int flags, mapid_t id, mapinfo_t info, const char *ma /* * Check possible error conditions. - * If error is returned, don't touch any output parameters. */ if ((info.status && !(tmp_status = strdup(params))) || (info.target && !tmp_target && !(tmp_target = strdup(params)))) return DMP_ERR; - if (info.name) { - strlcpy(info.name, name, WWID_SIZE); - condlog(4, "%s: %s: name: \"%s\"", fname__, map_id, info.name); - } - if (info.uuid) { - strlcpy(info.uuid, uuid, DM_UUID_LEN); - condlog(4, "%s: %s: uuid: \"%s\"", fname__, map_id, info.uuid); - } - if (info.size) { *info.size = length; condlog(4, "%s: %s: size: %lld", fname__, map_id, *info.size); } - if (info.dmi) { - memcpy(info.dmi, &dmi, sizeof(*info.dmi)); - condlog(4, "%s: %s %d:%d, %d targets, %s table, %s, %s, %d opened, %u events", - fname__, map_id, - info.dmi->major, info.dmi->minor, - info.dmi->target_count, - info.dmi->live_table ? "live" : - info.dmi->inactive_table ? "inactive" : "no", - info.dmi->suspended ? "suspended" : "active", - info.dmi->read_only ? "ro" : "rw", - info.dmi->open_count, - info.dmi->event_nr); - } - if (info.target) { *info.target = steal_ptr(tmp_target); if (!tgt_set) diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h index 0bd2b907..4aeefad1 100644 --- a/libmultipath/devmapper.h +++ b/libmultipath/devmapper.h @@ -115,7 +115,10 @@ typedef struct libmp_map_info { * * This function obtains the requested information for the device-mapper map * identified by the input parameters. - * Output parameters are only filled in if the return value is DMP_OK. + * If non-NULL, the name, uuid, and dmi output paramters may be filled in for + * any return value besides DMP_NOT_FOUND and will always be filled in for + * return values other than DMP_NOT_FOUND and DMP_ERR. + * The other parameters are only filled in if the return value is DMP_OK. * For target / status / size information, the map's table should contain * only one target (usually multipath or linear). */ diff --git a/libmultipath/structs_vec.c b/libmultipath/structs_vec.c index 5df495b3..d22056ca 100644 --- a/libmultipath/structs_vec.c +++ b/libmultipath/structs_vec.c @@ -504,6 +504,8 @@ update_multipath_table (struct multipath *mpp, vector pathvec, int flags) int r = DMP_ERR; char __attribute__((cleanup(cleanup_charp))) *params = NULL; char __attribute__((cleanup(cleanup_charp))) *status = NULL; + /* only set the actual mpp->dmi if libmp_mapinfo returns DMP_OK */ + struct dm_info dmi; unsigned long long size; struct config *conf; @@ -522,7 +524,7 @@ update_multipath_table (struct multipath *mpp, vector pathvec, int flags) .target = ¶ms, .status = &status, .size = &mpp->size, - .dmi = &mpp->dmi, + .dmi = &dmi, }); if (r != DMP_OK) { @@ -531,6 +533,7 @@ update_multipath_table (struct multipath *mpp, vector pathvec, int flags) } else if (size != mpp->size) condlog(0, "%s: size changed from %llu to %llu", mpp->alias, size, mpp->size); + mpp->dmi = dmi; return update_multipath_table__(mpp, pathvec, flags, params, status); } diff --git a/tests/mapinfo.c b/tests/mapinfo.c index ee487989..36511607 100644 --- a/tests/mapinfo.c +++ b/tests/mapinfo.c @@ -451,15 +451,21 @@ static void test_mapinfo_bad_check_uuid_00(void **state) static void test_mapinfo_bad_check_uuid_01(void **state) { int rc; + struct dm_info dmi = { .suspended = 0 }; + char name[WWID_SIZE] = { 0 }; + char uuid[DM_UUID_LEN] = { 0 }; mock_mapinfo_name_1(DM_DEVICE_INFO, 1, "foo", 1, 1, 0); WRAP_DM_TASK_GET_INFO(1); WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + will_return(__wrap_dm_task_get_name, MPATH_NAME_01); will_return(__wrap_dm_task_get_uuid, BAD_UUID_01); rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_CHECK_UUID, (mapid_t) { .str = "foo", }, - (mapinfo_t) { .name = NULL }); + (mapinfo_t) { .dmi = &dmi, .name = name, .uuid = uuid }); assert_int_equal(rc, DMP_NO_MATCH); + assert_true(!strcmp(name, MPATH_NAME_01)); + assert_true(!strcmp(uuid, BAD_UUID_01)); } static void test_mapinfo_bad_check_uuid_02(void **state) @@ -887,17 +893,26 @@ static void test_mapinfo_bad_next_target_01(void **state) static void test_mapinfo_bad_next_target_02(void **state) { int rc; - unsigned long long size; + struct dm_info dmi = { .suspended = 0 }; + char name[WWID_SIZE] = { 0 }; + char uuid[DM_UUID_LEN] = { 0 }; + unsigned long long size = 0; mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 1, 0); WRAP_DM_TASK_GET_INFO(1); WRAP_DM_TASK_GET_INFO(&MPATH_DMI_02); + will_return(__wrap_dm_task_get_name, MPATH_NAME_01); + will_return(__wrap_dm_task_get_uuid, MPATH_UUID_01); /* no targets */ mock_dm_get_next_target(0, NULL, NULL, NULL); rc = libmp_mapinfo(DM_MAP_BY_NAME, (mapid_t) { .str = "foo", }, - (mapinfo_t) { .size = &size }); + (mapinfo_t) { .dmi = &dmi, .name = name, .uuid = uuid, .size = &size }); assert_int_equal(rc, DMP_EMPTY); + assert_int_equal(size, 0); + assert_memory_equal(&dmi, &MPATH_DMI_02, sizeof(dmi)); + assert_true(!strcmp(name, MPATH_NAME_01)); + assert_true(!strcmp(uuid, MPATH_UUID_01)); } /* libmp_mapinfo needs to do a DM_DEVICE_STATUS ioctl */ @@ -946,10 +961,10 @@ static void test_mapinfo_bad_target_type_03(void **state) (mapid_t) { .str = "foo", }, (mapinfo_t) { .dmi = &dmi, .name = name, .uuid = uuid }); assert_int_equal(rc, DMP_NO_MATCH); - /* make sure memory content is not changed */ - assert_memory_equal(&dmi, &((struct dm_info) { .exists = 0 }), sizeof(dmi)); - assert_memory_equal(&name, &((char[WWID_SIZE]) { 0 }), WWID_SIZE); - assert_memory_equal(&uuid, &((char[DM_UUID_LEN]) { 0 }), DM_UUID_LEN); + /* make sure that the ouput was filled in */ + assert_memory_equal(&dmi, &MPATH_DMI_01, sizeof(dmi)); + assert_true(!strcmp(name, MPATH_NAME_01)); + assert_true(!strcmp(uuid, MPATH_UUID_01)); } static void test_mapinfo_bad_target_type_04(void **state) @@ -1065,23 +1080,32 @@ static void test_mapinfo_no_table_01(void **state) (mapid_t) { .str = "foo", }, (mapinfo_t) { .dmi = &dmi }); assert_int_equal(rc, DMP_EMPTY); + assert_memory_equal(&dmi, &MPATH_DMI_02, sizeof(dmi)); } static void test_mapinfo_no_table_02(void **state) { int rc; struct dm_info dmi = { .suspended = 0 }; + char name[WWID_SIZE] = { 0 }; + char uuid[DM_UUID_LEN] = { 0 }; + unsigned long long size = 0; mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 1, 0); WRAP_DM_TASK_GET_INFO(1); /* DMI with no live table, MAPINFO_CHECK_UUID set */ WRAP_DM_TASK_GET_INFO(&MPATH_DMI_02); + will_return(__wrap_dm_task_get_name, MPATH_NAME_01); mock_dm_get_next_target(0, NULL, NULL, NULL); will_return(__wrap_dm_task_get_uuid, MPATH_UUID_01); rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_CHECK_UUID | MAPINFO_MPATH_ONLY, (mapid_t) { .str = "foo", }, - (mapinfo_t) { .dmi = &dmi }); + (mapinfo_t) { .dmi = &dmi, .name = name, .uuid = uuid, .size = &size }); assert_int_equal(rc, DMP_EMPTY); + assert_int_equal(size, 0); + assert_memory_equal(&dmi, &MPATH_DMI_02, sizeof(dmi)); + assert_true(!strcmp(name, MPATH_NAME_01)); + assert_true(!strcmp(uuid, MPATH_UUID_01)); } static void test_mapinfo_good_status_01(void **state) @@ -1121,8 +1145,6 @@ static void test_mapinfo_bad_strdup_01(void **state) (mapinfo_t) { .status = &status, .uuid = uuid, .name = name }); assert_int_equal(rc, DMP_ERR); assert_null(status); - assert_memory_equal(&name, &((char[WWID_SIZE]) { 0 }), WWID_SIZE); - assert_memory_equal(&uuid, &((char[DM_UUID_LEN]) { 0 }), DM_UUID_LEN); } @@ -1284,9 +1306,6 @@ static void test_mapinfo_bad_strdup_02(void **state) assert_int_equal(rc, DMP_ERR); assert_null(status); assert_null(target); - assert_memory_equal(&dmi, &((struct dm_info) { .suspended = 0 }), sizeof(dmi)); - assert_memory_equal(&name, &((char[WWID_SIZE]) { 0 }), WWID_SIZE); - assert_memory_equal(&uuid, &((char[DM_UUID_LEN]) { 0 }), DM_UUID_LEN); } static void test_mapinfo_bad_strdup_03(void **state) From patchwork Fri Nov 22 21:11:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 13883619 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 636CA178CF6 for ; Fri, 22 Nov 2024 21:11:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732309902; cv=none; b=ZVh9hCykz7367cZ53iBswI3N+E2Mr5a/x7G1TYgB96Rx4oBxCxbWed6yK7P6fB8etmJHlfSL8mm9+NHhtTgaAIbh4K901UQFeQXM/Q50AObHKFkbs6IOSRD06I9Z6IBqFXmjP/3CUlvI8iF6D7s/d8V5UpgcGR36qAi4sHXRT2M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732309902; c=relaxed/simple; bh=VwvzbyvScF8jnJVrihY0aPnabhJ3Efna+oVUzp5PJhc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:content-type; b=rtK0AtQjSPodruvPnOZ0NWqMKaZYq8xjlIRsgR7C5qx3muFfb6JD3u7WncZzwHeMyIUa3luonGgs/8INwKg9JWwHxygbr7FSOMU8bNUYfkTzd3YgoiTyYLaUeYp+gCR2N+zTqUkYmTgh0eLp7cgS+l7H8AMbT1EDmJb+MXRBuQ8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Nkqv2cNt; arc=none smtp.client-ip=170.10.133.124 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="Nkqv2cNt" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732309899; 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/EWs7G4+cTXuh+UJnvci/afZKJkUq82+iUPugW2+MM=; b=Nkqv2cNtbX+An3kkgqec3wf+hgisooKQFpE+E+rlBnCPQwGHlFJcIDx/P/Fu08RdmUh1de BUBF9m534Vx7HBdxopsEUWc7J9REHkBQEcs62Kk5VxV8PgGy8rwPpD4Wtnl5KwsDl1Xlko rsrYhQnH1lNlDDMsqsIQre6XLRAiJKA= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-584-7ISZT1ntOjSZpSP6-l5Xhw-1; Fri, 22 Nov 2024 16:11:37 -0500 X-MC-Unique: 7ISZT1ntOjSZpSP6-l5Xhw-1 X-Mimecast-MFC-AGG-ID: 7ISZT1ntOjSZpSP6-l5Xhw Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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 mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 887681955EE7; Fri, 22 Nov 2024 21:11:36 +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 mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3723E1955F3E; Fri, 22 Nov 2024 21:11:36 +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.2/8.17.1) with ESMTPS id 4AMLBYKF718903 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 22 Nov 2024 16:11:34 -0500 Received: (from bmarzins@localhost) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.2/8.17.2/Submit) id 4AMLBYJt718902; Fri, 22 Nov 2024 16:11:34 -0500 From: Benjamin Marzinski To: Christophe Varoqui Cc: device-mapper development , Martin Wilck Subject: [PATCH v2 05/13] libmultipath: check table type in dm_find_map_by_wwid Date: Fri, 22 Nov 2024 16:11:25 -0500 Message-ID: <20241122211133.718861-6-bmarzins@redhat.com> In-Reply-To: <20241122211133.718861-1-bmarzins@redhat.com> References: <20241122211133.718861-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.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: CIKsyxC5JUgSk3BGn0Pkl0-u1tM9t800XtCw844A-B4_1732309896 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true This function is only supposed to work on multipath devices (it adds the multipath uuid prefix to the passed in wwid). Check this, and adapt cli_add_map() to handle the corner case where there is a non-multipath device with a multipath uuid. Signed-off-by: Benjamin Marzinski --- libmultipath/devmapper.c | 2 +- multipathd/cli_handlers.c | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 38c49bd5..e5f49a5b 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -892,7 +892,7 @@ int dm_find_map_by_wwid(const char *wwid, char *name, struct dm_info *dmi) if (safe_sprintf(tmp, UUID_PREFIX "%s", wwid)) return DMP_ERR; - return libmp_mapinfo(DM_MAP_BY_UUID, + return libmp_mapinfo(DM_MAP_BY_UUID | MAPINFO_MPATH_ONLY, (mapid_t) { .str = tmp }, (mapinfo_t) { .name = name, .dmi = dmi }); } diff --git a/multipathd/cli_handlers.c b/multipathd/cli_handlers.c index 184c3f91..ec330d81 100644 --- a/multipathd/cli_handlers.c +++ b/multipathd/cli_handlers.c @@ -725,7 +725,13 @@ cli_add_map (void * v, struct strbuf *reply, void * data) condlog(2, "%s: unknown map.", param); return -ENODEV; } - if (dm_find_map_by_wwid(refwwid, alias, &dmi) != DMP_OK) { + rc = dm_find_map_by_wwid(refwwid, alias, &dmi); + if (rc == DMP_NO_MATCH) { + condlog(2, "%s: wwid %s already in use by non-multipath device %s", + param, refwwid, alias); + return 1; + } + if (rc != DMP_OK) { condlog(3, "%s: map not present. creating", param); if (coalesce_paths(vecs, NULL, refwwid, FORCE_RELOAD_NONE, CMD_NONE) != CP_OK) { From patchwork Fri Nov 22 21:11: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: 13883623 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 1894C1632DC for ; Fri, 22 Nov 2024 21:11:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732309902; cv=none; b=b0mw9E373yCimw5FEX73NlMrh3uU8Ex0IXKPI0cqfkAaYDBSxCY2ngH8B0c7lBmOvJCEbZXY8lXCmQjNyhbtwMzqdkxZWTCmYHJ1VdZOrCIznXgt3LTJ8wksfdn9pxLxWn0WXumP+I9SWllFMfcW6WYYfk0K94g5+5fWbHbJik0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732309902; c=relaxed/simple; bh=5u1fJfaqTxp5ngofSBsrH3Ty4t5CaaV50Q/BQT6r3qc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:content-type; b=bBuw5YUstdH4INLrNRVqoF3ou4xR3gtCCC9X35ZfZG0UfGzHsOAShx3UMJVz9aC/jysNvrLUKnaKx/RDwGNpGdQAfY2atcp+19cuh/w4I1ycqWherVPLgBuVoW9oqdPCyQ0v7bJDUQ+4j7WRk2JMJd1BiVReefbyLDDUX32kkEM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=ek/axpy7; arc=none smtp.client-ip=170.10.133.124 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="ek/axpy7" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732309898; 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=HrIsM1M6Hi4v7xXB9cBnBk0Dvf5k+gzPhDBAiU2nhoY=; b=ek/axpy7P1wAikA0U0c5ugO/wmBrDIf8kjOfr3DTJzUKpHXRCQmjGz/OIDPEdwgoK9XEuj APkvhLiS3UKgimBD5cry/kep2WD5P+ywxeqY4N1DU3EaCSAm0mjjD0A6UZZnnF+Ori5TzM RUTWSfBbypGO2LdUckJlE9nGN/zhnnc= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-590-YpgkjiwhOkOi3ZM_fL7i6Q-1; Fri, 22 Nov 2024 16:11:37 -0500 X-MC-Unique: YpgkjiwhOkOi3ZM_fL7i6Q-1 X-Mimecast-MFC-AGG-ID: YpgkjiwhOkOi3ZM_fL7i6Q Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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 mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 941C2195604F; Fri, 22 Nov 2024 21:11:36 +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 mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 426891955E9E; Fri, 22 Nov 2024 21:11:36 +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.2/8.17.1) with ESMTPS id 4AMLBYoO718907 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 22 Nov 2024 16:11:34 -0500 Received: (from bmarzins@localhost) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.2/8.17.2/Submit) id 4AMLBYrL718906; Fri, 22 Nov 2024 16:11:34 -0500 From: Benjamin Marzinski To: Christophe Varoqui Cc: device-mapper development , Martin Wilck Subject: [PATCH v2 06/13] libmultipath: handle a create corner case for empty devices Date: Fri, 22 Nov 2024 16:11:26 -0500 Message-ID: <20241122211133.718861-7-bmarzins@redhat.com> In-Reply-To: <20241122211133.718861-1-bmarzins@redhat.com> References: <20241122211133.718861-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.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: hkGmjBEN9Wm3AHCQESzBYbHLalpCN3-AeVFeD4pia8w_1732309896 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true Multipath already notices if there is any empty device with the same alias and wwid as a device it is trying to create, and switches to a reload. However, if the empty device has a different alias but the same wwid, instead of reloading and renaming the device like it would for a device with a table. multipath will attempt to create a new device and fail. Fix this by checking for these devices, and doing a reload and rename. Signed-off-by: Benjamin Marzinski --- libmultipath/configure.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/libmultipath/configure.c b/libmultipath/configure.c index a7257981..d0e9c958 100644 --- a/libmultipath/configure.c +++ b/libmultipath/configure.c @@ -835,7 +835,6 @@ int domap(struct multipath *mpp, char *params, int is_daemon) { int r = DOMAP_FAIL; struct config *conf; - char wwid[WWID_SIZE]; /* * last chance to quit before touching the devmaps @@ -846,6 +845,7 @@ int domap(struct multipath *mpp, char *params, int is_daemon) } if (mpp->action == ACT_CREATE) { + char wwid[WWID_SIZE]; int rc = dm_get_wwid(mpp->alias, wwid, sizeof(wwid)); if (rc == DMP_OK && !strncmp(mpp->wwid, wwid, sizeof(wwid))) { @@ -863,7 +863,26 @@ int domap(struct multipath *mpp, char *params, int is_daemon) mpp->action = ACT_REJECT; } } + if (mpp->action == ACT_CREATE) { + char alias[WWID_SIZE]; + int rc = dm_find_map_by_wwid(mpp->wwid, alias, NULL); + if (rc == DMP_NO_MATCH) { + condlog(1, "%s: wwid \"%s\" already in use by non-multipath map \"%s\"", + mpp->alias, mpp->wwid, alias); + mpp->action = ACT_REJECT; + } else if (rc == DMP_OK || rc == DMP_EMPTY) { + /* + * we already handled the case were rc == DMO_OK and + * the alias == mpp->alias above. So the alias must be + * different here. + */ + condlog(3, "%s: map already present with a different name \"%s\". reloading", + mpp->alias, alias); + strlcpy(mpp->alias_old, alias, WWID_SIZE); + mpp->action = ACT_RELOAD_RENAME; + } + } if (mpp->action == ACT_RENAME || mpp->action == ACT_SWITCHPG_RENAME || mpp->action == ACT_RELOAD_RENAME || mpp->action == ACT_RESIZE_RENAME) { From patchwork Fri Nov 22 21:11: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: 13883625 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 B7047188736 for ; Fri, 22 Nov 2024 21:11:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732309903; cv=none; b=Wu+Yx83KQVA2HPSloigumww1StniDhUimabD3xv2QrAu6LHPKSRx9xs5/HZvuahpqzhF31ugl2TVbo9gZd1qCzUaSIGa5VPMRNfivQfRg9TpYdNHpM+buX0unpQnEBgDBKAfUlrRK5OTYKtFxN/XrmHsFnXOfvwfYxLpHr6BwwM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732309903; c=relaxed/simple; bh=vWz+OlsAsdn/pwUjYWntePA7f0Imk6skyYDtZAHOwJo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:content-type; b=RDM+XSYhC/5klARywTKH2bye5wEU50Qd5XPwhmCkzBUa877d8lqNU3SYPO4MsDglsnNqjIVGjwOVe0CMSin371dwsL3SVM4P0vvwMJFe7O3F9S8r4PzvL5rSNX309WQdxRw5jQyZzYDwLB/WNa+d925mGe6K3iwafNiLUcZqKGs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=ZzBXphXZ; arc=none smtp.client-ip=170.10.133.124 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="ZzBXphXZ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732309900; 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=2VKNqjVaxF3u8YRRwe6C5a46Ejz0trjeequzLepicg4=; b=ZzBXphXZYx2/InGrEiiDkQh+tXSoBDwS+0fNCOiGCt/SM4It+6bkVfqLkTapG9Zr+b/uR+ ice/N+3dhX+frI01M/kfaONkJhJgzFLMq/3YKFcdSsyuB4rF7IYaNYoP383UZCwnEfnnTy evZdBrt9aowCES8mQwfF+Yj2Risa3WU= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-590-rcPNOKCIPxeoZ9x061Hi9Q-1; Fri, 22 Nov 2024 16:11:37 -0500 X-MC-Unique: rcPNOKCIPxeoZ9x061Hi9Q-1 X-Mimecast-MFC-AGG-ID: rcPNOKCIPxeoZ9x061Hi9Q Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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 mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 947E41956064; Fri, 22 Nov 2024 21:11:36 +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 mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5391B1955EA9; Fri, 22 Nov 2024 21:11:36 +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.2/8.17.1) with ESMTPS id 4AMLBZAa718911 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 22 Nov 2024 16:11:35 -0500 Received: (from bmarzins@localhost) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.2/8.17.2/Submit) id 4AMLBZQu718910; Fri, 22 Nov 2024 16:11:35 -0500 From: Benjamin Marzinski To: Christophe Varoqui Cc: device-mapper development , Martin Wilck Subject: [PATCH v2 07/13] libmultipath: handle empty maps in dm_flush_map__ Date: Fri, 22 Nov 2024 16:11:27 -0500 Message-ID: <20241122211133.718861-8-bmarzins@redhat.com> In-Reply-To: <20241122211133.718861-1-bmarzins@redhat.com> References: <20241122211133.718861-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.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: zH1DAQ-PgnyGwupBKRX18gF6thfkqErpf_PV4akdkr0_1732309896 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true Make dm_flush_map__() remove empty devices, as long as they have valid multipath uuids. Signed-off-by: Benjamin Marzinski --- libmultipath/devmapper.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index e5f49a5b..b0bd0d4f 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -982,11 +982,16 @@ int dm_flush_map__ (const char *mapname, int flags, int retries) int udev_flags = 0; char *params __attribute__((cleanup(cleanup_charp))) = NULL; - if (libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY | MAPINFO_CHECK_UUID, + r = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY | MAPINFO_CHECK_UUID, (mapid_t) { .str = mapname }, - (mapinfo_t) { .target = ¶ms }) != DMP_OK) + (mapinfo_t) { .target = ¶ms }); + if (r != DMP_OK && r != DMP_EMPTY) return DM_FLUSH_OK; /* nothing to do */ + /* device mapper will not let you resume an empty device */ + if (r == DMP_EMPTY) + flags &= ~DMFL_SUSPEND; + /* if the device currently has no partitions, do not run kpartx on it if you fail to delete it */ if (do_foreach_partmaps(mapname, has_partmap, NULL) == 0) From patchwork Fri Nov 22 21:11: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: 13883627 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 45A9018BC0D for ; Fri, 22 Nov 2024 21:11:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732309903; cv=none; b=sggYnbbbNXDGyyvNPE/z6tgq6ehKnVf9+zK03/0Psb5TBlt7xrUiR//n7s1KfT96DSyAiHu83VJ6TJ8mZedp4NvCVvQSVIqT1Nzt3u/NejYNR+Sfk1V9v3V+vQxW1IXJidJCSacUf/GEWO0l2roj0EpOgH6v3BzVxVaY4nocyxQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732309903; c=relaxed/simple; bh=RirEoRPr0csyNeaEP0BXGDHSR8LsqTu1sOBNQbON2oM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:content-type; b=n28zloa4NEhlPYOBryMtM2nPOoRSThWNjsaObJQBE3PdWaHyCbnZoFyjnzU46v2049xbhzGrEpWcn9/Ncb5GYhyDC+HeClggvy0cXuM+VbBbJDqLXqZo3iDOXKWl8bSTXmB9IvhOOHn2jx2XWjn0AAQH2WA9h+cadT3liTTA5SI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=KDX9MhDt; arc=none smtp.client-ip=170.10.129.124 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="KDX9MhDt" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732309901; 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=Eu+bRsKkC7V9Qb4CjosKMZBobvgsdQGqyoqGWbQLXGM=; b=KDX9MhDtxx5w+kW90rpWH+y/rp30vi1x43QxfwB+9zCjILAgHAOCzJttCNs7g/aEoQJZl3 SeJNRvAyzc2A5t1g+7nAYPZ7Mz1QmFgFIDHgEvnaX6ylv63Drbxdo/4DiOXml/E/JuPjzq vZV+tSdYgZay0+dCFecfGjlrYWt1who= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-99-49c5Jmo7P2iRCWzsGrvjYw-1; Fri, 22 Nov 2024 16:11:37 -0500 X-MC-Unique: 49c5Jmo7P2iRCWzsGrvjYw-1 X-Mimecast-MFC-AGG-ID: 49c5Jmo7P2iRCWzsGrvjYw Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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 mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 038C4195608C; Fri, 22 Nov 2024 21:11:37 +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 mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id ADCAE1955F43; Fri, 22 Nov 2024 21:11:36 +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.2/8.17.1) with ESMTPS id 4AMLBZFU718915 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 22 Nov 2024 16:11:35 -0500 Received: (from bmarzins@localhost) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.2/8.17.2/Submit) id 4AMLBZqJ718914; Fri, 22 Nov 2024 16:11:35 -0500 From: Benjamin Marzinski To: Christophe Varoqui Cc: device-mapper development , Martin Wilck Subject: [PATCH v2 08/13] libmultipath: factor out code to check if a device is a parition Date: Fri, 22 Nov 2024 16:11:28 -0500 Message-ID: <20241122211133.718861-9-bmarzins@redhat.com> In-Reply-To: <20241122211133.718861-1-bmarzins@redhat.com> References: <20241122211133.718861-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.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: PgXft8B-Hpn_x_Cnx3sKzLONgRHLClfGVTNpQcnV83c_1732309897 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true Move the code to check if a device is a valid parition of a multipath device out into it's own function. A future patch will make this code more complicated. No functional changes. Signed-off-by: Benjamin Marzinski --- libmultipath/devmapper.c | 57 ++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index b0bd0d4f..0df9ee40 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -1318,17 +1318,43 @@ char *dm_mapname(int major, int minor) return strdup(name); } +static bool +is_valid_partmap(const char *name, const char *map_dev_t, + const char *map_uuid) { + int r; + char __attribute__((cleanup(cleanup_charp))) *params = NULL; + char *p; + char part_uuid[DM_UUID_LEN]; + + r = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_PART_ONLY | MAPINFO_CHECK_UUID, + (mapid_t) { .str = name }, + (mapinfo_t) { .uuid = part_uuid, .target = ¶ms}); + + /* There must be a single linear target */ + if (r != DMP_OK) + return false; + + /* + * and the uuid of the target must be a partition of the uuid of the + * multipath device + */ + if (!is_mpath_part_uuid(part_uuid, map_uuid)) + return false; + + /* and the table must map over the multipath map */ + return ((p = strstr(params, map_dev_t)) && + !isdigit(*(p + strlen(map_dev_t)))); +} + static int do_foreach_partmaps (const char *mapname, int (*partmap_func)(const char *, void *), void *data) { struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; - char __attribute__((cleanup(cleanup_charp))) *params = NULL; struct dm_names *names; unsigned next = 0; char dev_t[BLK_DEV_SIZE]; - char *p; char map_uuid[DM_UUID_LEN]; struct dm_info info; @@ -1354,35 +1380,10 @@ do_foreach_partmaps (const char *mapname, return 0; do { - char part_uuid[DM_UUID_LEN]; - - if ( - /* - * if there is only a single "linear" target - */ - libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_PART_ONLY | MAPINFO_CHECK_UUID, - (mapid_t) { .str = names->name }, - (mapinfo_t) { - .uuid = part_uuid, - .target = ¶ms, - }) == DMP_OK && - /* - * and the uuid of the target is a partition of the - * uuid of the multipath device - */ - is_mpath_part_uuid(part_uuid, map_uuid) && - - /* - * and the table maps over the multipath map - */ - (p = strstr(params, dev_t)) && - !isdigit(*(p + strlen(dev_t))) && - + if (is_valid_partmap(names->name, dev_t, map_uuid) && (partmap_func(names->name, data) != 0)) return 1; - free(params); - params = NULL; next = names->next; names = (void*) names + next; } while (next); From patchwork Fri Nov 22 21:11: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: 13883632 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 BB89B178CF6 for ; Fri, 22 Nov 2024 21:11:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732309905; cv=none; b=T7hWwlcJPsbOtmbew6PxICKsD5TbRB4ZHoobhj2T4lnrFkMAgfRUCQU5eWuO2tBGRpZMQGKQf2L1+r8QdyQMGml/PYehjjrgH1lLY8juj4ia96KwE6RvJQJ2VZzpi3l3l1V778hkGxQ9fyq45FKaFidNvSOdSliR5NKMHweD6q8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732309905; c=relaxed/simple; bh=hNp8aWzVrgDcvGmpvL3KKXveArT/1inn8TGDDT63C7c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:content-type; b=lZAdhW8LnLJcUHezHcj9LEIxQJhygJZ44tSrcTmj0GoKuSlAYqGIPGMpCfGfvc+wDXAhnBw2wAzLLCdt+wR3OmNAKpAdbV9bk/tYwhpnnpDY5QqygT8ugHLFMcmHehN1tj9Bymf8pdO3v8mBFBDbcAzUIBkcj0kCAHMlo/eu0lo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=C4RieKK1; arc=none smtp.client-ip=170.10.133.124 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="C4RieKK1" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732309901; 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=47tzZZFAwY5Er/bvu2kHSwnueG5bGT0+04j0TwjAM7Q=; b=C4RieKK19cgOidjGYcT5USnZcqMSLSZHazZx5surtdcdh7CBBzYy/f8ifz7QVadfRPcCy5 TYHhRL+GuhcEF7mjSkDvt1TsGV0Wsz9wL0VvIy8fISBOYjoEp9RbyyCD8za0u8rM4FqhEg Bbjdv6tyYCPxQRu5KykYDBfqCky4NwY= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-444-cQNnjzaJOmuZX2ocJTm6FQ-1; Fri, 22 Nov 2024 16:11:38 -0500 X-MC-Unique: cQNnjzaJOmuZX2ocJTm6FQ-1 X-Mimecast-MFC-AGG-ID: cQNnjzaJOmuZX2ocJTm6FQ Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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 mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 38D70195609F; Fri, 22 Nov 2024 21:11:37 +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 mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DE1811955E9E; Fri, 22 Nov 2024 21:11:36 +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.2/8.17.1) with ESMTPS id 4AMLBZsi718919 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 22 Nov 2024 16:11:35 -0500 Received: (from bmarzins@localhost) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.2/8.17.2/Submit) id 4AMLBZSp718918; Fri, 22 Nov 2024 16:11:35 -0500 From: Benjamin Marzinski To: Christophe Varoqui Cc: device-mapper development , Martin Wilck Subject: [PATCH v2 09/13] libmultipath: remove recursive calls in partmap_funcs Date: Fri, 22 Nov 2024 16:11:29 -0500 Message-ID: <20241122211133.718861-10-bmarzins@redhat.com> In-Reply-To: <20241122211133.718861-1-bmarzins@redhat.com> References: <20241122211133.718861-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.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: QhKoOmdcxHugaszoi3KGaFb6Q7j8quo7fCYhNhDMm7c_1732309897 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true cancel_remove_partmap() and rename_partmap() both could end up calling do_foreach_partmaps() with the partition instead of the original multipath device. This won't ever do anything, since do_foreach_partmaps() checks that it's called with a multipath device. Signed-off-by: Benjamin Marzinski --- libmultipath/devmapper.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 0df9ee40..daaeebb4 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -1421,8 +1421,6 @@ dm_remove_partmaps (const char * mapname, int flags) static int cancel_remove_partmap (const char *name, void *unused __attribute__((unused))) { - if (dm_get_opencount(name)) - dm_cancel_remove_partmaps(name); if (dm_message(name, "@cancel_deferred_remove") != 0) condlog(0, "%s: can't cancel deferred remove: %s", name, strerror(errno)); @@ -1481,6 +1479,9 @@ struct rename_data { char *delim; }; +static int +dm_rename__(const char *old, char *new, int skip_kpartx); + static int rename_partmap (const char *name, void *data) { @@ -1492,7 +1493,7 @@ rename_partmap (const char *name, void *data) return 0; for (offset = strlen(rd->old); name[offset] && !(isdigit(name[offset])); offset++); /* do nothing */ if (asprintf(&buff, "%s%s%s", rd->new, rd->delim, name + offset) >= 0) { - dm_rename(name, buff, rd->delim, SKIP_KPARTX_OFF); + dm_rename__(name, buff, SKIP_KPARTX_OFF); free(buff); condlog(4, "partition map %s renamed", name); } else @@ -1519,17 +1520,14 @@ dm_rename_partmaps (const char * old, char * new, char *delim) return do_foreach_partmaps(old, rename_partmap, &rd); } -int -dm_rename (const char * old, char * new, char *delim, int skip_kpartx) +static int +dm_rename__(const char *old, char *new, int skip_kpartx) { int r = 0; struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; uint32_t cookie = 0; uint16_t udev_flags = DM_UDEV_DISABLE_LIBRARY_FALLBACK | ((skip_kpartx == SKIP_KPARTX_ON)? MPATH_UDEV_NO_KPARTX_FLAG : 0); - if (dm_rename_partmaps(old, new, delim)) - return r; - if (!(dmt = libmp_dm_task_create(DM_DEVICE_RENAME))) return r; @@ -1550,6 +1548,14 @@ dm_rename (const char * old, char * new, char *delim, int skip_kpartx) return r; } +int +dm_rename (const char * old, char * new, char *delim, int skip_kpartx) +{ + if (dm_rename_partmaps(old, new, delim)) + return 0; + return dm_rename__(old, new, skip_kpartx); +} + void dm_reassign_deps(char *table, const char *dep, const char *newdep) { char *n, *newtable; From patchwork Fri Nov 22 21:11: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: 13883621 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 6717B17DFFC for ; Fri, 22 Nov 2024 21:11:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732309902; cv=none; b=AzdEJLDDyv4VA6OQnkqIeTBM2DEgnHp2mWEDpAfFqbTNbsVaekj8o2LX8kdZ3uWSImCiGnmQSlud17NN3mBKSDCu11xYvjduIasIUgB0mh72p6UiEEr4Q+TcWjABeMZyXXm5i2yoGdSIePeAhZQFMy2zDRviDuSPi4swqZ0F5DM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732309902; c=relaxed/simple; bh=aEnNGcu2YdXcKRGpLp4D8SLXxgHyuR9topp8iWcrtBQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:content-type; b=mxO5T+Gkd9Uox6cW5kuqcFUrDm8VCk+VBqer3KrVoY408382Rx+qzJejxOK/wQHuJF4NaAQ9UxwVr+mz0yihc/dIhEv22Cl67B22Xor3l9aNVtN/HGDT/3MocL7deIMFIeizY3onM34GsIdlBf1n7Bd1/5gjzA98IO1P3PtHkpY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=ZhOAlV6a; arc=none smtp.client-ip=170.10.129.124 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="ZhOAlV6a" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732309899; 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=esAFpuP4FfauggHP7CiJ3Npwrh2FqmsCsbcPKj3efw0=; b=ZhOAlV6alcv6XM1oDMQMqVuMx2x49X0hJAKoBubuCkAyBUi15xN6eqHMAV9tjyGBFowaIZ SoRzskFEngCIAhTPImZMV/hz5JAtQTwWvjjUOl66CzhC8NFZThc7KLd0qAAkfZyHwtPd8z hCtJiR/Ms4ftPRmDz0mtvIA8z3MFvEs= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-99-TSQ-VfInMRCt4tBtGRLA9g-1; Fri, 22 Nov 2024 16:11:38 -0500 X-MC-Unique: TSQ-VfInMRCt4tBtGRLA9g-1 X-Mimecast-MFC-AGG-ID: TSQ-VfInMRCt4tBtGRLA9g Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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 mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 23A291955EEA; Fri, 22 Nov 2024 21:11:37 +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 mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D6F911955F3E; Fri, 22 Nov 2024 21:11:36 +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.2/8.17.1) with ESMTPS id 4AMLBZll718923 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 22 Nov 2024 16:11:35 -0500 Received: (from bmarzins@localhost) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.2/8.17.2/Submit) id 4AMLBZgf718922; Fri, 22 Nov 2024 16:11:35 -0500 From: Benjamin Marzinski To: Christophe Varoqui Cc: device-mapper development , Martin Wilck Subject: [PATCH v2 10/13] libmultipath: move dm_rename__ before rename_partmap Date: Fri, 22 Nov 2024 16:11:30 -0500 Message-ID: <20241122211133.718861-11-bmarzins@redhat.com> In-Reply-To: <20241122211133.718861-1-bmarzins@redhat.com> References: <20241122211133.718861-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.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 90KYTuhQ8coBFltfNfhtzZTCJdUTMsBXvm1F9tNUiGk_1732309897 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true No functional changes. Signed-off-by: Benjamin Marzinski --- libmultipath/devmapper.c | 55 +++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index daaeebb4..751b45d8 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -1480,7 +1480,32 @@ struct rename_data { }; static int -dm_rename__(const char *old, char *new, int skip_kpartx); +dm_rename__(const char *old, char *new, int skip_kpartx) +{ + int r = 0; + struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; + uint32_t cookie = 0; + uint16_t udev_flags = DM_UDEV_DISABLE_LIBRARY_FALLBACK | ((skip_kpartx == SKIP_KPARTX_ON)? MPATH_UDEV_NO_KPARTX_FLAG : 0); + + if (!(dmt = libmp_dm_task_create(DM_DEVICE_RENAME))) + return r; + + if (!dm_task_set_name(dmt, old)) + return r; + + if (!dm_task_set_newname(dmt, new)) + return r; + + if (!dm_task_set_cookie(dmt, &cookie, udev_flags)) + return r; + + r = libmp_dm_task_run(dmt); + if (!r) + dm_log_error(2, DM_DEVICE_RENAME, dmt); + + libmp_udev_wait(cookie); + return r; +} static int rename_partmap (const char *name, void *data) @@ -1520,34 +1545,6 @@ dm_rename_partmaps (const char * old, char * new, char *delim) return do_foreach_partmaps(old, rename_partmap, &rd); } -static int -dm_rename__(const char *old, char *new, int skip_kpartx) -{ - int r = 0; - struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; - uint32_t cookie = 0; - uint16_t udev_flags = DM_UDEV_DISABLE_LIBRARY_FALLBACK | ((skip_kpartx == SKIP_KPARTX_ON)? MPATH_UDEV_NO_KPARTX_FLAG : 0); - - if (!(dmt = libmp_dm_task_create(DM_DEVICE_RENAME))) - return r; - - if (!dm_task_set_name(dmt, old)) - return r; - - if (!dm_task_set_newname(dmt, new)) - return r; - - if (!dm_task_set_cookie(dmt, &cookie, udev_flags)) - return r; - - r = libmp_dm_task_run(dmt); - if (!r) - dm_log_error(2, DM_DEVICE_RENAME, dmt); - - libmp_udev_wait(cookie); - return r; -} - int dm_rename (const char * old, char * new, char *delim, int skip_kpartx) { From patchwork Fri Nov 22 21:11: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: 13883622 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 DB99C185935 for ; Fri, 22 Nov 2024 21:11:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732309902; cv=none; b=Ti48FqNOJJ9hIVNE4JNdyenN48Vt51VC33DSpi87AciAdo5nFyY1ULGrPz4MH4F8gNdetRbvTX4ip0ROHzpraIuM237SQZJhN/GrJ884KqpakzetTSnepdjzTqzYOUgsOB4swgbXq8ElRHXVc29+PiyvCx0eoW48waVgsiF3f5w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732309902; c=relaxed/simple; bh=Rh2le38k2zTqgsSlbPqTcg8SjtXhfTa0CweonlKGFJc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:content-type; b=rLYTnjYAi0+TPHBWWIc4aShB+bxE5br/az0uixT4/HTf89wTu1MSTpKrgGUKAhIUAA+jEgjx5/vhzVqP5kOw/C9ybFmU+Varxbyetv9BAEn2avqZ9H5RjpKz4ItmaJ//JTD+wr0GyMDDLUhmnBsWn3b6QfaIVhyUaav3ODOy6Aw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=diqmj8sb; arc=none smtp.client-ip=170.10.129.124 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="diqmj8sb" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732309899; 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=CJ5uAYFvL1AJ+ZMTTe1UCIxratP6ILGARNXBTpgX/dM=; b=diqmj8sboaY1qjSzjvkcJ/8zkqZN0Wn0UTu9dgKMoWspcxGt6iWJdTbfCgcaH/CTyx2BMr lFu/scHWUTEyNyCtVEAcPIcOwr4YKVFeRBE+iofVXOm4+N1U7E1FseSjdwGyDAdzkQxRV3 jrFiqSoOCrLer9GJz9PVtxS4/BApAhE= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-151-hzdTeLrnN7KklWe4UUV9Eg-1; Fri, 22 Nov 2024 16:11:38 -0500 X-MC-Unique: hzdTeLrnN7KklWe4UUV9Eg-1 X-Mimecast-MFC-AGG-ID: hzdTeLrnN7KklWe4UUV9Eg Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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 mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 948511955F3C; Fri, 22 Nov 2024 21:11:37 +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 mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 35C781955EA9; Fri, 22 Nov 2024 21:11:37 +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.2/8.17.1) with ESMTPS id 4AMLBZbi718927 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 22 Nov 2024 16:11:35 -0500 Received: (from bmarzins@localhost) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.2/8.17.2/Submit) id 4AMLBZFJ718926; Fri, 22 Nov 2024 16:11:35 -0500 From: Benjamin Marzinski To: Christophe Varoqui Cc: device-mapper development , Martin Wilck Subject: [PATCH v2 11/13] libmultipath: assume device is in use if dm_get_opencount fails Date: Fri, 22 Nov 2024 16:11:31 -0500 Message-ID: <20241122211133.718861-12-bmarzins@redhat.com> In-Reply-To: <20241122211133.718861-1-bmarzins@redhat.com> References: <20241122211133.718861-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.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: gPhravZhsakFU8wA351Ou3kXj2ogGHi-5-VhbQ6wfAc_1732309897 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true If dm_get_opencount() fails, open_count will be negative, which means mpath_in_use() will never fail. However, dm_flush_map__() will eventually fail. There are multiple callers of dm_get_opencount() that run when trying to remove a device. All the others treat a failed call as if the device was in use, including one that will later be called directly on this device. So save ourselves the work, and exit early Signed-off-by: Benjamin Marzinski --- libmultipath/devmapper.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 751b45d8..3667c51b 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -961,6 +961,11 @@ int mpath_in_use(const char *name) { int open_count = dm_get_opencount(name); + if (open_count < 0) { + condlog(0, "%s: %s: failed to get open count, assuming in use", + __func__, name); + return 1; + } if (open_count) { int part_count = 0; From patchwork Fri Nov 22 21:11: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: 13883631 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 ABCAC1DF97E for ; Fri, 22 Nov 2024 21:11:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732309904; cv=none; b=YYB4Fy3fXJR0zRt/GMXeVr3y4B8/6WtCF2oJ+OP5ZnnIlj38FEFkBr1NciK4KkTJQgb8DnyAjtso7M+pGyDdrJ6qEdP8cmGSoJc4bhwIQN/i3vfvG4hDCu+LQGQEI0zU0ecKn0bnuztYNVyW04D6vu1viBjnZ6hB6vBWuzps3OE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732309904; c=relaxed/simple; bh=LaRDZrheB9unV62VRnaA4qutHmmIfhK6iNsa1kwEDD0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:content-type; b=qBSy8ICF8toHQxnSar3P0sEUJFoYh8dIdgbV99lKwDeWg2MtPSiwtZPRa+ElU8MxBrpV9SoP8lMZ8aALvJNm4IEqzJBcwwPlY+61E38nGtNAu4hZJCU3dN7s4TyJYwhcvImQC8nk47tY+YTRmBsScLIasush8VuBeggyNDnq7eU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=aLJMy50w; arc=none smtp.client-ip=170.10.129.124 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="aLJMy50w" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732309901; 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=yTVWr4XU3+SRWl5S3SmM/r7UolCqOGhaATMV3uGEO2s=; b=aLJMy50we1w4uPC201Im8HrZ7uMcyLIdL49axyzcdeq729nuW/JbETX447JeDiwvuRATpG sCKMVdfJGlQ30LIdn14M0kqbNvc7vaMimVvLJhjANZBqw0jA7Nh5cEWbyMreByVgZDiQWR HYZYg0zml6DsATj/g799Fu5z9NA7oQU= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-141-66n_wCDKMbGUqUhKJJCJKA-1; Fri, 22 Nov 2024 16:11:38 -0500 X-MC-Unique: 66n_wCDKMbGUqUhKJJCJKA-1 X-Mimecast-MFC-AGG-ID: 66n_wCDKMbGUqUhKJJCJKA Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 87F761955F34; Fri, 22 Nov 2024 21:11:37 +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 mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3D85919560A3; Fri, 22 Nov 2024 21:11:37 +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.2/8.17.1) with ESMTPS id 4AMLBZ7f718931 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 22 Nov 2024 16:11:35 -0500 Received: (from bmarzins@localhost) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.2/8.17.2/Submit) id 4AMLBZM4718930; Fri, 22 Nov 2024 16:11:35 -0500 From: Benjamin Marzinski To: Christophe Varoqui Cc: device-mapper development , Martin Wilck Subject: [PATCH v2 12/13] libmultipath: accept empty partitions as valid in do_foreach_partmaps Date: Fri, 22 Nov 2024 16:11:32 -0500 Message-ID: <20241122211133.718861-13-bmarzins@redhat.com> In-Reply-To: <20241122211133.718861-1-bmarzins@redhat.com> References: <20241122211133.718861-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.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: I20JFRa2x6_JdIPRjZWNuBMrTZAEYD7vp8EQIgBtdPQ_1732309897 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true If the partition is empty, is_valid_partmap() only checks that the uuid matches the multipath device, since there is no table to check for mapping over the multipath device. The only partmap_func that needs changes to handle empty devices is count_partitions(), which should only count a partition is it has a table (since otherwise it will not have the multipath device open). Signed-off-by: Benjamin Marzinski --- libmultipath/devmapper.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 3667c51b..c96e4b22 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -944,16 +944,23 @@ has_partmap(const char *name __attribute__((unused)), * This will be called from mpath_in_use, for each partition. * If the partition itself in use, returns 1 immediately, causing * do_foreach_partmaps() to stop iterating and return 1. - * Otherwise, increases the partition count. + * Otherwise, increases the partition count if the partition has a + * table (live or inactive). Devices with no table don't count + * towards the multipath device open count. */ static int count_partitions(const char *name, void *data) { + struct dm_info info; int *ret_count = (int *)data; - int open_count = dm_get_opencount(name); - if (open_count) + if (dm_get_info(name, &info) != DMP_OK) + return 1; + + if (info.open_count) return 1; - (*ret_count)++; + + if (info.live_table || info.inactive_table) + (*ret_count)++; return 0; } @@ -1335,8 +1342,8 @@ is_valid_partmap(const char *name, const char *map_dev_t, (mapid_t) { .str = name }, (mapinfo_t) { .uuid = part_uuid, .target = ¶ms}); - /* There must be a single linear target */ - if (r != DMP_OK) + /* There must be a single linear target or an empty map. */ + if (r != DMP_OK && r != DMP_EMPTY) return false; /* @@ -1346,7 +1353,10 @@ is_valid_partmap(const char *name, const char *map_dev_t, if (!is_mpath_part_uuid(part_uuid, map_uuid)) return false; - /* and the table must map over the multipath map */ + if (r == DMP_EMPTY) + return true; + + /* and if the table isn't empty it must map over the multipath map */ return ((p = strstr(params, map_dev_t)) && !isdigit(*(p + strlen(map_dev_t)))); } From patchwork Fri Nov 22 21:11: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: 13883630 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 BB9AE1DF983 for ; Fri, 22 Nov 2024 21:11:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732309904; cv=none; b=NpIimOQvWmuyOpTEASM8Fcs9QcNKxCdCFW0hUW/ndDQZdOj4SpA2kLnRuh4FikQMkEsoJfxvupUinkvl/0rpfZ2+lJQuLIghMEHdWiJMF5ADuNAlyZOVJbOkUNGzDRTCUspQHru5gvvEoiR5XiPgwrvKKDIGRp1wI9u9X2sFExM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732309904; c=relaxed/simple; bh=JUIzH9TzWSydGAH5Joqz9z3FY7nSKxo3remZW+zTAo8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:content-type; b=Iskk3iW9ZcAYfRVcZjpQfThtPV52mGprfidfkXYmgD38joKek2WoLt85YzAUSCU5X1l/zy9fjdoLQhF6KYEcMv5BA3dlIOwJZeXMnmKAf2QRIDhpFO7WHa4u5RuKydek3FCnVwJdfAFCF6GadpAgDRz7Rg+nEvro16ciH5fBQAw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=HBt4Wqk9; arc=none smtp.client-ip=170.10.129.124 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="HBt4Wqk9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732309901; 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=aj0lv6ee3CDib+HrfiUTl7DmMB8KXKwTOZuG+o3CZFE=; b=HBt4Wqk9KWx5PJ+2IKJ0fYj0Oakh5q6iuN1akhKturYSPcDaAtrnS0PMcS2gV8oXdUyL0D S5Ughac0wy3xiv7Nug/V8dXguSOS+6eMOgq5dnrL//Z9BE6p5mvXlvOs5/168LtJqUS+gD i6rOHe8ZGP1XuFm4vcVYRHsEFpMzN5w= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-141-1vyqTDsDOR2Lw6nQ4qzTtA-1; Fri, 22 Nov 2024 16:11:38 -0500 X-MC-Unique: 1vyqTDsDOR2Lw6nQ4qzTtA-1 X-Mimecast-MFC-AGG-ID: 1vyqTDsDOR2Lw6nQ4qzTtA Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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 mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9095B1955F42; Fri, 22 Nov 2024 21:11:37 +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 mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 502711955E9E; Fri, 22 Nov 2024 21:11:37 +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.2/8.17.1) with ESMTPS id 4AMLBaFm718935 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 22 Nov 2024 16:11:36 -0500 Received: (from bmarzins@localhost) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.2/8.17.2/Submit) id 4AMLBaAx718934; Fri, 22 Nov 2024 16:11:36 -0500 From: Benjamin Marzinski To: Christophe Varoqui Cc: device-mapper development , Martin Wilck Subject: [PATCH v2 13/13] libmultipath: reduce log level for DMP_NOT_FOUND Date: Fri, 22 Nov 2024 16:11:33 -0500 Message-ID: <20241122211133.718861-14-bmarzins@redhat.com> In-Reply-To: <20241122211133.718861-1-bmarzins@redhat.com> References: <20241122211133.718861-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.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: y9FXtC0NVBOQ8-ogbkpRkyIbmrGB9nYD8gudHr8wBMA_1732309897 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true multipath make many calls just to check if a device exists. Don't warn on each of these. Signed-off-by: Benjamin Marzinski --- libmultipath/devmapper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index c96e4b22..d4dd9540 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -727,7 +727,7 @@ static int libmp_mapinfo__(int flags, mapid_t id, mapinfo_t info, const char *ma condlog(2, "%s: dm_task_get_info() failed for %s ", fname__, map_id); return DMP_ERR; } else if(!dmi.exists) { - condlog(2, "%s: map %s doesn't exist", fname__, map_id); + condlog(3, "%s: map %s doesn't exist", fname__, map_id); return DMP_NOT_FOUND; }