From patchwork Fri Sep 1 18:02: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: 13372811 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 1A035CA0FF0 for ; Fri, 1 Sep 2023 18:03:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693591408; 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=hWaZ6gA6n+H/pb1zNYAUXFmGuM9855BQOiEYwi0/itw=; b=RSqbMoyynyIeYZ/seJa1/j3y2cgdgpA5wQvQQkGPxbIMqHXBLXUruB2tA+1iUXWCs73loY vVKebCo7GFd2XzviY/i5d0yHThKFU1/U9ePt4lL3y+C89hLZLrrIDgloGoPJjJbBBDT8Bq VNyukaTsaZHmfkI3bsz9xh8Hmgyo3Kk= 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-693-ZOO9A1KeNDS-3M10DiKsNw-1; Fri, 01 Sep 2023 14:03:24 -0400 X-MC-Unique: ZOO9A1KeNDS-3M10DiKsNw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 18EB9917E79; Fri, 1 Sep 2023 18:03: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 85C9640C84A6; Fri, 1 Sep 2023 18:03: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 62A931947299; Fri, 1 Sep 2023 18:03:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id AD46F19465B7 for ; Fri, 1 Sep 2023 18:03:19 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 909011402C0A; Fri, 1 Sep 2023 18:03:19 +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 888151460FE7 for ; Fri, 1 Sep 2023 18:03:19 +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 4F9931817907 for ; Fri, 1 Sep 2023 18:03: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-396-lIcnhm-SOCSFBOkZe1I8Rg-1; Fri, 01 Sep 2023 14:03:17 -0400 X-MC-Unique: lIcnhm-SOCSFBOkZe1I8Rg-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 315BD21862; Fri, 1 Sep 2023 18:03: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 E98E013582; Fri, 1 Sep 2023 18:03:15 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id GIYWN2Mn8mTpRQAAMHmgww (envelope-from ); Fri, 01 Sep 2023 18:03:15 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 1 Sep 2023 20:02:14 +0200 Message-ID: <20230901180235.23980-2-mwilck@suse.com> In-Reply-To: <20230901180235.23980-1-mwilck@suse.com> References: <20230901180235.23980-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.7 Subject: [dm-devel] [PATCH 01/21] 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.1 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 Fri Sep 1 18:02: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: 13372813 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 5D540CA0FF4 for ; Fri, 1 Sep 2023 18:03:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693591409; 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=YqradqieUeyyS36hjN+rqQ5NgWjmOnFaDspqtQv0WAc=; b=fHV8qzVuq0u2oM/tN6OSuitKfzHKvSjjnpVEvbDSTVyKJUZaDRgdxSFeRLISa3FhFNbm0j deVvvqhbolkQVNryeEK3oP04S0KphrtcJGlQPu9i1C7kWvB6vqnWphJHRm/20cT48tXq4t KD/w2Qaw1XSxnoHINcqzHr3vwlUTOaw= 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-516-7nAG2YmUNxeYhQaLKJn5tQ-1; Fri, 01 Sep 2023 14:03:26 -0400 X-MC-Unique: 7nAG2YmUNxeYhQaLKJn5tQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 42CC81C18C9B; Fri, 1 Sep 2023 18:03: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 2AE3D20C3B2A; Fri, 1 Sep 2023 18:03: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 E695C194729D; Fri, 1 Sep 2023 18:03:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 8096219472AD for ; Fri, 1 Sep 2023 18:03:21 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 7021F1460FE7; Fri, 1 Sep 2023 18:03: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 699DC1402C0A for ; Fri, 1 Sep 2023 18:03:21 +0000 (UTC) Received: from us-smtp-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 4DF7610264FA for ; Fri, 1 Sep 2023 18:03: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-635-qLFsq1_sOKWx0zaV32HuhQ-1; Fri, 01 Sep 2023 14:03:17 -0400 X-MC-Unique: qLFsq1_sOKWx0zaV32HuhQ-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 A0B2E21865; Fri, 1 Sep 2023 18:03: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 4304713582; Fri, 1 Sep 2023 18:03:16 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ANGeDWQn8mTpRQAAMHmgww (envelope-from ); Fri, 01 Sep 2023 18:03:16 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 1 Sep 2023 20:02:15 +0200 Message-ID: <20230901180235.23980-3-mwilck@suse.com> In-Reply-To: <20230901180235.23980-1-mwilck@suse.com> References: <20230901180235.23980-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.7 Subject: [dm-devel] [PATCH 02/21] 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 , David Bond 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 Factor out a trivial helper function. Signed-off-by: Martin Wilck Cc: David Bond --- libmultipath/alias.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/libmultipath/alias.c b/libmultipath/alias.c index c0139a2..abde08c 100644 --- a/libmultipath/alias.c +++ b/libmultipath/alias.c @@ -8,6 +8,7 @@ #include #include #include +#include #include "debug.h" #include "util.h" @@ -109,8 +110,24 @@ 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) +{ + + 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 false; + condlog(3, "%s: alias '%s' already taken, but not in bindings file. reselecting alias", + map_wwid, alias); + return true; + } + return false; +} + +static bool id_already_taken(int id, const char *prefix, const char *map_wwid) { STRBUF_ON_STACK(buf); const char *alias; @@ -120,20 +137,9 @@ id_already_taken(int id, const char *prefix, const char *map_wwid) 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 0; + return alias_already_taken(alias, map_wwid); } - /* * Returns: 0 if matching entry in WWIDs file found * -1 if an error occurs From patchwork Fri Sep 1 18:02: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: 13372810 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 32369CA0FEF for ; Fri, 1 Sep 2023 18:03:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693591407; 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=EZgwwZqbMcd4xe45dp4JTdgrR9S4/644wrd+/iX9QRA=; b=B9BbSN4Jrav0jSsOwWjnuiLT4OTxsuzHqqnqQCMWqtl+N7dEPyJzlcujpHffau7fG6ye/9 CaaP4IIoQBybxhYqiE6Hv2TJhckpzq7OFJTFqtAi7v9Jf7de+tLbnHs3DuygpR6/mBA5lt /beqRpeklI4PcKFPRSm7Op+w93ow+uM= 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-650-IKRgEI-KNnmoD2UkOYGmTw-1; Fri, 01 Sep 2023 14:03:25 -0400 X-MC-Unique: IKRgEI-KNnmoD2UkOYGmTw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 19187381CC15; Fri, 1 Sep 2023 18:03: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 F3B6E1055466; Fri, 1 Sep 2023 18:03: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 8D88919472AF; Fri, 1 Sep 2023 18:03:21 +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 15A8D19465B7 for ; Fri, 1 Sep 2023 18:03:20 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id EA53140C84A6; Fri, 1 Sep 2023 18:03:19 +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 E337840C84A5 for ; Fri, 1 Sep 2023 18:03:19 +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 C549492ACE3 for ; Fri, 1 Sep 2023 18:03: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-652-GlwMz_AUOCOWgsqMLqEjKw-1; Fri, 01 Sep 2023 14:03:18 -0400 X-MC-Unique: GlwMz_AUOCOWgsqMLqEjKw-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 069F02186C; Fri, 1 Sep 2023 18:03: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 AD60013582; Fri, 1 Sep 2023 18:03:16 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id +EeXKGQn8mTpRQAAMHmgww (envelope-from ); Fri, 01 Sep 2023 18:03:16 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 1 Sep 2023 20:02:16 +0200 Message-ID: <20230901180235.23980-4-mwilck@suse.com> In-Reply-To: <20230901180235.23980-1-mwilck@suse.com> References: <20230901180235.23980-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 03/21] 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 , David Bond 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 These functions are only called from select_alias(). The logic is more obvious when unified in a single function. Signed-off-by: Martin Wilck Cc: David Bond 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 abde08c..9b9b789 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 Fri Sep 1 18:02: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: 13372814 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 00DA0CA0FF3 for ; Fri, 1 Sep 2023 18:03:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693591410; 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=fVTofy/GE26BoZ46iNBTKBO3MnFugZ8nRx62ktSN2Uw=; b=Z3CtSobOTr72g0UWbQH8Ykdq3CcbJpZeyTI03izqHK9BTWNLJUoSgzCsM42tlJFVLenr3V 5K/YGtB2if0lbG280ZAnM7RBZPuhcdNcg46HxsJO/4jdyuStbD+S+qfznVG1Nc2dsp2cAm bJbdw2Ztg0dbGl8y6V1vX4quu7Xqqhc= 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-630-wXCamYrVO3SaPS8QPHGBQg-1; Fri, 01 Sep 2023 14:03:26 -0400 X-MC-Unique: wXCamYrVO3SaPS8QPHGBQg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 00E393C0EAB6; Fri, 1 Sep 2023 18:03: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 E2AC7400E413; Fri, 1 Sep 2023 18:03: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 B88A11946A46; Fri, 1 Sep 2023 18:03:22 +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 8066219472AC for ; Fri, 1 Sep 2023 18:03:21 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 70F27200A86A; Fri, 1 Sep 2023 18:03:21 +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 6A40321D4F3D for ; Fri, 1 Sep 2023 18:03:21 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.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 4D175897F6A for ; Fri, 1 Sep 2023 18:03: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-686-QlobgJM6NACM-2_GOoEwIA-1; Fri, 01 Sep 2023 14:03:18 -0400 X-MC-Unique: QlobgJM6NACM-2_GOoEwIA-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 4C2BD1F45E; Fri, 1 Sep 2023 18:03: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 16C7113582; Fri, 1 Sep 2023 18:03:17 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 4C2AA2Un8mTpRQAAMHmgww (envelope-from ); Fri, 01 Sep 2023 18:03:17 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 1 Sep 2023 20:02:17 +0200 Message-ID: <20230901180235.23980-5-mwilck@suse.com> In-Reply-To: <20230901180235.23980-1-mwilck@suse.com> References: <20230901180235.23980-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 04/21] 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.2 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 --- libmultipath/alias.c | 36 +++++++++++++++++++++++++++++++----- tests/alias.c | 2 +- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/libmultipath/alias.c b/libmultipath/alias.c index 9b9b789..f7834d1 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; } @@ -363,28 +363,54 @@ char *get_user_friendly_alias(const char *wwid, const char *file, const char *al * allocated correctly */ if (strcmp(buff, wwid) == 0) { - alias = strdup(alias_old); + if (!alias_already_taken(alias_old, wwid)) + alias = strdup(alias_old); + else + condlog(0, "ERROR: old alias [%s] for wwid [%s] is used by other map", + alias_old, wwid); goto out; + } else { condlog(0, "alias %s already bound to wwid %s, cannot reuse", alias_old, buff); - goto new_alias; + 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. + */ 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 */ id = scan_devname(alias_old, prefix); + if (id > 0 && id_already_taken(id, prefix, wwid)) { + condlog(0, "ERROR: old alias [%s] for wwid [%s] is used by other map", + alias_old, wwid); + goto out; + } 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 Fri Sep 1 18:02: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: 13372812 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 80F0FCA0FF2 for ; Fri, 1 Sep 2023 18:03:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693591408; 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=8QW8RLG0J+La7zuf7vvqt1JqJVoARX/f7jN3DA6EzTg=; b=GwoNR/hHsWMauffORdKC+G1akbEKUHJD8PoDUt6sp2sxIb86nlwHTRiVX/T6D27SfbvoDo Z6ga7IOFF/ZmcJVsDLIZ1mxRnHw5Glp/5WfIaV4ajW3L1zCF0qcjiCtzpAIcB8fTWBhUjr sSzw6pexxeXfqo1zoCu9TjC4x0YkieM= 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-621-AFF7DOUPO-W82D-jI7Mw2Q-1; Fri, 01 Sep 2023 14:03:25 -0400 X-MC-Unique: AFF7DOUPO-W82D-jI7Mw2Q-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9D28E917E7A; Fri, 1 Sep 2023 18:03: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 8BDD5D47819; Fri, 1 Sep 2023 18:03: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 71A621946A46; Fri, 1 Sep 2023 18:03:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id CB53A19465B7 for ; Fri, 1 Sep 2023 18:03:20 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id B9184D4781A; Fri, 1 Sep 2023 18:03:20 +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 B1A7CD4781D for ; Fri, 1 Sep 2023 18:03:20 +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 94FCF8F99FC for ; Fri, 1 Sep 2023 18:03: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-125-bs4UTZ3BNfiDdgp12CF9eQ-1; Fri, 01 Sep 2023 14:03:19 -0400 X-MC-Unique: bs4UTZ3BNfiDdgp12CF9eQ-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 D20502186E; Fri, 1 Sep 2023 18:03: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 55DA313582; Fri, 1 Sep 2023 18:03:17 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id mHFqE2Un8mTpRQAAMHmgww (envelope-from ); Fri, 01 Sep 2023 18:03:17 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 1 Sep 2023 20:02:18 +0200 Message-ID: <20230901180235.23980-6-mwilck@suse.com> In-Reply-To: <20230901180235.23980-1-mwilck@suse.com> References: <20230901180235.23980-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.8 Subject: [dm-devel] [PATCH 05/21] 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.8 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 f7834d1..e61eb91 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 Fri Sep 1 18:02: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: 13372816 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 4FF95CA0FEF for ; Fri, 1 Sep 2023 18:03:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693591414; 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=kyijpXnKcpSNm373USndNsOEP+5+kB7bYcvv+kXpSGc=; b=O0pmByGANFV8OXGXQCFZCY+E1nQ0w6V2x5XgDoKTdyrXPvu/vE+8ar9ed5a87CC5pYaiXE nm+xnMLg/PJ27O0Y2QpOs4E0ozhQ6rZ16JcuF7Uh9YaJDNAGQ0LMIjz/jyUJwllZ/h8X58 1nTuHOQIGWsNj0phaKgkgaAH6VDLLzQ= 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-329-z5cVcW65NI2bA6ZUYDEmsQ-1; Fri, 01 Sep 2023 14:03:30 -0400 X-MC-Unique: z5cVcW65NI2bA6ZUYDEmsQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3C8ED3C0EAC4; Fri, 1 Sep 2023 18:03: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 2BEFF2026D0E; Fri, 1 Sep 2023 18:03: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 1E2201946A46; Fri, 1 Sep 2023 18:03:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id B84AB19472A8 for ; Fri, 1 Sep 2023 18:03:23 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 9A464493110; Fri, 1 Sep 2023 18:03:23 +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 9325649310F for ; Fri, 1 Sep 2023 18:03:23 +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 72AF2381DC9E for ; Fri, 1 Sep 2023 18:03: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-207-DjUVIyOlPgKj9YspEy3ARA-1; Fri, 01 Sep 2023 14:03:19 -0400 X-MC-Unique: DjUVIyOlPgKj9YspEy3ARA-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 48EB91F74D; Fri, 1 Sep 2023 18:03: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 ED56013582; Fri, 1 Sep 2023 18:03:17 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id cJhcNmUn8mTpRQAAMHmgww (envelope-from ); Fri, 01 Sep 2023 18:03:17 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 1 Sep 2023 20:02:19 +0200 Message-ID: <20230901180235.23980-7-mwilck@suse.com> In-Reply-To: <20230901180235.23980-1-mwilck@suse.com> References: <20230901180235.23980-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.10 Subject: [dm-devel] [PATCH 06/21] 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.4 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 Fri Sep 1 18:02: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: 13372821 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 7B6CBCA0FF5 for ; Fri, 1 Sep 2023 18:03:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693591416; 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=QRFoqeJrwAruntQyinFcz7aRB0X8ya+QH8tzsGRClNk=; b=GZwlLkErnmGqJjMyDakxl7mqCpKBtHkUqh4DgamEmonN0Fscw4p3+VyS6vz5LUD7JKzLyP 4yW0OJM5SQXV0t3ImtsoVXPXAFIJB9uKY3uZj3CPCktRbGbR2Qf6DSRdXfOCuB27KxgB2X hgda1guf00u2MXH1LsRciyWMSyzRaoE= 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-172-5y8R5AVtPYGR8cn-hlesEQ-1; Fri, 01 Sep 2023 14:03:30 -0400 X-MC-Unique: 5y8R5AVtPYGR8cn-hlesEQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 830A08F99FE; Fri, 1 Sep 2023 18:03: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 6AD60404754A; Fri, 1 Sep 2023 18:03: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 48FFA19472AA; Fri, 1 Sep 2023 18:03:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 25C0E19465B7 for ; Fri, 1 Sep 2023 18:03:24 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 04BA81208F6E; Fri, 1 Sep 2023 18:03:24 +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 F0EC41055466 for ; Fri, 1 Sep 2023 18:03:23 +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 D2EA290A7E5 for ; Fri, 1 Sep 2023 18:03: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-552-ADfLOXSEP6qqgJIlLsNH1g-1; Fri, 01 Sep 2023 14:03:20 -0400 X-MC-Unique: ADfLOXSEP6qqgJIlLsNH1g-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 C0FDA211CE; Fri, 1 Sep 2023 18:03: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 62B6F13582; Fri, 1 Sep 2023 18:03:18 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id sBaxFGYn8mTpRQAAMHmgww (envelope-from ); Fri, 01 Sep 2023 18:03:18 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 1 Sep 2023 20:02:20 +0200 Message-ID: <20230901180235.23980-8-mwilck@suse.com> In-Reply-To: <20230901180235.23980-1-mwilck@suse.com> References: <20230901180235.23980-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.3 Subject: [dm-devel] [PATCH 07/21] 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.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: suse.com From: Martin Wilck Signed-off-by: Martin Wilck --- tests/alias.c | 531 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 531 insertions(+) diff --git a/tests/alias.c b/tests/alias.c index 11f209e..e2372d1 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,472 @@ 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_unused_alias("MPATHz"); + + 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_empty_self(void **state) { + char *alias; + will_return(__wrap_open_file, true); + + will_return(__wrap_fgets, NULL); + expect_condlog(3, NOMATCH_STR("MPATHz")); + + will_return(__wrap_fgets, NULL); + expect_condlog(3, NOMATCH_WWID_STR("WWID0")); + mock_self_alias("MPATHz", "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_empty_used(void **state) { + char *alias; + will_return(__wrap_open_file, true); + + will_return(__wrap_fgets, NULL); + expect_condlog(3, NOMATCH_STR("MPATHz")); + + will_return(__wrap_fgets, NULL); + expect_condlog(3, NOMATCH_WWID_STR("WWID0")); + mock_used_alias("MPATHz", USED_STR("MPATHz", "WWID0")); + expect_condlog(0, ERR_STR("MPATHz", "WWID0")); + + alias = get_user_friendly_alias("WWID0", "x", "MPATHz", "MPATH", false); + assert_ptr_equal(alias, NULL); +} + +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")); + mock_unused_alias("MPATHz"); + + alias = get_user_friendly_alias("WWID0", "x", "MPATHz", "MPATH", false); + assert_string_equal(alias, "MPATHz"); + free(alias); +} + +static void gufa_old_match_self(void **state) { + char *alias; + will_return(__wrap_open_file, true); + + mock_bindings_file("MPATHz WWID0", 0); + expect_condlog(3, FOUND_ALIAS_STR("MPATHz", "WWID0")); + mock_self_alias("MPATHz", "WWID0"); + + alias = get_user_friendly_alias("WWID0", "x", "MPATHz", "MPATH", false); + assert_string_equal(alias, "MPATHz"); + free(alias); +} + +static void gufa_old_match_used(void **state) { + char *alias; + will_return(__wrap_open_file, true); + + mock_bindings_file("MPATHz WWID0", 0); + expect_condlog(3, FOUND_ALIAS_STR("MPATHz", "WWID0")); + mock_used_alias("MPATHz", USED_STR("MPATHz", "WWID0")); + expect_condlog(0, ERR_STR("MPATHz", "WWID0")); + + alias = get_user_friendly_alias("WWID0", "x", "MPATHz", "MPATH", false); + assert_ptr_equal(alias, NULL); +} + +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_unused_alias("MPATHz"); + + 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_nomatch_nowwidmatch_used(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_used_alias("MPATHz", USED_STR("MPATHz", "WWID0")); + expect_condlog(0, ERR_STR("MPATHz", "WWID0")); + + alias = get_user_friendly_alias("WWID0", "x", "MPATHz", "MPATH", false); + assert_ptr_equal(alias, NULL); +} + +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_empty_self), + cmocka_unit_test(gufa_old_empty_used), + cmocka_unit_test(gufa_old_match), + cmocka_unit_test(gufa_old_match_self), + cmocka_unit_test(gufa_old_match_used), + 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(gufa_old_nomatch_nowwidmatch_used), + }; + + return cmocka_run_group_tests(tests, NULL, NULL); +} + int main(void) { int ret = 0; @@ -1157,6 +1686,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 Fri Sep 1 18:02: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: 13372830 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 2B82FCA0FF4 for ; Fri, 1 Sep 2023 18:03:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693591422; 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=srho8y1i3L8K2FUOS38UJCShWy+2otN9H8uU4Uuaa+A=; b=c76wwdCbFToEjiny5ca2LNgb4/b5nQdExPFFs/sryfLXUFl/k17b43Gg+C2JK0RA96jrq/ WouEUaLDiAQ4s1m8ZCjKjStQy3KsKvwOvpbE8o8eeXQYpJKODr7JrHIwUh9Xfs9ZNfUZ/h rYnpF7TKIeTk6YXAjfwRgRIeA+GxVUU= 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-128-fndhjUTjPPi-buoK19rg3w-1; Fri, 01 Sep 2023 14:03:39 -0400 X-MC-Unique: fndhjUTjPPi-buoK19rg3w-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9422629AB419; Fri, 1 Sep 2023 18:03: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 7D3906B5AA; Fri, 1 Sep 2023 18:03:28 +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 4DA4A19472A5; Fri, 1 Sep 2023 18:03:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id AC42A1946A46 for ; Fri, 1 Sep 2023 18:03:24 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 9F4221402C0A; Fri, 1 Sep 2023 18:03:24 +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 9736C1460FF4 for ; Fri, 1 Sep 2023 18:03:24 +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 7936E897F57 for ; Fri, 1 Sep 2023 18:03: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-42-jp3CZftyO3ymx-peYEmr-w-1; Fri, 01 Sep 2023 14:03:20 -0400 X-MC-Unique: jp3CZftyO3ymx-peYEmr-w-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 20D321F853; Fri, 1 Sep 2023 18:03: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 DC00713582; Fri, 1 Sep 2023 18:03:18 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id sCRIM2Yn8mTpRQAAMHmgww (envelope-from ); Fri, 01 Sep 2023 18:03:18 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 1 Sep 2023 20:02:21 +0200 Message-ID: <20230901180235.23980-9-mwilck@suse.com> In-Reply-To: <20230901180235.23980-1-mwilck@suse.com> References: <20230901180235.23980-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.7 Subject: [dm-devel] [PATCH 08/21] 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.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: suse.com From: Martin Wilck Used 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 e2372d1..1c9903c 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 Fri Sep 1 18:02: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: 13372815 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 1B9B6CA0FF1 for ; Fri, 1 Sep 2023 18:03:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693591412; 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=2fDgDawuyYtHr8NthhdK4720jrqPltdYvBNVzIBCol8=; b=QtrLYBE71qjY+mcNBRyW4Tk3Spr9OQfTiKq5WhkFJVp9Q8ZS3DVLW5ysGgKXcNNuxlYxAy Q0XAYqyNhghhqKF25EOf3F1NYAd173mrBWvkb/hRwUJCGhGdfIVuaes+JLEpfqAxo8qxbu ZgW9JDhnZeexcZ7Ya5SBo2SQoF3E8oc= 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-678-LKLA8k1LNpmyTGvoJ3rBrA-1; Fri, 01 Sep 2023 14:03:27 -0400 X-MC-Unique: LKLA8k1LNpmyTGvoJ3rBrA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C7ABC29ABA2B; Fri, 1 Sep 2023 18:03: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 B293E4069775; Fri, 1 Sep 2023 18:03: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 9BF94194729A; Fri, 1 Sep 2023 18:03:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 4C8141947299 for ; Fri, 1 Sep 2023 18:03:23 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 3B40957783B; Fri, 1 Sep 2023 18:03: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 3343C493110 for ; Fri, 1 Sep 2023 18:03:23 +0000 (UTC) Received: from us-smtp-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 1142A29ABA2E for ; Fri, 1 Sep 2023 18:03: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-25-6W-K2raEPfSbYdJuiHzAPQ-1; Fri, 01 Sep 2023 14:03:21 -0400 X-MC-Unique: 6W-K2raEPfSbYdJuiHzAPQ-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 95FF51F86C; Fri, 1 Sep 2023 18:03: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 2E3CA13582; Fri, 1 Sep 2023 18:03:19 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id yIa2CWcn8mTpRQAAMHmgww (envelope-from ); Fri, 01 Sep 2023 18:03:19 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 1 Sep 2023 20:02:22 +0200 Message-ID: <20230901180235.23980-10-mwilck@suse.com> In-Reply-To: <20230901180235.23980-1-mwilck@suse.com> References: <20230901180235.23980-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.9 Subject: [dm-devel] [PATCH 09/21] 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.1 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 | 98 +++++++++++++++++++++++++-------------------------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/tests/alias.c b/tests/alias.c index 1c9903c..cb6695b 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"); @@ -1434,7 +1434,7 @@ static void gufa_old_empty_used(void **state) { will_return(__wrap_fgets, NULL); expect_condlog(3, NOMATCH_WWID_STR("WWID0")); - mock_used_alias("MPATHz", USED_STR("MPATHz", "WWID0")); + mock_used_alias("MPATHz", "WWID0"); expect_condlog(0, ERR_STR("MPATHz", "WWID0")); alias = get_user_friendly_alias("WWID0", "x", "MPATHz", "MPATH", false); @@ -1475,7 +1475,7 @@ static void gufa_old_match_used(void **state) { mock_bindings_file("MPATHz WWID0", 0); expect_condlog(3, FOUND_ALIAS_STR("MPATHz", "WWID0")); - mock_used_alias("MPATHz", USED_STR("MPATHz", "WWID0")); + mock_used_alias("MPATHz", "WWID0"); expect_condlog(0, ERR_STR("MPATHz", "WWID0")); alias = get_user_friendly_alias("WWID0", "x", "MPATHz", "MPATH", false); @@ -1514,7 +1514,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"); @@ -1557,7 +1557,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); @@ -1592,7 +1592,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); @@ -1632,7 +1632,7 @@ static void gufa_old_nomatch_nowwidmatch_used(void **state) { mock_bindings_file(bindings, -1); expect_condlog(3, NOMATCH_WWID_STR("WWID0")); - mock_used_alias("MPATHz", USED_STR("MPATHz", "WWID0")); + mock_used_alias("MPATHz", "WWID0"); expect_condlog(0, ERR_STR("MPATHz", "WWID0")); alias = get_user_friendly_alias("WWID0", "x", "MPATHz", "MPATH", false); From patchwork Fri Sep 1 18:02: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: 13372826 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 33988CA0FF6 for ; Fri, 1 Sep 2023 18:03:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693591417; 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=+UszuFFDYYvIjxgu3hJufd1CRmw9A3jyOkAh066l3eQ=; b=RRAgd6diOitq0KNESC8yDQsQ/3dNd9VOr5iisJI/wMvAL6wyIW+dF6itImNkKhjqYfkofs oIqSf2VE2nMmn+WhIKglkHj1x5Og8Sh0sYRP5tQsmIYWnhVrIo0er6x/LtHy9vaEZdcUoR uqQVJbuRthElKdvMXPvNbH3MDjNw19U= 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-149-injVzbcWMlad-ZVfCWimGg-1; Fri, 01 Sep 2023 14:03:32 -0400 X-MC-Unique: injVzbcWMlad-ZVfCWimGg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 26A0B92AD06; Fri, 1 Sep 2023 18:03: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 13C1D83B7A; Fri, 1 Sep 2023 18:03:28 +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 AEDF319465B7; Fri, 1 Sep 2023 18:03:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id E72AC1947299 for ; Fri, 1 Sep 2023 18:03:23 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id D8DABD4781A; Fri, 1 Sep 2023 18:03:23 +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 D121DD47819 for ; Fri, 1 Sep 2023 18:03:23 +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 B2E8B1817936 for ; Fri, 1 Sep 2023 18:03: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-408-mXd7xGT5OsuzploK8TQBzQ-1; Fri, 01 Sep 2023 14:03:22 -0400 X-MC-Unique: mXd7xGT5OsuzploK8TQBzQ-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 E50BD1F45E; Fri, 1 Sep 2023 18:03: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 A702913582; Fri, 1 Sep 2023 18:03:19 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id QMf0Jmcn8mTpRQAAMHmgww (envelope-from ); Fri, 01 Sep 2023 18:03:19 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 1 Sep 2023 20:02:23 +0200 Message-ID: <20230901180235.23980-11-mwilck@suse.com> In-Reply-To: <20230901180235.23980-1-mwilck@suse.com> References: <20230901180235.23980-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.8 Subject: [dm-devel] [PATCH 10/21] 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.5 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 | 186 ++++++++++++++++++++++---------------------------- 1 file changed, 80 insertions(+), 106 deletions(-) diff --git a/tests/alias.c b/tests/alias.c index cb6695b..a1415c6 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_unused_alias("MPATHz"); @@ -1410,10 +1384,10 @@ static void gufa_old_empty_self(void **state) { char *alias; will_return(__wrap_open_file, true); - will_return(__wrap_fgets, NULL); + mock_bindings_file("", -1); expect_condlog(3, NOMATCH_STR("MPATHz")); - will_return(__wrap_fgets, NULL); + mock_bindings_file("", -1); expect_condlog(3, NOMATCH_WWID_STR("WWID0")); mock_self_alias("MPATHz", "WWID0"); @@ -1429,10 +1403,10 @@ static void gufa_old_empty_used(void **state) { char *alias; will_return(__wrap_open_file, true); - will_return(__wrap_fgets, NULL); + mock_bindings_file("", -1); expect_condlog(3, NOMATCH_STR("MPATHz")); - will_return(__wrap_fgets, NULL); + mock_bindings_file("", -1); expect_condlog(3, NOMATCH_WWID_STR("WWID0")); mock_used_alias("MPATHz", "WWID0"); expect_condlog(0, ERR_STR("MPATHz", "WWID0")); From patchwork Fri Sep 1 18:02: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: 13372823 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 D5ADDCA0FF0 for ; Fri, 1 Sep 2023 18:03:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693591417; 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=YFKpZsaMrrry+dB/4K+Ejef/djd+IojWD5GsG/xqZHA=; b=F+cuI5OKGTYpCBqpX9UIO7Ft8u8bePoK7dx5Yr5hcCYhTEmvID6zoMwywnCsEG7qNcfJ6N ktG1uNaZ6qBuz+QqndWzgl2GTBE02DEaIgA7hM4dluDIYtM1g2g9I8YPMZtom86dLFTSPg an2NJB2hChUiFrJlA/siA2B+si96wFY= 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-115-jmQWk_ELOBOiJIG8jcegWw-1; Fri, 01 Sep 2023 14:03:32 -0400 X-MC-Unique: jmQWk_ELOBOiJIG8jcegWw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E849F92AD02; Fri, 1 Sep 2023 18:03: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 D690E200BA73; Fri, 1 Sep 2023 18:03: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 82D4F19472A0; Fri, 1 Sep 2023 18:03:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 9303919465B7 for ; Fri, 1 Sep 2023 18:03:23 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 845A31208F6E; Fri, 1 Sep 2023 18:03:23 +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 7D0111055466 for ; Fri, 1 Sep 2023 18:03:23 +0000 (UTC) Received: from us-smtp-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 6176A8030A9 for ; Fri, 1 Sep 2023 18:03: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-57-6hkNg2r2N-uDJZNNnjxmXw-1; Fri, 01 Sep 2023 14:03:21 -0400 X-MC-Unique: 6hkNg2r2N-uDJZNNnjxmXw-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 2B22D1F88D; Fri, 1 Sep 2023 18:03: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 EFF7313582; Fri, 1 Sep 2023 18:03:19 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id sEr0OGcn8mTpRQAAMHmgww (envelope-from ); Fri, 01 Sep 2023 18:03:19 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 1 Sep 2023 20:02:24 +0200 Message-ID: <20230901180235.23980-12-mwilck@suse.com> In-Reply-To: <20230901180235.23980-1-mwilck@suse.com> References: <20230901180235.23980-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.3 Subject: [dm-devel] [PATCH 11/21] 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.4 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 e61eb91..0759643 100644 --- a/libmultipath/alias.c +++ b/libmultipath/alias.c @@ -522,6 +522,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) { @@ -533,6 +534,11 @@ static void free_bindings(Bindings *bindings) vector_reset(bindings); } +void cleanup_bindings(void) +{ + free_bindings(&global_bindings); +} + enum { BINDING_EXISTS, BINDING_CONFLICT, @@ -762,7 +768,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"); @@ -782,6 +787,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 Fri Sep 1 18:02: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: 13372819 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 17207CA0FF1 for ; Fri, 1 Sep 2023 18:03:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693591416; 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=b30aCv+od6oc4QWeGM0DL+CjKsa37c46bEXcZYxezII=; b=IJwsij+550faKwe6rnCdWA09z1S3T+TsKZEShMIMNd8i4M9/WI7dTp79KQja6eYRIQ2B+8 4pSiXIMCo7rWLtWqLcLx0AmzIvw/KJPUcw/7iGm/WdfcOeoyL24owiAf6bnNjx0yYaF6CB X53+ZF0/F3FjmBff7OjZ8sriXKlVJK8= 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-106-OfivhjS1P16QXp3hXbN47w-1; Fri, 01 Sep 2023 14:03:33 -0400 X-MC-Unique: OfivhjS1P16QXp3hXbN47w-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EA7B529ABA29; Fri, 1 Sep 2023 18:03: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 D93E5200A86A; Fri, 1 Sep 2023 18:03: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 C9C771946A46; Fri, 1 Sep 2023 18:03:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 97A4C1946A46 for ; Fri, 1 Sep 2023 18:03:23 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 79371493112; Fri, 1 Sep 2023 18:03:23 +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 71D2F493110 for ; Fri, 1 Sep 2023 18:03:23 +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 465F11C18C9C for ; Fri, 1 Sep 2023 18:03: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-675-SJ46c_L7O36nISugTqCtdg-1; Fri, 01 Sep 2023 14:03:21 -0400 X-MC-Unique: SJ46c_L7O36nISugTqCtdg-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 6361A1F891; Fri, 1 Sep 2023 18:03: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 366E713582; Fri, 1 Sep 2023 18:03:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ONm1C2gn8mTpRQAAMHmgww (envelope-from ); Fri, 01 Sep 2023 18:03:20 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 1 Sep 2023 20:02:25 +0200 Message-ID: <20230901180235.23980-13-mwilck@suse.com> In-Reply-To: <20230901180235.23980-1-mwilck@suse.com> References: <20230901180235.23980-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.9 Subject: [dm-devel] [PATCH 12/21] 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.6 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 0759643..af2f647 100644 --- a/libmultipath/alias.c +++ b/libmultipath/alias.c @@ -606,8 +606,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; @@ -777,7 +777,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 Fri Sep 1 18:02: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: 13372825 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 68BEACA0FEF for ; Fri, 1 Sep 2023 18:03:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693591418; 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=92axBFeIvhVWESC5HXFNr2wHy1c50hgAOsa/38egEHo=; b=dLZp5xjPp9pbCzQt/nt5ANwBnSbjNvZAkQG5lY4xIiTmddNaN9LiEj3/vVP/uZKDndHRG/ TzEVb9PztsUeq47uHV1IKoFIfcf3x8ar/E0BdwD5VcViCJ3gj66JHMHfEcPeraJZsIf5Zb jZGron9jr5svtxLHF2bRDg7lKwUYvc4= 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-146-dgE1XPMJNIGeQZA5XRVTgw-1; Fri, 01 Sep 2023 14:03:36 -0400 X-MC-Unique: dgE1XPMJNIGeQZA5XRVTgw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A51F4897F57; Fri, 1 Sep 2023 18:03: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 922AF400E13E; Fri, 1 Sep 2023 18:03: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 2ACCB19472A9; Fri, 1 Sep 2023 18:03:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id CC57B1947299 for ; Fri, 1 Sep 2023 18:03:25 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id BF2181460FE7; Fri, 1 Sep 2023 18:03:25 +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 B86311402C0A for ; Fri, 1 Sep 2023 18:03: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 9EA7E3C0EAB7 for ; Fri, 1 Sep 2023 18:03: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-620-cABI4_ioNTO4BJe6hCc5vQ-1; Fri, 01 Sep 2023 14:03:22 -0400 X-MC-Unique: cABI4_ioNTO4BJe6hCc5vQ-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 AB21921862; Fri, 1 Sep 2023 18:03: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 70F7613582; Fri, 1 Sep 2023 18:03:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id WIi6GWgn8mTpRQAAMHmgww (envelope-from ); Fri, 01 Sep 2023 18:03:20 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 1 Sep 2023 20:02:26 +0200 Message-ID: <20230901180235.23980-14-mwilck@suse.com> In-Reply-To: <20230901180235.23980-1-mwilck@suse.com> References: <20230901180235.23980-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.7 Subject: [dm-devel] [PATCH 13/21] 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 af2f647..5a6cdee 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) { @@ -505,25 +625,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; @@ -539,106 +640,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 Fri Sep 1 18:02: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: 13372820 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 17246CA0FF4 for ; Fri, 1 Sep 2023 18:03:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693591416; 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=tt5z/D697IfPXT/pZGGVYSA0oh7reM8CMYI5wNBtI9c=; b=fPOk90M1JM9AlCAlTn+S0t2zRaJATjAalInd0qlNKnRoJIYtI8+4I2+hDSHbTEFOIhvZdg ZrJWACxzD7KSEuhBxhZuP7ZzgpFP1EkBkDy5R5CZ16udWtq3vu1ek0bI9edj6cEIaoWnIy 9SS0CAOwsjjvH4dOBsIk7Mbm8LCO50M= 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-106-RDSBEvJfPryt-t7QlVFrHA-1; Fri, 01 Sep 2023 14:03:32 -0400 X-MC-Unique: RDSBEvJfPryt-t7QlVFrHA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9947C3C0EAB7; Fri, 1 Sep 2023 18:03: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 87A1963F7A; Fri, 1 Sep 2023 18:03: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 75DD51946A46; Fri, 1 Sep 2023 18:03:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 7610F194729A for ; Fri, 1 Sep 2023 18:03:25 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 64156D4781B; Fri, 1 Sep 2023 18:03: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 5C774D4781A for ; Fri, 1 Sep 2023 18:03:25 +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 E903A89F4FD for ; Fri, 1 Sep 2023 18:03: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-281-RSj63q7LM5yIni8C9u1apw-1; Fri, 01 Sep 2023 14:03:22 -0400 X-MC-Unique: RSj63q7LM5yIni8C9u1apw-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 E9D651F74D; Fri, 1 Sep 2023 18:03: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 B6DC713582; Fri, 1 Sep 2023 18:03:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id GNj9Kmgn8mTpRQAAMHmgww (envelope-from ); Fri, 01 Sep 2023 18:03:20 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 1 Sep 2023 20:02:27 +0200 Message-ID: <20230901180235.23980-15-mwilck@suse.com> In-Reply-To: <20230901180235.23980-1-mwilck@suse.com> References: <20230901180235.23980-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.8 Subject: [dm-devel] [PATCH 14/21] 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.5 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 5a6cdee..76d852f 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; } @@ -778,7 +778,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 Fri Sep 1 18:02: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: 13372827 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 E4029CA0FF2 for ; Fri, 1 Sep 2023 18:03:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693591420; 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=5jUVfb5NKJ8vAqjHPU9r4h8vic+woTPvMXO7Sem7d+M=; b=DpXyQ34Bln9Wn5zlDAzxcJ1IIv3VXHkY82HCqHgXq191wmm6jZD4NWJDH53pXp8A1Lkea4 qpRWH0NbnWpNFr8P+0stDhJA+RjxB78CN2pzS6xuz4jjTdwOxPe8xqHDOLJr10bFZXSt+I gvta00+JmkJOP533sxIbL27YuCbyx0k= 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-608-joDScYM9NiO3OipJBQ7gqA-1; Fri, 01 Sep 2023 14:03:33 -0400 X-MC-Unique: joDScYM9NiO3OipJBQ7gqA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C7FAA381DC8A; Fri, 1 Sep 2023 18:03: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 B6F52D47819; Fri, 1 Sep 2023 18:03: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 55D5719472B0; Fri, 1 Sep 2023 18:03: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 1C6FF1947299 for ; Fri, 1 Sep 2023 18:03:26 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 0CFB22026D0E; Fri, 1 Sep 2023 18:03: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 0565B200BA73 for ; Fri, 1 Sep 2023 18:03: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 DA6C090A7E5 for ; Fri, 1 Sep 2023 18:03: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-564-IeUaPCY9OASTO0DazN4j8w-1; Fri, 01 Sep 2023 14:03:22 -0400 X-MC-Unique: IeUaPCY9OASTO0DazN4j8w-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 30DD0211CE; Fri, 1 Sep 2023 18:03: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 0295713582; Fri, 1 Sep 2023 18:03:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id SC1QOmgn8mTpRQAAMHmgww (envelope-from ); Fri, 01 Sep 2023 18:03:20 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 1 Sep 2023 20:02:28 +0200 Message-ID: <20230901180235.23980-16-mwilck@suse.com> In-Reply-To: <20230901180235.23980-1-mwilck@suse.com> References: <20230901180235.23980-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 15/21] 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.8 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 76d852f..c26f37c 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 Fri Sep 1 18:02: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: 13372817 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 AD524CA0FF0 for ; Fri, 1 Sep 2023 18:03:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693591414; 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=SaBpfWFkDEzDhRnKlgnpdKVp92ZUILDMQMHmpwfQo7E=; b=MSZWv/rBtJf1NWDfb1rCqH4VkCHCtYt1Mrh+sqAyYZ5jRWDk0USAsMNRuAJ+LzMAqbUo3I 3iHhO53Rmb7wz99p6I1+oNnl4e/wzouamNM5nwwSl4hLbtHydPtKE8voJfEuvS8VXwVgJc m5Mqr21iuCywUFe9Bv/0byc2Kf3Ljo4= 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-307-XLsEAq8KN1uO6pFJMFdIkQ-1; Fri, 01 Sep 2023 14:03:33 -0400 X-MC-Unique: XLsEAq8KN1uO6pFJMFdIkQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B95DF90A7E6; Fri, 1 Sep 2023 18:03: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 A496240EEB42; Fri, 1 Sep 2023 18:03:28 +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 7CC24194729D; Fri, 1 Sep 2023 18:03:28 +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 CB7E919465B7 for ; Fri, 1 Sep 2023 18:03:26 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id BC5F321D4F3D; Fri, 1 Sep 2023 18:03: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 B483521D4F3E for ; Fri, 1 Sep 2023 18:03:26 +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 98E3C1051048 for ; Fri, 1 Sep 2023 18:03: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-267-H2e-Uqa8N-ON72NpJDCKfA-1; Fri, 01 Sep 2023 14:03:23 -0400 X-MC-Unique: H2e-Uqa8N-ON72NpJDCKfA-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 743F51F894; Fri, 1 Sep 2023 18:03: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 3CBE013582; Fri, 1 Sep 2023 18:03:21 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id YLUjDWkn8mTpRQAAMHmgww (envelope-from ); Fri, 01 Sep 2023 18:03:21 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 1 Sep 2023 20:02:29 +0200 Message-ID: <20230901180235.23980-17-mwilck@suse.com> In-Reply-To: <20230901180235.23980-1-mwilck@suse.com> References: <20230901180235.23980-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 16/21] 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.1 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 uses, 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 c26f37c..9ca5da8 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 Fri Sep 1 18:02: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: 13372822 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 CC360CA0FF3 for ; Fri, 1 Sep 2023 18:03:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693591416; 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=8vDcUikOh1VAwLWn1WRHLbzQ5JwCFd4DAXWO1ZJ8yYs=; b=bsAfHLDjP2A3kl+t/etiwcDHPDjBjj1sVE5kBCedypmFkouZif9p/PminKEYGSmruEj/kH ldxqHNOpcxPVvQ6cUE9dgDow87dVr+/W8nIVWAAIJ30pBYsYSpExNSfSinALJsDK0eGvKs j+VETZtStdbOKxAQwexF/egWcZY11HY= 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-354-cETJWyV7O0mL8P5t8eTSEg-1; Fri, 01 Sep 2023 14:03:33 -0400 X-MC-Unique: cETJWyV7O0mL8P5t8eTSEg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 46E9729DD997; Fri, 1 Sep 2023 18:03: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 34D8F1460FF2; Fri, 1 Sep 2023 18:03: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 0347F1946A46; Fri, 1 Sep 2023 18:03:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 96E8519465B7 for ; Fri, 1 Sep 2023 18:03:24 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 87A0FD4781A; Fri, 1 Sep 2023 18:03:24 +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 805E4D47819 for ; Fri, 1 Sep 2023 18:03:24 +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 671AA1817908 for ; Fri, 1 Sep 2023 18:03: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-682-6E5dRmv6PWCJ0612dE065g-1; Fri, 01 Sep 2023 14:03:22 -0400 X-MC-Unique: 6E5dRmv6PWCJ0612dE065g-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 AD53121865; Fri, 1 Sep 2023 18:03: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 7EB0813582; Fri, 1 Sep 2023 18:03:21 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 2LhRHWkn8mTpRQAAMHmgww (envelope-from ); Fri, 01 Sep 2023 18:03:21 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 1 Sep 2023 20:02:30 +0200 Message-ID: <20230901180235.23980-18-mwilck@suse.com> In-Reply-To: <20230901180235.23980-1-mwilck@suse.com> References: <20230901180235.23980-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.8 Subject: [dm-devel] [PATCH 17/21] 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.7 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 9ca5da8..2f9bc82 100644 --- a/libmultipath/alias.c +++ b/libmultipath/alias.c @@ -647,6 +647,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) { @@ -658,27 +695,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 Fri Sep 1 18:02: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: 13372818 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 147ECCA0FF2 for ; Fri, 1 Sep 2023 18:03:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693591415; 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=x9I9BB5Rgy4925UuRQR/eDlHMh5kijrzpA+d2NBh/Ww=; b=du0HLKJHISJiYV5tgO73OjjEJemZiqHcvGJbrvN2NiBenFGw1l+GA9B/MFMdKgR76t6Te9 vZKyFzRniGu/3QbT+xBXGt9dldEQTCd00/u7Px20FfjpQ4o7TrZ8vuPX7R/KjCc9OeAS8C 0+H5q4H92rCAnc7GVmqQpTMDggPI5/Q= 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-113-Hr3wAwPeNImE_o9aO5Avow-1; Fri, 01 Sep 2023 14:03:32 -0400 X-MC-Unique: Hr3wAwPeNImE_o9aO5Avow-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 725C990A7FF; Fri, 1 Sep 2023 18:03: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 5AAE5493111; Fri, 1 Sep 2023 18:03:28 +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 16D8E19472B4; Fri, 1 Sep 2023 18:03:28 +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 27D5719472A5 for ; Fri, 1 Sep 2023 18:03:27 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 18DF421EE561; Fri, 1 Sep 2023 18:03: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 10CF821EE560 for ; Fri, 1 Sep 2023 18:03:27 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.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 E71D41051048 for ; Fri, 1 Sep 2023 18:03: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-196-B31wUMSjO7i4MGIQJaZ3hg-1; Fri, 01 Sep 2023 14:03:23 -0400 X-MC-Unique: B31wUMSjO7i4MGIQJaZ3hg-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 00CF91F853; Fri, 1 Sep 2023 18:03: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 BF9DB13582; Fri, 1 Sep 2023 18:03:21 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id AO/ZLGkn8mTpRQAAMHmgww (envelope-from ); Fri, 01 Sep 2023 18:03:21 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 1 Sep 2023 20:02:31 +0200 Message-ID: <20230901180235.23980-19-mwilck@suse.com> In-Reply-To: <20230901180235.23980-1-mwilck@suse.com> References: <20230901180235.23980-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 18/21] 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.10 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 --- libmultipath/alias.c | 369 ++++++++++++++++----------------------- libmultipath/alias.h | 2 +- libmultipath/configure.c | 3 +- 3 files changed, 157 insertions(+), 217 deletions(-) diff --git a/libmultipath/alias.c b/libmultipath/alias.c index 2f9bc82..6003df0 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,63 +400,16 @@ 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; if (id <= 0) { @@ -460,29 +422,22 @@ 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'; @@ -491,144 +446,130 @@ allocate_binding(int fd, const char *wwid, int id, const char *prefix) 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 + * - U: old alias is used + * + * | No | O | A | W | U | 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 | n | add binding for old alias | old_nomatch_nowwidmatch | + * | 4 | y | n | n | y | error, no alias (can't add entry) | old_nomatch_nowwidmatch_used | + * | 5 | y | n | y | - | use alias from bindings (avoid duplicates) | old_nomatch_wwidmatch | + * | 6 | y | y | n | - | [ impossible ] | - | + * | 7 | y | y | y | n | use old alias == alias from bindings | old_match | + * | 8 | y | y | y | y | error, no alias (would be duplicate) | old_match_used | + * | 9 | y | X | n | - | get new alias | old_match_other | + * | 10 | 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. + */ + 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; + bool old_alias_taken = false; + 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)) { if (!alias_already_taken(alias_old, wwid)) alias = strdup(alias_old); else condlog(0, "ERROR: old alias [%s] for wwid [%s] is used by other map", alias_old, wwid); 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. - */ - 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; - } - /* allocate the existing alias in the bindings file */ - id = scan_devname(alias_old, prefix); - if (id > 0 && id_already_taken(id, prefix, wwid)) { + if (alias_already_taken(alias_old, wwid)) { condlog(0, "ERROR: old alias [%s] for wwid [%s] is used by other map", alias_old, wwid); + old_alias_taken = true; + } else + 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; } -new_alias: - if (id <= 0) { + /* + * old_alias_taken means that the WWID is not in the bindings file, but + * alias_old is currently taken by a different WWID. We shouldn't added + * a new binding in this case. + */ + if (id <= 0 && !old_alias_taken) { /* * 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->alias, 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 Fri Sep 1 18:02: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: 13372829 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 33CD0CA0FF8 for ; Fri, 1 Sep 2023 18:03:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693591417; 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=rX/9+zlHiKQxX3TSvkiiIPohUs5sconFfq67hok+1UA=; b=bwO4UsIDbHLcCnHkJabASxDbKRlrJovdhLj4RbiSQZyT2DgmM04PFV1QhmQOOus8EnYkBA VhhPM2i9pvpDzqFHBJPOxWtbxLG4VGyEyCNv9lg9LttEL02gnXGd+FGDW+/VmO2G7yYelC c6bxxFFjoo5YmtC8R+uGiA3dLe8V7iM= 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-198-fOmODNHaMbOCkj41I6iMEQ-1; Fri, 01 Sep 2023 14:03:33 -0400 X-MC-Unique: fOmODNHaMbOCkj41I6iMEQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4DD6F8A2D07; Fri, 1 Sep 2023 18:03: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 354632017E87; Fri, 1 Sep 2023 18:03:28 +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 D934519472BB; Fri, 1 Sep 2023 18:03:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 4A4A019465B7 for ; Fri, 1 Sep 2023 18:03:26 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 2AEC81460FE7; Fri, 1 Sep 2023 18:03:26 +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 223661402C0A for ; Fri, 1 Sep 2023 18:03: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 EF277917E7C for ; Fri, 1 Sep 2023 18:03: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-320-JXQuBuwtOAO2AwV3ifpUQg-1; Fri, 01 Sep 2023 14:03:23 -0400 X-MC-Unique: JXQuBuwtOAO2AwV3ifpUQg-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 57EEA1F86C; Fri, 1 Sep 2023 18:03: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 132C513582; Fri, 1 Sep 2023 18:03:22 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 6OkbA2on8mTpRQAAMHmgww (envelope-from ); Fri, 01 Sep 2023 18:03:22 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 1 Sep 2023 20:02:32 +0200 Message-ID: <20230901180235.23980-20-mwilck@suse.com> In-Reply-To: <20230901180235.23980-1-mwilck@suse.com> References: <20230901180235.23980-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.7 Subject: [dm-devel] [PATCH 19/21] 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 --- tests/alias.c | 1013 +++++++++++++++++++++++++++++++------------------ 1 file changed, 638 insertions(+), 375 deletions(-) diff --git a/tests/alias.c b/tests/alias.c index a1415c6..4ac6425 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; + 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,71 +1349,137 @@ 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")); - mock_allocate_binding("MPATHa", "WWID0"); + alias = get_user_friendly_alias("WWID0", "x", "", "MPATH", false); assert_string_equal(alias, "MPATHa"); free(alias); @@ -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,34 +1613,60 @@ 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_unused_alias("MPATHz"); mock_allocate_binding("MPATHz", "WWID0"); @@ -1382,12 +1679,11 @@ static void gufa_old_empty(void **state) { static void gufa_old_empty_self(void **state) { char *alias; - will_return(__wrap_open_file, true); - mock_bindings_file("", -1); + mock_bindings_file(""); expect_condlog(3, NOMATCH_STR("MPATHz")); - mock_bindings_file("", -1); + mock_bindings_file(""); expect_condlog(3, NOMATCH_WWID_STR("WWID0")); mock_self_alias("MPATHz", "WWID0"); @@ -1401,15 +1697,14 @@ static void gufa_old_empty_self(void **state) { static void gufa_old_empty_used(void **state) { char *alias; - will_return(__wrap_open_file, true); - mock_bindings_file("", -1); + mock_bindings_file(""); expect_condlog(3, NOMATCH_STR("MPATHz")); - mock_bindings_file("", -1); - expect_condlog(3, NOMATCH_WWID_STR("WWID0")); + mock_bindings_file(""); mock_used_alias("MPATHz", "WWID0"); expect_condlog(0, ERR_STR("MPATHz", "WWID0")); + expect_condlog(3, NOMATCH_WWID_STR("WWID0")); alias = get_user_friendly_alias("WWID0", "x", "MPATHz", "MPATH", false); assert_ptr_equal(alias, NULL); @@ -1417,11 +1712,9 @@ static void gufa_old_empty_used(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")); mock_unused_alias("MPATHz"); @@ -1432,9 +1725,8 @@ static void gufa_old_match(void **state) { static void gufa_old_match_self(void **state) { char *alias; - will_return(__wrap_open_file, true); - mock_bindings_file("MPATHz WWID0", 0); + mock_bindings_file("MPATHz WWID0"); expect_condlog(3, FOUND_ALIAS_STR("MPATHz", "WWID0")); mock_self_alias("MPATHz", "WWID0"); @@ -1445,9 +1737,8 @@ static void gufa_old_match_self(void **state) { static void gufa_old_match_used(void **state) { char *alias; - will_return(__wrap_open_file, true); - mock_bindings_file("MPATHz WWID0", 0); + mock_bindings_file("MPATHz WWID0"); expect_condlog(3, FOUND_ALIAS_STR("MPATHz", "WWID0")); mock_used_alias("MPATHz", "WWID0"); expect_condlog(0, ERR_STR("MPATHz", "WWID0")); @@ -1458,19 +1749,15 @@ static void gufa_old_match_used(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"); @@ -1479,21 +1766,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); @@ -1503,15 +1785,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"); @@ -1523,13 +1803,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"); @@ -1541,12 +1817,9 @@ 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); + mock_unused_alias("MPATHz"); 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")); @@ -1559,12 +1832,10 @@ 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); + mock_unused_alias("MPATHz"); expect_condlog(3, NOMATCH_STR("MPATHz")); - - mock_bindings_file(bindings, 0); expect_condlog(3, FOUND_STR("MPATHa", "WWID0")); mock_used_alias("MPATHa", "WWID0"); @@ -1574,19 +1845,14 @@ 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_unused_alias("MPATHz"); - 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); @@ -1598,16 +1864,12 @@ static void gufa_old_nomatch_nowwidmatch_used(void **state) { char *alias; static const char bindings[] = "MPATHb WWID1"; - 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_used_alias("MPATHz", "WWID0"); expect_condlog(0, ERR_STR("MPATHz", "WWID0")); + expect_condlog(3, NOMATCH_WWID_STR("WWID0")); alias = get_user_friendly_alias("WWID0", "x", "MPATHz", "MPATH", false); assert_ptr_equal(alias, NULL); @@ -1616,31 +1878,33 @@ static void gufa_old_nomatch_nowwidmatch_used(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_empty_self), - cmocka_unit_test(gufa_old_empty_used), - cmocka_unit_test(gufa_old_match), - cmocka_unit_test(gufa_old_match_self), - cmocka_unit_test(gufa_old_match_used), - 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(gufa_old_nomatch_nowwidmatch_used), + 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_empty_self, teardown_bindings), + cmocka_unit_test_teardown(gufa_old_empty_used, teardown_bindings), + cmocka_unit_test_teardown(gufa_old_match, teardown_bindings), + cmocka_unit_test_teardown(gufa_old_match_self, teardown_bindings), + cmocka_unit_test_teardown(gufa_old_match_used, 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), + cmocka_unit_test_teardown(gufa_old_nomatch_nowwidmatch_used, teardown_bindings), }; return cmocka_run_group_tests(tests, NULL, NULL); @@ -1656,7 +1920,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 Fri Sep 1 18:02: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: 13372824 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 70BFCCA0FF7 for ; Fri, 1 Sep 2023 18:03:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693591418; 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=Z/cs1gcOYLai8ievTzsgbQcSzuam0RmGFv5SxocU+FI=; b=CbrGFiZntSx6jQGnDA+oKsk95EJrR+QjUY+b0JxLLJuDwNdu9VMhjFmFWoVaMUF1qvadBq gcPB+fGUxKdSMEJ3Hk0TXJbV3VV+pbMkvqiIEnWXfxF69bJfWK3OO5vGLMmKEAQJ1SuH43 qbJbNP45ubXbCRnyKqSiuvqCK1jGlWA= 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-451-dpfKINGzOkea2zoRwASMrg-1; Fri, 01 Sep 2023 14:03:35 -0400 X-MC-Unique: dpfKINGzOkea2zoRwASMrg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E14C429AB44F; Fri, 1 Sep 2023 18:03: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 CA8681208F6F; Fri, 1 Sep 2023 18:03:28 +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 A40A819472B2; Fri, 1 Sep 2023 18:03:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 6FF6319472B6 for ; Fri, 1 Sep 2023 18:03:27 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 5D4EDD4781B; Fri, 1 Sep 2023 18:03: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 56BFED4781A for ; Fri, 1 Sep 2023 18:03:27 +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 3B74092ACE1 for ; Fri, 1 Sep 2023 18:03: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-605-WRQecNqvMxi7UWK_pgfFyw-1; Fri, 01 Sep 2023 14:03:23 -0400 X-MC-Unique: WRQecNqvMxi7UWK_pgfFyw-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 918812186C; Fri, 1 Sep 2023 18:03: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 63DEA13582; Fri, 1 Sep 2023 18:03:22 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 4DmJFmon8mTpRQAAMHmgww (envelope-from ); Fri, 01 Sep 2023 18:03:22 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 1 Sep 2023 20:02:33 +0200 Message-ID: <20230901180235.23980-21-mwilck@suse.com> In-Reply-To: <20230901180235.23980-1-mwilck@suse.com> References: <20230901180235.23980-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.8 Subject: [dm-devel] [PATCH 20/21] 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 Fri Sep 1 18:02: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: 13372828 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 ACAA4CA0FF1 for ; Fri, 1 Sep 2023 18:03:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693591420; 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=PYvA9zrj7IT7SetLVrX8l1FPO9/hu/I4w1vOmnKu9K4=; b=SPU9pJBIvADqyW3U3cZ+igoIFzirudg97nvntoqYYNp4es1yyDlwsSm/gAnmMQ7eZWcqy7 UlJ3McSidHqnQOaC0WbztzKYFyXONYuDJlo7nupixxKU9Vg4t+WmfakrLhALQtIqN5xy9y N2L60AqVjEOK0CfYJ7aQWpRrQ8iM2yQ= 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-335-0-eDhyaqMfKK1sUcPVFdZQ-1; Fri, 01 Sep 2023 14:03:36 -0400 X-MC-Unique: 0-eDhyaqMfKK1sUcPVFdZQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 11C7B1051066; Fri, 1 Sep 2023 18:03: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 F12571460FE7; Fri, 1 Sep 2023 18:03:28 +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 CECC119472AB; Fri, 1 Sep 2023 18:03:28 +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 C3B6219472AC for ; Fri, 1 Sep 2023 18:03:27 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id A3B1520C3B2A; Fri, 1 Sep 2023 18:03:27 +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 9C5FA207A813 for ; Fri, 1 Sep 2023 18:03:27 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.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 81B653C0EABE for ; Fri, 1 Sep 2023 18:03: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-636-fFVdHvZwMAS2kzgJJ5g77A-1; Fri, 01 Sep 2023 14:03:24 -0400 X-MC-Unique: fFVdHvZwMAS2kzgJJ5g77A-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 DC1741F45E; Fri, 1 Sep 2023 18:03: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 9DFE413582; Fri, 1 Sep 2023 18:03:22 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id UD+1JGon8mTpRQAAMHmgww (envelope-from ); Fri, 01 Sep 2023 18:03:22 +0000 From: mwilck@suse.com To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 1 Sep 2023 20:02:34 +0200 Message-ID: <20230901180235.23980-22-mwilck@suse.com> In-Reply-To: <20230901180235.23980-1-mwilck@suse.com> References: <20230901180235.23980-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 21/21] 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.7 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 | 30 ++++++------------------------ 2 files changed, 18 insertions(+), 35 deletions(-) diff --git a/libmultipath/alias.c b/libmultipath/alias.c index 6003df0..0f5af17 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 4ac6425..4f54031 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); } @@ -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"));