From patchwork Fri Nov 15 23:22:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 13877402 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 C90DD18DF8D for ; Fri, 15 Nov 2024 23:23:04 +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=1731712986; cv=none; b=gRyppuLcr43vhwE6Qd3jHYrsAtXxdxHZs9jyEO9fvTYTznQ6koPz6dNTJc1LItCVB3py4gMjvAE4gmiMlqxb3iKdBFY29LAns4hDo1Ph/P45P7YU65LBaFtBzpK0NtVUf41PzGUvDs2gPVucfznCBHkUu5+d1tl4ufkGR+7XVu8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731712986; c=relaxed/simple; bh=X7XXXCnX3Q42918UGNB5knHK4IblelN/UKYflPCOTIg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=I1LG58RPh7ZsDHryvKU9P6rfvrAQN+1RSTh9DwfR4LWbWaGh2o5K6QLGSY7wCnJqS3AdrIKGHLupuJ/RyID6Q9MWMlDFFp3VW4MGRNTXNtUEGBEpehkUvAAy3ZW7aDIJTnjAUHHL9zD1yUdgTNNcFWPNJeqS7b26iTOFpTrKLrQ= 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=RB3K2fUj; 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="RB3K2fUj" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1731712983; 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=/nf3mHlDWAKCg9R17oBCeJyqjRQ32l+A9wojRwR414Y=; b=RB3K2fUjLkCBUqiU8CGSAwaouD0hAqnDIn1jy9Wd+gH6poq/tC4CY9XrE8ICNNC4Di1qAJ MuuwxlF4WBW36VcLv6z0ReOuI8aAauSthTY/6WNMX31SdcOX2NVoVvV7LDNKlG3EQIiE4o BRMuIs7uqFA5ZjAyaxe3YT3l9SpG7dY= 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-182-7fSoIBntOKG3KrLEk3d66A-1; Fri, 15 Nov 2024 18:23:00 -0500 X-MC-Unique: 7fSoIBntOKG3KrLEk3d66A-1 X-Mimecast-MFC-AGG-ID: 7fSoIBntOKG3KrLEk3d66A 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 3E42119560A6; Fri, 15 Nov 2024 23:22:59 +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 BEEBC3003B71; Fri, 15 Nov 2024 23:22:58 +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 4AFNMvJp627952 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 15 Nov 2024 18:22:57 -0500 Received: (from bmarzins@localhost) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.2/8.17.2/Submit) id 4AFNMvNV627951; Fri, 15 Nov 2024 18:22:57 -0500 From: Benjamin Marzinski To: Christophe Varoqui Cc: device-mapper development , Martin Wilck Subject: [PATCH 1/6] libmultipath: signal device with no table in libmp_mapinfo Date: Fri, 15 Nov 2024 18:22:51 -0500 Message-ID: <20241115232256.627933-2-bmarzins@redhat.com> In-Reply-To: <20241115232256.627933-1-bmarzins@redhat.com> References: <20241115232256.627933-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: Ck-2XEHS2ejRp2Kc5e24zueK8IBWsZAwKJsiuwV54Po_1731712979 X-Mimecast-Originator: redhat.com 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 9714270d..b718dccf 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 15 23:22:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 13877407 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 8030719F40E for ; Fri, 15 Nov 2024 23:23:05 +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=1731712987; cv=none; b=Qgws8YfTVHZ2VRjQ+oJ5ZdDDifWWrQ3I4bRlZp12uC51IDduCEnKiVy5e2TfBxhDKAL8CdpXa/ASfcFYlszWS8cYkUGqVH1KS0RvCDPq2KSQhKqK9lb0KnOdIPHp/76OJEgX0x8VTtmrGiRcpLQIDfZ7LLGnpEABYqI1j3vi5Ow= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731712987; c=relaxed/simple; bh=P8I73uIvErG1CVcnSjIv84jZCfTY/0oo7ixlvdEfgIc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=s5hfEqhKax7GDHBzmnjmyY3WPQdZ4hT6mdjcLRTf2vqMtmwdguu3MSeItp4Ogi6gjFItVxz78qrMTJqbgfvrghKolPEXOv2Q0bIV6zgpO5d9bsXMynVKZUetBJZ4N8fW+C5aTCjlVfnY3BXP106vzPPkv3XxU/mBksaw5gPMmVM= 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=I6M5Ljeg; 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="I6M5Ljeg" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1731712984; 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=I6M5LjegIhtRu0DLKinSAGUDVeOy2wW8NEkOqhWw5IzCN4LRQm4HVg6atFNSZor8WXIj2o v7cbKMlvKbd4NaEIpl+V0wOW2j7trNcJ9gWkqqyfBBHqNOzitUs1qNvIk0RwqETM6tDBXv b2IZEQD51HMIvZRieIV/VYIawwlBiHg= 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-182-wx6uvRrhOU2ODLH3ddQdKQ-1; Fri, 15 Nov 2024 18:23:00 -0500 X-MC-Unique: wx6uvRrhOU2ODLH3ddQdKQ-1 X-Mimecast-MFC-AGG-ID: wx6uvRrhOU2ODLH3ddQdKQ 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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6DDEC1955F41; Fri, 15 Nov 2024 23:22:59 +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 112D01956089; Fri, 15 Nov 2024 23:22:58 +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 4AFNMvGE627956 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 15 Nov 2024 18:22:57 -0500 Received: (from bmarzins@localhost) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.2/8.17.2/Submit) id 4AFNMvG8627955; Fri, 15 Nov 2024 18:22:57 -0500 From: Benjamin Marzinski To: Christophe Varoqui Cc: device-mapper development , Martin Wilck , Martin Wilck Subject: [PATCH 2/6] multipath-tools tests: fix mapinfo tests Date: Fri, 15 Nov 2024 18:22:52 -0500 Message-ID: <20241115232256.627933-3-bmarzins@redhat.com> In-Reply-To: <20241115232256.627933-1-bmarzins@redhat.com> References: <20241115232256.627933-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: Oqhv6i9FFBFrMU31ePJY-8rQcN3ZuI7kT2zrZONjeOI_1731712979 X-Mimecast-Originator: redhat.com 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 15 23:22:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 13877408 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 DEB5A1A00FE for ; Fri, 15 Nov 2024 23:23:05 +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=1731712987; cv=none; b=VxlS0n+nVJ66fhzpOgZd9nEh0D0AqkbLyL3INFUS6FMDNWfrhIuycqYFJMyfNERfcgzlH/vFEjZIo5h+oXxfk8SPug4aIFE6FSaSxb4AXb1issIP18g2TnHHchAswzdCZuGBdD21iTWzIw2lmMheu1rsCM44YqH24RWu19FiuUY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731712987; c=relaxed/simple; bh=UfE3wje387FLrxxxZScNuOZLGOpSD/o7iKAdXhnqpVI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=c3q+RWZunVX4oegW0xTpMVwfZZOuwPx9+II9fDVmb49qZDsncDgTfO+CXlDEYBrOOqAqPWJWKSgJWG5hUCeN7JVUO8l8jqaPhl1pQJDvIGqWkjmptwu1XwxLLPfn2qP5C43x73+Lo4sv922sSDMx5lITuEho6gwUxt2KVJpk80o= 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=KDqk2sSS; 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="KDqk2sSS" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1731712984; 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=BCYWfZec574Tuw0r1eGkLNFpu1884L0vft1euEnA8Z8=; b=KDqk2sSST6YkqYQKpxs8TRvPXiN3GS4EmW/VQs3ZTdzKveALPZB7ZF77D+NcrCH2lZOLY2 fbhsG2uWu2n3vZAW3GBTj0ObqP9wSUKAWisnMHmRq6OVhn8Iocx1HXwMfyRhSSxmNoz0EN //+myO/edbSF2j6Iehcapmbio7+fG0M= 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-435-qCESoN2aPI-n2Z2w7RV7dg-1; Fri, 15 Nov 2024 18:23:00 -0500 X-MC-Unique: qCESoN2aPI-n2Z2w7RV7dg-1 X-Mimecast-MFC-AGG-ID: qCESoN2aPI-n2Z2w7RV7dg 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 40D1F19560B8; Fri, 15 Nov 2024 23:22:59 +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 E940E1956054; Fri, 15 Nov 2024 23:22:58 +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 4AFNMvw5627960 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 15 Nov 2024 18:22:57 -0500 Received: (from bmarzins@localhost) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.2/8.17.2/Submit) id 4AFNMv6u627959; Fri, 15 Nov 2024 18:22:57 -0500 From: Benjamin Marzinski To: Christophe Varoqui Cc: device-mapper development , Martin Wilck Subject: [PATCH 3/6] libmultipath: fix removing device after failed creation Date: Fri, 15 Nov 2024 18:22:53 -0500 Message-ID: <20241115232256.627933-4-bmarzins@redhat.com> In-Reply-To: <20241115232256.627933-1-bmarzins@redhat.com> References: <20241115232256.627933-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: asXoXD9RcYva-KqPsTJBn05t5JHVWDAZOt_9utrd-mI_1731712979 X-Mimecast-Originator: redhat.com 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 b718dccf..842e7c80 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 15 23:22:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 13877403 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 D7518190497 for ; Fri, 15 Nov 2024 23:23:04 +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=1731712986; cv=none; b=VBIkxZCd56sDN0dChaw5WefiOF+JFonijjmQ2uJetEJVh1BKjqduDooJJ6vF5uqo7ELnBmIen6L7smW/XFmI/FN5zKR+jpwoSXs5HSO8TFTQdFaGN0i+qBlmWpRCLQllycJM4IWZhoCs0FiwHxxlsx1Fkyb6YF/nrtf0GQ8yO3s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731712986; c=relaxed/simple; bh=obMWWhOGLTqybL0WOXC8WHGqjF5h4nczWyLp6Q08FWw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pRYlDS368dTDkMAmRreIQvW0umsA4aT8HDVgyVmMLwm4Tk2ChhIrwlNp/hC0MCOOdGXpiMZyR5GWoJtzuPpXeqUgl9eY3UHrpyDJld1r9iz+1rMRQKO3686XoVB1f5pQy2vwBfctPNrtU1Jb5HsSy6EwCIwgNC7Jso+Ugp6ZSJk= 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=Sbs2ptOp; 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="Sbs2ptOp" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1731712983; 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=cl5X1XtdBeeUSeRnglrhSlI4Mewb5bVavrffhDe3xYs=; b=Sbs2ptOpSX7gmIkQMWCB3GAs/sob5U2D6TliGYM6y3JuUM14zt/AR75HOGQ4Mug9NFvWQc QmNmMC9MKOWxMPSC02zJUg0nFBg88wkJLwPsK8Lr0loqlVaxlLiq7qzc/UWlQ8DqEX0daM /EARcVPEzr/BkHU7u9vYUXthcsH2Vxg= 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-425-7SPMq8WRPma8_i3674FL-w-1; Fri, 15 Nov 2024 18:23:00 -0500 X-MC-Unique: 7SPMq8WRPma8_i3674FL-w-1 X-Mimecast-MFC-AGG-ID: 7SPMq8WRPma8_i3674FL-w 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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A73301956083; Fri, 15 Nov 2024 23:22:59 +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 540C4196BC05; Fri, 15 Nov 2024 23:22:59 +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 4AFNMvvV627964 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 15 Nov 2024 18:22:57 -0500 Received: (from bmarzins@localhost) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.2/8.17.2/Submit) id 4AFNMvt6627963; Fri, 15 Nov 2024 18:22:57 -0500 From: Benjamin Marzinski To: Christophe Varoqui Cc: device-mapper development , Martin Wilck Subject: [PATCH 4/6] libmultipath: Add flag to always return device ID when found Date: Fri, 15 Nov 2024 18:22:54 -0500 Message-ID: <20241115232256.627933-5-bmarzins@redhat.com> In-Reply-To: <20241115232256.627933-1-bmarzins@redhat.com> References: <20241115232256.627933-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: kHvkXNGIWPgZWw92YLCLp0AiJJhm6F4n-RjWu_PvSVs_1731712979 X-Mimecast-Originator: redhat.com Normally, libmp_mapinfo will only return the name and uuid of a device if the device matches all the check requirements. Add a flag, MAPINFO_ID_IF_FOUND, to make it return the name and uuid as long as the result isn't DMP_ERR or DMP_NOT_FOUND. This will be used by a future patch. Signed-off-by: Benjamin Marzinski --- libmultipath/devmapper.c | 33 +++++++++---- libmultipath/devmapper.h | 5 ++ tests/mapinfo.c | 100 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 130 insertions(+), 8 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 842e7c80..42dcbc77 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -663,6 +663,19 @@ static int libmp_set_map_identifier(int flags, mapid_t id, struct dm_task *dmt) } } +static void write_ids(char *dst_name, const char *src_name, + char *dst_uuid, const char *src_uuid, const char *map_id) +{ + if (dst_name) { + strlcpy(dst_name, src_name, WWID_SIZE); + condlog(4, "libmp_mapinfo: %s: name: \"%s\"", map_id, dst_name); + } + if (dst_uuid) { + strlcpy(dst_uuid, src_uuid, DM_UUID_LEN); + condlog(4, "libmp_mapinfo: %s: uuid: \"%s\"", map_id, dst_uuid); + } +} + static int libmp_mapinfo__(int flags, mapid_t id, mapinfo_t info, const char *map_id) { /* avoid libmp_mapinfo__ in log messages */ @@ -740,6 +753,8 @@ static int libmp_mapinfo__(int flags, mapid_t id, mapinfo_t info, const char *ma ((flags & MAPINFO_PART_ONLY && !is_mpath_part_uuid(uuid, NULL)) || !is_mpath_uuid(uuid))) { condlog(4, "%s: UUID mismatch: %s", fname__, uuid); + if (flags & MAPINFO_ID_IF_FOUND) + write_ids(info.name, name, info.uuid, uuid, map_id); return DMP_NO_MATCH; } @@ -749,10 +764,16 @@ static int libmp_mapinfo__(int flags, mapid_t id, mapinfo_t info, const char *ma if (dm_get_next_target(dmt, NULL, &start, &length, &target_type, ¶ms) != NULL) { condlog(lvl, "%s: map %s has multiple targets", fname__, map_id); + if (flags & MAPINFO_ID_IF_FOUND) + write_ids(info.name, name, info.uuid, uuid, + map_id); return DMP_NO_MATCH; } if (!params || !target_type) { condlog(lvl, "%s: map %s has no targets", fname__, map_id); + if (flags & MAPINFO_ID_IF_FOUND) + write_ids(info.name, name, info.uuid, uuid, + map_id); return DMP_EMPTY; } if (flags & MAPINFO_TGT_TYPE__) { @@ -761,6 +782,9 @@ static int libmp_mapinfo__(int flags, mapid_t id, mapinfo_t info, const char *ma if (strcmp(target_type, tgt_type)) { condlog(lvl, "%s: target type mismatch: \"%s\" != \"%s\"", fname__, tgt_type, target_type); + if (flags & MAPINFO_ID_IF_FOUND) + write_ids(info.name, name, info.uuid, + uuid, map_id); return DMP_NO_MATCH; } } @@ -774,14 +798,7 @@ static int libmp_mapinfo__(int flags, mapid_t id, mapinfo_t info, const char *ma || (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); - } + write_ids(info.name, name, info.uuid, uuid, map_id); if (info.size) { *info.size = length; diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h index 0bd2b907..630dd7b6 100644 --- a/libmultipath/devmapper.h +++ b/libmultipath/devmapper.h @@ -67,6 +67,11 @@ enum { * multipath UUID format ("mpath-xyz"). */ MAPINFO_CHECK_UUID = (1 << 10), + /* + * If a device is found and info.name or info.uuid are non-NULL + * they will be set, even if the device doesn't match + */ + MAPINFO_ID_IF_FOUND = (1 << 11), }; typedef union libmp_map_identifier { diff --git a/tests/mapinfo.c b/tests/mapinfo.c index ee487989..1bfa1201 100644 --- a/tests/mapinfo.c +++ b/tests/mapinfo.c @@ -381,6 +381,23 @@ static void test_mapinfo_bad_get_info_01(void **state) assert_int_equal(rc, DMP_ERR); } +static void test_mapinfo_bad_get_with_ids(void **state) +{ + int rc; + char name[WWID_SIZE] = { 0 }; + struct dm_info dmi = { .suspended = 0 }; + + mock_mapinfo_name_1(DM_DEVICE_INFO, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&dmi); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_ID_IF_FOUND, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = name }); + assert_int_equal(rc, DMP_NOT_FOUND); + /* verify that name isn't set */ + assert_memory_equal(&name, &((char[WWID_SIZE]) { 0 }), WWID_SIZE); +} + static void test_mapinfo_bad_get_info_02(void **state) { int rc; @@ -574,6 +591,22 @@ static void test_mapinfo_bad_check_uuid_09(void **state) assert_int_equal(rc, DMP_OK); } +static void test_mapinfo_bad_check_uuid_with_ids(void **state) +{ + int rc; + 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_uuid, BAD_UUID_01); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_CHECK_UUID | MAPINFO_ID_IF_FOUND, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .uuid = uuid }); + assert_int_equal(rc, DMP_NO_MATCH); + assert_true(!strcmp(uuid, BAD_UUID_01)); +} + static void test_mapinfo_good_check_uuid_01(void **state) { int rc; @@ -884,6 +917,25 @@ static void test_mapinfo_bad_next_target_01(void **state) assert_int_equal(rc, DMP_NO_MATCH); } +static void test_mapinfo_bad_next_target_with_ids(void **state) +{ + int rc; + unsigned long long size; + char uuid[DM_UUID_LEN] = { 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_01); + will_return(__wrap_dm_task_get_uuid, MPATH_UUID_01); + /* multiple targets */ + mock_dm_get_next_target(12345, NULL, MPATH_STATUS_01, (void *)1); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_ID_IF_FOUND, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .size = &size, .uuid = uuid }); + assert_int_equal(rc, DMP_NO_MATCH); + assert_true(!strcmp(uuid, MPATH_UUID_01)); +} + static void test_mapinfo_bad_next_target_02(void **state) { int rc; @@ -900,6 +952,29 @@ static void test_mapinfo_bad_next_target_02(void **state) assert_int_equal(rc, DMP_EMPTY); } +static void test_mapinfo_no_target_with_ids(void **state) +{ + int rc; + unsigned long long size; + char name[WWID_SIZE] = { 0 }; + + expect_value(__wrap_dm_task_create, task, DM_DEVICE_STATUS); + will_return(__wrap_dm_task_create, 1); + expect_value(__wrap_dm_task_set_uuid, uuid, MPATH_UUID_01); + will_return(__wrap_dm_task_set_uuid, 1); + will_return(__wrap_dm_task_run, 1); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_02); + will_return(__wrap_dm_task_get_name, MPATH_NAME_01); + /* no targets */ + mock_dm_get_next_target(0, NULL, NULL, NULL); + rc = libmp_mapinfo(DM_MAP_BY_UUID | MAPINFO_ID_IF_FOUND, + (mapid_t) { .str = MPATH_UUID_01, }, + (mapinfo_t) { .size = &size, .name = name }); + assert_int_equal(rc, DMP_EMPTY); + assert_true(!strcmp(name, MPATH_NAME_01)); +} + /* libmp_mapinfo needs to do a DM_DEVICE_STATUS ioctl */ static void test_mapinfo_bad_target_type_01(void **state) { @@ -915,6 +990,26 @@ static void test_mapinfo_bad_target_type_01(void **state) assert_int_equal(rc, DMP_NO_MATCH); } +static void test_mapinfo_bad_target_with_ids(void **state) +{ + int rc; + char uuid[DM_UUID_LEN] = { 0 }; + struct dm_info dmi = { .suspended = 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_01); + will_return(__wrap_dm_task_get_uuid, MPATH_UUID_01); + mock_dm_get_next_target(12345, "linear", MPATH_STATUS_01, NULL); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY | MAPINFO_ID_IF_FOUND, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .uuid = uuid, .dmi = &dmi }); + assert_int_equal(rc, DMP_NO_MATCH); + assert_true(!strcmp(uuid, MPATH_UUID_01)); + /* Verify the dmi isn't geting set */ + assert_memory_equal(&dmi, &((struct dm_info) { .exists = 0 }), sizeof(dmi)); +} + static void test_mapinfo_bad_target_type_02(void **state) { int rc; @@ -1376,6 +1471,7 @@ static int test_mapinfo(void) cmocka_unit_test(test_mapinfo_bad_task_run_10), cmocka_unit_test(test_mapinfo_bad_task_run_11), cmocka_unit_test(test_mapinfo_bad_get_info_01), + cmocka_unit_test(test_mapinfo_bad_get_with_ids), cmocka_unit_test(test_mapinfo_bad_get_info_02), cmocka_unit_test(test_mapinfo_bad_get_info_03), cmocka_unit_test(test_mapinfo_bad_get_info_04), @@ -1390,6 +1486,7 @@ static int test_mapinfo(void) cmocka_unit_test(test_mapinfo_bad_check_uuid_07), cmocka_unit_test(test_mapinfo_bad_check_uuid_08), cmocka_unit_test(test_mapinfo_bad_check_uuid_09), + cmocka_unit_test(test_mapinfo_bad_check_uuid_with_ids), cmocka_unit_test(test_mapinfo_good_check_uuid_01), cmocka_unit_test(test_mapinfo_good_check_uuid_02), cmocka_unit_test(test_mapinfo_good_check_uuid_03), @@ -1409,8 +1506,11 @@ static int test_mapinfo(void) cmocka_unit_test(test_mapinfo_good_uuid), cmocka_unit_test(test_mapinfo_good_size), cmocka_unit_test(test_mapinfo_bad_next_target_01), + cmocka_unit_test(test_mapinfo_bad_next_target_with_ids), cmocka_unit_test(test_mapinfo_bad_next_target_02), + cmocka_unit_test(test_mapinfo_no_target_with_ids), cmocka_unit_test(test_mapinfo_bad_target_type_01), + cmocka_unit_test(test_mapinfo_bad_target_with_ids), cmocka_unit_test(test_mapinfo_bad_target_type_02), cmocka_unit_test(test_mapinfo_bad_target_type_03), cmocka_unit_test(test_mapinfo_bad_target_type_04), From patchwork Fri Nov 15 23:22:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 13877405 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 507961991DD for ; Fri, 15 Nov 2024 23:23:05 +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=1731712987; cv=none; b=mEgaGHx18x7kJciOTl+J5ww6e+1T7uFFMRAnA7BXviWboNqIgwX5rRaE+YuXIatjZKT2t4W5/bc1po3u5IrGQ8Uf3JZ3W7nJ6vfy/qkdyB7EYSmxIcBCxy4w/BAH7jHiQ0wcVltarWrtUxuFkCcDL7oL5tTBrAxX5faVvojv88k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731712987; c=relaxed/simple; bh=2wZ5mjxv3kRL+QvMvIoRvxY0+LfEaXpNmbawtQrDKbc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=D7ApsC6t3FKSzUIUuSjVkq5OGNd2Jg9TKXLZOoGGnAc+RwKVzAS8Kko0EdechL2EJv/Bvj9nbaSuIKBfyWMLYiMLNbmFuntoh/quqeL+oiooVmekdcWNDGAJs5EyXAKhCuOynkNw+3I0DTyt+KYxRXMhJIIa7ixRGWzp3pzsvJs= 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=bpnWI2wP; 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="bpnWI2wP" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1731712984; 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=QO3/xpnSX52xP7nQ607VKTNlDEaSqeLqe30Wuj37Zvs=; b=bpnWI2wPW25Q/kIE5SmM+Px342GSZkNvIQ9OgrLgzXTIMALzk08SKiGY7jm41vW5W8vfYr TPwjUcj41V8LYmCi8dCVuUdVci2zXaPNEx26Sfp2Sqi7kA3cEKXcct+tPbGrl+ad7ziMSN FKz9fHeo7cGZYrptLK0q/jeZVcKvoYc= 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-439-Ku2gwpIYPEa0eaHcZLRepg-1; Fri, 15 Nov 2024 18:23:00 -0500 X-MC-Unique: Ku2gwpIYPEa0eaHcZLRepg-1 X-Mimecast-MFC-AGG-ID: Ku2gwpIYPEa0eaHcZLRepg 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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B286619541AE; Fri, 15 Nov 2024 23:22:59 +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 663B23003B71; Fri, 15 Nov 2024 23:22:59 +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 4AFNMwMs627968 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 15 Nov 2024 18:22:58 -0500 Received: (from bmarzins@localhost) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.2/8.17.2/Submit) id 4AFNMwHe627967; Fri, 15 Nov 2024 18:22:58 -0500 From: Benjamin Marzinski To: Christophe Varoqui Cc: device-mapper development , Martin Wilck Subject: [PATCH 5/6] libmultipath: check table type in dm_find_map_by_wwid Date: Fri, 15 Nov 2024 18:22:55 -0500 Message-ID: <20241115232256.627933-6-bmarzins@redhat.com> In-Reply-To: <20241115232256.627933-1-bmarzins@redhat.com> References: <20241115232256.627933-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: p_GbZNG31TEdEMo512MhCgEjOuq_4bWRTi1U9kDCay4_1731712979 X-Mimecast-Originator: redhat.com 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. Also, make dm_find_map_by_wwid() returned the alias of any found device, even if it's not a valid multipath device. 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 42dcbc77..fa637c75 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -910,7 +910,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 | MAPINFO_ID_IF_FOUND, (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 15 23:22:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 13877406 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 3886319E98B for ; Fri, 15 Nov 2024 23:23:05 +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=1731712987; cv=none; b=nm5vrML0Jma7PJnZ18bW/MqZn+osr+RqCOEG1jeR0LVad7BzbZTIW3Qx7h6Fqxx1MNxKANRMBdbUNY/gzfVIpvTzv+z9Co7+4eVLFOIvFyB7057uqeXFGJCFX2goi0Lg9NugRz+XnngBYqr/ZnVkNUHZNE9QfgILdvxOnVjRmnI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731712987; c=relaxed/simple; bh=5u1fJfaqTxp5ngofSBsrH3Ty4t5CaaV50Q/BQT6r3qc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rLCyM5z2m4+ed2FWx1G3a9rCzDeIJgYIFQinQQZmbfrSe+3lXzDnaVxI6s/IDmcjHJHEyhU57Xm26/GPSAtZiruu2eTSRNq6DXqzonLhUet4op3OZwra9RStd0fsfnjxemFGjw/uwel+oqz6UfIAzGEZ89RQ5u8DLQuNgymYblA= 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=ZUhH/0+U; 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="ZUhH/0+U" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1731712984; 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=ZUhH/0+UktdYYMVB7zbuCidLdH1thGKrCLo+MZ6ooir8Wb56o0ExJNuL5g+qWhlBt95K8M QwO6silhCCbRrE7EEnOZMf//20bv7OMc3Rx9m0HuqjRw/aPcYEM3qvl0pAARIJ7tt9chDf 7jIYRYc8bbS+sFDa9MxTr9Bb2DoB6WU= 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-472-3v9HOHZTPzKrZ1CMdVjyAw-1; Fri, 15 Nov 2024 18:23:01 -0500 X-MC-Unique: 3v9HOHZTPzKrZ1CMdVjyAw-1 X-Mimecast-MFC-AGG-ID: 3v9HOHZTPzKrZ1CMdVjyAw 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 033FD19560A2; Fri, 15 Nov 2024 23:23:00 +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 A21B51956054; Fri, 15 Nov 2024 23:22:59 +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 4AFNMw0R627972 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 15 Nov 2024 18:22:58 -0500 Received: (from bmarzins@localhost) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.2/8.17.2/Submit) id 4AFNMwdX627971; Fri, 15 Nov 2024 18:22:58 -0500 From: Benjamin Marzinski To: Christophe Varoqui Cc: device-mapper development , Martin Wilck Subject: [PATCH 6/6] libmultipath: handle a create corner case for empty devices Date: Fri, 15 Nov 2024 18:22:56 -0500 Message-ID: <20241115232256.627933-7-bmarzins@redhat.com> In-Reply-To: <20241115232256.627933-1-bmarzins@redhat.com> References: <20241115232256.627933-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: c2qt_nS_UqdH96rqQpQBZ2LvTPKh9xrHA3n4uj35IcM_1731712980 X-Mimecast-Originator: redhat.com 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) {