From patchwork Fri Jul 12 17:14:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13732048 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 55C791741FE for ; Fri, 12 Jul 2024 17:15:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804534; cv=none; b=QIl/y5jo2mK+hCvh88QqqDww4Ws09AnMTQtyzphPlDaBnjviECWeM0trUdf0puC4fItyq0WSrqotMOTapP5OQtjUmsY/ASohxzv1l/bLzrBqqz87ZgT4SZmn5P9BUR7O1w4AILa+Nq5a7H7Ho2e/xTtG7Qr1JHgUGc4zRq1zi9I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804534; c=relaxed/simple; bh=lrE5nAEnTXOTGAJDgbqB1wnOa8mj/YBYNdfzgHgFexg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ir91s829UoSLMWp1S9m2on8o2Nj2XmBxcvww4/0saqrDXs+NfNccs+1QIwiIvvdSQ9xgTlYghH9H71OkamLBI/Fofu8EtaeCXjI5hX2sYhPSNyE0gdpExih6SF6j858JuJg7PwY8uGublc+H67foi97V9SKOI14Hm/7RqskWPCg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=Da33KnE8; arc=none smtp.client-ip=209.85.218.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="Da33KnE8" Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-a77e2f51496so313310566b.0 for ; Fri, 12 Jul 2024 10:15:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1720804530; x=1721409330; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9ivbZdM3R+FX1L2KmRZ3BQcmEiZdEEqW/Q42IbE6QDg=; b=Da33KnE8JrrDm5/SBQBoNTpOlYgwaL78ce0sFSbO97BeBx6h9Omf2rOURKzU0x5Kxl RRzahLoMtUhn0gddLlLG2wnZmjxbGCxJ3R9hiZtcpmQTjbqPseOMuKcxbhcosl0+veb7 6RbG/FkD/WMZ6cmfC8ob8b/OfC6Nx9PoZ+lBm1K/Lthh7ayNoesrPloQAF+kXJu999Ma iZjEbPOha6S7h2Sv6b3ykIc4waOc+DZ4OCNDON5Q+AuWYDq9YAYYUwudpxxK8Xmx0lCe fGMfEHM1jtHs4Tdr1miQHxDFiNUnFgpD99BlQlCcNxPOiyEx5MoOXPS6ySntWWSwi4Jk lBqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720804530; x=1721409330; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9ivbZdM3R+FX1L2KmRZ3BQcmEiZdEEqW/Q42IbE6QDg=; b=EOQyDyP6gb4ZJuner2eojXQyTKhl4IbGhmLpxOT0AkAbFsLt3hMuyHdchUh1r4Ubgx mYPIfexT3ZR46M67nyaed52bBtOEb7X6fmDj5CU8eMXmQ/ApzMDLBOgt8pLMxYFlKjII nQ+j5t6neydjxooS2NdVg5HbIP8sUeh7ig0hsfxJyQJ3U4CqbCyFUBP3eTOO/gXPPWAJ 44WWCUPkylRd2x+YmtpUW9u7pSIqCI0bl4nY3FfeS+Gmbiob9e5OQfbSixXZoQ3CvOxd CMxAB3gviqTA2StHVkFnsbJpp6pNgxIKor5mKzyFkZggTzk6ShdGVJaK5IdPCp1+TUNZ cAyg== X-Gm-Message-State: AOJu0Yyd4cehY+IO69Lw+0MKdoBcHvUOP8C4a3mRiiYQ6dW7xtFr9ZEo zkrs9Mv67xUNgeiB6cSvGEI8zdZlhl5IQWu61wJ4GrNgzhgRc/tnAM6vZSDbxoQ= X-Google-Smtp-Source: AGHT+IE+FNmUw+lsZhW2TJaPxdjn07+eTP8YhF5BYtmibQUydG7qU3UX30krgvSsX3iL3NmEEC8phg== X-Received: by 2002:a17:906:f58e:b0:a6f:501d:c224 with SMTP id a640c23a62f3a-a780b883529mr1124233066b.57.1720804529437; Fri, 12 Jul 2024 10:15:29 -0700 (PDT) Received: from localhost (p200300de37360a00d7e56139e90929dd.dip0.t-ipconnect.de. [2003:de:3736:a00:d7e5:6139:e909:29dd]) by smtp.gmail.com with UTF8SMTPSA id a640c23a62f3a-a780a6bc897sm364000666b.39.2024.07.12.10.15.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 10:15:29 -0700 (PDT) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, Martin Wilck Subject: [PATCH v2 01/49] multipath-tools CI: more fixes for arm/v7 Date: Fri, 12 Jul 2024 19:14:09 +0200 Message-ID: <20240712171458.77611-2-mwilck@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712171458.77611-1-mwilck@suse.com> References: <20240712171458.77611-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The previous fix for the CI under arm/v7 was incomplete, and actually broke the tests under openSUSE Tumbleweed. Closer examination showed that the issues were caused by Debian's move to 64bit time_t on some 32 bit architectures [1][2]. This effort causes _TIME_BITS=64 to be set by gcc internally, and introduces symbol redirections for libaio [3], on Debian with gcc 13 and newer only. Fix the conditions for symbol remappings in wrap64.h. [1] https://wiki.debian.org/ReleaseGoals/64bit-time [2] https://salsa.debian.org/toolchain-team/gcc/-/commit/d82fb8a8ab7b84f61fb8290a2c3aa2e3f54e7b8a [3] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1062218 Fixes: 6a7524a ("multipath-tools tests: fix CI failures on arm/v7 with glibc 2.37") Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- tests/wrap64.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/wrap64.h b/tests/wrap64.h index 7e43420..af6cc2b 100644 --- a/tests/wrap64.h +++ b/tests/wrap64.h @@ -2,6 +2,8 @@ #define _WRAP64_H 1 #include #include +/* The following include is required for LIBAIO_REDIRECT */ +#include #include "util.h" /* @@ -47,7 +49,8 @@ * fcntl() needs special treatment; fcntl64() has been introduced in 2.28. * https://savannah.gnu.org/forum/forum.php?forum_id=9205 */ -#if defined(__GLIBC__) && __GLIBC_PREREQ(2, 37) && defined(__arm__) && __ARM_ARCH == 7 +#if defined(__GLIBC__) && __GLIBC_PREREQ(2, 34) && __BITS_PER_LONG == 32 \ + && defined(_TIME_BITS) && _TIME_BITS == 64 #define WRAP_FCNTL_NAME __fcntl_time64 #elif defined(__GLIBC__) && __GLIBC_PREREQ(2, 28) #define WRAP_FCNTL_NAME WRAP_NAME(fcntl) @@ -60,7 +63,8 @@ /* * glibc 2.37 uses __ioctl_time64 for ioctl */ -#if defined(__GLIBC__) && __GLIBC_PREREQ(2, 37) && defined(__arm__) && __ARM_ARCH == 7 +#if defined(__GLIBC__) && __GLIBC_PREREQ(2, 34) && __BITS_PER_LONG == 32 \ + && defined(_TIME_BITS) && _TIME_BITS == 64 #define WRAP_IOCTL_NAME __ioctl_time64 #else #define WRAP_IOCTL_NAME ioctl @@ -68,7 +72,8 @@ #define WRAP_IOCTL CONCAT2(__wrap_, WRAP_IOCTL_NAME) #define REAL_IOCTL CONCAT2(__real_, WRAP_IOCTL_NAME) -#if defined(__NR_io_pgetevents) && __BITS_PER_LONG == 32 && defined(_TIME_BITS) && _TIME_BITS == 64 +#if defined(__GLIBC__) && defined(LIBAIO_REDIRECT) && __BITS_PER_LONG == 32 \ + && defined(_TIME_BITS) && _TIME_BITS == 64 #define WRAP_IO_GETEVENTS_NAME io_getevents_time64 #else #define WRAP_IO_GETEVENTS_NAME io_getevents From patchwork Fri Jul 12 17:14:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13732050 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A39CE176ABE for ; Fri, 12 Jul 2024 17:15:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804536; cv=none; b=tjJSrXSRWkpD0G/kCbwoo5vhr7Bag3MaewWgzcd87+NUB4U3UF3s/Hd1/234yR2YtmBMgXld9JAsxwG6tq2LmGbytcI+o7pVA+Ey4A1ItixBPrX7MlPXoZ0clQxGpvQ7A6Y2iMc0yBs3Y2hYOWVsNN4BOwcTpFaqlZgrrBuiXeU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804536; c=relaxed/simple; bh=OKCYTNZZaDC20n0Cy3CqNlORaDH191ES0Cxf1QL6zy0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sOYp92+UwGyw9BjMBccKzUgWuszxs8QFRhVI1Tn5TYDOVuqwjpTvgpE3T3f/1oWBXqEEnse8Can5QEFEdUZjJXN7MFg/eWMD7eN0tu8kJso3BlTzHtmVuE6PeXdkUROoJ08dHhrs1soPOzchr5fcToHy+9H6MzJX+yKOSF5rhoo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=P+jvRLUS; arc=none smtp.client-ip=209.85.218.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="P+jvRLUS" Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-a77d9217e6fso306964666b.2 for ; Fri, 12 Jul 2024 10:15:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1720804532; x=1721409332; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mqusqh2vhyGec+snCsCxQ3oDSIUwcEZnW2tcGL8ffEY=; b=P+jvRLUSn1k3CCWeYWg8WHWc8tbgx0ov0Abf8E3IZ4H+gx5VcdC1fuHMCPquGleuUN 9/w6J3E1RnN6OcWFCcA0j83GGuQc3lt7R/2YKxXuX/i+jYe2ZimizswVhPyQM2BYR74o tW4e6j31hSZYOGD4U/tCejYkewVLC71pKvXcTaNvLuxllEpa0G/8e7ICC7NS7Nu3feVL rJ6l2MTeWZ+TJNYXQYKh+sH6t0kxNfmacmhimhv3LcbxaM0m2o+WLEbMEVyEm8vCuZUk kMXrw2VqDj8e239B+jQ9s9jKEkJTUbfG5WT8Ervi7PKBTbrgYR00chnF1AnnELXYukaQ Oc/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720804532; x=1721409332; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mqusqh2vhyGec+snCsCxQ3oDSIUwcEZnW2tcGL8ffEY=; b=HroKlGDt1sai45w2rlb44KZbCQGH0xd6Jq+INN3MUoRjMjy/QLhWWErnfpIjLEn1uS /E8Kr5Chmw2S6CgSagYNo3aWoqAa7NuAQy8HU6QQ8a6I5E8nOXgg93ko0EaIwEsV82mB jU2j4Q0sc5D5EC2My7KyAaj4XPSk1vF1xXBCgV7XiJyHRCf7ukUNbmfLvB5/4WeW/deo IL0vRS1anguHJFzGohlfJogoe7yD6zIMRoTmkCbT584/J7Ir0JjMKR/qJrLTwxVfj6jP 7IHQoeJHCCeG0O+3zbByIKBUiYB+79MDgFcauR0UHnaeS+rVtRJGp7+7AZ7/hCpYxXYq Kd9A== X-Gm-Message-State: AOJu0Yy2Uq27ERLufV+pJukWDb3LoEcm62nnnA+DxBTh2nPurtZhjc1L T6EPRZ89LsHqwijJ2s0O+wWCwzTFa+rotaPqnKxrwZj7cXZe40a/0jElKCizIxU= X-Google-Smtp-Source: AGHT+IF0VCCjIWYLU+mCLQJFWjdrvZmf7Xmf2zTHnKXruwDhOabYEjKllYRljPtcWLqdAk6svvZIXg== X-Received: by 2002:a17:907:7284:b0:a77:d1ea:ab36 with SMTP id a640c23a62f3a-a780b68a2d7mr1010095466b.6.1720804530683; Fri, 12 Jul 2024 10:15:30 -0700 (PDT) Received: from localhost (p200300de37360a00d7e56139e90929dd.dip0.t-ipconnect.de. [2003:de:3736:a00:d7e5:6139:e909:29dd]) by smtp.gmail.com with UTF8SMTPSA id a640c23a62f3a-a780a7ff282sm363091066b.130.2024.07.12.10.15.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 10:15:30 -0700 (PDT) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, Martin Wilck Subject: [PATCH v2 02/49] multipath-tools CI: fix dmevents test for Debian Sid, arm/v7 Date: Fri, 12 Jul 2024 19:14:10 +0200 Message-ID: <20240712171458.77611-3-mwilck@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712171458.77611-1-mwilck@suse.com> References: <20240712171458.77611-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Same fix as in 6a7524a ("multipath-tools tests: fix CI failures on arm/v7 with glibc 2.37"). Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- tests/dmevents.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/tests/dmevents.c b/tests/dmevents.c index 395b16d..668e6d2 100644 --- a/tests/dmevents.c +++ b/tests/dmevents.c @@ -253,8 +253,9 @@ int __wrap_dm_geteventnr(const char *name) return -1; } -int __wrap_ioctl(int fd, unsigned long request, void *argp) +int WRAP_IOCTL(int fd, unsigned long request, void *argp) { + condlog(1, "%s %ld", __func__, request); assert_int_equal(fd, waiter->fd); assert_int_equal(request, DM_DEV_ARM_POLL); return mock_type(int); @@ -675,7 +676,7 @@ static void test_dmevent_loop_bad1(void **state) skip(); will_return(__wrap_poll, 1); - will_return(__wrap_ioctl, -1); + wrap_will_return(WRAP_IOCTL, -1); assert_int_equal(dmevent_loop(), 1); dev_evt = find_dmevents("foo"); assert_ptr_not_equal(dev_evt, NULL); @@ -697,7 +698,7 @@ static void test_dmevent_loop_bad2(void **state) skip(); will_return(__wrap_poll, 1); - will_return(__wrap_ioctl, 0); + wrap_will_return(WRAP_IOCTL, 0); will_return(__wrap_libmp_dm_task_create, NULL); assert_int_equal(dmevent_loop(), 1); dev_evt = find_dmevents("foo"); @@ -721,9 +722,8 @@ static void test_dmevent_loop_good0(void **state) remove_all_dm_device_events(); unwatch_all_dmevents(); will_return(__wrap_poll, 1); - will_return(__wrap_ioctl, 0); + wrap_will_return(WRAP_IOCTL, 0); will_return(__wrap_libmp_dm_task_create, &data); - will_return(__wrap_dm_task_no_open_count, 1); will_return(__wrap_dm_task_run, 1); will_return(__wrap_dm_task_get_names, 1); assert_int_equal(dmevent_loop(), 1); @@ -757,9 +757,8 @@ static void test_dmevent_loop_good1(void **state) assert_int_equal(add_dm_device_event("foo", 1, 6), 0); assert_int_equal(remove_dm_device_event("xyzzy"), 0); will_return(__wrap_poll, 1); - will_return(__wrap_ioctl, 0); + wrap_will_return(WRAP_IOCTL, 0); will_return(__wrap_libmp_dm_task_create, &data); - will_return(__wrap_dm_task_no_open_count, 1); will_return(__wrap_dm_task_run, 1); will_return(__wrap_dm_task_get_names, 1); expect_string(__wrap_update_multipath, mapname, "foo"); @@ -805,9 +804,8 @@ static void test_dmevent_loop_good2(void **state) assert_int_equal(watch_dmevents("baz"), 0); assert_int_equal(add_dm_device_event("baz", 1, 14), 0); will_return(__wrap_poll, 1); - will_return(__wrap_ioctl, 0); + wrap_will_return(WRAP_IOCTL, 0); will_return(__wrap_libmp_dm_task_create, &data); - will_return(__wrap_dm_task_no_open_count, 1); will_return(__wrap_dm_task_run, 1); will_return(__wrap_dm_task_get_names, 1); expect_string(__wrap_update_multipath, mapname, "bar"); @@ -849,9 +847,8 @@ static void test_dmevent_loop_good3(void **state) assert_int_equal(remove_dm_device_event("foo"), 0); unwatch_dmevents("bar"); will_return(__wrap_poll, 1); - will_return(__wrap_ioctl, 0); + wrap_will_return(WRAP_IOCTL, 0); will_return(__wrap_libmp_dm_task_create, &data); - will_return(__wrap_dm_task_no_open_count, 1); will_return(__wrap_dm_task_run, 1); will_return(__wrap_dm_task_get_names, 1); expect_string(__wrap_remove_map_by_alias, alias, "foo"); @@ -874,7 +871,7 @@ static void test_arm_poll(void **state) struct test_data *datap = (struct test_data *)(*state); if (datap == NULL) skip(); - will_return(__wrap_ioctl, 0); + wrap_will_return(WRAP_IOCTL, 0); assert_int_equal(arm_dm_event_poll(waiter->fd), 0); } From patchwork Fri Jul 12 17:14:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13732051 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CC5EF168C4 for ; Fri, 12 Jul 2024 17:15:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804537; cv=none; b=VNFxNfHTjRPwJ5kellCwBwCjMcBeyajm9j62rpvtNrUP1B3KtJ3Wlxv+RbWGcMsdMfb0evefQOMStKCM6EJQBwfD8fmKnqmYKI816OqOsu4wQbAaQuTl+sUT6yYRDdTgLGKsU6GYroVRZM1EKBo4NcEGU0L9by1t6uFgN5uWD8Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804537; c=relaxed/simple; bh=JDFDHoU9d6lh3O6Di3X+L8QStA3NoULhVKibPZLGtAw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ubes3b2PAiL/pzmLUuXCOeIIDDqigg5c+PdndEi1MjLN05Llm4dGlYaVnIlhiJ5l6WpN850zBa2VJEpsrUEy+oez7O5EK/H1S7JAd+CxUaW2km6YbSszKwBuNguWmiLixpV3grzvUPeRyrs7fN3XogEu1OC1vnmt7KnZt4T9hT0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=IOIo3SWK; arc=none smtp.client-ip=209.85.218.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="IOIo3SWK" Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-a77cc73d35fso586712666b.0 for ; Fri, 12 Jul 2024 10:15:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1720804533; x=1721409333; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ky0DDwpVe7VQGfMPQcn0cPxjmfpgfFVqTfAk8RZ/c5w=; b=IOIo3SWK+NoNX0a9jFiKd03Ii3XZyxcLWqFEyEPuJruWeyNbIr/uTFipywSWYziL9M MuXxOFy0M96g8L424b/XBkJvjldiyhIr7vwGFlau2u7fRmOdCdDIjyqoXA9lhb5WhqAM tFBSiqcn3MIdQ8X1cOH/IoYunsKgN6in7uzAHrLhV3BawkPttETHg6UCDzvtlxr4YYDe dEkHS/KvG1C4HtEgHErAWsab35K4i02STu1tzY34mvRglQyfx5EjN24up4OqEj7NpxOA piAI9X/Z+jdGNkkAllz7p8VZ8yMYsrRcrMc1NegGlHK+ovnfGAE1JnIhLaRvsjMp+FGi C71Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720804533; x=1721409333; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ky0DDwpVe7VQGfMPQcn0cPxjmfpgfFVqTfAk8RZ/c5w=; b=AZ7S54z+ODVLeSYDqY7Ues9Zwxd1qjFq4QOaN0oAd4V1jBalDb+V2VJqceqZHOkuP9 wRzaUsBIJPmwIynrDlfM8TLQ+p2tdqSEtSJe/s+iRNtvqC5rQzqD5CM9jilStfS5thJt aDuZK+FeycK48YshecMrtMDPLQyvgFfM87fII+DfsiaGTteZqyWYbto+7BrVApckpoyW hilA7uoErQGckq2rPUQrWe0gF0kw9Fn8zkEAy5Okw67qAlMBY01VmaSItRkaF5n+PMW5 u/mVlNWOWBfi2BJlv+fzOK3onOTb7KUo8MEzKVDbePp+eseRoH09UjUKXxTMz7iOPX1t xrTg== X-Gm-Message-State: AOJu0Yy0U3xYFLRaJoSpJ86wGddQbVZtPyR/4vxI6l5Fo4dXabhunUkv D1DLAIbi5qvy4+CG3Nb89i++QZfr8Mnt6lkK4oegTM/00+jkNi43O8AUJix40uoKd+du7iTx+3y j X-Google-Smtp-Source: AGHT+IGWvEDtpdTKDycfxgtj6BwQ4oXUl3hP6JE98F7fshkpZMm6nkZqE6Vc9xVPz4v2+2+gzAHfqQ== X-Received: by 2002:a17:907:86a3:b0:a72:75a5:bb42 with SMTP id a640c23a62f3a-a799d393418mr290974366b.29.1720804533029; Fri, 12 Jul 2024 10:15:33 -0700 (PDT) Received: from localhost (p200300de37360a00d7e56139e90929dd.dip0.t-ipconnect.de. [2003:de:3736:a00:d7e5:6139:e909:29dd]) by smtp.gmail.com with UTF8SMTPSA id a640c23a62f3a-a780a856251sm363280666b.185.2024.07.12.10.15.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 10:15:32 -0700 (PDT) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, Martin Wilck Subject: [PATCH v2 03/49] create-config.mk: use printf instead of /bin/echo Date: Fri, 12 Jul 2024 19:14:11 +0200 Message-ID: <20240712171458.77611-4-mwilck@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712171458.77611-1-mwilck@suse.com> References: <20240712171458.77611-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The behavior of "echo -e" is not part of the POSIY standard and different shells handle it differently. OTOH, /bin/echo isn't necessarily available, either. Use printf instead, which is part of POSIX. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- create-config.mk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/create-config.mk b/create-config.mk index 4d318b9..0abbb3a 100644 --- a/create-config.mk +++ b/create-config.mk @@ -147,11 +147,11 @@ TEST_CC_OPTION = $(shell \ # On some distros (e.g. Debian Buster) it will be falsely reported as supported # but it doesn't seem to make a difference wrt the compilation result. FORTIFY_OPT := $(shell \ - if /bin/echo -e '$(__HASH__)include \nint main(void) { return 0; }' | \ + if printf '$(__HASH__)include \nint main(void) { return 0; }\n' | \ $(CC) -o /dev/null $(OPTFLAGS) -c -Werror -D_FORTIFY_SOURCE=3 -xc - 2>/dev/null; \ then \ echo "-D_FORTIFY_SOURCE=3"; \ - elif /bin/echo -e '$(__HASH__)include \nint main(void) { return 0; }' | \ + elif printf '$(__HASH__)include \nint main(void) { return 0; }\n' | \ $(CC) -o /dev/null $(OPTFLAGS) -c -Werror -D_FORTIFY_SOURCE=2 -xc - 2>/dev/null; \ then \ echo "-D_FORTIFY_SOURCE=2"; \ From patchwork Fri Jul 12 17:14:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13732052 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-ej1-f49.google.com (mail-ej1-f49.google.com [209.85.218.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B5AC31741FE for ; Fri, 12 Jul 2024 17:15:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804537; cv=none; b=EK0egVf6kZlTzq5bh7adp0fpEgOBMLWhSojVspE9YB38O5pmBLxfC2eFNlrn2Hz8CaXbSFYaOq8KI1d0Bn9Xh11ZNMBPnmHMgln9o+9Lk/uYqZCipIUSrpX9edegDOjKS1oR8BTfwUWFWxhrXEP2KoU2aS+x3dV2A7ZF2FarnUw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804537; c=relaxed/simple; bh=CNLRRXAEnW/JowZaB9dPkXOsSETqiaaDYJmrWlr0aH0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aEVsIfA4ae4GvfE1EWZNvVZygQF6zgmi1A6JIlmShdNY6MUpRVPN/BHbk8/8QrU9up2DTYrdoP4wud6sdh9nTktKcUf5cYIslcAp9kqol6y8TrKK/zDrsCRx0CxemTJVbxMO57ciiFAJc3dbIRC83KdN9Q5rVbZYqDccNKdbpuo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=XTQMtm9e; arc=none smtp.client-ip=209.85.218.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="XTQMtm9e" Received: by mail-ej1-f49.google.com with SMTP id a640c23a62f3a-a77cc73d35fso586714966b.0 for ; Fri, 12 Jul 2024 10:15:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1720804534; x=1721409334; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IZFL8y3BYWp+nTuY6qkieNI9HfQyambeOkiI5ShwR6I=; b=XTQMtm9eMP6hLyV5rg8q40QMxD2lGiKea+rlgxIhClXFksrR5DMTI5IghJuGSr/CtN 1UoRlp2HOEtUNs2fFjk3KfbwfCNmSXCqj3coSTA8SDJCtZThmSRe+Cia5m6JuPBW08yU X+fQGT9azPXMnL4OMq2eWEJOzxQtxBJm9cx/KamEQ9Fiv3Lqwajb9XU4Wt9Z7RXerA3j 52yrw0ZHX1iF+/7Sn7IOxF5+mahRokN47aqyujDm5PgNzKQ3NtW5xdfwy6ea1YAOIKcD WDVYcEZwkg5W3JiGggYPB3jeP31iTGAsdB/4C1/mhI2RnWzY3y4bZGIcF4oQbHyq8+tX o+Ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720804534; x=1721409334; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IZFL8y3BYWp+nTuY6qkieNI9HfQyambeOkiI5ShwR6I=; b=XLbsV4Rp3Liv52jiTdeqUpJBwWhPaG/Dwfb+N4o7y/IHcAEVy9xasEaUMoc7q7fnkA iIQfg0NDWrtIUuPi+Vw65NGf4UzV62y4tcvzaTR4OfH2v6v5kjsNS/GHKgzzRKgYudHt 3cf1deQ8WNCYM1to8CWep8/PagQ2Y+m9CaU0Imtcz30HSABL076doHmwVDnA/YfX712U OroBc2FLat5/YR6pyTxNml7MIT7N0pBWLv38tDwzPEM55cru+ECmPClyijva+dwZGfEI HPG+u/aPT83s90AKcsqXIx1cLUG1hWOlsK+iU/dSIoVLFPukljHQvS/QsEr7d6TlrjJt EWig== X-Gm-Message-State: AOJu0YxYWSGenU1YxfOe5W4jOjiLDuC/hPJVlOAJMMHv3swWLhtwB6To knLKfqOle7D9UcLL/8om500a50PwqwCJR+2i3hfPztZjWDzUJpYZ+C1KvE+IDj+fQ9NgCW4Ovoi g X-Google-Smtp-Source: AGHT+IEzQ9bimzGr4nz7SONzXubehSZu66EAlAm+Q0bODxW6jy5pHl5QvOHYIBv8MAOPcqOvXXiWoA== X-Received: by 2002:a17:907:1c25:b0:a73:9037:fdf5 with SMTP id a640c23a62f3a-a799d301a04mr311949466b.6.1720804533969; Fri, 12 Jul 2024 10:15:33 -0700 (PDT) Received: from localhost (p200300de37360a00d7e56139e90929dd.dip0.t-ipconnect.de. [2003:de:3736:a00:d7e5:6139:e909:29dd]) by smtp.gmail.com with UTF8SMTPSA id a640c23a62f3a-a780a86f604sm363811266b.207.2024.07.12.10.15.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 10:15:33 -0700 (PDT) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, Martin Wilck Subject: [PATCH v2 04/49] multipathd.service.in: use @BINDIR@ instead of /sbin Date: Fri, 12 Jul 2024 19:14:12 +0200 Message-ID: <20240712171458.77611-5-mwilck@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712171458.77611-1-mwilck@suse.com> References: <20240712171458.77611-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The path in the unit file should match the actual installation path. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- multipathd/multipathd.service.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/multipathd/multipathd.service.in b/multipathd/multipathd.service.in index a63ddd9..646001e 100644 --- a/multipathd/multipathd.service.in +++ b/multipathd/multipathd.service.in @@ -16,8 +16,8 @@ ConditionVirtualization=!container [Service] Type=notify NotifyAccess=main -ExecStart=/sbin/multipathd -d -s -ExecReload=/sbin/multipathd reconfigure +ExecStart=@BINDIR@/multipathd -d -s +ExecReload=@BINDIR@/multipathd reconfigure TasksMax=infinity LimitRTPRIO=10 CPUWeight=1000 From patchwork Fri Jul 12 17:14:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13732054 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-ed1-f48.google.com (mail-ed1-f48.google.com [209.85.208.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 19018176ABE for ; Fri, 12 Jul 2024 17:15:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804539; cv=none; b=SgGqy+Fr0Sq2zgcGNwBM/sJU1ECN6cbC6HzkWNmogRj6fWp+1YgmoBJYUd3mg4xj2V2CLowjHat76U/dcySKNIgYeNCOBmMNjT1OrqJZxoUSTXerXwP+GMsl1y4Pg53BW25HGY4z4a32ZdNYwu4SP7m1LyrWqVAJqKPolN0ZTo0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804539; c=relaxed/simple; bh=9jt5Guh6ISKYfj1RD6Ts+RWxC5vRJx9WzJAyMCwWdkA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y44Pb8Um9L+09c9DbTgfVWpPxK9ONdRP8+YhTSENzD83nchiCiDAoNwjJ5dq9t5IjzUau4vMuSfuR9IhewjCYPD1oZoEi2ZJBOzzfGzryxsb1vuNGub2jAnaZEtFkE4DCSt4OVdWyOHfrBXL48mqEijV3mpUAZMZ3uT25UCTEow= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=TdSzj4us; arc=none smtp.client-ip=209.85.208.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="TdSzj4us" Received: by mail-ed1-f48.google.com with SMTP id 4fb4d7f45d1cf-58b966b4166so2747207a12.1 for ; Fri, 12 Jul 2024 10:15:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1720804535; x=1721409335; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ePu3SC1iZasRALA8wuHfQT1WcdAaMxxqS8D8uK8AGzQ=; b=TdSzj4usvsxBMSrENx994FYN0fhzJQER7B3+oxzMEHF2IWd6DTGYm67kX7ihW/455u ecp5c2RWZh0iwUe6295Kk9HViseekPVJMIoxn8Xem4ZLWIE/iunkR8R+WfIZuHpJVKVb 2pmIYkRrH3UuYoTOAL3ToegCxGrcoVJ9hriQQD+b72kK3quxiiV+PpvmXE/UIIYUdtVZ xx8UI/Up+mzN2cnA+b3CEDn6I7HS9H18J3tb1lCTPaqqExJIrdyF2MPlrFgG0GAi6kUe 6vgz5Dz0D9CbZhv6rL1f9UOmsYSFFnc6n532tHuLxIaJgBkcocX3rcCh2rbgI0XmcP6l dDRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720804535; x=1721409335; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ePu3SC1iZasRALA8wuHfQT1WcdAaMxxqS8D8uK8AGzQ=; b=aFo2j5oOec3EzZcJyos9kXZ5HyMZlwt5TChVLOTo2zklNBx4lJwAjUuvfPUHxk1KS7 WwFns0N2zI7h95P+0eDyAFbrOCwFr9JoskKMZ7yYrtrIASX1TZ0gdQ6fzLhGpi3Gxlnz 9sycYA5k902IdyxuIslxo1zz5RNhPIJ+xUbN/DBaNCEBD0zh6/iwI1+me3vRFVRS5TOA IuuacZBl3V5DRu8osAtmxHqJB1WJlPKoybZOjjvhkZfwfZaB+qPLk5N5vlXF9y70XIB0 Ajdh7RAN7dAYp8VQThfpErWhzZsGxOKIY5JgodfqwrLcf+2b0soO/UDmqS/c6LcDXhMv UBJA== X-Gm-Message-State: AOJu0Yw/uRRz0DtXbQoPEiWv62TxtFcEMPMHDrJ6CECJmYZLuhOnvXOw h2+bstZSp0kg1bkTpOfhpvkEJQBotaXHMOWVBhrHt2wLfiK6G+HZEikpPkpPgIKmcyU9LDUY7Xo l X-Google-Smtp-Source: AGHT+IFoemqevxLEz+YDazk8f06DDSo/6GHTEPjFmdCZ1b6Ph0syjUM5JS+2hLFLRiXixEzwOx3ymQ== X-Received: by 2002:a05:6402:348d:b0:58d:81ac:ea90 with SMTP id 4fb4d7f45d1cf-594bcba77e6mr9764182a12.38.1720804534815; Fri, 12 Jul 2024 10:15:34 -0700 (PDT) Received: from localhost (p200300de37360a00d7e56139e90929dd.dip0.t-ipconnect.de. [2003:de:3736:a00:d7e5:6139:e909:29dd]) by smtp.gmail.com with UTF8SMTPSA id 4fb4d7f45d1cf-594bbe2d338sm4812097a12.39.2024.07.12.10.15.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 10:15:34 -0700 (PDT) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, Martin Wilck Subject: [PATCH v2 05/49] Makefile.inc: replace @BINDIR@ with $(TGTDIR)/$(bindir) Date: Fri, 12 Jul 2024 19:14:13 +0200 Message-ID: <20240712171458.77611-6-mwilck@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712171458.77611-1-mwilck@suse.com> References: <20240712171458.77611-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The unit files and udev rules that use @BINDIR@ for substitutions have the installation target's point of view, they must include $(TGTDIR) (which is empty by default). Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- Makefile.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.inc b/Makefile.inc index ed4a423..28b6032 100644 --- a/Makefile.inc +++ b/Makefile.inc @@ -150,4 +150,4 @@ NV_VERSION_SCRIPT = $(DEVLIB:%.so=%-nv.version) %: %.in @echo creating $@ - $(Q)sed 's:@CONFIGFILE@:'$(TGTDIR)$(configfile)':g;s:@CONFIGDIR@:'$(TGTDIR)$(configdir)':g;s:@STATE_DIR@:'$(TGTDIR)$(statedir)':g;s:@RUNTIME_DIR@:'$(runtimedir)':g;s/@MODPROBE_UNIT@/'$(MODPROBE_UNIT)'/g;s:@BINDIR@:'$(bindir)':g' $< >$@ + $(Q)sed 's:@CONFIGFILE@:'$(TGTDIR)$(configfile)':g;s:@CONFIGDIR@:'$(TGTDIR)$(configdir)':g;s:@STATE_DIR@:'$(TGTDIR)$(statedir)':g;s:@RUNTIME_DIR@:'$(runtimedir)':g;s/@MODPROBE_UNIT@/'$(MODPROBE_UNIT)'/g;s:@BINDIR@:'$(TGTDIR)$(bindir)':g' $< >$@ From patchwork Fri Jul 12 17:14:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13732053 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BC82C176AB1 for ; Fri, 12 Jul 2024 17:15:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804539; cv=none; b=DBnQaapkJ51aNhJP7xnXxkcdqQP+orgtElcrxTjdRQDUUAAdNrz+4ys7nSGwtwbkxfAPX/Tcca05AFbERkIUZzkPwTEzwC3CHKqpa2588jvqRVO3QR07dlpbGAasQNoOnf+1m9VkYgFwxL96sDZG5Odv4m+WIB8b3PgzYk4D9mA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804539; c=relaxed/simple; bh=7yu2FqZf1ktONrE7YCdwTRFBhKkKB09JfneUt1Kk8Xk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pxriNV8wbJTIxH/s55rJHF1OZ2OvoI7s5JT9qIFntnkcIWSWuD8A+k+UnjROANmybEhl1pxfa69RmGvAs6z99ATsZvArQRfcHfHQJxI5X4gyBHPcHeincmtbmMha7ODFoMQHo3H3x6/4GxBUkKGmNFcz7rEmyoDeoYJFkJMr/G0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=MjjP/4K2; arc=none smtp.client-ip=209.85.218.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="MjjP/4K2" Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-a6265d3ba8fso273079266b.0 for ; Fri, 12 Jul 2024 10:15:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1720804536; x=1721409336; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=p3IHQCv+CrraQVi20skPR3x5tckU0no605O5x1GaU40=; b=MjjP/4K2k9jrzGDiQr+Oe4CeRTM/9oM31LJA+BggEKTNeXTDqU5KWmDy7XgaDAoPXi BPh7coASslHtQFtyDj86hW9/CjEhvSNg/ySLj/8heW63BRkJ2RmgT61jJsJ8cMmBY0L7 54WSacHw0gPMc1FseqQhp7trDePSnpwhe/VpStU2h5DYcow1G8FjS/zxiRjUEN/mHgwG i181DXk88DZXitCIKiWRN6kRBtHGZEvgscpdppMxn+grzd6Ys0H+ujy/RNuW0w8ouOx3 jmn14V5zbaSjvkdZ1zHtgmW7+Rs+A5PWeCPZ8ocM1AnRutK0PyGuLGgGsVEqjRWAzO8m c08A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720804536; x=1721409336; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=p3IHQCv+CrraQVi20skPR3x5tckU0no605O5x1GaU40=; b=ZHZn6KDEs53WAQ8k9RNrHlJAD2NoKfmfXgszPFKqdERpGXBuXeDxsgcurKhnnPiNIt CbqbBYeOU3abV3G+h3tXtu+Cg/klNxLItARpNc9ewhvyr3NuJxWFVIsJH+Iy3H9yYLao rBAN8KVKMcb9UeGdFFvJuX4RnBirca884AkP5E3ljnfX2Aud8tnZ7jdIdsUt8Nx4pRaY KuOeLsad6tSvwGxNhMv/K1y1dESaG+bqafjmXpBzxiRHogCsFo1tWYasKKpFSMfJ4AuE QJZMqhMhrV4qkPVLVOTwAmUjyUGSTAAUN7/xjZcJMd0qdlFU286YNdJzuNSnEubCiTWm paQA== X-Gm-Message-State: AOJu0YzezScJUcvuU2tQRMyix6+HWFyV7GV1lzj454lfHyA7FUHzELbq 4Zfk7jkYiRhiKz7osQSkDGurHWrF4ChLStHdJN3BW8OtyhtDMRjq0NhjFpKP10s= X-Google-Smtp-Source: AGHT+IGLcjpJ/Cgw5UyVuX1FhkB6Z8sxktRxYHvMh+0ZBURcVzZ92lYtBlzXa3UrZaDZiyvPNVcrqA== X-Received: by 2002:a17:907:3f97:b0:a79:8290:ab with SMTP id a640c23a62f3a-a7982900482mr576624166b.15.1720804535751; Fri, 12 Jul 2024 10:15:35 -0700 (PDT) Received: from localhost (p200300de37360a00d7e56139e90929dd.dip0.t-ipconnect.de. [2003:de:3736:a00:d7e5:6139:e909:29dd]) by smtp.gmail.com with UTF8SMTPSA id a640c23a62f3a-a780a6bc693sm362917266b.24.2024.07.12.10.15.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 10:15:35 -0700 (PDT) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, Martin Wilck Subject: [PATCH v2 06/49] kpartx.rules: use @BINDIR@ to locate kpartx Date: Fri, 12 Jul 2024 19:14:14 +0200 Message-ID: <20240712171458.77611-7-mwilck@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712171458.77611-1-mwilck@suse.com> References: <20240712171458.77611-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The path for kpartx should match the installed binary. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- .gitignore | 1 + kpartx/Makefile | 6 +++--- kpartx/{kpartx.rules => kpartx.rules.in} | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) rename kpartx/{kpartx.rules => kpartx.rules.in} (96%) diff --git a/.gitignore b/.gitignore index 049ffe8..355ddbb 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ config.mk cscope.files cscope.out kpartx/kpartx +kpartx/kpartx.rules multipath/multipath multipath/multipath.8 multipath/multipath.conf.5 diff --git a/kpartx/Makefile b/kpartx/Makefile index 7720a74..849fd36 100644 --- a/kpartx/Makefile +++ b/kpartx/Makefile @@ -13,13 +13,13 @@ LIBDEPS += -ldevmapper OBJS := bsd.o dos.o kpartx.o solaris.o unixware.o dasd.o sun.o \ gpt.o mac.o ps3.o crc32.o lopart.o xstrncpy.o devmapper.o -all: $(EXEC) +all: $(EXEC) kpartx.rules $(EXEC): $(OBJS) @echo building $@ because of $? $(Q)$(CC) $(CFLAGS) $(OBJS) -o $(EXEC) $(LDFLAGS) $(LIBDEPS) -install: $(EXEC) $(EXEC).8 +install: $(EXEC) $(EXEC).8 kpartx.rules $(Q)$(INSTALL_PROGRAM) -d $(DESTDIR)$(bindir) $(Q)$(INSTALL_PROGRAM) -m 755 $(EXEC) $(DESTDIR)$(bindir) $(Q)$(INSTALL_PROGRAM) -d $(DESTDIR)$(libudevdir) @@ -41,7 +41,7 @@ uninstall: $(Q)$(RM) $(DESTDIR)$(libudevdir)/rules.d/68-del-part-nodes.rules clean: dep_clean - $(Q)$(RM) core *.o $(EXEC) + $(Q)$(RM) core *.o $(EXEC) kpartx.rules include $(wildcard $(OBJS:.o=.d)) diff --git a/kpartx/kpartx.rules b/kpartx/kpartx.rules.in similarity index 96% rename from kpartx/kpartx.rules rename to kpartx/kpartx.rules.in index 8dd3369..9d87960 100644 --- a/kpartx/kpartx.rules +++ b/kpartx/kpartx.rules.in @@ -39,6 +39,6 @@ LABEL="mpath_kpartx_end" GOTO="kpartx_end" LABEL="run_kpartx" -RUN+="/sbin/kpartx -un -p -part /dev/$name" +RUN+="@BINDIR@/kpartx -un -p -part /dev/$name" LABEL="kpartx_end" From patchwork Fri Jul 12 17:14:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13732055 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C7AF4171085 for ; Fri, 12 Jul 2024 17:15:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804541; cv=none; b=iY05T688UFNphQBY2fRPYCex/JWYJUF+BxWX2sg6H44Hqfh6CsKx32Ncj+iArxUL2mIyVe1LL5D7GZHM/F11MWB9E1GgxIV8/HR/W0GHBOxeo8NtuDstCymw6H3voAz4SfR8inKXyCfcAtH5rx2ZzM/p8nMqOc359oDoRyCo3yc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804541; c=relaxed/simple; bh=rDlaQHCWZ3uVd71QutXHQDhnycZROvvbRCXjPGmZAXg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=c2MP5Mab3pwuo4jHwVE8foKeV2hjgnAbyy0LUmlI3HAaAAGax76EFph6GrSMsI4n24hERCBl6Q78JYn9JPF/7eiX/Mr1tXQslBqhufKfDe91kaJMukB//TrL2K3NIUY87O7BiwO82XNoXFtbssE0Q510/q/zcBC5XNokZqjhki8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=cK0HahNz; arc=none smtp.client-ip=209.85.218.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="cK0HahNz" Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-a77c080b521so282396966b.3 for ; Fri, 12 Jul 2024 10:15:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1720804537; x=1721409337; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5J2XfElcXeeLrNofeMINOOTkKDTQ2yjH7D1MMLUFCq0=; b=cK0HahNzwQIDJz+ugx2Y41MNgGS7NDtOlIqv/KN3xs84CFGWLJ3tXouluKnKHsaCAl dqnZAVRW8Pc7l7xApO5S57QJXdnxLIbRBX1c1fGTuR4oJYJMEmlBJHEd5HWo0O3zRBY+ y1LYWhh3PqegjnrJnq/JNMqOXBdztq3xpm4jSwAynd8zFGDZZg2Tx2MBalRuU9OshQbk u3wKhzB+civfxLqay3srZK8E0jqwgj+db5MQk4W1QsGwhp82NnmzLVc+QXC4bVU7lG56 /CwX0XnSJXyLuIV1eI9dydWcBMZdyeMoS3G/9sEp2bkZzLn8eCcMwURv5n1SisfG+Alq fV+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720804537; x=1721409337; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5J2XfElcXeeLrNofeMINOOTkKDTQ2yjH7D1MMLUFCq0=; b=mvRb5SMq1OqMkyAuIIw0lC1TICakZFG4fr9iCbFB9a9iAS3FsgVo7U/IyiQmjAdQxb w+kyFJvRAD6C6miMW2HQ89z2LefzzeaKdN/OpelDdBAuUo73nKWTz1WevEMjbA1muswZ 6RSlmVUztjIOorQtK1S3I4Kk/5Gr3iT6rnQJwyrwhyOpw+mLtvdJtRfDBjNzIBpbId5u i0p7SuavZWa0IvtCcUbLc0MhvFWVkIPoGZMYvxd/2ZAX+wyyFO4Jy9kgV6f41a3k2/si w/+t6XcEsn2dxYyGH2v21fPiAryCjfeRbIIJwBm8I80Ac9jmwRwsHTX6oahlq8dplCiT y4wQ== X-Gm-Message-State: AOJu0YxDjlwEv22NNlc2RZbSnEhMzWPm55vgBLWO9Bvg105QPLwugTeS YfHd1ZWfEQBonItYv7yBFPZFil0n/4/L4ijVE/Fp/8O82qrVJxb5MMUwqel5n1A= X-Google-Smtp-Source: AGHT+IF1YdZkB3WbL3rviyIfzeHOH9AlApQQj3c4ha6/qKT3aZUShbEr5XWRGjbs0JdqmkniHz3OZQ== X-Received: by 2002:a17:906:5a92:b0:a6f:51d8:1963 with SMTP id a640c23a62f3a-a780b6ff67amr803651066b.43.1720804536975; Fri, 12 Jul 2024 10:15:36 -0700 (PDT) Received: from localhost (p200300de37360a00d7e56139e90929dd.dip0.t-ipconnect.de. [2003:de:3736:a00:d7e5:6139:e909:29dd]) by smtp.gmail.com with UTF8SMTPSA id a640c23a62f3a-a780a6bcc8csm367681966b.17.2024.07.12.10.15.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 10:15:36 -0700 (PDT) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, Martin Wilck Subject: [PATCH v2 07/49] multipath-tools: Remove hard-coded paths to executables Date: Fri, 12 Jul 2024 19:14:15 +0200 Message-ID: <20240712171458.77611-8-mwilck@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712171458.77611-1-mwilck@suse.com> References: <20240712171458.77611-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- Makefile.inc | 17 ++++++++++++++--- kpartx/kpartx_id | 8 ++++---- multipath/11-dm-mpath.rules.in | 4 ++-- multipath/multipath.rules.in | 6 +++--- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/Makefile.inc b/Makefile.inc index 28b6032..fe9f1bf 100644 --- a/Makefile.inc +++ b/Makefile.inc @@ -42,9 +42,11 @@ etc_prefix := $(prefix) # Where to install systemd-related files. systemd is usually installed under /usr # Note: systemd installations with "split-usr=true" use separate "prefixdir" and # "rootprefixdir". Our systemd_prefix corresponds to "prefixdir". -# In this case, override only unitdir and libudevdir below to use -# systemd's "rootprefixdir" instead of $(systemd_prefix) +# In this case, override only unitdir, libudevdir and sys_execprefix below +# to use systemd's "rootprefixdir" instead of $(systemd_prefix) systemd_prefix := /usr +# Prefix for binaries that are owned by other packages (including systemd) +sys_execprefix := /usr # Make sure all prefix variables end in "/" append-slash = $(1)$(if $(filter %/,$(1)),,/) @@ -53,6 +55,7 @@ override exec_prefix := $(call append-slash,$(exec_prefix)) override usr_prefix := $(call append-slash,$(usr_prefix)) override etc_prefix := $(call append-slash,$(etc_prefix)) override systemd_prefix := $(call append-slash,$(systemd_prefix)) +override sys_execprefix := $(call append-slash,$(sys_execprefix)) unitdir := $(systemd_prefix)lib/systemd/system tmpfilesdir := $(systemd_prefix)lib/tmpfiles.d @@ -74,6 +77,7 @@ runtimedir := $(if $(shell test -L /var/run -o ! -d /var/run && echo 1),/ru devmapper_incdir := $(or $(shell $(PKG_CONFIG) --variable=includedir devmapper),/usr/include) libudev_incdir := $(or $(shell $(PKG_CONFIG) --variable=includedir libudev),/usr/include) kernel_incdir := /usr/include +sysdir_bin := $(sys_execprefix)bin ifeq ($(V),) Q := @ @@ -150,4 +154,11 @@ NV_VERSION_SCRIPT = $(DEVLIB:%.so=%-nv.version) %: %.in @echo creating $@ - $(Q)sed 's:@CONFIGFILE@:'$(TGTDIR)$(configfile)':g;s:@CONFIGDIR@:'$(TGTDIR)$(configdir)':g;s:@STATE_DIR@:'$(TGTDIR)$(statedir)':g;s:@RUNTIME_DIR@:'$(runtimedir)':g;s/@MODPROBE_UNIT@/'$(MODPROBE_UNIT)'/g;s:@BINDIR@:'$(TGTDIR)$(bindir)':g' $< >$@ + $(Q)sed -e 's:@CONFIGFILE@:'$(TGTDIR)$(configfile)':g' \ + -e 's:@CONFIGDIR@:'$(TGTDIR)$(configdir)':g' \ + -e 's:@STATE_DIR@:'$(TGTDIR)$(statedir)':g' \ + -e 's:@BINDIR@:'$(TGTDIR)$(bindir)':g' \ + -e 's:@SYSDIR_BIN@:'$(sysdir_bin)': g' \ + -e 's:@RUNTIME_DIR@:'$(runtimedir)':g' \ + -e 's/@MODPROBE_UNIT@/'$(MODPROBE_UNIT)'/g' \ + $< >$@ diff --git a/kpartx/kpartx_id b/kpartx/kpartx_id index 4672927..f9211d2 100755 --- a/kpartx/kpartx_id +++ b/kpartx/kpartx_id @@ -21,8 +21,6 @@ # sent upstream but has not been accepted yet. # -DMSETUP=/sbin/dmsetup - MAJOR=$1 MINOR=$2 UUID=$3 @@ -32,12 +30,14 @@ if [ -z "$MAJOR" -o -z "$MINOR" ]; then exit 1; fi +DMSETUP=$(command -v dmsetup) || DMSETUP=/sbin/dmsetup + # Device-mapper not installed; not an error -if [ ! -x $DMSETUP ] ; then +if [ ! -x "$DMSETUP" ] ; then + echo "$0: dmsetup not found" >&2 exit 0 fi - # Table UUIDs are always '-'. dmuuid=${UUID#*-} dmtbl=${UUID%%-*} diff --git a/multipath/11-dm-mpath.rules.in b/multipath/11-dm-mpath.rules.in index 0562edd..30647b9 100644 --- a/multipath/11-dm-mpath.rules.in +++ b/multipath/11-dm-mpath.rules.in @@ -9,7 +9,7 @@ ENV{.DM_SUSPENDED}!="?*", ENV{.DM_SUSPENDED}="$env{DM_SUSPENDED}" # Coldplug event while device is suspended (e.g. during a reload) ACTION=="add", ENV{DM_ACTIVATION}=="1", ENV{.DM_SUSPENDED}=="1", \ - PROGRAM="/bin/logger -t 11-dm-mpath.rules -p daemon.warning \"Coldplug event for suspended device\"", \ + PROGRAM="@SYSDIR_BIN@/logger -t 11-dm-mpath.rules -p daemon.warning \"Coldplug event for suspended device\"", \ ENV{DM_COLDPLUG_SUSPENDED}="1", GOTO="scan_import" # Coldplug event. Import previously set properties. @@ -70,7 +70,7 @@ LABEL="check_mpath_unchanged" IMPORT{db}="DM_COLDPLUG_SUSPENDED" ENV{DM_COLDPLUG_SUSPENDED}=="1", ENV{.DM_SUSPENDED}!="1", \ ENV{DM_ACTIVATION}="1", ENV{MPATH_UNCHANGED}="0", \ - PROGRAM="/bin/logger -t 11-dm-mpath.rules -p daemon.notice \"Forcing activation of previously suspended device\"", \ + PROGRAM="@SYSDIR_BIN@/logger -t 11-dm-mpath.rules -p daemon.notice \"Forcing activation of previously suspended device\"", \ GOTO="check_mpath_ready" # DM_SUBSYSTEM_UDEV_FLAG0 is the "RELOAD" flag for multipath subsystem. diff --git a/multipath/multipath.rules.in b/multipath/multipath.rules.in index 780bf85..2ac1972 100644 --- a/multipath/multipath.rules.in +++ b/multipath/multipath.rules.in @@ -2,7 +2,7 @@ SUBSYSTEM!="block", GOTO="end_mpath" KERNEL!="sd*|dasd*|nvme*", GOTO="end_mpath" ACTION=="remove", TEST=="@RUNTIME_DIR@/multipath/find_multipaths/$major:$minor", \ - RUN+="/usr/bin/rm -f @RUNTIME_DIR@/multipath/find_multipaths/$major:$minor" + RUN+="@SYSDIR_BIN@/rm -f @RUNTIME_DIR@/multipath/find_multipaths/$major:$minor" ACTION!="add|change", GOTO="end_mpath" IMPORT{cmdline}="nompath" @@ -69,7 +69,7 @@ ENV{.SAVED_FM_WAIT_UNTIL}=="?*", GOTO="pretend_mpath" # # We must trigger an "add" event because LVM2 will only act on those. -RUN+="/usr/bin/systemd-run --unit=cancel-multipath-wait-$kernel --description 'cancel waiting for multipath siblings of $kernel' --no-block --timer-property DefaultDependencies=no --timer-property Conflicts=shutdown.target --timer-property Before=shutdown.target --timer-property Conflicts=initrd-cleanup.service --timer-property Before=initrd-cleanup.service --timer-property AccuracySec=500ms --property DefaultDependencies=no --property Conflicts=shutdown.target --property Before=shutdown.target --property Conflicts=initrd-cleanup.service --property Before=initrd-cleanup.service --on-active=$env{FIND_MULTIPATHS_WAIT_UNTIL} /usr/bin/udevadm trigger --action=add $sys$devpath" +RUN+="@SYSDIR_BIN@/systemd-run --unit=cancel-multipath-wait-$kernel --description 'cancel waiting for multipath siblings of $kernel' --no-block --timer-property DefaultDependencies=no --timer-property Conflicts=shutdown.target --timer-property Before=shutdown.target --timer-property Conflicts=initrd-cleanup.service --timer-property Before=initrd-cleanup.service --timer-property AccuracySec=500ms --property DefaultDependencies=no --property Conflicts=shutdown.target --property Before=shutdown.target --property Conflicts=initrd-cleanup.service --property Before=initrd-cleanup.service --on-active=$env{FIND_MULTIPATHS_WAIT_UNTIL} @SYSDIR_BIN@/udevadm trigger --action=add $sys$devpath" LABEL="pretend_mpath" ENV{DM_MULTIPATH_DEVICE_PATH}="1" @@ -85,7 +85,7 @@ ENV{FIND_MULTIPATHS_WAIT_UNTIL}!="?*", GOTO="end_mpath" ENV{FIND_MULTIPATHS_WAIT_UNTIL}=="0", GOTO="end_mpath" ENV{FIND_MULTIPATHS_WAIT_CANCELLED}="1" -RUN+="/usr/bin/systemctl stop cancel-multipath-wait-$kernel.timer" +RUN+="@SYSDIR_BIN@/systemctl stop cancel-multipath-wait-$kernel.timer" # If "multipath -u" failed, no values are imported from the program, # and we are still using the values for DM_MULTIPATH_DEVICE_PATH and From patchwork Fri Jul 12 17:14:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13732056 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C366E1DFEF for ; Fri, 12 Jul 2024 17:15:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804542; cv=none; b=BH9EtfhlktP6rce4VIsU7t5xiH88zhBE/qVwhjaxsBfnHCftlSDwlTMadUcgFAAY0Bzswew4k2dEpkLgUyijBMYsIGpiuHbHkVnNvbzDwlVkrsDSGOp2LZBn3Kx2ThSKXhDWACOZaF3gbXVEFU6h/rtCD/jJ2pFpFZDaK9n/qgs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804542; c=relaxed/simple; bh=S6huMpydLTZ7DE9RnoBeBxzgQasmLdJ59j0iScYasbs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GOxzFlKXQMUEC2iAcEx0chq/zg2MS/PzEAjEJCZaZKF3qPZUo/t/p08vJohLWOB1HiLy67lauO8NYE46XIzA3KPM/PvDicq81F8jB//EpIf+ubzXHXZWZjJmUy3kbGJ4jlzKjSqfMr1NwGXp2vYEsJCGnc2y8HjsCHIRlOsJy0w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=Sihe0eZh; arc=none smtp.client-ip=209.85.218.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="Sihe0eZh" Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-a77c25beae1so259244866b.2 for ; Fri, 12 Jul 2024 10:15:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1720804538; x=1721409338; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QyOyMsTWf666ToHkixtSQKwrdiNcha08nD2pvn99+zI=; b=Sihe0eZh7WioNTek4p1M6Rc+IoRL3qUHva2acI8GcjJiTsFy86xesJYNng58W5CFTy CfgeM8RQ5AKibmzpVO5wdeOW7vViCWQQV6dM+awh6KkhyOElvmNUhvebh5B5ZOkipj7N kxfbscrZXZWFHtIIDmrzbvj7RiMziNshdgrPd/XQ4rolrWMZARs7NGZDxCZsPWazvqRS T6vFD0OMFrn9iCEOqf2gbqD2Bg91UhvAGkWhSrEwWoMJ8Q4QLRXvUWHRWTaw10BasH3P Oqt3bb+8TKV0zeQ20PquUPH2KBkH2lSXCAkNapH/41z7tHgIJ/QUAMys2QOS2qyZS/GT GbmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720804538; x=1721409338; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QyOyMsTWf666ToHkixtSQKwrdiNcha08nD2pvn99+zI=; b=i2PVttMgMGqkXmanQFqfa0sUbL0d8IX7KyklxcEe4/+1sEoLsvK9D5x+jcE/6Szfc9 Mm451yhPdjuObGQWQ7jPJfmYoVImuteAGoVZHmOP20qPfZ9HiaENIKE52ZFeU+H8N2/a VBz9oSoTmEir50rYickOJifdJq39myNDoifscMA8kaox4XZToF7nGOfon1TQlDZx4roZ BJ0VBGv02CHO4LkO3NoRwbwAx2WWCZenqLhgVVnItxSwsjgRpagqqp12uO0v3iranRXF rnLVL60GPXjzpfdlAk0MrG09O2G4LuO3pPR2EPCEYVbQasPpoxBo8djeIfpZMMvuKvZe Y2zA== X-Gm-Message-State: AOJu0Yyf6KN0jAz2/5JdXZ6f/J/YjkyIm0Ye4dR+bcIkAK+b5s+uZ0Fq VTcztd/XCQDbgfRgOdpf8RAzXtHUkyqe2Xe7hhXNRfvYMbnneaELYgoxcAPHZmw= X-Google-Smtp-Source: AGHT+IEbZ1Pk8oLIhufVOD9b5K/LpHYSQ+i2EyMtJ9pHjyClpl1H0aLJDMuJA2tAASUVId7wTPpW4A== X-Received: by 2002:a17:907:3f1a:b0:a79:82c1:a5b2 with SMTP id a640c23a62f3a-a7982c1a956mr721349866b.9.1720804537898; Fri, 12 Jul 2024 10:15:37 -0700 (PDT) Received: from localhost (p200300de37360a00d7e56139e90929dd.dip0.t-ipconnect.de. [2003:de:3736:a00:d7e5:6139:e909:29dd]) by smtp.gmail.com with UTF8SMTPSA id a640c23a62f3a-a780a72fd39sm364322966b.91.2024.07.12.10.15.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 10:15:37 -0700 (PDT) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, Martin Wilck Subject: [PATCH v2 08/49] multipath-tools: compile_commands.json fixes Date: Fri, 12 Jul 2024 19:14:16 +0200 Message-ID: <20240712171458.77611-9-mwilck@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712171458.77611-1-mwilck@suse.com> References: <20240712171458.77611-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 compile_commands.json serves as input for clangd, while working with lsp under emacs. It's normal for functions and parameters to be unused while writing code. Therefore suppress -Werror for this use case. clangd will display the warnings. Use "make testprogs" to generate compile_commands.json, in order to be able to use clangd for the CI code, too. Finally, don't remove compile_commands.json with "make clean". Normally the compile commands remain the same, even if a clean rebuild of the binaries is necessary. Put the file into .gitignore instead. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- .gitignore | 1 + Makefile | 4 ++-- Makefile.inc | 12 +++++++++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 355ddbb..efdbd8a 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ *.gz *.d \#* +compile_commands.json config.mk cscope.files cscope.out diff --git a/Makefile b/Makefile index 4df5f16..14bbac2 100644 --- a/Makefile +++ b/Makefile @@ -83,7 +83,7 @@ abi-test: abi reference-abi $(wildcard abi/*.abi) # Requires bear (https://github.com/rizsotto/Bear) compile_commands.json: Makefile Makefile.inc $(BUILDDIRS:=/Makefile) $(Q)$(MAKE) clean - $(Q)bear -- $(MAKE) + $(Q)bear -- $(MAKE) WARN_ONLY=1 test-progs || rm $@ libmpathutil libdmmp: libmpathcmd libmultipath: libmpathutil @@ -109,7 +109,7 @@ $(BUILDDIRS:=.uninstall): clean: @touch config.mk $(Q)$(MAKE) $(BUILDDIRS:=.clean) tests.clean || true - $(Q)$(RM) -r abi abi.tar.gz abi-test compile_commands.json config.mk + $(Q)$(RM) -r abi abi.tar.gz abi-test config.mk install: $(BUILDDIRS:=.install) uninstall: $(BUILDDIRS:=.uninstall) diff --git a/Makefile.inc b/Makefile.inc index fe9f1bf..729618b 100644 --- a/Makefile.inc +++ b/Makefile.inc @@ -100,9 +100,15 @@ MODPROBE_UNIT := $(shell test "0$(SYSTEMD)" -lt 245 2>/dev/null || \ echo "modprobe@dm_multipath.service") OPTFLAGS := -O2 -g $(STACKPROT) --param=ssp-buffer-size=4 -WARNFLAGS := -Werror -Wall -Wextra -Wformat=2 $(WFORMATOVERFLOW) -Werror=implicit-int \ - -Werror=implicit-function-declaration -Werror=format-security \ - $(WNOCLOBBERED) -Werror=cast-qual $(ERROR_DISCARDED_QUALIFIERS) $(W_URCU_TYPE_LIMITS) + +# Set WARN_ONLY=1 to avoid compilation erroring out due to warnings. Useful during development. +WARN_ONLY := +ERROR := $(if $(WARN_ONLY),,error=) +WERROR := $(if $(WARN_ONLY),,-Werror) +WARNFLAGS := $(WERROR) -Wall -Wextra -Wformat=2 $(WFORMATOVERFLOW) -W$(ERROR)implicit-int \ + -W$(ERROR)implicit-function-declaration -W$(ERROR)format-security \ + $(WNOCLOBBERED) -W$(ERROR)cast-qual $(ERROR_DISCARDED_QUALIFIERS) $(W_URCU_TYPE_LIMITS) + CPPFLAGS := $(FORTIFY_OPT) $(CPPFLAGS) $(D_URCU_VERSION) \ -D_FILE_OFFSET_BITS=64 \ -DBIN_DIR=\"$(bindir)\" -DMULTIPATH_DIR=\"$(TGTDIR)$(plugindir)\" \ From patchwork Fri Jul 12 17:14:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13732057 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AEC34176AB1 for ; Fri, 12 Jul 2024 17:15:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804542; cv=none; b=Ag1QwRjmvAnYTCBt6SSdWBOuhiQ4MdrImuIXJLIg7wtekU5zrS4wwEu0AR+QI300HUYxCLVfiqfvM7LHbhxQ3PvUUPUd3ipZDj1gWL8IyuqCcZtvR0ds3mprolwj8B8tE0DPA6gDiRbCHV6DFKkTyTA9I6XZCk8YJNQLqfiErhg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804542; c=relaxed/simple; bh=ei/dWGDoznhqhBkkNr2rYevtzlQG+nw5zFGGdtM+4g0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LLDCp+JLZ2dl9GW+ZDXORAD3K0OB4bVQQmPFaz6QZW1Ep8W7VEykiFGvfkge7YHYa1c+eJofrKiKRX7OT+KBHgRVGzV39RRNTBUesLOceOIO2XFt3h6QuOLCfc0aXLHH9+kG+rLNevXAjYxcCrOWA3SjIDb8N0EVFwfj7qAiO1k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=T8g04mUn; arc=none smtp.client-ip=209.85.208.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="T8g04mUn" Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-58e76294858so5869696a12.0 for ; Fri, 12 Jul 2024 10:15:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1720804539; x=1721409339; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kG/sRR8mXDhOojSugaJG/UCzOcISIeIlDj/9lc7N/Co=; b=T8g04mUnyhEsPeUfXPJrwMeWS3w2mPyf2N9Nd4ODgeXpNhKb5OzdbsYx1oYGaQDur+ pLiXE3ZgwvjWBaK5K8V1v7MXzTA0FZvGpVdkxuX4c627fj43Dt3hBFqXv1fKNJRKnWXX 6cSBOAp21qGi/uWowXjrWR6pqMg5qzdQ999kel+leQ5H+vOo9gUk6Nco9T6KDbG+5bNC tyjNI5j0uExJQKXVs7njf+GFdnkgWsh3rE2ThEDVmkI0mFzexPDw+m1W+9k0HWupxCm1 pxbmyQhOoMkix3/EVcIlI7EPm6WaenvxW1pFqFFZzgjmbjSWXV2lEUDoz4uHfgtWubLu NMUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720804539; x=1721409339; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kG/sRR8mXDhOojSugaJG/UCzOcISIeIlDj/9lc7N/Co=; b=f58/cwUWCV5RGGLt6lgkZolAdqmIyPD26Zcz6m5FwAaG0pNmiG7u5ujhSMPT2qP820 Kr+9jPHLpIAKYCBWmM1vAdQRglwW6tIrC5O9xosm7GFF2S1YIfGYun2ODoua367Jk28n j7QRIOaRKTldZUsDd/8982mWvhTtBWg9EytkwM4ML29nVvYbjim238pz6wqAxlhVMCpa x9el36/a9YY80cl4wgWKVtGetMlyRmaOdl+nToLra2a+w3qDWn5U0lDsRLn/xuCPzJb/ JrEKndrgo/YTyZOe171tHJUooLBJglkwQssP6gGH07RBud4tVVJ/CUpitW3SD5mfiHiS BJNA== X-Gm-Message-State: AOJu0Yw+RhDelBX5C91s6tO5wcKbGpvWzjTNpgWI864UxqRqRnuuT75S XOTS1Firw02EENuQcQwVKz0bxtP+byL00Xm/kJWUryOPTFmSSy7oYu9XEtz/T0k= X-Google-Smtp-Source: AGHT+IFhZRHx3xsIo+wCitVMA9SqfjIIbH71r4TobmnYKMYjyX/S9eA3HJTEQAxSW9OB/keEiGuObw== X-Received: by 2002:a50:d59e:0:b0:57d:d59:461b with SMTP id 4fb4d7f45d1cf-59960007edemr2412537a12.13.1720804538943; Fri, 12 Jul 2024 10:15:38 -0700 (PDT) Received: from localhost (p200300de37360a00d7e56139e90929dd.dip0.t-ipconnect.de. [2003:de:3736:a00:d7e5:6139:e909:29dd]) by smtp.gmail.com with UTF8SMTPSA id 4fb4d7f45d1cf-59a68949578sm334412a12.3.2024.07.12.10.15.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 10:15:38 -0700 (PDT) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, Martin Wilck Subject: [PATCH v2 09/49] multipath-tools: .gitignore: ignore o.wrap files for CI helpers Date: Fri, 12 Jul 2024 19:14:17 +0200 Message-ID: <20240712171458.77611-10-mwilck@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712171458.77611-1-mwilck@suse.com> References: <20240712171458.77611-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Unlike the .o.wrap files for the CI tests themselves, these are not automatically deleted by "make" as intermediate files. Ignore them. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index efdbd8a..4548cfb 100644 --- a/.gitignore +++ b/.gitignore @@ -42,6 +42,8 @@ libdmmp/test/libdmmp_speed_test tests/*-test tests/*.out tests/*.vgr +tests/test-lib.o.wrap +tests/test-log.o.wrap libmultipath/nvme-ioctl.c libmultipath/nvme-ioctl.h libmultipath/autoconfig.h From patchwork Fri Jul 12 17:14:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13732058 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 99F73176FA3 for ; Fri, 12 Jul 2024 17:15:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804543; cv=none; b=M78dBuTVw9lVNJqTF0tdmHx1sRaEi3LuIXqszWNvRmD4+NwDYL6Cobk1Jr2lJNYzjMGyiPEAiZXWFEVptSZRPvXcFYCcvYaqm39wkAIuCIx7ZPAcpOX0aYwa7edTpGfsczHOL7aqphUbQZInET1uUiiYkakq4iIVs7yWXIHAUvU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804543; c=relaxed/simple; bh=DkpK5sEthTCt+y/GnS6D/M8eXItVAmzk+mJz+pD03Gg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sceLrb/slMpTGnlIrg/oyXwcvuFZ66R+8B9SIqIUp/rx5OcMxPSYjT6gD2YsB9AmQOdK5untu+aC98iOFNB9E6aXMnL7Al3+Gj8YLTSfmgoSX8U2vJMBSu1IRGJRJvQQ8u5IsiD69JaZy0dv+dljagsDN7m/I+65IXVIrFWVzjI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=DBoGr1Aj; arc=none smtp.client-ip=209.85.218.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="DBoGr1Aj" Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-a77c1658c68so279267066b.0 for ; Fri, 12 Jul 2024 10:15:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1720804540; x=1721409340; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2vPyUeFhrVt6vMKZJgkpTDZ38Ys1EHTjBOKpBEKY4tU=; b=DBoGr1AjLIckZnuC6e4mmyqiz9FS/QJmVwnQeLh9cxVBY03O8wZPQIGvRiv1JpGPiK s1OumeWc3L8MtDU2q2ZIqgoFEX9evKFUHN+c6vK2FtQuFflib3JDZvPjRKz+HJ2/n4gw 6iJw1/fUhm3junXSm2qhllndtmVyzm3hW3EKe2wq/poFGkgdUApu0h8Bt0oAJWC8FeCV CMLeKxt+fAvIJNcAa/ZjuZlydoKQazb3CqOzVadwxuu7RuKjF2ulVVTQDN5+iIHoIUcp 0Ow8zScdhhm65z616wKJbnG47K6lvxwdoknbLr2Z566P/9WYa70/D+EBa9ma8jk6Y1Fd 7VGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720804540; x=1721409340; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2vPyUeFhrVt6vMKZJgkpTDZ38Ys1EHTjBOKpBEKY4tU=; b=HjiSnol1dm9mYRu7COOaBYvVBWIfJPNQAvhyNgxc+bmyjRuar2iWyKyoncsI9TA4v1 gqvZGS8yJYIn7ppiFF6tkxwhIgByflxCswhMY6dbALndwA+8V8xyAjW1ZUscpfCRVluO Jr8mWLCvJw2FVUFEfT3YrOhSggeuOjnvDJaZxUlNqlwH1ZzOSuwku6XWH7s6N1V+qYOj 5l2u6X1ltT1k04slww1Xb/8bNpV/hv8stS8ifbTyYuVYwOqJRevo+jGVbGRm4oymcYhF X67TJ5X3zmnIUnuEL5eqomquNMCqPz+AHNGdpcJFk0pZ2nbwDpdeDXnFJhBDnrktkufr yi5A== X-Gm-Message-State: AOJu0YxloYB8/Svu3Dq2oRaJMHmbiINqcZclX/pWQGDYv3mMtQVhYytO GoObFkKFKns06vi7UoX+jkE3Ce4RFfDtxP9HoTi+mbY1/mDAEK3E9z5ax+HjLum7PIxRZluX/9c n X-Google-Smtp-Source: AGHT+IEyWWhmVtSZkpRtcusyklFTrnMNkltXi5Ogv71F2wylZNYBGBVfMu6mvoEjdl3u3XfLdrdhVw== X-Received: by 2002:a17:906:5650:b0:a72:8d2f:8594 with SMTP id a640c23a62f3a-a780b6b2f20mr773913066b.27.1720804540056; Fri, 12 Jul 2024 10:15:40 -0700 (PDT) Received: from localhost (p200300de37360a00d7e56139e90929dd.dip0.t-ipconnect.de. [2003:de:3736:a00:d7e5:6139:e909:29dd]) by smtp.gmail.com with UTF8SMTPSA id a640c23a62f3a-a780a855e24sm369204166b.177.2024.07.12.10.15.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 10:15:39 -0700 (PDT) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, Martin Wilck Subject: [PATCH v2 10/49] libmultipath: remove unused includes in devmapper.h Date: Fri, 12 Jul 2024 19:14:18 +0200 Message-ID: <20240712171458.77611-11-mwilck@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712171458.77611-1-mwilck@suse.com> References: <20240712171458.77611-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/devmapper.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 08bb3c5..3ee8555 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -17,13 +17,11 @@ #include #include "util.h" -#include "checkers.h" #include "vector.h" #include "structs.h" #include "debug.h" #include "devmapper.h" #include "sysfs.h" -#include "config.h" #include "wwids.h" #include "version.h" #include "time-util.h" From patchwork Fri Jul 12 17:14:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13732059 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1823817C6B for ; Fri, 12 Jul 2024 17:15:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804545; cv=none; b=q/yMn1IlEFNV1N3lggnlYiOD/CGEdZwaXhfNKBXOu21tU6RJVaz38ZNF56Q0P/o1AN/zaz3BDv8osWwfNaTR3rwzxSLz+q/N2ylD7k3rz4gMJd+mFn5w99W0Ny6V50PRtC/Wn8CCklM9YT5+upoHri+vZnG3vtD8qvjtDS4AdkQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804545; c=relaxed/simple; bh=EHVIdQjEPCn9dbQB+9y+hO7sTWOOE6Fx1oJK0zfY8VU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fA1fbaVhMpfmG7Ntl1YPnJ7YWFltEd0P2AvDWjxSXkGOQ5fEwEL5Nk3dPR/WLUrS8SRzlXwUYdqNqFmErd7+YOB/tI0L7sYCfBIlVvu+xTbgUf8eRkUu9sJAdj/Qytq0SnsWeBFBwXi6yGm/pG78cgX8jeIKd7TX7KHHIvKHm0Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=EUXOrVgQ; arc=none smtp.client-ip=209.85.208.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="EUXOrVgQ" Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-58b447c5112so3121192a12.3 for ; Fri, 12 Jul 2024 10:15:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1720804541; x=1721409341; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yhQBOEExdxLioLnfTE8uk5qUeyX81jGOGkpCXie+Nxg=; b=EUXOrVgQxv0tzZnlRYcwm2kgGrGQviz2ggSqtIyvvb/yzLXvNtt+vF7l76Hg5gVBvN ylzhjwhcB1GLV43mfNIx0Ro1KUb46lGEXfxLrioimHay+st5qMu+xi0nvQUMZeXnOVQK Mq7I+I2eOCYHhiOfZWpTpLRkUWqdulnJw6bvfdQ04Swqv7jTJj96JliSx8MPSwWvU5fj r7KlcfX/YBBD/ivQ696JiX6UqhEITd7khR0CikNOLNrIetCvIpiTSkJm8n6Zi+5e8GRO ahLn+6rr9Ge9kKGj9xvKL060pGqhLMJpQXUO4kgTv4d0sE9KBL48/BoknCNd8PTkJP0g VVXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720804541; x=1721409341; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yhQBOEExdxLioLnfTE8uk5qUeyX81jGOGkpCXie+Nxg=; b=neC9lMFsKOSx3gQcwP8JChYysIUQ3BHdBa1qX4c2wNWzodz+npHHLjhvsLXp+A8CnE HCLgECJgLfu/LfUAN+EYPSoAGUD7w7VXYj8ApOi5lddwurHTR+U9UxdLfTb1afLQTGn4 jEuCUpJeFuFajo3p7jN7im00c1c7ymzRlDjEmOI/F0rFWIhO6yHC3mC/cP3nZK8nbsrB HSB2KyNik0gHY1OYTfWCxM2+BsNLQCqXRF+b4HTu6/aahIDcMzWESairwLBuXAQT3x1J nZQMxeKv3U2hfb0cCV0Y7cuZHc8psblaS33Fg4VBdNJ9ij1vixnQJvK0ZulI9auUEc13 d8CQ== X-Gm-Message-State: AOJu0Yz0hQFW3PUi/o0COcv0O24HwlvUTFt4HsAihW1QjFaL0ILIgQ8c 09s9Ap1gVtxj6EIrY1ugjQ52vDQwmdq/ABtiSWl+Vp7pnP2rueDAPrckNUIx5Ls= X-Google-Smtp-Source: AGHT+IHx6dvKIoVrBwED4uZlWxnzG17oHzEKCDtomQxwUjozxiEekiG8ypHOae7sojJ6ecojqJzkwg== X-Received: by 2002:a17:907:1759:b0:a6f:4bf2:daa2 with SMTP id a640c23a62f3a-a780b68a8a3mr797431866b.15.1720804541176; Fri, 12 Jul 2024 10:15:41 -0700 (PDT) Received: from localhost (p200300de37360a00d7e56139e90929dd.dip0.t-ipconnect.de. [2003:de:3736:a00:d7e5:6139:e909:29dd]) by smtp.gmail.com with UTF8SMTPSA id a640c23a62f3a-a780a86ed05sm362568266b.188.2024.07.12.10.15.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 10:15:41 -0700 (PDT) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, Martin Wilck Subject: [PATCH v2 11/49] libmultipath: use DM_DEVICE_INFO in dm_mapname() Date: Fri, 12 Jul 2024 19:14:19 +0200 Message-ID: <20240712171458.77611-12-mwilck@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712171458.77611-1-mwilck@suse.com> References: <20240712171458.77611-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 DM_DEVICE_INFO aka the kernel's DM_DEV_STATUS ioctl, is sufficient to fetch the map name, and more lightweight than DM_DEVICE_STATUS, which maps to the kernel's DM_TABLE_STATUS ioctl. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/devmapper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 3ee8555..baa1ead 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -1412,7 +1412,7 @@ dm_mapname(int major, int minor) struct dm_task *dmt; int r; - if (!(dmt = libmp_dm_task_create(DM_DEVICE_STATUS))) + if (!(dmt = libmp_dm_task_create(DM_DEVICE_INFO))) return NULL; if (!dm_task_set_major(dmt, major) || @@ -1422,7 +1422,7 @@ dm_mapname(int major, int minor) dm_task_no_open_count(dmt); r = libmp_dm_task_run(dmt); if (!r) { - dm_log_error(2, DM_DEVICE_STATUS, dmt); + dm_log_error(2, DM_DEVICE_INFO, dmt); goto bad; } From patchwork Fri Jul 12 17:14:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13732061 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F39A1175564 for ; Fri, 12 Jul 2024 17:15:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804547; cv=none; b=XgBUQzLPDqqUBsuzo2jt7yUmNgoXZpe+CTI3n5iwniVmnJnKM+SRbmxwq8nJzwhoTvmi6KTID72A8G7f6SldJRckDvsZLHe6AKO1KVwhBnmhdhjYguJJcTFISNw6vxgi2hoaM7MmQ6MhJ5yOxxa+Hh6rL/i45NBrIEkW+KvtjNM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804547; c=relaxed/simple; bh=kqoHTm86gv/Ca7roOU+R0hbIeb0+3e5T6+ngMIqwAFQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=u++TWK/OCGtZCIeZ7uRA3/LVGFcgBFZK5ILxaJvBoDk6WaWsxbB9LBxWbpPc2VVcJDIBU/tkDnoBKSPHrcqyvQGomJIRkvG2R1poDKQX8kvMD2lp19yoHyEiJhYJtJIpqEsICcNciSnkGLkRb1bxhYivEFObfs80RgsvWbzjVSo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=eIIDAxN/; arc=none smtp.client-ip=209.85.218.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="eIIDAxN/" Received: by mail-ej1-f46.google.com with SMTP id a640c23a62f3a-a77e392f59fso300502166b.1 for ; Fri, 12 Jul 2024 10:15:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1720804542; x=1721409342; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=AtjsweYUUStq+L7WMe0F66Ap1LoZbG1z5BU3NOgCkgM=; b=eIIDAxN/J1Qgi3aqhbzCqTRQc4vFtqw/wIMAi2/PCgDKKYNxI0NUZ/tsntdXJ9c/y/ NlJUEelvSmzAVaRCZXvW5W75d6cH9ccZvJf7QzOCmsH6qU9l87IWRqBdBHRAWQwGzGjk OTA0P/VsxnObz/AJXIFuYl9GA4OVSicToOcP14h3sIsU+QU7ondLqBJ+dd1GL48ZbEi+ c0bKW/rSSy3jWVvGP4iLOSvx+Cb2UC0tYQbnUGG6UjazUvMBty17JeRHyBwNwD7QzAzA F0qr3DxVcBwZTk2NDtBz9gBvYTsdPbhRuWLVeAUXHi0qkfPDs3ZF4bc19KOpCrkBuNDk 3cjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720804542; x=1721409342; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AtjsweYUUStq+L7WMe0F66Ap1LoZbG1z5BU3NOgCkgM=; b=KyMhmIIXfkx9JygKidKiCoPr25rl6JSF1YDHHiNHy9zWVVm4H+nsiDTpmLzCJME5jJ QtVqO4MRVkFE63Wpq6rnc/+S5qxtVkGNPirdVBC1f+unj00avvQTJyU8CU1BFuFboiWD cKdzb74iovmwMkQ9IcCKBnlCwgXo3ktRz9hgTbFUxe7xVJWLqRqQ2URR1vuZR9XN9h7o 5kWkxjICHRqhYFLM78N9zUTDrEi+uTM2ltHOL5P6cv5uwEuC6n8iOWfM5OpBzqauCoEh LPYisoJyolOzwF249bwlJ+J8MlaJ6aurUaigrL1DezKrcaEjM2TE0sH++uK2f3g28rhX b3rw== X-Gm-Message-State: AOJu0YysuzKqqdwuPseJelANYxjhRlkIwuHXo/5A8JbI1EOV7+Loo9Bz QxNbHE/VrW0kM6xiqT2BS9++lgHMU5GJBSqacfTZ45GsHmTh9IXJ5AXFf+ukVEoPclolv2cmiY8 6 X-Google-Smtp-Source: AGHT+IHlSPClHOJxxLZGvv3pg8Qj0r+u/7jQZToigUkugCpFZdoj0vDGjCR3XQNZ0mHwXJCi5TH9AA== X-Received: by 2002:a17:906:dfc3:b0:a75:360a:6cb0 with SMTP id a640c23a62f3a-a780b6b3644mr757314066b.29.1720804542231; Fri, 12 Jul 2024 10:15:42 -0700 (PDT) Received: from localhost (p200300de37360a00d7e56139e90929dd.dip0.t-ipconnect.de. [2003:de:3736:a00:d7e5:6139:e909:29dd]) by smtp.gmail.com with UTF8SMTPSA id a640c23a62f3a-a780a86ed05sm362569566b.188.2024.07.12.10.15.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 10:15:42 -0700 (PDT) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, Martin Wilck Subject: [PATCH v2 12/49] multipath-tools: don't call dm_task_no_open_count() Date: Fri, 12 Jul 2024 19:14:20 +0200 Message-ID: <20240712171458.77611-13-mwilck@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712171458.77611-1-mwilck@suse.com> References: <20240712171458.77611-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 dm_task_no_open_count() only sets DM_SKIP_BDGET_FLAG in the dm task, which has been ignored by the kernel since 5c6bd75d06db ("[PATCH] dm: prevent removal if open") (v2.6.18 / 2006). Even for older kernels, not setting this flag has only a minor, performance-related effect (skipping one call to bdget_disk()). Don't use this dead API any more. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- kpartx/devmapper.c | 15 --------------- libmultipath/devmapper.c | 36 ------------------------------------ multipathd/dmevents.c | 2 -- multipathd/waiter.c | 2 -- tests/dmevents.c | 13 ------------- 5 files changed, 68 deletions(-) diff --git a/kpartx/devmapper.c b/kpartx/devmapper.c index f12762c..bf07838 100644 --- a/kpartx/devmapper.c +++ b/kpartx/devmapper.c @@ -35,8 +35,6 @@ int dm_prereq(char * str, uint32_t x, uint32_t y, uint32_t z) if (!(dmt = dm_task_create(DM_DEVICE_LIST_VERSIONS))) return 1; - dm_task_no_open_count(dmt); - if (!dm_task_run(dmt)) goto out; @@ -78,7 +76,6 @@ int dm_simplecmd(int task, const char *name, int no_flush, __DM_API_COOKIE_UNUSE if (!dm_task_set_name(dmt, name)) goto out; - dm_task_no_open_count(dmt); dm_task_skip_lockfs(dmt); if (no_flush) @@ -175,8 +172,6 @@ int dm_addmap(int task, const char *name, const char *target, if (!dm_task_set_gid(dmt, gid)) goto addout; - dm_task_no_open_count(dmt); - #ifdef LIBDM_API_COOKIE if (!udev_sync) udev_flags = DM_UDEV_DISABLE_LIBRARY_FALLBACK; @@ -212,8 +207,6 @@ static int dm_map_present(char *str, char **uuid) if (!dm_task_set_name(dmt, str)) goto out; - dm_task_no_open_count(dmt); - if (!dm_task_run(dmt)) goto out; @@ -247,7 +240,6 @@ static int dm_rename (const char *old, const char *new) if (!dm_task_set_name(dmt, old) || !dm_task_set_newname(dmt, new) || - !dm_task_no_open_count(dmt) || !dm_task_set_cookie(dmt, &cookie, udev_flags)) goto out; @@ -291,7 +283,6 @@ dm_mapname(int major, int minor) if (!(dmt = dm_task_create(DM_DEVICE_INFO))) return NULL; - dm_task_no_open_count(dmt); dm_task_set_major(dmt, major); dm_task_set_minor(dmt, minor); @@ -352,7 +343,6 @@ dm_mapuuid(const char *mapname) if (!dm_task_set_name(dmt, mapname)) goto out; - dm_task_no_open_count(dmt); if (!dm_task_run(dmt)) goto out; @@ -407,7 +397,6 @@ dm_get_map(const char *mapname, char * outparams) if (!dm_task_set_name(dmt, mapname)) goto out; - dm_task_no_open_count(dmt); if (!dm_task_run(dmt)) goto out; @@ -474,8 +463,6 @@ dm_type(const char * name, char * type) if (!dm_task_set_name(dmt, name)) goto out; - dm_task_no_open_count(dmt); - if (!dm_task_run(dmt)) goto out; @@ -545,8 +532,6 @@ do_foreach_partmaps (const char * mapname, const char *uuid, if (!(dmt = dm_task_create(DM_DEVICE_LIST))) return 1; - dm_task_no_open_count(dmt); - if (!dm_task_run(dmt)) goto out; diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index baa1ead..8996c1d 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -217,8 +217,6 @@ static int dm_tgt_version (unsigned int *version, char *str) if (!(dmt = dm_task_create(DM_DEVICE_LIST_VERSIONS))) return 1; - dm_task_no_open_count(dmt); - if (!libmp_dm_task_run(dmt)) { dm_log_error(2, DM_DEVICE_LIST_VERSIONS, dmt); condlog(0, "Cannot communicate with kernel DM"); @@ -398,7 +396,6 @@ dm_simplecmd (int task, const char *name, int flags, uint16_t udev_flags) { if (!dm_task_set_name (dmt, name)) goto out; - dm_task_no_open_count(dmt); dm_task_skip_lockfs(dmt); /* for DM_DEVICE_RESUME */ #ifdef LIBDM_API_FLUSH if (flags & DMFL_NO_FLUSH) @@ -495,8 +492,6 @@ dm_addmap (int task, const char *target, struct multipath *mpp, task == DM_DEVICE_RELOAD ? "reload" : "addmap", mpp->size, target, params); - dm_task_no_open_count(dmt); - if (task == DM_DEVICE_CREATE && !dm_task_set_cookie(dmt, &cookie, udev_flags)) goto freeout; @@ -627,8 +622,6 @@ dm_get_info(const char *name, struct dm_info *info) if (!dm_task_set_name(dmt, name)) goto out; - dm_task_no_open_count(dmt); - if (!libmp_dm_task_run(dmt)) { dm_log_error(3, DM_DEVICE_INFO, dmt); goto out; @@ -667,8 +660,6 @@ int dm_get_map(const char *name, unsigned long long *size, char **outparams) if (!dm_task_set_name(dmt, name)) goto out; - dm_task_no_open_count(dmt); - errno = 0; if (!libmp_dm_task_run(dmt)) { dm_log_error(3, DM_DEVICE_TABLE, dmt); @@ -787,8 +778,6 @@ int dm_get_status(const char *name, char **outstatus) if (!dm_task_set_name(dmt, name)) goto out; - dm_task_no_open_count(dmt); - errno = 0; if (!libmp_dm_task_run(dmt)) { dm_log_error(3, DM_DEVICE_STATUS, dmt); @@ -845,8 +834,6 @@ int dm_type(const char *name, char *type) if (!dm_task_set_name(dmt, name)) goto out; - dm_task_no_open_count(dmt); - if (!libmp_dm_task_run(dmt)) { dm_log_error(3, DM_DEVICE_TABLE, dmt); goto out; @@ -889,8 +876,6 @@ int dm_is_mpath(const char *name) if (!dm_task_set_name(dmt, name)) goto out_task; - dm_task_no_open_count(dmt); - if (!libmp_dm_task_run(dmt)) { dm_log_error(3, DM_DEVICE_TABLE, dmt); goto out_task; @@ -950,8 +935,6 @@ dm_map_present_by_uuid(const char *uuid) if (!(dmt = libmp_dm_task_create(DM_DEVICE_INFO))) goto out; - dm_task_no_open_count(dmt); - if (!dm_task_set_uuid(dmt, prefixed_uuid)) goto out_task; @@ -1158,8 +1141,6 @@ int dm_flush_maps (int retries) if (!(dmt = libmp_dm_task_create (DM_DEVICE_LIST))) return r; - dm_task_no_open_count(dmt); - if (!libmp_dm_task_run (dmt)) { dm_log_error(3, DM_DEVICE_LIST, dmt); goto out; @@ -1205,8 +1186,6 @@ dm_message(const char * mapname, char * message) if (!dm_task_set_message(dmt, message)) goto out; - dm_task_no_open_count(dmt); - if (!libmp_dm_task_run(dmt)) { dm_log_error(2, DM_DEVICE_TARGET_MSG, dmt); goto out; @@ -1341,8 +1320,6 @@ dm_get_maps (vector mp) if (!(dmt = libmp_dm_task_create(DM_DEVICE_LIST))) return 1; - dm_task_no_open_count(dmt); - if (!libmp_dm_task_run(dmt)) { dm_log_error(3, DM_DEVICE_LIST, dmt); goto out; @@ -1419,7 +1396,6 @@ dm_mapname(int major, int minor) !dm_task_set_minor(dmt, minor)) goto bad; - dm_task_no_open_count(dmt); r = libmp_dm_task_run(dmt); if (!r) { dm_log_error(2, DM_DEVICE_INFO, dmt); @@ -1455,8 +1431,6 @@ do_foreach_partmaps (const char * mapname, if (!(dmt = libmp_dm_task_create(DM_DEVICE_LIST))) return 1; - dm_task_no_open_count(dmt); - if (!libmp_dm_task_run(dmt)) { dm_log_error(3, DM_DEVICE_LIST, dmt); goto out; @@ -1665,8 +1639,6 @@ dm_rename (const char * old, char * new, char *delim, int skip_kpartx) if (!dm_task_set_newname(dmt, new)) goto out; - dm_task_no_open_count(dmt); - if (!dm_task_set_cookie(dmt, &cookie, udev_flags)) goto out; r = libmp_dm_task_run(dmt); @@ -1713,8 +1685,6 @@ int dm_reassign_table(const char *name, char *old, char *new) if (!dm_task_set_name(dmt, name)) goto out; - dm_task_no_open_count(dmt); - if (!libmp_dm_task_run(dmt)) { dm_log_error(3, DM_DEVICE_TABLE, dmt); goto out; @@ -1756,8 +1726,6 @@ int dm_reassign_table(const char *name, char *old, char *new) } while (next); if (modified) { - dm_task_no_open_count(reload_dmt); - if (!libmp_dm_task_run(reload_dmt)) { dm_log_error(3, DM_DEVICE_RELOAD, reload_dmt); condlog(3, "%s: failed to reassign targets", name); @@ -1803,8 +1771,6 @@ int dm_reassign(const char *mapname) if (!dm_task_set_name(dmt, mapname)) goto out; - dm_task_no_open_count(dmt); - if (!libmp_dm_task_run(dmt)) { dm_log_error(3, DM_DEVICE_DEPS, dmt); goto out; @@ -1861,8 +1827,6 @@ int dm_setgeometry(struct multipath *mpp) if (!dm_task_set_name(dmt, mpp->alias)) goto out; - dm_task_no_open_count(dmt); - /* What a sick interface ... */ snprintf(heads, 4, "%u", pp->geom.heads); snprintf(sectors, 4, "%u", pp->geom.sectors); diff --git a/multipathd/dmevents.c b/multipathd/dmevents.c index 5657000..3fbdc55 100644 --- a/multipathd/dmevents.c +++ b/multipathd/dmevents.c @@ -154,8 +154,6 @@ static int dm_get_events(void) if (!(dmt = libmp_dm_task_create(DM_DEVICE_LIST))) return -1; - dm_task_no_open_count(dmt); - if (!libmp_dm_task_run(dmt)) { dm_log_error(3, DM_DEVICE_LIST, dmt); goto fail; diff --git a/multipathd/waiter.c b/multipathd/waiter.c index d1f344b..1dd93c5 100644 --- a/multipathd/waiter.c +++ b/multipathd/waiter.c @@ -108,8 +108,6 @@ static int waiteventloop (struct event_thread *waiter) return 1; } - dm_task_no_open_count(waiter->dmt); - /* wait */ sigemptyset(&set); sigaddset(&set, SIGUSR2); diff --git a/tests/dmevents.c b/tests/dmevents.c index 668e6d2..2f98173 100644 --- a/tests/dmevents.c +++ b/tests/dmevents.c @@ -267,15 +267,6 @@ struct dm_task *__wrap_libmp_dm_task_create(int task) return mock_type(struct dm_task *); } -int __real_dm_task_no_open_count(struct dm_task *dmt); -int __wrap_dm_task_no_open_count(struct dm_task *dmt) -{ - if (!setup_done) - return __real_dm_task_no_open_count(dmt); - assert_ptr_equal((struct test_data *)dmt, &data); - return mock_type(int); -} - int __real_dm_task_run(struct dm_task *dmt); int __wrap_dm_task_run(struct dm_task *dmt) { @@ -554,7 +545,6 @@ static void test_get_events_bad1(void **state) skip(); will_return(__wrap_libmp_dm_task_create, &data); - will_return(__wrap_dm_task_no_open_count, 1); will_return(__wrap_dm_task_run, 0); assert_int_equal(dm_get_events(), -1); } @@ -567,7 +557,6 @@ static void test_get_events_bad2(void **state) skip(); will_return(__wrap_libmp_dm_task_create, &data); - will_return(__wrap_dm_task_no_open_count, 1); will_return(__wrap_dm_task_run, 1); will_return(__wrap_dm_task_get_names, 0); assert_int_equal(dm_get_events(), -1); @@ -582,7 +571,6 @@ static void test_get_events_good0(void **state) assert_int_equal(add_dm_device_event("foo", 1, 5), 0); will_return(__wrap_libmp_dm_task_create, &data); - will_return(__wrap_dm_task_no_open_count, 1); will_return(__wrap_dm_task_run, 1); will_return(__wrap_dm_task_get_names, 1); assert_int_equal(dm_get_events(), 0); @@ -617,7 +605,6 @@ static void test_get_events_good1(void **state) assert_int_equal(add_dm_device_event("foo", 1, 6), 0); assert_int_equal(remove_dm_device_event("xyzzy"), 0); will_return(__wrap_libmp_dm_task_create, &data); - will_return(__wrap_dm_task_no_open_count, 1); will_return(__wrap_dm_task_run, 1); will_return(__wrap_dm_task_get_names, 1); assert_int_equal(dm_get_events(), 0); From patchwork Fri Jul 12 17:14:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13732060 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F0D02176240 for ; Fri, 12 Jul 2024 17:15:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804547; cv=none; b=pK5s4u2Em7MpSWMTPwJM/dMdIOASwa/9FN5tVTut+/L98QXqrFgmEo3BXDkoaI8Rhc21MwdBDTlkebNP4NxVyUtctaTAXG/X3ETyCfSr1MHbgKlAUBJUgfTeoCTkbm4pp/x/56Q9imWSd01WWeji1nklCKzQYR+tPCIbQSbgIqs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804547; c=relaxed/simple; bh=FbifY8meWERMdy+RSPRDICc394kBtMfJTYhYIEkVzqE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iIMyYULAl6dDrbLlGeHOJJ2rJ0Xnto6htrLKCFugIcsgZFccKEiZznCkvceVCgKmcXeXoM2J3LSzbjccbJL59w7UUvt5oXgF02LkQivHAW8AZq5RVZaUnv4nNmIdArg9hYUfPEivk9snn748hnkRju3FtZlZ59o+HzA6wA6QHQ4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=Ew2tzFs2; arc=none smtp.client-ip=209.85.208.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="Ew2tzFs2" Received: by mail-ed1-f53.google.com with SMTP id 4fb4d7f45d1cf-585e774fd3dso3054509a12.0 for ; Fri, 12 Jul 2024 10:15:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1720804543; x=1721409343; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2fZ/Ks44oEMJt4fpgSvTODnYSB0uj/8LMWxAsP0vGNQ=; b=Ew2tzFs2CqWOvYBdeIuGkjAH5SN0jP/GQMpj1IJL9+gkv97SHUzF1otXR2lcyTo54S J8+C4P1OCLl7gZ1fNCE6GfRctvGXzLIZ0SUvxJ8S0avlNddEuxCKrp31AqXtv6y7drOJ GnIP/l+Box6TM87z4gdrwE1CSZ8oxEIW5cPxGDM1nw1fxQgWNji5R/j6n+0obPSBrAez 5GxjqiPGiIFwMPvcRZNnUDdE8paCGdSVoVyejPPc0eGLPyXaKqrrkNe49SWAuqLWVdSj xDAbzGQ7sQAJWzujeRJay2MUH+3lWCo/Wi8nUirhqQUgCJ8z8391MYYgg2LvV60SxTUw TNNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720804543; x=1721409343; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2fZ/Ks44oEMJt4fpgSvTODnYSB0uj/8LMWxAsP0vGNQ=; b=tXVjnE4AYUhZXtEKkqZ7Yd6kHF9athB1+dkiY+DNn9O0/MdY82iY7kTgQTc2C8YBSS qTgjLEiegI3qsJt+t5mz9eOz158RmlCcjBSThOfasT8CkEjCrrJGONNrvFgATr5IBEOp GUjqD/IrtfbYX4m9aL0YDlKbkGcabuzh7A4MorW/Tgc39AlYwsQTlIU6MaqFCnBpcoao gLnH7hY8u869iw6+8dn9C3rinAcII8UeJPYtkTJtaadFa5sXBEV1xHiw8mwgZzT0PKv4 9khqt4QpgLkY4YBYwli2hITFi+/JiGYwkRt4RbXtlzdPGWf4yqqt4i8yh89knsu6nHVR MoYQ== X-Gm-Message-State: AOJu0YwWttTfvbA2oJvXXBA2swhCh/WlBtqNZAvjihQ67BKzuswNmwvx FiWmGlIK5T1znF87HSAqaBqrBYbcTvXxCi6V6ZCgnhp7+ePzUla43yd5HvSbQ34= X-Google-Smtp-Source: AGHT+IHQ31NO3gt/tDBUvsqHaJO2aFF66mnJSYezbTo6yIVTJnNSPQIG0joZj1nXvuPIHgK7ltY38w== X-Received: by 2002:a17:906:6c93:b0:a6f:4d6b:c779 with SMTP id a640c23a62f3a-a780b881c6fmr713735766b.52.1720804543145; Fri, 12 Jul 2024 10:15:43 -0700 (PDT) Received: from localhost (p200300de37360a00d7e56139e90929dd.dip0.t-ipconnect.de. [2003:de:3736:a00:d7e5:6139:e909:29dd]) by smtp.gmail.com with UTF8SMTPSA id a640c23a62f3a-a780a6bc57csm360189566b.1.2024.07.12.10.15.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 10:15:43 -0700 (PDT) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, Martin Wilck Subject: [PATCH v2 13/49] libmpathutil: export cleanup_udev_device() Date: Fri, 12 Jul 2024 19:14:21 +0200 Message-ID: <20240712171458.77611-14-mwilck@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712171458.77611-1-mwilck@suse.com> References: <20240712171458.77611-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This function is useful in multiple callers. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmpathutil/libmpathutil.version | 4 ++++ libmpathutil/util.c | 6 ++++++ libmpathutil/util.h | 3 +++ libmultipath/print.c | 6 ------ tests/Makefile | 2 +- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/libmpathutil/libmpathutil.version b/libmpathutil/libmpathutil.version index fee74a3..86450f4 100644 --- a/libmpathutil/libmpathutil.version +++ b/libmpathutil/libmpathutil.version @@ -133,3 +133,7 @@ LIBMPATHUTIL_2.0 { LIBMPATHUTIL_2.1 { libmp_basename; }; + +LIBMPATHUTIL_2.2 { + cleanup_udev_device; +}; diff --git a/libmpathutil/util.c b/libmpathutil/util.c index 23d303f..67db3c8 100644 --- a/libmpathutil/util.c +++ b/libmpathutil/util.c @@ -373,3 +373,9 @@ void cleanup_ucharp(unsigned char **p) { free(*p); } + +void cleanup_udev_device(struct udev_device **udd) +{ + if (*udd) + udev_device_unref(*udd); +} diff --git a/libmpathutil/util.h b/libmpathutil/util.h index 4997fed..c19f749 100644 --- a/libmpathutil/util.h +++ b/libmpathutil/util.h @@ -10,6 +10,7 @@ #include #include #include +#include size_t strchop(char *); @@ -139,4 +140,6 @@ static inline void clear_bit_in_bitfield(unsigned int bit, struct bitfield *bf) void cleanup_charp(char **p); void cleanup_ucharp(unsigned char **p); +void cleanup_udev_device(struct udev_device **udd); + #endif /* _UTIL_H */ diff --git a/libmultipath/print.c b/libmultipath/print.c index d592001..b7af913 100644 --- a/libmultipath/print.c +++ b/libmultipath/print.c @@ -436,12 +436,6 @@ snprint_multipath_vpd_data(struct strbuf *buff, return append_strbuf_str(buff, "[undef]"); } -static void cleanup_udev_device(struct udev_device **udd) -{ - if (*udd) - udev_device_unref(*udd); -} - static int snprint_multipath_max_sectors_kb(struct strbuf *buff, const struct multipath *mpp) { diff --git a/tests/Makefile b/tests/Makefile index 4005204..8afa8c6 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -53,7 +53,7 @@ vpd-test_OBJDEPS := $(multipathdir)/discovery.o vpd-test_LIBDEPS := -ludev -lpthread -ldl alias-test_TESTDEPS := test-log.o alias-test_OBJDEPS := $(mpathutildir)/util.o -alias-test_LIBDEPS := -lpthread -ldl +alias-test_LIBDEPS := -ludev -lpthread -ldl valid-test_OBJDEPS := $(multipathdir)/valid.o $(multipathdir)/discovery.o valid-test_LIBDEPS := -lmount -ludev -lpthread -ldl devt-test_LIBDEPS := -ludev From patchwork Fri Jul 12 17:14:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13732062 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1C629176256 for ; Fri, 12 Jul 2024 17:15:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804549; cv=none; b=SE3vHPCJifsQANIUMO82qH52/GTsdvkHKrHRTRLgR//O9UTvF+HM8q09gn9rlidEba3TuNutVZSUctNJRCKtQF++XTjc7eWIT7NnVCa+CMBOxtcmCrIq4mBq+rKbdW/dOeBLq9PvsbUQM1M+W+e/iMIaKA9mE0QyomvuaO2bO9k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804549; c=relaxed/simple; bh=KmzolhYSqPZa4mjb8XegQnSn9CbgsYBLPLQXdZbhyC4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Qw/BRYsGQ2xiBYdhj3RMXOVhO8qJpPNd1EQ8etCUsagUV1QefB5z+KSO31CFaJ+jEAPKBlaBxSYL2YPZv4/xlCaNA0Gd9dtvJpzH0DjSIfeVLezawDUE4Jvmf7K24+6o446cjgJvw7DwQ0o3SibTFMlHk5o2S56ijq5j9fY4yHs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=CYFnZK0X; arc=none smtp.client-ip=209.85.218.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="CYFnZK0X" Received: by mail-ej1-f46.google.com with SMTP id a640c23a62f3a-a79a7d1a0dbso87981866b.2 for ; Fri, 12 Jul 2024 10:15:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1720804544; x=1721409344; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=S9UDYTV9Sr+10JeObUXODObNAZnhUpdDLyTLHRJjE+w=; b=CYFnZK0XKIlogzKtf4yKKB4LbzOUcbVa3nVFLtC4Ym5DQ+ryCMj4TUFt5yvdcN7l75 t+cvMSVAKototJN4y9GnyTx5nZQBbCgNPvAINQJURcDNTT3GRIHDbCIwURVgVlcBypqZ nkldN0PaqDfCOfb1RgR1BeOgX1da2IcqjFfmJoQk3HoXc9/29FTylHWFqCXhQXmd+98D 2RlDJOizbJpOzWMkKsiikFHSpgdxobibNPQHdNpxjcNXgIwaZMqPjTEy/dZk6fR+7TL+ LSN8KMnaBMiimWYi5nXlY4LGC3weKH+cTyPqwNZjVGwok8P3X7+u6YucNVep/GuJOcSR UdOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720804544; x=1721409344; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=S9UDYTV9Sr+10JeObUXODObNAZnhUpdDLyTLHRJjE+w=; b=XR7va9JhT+X051hlhzT+RE8pSytBfHPZghX62MWkOu5aXBhqb/RpuDmFdB5sNJbS6i X7tpvoIgltVxeTVNSlrCYn2iDieBGvxXzPaJaYst+3Q0uY+/m1MjEzzybBIa/uqzOUgJ 4YTIakIcpADnPg/KMo1Xl2xlzW88PFTjEZQefLbeucGdfBnoXlYGHcLbZInnRCr0Esz8 9ZOhczqB2bi7+/X4/9L63IJxJJMt9wjzvdqK7c6TRMaKsSa8RNXxmIKbYoKHJrXzRSqt 5rlS8ruitxWQ4y0U2CLgOqI+z9ZvlW3pw0DlYYqdkLIWi0hm2iSv8FJ+W8dIE43HoAcH yDnQ== X-Gm-Message-State: AOJu0YywfZ/ofF0D+6vcm2XQ8FH1dMc+RlcjJP8gcKPNRssW+a6LlmSc A5lHNZWy9+TYTzVDtcLq7jWk9N9sIf7RQvo8Byq5ugx7tuSXC0rRjE+eKIVaPFU= X-Google-Smtp-Source: AGHT+IH8DDj6XDRIdNcOKVIwmM2GTtBy9TRsQelKkz+1a95XilpzLZwCwFrODcZlWHB23nPiVG4B9g== X-Received: by 2002:a17:906:68d7:b0:a77:e0ed:8b9 with SMTP id a640c23a62f3a-a780b6889dfmr766930866b.6.1720804544396; Fri, 12 Jul 2024 10:15:44 -0700 (PDT) Received: from localhost (p200300de37360a00d7e56139e90929dd.dip0.t-ipconnect.de. [2003:de:3736:a00:d7e5:6139:e909:29dd]) by smtp.gmail.com with UTF8SMTPSA id a640c23a62f3a-a780a6bcc97sm361763566b.35.2024.07.12.10.15.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 10:15:44 -0700 (PDT) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, Martin Wilck Subject: [PATCH v2 14/49] libmpathutil: add cleanup_vector() Date: Fri, 12 Jul 2024 19:14:22 +0200 Message-ID: <20240712171458.77611-15-mwilck@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712171458.77611-1-mwilck@suse.com> References: <20240712171458.77611-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmpathutil/libmpathutil.version | 1 + libmpathutil/vector.c | 6 ++++++ libmpathutil/vector.h | 1 + 3 files changed, 8 insertions(+) diff --git a/libmpathutil/libmpathutil.version b/libmpathutil/libmpathutil.version index 86450f4..cb05231 100644 --- a/libmpathutil/libmpathutil.version +++ b/libmpathutil/libmpathutil.version @@ -136,4 +136,5 @@ LIBMPATHUTIL_2.1 { LIBMPATHUTIL_2.2 { cleanup_udev_device; + cleanup_vector; }; diff --git a/libmpathutil/vector.c b/libmpathutil/vector.c index df59db5..7c3ce43 100644 --- a/libmpathutil/vector.c +++ b/libmpathutil/vector.c @@ -169,6 +169,12 @@ vector_free(vector v) free(v); } +void cleanup_vector(vector *pv) +{ + if (*pv) + vector_free(*pv); +} + void free_strvec(vector strvec) { diff --git a/libmpathutil/vector.h b/libmpathutil/vector.h index c0b09cb..a41f157 100644 --- a/libmpathutil/vector.h +++ b/libmpathutil/vector.h @@ -78,6 +78,7 @@ extern vector vector_alloc(void); extern bool vector_alloc_slot(vector v); vector vector_reset(vector v); extern void vector_free(vector v); +void cleanup_vector(vector *pv); #define vector_free_const(x) vector_free((vector)(long)(x)) extern void free_strvec(vector strvec); extern void vector_set_slot(vector v, void *value); From patchwork Fri Jul 12 17:14:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13732063 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5FE861DFE1 for ; Fri, 12 Jul 2024 17:15:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804549; cv=none; b=NjHb7lhYw389uJqUIV109UHFE66XlFhX8odAmn5l716hcSbimIEX04NFO0HXZBMjNyihJwDuz4ix+BiRNOuy+NkQKHBwZMk62WdpeZJRm8TK0R4r0Y4HuIB+AQoSJTGMHa3LusXuPWFF6aflFcHdPJWPOzRrJcn3KYmWfk+f1Wk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804549; c=relaxed/simple; bh=ttassK2Ik6roh/vZD4oEg0h2kSKboyhvr0hmX5lygjo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZcQUgGSe2qj1rc9NkAImjAehtTIqgRzsMEBhnVKv0IgOghjx6rAviiZ1Hi2J3A1QpSqtOMyav7D/2ed9ufMOM52PcwEOZeh9FRMPBRz0sgNUrmG+FNPUbqln9gcIYNOo8XgBOQ7dhDGP9LEN2i6x+DtHjEvF2QFDgNiqfzPxTcQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=RqgirPye; arc=none smtp.client-ip=209.85.167.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="RqgirPye" Received: by mail-lf1-f44.google.com with SMTP id 2adb3069b0e04-52e97e5a84bso3267006e87.2 for ; Fri, 12 Jul 2024 10:15:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1720804546; x=1721409346; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4MXeOB02twXZFP13SYTKhlUqfQR1lX7YEE2GnAaoof0=; b=RqgirPyejGQt/e7K9wEEhag+DVainegRYBA0QVz5KOqhBEKALbTreHt6Vfo5QuWYbw PIm+G8mykkrlezQquHeRt2TVue4JGSwHqh0fs9UQSxVqY56XVU7rNzaKHGIe8VZi/rhm NEbOiVW9dp+kNYLEHcrwhvKaGpOq0G80RinLJ74/XrhQPxijhCMgQTMpCYi5pdeKpFY0 ha3XMv3g1kwttVXOkJV7IDXbI0Qg6gafqmhcXGnZZMdcJ4B/1V8fZSkw8yrQX3Utbyv5 ptThRU1RzRg2wbnuo0CmNh16RVMvTzFOsKE4oTxNWBDymKksZ4jg/Dv0aIi1te7ayKq0 EUcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720804546; x=1721409346; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4MXeOB02twXZFP13SYTKhlUqfQR1lX7YEE2GnAaoof0=; b=tsKkLB2PhSPNFmoQ1nzmGuddZWTeynyvr5eGHyV6vYDNdj64YRYuDyJqjSjN9WpsI/ /GsQwlGXAqMIamSX1nP1+0awhoylgbQVPOnpyqOU/Po6LsfZFU+i0/xG25I60QqIfijf 7TK3UfPM6PWNSuFaXJnfe3ysEYTK3hbXby/WqJJt037Z5H085k6uz2QP6ZMXE0rTc8LP 1qI5idYsaW+7WtmHthmEez2hlxAe5lnZAgZPsJYu4DDXytXdYJZH1sT3ECt/utbg9ZNa QDZloBGIGIyjA4NAhwmJ+tVd2TsUQXVBqJPtaowvLVDHkNByXR3cy5yRwENbkTtbV2he blxw== X-Gm-Message-State: AOJu0YxMwWtzydyroMJFOMgPtLBKWpx1Zf4HUbVbfteipo1rXeraewvA c2Sg4dzjWFzkZnnBUAom2OE+HAtYjDFE+ugoCFsa3SwelP6vcit7szCHb2cS1ks= X-Google-Smtp-Source: AGHT+IHDJTbqdnuLM+4lAKFmBpawkWqPn0uz46Xol6dfOy5TwuzQbwoxSlEztN37KbROjlStm5VG6Q== X-Received: by 2002:a05:6512:1247:b0:52e:716a:1898 with SMTP id 2adb3069b0e04-52eb99d5ff5mr10616130e87.58.1720804545406; Fri, 12 Jul 2024 10:15:45 -0700 (PDT) Received: from localhost (p200300de37360a00d7e56139e90929dd.dip0.t-ipconnect.de. [2003:de:3736:a00:d7e5:6139:e909:29dd]) by smtp.gmail.com with UTF8SMTPSA id a640c23a62f3a-a780a6dc520sm362473366b.51.2024.07.12.10.15.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 10:15:45 -0700 (PDT) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, Martin Wilck Subject: [PATCH v2 15/49] libmultipath: add cleanup helpers for struct multipath Date: Fri, 12 Jul 2024 19:14:23 +0200 Message-ID: <20240712171458.77611-16-mwilck@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712171458.77611-1-mwilck@suse.com> References: <20240712171458.77611-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Export cleanup_multipath_and_paths(), which will be used by multipath. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/libmultipath.version | 1 + libmultipath/structs.c | 12 ++++++++++++ libmultipath/structs.h | 2 ++ 3 files changed, 15 insertions(+) diff --git a/libmultipath/libmultipath.version b/libmultipath/libmultipath.version index eb51174..f58cb1d 100644 --- a/libmultipath/libmultipath.version +++ b/libmultipath/libmultipath.version @@ -66,6 +66,7 @@ global: check_foreign; cleanup_bindings; cleanup_lock; + cleanup_multipath_and_paths; coalesce_paths; count_active_paths; delete_all_foreign; diff --git a/libmultipath/structs.c b/libmultipath/structs.c index be3125e..1583e00 100644 --- a/libmultipath/structs.c +++ b/libmultipath/structs.c @@ -329,6 +329,18 @@ free_multipath (struct multipath * mpp, enum free_path_mode free_paths) free(mpp); } +void cleanup_multipath(struct multipath **pmpp) +{ + if (*pmpp) + free_multipath(*pmpp, KEEP_PATHS); +} + +void cleanup_multipath_and_paths(struct multipath **pmpp) +{ + if (*pmpp) + free_multipath(*pmpp, FREE_PATHS); +} + void drop_multipath (vector mpvec, char * wwid, enum free_path_mode free_paths) { diff --git a/libmultipath/structs.h b/libmultipath/structs.h index dbaf4d4..3b91e39 100644 --- a/libmultipath/structs.h +++ b/libmultipath/structs.h @@ -544,6 +544,8 @@ void free_pathvec (vector vec, enum free_path_mode free_paths); void free_pathgroup (struct pathgroup * pgp, enum free_path_mode free_paths); void free_pgvec (vector pgvec, enum free_path_mode free_paths); void free_multipath (struct multipath *, enum free_path_mode free_paths); +void cleanup_multipath(struct multipath **pmpp); +void cleanup_multipath_and_paths(struct multipath **pmpp); void free_multipath_attributes (struct multipath *); void drop_multipath (vector mpvec, char * wwid, enum free_path_mode free_paths); void free_multipathvec (vector mpvec, enum free_path_mode free_paths); From patchwork Fri Jul 12 17:14:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13732064 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6817F175564 for ; Fri, 12 Jul 2024 17:15:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804551; cv=none; b=Vt6btEXfySOcrLgXNwezUuKIb4c253BOodsbRaLyqJ5y+RqEHFMBpWIvTzXr+ADkOqPAM5LCdPY7fIQPSD/VbkmxpUa807Z9kOzefCZg3SFyROff4xhiJZlTWpG/q5o9rA+WHJeDIZS9Xn7rrzI/j/q8qpsIDM2h+VWtrY/L0+M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804551; c=relaxed/simple; bh=WPSsU/iAWY+FKRl7GSeIc9EL+o4M4xsGcc/QFuPcYZQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OZkvzrfnEKmsyxGJIsiXCazRRxlj+7/f6vcQjHs3FuwbrKE7GIyyfz5O70IYjWdJyHFJFSQEiVvJwbaD31kNBUcO1C5FomD9jvNeYyrwXM1z7fYHfHuEXx1JTpjT7yt8w9fSyCy9DNLrj0CWyThxntzTzw9xPslccyctKs7i/3g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=L8O/rRqg; arc=none smtp.client-ip=209.85.208.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="L8O/rRqg" Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-58b0dddab63so3612911a12.3 for ; Fri, 12 Jul 2024 10:15:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1720804547; x=1721409347; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Mb0B7Hd7jBO2MYoksoGxVz1RYZrGwifSFfR0TgGjfro=; b=L8O/rRqgl+wr+6QeV4/TSVBMtLcbR1bg7wxpTBnjJDigXQa7mszpo5FKRgWAKkSlKN JDN32dtec9dWu0PPOcEGrHF6vi+CuFR/DhMx0UwSptxyVWfp7eyJHtFfm13hi1kCm0Qr Rpq9BqN1ri6Qs05uWYFTg6i2QuVpeKDVQovYUAmgfyrSoa6z8qQr45RxzxI54v68dM2e PI+EzNISDFtUV8qL7L5BrOsgC2XwohLULlVxtLdM6H38p+F/CkdfYq+bl4kkWfCgHqDk 9UG3DF1+EruXL4pdTUtIC3EoMk5rXruxJEr8UGYMGDGi5GXdgLyaji5duQQ8HK9QURSD lsDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720804547; x=1721409347; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Mb0B7Hd7jBO2MYoksoGxVz1RYZrGwifSFfR0TgGjfro=; b=Be7KStIbKo56dXdcSbqNH5VFeFIS8Qs0u3xa+L76NTdzwUTigUMAQ4YonOGj38xkjS E36pjmMK06exdHmVpiL20MA84h5zye5hLwkWRQFOTo5bHYUvZ+PlGZp406ixnVtxewal KZIprjVXDPnDtYmmqA6DmZenAaUkXBlfs5qQZ+DIptn0U4uxkefulVpE6LzRy0dwN4Sh YPwGT1J7FmZhTxeZDjbG2k2f0LLVYJG+9Y29Y7snBqvUd8Pj/4vTuMOujnfOvnLh7kd6 3QuwH9uQTn/Qct2v0/F2cn0YxoBf68TiIchrIzZXp6EJrSEySzTU3JSP0LfNkiVKacw0 a11w== X-Gm-Message-State: AOJu0Yxvk3tpiq9ug6vOQt1sYdPsqXUaOg7FN9Z8l2kX6ceHndu0M96i IIGdRly2+O2ZExRHHx2Ucql/55B0Ro5Eg9aN0pU9yi8wisXtIjXN9oV7u8p2U64= X-Google-Smtp-Source: AGHT+IGxeTpLhstx/yTRvo8mJf1MeKlHarO+jUb7Fm6D5SOYshzvQv+CRgJCbYIhBkROFF2Jv6b3Bg== X-Received: by 2002:a05:6402:2071:b0:58b:565d:ac92 with SMTP id 4fb4d7f45d1cf-594ba6953c2mr7144965a12.22.1720804546426; Fri, 12 Jul 2024 10:15:46 -0700 (PDT) Received: from localhost (p200300de37360a00d7e56139e90929dd.dip0.t-ipconnect.de. [2003:de:3736:a00:d7e5:6139:e909:29dd]) by smtp.gmail.com with UTF8SMTPSA id 4fb4d7f45d1cf-594bd459e1esm4706923a12.73.2024.07.12.10.15.46 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 10:15:46 -0700 (PDT) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, Martin Wilck Subject: [PATCH v2 16/49] libmultipath: add cleanup_dm_task(), and use it in devmapper.c Date: Fri, 12 Jul 2024 19:14:24 +0200 Message-ID: <20240712171458.77611-17-mwilck@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712171458.77611-1-mwilck@suse.com> References: <20240712171458.77611-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This allows us to get rid of a lot of goto statements, and generally obtain cleaner code. Signed-off-by: Martin Wilck --- libmultipath/devmapper.c | 258 ++++++++++++++++----------------------- 1 file changed, 107 insertions(+), 151 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 8996c1d..4bff62d 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -91,6 +91,12 @@ int libmp_dm_task_run(struct dm_task *dmt) return r; } +static void cleanup_dm_task(struct dm_task **pdmt) +{ + if (*pdmt) + dm_task_destroy(*pdmt); +} + __attribute__((format(printf, 4, 5))) static void dm_write_log (int level, const char *file, int line, const char *f, ...) { @@ -203,8 +209,8 @@ static void init_dm_drv_version(void) static int dm_tgt_version (unsigned int *version, char *str) { - int r = 2; - struct dm_task *dmt; + bool found = false; + struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; struct dm_versions *target; struct dm_versions *last_target; unsigned int *v; @@ -220,31 +226,28 @@ static int dm_tgt_version (unsigned int *version, char *str) if (!libmp_dm_task_run(dmt)) { dm_log_error(2, DM_DEVICE_LIST_VERSIONS, dmt); condlog(0, "Cannot communicate with kernel DM"); - goto out; + return 1; } target = dm_task_get_versions(dmt); do { last_target = target; if (!strncmp(str, target->name, strlen(str))) { - r = 1; + found = true; break; } target = (void *) target + target->next; } while (last_target != target); - if (r == 2) { + if (!found) { condlog(0, "DM %s kernel driver not loaded", str); - goto out; + return 1; } v = target->version; version[0] = v[0]; version[1] = v[1]; version[2] = v[2]; - r = 0; -out: - dm_task_destroy(dmt); - return r; + return 0; } static void init_dm_mpath_version(void) @@ -383,18 +386,18 @@ libmp_dm_task_create(int task) static int dm_simplecmd (int task, const char *name, int flags, uint16_t udev_flags) { - int r = 0; + int r; int udev_wait_flag = (((flags & DMFL_NEED_SYNC) || udev_flags) && (task == DM_DEVICE_RESUME || task == DM_DEVICE_REMOVE)); uint32_t cookie = 0; - struct dm_task *dmt; + struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; if (!(dmt = libmp_dm_task_create (task))) return 0; if (!dm_task_set_name (dmt, name)) - goto out; + return 0; dm_task_skip_lockfs(dmt); /* for DM_DEVICE_RESUME */ #ifdef LIBDM_API_FLUSH @@ -408,7 +411,7 @@ dm_simplecmd (int task, const char *name, int flags, uint16_t udev_flags) { if (udev_wait_flag && !dm_task_set_cookie(dmt, &cookie, DM_UDEV_DISABLE_LIBRARY_FALLBACK | udev_flags)) - goto out; + return 0; r = libmp_dm_task_run (dmt); if (!r) @@ -416,8 +419,6 @@ dm_simplecmd (int task, const char *name, int flags, uint16_t udev_flags) { if (udev_wait_flag) libmp_udev_wait(cookie); -out: - dm_task_destroy (dmt); return r; } @@ -440,8 +441,9 @@ static int dm_addmap (int task, const char *target, struct multipath *mpp, char * params, int ro, uint16_t udev_flags) { int r = 0; - struct dm_task *dmt; - char *prefixed_uuid = NULL; + struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; + char __attribute__((cleanup(cleanup_charp))) *prefixed_uuid = NULL; + uint32_t cookie = 0; if (task == DM_DEVICE_CREATE && strlen(mpp->wwid) == 0) { @@ -457,10 +459,10 @@ dm_addmap (int task, const char *target, struct multipath *mpp, return 0; if (!dm_task_set_name (dmt, mpp->alias)) - goto addout; + return 0; if (!dm_task_add_target (dmt, 0, mpp->size, target, params)) - goto addout; + return 0; if (ro) dm_task_set_ro(dmt); @@ -469,10 +471,10 @@ dm_addmap (int task, const char *target, struct multipath *mpp, if (asprintf(&prefixed_uuid, UUID_PREFIX "%s", mpp->wwid) < 0) { condlog(0, "cannot create prefixed uuid : %s", strerror(errno)); - goto addout; + return 0; } if (!dm_task_set_uuid(dmt, prefixed_uuid)) - goto freeout; + return 0; dm_task_skip_lockfs(dmt); #ifdef LIBDM_API_FLUSH dm_task_no_flush(dmt); @@ -481,33 +483,28 @@ dm_addmap (int task, const char *target, struct multipath *mpp, if (mpp->attribute_flags & (1 << ATTR_MODE) && !dm_task_set_mode(dmt, mpp->mode)) - goto freeout; + return 0; if (mpp->attribute_flags & (1 << ATTR_UID) && !dm_task_set_uid(dmt, mpp->uid)) - goto freeout; + return 0; if (mpp->attribute_flags & (1 << ATTR_GID) && !dm_task_set_gid(dmt, mpp->gid)) - goto freeout; + return 0; + condlog(2, "%s: %s [0 %llu %s %s]", mpp->alias, task == DM_DEVICE_RELOAD ? "reload" : "addmap", mpp->size, target, params); if (task == DM_DEVICE_CREATE && !dm_task_set_cookie(dmt, &cookie, udev_flags)) - goto freeout; + return 0; r = libmp_dm_task_run (dmt); if (!r) dm_log_error(2, task, dmt); if (task == DM_DEVICE_CREATE) - libmp_udev_wait(cookie); -freeout: - if (prefixed_uuid) - free(prefixed_uuid); - -addout: - dm_task_destroy (dmt); + libmp_udev_wait(cookie); if (r) mpp->need_reload = false; @@ -648,46 +645,41 @@ int dm_map_present(const char * str) int dm_get_map(const char *name, unsigned long long *size, char **outparams) { - int r = DMP_ERR; - struct dm_task *dmt; + struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; uint64_t start, length; char *target_type = NULL; char *params = NULL; if (!(dmt = libmp_dm_task_create(DM_DEVICE_TABLE))) - return r; + return DMP_ERR; if (!dm_task_set_name(dmt, name)) - goto out; + return DMP_ERR; errno = 0; if (!libmp_dm_task_run(dmt)) { dm_log_error(3, DM_DEVICE_TABLE, dmt); if (dm_task_get_errno(dmt) == ENXIO) - r = DMP_NOT_FOUND; - goto out; + return DMP_NOT_FOUND; + else + return DMP_ERR; } - r = DMP_NOT_FOUND; /* Fetch 1st target */ if (dm_get_next_target(dmt, NULL, &start, &length, &target_type, ¶ms) != NULL || !params) /* more than one target or not found target */ - goto out; + return DMP_NOT_FOUND; if (size) *size = length; if (!outparams) - r = DMP_OK; + return DMP_OK; else { *outparams = strdup(params); - r = *outparams ? DMP_OK : DMP_ERR; + return *outparams ? DMP_OK : DMP_ERR; } - -out: - dm_task_destroy(dmt); - return r; } static int @@ -767,7 +759,7 @@ is_mpath_part(const char *part_name, const char *map_name) int dm_get_status(const char *name, char **outstatus) { int r = DMP_ERR; - struct dm_task *dmt; + struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; uint64_t start, length; char *target_type = NULL; char *status = NULL; @@ -796,7 +788,7 @@ int dm_get_status(const char *name, char **outstatus) goto out; if (!status) { - condlog(2, "get null status."); + condlog(2, "got null status."); goto out; } @@ -808,9 +800,9 @@ int dm_get_status(const char *name, char **outstatus) } out: if (r != DMP_OK) - condlog(0, "%s: error getting map status string", name); + condlog(0, "%s: %s: error getting map status string: %d", + __func__, name, r); - dm_task_destroy(dmt); return r; } @@ -823,7 +815,7 @@ out: int dm_type(const char *name, char *type) { int r = 0; - struct dm_task *dmt; + struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; uint64_t start, length; char *target_type = NULL; char *params; @@ -850,7 +842,6 @@ int dm_type(const char *name, char *type) r = 1; out: - dm_task_destroy(dmt); return r; } @@ -863,7 +854,7 @@ out: int dm_is_mpath(const char *name) { int r = -1; - struct dm_task *dmt; + struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; struct dm_info info; uint64_t start, length; char *target_type = NULL; @@ -874,38 +865,36 @@ int dm_is_mpath(const char *name) goto out; if (!dm_task_set_name(dmt, name)) - goto out_task; + goto out; if (!libmp_dm_task_run(dmt)) { dm_log_error(3, DM_DEVICE_TABLE, dmt); - goto out_task; + goto out; } if (!dm_task_get_info(dmt, &info)) - goto out_task; + goto out; r = 0; if (!info.exists) - goto out_task; + goto out; uuid = dm_task_get_uuid(dmt); if (!uuid || strncmp(uuid, UUID_PREFIX, UUID_PREFIX_LEN) != 0) - goto out_task; + goto out; /* Fetch 1st target */ if (dm_get_next_target(dmt, NULL, &start, &length, &target_type, ¶ms) != NULL) /* multiple targets */ - goto out_task; + goto out; if (!target_type || strcmp(target_type, TGT_MPATH) != 0) - goto out_task; + goto out; r = 1; -out_task: - dm_task_destroy(dmt); out: if (r < 0) condlog(3, "%s: dm command failed in %s: %s", name, __FUNCTION__, strerror(errno)); @@ -1131,10 +1120,10 @@ dm_flush_map_nopaths(const char *mapname, int deferred_remove __DR_UNUSED__) return _dm_flush_map(mapname, flags, 0); } -int dm_flush_maps (int retries) +int dm_flush_maps(int retries) { int r = DM_FLUSH_FAIL; - struct dm_task *dmt; + struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; struct dm_names *names; unsigned next = 0; @@ -1143,15 +1132,15 @@ int dm_flush_maps (int retries) if (!libmp_dm_task_run (dmt)) { dm_log_error(3, DM_DEVICE_LIST, dmt); - goto out; + return r; } if (!(names = dm_task_get_names (dmt))) - goto out; + return r; r = DM_FLUSH_OK; if (!names->dev) - goto out; + return r; do { int ret; @@ -1163,16 +1152,13 @@ int dm_flush_maps (int retries) names = (void *) names + next; } while (next); -out: - dm_task_destroy (dmt); return r; } int dm_message(const char * mapname, char * message) { - int r = 1; - struct dm_task *dmt; + struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; if (!(dmt = libmp_dm_task_create(DM_DEVICE_TARGET_MSG))) return 1; @@ -1191,13 +1177,10 @@ dm_message(const char * mapname, char * message) goto out; } - r = 0; + return 0; out: - if (r) - condlog(0, "DM message failed [%s]", message); - - dm_task_destroy(dmt); - return r; + condlog(0, "DM message failed [%s]", message); + return 1; } int @@ -1305,12 +1288,10 @@ out: return NULL; } -int -dm_get_maps (vector mp) +int dm_get_maps(vector mp) { struct multipath * mpp; - int r = 1; - struct dm_task *dmt; + struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; struct dm_names *names; unsigned next = 0; @@ -1322,15 +1303,15 @@ dm_get_maps (vector mp) if (!libmp_dm_task_run(dmt)) { dm_log_error(3, DM_DEVICE_LIST, dmt); - goto out; + return 1; } if (!(names = dm_task_get_names(dmt))) - goto out; + return 1; if (!names->dev) { - r = 0; /* this is perfectly valid */ - goto out; + /* this is perfectly valid */ + return 0; } do { @@ -1339,11 +1320,11 @@ dm_get_maps (vector mp) mpp = dm_get_multipath(names->name); if (!mpp) - goto out; + return 1; if (!vector_alloc_slot(mp)) { free_multipath(mpp, KEEP_PATHS); - goto out; + return 1; } vector_set_slot(mp, mpp); @@ -1352,11 +1333,7 @@ next: names = (void *) names + next; } while (next); - r = 0; - goto out; -out: - dm_task_destroy (dmt); - return r; + return 0; } int @@ -1419,10 +1396,10 @@ do_foreach_partmaps (const char * mapname, int (*partmap_func)(const char *, void *), void *data) { - struct dm_task *dmt; + 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 *params = NULL; unsigned long long size; char dev_t[32]; int r = 1; @@ -1431,21 +1408,18 @@ do_foreach_partmaps (const char * mapname, if (!(dmt = libmp_dm_task_create(DM_DEVICE_LIST))) return 1; - if (!libmp_dm_task_run(dmt)) { - dm_log_error(3, DM_DEVICE_LIST, dmt); - goto out; - } + if (!libmp_dm_task_run(dmt)) + return 1; if (!(names = dm_task_get_names(dmt))) - goto out; + return 1; - if (!names->dev) { - r = 0; /* this is perfectly valid */ - goto out; - } + if (!names->dev) + /* this is perfectly valid */ + return 0; if (dm_dev_t(mapname, &dev_t[0], 32)) - goto out; + return 1; do { if ( @@ -1472,7 +1446,7 @@ do_foreach_partmaps (const char * mapname, !isdigit(*(p + strlen(dev_t))) ) { if ((r = partmap_func(names->name, data)) != 0) - goto out; + return 1; } free(params); @@ -1481,11 +1455,7 @@ do_foreach_partmaps (const char * mapname, names = (void *) names + next; } while (next); - r = 0; -out: - free(params); - dm_task_destroy (dmt); - return r; + return 0; } struct remove_data { @@ -1623,7 +1593,7 @@ int dm_rename (const char * old, char * new, char *delim, int skip_kpartx) { int r = 0; - struct dm_task *dmt; + 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); @@ -1634,22 +1604,19 @@ dm_rename (const char * old, char * new, char *delim, int skip_kpartx) return r; if (!dm_task_set_name(dmt, old)) - goto out; + return r; if (!dm_task_set_newname(dmt, new)) - goto out; + return r; if (!dm_task_set_cookie(dmt, &cookie, udev_flags)) - goto out; + return r; + r = libmp_dm_task_run(dmt); if (!r) dm_log_error(2, DM_DEVICE_RENAME, dmt); libmp_udev_wait(cookie); - -out: - dm_task_destroy(dmt); - return r; } @@ -1672,9 +1639,10 @@ void dm_reassign_deps(char *table, const char *dep, const char *newdep) int dm_reassign_table(const char *name, char *old, char *new) { - int r = 0, modified = 0; + int modified = 0; uint64_t start, length; - struct dm_task *dmt, *reload_dmt; + struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; + struct dm_task __attribute__((cleanup(cleanup_dm_task))) *reload_dmt = NULL; char *target, *params = NULL; char *buff; void *next = NULL; @@ -1683,16 +1651,16 @@ int dm_reassign_table(const char *name, char *old, char *new) return 0; if (!dm_task_set_name(dmt, name)) - goto out; + return 0; if (!libmp_dm_task_run(dmt)) { dm_log_error(3, DM_DEVICE_TABLE, dmt); - goto out; + return 0; } if (!(reload_dmt = libmp_dm_task_create(DM_DEVICE_RELOAD))) - goto out; + return 0; if (!dm_task_set_name(reload_dmt, name)) - goto out_reload; + return 0; do { next = dm_get_next_target(dmt, next, &start, &length, @@ -1705,13 +1673,13 @@ int dm_reassign_table(const char *name, char *old, char *new) */ condlog(1, "%s: invalid target found in map %s", __func__, name); - goto out_reload; + return 0; } buff = strdup(params); if (!buff) { condlog(3, "%s: failed to replace target %s, " "out of memory", name, target); - goto out_reload; + return 0; } if (strcmp(target, TGT_MPATH) && strstr(params, old)) { condlog(3, "%s: replace target %s %s", @@ -1729,18 +1697,12 @@ int dm_reassign_table(const char *name, char *old, char *new) if (!libmp_dm_task_run(reload_dmt)) { dm_log_error(3, DM_DEVICE_RELOAD, reload_dmt); condlog(3, "%s: failed to reassign targets", name); - goto out_reload; + return 0; } dm_simplecmd_noflush(DM_DEVICE_RESUME, name, MPATH_UDEV_RELOAD_FLAG); } - r = 1; - -out_reload: - dm_task_destroy(reload_dmt); -out: - dm_task_destroy(dmt); - return r; + return 1; } @@ -1752,10 +1714,9 @@ out: int dm_reassign(const char *mapname) { struct dm_deps *deps; - struct dm_task *dmt; + struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; struct dm_info info; char dev_t[32], dm_dep[32]; - int r = 0; unsigned int i; if (dm_dev_t(mapname, &dev_t[0], 32)) { @@ -1769,21 +1730,21 @@ int dm_reassign(const char *mapname) } if (!dm_task_set_name(dmt, mapname)) - goto out; + return 0; if (!libmp_dm_task_run(dmt)) { dm_log_error(3, DM_DEVICE_DEPS, dmt); - goto out; + return 0; } if (!dm_task_get_info(dmt, &info)) - goto out; + return 0; if (!(deps = dm_task_get_deps(dmt))) - goto out; + return 0; if (!info.exists) - goto out; + return 0; for (i = 0; i < deps->count; i++) { sprintf(dm_dep, "%d:%d", @@ -1792,15 +1753,12 @@ int dm_reassign(const char *mapname) sysfs_check_holders(dm_dep, dev_t); } - r = 1; -out: - dm_task_destroy (dmt); - return r; + return 1; } int dm_setgeometry(struct multipath *mpp) { - struct dm_task *dmt; + struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; struct path *pp; char heads[4], sectors[4]; char cylinders[10], start[32]; @@ -1825,7 +1783,7 @@ int dm_setgeometry(struct multipath *mpp) return 0; if (!dm_task_set_name(dmt, mpp->alias)) - goto out; + return 0; /* What a sick interface ... */ snprintf(heads, 4, "%u", pp->geom.heads); @@ -1834,14 +1792,12 @@ int dm_setgeometry(struct multipath *mpp) snprintf(start, 32, "%lu", pp->geom.start); if (!dm_task_set_geometry(dmt, cylinders, heads, sectors, start)) { condlog(3, "%s: Failed to set geometry", mpp->alias); - goto out; + return 0; } r = libmp_dm_task_run(dmt); if (!r) dm_log_error(3, DM_DEVICE_SET_GEOMETRY, dmt); -out: - dm_task_destroy(dmt); return r; } From patchwork Fri Jul 12 17:14:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13732065 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4E4A0176AAD for ; Fri, 12 Jul 2024 17:15:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804551; cv=none; b=rmea8ifeJnhv8CbY/47P/yWzt8yOQ3BnraMMh11ZZ8eIvkWl5cPxTpgfoLJrrAU+i7CqpNBMMff89SFk4bNJ7yyti6dJoSIRZje33RJRniWqzihtCsCA7F/20sDv0Xix1vCiDQYQ0Ob8EVsMPh5g2V2Y7b1+9otK8FB4Ph996KY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804551; c=relaxed/simple; bh=GbPl1jhGQtpULVCFUDcVuirJGddvFbXJxiQNHxd/qAk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YE1zZ/hdCC6tUJsIZEb7gkhLq4HGLGXw/D8Bs5CBTWRvECLhb3mYxezc0Sga18aq4otcKS5wbrpNx9RShaANouwLllUAQ9FsFFLp7A1grMNooLpnlZw8a3gdT0p/IRBzfUkpSgUsEmHku1zOSQes1H6gFtaMeNTP2+xhmNUjdUo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=elxygJ2h; arc=none smtp.client-ip=209.85.218.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="elxygJ2h" Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-a6265d3ba8fso273098666b.0 for ; Fri, 12 Jul 2024 10:15:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1720804548; x=1721409348; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=cVmA7ZgDqHQeLCSjLbZhultkOWjweqJFgk141ONO2m0=; b=elxygJ2hV79lT9sBSJ155YNxS7LP+mvjGegOgwR7LvkclOXlzqBjQ5Qn6B9SnMGYKc UoqtU7Ma5WGTGKslLzAi7hp+sOhOKKf/KoC/aZ9mDGfhDlmQ82+4kpRVjf3IzFfTlPJK VjkL5agw23QYtkPnXeyeMgQMwXh3ucdRimEDJ0aCvZTf6+KcKmuBxL3lrED2BfC8Xzp1 Wrxy+09F9oos8SFzo/RUlVDNlHLKnEl0fnGWuSrIFDb6ZRI3HwlSFKE8KJ5TLdli1JGe /1QPYoVC5bngz1K1oP6PAovkR3Gg315Ln3PGBsPRRXT4CNv09weOOP5dhZfrUdgktlfQ MmVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720804548; x=1721409348; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cVmA7ZgDqHQeLCSjLbZhultkOWjweqJFgk141ONO2m0=; b=WMbQPM16OuxVAt8ilJmjm8OTmVrVuCrNDg8hbJ9ZbH4PvwyTQhTH2BLs0qm1P+zFHW /fjirldffkejSXgMK60tmCV0s+iM1je4ryiqhpVw3T4ygPs9v8BlxBAVQLKafpnNel7K +Hpl82wZUQpLmkpZJIxnuaRcQ6UaE/ihTP/BRkE4l9VB9evhMYiWyiiMAJ0mCQDYM0OW x4nMqxr6RhAHzjvlG7sFcrU9hAraXoCBHZYfMMG32UG33p7zDLyRGZoEy7eQ3ordI2kB qqLrWivIbJ0Z7Fl060xbB0oHuCgzMlbbaCmP7FceSyYZm0BZJiwh5CZtIh/M8bbVPqoZ xMFw== X-Gm-Message-State: AOJu0Yy1ydp/a815RTVthVESFbUORdbQLwc/pXX2Ck9HrnE62tST73bA 5hQvCqmpmZZczyjYKG0QAxfEDVjqDkD3ZPLBRh/n+zf5vzOc1XaSj+99SpvTUrOyOeg/QMN0anJ w X-Google-Smtp-Source: AGHT+IE6EH02GsECf6/EclV7bUpew4m5eveASEQ4yM28Am750DwrOBxfh4/4csspK82t8vEfRmNw8A== X-Received: by 2002:a17:906:6895:b0:a6f:718f:39b6 with SMTP id a640c23a62f3a-a780b6b1818mr770090466b.25.1720804547395; Fri, 12 Jul 2024 10:15:47 -0700 (PDT) Received: from localhost (p200300de37360a00d7e56139e90929dd.dip0.t-ipconnect.de. [2003:de:3736:a00:d7e5:6139:e909:29dd]) by smtp.gmail.com with UTF8SMTPSA id a640c23a62f3a-a780a855193sm369760966b.172.2024.07.12.10.15.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 10:15:47 -0700 (PDT) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, Martin Wilck Subject: [PATCH v2 17/49] libmultipath: rename dm_type()->dm_type_match() and use symbolic values Date: Fri, 12 Jul 2024 19:14:25 +0200 Message-ID: <20240712171458.77611-18-mwilck@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712171458.77611-1-mwilck@suse.com> References: <20240712171458.77611-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Also, make the function static. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/devmapper.c | 37 +++++++++++++++++++------------------ libmultipath/devmapper.h | 1 - 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 4bff62d..a63154f 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -806,43 +806,44 @@ out: return r; } -/* - * returns: - * 1 : match - * 0 : no match - * -1 : empty map, or more than 1 target - */ -int dm_type(const char *name, char *type) +enum { + DM_TYPE_NOMATCH = 0, + DM_TYPE_MATCH, + /* more than 1 target */ + DM_TYPE_MULTI, + /* empty map */ + DM_TYPE_EMPTY, + DM_TYPE_ERR, +}; +static int dm_type_match(const char *name, char *type) { - int r = 0; struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; uint64_t start, length; char *target_type = NULL; char *params; if (!(dmt = libmp_dm_task_create(DM_DEVICE_TABLE))) - return 0; + return DM_TYPE_ERR; if (!dm_task_set_name(dmt, name)) - goto out; + return DM_TYPE_ERR; if (!libmp_dm_task_run(dmt)) { dm_log_error(3, DM_DEVICE_TABLE, dmt); - goto out; + return DM_TYPE_ERR; } /* Fetch 1st target */ if (dm_get_next_target(dmt, NULL, &start, &length, &target_type, ¶ms) != NULL) /* multiple targets */ - r = -1; + return DM_TYPE_MULTI; else if (!target_type) - r = -1; + return DM_TYPE_EMPTY; else if (!strcmp(target_type, type)) - r = 1; - -out: - return r; + return DM_TYPE_MATCH; + else + return DM_TYPE_NOMATCH; } /* @@ -1426,7 +1427,7 @@ do_foreach_partmaps (const char * mapname, /* * if there is only a single "linear" target */ - (dm_type(names->name, TGT_PART) == 1) && + (dm_type_match(names->name, TGT_PART) == DM_TYPE_MATCH) && /* * and the uuid of the target is a partition of the diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h index 19b79c5..ff28575 100644 --- a/libmultipath/devmapper.h +++ b/libmultipath/devmapper.h @@ -46,7 +46,6 @@ int dm_map_present (const char *name); int dm_map_present_by_uuid(const char *uuid); int dm_get_map(const char *name, unsigned long long *size, char **outparams); int dm_get_status(const char *name, char **outstatus); -int dm_type(const char *name, char *type); int dm_is_mpath(const char *name); enum { From patchwork Fri Jul 12 17:14:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13732066 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2FBFA1DFE1 for ; Fri, 12 Jul 2024 17:15:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804552; cv=none; b=Rx64BuOqdhsM43DPCnpt3pkX44wLA+mjCx6DvpYLVOSKbkZ8jRWKohpgv/Jj0tMZsAOFb6P4P8EnoQ6tnW2avSJ/Zg//ia+OIAQqaULxpi62bWOlVo/arLLm3sPSx/t+x3NgVbYs5GbjkcHYJ7U+CyHVUL4qOX2haSvw8TIkMGw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804552; c=relaxed/simple; bh=a3Qomh7r+XQJv8AgJcSa7KEIG/bdVHWIY5lhTvSAKl8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PB5EpvjXG/OsjDIR0mzq9hAS5U8wx2rk3JxVzgqlJcgdNl39Ya6AOD5glbw7ljsLBAyNbcn8ra9xZDxYXfpNqwPUeI4gjMa7HaDFcxDifyVpejX8Yoe3K84C13lES6c03dq4lmKsXqhpNryXDcCGPnY1rBwB5SX0EZBV5a1vD/I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=YabDJqTB; arc=none smtp.client-ip=209.85.218.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="YabDJqTB" Received: by mail-ej1-f46.google.com with SMTP id a640c23a62f3a-a77d85f7fa3so353681366b.0 for ; Fri, 12 Jul 2024 10:15:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1720804548; x=1721409348; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xDRAEgksnrwrHraCLi40lP8JWJgvc8mA85ibNChiY8o=; b=YabDJqTByzXqxiH6R7xNVwVT/KmZdg4mYDAK8HKTe8m5IIeilV8OOjirTvDP7DbQnv AScoAlCjBjeA1RzY4/6ekPPQcaeVCNBdB8uoCoKjxvkTC72Cn6n4/zsFgep0/ACJrcN0 pv43h54R57MLsRYmE8gKngmJNEvwhDCUFFNQB9iiPGJqwzWMj1S6qFMfDI1LYIe5tobg 1U3MvBIChRc/ZwP2N+obESy5Fws/f5F/nyiwC+XhOynlZn1+KQjxaumNdJQc4grGntyJ 8aAaCLKcsjos6QnJ1+e3tthmm6i4QNF2R83ky6rCwRU6Q+QQnZIfz1vdmcLRrmDrbrtU h5lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720804548; x=1721409348; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xDRAEgksnrwrHraCLi40lP8JWJgvc8mA85ibNChiY8o=; b=hVguCq0cJflB1d9ZBO0agvkZ7qCCMuRWsPZ4sDHjC0F8LUsgYv/WK0TVeAvebR6aHT cGEBXFw+QCJUJ3aY4B/zxBNQSt1ixJxg/BKy+8Aa3A4E8J0ZvQYAHtpRV8LrKiQ47ng/ IrjMZktuk/fY9YxhI/SBpKCs7PlK6/8w/kDB5v/0WiO793Igm76PvQndweC31gq0eGNo Iy/Os8MHt1pm/QyYWJONIYNyuqeIJk9IgXP3ctM39UkcIvfGsrtQCVOk5q6Jx9sSJaK3 2roBN4g+F46LKqCFVptEgCJwzAPy4x9w3gaU4/lgHTfyz0qjvEfloYL6WGY8kwjmrDkS +QuA== X-Gm-Message-State: AOJu0Yy+mbEywJ+XEK/1m7Waij/oh0B0DDXkn5yQcHtBdpX8b7KyCI7+ F3MiD+YALhobjDUeKs4eWoiwzXxjylYy6VpALhl51F+dIywK9KEqIL3YbZ02oro= X-Google-Smtp-Source: AGHT+IGC2ESdspVhmMapgBQ/Cl39AsiL2n3GdspjacJahGsK7qIXZHICFk1e9m+N9OJ3uweFr8dnsg== X-Received: by 2002:a17:906:fe4b:b0:a6f:e7a0:91cf with SMTP id a640c23a62f3a-a799cd005ddmr300095866b.24.1720804548414; Fri, 12 Jul 2024 10:15:48 -0700 (PDT) Received: from localhost (p200300de37360a00d7e56139e90929dd.dip0.t-ipconnect.de. [2003:de:3736:a00:d7e5:6139:e909:29dd]) by smtp.gmail.com with UTF8SMTPSA id 4fb4d7f45d1cf-5959bd1d4bdsm4002966a12.88.2024.07.12.10.15.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 10:15:48 -0700 (PDT) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, Martin Wilck Subject: [PATCH v2 18/49] libmultipath: Use symbolic return values for dm_is_mpath() Date: Fri, 12 Jul 2024 19:14:26 +0200 Message-ID: <20240712171458.77611-19-mwilck@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712171458.77611-1-mwilck@suse.com> References: <20240712171458.77611-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmpathpersist/mpath_persist_int.c | 2 +- libmultipath/devmapper.c | 22 ++++++++-------------- libmultipath/devmapper.h | 6 ++++++ multipath/main.c | 4 ++-- multipathd/dmevents.c | 19 +++++++++++++------ multipathd/main.c | 2 +- 6 files changed, 31 insertions(+), 24 deletions(-) diff --git a/libmpathpersist/mpath_persist_int.c b/libmpathpersist/mpath_persist_int.c index 178c2f5..6da0401 100644 --- a/libmpathpersist/mpath_persist_int.c +++ b/libmpathpersist/mpath_persist_int.c @@ -185,7 +185,7 @@ static int mpath_get_map(vector curmp, vector pathvec, int fd, char **palias, condlog(3, "alias = %s", alias); - if (dm_map_present(alias) && dm_is_mpath(alias) != 1){ + if (dm_map_present(alias) && dm_is_mpath(alias) != DM_IS_MPATH_YES) { condlog(3, "%s: not a multipath device.", alias); goto out; } diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index a63154f..3abdc26 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -846,15 +846,9 @@ static int dm_type_match(const char *name, char *type) return DM_TYPE_NOMATCH; } -/* - * returns: - * 1 : is multipath device - * 0 : is not multipath device - * -1 : error - */ int dm_is_mpath(const char *name) { - int r = -1; + int r = DM_IS_MPATH_ERR; struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; struct dm_info info; uint64_t start, length; @@ -876,7 +870,7 @@ int dm_is_mpath(const char *name) if (!dm_task_get_info(dmt, &info)) goto out; - r = 0; + r = DM_IS_MPATH_NO; if (!info.exists) goto out; @@ -895,10 +889,10 @@ int dm_is_mpath(const char *name) if (!target_type || strcmp(target_type, TGT_MPATH) != 0) goto out; - r = 1; + r = DM_IS_MPATH_YES; out: - if (r < 0) - condlog(3, "%s: dm command failed in %s: %s", name, __FUNCTION__, strerror(errno)); + if (r == DM_IS_MPATH_ERR) + condlog(3, "%s: dm command failed in %s: %s", name, __func__, strerror(errno)); return r; } @@ -1039,7 +1033,7 @@ int _dm_flush_map (const char *mapname, int flags, int retries) unsigned long long mapsize; char *params = NULL; - if (dm_is_mpath(mapname) != 1) + if (dm_is_mpath(mapname) != DM_IS_MPATH_YES) return DM_FLUSH_OK; /* nothing to do */ /* if the device currently has no partitions, do not @@ -1086,7 +1080,7 @@ int _dm_flush_map (const char *mapname, int flags, int retries) } condlog(4, "multipath map %s removed", mapname); return DM_FLUSH_OK; - } else if (dm_is_mpath(mapname) != 1) { + } else if (dm_is_mpath(mapname) != DM_IS_MPATH_YES) { condlog(4, "multipath map %s removed externally", mapname); return DM_FLUSH_OK; /* raced. someone else removed it */ @@ -1316,7 +1310,7 @@ int dm_get_maps(vector mp) } do { - if (dm_is_mpath(names->name) != 1) + if (dm_is_mpath(names->name) != DM_IS_MPATH_YES) goto next; mpp = dm_get_multipath(names->name); diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h index ff28575..9438c2d 100644 --- a/libmultipath/devmapper.h +++ b/libmultipath/devmapper.h @@ -46,6 +46,12 @@ int dm_map_present (const char *name); int dm_map_present_by_uuid(const char *uuid); int dm_get_map(const char *name, unsigned long long *size, char **outparams); int dm_get_status(const char *name, char **outstatus); + +enum { + DM_IS_MPATH_NO, + DM_IS_MPATH_YES, + DM_IS_MPATH_ERR, +}; int dm_is_mpath(const char *name); enum { diff --git a/multipath/main.c b/multipath/main.c index ce702e7..c82bc86 100644 --- a/multipath/main.c +++ b/multipath/main.c @@ -247,7 +247,7 @@ static int check_usable_paths(struct config *conf, goto out; } - if (dm_is_mpath(mapname) != 1) { + if (dm_is_mpath(mapname) != DM_IS_MPATH_YES) { condlog(1, "%s is not a multipath map", devpath); goto free; } @@ -1080,7 +1080,7 @@ main (int argc, char *argv[]) goto out; } if (cmd == CMD_FLUSH_ONE) { - if (dm_is_mpath(dev) != 1) { + if (dm_is_mpath(dev) != DM_IS_MPATH_YES) { condlog(0, "%s is not a multipath device", dev); r = RTVL_FAIL; goto out; diff --git a/multipathd/dmevents.c b/multipathd/dmevents.c index 3fbdc55..af1e12e 100644 --- a/multipathd/dmevents.c +++ b/multipathd/dmevents.c @@ -168,9 +168,13 @@ static int dm_get_events(void) while (names->dev) { uint32_t event_nr; - /* Don't delete device if dm_is_mpath() fails without - * checking the device type */ - if (dm_is_mpath(names->name) == 0) + /* + * Don't delete device if dm_is_mpath() fails without + * checking the device type. + * IOW, only delete devices from the event list for which + * we positively know that they aren't multipath devices. + */ + if (dm_is_mpath(names->name) == DM_IS_MPATH_NO) goto next; event_nr = dm_event_nr(names); @@ -206,9 +210,12 @@ int watch_dmevents(char *name) struct dev_event *dev_evt, *old_dev_evt; int i; - /* We know that this is a multipath device, so only fail if - * device-mapper tells us that we're wrong */ - if (dm_is_mpath(name) == 0) { + /* + * We know that this is a multipath device, so only fail if + * device-mapper tells us that we're wrong + * IOW, don't fail for DM generic errors. + */ + if (dm_is_mpath(name) == DM_IS_MPATH_NO) { condlog(0, "%s: not a multipath device. can't watch events", name); return -1; diff --git a/multipathd/main.c b/multipathd/main.c index 58afe14..132bb2e 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -865,7 +865,7 @@ ev_add_map (char * dev, const char * alias, struct vectors * vecs) int reassign_maps; struct config *conf; - if (dm_is_mpath(alias) != 1) { + if (dm_is_mpath(alias) != DM_IS_MPATH_YES) { condlog(4, "%s: not a multipath map", alias); return 0; } From patchwork Fri Jul 12 17:14:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13732067 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 26F31176AA9 for ; Fri, 12 Jul 2024 17:15:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804553; cv=none; b=Oo+hodZvGHksRTCo3uDcWu3g8eb4qsxsqnokn/4z1Pg3W33U14KQUejUe+tDz8cPxtcECX/083+4cq70WMrOChzuWoUjuOyHR6jEhQr7hs6SSIFbwm6jHEtp6eoGfFRKC6wwUWeBwP7wWwrTtfelEe7tnJr2E65nnyAIMf4+AZY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804553; c=relaxed/simple; bh=pQJrRam2VtNQqndmaWopeCpBbITK9h4uRWXitDfKN5Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PfVfbA/lLgC3/6VfR9Rb1W5VCQSSb1hKS3TgFHiHc0Y3iD2jPolnj5x66ztmlLIV0tnPAJ95OWIn42EylbSRxP4vLnyTJIpmsNRRN8KHd6kPecJz4n2I/lp0gFZD9ffSNY+RBwOfOSNy3qYco9GxboWKs2nk0C22MWzvnfVeIgk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=frOgCO4P; arc=none smtp.client-ip=209.85.208.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="frOgCO4P" Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-58ba3e37feeso2757154a12.3 for ; Fri, 12 Jul 2024 10:15:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1720804549; x=1721409349; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=aa6wUSypjo1d3DfgiyFgTVMNcPyvRoSI+1zR7JTlET8=; b=frOgCO4Pe1hr5vFuTLk/EYM8yGOf7cOFZnMf7PiRUyf21mpj3ivyKGx82g7W81b1V0 +qTFZoZrJNkc0KFDkudp1TKsxUY4zFKN66Gn77qJu8bINu1dwYn55OgSYLswNWT2e7z1 xrH7kKdi9DCTwtDz3J3PWlUKeg31Yy2mCEWcp2idMI4qgndJmjM3Zh5qfA8FcnJV6IFp Pdbzz4Va1H/C5zwzD0H0tJiCbqvZMHYAmYCrJucUXiI8XIPHR1MzrfGJyJhp9+KG0x6Z oi607VEPi/Y+zzD5Kw0+dhyTqs5CmCnL7fFkgv6tfHH4Tnr9wTmj2J75jQMr4AN4ttBN YqXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720804549; x=1721409349; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aa6wUSypjo1d3DfgiyFgTVMNcPyvRoSI+1zR7JTlET8=; b=OMgvukDVr36n3/1J5x6U4pbme2WmBWHabUrbuuQaT3befMrTrZFnH78Qoaosmxk5Rg odppWGUlxDUSMJ9sIShP5CieNY5wZ1Qlbz8vY/Nm6wBVz9VVvaxg7cDt8DDkEle2jm8F KvPi+maisztROp4X/4vstD9bHCkL4v/Dq07/bf6lxr3cjd8kB3kMu6OoZ9waH2qRcxsr 2xvcaC6dXN9barfE06n8CMQdVQ4h8Yi9TBCab9guRnC+wXeH+9zpeFQI9ktUBxT/a7wB 01p9It4gh/2X4HLIrgKxnMyno4svxMnqNOqkxGfoOjjJbGzeantuKvv/bEQ4KmFitIP+ BHCw== X-Gm-Message-State: AOJu0YxAdZss1jF2+rcTfnadi+J7F8cefRcoSbfRwHcLEnmgQJ+/WkyY KZ8PKoMvZne/ew9gS5sntJudBei9tJdEjLGbw/h20thy+Q3D4+8NNbaOPXQ9P5E= X-Google-Smtp-Source: AGHT+IFNpuroIaRbOclYFrzYikMhBg/0X/0v2HUhAoJs08RIHPLX0vQvxUuOV1MCNOhay/bhy4jKHw== X-Received: by 2002:a50:ed04:0:b0:58c:34cb:16ca with SMTP id 4fb4d7f45d1cf-594bc7c7e6cmr6377698a12.28.1720804549337; Fri, 12 Jul 2024 10:15:49 -0700 (PDT) Received: from localhost (p200300de37360a00d7e56139e90929dd.dip0.t-ipconnect.de. [2003:de:3736:a00:d7e5:6139:e909:29dd]) by smtp.gmail.com with UTF8SMTPSA id 4fb4d7f45d1cf-594bda30fabsm4763180a12.93.2024.07.12.10.15.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 10:15:49 -0700 (PDT) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, Martin Wilck Subject: [PATCH v2 19/49] libmultipath: add libmp_mapinfo() Date: Fri, 12 Jul 2024 19:14:27 +0200 Message-ID: <20240712171458.77611-20-mwilck@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712171458.77611-1-mwilck@suse.com> References: <20240712171458.77611-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 libmp_mapinfo() is intended as a generic abstraction for retrieving information from the kernel device-mapper driver. It retrieves the information that the caller needs, with a minimal set of DM ioctls, and never more then 2 ioctl calls. libdm's DM_DEVICE_TABLE and DM_DEVICE_STATUS calls map to the kernel's DM_TABLE_STATUS ioctl, with or without the DM_STATUS_TABLE_FLAG set, respectively. DM_TABLE_STATUS always retrieves the basic map status (struct dm_info) and the map UUID and name, too. Note: I'd prefer to use an unnamed struct instead of _u in union libmp_map_identifer. But doing using an unnamed struct and and initializing the union like this in a function argument: func((mapid_t) { .major = major, .minor = minor }) is not part of C99, and not supported in gcc 4.8, which we still support. Likewise, the following syntax for initializing an empty struct: (mapinfo_t) { 0 } is not supported on all architectures we support (notably clang 3.5 under Debian Jessie). Signed-off-by: Martin Wilck --- libmultipath/devmapper.c | 192 +++++++++++++++++++++++++++++- libmultipath/devmapper.h | 70 +++++++++++ libmultipath/libmultipath.version | 3 +- 3 files changed, 263 insertions(+), 2 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 3abdc26..4e6b5b2 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -14,7 +14,6 @@ #include #include #include -#include #include "util.h" #include "vector.h" @@ -604,6 +603,197 @@ has_dm_info(const struct multipath *mpp) return (mpp && mpp->dmi.exists != 0); } +static int libmp_set_map_identifier(int flags, mapid_t id, struct dm_task *dmt) +{ + switch (flags & __DM_MAP_BY_MASK) { + case DM_MAP_BY_UUID: + if (!id.str || !(*id.str)) + return 0; + return dm_task_set_uuid(dmt, id.str); + case DM_MAP_BY_NAME: + if (!id.str || !(*id.str)) + return 0; + return dm_task_set_name(dmt, id.str); + case DM_MAP_BY_DEV: + if (!dm_task_set_major(dmt, id._u.major)) + return 0; + return dm_task_set_minor(dmt, id._u.minor); + case DM_MAP_BY_DEVT: + if (!dm_task_set_major(dmt, major(id.devt))) + return 0; + return dm_task_set_minor(dmt, minor(id.devt)); + default: + condlog(0, "%s: invalid by_id", __func__); + return 0; + } +} + +static int libmp_mapinfo__(int flags, mapid_t id, mapinfo_t info, const char *map_id) +{ + struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; + struct dm_info dmi; + int rc, ioctl_nr; + uint64_t start, length = 0; + char *target_type = NULL, *params = NULL; + const char *name = NULL, *uuid = NULL; + char __attribute__((cleanup(cleanup_charp))) *tmp_target = NULL; + char __attribute__((cleanup(cleanup_charp))) *tmp_status = NULL; + bool tgt_set = false; + + /* + * If both info.target and info.status are set, we need two + * ioctls. Call this function recursively. + * If successful, tmp_target will be non-NULL. + */ + if (info.target && info.status) { + rc = libmp_mapinfo__(flags, id, + (mapinfo_t) { .target = &tmp_target }, + map_id); + if (rc != DMP_OK) + return rc; + tgt_set = true; + } + + /* + * The DM_DEVICE_TABLE and DM_DEVICE_STATUS ioctls both fetch the basic + * information from DM_DEVICE_INFO, too. + * Choose the most lightweight ioctl to fetch all requested info. + */ + if (info.target && !info.status) + ioctl_nr = DM_DEVICE_TABLE; + else if (info.status || info.size || flags & __MAPINFO_TGT_TYPE) + ioctl_nr = DM_DEVICE_STATUS; + else + ioctl_nr = DM_DEVICE_INFO; + + if (!(dmt = libmp_dm_task_create(ioctl_nr))) + return DMP_ERR; + + if (!libmp_set_map_identifier(flags, id, dmt)) { + condlog(2, "%s: failed to set map identifier to %s", __func__, map_id); + return DMP_ERR; + } + + if (!libmp_dm_task_run(dmt)) { + dm_log_error(3, ioctl_nr, dmt); + if (dm_task_get_errno(dmt) == ENXIO) { + condlog(2, "%s: map %s not found", __func__, map_id); + return DMP_NOT_FOUND; + } else + return DMP_ERR; + } + + condlog(4, "%s: DM ioctl %d succeeded for %s", + __func__, ioctl_nr, map_id); + + if (!dm_task_get_info(dmt, &dmi)) { + condlog(2, "%s: dm_task_get_info() failed for %s ", __func__, map_id); + return DMP_ERR; + } else if(!dmi.exists) { + condlog(2, "%s: map %s doesn't exist", __func__, map_id); + return DMP_NOT_FOUND; + } + + if (info.target || info.status || info.size || flags & __MAPINFO_TGT_TYPE) { + if (dm_get_next_target(dmt, NULL, &start, &length, + &target_type, ¶ms) != NULL) { + condlog(2, "%s: map %s has multiple targets", __func__, map_id); + return DMP_NOT_FOUND; + } + if (!params) { + condlog(2, "%s: map %s has no targets", __func__, map_id); + return DMP_NOT_FOUND; + } + if (flags & __MAPINFO_TGT_TYPE) { + const char *tgt_type = flags & MAPINFO_MPATH_ONLY ? TGT_MPATH : TGT_PART; + + if (strcmp(target_type, tgt_type)) { + condlog(3, "%s: target type mismatch: \"%s\" != \"%s\"", + __func__, tgt_type, target_type); + return DMP_NO_MATCH; + } + } + } + + /* + * Check possible error conditions. + * If error is returned, don't touch any output parameters. + */ + if ((info.name && !(name = dm_task_get_name(dmt))) + || (info.uuid && !(uuid = dm_task_get_uuid(dmt))) + || (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\"", __func__, map_id, info.name); + } + if (info.uuid) { + strlcpy(info.uuid, uuid, DM_UUID_LEN); + condlog(4, "%s: %s: uuid: \"%s\"", __func__, map_id, info.uuid); + } + + if (info.size) { + *info.size = length; + condlog(4, "%s: %s: size: %lld", __func__, 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", + __func__, 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) + condlog(4, "%s: %s: target: \"%s\"", __func__, map_id, *info.target); + } + + if (info.status) { + *info.status = steal_ptr(tmp_status); + condlog(4, "%s: %s: status: \"%s\"", __func__, map_id, *info.status); + } + + return DMP_OK; +} + +/* Helper: format a string describing the map for log messages */ +static const char* libmp_map_identifier(int flags, mapid_t id, char buf[BLK_DEV_SIZE]) +{ + switch (flags & __DM_MAP_BY_MASK) { + case DM_MAP_BY_NAME: + case DM_MAP_BY_UUID: + return id.str; + case DM_MAP_BY_DEV: + safe_snprintf(buf, BLK_DEV_SIZE, "%d:%d", id._u.major, id._u.minor); + return buf; + case DM_MAP_BY_DEVT: + safe_snprintf(buf, BLK_DEV_SIZE, "%d:%d", major(id.devt), minor(id.devt)); + return buf; + default: + safe_snprintf(buf, BLK_DEV_SIZE, "*invalid*"); + return buf; + } +} + +int libmp_mapinfo(int flags, mapid_t id, mapinfo_t info) +{ + char idbuf[BLK_DEV_SIZE]; + + return libmp_mapinfo__(flags, id, info, + libmp_map_identifier(flags, id, idbuf)); +} + int dm_get_info(const char *name, struct dm_info *info) { diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h index 9438c2d..725889b 100644 --- a/libmultipath/devmapper.h +++ b/libmultipath/devmapper.h @@ -1,5 +1,6 @@ #ifndef _DEVMAPPER_H #define _DEVMAPPER_H +#include #include "autoconfig.h" #include "structs.h" @@ -31,8 +32,77 @@ enum { DMP_ERR, DMP_OK, DMP_NOT_FOUND, + DMP_NO_MATCH, }; +/** + * enum mapinfo_flags: input flags for libmp_mapinfo() + */ +enum __mapinfo_flags { + /** DM_MAP_BY_NAME: identify map by device-mapper name from @name */ + DM_MAP_BY_NAME = 0, + /** DM_MAP_BY_UUID: identify map by device-mapper UUID from @uuid */ + DM_MAP_BY_UUID, + /** DM_MAP_BY_DEV: identify map by major/minor number from @dmi */ + DM_MAP_BY_DEV, + /** DM_MAP_BY_DEVT: identify map by a dev_t */ + DM_MAP_BY_DEVT, + __DM_MAP_BY_MASK = (1 << 3) - 1, + /* Fail if target type is not multipath */ + MAPINFO_MPATH_ONLY = (1 << 3), + /* Fail if target type is not "partition" (linear) */ + MAPINFO_PART_ONLY = (1 << 4), + __MAPINFO_TGT_TYPE = (MAPINFO_MPATH_ONLY | MAPINFO_PART_ONLY), +}; + +typedef union libmp_map_identifier { + const char *str; + struct { + int major; + int minor; + } _u; + dev_t devt; +} mapid_t; + +typedef struct libmp_map_info { + /** @name: name of the map. + * If non-NULL, it must point to an array of WWID_SIZE bytes + */ + char *name; + /** @uuid: UUID of the map. + * If non-NULL it must point to an array of DM_UUID_LEN bytes + */ + char *uuid; + /** @dmi: Basic info, must point to a valid dm_info buffer if non-NULL */ + struct dm_info *dmi; + /** @target: target params, *@target will be allocated if @target is non-NULL*/ + char **target; + /** @size: target size. Will be ignored if @target is NULL */ + unsigned long long *size; + /** @status: target status, *@status will be allocated if @status is non-NULL */ + char **status; +} mapinfo_t; + +/** + * libmp_mapinfo(): obtain information about a map from the kernel + * @param flags: see __mapinfo_flags above. + * Exactly one of DM_MAP_BY_NAME, DM_MAP_BY_UUID, and DM_MAP_BY_DEV must be set. + * @param id: string or major/minor to identify the map to query + * @param info: output parameters, see above. Non-NULL elements will be filled in. + * @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_ERR if some other error occurred. + * + * 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. + * For target / status / size information, the map's table should contain + * only one target (usually multipath or linear). + */ +int libmp_mapinfo(int flags, mapid_t id, mapinfo_t info); + int dm_prereq(unsigned int *v); void skip_libmp_dm_init(void); void libmp_dm_exit(void); diff --git a/libmultipath/libmultipath.version b/libmultipath/libmultipath.version index f58cb1d..48c2b67 100644 --- a/libmultipath/libmultipath.version +++ b/libmultipath/libmultipath.version @@ -43,7 +43,7 @@ LIBMPATHCOMMON_1.0.0 { put_multipath_config; }; -LIBMULTIPATH_24.0.0 { +LIBMULTIPATH_25.0.0 { global: /* symbols referenced by multipath and multipathd */ add_foreign; @@ -134,6 +134,7 @@ global: libmp_get_version; libmp_get_multipath_config; libmp_dm_task_run; + libmp_mapinfo; libmp_put_multipath_config; libmp_udev_set_sync_support; libmultipath_exit; From patchwork Fri Jul 12 17:14:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13732068 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 609AA176AAD for ; Fri, 12 Jul 2024 17:15:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804555; cv=none; b=GHfjvcrhWhD/imPKUlhUm8WVqmQbavw50WHWt14dB9IchiLemVtL4Y57cEYlFKu8zB2lS8DqIc/CCVuqrAQCGeiHjl0bdR1dvATL4rEYwzh8J7o9X7WjVKVzXd0ThI1/5CzuqjIgMdyQpYsVWRyNoUnD3Gbrs3dUl876PPR+K58= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804555; c=relaxed/simple; bh=+SETk7/NYbUTUVzSVuSJXDkEI3nxRFYPazbLUKUyFc8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mVF0LzYpLeud/udiyLZkOKaLHHCIt3kL+v2Q+8PzTobvL+QUSCnY2t6F2MwXGaqIdRrV5muiuXjACPYuUq7cPvxTkVBT9bxd9Dg4BSnZAyvG4NxopAI3wAJCPm10GAfXXQK9o8S/6Ho58UQaSLHdESsAg5WweDPd0xjEbgMfo50= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=WkVEPQs7; arc=none smtp.client-ip=209.85.208.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="WkVEPQs7" Received: by mail-ed1-f42.google.com with SMTP id 4fb4d7f45d1cf-59589a9be92so3190525a12.2 for ; Fri, 12 Jul 2024 10:15:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1720804551; x=1721409351; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=B0g7S5N57ybsPOWQVQANTF292ofgfH7Tv5VKS9orJXM=; b=WkVEPQs7AKsuc86OZ5uLVS+0EkyXHAOOKVFbI5Xa/XKGTFIdQUGmeEnRBq2mB/9j+h jjCfV4dYbjTOPvwnja7thPFl8P7T2B95raDOLTfT2/1DcV44aFq35Ln+huLwPjSFwheT WBoukppDs91ixe7OmCmMk0e2FGMo7McCBnd8mcku5zbfOowNX5zUNNk3I2ZsgYt5Bt53 McTzHG3dGnQomCbtcGZNoxsXA8q27BcLpgeU+gPPtvT0dV+l6571jev9m3rqZfYwIlnP S/FEIYUdRHAd03BZfRY8EkvI+6M2KEIPB/gyYoICSO9Mah2wvnyAX7XnUHKifn8SffmM zXXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720804551; x=1721409351; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=B0g7S5N57ybsPOWQVQANTF292ofgfH7Tv5VKS9orJXM=; b=G0JrGfxTZZlmupv8455K9Rf99yOVLzuH3jOKSKfk5U65BLjb81+9JVu+C2AttcjybG +qHj/n67/PBpNmrFzRX2sDcdWQCx6tma1u5+MZ0C9ml7uKjCs1PEjzVaDYfAzCJG+ZHF 8Yfvw4ia1WLhWs9H1wxNtLNSZxbANz9l/yTkqQy3KPxhtffbbhWBsKEIKFrZWBr/gyWM xVqmC6pSnrD7Mt+R6dXQgz7zebfCAHrj+6EE8YXZnH999pKVEj8jMzNVPHPpGrKr5igf L0afTB/YQOvSDkynkoRmXjgpvjglZq1Ljm9kxXq6qqKoh3ovTEfUwvcyBPbVMgHQsqy7 aCbA== X-Gm-Message-State: AOJu0YyvHVEwbYWywDzD2niyTGyeGbPhFHcMJqw+GA2KNkkvSbtG78Au 6rgteW+ClofSmsKCmqR5CQgtHaSSilMo6G4NYGOwSLSkaQbXPUISaDfkR1Lgzek= X-Google-Smtp-Source: AGHT+IFmU3domEu02vC1iGcKaxAAOCVwZ/jI1XgwbN5wEXpWGRWYsxUk1Z9n6q4PAE+ZqZFDg5OlPg== X-Received: by 2002:a05:6402:210f:b0:58b:6096:5554 with SMTP id 4fb4d7f45d1cf-594bcba7e40mr10101129a12.37.1720804550406; Fri, 12 Jul 2024 10:15:50 -0700 (PDT) Received: from localhost (p200300de37360a00d7e56139e90929dd.dip0.t-ipconnect.de. [2003:de:3736:a00:d7e5:6139:e909:29dd]) by smtp.gmail.com with UTF8SMTPSA id 4fb4d7f45d1cf-594bb9604d4sm4727995a12.20.2024.07.12.10.15.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 10:15:50 -0700 (PDT) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, Martin Wilck Subject: [PATCH v2 20/49] libmultipath tests: add tests for libmp_mapinfo() Date: Fri, 12 Jul 2024 19:14:28 +0200 Message-ID: <20240712171458.77611-21-mwilck@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712171458.77611-1-mwilck@suse.com> References: <20240712171458.77611-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Unfortunately, we need several ugly compatibility macros again in order to make these tests work with the entire set of compilers and libraries supported by multipath-tools. Details are found in comments in the code. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/devmapper.h | 1 + tests/Makefile | 3 +- tests/mapinfo.c | 1175 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 1178 insertions(+), 1 deletion(-) create mode 100644 tests/mapinfo.c diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h index 725889b..62f50de 100644 --- a/libmultipath/devmapper.h +++ b/libmultipath/devmapper.h @@ -1,5 +1,6 @@ #ifndef _DEVMAPPER_H #define _DEVMAPPER_H +#include #include #include "autoconfig.h" #include "structs.h" diff --git a/tests/Makefile b/tests/Makefile index 8afa8c6..55fbf0f 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -9,7 +9,7 @@ CFLAGS += $(BIN_CFLAGS) -Wno-unused-parameter $(W_MISSING_INITIALIZERS) LIBDEPS += -L. -L $(mpathutildir) -L$(mpathcmddir) -lmultipath -lmpathutil -lmpathcmd -lcmocka TESTS := uevent parser util dmevents hwtable blacklist unaligned vpd pgpolicy \ - alias directio valid devt mpathvalid strbuf sysfs features cli + alias directio valid devt mpathvalid strbuf sysfs features cli mapinfo HELPERS := test-lib.o test-log.o .PRECIOUS: $(TESTS:%=%-test) @@ -68,6 +68,7 @@ sysfs-test_OBJDEPS := $(multipathdir)/sysfs.o $(mpathutildir)/util.o sysfs-test_LIBDEPS := -ludev -lpthread -ldl features-test_LIBDEPS := -ludev -lpthread cli-test_OBJDEPS := $(daemondir)/cli.o +mapinfo-test_LIBDEPS = -lpthread -ldevmapper %.o: %.c @echo building $@ because of $? diff --git a/tests/mapinfo.c b/tests/mapinfo.c new file mode 100644 index 0000000..f3a8440 --- /dev/null +++ b/tests/mapinfo.c @@ -0,0 +1,1175 @@ +/* + * Copyright (c) 2024 Martin Wilck, SUSE + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +/* + * glibc <= 2.19 (Ubuntu Trusty, Debian Jessie) uses macros to inline strdup(), + * which makes our strdup wrapper fail. + */ +#define _GNU_SOURCE 1 +#include +#include +#ifndef __GLIBC_PREREQ +#define __GLIBC_PREREQ(x, y) 0 +#endif +#if defined(__GLIBC__) && !(__GLIBC_PREREQ(2, 20)) +#define __NO_STRING_INLINES 1 +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "util.h" +#include "devmapper.h" +#include "globals.c" +/* + * We can't just use mapinfo-test_OBJDEPS because + */ +#include "../libmultipath/devmapper.c" + +static const struct dm_info __attribute__((unused)) MPATH_DMI_01 = { + .exists = 1, + .live_table = 1, + .open_count = 1, + .target_count = 1, + .major = 254, + .minor = 123, +}; + +static const char MPATH_NAME_01[] = "mpathx"; +static const char MPATH_UUID_01[] = "mpath-3600a098038302d414b2b4d4453474f62"; +static const char MPATH_TARGET_01[] = + "2 pg_init_retries 50 1 alua 2 1 " + "service-time 0 3 2 65:32 1 1 67:64 1 1 69:96 1 1 " + "service-time 0 3 2 8:16 1 1 66:48 1 1 68:80 1 1 "; +static const char MPATH_STATUS_01[] = + "2 0 1 0 2 1 " + "A 0 3 2 65:32 A 0 0 1 67:64 A 0 0 1 69:96 A 0 0 1 " + "E 0 3 2 8:16 A 0 0 1 66:48 A 0 0 1 68:80 A 0 0 1 "; + +char *__real_strdup(const char *str); +char *__wrap_strdup(const char *str) +{ + if (mock_type(int)) + return __real_strdup(str); + return NULL; +} + +void __wrap_dm_task_destroy(struct dm_task *t) +{ +} + +struct dm_task *__wrap_dm_task_create(int task) +{ + check_expected(task); + return mock_ptr_type(void *); +} + +int __wrap_dm_task_run(struct dm_task *t) +{ + return mock_type(int); +} + +/* + * Hack for older versions of libdevmapper, where dm_task_get_errno() + * is not available. + */ +#ifndef LIBDM_API_GET_ERRNO +#define WILL_RETURN_GET_ERRNO(y) do { errno = y; } while (0) +#else +int __wrap_dm_task_get_errno(struct dm_task *t) +{ + return mock_type(int); +} +#define WILL_RETURN_GET_ERRNO(y) will_return(__wrap_dm_task_get_errno, y) +#endif + +int __wrap_dm_task_set_name(struct dm_task *t, const char *name) +{ + check_expected(name); + return mock_type(int); +} + +int __wrap_dm_task_set_uuid(struct dm_task *t, const char *uuid) +{ + check_expected(uuid); + return mock_type(int); +} + +int __wrap_dm_task_set_major(struct dm_task *t, int val) +{ + check_expected(val); + return mock_type(int); +} + +int __wrap_dm_task_set_minor(struct dm_task *t, int val) +{ + check_expected(val); + return mock_type(int); +} + +/* between LVM2 2.02.110 and 2.02.112, dm_task_get_info was a macro */ +#ifdef dm_task_get_info +#define WRAP_DM_TASK_GET_INFO(x) \ + will_return(__wrap_dm_task_get_info_with_deferred_remove, x) +int __wrap_dm_task_get_info_with_deferred_remove(struct dm_task *t, struct dm_info *dmi) +#else +#define WRAP_DM_TASK_GET_INFO(x) \ + will_return(__wrap_dm_task_get_info, x) +int __wrap_dm_task_get_info(struct dm_task *t, struct dm_info *dmi) +#endif +{ + int rc = mock_type(int); + + assert_non_null(dmi); + if (rc) { + struct dm_info *info = mock_ptr_type(struct dm_info *); + + memcpy(dmi, info, sizeof(*dmi)); + } + return rc; +} + +void * __wrap_dm_get_next_target(struct dm_task *dmt, void *next, + uint64_t *start, uint64_t *length, + char **target_type, char **params) +{ + *start = 0; + *length = mock_type(uint64_t); + *target_type = mock_ptr_type(char *); + *params = mock_ptr_type(char *); + return mock_ptr_type(void *); +} + +static void mock_dm_get_next_target(uint64_t len, const char *target_type, + const char *params, void *next) +{ + will_return(__wrap_dm_get_next_target, len); + will_return(__wrap_dm_get_next_target, target_type); + will_return(__wrap_dm_get_next_target, params); + will_return(__wrap_dm_get_next_target, next); +} + +const char *__wrap_dm_task_get_name(struct dm_task *t) +{ + return mock_ptr_type(const char *); +} + +const char *__wrap_dm_task_get_uuid(struct dm_task *t) +{ + return mock_ptr_type(const char *); +} + +static void mock_mapinfo_name_1(int ioctl_nr, int create_rc, const char *name, + int name_rc, int run_rc, int err) +{ + expect_value(__wrap_dm_task_create, task, ioctl_nr); + will_return(__wrap_dm_task_create, create_rc); + if (create_rc == 0) + return; + expect_value(__wrap_dm_task_set_name, name, name); + will_return(__wrap_dm_task_set_name, name_rc); + if (name_rc == 0) + return; + will_return(__wrap_dm_task_run, run_rc); + if (run_rc == 0) { + WILL_RETURN_GET_ERRNO(err); + /* for dm_log_error() */ + WILL_RETURN_GET_ERRNO(err); + } +} + +static void test_mapinfo_bad_task_create_01(void **state) +{ + int rc; + + mock_mapinfo_name_1(DM_DEVICE_INFO, 0, NULL, 0, 0, 0); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_ERR); +} + +static void test_mapinfo_bad_mapid(void **state) +{ + int rc; + + /* can't use mock_mapinfo_name() here because of invalid id type */ + expect_value(__wrap_dm_task_create, task, DM_DEVICE_INFO); + will_return(__wrap_dm_task_create, 1); + rc = libmp_mapinfo(DM_MAP_BY_NAME + 100, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_ERR); +} + +static void test_mapinfo_bad_set_name(void **state) +{ + int rc; + + mock_mapinfo_name_1(DM_DEVICE_INFO, 1, "foo", 0, 0, 0); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_ERR); +} + +static void test_mapinfo_bad_task_run_01(void **state) +{ + int rc; + + mock_mapinfo_name_1(DM_DEVICE_INFO, 1, "foo", 1, 0, EINVAL); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_ERR); +} + +static void test_mapinfo_bad_task_run_02(void **state) +{ + int rc; + + mock_mapinfo_name_1(DM_DEVICE_INFO, 1, "foo", 1, 0, ENXIO); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_NOT_FOUND); +} + +/* libmp_mapinfo must choose DM_DEVICE_STATUS */ +static void test_mapinfo_bad_task_run_03(void **state) +{ + int rc; + + mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 0, EINVAL); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_ERR); +} + +static void test_mapinfo_bad_task_run_04(void **state) +{ + int rc; + + mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 0, ENXIO); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_NOT_FOUND); +} + +/* If target is set, libmp_mapinfo must choose DM_DEVICE_TABLE */ +static void test_mapinfo_bad_task_run_05(void **state) +{ + int rc; + char *params = NULL; + + mock_mapinfo_name_1(DM_DEVICE_TABLE, 1, "foo", 1, 0, EINVAL); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .target = ¶ms }); + assert_int_equal(rc, DMP_ERR); + assert_ptr_equal(params, NULL); +} + +static void test_mapinfo_bad_task_run_06(void **state) +{ + int rc; + char *params = NULL; + + mock_mapinfo_name_1(DM_DEVICE_TABLE, 1, "foo", 1, 0, ENXIO); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .target = ¶ms }); + assert_int_equal(rc, DMP_NOT_FOUND); + assert_ptr_equal(params, NULL); +} + +/* If status is set, libmp_mapinfo must choose DM_DEVICE_STATUS */ +static void test_mapinfo_bad_task_run_07(void **state) +{ + int rc; + char *params = NULL; + + mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 0, EINVAL); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .status = ¶ms }); + assert_int_equal(rc, DMP_ERR); + assert_ptr_equal(params, NULL); +} + +static void test_mapinfo_bad_task_run_08(void **state) +{ + int rc; + char *params = NULL; + + mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 0, ENXIO); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .status = ¶ms }); + assert_int_equal(rc, DMP_NOT_FOUND); + assert_ptr_equal(params, NULL); +} + +static void test_mapinfo_bad_task_run_09(void **state) +{ + int rc; + char *params = NULL, *status = NULL; + + mock_mapinfo_name_1(DM_DEVICE_TABLE, 1, "foo", 1, 0, EINVAL); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .target = ¶ms, .status = &status }); + assert_int_equal(rc, DMP_ERR); + assert_ptr_equal(params, NULL); + assert_ptr_equal(status, NULL); +} + +static void test_mapinfo_bad_task_run_10(void **state) +{ + int rc; + char *params = NULL, *status = NULL; + + mock_mapinfo_name_1(DM_DEVICE_TABLE, 1, "foo", 1, 0, ENXIO); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .target = ¶ms, .status = &status }); + assert_int_equal(rc, DMP_NOT_FOUND); + assert_ptr_equal(params, NULL); + assert_ptr_equal(status, NULL); +} + +static void test_mapinfo_bad_get_info_01(void **state) +{ + int rc; + + mock_mapinfo_name_1(DM_DEVICE_INFO, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(0); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_ERR); +} + +static void test_mapinfo_bad_get_info_02(void **state) +{ + int rc; + 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, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_NOT_FOUND); +} + +static void test_mapinfo_bad_get_info_03(void **state) +{ + int rc; + + mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 1, 0); + WRAP_DM_TASK_GET_INFO(0); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_PART_ONLY, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_ERR); +} + +static void test_mapinfo_bad_get_info_04(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); + WRAP_DM_TASK_GET_INFO(&dmi); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_PART_ONLY, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_NOT_FOUND); +} + +static void test_mapinfo_good_exists(void **state) +{ + int rc; + + 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); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_OK); +} + +static void test_mapinfo_bad_set_uuid(void **state) +{ + int rc; + + expect_value(__wrap_dm_task_create, task, DM_DEVICE_INFO); + will_return(__wrap_dm_task_create, 1); + expect_value(__wrap_dm_task_set_uuid, uuid, "foo"); + will_return(__wrap_dm_task_set_uuid, 0); + rc = libmp_mapinfo(DM_MAP_BY_UUID, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_ERR); +} + +static void test_mapinfo_bad_set_dev_01(void **state) +{ + int rc; + + expect_value(__wrap_dm_task_create, task, DM_DEVICE_INFO); + will_return(__wrap_dm_task_create, 1); + expect_value(__wrap_dm_task_set_major, val, 254); + will_return(__wrap_dm_task_set_major, 0); + rc = libmp_mapinfo(DM_MAP_BY_DEV, + (mapid_t) { ._u = { 254, 123 } }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_ERR); +} + +static void test_mapinfo_bad_set_dev_02(void **state) +{ + int rc; + + expect_value(__wrap_dm_task_create, task, DM_DEVICE_INFO); + will_return(__wrap_dm_task_create, 1); + expect_value(__wrap_dm_task_set_major, val, 254); + will_return(__wrap_dm_task_set_major, 1); + expect_value(__wrap_dm_task_set_minor, val, 123); + will_return(__wrap_dm_task_set_minor, 0); + rc = libmp_mapinfo(DM_MAP_BY_DEV, + (mapid_t) { ._u = { 254, 123 } }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_ERR); +} + +static void test_mapinfo_bad_set_dev_03(void **state) +{ + int rc; + dev_t devt = makedev(254, 123); + + expect_value(__wrap_dm_task_create, task, DM_DEVICE_INFO); + will_return(__wrap_dm_task_create, 1); + expect_value(__wrap_dm_task_set_major, val, 254); + will_return(__wrap_dm_task_set_major, 0); + rc = libmp_mapinfo(DM_MAP_BY_DEVT, + (mapid_t) { .devt = devt }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_ERR); +} + +static void test_mapinfo_bad_set_dev_04(void **state) +{ + int rc; + dev_t devt = makedev(254, 123); + + expect_value(__wrap_dm_task_create, task, DM_DEVICE_INFO); + will_return(__wrap_dm_task_create, 1); + expect_value(__wrap_dm_task_set_major, val, 254); + will_return(__wrap_dm_task_set_major, 1); + expect_value(__wrap_dm_task_set_minor, val, 123); + will_return(__wrap_dm_task_set_minor, 0); + rc = libmp_mapinfo(DM_MAP_BY_DEVT, + (mapid_t) { .devt = devt }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_ERR); +} + +static void test_mapinfo_good_info(void **state) +{ + int rc; + struct dm_info dmi; + + 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); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .dmi = &dmi }); + assert_int_equal(rc, DMP_OK); + assert_memory_equal(&dmi, &MPATH_DMI_01, sizeof(dmi)); +} + +static void test_mapinfo_good_by_uuid_info(void **state) +{ + int rc; + struct dm_info dmi; + + expect_value(__wrap_dm_task_create, task, DM_DEVICE_INFO); + will_return(__wrap_dm_task_create, 1); + expect_value(__wrap_dm_task_set_uuid, uuid, "foo"); + 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_01); + rc = libmp_mapinfo(DM_MAP_BY_UUID, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .dmi = &dmi }); + assert_int_equal(rc, DMP_OK); + assert_memory_equal(&dmi, &MPATH_DMI_01, sizeof(dmi)); +} + +static void test_mapinfo_good_by_dev_info(void **state) +{ + int rc; + struct dm_info dmi; + + expect_value(__wrap_dm_task_create, task, DM_DEVICE_INFO); + will_return(__wrap_dm_task_create, 1); + expect_value(__wrap_dm_task_set_major, val, 254); + will_return(__wrap_dm_task_set_major, 1); + expect_value(__wrap_dm_task_set_minor, val, 123); + will_return(__wrap_dm_task_set_minor, 1); + will_return(__wrap_dm_task_run, 1); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + rc = libmp_mapinfo(DM_MAP_BY_DEV, + (mapid_t) { ._u = { 254, 123 } }, + (mapinfo_t) { .dmi = &dmi }); + assert_int_equal(rc, DMP_OK); + assert_memory_equal(&dmi, &MPATH_DMI_01, sizeof(dmi)); +} + +static void test_mapinfo_good_by_devt_info(void **state) +{ + dev_t devt = makedev(254, 123); + int rc; + struct dm_info dmi; + + expect_value(__wrap_dm_task_create, task, DM_DEVICE_INFO); + will_return(__wrap_dm_task_create, 1); + expect_value(__wrap_dm_task_set_major, val, 254); + will_return(__wrap_dm_task_set_major, 1); + expect_value(__wrap_dm_task_set_minor, val, 123); + will_return(__wrap_dm_task_set_minor, 1); + will_return(__wrap_dm_task_run, 1); + WRAP_DM_TASK_GET_INFO(1); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + rc = libmp_mapinfo(DM_MAP_BY_DEVT, + (mapid_t) { .devt = devt }, + (mapinfo_t) { .dmi = &dmi }); + assert_int_equal(rc, DMP_OK); + assert_memory_equal(&dmi, &MPATH_DMI_01, sizeof(dmi)); +} + +static void test_mapinfo_bad_name(void **state) +{ + int rc; + char name[WWID_SIZE] = { 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, NULL); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = name }); + assert_int_equal(rc, DMP_ERR); +} + +static void test_mapinfo_good_name(void **state) +{ + int rc; + char name[WWID_SIZE] = { 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); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = name }); + assert_int_equal(rc, DMP_OK); + assert_true(!strcmp(name, MPATH_NAME_01)); +} + +static void test_mapinfo_bad_uuid(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, NULL); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .uuid = uuid }); + assert_int_equal(rc, DMP_ERR); +} + +static void test_mapinfo_good_uuid(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, MPATH_UUID_01); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .uuid = uuid }); + assert_int_equal(rc, DMP_OK); + assert_true(!strcmp(uuid, MPATH_UUID_01)); +} + +/* If size is set, libmp_mapinfo needs to do a DM_DEVICE_STATUS ioctl */ +static void test_mapinfo_good_size(void **state) +{ + int rc; + unsigned long long size; + + 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); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .size = &size }); + assert_int_equal(rc, DMP_OK); + assert_int_equal(size, 12345); +} + +static void test_mapinfo_bad_next_target_01(void **state) +{ + int rc; + unsigned long long size; + + 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); + /* multiple targets */ + mock_dm_get_next_target(12345, NULL, MPATH_STATUS_01, (void *)1); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .size = &size }); + assert_int_equal(rc, DMP_NOT_FOUND); +} + +static void test_mapinfo_bad_next_target_02(void **state) +{ + int rc; + unsigned long long size; + + 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); + /* no targets */ + mock_dm_get_next_target(12345, 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); +} + +/* libmp_mapinfo needs to do a DM_DEVICE_STATUS ioctl */ +static void test_mapinfo_bad_target_type_01(void **state) +{ + int rc; + + 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, "linear", MPATH_STATUS_01, NULL); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_NO_MATCH); +} + +static void test_mapinfo_bad_target_type_02(void **state) +{ + int rc; + + 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, TGT_MPATH, MPATH_STATUS_01, NULL); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_PART_ONLY, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_NO_MATCH); +} + +static void test_mapinfo_bad_target_type_03(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_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, TGT_PART, MPATH_STATUS_01, NULL); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY, + (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); +} + +static void test_mapinfo_bad_target_type_04(void **state) +{ + int rc; + char __attribute__((cleanup(cleanup_charp))) *status = NULL; + + 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, TGT_MPATH, MPATH_STATUS_01, NULL); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_PART_ONLY, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .status = &status }); + assert_int_equal(rc, DMP_NO_MATCH); + assert_null(status); +} + +static void test_mapinfo_bad_target_type_05(void **state) +{ + int rc; + char __attribute__((cleanup(cleanup_charp))) *target = NULL; + + 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, TGT_MPATH, MPATH_STATUS_01, NULL); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_PART_ONLY, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .target = &target }); + assert_int_equal(rc, DMP_NO_MATCH); + assert_null(target); +} + +static void test_mapinfo_good_target_type_01(void **state) +{ + int rc; + + 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, TGT_MPATH, MPATH_STATUS_01, NULL); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_OK); +} + +static void test_mapinfo_good_target_type_02(void **state) +{ + int rc; + + 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, TGT_PART, MPATH_STATUS_01, NULL); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_PART_ONLY, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_OK); +} + +static void test_mapinfo_good_target_type_03(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); + WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01); + mock_dm_get_next_target(12345, TGT_MPATH, MPATH_STATUS_01, NULL); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .dmi = &dmi }); + assert_int_equal(rc, DMP_OK); + assert_memory_equal(&dmi, &MPATH_DMI_01, sizeof(dmi)); +} + +/* test for returning multiple parameters */ +static void test_mapinfo_good_target_type_04(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_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, TGT_MPATH, MPATH_STATUS_01, NULL); + will_return(__wrap_dm_task_get_name, MPATH_NAME_01); + will_return(__wrap_dm_task_get_uuid, MPATH_UUID_01); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .dmi = &dmi, .name = name, .uuid = uuid }); + assert_int_equal(rc, DMP_OK); + 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_good_status_01(void **state) +{ + int rc; + char __attribute__((cleanup(cleanup_charp))) *status = NULL; + + 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, TGT_MPATH, MPATH_STATUS_01, NULL); + will_return(__wrap_strdup, 1); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .status = &status }); + assert_int_equal(rc, DMP_OK); + assert_non_null(status); + assert_true(!strcmp(status, MPATH_STATUS_01)); +} + +static void test_mapinfo_bad_strdup_01(void **state) +{ + int rc; + char __attribute__((cleanup(cleanup_charp))) *status = NULL; + char name[WWID_SIZE] = { 0 }; + 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); + mock_dm_get_next_target(12345, TGT_MPATH, MPATH_STATUS_01, NULL); + will_return(__wrap_dm_task_get_name, MPATH_NAME_01); + will_return(__wrap_dm_task_get_uuid, MPATH_UUID_01); + will_return(__wrap_strdup, 0); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (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); + +} + +static void test_mapinfo_bad_get_name_01(void **state) +{ + int rc; + char __attribute__((cleanup(cleanup_charp))) *status = NULL; + char name[WWID_SIZE] = { 0 }; + 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); + mock_dm_get_next_target(12345, TGT_MPATH, MPATH_STATUS_01, NULL); + will_return(__wrap_dm_task_get_name, NULL); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (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); + +} + +static void test_mapinfo_bad_get_uuid_01(void **state) +{ + int rc; + char __attribute__((cleanup(cleanup_charp))) *status = NULL; + char name[WWID_SIZE] = { 0 }; + 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); + mock_dm_get_next_target(12345, TGT_MPATH, MPATH_STATUS_01, NULL); + will_return(__wrap_dm_task_get_name, MPATH_NAME_01); + will_return(__wrap_dm_task_get_uuid, NULL); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (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); + +} + +static void test_mapinfo_bad_task_run_11(void **state) +{ + int rc; + char *params = NULL, *status = NULL; + + 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); + will_return(__wrap_strdup, 1); + /* error in 2nd dm_task_run */ + mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 0, EINVAL); + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .target = ¶ms, .status = &status }); + assert_int_equal(rc, DMP_ERR); + assert_ptr_equal(params, NULL); + assert_ptr_equal(status, NULL); +} + +static void test_mapinfo_bad_get_name_02(void **state) +{ + int rc; + char *target = NULL, *status = NULL; + char name[WWID_SIZE] = { 0 }; + char uuid[DM_UUID_LEN] = { 0 }; + struct dm_info dmi = { .suspended = 0 }; + + 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, TGT_MPATH, MPATH_TARGET_01, NULL); + will_return(__wrap_strdup, 1); + /* 2nd ioctl */ + 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, TGT_MPATH, MPATH_STATUS_01, NULL); + will_return(__wrap_dm_task_get_name, NULL); + + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { + .target = &target, .status = &status, + .uuid = uuid, .name = name, .dmi = &dmi }); + 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_get_uuid_02(void **state) +{ + int rc; + char *target = NULL, *status = NULL; + char name[WWID_SIZE] = { 0 }; + char uuid[DM_UUID_LEN] = { 0 }; + struct dm_info dmi = { .suspended = 0 }; + + 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, TGT_MPATH, MPATH_TARGET_01, NULL); + will_return(__wrap_strdup, 1); + /* 2nd ioctl */ + 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, TGT_MPATH, MPATH_STATUS_01, NULL); + will_return(__wrap_dm_task_get_name, MPATH_NAME_01); + will_return(__wrap_dm_task_get_uuid, NULL); + + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { + .target = &target, .status = &status, + .uuid = uuid, .name = name, .dmi = &dmi }); + 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_02(void **state) +{ + int rc; + char *target = NULL, *status = NULL; + char name[WWID_SIZE] = { 0 }; + char uuid[DM_UUID_LEN] = { 0 }; + struct dm_info dmi = { .suspended = 0 }; + + 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, TGT_MPATH, MPATH_TARGET_01, NULL); + will_return(__wrap_strdup, 1); + /* 2nd ioctl */ + 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, TGT_MPATH, MPATH_STATUS_01, NULL); + will_return(__wrap_dm_task_get_name, MPATH_NAME_01); + will_return(__wrap_dm_task_get_uuid, MPATH_UUID_01); + will_return(__wrap_strdup, 0); + + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { + .target = &target, .status = &status, + .uuid = uuid, .name = name, .dmi = &dmi }); + 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) +{ + int rc; + char *target = NULL, *status = NULL; + char name[WWID_SIZE] = { 0 }; + char uuid[DM_UUID_LEN] = { 0 }; + struct dm_info dmi = { .suspended = 0 }; + + 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, TGT_MPATH, MPATH_TARGET_01, NULL); + will_return(__wrap_strdup, 0); + /* No 2nd ioctl, as there was an error in the 1st */ + + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { + .target = &target, .status = &status, + .uuid = uuid, .name = name, .dmi = &dmi }); + 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_good_all_01(void **state) +{ + int rc; + char __attribute__((cleanup(cleanup_charp))) *target = NULL; + char __attribute__((cleanup(cleanup_charp))) *status = NULL; + char name[WWID_SIZE] = { 0 }; + char uuid[DM_UUID_LEN] = { 0 }; + struct dm_info dmi = { .suspended = 0 }; + unsigned long long size; + + 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, TGT_MPATH, MPATH_TARGET_01, NULL); + will_return(__wrap_strdup, 1); + /* 2nd ioctl */ + 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, TGT_MPATH, MPATH_STATUS_01, NULL); + will_return(__wrap_dm_task_get_name, MPATH_NAME_01); + will_return(__wrap_dm_task_get_uuid, MPATH_UUID_01); + will_return(__wrap_strdup, 1); + + rc = libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { + .target = &target, .status = &status, + .uuid = uuid, .name = name, + .dmi = &dmi, .size = &size }); + assert_int_equal(rc, DMP_OK); + assert_non_null(status); + assert_non_null(target); + assert_int_equal(size, 12345); + assert_memory_equal(&dmi, &MPATH_DMI_01, sizeof(dmi)); + assert_true(!strcmp(target, MPATH_TARGET_01)); + assert_true(!strcmp(status, MPATH_STATUS_01)); + assert_true(!strcmp(name, MPATH_NAME_01)); + assert_true(!strcmp(uuid, MPATH_UUID_01)); +} + +static int test_mapinfo(void) +{ + const struct CMUnitTest tests[] = { + cmocka_unit_test(test_mapinfo_bad_task_create_01), + cmocka_unit_test(test_mapinfo_bad_mapid), + cmocka_unit_test(test_mapinfo_bad_set_name), + cmocka_unit_test(test_mapinfo_bad_task_run_01), + cmocka_unit_test(test_mapinfo_bad_task_run_02), + cmocka_unit_test(test_mapinfo_bad_task_run_03), + cmocka_unit_test(test_mapinfo_bad_task_run_04), + cmocka_unit_test(test_mapinfo_bad_task_run_05), + cmocka_unit_test(test_mapinfo_bad_task_run_06), + cmocka_unit_test(test_mapinfo_bad_task_run_07), + cmocka_unit_test(test_mapinfo_bad_task_run_08), + cmocka_unit_test(test_mapinfo_bad_task_run_09), + 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_info_02), + cmocka_unit_test(test_mapinfo_bad_get_info_03), + cmocka_unit_test(test_mapinfo_bad_get_info_04), + cmocka_unit_test(test_mapinfo_good_exists), + cmocka_unit_test(test_mapinfo_bad_set_uuid), + cmocka_unit_test(test_mapinfo_bad_set_dev_01), + cmocka_unit_test(test_mapinfo_bad_set_dev_02), + cmocka_unit_test(test_mapinfo_bad_set_dev_03), + cmocka_unit_test(test_mapinfo_bad_set_dev_04), + cmocka_unit_test(test_mapinfo_good_info), + cmocka_unit_test(test_mapinfo_good_by_uuid_info), + cmocka_unit_test(test_mapinfo_good_by_dev_info), + cmocka_unit_test(test_mapinfo_good_by_devt_info), + cmocka_unit_test(test_mapinfo_bad_name), + cmocka_unit_test(test_mapinfo_good_name), + cmocka_unit_test(test_mapinfo_bad_uuid), + 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_02), + cmocka_unit_test(test_mapinfo_bad_target_type_01), + 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), + cmocka_unit_test(test_mapinfo_bad_target_type_05), + cmocka_unit_test(test_mapinfo_good_target_type_01), + 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_good_status_01), + cmocka_unit_test(test_mapinfo_bad_get_name_01), + cmocka_unit_test(test_mapinfo_bad_get_uuid_01), + cmocka_unit_test(test_mapinfo_bad_strdup_01), + cmocka_unit_test(test_mapinfo_bad_get_name_02), + cmocka_unit_test(test_mapinfo_bad_get_uuid_02), + cmocka_unit_test(test_mapinfo_bad_strdup_02), + cmocka_unit_test(test_mapinfo_bad_strdup_03), + cmocka_unit_test(test_mapinfo_good_all_01), + }; + return cmocka_run_group_tests(tests, NULL, NULL); +} + +int main(void) +{ + int ret = 0; + + init_test_verbosity(4); + skip_libmp_dm_init(); + ret += test_mapinfo(); + return ret; +} From patchwork Fri Jul 12 17:14:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13732069 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1FD1817BCD for ; Fri, 12 Jul 2024 17:15:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804556; cv=none; b=iFIJQsx3HzYR/18hVjEk6vg3LHOOk8xIp4R3bvhLfIfYMaLuhDzNT5N1uv+Oll6rOkE5agwXXKl4eE76WiI/d8YfC4fX77do77xrFHGnix3ICOtlMDKNLRRK2u/LDTjT1ROtJ4mJ1Gfaa9sbYoLxNO9NIMxFVlSmdUoiMQuOTms= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804556; c=relaxed/simple; bh=oOWc/M484IeF9+mJU6e+I6+idN6xoVnSZYHEzXpquV8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gmLzRpffjJdv9iObgr32mw+sJcxy4TmnrC/sgrcVcvRIHCklif8c8sQrZrxCsUjTXguC+dh/MswUls8Onrtagj2OqW9czgPucqM0Ph6BJJkDCxkhoSvy/3veyRRZKdmndx04kYZ85WHGneY2GcfCAqeyz/VmEGkvbKpMZwcHc84= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=NGAAW4Rb; arc=none smtp.client-ip=209.85.218.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="NGAAW4Rb" Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-a77e5929033so315997266b.0 for ; Fri, 12 Jul 2024 10:15:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1720804552; x=1721409352; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1V8rDsIOutfB4ukS9az8eU485SujLHQxpe369D7FMZg=; b=NGAAW4Rb/6kICF/ZBod1/El6JNClOPQc8puYzoQ3slKtKm/qHkM/H1TkG0yI14247f 7SCbO0Iwsf2wTGFup1wljjX6+4fqQbfMBRtk1RgnZLYV3qYXl1Y78S3rlaPadGSsIpdH Zv996Dc6GFEb4avgK4VQXvtQunyNUhRG91e37zFD2Kp3AnMlHYVas6crDT4R2dGU6/nx KoFGZa0jPuDdk5qyq9Y4fGdE1nHvHq6ck6i9MgooRqm4qI0b0FGGiwnHKs+FOJKoNaHU Bnrquw4KfeKqD877pu1fI8xwJoN7ZVSi0YA/nAf08wRZYQ1RdHzrjGbz9w0tcx8kMILg fJzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720804552; x=1721409352; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1V8rDsIOutfB4ukS9az8eU485SujLHQxpe369D7FMZg=; b=UO8OwbnjmrnLu5/FMDCleqmHxG6DlTXTZfsKgCh6SnFYnjty+fHREp3ihSc9cbhzo9 i73tMH5/UVmVWI3nio8EYZXj1XcrnsTm0achh8c2cvzwQomUqES+exrRpymHnvxubOml Ik5zpqPqxVi0NkfWK6XYc0NNC2vLYmJjqtpES0uz264T9T3/dPMMv7PD7Hbnlu6U/qS8 1Am8epBM8M6fQGKGweRe9tiH3nFQf9PcKLISZlj5Z+lDr1sm0bi1BDE60TF/UBRrfYEg /MxjF4cOW6ncnZHEmWCCQQP8u3/9z3p3s3b14DDDjx9BQ4kzAv5fMV8hE2LhcFBpc8BU qHxw== X-Gm-Message-State: AOJu0YyZ9vu/vYklRTBGFG6LuEllfNW6s7i8+fwUJYCb3KVTTrdrlS4b /3QsbUJpfIClnp9lHi6mi9JJxScFj/YA+7Rm99X7xzMYvzxUYgi9viZ7AUHuUc9TAVYE3zeoUyO + X-Google-Smtp-Source: AGHT+IE0uCOvqv9C0B7zuFGQ+d1Y2nSHWRwlGIAczxewVu1t6E+OxTcZ8m7pM80cxCHlyzd0svC6sQ== X-Received: by 2002:a17:907:94c5:b0:a6f:392d:51a9 with SMTP id a640c23a62f3a-a780b6883c2mr1030396966b.14.1720804551409; Fri, 12 Jul 2024 10:15:51 -0700 (PDT) Received: from localhost (p200300de37360a00d7e56139e90929dd.dip0.t-ipconnect.de. [2003:de:3736:a00:d7e5:6139:e909:29dd]) by smtp.gmail.com with UTF8SMTPSA id a640c23a62f3a-a780a6e37ffsm359778166b.76.2024.07.12.10.15.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 10:15:51 -0700 (PDT) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, Martin Wilck Subject: [PATCH v2 21/49] libmultipath: implement dm_get_info() and dm_map_present() with new API Date: Fri, 12 Jul 2024 19:14:29 +0200 Message-ID: <20240712171458.77611-22-mwilck@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712171458.77611-1-mwilck@suse.com> References: <20240712171458.77611-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/devmapper.c | 54 ++++--------------------------- libmultipath/devmapper.h | 16 +++++++-- libmultipath/libmultipath.version | 2 -- multipathd/main.c | 4 +-- 4 files changed, 23 insertions(+), 53 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 4e6b5b2..754f45e 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -794,45 +794,6 @@ int libmp_mapinfo(int flags, mapid_t id, mapinfo_t info) libmp_map_identifier(flags, id, idbuf)); } -int -dm_get_info(const char *name, struct dm_info *info) -{ - int r = -1; - struct dm_task *dmt; - - if (!name || !info) - return r; - - if (!(dmt = libmp_dm_task_create(DM_DEVICE_INFO))) - return r; - - if (!dm_task_set_name(dmt, name)) - goto out; - - if (!libmp_dm_task_run(dmt)) { - dm_log_error(3, DM_DEVICE_INFO, dmt); - goto out; - } - - if (!dm_task_get_info(dmt, info)) - goto out; - - if (!info->exists) - goto out; - - r = 0; -out: - dm_task_destroy(dmt); - return r; -} - -int dm_map_present(const char * str) -{ - struct dm_info info; - - return (dm_get_info(str, &info) == 0); -} - int dm_get_map(const char *name, unsigned long long *size, char **outparams) { struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; @@ -1131,15 +1092,14 @@ out: return r; } -static int -dm_dev_t (const char * mapname, char * dev_t, int len) +static int dm_dev_t (const char *mapname, char *dev_t, int len) { struct dm_info info; - if (dm_get_info(mapname, &info) != 0) + if (dm_get_info(mapname, &info) != DMP_OK) return 1; - if (snprintf(dev_t, len, "%i:%i", info.major, info.minor) > len) + if (safe_snprintf(dev_t, len, "%i:%i", info.major, info.minor)) return 1; return 0; @@ -1180,7 +1140,7 @@ dm_get_major_minor(const char *name, int *major, int *minor) { struct dm_info info; - if (dm_get_info(name, &info) != 0) + if (dm_get_info(name, &info) != DMP_OK) return -1; *major = info.major; @@ -1526,7 +1486,7 @@ dm_geteventnr (const char *name) { struct dm_info info; - if (dm_get_info(name, &info) != 0) + if (dm_get_info(name, &info) != DMP_OK) return -1; return info.event_nr; @@ -1537,7 +1497,7 @@ dm_is_suspended(const char *name) { struct dm_info info; - if (dm_get_info(name, &info) != 0) + if (dm_get_info(name, &info) != DMP_OK) return -1; return info.suspended; @@ -1689,7 +1649,7 @@ dm_get_deferred_remove (const char * mapname) { struct dm_info info; - if (dm_get_info(mapname, &info) != 0) + if (dm_get_info(mapname, &info) != DMP_OK) return -1; return info.deferred_remove; diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h index 62f50de..6fa99be 100644 --- a/libmultipath/devmapper.h +++ b/libmultipath/devmapper.h @@ -104,6 +104,20 @@ typedef struct libmp_map_info { */ int libmp_mapinfo(int flags, mapid_t id, mapinfo_t info); +static inline int dm_get_info(const char *mapname, struct dm_info *info) +{ + return libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = mapname }, + (mapinfo_t) { .dmi = info }); +} + +static inline int dm_map_present(const char *mapname) +{ + return libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = mapname }, + (mapinfo_t) { .name = NULL }) == DMP_OK; +} + int dm_prereq(unsigned int *v); void skip_libmp_dm_init(void); void libmp_dm_exit(void); @@ -113,7 +127,6 @@ int dm_simplecmd_flush (int task, const char *name, uint16_t udev_flags); int dm_simplecmd_noflush (int task, const char *name, uint16_t udev_flags); int dm_addmap_create (struct multipath *mpp, char *params); int dm_addmap_reload (struct multipath *mpp, char *params, int flush); -int dm_map_present (const char *name); int dm_map_present_by_uuid(const char *uuid); int dm_get_map(const char *name, unsigned long long *size, char **outparams); int dm_get_status(const char *name, char **outstatus); @@ -164,7 +177,6 @@ int dm_get_major_minor (const char *name, int *major, int *minor); char * dm_mapname(int major, int minor); int dm_get_uuid(const char *name, char *uuid, int uuid_len); bool has_dm_info(const struct multipath *mpp); -int dm_get_info (const char * mapname, struct dm_info *dmi); int dm_rename (const char * old, char * new, char * delim, int skip_kpartx); int dm_reassign(const char * mapname); int dm_reassign_table(const char *name, char *old, char *new); diff --git a/libmultipath/libmultipath.version b/libmultipath/libmultipath.version index 48c2b67..7a50349 100644 --- a/libmultipath/libmultipath.version +++ b/libmultipath/libmultipath.version @@ -78,14 +78,12 @@ global: dm_flush_map_nopaths; dm_flush_maps; dm_geteventnr; - dm_get_info; dm_get_major_minor; dm_get_maps; dm_get_multipath; dm_get_uuid; dm_is_mpath; dm_mapname; - dm_map_present; dm_prereq; dm_queue_if_no_path; dm_reassign; diff --git a/multipathd/main.c b/multipathd/main.c index 132bb2e..394ca7d 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -502,7 +502,7 @@ remove_maps_and_stop_waiters(struct vectors *vecs) int refresh_multipath(struct vectors *vecs, struct multipath *mpp) { - if (dm_get_info(mpp->alias, &mpp->dmi)) { + if (dm_get_info(mpp->alias, &mpp->dmi) != DMP_OK) { /* Error accessing table */ condlog(2, "%s: cannot access table", mpp->alias); goto out; @@ -722,7 +722,7 @@ add_map_without_path (struct vectors *vecs, const char *alias) mpp->alias = strdup(alias); - if (dm_get_info(mpp->alias, &mpp->dmi)) { + if (dm_get_info(mpp->alias, &mpp->dmi) != DMP_OK) { condlog(3, "%s: cannot access table", mpp->alias); goto out; } From patchwork Fri Jul 12 17:14:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13732070 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4838A176AC4 for ; Fri, 12 Jul 2024 17:15:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804557; cv=none; b=Zq+UIF0xq/DLHULVao3YYZXTJZVQ9mPm0WQldVSBEt3IW9i0QRe5ZjfrkIc9O1bXmkoqU20xgtrCf9WjkCJeOVCYOqPk393I+yOlYyfwRHe41osC/Mq5nWI8GtmDy7x3PLOUXlBvi08jkHzXUJ43rZ2TjDecfz5dLWEFsyv1ZoA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804557; c=relaxed/simple; bh=a8G7yjtFjtTnylXmRJ1wkfGU2sh+fH+uwA2vwP4mSi0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DAIanL1tr8aEW20fwrcGpept5S+C+WDzK0U4p6d18IOteWZKNKolcWRiMkH4pc8uJVbg4BbEP8YhWKKqqo0AqeMYzME46BgOnLElQjoPNOTz8rVzb5tSHow2UDWXy18p3tFuRNQY9ugdqGPG+KOXyc5VTUGrMz0mQjADg9P9Ij4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=bQiaD7mj; arc=none smtp.client-ip=209.85.218.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="bQiaD7mj" Received: by mail-ej1-f46.google.com with SMTP id a640c23a62f3a-a77bf336171so394390066b.1 for ; Fri, 12 Jul 2024 10:15:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1720804553; x=1721409353; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BHKJqr4xfU2xTHDsp1UcD3N458lleWBHy+eHORPTvdw=; b=bQiaD7mjymreECKlEMjCh2tCWwTI2CQyrFchYxrEVBhw9JRocvEYMLYymoT758aJbk SN6Qh7iPhBDqgWCqhCVj5Zp+u9HA1Ei/3dQ0UKAevmcpfuEKAC4xspBz02xqbtqrtyQP mJ0LkjxZ5PZcXDzaV0Mgayx0sSWNNurBvGf++uXDnBWelRr9dC51ICQmWHkfrlW2kBuN rwfa11LZ0fofL2+IeKbkOd68apTy5+olB0jrS+Fac+0ijcPWqHIbpbsZEGB134yCsAXN hrFfaulClyD7OFYa1zjdHywANpZ7LczgCmzIo/hfm3P4Y1qUyg/9Dg0rkO1MjSszWH4Q OKyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720804553; x=1721409353; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BHKJqr4xfU2xTHDsp1UcD3N458lleWBHy+eHORPTvdw=; b=vlUhunWUWZAdM+aHs008tg+sScnfiG+/LoNr4dbrz0I3moAuSb651JhD0vNKo2R8ua Kbip6aLLohk8hiTsVDeaQ9k5BRYiPypHjbkg4WjGLasa1FsWyO+M0045FXmLw+7J5bq/ z/uPW9CL/gN+Cn2dn/nKyhTWBR4kdiW8ldLzpVJmqf3E9psqtSLp6G44YHWI7j6RkNrq lrx3Oesh/8LqSn4jKPbBQDwUjyS+lRBm7IrEU9QUoITKCAjkCrz4BxVi4moJzk5SgtTK R3AN+IMRube7tYub3LlM5k6+uo1ttxxnGF26rhFQOYFqejusOgN8B8EpzFtuK8Jn6JgW Tg4Q== X-Gm-Message-State: AOJu0Yx62mjgh9btGIt6FNssqevOhCxESj04kQMDFlIe58i8btxXIT7G OaCtog0o/d3BAhOGUABCgvlCcKCnXnFu95V7giJUt6b57XyxNrDI06bqupHHNmQ= X-Google-Smtp-Source: AGHT+IHT7UGdGQMBdB/W1cBiUuR+5IvgukWy6+QnZ7tJ3wfkrrWaC5GbM1muSMtcsVXeOGGA1G6XIg== X-Received: by 2002:a17:907:7802:b0:a77:c693:9ddf with SMTP id a640c23a62f3a-a799cd38e5cmr221936366b.34.1720804553345; Fri, 12 Jul 2024 10:15:53 -0700 (PDT) Received: from localhost (p200300de37360a00d7e56139e90929dd.dip0.t-ipconnect.de. [2003:de:3736:a00:d7e5:6139:e909:29dd]) by smtp.gmail.com with UTF8SMTPSA id a640c23a62f3a-a780a7ff722sm358883666b.123.2024.07.12.10.15.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 10:15:53 -0700 (PDT) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, Martin Wilck Subject: [PATCH v2 22/49] libmultipath: remove dm_get_prefixed_uuid() Date: Fri, 12 Jul 2024 19:14:30 +0200 Message-ID: <20240712171458.77611-23-mwilck@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712171458.77611-1-mwilck@suse.com> References: <20240712171458.77611-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 ... and replace it by calls to the new API. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/devmapper.c | 53 +++++++++------------------------------- 1 file changed, 11 insertions(+), 42 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 754f45e..0bc5e34 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -794,6 +794,13 @@ int libmp_mapinfo(int flags, mapid_t id, mapinfo_t info) libmp_map_identifier(flags, id, idbuf)); } +static int dm_get_dm_uuid(const char *mapname, char uuid[DM_UUID_LEN]) +{ + return libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = mapname }, + (mapinfo_t) { .uuid = uuid }); +} + int dm_get_map(const char *name, unsigned long long *size, char **outparams) { struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; @@ -833,48 +840,11 @@ int dm_get_map(const char *name, unsigned long long *size, char **outparams) } } -static int -dm_get_prefixed_uuid(const char *name, char *uuid, int uuid_len) -{ - struct dm_task *dmt; - const char *uuidtmp; - struct dm_info info; - int r = 1; - - dmt = libmp_dm_task_create(DM_DEVICE_INFO); - if (!dmt) - return 1; - - if (uuid_len > 0) - uuid[0] = '\0'; - - if (!dm_task_set_name (dmt, name)) - goto uuidout; - - if (!libmp_dm_task_run(dmt)) { - dm_log_error(3, DM_DEVICE_INFO, dmt); - goto uuidout; - } - - if (!dm_task_get_info(dmt, &info) || - !info.exists) - goto uuidout; - - uuidtmp = dm_task_get_uuid(dmt); - if (uuidtmp) - strlcpy(uuid, uuidtmp, uuid_len); - - r = 0; -uuidout: - dm_task_destroy(dmt); - return r; -} - int dm_get_uuid(const char *name, char *uuid, int uuid_len) { char tmp[DM_UUID_LEN]; - if (dm_get_prefixed_uuid(name, tmp, sizeof(tmp))) + if (dm_get_dm_uuid(name, tmp) != DMP_OK) return 1; if (!strncmp(tmp, UUID_PREFIX, UUID_PREFIX_LEN)) @@ -885,16 +855,15 @@ int dm_get_uuid(const char *name, char *uuid, int uuid_len) return 0; } -static int -is_mpath_part(const char *part_name, const char *map_name) +static int is_mpath_part(const char *part_name, const char *map_name) { char *p; char part_uuid[DM_UUID_LEN], map_uuid[DM_UUID_LEN]; - if (dm_get_prefixed_uuid(part_name, part_uuid, sizeof(part_uuid))) + if (dm_get_dm_uuid(part_name, part_uuid) != DMP_OK) return 0; - if (dm_get_prefixed_uuid(map_name, map_uuid, sizeof(map_uuid))) + if (dm_get_dm_uuid(map_name, map_uuid) != DMP_OK) return 0; if (strncmp(part_uuid, "part", 4) != 0) From patchwork Fri Jul 12 17:14:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13732071 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 18C1D176ACE for ; Fri, 12 Jul 2024 17:15:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804558; cv=none; b=qHUca3zctduGZxbT5otTki/rvVs/Fo8K77PVXCepq0NLUd7sl05jrawtf5HEmXAwD6nQ1PDIf2+eNP2P+AaV0+zPDl6ptdNabl8nfzZNVg/XxcACLubHcN1QDk5/o39rKO/iBQ7uZuAFOa9oa1VrLUeY/DHtYURAneHkvobahww= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804558; c=relaxed/simple; bh=uqYBnk2DSEy3yh+KxclPWWI5O3FbNdTPOQtwW1GCH6Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ETilsBMxfZKbikU65X4tC6G5IwQVsXL1MCWMYqEGeQAmomxOkUsqAae9D7YRRZSdPBP4moiBhOzRgc67iIUaXMinS6S3NPyMDUdJQ3sZhKRjy6i+PsfiQSyNCf6v7qWINquanzzCAfFImhiGSamGGdsQGdkmq5efoSEn33EduDs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=P2BRiC2Q; arc=none smtp.client-ip=209.85.218.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="P2BRiC2Q" Received: by mail-ej1-f42.google.com with SMTP id a640c23a62f3a-a77cb7c106dso286417966b.1 for ; Fri, 12 Jul 2024 10:15:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1720804554; x=1721409354; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Rd5jiIJdq95VDuJROUfCB4shfMuH9jcNHZ+S2lg/4lo=; b=P2BRiC2QRrhrasIsflM+Ik0Gy+oB29nRt8onticiwXcrqVUwNnQXetN5oewFKHqypA EH0lHmST0MYmzZR7MJAAgqVeT6q/v4i7B2QxKlNsHuoU8qE6V4TQML02+AfNmA7UwgFM ypyTv9SRc6VRAHbFS0sGAyhETRnv6+0ZN/qwo7sT5Xt8+JAU2dFZ9GwlaMGKzXn1Hrdk fWRHQii05y5c1Ef8ttxLZ1A7nrktyJ6OWPLyy/AnbzxZkDzobvOkV6MbfnFliBuFwnRx J8xnejt0QFwASL7HRdG8lbu1GKSqIUN5y2F3ZIKpTjjWIVI1c/YyTZ0B/LPCIq7/ljna s8ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720804554; x=1721409354; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Rd5jiIJdq95VDuJROUfCB4shfMuH9jcNHZ+S2lg/4lo=; b=WlC6zUQwc6Gi/VaNwZpuaJwN8KgXIop9URLBstQxtuU6zinfDKeNbU7WyIM70KGtUO HtOeX6qwm+qLQ7Yr5qaCVo5a1+9zjS2H9YfI3RTOMVMfGZwkrGzEsByplmHdV2m9CJqc dh0NJY2GIT6nL2PpVbscyBbj5lqi3b6duyr0jbP2agP54rqlkhM94mx2kJw0f7hLpUXw p0e1AJeSEN8otA52WYUCbloqNRIdSgh9OnMN6ZRqG96H3xASbOsHPLFh2r2tyLb2McCu IBYnr9TH5o31C+ae+UcdmiWrV4Q+1boGyf9Jpj1Dv/R5CUDd7scZLciKVr1rfp465NTd B9Rw== X-Gm-Message-State: AOJu0YyJ5JlOzI3Qy8SMzGRo6UFSE6XTRhKPlfBqoOV6Eo/PYlhkuvRs cfxDwlh1T4FLfTtvkN/eAysesHJloPVAhB5Bm32fWjqtJX+Z63aYDxzQ8d+4lnqFrl0xrmOxhq6 h X-Google-Smtp-Source: AGHT+IHplqKHSmuuyeuq81XMw8/HaX0u2pRAZ9+XaxlhDmeJXXoY/3lzAOd3oigXYb4ZDJ/5XYMKgg== X-Received: by 2002:a17:906:28cd:b0:a72:6b08:ab27 with SMTP id a640c23a62f3a-a780b70166cmr757846266b.36.1720804554284; Fri, 12 Jul 2024 10:15:54 -0700 (PDT) Received: from localhost (p200300de37360a00d7e56139e90929dd.dip0.t-ipconnect.de. [2003:de:3736:a00:d7e5:6139:e909:29dd]) by smtp.gmail.com with UTF8SMTPSA id a640c23a62f3a-a780a6bcc3bsm361367866b.22.2024.07.12.10.15.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 10:15:54 -0700 (PDT) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, Martin Wilck Subject: [PATCH v2 23/49] libmultipath: is_mpath_part(): improve parsing Date: Fri, 12 Jul 2024 19:14:31 +0200 Message-ID: <20240712171458.77611-24-mwilck@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712171458.77611-1-mwilck@suse.com> References: <20240712171458.77611-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use sscanf to make the parsing of the UUID more robust. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/devmapper.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 0bc5e34..f80fbdf 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -857,23 +857,20 @@ int dm_get_uuid(const char *name, char *uuid, int uuid_len) static int is_mpath_part(const char *part_name, const char *map_name) { - char *p; - char part_uuid[DM_UUID_LEN], map_uuid[DM_UUID_LEN]; + char part_uuid[DM_UUID_LEN], map_uuid[DM_UUID_LEN], c; + int np, nc; if (dm_get_dm_uuid(part_name, part_uuid) != DMP_OK) return 0; + if (2 != sscanf(part_uuid, "part%d-%n" UUID_PREFIX "%c", &np, &nc, &c) + || np <= 0) + return 0; + if (dm_get_dm_uuid(map_name, map_uuid) != DMP_OK) return 0; - if (strncmp(part_uuid, "part", 4) != 0) - return 0; - - p = strstr(part_uuid, UUID_PREFIX); - if (p && !strcmp(p, map_uuid)) - return 1; - - return 0; + return !strcmp(part_uuid + nc, map_uuid); } int dm_get_status(const char *name, char **outstatus) From patchwork Fri Jul 12 17:14:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13732072 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 77503176AD0 for ; Fri, 12 Jul 2024 17:15:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804559; cv=none; b=MeHAOI2n0KgCYKd3VD+XvYrChwZMvh/d4OpNht0Uqobp2LeG9vfwxZ3dkSqmI7PG9Hfd+pQJOuykTyyEDQz9+EHPmMtAWfBr/+PQjLgR88ToYDH9eqOTHwgBm/YWlUhcSHKbv5utM0hAijKLTSxqUV+ZvatcpQcK+KGtUws8nNo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804559; c=relaxed/simple; bh=vL6K9xU7u9NuzWqPxV563zp9GYsPQ+Ub3RyB+N02w+w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sJgR9THKpyLgdRA55bIwK2WAabvtZ4eepZaOdAODVbk89lYMeFMvh4M5ibFxj6EQhpZyioHwbS5nPcXu5qTlr7V8tqrDzqoS6YIbI/IxIUpA0X8THels3d8jbT4+4yxXFLOeOGQUbORXbLzd22PorQrCdC4DqlpKBU2ghNMaAys= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=fAaMNO+x; arc=none smtp.client-ip=209.85.218.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="fAaMNO+x" Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-a77e392f59fso300528766b.1 for ; Fri, 12 Jul 2024 10:15:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1720804556; x=1721409356; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=30Dw1pELeKsdeaVqOTPPGfpXeD6RAm1zeeVh5PxW+Qs=; b=fAaMNO+xOYW+xLeB4w5ht6+T+CzeqjowADgdvMrHvgMJkyP+6QgIEkCaVTbjlXlJxB edJ+mxiEKqMnubEc3Ykf2SdNR8c77lf/tEzQHVjTqRR/TXphCFJmcJ06DWFEgKgGQM7f +PNXNsdLB21iGP0eYeMZerzXOKoPebtJrIfj8yu50B7sPGyb5t9QLhkBCO+CANk37n4C mZbDWKb1/xtOijkrL7h4PgwuklrT1rDJKDNgPRIj7q0hDsCpRCv2FR+8Zqp1PrOqLgmS F4mdDXPcjydua6Opc/BM4/bYpfLomj8KhGN3xK/mODDGilo7Jdvzk3gwSrI+E8xDECzr b3LA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720804556; x=1721409356; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=30Dw1pELeKsdeaVqOTPPGfpXeD6RAm1zeeVh5PxW+Qs=; b=IQbmKoX7OoHQuzEeyXERdAZBCwrx9a/M9Kc1JcN9ZqSK3MOoXmwchm6IQ9Tcr9QWY2 wyZWs7lBvzVb4Q4Oyvllqe9ZpcJeWIKKXS0c+FES0ehBAGA/hZnlRNLz5ft4qLil3bUL ySIVjodkVYDbmBwjYEOgjcwdJCpAPSbakdOMeR7t56yTD53MTswIIhbDneeXtIbHO8Bc kLGD4WmRVR6iNw8ETiHt4rriTK9uyQwVnriKSewvYB0SjinAcua9Tso6HoptHrjlONos Yf9p/8d1ha1ztx+o8VQtaxQQ9rWzVATsnh4dNvkVnVAaL8POcBp9zoSF92NwEkGGgvJ8 PMkw== X-Gm-Message-State: AOJu0YwyxXT3UrT9P+cOZGTYaPSBq0XnCJKQpt7Ns+0Y5zjXfHuLtOPb Hq+dpXSFUkBqSTdNqPFbXh88WDQbOAtFJFL5HLR4UKyOc/Jw/I9TCp5GBLD0xgU= X-Google-Smtp-Source: AGHT+IF262mL3kUSfcu3oNDv5e6U2KYsAr3ZePW2Wq8UHfeMo/UnLQVZJJpgGFmMW3z3gDqZPK7p1g== X-Received: by 2002:a17:906:4fd0:b0:a79:7e8b:34c0 with SMTP id a640c23a62f3a-a797e8b4264mr644597566b.1.1720804555478; Fri, 12 Jul 2024 10:15:55 -0700 (PDT) Received: from localhost (p200300de37360a00d7e56139e90929dd.dip0.t-ipconnect.de. [2003:de:3736:a00:d7e5:6139:e909:29dd]) by smtp.gmail.com with UTF8SMTPSA id a640c23a62f3a-a780a872e23sm362286766b.225.2024.07.12.10.15.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 10:15:55 -0700 (PDT) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, Martin Wilck Subject: [PATCH v2 24/49] libmultipath: rename dm_get_uuid() -> dm_get_wwid() Date: Fri, 12 Jul 2024 19:14:32 +0200 Message-ID: <20240712171458.77611-25-mwilck@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712171458.77611-1-mwilck@suse.com> References: <20240712171458.77611-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 ... to make the distinction between WWID (multipath) and UUID (device mapper) a little more obvious. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/alias.c | 2 +- libmultipath/configure.c | 4 ++-- libmultipath/devmapper.c | 4 ++-- libmultipath/devmapper.h | 2 +- libmultipath/libmultipath.version | 2 +- libmultipath/wwids.c | 2 +- multipathd/main.c | 2 +- tests/alias.c | 30 +++++++++++++++--------------- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/libmultipath/alias.c b/libmultipath/alias.c index a54616c..10e58a7 100644 --- a/libmultipath/alias.c +++ b/libmultipath/alias.c @@ -410,7 +410,7 @@ static bool alias_already_taken(const char *alias, const char *map_wwid) char wwid[WWID_SIZE]; /* If the map doesn't exist, it's fine */ - if (dm_get_uuid(alias, wwid, sizeof(wwid)) != 0) + if (dm_get_wwid(alias, wwid, sizeof(wwid)) != 0) return false; /* If both the name and the wwid match, it's fine.*/ diff --git a/libmultipath/configure.c b/libmultipath/configure.c index b5c701f..666d4e8 100644 --- a/libmultipath/configure.c +++ b/libmultipath/configure.c @@ -846,7 +846,7 @@ int domap(struct multipath *mpp, char *params, int is_daemon) if (mpp->action == ACT_CREATE && dm_map_present(mpp->alias)) { char wwid[WWID_SIZE]; - if (dm_get_uuid(mpp->alias, wwid, sizeof(wwid)) == 0) { + if (dm_get_wwid(mpp->alias, wwid, sizeof(wwid)) == 0) { if (!strncmp(mpp->wwid, wwid, sizeof(wwid))) { condlog(3, "%s: map already present", mpp->alias); @@ -1320,7 +1320,7 @@ static int _get_refwwid(enum mpath_cmds cmd, const char *dev, break; case DEV_DEVMAP: - if (((dm_get_uuid(dev, tmpwwid, WWID_SIZE)) == 0) + if (((dm_get_wwid(dev, tmpwwid, WWID_SIZE)) == 0) && (strlen(tmpwwid))) refwwid = tmpwwid; diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index f80fbdf..3fca08c 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -840,7 +840,7 @@ int dm_get_map(const char *name, unsigned long long *size, char **outparams) } } -int dm_get_uuid(const char *name, char *uuid, int uuid_len) +int dm_get_wwid(const char *name, char *uuid, int uuid_len) { char tmp[DM_UUID_LEN]; @@ -1388,7 +1388,7 @@ struct multipath *dm_get_multipath(const char *name) if (dm_get_map(name, &mpp->size, NULL) != DMP_OK) goto out; - if (dm_get_uuid(name, mpp->wwid, WWID_SIZE) != 0) + if (dm_get_wwid(name, mpp->wwid, WWID_SIZE) != 0) condlog(2, "%s: failed to get uuid for %s", __func__, name); if (dm_get_info(name, &mpp->dmi) != 0) condlog(2, "%s: failed to get info for %s", __func__, name); diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h index 6fa99be..25e0504 100644 --- a/libmultipath/devmapper.h +++ b/libmultipath/devmapper.h @@ -175,7 +175,7 @@ int dm_geteventnr (const char *name); int dm_is_suspended(const char *name); int dm_get_major_minor (const char *name, int *major, int *minor); char * dm_mapname(int major, int minor); -int dm_get_uuid(const char *name, char *uuid, int uuid_len); +int dm_get_wwid(const char *name, char *uuid, int uuid_len); bool has_dm_info(const struct multipath *mpp); int dm_rename (const char * old, char * new, char * delim, int skip_kpartx); int dm_reassign(const char * mapname); diff --git a/libmultipath/libmultipath.version b/libmultipath/libmultipath.version index 7a50349..7d3ff63 100644 --- a/libmultipath/libmultipath.version +++ b/libmultipath/libmultipath.version @@ -81,7 +81,7 @@ global: dm_get_major_minor; dm_get_maps; dm_get_multipath; - dm_get_uuid; + dm_get_wwid; dm_is_mpath; dm_mapname; dm_prereq; diff --git a/libmultipath/wwids.c b/libmultipath/wwids.c index 591cd09..7a4cb74 100644 --- a/libmultipath/wwids.c +++ b/libmultipath/wwids.c @@ -295,7 +295,7 @@ should_multipath(struct path *pp1, vector pathvec, vector mpvec) struct multipath *mp = find_mp_by_wwid(mpvec, pp1->wwid); if (mp != NULL && - dm_get_uuid(mp->alias, tmp_wwid, WWID_SIZE) == 0 && + dm_get_wwid(mp->alias, tmp_wwid, WWID_SIZE) == 0 && !strncmp(tmp_wwid, pp1->wwid, WWID_SIZE)) { condlog(3, "wwid %s is already multipathed, keeping it", pp1->wwid); diff --git a/multipathd/main.c b/multipathd/main.c index 394ca7d..442a154 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -727,7 +727,7 @@ add_map_without_path (struct vectors *vecs, const char *alias) goto out; } if (!strlen(mpp->wwid)) - dm_get_uuid(mpp->alias, mpp->wwid, WWID_SIZE); + dm_get_wwid(mpp->alias, mpp->wwid, WWID_SIZE); if (!strlen(mpp->wwid)) condlog(1, "%s: adding map with empty WWID", mpp->alias); conf = get_multipath_config(); diff --git a/tests/alias.c b/tests/alias.c index 95ce994..1f78656 100644 --- a/tests/alias.c +++ b/tests/alias.c @@ -76,7 +76,7 @@ int WRAP_FUNC(mkstemp)(char *template) return 10; } -int __wrap_dm_get_uuid(const char *name, char *uuid, int uuid_len) +int __wrap_dm_get_wwid(const char *name, char *uuid, int uuid_len) { int ret; @@ -436,17 +436,17 @@ static int test_scan_devname(void) static void mock_unused_alias(const char *alias) { - expect_string(__wrap_dm_get_uuid, name, alias); - expect_value(__wrap_dm_get_uuid, uuid_len, WWID_SIZE); - will_return(__wrap_dm_get_uuid, 1); + expect_string(__wrap_dm_get_wwid, name, alias); + expect_value(__wrap_dm_get_wwid, uuid_len, WWID_SIZE); + will_return(__wrap_dm_get_wwid, 1); } static void mock_self_alias(const char *alias, const char *wwid) { - expect_string(__wrap_dm_get_uuid, name, alias); - expect_value(__wrap_dm_get_uuid, uuid_len, WWID_SIZE); - will_return(__wrap_dm_get_uuid, 0); - will_return(__wrap_dm_get_uuid, wwid); + expect_string(__wrap_dm_get_wwid, name, alias); + expect_value(__wrap_dm_get_wwid, uuid_len, WWID_SIZE); + will_return(__wrap_dm_get_wwid, 0); + will_return(__wrap_dm_get_wwid, wwid); } #define USED_STR(alias_str, wwid_str) wwid_str ": alias '" alias_str "' already taken, reselecting alias\n" @@ -469,17 +469,17 @@ static void mock_self_alias(const char *alias, const char *wwid) #define mock_failed_alias(alias, wwid) \ do { \ - expect_string(__wrap_dm_get_uuid, name, alias); \ - expect_value(__wrap_dm_get_uuid, uuid_len, WWID_SIZE); \ - will_return(__wrap_dm_get_uuid, 1); \ + expect_string(__wrap_dm_get_wwid, name, alias); \ + expect_value(__wrap_dm_get_wwid, uuid_len, WWID_SIZE); \ + will_return(__wrap_dm_get_wwid, 1); \ } while (0) #define mock_used_alias(alias, wwid) \ do { \ - expect_string(__wrap_dm_get_uuid, name, alias); \ - expect_value(__wrap_dm_get_uuid, uuid_len, WWID_SIZE); \ - will_return(__wrap_dm_get_uuid, 0); \ - will_return(__wrap_dm_get_uuid, "WWID_USED"); \ + expect_string(__wrap_dm_get_wwid, name, alias); \ + expect_value(__wrap_dm_get_wwid, uuid_len, WWID_SIZE); \ + will_return(__wrap_dm_get_wwid, 0); \ + will_return(__wrap_dm_get_wwid, "WWID_USED"); \ expect_condlog(3, USED_STR(alias, wwid)); \ } while(0) From patchwork Fri Jul 12 17:14:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13732073 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 27473177980 for ; Fri, 12 Jul 2024 17:15:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804560; cv=none; b=BtAc2OL7PtpKSLjpHoz52bBW2ZmqNq375lsvCp4XevM1ADCdhJBOdOBio0EpjptTe2FEyUzvxbCdGUab9yZb2R+Vg1YTbBT0gMlarcu6HDEeQq9pL5APbd4IDOf0EjuYgjMnLLjJeE+saIKmNLS+SeHkhkpWnP/8TJlNZLbl5CA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804560; c=relaxed/simple; bh=DdlHN+lMe9H17G9yNb1kRBORW8GnkTPOhda2Rsx5OCw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AHj3O2U8mBurewlzO/cq86rX/9f23gUmbI+3BDwO4aBiWbTnvxkZVn30UV6dfc2trI8rJCTKzlFHKPiXO/JWLhDGOH+NBli/ZSfZmglXN0sCBUFktYVAfRwEKBOk89HKxy8K4ycC9YSUvZ5U0FB5bWSlCWfkx5M6b1NqtrROLZk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=OOojQ2h4; arc=none smtp.client-ip=209.85.208.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="OOojQ2h4" Received: by mail-ed1-f42.google.com with SMTP id 4fb4d7f45d1cf-58b0dddab63so3613110a12.3 for ; Fri, 12 Jul 2024 10:15:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1720804556; x=1721409356; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8OgNsgrmPxw01pq/WkRg7H0dk7DF2OPmdmGbajJDocU=; b=OOojQ2h4OrFhRVNKAZ6qFabdDdoj3SoCqTBRk0rJtYwzcodi9LfDe50QgPjGh33a98 vd1ch93qy605S+0StsHkjzVoA80KOE33EnE/EvygWx9TitSh9rHPVQoS4PTULb9hZU5h 6foinTon6+2QAF8OItCzmzjmjTkuE3SIrVXA88PewQT4eBU7sbp5I/K4o13/iZjyn97w FHgz7Zb8UzbeJ3mxc3pAgDoj4KBvJM9S5ByPvnVcVGkYwpAgbOWr8+RBginFFlsL5I+V OMotL3VXrwMtG+VBvZCyVmqOkdb/LNHXKmCk1xsdc4CV9bDyv+KmO56gIPQgYRntNEIB uUxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720804556; x=1721409356; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8OgNsgrmPxw01pq/WkRg7H0dk7DF2OPmdmGbajJDocU=; b=S/1BvnsA9WMSf7hQ76APXnJwxok5MBxfhdxVnBFfC6/Y75yvHl7eW5ku+HVMEq+lf+ Ho8eoZJgs1GbQd25cl+WccHVObdwipZ4fhMKJYUJzXRprDumrsr+KD4wlIub7JD4vnK5 s/Bv8MIaEv0TctJhkOYwXzs/w8FsXNO3BDctya2HkL7qzPheDkqWTNdSgbQ4deZyqGJM jIp94iR5N0cRDMKoprPMzXZgrff2mDLVCwz5+3dK9eJiWRdoeqJZFVduu04GJXPorAui Qi6F8oZ2UO0jByavIBQI/8Sl78/oghooZrZnaExQR1Ir8DqjoMQYaivTq6NoOMvpewRe TlFA== X-Gm-Message-State: AOJu0Ywf+mFQs+ipfynmRP2CZNvueMK6lrku4TdYG4sv00xA2O/wFhJb mG6g/ki/iqQwzJH81F0ggxYIRtepiV5lICYFaJ3kmyQbgrSkSIMX3D2sKGDRo9A= X-Google-Smtp-Source: AGHT+IHWM9rOX+QaXWPDHfoNHXan4UXnBWCvX4vSbYEuWi1GBa2jF8Uhp331CWL0BzvFTA7xNcTNEw== X-Received: by 2002:a17:906:6948:b0:a77:d0a0:ea6d with SMTP id a640c23a62f3a-a780b6b1c55mr734260166b.24.1720804556474; Fri, 12 Jul 2024 10:15:56 -0700 (PDT) Received: from localhost (p200300de37360a00d7e56139e90929dd.dip0.t-ipconnect.de. [2003:de:3736:a00:d7e5:6139:e909:29dd]) by smtp.gmail.com with UTF8SMTPSA id a640c23a62f3a-a780a86ed05sm362593766b.188.2024.07.12.10.15.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 10:15:56 -0700 (PDT) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, Martin Wilck Subject: [PATCH v2 25/49] libmultipath: improve dm_get_wwid() return value logic Date: Fri, 12 Jul 2024 19:14:33 +0200 Message-ID: <20240712171458.77611-26-mwilck@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712171458.77611-1-mwilck@suse.com> References: <20240712171458.77611-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Make dm_get_wwid() return different status codes for non-existing maps, maps that exists but are not multipath maps, and generic error case, and handle these return codes appropriately in callers. The error handling is als changed; dm_get_wwid() doesn't take care of making the ouput 0-terminated if anything fails. The caller is responsible for that. Change callers accordingly. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/alias.c | 11 ++++++++--- libmultipath/configure.c | 27 +++++++++++++++------------ libmultipath/devmapper.c | 22 +++++++++++++++++----- libmultipath/wwids.c | 2 +- multipathd/main.c | 7 +++++-- tests/alias.c | 10 +++++----- 6 files changed, 51 insertions(+), 28 deletions(-) diff --git a/libmultipath/alias.c b/libmultipath/alias.c index 10e58a7..c4eb5d8 100644 --- a/libmultipath/alias.c +++ b/libmultipath/alias.c @@ -408,13 +408,18 @@ static bool alias_already_taken(const char *alias, const char *map_wwid) { char wwid[WWID_SIZE]; + int rc = dm_get_wwid(alias, wwid, sizeof(wwid)); - /* If the map doesn't exist, it's fine */ - if (dm_get_wwid(alias, wwid, sizeof(wwid)) != 0) + /* + * If the map doesn't exist, it's fine. + * In the generic error case, assume that the device is not + * taken, and try to proceed. + */ + if (rc == DMP_NOT_FOUND || rc == DMP_ERR) return false; /* If both the name and the wwid match, it's fine.*/ - if (strncmp(map_wwid, wwid, sizeof(wwid)) == 0) + if (rc == DMP_OK && strncmp(map_wwid, wwid, sizeof(wwid)) == 0) return false; condlog(3, "%s: alias '%s' already taken, reselecting alias", diff --git a/libmultipath/configure.c b/libmultipath/configure.c index 666d4e8..2fdaca8 100644 --- a/libmultipath/configure.c +++ b/libmultipath/configure.c @@ -845,18 +845,21 @@ int domap(struct multipath *mpp, char *params, int is_daemon) if (mpp->action == ACT_CREATE && dm_map_present(mpp->alias)) { char wwid[WWID_SIZE]; + int rc = dm_get_wwid(mpp->alias, wwid, sizeof(wwid)); - if (dm_get_wwid(mpp->alias, wwid, sizeof(wwid)) == 0) { - if (!strncmp(mpp->wwid, wwid, sizeof(wwid))) { - condlog(3, "%s: map already present", - mpp->alias); - mpp->action = ACT_RELOAD; - } else { - condlog(0, "%s: map \"%s\" already present with WWID %s, skipping", - mpp->wwid, mpp->alias, wwid); - condlog(0, "please check alias settings in config and bindings file"); - mpp->action = ACT_REJECT; - } + if (rc == DMP_OK && !strncmp(mpp->wwid, wwid, sizeof(wwid))) { + condlog(3, "%s: map already present", + mpp->alias); + mpp->action = ACT_RELOAD; + } else if (rc == DMP_OK) { + condlog(1, "%s: map \"%s\" already present with WWID \"%s\", skipping\n" + "please check alias settings in config and bindings file", + mpp->wwid, mpp->alias, wwid); + mpp->action = ACT_REJECT; + } else if (rc == DMP_NO_MATCH) { + condlog(1, "%s: alias \"%s\" already taken by a non-multipath map", + mpp->wwid, mpp->alias); + mpp->action = ACT_REJECT; } } @@ -1320,7 +1323,7 @@ static int _get_refwwid(enum mpath_cmds cmd, const char *dev, break; case DEV_DEVMAP: - if (((dm_get_wwid(dev, tmpwwid, WWID_SIZE)) == 0) + if (((dm_get_wwid(dev, tmpwwid, WWID_SIZE)) == DMP_OK) && (strlen(tmpwwid))) refwwid = tmpwwid; diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 3fca08c..003d834 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -840,19 +840,29 @@ int dm_get_map(const char *name, unsigned long long *size, char **outparams) } } +/** + * dm_get_wwid(): return WWID for a multipath map + * @returns: + * DMP_OK if successful + * DMP_NOT_FOUND if the map doesn't exist + * DMP_NO_MATCH if the map exists but is not a multipath map + * DMP_ERR for other errors + * Caller may access uuid if and only if DMP_OK is returned. + */ int dm_get_wwid(const char *name, char *uuid, int uuid_len) { char tmp[DM_UUID_LEN]; + int rc = dm_get_dm_uuid(name, tmp); - if (dm_get_dm_uuid(name, tmp) != DMP_OK) - return 1; + if (rc != DMP_OK) + return rc; if (!strncmp(tmp, UUID_PREFIX, UUID_PREFIX_LEN)) strlcpy(uuid, tmp + UUID_PREFIX_LEN, uuid_len); else - uuid[0] = '\0'; + return DMP_NO_MATCH; - return 0; + return DMP_OK; } static int is_mpath_part(const char *part_name, const char *map_name) @@ -1388,8 +1398,10 @@ struct multipath *dm_get_multipath(const char *name) if (dm_get_map(name, &mpp->size, NULL) != DMP_OK) goto out; - if (dm_get_wwid(name, mpp->wwid, WWID_SIZE) != 0) + if (dm_get_wwid(name, mpp->wwid, WWID_SIZE) != DMP_OK) { condlog(2, "%s: failed to get uuid for %s", __func__, name); + mpp->wwid[0] = '\0'; + } if (dm_get_info(name, &mpp->dmi) != 0) condlog(2, "%s: failed to get info for %s", __func__, name); diff --git a/libmultipath/wwids.c b/libmultipath/wwids.c index 7a4cb74..aac18c0 100644 --- a/libmultipath/wwids.c +++ b/libmultipath/wwids.c @@ -295,7 +295,7 @@ should_multipath(struct path *pp1, vector pathvec, vector mpvec) struct multipath *mp = find_mp_by_wwid(mpvec, pp1->wwid); if (mp != NULL && - dm_get_wwid(mp->alias, tmp_wwid, WWID_SIZE) == 0 && + dm_get_wwid(mp->alias, tmp_wwid, WWID_SIZE) == DMP_OK && !strncmp(tmp_wwid, pp1->wwid, WWID_SIZE)) { condlog(3, "wwid %s is already multipathed, keeping it", pp1->wwid); diff --git a/multipathd/main.c b/multipathd/main.c index 442a154..1e7a6ac 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -726,8 +726,11 @@ add_map_without_path (struct vectors *vecs, const char *alias) condlog(3, "%s: cannot access table", mpp->alias); goto out; } - if (!strlen(mpp->wwid)) - dm_get_wwid(mpp->alias, mpp->wwid, WWID_SIZE); + if (!strlen(mpp->wwid) && + dm_get_wwid(mpp->alias, mpp->wwid, WWID_SIZE) != DMP_OK) { + condlog(3, "%s: cannot obtain WWID", mpp->alias); + goto out; + } if (!strlen(mpp->wwid)) condlog(1, "%s: adding map with empty WWID", mpp->alias); conf = get_multipath_config(); diff --git a/tests/alias.c b/tests/alias.c index 1f78656..a95b308 100644 --- a/tests/alias.c +++ b/tests/alias.c @@ -84,7 +84,7 @@ int __wrap_dm_get_wwid(const char *name, char *uuid, int uuid_len) check_expected(uuid_len); assert_non_null(uuid); ret = mock_type(int); - if (ret == 0) + if (ret == DMP_OK) strcpy(uuid, mock_ptr_type(char *)); return ret; } @@ -438,14 +438,14 @@ static void mock_unused_alias(const char *alias) { expect_string(__wrap_dm_get_wwid, name, alias); expect_value(__wrap_dm_get_wwid, uuid_len, WWID_SIZE); - will_return(__wrap_dm_get_wwid, 1); + will_return(__wrap_dm_get_wwid, DMP_NOT_FOUND); } static void mock_self_alias(const char *alias, const char *wwid) { expect_string(__wrap_dm_get_wwid, name, alias); expect_value(__wrap_dm_get_wwid, uuid_len, WWID_SIZE); - will_return(__wrap_dm_get_wwid, 0); + will_return(__wrap_dm_get_wwid, DMP_OK); will_return(__wrap_dm_get_wwid, wwid); } @@ -471,14 +471,14 @@ static void mock_self_alias(const char *alias, const char *wwid) do { \ expect_string(__wrap_dm_get_wwid, name, alias); \ expect_value(__wrap_dm_get_wwid, uuid_len, WWID_SIZE); \ - will_return(__wrap_dm_get_wwid, 1); \ + will_return(__wrap_dm_get_wwid, DMP_NOT_FOUND); \ } while (0) #define mock_used_alias(alias, wwid) \ do { \ expect_string(__wrap_dm_get_wwid, name, alias); \ expect_value(__wrap_dm_get_wwid, uuid_len, WWID_SIZE); \ - will_return(__wrap_dm_get_wwid, 0); \ + will_return(__wrap_dm_get_wwid, DMP_OK); \ will_return(__wrap_dm_get_wwid, "WWID_USED"); \ expect_condlog(3, USED_STR(alias, wwid)); \ } while(0) From patchwork Fri Jul 12 17:14:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13732074 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2F68417BCD for ; Fri, 12 Jul 2024 17:15:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804561; cv=none; b=dFh+tD7QOgQRpMiv62eFlWvZ/d770HI5jklOHXRDYWdOx8dZiipxUAU4L5Ob8U1TAYYkOUJVd64Dcz8mVtQUHDJ9LxamIJNC9m9oijt0fkfa+iEgaEuzIx4Agr8V6zomXFvrlTtMXfR49gO/t3IXgG2ANsyetRPZtrbRQYouJ2k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804561; c=relaxed/simple; bh=QDptvS7uYoQvzzR+xQFWt+pz4LwOXTTRapQrykmxxu8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tzWgP983gV6kWAegWB0IFhXJiaovpxuH/HM+2991Rq8jhRQyC+eXVqw0bvLI10J4xP9N9uhSeJbRqwnZtP6gEzzC3fu7oDsZL0Goe7Rrr7sg/tJcNEcm+kZM6Ufe/xa5Fc9p+yuh/UDotC8/N8lgUHLJw5j3l4u/h3C4CVg7pyo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=RCaEpAYa; arc=none smtp.client-ip=209.85.208.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="RCaEpAYa" Received: by mail-ed1-f50.google.com with SMTP id 4fb4d7f45d1cf-58b447c51bfso2871445a12.2 for ; Fri, 12 Jul 2024 10:15:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1720804557; x=1721409357; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4e/tyY2eQGPT+A/M6tl3n8h+9lLbt+diAgdDFdeZx4U=; b=RCaEpAYazTmtwt1v0hZ4IPs8b+lceAHCrGz/rYbyRqOnedVwUsruh4Jbkt0wExhEYX 5/Iu6KocavGmaCHkV/DRaxW71goxt1pXm9PHXZ8ZA28fe7kONwI0/ajNGXmbPgKaksBa xWamZB1+kR1Kr1SPMu2e9RENUQ0Lrwx91x82yZsUzTNe9wCjex50ebVHRAlGkj5H4yJx rGCnv6opX0xm4ftrMS2Jzz7EcYOwMCW8ljgeDasXKDx7OSuaCU2kTZh0wwT+CSoZ4syW WzDigHf0h8Id3sSVMq3yYozL1jiDkOMZh+aRZRJY0+iLKOy7nxV1DxXJBFXTCjX+e96L bPaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720804557; x=1721409357; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4e/tyY2eQGPT+A/M6tl3n8h+9lLbt+diAgdDFdeZx4U=; b=EKMqKklxL5HO8xqddzqDIpfDMN06WE/a6SXgucJXAGyDMx8/RFP/z6UTQY0AOX4IqO tMJ0P7LaDhEDixX5egtm44SoRj+alPInOO0ZLnNuTGxjT15o6myfQdWSZGfTA8ECuFWd Dq8RbU7fUrMoz5Jx8wJV3hDA6kzsSmtoJ36/52nv7ukhKJC4VLfGa6RmFjg/Tgjw54wP CfW6TMFOXOz4WX2bA3KG+uUJ5Ig6ihCMLzHh6LcMGWHMnmkaUmcSQI5ZiUuboReCG2oi idAAzWL/DwfB5OICj504CXp5k9pjBF2cDZZt5y92hLxnhoaBUPgb7toQEzD6xyKzWz/z 9t4g== X-Gm-Message-State: AOJu0YzmHATitlEpwCgDGkgu0VK34YYmaXPP/jtT+loIlQvlKukOwc28 +aUhVy8ZgQCsvK/6GPKgnHeQwepEizUxZPH7IuB19J5TRmpKSJSDWKa3f33O01JCfvAIRRfaC+F b X-Google-Smtp-Source: AGHT+IH6mXn/Tjko/IHwYd5eordoPwbHTy17bhELqIenUf8M5Vfum344ZMDXYFuBCKcaizOsTodWWQ== X-Received: by 2002:a50:eac6:0:b0:578:6c19:4801 with SMTP id 4fb4d7f45d1cf-594bb5807a2mr7712658a12.22.1720804557463; Fri, 12 Jul 2024 10:15:57 -0700 (PDT) Received: from localhost (p200300de37360a00d7e56139e90929dd.dip0.t-ipconnect.de. [2003:de:3736:a00:d7e5:6139:e909:29dd]) by smtp.gmail.com with UTF8SMTPSA id 4fb4d7f45d1cf-5994d1ff8edsm1254391a12.18.2024.07.12.10.15.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 10:15:57 -0700 (PDT) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, Martin Wilck Subject: [PATCH v2 26/49] libmultipath: reimplement dm_map_name() with new API Date: Fri, 12 Jul 2024 19:14:34 +0200 Message-ID: <20240712171458.77611-27-mwilck@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712171458.77611-1-mwilck@suse.com> References: <20240712171458.77611-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/devmapper.c | 34 ++++++---------------------------- 1 file changed, 6 insertions(+), 28 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 003d834..8af4167 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -1481,37 +1481,15 @@ dm_is_suspended(const char *name) return info.suspended; } -char * -dm_mapname(int major, int minor) +char *dm_mapname(int major, int minor) { - char * response = NULL; - const char *map; - struct dm_task *dmt; - int r; + char name[WWID_SIZE]; - if (!(dmt = libmp_dm_task_create(DM_DEVICE_INFO))) + if (libmp_mapinfo(DM_MAP_BY_DEV, + (mapid_t) { ._u = { major, minor } }, + (mapinfo_t) { .name = name }) != DMP_OK) return NULL; - - if (!dm_task_set_major(dmt, major) || - !dm_task_set_minor(dmt, minor)) - goto bad; - - r = libmp_dm_task_run(dmt); - if (!r) { - dm_log_error(2, DM_DEVICE_INFO, dmt); - goto bad; - } - - map = dm_task_get_name(dmt); - if (map && strlen(map)) - response = strdup((const char *)map); - - dm_task_destroy(dmt); - return response; -bad: - dm_task_destroy(dmt); - condlog(0, "%i:%i: error fetching map name", major, minor); - return NULL; + return strdup(name); } static int From patchwork Fri Jul 12 17:14:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13732075 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 48ADB176FDF for ; Fri, 12 Jul 2024 17:16:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804562; cv=none; b=IoMKV7PTB7jmnLSypGGUcCwbbcA69B00HSADO7qNhi8BKbtf4TXw3pXoyhSnyqYA12wgqVq3use9Rix1xyyAhOmASKH8+HNHEV8kPNEBeji1gHeZ8IrPhVqEpTMU+HFseLy3reGssx27OBfziR4p/lIWxGvZ30vZAOZyQX18LyA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804562; c=relaxed/simple; bh=H3lbTgafBwE3FdhWe5HVIIU74OtJhuUVMb2JQCJ/2Ns=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VTPq6dlZQ3jHLsb/gGa1MLdcCWTRyPpzKQBB1cAfCXQFQbXp648kDSstHbYlUt+n3hB8YIiQMudBrIJV5PjG1B1Dl2kMxwNvIJ6SHuQAZ/iweP3JMSkSAEGwVQHqU6WwYxAyI/crrJhmPA2BFYxieEeARoDt0TKNfKpYMdexUv0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=G705/Alr; arc=none smtp.client-ip=209.85.167.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="G705/Alr" Received: by mail-lf1-f47.google.com with SMTP id 2adb3069b0e04-52ea929ea56so4443126e87.0 for ; Fri, 12 Jul 2024 10:16:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1720804558; x=1721409358; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=USesQfSeVdBwIDVYLPok92k5IMH0ABwZ/Vwmqq5x8bk=; b=G705/Alr/1j4QBcRx5H6BXWHeZCtBh031xTpp+Dpvr9CsNJJRiuAS1jekYx94Fdc5S L+3nzzPXIau6WuX5lsJXDb+RKD828dSx+FOQN5rss5hUnRx5+advcdeCPVNQ0Aj8fgEG JK3rXsrzdX/60RMLwZGDOSX4qF1OhvPWzQqKogo5Gzzqzy5rWLDW0CsDr0CgIMGXq10a CDu1T7Hq2JoeQa6bWbY8yNHJgRfyqFIfnk1TMQ3utZ1sefqt0emKx8svTZjvrV08aCnW dQMYZBF57lfihoM4aj2pRJGuN20uFSKRPyga5A1rp5uOopoCLPXIm/efQixQkzFhJnIb AV7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720804558; x=1721409358; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=USesQfSeVdBwIDVYLPok92k5IMH0ABwZ/Vwmqq5x8bk=; b=uEDIMuxyrufg+CvmLkDKvV9W7gNL2qfjeZe6UiqbTfRVPB/v6szBk8RJ4Z63FcLOGm BbN6aPnaN6jLmcdPOmkquJ/uBUgB7iuDWqkkKzKJ1AT/s+/70Da7bFItkSu/2Z1aHZGj k4Z8NJvtUY+p4F6G9J4SVQWYkVkEjUFfwZD2ub4MWHFbRUlpah9YW2s4RXRqxzMx/2J+ OzPj4PinwcWFHz59k1KkS9wNSC33uwpJElv95GtEkhHjjbJzfOG63fPYWujsw577G7FE V4+5I8Y8n/7EacbVyyvPJtrjonZTiBwqXCNcrfKhzyEar9HpH2m5whnhjJsln9XCVNEN r89A== X-Gm-Message-State: AOJu0YxIKKdApCxN44Mbvu/40PNi7BBNhhb6aglqvwGt4GcZqbL2k/oU HH0mKOkCqCYYRrJ+14glOWeRz/S7zCvm5iEVHDxa4116Im2w22ESeavgNYzLwk0= X-Google-Smtp-Source: AGHT+IE5IltU5Fl3275ShY3BBch2lNKEjjXZNShGvY18YdMLombzYI2EOsyyk1g3W1tFEWmrHJKQCw== X-Received: by 2002:ac2:4db5:0:b0:52e:932d:88ab with SMTP id 2adb3069b0e04-52eb999c206mr8476336e87.23.1720804558372; Fri, 12 Jul 2024 10:15:58 -0700 (PDT) Received: from localhost (p200300de37360a00d7e56139e90929dd.dip0.t-ipconnect.de. [2003:de:3736:a00:d7e5:6139:e909:29dd]) by smtp.gmail.com with UTF8SMTPSA id a640c23a62f3a-a780a854368sm359363666b.155.2024.07.12.10.15.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 10:15:58 -0700 (PDT) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, Martin Wilck Subject: [PATCH v2 27/49] libmultipath: reimplement dm_map_present_by_uuid() Date: Fri, 12 Jul 2024 19:14:35 +0200 Message-ID: <20240712171458.77611-28-mwilck@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712171458.77611-1-mwilck@suse.com> References: <20240712171458.77611-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 ... and rename it to dm_map_present_by_wwid(). Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/devmapper.c | 47 ++++++---------------------------------- libmultipath/devmapper.h | 2 +- libmultipath/valid.c | 2 +- tests/valid.c | 10 ++++----- 4 files changed, 14 insertions(+), 47 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 8af4167..5cada4c 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -1023,49 +1023,16 @@ out: return r; } -/* - * Return - * 1 : map with uuid exists - * 0 : map with uuid doesn't exist - * -1 : error - */ -int -dm_map_present_by_uuid(const char *uuid) +int dm_map_present_by_wwid(const char *wwid) { - struct dm_task *dmt; - struct dm_info info; - char prefixed_uuid[WWID_SIZE + UUID_PREFIX_LEN]; - int r = -1; + char tmp[DM_UUID_LEN]; - if (!uuid || uuid[0] == '\0') - return 0; + if (safe_sprintf(tmp, UUID_PREFIX "%s", wwid)) + return DMP_ERR; - if (safe_sprintf(prefixed_uuid, UUID_PREFIX "%s", uuid)) - goto out; - - if (!(dmt = libmp_dm_task_create(DM_DEVICE_INFO))) - goto out; - - if (!dm_task_set_uuid(dmt, prefixed_uuid)) - goto out_task; - - if (!libmp_dm_task_run(dmt)) { - dm_log_error(3, DM_DEVICE_INFO, dmt); - goto out_task; - } - - if (!dm_task_get_info(dmt, &info)) - goto out_task; - - r = !!info.exists; - -out_task: - dm_task_destroy(dmt); -out: - if (r < 0) - condlog(3, "%s: dm command failed in %s: %s", uuid, - __FUNCTION__, strerror(errno)); - return r; + return libmp_mapinfo(DM_MAP_BY_UUID, + (mapid_t) { .str = tmp }, + (mapinfo_t) { .name = NULL }); } static int dm_dev_t (const char *mapname, char *dev_t, int len) diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h index 25e0504..4c8f345 100644 --- a/libmultipath/devmapper.h +++ b/libmultipath/devmapper.h @@ -127,7 +127,7 @@ int dm_simplecmd_flush (int task, const char *name, uint16_t udev_flags); int dm_simplecmd_noflush (int task, const char *name, uint16_t udev_flags); int dm_addmap_create (struct multipath *mpp, char *params); int dm_addmap_reload (struct multipath *mpp, char *params, int flush); -int dm_map_present_by_uuid(const char *uuid); +int dm_map_present_by_wwid(const char *uuid); int dm_get_map(const char *name, unsigned long long *size, char **outparams); int dm_get_status(const char *name, char **outstatus); diff --git a/libmultipath/valid.c b/libmultipath/valid.c index f223778..9267cef 100644 --- a/libmultipath/valid.c +++ b/libmultipath/valid.c @@ -360,7 +360,7 @@ is_path_valid(const char *name, struct config *conf, struct path *pp, if (check_wwids_file(pp->wwid, 0) == 0) return PATH_IS_VALID_NO_CHECK; - if (dm_map_present_by_uuid(pp->wwid) == 1) + if (dm_map_present_by_wwid(pp->wwid) == DMP_OK) return PATH_IS_VALID; /* all these act like FIND_MULTIPATHS_STRICT for finding if a diff --git a/tests/valid.c b/tests/valid.c index 18a5a7b..a93bbe5 100644 --- a/tests/valid.c +++ b/tests/valid.c @@ -189,7 +189,7 @@ int __wrap_check_wwids_file(char *wwid, int write_wwid) return -1; } -int __wrap_dm_map_present_by_uuid(const char *uuid) +int __wrap_dm_map_present_by_wwid(const char *uuid) { int ret = mock_type(int); assert_string_equal(uuid, mock_ptr_type(char *)); @@ -271,8 +271,8 @@ static void setup_passing(char *name, char *wwid, unsigned int check_multipathd, will_return(__wrap_check_wwids_file, wwid); if (stage == STAGE_CHECK_WWIDS) return; - will_return(__wrap_dm_map_present_by_uuid, 0); - will_return(__wrap_dm_map_present_by_uuid, wwid); + will_return(__wrap_dm_map_present_by_wwid, 0); + will_return(__wrap_dm_map_present_by_wwid, wwid); } static void test_bad_arguments(void **state) @@ -516,8 +516,8 @@ static void test_check_uuid_present(void **state) memset(&pp, 0, sizeof(pp)); conf.find_multipaths = FIND_MULTIPATHS_STRICT; setup_passing(name, wwid, CHECK_MPATHD_RUNNING, STAGE_CHECK_WWIDS); - will_return(__wrap_dm_map_present_by_uuid, 1); - will_return(__wrap_dm_map_present_by_uuid, wwid); + will_return(__wrap_dm_map_present_by_wwid, 1); + will_return(__wrap_dm_map_present_by_wwid, wwid); assert_int_equal(is_path_valid(name, &conf, &pp, true), PATH_IS_VALID); assert_string_equal(pp.dev, name); From patchwork Fri Jul 12 17:14:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13732076 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-ej1-f49.google.com (mail-ej1-f49.google.com [209.85.218.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 64D8616191E for ; Fri, 12 Jul 2024 17:16:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804565; cv=none; b=IBvl6V4vsyjaroDSHovV4LAHK/VQPQB2zd//h1yTjXoxk6x8dti8uJo6GPyrk7rRTPOopiO38+jfd+JFys5uff0wAeNFO68GfMOA1fvdVWdQiObRRob0QBDiRiRtUR3XL63W6oKNm9KAYmBZXikIA67vAfiifjvvNfjrPkGrlO4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804565; c=relaxed/simple; bh=iJMaFNNxmTL2IibeLRCmVUpqO6YCMoHUHwxljp9/wfU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ntdEKNs3kG0j6aBADnc6eJ7ClvuHa4TXWUlV4AV6elQVhfX56HmaLs0Q0iH2X9M2HK+eFaO5OD7sMBmKULDCPUARDZK1BxsAB+rsI97YBCRgmc1j+mehfkiOm48mqC2WfsQb9BUozMmJJSA+Igek8Ih1ys6V/dR/3rlcIRXXmo0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=X2Vvr6Zk; arc=none smtp.client-ip=209.85.218.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="X2Vvr6Zk" Received: by mail-ej1-f49.google.com with SMTP id a640c23a62f3a-a77c2d89af8so291976166b.2 for ; Fri, 12 Jul 2024 10:16:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1720804562; x=1721409362; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5hOW0DVeC6Jzop7KNSYiOpbwl+glUBvDsj/EU75kw7A=; b=X2Vvr6ZkV2ZB/7FbM4Rd1uzqmsEaJQcr1xh7q7PuVjnZN73IyCnC4ZK7MsvxL54VjA zt9+McKgxH0e+SYzLwWvr5gbgRAMq4ZBkN9wWtJJ/d1pMriFJE97ZbiXSMEwCizcYHKC dWOoVyUUPVdOPDgGHcOlHcx7+iYkKlQNq/vlbksXg6MHIt3SUel5FA9TBFtfqN+A0xnx kwrFnoyxtn1Mk9NQe0ipAkGYThDyH5hWtMUwvqZF205A7nJ1NOjjL9Q1uR6jqtUYQw9X Fbx226cjBVlfqsUKllW5Vz/BdiEMoq1TOMD7RPWtFFjA7+cV3D3D8+0bzv9zExHvN2Pi 8bgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720804562; x=1721409362; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5hOW0DVeC6Jzop7KNSYiOpbwl+glUBvDsj/EU75kw7A=; b=Bow5r4doagmJ+2C8tvUiz7+1xGhbIkjtOaIE59H3gA78bCHZrDloLhHNjxhPQyuJmS +0CX5SU2yVvCcZS7p2sUBHFXl90KslQ7Ms6xknJG9KDDE3FiE0E5w//v3dN6sGyCoxPG p/WCz7aBzfbio/k8AQ0rpeYdGTtM5HuhG2Uz6f1cqDZLMgENeWIOwgyQaA9GCDcLFcbD wTSwl0Fw+X+i7yI3Z61AxqoCPgg/dtn4RLMQ/bhesB4Y1Jidtx2B/gMlbsSfJNY9OfIn q59MPV4yQXdybRIsXhfTqikZz8rVIoDutGeJ8Ewtli5Wp+SJ2plOgjDdt7LYcMNN+wiT Mpfg== X-Gm-Message-State: AOJu0YxcmUU6sI76147sXQePWU5PI3MCGy986vZhZ6xpXrwL24yhdi71 Xnz6qUGXG9myLQ6ixPok/TaMJXlX4j1aGj9jhT5/yetDlKYek1RGQnuAPHy2Z6BC+dWOOcKRHDX K X-Google-Smtp-Source: AGHT+IGgRVv1fjkIfbg0pNhHj/1Nz+OIyHaXnJw2InVxQUExok6Cp7G70/KHqc412Ush6mXYAhKQGg== X-Received: by 2002:a17:907:9496:b0:a77:e2e3:3557 with SMTP id a640c23a62f3a-a780b884a19mr1027743266b.57.1720804559690; Fri, 12 Jul 2024 10:15:59 -0700 (PDT) Received: from localhost (p200300de37360a00d7e56139e90929dd.dip0.t-ipconnect.de. [2003:de:3736:a00:d7e5:6139:e909:29dd]) by smtp.gmail.com with UTF8SMTPSA id a640c23a62f3a-a780a6e172csm363285066b.86.2024.07.12.10.15.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 10:15:59 -0700 (PDT) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, Martin Wilck Subject: [PATCH v2 28/49] libmultipath: reimplement dm_get_opencount() with new API Date: Fri, 12 Jul 2024 19:14:36 +0200 Message-ID: <20240712171458.77611-29-mwilck@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712171458.77611-1-mwilck@suse.com> References: <20240712171458.77611-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/devmapper.c | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 5cada4c..47ff827 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -1048,34 +1048,14 @@ static int dm_dev_t (const char *mapname, char *dev_t, int len) return 0; } -int -dm_get_opencount (const char * mapname) +int dm_get_opencount (const char *mapname) { - int r = -1; - struct dm_task *dmt; struct dm_info info; - if (!(dmt = libmp_dm_task_create(DM_DEVICE_INFO))) - return 0; + if (dm_get_info(mapname, &info) != DMP_OK) + return -1; - if (!dm_task_set_name(dmt, mapname)) - goto out; - - if (!libmp_dm_task_run(dmt)) { - dm_log_error(3, DM_DEVICE_INFO, dmt); - goto out; - } - - if (!dm_task_get_info(dmt, &info)) - goto out; - - if (!info.exists) - goto out; - - r = info.open_count; -out: - dm_task_destroy(dmt); - return r; + return info.open_count; } int From patchwork Fri Jul 12 17:14:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13732077 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6159817736 for ; Fri, 12 Jul 2024 17:16:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804566; cv=none; b=iVXrrT/CJdMuObcTXp13ZV+shkPrFtkIFLX1LTIQsj2kZb/RTjxlEvoJsw1fVmd7fkkzaKFNVH5lb+hritrfQxn9VDpRW8oOYzLnl93tOaXp+N7dQEp8XNc5R/HGDNFmS5juFW4yZyPWJ487KiW2UDBIxDauzfNizDG+X1LREHE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804566; c=relaxed/simple; bh=HF3j0dbEr3yuUCnuLfxqfJBJ5H75iSUG0ZhKAGRsb3Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qm36wRQoEQrnDSRobCua3A7AmFDdGGFUdk++P4sYATvXVBtnY+d3AmbBmdNMXnHikzjeRR3uESYT+yt+/hoLtIkusplZ3KWl15KiHI6EPHMPe2Gh2GSWELHo+CCO3Xda4k4FkCx72KKg4BNCkIZXQj04qExqY4t+X20lp0bPFK4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=ZbgTZDsg; arc=none smtp.client-ip=209.85.218.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="ZbgTZDsg" Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-a77e5929033so316013866b.0 for ; Fri, 12 Jul 2024 10:16:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1720804563; x=1721409363; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vfjcoQiCbIhNP7HJ5CwzQFMqhlKc4fWC00aaqfOdGmo=; b=ZbgTZDsg0CtCMjfjd4g/mK3wWpM+lsLm1rryi0RlbBc/oJIMs15uECQ6AOl+guOr/L FbsBo1nBxy93MUQnCxx1zfuIS4s4In5V26ryNMgFyzkEqoc6DRdEOZxc+ULU8Cnm3hBR mFLGHPUeGkoC45s9gNx1yHbXxhC9NWuQVj/Zr71Tw2o/WAjwzhdGhx5JSK5G0D3rA0rZ 4hI4TM8r8S3uHi+oC9XgXjsf6l4GcC1QuqdGcciz+aal/aP01CLZpVX6wkzkNwW6qIuV QE1okcIhq71rVuXjMvOlFiUjeDztK5KKR9BXONtYSKl/R8D5OeiijEsGjh3S+BLvn6fY 8jLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720804563; x=1721409363; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vfjcoQiCbIhNP7HJ5CwzQFMqhlKc4fWC00aaqfOdGmo=; b=JHrUBcL2qNsZPG1VnEW835iVUTYeXQw+doZRWtbTft8SLih2Jykp0axwzP8Hm0/iA+ J1mYa8BJ0Hc5sRXZFtUVk5zI4T1fll5Ar14pC4B7FnmAcse/GkKhioJFdwnYMHP9KL6C 55tz3OFyluPubhD/GQ1Zzno7T54Q8C1pJbhpSe7LQ7gQq6VTPFWcl0xiG+tHR6LEZQHe uJFAKAOmlXudAxh7qOoozg7R3zqrVRXKZkb7p5CLUbc1R2gwC2AvU5AZ/K3bkqy1PQvE VSPA0n+HVcrGsQIm80WFONGQJpfeFN+77jDUdhhzfjlaLgUL+qWVdKX2gYBJLJhEmhpa s3Zw== X-Gm-Message-State: AOJu0YxMECeDcBtlJCyTedlpLhB6L9Zo9wBYmJU98C/L8g5+qhKmhAah XuiwiX6dd9s3msVGVLgquHQ1QFyDWhFoBtiGn4gRPmXImeG8uYSQDvo8/yx9ajw= X-Google-Smtp-Source: AGHT+IHW4rYyxOCU3j7UDKmNPsLEpML2Oikz2+ctVToq7O6REUoKHpXYdHwWNVs+b01MqQnjpGdSig== X-Received: by 2002:a17:906:6149:b0:a6f:ba77:e677 with SMTP id a640c23a62f3a-a780b89ca10mr741615466b.73.1720804562658; Fri, 12 Jul 2024 10:16:02 -0700 (PDT) Received: from localhost (p200300de37360a00d7e56139e90929dd.dip0.t-ipconnect.de. [2003:de:3736:a00:d7e5:6139:e909:29dd]) by smtp.gmail.com with UTF8SMTPSA id a640c23a62f3a-a780a6bc80asm360141966b.7.2024.07.12.10.16.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 10:16:02 -0700 (PDT) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, Martin Wilck Subject: [PATCH v2 29/49] libmpathpersist: skip redundant dm_map_present() call Date: Fri, 12 Jul 2024 19:14:37 +0200 Message-ID: <20240712171458.77611-30-mwilck@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712171458.77611-1-mwilck@suse.com> References: <20240712171458.77611-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 dm_is_mpath() returns 0 if the map does not exist, the additional dm_map_present() call is not necessary. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmpathpersist/mpath_persist_int.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libmpathpersist/mpath_persist_int.c b/libmpathpersist/mpath_persist_int.c index 6da0401..5a5ac3b 100644 --- a/libmpathpersist/mpath_persist_int.c +++ b/libmpathpersist/mpath_persist_int.c @@ -185,7 +185,7 @@ static int mpath_get_map(vector curmp, vector pathvec, int fd, char **palias, condlog(3, "alias = %s", alias); - if (dm_map_present(alias) && dm_is_mpath(alias) != DM_IS_MPATH_YES) { + if (dm_is_mpath(alias) != DM_IS_MPATH_YES) { condlog(3, "%s: not a multipath device.", alias); goto out; } From patchwork Fri Jul 12 17:14:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13732078 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-lj1-f181.google.com (mail-lj1-f181.google.com [209.85.208.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9BFD3176FDF for ; Fri, 12 Jul 2024 17:16:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804567; cv=none; b=EUX6Zzs2wfPFqr06mIXpKZTqwZHrlvPayH38JB0h9tliUGZA3ko5RA11HKGST+XBFaFSd/LGfdBSybZ28sqwJvkuzpXPrPiLqtIlYlV2/tN9bq+wu255KN0V05RgUJTFZDY2+GrDdvaIAsFY4j8NO4nkvxDIS8hztMhSrh+ypnw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804567; c=relaxed/simple; bh=CpUi9ryYZ9UT1cESP/YEM9Hlk43mDR6clCNFL3HA4S8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QrW9bQurKcKtDm6MIW6H89Vx/M2TbcNtlzLMrBOtb27pQdyc+O82JaWJ/QXceE+Mcw0afE9TxzfuGU+xV/TF/o6QZ/hF0cxQGhjbbS+nO/S4VARiBU2kM0Iznp9yDqzj6ALsOSbkPRuERwVBiOwWww/PbAGT39zq60ZSk7Mr7tw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=SLYOuuAZ; arc=none smtp.client-ip=209.85.208.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="SLYOuuAZ" Received: by mail-lj1-f181.google.com with SMTP id 38308e7fff4ca-2eeb2d60efbso26562491fa.1 for ; Fri, 12 Jul 2024 10:16:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1720804564; x=1721409364; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9Wn1uWuzvav9H0JMIm7n9qmYN7T2+TrD9QXFyG47DaU=; b=SLYOuuAZMXgQLv2rB7bBddqs5pI8eXkmKG0xE6xFI9fWL+PtJanOt6+VZ82VHSUG7Z EVzkmMloqZxfj20WsHpZjSHOi65W4sVkeX/Rn1vK5KMrfeTH4I8IYq0xRJ5YytU1q0st ljCei/SR0+sZYKyHuTc/zyt6PtxpPlQTY8jgY6mFC8Hi+IMke/JC6eYJ1AGd6qEz8f+/ OT0I8MtcSjVScqFvtMuFfrLCjocE46ZMXdSH176xD3eyPA9SuM/oUage7KWTNdu/nhp5 Z2spznqmDLuw87c/S3MsoNReywZYpvUfl04/EfrfIYNdA9udGJVdhepmUwks09YNrDDx GzRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720804564; x=1721409364; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9Wn1uWuzvav9H0JMIm7n9qmYN7T2+TrD9QXFyG47DaU=; b=ZbD9AvQJ0+J/ZIm1BQ6yFFPPaJ6J3yUc+8oXno5HtGL+TXDmyTuNukDib/8qxjFy7S ojN7OHTMEUNq5pmB+qFm29MbNkmU+rDPRUaDnelheTQgsSRyyfNTg6l5PAk9mD+Ep8eb zzkAf9EtwvsUVBWvXShyx31sOxXvTMRB+H9XcEoH47RncGnkQFsh5f+V0papQc/skvd+ GznAQie4th5TeB7fg7KMjc25ALIwUEZ9zGP1FYj+ZUdUvb67e+pNd1jjGCFnwDYH12od o1bGXSHqqNhTEpQzJNc2CkKSUNNjFCofTodUdPYQmwxPLEwQQIWhrmXCPRsRReRvJp5f 9Rmw== X-Gm-Message-State: AOJu0YxF+E1wtZRkCTKbpCaarAm5yrXv7aMR9ST2tf6k8qTax0JV20in qP00Cc4eyo+DiV9F4pIwnc3LDEc8w32q5krKu6Bvgwt6qB5+CuOsVZeSNl/SzV8= X-Google-Smtp-Source: AGHT+IEDTQkNEliO3LAvvSVzWzYKOSDroZNbLcgpw5OIRuYBnKGteYHyesVZ+RX+Ka40TAiHRvA9kg== X-Received: by 2002:a2e:a4ad:0:b0:2ec:3d2e:2408 with SMTP id 38308e7fff4ca-2eeb317175emr80829981fa.33.1720804563611; Fri, 12 Jul 2024 10:16:03 -0700 (PDT) Received: from localhost (p200300de37360a00d7e56139e90929dd.dip0.t-ipconnect.de. [2003:de:3736:a00:d7e5:6139:e909:29dd]) by smtp.gmail.com with UTF8SMTPSA id 4fb4d7f45d1cf-594bb96042fsm4766405a12.5.2024.07.12.10.16.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 10:16:03 -0700 (PDT) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, Martin Wilck Subject: [PATCH v2 30/49] libmultipath: implement dm_is_mpath() with new API Date: Fri, 12 Jul 2024 19:14:38 +0200 Message-ID: <20240712171458.77611-31-mwilck@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712171458.77611-1-mwilck@suse.com> References: <20240712171458.77611-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/devmapper.c | 59 ++++++++++------------------------------ 1 file changed, 15 insertions(+), 44 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 47ff827..11bccb1 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -975,52 +975,23 @@ static int dm_type_match(const char *name, char *type) int dm_is_mpath(const char *name) { - int r = DM_IS_MPATH_ERR; - struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; - struct dm_info info; - uint64_t start, length; - char *target_type = NULL; - char *params; - const char *uuid; + char uuid[DM_UUID_LEN]; + int rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY, + (mapid_t) { .str = name }, + (mapinfo_t) { .uuid = uuid }); - if (!(dmt = libmp_dm_task_create(DM_DEVICE_TABLE))) - goto out; - - if (!dm_task_set_name(dmt, name)) - goto out; - - if (!libmp_dm_task_run(dmt)) { - dm_log_error(3, DM_DEVICE_TABLE, dmt); - goto out; + switch (rc) { + case DMP_OK: + if (!strncmp(uuid, UUID_PREFIX, UUID_PREFIX_LEN)) + return DM_IS_MPATH_YES; + /* fallthrough */ + case DMP_NOT_FOUND: + case DMP_NO_MATCH: + return DM_IS_MPATH_NO; + case DMP_ERR: + default: + return DM_IS_MPATH_ERR; } - - if (!dm_task_get_info(dmt, &info)) - goto out; - - r = DM_IS_MPATH_NO; - - if (!info.exists) - goto out; - - uuid = dm_task_get_uuid(dmt); - - if (!uuid || strncmp(uuid, UUID_PREFIX, UUID_PREFIX_LEN) != 0) - goto out; - - /* Fetch 1st target */ - if (dm_get_next_target(dmt, NULL, &start, &length, &target_type, - ¶ms) != NULL) - /* multiple targets */ - goto out; - - if (!target_type || strcmp(target_type, TGT_MPATH) != 0) - goto out; - - r = DM_IS_MPATH_YES; -out: - if (r == DM_IS_MPATH_ERR) - condlog(3, "%s: dm command failed in %s: %s", name, __func__, strerror(errno)); - return r; } int dm_map_present_by_wwid(const char *wwid) From patchwork Fri Jul 12 17:14:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13732079 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4D09C174EF8 for ; Fri, 12 Jul 2024 17:16:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804568; cv=none; b=W0JqAclCuJw4tidO4L4wBTiCQEUuAdY0brpWV8JKhQUl4Shxj421Md7Y5So4BlaPQUA8H7j0TXaE3njzKCylIHFNdlNlM2wdoKscufpz341cAPYaQ0G/vxaJ1bO3IT8n9FUBXLPjMzasbymFdu9LJKpLDeSbDTrJsQbscwR0UiY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804568; c=relaxed/simple; bh=oESVIlTvO/5abDWegJygZFZAnJNqDSMmX8tBYhUIsR0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L1iffSGG0Au9KUo93VsgbMTKjDtJkAv7vcsYSaF1KyiY6wKK5QatfUcnQ7gRksVAI85wHKb0csPlATjFqrd7OqNfLp9A3fpOsP061u/UkwXMv6Vwcf02bSGGYHe5i1bd7IxlbNaYwfYiFJywPQXg0L14wYxUfbreptknfIWkveI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=HCxNRIIX; arc=none smtp.client-ip=209.85.218.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="HCxNRIIX" Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-a77c1658c68so279309966b.0 for ; Fri, 12 Jul 2024 10:16:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1720804565; x=1721409365; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=I7N36qMCpcSl6TETGX5COtXj99LlnsyTYf2d/0laR8c=; b=HCxNRIIXvJFWOAVDekOhuqzoY1Y9bJx25M0kw7WnapwRxS3BbMsPEgqU9KDF1J6FUY ZFSXmT0dLkFzgt+xiyVE5VuhlPWacfV3Zkh7YXZJliJc6VEa0fHq+l/Qmok2jdwNakLa Cnonbwavivx/CRiorsIb4hSsb1jq9QwgkMuRVt82s/RSi+Fc0DVaiMBSWlzY/hCI5NvI ZK4N7Ab1XZ/agT1LaONVQFrLBXULWKAgAswi324GkNdds4JrXYySSRt29ADcCu0NWDBO kPcqhBpbA+/dBapDOO3Cq5sS9pGpOIsK9fSx8e6vd3BaX4NafdQ/lhlighuUWo3FZ931 msHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720804565; x=1721409365; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=I7N36qMCpcSl6TETGX5COtXj99LlnsyTYf2d/0laR8c=; b=MHZaWAxFY9ze6ySqoiMwKZ+fE9g7tWfWtizteHCqFmqk4HX6RL8JBPxjqrD5uQxrt9 SORDL+OIEUIfkWEW1z4xTmODBH9mB/QkVQdO9AWfrzaC/7iy9Ek8aDEDAkhwrh7kqhmz qZL0v5GvM9VzB64AlxtN9upjW23F5CIpFu89ispgKpFx5qYvg1fKlpizCgiKgSAFPMKV gtaitTIHEN1+z7krrSWflFGGpZUb/F1fJxjtoO7n2KYWzUHbrYo7bB99f2V3Hpnl9lCk H2n8hUvzsillhnxtwgJ4YRao2DXgPS5OxEzFUVzmR8yVMjK9qcIHFo8XN8LV+HmeV46w lvUA== X-Gm-Message-State: AOJu0YxAYV0Z+ah8WWs9JRFwi9a7rzELInFnX8hkNLptyqyZMjoLsCli XiGRxzTJbDjpF2oxXHRFrBkxBbu+Vr3tkhwLQ29dDIzn4gypn39kr2sbP7IEdMc= X-Google-Smtp-Source: AGHT+IGG7tvY3kLK2g/swpkF+Q57NJcii2DP69L5Bo8Ydp5Ci/bB2Q9lSBGiPJvyIOmEeAVlPtQnJg== X-Received: by 2002:a17:906:af09:b0:a6f:6029:998f with SMTP id a640c23a62f3a-a780b705436mr715243566b.46.1720804564605; Fri, 12 Jul 2024 10:16:04 -0700 (PDT) Received: from localhost (p200300de37360a00d7e56139e90929dd.dip0.t-ipconnect.de. [2003:de:3736:a00:d7e5:6139:e909:29dd]) by smtp.gmail.com with UTF8SMTPSA id a640c23a62f3a-a780a7ff73bsm361701066b.101.2024.07.12.10.16.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 10:16:04 -0700 (PDT) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, Martin Wilck Subject: [PATCH v2 31/49] libmultipath: implement dm_get_multipath() with new API Date: Fri, 12 Jul 2024 19:14:39 +0200 Message-ID: <20240712171458.77611-32-mwilck@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712171458.77611-1-mwilck@suse.com> References: <20240712171458.77611-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/devmapper.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 11bccb1..2f547ab 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -1302,7 +1302,8 @@ dm_disablegroup(const char * mapname, int index) struct multipath *dm_get_multipath(const char *name) { - struct multipath *mpp = NULL; + struct multipath __attribute((cleanup(cleanup_multipath))) *mpp = NULL; + char uuid[DM_UUID_LEN]; mpp = alloc_multipath(); if (!mpp) @@ -1311,22 +1312,22 @@ struct multipath *dm_get_multipath(const char *name) mpp->alias = strdup(name); if (!mpp->alias) - goto out; + return NULL; - if (dm_get_map(name, &mpp->size, NULL) != DMP_OK) - goto out; + if (libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY, + (mapid_t) { .str = name }, + (mapinfo_t) { + .size = &mpp->size, + .uuid = uuid, + .dmi = &mpp->dmi, + }) != DMP_OK) + return NULL; - if (dm_get_wwid(name, mpp->wwid, WWID_SIZE) != DMP_OK) { - condlog(2, "%s: failed to get uuid for %s", __func__, name); - mpp->wwid[0] = '\0'; - } - if (dm_get_info(name, &mpp->dmi) != 0) - condlog(2, "%s: failed to get info for %s", __func__, name); + if (strncmp(uuid, UUID_PREFIX, UUID_PREFIX_LEN)) + return NULL; - return mpp; -out: - free_multipath(mpp, KEEP_PATHS); - return NULL; + strlcpy(mpp->wwid, uuid + UUID_PREFIX_LEN, sizeof(mpp->wwid)); + return steal_ptr(mpp); } int dm_get_maps(vector mp) From patchwork Fri Jul 12 17:14:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13732080 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2927517736 for ; Fri, 12 Jul 2024 17:16:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804569; cv=none; b=u4TgIQ4kUa6O5xV9lEGQEPMeXYXKiB/txj+qWSFpDFhxh3s1d2A4XWnp+Czz/KLKaQOlFDqfGiClljN+ReaInMjCBnA2R4tZ3BVWuOryO9332diF8KjlNlWk14QBMxzxMGecmjaJYWCnYFe9eZevMdNTifkT9RTo9VYm540z+9Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804569; c=relaxed/simple; bh=vBEJ8hgk5mbVoFyIF9lBA2AyZUdnOTHBsYBg/IRz0L8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WuHQ93Q0tDlOqT5syTlt4TJa1jqhk8lLFQubiFvup+IvARcN4yMv4Aa3hwqikbgnupbm/w8GNolnw0gLAW2IZCPz/9vlkZtKLuwzvEyP6CtbJFm+l74s/UDsq6fAFXgY6UBN3KhuvqmCaNZoHBarFQ3fDJaFdRCAhf79UCj/hyU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=FAGDEsxb; arc=none smtp.client-ip=209.85.218.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="FAGDEsxb" Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-a77dc08db60so284262666b.1 for ; Fri, 12 Jul 2024 10:16:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1720804565; x=1721409365; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=U1+rE77bDSNAEPCQMi8HjUNLyVF+VXzSkeRMqWUfpGg=; b=FAGDEsxb5apR1ZQ9SPYaVKc5rKm+WrTm3VjgMzH2ylidepC20zmZwRKrP4Gt2Al6Tm 1w+oAHyevGRrl1TXHstJF3SPPDLjV9zcbxwZVs/rwTSmQtiV5OUIHT6/x8K99NASbYEq dq1J/hHJPEVRFiJoT2xvyl1DlQW9ADoIH4aGkMY+rWoTxnVe2C6Hp60Rx2XxL3iXfw9s OIAarV6hmUIaQ9qLrmcCX80L9CQpVCmdcBTr0rZ02QcxxwcMQCk2caUM8fnW3Qfhuuw1 DUGW8uTLshrlShChnOEm0TqHkMot67rQHUSgn6oC/3jpOLN1TlDa6n6TGoyZ6wQaP5Jo /ezg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720804565; x=1721409365; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=U1+rE77bDSNAEPCQMi8HjUNLyVF+VXzSkeRMqWUfpGg=; b=ql6jp/HGMUgyWw0ZyDvyCNl8t0ab5woFfmSk4s+rr/u34ePgyKTc1w3x/V4V064x3f numJespqxXalpdz5/a5lbWmdszUaYfoaMMUlZNLI1m6AcUvDQt+EgBJgXqKD4gh3qzho fQscOXNrT4KGeWRA3ka0zEWyeUEUxROmhM2v0e4oREssPskjxKOYlcgzXPEBrD9qIQcv oMVBkBVaYY6E66nNarz70Rmr3USsno7x0KqZ3TtCMyPO49VT9YjjL97ME+pP9C4O9xb3 oQ6tzKQxty/CFMTH+2aMB99vUQDnVuRRoW3fnXUj1RMdtI+AAIiKKYyYOy/e7HLMhb1c Yphw== X-Gm-Message-State: AOJu0YxzNMtrbZCFdQugfk7cdlF6P1qUvLiar2WjbcRN2DvEQpBTisHL L7G2atgbvLJtrYxtsnF2kooJAZQPOQm1VXgniEbHL6Ix0XgLsAR1bcTAAfUpek8= X-Google-Smtp-Source: AGHT+IGSMJE/nKvVgItnsAb3JDetQhEk6+Aeog+YLQGjH5M2x385L3Zd7GOxfgbCeu056Rtau0laGA== X-Received: by 2002:a17:906:195a:b0:a72:a05a:6601 with SMTP id a640c23a62f3a-a780b6891f6mr832442466b.14.1720804565494; Fri, 12 Jul 2024 10:16:05 -0700 (PDT) Received: from localhost (p200300de37360a00d7e56139e90929dd.dip0.t-ipconnect.de. [2003:de:3736:a00:d7e5:6139:e909:29dd]) by smtp.gmail.com with UTF8SMTPSA id a640c23a62f3a-a780a7ff038sm358713866b.115.2024.07.12.10.16.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 10:16:05 -0700 (PDT) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, Martin Wilck Subject: [PATCH v2 32/49] libmultipath: use libmp_mapinfo() in _dm_flush_map() Date: Fri, 12 Jul 2024 19:14:40 +0200 Message-ID: <20240712171458.77611-33-mwilck@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712171458.77611-1-mwilck@suse.com> References: <20240712171458.77611-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We can spare one dm ioctl here. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/devmapper.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 2f547ab..9483f02 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -1074,10 +1074,15 @@ int _dm_flush_map (const char *mapname, int flags, int retries) int r; int queue_if_no_path = 0; int udev_flags = 0; - unsigned long long mapsize; - char *params = NULL; + char *params __attribute__((cleanup(cleanup_charp))) = NULL; + char uuid[DM_UUID_LEN]; - if (dm_is_mpath(mapname) != DM_IS_MPATH_YES) + if (libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY, + (mapid_t) { .str = mapname }, + (mapinfo_t) { + .uuid = uuid, + .target = ¶ms }) != DMP_OK + || strncmp(uuid, UUID_PREFIX, UUID_PREFIX_LEN)) return DM_FLUSH_OK; /* nothing to do */ /* if the device currently has no partitions, do not @@ -1091,7 +1096,6 @@ int _dm_flush_map (const char *mapname, int flags, int retries) return DM_FLUSH_BUSY; if ((flags & DMFL_SUSPEND) && - dm_get_map(mapname, &mapsize, ¶ms) == DMP_OK && strstr(params, "queue_if_no_path")) { if (!_dm_queue_if_no_path(mapname, 0)) queue_if_no_path = 1; @@ -1099,8 +1103,6 @@ int _dm_flush_map (const char *mapname, int flags, int retries) /* Leave queue_if_no_path alone if unset failed */ queue_if_no_path = -1; } - free(params); - params = NULL; if ((r = dm_remove_partmaps(mapname, flags))) return r; From patchwork Fri Jul 12 17:14:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13732081 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-ed1-f54.google.com (mail-ed1-f54.google.com [209.85.208.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 185EA176228 for ; Fri, 12 Jul 2024 17:16:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804570; cv=none; b=tr+JpDpK5XxBeXw6R6FCnbBh2cmRvA3CSu8rC+2PXk7q2d1b1wprUVz07MaheyOO0ttyjFx4Xg+blnk4wzaVH+u1DdGAARI474Flz8rFv7oGb12BSAwckw/Y5W+wNF2KGGECu4BHZiDB1619iYlZt0yrs78jcXn/Y7O7/6LZjZk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804570; c=relaxed/simple; bh=fN4QplXuqUjHwByYmUvDNZveEYmgQJcJGoh6pTjDIk0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PXWDlVxTBxdkxHDx61GppziEtFikCWyxgLv4hvSr/TeAEJQi0riMVmWvv2ZhtyLWuEEdlJNuah4Goexc3ClUZZztEkaE5t4+dJ2goQ0GeljR6bvHPL9odN/r3F/oAM7wq1Y+MfO2HDqvDcQ+MXdchw0w3jeREmh76suc3QmqGYk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=dij0vAeb; arc=none smtp.client-ip=209.85.208.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="dij0vAeb" Received: by mail-ed1-f54.google.com with SMTP id 4fb4d7f45d1cf-595856e2336so3804701a12.1 for ; Fri, 12 Jul 2024 10:16:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1720804566; x=1721409366; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5lRj/fzwkWhiBcG+aLN/qvt6ptCQSYYEiGkgciwWklo=; b=dij0vAebCBBXELqR6wbzeWTxJQH+0jeTnLGHkqCEdCEm+8EQF6ACJ7A8fLmSRvMjsE 1FejE3eJbddlYxckAzKG4/iOUH5eweq1D0Mw0yldnBuQBn+A+QnC3AyJ+hBtpgYQ2wsS rI3PLIN+q4qbNjr3o1UdC2cL+bRANlq1LX3FMVzToqpJEGLFIhyJEFMKOUnBeYXpOTSy IZU3RM6CRoLWrjDodBaAV8nQ83Jfj+0CvIV+mLimfkmVYEnmqLUuwYkbuOYPU6P/CR5O CvUunSEc8ffajC00dPezsvvJ3f3DkQJZWQY8VL092ws+j7Dp0cYA/7mJSjcNU8zBfICz Tx+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720804566; x=1721409366; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5lRj/fzwkWhiBcG+aLN/qvt6ptCQSYYEiGkgciwWklo=; b=aamoFZSFn+O/yMqlIY8VdeiXN6r+TPpZbEFMskcvIfwMNuaa+yvXTYMYpKMuq8j51R yLklDyTL8fl9QAQlCBjoPOICP5WVJ/kDUfpfYnL3ftRxLlmpJmiYbfW37Jh+/M/SmA8B qqLVW0QFbENVzWogiax9nucvya1BqqKXntii52Stau1aRFSc//CdLCyGWkLEiH0QuoPu bOiu0bq7RfCEqrP6DjY5N9SPrw/YOWKO/ELFK53XnJklJGvkGGS3mOH9NZiy5Ir8TEgK +nFB3Wd5HGu+T5aCxoqhCEoThz7MlmVQSBnsqfqZEDjvNS5cdj6dojlcW6G5nMWG1vKr YckA== X-Gm-Message-State: AOJu0YwNFm187yKW9H9GrLQSjZppgDdNaSNBmkFzg0c9kK9E5tQcvygH +IHdsUArrFU0W0cbz8IDNg8c1iBFTRKd5bEJ86LRkebToUjRBoSih219D2PPM0Y= X-Google-Smtp-Source: AGHT+IHHroq+KWU4SUwLLawFyBFB1Tpee2UOTrc/4zLeBtcGlpOJMT6c5Wh47KYWq2PnL4QIsPIwwg== X-Received: by 2002:a05:6402:34d5:b0:57c:7f3a:6c81 with SMTP id 4fb4d7f45d1cf-599642c3368mr2992051a12.8.1720804566325; Fri, 12 Jul 2024 10:16:06 -0700 (PDT) Received: from localhost (p200300de37360a00d7e56139e90929dd.dip0.t-ipconnect.de. [2003:de:3736:a00:d7e5:6139:e909:29dd]) by smtp.gmail.com with UTF8SMTPSA id 4fb4d7f45d1cf-594bbe2cf93sm4732586a12.33.2024.07.12.10.16.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 10:16:06 -0700 (PDT) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, Martin Wilck Subject: [PATCH v2 33/49] libmultipath: add is_mpath_uuid() helper Date: Fri, 12 Jul 2024 19:14:41 +0200 Message-ID: <20240712171458.77611-34-mwilck@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712171458.77611-1-mwilck@suse.com> References: <20240712171458.77611-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Export it, as it will be used by multipathd and libmpathpersist. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/devmapper.c | 13 +++++++++---- libmultipath/devmapper.h | 2 ++ libmultipath/libmultipath.version | 1 + 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 9483f02..6f17d32 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -840,6 +840,11 @@ int dm_get_map(const char *name, unsigned long long *size, char **outparams) } } +bool is_mpath_uuid(const char uuid[DM_UUID_LEN]) +{ + return !strncmp(uuid, UUID_PREFIX, UUID_PREFIX_LEN); +} + /** * dm_get_wwid(): return WWID for a multipath map * @returns: @@ -857,7 +862,7 @@ int dm_get_wwid(const char *name, char *uuid, int uuid_len) if (rc != DMP_OK) return rc; - if (!strncmp(tmp, UUID_PREFIX, UUID_PREFIX_LEN)) + if (is_mpath_uuid(tmp)) strlcpy(uuid, tmp + UUID_PREFIX_LEN, uuid_len); else return DMP_NO_MATCH; @@ -982,7 +987,7 @@ int dm_is_mpath(const char *name) switch (rc) { case DMP_OK: - if (!strncmp(uuid, UUID_PREFIX, UUID_PREFIX_LEN)) + if (is_mpath_uuid(uuid)) return DM_IS_MPATH_YES; /* fallthrough */ case DMP_NOT_FOUND: @@ -1082,7 +1087,7 @@ int _dm_flush_map (const char *mapname, int flags, int retries) (mapinfo_t) { .uuid = uuid, .target = ¶ms }) != DMP_OK - || strncmp(uuid, UUID_PREFIX, UUID_PREFIX_LEN)) + || !is_mpath_uuid(uuid)) return DM_FLUSH_OK; /* nothing to do */ /* if the device currently has no partitions, do not @@ -1325,7 +1330,7 @@ struct multipath *dm_get_multipath(const char *name) }) != DMP_OK) return NULL; - if (strncmp(uuid, UUID_PREFIX, UUID_PREFIX_LEN)) + if (!is_mpath_uuid(uuid)) return NULL; strlcpy(mpp->wwid, uuid + UUID_PREFIX_LEN, sizeof(mpp->wwid)); diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h index 4c8f345..a10821f 100644 --- a/libmultipath/devmapper.h +++ b/libmultipath/devmapper.h @@ -136,6 +136,8 @@ enum { DM_IS_MPATH_YES, DM_IS_MPATH_ERR, }; + +bool is_mpath_uuid(const char uuid[DM_UUID_LEN]); int dm_is_mpath(const char *name); enum { diff --git a/libmultipath/libmultipath.version b/libmultipath/libmultipath.version index 7d3ff63..5b8f9e0 100644 --- a/libmultipath/libmultipath.version +++ b/libmultipath/libmultipath.version @@ -127,6 +127,7 @@ global: init_foreign; init_prio; io_err_stat_handle_pathfail; + is_mpath_uuid; is_path_valid; libmp_dm_task_create; libmp_get_version; From patchwork Fri Jul 12 17:14:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13732082 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BD50E177999 for ; Fri, 12 Jul 2024 17:16:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804570; cv=none; b=lZlz+JrD2SToPXiLpLvUmdmuIbbBbhJdXyhtm6xH8Gay53FEzhwyORWrQB8rUm4XjZEIcoPx/5pbxFB2bYrHWnX+BGgn3WcMiSHLyHhtEcfJIyj7rAivstffzCw9q5S3tuNKLYg4K3naH9Y1GnnIdqYIt8zb1tqlvloVKAK4OLM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804570; c=relaxed/simple; bh=tKWt4/1zCA/FNfqJzws5IAf92vxgOmrsBFaOU0AXvZw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Jff1UaoaDFI4qvmy1Y2PFuVT5U86Km/BYQ8WetaUNJFpT26JRfduWXzrXJsDabYZmLqAYm0Fo9DS7b0Kqo/YfATUPyO52kbBQ3R8oZxdPwkjgAGSALI0hZnD1ktURZpv5gs1jyCxzaNlBnkl5A2AN2lHjgk961y115XEExroRvM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=Fmv+symU; arc=none smtp.client-ip=209.85.218.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="Fmv+symU" Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-a77dc08db60so284265966b.1 for ; Fri, 12 Jul 2024 10:16:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1720804567; x=1721409367; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=i4vItA7EW5RGeKtTjXZNOru8Xocm80XSNLAgW2ehs5k=; b=Fmv+symUMyPTsRHqvXoIdDm61Rc8NyQRi+HO3aPxlV+Wa2cs6UMxbow+SRwLprnOCy j4wXHejQ6qonn/SSd/iqo/8RcbnMO3zCTilVplHGo0dC7GAAaDRjZtI/iK9jDwRhILsH 603t5b5HdZbF152Y19QiY8K4TR90827CFFzBR7WRSW4odCA7d4RNYbCtChwlHMdBO+DS ZXQ5MvujHuYHUCUeK2PqZ0yHa11Qu5hdAzkxQB/3x5pacOCTSHziVFtQWlsWPUYMIlAv ziMLZVZEExMVX/hruoqTNur8ASM73chHHlGBQRjWy7Afd4CLDBV8DqQq5k6Z84zXK+F+ qPCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720804567; x=1721409367; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=i4vItA7EW5RGeKtTjXZNOru8Xocm80XSNLAgW2ehs5k=; b=QQqiyNoIMZKT3AGXHvCrCweGCaMzo3AbfHtcR871VqP9m/E4EP4N54+RZgvHRcys13 gJjIx0bwfHV7O+baKiLOaqcJgJXG/fWzCwiKQC2zIq4LJQjEHx1Z1znYWSvgtmFePHb7 eTqC6lGtax9WrLMJrx+CMsDJgkXjpelW4U1Sz8kxqO781h/OXqk2w3kNPEG+2MDe+QO0 T695H5HMyVfskDtBXvorv3MK72gWmDDrC+iS40wrQ2rZg5MZLk+cIR9BWZe0QEgp9yt+ 593/leGzQKbQWQCMesMS/oh3Ky9ttNSSlAkJhKk0+9rXuWhEebHWgOb07vLOztdoXJlC X8iQ== X-Gm-Message-State: AOJu0Yx9hO5yu8Qg1qYVrVR9tFO4WxwoLXwFVmteAIV1whMz3U4JlhVa wcyqFWJ2Qn5obgDpX3jLNaH+IZIS7XchkyTiZ0cBBwpP8B1jKv9O9/jyB3ZtHBA= X-Google-Smtp-Source: AGHT+IFnZow9Nzfqxp9efLnM6Lg5kAxjH5TlpcNEbaOT4jfHSBZ3FFE/xoypwN1OSnABkM+XnJFlwg== X-Received: by 2002:a17:907:d93:b0:a75:20f7:2c71 with SMTP id a640c23a62f3a-a780b6ff667mr1223210866b.38.1720804567231; Fri, 12 Jul 2024 10:16:07 -0700 (PDT) Received: from localhost (p200300de37360a00d7e56139e90929dd.dip0.t-ipconnect.de. [2003:de:3736:a00:d7e5:6139:e909:29dd]) by smtp.gmail.com with UTF8SMTPSA id a640c23a62f3a-a780a8561fesm360310066b.186.2024.07.12.10.16.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 10:16:07 -0700 (PDT) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, Martin Wilck Subject: [PATCH v2 34/49] libmultipath: add is_mpath_part_uuid() helper Date: Fri, 12 Jul 2024 19:14:42 +0200 Message-ID: <20240712171458.77611-35-mwilck@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712171458.77611-1-mwilck@suse.com> References: <20240712171458.77611-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/devmapper.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 6f17d32..4ad84dd 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -870,21 +870,15 @@ int dm_get_wwid(const char *name, char *uuid, int uuid_len) return DMP_OK; } -static int is_mpath_part(const char *part_name, const char *map_name) +static bool is_mpath_part_uuid(const char part_uuid[DM_UUID_LEN], + const char map_uuid[DM_UUID_LEN]) { - char part_uuid[DM_UUID_LEN], map_uuid[DM_UUID_LEN], c; + char c; int np, nc; - if (dm_get_dm_uuid(part_name, part_uuid) != DMP_OK) - return 0; - if (2 != sscanf(part_uuid, "part%d-%n" UUID_PREFIX "%c", &np, &nc, &c) || np <= 0) - return 0; - - if (dm_get_dm_uuid(map_name, map_uuid) != DMP_OK) - return 0; - + return false; return !strcmp(part_uuid + nc, map_uuid); } @@ -978,6 +972,20 @@ static int dm_type_match(const char *name, char *type) return DM_TYPE_NOMATCH; } +static bool is_mpath_part(const char *part_name, const char *map_name) +{ + char part_uuid[DM_UUID_LEN], map_uuid[DM_UUID_LEN]; + + if (dm_get_dm_uuid(map_name, map_uuid) != DMP_OK + || !is_mpath_uuid(map_uuid)) + return false; + + if (dm_get_dm_uuid(part_name, part_uuid) != DMP_OK) + return false; + + return is_mpath_part_uuid(part_uuid, map_uuid); +} + int dm_is_mpath(const char *name) { char uuid[DM_UUID_LEN]; From patchwork Fri Jul 12 17:14:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13732083 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-ed1-f48.google.com (mail-ed1-f48.google.com [209.85.208.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E4066176FA8 for ; Fri, 12 Jul 2024 17:16:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804571; cv=none; b=kuGlbts9Mqt/SSJ3uXC0SZTqrwwAgzEEY9fjuejkFnAObbjRrr1iHvTFHnKUk+Aq4NwT0So1CIjWYqvY2bFIgL4aVzMbknJ23uHsZzLrzJuzekgdE7vVPGePX2oT+8XDreRHRUtpvmH3uovNbe3YhV5/Aq7ODObCEJEeyHMQ3Hs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804571; c=relaxed/simple; bh=rdSG7FmxdyXLeAq25o3hQE3nxP+IUBdsYier13bmL2g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FGovh45DyXi5MYYN/WZX5JzAJXh9qyHzHCdUw4FuscEMJtMDErQ+mPszC8w0NTiYJvOjwb2mCFFIYuQZa4m1+0VWQjJO0c8WO8HE0zUoJHnIQDCPteqMe5A7mDpSpSNffVWfedwkzQMHJMwHaYVezLGKwhgd4V7y6iURMPMRQq8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=ZM2jmq0q; arc=none smtp.client-ip=209.85.208.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="ZM2jmq0q" Received: by mail-ed1-f48.google.com with SMTP id 4fb4d7f45d1cf-58ef19aa6b3so1408253a12.1 for ; Fri, 12 Jul 2024 10:16:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1720804568; x=1721409368; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=E6nDPc0IZERQmxcZS+rTSoQQ2RUISh07zFf1sF58B3Q=; b=ZM2jmq0qmzm1aWDv+RUoGQUwUhKeO6cdhjr8hgCGbyXsrQSc7Jn8CEF011KNOOhIUl tPGqfUMbwTrUR2mflmNDP5bDdiRQSpUkM4Wd2L1UfTTrshZYRy7qYoUezMa1MhYjT5po 03SWClEWan3Z9qMOvy2jlrWZkqHY+QFmfW5tpRkk+L0p/A540o3y6KeEYz87wj/7G7xu A9AOtCsAnhXJ2/KZdAikOQoRhbhT8i0nzeRJu4WffrE0df0WFfwH4UJEyfqkVj4isg/R UJ++wRu2jiaGuf69O3UgZTFMB1+iOJ/IV7sJGVxn9I42kwkbpcEZn0agggXx+eoKfTkq vYTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720804568; x=1721409368; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=E6nDPc0IZERQmxcZS+rTSoQQ2RUISh07zFf1sF58B3Q=; b=OYZJzW8Vb439IyRr7nYgrmxsVa9tCWNim+TN4gInwcJBoYDtU4egJ6mllRv1tKN5Ar mSyZ/z3sUE+ppk6p3gBieOMS8OXT431As1tYEke/X3+en+cZ0oAFHCbZQI7wBBQ4AY+2 T9BPnB8KhLoMp1ppiDBgpoy7GIXI6K6rLx6utAEJScbEXmgaiB2leBNh6IdABW9Vevp9 gM7XKCwPB7BRGoAgPeBD3BHVfKv7kqWef4XnrlzQQ7pJGOrnu10olrJZNVajC632J90E bn/JfyBwuSJrKJh/w36c9YGvjc1NTnPYFBYeS+vShkH6WLLiywk5DTbLdf8WblVcWc9N R7ag== X-Gm-Message-State: AOJu0YwEMA7WGE+a26CYj2L9duGOd8pk3n2kLsvVkemlc74uETYFm46X OJ/2BE1U8BuRgXgs82tmXQ3KnVTeVrVk/OeBhJyH8b+ZmYcolmk8/C7BnTsLeyWUXUWjRs0jgVZ 8 X-Google-Smtp-Source: AGHT+IEg2iiRb/ljCRJ1xSpw2ZofL64rUrY0OTDuNYh9MPVW/dWz+TtyVcxEs66AswwrDlwFpl24uw== X-Received: by 2002:a05:6402:348c:b0:58f:2087:7983 with SMTP id 4fb4d7f45d1cf-594bcba842bmr11035265a12.40.1720804568164; Fri, 12 Jul 2024 10:16:08 -0700 (PDT) Received: from localhost (p200300de37360a00d7e56139e90929dd.dip0.t-ipconnect.de. [2003:de:3736:a00:d7e5:6139:e909:29dd]) by smtp.gmail.com with UTF8SMTPSA id 4fb4d7f45d1cf-594bbe2cc6asm4703919a12.24.2024.07.12.10.16.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 10:16:08 -0700 (PDT) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, Martin Wilck Subject: [PATCH v2 35/49] libmultipath: add dmp_errstr() helper Date: Fri, 12 Jul 2024 19:14:43 +0200 Message-ID: <20240712171458.77611-36-mwilck@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712171458.77611-1-mwilck@suse.com> References: <20240712171458.77611-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/devmapper.c | 14 ++++++++++++++ libmultipath/devmapper.h | 3 +++ 2 files changed, 17 insertions(+) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 4ad84dd..e51c2f0 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -79,6 +79,20 @@ static void libmp_udev_wait(unsigned int c) } #endif +const char *dmp_errstr(int rc) +{ + static const char *str[] = { + [DMP_ERR] = "generic error", + [DMP_OK] = "success", + [DMP_NOT_FOUND] = "not found", + [DMP_NO_MATCH] = "target type mismatch", + [__DMP_LAST__] = "**invalid**", + }; + if (rc < 0 || rc > __DMP_LAST__) + rc = __DMP_LAST__; + return str[rc]; +} + int libmp_dm_task_run(struct dm_task *dmt) { int r; diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h index a10821f..7231a98 100644 --- a/libmultipath/devmapper.h +++ b/libmultipath/devmapper.h @@ -34,8 +34,11 @@ enum { DMP_OK, DMP_NOT_FOUND, DMP_NO_MATCH, + __DMP_LAST__, }; +const char* dmp_errstr(int rc); + /** * enum mapinfo_flags: input flags for libmp_mapinfo() */ From patchwork Fri Jul 12 17:14:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13732084 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-ed1-f44.google.com (mail-ed1-f44.google.com [209.85.208.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B311317799B for ; Fri, 12 Jul 2024 17:16:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804572; cv=none; b=TL2l+WXn9wM+yl7yx0Z/iBdD8Ga9emHG6231F9sf8MIYaac1O8V6XXDnyjjN96ti3r7u0g6QwCqXaVKwwj/T0WLDcLRDjdXbOt5wjc6orizkhxX9P04Ga5fLZlZlAOiLjh3AgKAXN+XOmWEf0oJSqEBLFiuXWkVNOH7RGzKvNZc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804572; c=relaxed/simple; bh=zud+B1oqsmi3XLFljSXJ2pSJNl3tU+FHDB0+hqqBGvc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZbRBV7nDWIGKxHfkv7/vcbAcTT9aOWbyXJcTeuEUBT9kTTUwIjmFct++a19V7bdUWKePmUkWhJVxdndVkCLas+cjiB3h5j+O2BqVonIIYFZx8dIS0QqG/Alj97CzhU+ohAGs5sajIg0erb+/GQCNiL5RQs/+e08/O4jAXt/Re1I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=OLaNjqSW; arc=none smtp.client-ip=209.85.208.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="OLaNjqSW" Received: by mail-ed1-f44.google.com with SMTP id 4fb4d7f45d1cf-57cf8880f95so2807898a12.3 for ; Fri, 12 Jul 2024 10:16:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1720804569; x=1721409369; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0j3JXw6+f5Tz0Pb832Ll7sGOk/jw34ZbI5Ip+mrftAg=; b=OLaNjqSWCfZb6Mxz9fZ7ZpCGm3YRNfF3fzNwPSy6C9SghU+UFHTbtmTzaiFCpu/zyN KQwEQffbOO6e/2Q58AOxbV6fWUJJxnSTSFz7GO1E2Bx2JDMDAo9M27Bt8RPyrMBRycqs kJlg4htKccHSyeGxlQR7tPygN1bZddlXOUOt6x2Ud3ZTAbwTuML1xugk2IQWRQdvKdLr Ht2Fme0weYfNUzX9qo3HJSNzINgzDNK8308PcNGk6UB97uJOhH5dUSDlESFg2s9yBtdD GXaUU3rwOuVcw9F25kc85mvvykg+ixNrk0HrYLZ9mFQIJOjHto8XtDIPZXbv2aqZyXv4 189Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720804569; x=1721409369; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0j3JXw6+f5Tz0Pb832Ll7sGOk/jw34ZbI5Ip+mrftAg=; b=rDhF12WRDIMnTSCkzmJsHEdMRL5COhqNduK+rM4cyy3AZ82QkKIACTq2wDt1jIid94 yv7NG960ZNGhO86hLTdHsQWnTMBRs8NWyb5Q8BNY3KKv3S7CA65gRjmo3BNGxZ7KlF5d zPhgWcQKR/nyYdzUFa5xR23DCWClumKm8nwH2Zot9zZ9Py0VJYCmuVsbOymaiU9y2qfJ Ebt7w8EILJUTpy5aYCPnFu9VI0tnc0fehCFHhFBFDOSJCqOMcvTz4Ikt8XCyFKscmC7X B+tBJ1bmQ4/E7PNw5OIBL/ukm1/q7PEE7/YQk4HANaA4i/kCg1qEe8Q06Qf2elhEd97Y Os8g== X-Gm-Message-State: AOJu0Ywz/M2vmPna0hzrkYryhidjIQfYyASxxz7fOzZZ1ZgyHX/DSYLj /UK85eUaac0+WBMQsozcIQ17xvhb9596Adyoy3vIoV2mkQTHrXyyHNoLrwWaFqg= X-Google-Smtp-Source: AGHT+IGZJ0m/87PFSFtkDJeYjAYMXmaqXasUnPqpA58TnyzfLTUP3jrkgi5Boilx/OoU4GNhEeXHbQ== X-Received: by 2002:a05:6402:354f:b0:57d:2c9:6497 with SMTP id 4fb4d7f45d1cf-594bab80106mr11021413a12.3.1720804569058; Fri, 12 Jul 2024 10:16:09 -0700 (PDT) Received: from localhost (p200300de37360a00d7e56139e90929dd.dip0.t-ipconnect.de. [2003:de:3736:a00:d7e5:6139:e909:29dd]) by smtp.gmail.com with UTF8SMTPSA id 4fb4d7f45d1cf-594bda27f56sm4778048a12.80.2024.07.12.10.16.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 10:16:08 -0700 (PDT) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, Martin Wilck Subject: [PATCH v2 36/49] libmultipath: use libmp_mapinfo() in do_foreach_partmaps() Date: Fri, 12 Jul 2024 19:14:44 +0200 Message-ID: <20240712171458.77611-37-mwilck@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712171458.77611-1-mwilck@suse.com> References: <20240712171458.77611-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Also, simplify the if statement a bit. drop is_mpath_part() and dm_type_match, because do_foreach_partmaps() was the last user of these functions. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/devmapper.c | 100 ++++++++++----------------------------- 1 file changed, 26 insertions(+), 74 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index e51c2f0..587fc17 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -946,60 +946,6 @@ out: return r; } -enum { - DM_TYPE_NOMATCH = 0, - DM_TYPE_MATCH, - /* more than 1 target */ - DM_TYPE_MULTI, - /* empty map */ - DM_TYPE_EMPTY, - DM_TYPE_ERR, -}; -static int dm_type_match(const char *name, char *type) -{ - struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; - uint64_t start, length; - char *target_type = NULL; - char *params; - - if (!(dmt = libmp_dm_task_create(DM_DEVICE_TABLE))) - return DM_TYPE_ERR; - - if (!dm_task_set_name(dmt, name)) - return DM_TYPE_ERR; - - if (!libmp_dm_task_run(dmt)) { - dm_log_error(3, DM_DEVICE_TABLE, dmt); - return DM_TYPE_ERR; - } - - /* Fetch 1st target */ - if (dm_get_next_target(dmt, NULL, &start, &length, - &target_type, ¶ms) != NULL) - /* multiple targets */ - return DM_TYPE_MULTI; - else if (!target_type) - return DM_TYPE_EMPTY; - else if (!strcmp(target_type, type)) - return DM_TYPE_MATCH; - else - return DM_TYPE_NOMATCH; -} - -static bool is_mpath_part(const char *part_name, const char *map_name) -{ - char part_uuid[DM_UUID_LEN], map_uuid[DM_UUID_LEN]; - - if (dm_get_dm_uuid(map_name, map_uuid) != DMP_OK - || !is_mpath_uuid(map_uuid)) - return false; - - if (dm_get_dm_uuid(part_name, part_uuid) != DMP_OK) - return false; - - return is_mpath_part_uuid(part_uuid, map_uuid); -} - int dm_is_mpath(const char *name) { char uuid[DM_UUID_LEN]; @@ -1441,7 +1387,7 @@ char *dm_mapname(int major, int minor) } static int -do_foreach_partmaps (const char * mapname, +do_foreach_partmaps (const char *mapname, int (*partmap_func)(const char *, void *), void *data) { @@ -1449,10 +1395,19 @@ do_foreach_partmaps (const char * mapname, char __attribute__((cleanup(cleanup_charp))) *params = NULL; struct dm_names *names; unsigned next = 0; - unsigned long long size; - char dev_t[32]; + char dev_t[BLK_DEV_SIZE]; int r = 1; char *p; + char map_uuid[DM_UUID_LEN]; + struct dm_info info; + + if (libmp_mapinfo(DM_MAP_BY_NAME, + (mapid_t) { .str = mapname }, + (mapinfo_t) { .uuid = map_uuid, .dmi = &info }) != DMP_OK) + return 1; + + if (safe_sprintf(dev_t, "%i:%i", info.major, info.minor)) + return 1; if (!(dmt = libmp_dm_task_create(DM_DEVICE_LIST))) return 1; @@ -1467,41 +1422,38 @@ do_foreach_partmaps (const char * mapname, /* this is perfectly valid */ return 0; - if (dm_dev_t(mapname, &dev_t[0], 32)) - return 1; - do { + char part_uuid[DM_UUID_LEN]; + if ( /* * if there is only a single "linear" target */ - (dm_type_match(names->name, TGT_PART) == DM_TYPE_MATCH) && - + libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_PART_ONLY, + (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(names->name, mapname) && - - /* - * and we can fetch the map table from the kernel - */ - dm_get_map(names->name, &size, ¶ms) == DMP_OK && + 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 ((r = partmap_func(names->name, data)) != 0) - return 1; - } + !isdigit(*(p + strlen(dev_t))) && + + (r = partmap_func(names->name, data)) != 0) + return 1; free(params); params = NULL; next = names->next; - names = (void *) names + next; + names = (void*) names + next; } while (next); return 0; From patchwork Fri Jul 12 17:14:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13732085 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-ed1-f43.google.com (mail-ed1-f43.google.com [209.85.208.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A45D1176AB1 for ; Fri, 12 Jul 2024 17:16:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804573; cv=none; b=i/1jWDOyo96qZXt9Huicf1GXtKFCBGbpbnB+HZy1X2N3RmEbhi7wFUZj5PPgg27Ptt99I/T1av+hPqlKWRjtTVazjJKmnZuomQ0hiMQdKidDPiNmhIYkOa3pS8Wy16FW+0GO9jQ1HhYgKT05W4riQNeJBnRyuXTmv2MLxXvncUY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804573; c=relaxed/simple; bh=BEDR0u26pztS4Q43SaC5sQX0wkvfVRn2KrHxFGkwjqw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sOmVehQORsE+VUgYe2NWgSZKpCNktP2NgoPyL2X3Q2b8hPHKdwSHgm5nWLqI6/P9O7194owD46F7ecA0LtzfujIManQDip9VY1Rk+B6ufKDC5WP8+Mn9IPea/vObQ639hLQLmJc6WGE6CVZtKRtPmozA+sNB7MoVGtTL0caSdtg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=Gs7SBqvm; arc=none smtp.client-ip=209.85.208.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="Gs7SBqvm" Received: by mail-ed1-f43.google.com with SMTP id 4fb4d7f45d1cf-5957040e32aso1405670a12.2 for ; Fri, 12 Jul 2024 10:16:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1720804570; x=1721409370; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=GtR/ikc0e+KVBZHlRcqPzge00dOuQp7heewk7/O9FD0=; b=Gs7SBqvmYTPpxqvnem3GExAAkg/fHfyIZkaPXAVn0q78VQjst48ggPTmqXRZB/paAQ XLs8c5BbM+geep4e55PyUl9ntVXG3tSTJ4I3sqRP48dFH4g4rI+PeXARVnA0/A3PCOmD ++0P2Rw8RMoKTZH/RYPb2pb6/dlSLDHkB9AVccBqE6PKTfCGoXi+bWdwUrmA94WejHS/ lmIFfg2UWONNBBQalXMEwjny7IbyJulosvq2ZtShNr0aoFk5B5ohpBELbXVYPwIdFb6O s38LWKp4sZazmEz1KtFJe3uP3HqRakNQrG82Y6bnFB+tAPQlgrUXh996kpvGNVBwmYv6 7ZWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720804570; x=1721409370; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GtR/ikc0e+KVBZHlRcqPzge00dOuQp7heewk7/O9FD0=; b=jECS3uKr9RiKEemWxP55h2yAJO11bPFao5ST9QVi54Qizmj0tNVtzW5czzIFjkE58e hS+O6wnqrnHN5ZW3f9gG3GqLRGvVEPlzxuvySTxZm1hj/8XvWZJPHwEJ4rEnT/0US07G etwZq1yHZeZy0zNUkiGmAkGXtSwXbTOkAGEUOsn7i1HYL5DHRmuY/39u7c0wTJ83zrmK A/BZIluFBom+EIrW0A8ly42ICnpmUZMhqfxp6brM2uUOZHleSJ1rCD48IabfbPObXKel gMPagG92F+g+ATk3C9lNaWYGPzcJwSDxAM1UCmiZJhiPzyomqolxNcsErVgOdKkhCnO+ YiAA== X-Gm-Message-State: AOJu0Yx70z//8NYF8HErgMv6v/POeaMmeOTjWxcKTzxXmRkp5wM/HVkJ 3FDPSNNvr3SD3k23B9/fg7Ux9MpYKP4UEzzGnK8IWxvqS5RUvJJpaPk+jOKN2M2Dbh9hdUlLzbH z X-Google-Smtp-Source: AGHT+IH7KlF66LNTtKAyqd/OyKVnb+N5Z3OlDDMPWN4XzrBguvIsaBGBGvn3H1vPeZj9loehdJ6uCA== X-Received: by 2002:a05:6402:27ce:b0:58f:41e0:8d22 with SMTP id 4fb4d7f45d1cf-594bab8083fmr14131085a12.1.1720804569924; Fri, 12 Jul 2024 10:16:09 -0700 (PDT) Received: from localhost (p200300de37360a00d7e56139e90929dd.dip0.t-ipconnect.de. [2003:de:3736:a00:d7e5:6139:e909:29dd]) by smtp.gmail.com with UTF8SMTPSA id 4fb4d7f45d1cf-594bbe2cca6sm4739714a12.27.2024.07.12.10.16.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 10:16:09 -0700 (PDT) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, Martin Wilck Subject: [PATCH v2 37/49] libmultipath: use libmp_pathinfo() in update_multipath_table() Date: Fri, 12 Jul 2024 19:14:45 +0200 Message-ID: <20240712171458.77611-38-mwilck@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712171458.77611-1-mwilck@suse.com> References: <20240712171458.77611-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This allows us to remove dm_get_status(), and dm_get_map(), of which update_multipath_table() was the last caller. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/devmapper.c | 89 -------------------------------------- libmultipath/devmapper.h | 2 - libmultipath/structs_vec.c | 26 ++++++----- 3 files changed, 15 insertions(+), 102 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 587fc17..86ac01b 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -815,45 +815,6 @@ static int dm_get_dm_uuid(const char *mapname, char uuid[DM_UUID_LEN]) (mapinfo_t) { .uuid = uuid }); } -int dm_get_map(const char *name, unsigned long long *size, char **outparams) -{ - struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; - uint64_t start, length; - char *target_type = NULL; - char *params = NULL; - - if (!(dmt = libmp_dm_task_create(DM_DEVICE_TABLE))) - return DMP_ERR; - - if (!dm_task_set_name(dmt, name)) - return DMP_ERR; - - errno = 0; - if (!libmp_dm_task_run(dmt)) { - dm_log_error(3, DM_DEVICE_TABLE, dmt); - if (dm_task_get_errno(dmt) == ENXIO) - return DMP_NOT_FOUND; - else - return DMP_ERR; - } - - /* Fetch 1st target */ - if (dm_get_next_target(dmt, NULL, &start, &length, - &target_type, ¶ms) != NULL || !params) - /* more than one target or not found target */ - return DMP_NOT_FOUND; - - if (size) - *size = length; - - if (!outparams) - return DMP_OK; - else { - *outparams = strdup(params); - return *outparams ? DMP_OK : DMP_ERR; - } -} - bool is_mpath_uuid(const char uuid[DM_UUID_LEN]) { return !strncmp(uuid, UUID_PREFIX, UUID_PREFIX_LEN); @@ -896,56 +857,6 @@ static bool is_mpath_part_uuid(const char part_uuid[DM_UUID_LEN], return !strcmp(part_uuid + nc, map_uuid); } -int dm_get_status(const char *name, char **outstatus) -{ - int r = DMP_ERR; - struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; - uint64_t start, length; - char *target_type = NULL; - char *status = NULL; - - if (!(dmt = libmp_dm_task_create(DM_DEVICE_STATUS))) - return r; - - if (!dm_task_set_name(dmt, name)) - goto out; - - errno = 0; - if (!libmp_dm_task_run(dmt)) { - dm_log_error(3, DM_DEVICE_STATUS, dmt); - if (dm_task_get_errno(dmt) == ENXIO) - r = DMP_NOT_FOUND; - goto out; - } - - r = DMP_NOT_FOUND; - /* Fetch 1st target */ - if (dm_get_next_target(dmt, NULL, &start, &length, - &target_type, &status) != NULL) - goto out; - - if (!target_type || strcmp(target_type, TGT_MPATH) != 0) - goto out; - - if (!status) { - condlog(2, "got null status."); - goto out; - } - - if (!outstatus) - r = DMP_OK; - else { - *outstatus = strdup(status); - r = *outstatus ? DMP_OK : DMP_ERR; - } -out: - if (r != DMP_OK) - condlog(0, "%s: %s: error getting map status string: %d", - __func__, name, r); - - return r; -} - int dm_is_mpath(const char *name) { char uuid[DM_UUID_LEN]; diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h index 7231a98..3daaa4c 100644 --- a/libmultipath/devmapper.h +++ b/libmultipath/devmapper.h @@ -131,8 +131,6 @@ int dm_simplecmd_noflush (int task, const char *name, uint16_t udev_flags); int dm_addmap_create (struct multipath *mpp, char *params); int dm_addmap_reload (struct multipath *mpp, char *params, int flush); int dm_map_present_by_wwid(const char *uuid); -int dm_get_map(const char *name, unsigned long long *size, char **outparams); -int dm_get_status(const char *name, char **outstatus); enum { DM_IS_MPATH_NO, diff --git a/libmultipath/structs_vec.c b/libmultipath/structs_vec.c index ccc4efc..f2cfe31 100644 --- a/libmultipath/structs_vec.c +++ b/libmultipath/structs_vec.c @@ -484,30 +484,34 @@ int update_multipath_table (struct multipath *mpp, vector pathvec, int flags) { int r = DMP_ERR; - char *params = NULL; + char __attribute__((cleanup(cleanup_charp))) *params = NULL; + char __attribute__((cleanup(cleanup_charp))) *status = NULL; + unsigned long long size = mpp->size; if (!mpp) return r; - r = dm_get_map(mpp->alias, &mpp->size, ¶ms); + r = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY, + (mapid_t) { .str = mpp->alias }, + (mapinfo_t) { + .target = ¶ms, + .status = &status, + .size = &mpp->size, + }); + if (r != DMP_OK) { - condlog(2, "%s: %s", mpp->alias, (r == DMP_ERR)? "error getting table" : "map not present"); + condlog(2, "%s: %s", mpp->alias, dmp_errstr(r)); return r; - } + } else if (size != mpp->size) + condlog(0, "%s: size changed from %llu to %llu", mpp->alias, size, mpp->size); if (disassemble_map(pathvec, params, mpp)) { condlog(2, "%s: cannot disassemble map", mpp->alias); - free(params); return DMP_ERR; } - free(params); - params = NULL; - if (dm_get_status(mpp->alias, ¶ms) != DMP_OK) - condlog(2, "%s: %s", mpp->alias, (r == DMP_ERR)? "error getting status" : "map not present"); - else if (disassemble_status(params, mpp)) + if (disassemble_status(status, mpp)) condlog(2, "%s: cannot disassemble status", mpp->alias); - free(params); /* FIXME: we should deal with the return value here */ update_pathvec_from_dm(pathvec, mpp, flags); From patchwork Fri Jul 12 17:14:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13732086 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A6032176ABE for ; Fri, 12 Jul 2024 17:16:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804574; cv=none; b=FSNimaSZoWDY1ubralcU91lhfm63Oz4tul5hWRZFZHW0vtzi6jOIjziD+5kA4+bCoNbVWoYTD1sYQfDETQln5mlE8ik8Wl7Zc2tQDoMjIVEbUSrkVNyoj5coAGvEr1CEFoW+5W5tlKcyoJJfFph7M3bSi2PiAGqwKFkwYmF55nM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804574; c=relaxed/simple; bh=f6FJwVNd/STw2y9zRsAPqzEXHFiQ9ypYedvhDpRA+JE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=c/1COba6zSdIwhoQqWCvLB5lmCRzDdUftchtxhIZlTgfUv6TPDLnxI0YunAGeww/EA937TOp8u6+LG138PmfeOC+GGp4KdamenJXypHAm5KOinPr3th2grYq2ObU+fPc3kJ0likA160Me1B3pRvmT5bG0r8Z64eyX256zQ21eJo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=Ix3Rijmw; arc=none smtp.client-ip=209.85.208.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="Ix3Rijmw" Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-58b447c5112so3121974a12.3 for ; Fri, 12 Jul 2024 10:16:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1720804571; x=1721409371; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jgjj4l5iw6Q6BQz/iiJXLjnYQf7taPZxWA6gM/urBSE=; b=Ix3RijmwIWD714ikGOS3OsP3NlVR6VDyv3PWfB2ONLyoyBNeu7VDraHAnKqToTe5sY Co+8ltNR5z2QaoEM8nVMPfPg5Hno3mnSoXoYPuNG6lmEjBoMtl18y2lbP5wmm0h643M7 BtZUNBGgcprf1TT1UaVYb/Cq7TCwl/DD98fg1bPSJwdvJChoXgA1AiD1MdU64ivfIjw0 k7F1HGDoYdLyxN8HOxwXqAhLmZbC2Et7ui0qMDl9AFfafgQmFTtpbogc7mC8FzwwpgyI /N7wHI4QAtsHyRubfR2Vx+FWeJSC5AOSgmKdoDP46Fh4xTqBBMQYt6I/DPqyvqF2jTYL 0O6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720804571; x=1721409371; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jgjj4l5iw6Q6BQz/iiJXLjnYQf7taPZxWA6gM/urBSE=; b=m8wti1BH7N7wdYaBcqUoyCIPAjr6ug3nskdVHKzxTzp7MhDS2FzrQeN6HStVTOilRE K6QGhXaYzAnHZLgmu9IuWSy35vx6sZQWeDfCbPkwXXSHUseI4oO7PfDcbRvLSrh6inAI V9gq1DgVOgrChfy2iU6dktQDnUz4g17KUf9i2UCfUNDae6D/OmLBLkEter2W9Uchl2uD Bo2rV/NqkgKB1WTc0OWkLmrxCc06r+k8ZEW5EMUJ4tdnsDI1blYM2EuxJaHojB6VbC8M 9MNp5meqzd1TOeZoGD9VMMMn5VTMbZpAccfN77+U5R9a/rZuL4S6/ColOUbx5mrpdZMu 7NhQ== X-Gm-Message-State: AOJu0YyBu/WKdOcx3mqGd21w0+l7ytYt6cATGtMUlye+YLy6vVBEFUlD jk3QAqwg5OFlG9XEO+0CrJ3LPpgv7lRdVehARj3XVaCLZmusC1rWx9wwkCd5uaE= X-Google-Smtp-Source: AGHT+IFJsaDX8QW2eRRBkkjaHwnilokSjpyAlFr9VO7bAaNSdkOlt0L87PeH9eFfvYwScfPEoNPWxg== X-Received: by 2002:a05:6402:34c8:b0:595:7c14:18da with SMTP id 4fb4d7f45d1cf-5957c141933mr8730657a12.34.1720804570974; Fri, 12 Jul 2024 10:16:10 -0700 (PDT) Received: from localhost (p200300de37360a00d7e56139e90929dd.dip0.t-ipconnect.de. [2003:de:3736:a00:d7e5:6139:e909:29dd]) by smtp.gmail.com with UTF8SMTPSA id 4fb4d7f45d1cf-5959bd1d4bdsm4003325a12.88.2024.07.12.10.16.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 10:16:10 -0700 (PDT) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, Martin Wilck Subject: [PATCH v2 38/49] libmultipath: update mpp->dmi in update_multipath_table() Date: Fri, 12 Jul 2024 19:14:46 +0200 Message-ID: <20240712171458.77611-39-mwilck@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712171458.77611-1-mwilck@suse.com> References: <20240712171458.77611-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This comes almost for free now. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/structs_vec.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libmultipath/structs_vec.c b/libmultipath/structs_vec.c index f2cfe31..295dac8 100644 --- a/libmultipath/structs_vec.c +++ b/libmultipath/structs_vec.c @@ -497,6 +497,7 @@ update_multipath_table (struct multipath *mpp, vector pathvec, int flags) .target = ¶ms, .status = &status, .size = &mpp->size, + .dmi = &mpp->dmi, }); if (r != DMP_OK) { From patchwork Fri Jul 12 17:14:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13732087 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 13A9A176FAB for ; Fri, 12 Jul 2024 17:16:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804575; cv=none; b=o+HQX0INK0dftQNTdGhNMMrtL1SBuoJDKGNCj6ZMjgyH9yRqcxwgq565WbJeZ02jrcVRSznHT7NM8XRgRuPhzPxKglHuIOaQ6mrbiq9vS0FB/znx9yGEk1B3ju1qfCu+EtZq/ar1c1zUeTUjC+FP+NC+YE7JKRyohBwNro9RGqQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804575; c=relaxed/simple; bh=3mJfe5elNzQEbuXYSPBcymKhL6AzUUma4FQY5aZnSCo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=To/l0ihGha5PnhGlIRG85gEmBpj6Lb24/Hac9NS3q1yqmX6ElsQXMT1pXhpkvROoCnBVVrdbAoQQ1x2k7NWLyvnlkRKqw4vULZmeXxP1gQIGbWXjYMXeZVKgBHbKnwSh5RlRTtvI9dyxaohDjCRPRCRdZxn9w55B9RHorja/X3c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=Cf92xl9l; arc=none smtp.client-ip=209.85.167.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="Cf92xl9l" Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-52ea79e689eso3134507e87.1 for ; Fri, 12 Jul 2024 10:16:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1720804572; x=1721409372; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bxqsESTpjg9CK28sjPNodqMRrZfivIXhocnUtglpk1I=; b=Cf92xl9lqBKKMOmde3hHKEzic6DLRWwkVYffBqxg/YYqbszkJicZQZHpjy0GOVvRK2 +faQwPcl4T9ySFVoveQFYEYWmwzqfDQjNmx59hxJmQP/kgneEJju+fls55GQ0shUjr98 zL5JYcFCMzKxkXuC43S3VDh7wYmu4EF0p2NjQBHVbG134iZtcPVS06WxOVYRgp6SNwuN cZBt990/JNsXYopxb8tC0UcYwrokife9+HGAwXrogYUIBUHuGkSC0avtNxiOrX036a6k Nx0hM5IMjN7VI9H0xxN9tftwhfVXnTK5mOqbWHgUzFiTNxD5bOFPYpqmU/xeNW+vmD2d rOjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720804572; x=1721409372; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bxqsESTpjg9CK28sjPNodqMRrZfivIXhocnUtglpk1I=; b=OrrtUX02WXHkTR5M+qFFcEVS7z94rvGuPaQPH8cirHpYFNlHGA1UcLcn4TSxvKJGrk 5Dxem3z3ckf169kqLrv3dmjjdH851jWD8P1eNnthlGO+TZIC3JY9pT0AaIDZ1kzplS5F Dx1g1Mw2MzEzwclfnsN2PHXtiJ6WsPvZaLQnCW65OqXkqGvrvDE6OUa7ODfwwOLUomFh Vx2jrGYXAyFMxvJEXS5kXkLcF5z8aAyrLtmfXhSUcrAAS4LU+tGx2D6+JXQU3GniplCH 541KtLeLwv99acyj0Rl53Ku8L5LgMKWPINkjLcgkE4g/pPEiV7LvxmGNUXq1Uis9JxdR OrAQ== X-Gm-Message-State: AOJu0YzlPQKw1K/+oLqF7ihMp23pft6FRwQmn8qgdQK+rtXyuvigIuwD 721FFXrqIuJFBQsZ8/1sdTckkehYVpAQz6X0PyDhsY2CWAFySgQnyqBkmXkgSW4= X-Google-Smtp-Source: AGHT+IH5vWp2D1RecFnwBAHqre6Ah50z2ylv0sB+PJj6sP4RaMdaoxKJ4geU7dP3pbCG27gS3xWeIg== X-Received: by 2002:a05:6512:3b9d:b0:52b:be6b:d16a with SMTP id 2adb3069b0e04-52eb99a3526mr11243463e87.31.1720804572160; Fri, 12 Jul 2024 10:16:12 -0700 (PDT) Received: from localhost (p200300de37360a00d7e56139e90929dd.dip0.t-ipconnect.de. [2003:de:3736:a00:d7e5:6139:e909:29dd]) by smtp.gmail.com with UTF8SMTPSA id a640c23a62f3a-a780a6e37c4sm360583966b.82.2024.07.12.10.16.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 10:16:12 -0700 (PDT) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, Martin Wilck Subject: [PATCH v2 39/49] libmultipath: drop extra call to dm_map_present() in domap() Date: Fri, 12 Jul 2024 19:14:47 +0200 Message-ID: <20240712171458.77611-40-mwilck@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712171458.77611-1-mwilck@suse.com> References: <20240712171458.77611-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 dm_get_wwid() will return DMP_NOT_FOUND if the map doesn't exist. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/configure.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libmultipath/configure.c b/libmultipath/configure.c index 2fdaca8..b4de863 100644 --- a/libmultipath/configure.c +++ b/libmultipath/configure.c @@ -834,6 +834,7 @@ 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 @@ -843,8 +844,7 @@ int domap(struct multipath *mpp, char *params, int is_daemon) return DOMAP_DRY; } - if (mpp->action == ACT_CREATE && dm_map_present(mpp->alias)) { - char wwid[WWID_SIZE]; + if (mpp->action == ACT_CREATE) { int rc = dm_get_wwid(mpp->alias, wwid, sizeof(wwid)); if (rc == DMP_OK && !strncmp(mpp->wwid, wwid, sizeof(wwid))) { From patchwork Fri Jul 12 17:14:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13732088 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1664D171644 for ; Fri, 12 Jul 2024 17:16:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804577; cv=none; b=mp1pqJ6mDeKrNTbVNmhyZkE4HLwpSSdY3nansZg48ldO9arVLt+O3JTfuClesSkC2QE85ZTm2jORYH40g6UhDUVJ4uHkRcM46AW4ADxMV3oETx86hJbCijjnd1CmhsHhDGUestAB2K8EEHlRUwma7vQwohprzAm8lvDrj7L/qiU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804577; c=relaxed/simple; bh=bv2XiB53844utqamUEmtJ6ZlUTjE1ZLSB3RHagXCOEk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UiKqZkmaLvPXucl3/yqdckQUClckKrYMZaH8T/apMVrWUfyUz16jXlyY2q1gsh0AWMHnMy3GQs6wBIti7Gi1A+vkpdFEkDaL7tLrO6bcnI86KGM5boNV1APOYUGXnJKolSxzkCFRcKpE02zWRqxA5afTjGEyQ4GGZXPu8oLtMYc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=Ew4LDbke; arc=none smtp.client-ip=209.85.167.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="Ew4LDbke" Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-52e97e5a84bso3267622e87.2 for ; Fri, 12 Jul 2024 10:16:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1720804573; x=1721409373; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dQdLiGWmsHk+StvFm4Bmikh4b/IlgqNFJrtjTUzaBFU=; b=Ew4LDbkeLQ09LMRYMMTJMCrrCcSJL8WJxhocn7Tw9XOoeb+tQ8sao0hTRN3KI+R58L fXMVUn6K2bn36i000+OJb0ts4E5Q8IU6iqpRvpT4IHw9rgMdgIhCm7pDcpsluaIiIwkC IU4Jrc0hAeJ4R4tWYOFcdOL09RFdv46TPdvIeaZS1nJ7qQzzSszatApiYJ2cQFoTh8Dw lHIccSkZh0r60RGG44sgXlzKXzZZRCSwT9iJwEeNwRdL3YmkVfF4SXxxNmqnvEPjy8fU V6job5n7zd0zPAw5OnIrxG3iMZDvA7Zl3QyOl8NmyRg+YN+/v2oEddPX0xW+5NDdNXxH l9UA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720804573; x=1721409373; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dQdLiGWmsHk+StvFm4Bmikh4b/IlgqNFJrtjTUzaBFU=; b=Q9gkhgYGNWW4+9PHd9B1qclUTeJg0CKCrApGgSizqr5+2nmtW8SlTXGkeOjxP65+qE voAApQm0Z2Q4Ie+BUg+9zbtwLFFWnDh244Jbul5GrNWIRlxxe82BjB6UccOoAsVOTJcK JO4GbqJ8y9K4E3ZRIwGdgZ9n5kSO8ZZKJ2G6fbGG4n0hAd+qT+E8PpgrzPSuBMdYQ0Dp Tm1f/Wt/WrR8IrpgusZBqHR2lHF7NKxvgq1+ekhVHOX3oCh7KotpU/7KwF2AY4sS7Ly7 Be2L1rDYIeLzdpcdzZRJqGyrzfUAxiE03uPz7PwtJCi2pOBgp4UDcYxUAIrBkACztwnn CJdg== X-Gm-Message-State: AOJu0YyBBtsxYrGgPCT7D/bb3PyArrpXi8AJ3/gix6B4J4VJsK3Il8vf A3h1Ztnsx+fLx29oDbYG6GWLgGkX5QbeI+JAMqoGGg/Wh6CPrTBv1orFncB1Iiw= X-Google-Smtp-Source: AGHT+IEN9pK3mYfv4RqwnLoH4HrkwIqe/3RTlTTIRSkwfEuMkFUndOCzn52zprYJR/MDAtTFrxlOaw== X-Received: by 2002:ac2:442e:0:b0:52c:e17c:cd7b with SMTP id 2adb3069b0e04-52eb999c2cfmr8693666e87.22.1720804573154; Fri, 12 Jul 2024 10:16:13 -0700 (PDT) Received: from localhost (p200300de37360a00d7e56139e90929dd.dip0.t-ipconnect.de. [2003:de:3736:a00:d7e5:6139:e909:29dd]) by smtp.gmail.com with UTF8SMTPSA id a640c23a62f3a-a780a87208asm360998566b.210.2024.07.12.10.16.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 10:16:13 -0700 (PDT) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, Martin Wilck Subject: [PATCH v2 40/49] libmultipath: split off update_multipath_table__() Date: Fri, 12 Jul 2024 19:14:48 +0200 Message-ID: <20240712171458.77611-41-mwilck@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712171458.77611-1-mwilck@suse.com> References: <20240712171458.77611-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Split off the part of the function that does the disassembly from the part calling libmp_mapinfo(). This makes it possible to call the function from a context where the map info is already available. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/libmultipath.version | 1 + libmultipath/structs_vec.c | 31 +++++++++++++++++++------------ libmultipath/structs_vec.h | 2 ++ 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/libmultipath/libmultipath.version b/libmultipath/libmultipath.version index 5b8f9e0..54b5a23 100644 --- a/libmultipath/libmultipath.version +++ b/libmultipath/libmultipath.version @@ -206,6 +206,7 @@ global: uninit_config; update_mpp_paths; update_multipath_strings; + update_multipath_table__; update_multipath_table; update_queue_mode_add_path; update_queue_mode_del_path; diff --git a/libmultipath/structs_vec.c b/libmultipath/structs_vec.c index 295dac8..731b1bc 100644 --- a/libmultipath/structs_vec.c +++ b/libmultipath/structs_vec.c @@ -480,6 +480,24 @@ done: condlog(2, "%s: no hwe found", mpp->alias); } +int +update_multipath_table__ (struct multipath *mpp, vector pathvec, int flags, + const char *params, const char *status) +{ + if (disassemble_map(pathvec, params, mpp)) { + condlog(2, "%s: cannot disassemble map", mpp->alias); + return DMP_ERR; + } + + if (disassemble_status(status, mpp)) + condlog(2, "%s: cannot disassemble status", mpp->alias); + + /* FIXME: we should deal with the return value here */ + update_pathvec_from_dm(pathvec, mpp, flags); + + return DMP_OK; +} + int update_multipath_table (struct multipath *mpp, vector pathvec, int flags) { @@ -506,18 +524,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); - if (disassemble_map(pathvec, params, mpp)) { - condlog(2, "%s: cannot disassemble map", mpp->alias); - return DMP_ERR; - } - - if (disassemble_status(status, mpp)) - condlog(2, "%s: cannot disassemble status", mpp->alias); - - /* FIXME: we should deal with the return value here */ - update_pathvec_from_dm(pathvec, mpp, flags); - - return DMP_OK; + return update_multipath_table__(mpp, pathvec, flags, params, status); } static struct path *find_devt_in_pathgroups(const struct multipath *mpp, diff --git a/libmultipath/structs_vec.h b/libmultipath/structs_vec.h index dbc4305..01f5dc4 100644 --- a/libmultipath/structs_vec.h +++ b/libmultipath/structs_vec.h @@ -33,6 +33,8 @@ struct multipath * add_map_with_path (struct vectors * vecs, const struct multipath *current_mpp); void update_queue_mode_del_path(struct multipath *mpp); void update_queue_mode_add_path(struct multipath *mpp); +int update_multipath_table__ (struct multipath *mpp, vector pathvec, int flags, + const char *params, const char *status); int update_multipath_table (struct multipath *mpp, vector pathvec, int flags); int update_multipath_status (struct multipath *mpp); vector get_used_hwes(const struct _vector *pathvec); From patchwork Fri Jul 12 17:14:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13732089 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-lj1-f175.google.com (mail-lj1-f175.google.com [209.85.208.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2685A176240 for ; Fri, 12 Jul 2024 17:16:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804579; cv=none; b=l7cu2obx7PrBfDnikqiYVhXNzwIF7S+10RkKqpBfs0Al1/4O2X6gn9guxGPHvQj632MBEarJlXjPWAW+iDMLPr/thaItCT8WLLm6wXWoFJMafTcKVuo6xrRVLrgwX1phGcYf8/20HQV7wPPSL6tXuXHxOVmpX54Db5JPHxiUUj8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804579; c=relaxed/simple; bh=hma3/4Dy7UQTOuiP+1h8onTKqDe18yTEJMCV/y2zkcI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=f/Qvg/mfYPk0vvDTWwebQ/+PN2C30sqApZ+ykmON57NjODPo6MsQvtOjgPmEUSDXNljXPcqneqeYpr7JKzxpCsvJoXwTU8Ytuu1ZGyTPyEMAWNamMB6rByAMWO2hDtQ5FvICCvsNlKiZ4pnlmK4W7BL8kqiqsRWuzpjdhH3bVyI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=QTaCNgWP; arc=none smtp.client-ip=209.85.208.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="QTaCNgWP" Received: by mail-lj1-f175.google.com with SMTP id 38308e7fff4ca-2eeb2d60efbso26565251fa.1 for ; Fri, 12 Jul 2024 10:16:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1720804575; x=1721409375; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bsuNKbvHcKi2RQYjrHttssRResADhWilo+piqecnAFE=; b=QTaCNgWPCNGFPlf9JHFpyYtnk7CrPVPG41L+coAR0yWjp0inLnBaFjWZsaL+QebY5N hM+AXeeZQDPwuThnr98jffb/ijsuk67lMeot89Sqbk1jXLBKux8dAQlR+hdumoAwPrQG MYZv+vgRf7uDQQrihBOPypSpjwWKw7aCVYEba2t+I7Ri4vlP/kF+ptaDDtEQiCa53zn7 /uLOlRHxz00JvvB44szZILePNnrO1KMBzCfijYaxYuNXzvX3r6oxC9hwPyY/w3nSDo2X q0V4E4Z7CVCYhYu4CkU4GuhEudoQLrjZeZY60D6iuxLvYH71rJUhAgxe09EqWZ3bPky4 D8qQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720804575; x=1721409375; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bsuNKbvHcKi2RQYjrHttssRResADhWilo+piqecnAFE=; b=qILpcdzHDBiwVHF/M8Fw0n8bRxpdZYk367Q7kT4or2bIyE+/otv3WWT3rkAgZhV69J mu/YQnJxc2vZcEr9YWTTmQ/ohME9CpkZxv1eYTNHnQDLMNl+bXEeEuBfeYZV7cHY5aD2 RmZyTEdJVrdITAW+0wmgUDkyS7Cib9xUCgeAyqgQkgAZNO1HgO3jOemSbNTXYqtfJ7S/ 8Iduyp3qX2G4Dj62NW1cN3z+OeQxgdpbP4bftR1Kj8uzmaOmax9JaguXlKhxGOUpqVtv +KjaMh/utrUWyFxDg+6reWdv/Ss8E0H6eogwAv5Da3HnbHf1QPpaqsdrbODzhWO3X9JJ hkNg== X-Gm-Message-State: AOJu0YyaQ9LIIgHzHh7eJDJQF6SbWcQhvHNSscEDoDPnSdYoL46m/bX7 CKy+veMtNuZUbdAFG/8ajJvJ4J7Rf40wT6ginrX7XH5GKOzAUJIeCI/sbRHc7fk= X-Google-Smtp-Source: AGHT+IHgFjfL3pvPdLpzBeOETNV8gEqr5LyDn1DuZnawZJFN2JhEzFz3fmr1ElQKaal5U0DNYu+odg== X-Received: by 2002:a2e:9dd3:0:b0:2ec:51b5:27c8 with SMTP id 38308e7fff4ca-2eeb3171537mr82069961fa.32.1720804574217; Fri, 12 Jul 2024 10:16:14 -0700 (PDT) Received: from localhost (p200300de37360a00d7e56139e90929dd.dip0.t-ipconnect.de. [2003:de:3736:a00:d7e5:6139:e909:29dd]) by smtp.gmail.com with UTF8SMTPSA id 4fb4d7f45d1cf-594bb96062bsm4778225a12.12.2024.07.12.10.16.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 10:16:14 -0700 (PDT) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, Martin Wilck Subject: [PATCH v2 41/49] multipath: implement check_usable_paths() with libmp_pathinfo() Date: Fri, 12 Jul 2024 19:14:49 +0200 Message-ID: <20240712171458.77611-42-mwilck@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712171458.77611-1-mwilck@suse.com> References: <20240712171458.77611-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 ... and use cleanup attributes. We need to call the disassemble...() functions from multipath directly now, but we fetch exactly the data we need from the kernel. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- multipath/main.c | 58 ++++++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/multipath/main.c b/multipath/main.c index c82bc86..0d989dc 100644 --- a/multipath/main.c +++ b/multipath/main.c @@ -222,12 +222,14 @@ get_dm_mpvec (enum mpath_cmds cmd, vector curmp, vector pathvec, char * refwwid) static int check_usable_paths(struct config *conf, const char *devpath, enum devtypes dev_type) { - struct udev_device *ud = NULL; - struct multipath *mpp = NULL; + struct udev_device __attribute__((cleanup(cleanup_udev_device))) *ud = NULL; + struct multipath __attribute__((cleanup(cleanup_multipath_and_paths))) *mpp = NULL; struct pathgroup *pg; struct path *pp; - char *mapname; - vector pathvec = NULL; + char __attribute__((cleanup(cleanup_charp))) *params = NULL; + char __attribute__((cleanup(cleanup_charp))) *status = NULL; + vector __attribute((cleanup(cleanup_vector))) pathvec = NULL; + char uuid[DM_UUID_LEN]; dev_t devt; int r = 1, i, j; @@ -238,31 +240,39 @@ static int check_usable_paths(struct config *conf, devt = udev_device_get_devnum(ud); if (!dm_is_dm_major(major(devt))) { condlog(1, "%s is not a dm device", devpath); - goto out; + return r; } - mapname = dm_mapname(major(devt), minor(devt)); - if (mapname == NULL) { - condlog(1, "dm device not found: %s", devpath); - goto out; - } - - if (dm_is_mpath(mapname) != DM_IS_MPATH_YES) { - condlog(1, "%s is not a multipath map", devpath); - goto free; - } + mpp = alloc_multipath(); + if (!mpp) + return r; + if (!(mpp->alias = malloc(WWID_SIZE))) + return r; /* pathvec is needed for disassemble_map */ pathvec = vector_alloc(); if (pathvec == NULL) - goto free; + return r; - mpp = dm_get_multipath(mapname); - if (mpp == NULL) - goto free; + if (libmp_mapinfo(DM_MAP_BY_DEVT | MAPINFO_MPATH_ONLY, + (mapid_t) { .devt = devt }, + (mapinfo_t) { + .name = mpp->alias, + .uuid = uuid, + .dmi = &mpp->dmi, + .size = &mpp->size, + .target = ¶ms, + .status = &status, + }) != DMP_OK) + return r; - if (update_multipath_table(mpp, pathvec, 0) != DMP_OK) - goto free; + if (!is_mpath_uuid(uuid)) + return r; + + strlcpy(mpp->wwid, uuid + UUID_PREFIX_LEN, sizeof(mpp->wwid)); + + if (update_multipath_table__(mpp, pathvec, 0, params, status) != DMP_OK) + return r; vector_foreach_slot (mpp->pg, pg, i) { vector_foreach_slot (pg->paths, pp, j) { @@ -284,12 +294,6 @@ static int check_usable_paths(struct config *conf, found: condlog(r == 0 ? 3 : 2, "%s:%s usable paths found", devpath, r == 0 ? "" : " no"); -free: - free(mapname); - free_multipath(mpp, FREE_PATHS); - vector_free(pathvec); -out: - udev_device_unref(ud); return r; } From patchwork Fri Jul 12 17:14:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13732090 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-ed1-f52.google.com (mail-ed1-f52.google.com [209.85.208.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C729517C6B for ; Fri, 12 Jul 2024 17:16:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804579; cv=none; b=A7FxdxWsv9zdJcicTqvRmxWu9OcFzizDgo2QAAPnqPD3lKCzOmZuiJgJrHcP6zI+XBX3Ek71DA91z0aPrtPiiOVYLFZQUK0huzjORh58ZwHhzHcWZIua8fGt2qYSqLLisb4c4IJ0su9oYj+6g/VWiJtYObPjg6958jmb9i3JvpI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804579; c=relaxed/simple; bh=0SefcOZA2VGyfnGdP9TrIvcSJBuU2atdXx6iWLAxW5g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MFmqlTtV+QPf7p+2asj0xZHBiIg2pi6HMbbUfro+p6pDtw4FlSaFvnAaMdg9DPEJLQqvPtizxw39aaWhyM2g7CQh4jrODaLCVIojdMAI9du1UF91SyHrsXpa00uQuuPPxoyD7DeXCt03jr7ajaz+Va3DCsyjgd0PHkw0kogBtAU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=aIuD/vOQ; arc=none smtp.client-ip=209.85.208.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="aIuD/vOQ" Received: by mail-ed1-f52.google.com with SMTP id 4fb4d7f45d1cf-57cf8880f95so2808015a12.3 for ; Fri, 12 Jul 2024 10:16:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1720804576; x=1721409376; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4t6Jj3ad2vs5+I9v4godq/mHLy5FWdIDHzP5z/52gbc=; b=aIuD/vOQhqs2FVvFreefuT8lFgoVw9+8Ary2iaYGRIxt065lQ0QGe9kmh6D1KWNgck DGuPvqMBW145s3cCd6KSpXhNLTLdf8kBgzu6oUgMwPm3s4bTNaZXNr8tSaNDTZUghJhK JEZinP5sPe8ct0Gvgdfhe4b4lwXcmhYQ5Obsl7b8A4I8lJY8L8QRyc+2Gz6l9rQL/P6+ Iy2LALzcFcfopjA5rMSk3kVFWP5O1X3wAVy88UOG+2gMNFpawPwr+lWP+NSFP7N3pbFA xq4wipDKLBttROCFBal/aqO/LQCky/irZyTaUdBB+PJjaycgv8qVrVJQOJV9p4a6xxQT RMow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720804576; x=1721409376; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4t6Jj3ad2vs5+I9v4godq/mHLy5FWdIDHzP5z/52gbc=; b=u9uPbi9EdtfXhZPp8N2qqY9MJiSghjtoO7YbEkZUqNDp2Ok8xDJp2Y8ixZ4w+BpDLE OcRON1EWSAQU0yE+EKbdJW2gmho9ybGZFpiKKYdtWrbZAJlU9nXg3PxU/g9WoGMeVYmz HLWxxXWphIJzfU8wOGhM3qxZiOPGK0lKlMMo2/KmM9UNKcx1qIcuv58UN696oEEQN3GA a909naj5OK6ND+BbI/yQQJIENTHaTrXRNcPr3Oqgs5WryvugsCSbJwatCoYyqMY0jWEn 22YeB/IGOECqeDMnFBfy6pCbRQKn54DEAKX5k/yFkbilAiHS8sie4r0uBdxW8GuVKFrV IKDQ== X-Gm-Message-State: AOJu0Yx2iEtDLZtxLU992rVL7NE+Z+z29SWymPRZEMNkpk3I02SJIe5j +mJzseIhI85Piz7qoPV6Qs7w867AYjl0/Lfbe9KAnkXF0+8RxASxvzsyeqK/FIk= X-Google-Smtp-Source: AGHT+IFDjWLmYBJl4YRdH0aMP6zTqhOU9J/dj8dEtlGFyxIXN38BEP63hN5BO3aZfrFUDOlLhUsKJg== X-Received: by 2002:a17:906:e0d4:b0:a72:9001:ed73 with SMTP id a640c23a62f3a-a780b88277amr993221166b.50.1720804576148; Fri, 12 Jul 2024 10:16:16 -0700 (PDT) Received: from localhost (p200300de37360a00d7e56139e90929dd.dip0.t-ipconnect.de. [2003:de:3736:a00:d7e5:6139:e909:29dd]) by smtp.gmail.com with UTF8SMTPSA id a640c23a62f3a-a780a87213dsm361138966b.221.2024.07.12.10.16.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 10:16:16 -0700 (PDT) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, Martin Wilck Subject: [PATCH v2 42/49] multipathd: implement add_map_without_path() with libmp_mapinfo() Date: Fri, 12 Jul 2024 19:14:50 +0200 Message-ID: <20240712171458.77611-43-mwilck@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712171458.77611-1-mwilck@suse.com> References: <20240712171458.77611-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Also, change the return value to int, as this is more expressive and the returned struct multipath isn't used by the caller. Also remove the call to sync_map_state() in ev_add_map(), which is redundant because add_map_without_path() would have called update_map() and thus sync_map_state() already. Note: this removes the call to remove_map() at the end of the function, which doesn't make sense anyway, because update_multipath_table() would not return error unless the table disassembly failed, in which case nothing would have been added the the mpvec or pathvec yet. It should be sufficient to just cleanup the local data structures when add_map_without_path() fails. Signed-off-by: Martin Wilck --- multipathd/main.c | 79 ++++++++++++++++++++++++----------------------- 1 file changed, 41 insertions(+), 38 deletions(-) diff --git a/multipathd/main.c b/multipathd/main.c index 1e7a6ac..536974c 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -707,51 +707,57 @@ fail: return 0; } -static struct multipath * -add_map_without_path (struct vectors *vecs, const char *alias) +static int add_map_without_path (struct vectors *vecs, const char *alias) { - struct multipath * mpp = alloc_multipath(); + struct multipath __attribute__((cleanup(cleanup_multipath_and_paths))) + *mpp = alloc_multipath(); + char __attribute__((cleanup(cleanup_charp))) *params = NULL; + char __attribute__((cleanup(cleanup_charp))) *status = NULL; struct config *conf; + char uuid[DM_UUID_LEN]; + int rc = DMP_ERR; - if (!mpp) - return NULL; - if (!alias) { - free(mpp); - return NULL; - } + if (!mpp || !(mpp->alias = strdup(alias))) + return DMP_ERR; - mpp->alias = strdup(alias); + if ((rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY, + (mapid_t) { .str = mpp->alias }, + (mapinfo_t) { + .uuid = uuid, + .dmi = &mpp->dmi, + .size = &mpp->size, + .target = ¶ms, + .status = &status, + })) != DMP_OK) + return rc; + + if (!is_mpath_uuid(uuid)) + return DMP_NO_MATCH; + else + strlcpy(mpp->wwid, uuid + UUID_PREFIX_LEN, sizeof(mpp->wwid)); - if (dm_get_info(mpp->alias, &mpp->dmi) != DMP_OK) { - condlog(3, "%s: cannot access table", mpp->alias); - goto out; - } - if (!strlen(mpp->wwid) && - dm_get_wwid(mpp->alias, mpp->wwid, WWID_SIZE) != DMP_OK) { - condlog(3, "%s: cannot obtain WWID", mpp->alias); - goto out; - } if (!strlen(mpp->wwid)) condlog(1, "%s: adding map with empty WWID", mpp->alias); + conf = get_multipath_config(); mpp->mpe = find_mpe(conf->mptable, mpp->wwid); put_multipath_config(conf); - if (update_multipath_table(mpp, vecs->pathvec, 0) != DMP_OK) - goto out; + if ((rc = update_multipath_table__(mpp, vecs->pathvec, 0, params, status)) != DMP_OK) + return DMP_ERR; if (!vector_alloc_slot(vecs->mpvec)) - goto out; + return DMP_ERR; + vector_set_slot(vecs->mpvec, steal_ptr(mpp)); - vector_set_slot(vecs->mpvec, mpp); + /* + * We can pass mpp here, steal_ptr() has just nullified it. + * vector_set_slot() just set the last slot, use that. + */ + if (update_map(VECTOR_LAST_SLOT(vecs->mpvec), vecs, 1) != 0) /* map removed */ + return DMP_ERR; - if (update_map(mpp, vecs, 1) != 0) /* map removed */ - return NULL; - - return mpp; -out: - remove_map(mpp, vecs->pathvec, vecs->mpvec); - return NULL; + return DMP_OK; } static int @@ -865,14 +871,9 @@ int ev_add_map (char * dev, const char * alias, struct vectors * vecs) { struct multipath * mpp; - int reassign_maps; + int reassign_maps, rc; struct config *conf; - if (dm_is_mpath(alias) != DM_IS_MPATH_YES) { - condlog(4, "%s: not a multipath map", alias); - return 0; - } - mpp = find_mp_by_alias(vecs->mpvec, alias); if (mpp) { @@ -910,10 +911,12 @@ ev_add_map (char * dev, const char * alias, struct vectors * vecs) /* * now we can register the map */ - if ((mpp = add_map_without_path(vecs, alias))) { - sync_map_state(mpp); + if ((rc = add_map_without_path(vecs, alias)) == DMP_OK) { condlog(2, "%s: devmap %s registered", alias, dev); return 0; + } else if (rc == DMP_NO_MATCH) { + condlog(4, "%s: not a multipath map", alias); + return 0; } else { condlog(2, "%s: ev_add_map failed", dev); return 1; From patchwork Fri Jul 12 17:14:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13732091 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-ed1-f45.google.com (mail-ed1-f45.google.com [209.85.208.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 07797171644 for ; Fri, 12 Jul 2024 17:16:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804581; cv=none; b=bHwcdTK/nWQRKEZYc1MPpxvFmsTvwxEMzGvhD+9QKHNU1y4xSiajM95MOW9r1R9LNCdEDf96eDpkH4V8FU2LNJR2Ka7WHdYsQ3vdpJapl8bSfPj4fETTE7Es1sr+dzaS4DSV71h+hDwi4EpeLQb0pHLmchHPI+vQrZI+01glsNs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804581; c=relaxed/simple; bh=l+So8C98Vkng7UsbS5wUnPgzLBUlGOE+NCUp4/6T7+U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y1AZsyvHX+0k6jjunoPJw+4SM3eGZMVlD8z4/UmSvDX/i2zecUxaOISVA5k7SIb0IbmicVcdNp9CARatDmq/98FT/tlwBAKlQDayIgwveaOetLwFVcUd13fhImERV5a40TjZERYDUGNGuvx/71QUwKWjgNeH9v2oebd6K83zC3s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=SAUYtg9v; arc=none smtp.client-ip=209.85.208.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="SAUYtg9v" Received: by mail-ed1-f45.google.com with SMTP id 4fb4d7f45d1cf-58be2b8b6b2so2903846a12.3 for ; Fri, 12 Jul 2024 10:16:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1720804577; x=1721409377; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2ffMD0XQCVtitda9bJYFeR9HeIWQ36ZylmX7OTCZPtY=; b=SAUYtg9vy7+oMlyvtvXsNi6hSdxEUrRvdlTHYzA6Hi7BUUZhVaYPy8+XRGW4GzmwfM hYQWFFOHvqu2sctBUQgop929RxVVseHNcO4EnNAdWDrKoOpr1OCKSNFSB/KVMiCW9tKB gwDji8zBTpC8Um2Ofz2G9uPDxXCn0jphaRsNcUFqsVPbhPLHwbnwxa8M7YjRynlB1Hxh io2V8H8WQkQOzS6HhRRpPJoSgidzxPnaHVUWT5/PlItwQuE+VhN2o/OpfwaVvuNoOSov 73TpTPXsjgytRaNt8XAA1V12kjbwXKvd/HgqQ0ikGA0MraL1F96x6AKWb3MlugSeWpSM tqCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720804577; x=1721409377; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2ffMD0XQCVtitda9bJYFeR9HeIWQ36ZylmX7OTCZPtY=; b=R/o73amkVkXV0xEFDE3J0Uspe6SQVzwcPbwFrZ8j6yYt4vtqcIZjKTuhWxG6wRseEP 3hMWSnA6rxpTZHrxtRGc8LsTgob/VpLvI5+GR6pHqU6/QbfTkZY+NcYMuggKtMqHF7uQ b0DlSIruc3ZZOSk1sDoV9RExeiWpPCQWL6xkhbLEU1/Sc62tbL2GUGPq2gMWsWJxlNAf NasBPThJjAQWC8U8Dq6IoPpAFGUvu7PZaXDqSe/f6vB0VojUxYUONxIyXPO+MPUXEKTs jOqQr1JC8hi+kHuEAQholUfrFN8nTI1AFoREecJc6W5CfdS3g96L4R1n1hbNnMWDTt6b 7QYA== X-Gm-Message-State: AOJu0Yw23gWBIWKhHaJuqq9AJnP/GYBQIfQKwGPliriYVvqY0Kt2trQC 2BXSoEpoT0LyRoCXQcyEZXO6x4Y1zx4QGRTFAJh5MVAJV1x4C3SnjuGKzEQySpM= X-Google-Smtp-Source: AGHT+IFQTwNnO1nrh2eA2u1czJFbgWBwKPh+5C514Te3MRulTbu6T62HxtWTavlgrgxxEqsgwQsWMQ== X-Received: by 2002:a50:d513:0:b0:599:7a9c:37b0 with SMTP id 4fb4d7f45d1cf-5997a9c3c27mr1761137a12.35.1720804577249; Fri, 12 Jul 2024 10:16:17 -0700 (PDT) Received: from localhost (p200300de37360a00d7e56139e90929dd.dip0.t-ipconnect.de. [2003:de:3736:a00:d7e5:6139:e909:29dd]) by smtp.gmail.com with UTF8SMTPSA id 4fb4d7f45d1cf-594bda30fabsm4763556a12.93.2024.07.12.10.16.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 10:16:16 -0700 (PDT) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, Martin Wilck Subject: [PATCH v2 43/49] libmultipath: simplify dm_get_maps() Date: Fri, 12 Jul 2024 19:14:51 +0200 Message-ID: <20240712171458.77611-44-mwilck@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712171458.77611-1-mwilck@suse.com> References: <20240712171458.77611-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Make dm_get_multipath() return a distinct error code for non-multipath targets. This way the extra call to dm_is_mpath() is not necessary any more. As dm_get_maps() is the only caller of dm_get_multipath(), transform it into a static function. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/devmapper.c | 44 +++++++++++++++++++++------------------- libmultipath/devmapper.h | 1 - 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 86ac01b..b52b10e 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -1186,39 +1186,42 @@ dm_disablegroup(const char * mapname, int index) return dm_groupmsg("disable", mapname, index); } -struct multipath *dm_get_multipath(const char *name) +static int dm_get_multipath(const char *name, struct multipath **pmpp) { struct multipath __attribute((cleanup(cleanup_multipath))) *mpp = NULL; char uuid[DM_UUID_LEN]; + int rc; mpp = alloc_multipath(); if (!mpp) - return NULL; + return DMP_ERR; mpp->alias = strdup(name); if (!mpp->alias) - return NULL; + return DMP_ERR; - if (libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY, + if ((rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY, (mapid_t) { .str = name }, (mapinfo_t) { .size = &mpp->size, .uuid = uuid, .dmi = &mpp->dmi, - }) != DMP_OK) - return NULL; + })) != DMP_OK) + return rc; if (!is_mpath_uuid(uuid)) - return NULL; + return DMP_NO_MATCH; strlcpy(mpp->wwid, uuid + UUID_PREFIX_LEN, sizeof(mpp->wwid)); - return steal_ptr(mpp); + *pmpp = steal_ptr(mpp); + + return DMP_OK; } int dm_get_maps(vector mp) { - struct multipath * mpp; + struct multipath *mpp = NULL; struct dm_task __attribute__((cleanup(cleanup_dm_task))) *dmt = NULL; struct dm_names *names; unsigned next = 0; @@ -1243,20 +1246,19 @@ int dm_get_maps(vector mp) } do { - if (dm_is_mpath(names->name) != DM_IS_MPATH_YES) - goto next; - - mpp = dm_get_multipath(names->name); - if (!mpp) - return 1; - - if (!vector_alloc_slot(mp)) { - free_multipath(mpp, KEEP_PATHS); + switch (dm_get_multipath(names->name, &mpp)) { + case DMP_OK: + if (!vector_alloc_slot(mp)) { + free_multipath(mpp, KEEP_PATHS); + return 1; + } + vector_set_slot(mp, mpp); + break; + case DMP_NO_MATCH: + break; + default: return 1; } - - vector_set_slot(mp, mpp); -next: next = names->next; names = (void *) names + next; } while (next); diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h index 3daaa4c..d01f9f2 100644 --- a/libmultipath/devmapper.h +++ b/libmultipath/devmapper.h @@ -184,7 +184,6 @@ int dm_rename (const char * old, char * new, char * delim, int skip_kpartx); int dm_reassign(const char * mapname); int dm_reassign_table(const char *name, char *old, char *new); int dm_setgeometry(struct multipath *mpp); -struct multipath *dm_get_multipath(const char *name); #define VERSION_GE(v, minv) ( \ (v[0] > minv[0]) || \ From patchwork Fri Jul 12 17:14:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13732092 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D938E17836D for ; Fri, 12 Jul 2024 17:16:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804581; cv=none; b=hqGWy4xBuvbS+yUEA9LlM9q2Wtt1S/EssaAEWKNTMOsREZccRy/DU+G0Cg7zwEG9u9IwlnIgL6CMjh7NeqcJM4GQ6Bjt2EUoPAz/EMtHwkDwk4dGHsFUNgpDaw0af/WZZ78xUMDCZqSgRtQ0gCXV3GNvdDnCmuWIfkcJrvEJtfI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804581; c=relaxed/simple; bh=f2JTr815TCS6+nJIBCP4hYuee6KXnXSt/5jF41M5RHs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=K1KoE1+9bIxqXJQZO4HcLo3kkFT3cWYUHWDuBSWLzpuS1R5Ucaooty1fZCvtxcvc6bXozLm2f/dH1bl5Ki6G/CQPQL73nZ1sliHWTH8grmw04/jKfGQegJ14LcTB8fyJoKNz/UboQjlWV6aHddD+sgcCxGZRyhxbYUrgfPJyLHo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=KQJpKLRt; arc=none smtp.client-ip=209.85.218.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="KQJpKLRt" Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-a77c7d3e8bcso306383566b.1 for ; Fri, 12 Jul 2024 10:16:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1720804578; x=1721409378; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7+TvFQr5nyA4cZeO4x8JTdlMHR3KS2yjqm6y50qNAuI=; b=KQJpKLRtjjxj8O9aYv7j4lft+aVTZkJuT481sjCpJtXbw5XvfYnAo5B1qNobq5Pc1z LOV+Rufx0xzmO2HInRz2Wpa1JZmg5LE11J2ln2jF+A5dXuTXkH8OzTnCqe7Em4TTPmk9 W1BZTWz0681NcOqPHDqr2nK+IyfG3nk0fNLeja4DT9GnmmJNWh6AJUwsweCmQhrDsK26 +RSsyCEUlBETYoTUA2+eoYSsAvPrDEmJ3yii3pImaAmN6ir/IJiA08YZfmFYwHDoWhNq NSoRLW5oU/2xFovVe7ksUfcS1Pudqo5dirLY9YPYO74tPSTKdp2+H0fvYI/zaWgmQp0B 6S5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720804578; x=1721409378; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7+TvFQr5nyA4cZeO4x8JTdlMHR3KS2yjqm6y50qNAuI=; b=n6PheZjpd5KlkLPR/4NawY8eBWgCc6w6YXT1ZJh8uxiQ6bRN7TcgY7RPRFx1DzbxXE +XqhQCYoxUxFLsYAP1umTrfZTjQTgLn7avCPJG3chWWWEiAAm+e9JxxeiqlQ7Qqj162U ck/rB6xCM1wxcC/B7D0//9RgTywwlZSRoZeS7kohNqk0RQGfGAbKSf2Ggd/XjubCr2HS U0G6vm2zOY1tr+vIk/DE4tswRh0OKsL015fPjRpHeg0bi4jq9oThGMGt6neDD5Rynibj B8/Prbecn8a0d4i/iP1NPxG2fnuYU8w3XSeHeC1fHrDxihltZ7K3pV8wn5v3ahnFUF+y x3ng== X-Gm-Message-State: AOJu0YyIuFof6rT9ckfi7hi4HjB2DSxwd2kXKWEMdvD0arowAQNHeLwJ mzIQsnYCLNKB1zjrYivx2zTU90Bsh8CcOVsrr4qra5k9ROAzadTVRALF1h10n/R/Y6RMm7dGtYu N X-Google-Smtp-Source: AGHT+IGad0Mmu9h3vfSb4X0hI82sm+KUmekR6rb7qAB8E3qxYBqp/J4szx0maaVFaonufaBQAeEN/w== X-Received: by 2002:a17:907:e9f:b0:a77:cb7d:f362 with SMTP id a640c23a62f3a-a780b705276mr1039038166b.40.1720804578188; Fri, 12 Jul 2024 10:16:18 -0700 (PDT) Received: from localhost (p200300de37360a00d7e56139e90929dd.dip0.t-ipconnect.de. [2003:de:3736:a00:d7e5:6139:e909:29dd]) by smtp.gmail.com with UTF8SMTPSA id a640c23a62f3a-a780a7ff7e0sm365232866b.98.2024.07.12.10.16.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 10:16:18 -0700 (PDT) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, Martin Wilck Subject: [PATCH v2 44/49] libmpathpersist: use libmp_mapinfo() in mpath_get_map() Date: Fri, 12 Jul 2024 19:14:52 +0200 Message-ID: <20240712171458.77611-45-mwilck@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712171458.77611-1-mwilck@suse.com> References: <20240712171458.77611-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When obtaining the map name, make sure right away that the map is a multipath device. This saves an ioctl and slightly simplifies the function. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmpathpersist/mpath_persist_int.c | 50 +++++++++++++---------------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/libmpathpersist/mpath_persist_int.c b/libmpathpersist/mpath_persist_int.c index 5a5ac3b..a3eb80a 100644 --- a/libmpathpersist/mpath_persist_int.c +++ b/libmpathpersist/mpath_persist_int.c @@ -157,10 +157,9 @@ static int get_mpvec(vector curmp, vector pathvec, char *refwwid) static int mpath_get_map(vector curmp, vector pathvec, int fd, char **palias, struct multipath **pmpp) { - int ret = MPATH_PR_DMMP_ERROR; + int rc; struct stat info; - int major, minor; - char *alias; + char alias[WWID_SIZE], uuid[DM_UUID_LEN]; struct multipath *mpp; if (fstat(fd, &info) != 0){ @@ -172,47 +171,44 @@ static int mpath_get_map(vector curmp, vector pathvec, int fd, char **palias, return MPATH_PR_FILE_ERROR; } - major = major(info.st_rdev); - minor = minor(info.st_rdev); - condlog(4, "Device %d:%d", major, minor); - /* get alias from major:minor*/ - alias = dm_mapname(major, minor); - if (!alias){ - condlog(0, "%d:%d failed to get device alias.", major, minor); + rc = libmp_mapinfo(DM_MAP_BY_DEVT | MAPINFO_MPATH_ONLY, + (mapid_t) { .devt = info.st_rdev }, + (mapinfo_t) { + .name = alias, + .uuid = uuid, + }); + + if (rc == DMP_NO_MATCH || !is_mpath_uuid(uuid)) { + condlog(3, "%s: not a multipath device.", alias); + return MPATH_PR_DMMP_ERROR; + } else if (rc != DMP_OK) { + condlog(1, "%d:%d failed to get device alias.", + major(info.st_rdev), minor(info.st_rdev)); return MPATH_PR_DMMP_ERROR; } - condlog(3, "alias = %s", alias); - - if (dm_is_mpath(alias) != DM_IS_MPATH_YES) { - condlog(3, "%s: not a multipath device.", alias); - goto out; - } + condlog(4, "alias = %s", alias); /* get info of all paths from the dm device */ - if (get_mpvec(curmp, pathvec, alias)){ + if (get_mpvec(curmp, pathvec, alias)) { condlog(0, "%s: failed to get device info.", alias); - goto out; + return MPATH_PR_DMMP_ERROR; } mpp = find_mp_by_alias(curmp, alias); if (!mpp) { condlog(0, "%s: devmap not registered.", alias); - goto out; + return MPATH_PR_DMMP_ERROR; } - ret = MPATH_PR_SUCCESS; if (pmpp) *pmpp = mpp; - if (palias) { - *palias = alias; - alias = NULL; - } -out: - free(alias); - return ret; + if (palias && (*palias = strdup(alias)) == NULL) + return MPATH_PR_DMMP_ERROR; + + return MPATH_PR_SUCCESS; } int do_mpath_persistent_reserve_in(vector curmp, vector pathvec, From patchwork Fri Jul 12 17:14:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13732093 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-ed1-f43.google.com (mail-ed1-f43.google.com [209.85.208.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C1E5717C6B for ; Fri, 12 Jul 2024 17:16:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804582; cv=none; b=SS/5Dk28tYLyqv8mkz98C/7+C/XzLRFg6OLS6gVwBYSoTFkhScSDUBAZ0i4+kZ2x4kScO/n53TO6sUYvZCz0RoBAP8uFpr4dQVUfE046RE0yV3/tMeOuQKoJ3dhNvo+rW/jbfn/2lD9SaySeMHCUH0RtVVDcd3vElAYV701Ru7k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804582; c=relaxed/simple; bh=T/i/sc153Kwcqe/xc9wim2PKplEdEYDvS4pzALkFB4I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Wyf/Ddi56d9Rlpd4U/f+npMQxUab23hiLow2Mtg5ooINL2KbN2oPCU7Ce9fAL42tHlw2KJRhh/XHVVlR2lRuMlTpRJodmO9va1xaAtNvGfK5oeU2V8Y67pSkre50w4X+pq69+UaWpkBS3DP/kn04HV/j3p/aPZE2ifi3hpXiqMo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=Mg4KkFcq; arc=none smtp.client-ip=209.85.208.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="Mg4KkFcq" Received: by mail-ed1-f43.google.com with SMTP id 4fb4d7f45d1cf-59589a9be92so3191091a12.2 for ; Fri, 12 Jul 2024 10:16:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1720804579; x=1721409379; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qdKfvUMTtKRdoi/pm6nNvKWq+FKnlTr/ZC6Ww7KpRoU=; b=Mg4KkFcqAKD+dkNSZFYCXIQohLnntK8C1FrK4okpzisLVDsMjq2Siq1LqDLgoGPC91 P2D+9TCbGojs9PlP/WxyWIQQbFmVtBuxRXW/NEiP5a8wSaTeOvk7q5ZUSd1PnT0blJ7B Ya/1WhPgrepF12j8GGvNt4o0tQaW1QyQdobBX/1NPGzV9KV7a2olJyhZk4I7qajCH8/x vjbhGDJdrVdM9X4/pL75hT9VUWC2/kI297B6fYjLPxO24Q9OFEI4LzAJYNN6dXFBDUla P3QNh6gkKYysrYKl6aTEISDkSTSKKeHMMZkgtRQs8+km+Z+EVBLb2iFgNC8B1FoAk2Po u3Fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720804579; x=1721409379; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qdKfvUMTtKRdoi/pm6nNvKWq+FKnlTr/ZC6Ww7KpRoU=; b=ZOPTmRoVDBsofM1ELccZ6ZRVprb2qpcINMB2FQrDbFk/NpLOd4KQ8ETiOArKIe4BuF Rr48hSzadeGcHu3pmk8nEnxicvVjWYJMYupGS2ZZWOxYMoKuOzyu8qZ4iZVrGfPcOblx ag6ncIVqp5G+HRleC6HDotKa/a35ksbV+yygOk2pOuN0QDKLhMQpK5Fm8v9ATQRamJ4I 2EgAd+1hfz+VKypM/iJGwMiL6LrKJbtXw1E4uhVDgUQFRim9kX9HXrdE/HJP5FPETne1 0f8s+EJCd9tRC7fSM9xCFOqT1sF/Ozq9lFBg/m6zZYw7luTGCx5MY2nhl2RVw+9tduB+ T5mg== X-Gm-Message-State: AOJu0YwusLXynt3rmSlujx9Pek2FI4DrH40ej+vkdNj2czhiq4dFLe6/ qsGP3JAkKnMsNk5fPygEWZUnvquMAVaYb079IcI7aYVoEY0cxb5bNxj9XSoGgpc= X-Google-Smtp-Source: AGHT+IEsWbnhKuqHHtJuuTRBb5cfiZaFJYPf+5OpppNcyhzb0alNzlSootY+0GfBLZqf2racKni8wg== X-Received: by 2002:a05:6402:35d0:b0:58b:73f4:2ed with SMTP id 4fb4d7f45d1cf-594bcba7716mr8574176a12.35.1720804579069; Fri, 12 Jul 2024 10:16:19 -0700 (PDT) Received: from localhost (p200300de37360a00d7e56139e90929dd.dip0.t-ipconnect.de. [2003:de:3736:a00:d7e5:6139:e909:29dd]) by smtp.gmail.com with UTF8SMTPSA id 4fb4d7f45d1cf-594bc4e8255sm4733405a12.48.2024.07.12.10.16.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 10:16:18 -0700 (PDT) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, Martin Wilck Subject: [PATCH v2 45/49] libmpathpersist: use mpp->alias in do_mpath_persistent_reserve_out() Date: Fri, 12 Jul 2024 19:14:53 +0200 Message-ID: <20240712171458.77611-46-mwilck@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712171458.77611-1-mwilck@suse.com> References: <20240712171458.77611-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The extra pointer "alias" isn't necessary. The mp vector is initialized by dm_get_maps(), which will allocate mpp->alias for every map, thus we can use it in do_mpath_persistent_reserve_out(). This allows us to simplify both this function itself and mpath_get_map(). Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmpathpersist/mpath_persist_int.c | 38 ++++++++++++----------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/libmpathpersist/mpath_persist_int.c b/libmpathpersist/mpath_persist_int.c index a3eb80a..807415f 100644 --- a/libmpathpersist/mpath_persist_int.c +++ b/libmpathpersist/mpath_persist_int.c @@ -154,8 +154,7 @@ static int get_mpvec(vector curmp, vector pathvec, char *refwwid) return MPATH_PR_SUCCESS ; } -static int mpath_get_map(vector curmp, vector pathvec, int fd, char **palias, - struct multipath **pmpp) +static int mpath_get_map(vector curmp, vector pathvec, int fd, struct multipath **pmpp) { int rc; struct stat info; @@ -205,8 +204,6 @@ static int mpath_get_map(vector curmp, vector pathvec, int fd, char **palias, if (pmpp) *pmpp = mpp; - if (palias && (*palias = strdup(alias)) == NULL) - return MPATH_PR_DMMP_ERROR; return MPATH_PR_SUCCESS; } @@ -218,7 +215,7 @@ int do_mpath_persistent_reserve_in(vector curmp, vector pathvec, struct multipath *mpp; int ret; - ret = mpath_get_map(curmp, pathvec, fd, NULL, &mpp); + ret = mpath_get_map(curmp, pathvec, fd, &mpp); if (ret != MPATH_PR_SUCCESS) return ret; @@ -649,12 +646,11 @@ int do_mpath_persistent_reserve_out(vector curmp, vector pathvec, int fd, struct prout_param_descriptor *paramp, int noisy) { struct multipath *mpp; - char *alias; int ret; uint64_t prkey; struct config *conf; - ret = mpath_get_map(curmp, pathvec, fd, &alias, &mpp); + ret = mpath_get_map(curmp, pathvec, fd, &mpp); if (ret != MPATH_PR_SUCCESS) return ret; @@ -670,21 +666,20 @@ int do_mpath_persistent_reserve_out(vector curmp, vector pathvec, int fd, (!get_be64(mpp->reservation_key) || memcmp(paramp->key, &mpp->reservation_key, 8) == 0)))) { memcpy(&mpp->reservation_key, paramp->sa_key, 8); - if (update_prkey_flags(alias, get_be64(mpp->reservation_key), + if (update_prkey_flags(mpp->alias, get_be64(mpp->reservation_key), paramp->sa_flags)) { condlog(0, "%s: failed to set prkey for multipathd.", - alias); - ret = MPATH_PR_DMMP_ERROR; - goto out1; + mpp->alias); + return MPATH_PR_DMMP_ERROR; } } if (memcmp(paramp->key, &mpp->reservation_key, 8) && memcmp(paramp->sa_key, &mpp->reservation_key, 8) && (prkey || rq_servact != MPATH_PROUT_REG_IGN_SA)) { - condlog(0, "%s: configured reservation key doesn't match: 0x%" PRIx64, alias, get_be64(mpp->reservation_key)); - ret = MPATH_PR_SYNTAX_ERROR; - goto out1; + condlog(0, "%s: configured reservation key doesn't match: 0x%" PRIx64, + mpp->alias, get_be64(mpp->reservation_key)); + return MPATH_PR_SYNTAX_ERROR; } switch(rq_servact) @@ -703,24 +698,21 @@ int do_mpath_persistent_reserve_out(vector curmp, vector pathvec, int fd, ret = mpath_prout_rel(mpp, rq_servact, rq_scope, rq_type, paramp, noisy); break; default: - ret = MPATH_PR_OTHER; - goto out1; + return MPATH_PR_OTHER; } if ((ret == MPATH_PR_SUCCESS) && ((rq_servact == MPATH_PROUT_REG_SA) || (rq_servact == MPATH_PROUT_REG_IGN_SA))) { if (prkey == 0) { - update_prflag(alias, 0); - update_prkey(alias, 0); + update_prflag(mpp->alias, 0); + update_prkey(mpp->alias, 0); } else - update_prflag(alias, 1); + update_prflag(mpp->alias, 1); } else if ((ret == MPATH_PR_SUCCESS) && (rq_servact == MPATH_PROUT_CLEAR_SA)) { - update_prflag(alias, 0); - update_prkey(alias, 0); + update_prflag(mpp->alias, 0); + update_prkey(mpp->alias, 0); } -out1: - free(alias); return ret; } From patchwork Fri Jul 12 17:14:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13732094 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6B223178372 for ; Fri, 12 Jul 2024 17:16:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804583; cv=none; b=Q7YzuDVn9IoB0DyXy9bmSxxo2wR8a5PDkIhH5Ieeamrq16CuTNPimK1kvPcp5mfgZ5vwt7l+MwpRqz0zoexuezZMjqtsjg75jgOHB+pTSLCJkgFIxAfEvByr4jqN5TPteMWRh7IrFBq7Yh5ZgmoN0+cTikBhZGUGV5xOntIpmDA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804583; c=relaxed/simple; bh=7/eSxiYmc8IKQw9+EcIkfI1nv5QJYW8HSIpkAyO9tKU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Di9vuS+TCWZ+d0GherH3eRlH71C2lxyQ0yWspi+iVYDz7t1NAQq5PqWY0xOcyX/lj8p0Gvu3qoZSiikM0ne0/CQVkKf3HW5ViguJOg/29LXun0zhjE5o4CJYARDr7He51bV5we2p1s+4qOXEd1YsgK1qI82CB8vcUZHhFdNYlMY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=GShI8sl3; arc=none smtp.client-ip=209.85.218.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="GShI8sl3" Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-a77e392f59fso300576566b.1 for ; Fri, 12 Jul 2024 10:16:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1720804580; x=1721409380; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tnWScXCo1vFyuMNGR4o4Ab/JA4Iy5gM7X7XpNNA5SNM=; b=GShI8sl3mDi7xuv3UA0u52GWwS4wQvWuEyBC5Ya+IVEjwg5lEjzkC232QFLhoYKYMM CJ41mcYlxSdlqFCOVw3tjwtBpEVRkdv8qAjRSu2OJ6cN0LJ+Omtp9Pcw3P4l+B9FvfDL 0rV3xmnyMqRurVKwrPK5EvsnzRgW1JvJgKZRwDELw4XhvhhESBTSEvaw7vz+irTMk4pc zzuNn5VCOq6LY6RZ/DTq4PIhJyB5MlVqkGTlsOI2L1SwE7maV0JnqOrZ5HeGdRQanAPq 5NEEm/vXRUdQm2VXTJMS4ghjsCkLSabAbg31MKdh0CbioxIrVgad5Z3bt+VcePo6B8V8 k89g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720804580; x=1721409380; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tnWScXCo1vFyuMNGR4o4Ab/JA4Iy5gM7X7XpNNA5SNM=; b=bxZA6jUV8UwCpgdDpATsDSpEaIe+33xRkvRXvhcft/2Te9rKIw40G5FfZL7QbjDTDr i4Er2WlgDMdlqWF7gSXcNzaovcNBX89xwVjNetPhkFosu3pVOQrdX4Cdkxjf66tQpJ0j 21aqg/wa5C9zpWwFO6S12hWKc7mNP8l/GYwRBvc9Z/d5u73m9im3duiHoFqML0djkuvu LButX2kyBM5YLzD13LtQvWYDnUGWmJ9SFhBf8yf/7/HRFEH6u//5wplk8HSaFkUjzQQd 3vRWQ1HESzzqssG4cFnUv9rTFti5j6VOSlduIw5K81I5k31cwgzuzwIc+6XqWCPswQGq lWRw== X-Gm-Message-State: AOJu0Ywn7PO3nGR3CTkc2nFmjPeYHahtOXFmRCSiK8o2g5fRS9Xcy6r2 RdEDCy0odqbiR85h3btBCe2wvy6AC98NihNxB34DbS3l+HHBYrfB6kmK8EVDeeE= X-Google-Smtp-Source: AGHT+IEdUjS8TDir1U3WOEUfjqekcI++ep9nes/NzcR7rmMMwBbCenl6oVm94WUp1LtYBfFdXPjhYA== X-Received: by 2002:a17:907:3f19:b0:a77:c548:6456 with SMTP id a640c23a62f3a-a780b88608amr986224166b.59.1720804579887; Fri, 12 Jul 2024 10:16:19 -0700 (PDT) Received: from localhost (p200300de37360a00d7e56139e90929dd.dip0.t-ipconnect.de. [2003:de:3736:a00:d7e5:6139:e909:29dd]) by smtp.gmail.com with UTF8SMTPSA id a640c23a62f3a-a780a6e05cdsm360111866b.74.2024.07.12.10.16.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 10:16:19 -0700 (PDT) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, Martin Wilck Subject: [PATCH v2 46/49] libmultipath: fix deferred_remove logic in remove_partmap() Date: Fri, 12 Jul 2024 19:14:54 +0200 Message-ID: <20240712171458.77611-47-mwilck@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712171458.77611-1-mwilck@suse.com> References: <20240712171458.77611-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The logic for returning DM_FLUSH_BUSY in remove_partmap() got accidentally reverted in commit 20aeeb6. Fix it. Fixes: 20aeeb6 ("libmultipath: fix deferred_remove function arguments") Signed-off-by: Martin Wilck Reviewed-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 b52b10e..5749d63 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -1383,7 +1383,7 @@ remove_partmap(const char *name, void *data) if (dm_get_opencount(name)) { dm_remove_partmaps(name, rd->flags); - if ((rd->flags & DMFL_DEFERRED) && dm_get_opencount(name)) { + if (!(rd->flags & DMFL_DEFERRED) && dm_get_opencount(name)) { condlog(2, "%s: map in use", name); return DM_FLUSH_BUSY; } From patchwork Fri Jul 12 17:14:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13732095 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8AF2D17836D for ; Fri, 12 Jul 2024 17:16:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804584; cv=none; b=utdTHl3M9fd/yBJIRrfWqWF2aqYuo+HDyOfG0z0KwHnXnqUCLRQjwv5x9HrUawtXHo10/zjKg+Ww8x4CmR+TcPbGC04AXXfvMHMFOpoDJqnnJrRSI/u5FiFk2M3nYGxadeVz6/ZiR4dmmaYP0/7xF7A67Bvv/ezxQUYjWGrziDk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804584; c=relaxed/simple; bh=7Y0f+Km+jmh3o/ntj4+vkeIN57Ripocxqm1pn4RGfgs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oP38hHhzvKCR+X3I3ZMR6z6UFeV88fAvn/zuNfVKsBxbZ9qm+hTbNHIYXSUgw6LZMzauFVYpJzW7F2mDALZ0GgAVpYacaBdORHuhtcj9JL02bRsz6Z60gNkfIUZ1c5SbDuZgAqQ+JDYw3dPcUzaK26lRDO32Blz6FZkErDpTwyg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=Kr9o26dG; arc=none smtp.client-ip=209.85.218.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="Kr9o26dG" Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-a77e7420697so328557166b.1 for ; Fri, 12 Jul 2024 10:16:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1720804581; x=1721409381; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9jSFu0vK64uftNQS4GPPdyGYtRVv01//ENda8KRwDYk=; b=Kr9o26dGT02blU8W41k4ndMS6lxdApLHfvt5AwTHx2cb/U6FPnF3wDH1mjGW/M8LSv X/jeXmH8T5boOn945zrh+QJDVbwDTn0Li1o4tDCFDvUzRDaGrM6Zm58pJOzbTiMKQtri 5lMK4/qtelcUekUQ9By4gAbQgmzzwGddm1K+hia/3N+BeQ6MsiecYkBnGbfszZd4xJv3 jn0mJmlovlreKAAp2Pj4LpMyhb7iijrWknMHSU7Q2KyjAjsNdbOG/lu8XdoVhCuveozR 6AGZHBBtVnSCjgWbgeJo0tQ744UB8ItemO+hQ5Crit2A4KVYb1izb7iErmULWDAiA8WN +lCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720804581; x=1721409381; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9jSFu0vK64uftNQS4GPPdyGYtRVv01//ENda8KRwDYk=; b=lM4hY+afgRpLmgHkiL83A1V38ahSQuCNk5nnF8YqXmG4jrgcf+HLy9oFslDPUtv29Q Y7pXyMcmtZoacO/j2wcrkUBnFfaT/PLerDK4MfWOeFdpmqXsLek8EsVmEzvOs3ZH8XW4 TmITmy6dsJ9rjwuJ3XmTHztPXlObN5vF2Hc7KHQwB3p2L++rbn9woaPB3vdBqGi5qn4E SccNrUqI1ejdzgzNPtbZKDjzw2kz3bPjgj3Vjy36iyaIvgHLwBpDRsWuqOqCLLUCOK3S mqNoUHgzoq5hGobXt1CpHpL6KrcnYKp9INAfgdhUlmIU2VyKCl4V0Mnk2Eum+8dUqlSM 1D2g== X-Gm-Message-State: AOJu0Yyn/tS2PP0+H+jRx7nehHLEOvoPIp6+xNam8PsbdOEvEtHHX6wP 1gtT06cR800D/MbRmUvHH7ZHWkTOr+VQswWXrZPmnaDTV3FfyeQjvKh41D6eZGM= X-Google-Smtp-Source: AGHT+IFLBor2iFkXzquokwF0fXhu7JYFm/sDxcBau0vdzeny834gxYP/ODZ333+mnVA9xLxC7Q0FQw== X-Received: by 2002:a17:907:6e88:b0:a77:e0ed:8bb with SMTP id a640c23a62f3a-a780b6ff10emr1032277766b.42.1720804580755; Fri, 12 Jul 2024 10:16:20 -0700 (PDT) Received: from localhost (p200300de37360a00d7e56139e90929dd.dip0.t-ipconnect.de. [2003:de:3736:a00:d7e5:6139:e909:29dd]) by smtp.gmail.com with UTF8SMTPSA id a640c23a62f3a-a780a7ff073sm359689366b.137.2024.07.12.10.16.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 10:16:20 -0700 (PDT) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, Martin Wilck Subject: [PATCH v2 47/49] libmultipath: don't call do_foreach_partmaps() recursively Date: Fri, 12 Jul 2024 19:14:55 +0200 Message-ID: <20240712171458.77611-48-mwilck@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712171458.77611-1-mwilck@suse.com> References: <20240712171458.77611-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We've removed partition mappings recursively since 83fb936 ("Correctly remove logical partition maps"). This was wrong, because kpartx doesn't create logical partitions as mappings onto the extended partition. Rather, logical partitions are created by kpartx as mappings to the multipath device, and afaics, this has always been the case. Therefore, the loop in do_foreach_partmaps() will detect all partition mappings (primary, extended, and logical) without recursion. At least since 4059e42 ("libmultipath: fix partition detection"), the recursion has actually been pointless, because is_mpath_part() would never have returned "true" for a pair of two partition mappings (one representing an extended partition and one a logical partition). Avoiding the recursion has the additional benefit that the complexity of removing maps scales with N, where N is the number of dm devices, rather than with N^2. Also, it simplifies the code. Split partmap_in_use() into two separate functions, mpath_in_use() (to be called for multipath maps) and count_partitions(), which is called from do_foreach_partmaps(). Because do_foreach_partmaps() is now only legitimately called for multipath maps, quit early if called for another map type. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/devmapper.c | 48 +++++++++++++++++++------------ libmultipath/devmapper.h | 2 +- libmultipath/libmultipath.version | 2 +- multipathd/main.c | 2 +- 4 files changed, 33 insertions(+), 21 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 5749d63..d9d96be 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -933,22 +933,37 @@ has_partmap(const char *name __attribute__((unused)), return 1; } -int -partmap_in_use(const char *name, void *data) +/* + * 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. + */ +static int count_partitions(const char *name, void *data) +{ + int *ret_count = (int *)data; + int open_count = dm_get_opencount(name); + + if (open_count) + return 1; + (*ret_count)++; + return 0; +} + +int mpath_in_use(const char *name) { - int part_count, *ret_count = (int *)data; int open_count = dm_get_opencount(name); - if (ret_count) - (*ret_count)++; - part_count = 0; if (open_count) { - if (do_foreach_partmaps(name, partmap_in_use, &part_count)) - return 1; - if (open_count != part_count) { - condlog(2, "%s: map in use", name); + int part_count = 0; + + if (do_foreach_partmaps(name, count_partitions, &part_count)) { + condlog(4, "%s: %s has open partitions", __func__, name); return 1; } + condlog(4, "%s: %s: %d openers, %d partitions", __func__, name, + open_count, part_count); + return open_count > part_count; } return 0; } @@ -976,7 +991,7 @@ int _dm_flush_map (const char *mapname, int flags, int retries) /* If you aren't doing a deferred remove, make sure that no * devices are in use */ - if (!(flags & DMFL_DEFERRED) && partmap_in_use(mapname, NULL)) + if (!(flags & DMFL_DEFERRED) && mpath_in_use(mapname)) return DM_FLUSH_BUSY; if ((flags & DMFL_SUSPEND) && @@ -1314,7 +1329,7 @@ do_foreach_partmaps (const char *mapname, char map_uuid[DM_UUID_LEN]; struct dm_info info; - if (libmp_mapinfo(DM_MAP_BY_NAME, + if (libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_CHECK_UUID, (mapid_t) { .str = mapname }, (mapinfo_t) { .uuid = map_uuid, .dmi = &info }) != DMP_OK) return 1; @@ -1381,12 +1396,9 @@ remove_partmap(const char *name, void *data) { struct remove_data *rd = (struct remove_data *)data; - if (dm_get_opencount(name)) { - dm_remove_partmaps(name, rd->flags); - if (!(rd->flags & DMFL_DEFERRED) && dm_get_opencount(name)) { - condlog(2, "%s: map in use", name); - return DM_FLUSH_BUSY; - } + if (!(rd->flags & DMFL_DEFERRED) && dm_get_opencount(name)) { + condlog(2, "%s: map in use", name); + return DM_FLUSH_BUSY; } condlog(4, "partition map %s removed", name); dm_device_remove(name, rd->flags); diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h index d01f9f2..6eb5ab9 100644 --- a/libmultipath/devmapper.h +++ b/libmultipath/devmapper.h @@ -149,7 +149,7 @@ enum { DM_FLUSH_BUSY, }; -int partmap_in_use(const char *name, void *data); +int mpath_in_use(const char *name); enum { DMFL_NONE = 0, diff --git a/libmultipath/libmultipath.version b/libmultipath/libmultipath.version index 54b5a23..649c1cb 100644 --- a/libmultipath/libmultipath.version +++ b/libmultipath/libmultipath.version @@ -139,10 +139,10 @@ global: libmultipath_exit; libmultipath_init; load_config; + mpath_in_use; need_io_err_check; orphan_path; parse_prkey_flags; - partmap_in_use; pathcount; path_discovery; path_get_tpgs; diff --git a/multipathd/main.c b/multipathd/main.c index 536974c..13af94e 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -597,7 +597,7 @@ flush_map_nopaths(struct multipath *mpp, struct vectors *vecs) { return false; } if (mpp->flush_on_last_del == FLUSH_UNUSED && - partmap_in_use(mpp->alias, NULL) && is_queueing) { + mpath_in_use(mpp->alias) && is_queueing) { condlog(2, "%s: map in use and queueing, can't remove", mpp->alias); return false; From patchwork Fri Jul 12 17:14:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13732096 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6A899178378 for ; Fri, 12 Jul 2024 17:16:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804585; cv=none; b=itLqyvij/YhxoSL8/O1j8sCdtdGUonBUu85iXG/5PZ9r2hSifepxe6A0nOoIAVSfahoCXDSk/9XxD1E4HhxPMvQut7vr9NSK5vD6fjb0bH2OT5x+f5jfiWvZiCI0YXlaybw/rwODEMpypGmJAEAbYw8bOvcI02Z6zuHhg+nWkJk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804585; c=relaxed/simple; bh=1+XOsrMbSTQr1JMav2K4kPoGyz/fj3/idzqx5iLRkYU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A1tdB471z+th7awwgYNehQlMjcwpFJXLkorDyv4pooFybx4FlR18Sq5SfLfFhBilK1NJjYry1bHqcC3ZC8DXYOu7a2R7vUhBoR4G1iLMoDXq2kw0+w2ZqzMlg3vN5k8DtxDBPcooRoKVN8gQxGI2rg2Hx+o3Ias3SUdHWSgxLRQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=Bb28lmVL; arc=none smtp.client-ip=209.85.208.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="Bb28lmVL" Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-58ba3e38027so2503460a12.1 for ; Fri, 12 Jul 2024 10:16:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1720804582; x=1721409382; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=WTyDcYYnKMGgh8T6amsvuE4DGBR56P+VOW9lY2V4/KY=; b=Bb28lmVLGp/+ym0wmxXrXbaDsGyh0kFBWfi32Hbzk17VkymAHBTnBintCxW1KHeO+q jx+fxlsIX9tMgVfnae75mwICvsd1eU9uq85sKCc3DAW/jUygvO6PqJGyGiouxzLc8OYi zi0ClNS1yvDU2G3ONkixCCHNk5pkZAfp0zwcEbb3LTBvfz32XRDmVsXIvNEG6Q2NkSoc uYoytecC8kWsBbAkCvabBuZy7jPIXnJgbiJhyBKrT36SAHP362CV9XJ8iM305FsWhHyI 3WI0CAweziMqJOGZuDerXpbJRGwd2+9hUQH6lxOkFBGwJDgTQRhciFFbvR7DCdP1jqOk T5EQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720804582; x=1721409382; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WTyDcYYnKMGgh8T6amsvuE4DGBR56P+VOW9lY2V4/KY=; b=fi+tm6FAAheQQl0BxhKdfqLqAj0PrKi3c1BLSYEYHPKxbRaLDd6S1yEFZdjOYkKJP6 IRc4Wo6xyG6SMzDb4D6uKjl3SBxIz5MD3D04IqfLByQcBB7OuAZIvVA9KVAbuwMIBr2y kHwujSbzBK6xrXiWJxYXmX7WEYDmKkanWBfwrSTPpeDYykX2C8vrX1INvd9CMDf69dPG XOaVlwEak2leXt+o3kgvfBmO83+/kET20eruEB/zBpNRtMQwUFWUgMEZ/ohtYQbw8tg8 I80JBnb+Ci0uxlajWjGFTzhgSHh4PVgwPD5QhwyAOPknpCT2+BmV50DHAnaZA+QTcaUW oCJw== X-Gm-Message-State: AOJu0Yxxs4UxiFXAF1k0lOpvbOVHdhjBnoM8Q7dki2LhoJi8gLs7BFGk OJXibsPpWdlc+3kpI7cHyf1nnDezqvYPn/m1+LmvA5o9D5CpVtaNoAuYUIhMFr4= X-Google-Smtp-Source: AGHT+IFHrAJbte/r9sSFW6u5Vk5ps7/EONN+Ts0v1Ew3x8SF7CNIS0/hZRQKNS4OcFhvAKl/qdAOlg== X-Received: by 2002:a50:931c:0:b0:57c:db99:a131 with SMTP id 4fb4d7f45d1cf-594bc7c8aa6mr8020083a12.29.1720804581781; Fri, 12 Jul 2024 10:16:21 -0700 (PDT) Received: from localhost (p200300de37360a00d7e56139e90929dd.dip0.t-ipconnect.de. [2003:de:3736:a00:d7e5:6139:e909:29dd]) by smtp.gmail.com with UTF8SMTPSA id 4fb4d7f45d1cf-594bbe2ceadsm4778617a12.32.2024.07.12.10.16.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 10:16:21 -0700 (PDT) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, Martin Wilck Subject: [PATCH v2 48/49] libmultipath: Move UUID check into libmp_pathinfo__() Date: Fri, 12 Jul 2024 19:14:56 +0200 Message-ID: <20240712171458.77611-49-mwilck@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712171458.77611-1-mwilck@suse.com> References: <20240712171458.77611-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We have a couple of callers that check whether the map UUID conforms to the multipath convention ("mpath-xyz"). Move this check into libmp_mapinfo__(). Add another flag MAPINFO_CHECK_UUID for this purpose. This allows to simplify some callers, which only fetched the UUID in order to check it. Note that the UUID check is orthogonal to MAPINFO_MPATH_ONLY, which tests the target type. We shold make sure that both tests are in agreement, but this is postponed to a later patch set. is_mpath_uuid() can now be converted to a static function. Also add some unit tests for the WWID check. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmpathpersist/mpath_persist_int.c | 11 +- libmultipath/devmapper.c | 52 +++---- libmultipath/devmapper.h | 3 +- libmultipath/libmultipath.version | 1 - multipath/main.c | 5 +- multipathd/main.c | 7 +- tests/mapinfo.c | 226 ++++++++++++++++++++++++++++ 7 files changed, 256 insertions(+), 49 deletions(-) diff --git a/libmpathpersist/mpath_persist_int.c b/libmpathpersist/mpath_persist_int.c index 807415f..f4d9e7c 100644 --- a/libmpathpersist/mpath_persist_int.c +++ b/libmpathpersist/mpath_persist_int.c @@ -158,7 +158,7 @@ static int mpath_get_map(vector curmp, vector pathvec, int fd, struct multipath { int rc; struct stat info; - char alias[WWID_SIZE], uuid[DM_UUID_LEN]; + char alias[WWID_SIZE]; struct multipath *mpp; if (fstat(fd, &info) != 0){ @@ -171,14 +171,11 @@ static int mpath_get_map(vector curmp, vector pathvec, int fd, struct multipath } /* get alias from major:minor*/ - rc = libmp_mapinfo(DM_MAP_BY_DEVT | MAPINFO_MPATH_ONLY, + rc = libmp_mapinfo(DM_MAP_BY_DEVT | MAPINFO_MPATH_ONLY | MAPINFO_CHECK_UUID, (mapid_t) { .devt = info.st_rdev }, - (mapinfo_t) { - .name = alias, - .uuid = uuid, - }); + (mapinfo_t) { .name = alias }); - if (rc == DMP_NO_MATCH || !is_mpath_uuid(uuid)) { + if (rc == DMP_NO_MATCH) { condlog(3, "%s: not a multipath device.", alias); return MPATH_PR_DMMP_ERROR; } else if (rc != DMP_OK) { diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index d9d96be..bbbadee 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -611,6 +611,11 @@ int dm_addmap_reload(struct multipath *mpp, char *params, int flush) return 0; } +static bool is_mpath_uuid(const char uuid[DM_UUID_LEN]) +{ + return !strncmp(uuid, UUID_PREFIX, UUID_PREFIX_LEN); +} + bool has_dm_info(const struct multipath *mpp) { @@ -734,11 +739,17 @@ static int libmp_mapinfo__(int flags, mapid_t id, mapinfo_t info, const char *ma * If error is returned, don't touch any output parameters. */ if ((info.name && !(name = dm_task_get_name(dmt))) - || (info.uuid && !(uuid = dm_task_get_uuid(dmt))) + || ((info.uuid || flags & MAPINFO_CHECK_UUID) + && !(uuid = dm_task_get_uuid(dmt))) || (info.status && !(tmp_status = strdup(params))) || (info.target && !tmp_target && !(tmp_target = strdup(params)))) return DMP_ERR; + if (flags & MAPINFO_CHECK_UUID && !is_mpath_uuid(uuid)) { + condlog(3, "%s: UUID mismatch: %s", __func__, uuid); + return DMP_NO_MATCH; + } + if (info.name) { strlcpy(info.name, name, WWID_SIZE); condlog(4, "%s: %s: name: \"%s\"", __func__, map_id, info.name); @@ -808,18 +819,6 @@ int libmp_mapinfo(int flags, mapid_t id, mapinfo_t info) libmp_map_identifier(flags, id, idbuf)); } -static int dm_get_dm_uuid(const char *mapname, char uuid[DM_UUID_LEN]) -{ - return libmp_mapinfo(DM_MAP_BY_NAME, - (mapid_t) { .str = mapname }, - (mapinfo_t) { .uuid = uuid }); -} - -bool is_mpath_uuid(const char uuid[DM_UUID_LEN]) -{ - return !strncmp(uuid, UUID_PREFIX, UUID_PREFIX_LEN); -} - /** * dm_get_wwid(): return WWID for a multipath map * @returns: @@ -832,16 +831,14 @@ bool is_mpath_uuid(const char uuid[DM_UUID_LEN]) int dm_get_wwid(const char *name, char *uuid, int uuid_len) { char tmp[DM_UUID_LEN]; - int rc = dm_get_dm_uuid(name, tmp); + int rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_CHECK_UUID, + (mapid_t) { .str = name }, + (mapinfo_t) { .uuid = tmp }); if (rc != DMP_OK) return rc; - if (is_mpath_uuid(tmp)) - strlcpy(uuid, tmp + UUID_PREFIX_LEN, uuid_len); - else - return DMP_NO_MATCH; - + strlcpy(uuid, tmp + UUID_PREFIX_LEN, uuid_len); return DMP_OK; } @@ -859,16 +856,13 @@ static bool is_mpath_part_uuid(const char part_uuid[DM_UUID_LEN], int dm_is_mpath(const char *name) { - char uuid[DM_UUID_LEN]; - int rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY, + int rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY | MAPINFO_CHECK_UUID, (mapid_t) { .str = name }, - (mapinfo_t) { .uuid = uuid }); + (mapinfo_t) { .uuid = NULL }); switch (rc) { case DMP_OK: - if (is_mpath_uuid(uuid)) - return DM_IS_MPATH_YES; - /* fallthrough */ + return DM_IS_MPATH_YES; case DMP_NOT_FOUND: case DMP_NO_MATCH: return DM_IS_MPATH_NO; @@ -974,14 +968,10 @@ int _dm_flush_map (const char *mapname, int flags, int retries) int queue_if_no_path = 0; int udev_flags = 0; char *params __attribute__((cleanup(cleanup_charp))) = NULL; - char uuid[DM_UUID_LEN]; - if (libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY, + if (libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY | MAPINFO_CHECK_UUID, (mapid_t) { .str = mapname }, - (mapinfo_t) { - .uuid = uuid, - .target = ¶ms }) != DMP_OK - || !is_mpath_uuid(uuid)) + (mapinfo_t) { .target = ¶ms }) != DMP_OK) return DM_FLUSH_OK; /* nothing to do */ /* if the device currently has no partitions, do not diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h index 6eb5ab9..c28991f 100644 --- a/libmultipath/devmapper.h +++ b/libmultipath/devmapper.h @@ -57,6 +57,8 @@ enum __mapinfo_flags { /* Fail if target type is not "partition" (linear) */ MAPINFO_PART_ONLY = (1 << 4), __MAPINFO_TGT_TYPE = (MAPINFO_MPATH_ONLY | MAPINFO_PART_ONLY), + /* Fail if the UUID doesn't match the multipath UUID format */ + MAPINFO_CHECK_UUID = (1 << 8), }; typedef union libmp_map_identifier { @@ -138,7 +140,6 @@ enum { DM_IS_MPATH_ERR, }; -bool is_mpath_uuid(const char uuid[DM_UUID_LEN]); int dm_is_mpath(const char *name); enum { diff --git a/libmultipath/libmultipath.version b/libmultipath/libmultipath.version index 649c1cb..959f675 100644 --- a/libmultipath/libmultipath.version +++ b/libmultipath/libmultipath.version @@ -127,7 +127,6 @@ global: init_foreign; init_prio; io_err_stat_handle_pathfail; - is_mpath_uuid; is_path_valid; libmp_dm_task_create; libmp_get_version; diff --git a/multipath/main.c b/multipath/main.c index 0d989dc..4b19d2e 100644 --- a/multipath/main.c +++ b/multipath/main.c @@ -254,7 +254,7 @@ static int check_usable_paths(struct config *conf, if (pathvec == NULL) return r; - if (libmp_mapinfo(DM_MAP_BY_DEVT | MAPINFO_MPATH_ONLY, + if (libmp_mapinfo(DM_MAP_BY_DEVT | MAPINFO_MPATH_ONLY | MAPINFO_CHECK_UUID, (mapid_t) { .devt = devt }, (mapinfo_t) { .name = mpp->alias, @@ -266,9 +266,6 @@ static int check_usable_paths(struct config *conf, }) != DMP_OK) return r; - if (!is_mpath_uuid(uuid)) - return r; - strlcpy(mpp->wwid, uuid + UUID_PREFIX_LEN, sizeof(mpp->wwid)); if (update_multipath_table__(mpp, pathvec, 0, params, status) != DMP_OK) diff --git a/multipathd/main.c b/multipathd/main.c index 13af94e..386cd07 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -720,7 +720,7 @@ static int add_map_without_path (struct vectors *vecs, const char *alias) if (!mpp || !(mpp->alias = strdup(alias))) return DMP_ERR; - if ((rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY, + if ((rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY | MAPINFO_CHECK_UUID, (mapid_t) { .str = mpp->alias }, (mapinfo_t) { .uuid = uuid, @@ -731,10 +731,7 @@ static int add_map_without_path (struct vectors *vecs, const char *alias) })) != DMP_OK) return rc; - if (!is_mpath_uuid(uuid)) - return DMP_NO_MATCH; - else - strlcpy(mpp->wwid, uuid + UUID_PREFIX_LEN, sizeof(mpp->wwid)); + strlcpy(mpp->wwid, uuid + UUID_PREFIX_LEN, sizeof(mpp->wwid)); if (!strlen(mpp->wwid)) condlog(1, "%s: adding map with empty WWID", mpp->alias); diff --git a/tests/mapinfo.c b/tests/mapinfo.c index f3a8440..f7ad868 100644 --- a/tests/mapinfo.c +++ b/tests/mapinfo.c @@ -54,6 +54,16 @@ static const char MPATH_STATUS_01[] = "A 0 3 2 65:32 A 0 0 1 67:64 A 0 0 1 69:96 A 0 0 1 " "E 0 3 2 8:16 A 0 0 1 66:48 A 0 0 1 68:80 A 0 0 1 "; +static const char BAD_UUID_01[] = ""; +static const char BAD_UUID_02[] = "mpath3600a098038302d414b2b4d4453474f62"; +static const char BAD_UUID_03[] = " mpath-3600a098038302d414b2b4d4453474f62"; +static const char BAD_UUID_04[] = "-mpath-3600a098038302d414b2b4d4453474f62"; +static const char BAD_UUID_05[] = "mpth-3600a098038302d414b2b4d4453474f62"; +static const char BAD_UUID_06[] = "part1-mpath-3600a098038302d414b2b4d4453474f62"; +static const char BAD_UUID_07[] = "mpath 3600a098038302d414b2b4d4453474f62"; +static const char BAD_UUID_08[] = "mpath"; +static const char BAD_UUID_09[] = "mpath-"; + char *__real_strdup(const char *str); char *__wrap_strdup(const char *str) { @@ -413,6 +423,208 @@ static void test_mapinfo_good_exists(void **state) assert_int_equal(rc, DMP_OK); } +static void test_mapinfo_bad_check_uuid_00(void **state) +{ + int rc; + + 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, NULL); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_CHECK_UUID, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_ERR); +} + +static void test_mapinfo_bad_check_uuid_01(void **state) +{ + int rc; + + 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, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_NO_MATCH); +} + +static void test_mapinfo_bad_check_uuid_02(void **state) +{ + int rc; + + 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_02); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_CHECK_UUID, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_NO_MATCH); +} + +static void test_mapinfo_bad_check_uuid_03(void **state) +{ + int rc; + + 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_03); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_CHECK_UUID, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_NO_MATCH); +} + +static void test_mapinfo_bad_check_uuid_04(void **state) +{ + int rc; + + 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_04); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_CHECK_UUID, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_NO_MATCH); +} + +static void test_mapinfo_bad_check_uuid_05(void **state) +{ + int rc; + + 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_05); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_CHECK_UUID, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_NO_MATCH); +} + +static void test_mapinfo_bad_check_uuid_06(void **state) +{ + int rc; + + 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_06); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_CHECK_UUID, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_NO_MATCH); +} + +static void test_mapinfo_bad_check_uuid_07(void **state) +{ + int rc; + + 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_07); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_CHECK_UUID, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_NO_MATCH); +} + +static void test_mapinfo_bad_check_uuid_08(void **state) +{ + int rc; + + 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_08); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_CHECK_UUID, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_NO_MATCH); +} + +static void test_mapinfo_bad_check_uuid_09(void **state) +{ + int rc; + + 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_09); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_CHECK_UUID, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_OK); +} + +static void test_mapinfo_good_check_uuid_01(void **state) +{ + int rc; + + 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, MPATH_UUID_01); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_CHECK_UUID, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_OK); +} + +static void test_mapinfo_good_check_uuid_02(void **state) +{ + int rc; + char uuid[DM_UUID_LEN]; + + 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, MPATH_UUID_01); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_CHECK_UUID, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .uuid = uuid }); + assert_int_equal(rc, DMP_OK); +} + +static void test_mapinfo_good_check_uuid_03(void **state) +{ + int rc; + + 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, TGT_MPATH, MPATH_STATUS_01, NULL); + will_return(__wrap_dm_task_get_uuid, MPATH_UUID_01); + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY | MAPINFO_CHECK_UUID, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .name = NULL }); + assert_int_equal(rc, DMP_OK); +} + +static void test_mapinfo_good_check_uuid_04(void **state) +{ + char __attribute__((cleanup(cleanup_charp))) *target = NULL; + int rc; + + 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, TGT_MPATH, MPATH_STATUS_01, NULL); + will_return(__wrap_dm_task_get_uuid, MPATH_UUID_01); + will_return(__wrap_strdup, 1); + + rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY | MAPINFO_CHECK_UUID, + (mapid_t) { .str = "foo", }, + (mapinfo_t) { .target = &target }); + assert_int_equal(rc, DMP_OK); +} + static void test_mapinfo_bad_set_uuid(void **state) { int rc; @@ -1126,6 +1338,20 @@ static int test_mapinfo(void) cmocka_unit_test(test_mapinfo_bad_get_info_03), cmocka_unit_test(test_mapinfo_bad_get_info_04), cmocka_unit_test(test_mapinfo_good_exists), + cmocka_unit_test(test_mapinfo_bad_check_uuid_00), + cmocka_unit_test(test_mapinfo_bad_check_uuid_01), + cmocka_unit_test(test_mapinfo_bad_check_uuid_02), + cmocka_unit_test(test_mapinfo_bad_check_uuid_03), + cmocka_unit_test(test_mapinfo_bad_check_uuid_04), + cmocka_unit_test(test_mapinfo_bad_check_uuid_05), + cmocka_unit_test(test_mapinfo_bad_check_uuid_06), + 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_good_check_uuid_01), + cmocka_unit_test(test_mapinfo_good_check_uuid_02), + cmocka_unit_test(test_mapinfo_good_check_uuid_03), + cmocka_unit_test(test_mapinfo_good_check_uuid_04), cmocka_unit_test(test_mapinfo_bad_set_uuid), cmocka_unit_test(test_mapinfo_bad_set_dev_01), cmocka_unit_test(test_mapinfo_bad_set_dev_02), From patchwork Fri Jul 12 17:14:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13732097 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AD2C317838F for ; Fri, 12 Jul 2024 17:16:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804587; cv=none; b=P+bLGvb9+HoMDpU3W8UI0NBtZZHLqtNailtGnKRr4eNosms58/+DzuDFB/t7ck1gYpO+tsWD7sKL+u+AbjKr7wQB4WwDfQaRA8kELK9FtxlkVp1C0LTdYiFqSUzZN+zLomGkFEaHz0UE5LNX/56r0TCnwQqF2pujnyYlm63deCc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720804587; c=relaxed/simple; bh=cDHfDiWIi1uuI2Cs5vL9e2zCBK34NKZyVFM9bw4j6J4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=po1JTZTMea4CaGFViZSFHrD5/4rXQ1idnHeohYPkGDQfwtVYVdAvGUSjHgECFY7v4jbvWx0hy0dZSzB1kIZQ0TEshkPbhirUVz2CC+8+G1cN+Wsg8afV+1JDXJx6tOcC3uRUdI3Hy9X8RGsC64MrQjCJco6rqvFC/VVMBTJp+PQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=f9WXyqFQ; arc=none smtp.client-ip=209.85.167.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="f9WXyqFQ" Received: by mail-lf1-f50.google.com with SMTP id 2adb3069b0e04-52ea79e689eso3134757e87.1 for ; Fri, 12 Jul 2024 10:16:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1720804583; x=1721409383; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=855qBvMaJe894fAAKnmHCRxDw1hu9BGhS2XpfYlxhds=; b=f9WXyqFQ6XjhigLJSDvHXmhOl+EeKIXmytK3lO6KEbOEkjIEouVo/CcGL/1i3UdsNR ZHUX562jw2Kttgn+bQG5NmO2aN5uaonKtKwz9KXnMBAZ9AOwfebQ8JWXayV4JG7cqTvi Z0FvSVGA90Sk7UFv8srAdLyyXhNfX3/xmpgedv+s2bAZBvrEmbeXx6+4soPFYhCpbbLH cQwk5uGxblDBD+fuClhOOflIewMRCR0Ts8DMZ1eHmL8EpnFj1C5BJ1u4cTSp5lN+Lct3 hDqv7oJsuQZc0wnqT9RTFSRx+uGX0FiBA6NxCFF+Z8wcFYBvfcXK/GD7EUgXV2VD0TM8 gchg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720804583; x=1721409383; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=855qBvMaJe894fAAKnmHCRxDw1hu9BGhS2XpfYlxhds=; b=JCtv2po6b3H2zJa19b+louVcRwxv7gkYWCYwL9Unn+Md96hPy5nC1I1E1GkNgoZiQO jxq9U0ktTexJJvCupKs+alXImHQTdzRV5c0aH22y+F5wn5nggNBykEnehbm2oMHejE/w 6xm8IufoqME0uKWafn3Hp4/sOolSZUDvaJjlrHnq/cDgmYc277AwEgExrOhrhNNcq3cw UBP7Y5OKkuCOE6M2aDK7AuDaeYC4kgiwxgzXucobFB6uI45u8TrEKLGak4PzyTZ5MyEN l8Jwm7aG26ZrzqfWqbCmOw6NkrfbCbtkEfW2rhbCt5GdoFpROBK3ParCZYQQjQ8TGDNL Btew== X-Gm-Message-State: AOJu0YxsYaNWrbhdaMGJFcLI7Tmr1MHxsKm3qY5ZE+kxPUuRSLSU2F+A alPKXiO3Ffee453odM0S1BDb8BbGOEOqkC4+gUcuBxrDw4R/VSMHz3vLmgOHSco= X-Google-Smtp-Source: AGHT+IFtFcmD0pBYrQIp6lLVSwuWEDS7aPg4AtfaSMT0KYlQSySEbS1+MGASr549L2ngMRWnR0CugQ== X-Received: by 2002:a05:6512:36d3:b0:52c:daa4:2f6a with SMTP id 2adb3069b0e04-52eb99d670dmr8022130e87.64.1720804582673; Fri, 12 Jul 2024 10:16:22 -0700 (PDT) Received: from localhost (p200300de37360a00d7e56139e90929dd.dip0.t-ipconnect.de. [2003:de:3736:a00:d7e5:6139:e909:29dd]) by smtp.gmail.com with UTF8SMTPSA id a640c23a62f3a-a780a6bcc8csm367753566b.17.2024.07.12.10.16.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jul 2024 10:16:22 -0700 (PDT) From: Martin Wilck X-Google-Original-From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@lists.linux.dev, Martin Wilck Subject: [PATCH v2 49/49] multipath-tools tests: fix directio test with real device Date: Fri, 12 Jul 2024 19:14:57 +0200 Message-ID: <20240712171458.77611-50-mwilck@suse.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712171458.77611-1-mwilck@suse.com> References: <20240712171458.77611-1-mwilck@suse.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Allow setting DIO_TEST_DEV during runtime, by reading the environment variable. The test was fragile despite the delay, because the real io_getevents() call isn't guaranteed to return the number of events requested. Fix that. Moreover, allow reading DIO_TEST_DELAY (in us) from the environment. With the io_getevents fix, for me the test succeeded even with 0 us delay. Change the README accordingly. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- tests/Makefile | 8 --- tests/README.md | 29 ++++++-- tests/directio.c | 182 ++++++++++++++++++++++++++--------------------- 3 files changed, 122 insertions(+), 97 deletions(-) diff --git a/tests/Makefile b/tests/Makefile index 55fbf0f..02580e7 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -21,12 +21,6 @@ valgrind: $(TESTS:%=%.vgr) # test-specific compiler flags # XYZ-test_FLAGS: Additional compiler flags for this test -ifneq ($(wildcard directio_test_dev),) -DIO_TEST_DEV = $(shell sed -n -e 's/^[[:space:]]*DIO_TEST_DEV[[:space:]]*=[[:space:]]*\([^[:space:]\#]\+\).*/\1/p' < directio_test_dev) -endif -ifneq ($(DIO_TEST_DEV),) -directio-test_FLAGS := -DDIO_TEST_DEV=\"$(DIO_TEST_DEV)\" -endif mpathvalid-test_FLAGS := -I$(mpathvaliddir) features-test_FLAGS := -I$(multipathdir)/nvme @@ -59,9 +53,7 @@ valid-test_LIBDEPS := -lmount -ludev -lpthread -ldl devt-test_LIBDEPS := -ludev mpathvalid-test_LIBDEPS := -ludev -lpthread -ldl mpathvalid-test_OBJDEPS := $(mpathvaliddir)/mpath_valid.o -ifneq ($(DIO_TEST_DEV),) directio-test_LIBDEPS := -laio -endif strbuf-test_OBJDEPS := $(mpathutildir)/strbuf.o sysfs-test_TESTDEPS := test-log.o sysfs-test_OBJDEPS := $(multipathdir)/sysfs.o $(mpathutildir)/util.o diff --git a/tests/README.md b/tests/README.md index fd36fc1..0cae057 100644 --- a/tests/README.md +++ b/tests/README.md @@ -13,6 +13,17 @@ If valgrind detects a bad memory access or leak, the test will fail. The output of the test run, including valgrind output, is stored as `.vgr`. +## Running tests manually + +`make test` or `make -C test "$TEST.out"` will only run the test program if +the output files `$TEST.out` don't exist yet. To re-run the test, delete the +output file first. In order to run a test outside `make`, set the library +search path: + + cd tests + export LD_LIBRARY_PATH=.:../libmpathutil:../libmpathcmd + ./dmevents-test # or whatever other test you want to run + ## Controlling verbosity for unit tests Some test programs use the environment variable `MPATHTEST_VERBOSITY` to @@ -37,15 +48,21 @@ This test includes test items that require a access to a block device. The device will be opened in read-only mode; you don't need to worry about data loss. However, the user needs to specify a device to be used. Set the environment variable `DIO_TEST_DEV` to the path of the device. -Alternatively, create a file `directio_test_dev` under -the `tests` directory containing a single line that sets this environment -variable in Bourne Shell syntax, like this: - - DIO_TEST_DEV=/dev/sdc3 - After that, run `make directio.out` as root in the `tests` directory to perform the test. +With a real test device, the test results may note be 100% reproducible, +and sporadic test failures may occur under certain circumstances. +It may be necessary to introduce a certain delay between test +operations. To do so, set the environment variable `DIO_TEST_DELAY` to a +positive integer that determines the delay (in microseconds) after each +`io_submit()` operation. The default delay is 10 microseconds. + +*Note:* `DIO_TEST_DEV` doesn't have to be set during compilation of +`directio-test`. This used to be the case in previous versions of +multipath-tools. Previously, it was possible to set `DIO_TEST_DEV` in a file +`tests/directio_test_dev`. This is not supported any more. + ## Adding tests The unit tests are based on the [cmocka test framework](https://cmocka.org/), diff --git a/tests/directio.c b/tests/directio.c index d5f84f1..763929e 100644 --- a/tests/directio.c +++ b/tests/directio.c @@ -34,6 +34,8 @@ struct io_event mock_events[AIO_GROUP_SIZE]; /* same as the checker max */ int ev_off = 0; struct timespec zero_timeout = { .tv_sec = 0 }; struct timespec full_timeout = { .tv_sec = -1 }; +const char *test_dev = NULL; +unsigned int test_delay = 10000; #ifdef __GLIBC__ #define ioctl_request_t unsigned long @@ -45,12 +47,13 @@ int REAL_IOCTL(int fd, ioctl_request_t request, void *argp); int WRAP_IOCTL(int fd, ioctl_request_t request, void *argp) { -#ifdef DIO_TEST_DEV - mock_type(int); - return REAL_IOCTL(fd, request, argp); -#else int *blocksize = (int *)argp; + if (test_dev) { + mock_type(int); + return REAL_IOCTL(fd, request, argp); + } + assert_int_equal(fd, test_fd); /* * On MUSL libc, the "request" arg is an int (glibc: unsigned long). @@ -64,88 +67,80 @@ int WRAP_IOCTL(int fd, ioctl_request_t request, void *argp) assert_non_null(blocksize); *blocksize = mock_type(int); return 0; -#endif } int REAL_FCNTL (int fd, int cmd, long arg); int WRAP_FCNTL (int fd, int cmd, long arg) { -#ifdef DIO_TEST_DEV - return REAL_FCNTL(fd, cmd, arg); -#else + if (test_dev) + return REAL_FCNTL(fd, cmd, arg); assert_int_equal(fd, test_fd); assert_int_equal(cmd, F_GETFL); return O_DIRECT; -#endif } int __real___fxstat(int ver, int fd, struct stat *statbuf); int __wrap___fxstat(int ver, int fd, struct stat *statbuf) { -#ifdef DIO_TEST_DEV - return __real___fxstat(ver, fd, statbuf); -#else + if (test_dev) + return __real___fxstat(ver, fd, statbuf); + assert_int_equal(fd, test_fd); assert_non_null(statbuf); memset(statbuf, 0, sizeof(struct stat)); return 0; -#endif + } int __real_io_setup(int maxevents, io_context_t *ctxp); int __wrap_io_setup(int maxevents, io_context_t *ctxp) { - ioctx_count++; -#ifdef DIO_TEST_DEV int ret = mock_type(int); - assert_int_equal(ret, __real_io_setup(maxevents, ctxp)); + + if (test_dev) + assert_int_equal(ret, __real_io_setup(maxevents, ctxp)); + ioctx_count++; return ret; -#else - return mock_type(int); -#endif } int __real_io_destroy(io_context_t ctx); int __wrap_io_destroy(io_context_t ctx) { - ioctx_count--; -#ifdef DIO_TEST_DEV int ret = mock_type(int); - assert_int_equal(ret, __real_io_destroy(ctx)); + + ioctx_count--; + if (test_dev) + assert_int_equal(ret, __real_io_destroy(ctx)); + return ret; -#else - return mock_type(int); -#endif } int __real_io_submit(io_context_t ctx, long nr, struct iocb *ios[]); int __wrap_io_submit(io_context_t ctx, long nr, struct iocb *ios[]) { -#ifdef DIO_TEST_DEV - struct timespec dev_delay = { .tv_nsec = 100000 }; int ret = mock_type(int); - assert_int_equal(ret, __real_io_submit(ctx, nr, ios)); - nanosleep(&dev_delay, NULL); + + if (test_dev) { + struct timespec dev_delay = { .tv_nsec = test_delay }; + assert_int_equal(ret, __real_io_submit(ctx, nr, ios)); + nanosleep(&dev_delay, NULL); + } return ret; -#else - return mock_type(int); -#endif } int __real_io_cancel(io_context_t ctx, struct iocb *iocb, struct io_event *evt); int __wrap_io_cancel(io_context_t ctx, struct iocb *iocb, struct io_event *evt) { -#ifdef DIO_TEST_DEV - return __real_io_cancel(ctx, iocb, evt); -#else - return 0; -#endif + if (test_dev) + return __real_io_cancel(ctx, iocb, evt); + else + return 0; } int REAL_IO_GETEVENTS(io_context_t ctx, long min_nr, long nr, @@ -155,38 +150,43 @@ int WRAP_IO_GETEVENTS(io_context_t ctx, long min_nr, long nr, struct io_event *events, struct timespec *timeout) { int nr_evs; -#ifndef DIO_TEST_DEV struct timespec *sleep_tmo; int i; struct io_event *evs; -#endif assert_non_null(timeout); nr_evs = mock_type(int); assert_true(nr_evs <= nr); if (!nr_evs) return 0; -#ifdef DIO_TEST_DEV - mock_ptr_type(struct timespec *); - mock_ptr_type(struct io_event *); - assert_int_equal(nr_evs, REAL_IO_GETEVENTS(ctx, min_nr, nr_evs, - events, timeout)); -#else - sleep_tmo = mock_ptr_type(struct timespec *); - if (sleep_tmo) { - if (sleep_tmo->tv_sec < 0) - nanosleep(timeout, NULL); - else - nanosleep(sleep_tmo, NULL); + if (test_dev) { + int n = 0; + mock_ptr_type(struct timespec *); + mock_ptr_type(struct io_event *); + + condlog(2, "min_nr = %ld nr_evs = %d", min_nr, nr_evs); + while (n < nr_evs) { + min_nr = min_nr <= nr_evs - n ? min_nr : nr_evs - n; + n += REAL_IO_GETEVENTS(ctx, min_nr, nr_evs - n, + events + n, timeout); + } + assert_int_equal(nr_evs, n); + } else { + sleep_tmo = mock_ptr_type(struct timespec *); + if (sleep_tmo) { + if (sleep_tmo->tv_sec < 0) + nanosleep(timeout, NULL); + else + nanosleep(sleep_tmo, NULL); + } + if (nr_evs < 0) { + errno = -nr_evs; + return -1; + } + evs = mock_ptr_type(struct io_event *); + for (i = 0; i < nr_evs; i++) + events[i] = evs[i]; } - if (nr_evs < 0) { - errno = -nr_evs; - return -1; - } - evs = mock_ptr_type(struct io_event *); - for (i = 0; i < nr_evs; i++) - events[i] = evs[i]; -#endif ev_off -= nr_evs; return nr_evs; } @@ -259,10 +259,9 @@ static void do_libcheck_init(struct checker *c, int blocksize, assert_non_null(ct->req); if (req) *req = ct->req; -#ifndef DIO_TEST_DEV - /* don't check fake blocksize on real devices */ - assert_int_equal(ct->req->blksize, blocksize); -#endif + if (!test_dev) + /* don't check fake blocksize on real devices */ + assert_int_equal(ct->req->blksize, blocksize); } static int is_checker_running(struct checker *c) @@ -583,11 +582,11 @@ static void test_async_timeout_cancel_failed(void **state) do_check_state(&c[1], 0, 2, PATH_PENDING); return_io_getevents_none(); do_check_state(&c[0], 0, 2, PATH_DOWN); -#ifndef DIO_TEST_DEV - /* can't pick which even gets returned on real devices */ - return_io_getevents_nr(NULL, 1, &reqs[1], &res[1]); - do_check_state(&c[1], 0, 2, PATH_UP); -#endif + if (!test_dev) { + /* can't pick which even gets returned on real devices */ + return_io_getevents_nr(NULL, 1, &reqs[1], &res[1]); + do_check_state(&c[1], 0, 2, PATH_UP); + } return_io_getevents_none(); do_check_state(&c[0], 0, 2, PATH_DOWN); assert_true(is_checker_running(&c[0])); @@ -663,12 +662,11 @@ static void test_check_state_blksize(void **state) int blksize[] = {4096, 1024, 512}; struct async_req *reqs[3]; int res[] = {0,1,0}; -#ifdef DIO_TEST_DEV - /* can't pick event return state on real devices */ int chk_state[] = {PATH_UP, PATH_UP, PATH_UP}; -#else - int chk_state[] = {PATH_UP, PATH_DOWN, PATH_UP}; -#endif + + /* can't pick event return state on real devices */ + if (!test_dev) + chk_state[1] = PATH_DOWN; assert_true(list_empty(&aio_grp_list)); will_return(__wrap_io_setup, 0); @@ -718,20 +716,38 @@ static void test_check_state_async(void **state) static int setup(void **state) { -#ifdef DIO_TEST_DEV - test_fd = open(DIO_TEST_DEV, O_RDONLY); - if (test_fd < 0) - fail_msg("cannot open %s: %m", DIO_TEST_DEV); -#endif + char *dl = getenv("DIO_TEST_DELAY"); + test_dev = getenv("DIO_TEST_DEV"); + + if (test_dev) { + condlog(2, "%s: opening %s", __func__, test_dev); + test_fd = open(test_dev, O_RDONLY); + if (dl) { + char *e; + long int d = strtol(dl, &e, 10); + + if (*e == '\0' && d >= 0 && (d * 1000) < (long)UINT_MAX) + test_delay = d * 1000; + else { + condlog(1, "DIO_TEST_DELAY=%s is invalid", dl); + return 1; + } + } + condlog(2, "%s: delay = %u us", __func__, test_delay / 1000); + } + if (test_fd < 0) { + fail_msg("cannot open %s: %m", test_dev); + return 1; + } return 0; } static int teardown(void **state) { -#ifdef DIO_TEST_DEV - assert_true(test_fd > 0); - assert_int_equal(close(test_fd), 0); -#endif + if (test_dev) { + assert_true(test_fd > 0); + assert_int_equal(close(test_fd), 0); + } return 0; } @@ -762,7 +778,7 @@ int main(void) { int ret = 0; - init_test_verbosity(5); + init_test_verbosity(2); ret += test_directio(); return ret; }