From patchwork Tue Oct 15 03:28:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 13835715 X-Patchwork-Delegate: bmarzins@redhat.com 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 E74841714CC for ; Tue, 15 Oct 2024 03:28:43 +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=1728962927; cv=none; b=GhX5w1CmpVzp8vZPopsuEA8pwKnK328C/3hNIkS0YZlABKTI6Br4CXyeSKrCuijWAoQVsdlVTHmfjgRDVY3VhwslVestZxIy8E51AkO+WbA0oyw/j4yJJRIE1NAQqnwcUeqj/OVJKvE+T6vZf0ibyNdbwZtI01lITwwjO9yE3Sk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728962927; c=relaxed/simple; bh=VDbE0x5886dg1Q4JogrsSN1jO4LASeBe6qliyHPK8AA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=gdvs8G4dwDGLqAlg7nDI1ZGyK4InVrr8eEznNqR705zDKJDbb+1yCY7TspSxXbEWpMosOJXguBPkY6lMFeLfqvYkDPrIE8ySLvKM6CJ2WjKhkX1yQycUFPRwMEwXVMS4qxkUGpTf6etycLmxQJmucAnHxeAol5CYhh+43EBKmEM= 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=aMcAwWr2; 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="aMcAwWr2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728962922; 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=Trk8JV6w/ZdQPRK33bjSsbgKTL9TRmdgDAwoQzFLOAY=; b=aMcAwWr2A4NqUmUbEvTcgxAZOex1lzfLkAx9XHsvjaIsOjacwVwTTN4pOX6+o02b1qLX1P 1UrYQZlxFKrtN8nlbhFW6ifI/2dc/FVSfav1CmaUMS1GPdDf4v8w3n550NBIVI+B+XTxYK XNRNquXHAC5q5kGveGCvWjUNbSoG41s= Received: from mx-prod-mc-04.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-499-4w8xBhQmPJaSRpwIyh8rUg-1; Mon, 14 Oct 2024 23:28:41 -0400 X-MC-Unique: 4w8xBhQmPJaSRpwIyh8rUg-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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7230119560AE; Tue, 15 Oct 2024 03:28:40 +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 3CB3F1956054; Tue, 15 Oct 2024 03:28:40 +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 49F3Sdvs2693371 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 14 Oct 2024 23:28:39 -0400 Received: (from bmarzins@localhost) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.2/8.17.2/Submit) id 49F3SdLF2693370; Mon, 14 Oct 2024 23:28:39 -0400 From: Benjamin Marzinski To: Christophe Varoqui Cc: device-mapper development , Martin Wilck Subject: [PATCH v5 23/23] multipathd: use timestamps to tell when the directio checker timed out Date: Mon, 14 Oct 2024 23:28:35 -0400 Message-ID: <20241015032835.2693247-24-bmarzins@redhat.com> In-Reply-To: <20241015032835.2693247-1-bmarzins@redhat.com> References: <20241015032835.2693247-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 Instead of counting the number of times the path checker has been called and treating that as the number of seconds that have passed, calculate the actual timestamp when the checker will time out, and check that instead. Signed-off-by: Benjamin Marzinski --- libmultipath/checkers/directio.c | 44 ++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/libmultipath/checkers/directio.c b/libmultipath/checkers/directio.c index 27227894..d35a6bac 100644 --- a/libmultipath/checkers/directio.c +++ b/libmultipath/checkers/directio.c @@ -60,13 +60,28 @@ const char *libcheck_msgtable[] = { #define LOG(prio, fmt, args...) condlog(prio, "directio: " fmt, ##args) struct directio_context { - unsigned int running; - int reset_flags; + time_t timeout; + int reset_flags; struct aio_group *aio_grp; struct async_req *req; bool checked_state; }; +bool is_running(struct directio_context *ct) { + return (ct->timeout != 0); +} + +void start_running(struct directio_context *ct, int timeout_secs) { + struct timespec now; + + get_monotonic_time(&now); + ct->timeout = now.tv_sec + timeout_secs; +} + +void stop_running(struct directio_context *ct) { + ct->timeout = 0; +} + static struct aio_group * add_aio_group(void) { @@ -234,9 +249,9 @@ void libcheck_free (struct checker * c) } } - if (ct->running && ct->req->state != PATH_PENDING) - ct->running = 0; - if (!ct->running) { + if (is_running(ct) && ct->req->state != PATH_PENDING) + stop_running(ct); + if (!is_running(ct)) { free(ct->req->buf); free(ct->req); ct->aio_grp->holders--; @@ -304,7 +319,7 @@ check_pending(struct directio_context *ct, struct timespec timeout) r = get_events(ct->aio_grp, &timeout); if (ct->req->state != PATH_PENDING) { - ct->running = 0; + stop_running(ct); return; } else if (r == 0 || (timeout.tv_sec == 0 && timeout.tv_nsec == 0)) @@ -330,10 +345,10 @@ check_state(int fd, struct directio_context *ct, int sync, int timeout_secs) if (sync > 0) LOG(4, "called in synchronous mode"); - if (ct->running) { + if (is_running(ct)) { ct->checked_state = true; if (ct->req->state != PATH_PENDING) { - ct->running = 0; + stop_running(ct); return ct->req->state; } } else { @@ -348,9 +363,9 @@ check_state(int fd, struct directio_context *ct, int sync, int timeout_secs) LOG(3, "io_submit error %i", -rc); return PATH_UNCHECKED; } + start_running(ct, timeout_secs); ct->checked_state = false; } - ct->running++; if (!sync) return PATH_PENDING; @@ -388,7 +403,7 @@ static void set_msgid(struct checker *c, int state) bool libcheck_need_wait(struct checker *c) { struct directio_context *ct = (struct directio_context *)c->context; - return (ct && ct->running && ct->req->state == PATH_PENDING && + return (ct && is_running(ct) && ct->req->state == PATH_PENDING && !ct->checked_state); } @@ -400,7 +415,7 @@ int libcheck_pending(struct checker *c) struct timespec no_wait = { .tv_sec = 0 }; /* The if path checker isn't running, just return the exiting value. */ - if (!ct || !ct->running) { + if (!ct || !is_running(ct)) { rc = c->path_state; goto out; } @@ -408,10 +423,13 @@ int libcheck_pending(struct checker *c) if (ct->req->state == PATH_PENDING) check_pending(ct, no_wait); else - ct->running = 0; + stop_running(ct); rc = ct->req->state; if (rc == PATH_PENDING) { - if (ct->running > c->timeout) { + struct timespec now; + + get_monotonic_time(&now); + if (now.tv_sec > ct->timeout) { LOG(3, "abort check on timeout"); io_cancel(ct->aio_grp->ioctx, &ct->req->io, &event); rc = PATH_DOWN;