From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CA2CC606A33E for ; Sun, 8 Nov 2026 20:48:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=hiGE1K91; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=O9Jp88ls DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=7IWC9iRb2iMutylTV3wTN9F4lqxXhmqki0q58tou2N0=; b=hiGE1K91i4yVEB xl3d8COBsKNTF56UNiWfrZ/YTex/EAH7hwc9xeDFBdY/+gWv4G9WTOsgbsGbx+QsZkpU55AjRfOcr 1I/WMnPKem/Ijnin+19T45M2FYTyUmbCli29gxqNe7IZa3cLy5INb6P1DESnxjDLYDefenCFcjUMj uBX2KC+rvdR9KF6w1KDvDlbKq7GJWEYNAtB5vgqplbM69h1OGOxO2BYn5n957hkmJWzPsWu5JcjdS Sze5N8/SrydoqOn9t6jBSmM9GzThv994+4a1WkSrV/6PEer+Qd+kDzYB2SDgN81MELYzr7pV3D25J 8SZk9wTUuXCgb8ppy//A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xQ9o8-0000000Gbro-298k; Sun, 08 Nov 2026 20:48:08 +0000 Received: from out-52.mta1.migadu.com ([95.215.58.52] helo=mta1.migadu.com) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xQ9o4-0000000Gbka-0i24 for linux-nvme@lists.infradead.org; Sun, 08 Nov 2026 20:48:05 +0000 X-Envelope-To: linux-nvme@lists.infradead.org DKIM-Signature: a=rsa-sha256; bh=KQ58HxN+QINzjNeXUVexzQ283FkiHEbWebIwDbAZvzE=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1794170882; v=1; x=1794775682; b=O9Jp88ls7YrQTUME0USZf7kwxEtBofr8hvDF9WCQFhEANYa8380ZX1l4/z/i9I3wSqimF7F1 NKWAFrRyHPOZ+kmRHzUp5UEOYcuwQ9h6h9jmFM8V5F8fQhd+3YdCuUwFiPNYQ27+e8zFqZq+4Cs TL0/ULmTY2DXr5hf8CH8oXZg= X-Envelope-To: linux-nvme@lists.infradead.org Received: by mta10.migadu.com with ESMTPS id 16be4bca72700676; Sun, 08 Nov 2026 20:48:02 +0000 X-Mizu-Trace-ID: 16be4bca72700676 X-Migadu-Flow: FLOW_OUT From: John Garry To: james.bottomley@hansenpartnership.com, mkp@kernel.org Cc: hare@suse.com, linux-nvme@lists.infradead.org, linux-scsi@vger.kernel.org, snitzer@kernel.org, jmeneghi@redhat.com, bmarzins@redhat.com, dm-devel@lists.linux.dev, hch@lst.de, michael.christie@oracle.com, John Garry Subject: [PATCH v9 07/29] libmultipath: Add delayed removal support Date: Sun, 8 Nov 2026 20:47:11 +0000 Message-ID: <20261108204733.557995-8-john.garry@linux.dev> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261108204733.557995-1-john.garry@linux.dev> References: <20261108204733.557995-1-john.garry@linux.dev> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261108_124804_354221_6F3DE478 X-CRM114-Status: GOOD ( 22.05 ) X-Spam-Score: -2.1 (--) X-BeenThere: linux-nvme@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-nvme" X-Spam-Status: No, score=-18.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 Add support for delayed removal, same as exists for NVMe. The purpose of this feature is to keep the multipath disk and cdev present for intermittent periods of no available path. Helpers mpath_delayed_removal_secs_show() and mpath_delayed_removal_secs_store() may be used in the driver sysfs code. The driver is responsible for supplying the removal work callback for the delayed work. Signed-off-by: John Garry --- include/linux/multipath.h | 18 ++++++++ lib/multipath.c | 91 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 108 insertions(+), 1 deletion(-) diff --git a/include/linux/multipath.h b/include/linux/multipath.h index 033ee8d54bbe..66b6ad9c2219 100644 --- a/include/linux/multipath.h +++ b/include/linux/multipath.h @@ -34,6 +34,7 @@ struct mpath_device { struct mpath_head_template { bool (*available_path)(struct mpath_device *); + void (*remove_head)(struct mpath_head *); bool (*is_disabled)(struct mpath_device *); bool (*is_optimized)(struct mpath_device *); struct bio *(*clone_bio)(struct bio *); @@ -41,6 +42,7 @@ struct mpath_head_template { }; #define MPATH_HEAD_DISK_LIVE 0 +#define MPATH_HEAD_QUEUE_IF_NO_PATH 1 struct mpath_head { struct srcu_struct srcu; @@ -58,6 +60,10 @@ struct mpath_head { atomic_long_t requeue_no_usable_path_cnt; atomic_long_t fail_no_avail_path_cnt; + struct delayed_work remove_work; + unsigned int delayed_removal_secs; + struct module *drv_module; + unsigned long flags; struct gendisk *disk; struct work_struct partition_scan_work; @@ -111,6 +117,11 @@ void mpath_remove_disk(struct mpath_head *mpath_head); int mpath_alloc_head_disk(struct mpath_head *mpath_head, struct queue_limits *lim, int numa_node); void mpath_device_set_live(struct mpath_device *mpath_device); +bool mpath_can_remove_head(struct mpath_head *mpath_head); +ssize_t mpath_delayed_removal_secs_show(struct mpath_head *mpath_head, + char *buf); +ssize_t mpath_delayed_removal_secs_store(struct mpath_head *mpath_head, + const char *buf, size_t count); static inline bool is_mpath_disk(struct gendisk *disk) { @@ -126,6 +137,13 @@ static inline bool mpath_qd_iopolicy(enum mpath_iopolicy_e *iopolicy) return READ_ONCE(*iopolicy) == MPATH_IOPOLICY_QD; } +static inline bool mpath_head_queue_if_no_path(struct mpath_head *mpath_head) +{ + if (test_bit(MPATH_HEAD_QUEUE_IF_NO_PATH, &mpath_head->flags)) + return true; + return false; +} + static inline void mpath_schedule_requeue_work(struct mpath_head *mpath_head) { kblockd_schedule_work(&mpath_head->requeue_work); diff --git a/lib/multipath.c b/lib/multipath.c index fd7821824447..cdf8fbc5105b 100644 --- a/lib/multipath.c +++ b/lib/multipath.c @@ -67,6 +67,9 @@ int mpath_add_device(struct mpath_device *mpath_device, struct gendisk *disk, list_add_tail_rcu(&mpath_device->siblings, &mpath_head->dev_list); mutex_unlock(&mpath_head->lock); + if (cancel_delayed_work(&mpath_head->remove_work)) + module_put(mpath_head->drv_module); + return 0; } EXPORT_SYMBOL_GPL(mpath_add_device); @@ -340,7 +343,16 @@ static bool mpath_available_path(struct mpath_head *mpath_head) return true; } - return false; + /* + * If "mpath_head->delayed_removal_secs" is set (i.e., non-zero), do + * not immediately fail I/O. Instead, requeue the I/O for the configured + * duration, anticipating that if there's a transient link failure then + * it may recover within this time window. This parameter is exported to + * userspace via sysfs, and its default value is zero. It is internally + * mapped to MPATH_HEAD_QUEUE_IF_NO_PATH. When delayed_removal_secs is + * non-zero, this flag is set to true. When zero, the flag is cleared. + */ + return mpath_head_queue_if_no_path(mpath_head); } static void mpath_bdev_submit_bio(struct bio *bio) @@ -482,6 +494,39 @@ static void mpath_requeue_work(struct work_struct *work) } } +bool mpath_can_remove_head(struct mpath_head *mpath_head) +{ + unsigned long delay; + bool remove = false; + + mutex_lock(&mpath_head->lock); + /* + * Ensure that no one could remove this module while the head + * remove work is pending. + */ + if (mpath_head_queue_if_no_path(mpath_head) && + !check_mul_overflow(mpath_head->delayed_removal_secs, HZ, &delay) && + try_module_get(mpath_head->drv_module)) { + mod_delayed_work(mpath_wq, &mpath_head->remove_work, delay); + } else { + remove = true; + } + + mutex_unlock(&mpath_head->lock); + return remove; +} +EXPORT_SYMBOL_GPL(mpath_can_remove_head); + +static void mpath_remove_head_work(struct work_struct *work) +{ + struct mpath_head *mpath_head = container_of(to_delayed_work(work), + struct mpath_head, remove_work); + struct module *drv_module = mpath_head->drv_module; + + mpath_head->mpdt->remove_head(mpath_head); + module_put(drv_module); +} + void mpath_remove_disk(struct mpath_head *mpath_head) { if (test_and_clear_bit(MPATH_HEAD_DISK_LIVE, &mpath_head->flags)) { @@ -529,6 +574,9 @@ int mpath_alloc_head_disk(struct mpath_head *mpath_head, mpath_head->disk->private_data = mpath_head; mpath_head->disk->fops = &mpath_ops; + INIT_DELAYED_WORK(&mpath_head->remove_work, mpath_remove_head_work); + mpath_head->delayed_removal_secs = 0; + set_bit(GD_SUPPRESS_PART_SCAN, &mpath_head->disk->state); return 0; @@ -572,6 +620,47 @@ void mpath_device_set_live(struct mpath_device *mpath_device) } EXPORT_SYMBOL_GPL(mpath_device_set_live); +ssize_t mpath_delayed_removal_secs_show(struct mpath_head *mpath_head, + char *buf) +{ + int ret; + + mutex_lock(&mpath_head->lock); + ret = sysfs_emit(buf, "%u\n", mpath_head->delayed_removal_secs); + mutex_unlock(&mpath_head->lock); + + return ret; +} +EXPORT_SYMBOL_GPL(mpath_delayed_removal_secs_show); + +ssize_t mpath_delayed_removal_secs_store(struct mpath_head *mpath_head, + const char *buf, size_t count) +{ + unsigned int sec; + ssize_t ret; + + ret = kstrtouint(buf, 0, &sec); + if (ret < 0) + return ret; + + mutex_lock(&mpath_head->lock); + mpath_head->delayed_removal_secs = sec; + if (sec) + set_bit(MPATH_HEAD_QUEUE_IF_NO_PATH, &mpath_head->flags); + else + clear_bit(MPATH_HEAD_QUEUE_IF_NO_PATH, &mpath_head->flags); + mutex_unlock(&mpath_head->lock); + + /* + * Ensure that update to MPATH_HEAD_QUEUE_IF_NO_PATH is seen + * by its reader. + */ + mpath_synchronize(mpath_head); + + return count; +} +EXPORT_SYMBOL_GPL(mpath_delayed_removal_secs_store); + void mpath_add_sysfs_link(struct mpath_head *mpath_head) { struct device *target; -- 2.43.0