Skip to content

Commit ed783ea

Browse files
shroffniigaw
authored andcommitted
tree: add queue-depth attribute for nvme path object
Introduce a new sysfs attribute, queue_depth, under the NVMe path object. This attribute is used by the queue-depth I/O policy introduced in kernel v6.11, but the sysfs interface for this attribute was only added later in kernel v6.15. The queue_depth value is useful for observing which paths are selected for I/O forwarding based on their current queue depths. To make this information available to user space tools such as nvme-cli, the attribute is now exported in libnvme.map. As queue_depth value could change frequently, nvme_path_get_queue_depth() is implemented to always fetch the latest queue_depth value, rather than relying solely on a cached version. If fetching the latest value fails, the function gracefully falls back to the cached value. Signed-off-by: Nilay Shroff <[email protected]> Signed-off-by: Daniel Wagner <[email protected]>
1 parent f5b9a34 commit ed783ea

4 files changed

Lines changed: 28 additions & 1 deletion

File tree

src/libnvme.map

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ LIBNVME_1_0 {
327327
nvme_path_get_ctrl;
328328
nvme_path_get_name;
329329
nvme_path_get_ns;
330+
nvme_path_get_queue_depth;
330331
nvme_path_get_sysfs_dir;
331332
nvme_paths_filter;
332333
nvme_read_config;

src/nvme/private.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ struct nvme_path {
3434
char *sysfs_dir;
3535
char *ana_state;
3636
int grpid;
37+
int queue_depth;
3738
};
3839

3940
struct nvme_ns_head {

src/nvme/tree.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,18 @@ const char *nvme_path_get_name(nvme_path_t p)
908908
return p->name;
909909
}
910910

911+
int nvme_path_get_queue_depth(nvme_path_t p)
912+
{
913+
_cleanup_free_ char *queue_depth = NULL;
914+
915+
queue_depth = nvme_get_path_attr(p, "queue_depth");
916+
if (queue_depth) {
917+
sscanf(queue_depth, "%d", &p->queue_depth);
918+
}
919+
920+
return p->queue_depth;
921+
}
922+
911923
const char *nvme_path_get_ana_state(nvme_path_t p)
912924
{
913925
return p->ana_state;
@@ -926,7 +938,7 @@ void nvme_free_path(struct nvme_path *p)
926938
static int nvme_ctrl_scan_path(nvme_root_t r, struct nvme_ctrl *c, char *name)
927939
{
928940
struct nvme_path *p;
929-
_cleanup_free_ char *path = NULL, *grpid = NULL;
941+
_cleanup_free_ char *path = NULL, *grpid = NULL, *queue_depth = NULL;
930942
int ret;
931943

932944
nvme_msg(r, LOG_DEBUG, "scan controller %s path %s\n",
@@ -960,6 +972,11 @@ static int nvme_ctrl_scan_path(nvme_root_t r, struct nvme_ctrl *c, char *name)
960972
sscanf(grpid, "%d", &p->grpid);
961973
}
962974

975+
queue_depth = nvme_get_path_attr(p, "queue_depth");
976+
if (queue_depth) {
977+
sscanf(queue_depth, "%d", &p->queue_depth);
978+
}
979+
963980
list_node_init(&p->nentry);
964981
list_node_init(&p->entry);
965982
list_add_tail(&c->paths, &p->entry);

src/nvme/tree.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,14 @@ const char *nvme_path_get_sysfs_dir(nvme_path_t p);
867867
*/
868868
const char *nvme_path_get_ana_state(nvme_path_t p);
869869

870+
/**
871+
* nvme_path_get_queue_depth() - Queue depth of an nvme_path_t object
872+
* @p: &nvme_path_t object
873+
*
874+
* Return: Queue depth of @p
875+
*/
876+
int nvme_path_get_queue_depth(nvme_path_t p);
877+
870878
/**
871879
* nvme_path_get_ctrl() - Parent controller of an nvme_path_t object
872880
* @p: &nvme_path_t object

0 commit comments

Comments
 (0)