Skip to content

Commit 5523019

Browse files
committed
mi: Add endpoint get/set timeout API
This change introduces an API for querying and modifying the endpoint timeout. Transports may provide a function for valiating a new timeout value before setting. Signed-off-by: Jeremy Kerr <[email protected]>
1 parent 6c5aedd commit 5523019

3 files changed

Lines changed: 39 additions & 0 deletions

File tree

src/nvme/mi.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
#include "mi.h"
1818
#include "private.h"
1919

20+
static const int default_timeout = 1000; /* milliseconds; endpoints may
21+
override */
22+
2023
/* MI-equivalent of nvme_create_root, but avoids clashing symbol names
2124
* when linking against both libnvme and libnvme-mi.
2225
*/
@@ -57,13 +60,32 @@ struct nvme_mi_ep *nvme_mi_init_ep(nvme_root_t root)
5760
list_node_init(&ep->root_entry);
5861
ep->root = root;
5962
ep->controllers_scanned = false;
63+
ep->timeout = default_timeout;
6064
list_head_init(&ep->controllers);
6165

6266
list_add(&root->endpoints, &ep->root_entry);
6367

6468
return ep;
6569
}
6670

71+
int nvme_mi_ep_set_timeout(nvme_mi_ep_t ep, unsigned int timeout_ms)
72+
{
73+
if (ep->transport->check_timeout) {
74+
int rc;
75+
rc = ep->transport->check_timeout(ep, timeout_ms);
76+
if (rc)
77+
return rc;
78+
}
79+
80+
ep->timeout = timeout_ms;
81+
return 0;
82+
}
83+
84+
unsigned int nvme_mi_ep_get_timeout(nvme_mi_ep_t ep)
85+
{
86+
return ep->timeout;
87+
}
88+
6789
struct nvme_mi_ctrl *nvme_mi_init_ctrl(nvme_mi_ep_t ep, __u16 ctrl_id)
6890
{
6991
struct nvme_mi_ctrl *ctrl;

src/nvme/mi.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,21 @@ nvme_mi_ep_t nvme_mi_next_endpoint(nvme_root_t m, nvme_mi_ep_t e);
451451
e != NULL; \
452452
e = _e, _e = nvme_mi_next_endpoint(m, e))
453453

454+
/**
455+
* nvme_mi_ep_set_timeout - set a timeout for NVMe-MI responses
456+
* @ep: MI endpoint object
457+
* @timeout_ms: Timeout for MI responses, given in milliseconds
458+
*/
459+
int nvme_mi_ep_set_timeout(nvme_mi_ep_t ep, unsigned int timeout_ms);
460+
461+
/**
462+
* nvme_mi_ep_get_timeout - get the current timeout value for NVMe-MI responses
463+
* @ep: MI endpoint object
464+
*
465+
* Returns the current timeout value, in milliseconds, for this endpoint.
466+
*/
467+
unsigned int nvme_mi_ep_get_timeout(nvme_mi_ep_t ep);
468+
454469
struct nvme_mi_ctrl;
455470

456471
/**

src/nvme/private.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ struct nvme_mi_transport {
183183
struct nvme_mi_resp *resp);
184184
void (*close)(struct nvme_mi_ep *ep);
185185
int (*desc_ep)(struct nvme_mi_ep *ep, char *buf, size_t len);
186+
int (*check_timeout)(struct nvme_mi_ep *ep, unsigned int timeout);
186187
};
187188

188189
struct nvme_mi_ep {
@@ -192,6 +193,7 @@ struct nvme_mi_ep {
192193
struct list_node root_entry;
193194
struct list_head controllers;
194195
bool controllers_scanned;
196+
unsigned int timeout;
195197
};
196198

197199
struct nvme_mi_ctrl {

0 commit comments

Comments
 (0)