From patchwork Mon Sep 11 16:38:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13379489 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8554AEE7FF4 for ; Mon, 11 Sep 2023 16:39:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694450374; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=m2xTUFhuuUThl0HJ8FPDoMetEDQX0dTRaKqVkR2XBEI=; b=OC9SXFlTOcFhdYZiDi2o0Kg7jb8e1s4HCGNh3Z8WxqhpiuMD+u+n8XtJ4o6MQ3tiiKMScM BTEvvocgR7Ka+nJJq7fHjbop8wAIT7D/KM8F4j++xTUQKImRsZnQNbQjFGMbzl2m3FzKap hfqTFrqYGGqFehpASuyEGbNUV23m50I= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-617-ZHK65lwBOfeYEvKewhX-vQ-1; Mon, 11 Sep 2023 12:39:28 -0400 X-MC-Unique: ZHK65lwBOfeYEvKewhX-vQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E34D61C04348; Mon, 11 Sep 2023 16:39:21 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id CEC1410005D4; Mon, 11 Sep 2023 16:39:21 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 9017E19465B6; Mon, 11 Sep 2023 16:39:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id DE99419465A3 for ; Mon, 11 Sep 2023 16:39:19 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id C225D2156711; Mon, 11 Sep 2023 16:39:19 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast07.extmail.prod.ext.rdu2.redhat.com [10.11.55.23]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BA8912156701 for ; Mon, 11 Sep 2023 16:39:19 +0000 (UTC) Received: from us-smtp-inbound-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9E73C3C02B64 for ; Mon, 11 Sep 2023 16:39:19 +0000 (UTC) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-173-q9AjeYsjMPC7wHdIu_kKeg-1; Mon, 11 Sep 2023 12:39:16 -0400 X-MC-Unique: q9AjeYsjMPC7wHdIu_kKeg-1 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id CA06221860; Mon, 11 Sep 2023 16:39:14 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 963DD139CC; Mon, 11 Sep 2023 16:39:14 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id WH3uIrJC/2RzEAAAMHmgww (envelope-from ); Mon, 11 Sep 2023 16:39:14 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Mon, 11 Sep 2023 18:38:10 +0200 Message-ID: <20230911163846.27197-2-mwilck@suse.com> In-Reply-To: <20230911163846.27197-1-mwilck@suse.com> References: <20230911163846.27197-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Subject: [dm-devel] [PATCH v2 01/37] libmultipath: sysfs_set_scsi_tmo: do nothing for ACT_DRY_RUN X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dm-devel@redhat.com, Jehan Singh , Martin Wilck Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: suse.com From: Martin Wilck "multipath -d" might change sysfs timeouts of SCSI devices. Make sure it doesn't. Signed-off-by: Martin Wilck Cc: Jehan Singh Reviewed-by: Benjamin Marzinski --- libmultipath/configure.c | 4 ++-- libmultipath/discovery.c | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/libmultipath/configure.c b/libmultipath/configure.c index 9513baa..029fbbd 100644 --- a/libmultipath/configure.c +++ b/libmultipath/configure.c @@ -1193,13 +1193,13 @@ int coalesce_paths (struct vectors *vecs, vector mpvec, char *refwwid, if (cmpp) mpp->queue_mode = cmpp->queue_mode; + if (cmd == CMD_DRY_RUN && mpp->action == ACT_UNDEF) + mpp->action = ACT_DRY_RUN; if (setup_map(mpp, ¶ms, vecs)) { remove_map(mpp, vecs->pathvec, NULL); continue; } - if (cmd == CMD_DRY_RUN) - mpp->action = ACT_DRY_RUN; if (mpp->action == ACT_UNDEF) select_action(mpp, curmp, force_reload == FORCE_RELOAD_YES ? 1 : 0); diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c index e4de48e..84ce5fe 100644 --- a/libmultipath/discovery.c +++ b/libmultipath/discovery.c @@ -857,6 +857,9 @@ sysfs_set_scsi_tmo (struct config *conf, struct multipath *mpp) bool warn_dev_loss = false; bool warn_fast_io_fail = false; + if (mpp->action == ACT_DRY_RUN || mpp->action == ACT_REJECT) + return 0; + if (mpp->no_path_retry > 0) { uint64_t no_path_retry_tmo = (uint64_t)mpp->no_path_retry * conf->checkint; From patchwork Mon Sep 11 16:38:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13379480 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4217FEE7FF4 for ; Mon, 11 Sep 2023 16:39:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694450368; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=HVDT1SYcLUEydV/XVP6nY9+KfGWT/cNHNhMMFTg8cTY=; b=fNIGYwUEljuBQZxlZBJ7xIKWzpw1y8K2x67LSnlcExg9W2TvvaJFven/11E2hTWa7w7hrF aW9SbfRlTp6A5gLyMhd5JmNUvU2YZqOhSeKFSx7QYg7yIqU9OehpPSZe/Fd58PgoAdBODZ NRUCgUeelyKJB5Fe6aH34yu66GPDIlM= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-692-Z2f7Q5Q_Nj-T0sWDDw87Qg-1; Mon, 11 Sep 2023 12:39:24 -0400 X-MC-Unique: Z2f7Q5Q_Nj-T0sWDDw87Qg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D9D782999B2E; Mon, 11 Sep 2023 16:39:20 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 649AF40C6EA8; Mon, 11 Sep 2023 16:39:20 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 767A219465B7; Mon, 11 Sep 2023 16:39:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id AC27C1946597 for ; Mon, 11 Sep 2023 16:39:18 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 9B16440C6EBF; Mon, 11 Sep 2023 16:39:18 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9410140C6EA8 for ; Mon, 11 Sep 2023 16:39:18 +0000 (UTC) Received: from us-smtp-inbound-delivery-1.mimecast.com (us-smtp-inbound-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 70A5990F841 for ; Mon, 11 Sep 2023 16:39:18 +0000 (UTC) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-365-_Zhp0QBkMM2kU3iat3beRg-1; Mon, 11 Sep 2023 12:39:16 -0400 X-MC-Unique: _Zhp0QBkMM2kU3iat3beRg-1 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 1139421858; Mon, 11 Sep 2023 16:39:15 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id D6088139CC; Mon, 11 Sep 2023 16:39:14 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id CDGPMrJC/2RzEAAAMHmgww (envelope-from ); Mon, 11 Sep 2023 16:39:14 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Mon, 11 Sep 2023 18:38:11 +0200 Message-ID: <20230911163846.27197-3-mwilck@suse.com> In-Reply-To: <20230911163846.27197-1-mwilck@suse.com> References: <20230911163846.27197-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 Subject: [dm-devel] [PATCH v2 02/37] libmultipath: add alias_already_taken() X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dm-devel@redhat.com, Martin Wilck Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: suse.com From: Martin Wilck Factor out a trivial helper function. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/alias.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/libmultipath/alias.c b/libmultipath/alias.c index c0139a2..83ded88 100644 --- a/libmultipath/alias.c +++ b/libmultipath/alias.c @@ -8,6 +8,7 @@ #include #include #include +#include #include "debug.h" #include "util.h" @@ -109,30 +110,35 @@ scan_devname(const char *alias, const char *prefix) return n; } -static int -id_already_taken(int id, const char *prefix, const char *map_wwid) +static bool alias_already_taken(const char *alias, const char *map_wwid) { - STRBUF_ON_STACK(buf); - const char *alias; - if (append_strbuf_str(&buf, prefix) < 0 || - format_devname(&buf, id) < 0) - return 0; - - alias = get_strbuf_str(&buf); if (dm_map_present(alias)) { char wwid[WWID_SIZE]; /* If both the name and the wwid match, then it's fine.*/ if (dm_get_uuid(alias, wwid, sizeof(wwid)) == 0 && strncmp(map_wwid, wwid, sizeof(wwid)) == 0) - return 0; - condlog(3, "%s: alias '%s' already taken, but not in bindings file. reselecting alias", map_wwid, alias); - return 1; + return false; + condlog(3, "%s: alias '%s' already taken, but not in bindings file. reselecting alias", + map_wwid, alias); + return true; } - return 0; + return false; } +static bool id_already_taken(int id, const char *prefix, const char *map_wwid) +{ + STRBUF_ON_STACK(buf); + const char *alias; + + if (append_strbuf_str(&buf, prefix) < 0 || + format_devname(&buf, id) < 0) + return false; + + alias = get_strbuf_str(&buf); + return alias_already_taken(alias, map_wwid); +} /* * Returns: 0 if matching entry in WWIDs file found From patchwork Mon Sep 11 16:38:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13379486 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A9237EEB580 for ; Mon, 11 Sep 2023 16:39:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694450372; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=24l0lUqQATyH9eIXAiY/8SwChr8VHSvk2GqBW7T5n5I=; b=HM2VWMa/t7N21y55kILAIw5ZeixNdoCQivIgm5TQpnUDYYFh9xxzOdX0jpfRdt1sHPiFvo EETcuiUIqfBqkVjOUeaQuZ9c3HHnz7LQfqR1rt3NN2PSsU/pbfZpYUh2QwZQ0iEzKW5FCP 1O/HokT1mHaWfu6b+cO/O5yDg2yrP8s= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-611-LZaLaGyVMZWO0UokKq8_QA-1; Mon, 11 Sep 2023 12:39:27 -0400 X-MC-Unique: LZaLaGyVMZWO0UokKq8_QA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4DF3138117FD; Mon, 11 Sep 2023 16:39:21 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0647563F48; Mon, 11 Sep 2023 16:39:21 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 9B4A71946A42; Mon, 11 Sep 2023 16:39:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 8DFDD1946597 for ; Mon, 11 Sep 2023 16:39:18 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 6E2C22156701; Mon, 11 Sep 2023 16:39:18 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast09.extmail.prod.ext.rdu2.redhat.com [10.11.55.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 675982156702 for ; Mon, 11 Sep 2023 16:39:18 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-inbound-delivery-1.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4A1372999B25 for ; Mon, 11 Sep 2023 16:39:18 +0000 (UTC) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-694-KoplRMifMk6oFuKW2PmB7w-1; Mon, 11 Sep 2023 12:39:16 -0400 X-MC-Unique: KoplRMifMk6oFuKW2PmB7w-1 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 521F71F38D; Mon, 11 Sep 2023 16:39:15 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 1E4DE139CC; Mon, 11 Sep 2023 16:39:15 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id +MzBBbNC/2RzEAAAMHmgww (envelope-from ); Mon, 11 Sep 2023 16:39:15 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Mon, 11 Sep 2023 18:38:12 +0200 Message-ID: <20230911163846.27197-4-mwilck@suse.com> In-Reply-To: <20230911163846.27197-1-mwilck@suse.com> References: <20230911163846.27197-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Subject: [dm-devel] [PATCH v2 03/37] libmultipath: unify use_existing_alias() and get_user_friendly_alias() X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dm-devel@redhat.com, Martin Wilck Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: suse.com From: Martin Wilck These functions are only called from select_alias(). The logic is more obvious when unified in a single function. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/alias.c | 82 ++++++++++++------------------------------ libmultipath/alias.h | 9 ++--- libmultipath/propsel.c | 19 +++++----- 3 files changed, 34 insertions(+), 76 deletions(-) diff --git a/libmultipath/alias.c b/libmultipath/alias.c index 83ded88..68f5d84 100644 --- a/libmultipath/alias.c +++ b/libmultipath/alias.c @@ -329,13 +329,13 @@ allocate_binding(int fd, const char *wwid, int id, const char *prefix) return alias; } -char * -use_existing_alias (const char *wwid, const char *file, const char *alias_old, - const char *prefix, int bindings_read_only) +char *get_user_friendly_alias(const char *wwid, const char *file, const char *alias_old, + const char *prefix, bool bindings_read_only) { char *alias = NULL; int id = 0; int fd, can_write; + bool new_binding = false; char buff[WWID_SIZE]; FILE *f; @@ -349,6 +349,10 @@ use_existing_alias (const char *wwid, const char *file, const char *alias_old, close(fd); return NULL; } + + if (!strlen(alias_old)) + goto new_alias; + /* lookup the binding. if it exists, the wwid will be in buff * either way, id contains the id for the alias */ @@ -358,14 +362,14 @@ use_existing_alias (const char *wwid, const char *file, const char *alias_old, /* if buff is our wwid, it's already * allocated correctly */ - if (strcmp(buff, wwid) == 0) + if (strcmp(buff, wwid) == 0) { alias = strdup(alias_old); - else { - alias = NULL; + goto out; + } else { condlog(0, "alias %s already bound to wwid %s, cannot reuse", alias_old, buff); + goto new_alias; } - goto out; } id = lookup_binding(f, wwid, &alias, NULL, 0); @@ -377,8 +381,15 @@ use_existing_alias (const char *wwid, const char *file, const char *alias_old, /* allocate the existing alias in the bindings file */ id = scan_devname(alias_old, prefix); - if (id <= 0) - goto out; + +new_alias: + if (id <= 0) { + id = lookup_binding(f, wwid, &alias, prefix, 1); + if (id <= 0) + goto out; + else + new_binding = true; + } if (fflush(f) != 0) { condlog(0, "cannot fflush bindings file stream : %s", @@ -388,8 +399,9 @@ use_existing_alias (const char *wwid, const char *file, const char *alias_old, if (can_write && !bindings_read_only) { alias = allocate_binding(fd, wwid, id, prefix); - condlog(0, "Allocated existing binding [%s] for WWID [%s]", - alias, wwid); + if (alias && !new_binding) + condlog(2, "Allocated existing binding [%s] for WWID [%s]", + alias, wwid); } out: @@ -399,54 +411,6 @@ out: return alias; } -char * -get_user_friendly_alias(const char *wwid, const char *file, const char *prefix, - int bindings_read_only) -{ - char *alias; - int fd, id; - FILE *f; - int can_write; - - if (!wwid || *wwid == '\0') { - condlog(3, "Cannot find binding for empty WWID"); - return NULL; - } - - fd = open_file(file, &can_write, bindings_file_header); - if (fd < 0) - return NULL; - - f = fdopen(fd, "r"); - if (!f) { - condlog(0, "cannot fdopen on bindings file descriptor : %s", - strerror(errno)); - close(fd); - return NULL; - } - - id = lookup_binding(f, wwid, &alias, prefix, 1); - if (id < 0) { - fclose(f); - return NULL; - } - - pthread_cleanup_push(free, alias); - - if (fflush(f) != 0) { - condlog(0, "cannot fflush bindings file stream : %s", - strerror(errno)); - free(alias); - alias = NULL; - } else if (can_write && !bindings_read_only && !alias) - alias = allocate_binding(fd, wwid, id, prefix); - - fclose(f); - - pthread_cleanup_pop(0); - return alias; -} - int get_user_friendly_wwid(const char *alias, char *buff, const char *file) { diff --git a/libmultipath/alias.h b/libmultipath/alias.h index dbc950c..fa33223 100644 --- a/libmultipath/alias.h +++ b/libmultipath/alias.h @@ -2,13 +2,10 @@ #define _ALIAS_H int valid_alias(const char *alias); -char *get_user_friendly_alias(const char *wwid, const char *file, - const char *prefix, - int bindings_readonly); int get_user_friendly_wwid(const char *alias, char *buff, const char *file); -char *use_existing_alias (const char *wwid, const char *file, - const char *alias_old, - const char *prefix, int bindings_read_only); +char *get_user_friendly_alias(const char *wwid, const char *file, + const char *alias_old, + const char *prefix, bool bindings_read_only); struct config; int check_alias_settings(const struct config *); diff --git a/libmultipath/propsel.c b/libmultipath/propsel.c index d6bce12..354e883 100644 --- a/libmultipath/propsel.c +++ b/libmultipath/propsel.c @@ -401,19 +401,16 @@ int select_alias(struct config *conf, struct multipath * mp) select_alias_prefix(conf, mp); - if (strlen(mp->alias_old) > 0) { - mp->alias = use_existing_alias(mp->wwid, conf->bindings_file, - mp->alias_old, mp->alias_prefix, - conf->bindings_read_only); - memset (mp->alias_old, 0, WWID_SIZE); - origin = "(setting: using existing alias)"; - } + mp->alias = get_user_friendly_alias(mp->wwid, conf->bindings_file, + mp->alias_old, mp->alias_prefix, + conf->bindings_read_only); - if (mp->alias == NULL) { - mp->alias = get_user_friendly_alias(mp->wwid, - conf->bindings_file, mp->alias_prefix, conf->bindings_read_only); + if (mp->alias && !strncmp(mp->alias, mp->alias_old, WWID_SIZE)) + origin = "(setting: using existing alias)"; + else if (mp->alias) origin = "(setting: user_friendly_name)"; - } + memset (mp->alias_old, 0, WWID_SIZE); + out: if (mp->alias == NULL) { mp->alias = strdup(mp->wwid); From patchwork Mon Sep 11 16:38:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13379483 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D9498EEB581 for ; Mon, 11 Sep 2023 16:39:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694450371; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=yEHgkoO+OvIjhEk2USPc44d0XLLXuV32bIoWrF8qLdk=; b=aj78rNTLe6B8W5GoN0HN0gT/u+107d8el8H+iV4hgnW8KkM0eYos1K0qLH3rpPSJdhXNVY ZWLMnK4ZrqdJYXIhMEMwuDQFLzjsb/jC2zm+NwFE6GSa84uc5xLIw6ZYX41/5LGS17eXp9 BAaZ3HQeBm8md/FyLk1LyDlztjZvSrs= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-58-f5jmrUPFNLK5zz9chL5FxQ-1; Mon, 11 Sep 2023 12:39:29 -0400 X-MC-Unique: f5jmrUPFNLK5zz9chL5FxQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B7D591C0433D; Mon, 11 Sep 2023 16:39:21 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id A540740C2064; Mon, 11 Sep 2023 16:39:21 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 5E96F19465A3; Mon, 11 Sep 2023 16:39:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id AEBF71946A48 for ; Mon, 11 Sep 2023 16:39:19 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 9B98F2027046; Mon, 11 Sep 2023 16:39:19 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast07.extmail.prod.ext.rdu2.redhat.com [10.11.55.23]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 938972027045 for ; Mon, 11 Sep 2023 16:39:19 +0000 (UTC) Received: from us-smtp-inbound-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7661C3C02B64 for ; Mon, 11 Sep 2023 16:39:19 +0000 (UTC) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-192-vMusTPKIMeWT3FY_uc6BIg-1; Mon, 11 Sep 2023 12:39:16 -0400 X-MC-Unique: vMusTPKIMeWT3FY_uc6BIg-1 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 95C491F8A6; Mon, 11 Sep 2023 16:39:15 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 5FB54139CC; Mon, 11 Sep 2023 16:39:15 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id aKq+FbNC/2RzEAAAMHmgww (envelope-from ); Mon, 11 Sep 2023 16:39:15 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Mon, 11 Sep 2023 18:38:13 +0200 Message-ID: <20230911163846.27197-5-mwilck@suse.com> In-Reply-To: <20230911163846.27197-1-mwilck@suse.com> References: <20230911163846.27197-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 Subject: [dm-devel] [PATCH v2 04/37] libmultipath: never allocate an alias that's already taken X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dm-devel@redhat.com, Martin Wilck , David Bond Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: suse.com From: Martin Wilck If the bindings file is changed in a way that multipathd can't handle (e.g. by swapping the aliases of two maps), multipathd must not try to re-use an alias that is already used by another map. Creating or renaming a map with such an alias will fail. We already avoid this for some cases, but not for all. Fix it. Signed-off-by: Martin Wilck Cc: David Bond Reviewed-by: Benjamin Marzinski --- libmultipath/alias.c | 33 ++++++++++++++++++++++++--------- tests/alias.c | 2 +- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/libmultipath/alias.c b/libmultipath/alias.c index 68f5d84..b5248f2 100644 --- a/libmultipath/alias.c +++ b/libmultipath/alias.c @@ -120,7 +120,7 @@ static bool alias_already_taken(const char *alias, const char *map_wwid) if (dm_get_uuid(alias, wwid, sizeof(wwid)) == 0 && strncmp(map_wwid, wwid, sizeof(wwid)) == 0) return false; - condlog(3, "%s: alias '%s' already taken, but not in bindings file. reselecting alias", + condlog(3, "%s: alias '%s' already taken, reselecting alias", map_wwid, alias); return true; } @@ -359,32 +359,47 @@ char *get_user_friendly_alias(const char *wwid, const char *file, const char *al rlookup_binding(f, buff, alias_old); if (strlen(buff) > 0) { - /* if buff is our wwid, it's already - * allocated correctly - */ + /* If buff is our wwid, it's already allocated correctly. */ if (strcmp(buff, wwid) == 0) { alias = strdup(alias_old); goto out; + } else { condlog(0, "alias %s already bound to wwid %s, cannot reuse", alias_old, buff); - goto new_alias; + goto new_alias; ; } } - id = lookup_binding(f, wwid, &alias, NULL, 0); + /* + * Look for an existing alias in the bindings file. + * Pass prefix = NULL, so lookup_binding() won't try to allocate a new id. + */ + lookup_binding(f, wwid, &alias, NULL, 0); if (alias) { - condlog(3, "Use existing binding [%s] for WWID [%s]", - alias, wwid); + if (alias_already_taken(alias, wwid)) { + free(alias); + alias = NULL; + } else + condlog(3, "Use existing binding [%s] for WWID [%s]", + alias, wwid); goto out; } - /* allocate the existing alias in the bindings file */ + /* alias_old is already taken by our WWID, update bindings file. */ id = scan_devname(alias_old, prefix); new_alias: if (id <= 0) { + /* + * no existing alias was provided, or allocating it + * failed. Try a new one. + */ id = lookup_binding(f, wwid, &alias, prefix, 1); + if (id == 0 && alias_already_taken(alias, wwid)) { + free(alias); + alias = NULL; + } if (id <= 0) goto out; else diff --git a/tests/alias.c b/tests/alias.c index 3ca6c28..11f209e 100644 --- a/tests/alias.c +++ b/tests/alias.c @@ -398,7 +398,7 @@ static void mock_self_alias(const char *alias, const char *wwid) will_return(__wrap_dm_get_uuid, wwid); } -#define USED_STR(alias_str, wwid_str) wwid_str ": alias '" alias_str "' already taken, but not in bindings file. reselecting alias\n" +#define USED_STR(alias_str, wwid_str) wwid_str ": alias '" alias_str "' already taken, reselecting alias\n" static void mock_failed_alias(const char *alias, char *msg) { From patchwork Mon Sep 11 16:38:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13379487 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D0709EEB57E for ; Mon, 11 Sep 2023 16:39:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694450373; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=OU+QyGjgfWGBfL0VNwRFlLd/VOUIlp4JzCR1Lv4mdM8=; b=Mul5ncV+9UsrkUuL2yBLX+V4HQ0Z1fatDzyKzSVhrX7IOCUKUtnEKzpeSd2gi6QXHML2Zn CAxfsKMYncOzvj+KO1lJMYaJvkETQZRHSSNNQINMoQjD+PhOk6eOcxckBH5jimHsTIp+vH /HtO6+j32dXJrzvlMPtJtP1kjj0TSL0= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-85-pzkhRBe2MeeKuhiR5-ZLlw-1; Mon, 11 Sep 2023 12:39:29 -0400 X-MC-Unique: pzkhRBe2MeeKuhiR5-ZLlw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 48EBB945E6D; Mon, 11 Sep 2023 16:39:23 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 311E540C200D; Mon, 11 Sep 2023 16:39:23 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 2237719465B8; Mon, 11 Sep 2023 16:39:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 05E1819465A8 for ; Mon, 11 Sep 2023 16:39:21 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id DCAED40C200A; Mon, 11 Sep 2023 16:39:20 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D540440C200D for ; Mon, 11 Sep 2023 16:39:20 +0000 (UTC) Received: from us-smtp-inbound-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AA3A2928B8A for ; Mon, 11 Sep 2023 16:39:20 +0000 (UTC) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-473-UlfD15EyOjaF9bLWM5nbWw-1; Mon, 11 Sep 2023 12:39:17 -0400 X-MC-Unique: UlfD15EyOjaF9bLWM5nbWw-1 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id CF6C021863; Mon, 11 Sep 2023 16:39:15 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id A0921139CC; Mon, 11 Sep 2023 16:39:15 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id cGuLJbNC/2RzEAAAMHmgww (envelope-from ); Mon, 11 Sep 2023 16:39:15 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Mon, 11 Sep 2023 18:38:14 +0200 Message-ID: <20230911163846.27197-6-mwilck@suse.com> In-Reply-To: <20230911163846.27197-1-mwilck@suse.com> References: <20230911163846.27197-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Subject: [dm-devel] [PATCH v2 05/37] libmultipath: lookup_binding: add comment about the algorithm X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dm-devel@redhat.com, Martin Wilck Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: suse.com From: Martin Wilck When I read this code, I always get confused. Adding comments to explain the algorithm. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/alias.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/libmultipath/alias.c b/libmultipath/alias.c index b5248f2..b95cbbe 100644 --- a/libmultipath/alias.c +++ b/libmultipath/alias.c @@ -172,6 +172,41 @@ lookup_binding(FILE *f, const char *map_wwid, char **map_alias, alias = strtok_r(buf, " \t", &saveptr); if (!alias) /* blank line */ continue; + + /* + * Find an unused index - explanation of the algorithm + * + * ID: 1 = mpatha, 2 = mpathb, ... + * + * We assume the bindings are unsorted. The only constraint + * is that no ID occurs more than once. IDs that occur in the + * bindings are called "used". + * + * We call the list 1,2,3,..., exactly in this order, the list + * of "expected" IDs. The variable "id" always holds the next + * "expected" ID, IOW the last "expected" ID encountered plus 1. + * Thus all IDs below "id" are known to be used. However, at the + * end of the loop, the value of "id" isn't necessarily unused. + * + * "smallest_bigger_id" is the smallest used ID that was + * encountered while it was larger than the next "expected" ID + * at that iteration. Let X be some used ID. If all IDs below X + * are used and encountered in the right sequence before X, "id" + * will be > X when the loop ends. Otherwise, X was encountered + * "out of order", the condition (X > id) holds when X is + * encountered, and "smallest_bigger_id" will be set to X; i.e. + * it will be less or equal than X when the loop ends. + * + * At the end of the loop, (id < smallest_bigger_id) means that + * the value of "id" had been encountered neither in order nor + * out of order, and is thus unused. (id >= smallest_bigger_id) + * means that "id"'s value is in use. In this case, we play safe + * and use "biggest_id + 1" as the next value to try. + * + * biggest_id is always > smallest_bigger_id, except in the + * "perfectly ordered" case. + */ + curr_id = scan_devname(alias, prefix); if (curr_id == id) { if (id < INT_MAX) From patchwork Mon Sep 11 16:38:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13379488 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 14A5EEEB590 for ; Mon, 11 Sep 2023 16:39:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694450371; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=/LTSpJ9QaqH8Y2OdzYSTvc3XR7jVecFnJ4iSnyIPtHI=; b=N7GN6by2YwcEAjx8AVco9DMDDt1jV4CyfzoH1e0m65TphMqm4yR6d1xTB91OdhZcUNnTUL GVjN+N0UmdCVfTNixPKb5CWGlKDpSHPXAGpU3cn+P0tdt4HOY9eqbzkbyvtQ6C+76hN+ac EZz0wE5H2D0E1H5jr5hPgnnm21hp3TQ= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-324-IvMKBqg2OIC_kIh_mRm28w-1; Mon, 11 Sep 2023 12:39:26 -0400 X-MC-Unique: IvMKBqg2OIC_kIh_mRm28w-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 600DB29DD98A; Mon, 11 Sep 2023 16:39:22 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 470D04402E; Mon, 11 Sep 2023 16:39:22 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id F212D19465A2; Mon, 11 Sep 2023 16:39:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 3481419465A8 for ; Mon, 11 Sep 2023 16:39:21 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 1620840C6E75; Mon, 11 Sep 2023 16:39:21 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0D5F440C6EA8 for ; Mon, 11 Sep 2023 16:39:21 +0000 (UTC) Received: from us-smtp-inbound-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E5980101FAAE for ; Mon, 11 Sep 2023 16:39:20 +0000 (UTC) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-470-IxUKEFifMdKnyxXNE9Sg-g-1; Mon, 11 Sep 2023 12:39:17 -0400 X-MC-Unique: IxUKEFifMdKnyxXNE9Sg-g-1 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 150641F8B3; Mon, 11 Sep 2023 16:39:16 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id DAAA4139CC; Mon, 11 Sep 2023 16:39:15 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id sGa6M7NC/2RzEAAAMHmgww (envelope-from ); Mon, 11 Sep 2023 16:39:15 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Mon, 11 Sep 2023 18:38:15 +0200 Message-ID: <20230911163846.27197-7-mwilck@suse.com> In-Reply-To: <20230911163846.27197-1-mwilck@suse.com> References: <20230911163846.27197-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 Subject: [dm-devel] [PATCH v2 06/37] multipath-tools test: simplify debugging for condlog mismatch X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dm-devel@redhat.com, Martin Wilck Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: suse.com From: Martin Wilck If there's a mismatch between expected and actual log message, print both messages. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- tests/test-log.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test-log.c b/tests/test-log.c index c174587..6351699 100644 --- a/tests/test-log.c +++ b/tests/test-log.c @@ -16,12 +16,14 @@ void __wrap_dlog (int prio, const char * fmt, ...) va_list ap; char *expected; - check_expected(prio); va_start(ap, fmt); vsnprintf(buff, MAX_MSG_SIZE, fmt, ap); va_end(ap); fprintf(stderr, "%s(%d): %s", __func__, prio, buff); expected = mock_ptr_type(char *); + if (memcmp(expected, buff, strlen(expected))) + fprintf(stderr, "%s(expected): %s", __func__, expected); + check_expected(prio); assert_memory_equal(buff, expected, strlen(expected)); } From patchwork Mon Sep 11 16:38:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13379492 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DD50FEEB592 for ; Mon, 11 Sep 2023 16:39:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694450375; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=F5cJWVX8FdmFbAboiH6tZoqjNuf3C2W7Zl5uCE2gK60=; b=KEKUFSwBlyAX9UYAfBRV5bCX35yWxT+xa4tPbgOAa69/lrXCEP6iZVv2e2yHhT9toFvIFX TXiCUQxa1iwnH2lr5BqMZm0AcFBh6zF6TX7wKXx627iDgl/e9iBE894Li5JNnkUAxl9PHj j3ZavzTvSgw8/GTIk7bb3wYRPT6b7mY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-661-wzIMeARcNxSdAlwFm3jQMQ-1; Mon, 11 Sep 2023 12:39:31 -0400 X-MC-Unique: wzIMeARcNxSdAlwFm3jQMQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EE732928BAA; Mon, 11 Sep 2023 16:39:23 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id D6B0D215670B; Mon, 11 Sep 2023 16:39:23 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 7EB6519465BB; Mon, 11 Sep 2023 16:39:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 0A25719465BB for ; Mon, 11 Sep 2023 16:39:22 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id EC5722024CDB; Mon, 11 Sep 2023 16:39:21 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast09.extmail.prod.ext.rdu2.redhat.com [10.11.55.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E45FC2024CD6 for ; Mon, 11 Sep 2023 16:39:21 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DAE622999B24 for ; Mon, 11 Sep 2023 16:39:19 +0000 (UTC) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-592-3G_9fYdWPO6chin3OTMUXw-1; Mon, 11 Sep 2023 12:39:17 -0400 X-MC-Unique: 3G_9fYdWPO6chin3OTMUXw-1 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 64A2421875; Mon, 11 Sep 2023 16:39:16 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 22FA3139CC; Mon, 11 Sep 2023 16:39:16 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id gJjHBrRC/2RzEAAAMHmgww (envelope-from ); Mon, 11 Sep 2023 16:39:16 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Mon, 11 Sep 2023 18:38:16 +0200 Message-ID: <20230911163846.27197-8-mwilck@suse.com> In-Reply-To: <20230911163846.27197-1-mwilck@suse.com> References: <20230911163846.27197-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 Subject: [dm-devel] [PATCH v2 07/37] multipath-tools tests: add tests for get_user_friendly_alias() X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dm-devel@redhat.com, Martin Wilck Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: suse.com From: Martin Wilck Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- tests/alias.c | 441 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 441 insertions(+) diff --git a/tests/alias.c b/tests/alias.c index 11f209e..7e443b0 100644 --- a/tests/alias.c +++ b/tests/alias.c @@ -81,6 +81,35 @@ int __wrap_dm_get_uuid(const char *name, char *uuid, int uuid_len) return ret; } +#define TEST_FDNO 1234 +#define TEST_FPTR ((FILE *) 0xaffe) + +int __wrap_open_file(const char *file, int *can_write, const char *header) +{ + int cw = mock_type(int); + + *can_write = cw; + return TEST_FDNO; +} + +FILE *__wrap_fdopen(int fd, const char *mode) +{ + assert_int_equal(fd, TEST_FDNO); + return TEST_FPTR; +} + +int __wrap_fflush(FILE *f) +{ + assert_ptr_equal(f, TEST_FPTR); + return 0; +} + +int __wrap_fclose(FILE *f) +{ + assert_ptr_equal(f, TEST_FPTR); + return 0; +} + /* strbuf wrapper for the old format_devname() */ static int __format_devname(char *name, int id, size_t len, const char *prefix) { @@ -399,6 +428,22 @@ static void mock_self_alias(const char *alias, const char *wwid) } #define USED_STR(alias_str, wwid_str) wwid_str ": alias '" alias_str "' already taken, reselecting alias\n" +#define NOMATCH_STR(alias_str) ("No matching alias [" alias_str "] in bindings file.\n") +#define FOUND_STR(alias_str, wwid_str) \ + "Found matching wwid [" wwid_str "] in bindings file." \ + " Setting alias to " alias_str "\n" +#define FOUND_ALIAS_STR(alias_str, wwid_str) \ + "Found matching alias [" alias_str "] in bindings file." \ + " Setting wwid to " wwid_str "\n" +#define NOMATCH_WWID_STR(wwid_str) ("No matching wwid [" wwid_str "] in bindings file.\n") +#define NEW_STR(alias_str, wwid_str) ("Created new binding [" alias_str "] for WWID [" wwid_str "]\n") +#define EXISTING_STR(alias_str, wwid_str) ("Use existing binding [" alias_str "] for WWID [" wwid_str "]\n") +#define ALLOC_STR(alias_str, wwid_str) ("Allocated existing binding [" alias_str "] for WWID [" wwid_str "]\n") +#define BINDING_STR(alias_str, wwid_str) (alias_str " " wwid_str "\n") +#define BOUND_STR(alias_str, wwid_str) ("alias "alias_str " already bound to wwid " wwid_str ", cannot reuse") +#define ERR_STR(alias_str, wwid_str) ("ERROR: old alias [" alias_str "] for wwid [" wwid_str "] is used by other map\n") +#define REUSE_STR(alias_str, wwid_str) ("alias " alias_str " already bound to wwid " wwid_str ", cannot reuse\n") +#define NOMORE_STR "no more available user_friendly_names\n" static void mock_failed_alias(const char *alias, char *msg) { @@ -421,6 +466,24 @@ static void mock_used_alias(const char *alias, char *msg) expect_condlog(3, msg); } +static void mock_bindings_file(const char *content, int match_line) +{ + static char cnt[1024]; + char *token; + int i; + + assert_in_range(strlcpy(cnt, content, sizeof(cnt)), 0, sizeof(cnt) - 1); + + for (token = strtok(cnt, "\n"), i = 0; + token && *token; + token = strtok(NULL, "\n"), i++) { + will_return(__wrap_fgets, token); + if (match_line == i) + return; + } + will_return(__wrap_fgets, NULL); +} + static void lb_empty(void **state) { int rc; @@ -1147,6 +1210,382 @@ static int test_allocate_binding(void) return cmocka_run_group_tests(tests, NULL, NULL); } +#define mock_allocate_binding(alias, wwid) \ + do { \ + static const char ln[] = BINDING_STR(alias, wwid); \ + \ + will_return(__wrap_lseek, 0); \ + expect_value(__wrap_write, count, strlen(ln)); \ + expect_string(__wrap_write, buf, ln); \ + will_return(__wrap_write, strlen(ln)); \ + expect_condlog(3, NEW_STR(alias, wwid)); \ + } while (0) + +static void gufa_empty_new_rw(void **state) { + char *alias; + + will_return(__wrap_open_file, true); + + will_return(__wrap_fgets, NULL); + mock_unused_alias("MPATHa"); + expect_condlog(3, NOMATCH_WWID_STR("WWID0")); + + mock_allocate_binding("MPATHa", "WWID0"); + alias = get_user_friendly_alias("WWID0", "x", "", "MPATH", false); + assert_string_equal(alias, "MPATHa"); + free(alias); +} + +static void gufa_empty_new_ro_1(void **state) { + char *alias; + will_return(__wrap_open_file, false); + will_return(__wrap_fgets, NULL); + mock_unused_alias("MPATHa"); + expect_condlog(3, NOMATCH_WWID_STR("WWID0")); + + alias = get_user_friendly_alias("WWID0", "x", "", "MPATH", false); + assert_ptr_equal(alias, NULL); +} + +static void gufa_empty_new_ro_2(void **state) { + char *alias; + + will_return(__wrap_open_file, true); + + will_return(__wrap_fgets, NULL); + mock_unused_alias("MPATHa"); + expect_condlog(3, NOMATCH_WWID_STR("WWID0")); + + alias = get_user_friendly_alias("WWID0", "x", "", "MPATH", true); + assert_ptr_equal(alias, NULL); +} + +static void gufa_match_a_unused(void **state) { + char *alias; + + will_return(__wrap_open_file, true); + + will_return(__wrap_fgets, BINDING_STR("MPATHa", "WWID0")); + expect_condlog(3, FOUND_STR("MPATHa", "WWID0")); + mock_unused_alias("MPATHa"); + + alias = get_user_friendly_alias("WWID0", "x", "", "MPATH", true); + assert_string_equal(alias, "MPATHa"); + free(alias); +} + +static void gufa_match_a_self(void **state) { + char *alias; + + will_return(__wrap_open_file, true); + + will_return(__wrap_fgets, BINDING_STR("MPATHa", "WWID0")); + expect_condlog(3, FOUND_STR("MPATHa", "WWID0")); + mock_self_alias("MPATHa", "WWID0"); + + alias = get_user_friendly_alias("WWID0", "x", "", "MPATH", true); + assert_string_equal(alias, "MPATHa"); + free(alias); +} + +static void gufa_match_a_used(void **state) { + char *alias; + + will_return(__wrap_open_file, true); + + will_return(__wrap_fgets, BINDING_STR("MPATHa", "WWID0")); + expect_condlog(3, FOUND_STR("MPATHa", "WWID0")); + mock_used_alias("MPATHa", USED_STR("MPATHa", "WWID0")); + + alias = get_user_friendly_alias("WWID0", "x", "", "MPATH", true); + assert_ptr_equal(alias, NULL); +} + +static void gufa_nomatch_a_c(void **state) { + char *alias; + will_return(__wrap_open_file, true); + + mock_bindings_file("MPATHa WWID0\n" + "MPATHc WWID2", + -1); + mock_unused_alias("MPATHb"); + expect_condlog(3, NOMATCH_WWID_STR("WWID1")); + + mock_allocate_binding("MPATHb", "WWID1"); + + alias = get_user_friendly_alias("WWID1", "x", "", "MPATH", false); + assert_string_equal(alias, "MPATHb"); + free(alias); +} + +static void gufa_nomatch_c_a(void **state) { + char *alias; + will_return(__wrap_open_file, true); + + mock_bindings_file("MPATHc WWID2\n" + "MPATHa WWID0", + -1); + mock_unused_alias("MPATHb"); + expect_condlog(3, NOMATCH_WWID_STR("WWID1")); + + mock_allocate_binding("MPATHb", "WWID1"); + + alias = get_user_friendly_alias("WWID1", "x", "", "MPATH", false); + assert_string_equal(alias, "MPATHb"); + free(alias); +} + +static void gufa_nomatch_c_b(void **state) { + char *alias; + will_return(__wrap_open_file, true); + + mock_bindings_file("MPATHc WWID2\n" + "MPATHb WWID1\n", + -1); + mock_unused_alias("MPATHa"); + expect_condlog(3, NOMATCH_WWID_STR("WWID0")); + + mock_allocate_binding("MPATHa", "WWID0"); + + alias = get_user_friendly_alias("WWID0", "x", "", "MPATH", false); + assert_string_equal(alias, "MPATHa"); + free(alias); +} + +static void gufa_nomatch_c_b_used(void **state) { + char *alias; + will_return(__wrap_open_file, true); + + mock_bindings_file("MPATHc WWID2\n" + "MPATHb WWID1", + -1); + mock_used_alias("MPATHa", USED_STR("MPATHa", "WWID4")); + expect_condlog(3, NOMATCH_WWID_STR("WWID4")); + mock_unused_alias("MPATHd"); + + mock_allocate_binding("MPATHd", "WWID4"); + + alias = get_user_friendly_alias("WWID4", "x", "", "MPATH", false); + assert_string_equal(alias, "MPATHd"); + free(alias); +} + +static void gufa_nomatch_b_f_a(void **state) { + char *alias; + will_return(__wrap_open_file, true); + + mock_bindings_file("MPATHb WWID1\n" + "MPATHf WWID6\n" + "MPATHa WWID0\n", + -1); + expect_condlog(3, NOMATCH_WWID_STR("WWID7")); + mock_unused_alias("MPATHg"); + + mock_allocate_binding("MPATHg", "WWID7"); + + alias = get_user_friendly_alias("WWID7", "x", "", "MPATH", false); + assert_string_equal(alias, "MPATHg"); + free(alias); +} + +static void gufa_old_empty(void **state) { + char *alias; + will_return(__wrap_open_file, true); + + /* rlookup_binding for ALIAS */ + will_return(__wrap_fgets, NULL); + expect_condlog(3, NOMATCH_STR("MPATHz")); + + /* lookup_binding */ + will_return(__wrap_fgets, NULL); + expect_condlog(3, NOMATCH_WWID_STR("WWID0")); + + mock_allocate_binding("MPATHz", "WWID0"); + expect_condlog(2, ALLOC_STR("MPATHz", "WWID0")); + + alias = get_user_friendly_alias("WWID0", "x", "MPATHz", "MPATH", false); + assert_string_equal(alias, "MPATHz"); + free(alias); +} + +static void gufa_old_match(void **state) { + char *alias; + will_return(__wrap_open_file, true); + + mock_bindings_file("MPATHb WWID1\n" + "MPATHz WWID0", + 1); + expect_condlog(3, FOUND_ALIAS_STR("MPATHz", "WWID0")); + + alias = get_user_friendly_alias("WWID0", "x", "MPATHz", "MPATH", false); + assert_string_equal(alias, "MPATHz"); + free(alias); +} + +static void gufa_old_match_other(void **state) { + char *alias; + static const char bindings[] = "MPATHz WWID9"; + + will_return(__wrap_open_file, true); + + mock_bindings_file(bindings, 0); + expect_condlog(3, FOUND_ALIAS_STR("MPATHz", "WWID9")); + expect_condlog(0, REUSE_STR("MPATHz", "WWID9")); + + mock_bindings_file(bindings, -1); + expect_condlog(3, NOMATCH_WWID_STR("WWID0")); + mock_unused_alias("MPATHa"); + + mock_allocate_binding("MPATHa", "WWID0"); + + alias = get_user_friendly_alias("WWID0", "x", "MPATHz", "MPATH", false); + assert_string_equal(alias, "MPATHa"); + free(alias); +} + +static void gufa_old_match_other_used(void **state) { + char *alias; + static const char bindings[] = "MPATHz WWID9"; + + will_return(__wrap_open_file, true); + + mock_bindings_file(bindings, 0); + expect_condlog(3, FOUND_ALIAS_STR("MPATHz", "WWID9")); + expect_condlog(0, REUSE_STR("MPATHz", "WWID9")); + + mock_bindings_file(bindings, -1); + mock_used_alias("MPATHa", USED_STR("MPATHa", "WWID0")); + expect_condlog(3, NOMATCH_WWID_STR("WWID0")); + mock_unused_alias("MPATHb"); + + mock_allocate_binding("MPATHb", "WWID0"); + + alias = get_user_friendly_alias("WWID0", "x", "MPATHz", "MPATH", false); + assert_string_equal(alias, "MPATHb"); + free(alias); +} + +static void gufa_old_match_other_wwidmatch(void **state) { + char *alias; + static const char bindings[] = ("MPATHz WWID9\n" + "MPATHc WWID2"); + will_return(__wrap_open_file, true); + + mock_bindings_file(bindings, 0); + expect_condlog(3, FOUND_ALIAS_STR("MPATHz", "WWID9")); + expect_condlog(0, REUSE_STR("MPATHz", "WWID9")); + + mock_bindings_file(bindings, 1); + expect_condlog(3, FOUND_STR("MPATHc", "WWID2")); + mock_unused_alias("MPATHc"); + + alias = get_user_friendly_alias("WWID2", "x", "MPATHz", "MPATH", false); + assert_string_equal(alias, "MPATHc"); + free(alias); +} + +static void gufa_old_match_other_wwidmatch_used(void **state) { + char *alias; + static const char bindings[] = ("MPATHz WWID9\n" + "MPATHc WWID2"); + + will_return(__wrap_open_file, true); + + mock_bindings_file(bindings, 0); + expect_condlog(3, FOUND_ALIAS_STR("MPATHz", "WWID9")); + expect_condlog(0, REUSE_STR("MPATHz", "WWID9")); + + mock_bindings_file(bindings, 1); + expect_condlog(3, FOUND_STR("MPATHc", "WWID2")); + mock_used_alias("MPATHc", USED_STR("MPATHc", "WWID2")); + + alias = get_user_friendly_alias("WWID2", "x", "MPATHz", "MPATH", false); + assert_ptr_equal(alias, NULL); +} + +static void gufa_old_nomatch_wwidmatch(void **state) { + char *alias; + static const char bindings[] = "MPATHa WWID0"; + + will_return(__wrap_open_file, true); + + mock_bindings_file(bindings, -1); + expect_condlog(3, NOMATCH_STR("MPATHz")); + + mock_bindings_file(bindings, 0); + expect_condlog(3, FOUND_STR("MPATHa", "WWID0")); + mock_unused_alias("MPATHa"); + expect_condlog(3, EXISTING_STR("MPATHa", "WWID0")); + + alias = get_user_friendly_alias("WWID0", "x", "MPATHz", "MPATH", false); + assert_string_equal(alias, "MPATHa"); + free(alias); +} + +static void gufa_old_nomatch_wwidmatch_used(void **state) { + char *alias; + static const char bindings[] = "MPATHa WWID0"; + will_return(__wrap_open_file, true); + + mock_bindings_file(bindings, -1); + expect_condlog(3, NOMATCH_STR("MPATHz")); + + mock_bindings_file(bindings, 0); + expect_condlog(3, FOUND_STR("MPATHa", "WWID0")); + mock_used_alias("MPATHa", USED_STR("MPATHa", "WWID0")); + + alias = get_user_friendly_alias("WWID0", "x", "MPATHz", "MPATH", false); + assert_ptr_equal(alias, NULL); +} + +static void gufa_old_nomatch_nowwidmatch(void **state) { + char *alias; + static const char bindings[] = "MPATHb WWID1"; + + will_return(__wrap_open_file, true); + + mock_bindings_file(bindings, -1); + expect_condlog(3, NOMATCH_STR("MPATHz")); + + mock_bindings_file(bindings, -1); + expect_condlog(3, NOMATCH_WWID_STR("WWID0")); + + mock_allocate_binding("MPATHz", "WWID0"); + expect_condlog(2, ALLOC_STR("MPATHz", "WWID0")); + + alias = get_user_friendly_alias("WWID0", "x", "MPATHz", "MPATH", false); + assert_string_equal(alias, "MPATHz"); + free(alias); +} + +static int test_get_user_friendly_alias() +{ + const struct CMUnitTest tests[] = { + cmocka_unit_test(gufa_empty_new_rw), + cmocka_unit_test(gufa_empty_new_ro_1), + cmocka_unit_test(gufa_empty_new_ro_2), + cmocka_unit_test(gufa_match_a_unused), + cmocka_unit_test(gufa_match_a_self), + cmocka_unit_test(gufa_match_a_used), + cmocka_unit_test(gufa_nomatch_a_c), + cmocka_unit_test(gufa_nomatch_c_a), + cmocka_unit_test(gufa_nomatch_c_b), + cmocka_unit_test(gufa_nomatch_c_b_used), + cmocka_unit_test(gufa_nomatch_b_f_a), + cmocka_unit_test(gufa_old_empty), + cmocka_unit_test(gufa_old_match), + cmocka_unit_test(gufa_old_match_other), + cmocka_unit_test(gufa_old_match_other_used), + cmocka_unit_test(gufa_old_match_other_wwidmatch), + cmocka_unit_test(gufa_old_match_other_wwidmatch_used), + cmocka_unit_test(gufa_old_nomatch_wwidmatch), + cmocka_unit_test(gufa_old_nomatch_wwidmatch_used), + cmocka_unit_test(gufa_old_nomatch_nowwidmatch), + }; + + return cmocka_run_group_tests(tests, NULL, NULL); +} + int main(void) { int ret = 0; @@ -1157,6 +1596,8 @@ int main(void) ret += test_lookup_binding(); ret += test_rlookup_binding(); ret += test_allocate_binding(); + ret += test_allocate_binding(); + ret += test_get_user_friendly_alias(); return ret; } From patchwork Mon Sep 11 16:38:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13379484 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D4209EE57DF for ; Mon, 11 Sep 2023 16:39:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694450371; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=5rSyM40fPUjiNwK17h4GLuW3m/zO/oypEBQwepguco8=; b=LvYNM7/XIc3UH21tToB2Fv7yYgTiuhsHk2M5Ceh/4kncDBqGP1DYCgSbcRx37fmwfg/qYV +HZIH1b7/ARJJzr5KpwkkblFEXTXN6Nq59k8Puk/Gvc8yuBipPimwd0otXcZS8YvyNNLOU +iUmAEt0jVO1IQgnRbkltoDYdBYKrfs= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-38-1gra6GjFPsWVxOdN09hUpA-1; Mon, 11 Sep 2023 12:39:25 -0400 X-MC-Unique: 1gra6GjFPsWVxOdN09hUpA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 641661C05ECE; Mon, 11 Sep 2023 16:39:21 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4FBF02156702; Mon, 11 Sep 2023 16:39:21 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id C74A419465A4; Mon, 11 Sep 2023 16:39:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 2340D19465A3 for ; Mon, 11 Sep 2023 16:39:20 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 020ED568FF; Mon, 11 Sep 2023 16:39:20 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast08.extmail.prod.ext.rdu2.redhat.com [10.11.55.24]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EDC0E4404C for ; Mon, 11 Sep 2023 16:39:19 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-inbound-delivery-1.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C840E38117E6 for ; Mon, 11 Sep 2023 16:39:19 +0000 (UTC) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-620-BpDAypoWMGGNhWykVMF6QQ-1; Mon, 11 Sep 2023 12:39:18 -0400 X-MC-Unique: BpDAypoWMGGNhWykVMF6QQ-1 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 96F8A21882; Mon, 11 Sep 2023 16:39:16 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 67F1513AD1; Mon, 11 Sep 2023 16:39:16 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id EAC1F7RC/2RzEAAAMHmgww (envelope-from ); Mon, 11 Sep 2023 16:39:16 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Mon, 11 Sep 2023 18:38:17 +0200 Message-ID: <20230911163846.27197-9-mwilck@suse.com> In-Reply-To: <20230911163846.27197-1-mwilck@suse.com> References: <20230911163846.27197-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Subject: [dm-devel] [PATCH v2 08/37] multipath-tools test: consistent use of macros in alias test X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dm-devel@redhat.com, Martin Wilck Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: suse.com From: Martin Wilck Use the macros introduced with the tests for get_user_friendly_alias() also in the previously existing tests. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- tests/alias.c | 80 ++++++++++++++++++++++++--------------------------- 1 file changed, 38 insertions(+), 42 deletions(-) diff --git a/tests/alias.c b/tests/alias.c index 7e443b0..427b281 100644 --- a/tests/alias.c +++ b/tests/alias.c @@ -490,7 +490,7 @@ static void lb_empty(void **state) char *alias; will_return(__wrap_fgets, NULL); - expect_condlog(3, "No matching wwid [WWID0] in bindings file.\n"); + expect_condlog(3, NOMATCH_WWID_STR("WWID0")); rc = lookup_binding(NULL, "WWID0", &alias, NULL, 0); assert_int_equal(rc, 1); assert_ptr_equal(alias, NULL); @@ -503,7 +503,7 @@ static void lb_empty_unused(void **state) will_return(__wrap_fgets, NULL); mock_unused_alias("MPATHa"); - expect_condlog(3, "No matching wwid [WWID0] in bindings file.\n"); + expect_condlog(3, NOMATCH_WWID_STR("WWID0")); rc = lookup_binding(NULL, "WWID0", &alias, "MPATH", 1); assert_int_equal(rc, 1); assert_ptr_equal(alias, NULL); @@ -518,7 +518,7 @@ static void lb_empty_failed(void **state) will_return(__wrap_fgets, NULL); mock_failed_alias("MPATHa", USED_STR("MPATHa", "WWID0")); mock_unused_alias("MPATHb"); - expect_condlog(3, "No matching wwid [WWID0] in bindings file.\n"); + expect_condlog(3, NOMATCH_WWID_STR("WWID0")); rc = lookup_binding(NULL, "WWID0", &alias, "MPATH", 1); assert_int_equal(rc, 2); assert_ptr_equal(alias, NULL); @@ -533,7 +533,7 @@ static void lb_empty_1_used(void **state) will_return(__wrap_fgets, NULL); mock_used_alias("MPATHa", USED_STR("MPATHa", "WWID0")); mock_unused_alias("MPATHb"); - expect_condlog(3, "No matching wwid [WWID0] in bindings file.\n"); + expect_condlog(3, NOMATCH_WWID_STR("WWID0")); rc = lookup_binding(NULL, "WWID0", &alias, "MPATH", 1); assert_int_equal(rc, 2); assert_ptr_equal(alias, NULL); @@ -548,7 +548,7 @@ static void lb_empty_1_used_self(void **state) will_return(__wrap_fgets, NULL); mock_used_alias("MPATHa", USED_STR("MPATHa", "WWID0")); mock_self_alias("MPATHb", "WWID0"); - expect_condlog(3, "No matching wwid [WWID0] in bindings file.\n"); + expect_condlog(3, NOMATCH_WWID_STR("WWID0")); rc = lookup_binding(NULL, "WWID0", &alias, "MPATH", 1); assert_int_equal(rc, 2); assert_ptr_equal(alias, NULL); @@ -561,8 +561,7 @@ static void lb_match_a(void **state) char *alias; will_return(__wrap_fgets, "MPATHa WWID0\n"); - expect_condlog(3, "Found matching wwid [WWID0] in bindings file." - " Setting alias to MPATHa\n"); + expect_condlog(3, FOUND_STR("MPATHa", "WWID0")); rc = lookup_binding(NULL, "WWID0", &alias, "MPATH", 0); assert_int_equal(rc, 0); assert_ptr_not_equal(alias, NULL); @@ -577,7 +576,7 @@ static void lb_nomatch_a(void **state) will_return(__wrap_fgets, "MPATHa WWID0\n"); will_return(__wrap_fgets, NULL); - expect_condlog(3, "No matching wwid [WWID1] in bindings file.\n"); + expect_condlog(3, NOMATCH_WWID_STR("WWID1")); rc = lookup_binding(NULL, "WWID1", &alias, "MPATH", 0); assert_int_equal(rc, 2); assert_ptr_equal(alias, NULL); @@ -590,7 +589,7 @@ static void lb_nomatch_a_bad_check(void **state) will_return(__wrap_fgets, "MPATHa WWID0\n"); will_return(__wrap_fgets, NULL); - expect_condlog(0, "no more available user_friendly_names\n"); + expect_condlog(0, NOMORE_STR); rc = lookup_binding(NULL, "WWID1", &alias, NULL, 1); assert_int_equal(rc, -1); assert_ptr_equal(alias, NULL); @@ -604,7 +603,7 @@ static void lb_nomatch_a_unused(void **state) will_return(__wrap_fgets, "MPATHa WWID0\n"); will_return(__wrap_fgets, NULL); mock_unused_alias("MPATHb"); - expect_condlog(3, "No matching wwid [WWID1] in bindings file.\n"); + expect_condlog(3, NOMATCH_WWID_STR("WWID1")); rc = lookup_binding(NULL, "WWID1", &alias, "MPATH", 1); assert_int_equal(rc, 2); assert_ptr_equal(alias, NULL); @@ -622,7 +621,7 @@ static void lb_nomatch_a_3_used_failed_self(void **state) mock_used_alias("MPATHd", USED_STR("MPATHd", "WWID1")); mock_failed_alias("MPATHe", USED_STR("MPATHe", "WWID1")); mock_self_alias("MPATHf", "WWID1"); - expect_condlog(3, "No matching wwid [WWID1] in bindings file.\n"); + expect_condlog(3, NOMATCH_WWID_STR("WWID1")); rc = lookup_binding(NULL, "WWID1", &alias, "MPATH", 1); assert_int_equal(rc, 6); assert_ptr_equal(alias, NULL); @@ -635,8 +634,7 @@ static void do_lb_match_c(void **state, int check_if_taken) will_return(__wrap_fgets, "MPATHa WWID0\n"); will_return(__wrap_fgets, "MPATHc WWID1\n"); - expect_condlog(3, "Found matching wwid [WWID1] in bindings file." - " Setting alias to MPATHc\n"); + expect_condlog(3, FOUND_STR("MPATHc", "WWID1")); rc = lookup_binding(NULL, "WWID1", &alias, "MPATH", check_if_taken); assert_int_equal(rc, 0); assert_ptr_not_equal(alias, NULL); @@ -662,7 +660,7 @@ static void lb_nomatch_a_c(void **state) will_return(__wrap_fgets, "MPATHa WWID0\n"); will_return(__wrap_fgets, "MPATHc WWID1\n"); will_return(__wrap_fgets, NULL); - expect_condlog(3, "No matching wwid [WWID2] in bindings file.\n"); + expect_condlog(3, NOMATCH_WWID_STR("WWID2")); rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 0); assert_int_equal(rc, 2); assert_ptr_equal(alias, NULL); @@ -677,7 +675,7 @@ static void lb_nomatch_a_d_unused(void **state) will_return(__wrap_fgets, "MPATHd WWID1\n"); will_return(__wrap_fgets, NULL); mock_unused_alias("MPATHb"); - expect_condlog(3, "No matching wwid [WWID2] in bindings file.\n"); + expect_condlog(3, NOMATCH_WWID_STR("WWID2")); rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 1); assert_int_equal(rc, 2); assert_ptr_equal(alias, NULL); @@ -693,7 +691,7 @@ static void lb_nomatch_a_d_1_used(void **state) will_return(__wrap_fgets, NULL); mock_used_alias("MPATHb", USED_STR("MPATHb", "WWID2")); mock_unused_alias("MPATHc"); - expect_condlog(3, "No matching wwid [WWID2] in bindings file.\n"); + expect_condlog(3, NOMATCH_WWID_STR("WWID2")); rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 1); assert_int_equal(rc, 3); assert_ptr_equal(alias, NULL); @@ -710,7 +708,7 @@ static void lb_nomatch_a_d_2_used(void **state) mock_used_alias("MPATHb", USED_STR("MPATHb", "WWID2")); mock_used_alias("MPATHc", USED_STR("MPATHc", "WWID2")); mock_unused_alias("MPATHe"); - expect_condlog(3, "No matching wwid [WWID2] in bindings file.\n"); + expect_condlog(3, NOMATCH_WWID_STR("WWID2")); rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 1); assert_int_equal(rc, 5); assert_ptr_equal(alias, NULL); @@ -728,7 +726,7 @@ static void lb_nomatch_a_d_3_used(void **state) mock_used_alias("MPATHc", USED_STR("MPATHc", "WWID2")); mock_used_alias("MPATHe", USED_STR("MPATHe", "WWID2")); mock_unused_alias("MPATHf"); - expect_condlog(3, "No matching wwid [WWID2] in bindings file.\n"); + expect_condlog(3, NOMATCH_WWID_STR("WWID2")); rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 1); assert_int_equal(rc, 6); assert_ptr_equal(alias, NULL); @@ -742,7 +740,7 @@ static void lb_nomatch_c_a(void **state) will_return(__wrap_fgets, "MPATHc WWID1\n"); will_return(__wrap_fgets, "MPATHa WWID0\n"); will_return(__wrap_fgets, NULL); - expect_condlog(3, "No matching wwid [WWID2] in bindings file.\n"); + expect_condlog(3, NOMATCH_WWID_STR("WWID2")); rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 0); assert_int_equal(rc, 2); assert_ptr_equal(alias, NULL); @@ -758,7 +756,7 @@ static void lb_nomatch_d_a_unused(void **state) will_return(__wrap_fgets, "MPATHd WWID0\n"); will_return(__wrap_fgets, NULL); mock_unused_alias("MPATHb"); - expect_condlog(3, "No matching wwid [WWID2] in bindings file.\n"); + expect_condlog(3, NOMATCH_WWID_STR("WWID2")); rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 1); assert_int_equal(rc, 2); assert_ptr_equal(alias, NULL); @@ -775,7 +773,7 @@ static void lb_nomatch_d_a_1_used(void **state) will_return(__wrap_fgets, NULL); mock_used_alias("MPATHb", USED_STR("MPATHb", "WWID2")); mock_unused_alias("MPATHe"); - expect_condlog(3, "No matching wwid [WWID2] in bindings file.\n"); + expect_condlog(3, NOMATCH_WWID_STR("WWID2")); rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 1); assert_int_equal(rc, 5); assert_ptr_equal(alias, NULL); @@ -790,7 +788,7 @@ static void lb_nomatch_a_b(void **state) will_return(__wrap_fgets, "MPATHz WWID26\n"); will_return(__wrap_fgets, "MPATHb WWID1\n"); will_return(__wrap_fgets, NULL); - expect_condlog(3, "No matching wwid [WWID2] in bindings file.\n"); + expect_condlog(3, NOMATCH_WWID_STR("WWID2")); rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 0); assert_int_equal(rc, 3); assert_ptr_equal(alias, NULL); @@ -806,7 +804,7 @@ static void lb_nomatch_a_b_bad(void **state) will_return(__wrap_fgets, "MPATHb\n"); will_return(__wrap_fgets, NULL); expect_condlog(3, "Ignoring malformed line 3 in bindings file\n"); - expect_condlog(3, "No matching wwid [WWID2] in bindings file.\n"); + expect_condlog(3, NOMATCH_WWID_STR("WWID2")); rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 0); assert_int_equal(rc, 3); assert_ptr_equal(alias, NULL); @@ -823,7 +821,7 @@ static void lb_nomatch_a_b_bad_self(void **state) will_return(__wrap_fgets, NULL); expect_condlog(3, "Ignoring malformed line 3 in bindings file\n"); mock_self_alias("MPATHc", "WWID2"); - expect_condlog(3, "No matching wwid [WWID2] in bindings file.\n"); + expect_condlog(3, NOMATCH_WWID_STR("WWID2")); rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 1); assert_int_equal(rc, 3); assert_ptr_equal(alias, NULL); @@ -838,7 +836,7 @@ static void lb_nomatch_b_a(void **state) will_return(__wrap_fgets, "MPATHz WWID26\n"); will_return(__wrap_fgets, "MPATHa WWID0\n"); will_return(__wrap_fgets, NULL); - expect_condlog(3, "No matching wwid [WWID2] in bindings file.\n"); + expect_condlog(3, NOMATCH_WWID_STR("WWID2")); rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 0); assert_int_equal(rc, 27); assert_ptr_equal(alias, NULL); @@ -857,7 +855,7 @@ static void lb_nomatch_b_a_3_used(void **state) mock_used_alias("MPATHab", USED_STR("MPATHab", "WWID2")); mock_used_alias("MPATHac", USED_STR("MPATHac", "WWID2")); mock_unused_alias("MPATHad"); - expect_condlog(3, "No matching wwid [WWID2] in bindings file.\n"); + expect_condlog(3, NOMATCH_WWID_STR("WWID2")); rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 1); assert_int_equal(rc, 30); assert_ptr_equal(alias, NULL); @@ -873,7 +871,7 @@ static void do_lb_nomatch_int_max(void **state, int check_if_taken) will_return(__wrap_fgets, "MPATH" MPATH_ID_INT_MAX " WWIDMAX\n"); will_return(__wrap_fgets, "MPATHa WWID0\n"); will_return(__wrap_fgets, NULL); - expect_condlog(0, "no more available user_friendly_names\n"); + expect_condlog(0, NOMORE_STR); rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", check_if_taken); assert_int_equal(rc, -1); assert_ptr_equal(alias, NULL); @@ -898,7 +896,7 @@ static void lb_nomatch_int_max_used(void **state) will_return(__wrap_fgets, "MPATH" MPATH_ID_INT_MAX " WWIDMAX\n"); will_return(__wrap_fgets, NULL); mock_used_alias("MPATHa", USED_STR("MPATHa", "WWID2")); - expect_condlog(0, "no more available user_friendly_names\n"); + expect_condlog(0, NOMORE_STR); rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 1); assert_int_equal(rc, -1); assert_ptr_equal(alias, NULL); @@ -913,7 +911,7 @@ static void lb_nomatch_int_max_m1(void **state) will_return(__wrap_fgets, "MPATH" MPATH_ID_INT_MAX_m1 " WWIDMAX\n"); will_return(__wrap_fgets, "MPATHa WWID0\n"); will_return(__wrap_fgets, NULL); - expect_condlog(3, "No matching wwid [WWID2] in bindings file.\n"); + expect_condlog(3, NOMATCH_WWID_STR("WWID2")); rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 0); assert_int_equal(rc, INT_MAX); assert_ptr_equal(alias, NULL); @@ -929,7 +927,7 @@ static void lb_nomatch_int_max_m1_used(void **state) will_return(__wrap_fgets, "MPATHa WWID0\n"); will_return(__wrap_fgets, NULL); mock_used_alias("MPATH" MPATH_ID_INT_MAX, USED_STR("MPATH" MPATH_ID_INT_MAX, "WWID2")); - expect_condlog(0, "no more available user_friendly_names\n"); + expect_condlog(0, NOMORE_STR); rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 1); assert_int_equal(rc, -1); assert_ptr_equal(alias, NULL); @@ -945,7 +943,7 @@ static void lb_nomatch_int_max_m1_1_used(void **state) will_return(__wrap_fgets, NULL); mock_used_alias("MPATHa", USED_STR("MPATHa", "WWID2")); mock_unused_alias("MPATH" MPATH_ID_INT_MAX); - expect_condlog(3, "No matching wwid [WWID2] in bindings file.\n"); + expect_condlog(3, NOMATCH_WWID_STR("WWID2")); rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 1); assert_int_equal(rc, INT_MAX); assert_ptr_equal(alias, NULL); @@ -961,7 +959,7 @@ static void lb_nomatch_int_max_m1_2_used(void **state) will_return(__wrap_fgets, NULL); mock_used_alias("MPATHa", USED_STR("MPATHa", "WWID2")); mock_used_alias("MPATH" MPATH_ID_INT_MAX, USED_STR("MPATH" MPATH_ID_INT_MAX, "WWID2")); - expect_condlog(0, "no more available user_friendly_names\n"); + expect_condlog(0, NOMORE_STR); rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 1); assert_int_equal(rc, -1); assert_ptr_equal(alias, NULL); @@ -1017,7 +1015,7 @@ static void rl_empty(void **state) buf[0] = '\0'; will_return(__wrap_fgets, NULL); - expect_condlog(3, "No matching alias [MPATHa] in bindings file.\n"); + expect_condlog(3, NOMATCH_STR("MPATHa")); rc = rlookup_binding(NULL, buf, "MPATHa"); assert_int_equal(rc, -1); assert_string_equal(buf, ""); @@ -1030,8 +1028,7 @@ static void rl_match_a(void **state) buf[0] = '\0'; will_return(__wrap_fgets, "MPATHa WWID0\n"); - expect_condlog(3, "Found matching alias [MPATHa] in bindings file. " - "Setting wwid to WWID0\n"); + expect_condlog(3, FOUND_ALIAS_STR("MPATHa", "WWID0")); rc = rlookup_binding(NULL, buf, "MPATHa"); assert_int_equal(rc, 0); assert_string_equal(buf, "WWID0"); @@ -1045,7 +1042,7 @@ static void rl_nomatch_a(void **state) buf[0] = '\0'; will_return(__wrap_fgets, "MPATHa WWID0\n"); will_return(__wrap_fgets, NULL); - expect_condlog(3, "No matching alias [MPATHb] in bindings file.\n"); + expect_condlog(3, NOMATCH_STR("MPATHb")); rc = rlookup_binding(NULL, buf, "MPATHb"); assert_int_equal(rc, -1); assert_string_equal(buf, ""); @@ -1060,7 +1057,7 @@ static void rl_malformed_a(void **state) will_return(__wrap_fgets, "MPATHa \n"); will_return(__wrap_fgets, NULL); expect_condlog(3, "Ignoring malformed line 1 in bindings file\n"); - expect_condlog(3, "No matching alias [MPATHa] in bindings file.\n"); + expect_condlog(3, NOMATCH_STR("MPATHa")); rc = rlookup_binding(NULL, buf, "MPATHa"); assert_int_equal(rc, -1); assert_string_equal(buf, ""); @@ -1080,7 +1077,7 @@ static void rl_overlong_a(void **state) will_return(__wrap_fgets, line); will_return(__wrap_fgets, NULL); expect_condlog(3, "Ignoring too large wwid at 1 in bindings file\n"); - expect_condlog(3, "No matching alias [MPATHa] in bindings file.\n"); + expect_condlog(3, NOMATCH_STR("MPATHa")); rc = rlookup_binding(NULL, buf, "MPATHa"); assert_int_equal(rc, -1); assert_string_equal(buf, ""); @@ -1095,8 +1092,7 @@ static void rl_match_b(void **state) will_return(__wrap_fgets, "MPATHa WWID0\n"); will_return(__wrap_fgets, "MPATHz WWID26\n"); will_return(__wrap_fgets, "MPATHb WWID2\n"); - expect_condlog(3, "Found matching alias [MPATHb] in bindings file. " - "Setting wwid to WWID2\n"); + expect_condlog(3, FOUND_ALIAS_STR("MPATHb", "WWID2")); rc = rlookup_binding(NULL, buf, "MPATHb"); assert_int_equal(rc, 0); assert_string_equal(buf, "WWID2"); @@ -1125,7 +1121,7 @@ static void al_a(void **state) expect_value(__wrap_write, count, strlen(ln)); expect_string(__wrap_write, buf, ln); will_return(__wrap_write, strlen(ln)); - expect_condlog(3, "Created new binding [MPATHa] for WWID [WWIDa]\n"); + expect_condlog(3, NEW_STR("MPATHa", "WWIDa")); alias = allocate_binding(0, "WWIDa", 1, "MPATH"); assert_ptr_not_equal(alias, NULL); @@ -1142,7 +1138,7 @@ static void al_zz(void **state) expect_value(__wrap_write, count, strlen(ln)); expect_string(__wrap_write, buf, ln); will_return(__wrap_write, strlen(ln)); - expect_condlog(3, "Created new binding [MPATHzz] for WWID [WWIDzz]\n"); + expect_condlog(3, NEW_STR("MPATHzz", "WWIDzz")); alias = allocate_binding(0, "WWIDzz", 26*26 + 26, "MPATH"); assert_ptr_not_equal(alias, NULL); From patchwork Mon Sep 11 16:38:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13379490 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CEA73EEB58C for ; Mon, 11 Sep 2023 16:39:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694450373; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=TIM6poLFIdYWvG/RRdv1jXPix8RyUDQYKD5JyFaMtyU=; b=hVvNJpPa0YUAL6yYSvDytrsLOWf7Xd6K7e1ZX7avz4gFNnwmu7k40OiYFKng6P1kYwtx18 ulkj7wF3od4hF3v8S4mFZWyZGjOIIrO5+kc5B0XMc+KYIgGwfh6ROUZzhojmmYV97zk0hi VCi9cymFj06omhPGBZXbYvSWIfSm6QU= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-665-4b9SrG59OduduYD6fkyojQ-1; Mon, 11 Sep 2023 12:39:31 -0400 X-MC-Unique: 4b9SrG59OduduYD6fkyojQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 31BD3101FAA4; Mon, 11 Sep 2023 16:39:22 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 18D9020235BE; Mon, 11 Sep 2023 16:39:22 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id BB18D1946A44; Mon, 11 Sep 2023 16:39:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 37B9619465A4 for ; Mon, 11 Sep 2023 16:39:20 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 2A7FB21B2413; Mon, 11 Sep 2023 16:39:20 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 237FE21B2414 for ; Mon, 11 Sep 2023 16:39:20 +0000 (UTC) Received: from us-smtp-inbound-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0431C181A6E6 for ; Mon, 11 Sep 2023 16:39:20 +0000 (UTC) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-250-6jqm7lbzPY-HYAE33eVG3Q-1; Mon, 11 Sep 2023 12:39:18 -0400 X-MC-Unique: 6jqm7lbzPY-HYAE33eVG3Q-1 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id DB3541F8BB; Mon, 11 Sep 2023 16:39:16 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id A508E139CC; Mon, 11 Sep 2023 16:39:16 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id MHuSJrRC/2RzEAAAMHmgww (envelope-from ); Mon, 11 Sep 2023 16:39:16 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Mon, 11 Sep 2023 18:38:18 +0200 Message-ID: <20230911163846.27197-10-mwilck@suse.com> In-Reply-To: <20230911163846.27197-1-mwilck@suse.com> References: <20230911163846.27197-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Subject: [dm-devel] [PATCH v2 09/37] multipath-tools tests: convert mock_{failed, used}_alias to macros X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dm-devel@redhat.com, Martin Wilck Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: suse.com From: Martin Wilck This way we can further improve readability of the individual test cases. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- tests/alias.c | 92 +++++++++++++++++++++++++-------------------------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/tests/alias.c b/tests/alias.c index 427b281..a32b43e 100644 --- a/tests/alias.c +++ b/tests/alias.c @@ -445,26 +445,26 @@ static void mock_self_alias(const char *alias, const char *wwid) #define REUSE_STR(alias_str, wwid_str) ("alias " alias_str " already bound to wwid " wwid_str ", cannot reuse\n") #define NOMORE_STR "no more available user_friendly_names\n" -static void mock_failed_alias(const char *alias, char *msg) -{ - expect_string(__wrap_dm_map_present, str, alias); - will_return(__wrap_dm_map_present, 1); - 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_condlog(3, msg); -} +#define mock_failed_alias(alias, wwid) \ + do { \ + expect_string(__wrap_dm_map_present, str, alias); \ + will_return(__wrap_dm_map_present, 1); \ + 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_condlog(3, USED_STR(alias, wwid)); \ + } while (0) -static void mock_used_alias(const char *alias, char *msg) -{ - expect_string(__wrap_dm_map_present, str, alias); - will_return(__wrap_dm_map_present, 1); - 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_condlog(3, msg); -} +#define mock_used_alias(alias, wwid) \ + do { \ + expect_string(__wrap_dm_map_present, str, alias); \ + will_return(__wrap_dm_map_present, 1); \ + 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_condlog(3, USED_STR(alias, wwid)); \ + } while(0) static void mock_bindings_file(const char *content, int match_line) { @@ -516,7 +516,7 @@ static void lb_empty_failed(void **state) char *alias; will_return(__wrap_fgets, NULL); - mock_failed_alias("MPATHa", USED_STR("MPATHa", "WWID0")); + mock_failed_alias("MPATHa", "WWID0"); mock_unused_alias("MPATHb"); expect_condlog(3, NOMATCH_WWID_STR("WWID0")); rc = lookup_binding(NULL, "WWID0", &alias, "MPATH", 1); @@ -531,7 +531,7 @@ static void lb_empty_1_used(void **state) char *alias; will_return(__wrap_fgets, NULL); - mock_used_alias("MPATHa", USED_STR("MPATHa", "WWID0")); + mock_used_alias("MPATHa", "WWID0"); mock_unused_alias("MPATHb"); expect_condlog(3, NOMATCH_WWID_STR("WWID0")); rc = lookup_binding(NULL, "WWID0", &alias, "MPATH", 1); @@ -546,7 +546,7 @@ static void lb_empty_1_used_self(void **state) char *alias; will_return(__wrap_fgets, NULL); - mock_used_alias("MPATHa", USED_STR("MPATHa", "WWID0")); + mock_used_alias("MPATHa", "WWID0"); mock_self_alias("MPATHb", "WWID0"); expect_condlog(3, NOMATCH_WWID_STR("WWID0")); rc = lookup_binding(NULL, "WWID0", &alias, "MPATH", 1); @@ -616,10 +616,10 @@ static void lb_nomatch_a_3_used_failed_self(void **state) will_return(__wrap_fgets, "MPATHa WWID0\n"); will_return(__wrap_fgets, NULL); - mock_used_alias("MPATHb", USED_STR("MPATHb", "WWID1")); - mock_used_alias("MPATHc", USED_STR("MPATHc", "WWID1")); - mock_used_alias("MPATHd", USED_STR("MPATHd", "WWID1")); - mock_failed_alias("MPATHe", USED_STR("MPATHe", "WWID1")); + mock_used_alias("MPATHb", "WWID1"); + mock_used_alias("MPATHc", "WWID1"); + mock_used_alias("MPATHd", "WWID1"); + mock_failed_alias("MPATHe", "WWID1"); mock_self_alias("MPATHf", "WWID1"); expect_condlog(3, NOMATCH_WWID_STR("WWID1")); rc = lookup_binding(NULL, "WWID1", &alias, "MPATH", 1); @@ -689,7 +689,7 @@ static void lb_nomatch_a_d_1_used(void **state) will_return(__wrap_fgets, "MPATHa WWID0\n"); will_return(__wrap_fgets, "MPATHd WWID1\n"); will_return(__wrap_fgets, NULL); - mock_used_alias("MPATHb", USED_STR("MPATHb", "WWID2")); + mock_used_alias("MPATHb", "WWID2"); mock_unused_alias("MPATHc"); expect_condlog(3, NOMATCH_WWID_STR("WWID2")); rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 1); @@ -705,8 +705,8 @@ static void lb_nomatch_a_d_2_used(void **state) will_return(__wrap_fgets, "MPATHa WWID0\n"); will_return(__wrap_fgets, "MPATHd WWID1\n"); will_return(__wrap_fgets, NULL); - mock_used_alias("MPATHb", USED_STR("MPATHb", "WWID2")); - mock_used_alias("MPATHc", USED_STR("MPATHc", "WWID2")); + mock_used_alias("MPATHb", "WWID2"); + mock_used_alias("MPATHc", "WWID2"); mock_unused_alias("MPATHe"); expect_condlog(3, NOMATCH_WWID_STR("WWID2")); rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 1); @@ -722,9 +722,9 @@ static void lb_nomatch_a_d_3_used(void **state) will_return(__wrap_fgets, "MPATHa WWID0\n"); will_return(__wrap_fgets, "MPATHd WWID1\n"); will_return(__wrap_fgets, NULL); - mock_used_alias("MPATHb", USED_STR("MPATHb", "WWID2")); - mock_used_alias("MPATHc", USED_STR("MPATHc", "WWID2")); - mock_used_alias("MPATHe", USED_STR("MPATHe", "WWID2")); + mock_used_alias("MPATHb", "WWID2"); + mock_used_alias("MPATHc", "WWID2"); + mock_used_alias("MPATHe", "WWID2"); mock_unused_alias("MPATHf"); expect_condlog(3, NOMATCH_WWID_STR("WWID2")); rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 1); @@ -771,7 +771,7 @@ static void lb_nomatch_d_a_1_used(void **state) will_return(__wrap_fgets, "MPATHa WWID0\n"); will_return(__wrap_fgets, "MPATHd WWID0\n"); will_return(__wrap_fgets, NULL); - mock_used_alias("MPATHb", USED_STR("MPATHb", "WWID2")); + mock_used_alias("MPATHb", "WWID2"); mock_unused_alias("MPATHe"); expect_condlog(3, NOMATCH_WWID_STR("WWID2")); rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 1); @@ -851,9 +851,9 @@ static void lb_nomatch_b_a_3_used(void **state) will_return(__wrap_fgets, "MPATHz WWID26\n"); will_return(__wrap_fgets, "MPATHa WWID0\n"); will_return(__wrap_fgets, NULL); - mock_used_alias("MPATHaa", USED_STR("MPATHaa", "WWID2")); - mock_used_alias("MPATHab", USED_STR("MPATHab", "WWID2")); - mock_used_alias("MPATHac", USED_STR("MPATHac", "WWID2")); + mock_used_alias("MPATHaa", "WWID2"); + mock_used_alias("MPATHab", "WWID2"); + mock_used_alias("MPATHac", "WWID2"); mock_unused_alias("MPATHad"); expect_condlog(3, NOMATCH_WWID_STR("WWID2")); rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 1); @@ -895,7 +895,7 @@ static void lb_nomatch_int_max_used(void **state) will_return(__wrap_fgets, "MPATHb WWID1\n"); will_return(__wrap_fgets, "MPATH" MPATH_ID_INT_MAX " WWIDMAX\n"); will_return(__wrap_fgets, NULL); - mock_used_alias("MPATHa", USED_STR("MPATHa", "WWID2")); + mock_used_alias("MPATHa", "WWID2"); expect_condlog(0, NOMORE_STR); rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 1); assert_int_equal(rc, -1); @@ -926,7 +926,7 @@ static void lb_nomatch_int_max_m1_used(void **state) will_return(__wrap_fgets, "MPATH" MPATH_ID_INT_MAX_m1 " WWIDMAX\n"); will_return(__wrap_fgets, "MPATHa WWID0\n"); will_return(__wrap_fgets, NULL); - mock_used_alias("MPATH" MPATH_ID_INT_MAX, USED_STR("MPATH" MPATH_ID_INT_MAX, "WWID2")); + mock_used_alias("MPATH" MPATH_ID_INT_MAX, "WWID2"); expect_condlog(0, NOMORE_STR); rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 1); assert_int_equal(rc, -1); @@ -941,7 +941,7 @@ static void lb_nomatch_int_max_m1_1_used(void **state) will_return(__wrap_fgets, "MPATHb WWID1\n"); will_return(__wrap_fgets, "MPATH" MPATH_ID_INT_MAX_m1 " WWIDMAX\n"); will_return(__wrap_fgets, NULL); - mock_used_alias("MPATHa", USED_STR("MPATHa", "WWID2")); + mock_used_alias("MPATHa", "WWID2"); mock_unused_alias("MPATH" MPATH_ID_INT_MAX); expect_condlog(3, NOMATCH_WWID_STR("WWID2")); rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 1); @@ -957,8 +957,8 @@ static void lb_nomatch_int_max_m1_2_used(void **state) will_return(__wrap_fgets, "MPATHb WWID1\n"); will_return(__wrap_fgets, "MPATH" MPATH_ID_INT_MAX_m1 " WWIDMAX\n"); will_return(__wrap_fgets, NULL); - mock_used_alias("MPATHa", USED_STR("MPATHa", "WWID2")); - mock_used_alias("MPATH" MPATH_ID_INT_MAX, USED_STR("MPATH" MPATH_ID_INT_MAX, "WWID2")); + mock_used_alias("MPATHa", "WWID2"); + mock_used_alias("MPATH" MPATH_ID_INT_MAX, "WWID2"); expect_condlog(0, NOMORE_STR); rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 1); assert_int_equal(rc, -1); @@ -1291,7 +1291,7 @@ static void gufa_match_a_used(void **state) { will_return(__wrap_fgets, BINDING_STR("MPATHa", "WWID0")); expect_condlog(3, FOUND_STR("MPATHa", "WWID0")); - mock_used_alias("MPATHa", USED_STR("MPATHa", "WWID0")); + mock_used_alias("MPATHa", "WWID0"); alias = get_user_friendly_alias("WWID0", "x", "", "MPATH", true); assert_ptr_equal(alias, NULL); @@ -1355,7 +1355,7 @@ static void gufa_nomatch_c_b_used(void **state) { mock_bindings_file("MPATHc WWID2\n" "MPATHb WWID1", -1); - mock_used_alias("MPATHa", USED_STR("MPATHa", "WWID4")); + mock_used_alias("MPATHa", "WWID4"); expect_condlog(3, NOMATCH_WWID_STR("WWID4")); mock_unused_alias("MPATHd"); @@ -1450,7 +1450,7 @@ static void gufa_old_match_other_used(void **state) { expect_condlog(0, REUSE_STR("MPATHz", "WWID9")); mock_bindings_file(bindings, -1); - mock_used_alias("MPATHa", USED_STR("MPATHa", "WWID0")); + mock_used_alias("MPATHa", "WWID0"); expect_condlog(3, NOMATCH_WWID_STR("WWID0")); mock_unused_alias("MPATHb"); @@ -1493,7 +1493,7 @@ static void gufa_old_match_other_wwidmatch_used(void **state) { mock_bindings_file(bindings, 1); expect_condlog(3, FOUND_STR("MPATHc", "WWID2")); - mock_used_alias("MPATHc", USED_STR("MPATHc", "WWID2")); + mock_used_alias("MPATHc", "WWID2"); alias = get_user_friendly_alias("WWID2", "x", "MPATHz", "MPATH", false); assert_ptr_equal(alias, NULL); @@ -1528,7 +1528,7 @@ static void gufa_old_nomatch_wwidmatch_used(void **state) { mock_bindings_file(bindings, 0); expect_condlog(3, FOUND_STR("MPATHa", "WWID0")); - mock_used_alias("MPATHa", USED_STR("MPATHa", "WWID0")); + mock_used_alias("MPATHa", "WWID0"); alias = get_user_friendly_alias("WWID0", "x", "MPATHz", "MPATH", false); assert_ptr_equal(alias, NULL); From patchwork Mon Sep 11 16:38:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13379502 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E580CEEB580 for ; Mon, 11 Sep 2023 16:39:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694450387; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=qoBz7n2ug6mAZ9FqMBF4kHKYMVCaMOaf2Dxapw9p5vo=; b=AB92VH4TEB4rvYiCC1JBoSehvQPFkA+ursFJiJtc5GDGUa5671gPWsLJusEDI8kGjQvfu1 v+gAuEamWGoP7qU6nz/tREinDBvSHCkkrxL9tzeO+SFRwG2FejBYG7R+3xGiKeQMQuLTa2 s9aj7yt9xuWvqP4RMYfh0UvWOYLkZ3k= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-57-Z48T5ZoYMmK-qFMxfy_WhA-1; Mon, 11 Sep 2023 12:39:42 -0400 X-MC-Unique: Z48T5ZoYMmK-qFMxfy_WhA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CEACD945E83; Mon, 11 Sep 2023 16:39:26 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id AFBB2215671F; Mon, 11 Sep 2023 16:39:26 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 68E7519466DF; Mon, 11 Sep 2023 16:39:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 3C2D819465B1 for ; Mon, 11 Sep 2023 16:39:23 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 0FDD640C200C; Mon, 11 Sep 2023 16:39:23 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 074C240C2064 for ; Mon, 11 Sep 2023 16:39:22 +0000 (UTC) Received: from us-smtp-inbound-delivery-1.mimecast.com (us-smtp-inbound-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D41E490F845 for ; Mon, 11 Sep 2023 16:39:22 +0000 (UTC) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-225-zeKbpuJuMruefDfKDdqHFA-1; Mon, 11 Sep 2023 12:39:18 -0400 X-MC-Unique: zeKbpuJuMruefDfKDdqHFA-1 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 2EB681F8C0; Mon, 11 Sep 2023 16:39:17 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id EC4EC139CC; Mon, 11 Sep 2023 16:39:16 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id +BzWN7RC/2RzEAAAMHmgww (envelope-from ); Mon, 11 Sep 2023 16:39:16 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Mon, 11 Sep 2023 18:38:19 +0200 Message-ID: <20230911163846.27197-11-mwilck@suse.com> In-Reply-To: <20230911163846.27197-1-mwilck@suse.com> References: <20230911163846.27197-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Subject: [dm-devel] [PATCH v2 10/37] multipath-tools test: use mock_bindings_file() consistently X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dm-devel@redhat.com, Martin Wilck Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: suse.com From: Martin Wilck Further improve test readablity. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- tests/alias.c | 178 +++++++++++++++++++++----------------------------- 1 file changed, 76 insertions(+), 102 deletions(-) diff --git a/tests/alias.c b/tests/alias.c index a32b43e..f334f92 100644 --- a/tests/alias.c +++ b/tests/alias.c @@ -489,7 +489,7 @@ static void lb_empty(void **state) int rc; char *alias; - will_return(__wrap_fgets, NULL); + mock_bindings_file("", -1); expect_condlog(3, NOMATCH_WWID_STR("WWID0")); rc = lookup_binding(NULL, "WWID0", &alias, NULL, 0); assert_int_equal(rc, 1); @@ -501,7 +501,7 @@ static void lb_empty_unused(void **state) int rc; char *alias; - will_return(__wrap_fgets, NULL); + mock_bindings_file("", -1); mock_unused_alias("MPATHa"); expect_condlog(3, NOMATCH_WWID_STR("WWID0")); rc = lookup_binding(NULL, "WWID0", &alias, "MPATH", 1); @@ -515,7 +515,7 @@ static void lb_empty_failed(void **state) int rc; char *alias; - will_return(__wrap_fgets, NULL); + mock_bindings_file("", -1); mock_failed_alias("MPATHa", "WWID0"); mock_unused_alias("MPATHb"); expect_condlog(3, NOMATCH_WWID_STR("WWID0")); @@ -530,7 +530,7 @@ static void lb_empty_1_used(void **state) int rc; char *alias; - will_return(__wrap_fgets, NULL); + mock_bindings_file("", -1); mock_used_alias("MPATHa", "WWID0"); mock_unused_alias("MPATHb"); expect_condlog(3, NOMATCH_WWID_STR("WWID0")); @@ -545,7 +545,7 @@ static void lb_empty_1_used_self(void **state) int rc; char *alias; - will_return(__wrap_fgets, NULL); + mock_bindings_file("", -1); mock_used_alias("MPATHa", "WWID0"); mock_self_alias("MPATHb", "WWID0"); expect_condlog(3, NOMATCH_WWID_STR("WWID0")); @@ -560,7 +560,7 @@ static void lb_match_a(void **state) int rc; char *alias; - will_return(__wrap_fgets, "MPATHa WWID0\n"); + mock_bindings_file("MPATHa WWID0\n", 0); expect_condlog(3, FOUND_STR("MPATHa", "WWID0")); rc = lookup_binding(NULL, "WWID0", &alias, "MPATH", 0); assert_int_equal(rc, 0); @@ -574,8 +574,7 @@ static void lb_nomatch_a(void **state) int rc; char *alias; - will_return(__wrap_fgets, "MPATHa WWID0\n"); - will_return(__wrap_fgets, NULL); + mock_bindings_file("MPATHa WWID0\n", -1); expect_condlog(3, NOMATCH_WWID_STR("WWID1")); rc = lookup_binding(NULL, "WWID1", &alias, "MPATH", 0); assert_int_equal(rc, 2); @@ -587,8 +586,7 @@ static void lb_nomatch_a_bad_check(void **state) int rc; char *alias; - will_return(__wrap_fgets, "MPATHa WWID0\n"); - will_return(__wrap_fgets, NULL); + mock_bindings_file("MPATHa WWID0\n", -1); expect_condlog(0, NOMORE_STR); rc = lookup_binding(NULL, "WWID1", &alias, NULL, 1); assert_int_equal(rc, -1); @@ -600,8 +598,7 @@ static void lb_nomatch_a_unused(void **state) int rc; char *alias; - will_return(__wrap_fgets, "MPATHa WWID0\n"); - will_return(__wrap_fgets, NULL); + mock_bindings_file("MPATHa WWID0\n", -1); mock_unused_alias("MPATHb"); expect_condlog(3, NOMATCH_WWID_STR("WWID1")); rc = lookup_binding(NULL, "WWID1", &alias, "MPATH", 1); @@ -614,8 +611,7 @@ static void lb_nomatch_a_3_used_failed_self(void **state) int rc; char *alias; - will_return(__wrap_fgets, "MPATHa WWID0\n"); - will_return(__wrap_fgets, NULL); + mock_bindings_file("MPATHa WWID0\n", -1); mock_used_alias("MPATHb", "WWID1"); mock_used_alias("MPATHc", "WWID1"); mock_used_alias("MPATHd", "WWID1"); @@ -632,8 +628,8 @@ static void do_lb_match_c(void **state, int check_if_taken) int rc; char *alias; - will_return(__wrap_fgets, "MPATHa WWID0\n"); - will_return(__wrap_fgets, "MPATHc WWID1\n"); + mock_bindings_file("MPATHa WWID0\n" + "MPATHc WWID1", 1); expect_condlog(3, FOUND_STR("MPATHc", "WWID1")); rc = lookup_binding(NULL, "WWID1", &alias, "MPATH", check_if_taken); assert_int_equal(rc, 0); @@ -657,9 +653,8 @@ static void lb_nomatch_a_c(void **state) int rc; char *alias; - will_return(__wrap_fgets, "MPATHa WWID0\n"); - will_return(__wrap_fgets, "MPATHc WWID1\n"); - will_return(__wrap_fgets, NULL); + mock_bindings_file("MPATHa WWID0\n" + "MPATHc WWID1", -1); expect_condlog(3, NOMATCH_WWID_STR("WWID2")); rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 0); assert_int_equal(rc, 2); @@ -671,9 +666,8 @@ static void lb_nomatch_a_d_unused(void **state) int rc; char *alias; - will_return(__wrap_fgets, "MPATHa WWID0\n"); - will_return(__wrap_fgets, "MPATHd WWID1\n"); - will_return(__wrap_fgets, NULL); + mock_bindings_file("MPATHa WWID0\n" + "MPATHd WWID1", -1); mock_unused_alias("MPATHb"); expect_condlog(3, NOMATCH_WWID_STR("WWID2")); rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 1); @@ -686,9 +680,8 @@ static void lb_nomatch_a_d_1_used(void **state) int rc; char *alias; - will_return(__wrap_fgets, "MPATHa WWID0\n"); - will_return(__wrap_fgets, "MPATHd WWID1\n"); - will_return(__wrap_fgets, NULL); + mock_bindings_file("MPATHa WWID0\n" + "MPATHd WWID1", -1); mock_used_alias("MPATHb", "WWID2"); mock_unused_alias("MPATHc"); expect_condlog(3, NOMATCH_WWID_STR("WWID2")); @@ -702,9 +695,8 @@ static void lb_nomatch_a_d_2_used(void **state) int rc; char *alias; - will_return(__wrap_fgets, "MPATHa WWID0\n"); - will_return(__wrap_fgets, "MPATHd WWID1\n"); - will_return(__wrap_fgets, NULL); + mock_bindings_file("MPATHa WWID0\n" + "MPATHd WWID1", -1); mock_used_alias("MPATHb", "WWID2"); mock_used_alias("MPATHc", "WWID2"); mock_unused_alias("MPATHe"); @@ -719,9 +711,8 @@ static void lb_nomatch_a_d_3_used(void **state) int rc; char *alias; - will_return(__wrap_fgets, "MPATHa WWID0\n"); - will_return(__wrap_fgets, "MPATHd WWID1\n"); - will_return(__wrap_fgets, NULL); + mock_bindings_file("MPATHa WWID0\n" + "MPATHd WWID1", -1); mock_used_alias("MPATHb", "WWID2"); mock_used_alias("MPATHc", "WWID2"); mock_used_alias("MPATHe", "WWID2"); @@ -737,9 +728,8 @@ static void lb_nomatch_c_a(void **state) int rc; char *alias; - will_return(__wrap_fgets, "MPATHc WWID1\n"); - will_return(__wrap_fgets, "MPATHa WWID0\n"); - will_return(__wrap_fgets, NULL); + mock_bindings_file("MPATHc WWID1\n" + "MPATHa WWID0\n", -1); expect_condlog(3, NOMATCH_WWID_STR("WWID2")); rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 0); assert_int_equal(rc, 2); @@ -751,10 +741,9 @@ static void lb_nomatch_d_a_unused(void **state) int rc; char *alias; - will_return(__wrap_fgets, "MPATHc WWID1\n"); - will_return(__wrap_fgets, "MPATHa WWID0\n"); - will_return(__wrap_fgets, "MPATHd WWID0\n"); - will_return(__wrap_fgets, NULL); + mock_bindings_file("MPATHc WWID1\n" + "MPATHa WWID0\n" + "MPATHd WWID0\n", -1); mock_unused_alias("MPATHb"); expect_condlog(3, NOMATCH_WWID_STR("WWID2")); rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 1); @@ -767,10 +756,9 @@ static void lb_nomatch_d_a_1_used(void **state) int rc; char *alias; - will_return(__wrap_fgets, "MPATHc WWID1\n"); - will_return(__wrap_fgets, "MPATHa WWID0\n"); - will_return(__wrap_fgets, "MPATHd WWID0\n"); - will_return(__wrap_fgets, NULL); + mock_bindings_file("MPATHc WWID1\n" + "MPATHa WWID0\n" + "MPATHd WWID0\n", -1); mock_used_alias("MPATHb", "WWID2"); mock_unused_alias("MPATHe"); expect_condlog(3, NOMATCH_WWID_STR("WWID2")); @@ -784,10 +772,9 @@ static void lb_nomatch_a_b(void **state) int rc; char *alias; - will_return(__wrap_fgets, "MPATHa WWID0\n"); - will_return(__wrap_fgets, "MPATHz WWID26\n"); - will_return(__wrap_fgets, "MPATHb WWID1\n"); - will_return(__wrap_fgets, NULL); + mock_bindings_file("MPATHa WWID0\n" + "MPATHz WWID26\n" + "MPATHb WWID1\n", -1); expect_condlog(3, NOMATCH_WWID_STR("WWID2")); rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 0); assert_int_equal(rc, 3); @@ -799,10 +786,9 @@ static void lb_nomatch_a_b_bad(void **state) int rc; char *alias; - will_return(__wrap_fgets, "MPATHa WWID0\n"); - will_return(__wrap_fgets, "MPATHz WWID26\n"); - will_return(__wrap_fgets, "MPATHb\n"); - will_return(__wrap_fgets, NULL); + mock_bindings_file("MPATHa WWID0\n" + "MPATHz WWID26\n" + "MPATHb\n", -1); expect_condlog(3, "Ignoring malformed line 3 in bindings file\n"); expect_condlog(3, NOMATCH_WWID_STR("WWID2")); rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 0); @@ -815,10 +801,9 @@ static void lb_nomatch_a_b_bad_self(void **state) int rc; char *alias; - will_return(__wrap_fgets, "MPATHa WWID0\n"); - will_return(__wrap_fgets, "MPATHz WWID26\n"); - will_return(__wrap_fgets, "MPATHb\n"); - will_return(__wrap_fgets, NULL); + mock_bindings_file("MPATHa WWID0\n" + "MPATHz WWID26\n" + "MPATHb\n", -1); expect_condlog(3, "Ignoring malformed line 3 in bindings file\n"); mock_self_alias("MPATHc", "WWID2"); expect_condlog(3, NOMATCH_WWID_STR("WWID2")); @@ -832,10 +817,9 @@ static void lb_nomatch_b_a(void **state) int rc; char *alias; - will_return(__wrap_fgets, "MPATHb WWID1\n"); - will_return(__wrap_fgets, "MPATHz WWID26\n"); - will_return(__wrap_fgets, "MPATHa WWID0\n"); - will_return(__wrap_fgets, NULL); + mock_bindings_file("MPATHb WWID1\n" + "MPATHz WWID26\n" + "MPATHa WWID0\n", -1); expect_condlog(3, NOMATCH_WWID_STR("WWID2")); rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 0); assert_int_equal(rc, 27); @@ -847,10 +831,9 @@ static void lb_nomatch_b_a_3_used(void **state) int rc; char *alias; - will_return(__wrap_fgets, "MPATHb WWID1\n"); - will_return(__wrap_fgets, "MPATHz WWID26\n"); - will_return(__wrap_fgets, "MPATHa WWID0\n"); - will_return(__wrap_fgets, NULL); + mock_bindings_file("MPATHb WWID1\n" + "MPATHz WWID26\n" + "MPATHa WWID0\n", -1); mock_used_alias("MPATHaa", "WWID2"); mock_used_alias("MPATHab", "WWID2"); mock_used_alias("MPATHac", "WWID2"); @@ -867,10 +850,9 @@ static void do_lb_nomatch_int_max(void **state, int check_if_taken) int rc; char *alias; - will_return(__wrap_fgets, "MPATHb WWID1\n"); - will_return(__wrap_fgets, "MPATH" MPATH_ID_INT_MAX " WWIDMAX\n"); - will_return(__wrap_fgets, "MPATHa WWID0\n"); - will_return(__wrap_fgets, NULL); + mock_bindings_file("MPATHb WWID1\n" + "MPATH" MPATH_ID_INT_MAX " WWIDMAX\n" + "MPATHa WWID0\n", -1); expect_condlog(0, NOMORE_STR); rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", check_if_taken); assert_int_equal(rc, -1); @@ -892,9 +874,8 @@ static void lb_nomatch_int_max_used(void **state) int rc; char *alias; - will_return(__wrap_fgets, "MPATHb WWID1\n"); - will_return(__wrap_fgets, "MPATH" MPATH_ID_INT_MAX " WWIDMAX\n"); - will_return(__wrap_fgets, NULL); + mock_bindings_file("MPATHb WWID1\n" + "MPATH" MPATH_ID_INT_MAX " WWIDMAX\n", -1); mock_used_alias("MPATHa", "WWID2"); expect_condlog(0, NOMORE_STR); rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 1); @@ -907,10 +888,9 @@ static void lb_nomatch_int_max_m1(void **state) int rc; char *alias; - will_return(__wrap_fgets, "MPATHb WWID1\n"); - will_return(__wrap_fgets, "MPATH" MPATH_ID_INT_MAX_m1 " WWIDMAX\n"); - will_return(__wrap_fgets, "MPATHa WWID0\n"); - will_return(__wrap_fgets, NULL); + mock_bindings_file("MPATHb WWID1\n" + "MPATH" MPATH_ID_INT_MAX_m1 " WWIDMAX\n" + "MPATHa WWID0\n", -1); expect_condlog(3, NOMATCH_WWID_STR("WWID2")); rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 0); assert_int_equal(rc, INT_MAX); @@ -922,10 +902,9 @@ static void lb_nomatch_int_max_m1_used(void **state) int rc; char *alias; - will_return(__wrap_fgets, "MPATHb WWID1\n"); - will_return(__wrap_fgets, "MPATH" MPATH_ID_INT_MAX_m1 " WWIDMAX\n"); - will_return(__wrap_fgets, "MPATHa WWID0\n"); - will_return(__wrap_fgets, NULL); + mock_bindings_file("MPATHb WWID1\n" + "MPATH" MPATH_ID_INT_MAX_m1 " WWIDMAX\n" + "MPATHa WWID0\n", -1); mock_used_alias("MPATH" MPATH_ID_INT_MAX, "WWID2"); expect_condlog(0, NOMORE_STR); rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 1); @@ -938,9 +917,8 @@ static void lb_nomatch_int_max_m1_1_used(void **state) int rc; char *alias; - will_return(__wrap_fgets, "MPATHb WWID1\n"); - will_return(__wrap_fgets, "MPATH" MPATH_ID_INT_MAX_m1 " WWIDMAX\n"); - will_return(__wrap_fgets, NULL); + mock_bindings_file("MPATHb WWID1\n" + "MPATH" MPATH_ID_INT_MAX_m1 " WWIDMAX\n", -1); mock_used_alias("MPATHa", "WWID2"); mock_unused_alias("MPATH" MPATH_ID_INT_MAX); expect_condlog(3, NOMATCH_WWID_STR("WWID2")); @@ -954,9 +932,8 @@ static void lb_nomatch_int_max_m1_2_used(void **state) int rc; char *alias; - will_return(__wrap_fgets, "MPATHb WWID1\n"); - will_return(__wrap_fgets, "MPATH" MPATH_ID_INT_MAX_m1 " WWIDMAX\n"); - will_return(__wrap_fgets, NULL); + mock_bindings_file("MPATHb WWID1\n" + "MPATH" MPATH_ID_INT_MAX_m1 " WWIDMAX\n", -1); mock_used_alias("MPATHa", "WWID2"); mock_used_alias("MPATH" MPATH_ID_INT_MAX, "WWID2"); expect_condlog(0, NOMORE_STR); @@ -1014,7 +991,7 @@ static void rl_empty(void **state) char buf[WWID_SIZE]; buf[0] = '\0'; - will_return(__wrap_fgets, NULL); + mock_bindings_file("", -1); expect_condlog(3, NOMATCH_STR("MPATHa")); rc = rlookup_binding(NULL, buf, "MPATHa"); assert_int_equal(rc, -1); @@ -1027,7 +1004,7 @@ static void rl_match_a(void **state) char buf[WWID_SIZE]; buf[0] = '\0'; - will_return(__wrap_fgets, "MPATHa WWID0\n"); + mock_bindings_file("MPATHa WWID0\n", 0); expect_condlog(3, FOUND_ALIAS_STR("MPATHa", "WWID0")); rc = rlookup_binding(NULL, buf, "MPATHa"); assert_int_equal(rc, 0); @@ -1040,8 +1017,7 @@ static void rl_nomatch_a(void **state) char buf[WWID_SIZE]; buf[0] = '\0'; - will_return(__wrap_fgets, "MPATHa WWID0\n"); - will_return(__wrap_fgets, NULL); + mock_bindings_file("MPATHa WWID0\n", -1); expect_condlog(3, NOMATCH_STR("MPATHb")); rc = rlookup_binding(NULL, buf, "MPATHb"); assert_int_equal(rc, -1); @@ -1054,8 +1030,7 @@ static void rl_malformed_a(void **state) char buf[WWID_SIZE]; buf[0] = '\0'; - will_return(__wrap_fgets, "MPATHa \n"); - will_return(__wrap_fgets, NULL); + mock_bindings_file("MPATHa \n", -1); expect_condlog(3, "Ignoring malformed line 1 in bindings file\n"); expect_condlog(3, NOMATCH_STR("MPATHa")); rc = rlookup_binding(NULL, buf, "MPATHa"); @@ -1074,8 +1049,7 @@ static void rl_overlong_a(void **state) snprintf(line + sizeof(line) - 2, 2, "\n"); buf[0] = '\0'; - will_return(__wrap_fgets, line); - will_return(__wrap_fgets, NULL); + mock_bindings_file(line, -1); expect_condlog(3, "Ignoring too large wwid at 1 in bindings file\n"); expect_condlog(3, NOMATCH_STR("MPATHa")); rc = rlookup_binding(NULL, buf, "MPATHa"); @@ -1089,9 +1063,9 @@ static void rl_match_b(void **state) char buf[WWID_SIZE]; buf[0] = '\0'; - will_return(__wrap_fgets, "MPATHa WWID0\n"); - will_return(__wrap_fgets, "MPATHz WWID26\n"); - will_return(__wrap_fgets, "MPATHb WWID2\n"); + mock_bindings_file("MPATHa WWID0\n" + "MPATHz WWID26\n" + "MPATHb WWID2\n", 2); expect_condlog(3, FOUND_ALIAS_STR("MPATHb", "WWID2")); rc = rlookup_binding(NULL, buf, "MPATHb"); assert_int_equal(rc, 0); @@ -1222,7 +1196,7 @@ static void gufa_empty_new_rw(void **state) { will_return(__wrap_open_file, true); - will_return(__wrap_fgets, NULL); + mock_bindings_file("", -1); mock_unused_alias("MPATHa"); expect_condlog(3, NOMATCH_WWID_STR("WWID0")); @@ -1235,7 +1209,7 @@ static void gufa_empty_new_rw(void **state) { static void gufa_empty_new_ro_1(void **state) { char *alias; will_return(__wrap_open_file, false); - will_return(__wrap_fgets, NULL); + mock_bindings_file("", -1); mock_unused_alias("MPATHa"); expect_condlog(3, NOMATCH_WWID_STR("WWID0")); @@ -1248,7 +1222,7 @@ static void gufa_empty_new_ro_2(void **state) { will_return(__wrap_open_file, true); - will_return(__wrap_fgets, NULL); + mock_bindings_file("", -1); mock_unused_alias("MPATHa"); expect_condlog(3, NOMATCH_WWID_STR("WWID0")); @@ -1261,7 +1235,7 @@ static void gufa_match_a_unused(void **state) { will_return(__wrap_open_file, true); - will_return(__wrap_fgets, BINDING_STR("MPATHa", "WWID0")); + mock_bindings_file("MPATHa WWID0", 0); expect_condlog(3, FOUND_STR("MPATHa", "WWID0")); mock_unused_alias("MPATHa"); @@ -1275,7 +1249,7 @@ static void gufa_match_a_self(void **state) { will_return(__wrap_open_file, true); - will_return(__wrap_fgets, BINDING_STR("MPATHa", "WWID0")); + mock_bindings_file("MPATHa WWID0", 0); expect_condlog(3, FOUND_STR("MPATHa", "WWID0")); mock_self_alias("MPATHa", "WWID0"); @@ -1289,7 +1263,7 @@ static void gufa_match_a_used(void **state) { will_return(__wrap_open_file, true); - will_return(__wrap_fgets, BINDING_STR("MPATHa", "WWID0")); + mock_bindings_file("MPATHa WWID0", 0); expect_condlog(3, FOUND_STR("MPATHa", "WWID0")); mock_used_alias("MPATHa", "WWID0"); @@ -1389,11 +1363,11 @@ static void gufa_old_empty(void **state) { will_return(__wrap_open_file, true); /* rlookup_binding for ALIAS */ - will_return(__wrap_fgets, NULL); + mock_bindings_file("", -1); expect_condlog(3, NOMATCH_STR("MPATHz")); /* lookup_binding */ - will_return(__wrap_fgets, NULL); + mock_bindings_file("", -1); expect_condlog(3, NOMATCH_WWID_STR("WWID0")); mock_allocate_binding("MPATHz", "WWID0"); From patchwork Mon Sep 11 16:38:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13379482 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E3F46EE7FF4 for ; Mon, 11 Sep 2023 16:39:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694450371; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=djza1+gJz4wYPDgVrue4NRbtBO2X/AzdE6pKe4YxVyQ=; b=VRgND5MaqNqq6xQM/DcARVLHhLgRJ/lBzmqxhq938eyfW8VT1QzrwRA7pZOmtPW5jTa4ds dlVOwZGOTBgzgf8Y6XAgkk9R5Uw6tDqlgM9Ak1OwRBS1JZy/3sO6Om9BQqdSv68Z0aHhWr MZrm3Ga0KAdhVSu59Aw8Y3Ueaxsl7Y8= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-480-Gbkd6VEiONyiok5pUZN0xg-1; Mon, 11 Sep 2023 12:39:26 -0400 X-MC-Unique: Gbkd6VEiONyiok5pUZN0xg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 25C1E3C01C27; Mon, 11 Sep 2023 16:39:23 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1296E21CAC7A; Mon, 11 Sep 2023 16:39:23 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id E7F4E19465A2; Mon, 11 Sep 2023 16:39:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id F1C1C1946A4D for ; Mon, 11 Sep 2023 16:39:20 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id D723C2027047; Mon, 11 Sep 2023 16:39:20 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CDC612027019 for ; Mon, 11 Sep 2023 16:39:20 +0000 (UTC) Received: from us-smtp-inbound-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AFC7A928B8B for ; Mon, 11 Sep 2023 16:39:20 +0000 (UTC) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-265-xmzJAbd0Ni2f9k8SJs237Q-1; Mon, 11 Sep 2023 12:39:18 -0400 X-MC-Unique: xmzJAbd0Ni2f9k8SJs237Q-1 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 682F621847; Mon, 11 Sep 2023 16:39:17 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 39BDC139CC; Mon, 11 Sep 2023 16:39:17 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id KGJpDLVC/2RzEAAAMHmgww (envelope-from ); Mon, 11 Sep 2023 16:39:17 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Mon, 11 Sep 2023 18:38:20 +0200 Message-ID: <20230911163846.27197-12-mwilck@suse.com> In-Reply-To: <20230911163846.27197-1-mwilck@suse.com> References: <20230911163846.27197-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 Subject: [dm-devel] [PATCH v2 11/37] libmultipath: add global variable for current bindings X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dm-devel@redhat.com, Martin Wilck Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: suse.com From: Martin Wilck Add a variable global_bindings that holds the currently active vector of bindings. This variable is freed at program exit. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/alias.c | 11 +++++++++-- libmultipath/alias.h | 1 + libmultipath/libmultipath.version | 1 + multipath/main.c | 2 ++ multipathd/main.c | 1 + 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/libmultipath/alias.c b/libmultipath/alias.c index b95cbbe..701e7a2 100644 --- a/libmultipath/alias.c +++ b/libmultipath/alias.c @@ -511,6 +511,7 @@ static void _free_binding(struct binding *bdg) * an abstract type. */ typedef struct _vector Bindings; +static Bindings global_bindings = { .allocated = 0 }; static void free_bindings(Bindings *bindings) { @@ -522,6 +523,11 @@ static void free_bindings(Bindings *bindings) vector_reset(bindings); } +void cleanup_bindings(void) +{ + free_bindings(&global_bindings); +} + enum { BINDING_EXISTS, BINDING_CONFLICT, @@ -751,7 +757,6 @@ int check_alias_settings(const struct config *conf) pthread_cleanup_pop(1); pthread_cleanup_pop(1); - pthread_cleanup_push_cast(free_bindings, &bindings); fd = open_file(conf->bindings_file, &can_write, BINDINGS_FILE_HEADER); if (fd != -1) { FILE *file = fdopen(fd, "r"); @@ -771,6 +776,8 @@ int check_alias_settings(const struct config *conf) close(fd); } } - pthread_cleanup_pop(1); + + cleanup_bindings(); + global_bindings = bindings; return rc; } diff --git a/libmultipath/alias.h b/libmultipath/alias.h index fa33223..37b49d9 100644 --- a/libmultipath/alias.h +++ b/libmultipath/alias.h @@ -9,5 +9,6 @@ char *get_user_friendly_alias(const char *wwid, const char *file, struct config; int check_alias_settings(const struct config *); +void cleanup_bindings(void); #endif /* _ALIAS_H */ diff --git a/libmultipath/libmultipath.version b/libmultipath/libmultipath.version index a7b8c33..ddd302f 100644 --- a/libmultipath/libmultipath.version +++ b/libmultipath/libmultipath.version @@ -64,6 +64,7 @@ global: checker_name; checker_state_name; check_foreign; + cleanup_bindings; cleanup_lock; coalesce_paths; count_active_paths; diff --git a/multipath/main.c b/multipath/main.c index b78f316..45e9745 100644 --- a/multipath/main.c +++ b/multipath/main.c @@ -843,6 +843,8 @@ main (int argc, char *argv[]) conf->force_sync = 1; if (atexit(cleanup_vecs)) condlog(1, "failed to register cleanup handler for vecs: %m"); + if (atexit(cleanup_bindings)) + condlog(1, "failed to register cleanup handler for bindings: %m"); while ((arg = getopt(argc, argv, ":adDcChl::eFfM:v:p:b:BrR:itTquUwW")) != EOF ) { switch(arg) { case 'v': diff --git a/multipathd/main.c b/multipathd/main.c index 2e02a54..214ed4a 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -3325,6 +3325,7 @@ static void cleanup_child(void) { cleanup_threads(); cleanup_vecs(); + cleanup_bindings(); if (poll_dmevents) cleanup_dmevent_waiter(); From patchwork Mon Sep 11 16:38:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13379497 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F3504EE57DF for ; Mon, 11 Sep 2023 16:39:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694450386; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=LAOfREypDhA3Tla9zOgvoqEBDSv6M7hIG3h2dgXRB3s=; b=QCczIqY0kKMXS/TqB6GEydbwEJQaHeJfnUiPNUOlloxs6ZRGM5TO7qtemisrNtpNH2JLds PZ1w3LJoM3RzSb9ZW53yyceDtoRR7FJFsbpobAZNMsNEa5OJRE4nD7HBlXshjodeDFlvX+ leyYB3KNHD4Q6dkn8eGAfwU3/TsR+B8= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-244-yaJtuHKePna37CEIDN61cw-1; Mon, 11 Sep 2023 12:39:42 -0400 X-MC-Unique: yaJtuHKePna37CEIDN61cw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 35A19933742; Mon, 11 Sep 2023 16:39:24 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 20EF11006B56; Mon, 11 Sep 2023 16:39:24 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id B03D91946A4D; Mon, 11 Sep 2023 16:39:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 8A7121946597 for ; Mon, 11 Sep 2023 16:39:22 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 7CA9B2156701; Mon, 11 Sep 2023 16:39:22 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 75CBB21CAC7A for ; Mon, 11 Sep 2023 16:39:22 +0000 (UTC) Received: from us-smtp-inbound-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5A77E181A706 for ; Mon, 11 Sep 2023 16:39:22 +0000 (UTC) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-124-eitjT9A7OnOKrhHmD9tQqQ-1; Mon, 11 Sep 2023 12:39:18 -0400 X-MC-Unique: eitjT9A7OnOKrhHmD9tQqQ-1 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id A4B7C1F88C; Mon, 11 Sep 2023 16:39:17 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 73EE1139CC; Mon, 11 Sep 2023 16:39:17 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id KK+aGrVC/2RzEAAAMHmgww (envelope-from ); Mon, 11 Sep 2023 16:39:17 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Mon, 11 Sep 2023 18:38:21 +0200 Message-ID: <20230911163846.27197-13-mwilck@suse.com> In-Reply-To: <20230911163846.27197-1-mwilck@suse.com> References: <20230911163846.27197-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Subject: [dm-devel] [PATCH v2 12/37] libmultipath: rename fix_bindings_file() to update_bindings_file() X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dm-devel@redhat.com, Martin Wilck Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: suse.com From: Martin Wilck We will use this function in a more generic way, give it a more generic name. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/alias.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libmultipath/alias.c b/libmultipath/alias.c index 701e7a2..06e6f7c 100644 --- a/libmultipath/alias.c +++ b/libmultipath/alias.c @@ -595,8 +595,8 @@ static int write_bindings_file(const Bindings *bindings, int fd) return 0; } -static int fix_bindings_file(const struct config *conf, - const Bindings *bindings) +static int update_bindings_file(const struct config *conf, + const Bindings *bindings) { int rc; int fd = -1; @@ -766,7 +766,7 @@ int check_alias_settings(const struct config *conf) rc = _check_bindings_file(conf, file, &bindings); pthread_cleanup_pop(1); if (rc == -1 && can_write && !conf->bindings_read_only) - rc = fix_bindings_file(conf, &bindings); + rc = update_bindings_file(conf, &bindings); else if (rc == -1) condlog(0, "ERROR: bad settings in read-only bindings file %s", conf->bindings_file); From patchwork Mon Sep 11 16:38:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13379495 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 10832EEB57E for ; Mon, 11 Sep 2023 16:39:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694450380; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Vxd96bS1QmQgYqzBeRXHj46GhQIeJjYG7dytok9mcmo=; b=Rpe85if8JYPy/5iovg7mADuOxDl+hbaHPWNg/5gQc4eTpwyb9axtThQUEvZlC0TbIaIUIR oOqg/qrU4exBZVFToiJ7ViZSW8UiL+cu5VzrUf1yQ9rSxN/0yrKSdkKsUzrlAOZQLFtPNQ OHJF9ZPuOEN/3qvd/A2QuJAXVl9NYYo= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-271-F5aRCnbXPwWwjhLPh_dUeA-1; Mon, 11 Sep 2023 12:39:36 -0400 X-MC-Unique: F5aRCnbXPwWwjhLPh_dUeA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7FDF5945E76; Mon, 11 Sep 2023 16:39:24 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6C2E540C6EC1; Mon, 11 Sep 2023 16:39:24 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id DE44219465A3; Mon, 11 Sep 2023 16:39:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 2067619465B8 for ; Mon, 11 Sep 2023 16:39:22 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 02A2640C200B; Mon, 11 Sep 2023 16:39:22 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EF2C340C200A for ; Mon, 11 Sep 2023 16:39:21 +0000 (UTC) Received: from us-smtp-inbound-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CFA4F101FAAB for ; Mon, 11 Sep 2023 16:39:21 +0000 (UTC) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-187-mCrr0ixROl2sorVc1W9Ufw-1; Mon, 11 Sep 2023 12:39:19 -0400 X-MC-Unique: mCrr0ixROl2sorVc1W9Ufw-1 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id E299C1F8A6; Mon, 11 Sep 2023 16:39:17 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id AD296139CC; Mon, 11 Sep 2023 16:39:17 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id uM26KLVC/2RzEAAAMHmgww (envelope-from ); Mon, 11 Sep 2023 16:39:17 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Mon, 11 Sep 2023 18:38:22 +0200 Message-ID: <20230911163846.27197-14-mwilck@suse.com> In-Reply-To: <20230911163846.27197-1-mwilck@suse.com> References: <20230911163846.27197-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Subject: [dm-devel] [PATCH v2 13/37] libmultipath: alias.c: move bindings related code up X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dm-devel@redhat.com, Martin Wilck Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: suse.com From: Martin Wilck No code changes, just moving code. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/alias.c | 239 ++++++++++++++++++++++--------------------- 1 file changed, 120 insertions(+), 119 deletions(-) diff --git a/libmultipath/alias.c b/libmultipath/alias.c index 06e6f7c..7e6b0d2 100644 --- a/libmultipath/alias.c +++ b/libmultipath/alias.c @@ -9,6 +9,7 @@ #include #include #include +#include #include "debug.h" #include "util.h" @@ -51,6 +52,125 @@ static const char bindings_file_header[] = BINDINGS_FILE_HEADER; +struct binding { + char *alias; + char *wwid; +}; + +/* + * Perhaps one day we'll implement this more efficiently, thus use + * an abstract type. + */ +typedef struct _vector Bindings; +static Bindings global_bindings = { .allocated = 0 }; + +enum { + BINDING_EXISTS, + BINDING_CONFLICT, + BINDING_ADDED, + BINDING_DELETED, + BINDING_NOTFOUND, + BINDING_ERROR, +}; + +static void _free_binding(struct binding *bdg) +{ + free(bdg->wwid); + free(bdg->alias); + free(bdg); +} + +static int add_binding(Bindings *bindings, const char *alias, const char *wwid) +{ + struct binding *bdg; + int i, cmp = 0; + + /* + * Keep the bindings array sorted by alias. + * Optimization: Search backwards, assuming that the bindings file is + * sorted already. + */ + vector_foreach_slot_backwards(bindings, bdg, i) { + if ((cmp = strcmp(bdg->alias, alias)) <= 0) + break; + } + + /* Check for exact match */ + if (i >= 0 && cmp == 0) + return strcmp(bdg->wwid, wwid) ? + BINDING_CONFLICT : BINDING_EXISTS; + + i++; + bdg = calloc(1, sizeof(*bdg)); + if (bdg) { + bdg->wwid = strdup(wwid); + bdg->alias = strdup(alias); + if (bdg->wwid && bdg->alias && + vector_insert_slot(bindings, i, bdg)) + return BINDING_ADDED; + else + _free_binding(bdg); + } + + return BINDING_ERROR; +} + +static int write_bindings_file(const Bindings *bindings, int fd) +{ + struct binding *bnd; + STRBUF_ON_STACK(line); + int i; + + if (write(fd, BINDINGS_FILE_HEADER, sizeof(BINDINGS_FILE_HEADER) - 1) + != sizeof(BINDINGS_FILE_HEADER) - 1) + return -1; + + vector_foreach_slot(bindings, bnd, i) { + int len; + + if ((len = print_strbuf(&line, "%s %s\n", + bnd->alias, bnd->wwid)) < 0) + return -1; + if (write(fd, get_strbuf_str(&line), len) != len) + return -1; + truncate_strbuf(&line, 0); + } + return 0; +} + +static int update_bindings_file(const struct config *conf, + const Bindings *bindings) +{ + int rc; + int fd = -1; + char tempname[PATH_MAX]; + mode_t old_umask; + + if (safe_sprintf(tempname, "%s.XXXXXX", conf->bindings_file)) + return -1; + /* coverity: SECURE_TEMP */ + old_umask = umask(0077); + if ((fd = mkstemp(tempname)) == -1) { + condlog(1, "%s: mkstemp: %m", __func__); + return -1; + } + umask(old_umask); + pthread_cleanup_push(cleanup_fd_ptr, &fd); + rc = write_bindings_file(bindings, fd); + pthread_cleanup_pop(1); + if (rc == -1) { + condlog(1, "failed to write new bindings file %s", + tempname); + unlink(tempname); + return rc; + } + if ((rc = rename(tempname, conf->bindings_file)) == -1) + condlog(0, "%s: rename: %m", __func__); + else + condlog(1, "updated bindings file %s", conf->bindings_file); + return rc; +} + int valid_alias(const char *alias) { @@ -494,25 +614,6 @@ get_user_friendly_wwid(const char *alias, char *buff, const char *file) return 0; } -struct binding { - char *alias; - char *wwid; -}; - -static void _free_binding(struct binding *bdg) -{ - free(bdg->wwid); - free(bdg->alias); - free(bdg); -} - -/* - * Perhaps one day we'll implement this more efficiently, thus use - * an abstract type. - */ -typedef struct _vector Bindings; -static Bindings global_bindings = { .allocated = 0 }; - static void free_bindings(Bindings *bindings) { struct binding *bdg; @@ -528,106 +629,6 @@ void cleanup_bindings(void) free_bindings(&global_bindings); } -enum { - BINDING_EXISTS, - BINDING_CONFLICT, - BINDING_ADDED, - BINDING_DELETED, - BINDING_NOTFOUND, - BINDING_ERROR, -}; - -static int add_binding(Bindings *bindings, const char *alias, const char *wwid) -{ - struct binding *bdg; - int i, cmp = 0; - - /* - * Keep the bindings array sorted by alias. - * Optimization: Search backwards, assuming that the bindings file is - * sorted already. - */ - vector_foreach_slot_backwards(bindings, bdg, i) { - if ((cmp = strcmp(bdg->alias, alias)) <= 0) - break; - } - - /* Check for exact match */ - if (i >= 0 && cmp == 0) - return strcmp(bdg->wwid, wwid) ? - BINDING_CONFLICT : BINDING_EXISTS; - - i++; - bdg = calloc(1, sizeof(*bdg)); - if (bdg) { - bdg->wwid = strdup(wwid); - bdg->alias = strdup(alias); - if (bdg->wwid && bdg->alias && - vector_insert_slot(bindings, i, bdg)) - return BINDING_ADDED; - else - _free_binding(bdg); - } - - return BINDING_ERROR; -} - -static int write_bindings_file(const Bindings *bindings, int fd) -{ - struct binding *bnd; - STRBUF_ON_STACK(line); - int i; - - if (write(fd, BINDINGS_FILE_HEADER, sizeof(BINDINGS_FILE_HEADER) - 1) - != sizeof(BINDINGS_FILE_HEADER) - 1) - return -1; - - vector_foreach_slot(bindings, bnd, i) { - int len; - - if ((len = print_strbuf(&line, "%s %s\n", - bnd->alias, bnd->wwid)) < 0) - return -1; - if (write(fd, get_strbuf_str(&line), len) != len) - return -1; - truncate_strbuf(&line, 0); - } - return 0; -} - -static int update_bindings_file(const struct config *conf, - const Bindings *bindings) -{ - int rc; - int fd = -1; - char tempname[PATH_MAX]; - mode_t old_umask; - - if (safe_sprintf(tempname, "%s.XXXXXX", conf->bindings_file)) - return -1; - /* coverity: SECURE_TEMP */ - old_umask = umask(0077); - if ((fd = mkstemp(tempname)) == -1) { - condlog(1, "%s: mkstemp: %m", __func__); - return -1; - } - umask(old_umask); - pthread_cleanup_push(cleanup_fd_ptr, &fd); - rc = write_bindings_file(bindings, fd); - pthread_cleanup_pop(1); - if (rc == -1) { - condlog(1, "failed to write new bindings file %s", - tempname); - unlink(tempname); - return rc; - } - if ((rc = rename(tempname, conf->bindings_file)) == -1) - condlog(0, "%s: rename: %m", __func__); - else - condlog(1, "updated bindings file %s", conf->bindings_file); - return rc; -} - static int _check_bindings_file(const struct config *conf, FILE *file, Bindings *bindings) { From patchwork Mon Sep 11 16:38:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13379491 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9E9C9EEB593 for ; Mon, 11 Sep 2023 16:39:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694450375; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=LI3Acn4bSJ6aOdu14j1adhvasfwhyeDgt+MIl3eKO4o=; b=VSuewwG2x49buvQtWnKVn8sPxB+eRJIW2UisusGnpL0YaB2/s3DKkdnSKl8lKKy7M1Vu4m wXhiQbviNVghF0G8w2ZgHkBzANRF0NXtkiVAewAV0IsizZFmya9fDkllB8kLbo1UR1qevf z0yj2px66zzR/0nXX+OMN5xincsJyr4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-682-5jGTQJFFPDGZ-SBRvTUmlQ-1; Mon, 11 Sep 2023 12:39:30 -0400 X-MC-Unique: 5jGTQJFFPDGZ-SBRvTUmlQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A05F9933737; Mon, 11 Sep 2023 16:39:23 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8CDA640C6EA8; Mon, 11 Sep 2023 16:39:23 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 52CBA19465B8; Mon, 11 Sep 2023 16:39:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id C231119465A2 for ; Mon, 11 Sep 2023 16:39:21 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id B3A9C4405A; Mon, 11 Sep 2023 16:39:21 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AC1B55CC01 for ; Mon, 11 Sep 2023 16:39:21 +0000 (UTC) Received: from us-smtp-inbound-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 77C7E181A6F7 for ; Mon, 11 Sep 2023 16:39:21 +0000 (UTC) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-426-Xre1CYOvPSC6DtKBcZd6Zg-1; Mon, 11 Sep 2023 12:39:19 -0400 X-MC-Unique: Xre1CYOvPSC6DtKBcZd6Zg-1 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 293F021858; Mon, 11 Sep 2023 16:39:18 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id EF1FB139CC; Mon, 11 Sep 2023 16:39:17 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id yFaeOLVC/2RzEAAAMHmgww (envelope-from ); Mon, 11 Sep 2023 16:39:17 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Mon, 11 Sep 2023 18:38:23 +0200 Message-ID: <20230911163846.27197-15-mwilck@suse.com> In-Reply-To: <20230911163846.27197-1-mwilck@suse.com> References: <20230911163846.27197-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Subject: [dm-devel] [PATCH v2 14/37] libmultipath: update_bindings_file: take filename argument X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dm-devel@redhat.com, Martin Wilck Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: suse.com From: Martin Wilck This function just uses the file name, no other configuration parameters. Also, pass the Bindings argument first to use the same convention as the other functions in this file. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/alias.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libmultipath/alias.c b/libmultipath/alias.c index 7e6b0d2..ae7bbd2 100644 --- a/libmultipath/alias.c +++ b/libmultipath/alias.c @@ -138,15 +138,15 @@ static int write_bindings_file(const Bindings *bindings, int fd) return 0; } -static int update_bindings_file(const struct config *conf, - const Bindings *bindings) +static int update_bindings_file(const Bindings *bindings, + const char *bindings_file) { int rc; int fd = -1; char tempname[PATH_MAX]; mode_t old_umask; - if (safe_sprintf(tempname, "%s.XXXXXX", conf->bindings_file)) + if (safe_sprintf(tempname, "%s.XXXXXX", bindings_file)) return -1; /* coverity: SECURE_TEMP */ old_umask = umask(0077); @@ -164,10 +164,10 @@ static int update_bindings_file(const struct config *conf, unlink(tempname); return rc; } - if ((rc = rename(tempname, conf->bindings_file)) == -1) + if ((rc = rename(tempname, bindings_file)) == -1) condlog(0, "%s: rename: %m", __func__); else - condlog(1, "updated bindings file %s", conf->bindings_file); + condlog(1, "updated bindings file %s", bindings_file); return rc; } @@ -767,7 +767,7 @@ int check_alias_settings(const struct config *conf) rc = _check_bindings_file(conf, file, &bindings); pthread_cleanup_pop(1); if (rc == -1 && can_write && !conf->bindings_read_only) - rc = update_bindings_file(conf, &bindings); + rc = update_bindings_file(&bindings, conf->bindings_file); else if (rc == -1) condlog(0, "ERROR: bad settings in read-only bindings file %s", conf->bindings_file); From patchwork Mon Sep 11 16:38:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13379493 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EB015EEB594 for ; Mon, 11 Sep 2023 16:39:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694450376; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=ejlfXJuAq/JC4YIlYEUCUR/eLfPJ9sY46EbLMxmpqak=; b=h3kCZthS8IIGEqNsC+YrU6jOd11hHYGwbj4yaslF2268oUAqksBfhdZL1JhKW/AFtxpsY0 lAup7+Rv5Cc3pyJh29DLraFpeP7R45KZi9HtnXdYqBYQnCFuwE+wQLVIonp+5XHLimWcsv a2tdbqdb0gOXzjQUKm8XgEeUgb73m44= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-151-54-E9CTZOsmpr_aIVHQ1Uw-1; Mon, 11 Sep 2023 12:39:31 -0400 X-MC-Unique: 54-E9CTZOsmpr_aIVHQ1Uw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 858E7928B83; Mon, 11 Sep 2023 16:39:26 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 73B7B40C6EBF; Mon, 11 Sep 2023 16:39:26 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 425D819465B3; Mon, 11 Sep 2023 16:39:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 618B419466DF for ; Mon, 11 Sep 2023 16:39:23 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 433052156711; Mon, 11 Sep 2023 16:39:23 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3C36D215670B for ; Mon, 11 Sep 2023 16:39:23 +0000 (UTC) Received: from us-smtp-inbound-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 215AF928B84 for ; Mon, 11 Sep 2023 16:39:23 +0000 (UTC) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-106-VsWX3DzsNsO5Fhb1uC1sgQ-1; Mon, 11 Sep 2023 12:39:19 -0400 X-MC-Unique: VsWX3DzsNsO5Fhb1uC1sgQ-1 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 657F11F8B3; Mon, 11 Sep 2023 16:39:18 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 34DDA139CC; Mon, 11 Sep 2023 16:39:18 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id yAhCC7ZC/2RzEAAAMHmgww (envelope-from ); Mon, 11 Sep 2023 16:39:18 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Mon, 11 Sep 2023 18:38:24 +0200 Message-ID: <20230911163846.27197-16-mwilck@suse.com> In-Reply-To: <20230911163846.27197-1-mwilck@suse.com> References: <20230911163846.27197-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Subject: [dm-devel] [PATCH v2 15/37] libmultipath: update_bindings_file: use a single write() X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dm-devel@redhat.com, Martin Wilck Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: suse.com From: Martin Wilck Save code and syscalls by assembling the content in memory first. write() may return less bytes written than expected. Deal with it. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/alias.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/libmultipath/alias.c b/libmultipath/alias.c index ae7bbd2..bd34466 100644 --- a/libmultipath/alias.c +++ b/libmultipath/alias.c @@ -118,22 +118,30 @@ static int add_binding(Bindings *bindings, const char *alias, const char *wwid) static int write_bindings_file(const Bindings *bindings, int fd) { struct binding *bnd; - STRBUF_ON_STACK(line); + STRBUF_ON_STACK(content); int i; + size_t len; - if (write(fd, BINDINGS_FILE_HEADER, sizeof(BINDINGS_FILE_HEADER) - 1) - != sizeof(BINDINGS_FILE_HEADER) - 1) + if (__append_strbuf_str(&content, BINDINGS_FILE_HEADER, + sizeof(BINDINGS_FILE_HEADER) - 1) == -1) return -1; vector_foreach_slot(bindings, bnd, i) { - int len; + if (print_strbuf(&content, "%s %s\n", + bnd->alias, bnd->wwid) < 0) + return -1; + } + len = get_strbuf_len(&content); + while (len > 0) { + ssize_t n = write(fd, get_strbuf_str(&content), len); - if ((len = print_strbuf(&line, "%s %s\n", - bnd->alias, bnd->wwid)) < 0) + if (n < 0) + return n; + else if (n == 0) { + condlog(2, "%s: short write", __func__); return -1; - if (write(fd, get_strbuf_str(&line), len) != len) - return -1; - truncate_strbuf(&line, 0); + } + len -= n; } return 0; } From patchwork Mon Sep 11 16:38:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13379504 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B9BF2EE57DF for ; Mon, 11 Sep 2023 16:39:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694450388; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=fJDKY3wnl6A+gESFARyZDD4WLFTqorBr6z6Y9og8wlU=; b=bmRMYjS2QKDDnxKqMYoPzbGw4w4VcoKGgAEXV4a00iI6k5r2NDcjef61wTx8OB3HkOieU1 myiNqPiSwS0h3N9xSbO7Xr4600nEfTlfHUe1aKALU6NJU9Poog5pJb+CrHPdHVNIS607Uo +pwWSbC9v+LC2VQOYU5FkIEcrkkuYQg= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-321-tsZzQ_SjPDK11zgn7rfCQQ-1; Mon, 11 Sep 2023 12:39:44 -0400 X-MC-Unique: tsZzQ_SjPDK11zgn7rfCQQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3D72D928B86; Mon, 11 Sep 2023 16:39:32 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2AA8D40C6EA8; Mon, 11 Sep 2023 16:39:32 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 1BDE319465A3; Mon, 11 Sep 2023 16:39:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 0334E19465B3 for ; Mon, 11 Sep 2023 16:39:22 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id E9CA644069; Mon, 11 Sep 2023 16:39:21 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E24AD4405A for ; Mon, 11 Sep 2023 16:39:21 +0000 (UTC) Received: from us-smtp-inbound-delivery-1.mimecast.com (us-smtp-inbound-delivery-1.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C4F1C933721 for ; Mon, 11 Sep 2023 16:39:21 +0000 (UTC) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-452-0EwF3fNnM3elezgInJ3PVw-1; Mon, 11 Sep 2023 12:39:19 -0400 X-MC-Unique: 0EwF3fNnM3elezgInJ3PVw-1 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 9DBC621860; Mon, 11 Sep 2023 16:39:18 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 706B0139CC; Mon, 11 Sep 2023 16:39:18 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id yKTOGbZC/2RzEAAAMHmgww (envelope-from ); Mon, 11 Sep 2023 16:39:18 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Mon, 11 Sep 2023 18:38:25 +0200 Message-ID: <20230911163846.27197-17-mwilck@suse.com> In-Reply-To: <20230911163846.27197-1-mwilck@suse.com> References: <20230911163846.27197-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Subject: [dm-devel] [PATCH v2 16/37] libmultipath: update_bindings_file: don't log temp file name X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dm-devel@redhat.com, Martin Wilck Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: suse.com From: Martin Wilck The name of the temp file is unlikely to be helpful for users, and hard to predict in the unit test. Omit it. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/alias.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libmultipath/alias.c b/libmultipath/alias.c index bd34466..de21f52 100644 --- a/libmultipath/alias.c +++ b/libmultipath/alias.c @@ -167,8 +167,7 @@ static int update_bindings_file(const Bindings *bindings, rc = write_bindings_file(bindings, fd); pthread_cleanup_pop(1); if (rc == -1) { - condlog(1, "failed to write new bindings file %s", - tempname); + condlog(1, "failed to write new bindings file"); unlink(tempname); return rc; } From patchwork Mon Sep 11 16:38:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13379485 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D0A18EEB58F for ; Mon, 11 Sep 2023 16:39:33 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-54-AiHbL9qsN5qTXssSa_UZbg-1; Mon, 11 Sep 2023 12:39:29 -0400 X-MC-Unique: AiHbL9qsN5qTXssSa_UZbg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3C52D928B91; Mon, 11 Sep 2023 16:39:25 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 27E1644029; Mon, 11 Sep 2023 16:39:25 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 1786619465A2; Mon, 11 Sep 2023 16:39:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id D83D61946597 for ; Mon, 11 Sep 2023 16:39:21 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id B7E8540C6EBF; Mon, 11 Sep 2023 16:39:21 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B0A2840C6EC0 for ; Mon, 11 Sep 2023 16:39:21 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 90F26181A6FC for ; Mon, 11 Sep 2023 16:39:21 +0000 (UTC) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-528-F5tKlEw5PYKn66EgHHXNpQ-1; Mon, 11 Sep 2023 12:39:20 -0400 X-MC-Unique: F5tKlEw5PYKn66EgHHXNpQ-1 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id D7A4021863; Mon, 11 Sep 2023 16:39:18 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id A9F44139CC; Mon, 11 Sep 2023 16:39:18 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 2N/KJ7ZC/2RzEAAAMHmgww (envelope-from ); Mon, 11 Sep 2023 16:39:18 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Mon, 11 Sep 2023 18:38:26 +0200 Message-ID: <20230911163846.27197-18-mwilck@suse.com> In-Reply-To: <20230911163846.27197-1-mwilck@suse.com> References: <20230911163846.27197-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 Subject: [dm-devel] [PATCH v2 17/37] libmultipath: alias.c: factor out read_binding() X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dm-devel@redhat.com, Martin Wilck Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: suse.com From: Martin Wilck This way we can test the parsing of input lines from the bindings file more easily. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/alias.c | 58 ++++++++++++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 18 deletions(-) diff --git a/libmultipath/alias.c b/libmultipath/alias.c index de21f52..ad83ca0 100644 --- a/libmultipath/alias.c +++ b/libmultipath/alias.c @@ -636,6 +636,43 @@ void cleanup_bindings(void) free_bindings(&global_bindings); } +enum { + READ_BINDING_OK, + READ_BINDING_SKIP, +}; + +static int read_binding(char *line, unsigned int linenr, char **alias, + char **wwid) { + char *c, *saveptr; + + c = strpbrk(line, "#\n\r"); + if (c) + *c = '\0'; + + *alias = strtok_r(line, " \t", &saveptr); + if (!*alias) /* blank line */ + return READ_BINDING_SKIP; + + *wwid = strtok_r(NULL, " \t", &saveptr); + if (!*wwid) { + condlog(1, "invalid line %u in bindings file, missing WWID", + linenr); + return READ_BINDING_SKIP; + } + if (strlen(*wwid) > WWID_SIZE - 1) { + condlog(3, + "Ignoring too large wwid at %u in bindings file", + linenr); + return READ_BINDING_SKIP; + } + c = strtok_r(NULL, " \t", &saveptr); + if (c) + /* This is non-fatal */ + condlog(1, "invalid line %d in bindings file, extra args \"%s\"", + linenr, c); + return READ_BINDING_OK; +} + static int _check_bindings_file(const struct config *conf, FILE *file, Bindings *bindings) { @@ -647,27 +684,12 @@ static int _check_bindings_file(const struct config *conf, FILE *file, pthread_cleanup_push(cleanup_free_ptr, &line); while ((n = getline(&line, &line_len, file)) >= 0) { - char *c, *alias, *wwid, *saveptr; + char *alias, *wwid; const char *mpe_wwid; - linenr++; - c = strpbrk(line, "#\n\r"); - if (c) - *c = '\0'; - alias = strtok_r(line, " \t", &saveptr); - if (!alias) /* blank line */ + if (read_binding(line, ++linenr, &alias, &wwid) + == READ_BINDING_SKIP) continue; - wwid = strtok_r(NULL, " \t", &saveptr); - if (!wwid) { - condlog(1, "invalid line %d in bindings file, missing WWID", - linenr); - continue; - } - c = strtok_r(NULL, " \t", &saveptr); - if (c) - /* This is non-fatal */ - condlog(1, "invalid line %d in bindings file, extra args \"%s\"", - linenr, c); mpe_wwid = get_mpe_wwid(conf->mptable, alias); if (mpe_wwid && strcmp(mpe_wwid, wwid)) { From patchwork Mon Sep 11 16:38:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13379498 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 58ED7EE7FF4 for ; Mon, 11 Sep 2023 16:39:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694450386; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=utrHpGJNr0++s2YgxZRFkkdKWEuTrKE9HKrVAsMR6no=; b=Fq2pDDW7lo9B7WDNIfPZE7H/KDwo5bbDppjPjsWZRcIKn83bA66I8a8xFgiX1H8wZOyOfv ElMGtGLtRTyb+YiZqCsSneSy49LLzt7VCJZFPw2EjyaQh2kTGtq/yQybeDilYfBdrA3MNC H5TXc6asyurlucoZQNDQxtJVD5snQi4= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-423-xKrN54bXPC2UG-ZKOPeI-Q-1; Mon, 11 Sep 2023 12:39:44 -0400 X-MC-Unique: xKrN54bXPC2UG-ZKOPeI-Q-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4259E38149A3; Mon, 11 Sep 2023 16:39:27 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2A2672156701; Mon, 11 Sep 2023 16:39:27 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id A183A1946A4F; Mon, 11 Sep 2023 16:39:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id C85631946597 for ; Mon, 11 Sep 2023 16:39:24 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id BBE9821B2414; Mon, 11 Sep 2023 16:39:24 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast09.extmail.prod.ext.rdu2.redhat.com [10.11.55.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B3E9721B2413 for ; Mon, 11 Sep 2023 16:39:24 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-inbound-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 71A2D29DD9A2 for ; Mon, 11 Sep 2023 16:39:24 +0000 (UTC) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-605-aBHkQYF9MJiSYMmb96-paA-1; Mon, 11 Sep 2023 12:39:20 -0400 X-MC-Unique: aBHkQYF9MJiSYMmb96-paA-1 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 2C3D921875; Mon, 11 Sep 2023 16:39:19 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id E5F86139CC; Mon, 11 Sep 2023 16:39:18 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id qASBNrZC/2RzEAAAMHmgww (envelope-from ); Mon, 11 Sep 2023 16:39:18 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Mon, 11 Sep 2023 18:38:27 +0200 Message-ID: <20230911163846.27197-19-mwilck@suse.com> In-Reply-To: <20230911163846.27197-1-mwilck@suse.com> References: <20230911163846.27197-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Subject: [dm-devel] [PATCH v2 18/37] libmultipath: keep bindings in memory X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dm-devel@redhat.com, Martin Wilck Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: suse.com From: Martin Wilck Rather than opening the bindings file every time we must retrieve a binding, keep the contents in memory and write the file only if additions have been made. This simplifies the code, and should speed up alias lookups significantly. As a side effect, the aliases will be stored sorted by alias, which changes the way aliases are allocated if there are unused "holes" in the sequence of aliases. For example, if the bindings file contains mpathb, mpathy, and mpatha, in this order, the next new alias used to be mpathz and is now mpathc. Another side effect is that multipathd will not automatically pick up changes to the bindings file at runtime without a reconfigure operation. It is questionable whether these on-the-fly changes were a good idea in the first place, as inconsistent configurations may easily come to pass. It desired, it would be feasible to implement automatic update of the bindings using the existing inotify approach. The new implementation of get_user_friendly_alias() is slightly different than before. The logic is summarized in a comment in the code. Unit tests will be provided that illustrate the changes. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/alias.c | 359 ++++++++++++++++----------------------- libmultipath/alias.h | 2 +- libmultipath/configure.c | 3 +- 3 files changed, 148 insertions(+), 216 deletions(-) diff --git a/libmultipath/alias.c b/libmultipath/alias.c index ad83ca0..d656374 100644 --- a/libmultipath/alias.c +++ b/libmultipath/alias.c @@ -50,8 +50,6 @@ "# alias wwid\n" \ "#\n" -static const char bindings_file_header[] = BINDINGS_FILE_HEADER; - struct binding { char *alias; char *wwid; @@ -80,6 +78,45 @@ static void _free_binding(struct binding *bdg) free(bdg); } +static const struct binding *get_binding_for_alias(const Bindings *bindings, + const char *alias) +{ + const struct binding *bdg; + int i; + + if (!alias) + return NULL; + vector_foreach_slot(bindings, bdg, i) { + if (!strncmp(bdg->alias, alias, WWID_SIZE)) { + condlog(3, "Found matching alias [%s] in bindings file." + " Setting wwid to %s", alias, bdg->wwid); + return bdg; + } + } + + condlog(3, "No matching alias [%s] in bindings file.", alias); + return NULL; +} + +static const struct binding *get_binding_for_wwid(const Bindings *bindings, + const char *wwid) +{ + const struct binding *bdg; + int i; + + if (!wwid) + return NULL; + vector_foreach_slot(bindings, bdg, i) { + if (!strncmp(bdg->wwid, wwid, WWID_SIZE)) { + condlog(3, "Found matching wwid [%s] in bindings file." + " Setting alias to %s", wwid, bdg->alias); + return bdg; + } + } + condlog(3, "No matching wwid [%s] in bindings file.", wwid); + return NULL; +} + static int add_binding(Bindings *bindings, const char *alias, const char *wwid) { struct binding *bdg; @@ -115,6 +152,24 @@ static int add_binding(Bindings *bindings, const char *alias, const char *wwid) return BINDING_ERROR; } +static int delete_binding(Bindings *bindings, const char *wwid) +{ + struct binding *bdg; + int i; + + vector_foreach_slot(bindings, bdg, i) { + if (!strncmp(bdg->wwid, wwid, WWID_SIZE)) { + _free_binding(bdg); + break; + } + } + if (i >= VECTOR_SIZE(bindings)) + return BINDING_NOTFOUND; + + vector_del_slot(bindings, i); + return BINDING_DELETED; +} + static int write_bindings_file(const Bindings *bindings, int fd) { struct binding *bnd; @@ -267,38 +322,15 @@ static bool id_already_taken(int id, const char *prefix, const char *map_wwid) return alias_already_taken(alias, map_wwid); } -/* - * Returns: 0 if matching entry in WWIDs file found - * -1 if an error occurs - * >0 a free ID that could be used for the WWID at hand - * *map_alias is set to a freshly allocated string with the matching alias if - * the function returns 0, or to NULL otherwise. - */ -static int -lookup_binding(FILE *f, const char *map_wwid, char **map_alias, - const char *prefix, int check_if_taken) +int get_free_id(const Bindings *bindings, const char *prefix, const char *map_wwid) { - char buf[LINE_MAX]; - unsigned int line_nr = 0; - int id = 1; + const struct binding *bdg; + int i, id = 1; int biggest_id = 1; int smallest_bigger_id = INT_MAX; - *map_alias = NULL; - - rewind(f); - while (fgets(buf, LINE_MAX, f)) { - const char *alias, *wwid; - char *c, *saveptr; - int curr_id; - - line_nr++; - c = strpbrk(buf, "#\n\r"); - if (c) - *c = '\0'; - alias = strtok_r(buf, " \t", &saveptr); - if (!alias) /* blank line */ - continue; + vector_foreach_slot(bindings, bdg, i) { + int curr_id = scan_devname(bdg->alias, prefix); /* * Find an unused index - explanation of the algorithm @@ -333,8 +365,6 @@ lookup_binding(FILE *f, const char *map_wwid, char **map_alias, * biggest_id is always > smallest_bigger_id, except in the * "perfectly ordered" case. */ - - curr_id = scan_devname(alias, prefix); if (curr_id == id) { if (id < INT_MAX) id++; @@ -345,36 +375,15 @@ lookup_binding(FILE *f, const char *map_wwid, char **map_alias, } if (curr_id > biggest_id) biggest_id = curr_id; + if (curr_id > id && curr_id < smallest_bigger_id) smallest_bigger_id = curr_id; - wwid = strtok_r(NULL, " \t", &saveptr); - if (!wwid){ - condlog(3, - "Ignoring malformed line %u in bindings file", - line_nr); - continue; - } - if (strcmp(wwid, map_wwid) == 0){ - condlog(3, "Found matching wwid [%s] in bindings file." - " Setting alias to %s", wwid, alias); - *map_alias = strdup(alias); - if (*map_alias == NULL) { - condlog(0, "Cannot copy alias from bindings " - "file: out of memory"); - return -1; - } - return 0; - } } - if (!prefix && check_if_taken) - id = -1; - if (id >= smallest_bigger_id) { - if (biggest_id < INT_MAX) - id = biggest_id + 1; - else - id = -1; - } - if (id > 0 && check_if_taken) { + + if (id >= smallest_bigger_id) + id = biggest_id < INT_MAX ? biggest_id + 1 : -1; + + if (id > 0) { while(id_already_taken(id, prefix, map_wwid)) { if (id == INT_MAX) { id = -1; @@ -391,64 +400,17 @@ lookup_binding(FILE *f, const char *map_wwid, char **map_alias, } } } - if (id < 0) { + + if (id < 0) condlog(0, "no more available user_friendly_names"); - return -1; - } else - condlog(3, "No matching wwid [%s] in bindings file.", map_wwid); return id; } -static int -rlookup_binding(FILE *f, char *buff, const char *map_alias) -{ - char line[LINE_MAX]; - unsigned int line_nr = 0; - - buff[0] = '\0'; - - while (fgets(line, LINE_MAX, f)) { - char *c, *saveptr; - const char *alias, *wwid; - - line_nr++; - c = strpbrk(line, "#\n\r"); - if (c) - *c = '\0'; - alias = strtok_r(line, " \t", &saveptr); - if (!alias) /* blank line */ - continue; - wwid = strtok_r(NULL, " \t", &saveptr); - if (!wwid){ - condlog(3, - "Ignoring malformed line %u in bindings file", - line_nr); - continue; - } - if (strlen(wwid) > WWID_SIZE - 1) { - condlog(3, - "Ignoring too large wwid at %u in bindings file", line_nr); - continue; - } - if (strcmp(alias, map_alias) == 0){ - condlog(3, "Found matching alias [%s] in bindings file." - " Setting wwid to %s", alias, wwid); - strlcpy(buff, wwid, WWID_SIZE); - return 0; - } - } - condlog(3, "No matching alias [%s] in bindings file.", map_alias); - - return -1; -} - static char * -allocate_binding(int fd, const char *wwid, int id, const char *prefix) +allocate_binding(const char *filename, const char *wwid, int id, const char *prefix) { STRBUF_ON_STACK(buf); - off_t offset; - ssize_t len; - char *alias, *c; + char *alias; if (id <= 0) { condlog(0, "%s: cannot allocate new binding for id %d", @@ -460,164 +422,135 @@ allocate_binding(int fd, const char *wwid, int id, const char *prefix) format_devname(&buf, id) == -1) return NULL; - if (print_strbuf(&buf, " %s\n", wwid) < 0) - return NULL; - - offset = lseek(fd, 0, SEEK_END); - if (offset < 0){ - condlog(0, "Cannot seek to end of bindings file : %s", - strerror(errno)); - return NULL; - } - - len = get_strbuf_len(&buf); alias = steal_strbuf_str(&buf); - if (write(fd, alias, len) != len) { - condlog(0, "Cannot write binding to bindings file : %s", - strerror(errno)); - /* clear partial write */ - if (ftruncate(fd, offset)) - condlog(0, "Cannot truncate the header : %s", - strerror(errno)); + if (add_binding(&global_bindings, alias, wwid) != BINDING_ADDED) { + condlog(0, "%s: cannot allocate new binding %s for %s", + __func__, alias, wwid); + free(alias); + return NULL; + } + + if (update_bindings_file(&global_bindings, filename) == -1) { + condlog(1, "%s: deleting binding %s for %s", __func__, alias, wwid); + delete_binding(&global_bindings, wwid); free(alias); return NULL; } - c = strchr(alias, ' '); - if (c) - *c = '\0'; condlog(3, "Created new binding [%s] for WWID [%s]", alias, wwid); return alias; } +/* + * get_user_friendly_alias() action table + * + * The table shows the various cases, the actions taken, and the CI + * functions from tests/alias.c that represent them. + * + * - O: old alias given + * - A: old alias in table (y: yes, correct WWID; X: yes, wrong WWID) + * - W: wwid in table + * + * | No | O | A | W | action | function gufa_X | + * |----+---+---+---+--------------------------------------------+------------------------------| + * | 1 | n | - | n | get new alias | nomatch_Y | + * | 2 | n | - | y | use alias from bindings | match_a_Y | + * | 3 | y | n | n | add binding for old alias | old_nomatch_nowwidmatch | + * | 4 | y | n | y | use alias from bindings (avoid duplicates) | old_nomatch_wwidmatch | + * | 5 | y | y | n | [ impossible ] | - | + * | 6 | y | y | y | use old alias == alias from bindings | old_match | + * | 7 | y | X | n | get new alias | old_match_other | + * | 8 | y | X | y | use alias from bindings | old_match_other_wwidmatch | + * + * Notes: + * - "use alias from bindings" means that the alias from the bindings file will + * be tried; if it is in use, the alias selection will fail. No other + * bindings will be attempted. + * - "get new alias" fails if all aliases are used up, or if writing the + * bindings file fails. + * - if "alias_old" is set, it can't be bound to a different map. alias_old is + * initialized in find_existing_alias() by scanning the mpvec. We trust + * that the mpvec corrcectly represents kernel state. + */ + char *get_user_friendly_alias(const char *wwid, const char *file, const char *alias_old, const char *prefix, bool bindings_read_only) { char *alias = NULL; int id = 0; - int fd, can_write; bool new_binding = false; - char buff[WWID_SIZE]; - FILE *f; + const struct binding *bdg; - fd = open_file(file, &can_write, bindings_file_header); - if (fd < 0) - return NULL; - - f = fdopen(fd, "r"); - if (!f) { - condlog(0, "cannot fdopen on bindings file descriptor"); - close(fd); - return NULL; - } - - if (!strlen(alias_old)) + if (!*alias_old) goto new_alias; - /* lookup the binding. if it exists, the wwid will be in buff - * either way, id contains the id for the alias - */ - rlookup_binding(f, buff, alias_old); - - if (strlen(buff) > 0) { - /* If buff is our wwid, it's already allocated correctly. */ - if (strcmp(buff, wwid) == 0) { + /* See if there's a binding matching both alias_old and wwid */ + bdg = get_binding_for_alias(&global_bindings, alias_old); + if (bdg) { + if (!strcmp(bdg->wwid, wwid)) { alias = strdup(alias_old); goto out; - } else { condlog(0, "alias %s already bound to wwid %s, cannot reuse", - alias_old, buff); - goto new_alias; ; + alias_old, bdg->wwid); + goto new_alias; } } - /* - * Look for an existing alias in the bindings file. - * Pass prefix = NULL, so lookup_binding() won't try to allocate a new id. - */ - lookup_binding(f, wwid, &alias, NULL, 0); - if (alias) { - if (alias_already_taken(alias, wwid)) { - free(alias); - alias = NULL; - } else - condlog(3, "Use existing binding [%s] for WWID [%s]", - alias, wwid); - goto out; - } - - /* alias_old is already taken by our WWID, update bindings file. */ + /* allocate the existing alias in the bindings file */ id = scan_devname(alias_old, prefix); new_alias: + /* Check for existing binding of WWID */ + bdg = get_binding_for_wwid(&global_bindings, wwid); + if (bdg) { + if (!alias_already_taken(bdg->alias, wwid)) { + condlog(3, "Use existing binding [%s] for WWID [%s]", + bdg->alias, wwid); + alias = strdup(bdg->alias); + } + goto out; + } + if (id <= 0) { /* * no existing alias was provided, or allocating it * failed. Try a new one. */ - id = lookup_binding(f, wwid, &alias, prefix, 1); - if (id == 0 && alias_already_taken(alias, wwid)) { - free(alias); - alias = NULL; - } + id = get_free_id(&global_bindings, prefix, wwid); if (id <= 0) goto out; else new_binding = true; } - if (fflush(f) != 0) { - condlog(0, "cannot fflush bindings file stream : %s", - strerror(errno)); - goto out; - } + if (!bindings_read_only && id > 0) + alias = allocate_binding(file, wwid, id, prefix); - if (can_write && !bindings_read_only) { - alias = allocate_binding(fd, wwid, id, prefix); - if (alias && !new_binding) - condlog(2, "Allocated existing binding [%s] for WWID [%s]", - alias, wwid); - } + if (alias && !new_binding) + condlog(2, "Allocated existing binding [%s] for WWID [%s]", + alias, wwid); out: - pthread_cleanup_push(free, alias); - fclose(f); - pthread_cleanup_pop(0); return alias; } -int -get_user_friendly_wwid(const char *alias, char *buff, const char *file) +int get_user_friendly_wwid(const char *alias, char *buff) { - int fd, unused; - FILE *f; + const struct binding *bdg; if (!alias || *alias == '\0') { condlog(3, "Cannot find binding for empty alias"); return -1; } - fd = open_file(file, &unused, bindings_file_header); - if (fd < 0) - return -1; - - f = fdopen(fd, "r"); - if (!f) { - condlog(0, "cannot fdopen on bindings file descriptor : %s", - strerror(errno)); - close(fd); + bdg = get_binding_for_alias(&global_bindings, alias); + if (!bdg) { + *buff = '\0'; return -1; } - - rlookup_binding(f, buff, alias); - if (!strlen(buff)) { - fclose(f); - return -1; - } - - fclose(f); + strlcpy(buff, bdg->wwid, WWID_SIZE); return 0; } diff --git a/libmultipath/alias.h b/libmultipath/alias.h index 37b49d9..5ef6720 100644 --- a/libmultipath/alias.h +++ b/libmultipath/alias.h @@ -2,7 +2,7 @@ #define _ALIAS_H int valid_alias(const char *alias); -int get_user_friendly_wwid(const char *alias, char *buff, const char *file); +int get_user_friendly_wwid(const char *alias, char *buff); char *get_user_friendly_alias(const char *wwid, const char *file, const char *alias_old, const char *prefix, bool bindings_read_only); diff --git a/libmultipath/configure.c b/libmultipath/configure.c index 029fbbd..d809490 100644 --- a/libmultipath/configure.c +++ b/libmultipath/configure.c @@ -1378,8 +1378,7 @@ static int _get_refwwid(enum mpath_cmds cmd, const char *dev, refwwid = tmpwwid; /* or may be a binding */ - else if (get_user_friendly_wwid(dev, tmpwwid, - conf->bindings_file) == 0) + else if (get_user_friendly_wwid(dev, tmpwwid) == 0) refwwid = tmpwwid; /* or may be an alias */ From patchwork Mon Sep 11 16:38:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13379511 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 04342EEB58C for ; Mon, 11 Sep 2023 16:39:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694450388; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=OG2d0CPDp9rATn2vV029FhAE8nmzpEOPjbGGFiyGwEA=; b=TWk3OJJ3nvt2xiZpCloqIkbUzbXjP8pIJcqr4CTF0QmGm3UNZYJJDUNCeHS+kO8TfWUuNi o/CiNdbz0NoFoomu2B0SjUnZd9rMHbie2TvTyxDwXpdSNIOTONK32oqZ0vEZ8/SZZGGK0X UvYEphb6/GOInG9uExb52bky+5IZLlY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-90-Bt_i4x2xNLueNLHEWxL-EA-1; Mon, 11 Sep 2023 12:39:43 -0400 X-MC-Unique: Bt_i4x2xNLueNLHEWxL-EA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5E87C101FAA0; Mon, 11 Sep 2023 16:39:26 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3FE182027047; Mon, 11 Sep 2023 16:39:26 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 2DF0E19465A2; Mon, 11 Sep 2023 16:39:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 3222A19465BC for ; Mon, 11 Sep 2023 16:39:23 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 139D82024CD5; Mon, 11 Sep 2023 16:39:23 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast09.extmail.prod.ext.rdu2.redhat.com [10.11.55.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0BE2B20268C8 for ; Mon, 11 Sep 2023 16:39:22 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CD97B29DD992 for ; Mon, 11 Sep 2023 16:39:22 +0000 (UTC) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-635-AkNIZelpOUGjHCmKkPOhtg-1; Mon, 11 Sep 2023 12:39:20 -0400 X-MC-Unique: AkNIZelpOUGjHCmKkPOhtg-1 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 9611E21882; Mon, 11 Sep 2023 16:39:19 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 40C2F139CC; Mon, 11 Sep 2023 16:39:19 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id OAkfDrdC/2RzEAAAMHmgww (envelope-from ); Mon, 11 Sep 2023 16:39:19 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Mon, 11 Sep 2023 18:38:28 +0200 Message-ID: <20230911163846.27197-20-mwilck@suse.com> In-Reply-To: <20230911163846.27197-1-mwilck@suse.com> References: <20230911163846.27197-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 Subject: [dm-devel] [PATCH v2 19/37] multipath-tools tests: fix alias tests X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dm-devel@redhat.com, Martin Wilck Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: suse.com From: Martin Wilck The different implementation of get_user_friendly_alias() and its helpers necessitates changes in the unit tests. It would be nice if it didn't, but the unit tests are too closely bound to the implementation to make this possible. - The bindings table is held in memory in alphabetically sorted order, which may change the result of looking for free alias IDs if the entries in the bindings file were unordered initially. In particular, if only a small number of bindings exists, "holes" in the file will be detected more easily. But because the sort order of the aliases differs from simple alphabetic sorting ("mpathz" precedes "mpathaa"), a bindings file that contains all bindings from "a" to "aa" (or more) will appear unsorted. As an extra check, some of the unit tests deliberately use a different implementation of add_binding() that does not order the bindings table. - Broken lines in the bindings file never make it to the in-memory representation. An alias that appeard "used" because it occurred in a broken line will not appear used any more. Warnings about malformed lines will only be printed while the bindings file is read, not from get_user_friendly_alias(). - The match_line argument of mock_bindings_file() is obsolete. - lookup_binding() and rlookup_binding() have been removed from libmultipath. They are now emulated in the unit test code. - lookup_binding() didn't check for used alias in all cases previously, but it does now. - prefix != NULL and check_if_taken == false is not supported any more in lookup_binding(). - allocate_binding() uses a very different sequence of systems calls now, as it's implemented using update_bindings_file(). In particular, it's now more difficult to predict the content of the write() call that creates the bindings file. See comments for __wrap_write(). - some unit tests for get_user_friendly_alias() had to call mock_bindings_file() twice, because the old implementation would read the file twice (first rlookup_binding() and then lookup_binding()). This is not necessary any more. - The unit tests need a teardown function to clear the bindings table in memory. - Minor changes are necessary because of changed ordering of the log messages. Previously, lookup_binding() combined check for an existing entry and the search for a new ID. The new algorithm does this in two separate steps and tests for used aliases in between, which causes a change in the order in which log messages are emitted. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- tests/alias.c | 971 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 621 insertions(+), 350 deletions(-) diff --git a/tests/alias.c b/tests/alias.c index f334f92..50a21ec 100644 --- a/tests/alias.c +++ b/tests/alias.c @@ -3,10 +3,12 @@ #include #include #include +#include "strbuf.h" #include "util.h" #include "alias.h" #include "test-log.h" #include +#include #include "globals.c" #include "../libmultipath/alias.c" @@ -20,18 +22,6 @@ #define MPATH_ID_INT_MAX_p1 "fxshrxx" #endif -void __wrap_rewind(FILE *stream) -{} - -char *__wrap_fgets(char *buf, int n, FILE *stream) -{ - char *val = mock_ptr_type(char *); - if (!val) - return NULL; - strlcpy(buf, val, n); - return buf; -} - static int __set_errno(int err) { if (err >= 0) { @@ -43,25 +33,46 @@ static int __set_errno(int err) } } -off_t __wrap_lseek(int fd, off_t offset, int whence) -{ - return __set_errno(mock_type(int)); - -} - +/* + * allocate_binding -> write_bindings_file() writes the entire file, i.e. the + * header, any pre-existing bindings, and the new binding. The complete content + * depends on history and is different to predict here. Therefore we check only + * the newly added binding. Because add_binding() sorts entries, this new + * binding isn't necessarily the last one; receive it from will_return() and + * search for it with strstr(). + * If the string to be written doesn't start with the bindings file + * header, it's a test of a partial write. + */ ssize_t __wrap_write(int fd, const void *buf, size_t count) { + const char *binding, *start; + +#if DEBUG_WRITE + fprintf(stderr, "%s: %zx exp %zx\n===\n%s\n===\n", __func__, strlen(buf), + count, (const char *)buf); +#endif + if (!strncmp((const char *)buf, BINDINGS_FILE_HEADER, + sizeof(BINDINGS_FILE_HEADER) - 1)) + start = (const char *)buf + sizeof(BINDINGS_FILE_HEADER) - 1; + else + start = buf; + binding = mock_ptr_type(char *); + start = strstr(start, binding); check_expected(count); - check_expected(buf); + assert_ptr_not_equal(start, NULL); return __set_errno(mock_type(int)); } -int __wrap_ftruncate(int fd, off_t length) +int __wrap_rename(const char *old, const char *new) { - check_expected(length); return __set_errno(mock_type(int)); } +int __wrap_mkstemp(char *template) +{ + return 10; +} + int __wrap_dm_map_present(const char * str) { check_expected(str); @@ -84,32 +95,6 @@ int __wrap_dm_get_uuid(const char *name, char *uuid, int uuid_len) #define TEST_FDNO 1234 #define TEST_FPTR ((FILE *) 0xaffe) -int __wrap_open_file(const char *file, int *can_write, const char *header) -{ - int cw = mock_type(int); - - *can_write = cw; - return TEST_FDNO; -} - -FILE *__wrap_fdopen(int fd, const char *mode) -{ - assert_int_equal(fd, TEST_FDNO); - return TEST_FPTR; -} - -int __wrap_fflush(FILE *f) -{ - assert_ptr_equal(f, TEST_FPTR); - return 0; -} - -int __wrap_fclose(FILE *f) -{ - assert_ptr_equal(f, TEST_FPTR); - return 0; -} - /* strbuf wrapper for the old format_devname() */ static int __format_devname(char *name, int id, size_t len, const char *prefix) { @@ -466,22 +451,85 @@ static void mock_self_alias(const char *alias, const char *wwid) expect_condlog(3, USED_STR(alias, wwid)); \ } while(0) -static void mock_bindings_file(const char *content, int match_line) +static int add_binding_unsorted(Bindings *bindings, + const char *alias, const char *wwid) { - static char cnt[1024]; - char *token; + struct binding *bdg = calloc(1, sizeof(*bdg)); + + if (!bdg) + return -1; + bdg->wwid = strdup(wwid); + bdg->alias = strdup(alias); + if (!bdg->wwid || !bdg->alias || !vector_alloc_slot(bindings)) { + free(bdg->alias); + free(bdg->wwid); + free(bdg); + return BINDING_ERROR; + } + vector_set_slot(bindings, bdg); + return BINDING_ADDED; +} + +static void __mock_bindings_file(const char *content, + int (*add)(Bindings *, const char *, const char *)) +{ + char *cnt __attribute__((cleanup(cleanup_charp))) = NULL; + char *token, *savep = NULL; int i; - assert_in_range(strlcpy(cnt, content, sizeof(cnt)), 0, sizeof(cnt) - 1); + cnt = strdup(content); + assert_ptr_not_equal(cnt, NULL); - for (token = strtok(cnt, "\n"), i = 0; + for (token = strtok_r(cnt, "\n", &savep), i = 0; token && *token; - token = strtok(NULL, "\n"), i++) { - will_return(__wrap_fgets, token); - if (match_line == i) - return; + token = strtok_r(NULL, "\n", &savep), i++) { + char *alias, *wwid; + int rc; + + if (read_binding(token, i + 1, &alias, &wwid) + == READ_BINDING_SKIP) + continue; + + rc = add(&global_bindings, alias, wwid); + assert_int_equal(rc, BINDING_ADDED); } - will_return(__wrap_fgets, NULL); +} + +static void mock_bindings_file(const char *content) { + return __mock_bindings_file(content, add_binding); +} + +static void mock_bindings_file_unsorted(const char *content) { + return __mock_bindings_file(content, add_binding_unsorted); +} + +static int teardown_bindings(void **state) +{ + cleanup_bindings(); + return 0; +} + +static int lookup_binding(FILE *dummy, const char *wwid, char **alias, + const char *prefix, int check_if_taken) +{ + const struct binding *bdg; + int id; + + /* + * get_free_id() always checks if aliases are taken. + * Therefore if prefix is non-null, check_if_taken must be true. + */ + assert_true(!prefix || check_if_taken); + *alias = NULL; + bdg = get_binding_for_wwid(&global_bindings, wwid); + if (bdg) { + *alias = strdup(bdg->alias); + return 0; + } else if (!prefix && check_if_taken) + return -1; + + id = get_free_id(&global_bindings, prefix, wwid); + return id; } static void lb_empty(void **state) @@ -489,7 +537,7 @@ static void lb_empty(void **state) int rc; char *alias; - mock_bindings_file("", -1); + mock_bindings_file(""); expect_condlog(3, NOMATCH_WWID_STR("WWID0")); rc = lookup_binding(NULL, "WWID0", &alias, NULL, 0); assert_int_equal(rc, 1); @@ -501,7 +549,7 @@ static void lb_empty_unused(void **state) int rc; char *alias; - mock_bindings_file("", -1); + mock_bindings_file(""); mock_unused_alias("MPATHa"); expect_condlog(3, NOMATCH_WWID_STR("WWID0")); rc = lookup_binding(NULL, "WWID0", &alias, "MPATH", 1); @@ -515,10 +563,10 @@ static void lb_empty_failed(void **state) int rc; char *alias; - mock_bindings_file("", -1); + mock_bindings_file(""); + expect_condlog(3, NOMATCH_WWID_STR("WWID0")); mock_failed_alias("MPATHa", "WWID0"); mock_unused_alias("MPATHb"); - expect_condlog(3, NOMATCH_WWID_STR("WWID0")); rc = lookup_binding(NULL, "WWID0", &alias, "MPATH", 1); assert_int_equal(rc, 2); assert_ptr_equal(alias, NULL); @@ -530,10 +578,10 @@ static void lb_empty_1_used(void **state) int rc; char *alias; - mock_bindings_file("", -1); + mock_bindings_file(""); + expect_condlog(3, NOMATCH_WWID_STR("WWID0")); mock_used_alias("MPATHa", "WWID0"); mock_unused_alias("MPATHb"); - expect_condlog(3, NOMATCH_WWID_STR("WWID0")); rc = lookup_binding(NULL, "WWID0", &alias, "MPATH", 1); assert_int_equal(rc, 2); assert_ptr_equal(alias, NULL); @@ -545,10 +593,10 @@ static void lb_empty_1_used_self(void **state) int rc; char *alias; - mock_bindings_file("", -1); + mock_bindings_file(""); + expect_condlog(3, NOMATCH_WWID_STR("WWID0")); mock_used_alias("MPATHa", "WWID0"); mock_self_alias("MPATHb", "WWID0"); - expect_condlog(3, NOMATCH_WWID_STR("WWID0")); rc = lookup_binding(NULL, "WWID0", &alias, "MPATH", 1); assert_int_equal(rc, 2); assert_ptr_equal(alias, NULL); @@ -560,9 +608,9 @@ static void lb_match_a(void **state) int rc; char *alias; - mock_bindings_file("MPATHa WWID0\n", 0); + mock_bindings_file("MPATHa WWID0\n"); expect_condlog(3, FOUND_STR("MPATHa", "WWID0")); - rc = lookup_binding(NULL, "WWID0", &alias, "MPATH", 0); + rc = lookup_binding(NULL, "WWID0", &alias, "MPATH", 1); assert_int_equal(rc, 0); assert_ptr_not_equal(alias, NULL); assert_string_equal(alias, "MPATHa"); @@ -574,9 +622,10 @@ static void lb_nomatch_a(void **state) int rc; char *alias; - mock_bindings_file("MPATHa WWID0\n", -1); + mock_bindings_file("MPATHa WWID0\n"); expect_condlog(3, NOMATCH_WWID_STR("WWID1")); - rc = lookup_binding(NULL, "WWID1", &alias, "MPATH", 0); + mock_unused_alias("MPATHb"); + rc = lookup_binding(NULL, "WWID1", &alias, "MPATH", 1); assert_int_equal(rc, 2); assert_ptr_equal(alias, NULL); } @@ -586,8 +635,8 @@ static void lb_nomatch_a_bad_check(void **state) int rc; char *alias; - mock_bindings_file("MPATHa WWID0\n", -1); - expect_condlog(0, NOMORE_STR); + mock_bindings_file("MPATHa WWID0\n"); + expect_condlog(3, NOMATCH_WWID_STR("WWID1")); rc = lookup_binding(NULL, "WWID1", &alias, NULL, 1); assert_int_equal(rc, -1); assert_ptr_equal(alias, NULL); @@ -598,7 +647,7 @@ static void lb_nomatch_a_unused(void **state) int rc; char *alias; - mock_bindings_file("MPATHa WWID0\n", -1); + mock_bindings_file("MPATHa WWID0\n"); mock_unused_alias("MPATHb"); expect_condlog(3, NOMATCH_WWID_STR("WWID1")); rc = lookup_binding(NULL, "WWID1", &alias, "MPATH", 1); @@ -611,27 +660,27 @@ static void lb_nomatch_a_3_used_failed_self(void **state) int rc; char *alias; - mock_bindings_file("MPATHa WWID0\n", -1); + mock_bindings_file("MPATHa WWID0\n"); + expect_condlog(3, NOMATCH_WWID_STR("WWID1")); mock_used_alias("MPATHb", "WWID1"); mock_used_alias("MPATHc", "WWID1"); mock_used_alias("MPATHd", "WWID1"); mock_failed_alias("MPATHe", "WWID1"); mock_self_alias("MPATHf", "WWID1"); - expect_condlog(3, NOMATCH_WWID_STR("WWID1")); rc = lookup_binding(NULL, "WWID1", &alias, "MPATH", 1); assert_int_equal(rc, 6); assert_ptr_equal(alias, NULL); } -static void do_lb_match_c(void **state, int check_if_taken) +static void do_lb_match_c(void **state) { int rc; char *alias; mock_bindings_file("MPATHa WWID0\n" - "MPATHc WWID1", 1); + "MPATHc WWID1"); expect_condlog(3, FOUND_STR("MPATHc", "WWID1")); - rc = lookup_binding(NULL, "WWID1", &alias, "MPATH", check_if_taken); + rc = lookup_binding(NULL, "WWID1", &alias, "MPATH", 1); assert_int_equal(rc, 0); assert_ptr_not_equal(alias, NULL); assert_string_equal(alias, "MPATHc"); @@ -640,12 +689,12 @@ static void do_lb_match_c(void **state, int check_if_taken) static void lb_match_c(void **state) { - do_lb_match_c(state, 0); + do_lb_match_c(state); } static void lb_match_c_check(void **state) { - do_lb_match_c(state, 1); + do_lb_match_c(state); } static void lb_nomatch_a_c(void **state) @@ -654,9 +703,10 @@ static void lb_nomatch_a_c(void **state) char *alias; mock_bindings_file("MPATHa WWID0\n" - "MPATHc WWID1", -1); + "MPATHc WWID1"); expect_condlog(3, NOMATCH_WWID_STR("WWID2")); - rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 0); + mock_unused_alias("MPATHb"); + rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 1); assert_int_equal(rc, 2); assert_ptr_equal(alias, NULL); } @@ -667,7 +717,7 @@ static void lb_nomatch_a_d_unused(void **state) char *alias; mock_bindings_file("MPATHa WWID0\n" - "MPATHd WWID1", -1); + "MPATHd WWID1"); mock_unused_alias("MPATHb"); expect_condlog(3, NOMATCH_WWID_STR("WWID2")); rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 1); @@ -681,10 +731,10 @@ static void lb_nomatch_a_d_1_used(void **state) char *alias; mock_bindings_file("MPATHa WWID0\n" - "MPATHd WWID1", -1); + "MPATHd WWID1"); + expect_condlog(3, NOMATCH_WWID_STR("WWID2")); mock_used_alias("MPATHb", "WWID2"); mock_unused_alias("MPATHc"); - expect_condlog(3, NOMATCH_WWID_STR("WWID2")); rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 1); assert_int_equal(rc, 3); assert_ptr_equal(alias, NULL); @@ -696,11 +746,11 @@ static void lb_nomatch_a_d_2_used(void **state) char *alias; mock_bindings_file("MPATHa WWID0\n" - "MPATHd WWID1", -1); + "MPATHd WWID1"); + expect_condlog(3, NOMATCH_WWID_STR("WWID2")); mock_used_alias("MPATHb", "WWID2"); mock_used_alias("MPATHc", "WWID2"); mock_unused_alias("MPATHe"); - expect_condlog(3, NOMATCH_WWID_STR("WWID2")); rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 1); assert_int_equal(rc, 5); assert_ptr_equal(alias, NULL); @@ -712,12 +762,12 @@ static void lb_nomatch_a_d_3_used(void **state) char *alias; mock_bindings_file("MPATHa WWID0\n" - "MPATHd WWID1", -1); + "MPATHd WWID1"); + expect_condlog(3, NOMATCH_WWID_STR("WWID2")); mock_used_alias("MPATHb", "WWID2"); mock_used_alias("MPATHc", "WWID2"); mock_used_alias("MPATHe", "WWID2"); mock_unused_alias("MPATHf"); - expect_condlog(3, NOMATCH_WWID_STR("WWID2")); rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 1); assert_int_equal(rc, 6); assert_ptr_equal(alias, NULL); @@ -729,9 +779,10 @@ static void lb_nomatch_c_a(void **state) char *alias; mock_bindings_file("MPATHc WWID1\n" - "MPATHa WWID0\n", -1); + "MPATHa WWID0\n"); + mock_unused_alias("MPATHb"); expect_condlog(3, NOMATCH_WWID_STR("WWID2")); - rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 0); + rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 1); assert_int_equal(rc, 2); assert_ptr_equal(alias, NULL); } @@ -743,7 +794,7 @@ static void lb_nomatch_d_a_unused(void **state) mock_bindings_file("MPATHc WWID1\n" "MPATHa WWID0\n" - "MPATHd WWID0\n", -1); + "MPATHd WWID0\n"); mock_unused_alias("MPATHb"); expect_condlog(3, NOMATCH_WWID_STR("WWID2")); rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 1); @@ -758,10 +809,10 @@ static void lb_nomatch_d_a_1_used(void **state) mock_bindings_file("MPATHc WWID1\n" "MPATHa WWID0\n" - "MPATHd WWID0\n", -1); + "MPATHd WWID0\n"); + expect_condlog(3, NOMATCH_WWID_STR("WWID2")); mock_used_alias("MPATHb", "WWID2"); mock_unused_alias("MPATHe"); - expect_condlog(3, NOMATCH_WWID_STR("WWID2")); rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 1); assert_int_equal(rc, 5); assert_ptr_equal(alias, NULL); @@ -774,9 +825,10 @@ static void lb_nomatch_a_b(void **state) mock_bindings_file("MPATHa WWID0\n" "MPATHz WWID26\n" - "MPATHb WWID1\n", -1); + "MPATHb WWID1\n"); expect_condlog(3, NOMATCH_WWID_STR("WWID2")); - rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 0); + mock_unused_alias("MPATHc"); + rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 1); assert_int_equal(rc, 3); assert_ptr_equal(alias, NULL); } @@ -786,13 +838,19 @@ static void lb_nomatch_a_b_bad(void **state) int rc; char *alias; + expect_condlog(1, "invalid line 3 in bindings file, missing WWID\n"); + /* + * The broken line will be ignored when constructing the bindings vector. + * Thus in lookup_binding() MPATHb is never encountered, + * and MPATHb appears usable. + */ mock_bindings_file("MPATHa WWID0\n" "MPATHz WWID26\n" - "MPATHb\n", -1); - expect_condlog(3, "Ignoring malformed line 3 in bindings file\n"); + "MPATHb\n"); expect_condlog(3, NOMATCH_WWID_STR("WWID2")); - rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 0); - assert_int_equal(rc, 3); + mock_unused_alias("MPATHb"); + rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 1); + assert_int_equal(rc, 2); assert_ptr_equal(alias, NULL); } @@ -801,28 +859,140 @@ static void lb_nomatch_a_b_bad_self(void **state) int rc; char *alias; + expect_condlog(1, "invalid line 3 in bindings file, missing WWID\n"); mock_bindings_file("MPATHa WWID0\n" "MPATHz WWID26\n" - "MPATHb\n", -1); - expect_condlog(3, "Ignoring malformed line 3 in bindings file\n"); - mock_self_alias("MPATHc", "WWID2"); + "MPATHb\n"); expect_condlog(3, NOMATCH_WWID_STR("WWID2")); + mock_self_alias("MPATHb", "WWID2"); + rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 1); + assert_int_equal(rc, 2); + assert_ptr_equal(alias, NULL); +} + +static void lb_nomatch_b_z_a(void **state) +{ + int rc; + char *alias; + + /* + * add_bindings() sorts alphabetically. Therefore get_free_id() + * finds MPATHc as a free entry. + */ + mock_bindings_file("MPATHb WWID1\n" + "MPATHz WWID26\n" + "MPATHa WWID0\n"); + expect_condlog(3, NOMATCH_WWID_STR("WWID2")); + mock_unused_alias("MPATHc"); rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 1); assert_int_equal(rc, 3); assert_ptr_equal(alias, NULL); } +static void lb_nomatch_b_aa_a(void **state) +{ + int rc; + char *alias; + + /* + * add_bindings() sorts alphabetically. ("a", "aa", b"). + * The get_free_id() algorithm finds the "hole" after "b". + */ + mock_bindings_file("MPATHb WWID1\n" + "MPATHz WWID26\n" + "MPATHa WWID0\n"); + expect_condlog(3, NOMATCH_WWID_STR("WWID2")); + mock_unused_alias("MPATHc"); + rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 1); + assert_int_equal(rc, 3); + assert_ptr_equal(alias, NULL); +} + +static void fill_bindings(struct strbuf *buf, int start, int end) +{ + int i; + + for (i = start; i <= end; i++) { + print_strbuf(buf, "MPATH"); + format_devname(buf, i + 1); + print_strbuf(buf, " WWID%d\n", i); + } +} + +static void lb_nomatch_b_a_aa(void **state) +{ + int rc; + char *alias; + STRBUF_ON_STACK(buf); + + /* + * add_bindings() sorts alphabetically. ("a", "aa", "ab", "b", "c", ...) + * lookup_binding finds MPATHac as next free entry. + */ + fill_bindings(&buf, 0, 26); + mock_bindings_file(get_strbuf_str(&buf)); + expect_condlog(3, NOMATCH_WWID_STR("WWID28")); + mock_unused_alias("MPATHab"); + rc = lookup_binding(NULL, "WWID28", &alias, "MPATH", 1); + assert_int_equal(rc, 28); + assert_ptr_equal(alias, NULL); +} + +static void lb_nomatch_b_a_aa_zz(void **state) +{ + int rc, i; + char *alias; + STRBUF_ON_STACK(buf); + + /* + * add_bindings() sorts alphabetically. ("a", "aa", "ab", "b", "c", ...) + * lookup_binding finds MPATHaaa as next free entry, because MPATHaa is + * found before MPATHb, and MPATHzz was in the bindings, too. + */ + for (i = 0; i <= 26; i++) { + print_strbuf(&buf, "MPATH"); + format_devname(&buf, i + 1); + print_strbuf(&buf, " WWID%d\n", i); + } + print_strbuf(&buf, "MPATHzz WWID676\n"); + mock_bindings_file(get_strbuf_str(&buf)); + expect_condlog(3, NOMATCH_WWID_STR("WWID703")); + mock_unused_alias("MPATHaaa"); + rc = lookup_binding(NULL, "WWID703", &alias, "MPATH", 1); + assert_int_equal(rc, 703); + assert_ptr_equal(alias, NULL); +} + +static void lb_nomatch_b_z_a_unsorted(void **state) +{ + int rc; + char *alias; + + /* + * With unsorted bindings (shouldn't happen normally), get_free_id() + * plays safe and returns MPATHaa as first free entry. + */ + mock_bindings_file_unsorted("MPATHb WWID1\n" + "MPATHz WWID26\n" + "MPATHa WWID0\n"); + expect_condlog(3, NOMATCH_WWID_STR("WWID2")); + mock_unused_alias("MPATHaa"); + rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 1); + assert_int_equal(rc, 27); + assert_ptr_equal(alias, NULL); +} + static void lb_nomatch_b_a(void **state) { int rc; char *alias; mock_bindings_file("MPATHb WWID1\n" - "MPATHz WWID26\n" - "MPATHa WWID0\n", -1); + "MPATHa WWID0\n"); expect_condlog(3, NOMATCH_WWID_STR("WWID2")); - rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 0); - assert_int_equal(rc, 27); + mock_unused_alias("MPATHc"); + rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 1); + assert_int_equal(rc, 3); assert_ptr_equal(alias, NULL); } @@ -830,55 +1000,59 @@ static void lb_nomatch_b_a_3_used(void **state) { int rc; char *alias; + STRBUF_ON_STACK(buf); - mock_bindings_file("MPATHb WWID1\n" - "MPATHz WWID26\n" - "MPATHa WWID0\n", -1); - mock_used_alias("MPATHaa", "WWID2"); - mock_used_alias("MPATHab", "WWID2"); - mock_used_alias("MPATHac", "WWID2"); - mock_unused_alias("MPATHad"); - expect_condlog(3, NOMATCH_WWID_STR("WWID2")); - rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 1); - assert_int_equal(rc, 30); + fill_bindings(&buf, 0, 26); + mock_bindings_file(get_strbuf_str(&buf)); + expect_condlog(3, NOMATCH_WWID_STR("WWID31")); + mock_used_alias("MPATHab", "WWID31"); + mock_used_alias("MPATHac", "WWID31"); + mock_used_alias("MPATHad", "WWID31"); + mock_unused_alias("MPATHae"); + rc = lookup_binding(NULL, "WWID31", &alias, "MPATH", 1); + assert_int_equal(rc, 31); assert_ptr_equal(alias, NULL); } #ifdef MPATH_ID_INT_MAX -static void do_lb_nomatch_int_max(void **state, int check_if_taken) +/* + * The bindings will be sorted by alias, alphabetically, which is not + * the same as the "numeric" sort order for user-friendly aliases. + * get_free_id() selects the highest used ID + 1 if an unsorted entry + * is encountered in the bindings table and it's id is equal to the + * next "expected" id. This happens if all IDs from "a" to "aa" are + * in the table. If the INT_MAX entry is in the table, too, it will + * overflow. + */ +static void lb_nomatch_int_max(void **state) { int rc; char *alias; + STRBUF_ON_STACK(buf); - mock_bindings_file("MPATHb WWID1\n" - "MPATH" MPATH_ID_INT_MAX " WWIDMAX\n" - "MPATHa WWID0\n", -1); + fill_bindings(&buf, 0, 26); + print_strbuf(&buf, "MPATH%s WWIDMAX\n", MPATH_ID_INT_MAX); + mock_bindings_file(get_strbuf_str(&buf)); + expect_condlog(3, NOMATCH_WWID_STR("WWIDNOMORE")); expect_condlog(0, NOMORE_STR); - rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", check_if_taken); + rc = lookup_binding(NULL, "WWIDNOMORE", &alias, "MPATH", 1); assert_int_equal(rc, -1); assert_ptr_equal(alias, NULL); } -static void lb_nomatch_int_max(void **state) -{ - do_lb_nomatch_int_max(state, 0); -} - -static void lb_nomatch_int_max_check(void **state) -{ - do_lb_nomatch_int_max(state, 1); -} - static void lb_nomatch_int_max_used(void **state) { int rc; char *alias; + STRBUF_ON_STACK(buf); - mock_bindings_file("MPATHb WWID1\n" - "MPATH" MPATH_ID_INT_MAX " WWIDMAX\n", -1); - mock_used_alias("MPATHa", "WWID2"); + fill_bindings(&buf, 1, 26); + print_strbuf(&buf, "MPATH%s WWIDMAX\n", MPATH_ID_INT_MAX); + mock_bindings_file(get_strbuf_str(&buf)); + expect_condlog(3, NOMATCH_WWID_STR("WWIDNOMORE")); + mock_used_alias("MPATHa", "WWIDNOMORE"); expect_condlog(0, NOMORE_STR); - rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 1); + rc = lookup_binding(NULL, "WWIDNOMORE", &alias, "MPATH", 1); assert_int_equal(rc, -1); assert_ptr_equal(alias, NULL); } @@ -887,12 +1061,14 @@ static void lb_nomatch_int_max_m1(void **state) { int rc; char *alias; + STRBUF_ON_STACK(buf); - mock_bindings_file("MPATHb WWID1\n" - "MPATH" MPATH_ID_INT_MAX_m1 " WWIDMAX\n" - "MPATHa WWID0\n", -1); - expect_condlog(3, NOMATCH_WWID_STR("WWID2")); - rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 0); + fill_bindings(&buf, 0, 26); + print_strbuf(&buf, "MPATH%s WWIDMAXM1\n", MPATH_ID_INT_MAX_m1); + mock_bindings_file(get_strbuf_str(&buf)); + expect_condlog(3, NOMATCH_WWID_STR("WWIDMAX")); + mock_unused_alias("MPATH" MPATH_ID_INT_MAX); + rc = lookup_binding(NULL, "WWIDMAX", &alias, "MPATH", 1); assert_int_equal(rc, INT_MAX); assert_ptr_equal(alias, NULL); } @@ -901,13 +1077,15 @@ static void lb_nomatch_int_max_m1_used(void **state) { int rc; char *alias; + STRBUF_ON_STACK(buf); - mock_bindings_file("MPATHb WWID1\n" - "MPATH" MPATH_ID_INT_MAX_m1 " WWIDMAX\n" - "MPATHa WWID0\n", -1); - mock_used_alias("MPATH" MPATH_ID_INT_MAX, "WWID2"); + fill_bindings(&buf, 0, 26); + print_strbuf(&buf, "MPATH%s WWIDMAXM1\n", MPATH_ID_INT_MAX_m1); + mock_bindings_file(get_strbuf_str(&buf)); + expect_condlog(3, NOMATCH_WWID_STR("WWIDMAX")); + mock_used_alias("MPATH" MPATH_ID_INT_MAX, "WWIDMAX"); expect_condlog(0, NOMORE_STR); - rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 1); + rc = lookup_binding(NULL, "WWIDMAX", &alias, "MPATH", 1); assert_int_equal(rc, -1); assert_ptr_equal(alias, NULL); } @@ -916,13 +1094,15 @@ static void lb_nomatch_int_max_m1_1_used(void **state) { int rc; char *alias; + STRBUF_ON_STACK(buf); - mock_bindings_file("MPATHb WWID1\n" - "MPATH" MPATH_ID_INT_MAX_m1 " WWIDMAX\n", -1); - mock_used_alias("MPATHa", "WWID2"); + fill_bindings(&buf, 1, 26); + print_strbuf(&buf, "MPATH%s WWIDMAXM1\n", MPATH_ID_INT_MAX_m1); + mock_bindings_file(get_strbuf_str(&buf)); + expect_condlog(3, NOMATCH_WWID_STR("WWIDMAX")); + mock_used_alias("MPATHa", "WWIDMAX"); mock_unused_alias("MPATH" MPATH_ID_INT_MAX); - expect_condlog(3, NOMATCH_WWID_STR("WWID2")); - rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 1); + rc = lookup_binding(NULL, "WWIDMAX", &alias, "MPATH", 1); assert_int_equal(rc, INT_MAX); assert_ptr_equal(alias, NULL); } @@ -931,13 +1111,17 @@ static void lb_nomatch_int_max_m1_2_used(void **state) { int rc; char *alias; + STRBUF_ON_STACK(buf); - mock_bindings_file("MPATHb WWID1\n" - "MPATH" MPATH_ID_INT_MAX_m1 " WWIDMAX\n", -1); - mock_used_alias("MPATHa", "WWID2"); - mock_used_alias("MPATH" MPATH_ID_INT_MAX, "WWID2"); + fill_bindings(&buf, 1, 26); + print_strbuf(&buf, "MPATH%s WWIDMAXM1\n", MPATH_ID_INT_MAX_m1); + mock_bindings_file(get_strbuf_str(&buf)); + + expect_condlog(3, NOMATCH_WWID_STR("WWIDMAX")); + mock_used_alias("MPATHa", "WWIDMAX"); + mock_used_alias("MPATH" MPATH_ID_INT_MAX, "WWIDMAX"); expect_condlog(0, NOMORE_STR); - rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 1); + rc = lookup_binding(NULL, "WWIDMAX", &alias, "MPATH", 1); assert_int_equal(rc, -1); assert_ptr_equal(alias, NULL); } @@ -946,52 +1130,68 @@ static void lb_nomatch_int_max_m1_2_used(void **state) static int test_lookup_binding(void) { const struct CMUnitTest tests[] = { - cmocka_unit_test(lb_empty), - cmocka_unit_test(lb_empty_unused), - cmocka_unit_test(lb_empty_failed), - cmocka_unit_test(lb_empty_1_used), - cmocka_unit_test(lb_empty_1_used_self), - cmocka_unit_test(lb_match_a), - cmocka_unit_test(lb_nomatch_a), - cmocka_unit_test(lb_nomatch_a_bad_check), - cmocka_unit_test(lb_nomatch_a_unused), - cmocka_unit_test(lb_nomatch_a_3_used_failed_self), - cmocka_unit_test(lb_match_c), - cmocka_unit_test(lb_match_c_check), - cmocka_unit_test(lb_nomatch_a_c), - cmocka_unit_test(lb_nomatch_a_d_unused), - cmocka_unit_test(lb_nomatch_a_d_1_used), - cmocka_unit_test(lb_nomatch_a_d_2_used), - cmocka_unit_test(lb_nomatch_a_d_3_used), - cmocka_unit_test(lb_nomatch_c_a), - cmocka_unit_test(lb_nomatch_d_a_unused), - cmocka_unit_test(lb_nomatch_d_a_1_used), - cmocka_unit_test(lb_nomatch_a_b), - cmocka_unit_test(lb_nomatch_a_b_bad), - cmocka_unit_test(lb_nomatch_a_b_bad_self), - cmocka_unit_test(lb_nomatch_b_a), - cmocka_unit_test(lb_nomatch_b_a_3_used), + cmocka_unit_test_teardown(lb_empty, teardown_bindings), + cmocka_unit_test_teardown(lb_empty_unused, teardown_bindings), + cmocka_unit_test_teardown(lb_empty_failed, teardown_bindings), + cmocka_unit_test_teardown(lb_empty_1_used, teardown_bindings), + cmocka_unit_test_teardown(lb_empty_1_used_self, teardown_bindings), + cmocka_unit_test_teardown(lb_match_a, teardown_bindings), + cmocka_unit_test_teardown(lb_nomatch_a, teardown_bindings), + cmocka_unit_test_teardown(lb_nomatch_a_bad_check, teardown_bindings), + cmocka_unit_test_teardown(lb_nomatch_a_unused, teardown_bindings), + cmocka_unit_test_teardown(lb_nomatch_a_3_used_failed_self, teardown_bindings), + cmocka_unit_test_teardown(lb_match_c, teardown_bindings), + cmocka_unit_test_teardown(lb_match_c_check, teardown_bindings), + cmocka_unit_test_teardown(lb_nomatch_a_c, teardown_bindings), + cmocka_unit_test_teardown(lb_nomatch_a_d_unused, teardown_bindings), + cmocka_unit_test_teardown(lb_nomatch_a_d_1_used, teardown_bindings), + cmocka_unit_test_teardown(lb_nomatch_a_d_2_used, teardown_bindings), + cmocka_unit_test_teardown(lb_nomatch_a_d_3_used, teardown_bindings), + cmocka_unit_test_teardown(lb_nomatch_c_a, teardown_bindings), + cmocka_unit_test_teardown(lb_nomatch_d_a_unused, teardown_bindings), + cmocka_unit_test_teardown(lb_nomatch_d_a_1_used, teardown_bindings), + cmocka_unit_test_teardown(lb_nomatch_a_b, teardown_bindings), + cmocka_unit_test_teardown(lb_nomatch_a_b_bad, teardown_bindings), + cmocka_unit_test_teardown(lb_nomatch_a_b_bad_self, teardown_bindings), + cmocka_unit_test_teardown(lb_nomatch_b_z_a, teardown_bindings), + cmocka_unit_test_teardown(lb_nomatch_b_aa_a, teardown_bindings), + cmocka_unit_test_teardown(lb_nomatch_b_a_aa, teardown_bindings), + cmocka_unit_test_teardown(lb_nomatch_b_a_aa_zz, teardown_bindings), + cmocka_unit_test_teardown(lb_nomatch_b_z_a_unsorted, teardown_bindings), + cmocka_unit_test_teardown(lb_nomatch_b_a, teardown_bindings), + cmocka_unit_test_teardown(lb_nomatch_b_a_3_used, teardown_bindings), #ifdef MPATH_ID_INT_MAX - cmocka_unit_test(lb_nomatch_int_max), - cmocka_unit_test(lb_nomatch_int_max_check), - cmocka_unit_test(lb_nomatch_int_max_used), - cmocka_unit_test(lb_nomatch_int_max_m1), - cmocka_unit_test(lb_nomatch_int_max_m1_used), - cmocka_unit_test(lb_nomatch_int_max_m1_1_used), - cmocka_unit_test(lb_nomatch_int_max_m1_2_used), + cmocka_unit_test_teardown(lb_nomatch_int_max, teardown_bindings), + cmocka_unit_test_teardown(lb_nomatch_int_max_used, teardown_bindings), + cmocka_unit_test_teardown(lb_nomatch_int_max_m1, teardown_bindings), + cmocka_unit_test_teardown(lb_nomatch_int_max_m1_used, teardown_bindings), + cmocka_unit_test_teardown(lb_nomatch_int_max_m1_1_used, teardown_bindings), + cmocka_unit_test_teardown(lb_nomatch_int_max_m1_2_used, teardown_bindings), #endif }; return cmocka_run_group_tests(tests, NULL, NULL); } +static int rlookup_binding(FILE *dummy, char *buf, const char *alias) { + + const struct binding *bdg; + + bdg = get_binding_for_alias(&global_bindings, alias); + if (!bdg) { + return -1; + } + strlcpy(buf, bdg->wwid, WWID_SIZE); + return 0; +} + static void rl_empty(void **state) { int rc; char buf[WWID_SIZE]; buf[0] = '\0'; - mock_bindings_file("", -1); + mock_bindings_file(""); expect_condlog(3, NOMATCH_STR("MPATHa")); rc = rlookup_binding(NULL, buf, "MPATHa"); assert_int_equal(rc, -1); @@ -1004,7 +1204,7 @@ static void rl_match_a(void **state) char buf[WWID_SIZE]; buf[0] = '\0'; - mock_bindings_file("MPATHa WWID0\n", 0); + mock_bindings_file("MPATHa WWID0\n"); expect_condlog(3, FOUND_ALIAS_STR("MPATHa", "WWID0")); rc = rlookup_binding(NULL, buf, "MPATHa"); assert_int_equal(rc, 0); @@ -1017,7 +1217,7 @@ static void rl_nomatch_a(void **state) char buf[WWID_SIZE]; buf[0] = '\0'; - mock_bindings_file("MPATHa WWID0\n", -1); + mock_bindings_file("MPATHa WWID0\n"); expect_condlog(3, NOMATCH_STR("MPATHb")); rc = rlookup_binding(NULL, buf, "MPATHb"); assert_int_equal(rc, -1); @@ -1030,8 +1230,8 @@ static void rl_malformed_a(void **state) char buf[WWID_SIZE]; buf[0] = '\0'; - mock_bindings_file("MPATHa \n", -1); - expect_condlog(3, "Ignoring malformed line 1 in bindings file\n"); + expect_condlog(1, "invalid line 1 in bindings file, missing WWID\n"); + mock_bindings_file("MPATHa \n"); expect_condlog(3, NOMATCH_STR("MPATHa")); rc = rlookup_binding(NULL, buf, "MPATHa"); assert_int_equal(rc, -1); @@ -1049,8 +1249,8 @@ static void rl_overlong_a(void **state) snprintf(line + sizeof(line) - 2, 2, "\n"); buf[0] = '\0'; - mock_bindings_file(line, -1); expect_condlog(3, "Ignoring too large wwid at 1 in bindings file\n"); + mock_bindings_file(line); expect_condlog(3, NOMATCH_STR("MPATHa")); rc = rlookup_binding(NULL, buf, "MPATHa"); assert_int_equal(rc, -1); @@ -1065,7 +1265,7 @@ static void rl_match_b(void **state) buf[0] = '\0'; mock_bindings_file("MPATHa WWID0\n" "MPATHz WWID26\n" - "MPATHb WWID2\n", 2); + "MPATHb WWID2\n"); expect_condlog(3, FOUND_ALIAS_STR("MPATHb", "WWID2")); rc = rlookup_binding(NULL, buf, "MPATHb"); assert_int_equal(rc, 0); @@ -1075,31 +1275,41 @@ static void rl_match_b(void **state) static int test_rlookup_binding(void) { const struct CMUnitTest tests[] = { - cmocka_unit_test(rl_empty), - cmocka_unit_test(rl_match_a), - cmocka_unit_test(rl_nomatch_a), - cmocka_unit_test(rl_malformed_a), - cmocka_unit_test(rl_overlong_a), - cmocka_unit_test(rl_match_b), + cmocka_unit_test_teardown(rl_empty, teardown_bindings), + cmocka_unit_test_teardown(rl_match_a, teardown_bindings), + cmocka_unit_test_teardown(rl_nomatch_a, teardown_bindings), + cmocka_unit_test_teardown(rl_malformed_a, teardown_bindings), + cmocka_unit_test_teardown(rl_overlong_a, teardown_bindings), + cmocka_unit_test_teardown(rl_match_b, teardown_bindings), }; return cmocka_run_group_tests(tests, NULL, NULL); } +void check_bindings_size(int n) +{ + /* avoid -Waddress problem */ + Bindings *bindings = &global_bindings; + + assert_int_equal(VECTOR_SIZE(bindings), n); +} + static void al_a(void **state) { static const char ln[] = "MPATHa WWIDa\n"; char *alias; - will_return(__wrap_lseek, 0); - expect_value(__wrap_write, count, strlen(ln)); - expect_string(__wrap_write, buf, ln); - will_return(__wrap_write, strlen(ln)); + expect_value(__wrap_write, count, strlen(BINDINGS_FILE_HEADER) + strlen(ln)); + will_return(__wrap_write, ln); + will_return(__wrap_write, strlen(BINDINGS_FILE_HEADER) + strlen(ln)); + will_return(__wrap_rename, 0); + expect_condlog(1, "updated bindings file foo"); expect_condlog(3, NEW_STR("MPATHa", "WWIDa")); - alias = allocate_binding(0, "WWIDa", 1, "MPATH"); + alias = allocate_binding("foo", "WWIDa", 1, "MPATH"); assert_ptr_not_equal(alias, NULL); assert_string_equal(alias, "MPATHa"); + check_bindings_size(1); free(alias); } @@ -1108,15 +1318,17 @@ static void al_zz(void **state) static const char ln[] = "MPATHzz WWIDzz\n"; char *alias; - will_return(__wrap_lseek, 0); - expect_value(__wrap_write, count, strlen(ln)); - expect_string(__wrap_write, buf, ln); - will_return(__wrap_write, strlen(ln)); + expect_value(__wrap_write, count, strlen(BINDINGS_FILE_HEADER) + strlen(ln)); + will_return(__wrap_write, ln); + will_return(__wrap_write, strlen(BINDINGS_FILE_HEADER) + strlen(ln)); + will_return(__wrap_rename, 0); + expect_condlog(1, "updated bindings file foo"); expect_condlog(3, NEW_STR("MPATHzz", "WWIDzz")); - alias = allocate_binding(0, "WWIDzz", 26*26 + 26, "MPATH"); + alias = allocate_binding("foo", "WWIDzz", 26*26 + 26, "MPATH"); assert_ptr_not_equal(alias, NULL); assert_string_equal(alias, "MPATHzz"); + check_bindings_size(1); free(alias); } @@ -1127,6 +1339,7 @@ static void al_0(void **state) expect_condlog(0, "allocate_binding: cannot allocate new binding for id 0\n"); alias = allocate_binding(0, "WWIDa", 0, "MPATH"); assert_ptr_equal(alias, NULL); + check_bindings_size(0); } static void al_m2(void **state) @@ -1136,67 +1349,133 @@ static void al_m2(void **state) expect_condlog(0, "allocate_binding: cannot allocate new binding for id -2\n"); alias = allocate_binding(0, "WWIDa", -2, "MPATH"); assert_ptr_equal(alias, NULL); + check_bindings_size(0); } -static void al_lseek_err(void **state) +static void al_write_partial(void **state) { + static const char ln[] = "MPATHa WWIDa\n"; char *alias; - will_return(__wrap_lseek, -ENODEV); - expect_condlog(0, "Cannot seek to end of bindings file : No such device\n"); - alias = allocate_binding(0, "WWIDa", 1, "MPATH"); + expect_value(__wrap_write, count, strlen(BINDINGS_FILE_HEADER) + strlen(ln)); + will_return(__wrap_write, ln); + will_return(__wrap_write, strlen(BINDINGS_FILE_HEADER) + strlen(ln) - 1); + expect_value(__wrap_write, count, 1); + will_return(__wrap_write, ln + sizeof(ln) - 2); + will_return(__wrap_write, 1); + will_return(__wrap_rename, 0); + expect_condlog(1, "updated bindings file foo"); + expect_condlog(3, "Created new binding [MPATHa] for WWID [WWIDa]\n"); + + alias = allocate_binding("foo", "WWIDa", 1, "MPATH"); + assert_ptr_not_equal(alias, NULL); + assert_string_equal(alias, "MPATHa"); + check_bindings_size(1); + free(alias); +} + +static void al_write_short(void **state) +{ + static const char ln[] = "MPATHa WWIDa\n"; + char *alias; + + expect_value(__wrap_write, count, strlen(BINDINGS_FILE_HEADER) + strlen(ln)); + will_return(__wrap_write, ln); + will_return(__wrap_write, strlen(BINDINGS_FILE_HEADER) + strlen(ln) - 1); + expect_value(__wrap_write, count, 1); + will_return(__wrap_write, ln + sizeof(ln) - 2); + will_return(__wrap_write, 0); + expect_condlog(2, "write_bindings_file: short write"); + expect_condlog(1, "failed to write new bindings file"); + expect_condlog(1, "allocate_binding: deleting binding MPATHa for WWIDa"); + + alias = allocate_binding("foo", "WWIDa", 1, "MPATH"); assert_ptr_equal(alias, NULL); + check_bindings_size(0); } static void al_write_err(void **state) { static const char ln[] = "MPATHa WWIDa\n"; - const int offset = 20; char *alias; - will_return(__wrap_lseek, offset); - expect_value(__wrap_write, count, strlen(ln)); - expect_string(__wrap_write, buf, ln); - will_return(__wrap_write, strlen(ln) - 1); - expect_value(__wrap_ftruncate, length, offset); - will_return(__wrap_ftruncate, 0); - expect_condlog(0, "Cannot write binding to bindings file :"); + expect_value(__wrap_write, count, strlen(BINDINGS_FILE_HEADER) + strlen(ln)); + will_return(__wrap_write, ln); + will_return(__wrap_write, -EPERM); + expect_condlog(1, "failed to write new bindings file"); + expect_condlog(1, "allocate_binding: deleting binding MPATHa for WWIDa"); - alias = allocate_binding(0, "WWIDa", 1, "MPATH"); + alias = allocate_binding("foo", "WWIDa", 1, "MPATH"); assert_ptr_equal(alias, NULL); + check_bindings_size(0); +} + +static void al_rename_err(void **state) +{ + static const char ln[] = "MPATHa WWIDa\n"; + char *alias; + + expect_value(__wrap_write, count, strlen(BINDINGS_FILE_HEADER) + strlen(ln)); + will_return(__wrap_write, ln); + will_return(__wrap_write, strlen(BINDINGS_FILE_HEADER) + strlen(ln)); + will_return(__wrap_rename, -EROFS); + + expect_condlog(0, "update_bindings_file: rename: Read-only file system"); + expect_condlog(1, "allocate_binding: deleting binding MPATHa for WWIDa"); + alias = allocate_binding("foo", "WWIDa", 1, "MPATH"); + assert_ptr_equal(alias, NULL); + check_bindings_size(0); } static int test_allocate_binding(void) { const struct CMUnitTest tests[] = { - cmocka_unit_test(al_a), - cmocka_unit_test(al_zz), - cmocka_unit_test(al_0), - cmocka_unit_test(al_m2), - cmocka_unit_test(al_lseek_err), - cmocka_unit_test(al_write_err), + cmocka_unit_test_teardown(al_a, teardown_bindings), + cmocka_unit_test_teardown(al_zz, teardown_bindings), + cmocka_unit_test_teardown(al_0, teardown_bindings), + cmocka_unit_test_teardown(al_m2, teardown_bindings), + cmocka_unit_test_teardown(al_write_partial, teardown_bindings), + cmocka_unit_test_teardown(al_write_short, teardown_bindings), + cmocka_unit_test_teardown(al_write_err, teardown_bindings), + cmocka_unit_test_teardown(al_rename_err, teardown_bindings), }; return cmocka_run_group_tests(tests, NULL, NULL); } -#define mock_allocate_binding(alias, wwid) \ +#define mock_allocate_binding_err_len(alias, wwid, len, err, msg) \ do { \ static const char ln[] = BINDING_STR(alias, wwid); \ \ - will_return(__wrap_lseek, 0); \ - expect_value(__wrap_write, count, strlen(ln)); \ - expect_string(__wrap_write, buf, ln); \ - will_return(__wrap_write, strlen(ln)); \ - expect_condlog(3, NEW_STR(alias, wwid)); \ + expect_value(__wrap_write, count, \ + strlen(BINDINGS_FILE_HEADER) + (len) + strlen(ln)); \ + will_return(__wrap_write, ln); \ + will_return(__wrap_write, \ + strlen(BINDINGS_FILE_HEADER) + (len) + strlen(ln)); \ + will_return(__wrap_rename, err); \ + if (err == 0) { \ + expect_condlog(1, "updated bindings file x\n"); \ + expect_condlog(3, NEW_STR(alias, wwid)); \ + } else { \ + expect_condlog(0, "update_bindings_file: rename: " msg "\n"); \ + expect_condlog(1, "allocate_binding: deleting binding " \ + alias " for " wwid "\n"); \ + } \ } while (0) +#define mock_allocate_binding_err(alias, wwid, err, msg) \ + mock_allocate_binding_err_len(alias, wwid, 0, err, msg) + +#define mock_allocate_binding(alias, wwid) \ + mock_allocate_binding_err(alias, wwid, 0, "") + +#define mock_allocate_binding_len(alias, wwid, len) \ + mock_allocate_binding_err_len(alias, wwid, len, 0, "") + static void gufa_empty_new_rw(void **state) { char *alias; - will_return(__wrap_open_file, true); - - mock_bindings_file("", -1); + mock_bindings_file(""); mock_unused_alias("MPATHa"); expect_condlog(3, NOMATCH_WWID_STR("WWID0")); @@ -1208,10 +1487,11 @@ static void gufa_empty_new_rw(void **state) { static void gufa_empty_new_ro_1(void **state) { char *alias; - will_return(__wrap_open_file, false); - mock_bindings_file("", -1); + + mock_bindings_file(""); mock_unused_alias("MPATHa"); expect_condlog(3, NOMATCH_WWID_STR("WWID0")); + mock_allocate_binding_err("MPATHa", "WWID0", -EROFS, "Read-only file system"); alias = get_user_friendly_alias("WWID0", "x", "", "MPATH", false); assert_ptr_equal(alias, NULL); @@ -1220,11 +1500,9 @@ static void gufa_empty_new_ro_1(void **state) { static void gufa_empty_new_ro_2(void **state) { char *alias; - will_return(__wrap_open_file, true); - - mock_bindings_file("", -1); - mock_unused_alias("MPATHa"); + mock_bindings_file(""); expect_condlog(3, NOMATCH_WWID_STR("WWID0")); + mock_unused_alias("MPATHa"); alias = get_user_friendly_alias("WWID0", "x", "", "MPATH", true); assert_ptr_equal(alias, NULL); @@ -1233,11 +1511,10 @@ static void gufa_empty_new_ro_2(void **state) { static void gufa_match_a_unused(void **state) { char *alias; - will_return(__wrap_open_file, true); - - mock_bindings_file("MPATHa WWID0", 0); + mock_bindings_file("MPATHa WWID0"); expect_condlog(3, FOUND_STR("MPATHa", "WWID0")); mock_unused_alias("MPATHa"); + expect_condlog(3, EXISTING_STR("MPATHa", "WWID0")); alias = get_user_friendly_alias("WWID0", "x", "", "MPATH", true); assert_string_equal(alias, "MPATHa"); @@ -1247,11 +1524,10 @@ static void gufa_match_a_unused(void **state) { static void gufa_match_a_self(void **state) { char *alias; - will_return(__wrap_open_file, true); - - mock_bindings_file("MPATHa WWID0", 0); + mock_bindings_file("MPATHa WWID0"); expect_condlog(3, FOUND_STR("MPATHa", "WWID0")); mock_self_alias("MPATHa", "WWID0"); + expect_condlog(3, EXISTING_STR("MPATHa", "WWID0")); alias = get_user_friendly_alias("WWID0", "x", "", "MPATH", true); assert_string_equal(alias, "MPATHa"); @@ -1261,9 +1537,8 @@ static void gufa_match_a_self(void **state) { static void gufa_match_a_used(void **state) { char *alias; - will_return(__wrap_open_file, true); - mock_bindings_file("MPATHa WWID0", 0); + mock_bindings_file("MPATHa WWID0"); expect_condlog(3, FOUND_STR("MPATHa", "WWID0")); mock_used_alias("MPATHa", "WWID0"); @@ -1273,15 +1548,14 @@ static void gufa_match_a_used(void **state) { static void gufa_nomatch_a_c(void **state) { char *alias; - will_return(__wrap_open_file, true); + static const char bindings[] = ("MPATHa WWID0\n" + "MPATHc WWID2\n"); - mock_bindings_file("MPATHa WWID0\n" - "MPATHc WWID2", - -1); + mock_bindings_file(bindings); mock_unused_alias("MPATHb"); expect_condlog(3, NOMATCH_WWID_STR("WWID1")); - mock_allocate_binding("MPATHb", "WWID1"); + mock_allocate_binding_len("MPATHb", "WWID1", strlen(bindings)); alias = get_user_friendly_alias("WWID1", "x", "", "MPATH", false); assert_string_equal(alias, "MPATHb"); @@ -1290,15 +1564,14 @@ static void gufa_nomatch_a_c(void **state) { static void gufa_nomatch_c_a(void **state) { char *alias; - will_return(__wrap_open_file, true); + const char bindings[] = ("MPATHc WWID2\n" + "MPATHa WWID0\n"); - mock_bindings_file("MPATHc WWID2\n" - "MPATHa WWID0", - -1); + mock_bindings_file(bindings); mock_unused_alias("MPATHb"); expect_condlog(3, NOMATCH_WWID_STR("WWID1")); - mock_allocate_binding("MPATHb", "WWID1"); + mock_allocate_binding_len("MPATHb", "WWID1", sizeof(bindings) - 1); alias = get_user_friendly_alias("WWID1", "x", "", "MPATH", false); assert_string_equal(alias, "MPATHb"); @@ -1307,15 +1580,14 @@ static void gufa_nomatch_c_a(void **state) { static void gufa_nomatch_c_b(void **state) { char *alias; - will_return(__wrap_open_file, true); + const char bindings[] = ("MPATHc WWID2\n" + "MPATHb WWID1\n"); - mock_bindings_file("MPATHc WWID2\n" - "MPATHb WWID1\n", - -1); - mock_unused_alias("MPATHa"); + mock_bindings_file(bindings); expect_condlog(3, NOMATCH_WWID_STR("WWID0")); + mock_unused_alias("MPATHa"); - mock_allocate_binding("MPATHa", "WWID0"); + mock_allocate_binding_len("MPATHa", "WWID0", sizeof(bindings) - 1); alias = get_user_friendly_alias("WWID0", "x", "", "MPATH", false); assert_string_equal(alias, "MPATHa"); @@ -1324,16 +1596,15 @@ static void gufa_nomatch_c_b(void **state) { static void gufa_nomatch_c_b_used(void **state) { char *alias; - will_return(__wrap_open_file, true); + const char bindings[] = ("MPATHc WWID2\n" + "MPATHb WWID1\n"); - mock_bindings_file("MPATHc WWID2\n" - "MPATHb WWID1", - -1); - mock_used_alias("MPATHa", "WWID4"); + mock_bindings_file(bindings); expect_condlog(3, NOMATCH_WWID_STR("WWID4")); + mock_used_alias("MPATHa", "WWID4"); mock_unused_alias("MPATHd"); - mock_allocate_binding("MPATHd", "WWID4"); + mock_allocate_binding_len("MPATHd", "WWID4", sizeof(bindings) - 1); alias = get_user_friendly_alias("WWID4", "x", "", "MPATH", false); assert_string_equal(alias, "MPATHd"); @@ -1342,32 +1613,59 @@ static void gufa_nomatch_c_b_used(void **state) { static void gufa_nomatch_b_f_a(void **state) { char *alias; - will_return(__wrap_open_file, true); + const char bindings[] = ("MPATHb WWID1\n" + "MPATHf WWID6\n" + "MPATHa WWID0\n"); - mock_bindings_file("MPATHb WWID1\n" - "MPATHf WWID6\n" - "MPATHa WWID0\n", - -1); + mock_bindings_file_unsorted(bindings); expect_condlog(3, NOMATCH_WWID_STR("WWID7")); mock_unused_alias("MPATHg"); - mock_allocate_binding("MPATHg", "WWID7"); + mock_allocate_binding_len("MPATHg", "WWID7", sizeof(bindings) - 1); alias = get_user_friendly_alias("WWID7", "x", "", "MPATH", false); assert_string_equal(alias, "MPATHg"); free(alias); } +static void gufa_nomatch_b_aa_a(void **state) { + char *alias; + STRBUF_ON_STACK(buf); + + fill_bindings(&buf, 0, 26); + mock_bindings_file(get_strbuf_str(&buf)); + expect_condlog(3, NOMATCH_WWID_STR("WWID28")); + mock_unused_alias("MPATHab"); + mock_allocate_binding_len("MPATHab", "WWID28", get_strbuf_len(&buf)); + + alias = get_user_friendly_alias("WWID28", "x", "", "MPATH", false); + assert_string_equal(alias, "MPATHab"); + free(alias); +} + +static void gufa_nomatch_b_f_a_sorted(void **state) { + char *alias; + const char bindings[] = ("MPATHb WWID1\n" + "MPATHf WWID6\n" + "MPATHa WWID0\n"); + + mock_bindings_file(bindings); + expect_condlog(3, NOMATCH_WWID_STR("WWID7")); + mock_unused_alias("MPATHc"); + + mock_allocate_binding_len("MPATHc", "WWID7", sizeof(bindings) - 1); + + alias = get_user_friendly_alias("WWID7", "x", "", "MPATH", false); + assert_string_equal(alias, "MPATHc"); + free(alias); +} + static void gufa_old_empty(void **state) { char *alias; - will_return(__wrap_open_file, true); /* rlookup_binding for ALIAS */ - mock_bindings_file("", -1); + mock_bindings_file(""); expect_condlog(3, NOMATCH_STR("MPATHz")); - - /* lookup_binding */ - mock_bindings_file("", -1); expect_condlog(3, NOMATCH_WWID_STR("WWID0")); mock_allocate_binding("MPATHz", "WWID0"); @@ -1380,11 +1678,9 @@ static void gufa_old_empty(void **state) { static void gufa_old_match(void **state) { char *alias; - will_return(__wrap_open_file, true); mock_bindings_file("MPATHb WWID1\n" - "MPATHz WWID0", - 1); + "MPATHz WWID0"); expect_condlog(3, FOUND_ALIAS_STR("MPATHz", "WWID0")); alias = get_user_friendly_alias("WWID0", "x", "MPATHz", "MPATH", false); @@ -1394,19 +1690,15 @@ static void gufa_old_match(void **state) { static void gufa_old_match_other(void **state) { char *alias; - static const char bindings[] = "MPATHz WWID9"; + static const char bindings[] = "MPATHz WWID9\n"; - will_return(__wrap_open_file, true); - - mock_bindings_file(bindings, 0); + mock_bindings_file(bindings); expect_condlog(3, FOUND_ALIAS_STR("MPATHz", "WWID9")); expect_condlog(0, REUSE_STR("MPATHz", "WWID9")); - - mock_bindings_file(bindings, -1); expect_condlog(3, NOMATCH_WWID_STR("WWID0")); mock_unused_alias("MPATHa"); - mock_allocate_binding("MPATHa", "WWID0"); + mock_allocate_binding_len("MPATHa", "WWID0", sizeof(bindings) - 1); alias = get_user_friendly_alias("WWID0", "x", "MPATHz", "MPATH", false); assert_string_equal(alias, "MPATHa"); @@ -1415,21 +1707,16 @@ static void gufa_old_match_other(void **state) { static void gufa_old_match_other_used(void **state) { char *alias; - static const char bindings[] = "MPATHz WWID9"; + static const char bindings[] = "MPATHz WWID9\n"; - will_return(__wrap_open_file, true); - - mock_bindings_file(bindings, 0); + mock_bindings_file(bindings); expect_condlog(3, FOUND_ALIAS_STR("MPATHz", "WWID9")); expect_condlog(0, REUSE_STR("MPATHz", "WWID9")); - - mock_bindings_file(bindings, -1); - mock_used_alias("MPATHa", "WWID0"); expect_condlog(3, NOMATCH_WWID_STR("WWID0")); + mock_used_alias("MPATHa", "WWID0"); mock_unused_alias("MPATHb"); - mock_allocate_binding("MPATHb", "WWID0"); - + mock_allocate_binding_len("MPATHb", "WWID0", sizeof(bindings) - 1); alias = get_user_friendly_alias("WWID0", "x", "MPATHz", "MPATH", false); assert_string_equal(alias, "MPATHb"); free(alias); @@ -1439,15 +1726,13 @@ static void gufa_old_match_other_wwidmatch(void **state) { char *alias; static const char bindings[] = ("MPATHz WWID9\n" "MPATHc WWID2"); - will_return(__wrap_open_file, true); - mock_bindings_file(bindings, 0); + mock_bindings_file(bindings); expect_condlog(3, FOUND_ALIAS_STR("MPATHz", "WWID9")); expect_condlog(0, REUSE_STR("MPATHz", "WWID9")); - - mock_bindings_file(bindings, 1); expect_condlog(3, FOUND_STR("MPATHc", "WWID2")); mock_unused_alias("MPATHc"); + expect_condlog(3, EXISTING_STR("MPATHc", "WWID2")); alias = get_user_friendly_alias("WWID2", "x", "MPATHz", "MPATH", false); assert_string_equal(alias, "MPATHc"); @@ -1459,13 +1744,9 @@ static void gufa_old_match_other_wwidmatch_used(void **state) { static const char bindings[] = ("MPATHz WWID9\n" "MPATHc WWID2"); - will_return(__wrap_open_file, true); - - mock_bindings_file(bindings, 0); + mock_bindings_file(bindings); expect_condlog(3, FOUND_ALIAS_STR("MPATHz", "WWID9")); expect_condlog(0, REUSE_STR("MPATHz", "WWID9")); - - mock_bindings_file(bindings, 1); expect_condlog(3, FOUND_STR("MPATHc", "WWID2")); mock_used_alias("MPATHc", "WWID2"); @@ -1477,12 +1758,8 @@ static void gufa_old_nomatch_wwidmatch(void **state) { char *alias; static const char bindings[] = "MPATHa WWID0"; - will_return(__wrap_open_file, true); - - mock_bindings_file(bindings, -1); + mock_bindings_file(bindings); expect_condlog(3, NOMATCH_STR("MPATHz")); - - mock_bindings_file(bindings, 0); expect_condlog(3, FOUND_STR("MPATHa", "WWID0")); mock_unused_alias("MPATHa"); expect_condlog(3, EXISTING_STR("MPATHa", "WWID0")); @@ -1495,12 +1772,9 @@ static void gufa_old_nomatch_wwidmatch(void **state) { static void gufa_old_nomatch_wwidmatch_used(void **state) { char *alias; static const char bindings[] = "MPATHa WWID0"; - will_return(__wrap_open_file, true); - mock_bindings_file(bindings, -1); + mock_bindings_file(bindings); expect_condlog(3, NOMATCH_STR("MPATHz")); - - mock_bindings_file(bindings, 0); expect_condlog(3, FOUND_STR("MPATHa", "WWID0")); mock_used_alias("MPATHa", "WWID0"); @@ -1510,17 +1784,13 @@ static void gufa_old_nomatch_wwidmatch_used(void **state) { static void gufa_old_nomatch_nowwidmatch(void **state) { char *alias; - static const char bindings[] = "MPATHb WWID1"; + static const char bindings[] = "MPATHb WWID1\n"; - will_return(__wrap_open_file, true); - - mock_bindings_file(bindings, -1); + mock_bindings_file(bindings); expect_condlog(3, NOMATCH_STR("MPATHz")); - - mock_bindings_file(bindings, -1); expect_condlog(3, NOMATCH_WWID_STR("WWID0")); - mock_allocate_binding("MPATHz", "WWID0"); + mock_allocate_binding_len("MPATHz", "WWID0", sizeof(bindings) - 1); expect_condlog(2, ALLOC_STR("MPATHz", "WWID0")); alias = get_user_friendly_alias("WWID0", "x", "MPATHz", "MPATH", false); @@ -1531,26 +1801,28 @@ static void gufa_old_nomatch_nowwidmatch(void **state) { static int test_get_user_friendly_alias() { const struct CMUnitTest tests[] = { - cmocka_unit_test(gufa_empty_new_rw), - cmocka_unit_test(gufa_empty_new_ro_1), - cmocka_unit_test(gufa_empty_new_ro_2), - cmocka_unit_test(gufa_match_a_unused), - cmocka_unit_test(gufa_match_a_self), - cmocka_unit_test(gufa_match_a_used), - cmocka_unit_test(gufa_nomatch_a_c), - cmocka_unit_test(gufa_nomatch_c_a), - cmocka_unit_test(gufa_nomatch_c_b), - cmocka_unit_test(gufa_nomatch_c_b_used), - cmocka_unit_test(gufa_nomatch_b_f_a), - cmocka_unit_test(gufa_old_empty), - cmocka_unit_test(gufa_old_match), - cmocka_unit_test(gufa_old_match_other), - cmocka_unit_test(gufa_old_match_other_used), - cmocka_unit_test(gufa_old_match_other_wwidmatch), - cmocka_unit_test(gufa_old_match_other_wwidmatch_used), - cmocka_unit_test(gufa_old_nomatch_wwidmatch), - cmocka_unit_test(gufa_old_nomatch_wwidmatch_used), - cmocka_unit_test(gufa_old_nomatch_nowwidmatch), + cmocka_unit_test_teardown(gufa_empty_new_rw, teardown_bindings), + cmocka_unit_test_teardown(gufa_empty_new_ro_1, teardown_bindings), + cmocka_unit_test_teardown(gufa_empty_new_ro_2, teardown_bindings), + cmocka_unit_test_teardown(gufa_match_a_unused, teardown_bindings), + cmocka_unit_test_teardown(gufa_match_a_self, teardown_bindings), + cmocka_unit_test_teardown(gufa_match_a_used, teardown_bindings), + cmocka_unit_test_teardown(gufa_nomatch_a_c, teardown_bindings), + cmocka_unit_test_teardown(gufa_nomatch_c_a, teardown_bindings), + cmocka_unit_test_teardown(gufa_nomatch_c_b, teardown_bindings), + cmocka_unit_test_teardown(gufa_nomatch_c_b_used, teardown_bindings), + cmocka_unit_test_teardown(gufa_nomatch_b_f_a, teardown_bindings), + cmocka_unit_test_teardown(gufa_nomatch_b_aa_a, teardown_bindings), + cmocka_unit_test_teardown(gufa_nomatch_b_f_a_sorted, teardown_bindings), + cmocka_unit_test_teardown(gufa_old_empty, teardown_bindings), + cmocka_unit_test_teardown(gufa_old_match, teardown_bindings), + cmocka_unit_test_teardown(gufa_old_match_other, teardown_bindings), + cmocka_unit_test_teardown(gufa_old_match_other_used, teardown_bindings), + cmocka_unit_test_teardown(gufa_old_match_other_wwidmatch, teardown_bindings), + cmocka_unit_test_teardown(gufa_old_match_other_wwidmatch_used, teardown_bindings), + cmocka_unit_test_teardown(gufa_old_nomatch_wwidmatch, teardown_bindings), + cmocka_unit_test_teardown(gufa_old_nomatch_wwidmatch_used, teardown_bindings), + cmocka_unit_test_teardown(gufa_old_nomatch_nowwidmatch, teardown_bindings), }; return cmocka_run_group_tests(tests, NULL, NULL); @@ -1566,7 +1838,6 @@ int main(void) ret += test_lookup_binding(); ret += test_rlookup_binding(); ret += test_allocate_binding(); - ret += test_allocate_binding(); ret += test_get_user_friendly_alias(); return ret; From patchwork Mon Sep 11 16:38:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13379510 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 67B67EEB581 for ; Mon, 11 Sep 2023 16:39:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694450394; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=fEDVJTrOQdnRy1/pXdHl3/tkOWpUQpmvcyFyTKM0QUM=; b=Pu7bXiXtxennKr12i4DnYjgrXir3/evoMQJGBquimcz4h5nr9js27ZxgubGKaJhfUlF2fB 7VLAZEp7GCDgAZy8KhcORQOvmNPMxrlwlBG+CBowMxfwidN0S7/Rpr+XG7db4TtsfYkyUK QWg6SOCE9H4jfQtM7WcxE3Pkv7CwE2E= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-490-uHayxb5MPyWxatvEFbASfw-1; Mon, 11 Sep 2023 12:39:48 -0400 X-MC-Unique: uHayxb5MPyWxatvEFbASfw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 855A090F87D; Mon, 11 Sep 2023 16:39:27 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6F2D31054FCB; Mon, 11 Sep 2023 16:39:27 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id E78A11946A69; Mon, 11 Sep 2023 16:39:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 857241946597 for ; Mon, 11 Sep 2023 16:39:25 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 665A24405A; Mon, 11 Sep 2023 16:39:25 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5EB8144029 for ; Mon, 11 Sep 2023 16:39:25 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3A68B933734 for ; Mon, 11 Sep 2023 16:39:25 +0000 (UTC) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-584-Z7JUiTlEM-q0IkyFC5xI7g-1; Mon, 11 Sep 2023 12:39:21 -0400 X-MC-Unique: Z7JUiTlEM-q0IkyFC5xI7g-1 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id D1D741F88C; Mon, 11 Sep 2023 16:39:19 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id A2DBF139CC; Mon, 11 Sep 2023 16:39:19 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 6McfJrdC/2RzEAAAMHmgww (envelope-from ); Mon, 11 Sep 2023 16:39:19 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Mon, 11 Sep 2023 18:38:29 +0200 Message-ID: <20230911163846.27197-21-mwilck@suse.com> In-Reply-To: <20230911163846.27197-1-mwilck@suse.com> References: <20230911163846.27197-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Subject: [dm-devel] [PATCH v2 20/37] libmultipath: dm_get_uuid(): return emtpy UUID for non-existing maps X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dm-devel@redhat.com, Martin Wilck Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: suse.com From: Martin Wilck libdevmapper will most probably not return a UUID for non-existing maps anyway. But it's cheap to double-check here. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/devmapper.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 248c373..9be82f4 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -706,12 +706,16 @@ 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; @@ -720,11 +724,13 @@ dm_get_prefixed_uuid(const char *name, char *uuid, int uuid_len) 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); - else - uuid[0] = '\0'; r = 0; uuidout: From patchwork Mon Sep 11 16:38:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13379496 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3902DEE7FF4 for ; Mon, 11 Sep 2023 16:39:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694450381; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=6F4ZH4rHmHcIzfQFlDMJkwxNY/QIWTLU96N/Xjiwm6M=; b=R5B4aWlgCLDbIyKrU06GYLCK+7dVaOR0HSN4Qn6+O9U29yBu1o8Bpm19H6Wwc6rlSMNzmS //L8R/Jo+ALDGKrNWjs8hWCXPUhYfU8PJEBaTxmg9n7VMlk0ayEhGvvH7Jpw5GCoJHJ1DW 0CQ3jcTlQ9xGtGJsc2da+c0wNGLfs94= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-61-FYhy5gWjNv668WVEEhAyDQ-1; Mon, 11 Sep 2023 12:39:35 -0400 X-MC-Unique: FYhy5gWjNv668WVEEhAyDQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3E92393374A; Mon, 11 Sep 2023 16:39:27 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2AD511054FC2; Mon, 11 Sep 2023 16:39:27 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id B52D119465BC; Mon, 11 Sep 2023 16:39:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 561AA19465A2 for ; Mon, 11 Sep 2023 16:39:25 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 2941A2027019; Mon, 11 Sep 2023 16:39:25 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2039F2027045 for ; Mon, 11 Sep 2023 16:39:25 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 05753101FAA9 for ; Mon, 11 Sep 2023 16:39:25 +0000 (UTC) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-642-EHyR-5zNNOOp9-mUqwf6-g-1; Mon, 11 Sep 2023 12:39:21 -0400 X-MC-Unique: EHyR-5zNNOOp9-mUqwf6-g-1 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 1D4E21F8BB; Mon, 11 Sep 2023 16:39:20 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id DDE7F139CC; Mon, 11 Sep 2023 16:39:19 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id +BZsNLdC/2RzEAAAMHmgww (envelope-from ); Mon, 11 Sep 2023 16:39:19 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Mon, 11 Sep 2023 18:38:30 +0200 Message-ID: <20230911163846.27197-22-mwilck@suse.com> In-Reply-To: <20230911163846.27197-1-mwilck@suse.com> References: <20230911163846.27197-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 Subject: [dm-devel] [PATCH v2 21/37] libmultipath: adapt to new semantics of dm_get_uuid() X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dm-devel@redhat.com, Martin Wilck Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: suse.com From: Martin Wilck dm_get_uuid() will return 1 for non-existing maps. Thus we don't need to call dm_map_present() any more in alias_already_taken(). This changes our semantics: previously we'd avoid using an alias for which dm_get_uuid() had failed. Now we treat failure in dm_get_uuid() as indication that the map doesn't exist. This is not dangerous because dm_task_get_uuid() cannot fail, and thus the modified dm_get_uuid() will fail if and only if dm_map_present() would return false. This makes the "failed alias" test mostly obsolete, as "failed" is now treated as "unused". Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/alias.c | 23 ++++++++++++----------- tests/alias.c | 32 +++++++------------------------- 2 files changed, 19 insertions(+), 36 deletions(-) diff --git a/libmultipath/alias.c b/libmultipath/alias.c index d656374..58436ec 100644 --- a/libmultipath/alias.c +++ b/libmultipath/alias.c @@ -295,18 +295,19 @@ scan_devname(const char *alias, const char *prefix) static bool alias_already_taken(const char *alias, const char *map_wwid) { - if (dm_map_present(alias)) { - char wwid[WWID_SIZE]; + char wwid[WWID_SIZE]; - /* If both the name and the wwid match, then it's fine.*/ - if (dm_get_uuid(alias, wwid, sizeof(wwid)) == 0 && - strncmp(map_wwid, wwid, sizeof(wwid)) == 0) - return false; - condlog(3, "%s: alias '%s' already taken, reselecting alias", - map_wwid, alias); - return true; - } - return false; + /* If the map doesn't exist, it's fine */ + if (dm_get_uuid(alias, wwid, sizeof(wwid)) != 0) + return false; + + /* If both the name and the wwid match, it's fine.*/ + if (strncmp(map_wwid, wwid, sizeof(wwid)) == 0) + return false; + + condlog(3, "%s: alias '%s' already taken, reselecting alias", + map_wwid, alias); + return true; } static bool id_already_taken(int id, const char *prefix, const char *map_wwid) diff --git a/tests/alias.c b/tests/alias.c index 50a21ec..d1cc487 100644 --- a/tests/alias.c +++ b/tests/alias.c @@ -73,12 +73,6 @@ int __wrap_mkstemp(char *template) return 10; } -int __wrap_dm_map_present(const char * str) -{ - check_expected(str); - return mock_type(int); -} - int __wrap_dm_get_uuid(const char *name, char *uuid, int uuid_len) { int ret; @@ -398,14 +392,13 @@ static int test_scan_devname(void) static void mock_unused_alias(const char *alias) { - expect_string(__wrap_dm_map_present, str, alias); - will_return(__wrap_dm_map_present, 0); + 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); } static void mock_self_alias(const char *alias, const char *wwid) { - expect_string(__wrap_dm_map_present, str, alias); - will_return(__wrap_dm_map_present, 1); 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); @@ -432,18 +425,13 @@ static void mock_self_alias(const char *alias, const char *wwid) #define mock_failed_alias(alias, wwid) \ do { \ - expect_string(__wrap_dm_map_present, str, alias); \ - will_return(__wrap_dm_map_present, 1); \ 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_condlog(3, USED_STR(alias, wwid)); \ } while (0) #define mock_used_alias(alias, wwid) \ do { \ - expect_string(__wrap_dm_map_present, str, alias); \ - will_return(__wrap_dm_map_present, 1); \ 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); \ @@ -566,9 +554,8 @@ static void lb_empty_failed(void **state) mock_bindings_file(""); expect_condlog(3, NOMATCH_WWID_STR("WWID0")); mock_failed_alias("MPATHa", "WWID0"); - mock_unused_alias("MPATHb"); rc = lookup_binding(NULL, "WWID0", &alias, "MPATH", 1); - assert_int_equal(rc, 2); + assert_int_equal(rc, 1); assert_ptr_equal(alias, NULL); free(alias); } @@ -666,9 +653,8 @@ static void lb_nomatch_a_3_used_failed_self(void **state) mock_used_alias("MPATHc", "WWID1"); mock_used_alias("MPATHd", "WWID1"); mock_failed_alias("MPATHe", "WWID1"); - mock_self_alias("MPATHf", "WWID1"); rc = lookup_binding(NULL, "WWID1", &alias, "MPATH", 1); - assert_int_equal(rc, 6); + assert_int_equal(rc, 5); assert_ptr_equal(alias, NULL); } @@ -940,7 +926,7 @@ static void lb_nomatch_b_a_aa(void **state) static void lb_nomatch_b_a_aa_zz(void **state) { - int rc, i; + int rc; char *alias; STRBUF_ON_STACK(buf); @@ -949,11 +935,7 @@ static void lb_nomatch_b_a_aa_zz(void **state) * lookup_binding finds MPATHaaa as next free entry, because MPATHaa is * found before MPATHb, and MPATHzz was in the bindings, too. */ - for (i = 0; i <= 26; i++) { - print_strbuf(&buf, "MPATH"); - format_devname(&buf, i + 1); - print_strbuf(&buf, " WWID%d\n", i); - } + fill_bindings(&buf, 0, 26); print_strbuf(&buf, "MPATHzz WWID676\n"); mock_bindings_file(get_strbuf_str(&buf)); expect_condlog(3, NOMATCH_WWID_STR("WWID703")); From patchwork Mon Sep 11 16:38:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13379507 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A7DC4EEB57E for ; Mon, 11 Sep 2023 16:39:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694450391; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=/VZJpo+0BefmtxVapXRxXHaGGaYL0nrY46GhwKNAWtc=; b=e55ZLP0Ecudidaqr+zZK6yqKnH/VZb8PkJDUfqscdNiQVx7vuuDdQhi91KABBkX3u6vPpb 5ID8Q2UIFi7SfuRDZKZwBdxroNcxBqm+TijAtRj002cEAqfiO1YEcv8aFsK51GaO84fxga vyHpt7UOO4M4mtNk1VIPF2zKPjiu+8M= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-340-T1roCxUJM8-xfMI0CHplww-1; Mon, 11 Sep 2023 12:39:47 -0400 X-MC-Unique: T1roCxUJM8-xfMI0CHplww-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B63E43815EFC; Mon, 11 Sep 2023 16:39:29 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9E89640C200A; Mon, 11 Sep 2023 16:39:29 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 7FA9E19466DF; Mon, 11 Sep 2023 16:39:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id DA4EE1946A61 for ; Mon, 11 Sep 2023 16:39:26 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id BFAF840C6ECA; Mon, 11 Sep 2023 16:39:26 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B7CAC40C6EA8 for ; Mon, 11 Sep 2023 16:39:26 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9808090F842 for ; Mon, 11 Sep 2023 16:39:26 +0000 (UTC) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-558-zVbqZIPVMgGs1PXXt7VObQ-1; Mon, 11 Sep 2023 12:39:23 -0400 X-MC-Unique: zVbqZIPVMgGs1PXXt7VObQ-1 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 5775C21847; Mon, 11 Sep 2023 16:39:20 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 28FA0139CC; Mon, 11 Sep 2023 16:39:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id mM5eCLhC/2RzEAAAMHmgww (envelope-from ); Mon, 11 Sep 2023 16:39:20 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Mon, 11 Sep 2023 18:38:31 +0200 Message-ID: <20230911163846.27197-23-mwilck@suse.com> In-Reply-To: <20230911163846.27197-1-mwilck@suse.com> References: <20230911163846.27197-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 Subject: [dm-devel] [PATCH v2 22/37] libmultipath: sort aliases by length and strcmp X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dm-devel@redhat.com, Martin Wilck Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: suse.com From: Martin Wilck The current sort order of aliases is alphabetical, which is does not match the actual order of aliases, where "mpathaa" > "mpathz". Change the ordering as follows: first sort by string length, then alphabetically. This will make sure that for aliases with the same prefix, alias order is correct ("mpathaaa" will be sorted after "mpathzz", etc). Even for mixed prefixes, the alias order will be correct for every individual prefix, even though aliases with different prefixes may alternate in the file. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/alias.c | 45 +++++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/libmultipath/alias.c b/libmultipath/alias.c index 58436ec..af6565b 100644 --- a/libmultipath/alias.c +++ b/libmultipath/alias.c @@ -117,6 +117,35 @@ static const struct binding *get_binding_for_wwid(const Bindings *bindings, return NULL; } +/* + * Sort order for aliases. + * + * The "numeric" ordering of aliases for a given prefix P is + * Pa, ..., Pz, Paa, ..., Paz, Pba, ... , Pzz, Paaa, ..., Pzzz, Paaaa, ... + * We use the fact that for equal prefix, longer strings are always + * higher than shorter ones. Strings of equal length are sorted alphabetically. + * This is achieved by sorting be length first, then using strcmp(). + * If multiple prefixes are in use, the aliases with a given prefix will + * not necessarily be in a contiguous range of the vector, but they will + * be ordered such that for a given prefix, numercally higher aliases will + * always be sorted after lower ones. + */ +static int alias_compar(const void *p1, const void *p2) +{ + const char *alias1 = *((char * const *)p1); + const char *alias2 = *((char * const *)p2); + + if (alias1 && alias2) { + ssize_t ldif = strlen(alias1) - strlen(alias2); + + if (ldif) + return ldif; + return strcmp(alias1, alias2); + } else + /* Move NULL alias to the end */ + return alias1 ? -1 : alias2 ? 1 : 0; +} + static int add_binding(Bindings *bindings, const char *alias, const char *wwid) { struct binding *bdg; @@ -128,7 +157,7 @@ static int add_binding(Bindings *bindings, const char *alias, const char *wwid) * sorted already. */ vector_foreach_slot_backwards(bindings, bdg, i) { - if ((cmp = strcmp(bdg->alias, alias)) <= 0) + if ((cmp = alias_compar(&bdg->alias, &alias)) <= 0) break; } @@ -657,16 +686,10 @@ static int _check_bindings_file(const struct config *conf, FILE *file, return rc; } -static int alias_compar(const void *p1, const void *p2) +static int mp_alias_compar(const void *p1, const void *p2) { - const char *alias1 = (*(struct mpentry * const *)p1)->alias; - const char *alias2 = (*(struct mpentry * const *)p2)->alias; - - if (alias1 && alias2) - return strcmp(alias1, alias2); - else - /* Move NULL alias to the end */ - return alias1 ? -1 : alias2 ? 1 : 0; + return alias_compar(&((*(struct mpentry * const *)p1)->alias), + &((*(struct mpentry * const *)p2)->alias)); } /* @@ -700,7 +723,7 @@ int check_alias_settings(const struct config *conf) pthread_cleanup_push_cast(free_bindings, &bindings); pthread_cleanup_push(cleanup_vector_free, mptable); - vector_sort(mptable, alias_compar); + vector_sort(mptable, mp_alias_compar); vector_foreach_slot(mptable, mpe, i) { if (!mpe->alias) /* From patchwork Mon Sep 11 16:38:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13379506 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0C6EBEEB594 for ; Mon, 11 Sep 2023 16:39:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694450390; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=jOCEPfTe5Zk4eWC766lSbAiOwPjfVfM0j6JQTZ2eFPk=; b=f2RjEQ45hvfMIC9o4mlYM8HpreQAHOfXVu8qJ3LO5tF4axSny92T1jsd+bIpzewfRhvqVr 1N3G6ZKXz8eBfslZp4xQ9c+dH/AfiyNNolz1ZnAOAssZHRe1hnTYVKrL8HuM7z5pJYYouo vfh9yJk+qwF9B47u++C3IeWIkfQUi00= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-571-YV0jrDcrMzOJf5Eyrqw8TQ-1; Mon, 11 Sep 2023 12:39:45 -0400 X-MC-Unique: YV0jrDcrMzOJf5Eyrqw8TQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A250C181A707; Mon, 11 Sep 2023 16:39:32 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8C1E740C200A; Mon, 11 Sep 2023 16:39:32 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 5595E19465B6; Mon, 11 Sep 2023 16:39:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id F1E021946597 for ; Mon, 11 Sep 2023 16:39:24 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id E33C740C2009; Mon, 11 Sep 2023 16:39:24 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast08.extmail.prod.ext.rdu2.redhat.com [10.11.55.24]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DBA8740C200A for ; Mon, 11 Sep 2023 16:39:24 +0000 (UTC) Received: from us-smtp-inbound-delivery-1.mimecast.com (us-smtp-inbound-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BE7D1381494E for ; Mon, 11 Sep 2023 16:39:24 +0000 (UTC) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-103-rltqEK98N5OGy1OQhndMgw-1; Mon, 11 Sep 2023 12:39:21 -0400 X-MC-Unique: rltqEK98N5OGy1OQhndMgw-1 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 924CC1F8B3; Mon, 11 Sep 2023 16:39:20 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 62596139CC; Mon, 11 Sep 2023 16:39:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id EJ9iFrhC/2RzEAAAMHmgww (envelope-from ); Mon, 11 Sep 2023 16:39:20 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Mon, 11 Sep 2023 18:38:32 +0200 Message-ID: <20230911163846.27197-24-mwilck@suse.com> In-Reply-To: <20230911163846.27197-1-mwilck@suse.com> References: <20230911163846.27197-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Subject: [dm-devel] [PATCH v2 23/37] multipath-tools tests: fix alias test after sort order change X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dm-devel@redhat.com, Martin Wilck Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: suse.com From: Martin Wilck Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- tests/alias.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/tests/alias.c b/tests/alias.c index d1cc487..8ed95d7 100644 --- a/tests/alias.c +++ b/tests/alias.c @@ -932,16 +932,15 @@ static void lb_nomatch_b_a_aa_zz(void **state) /* * add_bindings() sorts alphabetically. ("a", "aa", "ab", "b", "c", ...) - * lookup_binding finds MPATHaaa as next free entry, because MPATHaa is - * found before MPATHb, and MPATHzz was in the bindings, too. + * lookup_binding finds MPATHab as next free entry. */ fill_bindings(&buf, 0, 26); print_strbuf(&buf, "MPATHzz WWID676\n"); mock_bindings_file(get_strbuf_str(&buf)); expect_condlog(3, NOMATCH_WWID_STR("WWID703")); - mock_unused_alias("MPATHaaa"); + mock_unused_alias("MPATHab"); rc = lookup_binding(NULL, "WWID703", &alias, "MPATH", 1); - assert_int_equal(rc, 703); + assert_int_equal(rc, 28); assert_ptr_equal(alias, NULL); } @@ -998,13 +997,8 @@ static void lb_nomatch_b_a_3_used(void **state) #ifdef MPATH_ID_INT_MAX /* - * The bindings will be sorted by alias, alphabetically, which is not - * the same as the "numeric" sort order for user-friendly aliases. - * get_free_id() selects the highest used ID + 1 if an unsorted entry - * is encountered in the bindings table and it's id is equal to the - * next "expected" id. This happens if all IDs from "a" to "aa" are - * in the table. If the INT_MAX entry is in the table, too, it will - * overflow. + * The bindings will be sorted by alias. Therefore we have no chance to + * simulate a "full" table. */ static void lb_nomatch_int_max(void **state) { @@ -1016,9 +1010,9 @@ static void lb_nomatch_int_max(void **state) print_strbuf(&buf, "MPATH%s WWIDMAX\n", MPATH_ID_INT_MAX); mock_bindings_file(get_strbuf_str(&buf)); expect_condlog(3, NOMATCH_WWID_STR("WWIDNOMORE")); - expect_condlog(0, NOMORE_STR); + mock_unused_alias("MPATHab"); rc = lookup_binding(NULL, "WWIDNOMORE", &alias, "MPATH", 1); - assert_int_equal(rc, -1); + assert_int_equal(rc, 28); assert_ptr_equal(alias, NULL); } @@ -1049,9 +1043,9 @@ static void lb_nomatch_int_max_m1(void **state) print_strbuf(&buf, "MPATH%s WWIDMAXM1\n", MPATH_ID_INT_MAX_m1); mock_bindings_file(get_strbuf_str(&buf)); expect_condlog(3, NOMATCH_WWID_STR("WWIDMAX")); - mock_unused_alias("MPATH" MPATH_ID_INT_MAX); + mock_unused_alias("MPATHab"); rc = lookup_binding(NULL, "WWIDMAX", &alias, "MPATH", 1); - assert_int_equal(rc, INT_MAX); + assert_int_equal(rc, 28); assert_ptr_equal(alias, NULL); } @@ -1065,10 +1059,10 @@ static void lb_nomatch_int_max_m1_used(void **state) print_strbuf(&buf, "MPATH%s WWIDMAXM1\n", MPATH_ID_INT_MAX_m1); mock_bindings_file(get_strbuf_str(&buf)); expect_condlog(3, NOMATCH_WWID_STR("WWIDMAX")); - mock_used_alias("MPATH" MPATH_ID_INT_MAX, "WWIDMAX"); - expect_condlog(0, NOMORE_STR); + mock_used_alias("MPATHab", "WWIDMAX"); + mock_unused_alias("MPATHac"); rc = lookup_binding(NULL, "WWIDMAX", &alias, "MPATH", 1); - assert_int_equal(rc, -1); + assert_int_equal(rc, 29); assert_ptr_equal(alias, NULL); } From patchwork Mon Sep 11 16:38:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13379505 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5EB4FEEB593 for ; Mon, 11 Sep 2023 16:39:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694450388; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=uMaLp2bGJcD4n0xRADksY2CZMvP1Wk3cL76FEYHZkX4=; b=dNXHS+ufU4/ZwEd7XM2tM9Q+A67QqSINlicEMbpO4ClEN9hxiovNfAl3vSYuzpJLAsNddA bgD+yAU8yyPr9Cb5vL+UzlDs05rRMHNQOvQHkSLt8sr75oYWz/qVmJMIfi0bL4YWBEZY3+ Z9euVc9Bxrv1xybH6JSDQYEABao++RQ= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-460-n5S0IV7dMamJ0dpHgkbl_A-1; Mon, 11 Sep 2023 12:39:40 -0400 X-MC-Unique: n5S0IV7dMamJ0dpHgkbl_A-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EB588945E85; Mon, 11 Sep 2023 16:39:26 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id D4A304405A; Mon, 11 Sep 2023 16:39:26 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 7EA471946A45; Mon, 11 Sep 2023 16:39:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id EA69D1946A5A for ; Mon, 11 Sep 2023 16:39:23 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id DC4594405A; Mon, 11 Sep 2023 16:39:23 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast07.extmail.prod.ext.rdu2.redhat.com [10.11.55.23]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D4F7A44029 for ; Mon, 11 Sep 2023 16:39:23 +0000 (UTC) Received: from us-smtp-inbound-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B815F3C00120 for ; Mon, 11 Sep 2023 16:39:23 +0000 (UTC) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-321-zi-OsbWJOz6g8RArPkq85w-1; Mon, 11 Sep 2023 12:39:22 -0400 X-MC-Unique: zi-OsbWJOz6g8RArPkq85w-1 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id CA98C21858; Mon, 11 Sep 2023 16:39:20 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 9D5C7139CC; Mon, 11 Sep 2023 16:39:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 4AfkJLhC/2RzEAAAMHmgww (envelope-from ); Mon, 11 Sep 2023 16:39:20 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Mon, 11 Sep 2023 18:38:33 +0200 Message-ID: <20230911163846.27197-25-mwilck@suse.com> In-Reply-To: <20230911163846.27197-1-mwilck@suse.com> References: <20230911163846.27197-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Subject: [dm-devel] [PATCH v2 24/37] libmultipath: simplify get_free_id() assuming total ordering X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dm-devel@redhat.com, Martin Wilck Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: suse.com From: Martin Wilck If we can assume that the bindings array is totally ordered for every prefix, which the previous patch guarantees, the search for a free ID can be simplified. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/alias.c | 87 ++++++++++---------------------------------- 1 file changed, 19 insertions(+), 68 deletions(-) diff --git a/libmultipath/alias.c b/libmultipath/alias.c index af6565b..66e34e3 100644 --- a/libmultipath/alias.c +++ b/libmultipath/alias.c @@ -356,83 +356,34 @@ int get_free_id(const Bindings *bindings, const char *prefix, const char *map_ww { const struct binding *bdg; int i, id = 1; - int biggest_id = 1; - int smallest_bigger_id = INT_MAX; vector_foreach_slot(bindings, bdg, i) { int curr_id = scan_devname(bdg->alias, prefix); - /* - * Find an unused index - explanation of the algorithm - * - * ID: 1 = mpatha, 2 = mpathb, ... - * - * We assume the bindings are unsorted. The only constraint - * is that no ID occurs more than once. IDs that occur in the - * bindings are called "used". - * - * We call the list 1,2,3,..., exactly in this order, the list - * of "expected" IDs. The variable "id" always holds the next - * "expected" ID, IOW the last "expected" ID encountered plus 1. - * Thus all IDs below "id" are known to be used. However, at the - * end of the loop, the value of "id" isn't necessarily unused. - * - * "smallest_bigger_id" is the smallest used ID that was - * encountered while it was larger than the next "expected" ID - * at that iteration. Let X be some used ID. If all IDs below X - * are used and encountered in the right sequence before X, "id" - * will be > X when the loop ends. Otherwise, X was encountered - * "out of order", the condition (X > id) holds when X is - * encountered, and "smallest_bigger_id" will be set to X; i.e. - * it will be less or equal than X when the loop ends. - * - * At the end of the loop, (id < smallest_bigger_id) means that - * the value of "id" had been encountered neither in order nor - * out of order, and is thus unused. (id >= smallest_bigger_id) - * means that "id"'s value is in use. In this case, we play safe - * and use "biggest_id + 1" as the next value to try. - * - * biggest_id is always > smallest_bigger_id, except in the - * "perfectly ordered" case. - */ - if (curr_id == id) { - if (id < INT_MAX) - id++; - else { - id = -1; - break; - } + if (curr_id == -1) + continue; + if (id > curr_id) { + condlog(0, "%s: ERROR: bindings are not sorted", __func__); + return -1; } - if (curr_id > biggest_id) - biggest_id = curr_id; - - if (curr_id > id && curr_id < smallest_bigger_id) - smallest_bigger_id = curr_id; - } - - if (id >= smallest_bigger_id) - id = biggest_id < INT_MAX ? biggest_id + 1 : -1; - - if (id > 0) { - while(id_already_taken(id, prefix, map_wwid)) { - if (id == INT_MAX) { - id = -1; - break; - } + while (id < curr_id && id_already_taken(id, prefix, map_wwid)) id++; - if (id == smallest_bigger_id) { - if (biggest_id == INT_MAX) { - id = -1; - break; - } - if (biggest_id >= smallest_bigger_id) - id = biggest_id + 1; - } - } + if (id < curr_id) + return id; + id++; + if (id <= 0) + break; } - if (id < 0) + for (; id > 0; id++) { + if (!id_already_taken(id, prefix, map_wwid)) + break; + } + + if (id <= 0) { + id = -1; condlog(0, "no more available user_friendly_names"); + } return id; } From patchwork Mon Sep 11 16:38:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13379512 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 173EDEEB580 for ; Mon, 11 Sep 2023 16:39:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694450393; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=/ikEvEupXbD7p21e7Oli0g7sztZyYF3Yw71vogcRsXI=; b=dpL4WnKjtlorh2CZI/zz778kJwQJd93iqNCwndFaLl7pE79kNdEddBbDrKAu6wwV41H7LO u6ISFzZg2344CAzy404Xx6jHITOQFQ+0VzNVKogNrC75t12V9moK2nRizRpbZE8LhwEM99 uafzJGheInk61hTPoFiXYyxxSMMW0k4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-350-S1YYLiV7NkufYCz-OeQ9BA-1; Mon, 11 Sep 2023 12:39:49 -0400 X-MC-Unique: S1YYLiV7NkufYCz-OeQ9BA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BE128945E66; Mon, 11 Sep 2023 16:39:30 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id AABFF2024CD6; Mon, 11 Sep 2023 16:39:30 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 8BCE919465A2; Mon, 11 Sep 2023 16:39:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id EFBE91946A47 for ; Mon, 11 Sep 2023 16:39:26 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id D1B9521CAC7A; Mon, 11 Sep 2023 16:39:26 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CAEBA21CAC76 for ; Mon, 11 Sep 2023 16:39:26 +0000 (UTC) Received: from us-smtp-inbound-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AD9C6101FAB0 for ; Mon, 11 Sep 2023 16:39:26 +0000 (UTC) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-304-4G_b7KPfNN2e6rTtuCVQOQ-1; Mon, 11 Sep 2023 12:39:22 -0400 X-MC-Unique: 4G_b7KPfNN2e6rTtuCVQOQ-1 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 181941F8A6; Mon, 11 Sep 2023 16:39:21 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id D7869139CC; Mon, 11 Sep 2023 16:39:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 8IL/MrhC/2RzEAAAMHmgww (envelope-from ); Mon, 11 Sep 2023 16:39:20 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Mon, 11 Sep 2023 18:38:34 +0200 Message-ID: <20230911163846.27197-26-mwilck@suse.com> In-Reply-To: <20230911163846.27197-1-mwilck@suse.com> References: <20230911163846.27197-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Subject: [dm-devel] [PATCH v2 25/37] multipath-tools tests: adapt alias tests for total ordering X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dm-devel@redhat.com, Martin Wilck Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: suse.com From: Martin Wilck The "unsorted" test fail now, and are removed. The algorithm is now better at finding "gaps". Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- tests/alias.c | 88 ++++++++------------------------------------------- 1 file changed, 14 insertions(+), 74 deletions(-) diff --git a/tests/alias.c b/tests/alias.c index 8ed95d7..dff5f93 100644 --- a/tests/alias.c +++ b/tests/alias.c @@ -439,27 +439,7 @@ static void mock_self_alias(const char *alias, const char *wwid) expect_condlog(3, USED_STR(alias, wwid)); \ } while(0) -static int add_binding_unsorted(Bindings *bindings, - const char *alias, const char *wwid) -{ - struct binding *bdg = calloc(1, sizeof(*bdg)); - - if (!bdg) - return -1; - bdg->wwid = strdup(wwid); - bdg->alias = strdup(alias); - if (!bdg->wwid || !bdg->alias || !vector_alloc_slot(bindings)) { - free(bdg->alias); - free(bdg->wwid); - free(bdg); - return BINDING_ERROR; - } - vector_set_slot(bindings, bdg); - return BINDING_ADDED; -} - -static void __mock_bindings_file(const char *content, - int (*add)(Bindings *, const char *, const char *)) +static void __mock_bindings_file(const char *content) { char *cnt __attribute__((cleanup(cleanup_charp))) = NULL; char *token, *savep = NULL; @@ -478,17 +458,13 @@ static void __mock_bindings_file(const char *content, == READ_BINDING_SKIP) continue; - rc = add(&global_bindings, alias, wwid); + rc = add_binding(&global_bindings, alias, wwid); assert_int_equal(rc, BINDING_ADDED); } } static void mock_bindings_file(const char *content) { - return __mock_bindings_file(content, add_binding); -} - -static void mock_bindings_file_unsorted(const char *content) { - return __mock_bindings_file(content, add_binding_unsorted); + return __mock_bindings_file(content); } static int teardown_bindings(void **state) @@ -861,10 +837,6 @@ static void lb_nomatch_b_z_a(void **state) int rc; char *alias; - /* - * add_bindings() sorts alphabetically. Therefore get_free_id() - * finds MPATHc as a free entry. - */ mock_bindings_file("MPATHb WWID1\n" "MPATHz WWID26\n" "MPATHa WWID0\n"); @@ -880,10 +852,6 @@ static void lb_nomatch_b_aa_a(void **state) int rc; char *alias; - /* - * add_bindings() sorts alphabetically. ("a", "aa", b"). - * The get_free_id() algorithm finds the "hole" after "b". - */ mock_bindings_file("MPATHb WWID1\n" "MPATHz WWID26\n" "MPATHa WWID0\n"); @@ -911,10 +879,6 @@ static void lb_nomatch_b_a_aa(void **state) char *alias; STRBUF_ON_STACK(buf); - /* - * add_bindings() sorts alphabetically. ("a", "aa", "ab", "b", "c", ...) - * lookup_binding finds MPATHac as next free entry. - */ fill_bindings(&buf, 0, 26); mock_bindings_file(get_strbuf_str(&buf)); expect_condlog(3, NOMATCH_WWID_STR("WWID28")); @@ -930,10 +894,6 @@ static void lb_nomatch_b_a_aa_zz(void **state) char *alias; STRBUF_ON_STACK(buf); - /* - * add_bindings() sorts alphabetically. ("a", "aa", "ab", "b", "c", ...) - * lookup_binding finds MPATHab as next free entry. - */ fill_bindings(&buf, 0, 26); print_strbuf(&buf, "MPATHzz WWID676\n"); mock_bindings_file(get_strbuf_str(&buf)); @@ -944,25 +904,6 @@ static void lb_nomatch_b_a_aa_zz(void **state) assert_ptr_equal(alias, NULL); } -static void lb_nomatch_b_z_a_unsorted(void **state) -{ - int rc; - char *alias; - - /* - * With unsorted bindings (shouldn't happen normally), get_free_id() - * plays safe and returns MPATHaa as first free entry. - */ - mock_bindings_file_unsorted("MPATHb WWID1\n" - "MPATHz WWID26\n" - "MPATHa WWID0\n"); - expect_condlog(3, NOMATCH_WWID_STR("WWID2")); - mock_unused_alias("MPATHaa"); - rc = lookup_binding(NULL, "WWID2", &alias, "MPATH", 1); - assert_int_equal(rc, 27); - assert_ptr_equal(alias, NULL); -} - static void lb_nomatch_b_a(void **state) { int rc; @@ -1027,9 +968,9 @@ static void lb_nomatch_int_max_used(void **state) mock_bindings_file(get_strbuf_str(&buf)); expect_condlog(3, NOMATCH_WWID_STR("WWIDNOMORE")); mock_used_alias("MPATHa", "WWIDNOMORE"); - expect_condlog(0, NOMORE_STR); + mock_unused_alias("MPATHab"); rc = lookup_binding(NULL, "WWIDNOMORE", &alias, "MPATH", 1); - assert_int_equal(rc, -1); + assert_int_equal(rc, 28); assert_ptr_equal(alias, NULL); } @@ -1077,9 +1018,9 @@ static void lb_nomatch_int_max_m1_1_used(void **state) mock_bindings_file(get_strbuf_str(&buf)); expect_condlog(3, NOMATCH_WWID_STR("WWIDMAX")); mock_used_alias("MPATHa", "WWIDMAX"); - mock_unused_alias("MPATH" MPATH_ID_INT_MAX); + mock_unused_alias("MPATHab"); rc = lookup_binding(NULL, "WWIDMAX", &alias, "MPATH", 1); - assert_int_equal(rc, INT_MAX); + assert_int_equal(rc, 28); assert_ptr_equal(alias, NULL); } @@ -1095,10 +1036,10 @@ static void lb_nomatch_int_max_m1_2_used(void **state) expect_condlog(3, NOMATCH_WWID_STR("WWIDMAX")); mock_used_alias("MPATHa", "WWIDMAX"); - mock_used_alias("MPATH" MPATH_ID_INT_MAX, "WWIDMAX"); - expect_condlog(0, NOMORE_STR); + mock_used_alias("MPATHab", "WWIDMAX"); + mock_unused_alias("MPATHac"); rc = lookup_binding(NULL, "WWIDMAX", &alias, "MPATH", 1); - assert_int_equal(rc, -1); + assert_int_equal(rc, 29); assert_ptr_equal(alias, NULL); } #endif @@ -1133,7 +1074,6 @@ static int test_lookup_binding(void) cmocka_unit_test_teardown(lb_nomatch_b_aa_a, teardown_bindings), cmocka_unit_test_teardown(lb_nomatch_b_a_aa, teardown_bindings), cmocka_unit_test_teardown(lb_nomatch_b_a_aa_zz, teardown_bindings), - cmocka_unit_test_teardown(lb_nomatch_b_z_a_unsorted, teardown_bindings), cmocka_unit_test_teardown(lb_nomatch_b_a, teardown_bindings), cmocka_unit_test_teardown(lb_nomatch_b_a_3_used, teardown_bindings), #ifdef MPATH_ID_INT_MAX @@ -1593,14 +1533,14 @@ static void gufa_nomatch_b_f_a(void **state) { "MPATHf WWID6\n" "MPATHa WWID0\n"); - mock_bindings_file_unsorted(bindings); + mock_bindings_file(bindings); expect_condlog(3, NOMATCH_WWID_STR("WWID7")); - mock_unused_alias("MPATHg"); + mock_unused_alias("MPATHc"); - mock_allocate_binding_len("MPATHg", "WWID7", sizeof(bindings) - 1); + mock_allocate_binding_len("MPATHc", "WWID7", sizeof(bindings) - 1); alias = get_user_friendly_alias("WWID7", "x", "", "MPATH", false); - assert_string_equal(alias, "MPATHg"); + assert_string_equal(alias, "MPATHc"); free(alias); } From patchwork Mon Sep 11 16:38:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13379494 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E425AEE7FF4 for ; Mon, 11 Sep 2023 16:39:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694450378; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=NTPHg6uMh12OWU3pWGy8YZJeEFselZEIia7MWxdHhYc=; b=euwUqZYpOYJv91WbJGbpgKW92pKblOOsV1+5QcXJI2lyciuip4iDO/ziHh5XudOFeOBCkh ekrrwu6YaTY1+DMI5blLmeYrTpgL6GgtfRLBMGrjBNfeQNSr/cwXjb5sNezlBA24zwZj5c OmHv/dYBZ2uZbkLshnohVRbZkJeFZ8o= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-499-Zx4WkST0NB-wVj-6HMJ37Q-1; Mon, 11 Sep 2023 12:39:35 -0400 X-MC-Unique: Zx4WkST0NB-wVj-6HMJ37Q-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D7D443C0E20D; Mon, 11 Sep 2023 16:39:27 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id BA1D310EE402; Mon, 11 Sep 2023 16:39:27 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 225331946A49; Mon, 11 Sep 2023 16:39:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 5F7EE19465A8 for ; Mon, 11 Sep 2023 16:39:25 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 3E37C44069; Mon, 11 Sep 2023 16:39:25 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 34E224404C for ; Mon, 11 Sep 2023 16:39:25 +0000 (UTC) Received: from us-smtp-inbound-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0D29E945E66 for ; Mon, 11 Sep 2023 16:39:25 +0000 (UTC) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-90-SVODEKvlPIGLC9NofFDCKQ-1; Mon, 11 Sep 2023 12:39:23 -0400 X-MC-Unique: SVODEKvlPIGLC9NofFDCKQ-1 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 5985B21860; Mon, 11 Sep 2023 16:39:21 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 2527B139CC; Mon, 11 Sep 2023 16:39:21 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id gH5yB7lC/2RzEAAAMHmgww (envelope-from ); Mon, 11 Sep 2023 16:39:21 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Mon, 11 Sep 2023 18:38:35 +0200 Message-ID: <20230911163846.27197-27-mwilck@suse.com> In-Reply-To: <20230911163846.27197-1-mwilck@suse.com> References: <20230911163846.27197-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Subject: [dm-devel] [PATCH v2 26/37] multipath-tools tests: add test for ordering of bindings X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dm-devel@redhat.com, Martin Wilck Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: suse.com From: Martin Wilck As the assignment of free aliases now relies on the bindings being properly sorted, add some unit tests to make sure the sorting algorithm works. Reviewed-by: Benjamin Marzinski --- tests/alias.c | 212 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 209 insertions(+), 3 deletions(-) diff --git a/tests/alias.c b/tests/alias.c index dff5f93..2e765fb 100644 --- a/tests/alias.c +++ b/tests/alias.c @@ -13,6 +13,9 @@ #include "globals.c" #include "../libmultipath/alias.c" +/* For verbose printing of all aliases in the ordering tests */ +#define ALIAS_DEBUG 0 + #if INT_MAX == 0x7fffffff /* user_friendly_name for map #INT_MAX */ #define MPATH_ID_INT_MAX "fxshrxw" @@ -439,11 +442,12 @@ static void mock_self_alias(const char *alias, const char *wwid) expect_condlog(3, USED_STR(alias, wwid)); \ } while(0) -static void __mock_bindings_file(const char *content) +static void __mock_bindings_file(const char *content, bool conflict_ok) { char *cnt __attribute__((cleanup(cleanup_charp))) = NULL; char *token, *savep = NULL; int i; + LargestIntegralType values[] = { BINDING_ADDED, BINDING_CONFLICT }; cnt = strdup(content); assert_ptr_not_equal(cnt, NULL); @@ -459,12 +463,12 @@ static void __mock_bindings_file(const char *content) continue; rc = add_binding(&global_bindings, alias, wwid); - assert_int_equal(rc, BINDING_ADDED); + assert_in_set(rc, values, conflict_ok ? 2 : 1); } } static void mock_bindings_file(const char *content) { - return __mock_bindings_file(content); + return __mock_bindings_file(content, false); } static int teardown_bindings(void **state) @@ -1744,6 +1748,207 @@ static int test_get_user_friendly_alias() return cmocka_run_group_tests(tests, NULL, NULL); } +/* Numbers 1-1000, randomly shuffled */ +static int random_numbers[1000] = { + 694, 977, 224, 178, 841, 818, 914, 549, 831, 942, 263, 834, 919, 800, + 111, 517, 719, 297, 988, 98, 332, 516, 754, 772, 495, 488, 331, 529, + 142, 747, 848, 618, 375, 624, 74, 753, 782, 944, 623, 468, 862, 997, + 417, 258, 298, 774, 673, 904, 883, 766, 867, 400, 11, 950, 14, 784, + 655, 155, 396, 9, 743, 93, 651, 245, 968, 306, 785, 581, 880, 486, + 168, 631, 203, 4, 663, 294, 702, 762, 619, 684, 48, 181, 21, 443, 643, + 863, 1000, 327, 26, 126, 382, 765, 586, 76, 49, 925, 319, 865, 797, + 876, 693, 334, 433, 243, 419, 901, 854, 326, 985, 347, 874, 527, 282, + 290, 380, 167, 95, 3, 257, 936, 60, 426, 227, 345, 577, 492, 467, 580, + 967, 422, 823, 718, 610, 64, 700, 412, 163, 288, 506, 828, 432, 51, + 356, 348, 539, 478, 17, 945, 602, 123, 450, 660, 429, 113, 310, 358, + 512, 758, 508, 19, 542, 304, 286, 446, 918, 723, 333, 603, 731, 978, + 230, 697, 109, 872, 175, 853, 947, 965, 121, 222, 101, 811, 117, 601, + 191, 752, 384, 415, 938, 278, 915, 715, 240, 552, 912, 838, 150, 840, + 627, 29, 636, 464, 861, 481, 992, 249, 934, 82, 368, 724, 807, 593, + 157, 147, 199, 637, 41, 62, 902, 505, 621, 342, 174, 260, 729, 961, + 219, 311, 629, 789, 81, 739, 860, 712, 223, 165, 741, 981, 485, 363, + 346, 709, 125, 369, 279, 634, 399, 162, 193, 769, 149, 314, 868, 612, + 524, 675, 341, 343, 476, 606, 388, 613, 850, 264, 903, 451, 908, 779, + 453, 148, 497, 46, 132, 43, 885, 955, 269, 395, 72, 128, 767, 989, + 929, 423, 742, 55, 13, 79, 924, 182, 295, 563, 668, 169, 974, 154, + 970, 54, 674, 52, 437, 570, 550, 531, 554, 793, 678, 218, 367, 105, + 197, 315, 958, 892, 86, 47, 284, 37, 561, 522, 198, 689, 817, 573, + 877, 201, 803, 501, 881, 546, 530, 523, 780, 579, 953, 135, 23, 620, + 84, 698, 303, 656, 357, 323, 494, 58, 131, 913, 995, 120, 70, 1, 195, + 365, 210, 25, 898, 173, 307, 239, 77, 418, 952, 963, 92, 455, 425, 12, + 536, 161, 328, 933, 401, 251, 735, 725, 362, 322, 557, 681, 302, 53, + 786, 801, 391, 946, 748, 133, 717, 851, 7, 372, 993, 387, 906, 373, + 667, 33, 670, 389, 209, 611, 896, 652, 69, 999, 344, 845, 633, 36, + 487, 192, 180, 45, 640, 427, 707, 805, 188, 152, 905, 217, 30, 252, + 386, 665, 299, 541, 410, 787, 5, 857, 751, 392, 44, 595, 146, 745, + 641, 957, 866, 773, 806, 815, 659, 102, 704, 430, 106, 296, 129, 847, + 130, 990, 669, 236, 225, 680, 159, 213, 438, 189, 447, 600, 232, 594, + 32, 56, 390, 647, 855, 428, 330, 714, 738, 706, 666, 461, 469, 482, + 558, 814, 559, 177, 575, 538, 309, 383, 261, 156, 420, 761, 630, 893, + 10, 116, 940, 844, 71, 377, 662, 312, 520, 244, 143, 759, 119, 186, + 592, 909, 864, 376, 768, 254, 265, 394, 511, 760, 574, 6, 436, 514, + 59, 226, 644, 956, 578, 825, 548, 145, 736, 597, 378, 821, 987, 897, + 354, 144, 722, 895, 589, 503, 826, 498, 543, 617, 763, 231, 808, 528, + 89, 479, 607, 737, 170, 404, 371, 65, 103, 340, 283, 141, 313, 858, + 289, 124, 971, 687, 954, 732, 39, 926, 176, 100, 267, 519, 890, 535, + 276, 448, 27, 457, 899, 385, 184, 275, 770, 544, 614, 449, 160, 658, + 259, 973, 108, 604, 24, 207, 562, 757, 744, 324, 444, 962, 591, 480, + 398, 409, 998, 253, 325, 445, 979, 8, 35, 118, 73, 683, 208, 85, 190, + 791, 408, 871, 657, 179, 18, 556, 496, 475, 20, 894, 484, 775, 889, + 463, 241, 730, 57, 907, 551, 859, 943, 185, 416, 870, 590, 435, 471, + 932, 268, 381, 626, 502, 565, 273, 534, 672, 778, 292, 473, 566, 104, + 172, 285, 832, 411, 329, 628, 397, 472, 271, 910, 711, 690, 969, 585, + 809, 941, 923, 555, 228, 685, 242, 94, 96, 211, 140, 61, 922, 795, + 869, 34, 255, 38, 984, 676, 15, 560, 632, 434, 921, 355, 582, 351, + 212, 200, 819, 960, 649, 852, 75, 771, 361, 996, 238, 316, 720, 671, + 462, 112, 569, 171, 664, 625, 588, 405, 553, 270, 533, 353, 842, 114, + 972, 83, 937, 63, 194, 237, 537, 980, 802, 916, 959, 688, 839, 350, + 917, 650, 545, 615, 151, 352, 686, 726, 266, 509, 439, 491, 935, 608, + 518, 653, 339, 609, 277, 635, 836, 88, 407, 440, 642, 927, 229, 727, + 360, 477, 846, 413, 454, 616, 28, 598, 567, 540, 790, 424, 247, 317, + 746, 911, 798, 321, 547, 248, 734, 829, 220, 138, 756, 500, 691, 196, + 740, 930, 843, 733, 221, 827, 50, 813, 949, 525, 349, 474, 134, 875, + 695, 513, 414, 515, 638, 99, 366, 490, 975, 246, 465, 206, 281, 583, + 256, 587, 749, 2, 951, 679, 215, 364, 458, 402, 646, 991, 335, 982, + 835, 300, 900, 703, 994, 983, 234, 888, 532, 804, 584, 305, 792, 442, + 291, 964, 158, 370, 452, 250, 521, 166, 948, 812, 794, 272, 699, 205, + 183, 507, 301, 920, 781, 233, 824, 137, 489, 833, 887, 966, 856, 78, + 830, 153, 359, 696, 526, 216, 66, 701, 403, 891, 849, 571, 308, 483, + 164, 293, 928, 677, 320, 837, 441, 639, 564, 510, 648, 274, 336, 661, + 878, 777, 816, 976, 493, 810, 67, 87, 91, 187, 882, 986, 80, 22, 499, + 90, 705, 139, 136, 122, 708, 716, 886, 572, 127, 40, 721, 764, 16, + 379, 692, 645, 456, 710, 460, 783, 97, 776, 713, 884, 115, 466, 596, + 374, 406, 110, 568, 68, 214, 622, 470, 107, 504, 682, 31, 421, 576, + 654, 605, 788, 799, 280, 338, 931, 873, 204, 287, 459, 755, 939, 599, + 431, 796, 235, 42, 750, 262, 318, 393, 202, 822, 879, 820, 728, 337, +}; + +static void fill_bindings_random(struct strbuf *buf, int start, int end, + const char *prefix) +{ + int i; + + for (i = start; i < end; i++) { + print_strbuf(buf, "%s", prefix); + format_devname(buf, random_numbers[i]); + print_strbuf(buf, " WWID%d\n", random_numbers[i-1]); + } +} + +struct random_aliases { + int start; + int end; + const char *prefix; +}; + +static void order_test(int n, struct random_aliases ra[], bool conflict_ok) +{ + STRBUF_ON_STACK(buf); + int i, j, prev, curr, tmp; + struct binding *bdg; + Bindings *bindings = &global_bindings; + + for (j = 0; j < n; j++) + fill_bindings_random(&buf, ra[j].start, ra[j].end, ra[j].prefix); + __mock_bindings_file(get_strbuf_str(&buf), conflict_ok); + + for (j = 0; j < n; j++) { + bdg = VECTOR_SLOT(bindings, 0); + if (ALIAS_DEBUG && j == 0) + printf("%d: %s\n", 0, bdg->alias); + prev = scan_devname(bdg->alias, ra[j].prefix); + i = 1; + vector_foreach_slot_after(bindings, bdg, i) { + if (ALIAS_DEBUG && j == 0) + printf("%d: %s\n", i, bdg->alias); + tmp = scan_devname(bdg->alias, ra[j].prefix); + if (tmp == -1) + continue; + curr = tmp; + if (prev > 0) { + if (curr <= prev) + printf("ERROR: %d (%s) %d >= %d\n", + i, bdg->alias, prev, curr); + assert_true(curr > prev); + } + prev = curr; + } + } +} + +static void order_01(void **state) +{ + struct random_aliases ra[] = { + { 0, 1000, "MPATH" }, + }; + + order_test(ARRAY_SIZE(ra), ra, false); +} + +static void order_02(void **state) +{ + struct random_aliases ra[] = { + { 0, 500, "MPATH" }, + { 200, 700, "mpath" }, + }; + order_test(ARRAY_SIZE(ra), ra, false); +} + +static void order_03(void **state) +{ + struct random_aliases ra[] = { + { 500, 1000, "MPTH" }, + { 0, 500, "MPATH" }, + }; + order_test(ARRAY_SIZE(ra), ra, false); +} + +static void order_04(void **state) +{ + struct random_aliases ra[] = { + { 0, 500, "mpa" }, + { 250, 750, "mp" }, + }; + order_test(ARRAY_SIZE(ra), ra, true); +} + +static void order_05(void **state) +{ + struct random_aliases ra[] = { + { 0, 100, "A" }, + { 0, 100, "B" }, + { 0, 100, "C" }, + { 0, 100, "D" }, + }; + order_test(ARRAY_SIZE(ra), ra, false); +} + +static void order_06(void **state) +{ + struct random_aliases ra[] = { + { 0, 100, "" }, + { 0, 100, "a" }, + { 0, 100, "aa" }, + { 0, 100, "ab" }, + { 0, 100, "aaa" }, + }; + order_test(ARRAY_SIZE(ra), ra, true); +} + +static int test_bindings_order() +{ + const struct CMUnitTest tests[] = { + cmocka_unit_test_teardown(order_01, teardown_bindings), + cmocka_unit_test_teardown(order_02, teardown_bindings), + cmocka_unit_test_teardown(order_03, teardown_bindings), + cmocka_unit_test_teardown(order_04, teardown_bindings), + cmocka_unit_test_teardown(order_05, teardown_bindings), + cmocka_unit_test_teardown(order_06, teardown_bindings), + }; + + return cmocka_run_group_tests(tests, NULL, NULL); +} + int main(void) { int ret = 0; @@ -1755,6 +1960,7 @@ int main(void) ret += test_rlookup_binding(); ret += test_allocate_binding(); ret += test_get_user_friendly_alias(); + ret += test_bindings_order(); return ret; } From patchwork Mon Sep 11 16:38:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13380864 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CF793CA0EC3 for ; Tue, 12 Sep 2023 06:47:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694501223; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=meGRM5SPB8ekmoVoOo0ZUYXZ4JiIyoS5iZIVCmyEal8=; b=Kp9PnnzH/kbTeaxG02lmmJ/9yxHbAWPg0u8AIohC5yFU6AqPTR8Jy+s7r4Ar4j1Egw9Egj 3pnyVtXmlOmq6jUyY8BGyhEIGGQHU09O3qEWki2Fe6l1XWCVqCkj78Kt0NmiTmmLw0rGdM 8Ttwyen94bEGu0eTQsJov/sQGcjfsJc= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-527-b1VQTvLHMwOTVln-mxTocA-1; Tue, 12 Sep 2023 02:47:01 -0400 X-MC-Unique: b1VQTvLHMwOTVln-mxTocA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5AB46801FA9; Tue, 12 Sep 2023 06:46:59 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4614E40C6EA8; Tue, 12 Sep 2023 06:46:57 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id F211D1946597; Tue, 12 Sep 2023 06:46:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 7E86819465BA for ; Mon, 11 Sep 2023 16:39:27 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 709094405A; Mon, 11 Sep 2023 16:39:27 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 69B2044029 for ; Mon, 11 Sep 2023 16:39:27 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4880B816526 for ; Mon, 11 Sep 2023 16:39:27 +0000 (UTC) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-649-LtoF0y5iMjCDmUdi6JfTug-1; Mon, 11 Sep 2023 12:39:23 -0400 X-MC-Unique: LtoF0y5iMjCDmUdi6JfTug-1 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id A6DE521863; Mon, 11 Sep 2023 16:39:21 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 6B44C139CC; Mon, 11 Sep 2023 16:39:21 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id aDBtGLlC/2RzEAAAMHmgww (envelope-from ); Mon, 11 Sep 2023 16:39:21 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Mon, 11 Sep 2023 18:38:36 +0200 Message-ID: <20230911163846.27197-28-mwilck@suse.com> In-Reply-To: <20230911163846.27197-1-mwilck@suse.com> References: <20230911163846.27197-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mailman-Approved-At: Tue, 12 Sep 2023 06:46:55 +0000 Subject: [dm-devel] [PATCH v2 27/37] multipathd: watch bindings file with inotify + timestamp X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dm-devel@redhat.com, Martin Wilck Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: suse.com From: Martin Wilck Since "libmultipath: keep bindings in memory", we don't re-read the bindings file after every modification. Add a notification mechanism that makes multipathd aware of changes to the bindings file. Because multipathd itself will change the bindings file, it must compare timestamps in order to avoid reading the file repeatedly. Because select_alias() can be called from multiple thread contexts (uxlsnr, uevent handler), we need to add locking for the bindings file. The timestamp must also be protected by a lock, because it can't be read or written atomically. Note: The notification mechanism expects the bindings file to be atomically replaced by rename(2). Changes must be made in a temporary file and applied using rename(2), as in update_bindings_file(). The inotify mechanism deliberately does not listen to close-after-write events that would be generated by editing the bindings file directly. This Note also: new bindings will only be read from add_map_with_path(), i.e. either during reconfigure(), or when a new map is created during runtime. Existing maps will not be renamed if the binding file changes, unless the user runs "multipathd reconfigure". This is not a change wrt the previous code, but it should be mentioned anyway. Signed-off-by: Martin Wilck libmultipath: protect global_bindings with a mutex Signed-off-by: Martin Wilck libmultipath: check timestamp of bindings file before reading it Signed-off-by: Martin Wilck --- libmultipath/alias.c | 250 +++++++++++++++++++++++++----- libmultipath/alias.h | 3 +- libmultipath/libmultipath.version | 5 + multipathd/uxlsnr.c | 36 ++++- tests/alias.c | 3 + 5 files changed, 252 insertions(+), 45 deletions(-) diff --git a/libmultipath/alias.c b/libmultipath/alias.c index 66e34e3..76ed62d 100644 --- a/libmultipath/alias.c +++ b/libmultipath/alias.c @@ -10,6 +10,7 @@ #include #include #include +#include #include "debug.h" #include "util.h" @@ -22,6 +23,7 @@ #include "config.h" #include "devmapper.h" #include "strbuf.h" +#include "time-util.h" /* * significant parts of this file were taken from iscsi-bindings.c of the @@ -50,6 +52,12 @@ "# alias wwid\n" \ "#\n" +/* uatomic access only */ +static int bindings_file_changed = 1; + +static pthread_mutex_t timestamp_mutex = PTHREAD_MUTEX_INITIALIZER; +static struct timespec bindings_last_updated; + struct binding { char *alias; char *wwid; @@ -60,6 +68,9 @@ struct binding { * an abstract type. */ typedef struct _vector Bindings; + +/* Protect global_bindings */ +static pthread_mutex_t bindings_mutex = PTHREAD_MUTEX_INITIALIZER; static Bindings global_bindings = { .allocated = 0 }; enum { @@ -78,6 +89,26 @@ static void _free_binding(struct binding *bdg) free(bdg); } +static void free_bindings(Bindings *bindings) +{ + struct binding *bdg; + int i; + + vector_foreach_slot(bindings, bdg, i) + _free_binding(bdg); + vector_reset(bindings); +} + +static void set_global_bindings(Bindings *bindings) +{ + Bindings old_bindings = global_bindings; + + pthread_mutex_lock(&bindings_mutex); + global_bindings = *bindings; + pthread_mutex_unlock(&bindings_mutex); + free_bindings(&old_bindings); +} + static const struct binding *get_binding_for_alias(const Bindings *bindings, const char *alias) { @@ -199,7 +230,8 @@ static int delete_binding(Bindings *bindings, const char *wwid) return BINDING_DELETED; } -static int write_bindings_file(const Bindings *bindings, int fd) +static int write_bindings_file(const Bindings *bindings, int fd, + struct timespec *ts) { struct binding *bnd; STRBUF_ON_STACK(content); @@ -227,9 +259,56 @@ static int write_bindings_file(const Bindings *bindings, int fd) } len -= n; } + fsync(fd); + if (ts) { + struct stat st; + + if (fstat(fd, &st) == 0) + *ts = st.st_mtim; + else + clock_gettime(CLOCK_REALTIME_COARSE, ts); + } return 0; } +void handle_bindings_file_inotify(const struct inotify_event *event) +{ + struct config *conf; + const char *base; + bool changed = false; + struct stat st; + struct timespec ts = { 0 }; + int ret; + + if (!(event->mask & IN_MOVED_TO)) + return; + + conf = get_multipath_config(); + base = strrchr(conf->bindings_file, '/'); + changed = base && base > conf->bindings_file && + !strcmp(base + 1, event->name); + ret = stat(conf->bindings_file, &st); + put_multipath_config(conf); + + if (!changed) + return; + + pthread_mutex_lock(×tamp_mutex); + if (ret == 0) { + ts = st.st_mtim; + changed = timespeccmp(&ts, &bindings_last_updated) > 0; + } + pthread_mutex_unlock(×tamp_mutex); + + if (changed) { + uatomic_xchg(&bindings_file_changed, 1); + condlog(3, "%s: bindings file must be re-read, new timestamp: %ld.%06ld", + __func__, (long)ts.tv_sec, (long)ts.tv_nsec / 1000); + } else + condlog(3, "%s: bindings file is up-to-date, timestamp: %ld.%06ld", + __func__, (long)ts.tv_sec, (long)ts.tv_nsec / 1000); +} + static int update_bindings_file(const Bindings *bindings, const char *bindings_file) { @@ -237,6 +316,7 @@ static int update_bindings_file(const Bindings *bindings, int fd = -1; char tempname[PATH_MAX]; mode_t old_umask; + struct timespec ts; if (safe_sprintf(tempname, "%s.XXXXXX", bindings_file)) return -1; @@ -248,7 +328,7 @@ static int update_bindings_file(const Bindings *bindings, } umask(old_umask); pthread_cleanup_push(cleanup_fd_ptr, &fd); - rc = write_bindings_file(bindings, fd); + rc = write_bindings_file(bindings, fd, &ts); pthread_cleanup_pop(1); if (rc == -1) { condlog(1, "failed to write new bindings file"); @@ -257,8 +337,12 @@ static int update_bindings_file(const Bindings *bindings, } if ((rc = rename(tempname, bindings_file)) == -1) condlog(0, "%s: rename: %m", __func__); - else + else { condlog(1, "updated bindings file %s", bindings_file); + pthread_mutex_lock(×tamp_mutex); + bindings_last_updated = ts; + pthread_mutex_unlock(×tamp_mutex); + } return rc; } @@ -387,6 +471,7 @@ int get_free_id(const Bindings *bindings, const char *prefix, const char *map_ww return id; } +/* Called with binding_mutex held */ static char * allocate_binding(const char *filename, const char *wwid, int id, const char *prefix) { @@ -423,6 +508,30 @@ allocate_binding(const char *filename, const char *wwid, int id, const char *pre return alias; } +enum { + BINDINGS_FILE_UP2DATE, + BINDINGS_FILE_READ, + BINDINGS_FILE_ERROR, + BINDINGS_FILE_BAD, +}; + +static int _read_bindings_file(const struct config *conf, Bindings *bindings, + bool force); + +static void read_bindings_file(void) +{ + struct config *conf; + Bindings bindings = {.allocated = 0, }; + int rc; + + conf = get_multipath_config(); + pthread_cleanup_push(put_multipath_config, conf); + rc = _read_bindings_file(conf, &bindings, false); + pthread_cleanup_pop(1); + if (rc == BINDINGS_FILE_READ) + set_global_bindings(&bindings); +} + /* * get_user_friendly_alias() action table * @@ -463,6 +572,11 @@ char *get_user_friendly_alias(const char *wwid, const char *file, const char *al bool new_binding = false; const struct binding *bdg; + read_bindings_file(); + + pthread_mutex_lock(&bindings_mutex); + pthread_cleanup_push(cleanup_mutex, &bindings_mutex); + if (!*alias_old) goto new_alias; @@ -514,40 +628,38 @@ new_alias: alias, wwid); out: + /* unlock bindings_mutex */ + pthread_cleanup_pop(1); return alias; } int get_user_friendly_wwid(const char *alias, char *buff) { const struct binding *bdg; + int rc = -1; if (!alias || *alias == '\0') { condlog(3, "Cannot find binding for empty alias"); return -1; } + pthread_mutex_lock(&bindings_mutex); + pthread_cleanup_push(cleanup_mutex, &bindings_mutex); bdg = get_binding_for_alias(&global_bindings, alias); - if (!bdg) { + if (bdg) { + strlcpy(buff, bdg->wwid, WWID_SIZE); + rc = 0; + } else *buff = '\0'; - return -1; - } - strlcpy(buff, bdg->wwid, WWID_SIZE); - return 0; -} - -static void free_bindings(Bindings *bindings) -{ - struct binding *bdg; - int i; - - vector_foreach_slot(bindings, bdg, i) - _free_binding(bdg); - vector_reset(bindings); + pthread_cleanup_pop(1); + return rc; } void cleanup_bindings(void) { + pthread_mutex_lock(&bindings_mutex); free_bindings(&global_bindings); + pthread_mutex_unlock(&bindings_mutex); } enum { @@ -595,7 +707,21 @@ static int _check_bindings_file(const struct config *conf, FILE *file, char *line = NULL; size_t line_len = 0; ssize_t n; + char header[sizeof(BINDINGS_FILE_HEADER)]; + header[sizeof(BINDINGS_FILE_HEADER) - 1] = '\0'; + if (fread(header, sizeof(BINDINGS_FILE_HEADER) - 1, 1, file) + < sizeof(BINDINGS_FILE_HEADER) - 1) { + condlog(2, "%s: failed to read header from %s", __func__, + conf->bindings_file); + fseek(file, 0, SEEK_SET); + rc = -1; + } else if (strcmp(header, BINDINGS_FILE_HEADER)) { + condlog(2, "%s: invalid header in %s", __func__, + conf->bindings_file); + fseek(file, 0, SEEK_SET); + rc = -1; + } pthread_cleanup_push(cleanup_free_ptr, &line); while ((n = getline(&line, &line_len, file)) >= 0) { char *alias, *wwid; @@ -643,6 +769,68 @@ static int mp_alias_compar(const void *p1, const void *p2) &((*(struct mpentry * const *)p2)->alias)); } +static int _read_bindings_file(const struct config *conf, Bindings *bindings, + bool force) +{ + int can_write; + int rc = 0, ret, fd; + FILE *file; + struct stat st; + int has_changed = uatomic_xchg(&bindings_file_changed, 0); + + if (!force) { + if (!has_changed) { + condlog(4, "%s: bindings are unchanged", __func__); + return BINDINGS_FILE_UP2DATE; + } + } + + fd = open_file(conf->bindings_file, &can_write, BINDINGS_FILE_HEADER); + if (fd == -1) + return BINDINGS_FILE_ERROR; + + file = fdopen(fd, "r"); + if (file != NULL) { + condlog(3, "%s: reading %s", __func__, conf->bindings_file); + + pthread_cleanup_push(cleanup_fclose, file); + ret = _check_bindings_file(conf, file, bindings); + if (ret == 0) { + struct timespec ts; + + rc = BINDINGS_FILE_READ; + ret = fstat(fd, &st); + if (ret == 0) + ts = st.st_mtim; + else { + condlog(1, "%s: fstat failed (%m), using current time", __func__); + clock_gettime(CLOCK_REALTIME_COARSE, &ts); + } + pthread_mutex_lock(×tamp_mutex); + bindings_last_updated = ts; + pthread_mutex_unlock(×tamp_mutex); + } else if (ret == -1 && can_write && !conf->bindings_read_only) { + ret = update_bindings_file(bindings, conf->bindings_file); + if (ret == 0) + rc = BINDINGS_FILE_READ; + else + rc = BINDINGS_FILE_BAD; + } else if (ret == -1) { + condlog(0, "ERROR: bad settings in read-only bindings file %s", + conf->bindings_file); + rc = BINDINGS_FILE_BAD; + } + pthread_cleanup_pop(1); + } else { + condlog(1, "failed to fdopen %s: %m", + conf->bindings_file); + close(fd); + rc = BINDINGS_FILE_ERROR; + } + + return rc; +} + /* * check_alias_settings(): test for inconsistent alias configuration * @@ -661,8 +849,7 @@ static int mp_alias_compar(const void *p1, const void *p2) */ int check_alias_settings(const struct config *conf) { - int can_write; - int rc = 0, i, fd; + int i, rc; Bindings bindings = {.allocated = 0, }; vector mptable = NULL; struct mpentry *mpe; @@ -695,27 +882,12 @@ int check_alias_settings(const struct config *conf) pthread_cleanup_pop(1); pthread_cleanup_pop(1); - fd = open_file(conf->bindings_file, &can_write, BINDINGS_FILE_HEADER); - if (fd != -1) { - FILE *file = fdopen(fd, "r"); + rc = _read_bindings_file(conf, &bindings, true); - if (file != NULL) { - pthread_cleanup_push(cleanup_fclose, file); - rc = _check_bindings_file(conf, file, &bindings); - pthread_cleanup_pop(1); - if (rc == -1 && can_write && !conf->bindings_read_only) - rc = update_bindings_file(&bindings, conf->bindings_file); - else if (rc == -1) - condlog(0, "ERROR: bad settings in read-only bindings file %s", - conf->bindings_file); - } else { - condlog(1, "failed to fdopen %s: %m", - conf->bindings_file); - close(fd); - } + if (rc == BINDINGS_FILE_READ) { + set_global_bindings(&bindings); + rc = 0; } - cleanup_bindings(); - global_bindings = bindings; return rc; } diff --git a/libmultipath/alias.h b/libmultipath/alias.h index 5ef6720..ca8911f 100644 --- a/libmultipath/alias.h +++ b/libmultipath/alias.h @@ -10,5 +10,6 @@ char *get_user_friendly_alias(const char *wwid, const char *file, struct config; int check_alias_settings(const struct config *); void cleanup_bindings(void); - +struct inotify_event; +void handle_bindings_file_inotify(const struct inotify_event *event); #endif /* _ALIAS_H */ diff --git a/libmultipath/libmultipath.version b/libmultipath/libmultipath.version index ddd302f..57e50c1 100644 --- a/libmultipath/libmultipath.version +++ b/libmultipath/libmultipath.version @@ -238,3 +238,8 @@ global: local: *; }; + +LIBMULTIPATH_20.1.0 { +global: + handle_bindings_file_inotify; +}; diff --git a/multipathd/uxlsnr.c b/multipathd/uxlsnr.c index 02e89fb..d1f8f23 100644 --- a/multipathd/uxlsnr.c +++ b/multipathd/uxlsnr.c @@ -41,6 +41,7 @@ #include "cli.h" #include "uxlsnr.h" #include "strbuf.h" +#include "alias.h" /* state of client connection */ enum { @@ -190,6 +191,7 @@ void wakeup_cleanup(void *arg) struct watch_descriptors { int conf_wd; int dir_wd; + int mp_wd; /* /etc/multipath; for bindings file */ }; /* failing to set the watch descriptor is o.k. we just miss a warning @@ -200,6 +202,8 @@ static void reset_watch(int notify_fd, struct watch_descriptors *wds, struct config *conf; int dir_reset = 0; int conf_reset = 0; + int mp_reset = 0; + char *bindings_file __attribute__((cleanup(cleanup_charp))) = NULL; if (notify_fd == -1) return; @@ -214,7 +218,10 @@ static void reset_watch(int notify_fd, struct watch_descriptors *wds, conf_reset = 1; if (wds->dir_wd == -1) dir_reset = 1; + if (wds->mp_wd == -1) + mp_reset = 1; } + bindings_file = strdup(conf->bindings_file); put_multipath_config(conf); if (dir_reset) { @@ -235,7 +242,18 @@ static void reset_watch(int notify_fd, struct watch_descriptors *wds, if (wds->conf_wd == -1) condlog(3, "didn't set up notifications on /etc/multipath.conf: %m"); } - return; + if (mp_reset && bindings_file) { + char *slash = strrchr(bindings_file, '/'); + + if (slash && slash > bindings_file) { + *slash = '\0'; + wds->mp_wd = inotify_add_watch(notify_fd, bindings_file, + IN_MOVED_TO|IN_ONLYDIR); + if (wds->mp_wd == -1) + condlog(3, "didn't set up notifications on %s: %m", + bindings_file); + } + } } static void handle_inotify(int fd, struct watch_descriptors *wds) @@ -256,12 +274,13 @@ static void handle_inotify(int fd, struct watch_descriptors *wds) inotify_rm_watch(fd, wds->conf_wd); if (wds->dir_wd != -1) inotify_rm_watch(fd, wds->dir_wd); - wds->conf_wd = wds->dir_wd = -1; + if (wds->mp_wd != -1) + inotify_rm_watch(fd, wds->mp_wd); + wds->conf_wd = wds->dir_wd = wds->mp_wd = -1; } break; } - got_notify = 1; for (ptr = buff; ptr < buff + len; ptr += sizeof(struct inotify_event) + event->len) { event = (const struct inotify_event *) ptr; @@ -273,7 +292,13 @@ static void handle_inotify(int fd, struct watch_descriptors *wds) wds->conf_wd = inotify_add_watch(notify_fd, DEFAULT_CONFIGFILE, IN_CLOSE_WRITE); else if (wds->dir_wd == event->wd) wds->dir_wd = -1; + else if (wds->mp_wd == event->wd) + wds->mp_wd = -1; } + if (wds->mp_wd != -1 && wds->mp_wd == event->wd) + handle_bindings_file_inotify(event); + else + got_notify = 1; } } if (got_notify) @@ -599,7 +624,7 @@ void *uxsock_listen(long ux_sock, void *trigger_data) int max_pfds = MIN_POLLS + POLLFDS_BASE; /* conf->sequence_nr will be 1 when uxsock_listen is first called */ unsigned int sequence_nr = 0; - struct watch_descriptors wds = { .conf_wd = -1, .dir_wd = -1 }; + struct watch_descriptors wds = { .conf_wd = -1, .dir_wd = -1, .mp_wd = -1, }; struct vectors *vecs = trigger_data; condlog(3, "uxsock: startup listener"); @@ -666,7 +691,8 @@ void *uxsock_listen(long ux_sock, void *trigger_data) reset_watch(notify_fd, &wds, &sequence_nr); polls[POLLFD_NOTIFY].fd = notify_fd; - if (notify_fd == -1 || (wds.conf_wd == -1 && wds.dir_wd == -1)) + if (notify_fd == -1 || (wds.conf_wd == -1 && wds.dir_wd == -1 + && wds.mp_wd == -1)) polls[POLLFD_NOTIFY].events = 0; else polls[POLLFD_NOTIFY].events = POLLIN; diff --git a/tests/alias.c b/tests/alias.c index 2e765fb..872b1fc 100644 --- a/tests/alias.c +++ b/tests/alias.c @@ -1954,6 +1954,9 @@ int main(void) int ret = 0; init_test_verbosity(3); + /* avoid open_file() call in _read_bindings_file */ + bindings_file_changed = 0; + ret += test_format_devname(); ret += test_scan_devname(); ret += test_lookup_binding(); From patchwork Mon Sep 11 16:38:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13379499 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BEE11EEB57E for ; Mon, 11 Sep 2023 16:39:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694450386; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=FjUQLO3WYpbNTU34IKy1plm0822u9TuvJclrmLm3veU=; b=h4vrRilFpUYEMJwQ7huWV4Hv6Wch/s/07u5sPC7daBQkSb1jdnc+cEr0awYtjc9bBFICvP i9FNsbPmtdqNKGWJbP90uRe0w5y+KVUGxNca30aoYCcMcHEJ9rq+AfNXWPMtcH4gz6H6Rx Qi6hKNwa8dHquoA9NVJvvoXcDNZkrmo= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-345-dXRVL37CMNC7Ur8FwHTRdw-1; Mon, 11 Sep 2023 12:39:38 -0400 X-MC-Unique: dXRVL37CMNC7Ur8FwHTRdw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0141D928BAC; Mon, 11 Sep 2023 16:39:28 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id E15421006B56; Mon, 11 Sep 2023 16:39:27 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 4F5AF19465B5; Mon, 11 Sep 2023 16:39:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 96D1919465A2 for ; Mon, 11 Sep 2023 16:39:25 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 6753F2022EBE; Mon, 11 Sep 2023 16:39:25 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast09.extmail.prod.ext.rdu2.redhat.com [10.11.55.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5F4092023466 for ; Mon, 11 Sep 2023 16:39:25 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 40DB429DD991 for ; Mon, 11 Sep 2023 16:39:25 +0000 (UTC) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-597-SD0FEZ-_OGew-dtfscNXsA-1; Mon, 11 Sep 2023 12:39:23 -0400 X-MC-Unique: SD0FEZ-_OGew-dtfscNXsA-1 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id E12C321875; Mon, 11 Sep 2023 16:39:21 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id B2731139CC; Mon, 11 Sep 2023 16:39:21 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id aN7kKblC/2RzEAAAMHmgww (envelope-from ); Mon, 11 Sep 2023 16:39:21 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Mon, 11 Sep 2023 18:38:37 +0200 Message-ID: <20230911163846.27197-29-mwilck@suse.com> In-Reply-To: <20230911163846.27197-1-mwilck@suse.com> References: <20230911163846.27197-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 Subject: [dm-devel] [PATCH v2 28/37] multipath-tools tests: mock pthread_mutex_{lock, unlock} X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dm-devel@redhat.com, Martin Wilck Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: suse.com From: Martin Wilck If some test fails with a lock held, cmocka doesn't deal well with pthread_cleanup_pop(). Such tests can cause deadlock with the locking primitives in the alias code, because locks don't get properly unlocked. Just mock the lock/unlock functions and generate an error if they weren't paired at the end of the test. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- tests/Makefile | 1 + tests/alias.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/tests/Makefile b/tests/Makefile index c777d07..7dac8a8 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -52,6 +52,7 @@ blacklist-test_LIBDEPS := -ludev 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 valid-test_OBJDEPS := $(multipathdir)/valid.o $(multipathdir)/discovery.o valid-test_LIBDEPS := -lmount -ludev -lpthread -ldl diff --git a/tests/alias.c b/tests/alias.c index 872b1fc..962c158 100644 --- a/tests/alias.c +++ b/tests/alias.c @@ -89,6 +89,47 @@ int __wrap_dm_get_uuid(const char *name, char *uuid, int uuid_len) return ret; } +static int lock_errors; +static int bindings_locked; +static int timestamp_locked; +int __wrap_pthread_mutex_lock(pthread_mutex_t *mutex) +{ + if (mutex == &bindings_mutex) { + if (bindings_locked) { + fprintf(stderr, "%s: bindings_mutex LOCKED\n", __func__); + lock_errors++; + } + bindings_locked = 1; + } else if (mutex == ×tamp_mutex) { + if (timestamp_locked) { + fprintf(stderr, "%s: timestamp_mutex LOCKED\n", __func__); + lock_errors++; + } + timestamp_locked = 1; + } else + fprintf(stderr, "%s called for unknown mutex %p\n", __func__, mutex); + return 0; +} + +int __wrap_pthread_mutex_unlock(pthread_mutex_t *mutex) +{ + if (mutex == &bindings_mutex) { + if (!bindings_locked) { + fprintf(stderr, "%s: bindings_mutex UNLOCKED\n", __func__); + lock_errors++; + } + bindings_locked = 0; + } else if (mutex == ×tamp_mutex) { + if (!timestamp_locked) { + fprintf(stderr, "%s: timestamp_mutex UNLOCKED\n", __func__); + lock_errors++; + } + timestamp_locked = 0; + } else + fprintf(stderr, "%s called for unknown mutex %p\n", __func__, mutex); + return 0; +} + #define TEST_FDNO 1234 #define TEST_FPTR ((FILE *) 0xaffe) @@ -1718,6 +1759,10 @@ static void gufa_old_nomatch_nowwidmatch(void **state) { free(alias); } +static void gufa_check_locking(void **state) { + assert_int_equal(lock_errors, 0); +} + static int test_get_user_friendly_alias() { const struct CMUnitTest tests[] = { @@ -1743,6 +1788,7 @@ static int test_get_user_friendly_alias() cmocka_unit_test_teardown(gufa_old_nomatch_wwidmatch, teardown_bindings), cmocka_unit_test_teardown(gufa_old_nomatch_wwidmatch_used, teardown_bindings), cmocka_unit_test_teardown(gufa_old_nomatch_nowwidmatch, teardown_bindings), + cmocka_unit_test(gufa_check_locking), }; return cmocka_run_group_tests(tests, NULL, NULL); From patchwork Mon Sep 11 16:38:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13379513 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EC72FEEB58F for ; Mon, 11 Sep 2023 16:39:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694450395; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=2Kd2HuqH76UMYRQH2gn84U4jhVE6Z7VCmB7FHrynx2k=; b=DbwefPnaF0GrZR9nKXKZ61cmRVDZxCsJrXvfAmDynH4uTS9POsB2Ryfnghbn+ybSW5PKKg LfwldDZIXnH5AbazEH3sJ/7yNx2h4eLMCVT0anfMwiQ2mGgaZxFUfa05cAsebF8R2s0L6o p/HPhLISxYqHaZbpU/Y7qhL/GfS0YBU= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-17-rA3XJyLDNfayeAIZ78ZuxA-1; Mon, 11 Sep 2023 12:39:51 -0400 X-MC-Unique: rA3XJyLDNfayeAIZ78ZuxA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 78226101FACF; Mon, 11 Sep 2023 16:39:27 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 60B7E40C200B; Mon, 11 Sep 2023 16:39:27 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id DA42D1946A44; Mon, 11 Sep 2023 16:39:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 5DCAC19465A3 for ; Mon, 11 Sep 2023 16:39:25 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 4CE362024CD5; Mon, 11 Sep 2023 16:39:25 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast09.extmail.prod.ext.rdu2.redhat.com [10.11.55.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4512820268C8 for ; Mon, 11 Sep 2023 16:39:25 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2788929DD993 for ; Mon, 11 Sep 2023 16:39:25 +0000 (UTC) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-677-a1BVh0ySPoqUvSl69uusIQ-1; Mon, 11 Sep 2023 12:39:23 -0400 X-MC-Unique: a1BVh0ySPoqUvSl69uusIQ-1 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 26EBA21882; Mon, 11 Sep 2023 16:39:22 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id ECCCD139CC; Mon, 11 Sep 2023 16:39:21 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id cGsZOLlC/2RzEAAAMHmgww (envelope-from ); Mon, 11 Sep 2023 16:39:21 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Mon, 11 Sep 2023 18:38:38 +0200 Message-ID: <20230911163846.27197-30-mwilck@suse.com> In-Reply-To: <20230911163846.27197-1-mwilck@suse.com> References: <20230911163846.27197-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 Subject: [dm-devel] [PATCH v2 29/37] multipath-tools Makefile: sanitize paths for configuration files X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dm-devel@redhat.com, Martin Wilck Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: suse.com From: Martin Wilck Make the path to multipath.conf configurable, and use the same prefix by default for multipath.conf and multipath/conf.d. For "usr-merged" distributions with immutable /usr, we'll want to have the configuration under a different prefix. This can be achieved by using e.g. make prefix=/usr etc_prefix="" Note that with prefix=/usr, before this patch the code would use /usr/etc/multipath/conf.d, but /etc/multipath.conf. If this (rather inconsistent) behavior is desired, use the following command line: make prefix=/usr configfile=/etc/multipath.conf Reviewed-by: Benjamin Marzinski --- Makefile.inc | 9 ++++++--- libmultipath/defaults.h | 1 - 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Makefile.inc b/Makefile.inc index 502cd0f..39972d9 100644 --- a/Makefile.inc +++ b/Makefile.inc @@ -37,6 +37,8 @@ prefix := exec_prefix := $(prefix) # Prefix for non-essential libraries (libdmmp) usr_prefix := $(prefix) +# Prefix for configfuration files (multipath.conf) +etc_prefix := $(prefix) # Where to install systemd-related files. systemd is usually installed under /usr # Note: some systemd installations use separate "prefix" and "rootprefix". # In this case, override only unitdir to use systemd's "rootprefix" instead of $(systemd_prefix) @@ -54,7 +56,8 @@ usrlibdir := $(usr_prefix)/$(LIB) includedir := $(usr_prefix)/include pkgconfdir := $(usrlibdir)/pkgconfig plugindir := $(prefix)/$(LIB)/multipath -configdir := $(prefix)/etc/multipath/conf.d +configdir := $(etc_prefix)/etc/multipath/conf.d +configfile := $(etc_prefix)/etc/multipath.conf runtimedir := $(if $(shell test -L /var/run -o ! -d /var/run && echo 1),/run,/var/run) devmapper_incdir := $(or $(shell $(PKG_CONFIG) --variable=includedir devmapper),/usr/include) libudev_incdir := $(or $(shell $(PKG_CONFIG) --variable=includedir libudev),/usr/include) @@ -84,8 +87,8 @@ WARNFLAGS := -Werror -Wall -Wextra -Wformat=2 $(WFORMATOVERFLOW) -Werror=implici $(WNOCLOBBERED) -Werror=cast-qual $(ERROR_DISCARDED_QUALIFIERS) $(W_URCU_TYPE_LIMITS) CPPFLAGS := $(FORTIFY_OPT) $(CPPFLAGS) \ -DBIN_DIR=\"$(bindir)\" -DMULTIPATH_DIR=\"$(plugindir)\" \ - -DRUNTIME_DIR=\"$(runtimedir)\" \ - -DCONFIG_DIR=\"$(configdir)\" -DEXTRAVERSION=\"$(EXTRAVERSION)\" -MMD -MP + -DRUNTIME_DIR=\"$(runtimedir)\" -DCONFIG_DIR=\"$(configdir)\" \ + -DDEFAULT_CONFIGFILE=\"$(configfile)\" -DEXTRAVERSION=\"$(EXTRAVERSION)\" -MMD -MP CFLAGS := --std=gnu99 $(CFLAGS) $(OPTFLAGS) $(WARNFLAGS) -pipe BIN_CFLAGS := -fPIE -DPIE LIB_CFLAGS := -fPIC diff --git a/libmultipath/defaults.h b/libmultipath/defaults.h index b3f11d4..bc2d638 100644 --- a/libmultipath/defaults.h +++ b/libmultipath/defaults.h @@ -66,7 +66,6 @@ #define MAX_DEV_LOSS_TMO UINT_MAX #define DEFAULT_PIDFILE RUNTIME_DIR "/multipathd.pid" #define DEFAULT_SOCKET "/org/kernel/linux/storage/multipathd" -#define DEFAULT_CONFIGFILE "/etc/multipath.conf" #define DEFAULT_BINDINGS_FILE "/etc/multipath/bindings" #define DEFAULT_WWIDS_FILE "/etc/multipath/wwids" #define DEFAULT_PRKEYS_FILE "/etc/multipath/prkeys" From patchwork Mon Sep 11 16:38:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13379516 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B8A15EEB580 for ; Mon, 11 Sep 2023 16:39:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694450398; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=GDiUel+3E/JdsoqtQ7ZwjWSRQSJJeYXbOgrLMFN+sfU=; b=Cu0rCGLaK17EAOcAap8pmxCBXSUqkcnkB83CaELinT7gzAMtFpfui2GjsCXEE/yFtfRgGj DB3bGFmZx9k5sTWbyvPhnTVd3RGX9ZD5PmRm/PNFWjFNFD+qeamjmcmLRYEvbjNTxipcEL M7QlmhNSaJoy5O+qduGTd3bO4EUqSjE= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-692-yaszy-QxNGexoDUQl0qpNA-1; Mon, 11 Sep 2023 12:39:55 -0400 X-MC-Unique: yaszy-QxNGexoDUQl0qpNA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D4B2A381BE83; Mon, 11 Sep 2023 16:39:32 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id C11F840C6ECA; Mon, 11 Sep 2023 16:39:32 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 863DA1946A45; Mon, 11 Sep 2023 16:39:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 6957619465B7 for ; Mon, 11 Sep 2023 16:39:27 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 49D3144069; Mon, 11 Sep 2023 16:39:27 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3FBCF4407D for ; Mon, 11 Sep 2023 16:39:27 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2207A101FAC5 for ; Mon, 11 Sep 2023 16:39:27 +0000 (UTC) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-679-vfeLdAbbPVOqKq55UP8uHA-1; Mon, 11 Sep 2023 12:39:23 -0400 X-MC-Unique: vfeLdAbbPVOqKq55UP8uHA-1 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 6008B1F88C; Mon, 11 Sep 2023 16:39:22 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 31DFD139CC; Mon, 11 Sep 2023 16:39:22 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id cDGQCrpC/2RzEAAAMHmgww (envelope-from ); Mon, 11 Sep 2023 16:39:22 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Mon, 11 Sep 2023 18:38:39 +0200 Message-ID: <20230911163846.27197-31-mwilck@suse.com> In-Reply-To: <20230911163846.27197-1-mwilck@suse.com> References: <20230911163846.27197-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Subject: [dm-devel] [PATCH v2 30/37] multipath-tools: add compile time configuration for "/etc/multipath" X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dm-devel@redhat.com, Martin Wilck Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: suse.com From: Martin Wilck Instead of hard-conding "/etc/multipath" as the path for the state files "bindings", "prkeys", and "wwids", make this path configurable via the "statedir" compile-time option. The default is currently still /etc, it might change to /var/lib or similar in the future. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- Makefile.inc | 4 +++- libmultipath/defaults.h | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Makefile.inc b/Makefile.inc index 39972d9..96206b2 100644 --- a/Makefile.inc +++ b/Makefile.inc @@ -58,6 +58,7 @@ pkgconfdir := $(usrlibdir)/pkgconfig plugindir := $(prefix)/$(LIB)/multipath configdir := $(etc_prefix)/etc/multipath/conf.d configfile := $(etc_prefix)/etc/multipath.conf +statedir := $(etc_prefix)/etc/multipath runtimedir := $(if $(shell test -L /var/run -o ! -d /var/run && echo 1),/run,/var/run) devmapper_incdir := $(or $(shell $(PKG_CONFIG) --variable=includedir devmapper),/usr/include) libudev_incdir := $(or $(shell $(PKG_CONFIG) --variable=includedir libudev),/usr/include) @@ -88,7 +89,8 @@ WARNFLAGS := -Werror -Wall -Wextra -Wformat=2 $(WFORMATOVERFLOW) -Werror=implici CPPFLAGS := $(FORTIFY_OPT) $(CPPFLAGS) \ -DBIN_DIR=\"$(bindir)\" -DMULTIPATH_DIR=\"$(plugindir)\" \ -DRUNTIME_DIR=\"$(runtimedir)\" -DCONFIG_DIR=\"$(configdir)\" \ - -DDEFAULT_CONFIGFILE=\"$(configfile)\" -DEXTRAVERSION=\"$(EXTRAVERSION)\" -MMD -MP + -DDEFAULT_CONFIGFILE=\"$(configfile)\" -DSTATE_DIR=\"$(statedir)\" \ + -DEXTRAVERSION=\"$(EXTRAVERSION)\" -MMD -MP CFLAGS := --std=gnu99 $(CFLAGS) $(OPTFLAGS) $(WARNFLAGS) -pipe BIN_CFLAGS := -fPIE -DPIE LIB_CFLAGS := -fPIC diff --git a/libmultipath/defaults.h b/libmultipath/defaults.h index bc2d638..d01f971 100644 --- a/libmultipath/defaults.h +++ b/libmultipath/defaults.h @@ -66,9 +66,9 @@ #define MAX_DEV_LOSS_TMO UINT_MAX #define DEFAULT_PIDFILE RUNTIME_DIR "/multipathd.pid" #define DEFAULT_SOCKET "/org/kernel/linux/storage/multipathd" -#define DEFAULT_BINDINGS_FILE "/etc/multipath/bindings" -#define DEFAULT_WWIDS_FILE "/etc/multipath/wwids" -#define DEFAULT_PRKEYS_FILE "/etc/multipath/prkeys" +#define DEFAULT_BINDINGS_FILE STATE_DIR "/bindings" +#define DEFAULT_WWIDS_FILE STATE_DIR "/wwids" +#define DEFAULT_PRKEYS_FILE STATE_DIR "/prkeys" #define MULTIPATH_SHM_BASE RUNTIME_DIR "/multipath/" From patchwork Mon Sep 11 16:38:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13379514 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DEBA4EEB57E for ; Mon, 11 Sep 2023 16:39:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694450395; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=HH8khLGceWukN6GLUr4cCKlo1/o2jSSeYjwlL6T97co=; b=EXjFziXmpmxMoKGSMJfFwFMwJrkVnjCUrVFRb90a+V8a8cUChL6GJEgkpkzjTs8F0e1zAi rhhCr1JPD1PazGB3c9qKMQ020QDYQQeFmZVp8D9zURRfSTQrfld+p2NAayrOA3LrGOfG8U sBL7ZvDgh5Wy/xDz5OkrK46lgTF9FIw= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-629-YJoqsGenOvKtP9O4AKuWGA-1; Mon, 11 Sep 2023 12:39:51 -0400 X-MC-Unique: YJoqsGenOvKtP9O4AKuWGA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 047AE3815F74; Mon, 11 Sep 2023 16:39:31 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id E35B140C6EA8; Mon, 11 Sep 2023 16:39:30 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id B562E19465B6; Mon, 11 Sep 2023 16:39:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 4A43819465A8 for ; Mon, 11 Sep 2023 16:39:28 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 398822027046; Mon, 11 Sep 2023 16:39:28 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3187C2027047 for ; Mon, 11 Sep 2023 16:39:28 +0000 (UTC) Received: from us-smtp-inbound-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0F45D945E90 for ; Mon, 11 Sep 2023 16:39:28 +0000 (UTC) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-447-aKibbLd7OpuxzSee96tNDg-1; Mon, 11 Sep 2023 12:39:24 -0400 X-MC-Unique: aKibbLd7OpuxzSee96tNDg-1 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 999F91F8BB; Mon, 11 Sep 2023 16:39:22 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 6A80F139CC; Mon, 11 Sep 2023 16:39:22 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id sB9ZGLpC/2RzEAAAMHmgww (envelope-from ); Mon, 11 Sep 2023 16:39:22 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Mon, 11 Sep 2023 18:38:40 +0200 Message-ID: <20230911163846.27197-32-mwilck@suse.com> In-Reply-To: <20230911163846.27197-1-mwilck@suse.com> References: <20230911163846.27197-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 Subject: [dm-devel] [PATCH v2 31/37] multipath-tools man pages: generate with correct paths X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dm-devel@redhat.com, Martin Wilck Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: suse.com From: Martin Wilck Generate the man pages using the compile-time settings for paths to multipath.conf etc. Add a paragraph about the CONFIGDIR (/etc/multipath/conf.d) and the drop-in configuration files in the multipath.conf man page. Also, make sure all generated man pages and other files are correctly removed by "make clean". Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- .gitignore | 4 +++ Makefile.inc | 3 +++ mpathpersist/Makefile | 5 ++-- .../{mpathpersist.8 => mpathpersist.8.in} | 2 +- multipath/Makefile | 13 +++++---- multipath/{multipath.8 => multipath.8.in} | 10 +++---- .../{multipath.conf.5 => multipath.conf.5.in} | 27 ++++++++++++------- multipathd/Makefile | 9 ++++--- multipathd/{multipathd.8 => multipathd.8.in} | 8 +++--- 9 files changed, 49 insertions(+), 32 deletions(-) rename mpathpersist/{mpathpersist.8 => mpathpersist.8.in} (99%) rename multipath/{multipath.8 => multipath.8.in} (97%) rename multipath/{multipath.conf.5 => multipath.conf.5.in} (98%) rename multipathd/{multipathd.8 => multipathd.8.in} (97%) diff --git a/.gitignore b/.gitignore index 535353e..2986578 100644 --- a/.gitignore +++ b/.gitignore @@ -13,11 +13,15 @@ cscope.files cscope.out kpartx/kpartx multipath/multipath +multipath/multipath.8 +multipath/multipath.conf.5 multipath/multipath.rules multipath/tmpfiles.conf multipathd/multipathd +multipathd/multipathd.8 multipathd/multipathc mpathpersist/mpathpersist +mpathpersist/mpathpersist.8 abi.tar.gz abi abi-test diff --git a/Makefile.inc b/Makefile.inc index 96206b2..79e521e 100644 --- a/Makefile.inc +++ b/Makefile.inc @@ -133,3 +133,6 @@ NV_VERSION_SCRIPT = $(DEVLIB:%.so=%-nv.version) @grep -P '^[ \t]+[a-zA-Z_][a-zA-Z0-9_]*;' $< >>$@ @printf 'local:\n\t*;\n};\n' >>$@ +%: %.in + @echo creating $@ + $(Q)sed 's:@CONFIGFILE@:'$(configfile)':g;s:@CONFIGDIR@:'$(configdir)':g;s:@STATE_DIR@:'$(statedir)':g;s:@RUNTIME_DIR@:'$(runtimedir)':g' $< >$@ diff --git a/mpathpersist/Makefile b/mpathpersist/Makefile index f57c105..f374946 100644 --- a/mpathpersist/Makefile +++ b/mpathpersist/Makefile @@ -8,10 +8,11 @@ LIBDEPS += -L$(mpathpersistdir) -lmpathpersist -L$(multipathdir) -lmultipath \ -L$(mpathutildir) -lmpathutil -L$(mpathcmddir) -lmpathcmd -lpthread -ldevmapper -ludev EXEC = mpathpersist +MANPAGES := mpathpersist.8 OBJS = main.o -all: $(EXEC) +all: $(EXEC) $(MANPAGES) $(EXEC): $(OBJS) $(Q)$(CC) $(OBJS) -o $(EXEC) $(LDFLAGS) $(CFLAGS) $(LIBDEPS) @@ -23,7 +24,7 @@ install: $(Q)$(INSTALL_PROGRAM) -m 644 $(EXEC).8 $(DESTDIR)$(mandir)/man8 clean: dep_clean - $(Q)$(RM) core *.o $(EXEC) + $(Q)$(RM) core *.o $(EXEC) $(MANPAGES) include $(wildcard $(OBJS:.o=.d)) diff --git a/mpathpersist/mpathpersist.8 b/mpathpersist/mpathpersist.8.in similarity index 99% rename from mpathpersist/mpathpersist.8 rename to mpathpersist/mpathpersist.8.in index 8d26b37..fecef0d 100644 --- a/mpathpersist/mpathpersist.8 +++ b/mpathpersist/mpathpersist.8.in @@ -31,7 +31,7 @@ mpathpersist \- Manages SCSI persistent reservations on dm multipath devices. . This utility is used to manage SCSI persistent reservations on Device Mapper Multipath devices. To be able to use this functionality, the \fIreservation_key\fR -attribute must be defined in the \fI/etc/multipath.conf\fR file. Otherwise the +attribute must be defined in the \fI@CONFIGFILE@\fR file. Otherwise the \fBmultipathd\fR daemon will not check for persistent reservation for newly discovered paths or reinstated paths. . diff --git a/multipath/Makefile b/multipath/Makefile index 73db991..68cb5ce 100644 --- a/multipath/Makefile +++ b/multipath/Makefile @@ -3,7 +3,9 @@ # include ../Makefile.inc -EXEC := multipath +EXEC := multipath +MANPAGES := multipath.8 multipath.conf.5 +GENERATED := $(MANPAGES) multipath.rules tmpfiles.conf CPPFLAGS += -I$(multipathdir) -I$(mpathutildir) -I$(mpathcmddir) CFLAGS += $(BIN_CFLAGS) @@ -13,7 +15,7 @@ LIBDEPS += -L$(multipathdir) -lmultipath -L$(mpathutildir) -lmpathutil \ OBJS := main.o -all: $(EXEC) multipath.rules tmpfiles.conf +all: $(EXEC) $(GENERATED) $(EXEC): $(OBJS) $(multipathdir)/libmultipath.so $(mpathcmddir)/libmpathcmd.so @echo building $@ because of $? @@ -47,15 +49,12 @@ uninstall: $(Q)$(RM) $(DESTDIR)$(libudevdir)/rules.d/56-multipath.rules $(Q)$(RM) $(DESTDIR)$(mandir)/man8/$(EXEC).8 $(Q)$(RM) $(DESTDIR)$(mandir)/man5/$(EXEC).conf.5 + $(Q)$(RM) $(DESTDIR)$(tmpfilesdir)/multipath.conf clean: dep_clean - $(Q)$(RM) core *.o $(EXEC) multipath.rules tmpfiles.conf + $(Q)$(RM) core *.o $(EXEC) $(GENERATED) include $(wildcard $(OBJS:.o=.d)) dep_clean: $(Q)$(RM) $(OBJS:.o=.d) - -%: %.in - @echo creating $@ - $(Q)sed 's,@RUNTIME_DIR@,$(runtimedir),' $< >$@ diff --git a/multipath/multipath.8 b/multipath/multipath.8.in similarity index 97% rename from multipath/multipath.8 rename to multipath/multipath.8.in index 5fed6df..348eb22 100644 --- a/multipath/multipath.8 +++ b/multipath/multipath.8.in @@ -185,7 +185,7 @@ Display the currently used multipathd configuration. .B \-T Display the currently used multipathd configuration, limiting the output to those devices actually present in the system. This can be used a template for -creating \fImultipath.conf\fR. +creating \fI@CONFIGFILE@\fR. . .\" ---------------------------------------------------------------------------- .SH OPTIONS @@ -233,11 +233,11 @@ option from \fBmultipath.conf(5)\fR. .B \-i Ignore WWIDs file when processing devices. If \fIfind_multipaths strict\fR or \fIfind_multipaths no\fR is set in -\fImultipath.conf\fR, multipath only considers devices that are +\fI@CONFIGFILE@\fR, multipath only considers devices that are listed in the WWIDs file. This option overrides that behavior. For other values of \fIfind_multipaths\fR, this option has no effect. See the description of \fIfind_multipaths\fR in -.BR multipath.conf (5). +.BR @CONFIGFILE@ (5). This option should only be used in rare circumstances. . .TP @@ -246,8 +246,8 @@ Treat the bindings file as read only. . .TP .BI \-b " file" -Set \fIuser_friendly_names\fR bindings file location. The default is -\fI/etc/multipath/bindings\fR. +(\fBdeprecated, do not use\fR) Set \fIuser_friendly_names\fR bindings file location. The default is +\fI@STATE_DIR@/bindings\fR. . .TP .B \-q diff --git a/multipath/multipath.conf.5 b/multipath/multipath.conf.5.in similarity index 98% rename from multipath/multipath.conf.5 rename to multipath/multipath.conf.5.in index 93af17d..20df223 100644 --- a/multipath/multipath.conf.5 +++ b/multipath/multipath.conf.5.in @@ -13,14 +13,14 @@ .SH NAME .\" ---------------------------------------------------------------------------- . -multipath.conf \- multipath daemon configuration file. +@CONFIGFILE@, @CONFIGDIR@/*.conf \- multipath daemon configuration file. . . .\" ---------------------------------------------------------------------------- .SH DESCRIPTION .\" ---------------------------------------------------------------------------- . -.B "/etc/multipath.conf" +.B "@CONFIGFILE@" is the configuration file for the multipath daemon. It is used to overwrite the built-in configuration table of \fBmultipathd\fP. Any line whose first non-white-space character is a '#' is considered @@ -29,6 +29,15 @@ a comment line. Empty lines are ignored. Currently used multipathd configuration can be displayed with the \fBmultipath -t\fR or \fBmultipathd show config\fR command. . +.PP +Additional configuration can be made in drop-in files under +.B @CONFIGDIR@. +Files ending in \fI.conf\fR in this directory are read +in alphabetical order, after reading \fI@CONFIGFILE@\fR. +They use the same syntax as \fI@CONFIGFILE@\fR itself, +and support all sections and keywords. If a keyword occurs in the same section +in multiple files, the last occurence will take precedence over all others. +. . .\" ---------------------------------------------------------------------------- .SH SYNTAX @@ -85,7 +94,7 @@ not mandatory. . .LP .B Note on regular expressions: -The \fImultipath.conf\fR syntax allows many attribute values to be specified as POSIX +The \fI@CONFIGFILE@\fR syntax allows many attribute values to be specified as POSIX Extended Regular Expressions (see \fBregex\fR(7)). These regular expressions are \fBcase sensitive\fR and \fBnot anchored\fR, thus the expression "bar" matches "barbie", "rhabarber", and "wunderbar", but not "Barbie". To avoid unwanted substring @@ -711,7 +720,7 @@ The default is: \fBno\fR .B user_friendly_names If set to .I yes -, using the bindings file \fI/etc/multipath/bindings\fR to assign a persistent +, using the bindings file \fI@STATE_DIR@/bindings\fR to assign a persistent and unique alias to the multipath, in the form of mpath. If set to .I no use the WWID as the alias. In either case this be will @@ -790,7 +799,7 @@ The full pathname of the binding file to be used when the user_friendly_names option is set. .RS .TP -The default is: \fB/etc/multipath/bindings\fR +The default is: \fB@STATE_DIR@/bindings\fR .RE . . @@ -801,7 +810,7 @@ The full pathname of the WWIDs file, which is used by multipath to keep track of the WWIDs for LUNs it has created multipath devices on in the past. .RS .TP -The default is: \fB/etc/multipath/wwids\fR +The default is: \fB@STATE_DIR@/wwids\fR .RE . . @@ -813,7 +822,7 @@ track of the persistent reservation key used for a specific WWID, when \fIreservation_key\fR is set to \fBfile\fR. .RS .TP -The default is: \fB/etc/multipath/prkeys\fR +The default is: \fB@STATE_DIR@/prkeys\fR .RE . . @@ -872,7 +881,7 @@ The default is: \fBno\fR .I yes and the SCSI layer has already attached a hardware_handler to the device, multipath will not force the device to use the hardware_handler specified by -multipath.conf. If the SCSI layer has not attached a hardware handler, +@CONFIGFILE@. If the SCSI layer has not attached a hardware handler, multipath will continue to use its configured hardware handler. .RS .PP @@ -1559,7 +1568,7 @@ given device, the attributes of all matching entries are applied to it. If an attribute is specified in several matching device subsections, later entries take precedence. Thus, entries in files under \fIconfig_dir\fR (in reverse alphabetical order) have the highest precedence, followed by entries -in \fImultipath.conf\fR; the built-in hardware table has the lowest +in \fI@CONFIGFILE@\fR; the built-in hardware table has the lowest precedence. Inside a configuration file, later entries have higher precedence than earlier ones. .LP diff --git a/multipathd/Makefile b/multipathd/Makefile index 0d0146c..cdba3db 100644 --- a/multipathd/Makefile +++ b/multipathd/Makefile @@ -1,7 +1,8 @@ include ../Makefile.inc -EXEC := multipathd -CLI := multipathc +EXEC := multipathd +CLI := multipathc +MANPAGES := multipathd.8 CPPFLAGS += -I$(multipathdir) -I$(mpathutildir) -I$(mpathpersistdir) -I$(mpathcmddir) -I$(thirdpartydir) \ $(shell $(PKG_CONFIG) --modversion liburcu 2>/dev/null | \ @@ -42,7 +43,7 @@ ifeq ($(FPIN_SUPPORT),1) OBJS += fpin_handlers.o endif -all : $(EXEC) $(CLI) +all : $(EXEC) $(CLI) $(MANPAGES) $(EXEC): $(OBJS) $(multipathdir)/libmultipath.so $(mpathcmddir)/libmpathcmd.so @echo building $@ because of $? @@ -79,7 +80,7 @@ uninstall: $(Q)$(RM) $(DESTDIR)$(unitdir)/$(EXEC).socket clean: dep_clean - $(Q)$(RM) core *.o $(EXEC) $(CLI) + $(Q)$(RM) core *.o $(EXEC) $(CLI) $(MANPAGES) include $(wildcard $(OBJS:.o=.d) $(CLI_OBJS:.o=.d)) diff --git a/multipathd/multipathd.8 b/multipathd/multipathd.8.in similarity index 97% rename from multipathd/multipathd.8 rename to multipathd/multipathd.8.in index cc72b77..e98c27f 100644 --- a/multipathd/multipathd.8 +++ b/multipathd/multipathd.8.in @@ -155,7 +155,7 @@ Show the format wildcards used in interactive commands taking $format. .TP .B list|show config Show the currently used configuration, derived from default values and values -specified within the configuration file \fI/etc/multipath.conf\fR. +specified within the configuration file \fI@CONFIGFILE@\fR. . .TP .B list|show config local @@ -165,7 +165,7 @@ the devices section to those devices that are actually present in the system. .TP .B list|show blacklist Show the currently used blacklist rules, derived from default values and values -specified within the configuration file \fI/etc/multipath.conf\fR. +specified within the configuration file \fI@CONFIGFILE@\fR. . .TP .B list|show devices @@ -290,13 +290,13 @@ Get the current persistent reservation key associated with $map. .B map|multipath $map setprkey key $key Set the persistent reservation key associated with $map to $key in the \fIprkeys_file\fR. This key will only be used by multipathd if -\fIreservation_key\fR is set to \fBfile\fR in \fI/etc/multipath.conf\fR. +\fIreservation_key\fR is set to \fBfile\fR in \fI@CONFIGFILE@\fR. . .TP .B map|multipath $map unsetprkey Remove the persistent reservation key associated with $map from the \fIprkeys_file\fR. This will only unset the key used by multipathd if -\fIreservation_key\fR is set to \fBfile\fR in \fI/etc/multipath.conf\fR. +\fIreservation_key\fR is set to \fBfile\fR in \fI@CONFIGFILE@\fR. . .TP .B path $path setmarginal From patchwork Mon Sep 11 16:38:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13379500 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1EF38EEB581 for ; Mon, 11 Sep 2023 16:39:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694450387; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=a6LI0FhMHkYqwIB/3Ke8k2soEVYsfyzHL7SPNJwQFQU=; b=coao+Vh+vcbnAKX4i9o7ldOI6ECqoa8WteiSg7b8imHflIg+tGsquvsFQHLR6rzgYAW6GF 8YxpRRkPFG8pIZIVHsp/Q06y2wjr9brGL/mqoox+tm64JS7iFhh06/pQjQ+fKj78zBgTe+ sND09N9M6EHU1XoYRz2XxnbpT/BA2qw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-326-q-HVuD6EPYe-5PLZLxa6ZQ-1; Mon, 11 Sep 2023 12:39:42 -0400 X-MC-Unique: q-HVuD6EPYe-5PLZLxa6ZQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 67EC8928B82; Mon, 11 Sep 2023 16:39:29 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4EEDD40C2009; Mon, 11 Sep 2023 16:39:29 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 2E33A19465A2; Mon, 11 Sep 2023 16:39:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 4DBC619465B7 for ; Mon, 11 Sep 2023 16:39:26 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 2E10C2027046; Mon, 11 Sep 2023 16:39:26 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast08.extmail.prod.ext.rdu2.redhat.com [10.11.55.24]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 269D52027045 for ; Mon, 11 Sep 2023 16:39:26 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-inbound-delivery-1.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0A652381494E for ; Mon, 11 Sep 2023 16:39:26 +0000 (UTC) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-544-9JZt5eVKOZCXECJo47EiTw-1; Mon, 11 Sep 2023 12:39:24 -0400 X-MC-Unique: 9JZt5eVKOZCXECJo47EiTw-1 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id DB6C61F8C1; Mon, 11 Sep 2023 16:39:22 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id A31FE139CC; Mon, 11 Sep 2023 16:39:22 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 2GM+JrpC/2RzEAAAMHmgww (envelope-from ); Mon, 11 Sep 2023 16:39:22 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Mon, 11 Sep 2023 18:38:41 +0200 Message-ID: <20230911163846.27197-33-mwilck@suse.com> In-Reply-To: <20230911163846.27197-1-mwilck@suse.com> References: <20230911163846.27197-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 Subject: [dm-devel] [PATCH v2 32/37] libdmmp/Makefile: fix bug in install section X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dm-devel@redhat.com, Martin Wilck Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: suse.com From: Martin Wilck Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libdmmp/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libdmmp/Makefile b/libdmmp/Makefile index 078eca8..172ba04 100644 --- a/libdmmp/Makefile +++ b/libdmmp/Makefile @@ -44,7 +44,7 @@ install: $(DESTDIR)$(pkgconfdir)/$(PKGFILE) $(Q)sed -i 's|__INCLUDEDIR__|$(includedir)|g' \ $(DESTDIR)$(pkgconfdir)/$(PKGFILE) - $(Q)$(INSTALL_PROGRAM) -d 755 $(DESTDIR)$(mandir)/man3 + $(Q)$(INSTALL_PROGRAM) -m 755 -d $(DESTDIR)$(mandir)/man3 $(Q)$(INSTALL_PROGRAM) -m 644 -t $(DESTDIR)$(mandir)/man3 docs/man/*.3 uninstall: From patchwork Mon Sep 11 16:38:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13379508 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 45655EE7FF4 for ; Mon, 11 Sep 2023 16:39:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694450393; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=1vSj0+T2SOSdS99wOaDOXDNMnCuaqGZMOPdwpHI9jl0=; b=SSc3ZMTHD1g6ZqVCA2mXz9OWCRQCNUaKCc+Zqhfq+wiloITunIwzEdF9Tu8136MaGm7sZY Cd25MU7kCVjvSBdrwUPcTeLdXUNzAYjFverHacyIRMQHS9cxy9vqGO/bpMdzVvzDcQY35a HtzlkdverwQavBbDRM+GyNbZmtd8Vbo= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-14-Xs_X9tB6O7aotdS2lhsBlA-1; Mon, 11 Sep 2023 12:39:50 -0400 X-MC-Unique: Xs_X9tB6O7aotdS2lhsBlA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D2BD63815F01; Mon, 11 Sep 2023 16:39:29 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id BC86E44029; Mon, 11 Sep 2023 16:39:29 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id B071919465B7; Mon, 11 Sep 2023 16:39:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 5BC6819465A2 for ; Mon, 11 Sep 2023 16:39:28 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 3F3BB40C6EA8; Mon, 11 Sep 2023 16:39:28 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3823640C6EC0 for ; Mon, 11 Sep 2023 16:39:28 +0000 (UTC) Received: from us-smtp-inbound-delivery-1.mimecast.com (us-smtp-inbound-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 198C6181A719 for ; Mon, 11 Sep 2023 16:39:28 +0000 (UTC) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-219-fFkM_rd1M5SyOJE8a_iaMg-1; Mon, 11 Sep 2023 12:39:24 -0400 X-MC-Unique: fFkM_rd1M5SyOJE8a_iaMg-1 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 2059E1F8C3; Mon, 11 Sep 2023 16:39:23 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id E6648139CC; Mon, 11 Sep 2023 16:39:22 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id OG+VNrpC/2RzEAAAMHmgww (envelope-from ); Mon, 11 Sep 2023 16:39:22 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Mon, 11 Sep 2023 18:38:42 +0200 Message-ID: <20230911163846.27197-34-mwilck@suse.com> In-Reply-To: <20230911163846.27197-1-mwilck@suse.com> References: <20230911163846.27197-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 Subject: [dm-devel] [PATCH v2 33/37] multipath-tools: README.md: improve documentation for compile-time options X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dm-devel@redhat.com, Martin Wilck Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: suse.com From: Martin Wilck Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- README.md | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index a7f994a..679e55b 100644 --- a/README.md +++ b/README.md @@ -89,9 +89,17 @@ The following variables can be passed to the `make` command line: * `plugindir="/some/path"`: directory where libmultipath plugins (path checkers, prioritizers, and foreign multipath support) will be looked up. This used to be the run-time option `multipath_dir` in earlier versions. - * `configdir="/some/path"` : directory to search for configuration files. + The default is `$(prefix)/$(LIB)/multipath`, where `$(LIB)` is `lib64` on + systems that have `/lib64`, and `lib` otherwise. + * `configfile="/some/path`": The path to the main configuration file. + The defalt is `$(etc_prefix)/etc/multipath.conf`. + * `configdir="/some/path"` : directory to search for additional configuration files. This used to be the run-time option `config_dir` in earlier versions. - The default is `/etc/multipath/conf.d`. + The default is `$(etc_prefix)/etc/multipath/conf.d`. + * `statedir="/some/path"`: The path of the directory where multipath-tools + stores run-time settings that need persist between reboots, such as known + WWIDs, user-friendly names, and persistent reservation keys. + The default is `$(etc_prefix)/etc/multipath`. * `READLINE=libedit` or `READLINE=libreadline`: enable command line history and TAB completion in the interactive mode *(which is entered with `multipathd -k` or `multipathc`)*. The respective development package will be required for building. @@ -119,21 +127,27 @@ The following variables can be passed to the `make` command line: ### Installation Paths * `prefix`: The directory prefix for (almost) all files to be installed. - Distributions may want to set this to `/usr`. - **Note**: for multipath-tools, unlike many other packages, `prefix` - defaults to the empty string, which resolves to the root directory (`/`). + "Usr-merged" distributions[^systemd] may want to set this to `/usr`. The + default is empty (`""`). * `usr_prefix`: where to install those parts of the code that aren't necessary - for booting. You may want to set this to `/usr` if `prefix` is empty. - * `systemd_prefix`: Prefix for systemd-related files. It defaults to `/usr`. - Some systemd installations use separate `prefix` and `rootprefix`. On such - a distribution, set `prefix`, and override `unitdir` to use systemd's - `rootprefix`. + for booting. Non-usr-merged distributions[^systemd] may want to set this to + `/usr`. The default is `$(prefix)`. + * `systemd_prefix`: Prefix for systemd-related files[^systemd]. The default is `/usr`. + * `etc_prefix`: The prefix for configuration files. "Usr-merged" + distributions with immutable `/usr`[^systemd] may want to set this to + `/etc`. The default is `$(prefix)`. * `LIB`: the subdirectory under `prefix` where shared libraries will be installed. By default, the makefile uses `/lib64` if this directory is found on the build system, and `/lib` otherwise. -See also `configdir` and `plugindir` above. See `Makefile.inc` for more -fine-grained control. +The options `configdir`, `plugindir`, `configfile`, and `statedir` above can +be used for setting indvidual paths where the `prefix` variables don't provide +sufficient control. See `Makefile.inc` for even more fine-grained control. + +[^systemd]: Some systemd installations use separate `prefix` and `rootprefix`. + On such a distribution, set `prefix`, and override `unitdir` to use systemd's + `rootprefix`. Recent systemd releases generally require everything to be + installed under `/usr` (so-called "usr-merged" distribution). On "usr- ### Compiler Options From patchwork Mon Sep 11 16:38:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13379515 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BD12FEE57DF for ; Mon, 11 Sep 2023 16:39:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694450397; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=iFCWpjLvnCVZNd76en2Eb4KlohxV3GDdgTBAtuGVUT4=; b=Aoy6aNv0EG/HEHRSEZc8oaukNQtPpBoWIrosUHiXo+5bw4WWF1m++zVd/YjHT4vmLHA2kz hP+BmusIbDOrLE0oov8UvwkbBZS2+jRU5aprVnvooRCeRyrFulR/PsupC+nSvBgCjFPFL0 iv9zMFk8m72s7sw7Uq3HUNsemqo3ZTg= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-170-I2fj7Z81MhqhUaqmkUTaZw-1; Mon, 11 Sep 2023 12:39:49 -0400 X-MC-Unique: I2fj7Z81MhqhUaqmkUTaZw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6200481652E; Mon, 11 Sep 2023 16:39:31 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1EAB440C6EBF; Mon, 11 Sep 2023 16:39:31 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id DE8D019465B8; Mon, 11 Sep 2023 16:39:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 6C7AF1946597 for ; Mon, 11 Sep 2023 16:39:28 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 5DC232027047; Mon, 11 Sep 2023 16:39:28 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5619E2027045 for ; Mon, 11 Sep 2023 16:39:28 +0000 (UTC) Received: from us-smtp-inbound-delivery-1.mimecast.com (us-smtp-inbound-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 38BCC945E90 for ; Mon, 11 Sep 2023 16:39:28 +0000 (UTC) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-65-7HTqDs7JOEOEbvXzVhHqJg-1; Mon, 11 Sep 2023 12:39:24 -0400 X-MC-Unique: 7HTqDs7JOEOEbvXzVhHqJg-1 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 5C05E1F8CD; Mon, 11 Sep 2023 16:39:23 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 2CD9A139CC; Mon, 11 Sep 2023 16:39:23 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id WJ8xCbtC/2RzEAAAMHmgww (envelope-from ); Mon, 11 Sep 2023 16:39:23 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Mon, 11 Sep 2023 18:38:43 +0200 Message-ID: <20230911163846.27197-35-mwilck@suse.com> In-Reply-To: <20230911163846.27197-1-mwilck@suse.com> References: <20230911163846.27197-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 Subject: [dm-devel] [PATCH v2 34/37] libmultipath: print built-in values for deprecated options X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dm-devel@redhat.com, Martin Wilck Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: suse.com From: Martin Wilck In the error messages we print when a deprecated option is encountered, print the compile-time value of the option. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/dict.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/libmultipath/dict.c b/libmultipath/dict.c index f81c84a..dace343 100644 --- a/libmultipath/dict.c +++ b/libmultipath/dict.c @@ -314,14 +314,16 @@ def_ ## option ## _handler (struct config *conf, vector strvec, \ static int deprecated_handler(struct config *conf, vector strvec, const char *file, int line_nr); -#define declare_deprecated_handler(option) \ +#define declare_deprecated_handler(option, default) \ static int \ deprecated_ ## option ## _handler (struct config *conf, vector strvec, \ const char *file, int line_nr) \ { \ static bool warned; \ if (!warned) { \ - condlog(1, "%s line %d: ignoring deprecated option \"" #option "\"", file, line_nr); \ + condlog(1, "%s line %d: ignoring deprecated option \"" \ + #option "\", using built-in value: \"%s\"", \ + file, line_nr, default); \ warned = true; \ } \ return deprecated_handler(conf, strvec, file, line_nr); \ @@ -2057,11 +2059,11 @@ snprint_deprecated (struct config *conf, struct strbuf *buff, const void * data) } // Deprecated keywords -declare_deprecated_handler(config_dir) -declare_deprecated_handler(disable_changed_wwids) -declare_deprecated_handler(getuid_callout) -declare_deprecated_handler(multipath_dir) -declare_deprecated_handler(pg_timeout) +declare_deprecated_handler(config_dir, CONFIG_DIR) +declare_deprecated_handler(disable_changed_wwids, "yes") +declare_deprecated_handler(getuid_callout, "(not set)") +declare_deprecated_handler(multipath_dir, MULTIPATH_DIR) +declare_deprecated_handler(pg_timeout, "(not set)") /* * If you add or remove a keyword also update multipath/multipath.conf.5 From patchwork Mon Sep 11 16:38:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13379503 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C3EF8EEB592 for ; Mon, 11 Sep 2023 16:39:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694450388; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=XOXRaqSfLnKhoYGgN3jiZinlW0FCvY188znvDVJqifM=; b=JilZAOJIHFf13YlYsKw9cDZEy/54026C7WruK70J6tNvbRI9CquYQ+uTkeUSfEWuf2mm3P tKfM8tMBlstFsSzTE40a4kmfjY9C+fkyEzqCW5+jFNU03ahdHksdXAjHG6h/ET1vLei7N3 1QEMn6ivwer5yinlBI7AbYaag4nKX2U= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-145-QNxHSzMKN3GA4LABrufe6Q-1; Mon, 11 Sep 2023 12:39:45 -0400 X-MC-Unique: QNxHSzMKN3GA4LABrufe6Q-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 097531C06EE5; Mon, 11 Sep 2023 16:39:33 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id DF10921CAC89; Mon, 11 Sep 2023 16:39:32 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id B665619465B9; Mon, 11 Sep 2023 16:39:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 84AFB19465B6 for ; Mon, 11 Sep 2023 16:39:27 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 63645200E4BE; Mon, 11 Sep 2023 16:39:27 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5BE612156711 for ; Mon, 11 Sep 2023 16:39:27 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-inbound-delivery-1.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3D730101FAA5 for ; Mon, 11 Sep 2023 16:39:27 +0000 (UTC) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-549-VCH1SdBhM_qNW8JmpqqhMQ-1; Mon, 11 Sep 2023 12:39:25 -0400 X-MC-Unique: VCH1SdBhM_qNW8JmpqqhMQ-1 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id AB04C21858; Mon, 11 Sep 2023 16:39:23 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 670C3139CC; Mon, 11 Sep 2023 16:39:23 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id aB52F7tC/2RzEAAAMHmgww (envelope-from ); Mon, 11 Sep 2023 16:39:23 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Mon, 11 Sep 2023 18:38:44 +0200 Message-ID: <20230911163846.27197-36-mwilck@suse.com> In-Reply-To: <20230911163846.27197-1-mwilck@suse.com> References: <20230911163846.27197-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Subject: [dm-devel] [PATCH v2 35/37] multipath: add a missing newline X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dm-devel@redhat.com, Martin Wilck Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: suse.com From: Martin Wilck Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- multipath/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/multipath/main.c b/multipath/main.c index 45e9745..b91289e 100644 --- a/multipath/main.c +++ b/multipath/main.c @@ -1025,7 +1025,7 @@ main (int argc, char *argv[]) } if (check_alias_settings(conf)) { - fprintf(stderr, "fatal configuration error, aborting"); + fprintf(stderr, "fatal configuration error, aborting\n"); exit(RTVL_FAIL); } From patchwork Mon Sep 11 16:38:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13379501 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4BBA5EEB590 for ; Mon, 11 Sep 2023 16:39:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694450387; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=EwTjGY/U+OCBufnZK71y9R30vYDvN+w4uLAaji8+dug=; b=CokZkfkcQ9+qyVH6y70/clF5nVj24dFYteycIYQ3TLjLR/5VeysBXnN7ockW0mmxsL2UFn ZzwPm9W60ym63bc1bnfk814uEa8OVVgae7hMxAd7EO7CtGrW9n6RbY3k177UYN8QyQo6zv NkvTGI26Ezxv1CLWJyiF7ExTTOjTkTI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-317-99skw3kOMe-sC8AzwIG_9A-1; Mon, 11 Sep 2023 12:39:41 -0400 X-MC-Unique: 99skw3kOMe-sC8AzwIG_9A-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 91A4E945E71; Mon, 11 Sep 2023 16:39:29 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7A46240C6EBF; Mon, 11 Sep 2023 16:39:29 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 5E49019465B6; Mon, 11 Sep 2023 16:39:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 88A5319465A2 for ; Mon, 11 Sep 2023 16:39:27 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 655C240C6ECA; Mon, 11 Sep 2023 16:39:27 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5E93B40C6ECD for ; Mon, 11 Sep 2023 16:39:27 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-inbound-delivery-1.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3B34B928BB1 for ; Mon, 11 Sep 2023 16:39:27 +0000 (UTC) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-686-juO_gLT9ONqdWbIBN1kKeA-1; Mon, 11 Sep 2023 12:39:25 -0400 X-MC-Unique: juO_gLT9ONqdWbIBN1kKeA-1 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id D7CE41F8A6; Mon, 11 Sep 2023 16:39:23 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id A80B213AD1; Mon, 11 Sep 2023 16:39:23 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id wBFwJ7tC/2RzEAAAMHmgww (envelope-from ); Mon, 11 Sep 2023 16:39:23 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Mon, 11 Sep 2023 18:38:45 +0200 Message-ID: <20230911163846.27197-37-mwilck@suse.com> In-Reply-To: <20230911163846.27197-1-mwilck@suse.com> References: <20230911163846.27197-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 Subject: [dm-devel] [PATCH v2 36/37] multipath-tools: allow prefixes with and w/o trailing slash X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dm-devel@redhat.com, Martin Wilck Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: suse.com From: Martin Wilck Add some logic to Makefile.inc that leads to the same result for "prefix=" and "prefix=/", or "prefix=/usr" and "prefix=/usr/". The logic does not work for multiple trailing slashes. It applies to all XYZ_prefix variables in Makefile.inc. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- Makefile.inc | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/Makefile.inc b/Makefile.inc index 79e521e..6e384e6 100644 --- a/Makefile.inc +++ b/Makefile.inc @@ -43,22 +43,31 @@ etc_prefix := $(prefix) # Note: some systemd installations use separate "prefix" and "rootprefix". # In this case, override only unitdir to use systemd's "rootprefix" instead of $(systemd_prefix) systemd_prefix := /usr -unitdir := $(systemd_prefix)/lib/systemd/system -tmpfilesdir := $(systemd_prefix)/lib/tmpfiles.d -modulesloaddir := $(systemd_prefix)/lib/modules-load.d -libudevdir := $(systemd_prefix)/lib/udev + +# Make sure all prefix variables end in "/" +append-slash = $(1)$(if $(filter %/,$(1)),,/) +override prefix := $(call append-slash,$(prefix)) +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)) + +unitdir := $(systemd_prefix)lib/systemd/system +tmpfilesdir := $(systemd_prefix)lib/tmpfiles.d +modulesloaddir := $(systemd_prefix)lib/modules-load.d +libudevdir := $(systemd_prefix)lib/udev udevrulesdir := $(libudevdir)/rules.d -bindir := $(exec_prefix)/sbin -mandir := $(usr_prefix)/share/man +bindir := $(exec_prefix)sbin +mandir := $(usr_prefix)share/man LIB := $(if $(shell test -d /lib64 && echo 1),lib64,lib) -syslibdir := $(prefix)/$(LIB) -usrlibdir := $(usr_prefix)/$(LIB) -includedir := $(usr_prefix)/include +syslibdir := $(prefix)$(LIB) +usrlibdir := $(usr_prefix)$(LIB) +includedir := $(usr_prefix)include pkgconfdir := $(usrlibdir)/pkgconfig -plugindir := $(prefix)/$(LIB)/multipath -configdir := $(etc_prefix)/etc/multipath/conf.d -configfile := $(etc_prefix)/etc/multipath.conf -statedir := $(etc_prefix)/etc/multipath +plugindir := $(prefix)$(LIB)/multipath +configdir := $(etc_prefix)etc/multipath/conf.d +configfile := $(etc_prefix)etc/multipath.conf +statedir := $(etc_prefix)etc/multipath runtimedir := $(if $(shell test -L /var/run -o ! -d /var/run && echo 1),/run,/var/run) devmapper_incdir := $(or $(shell $(PKG_CONFIG) --variable=includedir devmapper),/usr/include) libudev_incdir := $(or $(shell $(PKG_CONFIG) --variable=includedir libudev),/usr/include) From patchwork Mon Sep 11 16:38:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 13379509 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 23AC6EEB595 for ; Mon, 11 Sep 2023 16:39:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694450390; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=ClzfUZJCL/E/LskH1tLLNN4zLlGMfQjeBhSCZgcQKsM=; b=OdSr8KNFpINq/RktDvku/bEoUT6mDMC+g9sgXsSVav39REoOolRveRB3CIQOAtCV1+uuWB lOumLR1cwBA62AARGSVfFjorUo0KUxX6dV+BpmI7i8V0dQ0XN0823vaQU0J8TRdolSEMnE cl45Qhqg+nYG33MSjTKyh7h7S0lvq6o= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-362-nGa08eoYML-Veuw8wUuJiA-1; Mon, 11 Sep 2023 12:39:45 -0400 X-MC-Unique: nGa08eoYML-Veuw8wUuJiA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4C923945E63; Mon, 11 Sep 2023 16:39:32 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 35C7940C2064; Mon, 11 Sep 2023 16:39:32 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 2741019465B2; Mon, 11 Sep 2023 16:39:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id BA40519465B8 for ; Mon, 11 Sep 2023 16:39:30 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id A02F82024CD5; Mon, 11 Sep 2023 16:39:30 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast10.extmail.prod.ext.rdu2.redhat.com [10.11.55.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9876A2024CAE for ; Mon, 11 Sep 2023 16:39:30 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6C8741C06ECA for ; Mon, 11 Sep 2023 16:39:30 +0000 (UTC) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-661-KF1hSJkWMX-_gxgRqp06Dg-1; Mon, 11 Sep 2023 12:39:26 -0400 X-MC-Unique: KF1hSJkWMX-_gxgRqp06Dg-1 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 2C54C1F8B3; Mon, 11 Sep 2023 16:39:24 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id E7043139CC; Mon, 11 Sep 2023 16:39:23 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id sKDINrtC/2RzEAAAMHmgww (envelope-from ); Mon, 11 Sep 2023 16:39:23 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Mon, 11 Sep 2023 18:38:46 +0200 Message-ID: <20230911163846.27197-38-mwilck@suse.com> In-Reply-To: <20230911163846.27197-1-mwilck@suse.com> References: <20230911163846.27197-1-mwilck@suse.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 Subject: [dm-devel] [PATCH v2 37/37] libmultipath: deprecate bindings_file, wwids_file, prkeys_file X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dm-devel@redhat.com, Martin Wilck Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: suse.com From: Martin Wilck The options bindings_file, wwids_file, and prkeys_file have been deprecated since cb4d6db ("libmultipath: deprecate file and directory config options") (multipath-tools 0.8.8). Deprecate and ignore them now. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/alias.c | 43 +++++++++---------- libmultipath/alias.h | 3 +- libmultipath/config.c | 18 -------- libmultipath/config.h | 3 -- libmultipath/dict.c | 39 +++--------------- libmultipath/libmultipath.version | 8 +--- libmultipath/prkey.c | 7 ++-- libmultipath/prkey.h | 7 ++-- libmultipath/propsel.c | 5 +-- libmultipath/wwids.c | 18 ++------ multipath/main.c | 2 +- multipath/multipath.conf.5.in | 23 +++++------ multipathd/uxlsnr.c | 17 +++----- tests/alias.c | 68 +++++++++++++++---------------- 14 files changed, 90 insertions(+), 171 deletions(-) diff --git a/libmultipath/alias.c b/libmultipath/alias.c index 76ed62d..11130e6 100644 --- a/libmultipath/alias.c +++ b/libmultipath/alias.c @@ -55,6 +55,8 @@ /* uatomic access only */ static int bindings_file_changed = 1; +static const char bindings_file_path[] = DEFAULT_BINDINGS_FILE; + static pthread_mutex_t timestamp_mutex = PTHREAD_MUTEX_INITIALIZER; static struct timespec bindings_last_updated; @@ -273,7 +275,6 @@ static int write_bindings_file(const Bindings *bindings, int fd, void handle_bindings_file_inotify(const struct inotify_event *event) { - struct config *conf; const char *base; bool changed = false; struct stat st; @@ -283,12 +284,9 @@ void handle_bindings_file_inotify(const struct inotify_event *event) if (!(event->mask & IN_MOVED_TO)) return; - conf = get_multipath_config(); - base = strrchr(conf->bindings_file, '/'); - changed = base && base > conf->bindings_file && - !strcmp(base + 1, event->name); - ret = stat(conf->bindings_file, &st); - put_multipath_config(conf); + base = strrchr(bindings_file_path, '/'); + changed = base && !strcmp(base + 1, event->name); + ret = stat(bindings_file_path, &st); if (!changed) return; @@ -309,8 +307,7 @@ void handle_bindings_file_inotify(const struct inotify_event *event) __func__, (long)ts.tv_sec, (long)ts.tv_nsec / 1000); } -static int update_bindings_file(const Bindings *bindings, - const char *bindings_file) +static int update_bindings_file(const Bindings *bindings) { int rc; int fd = -1; @@ -318,7 +315,7 @@ static int update_bindings_file(const Bindings *bindings, mode_t old_umask; struct timespec ts; - if (safe_sprintf(tempname, "%s.XXXXXX", bindings_file)) + if (safe_sprintf(tempname, "%s.XXXXXX", bindings_file_path)) return -1; /* coverity: SECURE_TEMP */ old_umask = umask(0077); @@ -335,10 +332,10 @@ static int update_bindings_file(const Bindings *bindings, unlink(tempname); return rc; } - if ((rc = rename(tempname, bindings_file)) == -1) + if ((rc = rename(tempname, bindings_file_path)) == -1) condlog(0, "%s: rename: %m", __func__); else { - condlog(1, "updated bindings file %s", bindings_file); + condlog(1, "updated bindings file %s", bindings_file_path); pthread_mutex_lock(×tamp_mutex); bindings_last_updated = ts; pthread_mutex_unlock(×tamp_mutex); @@ -473,7 +470,7 @@ int get_free_id(const Bindings *bindings, const char *prefix, const char *map_ww /* Called with binding_mutex held */ static char * -allocate_binding(const char *filename, const char *wwid, int id, const char *prefix) +allocate_binding(const char *wwid, int id, const char *prefix) { STRBUF_ON_STACK(buf); char *alias; @@ -497,7 +494,7 @@ allocate_binding(const char *filename, const char *wwid, int id, const char *pre return NULL; } - if (update_bindings_file(&global_bindings, filename) == -1) { + if (update_bindings_file(&global_bindings) == -1) { condlog(1, "%s: deleting binding %s for %s", __func__, alias, wwid); delete_binding(&global_bindings, wwid); free(alias); @@ -564,7 +561,7 @@ static void read_bindings_file(void) * that the mpvec corrcectly represents kernel state. */ -char *get_user_friendly_alias(const char *wwid, const char *file, const char *alias_old, +char *get_user_friendly_alias(const char *wwid, const char *alias_old, const char *prefix, bool bindings_read_only) { char *alias = NULL; @@ -621,7 +618,7 @@ new_alias: } if (!bindings_read_only && id > 0) - alias = allocate_binding(file, wwid, id, prefix); + alias = allocate_binding(wwid, id, prefix); if (alias && !new_binding) condlog(2, "Allocated existing binding [%s] for WWID [%s]", @@ -713,12 +710,12 @@ static int _check_bindings_file(const struct config *conf, FILE *file, if (fread(header, sizeof(BINDINGS_FILE_HEADER) - 1, 1, file) < sizeof(BINDINGS_FILE_HEADER) - 1) { condlog(2, "%s: failed to read header from %s", __func__, - conf->bindings_file); + bindings_file_path); fseek(file, 0, SEEK_SET); rc = -1; } else if (strcmp(header, BINDINGS_FILE_HEADER)) { condlog(2, "%s: invalid header in %s", __func__, - conf->bindings_file); + bindings_file_path); fseek(file, 0, SEEK_SET); rc = -1; } @@ -785,13 +782,13 @@ static int _read_bindings_file(const struct config *conf, Bindings *bindings, } } - fd = open_file(conf->bindings_file, &can_write, BINDINGS_FILE_HEADER); + fd = open_file(bindings_file_path, &can_write, BINDINGS_FILE_HEADER); if (fd == -1) return BINDINGS_FILE_ERROR; file = fdopen(fd, "r"); if (file != NULL) { - condlog(3, "%s: reading %s", __func__, conf->bindings_file); + condlog(3, "%s: reading %s", __func__, bindings_file_path); pthread_cleanup_push(cleanup_fclose, file); ret = _check_bindings_file(conf, file, bindings); @@ -810,20 +807,20 @@ static int _read_bindings_file(const struct config *conf, Bindings *bindings, bindings_last_updated = ts; pthread_mutex_unlock(×tamp_mutex); } else if (ret == -1 && can_write && !conf->bindings_read_only) { - ret = update_bindings_file(bindings, conf->bindings_file); + ret = update_bindings_file(bindings); if (ret == 0) rc = BINDINGS_FILE_READ; else rc = BINDINGS_FILE_BAD; } else if (ret == -1) { condlog(0, "ERROR: bad settings in read-only bindings file %s", - conf->bindings_file); + bindings_file_path); rc = BINDINGS_FILE_BAD; } pthread_cleanup_pop(1); } else { condlog(1, "failed to fdopen %s: %m", - conf->bindings_file); + bindings_file_path); close(fd); rc = BINDINGS_FILE_ERROR; } diff --git a/libmultipath/alias.h b/libmultipath/alias.h index ca8911f..629e8d5 100644 --- a/libmultipath/alias.h +++ b/libmultipath/alias.h @@ -3,8 +3,7 @@ int valid_alias(const char *alias); int get_user_friendly_wwid(const char *alias, char *buff); -char *get_user_friendly_alias(const char *wwid, const char *file, - const char *alias_old, +char *get_user_friendly_alias(const char *wwid, const char *alias_old, const char *prefix, bool bindings_read_only); struct config; diff --git a/libmultipath/config.c b/libmultipath/config.c index 7b20759..b7dbc6f 100644 --- a/libmultipath/config.c +++ b/libmultipath/config.c @@ -752,15 +752,6 @@ static void _uninit_config(struct config *conf) if (conf->hwhandler) free(conf->hwhandler); - if (conf->bindings_file) - free(conf->bindings_file); - - if (conf->wwids_file) - free(conf->wwids_file); - - if (conf->prkeys_file) - free(conf->prkeys_file); - if (conf->prio_name) free(conf->prio_name); @@ -922,9 +913,6 @@ int _init_config (const char *file, struct config *conf) * internal defaults */ get_sys_max_fds(&conf->max_fds); - conf->bindings_file = set_default(DEFAULT_BINDINGS_FILE); - conf->wwids_file = set_default(DEFAULT_WWIDS_FILE); - conf->prkeys_file = set_default(DEFAULT_PRKEYS_FILE); conf->attribute_flags = 0; conf->reassign_maps = DEFAULT_REASSIGN_MAPS; conf->checkint = CHECKINT_UNDEF; @@ -1078,12 +1066,6 @@ int _init_config (const char *file, struct config *conf) merge_blacklist(conf->elist_wwid); merge_blacklist_device(conf->elist_device); - if (conf->bindings_file == NULL) - conf->bindings_file = set_default(DEFAULT_BINDINGS_FILE); - - if (!conf->bindings_file || !conf->wwids_file || !conf->prkeys_file) - goto out; - libmp_verbosity = conf->verbosity; return 0; out: diff --git a/libmultipath/config.h b/libmultipath/config.h index 0a2c297..8c22ce7 100644 --- a/libmultipath/config.h +++ b/libmultipath/config.h @@ -207,9 +207,6 @@ struct config { char * uid_attribute; char * features; char * hwhandler; - char * bindings_file; - char * wwids_file; - char * prkeys_file; char * prio_name; char * prio_args; char * checker_name; diff --git a/libmultipath/dict.c b/libmultipath/dict.c index dace343..044067a 100644 --- a/libmultipath/dict.c +++ b/libmultipath/dict.c @@ -168,27 +168,6 @@ fail: return 0; } -static int -set_path(vector strvec, void *ptr, const char *file, int line_nr) -{ - char **str_ptr = (char **)ptr; - char *old_str = *str_ptr; - - *str_ptr = set_value(strvec); - if (!*str_ptr) { - free(old_str); - return 1; - } - if ((*str_ptr)[0] != '/'){ - condlog(1, "%s line %d, %s is not an absolute path. Ignoring", - file, line_nr, *str_ptr); - free(*str_ptr); - *str_ptr = old_str; - } else - free(old_str); - return 0; -} - static int set_str_noslash(vector strvec, void *ptr, const char *file, int line_nr) { @@ -831,15 +810,6 @@ declare_hw_snprint(user_friendly_names, print_yes_no_undef) declare_mp_handler(user_friendly_names, set_yes_no_undef) declare_mp_snprint(user_friendly_names, print_yes_no_undef) -declare_def_warn_handler(bindings_file, set_path) -declare_def_snprint(bindings_file, print_str) - -declare_def_warn_handler(wwids_file, set_path) -declare_def_snprint(wwids_file, print_str) - -declare_def_warn_handler(prkeys_file, set_path) -declare_def_snprint(prkeys_file, print_str) - declare_def_handler(retain_hwhandler, set_yes_no_undef) declare_def_snprint_defint(retain_hwhandler, print_yes_no_undef, DEFAULT_RETAIN_HWHANDLER) @@ -2064,6 +2034,9 @@ declare_deprecated_handler(disable_changed_wwids, "yes") declare_deprecated_handler(getuid_callout, "(not set)") declare_deprecated_handler(multipath_dir, MULTIPATH_DIR) declare_deprecated_handler(pg_timeout, "(not set)") +declare_deprecated_handler(bindings_file, DEFAULT_BINDINGS_FILE) +declare_deprecated_handler(wwids_file, DEFAULT_WWIDS_FILE) +declare_deprecated_handler(prkeys_file, DEFAULT_PRKEYS_FILE) /* * If you add or remove a keyword also update multipath/multipath.conf.5 @@ -2106,9 +2079,9 @@ init_keywords(vector keywords) install_keyword("fast_io_fail_tmo", &def_fast_io_fail_handler, &snprint_def_fast_io_fail); install_keyword("dev_loss_tmo", &def_dev_loss_handler, &snprint_def_dev_loss); install_keyword("eh_deadline", &def_eh_deadline_handler, &snprint_def_eh_deadline); - install_keyword("bindings_file", &def_bindings_file_handler, &snprint_def_bindings_file); - install_keyword("wwids_file", &def_wwids_file_handler, &snprint_def_wwids_file); - install_keyword("prkeys_file", &def_prkeys_file_handler, &snprint_def_prkeys_file); + install_keyword("bindings_file", &deprecated_bindings_file_handler, &snprint_deprecated); + install_keyword("wwids_file", &deprecated_wwids_file_handler, &snprint_deprecated); + install_keyword("prkeys_file", &deprecated_prkeys_file_handler, &snprint_deprecated); install_keyword("log_checker_err", &def_log_checker_err_handler, &snprint_def_log_checker_err); install_keyword("reservation_key", &def_reservation_key_handler, &snprint_def_reservation_key); install_keyword("all_tg_pt", &def_all_tg_pt_handler, &snprint_def_all_tg_pt); diff --git a/libmultipath/libmultipath.version b/libmultipath/libmultipath.version index 57e50c1..8368ef7 100644 --- a/libmultipath/libmultipath.version +++ b/libmultipath/libmultipath.version @@ -43,7 +43,7 @@ LIBMPATHCOMMON_1.0.0 { put_multipath_config; }; -LIBMULTIPATH_20.0.0 { +LIBMULTIPATH_21.0.0 { global: /* symbols referenced by multipath and multipathd */ add_foreign; @@ -121,6 +121,7 @@ global: get_used_hwes; get_vpd_sgio; group_by_prio; + handle_bindings_file_inotify; has_dm_info; init_checkers; init_config; @@ -238,8 +239,3 @@ global: local: *; }; - -LIBMULTIPATH_20.1.0 { -global: - handle_bindings_file_inotify; -}; diff --git a/libmultipath/prkey.c b/libmultipath/prkey.c index a215499..c66d293 100644 --- a/libmultipath/prkey.c +++ b/libmultipath/prkey.c @@ -157,8 +157,7 @@ static int do_prkey(int fd, char *wwid, char *keystr, int cmd) return 0; } -int get_prkey(struct config *conf, struct multipath *mpp, uint64_t *prkey, - uint8_t *sa_flags) +int get_prkey(struct multipath *mpp, uint64_t *prkey, uint8_t *sa_flags) { int fd; int unused; @@ -168,7 +167,7 @@ int get_prkey(struct config *conf, struct multipath *mpp, uint64_t *prkey, if (!strlen(mpp->wwid)) goto out; - fd = open_file(conf->prkeys_file, &unused, PRKEYS_FILE_HEADER); + fd = open_file(DEFAULT_PRKEYS_FILE, &unused, PRKEYS_FILE_HEADER); if (fd < 0) goto out; ret = do_prkey(fd, mpp->wwid, keystr, PRKEY_READ); @@ -201,7 +200,7 @@ int set_prkey(struct config *conf, struct multipath *mpp, uint64_t prkey, sa_flags &= MPATH_F_APTPL_MASK; } - fd = open_file(conf->prkeys_file, &can_write, PRKEYS_FILE_HEADER); + fd = open_file(DEFAULT_PRKEYS_FILE, &can_write, PRKEYS_FILE_HEADER); if (fd < 0) goto out; if (!can_write) { diff --git a/libmultipath/prkey.h b/libmultipath/prkey.h index a16de10..43afd5e 100644 --- a/libmultipath/prkey.h +++ b/libmultipath/prkey.h @@ -16,9 +16,8 @@ int print_reservation_key(struct strbuf *buff, struct be64 key, uint8_t flags, int source); int parse_prkey_flags(const char *ptr, uint64_t *prkey, uint8_t *flags); -int set_prkey(struct config *conf, struct multipath *mpp, uint64_t prkey, - uint8_t sa_flags); -int get_prkey(struct config *conf, struct multipath *mpp, uint64_t *prkey, - uint8_t *sa_flags); +int set_prkey(struct config *conf, struct multipath *mpp, + uint64_t prkey, uint8_t sa_flags); +int get_prkey(struct multipath *mpp, uint64_t *prkey, uint8_t *sa_flags); #endif /* _PRKEY_H */ diff --git a/libmultipath/propsel.c b/libmultipath/propsel.c index 354e883..44241e2 100644 --- a/libmultipath/propsel.c +++ b/libmultipath/propsel.c @@ -401,8 +401,7 @@ int select_alias(struct config *conf, struct multipath * mp) select_alias_prefix(conf, mp); - mp->alias = get_user_friendly_alias(mp->wwid, conf->bindings_file, - mp->alias_old, mp->alias_prefix, + mp->alias = get_user_friendly_alias(mp->wwid, mp->alias_old, mp->alias_prefix, conf->bindings_read_only); if (mp->alias && !strncmp(mp->alias, mp->alias_old, WWID_SIZE)) @@ -992,7 +991,7 @@ int select_reservation_key(struct config *conf, struct multipath *mp) out: if (mp->prkey_source == PRKEY_SOURCE_FILE) { from_file = " (from prkeys file)"; - if (get_prkey(conf, mp, &prkey, &mp->sa_flags) != 0) + if (get_prkey(mp, &prkey, &mp->sa_flags) != 0) put_be64(mp->reservation_key, 0); else put_be64(mp->reservation_key, prkey); diff --git a/libmultipath/wwids.c b/libmultipath/wwids.c index 89bb60c..591cd09 100644 --- a/libmultipath/wwids.c +++ b/libmultipath/wwids.c @@ -94,12 +94,8 @@ replace_wwids(vector mp) struct multipath * mpp; size_t len; int ret = -1; - struct config *conf; - conf = get_multipath_config(); - pthread_cleanup_push(put_multipath_config, conf); - fd = open_file(conf->wwids_file, &can_write, WWIDS_FILE_HEADER); - pthread_cleanup_pop(1); + fd = open_file(DEFAULT_WWIDS_FILE, &can_write, WWIDS_FILE_HEADER); if (fd < 0) goto out; @@ -200,7 +196,6 @@ remove_wwid(char *wwid) { int len, can_write; char *str; int ret = -1; - struct config *conf; len = strlen(wwid) + 4; /* two slashes the newline and a zero byte */ str = malloc(len); @@ -216,10 +211,7 @@ remove_wwid(char *wwid) { goto out; } condlog(3, "removing line '%s' from wwids file", str); - conf = get_multipath_config(); - pthread_cleanup_push(put_multipath_config, conf); - fd = open_file(conf->wwids_file, &can_write, WWIDS_FILE_HEADER); - pthread_cleanup_pop(1); + fd = open_file(DEFAULT_WWIDS_FILE, &can_write, WWIDS_FILE_HEADER); if (fd < 0) { ret = -1; @@ -244,12 +236,8 @@ check_wwids_file(char *wwid, int write_wwid) { int fd, can_write, found, ret; FILE *f; - struct config *conf; - conf = get_multipath_config(); - pthread_cleanup_push(put_multipath_config, conf); - fd = open_file(conf->wwids_file, &can_write, WWIDS_FILE_HEADER); - pthread_cleanup_pop(1); + fd = open_file(DEFAULT_WWIDS_FILE, &can_write, WWIDS_FILE_HEADER); if (fd < 0) return -1; diff --git a/multipath/main.c b/multipath/main.c index b91289e..9e1c505 100644 --- a/multipath/main.c +++ b/multipath/main.c @@ -856,7 +856,7 @@ main (int argc, char *argv[]) libmp_verbosity = atoi(optarg); break; case 'b': - conf->bindings_file = strdup(optarg); + condlog(1, "option -b ignored"); break; case 'B': conf->bindings_read_only = 1; diff --git a/multipath/multipath.conf.5.in b/multipath/multipath.conf.5.in index 20df223..d320a88 100644 --- a/multipath/multipath.conf.5.in +++ b/multipath/multipath.conf.5.in @@ -794,35 +794,28 @@ The default is: \fB\fR . .TP .B bindings_file -(Deprecated) This option is deprecated, and will be removed in a future release. -The full pathname of the binding file to be used when the user_friendly_names -option is set. +(Deprecated) This option is not supported any more, and will be ignored. .RS .TP -The default is: \fB@STATE_DIR@/bindings\fR +The compiled-in value is: \fB@STATE_DIR@/bindings\fR .RE . . .TP .B wwids_file -(Deprecated) This option is deprecated, and will be removed in a future release. -The full pathname of the WWIDs file, which is used by multipath to keep track -of the WWIDs for LUNs it has created multipath devices on in the past. +(Deprecated) This option is not supported any more, and will be ignored. .RS .TP -The default is: \fB@STATE_DIR@/wwids\fR +The compiled-in value is: \fB@STATE_DIR@/wwids\fR .RE . . .TP .B prkeys_file -(Deprecated) This option is deprecated, and will be removed in a future release. -The full pathname of the prkeys file, which is used by multipathd to keep -track of the persistent reservation key used for a specific WWID, when -\fIreservation_key\fR is set to \fBfile\fR. +(Deprecated) This option is not supported any more, and will be ignored. .RS .TP -The default is: \fB@STATE_DIR@/prkeys\fR +The compiled-in value is: \fB@STATE_DIR@/prkeys\fR .RE . . @@ -989,6 +982,10 @@ The default is: \fB\fR .TP .B config_dir (Deprecated) This option is not supported any more, and the value is ignored. +.RS +.TP +The compiled-in value is: \fB@CONFIGDIR@\fR +.RE . . .TP diff --git a/multipathd/uxlsnr.c b/multipathd/uxlsnr.c index d1f8f23..4d6f258 100644 --- a/multipathd/uxlsnr.c +++ b/multipathd/uxlsnr.c @@ -203,7 +203,6 @@ static void reset_watch(int notify_fd, struct watch_descriptors *wds, int dir_reset = 0; int conf_reset = 0; int mp_reset = 0; - char *bindings_file __attribute__((cleanup(cleanup_charp))) = NULL; if (notify_fd == -1) return; @@ -221,7 +220,6 @@ static void reset_watch(int notify_fd, struct watch_descriptors *wds, if (wds->mp_wd == -1) mp_reset = 1; } - bindings_file = strdup(conf->bindings_file); put_multipath_config(conf); if (dir_reset) { @@ -242,17 +240,12 @@ static void reset_watch(int notify_fd, struct watch_descriptors *wds, if (wds->conf_wd == -1) condlog(3, "didn't set up notifications on /etc/multipath.conf: %m"); } - if (mp_reset && bindings_file) { - char *slash = strrchr(bindings_file, '/'); - - if (slash && slash > bindings_file) { - *slash = '\0'; - wds->mp_wd = inotify_add_watch(notify_fd, bindings_file, - IN_MOVED_TO|IN_ONLYDIR); - if (wds->mp_wd == -1) + if (mp_reset) { + wds->mp_wd = inotify_add_watch(notify_fd, STATE_DIR, + IN_MOVED_TO|IN_ONLYDIR); + if (wds->mp_wd == -1) condlog(3, "didn't set up notifications on %s: %m", - bindings_file); - } + STATE_DIR); } } diff --git a/tests/alias.c b/tests/alias.c index 962c158..feca325 100644 --- a/tests/alias.c +++ b/tests/alias.c @@ -1264,10 +1264,10 @@ static void al_a(void **state) will_return(__wrap_write, ln); will_return(__wrap_write, strlen(BINDINGS_FILE_HEADER) + strlen(ln)); will_return(__wrap_rename, 0); - expect_condlog(1, "updated bindings file foo"); + expect_condlog(1, "updated bindings file " DEFAULT_BINDINGS_FILE); expect_condlog(3, NEW_STR("MPATHa", "WWIDa")); - alias = allocate_binding("foo", "WWIDa", 1, "MPATH"); + alias = allocate_binding("WWIDa", 1, "MPATH"); assert_ptr_not_equal(alias, NULL); assert_string_equal(alias, "MPATHa"); check_bindings_size(1); @@ -1283,10 +1283,10 @@ static void al_zz(void **state) will_return(__wrap_write, ln); will_return(__wrap_write, strlen(BINDINGS_FILE_HEADER) + strlen(ln)); will_return(__wrap_rename, 0); - expect_condlog(1, "updated bindings file foo"); + expect_condlog(1, "updated bindings file " DEFAULT_BINDINGS_FILE); expect_condlog(3, NEW_STR("MPATHzz", "WWIDzz")); - alias = allocate_binding("foo", "WWIDzz", 26*26 + 26, "MPATH"); + alias = allocate_binding("WWIDzz", 26*26 + 26, "MPATH"); assert_ptr_not_equal(alias, NULL); assert_string_equal(alias, "MPATHzz"); check_bindings_size(1); @@ -1298,7 +1298,7 @@ static void al_0(void **state) char *alias; expect_condlog(0, "allocate_binding: cannot allocate new binding for id 0\n"); - alias = allocate_binding(0, "WWIDa", 0, "MPATH"); + alias = allocate_binding("WWIDa", 0, "MPATH"); assert_ptr_equal(alias, NULL); check_bindings_size(0); } @@ -1308,7 +1308,7 @@ static void al_m2(void **state) char *alias; expect_condlog(0, "allocate_binding: cannot allocate new binding for id -2\n"); - alias = allocate_binding(0, "WWIDa", -2, "MPATH"); + alias = allocate_binding("WWIDa", -2, "MPATH"); assert_ptr_equal(alias, NULL); check_bindings_size(0); } @@ -1325,10 +1325,10 @@ static void al_write_partial(void **state) will_return(__wrap_write, ln + sizeof(ln) - 2); will_return(__wrap_write, 1); will_return(__wrap_rename, 0); - expect_condlog(1, "updated bindings file foo"); + expect_condlog(1, "updated bindings file " DEFAULT_BINDINGS_FILE); expect_condlog(3, "Created new binding [MPATHa] for WWID [WWIDa]\n"); - alias = allocate_binding("foo", "WWIDa", 1, "MPATH"); + alias = allocate_binding("WWIDa", 1, "MPATH"); assert_ptr_not_equal(alias, NULL); assert_string_equal(alias, "MPATHa"); check_bindings_size(1); @@ -1350,7 +1350,7 @@ static void al_write_short(void **state) expect_condlog(1, "failed to write new bindings file"); expect_condlog(1, "allocate_binding: deleting binding MPATHa for WWIDa"); - alias = allocate_binding("foo", "WWIDa", 1, "MPATH"); + alias = allocate_binding("WWIDa", 1, "MPATH"); assert_ptr_equal(alias, NULL); check_bindings_size(0); } @@ -1366,7 +1366,7 @@ static void al_write_err(void **state) expect_condlog(1, "failed to write new bindings file"); expect_condlog(1, "allocate_binding: deleting binding MPATHa for WWIDa"); - alias = allocate_binding("foo", "WWIDa", 1, "MPATH"); + alias = allocate_binding("WWIDa", 1, "MPATH"); assert_ptr_equal(alias, NULL); check_bindings_size(0); } @@ -1383,7 +1383,7 @@ static void al_rename_err(void **state) expect_condlog(0, "update_bindings_file: rename: Read-only file system"); expect_condlog(1, "allocate_binding: deleting binding MPATHa for WWIDa"); - alias = allocate_binding("foo", "WWIDa", 1, "MPATH"); + alias = allocate_binding("WWIDa", 1, "MPATH"); assert_ptr_equal(alias, NULL); check_bindings_size(0); } @@ -1415,7 +1415,7 @@ static int test_allocate_binding(void) strlen(BINDINGS_FILE_HEADER) + (len) + strlen(ln)); \ will_return(__wrap_rename, err); \ if (err == 0) { \ - expect_condlog(1, "updated bindings file x\n"); \ + expect_condlog(1, "updated bindings file " DEFAULT_BINDINGS_FILE); \ expect_condlog(3, NEW_STR(alias, wwid)); \ } else { \ expect_condlog(0, "update_bindings_file: rename: " msg "\n"); \ @@ -1441,7 +1441,7 @@ static void gufa_empty_new_rw(void **state) { expect_condlog(3, NOMATCH_WWID_STR("WWID0")); mock_allocate_binding("MPATHa", "WWID0"); - alias = get_user_friendly_alias("WWID0", "x", "", "MPATH", false); + alias = get_user_friendly_alias("WWID0", "", "MPATH", false); assert_string_equal(alias, "MPATHa"); free(alias); } @@ -1454,7 +1454,7 @@ static void gufa_empty_new_ro_1(void **state) { expect_condlog(3, NOMATCH_WWID_STR("WWID0")); mock_allocate_binding_err("MPATHa", "WWID0", -EROFS, "Read-only file system"); - alias = get_user_friendly_alias("WWID0", "x", "", "MPATH", false); + alias = get_user_friendly_alias("WWID0", "", "MPATH", false); assert_ptr_equal(alias, NULL); } @@ -1465,7 +1465,7 @@ static void gufa_empty_new_ro_2(void **state) { expect_condlog(3, NOMATCH_WWID_STR("WWID0")); mock_unused_alias("MPATHa"); - alias = get_user_friendly_alias("WWID0", "x", "", "MPATH", true); + alias = get_user_friendly_alias("WWID0", "", "MPATH", true); assert_ptr_equal(alias, NULL); } @@ -1477,7 +1477,7 @@ static void gufa_match_a_unused(void **state) { mock_unused_alias("MPATHa"); expect_condlog(3, EXISTING_STR("MPATHa", "WWID0")); - alias = get_user_friendly_alias("WWID0", "x", "", "MPATH", true); + alias = get_user_friendly_alias("WWID0", "", "MPATH", true); assert_string_equal(alias, "MPATHa"); free(alias); } @@ -1490,7 +1490,7 @@ static void gufa_match_a_self(void **state) { mock_self_alias("MPATHa", "WWID0"); expect_condlog(3, EXISTING_STR("MPATHa", "WWID0")); - alias = get_user_friendly_alias("WWID0", "x", "", "MPATH", true); + alias = get_user_friendly_alias("WWID0", "", "MPATH", true); assert_string_equal(alias, "MPATHa"); free(alias); } @@ -1503,7 +1503,7 @@ static void gufa_match_a_used(void **state) { expect_condlog(3, FOUND_STR("MPATHa", "WWID0")); mock_used_alias("MPATHa", "WWID0"); - alias = get_user_friendly_alias("WWID0", "x", "", "MPATH", true); + alias = get_user_friendly_alias("WWID0", "", "MPATH", true); assert_ptr_equal(alias, NULL); } @@ -1518,7 +1518,7 @@ static void gufa_nomatch_a_c(void **state) { mock_allocate_binding_len("MPATHb", "WWID1", strlen(bindings)); - alias = get_user_friendly_alias("WWID1", "x", "", "MPATH", false); + alias = get_user_friendly_alias("WWID1", "", "MPATH", false); assert_string_equal(alias, "MPATHb"); free(alias); } @@ -1534,7 +1534,7 @@ static void gufa_nomatch_c_a(void **state) { mock_allocate_binding_len("MPATHb", "WWID1", sizeof(bindings) - 1); - alias = get_user_friendly_alias("WWID1", "x", "", "MPATH", false); + alias = get_user_friendly_alias("WWID1", "", "MPATH", false); assert_string_equal(alias, "MPATHb"); free(alias); } @@ -1550,7 +1550,7 @@ static void gufa_nomatch_c_b(void **state) { mock_allocate_binding_len("MPATHa", "WWID0", sizeof(bindings) - 1); - alias = get_user_friendly_alias("WWID0", "x", "", "MPATH", false); + alias = get_user_friendly_alias("WWID0", "", "MPATH", false); assert_string_equal(alias, "MPATHa"); free(alias); } @@ -1567,7 +1567,7 @@ static void gufa_nomatch_c_b_used(void **state) { mock_allocate_binding_len("MPATHd", "WWID4", sizeof(bindings) - 1); - alias = get_user_friendly_alias("WWID4", "x", "", "MPATH", false); + alias = get_user_friendly_alias("WWID4", "", "MPATH", false); assert_string_equal(alias, "MPATHd"); free(alias); } @@ -1584,7 +1584,7 @@ static void gufa_nomatch_b_f_a(void **state) { mock_allocate_binding_len("MPATHc", "WWID7", sizeof(bindings) - 1); - alias = get_user_friendly_alias("WWID7", "x", "", "MPATH", false); + alias = get_user_friendly_alias("WWID7", "", "MPATH", false); assert_string_equal(alias, "MPATHc"); free(alias); } @@ -1599,7 +1599,7 @@ static void gufa_nomatch_b_aa_a(void **state) { mock_unused_alias("MPATHab"); mock_allocate_binding_len("MPATHab", "WWID28", get_strbuf_len(&buf)); - alias = get_user_friendly_alias("WWID28", "x", "", "MPATH", false); + alias = get_user_friendly_alias("WWID28", "", "MPATH", false); assert_string_equal(alias, "MPATHab"); free(alias); } @@ -1616,7 +1616,7 @@ static void gufa_nomatch_b_f_a_sorted(void **state) { mock_allocate_binding_len("MPATHc", "WWID7", sizeof(bindings) - 1); - alias = get_user_friendly_alias("WWID7", "x", "", "MPATH", false); + alias = get_user_friendly_alias("WWID7", "", "MPATH", false); assert_string_equal(alias, "MPATHc"); free(alias); } @@ -1632,7 +1632,7 @@ static void gufa_old_empty(void **state) { mock_allocate_binding("MPATHz", "WWID0"); expect_condlog(2, ALLOC_STR("MPATHz", "WWID0")); - alias = get_user_friendly_alias("WWID0", "x", "MPATHz", "MPATH", false); + alias = get_user_friendly_alias("WWID0", "MPATHz", "MPATH", false); assert_string_equal(alias, "MPATHz"); free(alias); } @@ -1644,7 +1644,7 @@ static void gufa_old_match(void **state) { "MPATHz WWID0"); expect_condlog(3, FOUND_ALIAS_STR("MPATHz", "WWID0")); - alias = get_user_friendly_alias("WWID0", "x", "MPATHz", "MPATH", false); + alias = get_user_friendly_alias("WWID0", "MPATHz", "MPATH", false); assert_string_equal(alias, "MPATHz"); free(alias); } @@ -1661,7 +1661,7 @@ static void gufa_old_match_other(void **state) { mock_allocate_binding_len("MPATHa", "WWID0", sizeof(bindings) - 1); - alias = get_user_friendly_alias("WWID0", "x", "MPATHz", "MPATH", false); + alias = get_user_friendly_alias("WWID0", "MPATHz", "MPATH", false); assert_string_equal(alias, "MPATHa"); free(alias); } @@ -1678,7 +1678,7 @@ static void gufa_old_match_other_used(void **state) { mock_unused_alias("MPATHb"); mock_allocate_binding_len("MPATHb", "WWID0", sizeof(bindings) - 1); - alias = get_user_friendly_alias("WWID0", "x", "MPATHz", "MPATH", false); + alias = get_user_friendly_alias("WWID0", "MPATHz", "MPATH", false); assert_string_equal(alias, "MPATHb"); free(alias); } @@ -1695,7 +1695,7 @@ static void gufa_old_match_other_wwidmatch(void **state) { mock_unused_alias("MPATHc"); expect_condlog(3, EXISTING_STR("MPATHc", "WWID2")); - alias = get_user_friendly_alias("WWID2", "x", "MPATHz", "MPATH", false); + alias = get_user_friendly_alias("WWID2", "MPATHz", "MPATH", false); assert_string_equal(alias, "MPATHc"); free(alias); } @@ -1711,7 +1711,7 @@ static void gufa_old_match_other_wwidmatch_used(void **state) { expect_condlog(3, FOUND_STR("MPATHc", "WWID2")); mock_used_alias("MPATHc", "WWID2"); - alias = get_user_friendly_alias("WWID2", "x", "MPATHz", "MPATH", false); + alias = get_user_friendly_alias("WWID2", "MPATHz", "MPATH", false); assert_ptr_equal(alias, NULL); } @@ -1725,7 +1725,7 @@ static void gufa_old_nomatch_wwidmatch(void **state) { mock_unused_alias("MPATHa"); expect_condlog(3, EXISTING_STR("MPATHa", "WWID0")); - alias = get_user_friendly_alias("WWID0", "x", "MPATHz", "MPATH", false); + alias = get_user_friendly_alias("WWID0", "MPATHz", "MPATH", false); assert_string_equal(alias, "MPATHa"); free(alias); } @@ -1739,7 +1739,7 @@ static void gufa_old_nomatch_wwidmatch_used(void **state) { expect_condlog(3, FOUND_STR("MPATHa", "WWID0")); mock_used_alias("MPATHa", "WWID0"); - alias = get_user_friendly_alias("WWID0", "x", "MPATHz", "MPATH", false); + alias = get_user_friendly_alias("WWID0", "MPATHz", "MPATH", false); assert_ptr_equal(alias, NULL); } @@ -1754,7 +1754,7 @@ static void gufa_old_nomatch_nowwidmatch(void **state) { mock_allocate_binding_len("MPATHz", "WWID0", sizeof(bindings) - 1); expect_condlog(2, ALLOC_STR("MPATHz", "WWID0")); - alias = get_user_friendly_alias("WWID0", "x", "MPATHz", "MPATH", false); + alias = get_user_friendly_alias("WWID0", "MPATHz", "MPATH", false); assert_string_equal(alias, "MPATHz"); free(alias); }