Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.1 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794170885; b=GMcMJi0ENn3WtCos0T3bKOKP2kOX3Mz84JR2ZO7TZ/MGpZVaPonh9CD4Z27t1v/D53ok HUXBTw/SB0+ikxkGwkMbRA/mOaLWg0zyPyBHCXlzjDzAPuBpoRYoKtIKfFuB6PhWb0g3F /V0Keh5JMV+4c13zxq6jDT/0LLpt4Acl1jCv/YhWEjAHqkvbtr3NIr8mEuz/Lr7nRxUdC n3egyWbobZIkZaoyjMLQhGAlqIv17+WnarejDhDBLTgJPGI5IQfP0rHhiRtnomPhsLPjS cQEZxpE3beA9vC+h/emKxEBw4WLfL1cK65qjkTDvn+vDd8+FjsvnbLCZJx57N7FrR+Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794170885; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=bMHACPgIcWPaET06xon/DoA1r+E9zH8ZH5JoC35wPb0=; b=kfI0HDrPkbbOu9H+K1cpgdkHYmAi7zFQ0P3mYkLwCMkLWSdolXMOCVtHNuwni+H5QrKa IyJKIr3pstAxD0D7Z4rZrZRb3qpTxU0S+Xpbf78zt+OPNoO0Kol/Jetd04iYyVtv3hgpu y+N1jBjUHGsv9uvsQmXMMkvFB9xiRKqL25NJbd6fyCObAhJOdxcmDPclwpUVLfx0qXyH2 IhmOXIrn4iCM7ZDKVNTQ2RFU5LDV9TauMxaHR9aHCSdu23m+CK7iO+AaXmVESy4+ixPyW OYchrHA5Bz86Iftu8+WeAprIxrIa75Yx47+onLyHYT/E4h+oPeAY3E7lG0UC0g+b7CA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=Mnlefwgu; arc=none smtp.remote-ip=91.218.175.1 Received: from mta0.migadu.com (out-1.mta0.migadu.com [91.218.175.1]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C347D606D80B for ; Sun, 8 Nov 2026 20:48:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C347D606D80B Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=Mnlefwgu X-Envelope-To: dm-devel@lists.linux.dev DKIM-Signature: a=rsa-sha256; bh=O/+RShHRlHw9LWvz4LZwZOeY2xmJPMvSVtw2UUCaH8c=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1794170883; v=1; x=1794775683; b=Mnlefwgutgn3nBRGYNuhulDjLCLe5fgqnR+CqBTGxAXcwEYealkGZzb6mD9EvFHnF1L9nhBV AFs+TsbRbJI1f6eQ9QJupp/g7fVb5NM7m/DmDlmxu7XLvnfl1q+F/2XAB685caKlgxIXuNeKEOM wgQ2NLiLJge09vG7x1fh5wQk= X-Envelope-To: dm-devel@lists.linux.dev Received: by mta10.migadu.com with ESMTPS id d1882979d78c9bce; Sun, 08 Nov 2026 20:48:03 +0000 X-Mizu-Trace-ID: d1882979d78c9bce 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 08/29] libmultipath: Add sysfs helpers Date: Sun, 8 Nov 2026 20:47:12 +0000 Message-ID: <20261108204733.557995-9-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-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Add helpers for driver sysfs code for the following functionality: - get/set iopolicy with mpath_iopolicy_store() and mpath_iopolicy_show() - show device path per NUMA node - "multipath" attribute group, equivalent to nvme_ns_mpath_attr_group - device groups attribute array, similar to nvme_ns_attr_groups but not containing NVMe members. Signed-off-by: John Garry --- include/linux/multipath.h | 5 +++ lib/multipath.c | 94 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) diff --git a/include/linux/multipath.h b/include/linux/multipath.h index 66b6ad9c2219..7a3708ff3725 100644 --- a/include/linux/multipath.h +++ b/include/linux/multipath.h @@ -7,6 +7,8 @@ #include extern const struct block_device_operations mpath_ops; +extern const struct attribute_group mpath_attr_group; +extern const struct attribute_group *mpath_device_groups[]; enum mpath_iopolicy_e { MPATH_IOPOLICY_NUMA, @@ -118,6 +120,9 @@ 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_numa_nodes_show(struct mpath_device *mpath_device, char *buf); +ssize_t mpath_iopolicy_show(enum mpath_iopolicy_e *iopolicy, char *buf); +bool mpath_iopolicy_store(enum mpath_iopolicy_e *iopolicy, const char *buf); 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, diff --git a/lib/multipath.c b/lib/multipath.c index cdf8fbc5105b..ae5a73d570b3 100644 --- a/lib/multipath.c +++ b/lib/multipath.c @@ -620,6 +620,100 @@ void mpath_device_set_live(struct mpath_device *mpath_device) } EXPORT_SYMBOL_GPL(mpath_device_set_live); +static struct attribute dummy_attr = { + .name = "dummy", +}; + +static struct attribute *mpath_attrs[] = { + &dummy_attr, + NULL +}; + +static bool multipath_sysfs_group_visible(struct kobject *kobj) +{ + struct device *dev = container_of(kobj, struct device, kobj); + struct gendisk *disk = dev_to_disk(dev); + + return is_mpath_disk(disk); +} +DEFINE_SIMPLE_SYSFS_GROUP_VISIBLE(multipath_sysfs) + +const struct attribute_group mpath_attr_group = { + .name = "multipath", + .attrs = mpath_attrs, + .is_visible = SYSFS_GROUP_VISIBLE(multipath_sysfs), +}; +EXPORT_SYMBOL_GPL(mpath_attr_group); + +const struct attribute_group *mpath_device_groups[] = { + &mpath_attr_group, + NULL +}; +EXPORT_SYMBOL_GPL(mpath_device_groups); + +ssize_t mpath_iopolicy_show(enum mpath_iopolicy_e *iopolicy, char *buf) +{ + return sysfs_emit(buf, "%s\n", + mpath_iopolicy_names[READ_ONCE(*iopolicy)]); +} +EXPORT_SYMBOL_GPL(mpath_iopolicy_show); + +static void mpath_iopolicy_update(enum mpath_iopolicy_e *iopolicy, + int new) +{ + int old = READ_ONCE(*iopolicy); + + if (old == new) + return; + + WRITE_ONCE(*iopolicy, new); + + pr_info("iopolicy changed from %s to %s\n", + mpath_iopolicy_names[old], + mpath_iopolicy_names[new]); +} + +bool mpath_iopolicy_store(enum mpath_iopolicy_e *iopolicy, const char *buf) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(mpath_iopolicy_names); i++) { + if (sysfs_streq(buf, mpath_iopolicy_names[i])) { + mpath_iopolicy_update(iopolicy, i); + return true; + } + } + + return false; +} +EXPORT_SYMBOL_GPL(mpath_iopolicy_store); + +ssize_t mpath_numa_nodes_show(struct mpath_device *mpath_device, char *buf) +{ + struct mpath_head *mpath_head = mpath_device->mpath_head; + int node, srcu_idx; + nodemask_t numa_nodes; + struct mpath_device *current_mpath_dev; + + if (mpath_read_iopolicy(mpath_head) != MPATH_IOPOLICY_NUMA) + return 0; + + nodes_clear(numa_nodes); + + srcu_idx = srcu_read_lock(&mpath_head->srcu); + for_each_node(node) { + current_mpath_dev = + srcu_dereference(mpath_head->current_path[node], + &mpath_head->srcu); + if (current_mpath_dev == mpath_device) + node_set(node, numa_nodes); + } + srcu_read_unlock(&mpath_head->srcu, srcu_idx); + + return sysfs_emit(buf, "%*pbl\n", nodemask_pr_args(&numa_nodes)); +} +EXPORT_SYMBOL_GPL(mpath_numa_nodes_show); + ssize_t mpath_delayed_removal_secs_show(struct mpath_head *mpath_head, char *buf) { -- 2.43.0