From: hare@kernel.org
To: Christoph Hellwig <hch@lst.de>
Cc: Keith Busch <kbusch@kernel.org>, Sagi Grimberg <sagi@grimberg.me>,
linux-nvme@lists.infradead.org, Hannes Reinecke <hare@kernel.org>
Subject: [PATCH 6/6] tools/testing/selftests: add sample nvme bpf path selector
Date: Tue, 29 Jul 2025 09:06:53 +0200 [thread overview]
Message-ID: <20250729070653.125258-7-hare@kernel.org> (raw)
In-Reply-To: <20250729070653.125258-1-hare@kernel.org>
From: Hannes Reinecke <hare@kernel.org>
As a simple nvme bpf path selector to demonstrate the namespace
path iteration.
Signed-off-by: Hannes Reinecke <hare@kernel.org>
---
.../selftests/bpf/progs/bpf_nvme_simple.c | 52 +++++++++++++++++++
1 file changed, 52 insertions(+)
create mode 100644 tools/testing/selftests/bpf/progs/bpf_nvme_simple.c
diff --git a/tools/testing/selftests/bpf/progs/bpf_nvme_simple.c b/tools/testing/selftests/bpf/progs/bpf_nvme_simple.c
new file mode 100644
index 000000000000..c9cafb6bd253
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/bpf_nvme_simple.c
@@ -0,0 +1,52 @@
+// SPDX-License-Identifier: GPL-2.0
+
+/*
+ * simple nvme ebpf path selector
+ *
+ * Simulates a RAID layout with chunk size 2M
+ */
+
+#include <vmlinux.h>
+#include <errno.h>
+#include <bpf/bpf_helpers.h>
+#include <bpf/bpf_tracing.h>
+
+char _license[] SEC("license") = "GPL";
+
+static sector_t simple_offset = 0;
+static sector_t simple_blocksize = 1048576;
+
+SEC("struct_ops")
+int BPF_PROG(simple_select, struct nvme_bpf_iter *iter, sector_t sector)
+{
+ sector_t offset = simple_offset;
+ sector_t block_size = simple_blocksize;
+ u32 num_blks, num_paths, num_iter, i;
+ int cntlid;
+
+ if (sector > offset)
+ sector -= offset;
+ cntlid = nvme_bpf_first_path(iter);
+ if (cntlid < 0)
+ return cntlid;
+ if (!block_size || sector < block_size)
+ return cntlid;
+
+ num_blks = (sector / block_size);
+ num_paths = nvme_bpf_count_paths(iter);
+ num_iter = num_blks % num_paths;
+ bpf_for (i, 1, num_iter) {
+ cntlid = nvme_bpf_next_path(iter);
+ if (cntlid < 0)
+ break;
+ }
+ return cntlid;
+}
+
+SEC(".struct_ops")
+struct nvme_bpf_ops bpf_nvme_simple = {
+ .uuid = { 0x86, 0xee, 0x41, 0xd5, 0x25, 0x6b, 0x45, 0xd0, 0xa4, 0x81, 0x5e, 0x35, 0xf6, 0x02, 0xf5, 0x11 },
+ .subsysnqn = "blktests-subsystem-1",
+ .nsid = 1,
+ .select_path = (void *)simple_select,
+};
--
2.43.0
next prev parent reply other threads:[~2025-07-29 7:07 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-29 7:06 [RFC PATCH 0/6] nvme multipath eBPF path selector hare
2025-07-29 7:06 ` [PATCH 1/6] nvme-multipath: do not assign ->current_path in __nvme_find_path() hare
2025-07-29 7:06 ` [PATCH 2/6] nvme: export nvme_find_get_subsystem()/nvme_put_subsystem() hare
2025-07-29 7:06 ` [PATCH 3/6] nvme: add per-namespace iopolicy sysfs attribute hare
2025-07-29 7:06 ` [PATCH 4/6] nvme: add 'sector' parameter to nvme_find_path() hare
2025-07-29 7:06 ` [PATCH 5/6] nvme-bpf: eBPF struct_ops path selectors hare
2025-07-29 7:06 ` hare [this message]
2025-07-30 2:03 ` [PATCH 6/6] tools/testing/selftests: add sample nvme bpf path selector Geliang Tang
2025-07-30 5:56 ` Hannes Reinecke
2025-07-29 7:54 ` [RFC PATCH 0/6] nvme multipath eBPF " Christoph Hellwig
2025-07-29 14:53 ` Mike Christie
2025-07-30 14:06 ` Christoph Hellwig
2025-07-30 2:03 ` Geliang Tang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250729070653.125258-7-hare@kernel.org \
--to=hare@kernel.org \
--cc=hch@lst.de \
--cc=kbusch@kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=sagi@grimberg.me \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).