From patchwork Sat Jul 13 06:04:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 13732333 X-Patchwork-Delegate: christophe.varoqui@free.fr Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5964B29428 for ; Sat, 13 Jul 2024 06:05:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720850719; cv=none; b=jznvW+0T2pRpgWMvR3f2/l/CPXaDj5pY8Kf63FcXYL3kDHDvqAIk2gnB5nGgNGBj8Gym0xbP+Vbo2Pkc474HiwNIDFmmY9Gk7yKuq6I5pJmlVZUXK4apIpK3MNXvfJC1Mts4bqEqzQXSmh+X1xyQlhhqL1BHTq7UlWDJwfOglcA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720850719; c=relaxed/simple; bh=We17LeLYHTE0WHG7s9Ywy6NHIWeIQBuq9SkxdAUUfe0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KCW7kVodwJedQaGC9FDCaMC9Efmr0g5Y9c63GbhYGQg24NkfR2wQjp2bDqb2w4ZkrzTrcUc6X6cf0bjG0sYIccTi9kaiRH0ZrKIZrOlR0qZhe31JPdi/3krF3AweTfU64Pd2KPSiuWmfXPZrxlsC0RvOd4m7qGqGL/SAdGoYfbE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=MCdgGGTs; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="MCdgGGTs" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720850716; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kP0kY/RuEaJUhM7ZjBDUaLXgmLQ467ttPzobG3bF5W4=; b=MCdgGGTsyAqsRrAfLtcpxFlqZR9Qc5lF5K8ICNqbHlt0sDOFzS0wJpFwclrAkETJ2e91Rc f877rS+oCICUKTbbBsC1/V0zPNnxW2QB6AY/nJDLn35DFKz76HwRDCSkoi5o28FXqpEi7w 0HP0EE+U7nQSCnuJ+wtj7UIq4pmufNU= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-687-9O0rKalcPPicntG6y1KYLQ-1; Sat, 13 Jul 2024 02:05:11 -0400 X-MC-Unique: 9O0rKalcPPicntG6y1KYLQ-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1DDEF195609D; Sat, 13 Jul 2024 06:05:10 +0000 (UTC) Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (bmarzins-01.fast.eng.rdu2.dc.redhat.com [10.6.23.12]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 92C2D1955F3B; Sat, 13 Jul 2024 06:05:09 +0000 (UTC) Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (localhost [127.0.0.1]) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.2/8.17.1) with ESMTPS id 46D658TR2015514 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 13 Jul 2024 02:05:08 -0400 Received: (from bmarzins@localhost) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.2/8.17.2/Submit) id 46D6587Q2015513; Sat, 13 Jul 2024 02:05:08 -0400 From: Benjamin Marzinski To: Christophe Varoqui Cc: device-mapper development , Martin Wilck Subject: [PATCH 05/22] multipathd: handle uninitialized paths in new function Date: Sat, 13 Jul 2024 02:04:49 -0400 Message-ID: <20240713060506.2015463-6-bmarzins@redhat.com> In-Reply-To: <20240713060506.2015463-1-bmarzins@redhat.com> References: <20240713060506.2015463-1-bmarzins@redhat.com> Precedence: bulk X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Pull the code to handle uninitialized paths out of check_path() and into a new function called handle_uninitialized_paths(). This should cause no functional changes. Signed-off-by: Benjamin Marzinski --- multipathd/main.c | 171 ++++++++++++++++++++++++++++------------------ 1 file changed, 105 insertions(+), 66 deletions(-) diff --git a/multipathd/main.c b/multipathd/main.c index 9b1b5226..9e329e89 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -2343,8 +2343,7 @@ check_path_state(struct path *pp) } /* - * Returns '1' if the path has been checked, '-1' if it was blacklisted - * and '0' otherwise + * Returns '1' if the path has been checked and '0' otherwise */ int check_path (struct vectors * vecs, struct path * pp, unsigned int ticks) @@ -2354,16 +2353,13 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks) int chkr_new_path_up = 0; int disable_reinstate = 0; int oldchkrstate = pp->chkrstate; - int retrigger_tries; unsigned int checkint, max_checkint; struct config *conf; int marginal_pathgroups, marginal_changed = 0; int ret; bool need_reload; - if (((pp->initialized == INIT_OK || pp->initialized == INIT_PARTIAL || - pp->initialized == INIT_REQUESTED_UDEV) && !pp->mpp) || - pp->initialized == INIT_REMOVED) + if (pp->initialized == INIT_REMOVED) return 0; if (pp->tick) @@ -2372,7 +2368,6 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks) return 0; /* don't check this path yet */ conf = get_multipath_config(); - retrigger_tries = conf->retrigger_tries; checkint = conf->checkint; max_checkint = conf->max_checkint; marginal_pathgroups = conf->marginal_pathgroups; @@ -2383,38 +2378,6 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks) pp->checkint = checkint; }; - if (!pp->mpp && pp->initialized == INIT_MISSING_UDEV) { - if (pp->retriggers < retrigger_tries) { - static const char change[] = "change"; - ssize_t ret; - - condlog(2, "%s: triggering change event to reinitialize", - pp->dev); - pp->initialized = INIT_REQUESTED_UDEV; - pp->retriggers++; - ret = sysfs_attr_set_value(pp->udev, "uevent", change, - sizeof(change) - 1); - if (ret != sizeof(change) - 1) - log_sysfs_attr_set_value(1, ret, - "%s: failed to trigger change event", - pp->dev); - return 0; - } else { - condlog(1, "%s: not initialized after %d udev retriggers", - pp->dev, retrigger_tries); - /* - * Make sure that the "add missing path" code path - * below may reinstate the path later, if it ever - * comes up again. - * The WWID needs not be cleared; if it was set, the - * state hadn't been INIT_MISSING_UDEV in the first - * place. - */ - pp->initialized = INIT_FAILED; - return 0; - } - } - /* * provision a next check soonest, * in case we exit abnormally from here @@ -2435,32 +2398,6 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks) pp->checkint = checkint; return 1; } - if (!pp->mpp) { - if (!strlen(pp->wwid) && - (pp->initialized == INIT_FAILED || - pp->initialized == INIT_NEW) && - (newstate == PATH_UP || newstate == PATH_GHOST)) { - condlog(2, "%s: add missing path", pp->dev); - conf = get_multipath_config(); - pthread_cleanup_push(put_multipath_config, conf); - ret = pathinfo(pp, conf, DI_ALL | DI_BLACKLIST); - pthread_cleanup_pop(1); - /* INIT_OK implies ret == PATHINFO_OK */ - if (pp->initialized == INIT_OK) { - ev_add_path(pp, vecs, 1); - pp->tick = 1; - } else { - if (ret == PATHINFO_SKIPPED) - return -1; - /* - * We failed multiple times to initialize this - * path properly. Don't re-check too often. - */ - pp->checkint = max_checkint; - } - } - return 0; - } /* * Async IO in flight. Keep the previous path state * and reschedule as soon as possible @@ -2679,6 +2616,104 @@ check_path (struct vectors * vecs, struct path * pp, unsigned int ticks) return 1; } +/* + * Returns -1 if the path was blacklisted, and 0 otherwise + */ +static int +handle_uninitialized_path(struct vectors * vecs, struct path * pp, + unsigned int ticks) +{ + int newstate; + int retrigger_tries; + unsigned int checkint, max_checkint; + struct config *conf; + int ret; + + if (((pp->initialized == INIT_OK || pp->initialized == INIT_PARTIAL || + pp->initialized == INIT_REQUESTED_UDEV) && !pp->mpp) || + pp->initialized == INIT_REMOVED) + return 0; + + if (pp->tick) + pp->tick -= (pp->tick > ticks) ? ticks : pp->tick; + if (pp->tick) + return 0; /* don't check this path yet */ + + conf = get_multipath_config(); + retrigger_tries = conf->retrigger_tries; + checkint = conf->checkint; + max_checkint = conf->max_checkint; + put_multipath_config(conf); + + if (!pp->mpp && pp->initialized == INIT_MISSING_UDEV) { + if (pp->retriggers < retrigger_tries) { + static const char change[] = "change"; + ssize_t ret; + + condlog(2, "%s: triggering change event to reinitialize", + pp->dev); + pp->initialized = INIT_REQUESTED_UDEV; + pp->retriggers++; + ret = sysfs_attr_set_value(pp->udev, "uevent", change, + sizeof(change) - 1); + if (ret != sizeof(change) - 1) + log_sysfs_attr_set_value(1, ret, + "%s: failed to trigger change event", + pp->dev); + return 0; + } else { + condlog(1, "%s: not initialized after %d udev retriggers", + pp->dev, retrigger_tries); + /* + * Make sure that the "add missing path" code path + * below may reinstate the path later, if it ever + * comes up again. + * The WWID needs not be cleared; if it was set, the + * state hadn't been INIT_MISSING_UDEV in the first + * place. + */ + pp->initialized = INIT_FAILED; + return 0; + } + } + + /* + * provision a next check soonest, + * in case we exit abnormally from here + */ + pp->tick = checkint; + + newstate = check_path_state(pp); + + if (!pp->mpp) { + if (!strlen(pp->wwid) && + (pp->initialized == INIT_FAILED || + pp->initialized == INIT_NEW) && + (newstate == PATH_UP || newstate == PATH_GHOST)) { + condlog(2, "%s: add missing path", pp->dev); + conf = get_multipath_config(); + pthread_cleanup_push(put_multipath_config, conf); + ret = pathinfo(pp, conf, DI_ALL | DI_BLACKLIST); + pthread_cleanup_pop(1); + /* INIT_OK implies ret == PATHINFO_OK */ + if (pp->initialized == INIT_OK) { + ev_add_path(pp, vecs, 1); + pp->tick = 1; + } else { + if (ret == PATHINFO_SKIPPED) + return -1; + /* + * We failed multiple times to initialize this + * path properly. Don't re-check too often. + */ + pp->checkint = max_checkint; + } + } + return 0; + } + return 0; +} + enum checker_state { CHECKER_STARTING, CHECKER_RUNNING, @@ -2751,7 +2786,11 @@ checkerloop (void *ap) if (pp->is_checked) continue; pp->is_checked = true; - rc = check_path(vecs, pp, ticks); + if (pp->mpp) + rc = check_path(vecs, pp, ticks); + else + rc = handle_uninitialized_path(vecs, pp, + ticks); if (rc < 0) { condlog(1, "%s: check_path() failed, removing", pp->dev);