From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.252 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794170885; b=oeDmwhN2Z9GkdY3+om3rN0bicIdIxA0w593bP8sOIf5pWdbvBckGtxQ8128i0H/yv4Jp xay1rlMxNL77KfnVgae+ZHsfR6YVVVy96aLBV/ayz0YVUxCLzIqAcEZm28Kc07K7XWL1S QrC36FvJLQ8KzPb7PmITukD5FLfMvF3zAI24I3xWtQ4H1nnIS2LPY56lZOzxycCrqsczx LqTIMHaxPKM+QLFKPBUruYL+Xgj6IoiZf9OnW1GyU2rAQ2LT1/w/56vVy/4ADHZpYf+Qm e4+AvcAdvC2cTA50Go5zBgBT2XKL/vZwNKyrQR+SuALRTRD3TvZFS3UDjIRd5YnKYOQ== 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=v31MBTpKVN1RZ3tXNOprM++fXEeru6mCNDAKzVW4bHOL4RXKoQQhzVlR46hoAUuS0YMF QrRtvmNPARYb3rPRg2jIcypN/m64QHuuah6Uf3lo6hySFUieADEX4uB+eCozJ0fP2Uyyu gyeaAtnTXxvPrKKf7L+No8eukzDF5a5hXidc9zKYcIJYzMJ7KJ7C5m9+wPVaJ4Gt+8GZa Db+kKZa91lmWxWoBE6ALGLckxeQgQCYdEjLinYv/1fd5NibV0Zw/OzQ5xgIZFfJ4hI/Jh xvLjNjQM9iGdtFE/DtIbT5ppueXlF20gkwgB4CHqQ4zYJczNHnoKEtpVjcc6u6rRe6g== 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.252 Received: from mta0.migadu.com (out-252.mta0.migadu.com [91.218.175.252]) (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 D8C27606A33A for ; Sun, 8 Nov 2026 20:48:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D8C27606A33A 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: linux-scsi@vger.kernel.org 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: linux-scsi@vger.kernel.org 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: linux-scsi@vger.kernel.org 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