]> www.infradead.org Git - users/sagi/libnvme.git/commitdiff
fabrics: Add nvmf_get_discovery_wargs()
authorMartin Belanger <martin.belanger@dell.com>
Mon, 26 Sep 2022 11:13:55 +0000 (07:13 -0400)
committerMartin Belanger <martin.belanger@dell.com>
Mon, 26 Sep 2022 11:13:55 +0000 (07:13 -0400)
This function is similar to nvmf_get_discovery_log(), but takes
an extensible "args" parameter. The args parameter contains more
options than are available with nvmf_get_discovery_log(). For
example, it provides a way to set the LSP (Log page Specific field)
which is needed for advanced TP8010 features.

Signed-off-by: Martin Belanger <martin.belanger@dell.com>
src/libnvme.map
src/nvme/fabrics.c
src/nvme/fabrics.h

index 79b8f88ecd3acb7689b7d8a16ddc0f71c3ed39a0..ac27d129edbaff4349929ad9aa7ef42439656b64 100644 (file)
@@ -4,6 +4,7 @@ LIBNVME_1_2 {
        global:
                nvme_ctrl_get_dhchap_host_key;
                nvme_ctrl_set_dhchap_host_key;
+               nvmf_get_discovery_wargs;
 };
 
 LIBNVME_1_1 {
index d5db5090e30b5304ef790a5dece0e938bb657238..c9af0c78a27562e465e06b56b0c7a78ee970f97a 100644 (file)
@@ -780,30 +780,9 @@ nvme_ctrl_t nvmf_connect_disc_entry(nvme_host_t h,
        return NULL;
 }
 
-static int nvme_discovery_log(int fd, __u32 len, struct nvmf_discovery_log *log, bool rae)
-{
-       struct nvme_get_log_args args = {
-               .args_size = sizeof(args),
-               .fd = fd,
-               .nsid = NVME_NSID_NONE,
-               .lsp = NVME_LOG_LSP_NONE,
-               .lsi = NVME_LOG_LSI_NONE,
-               .uuidx = NVME_UUID_NONE,
-               .timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
-               .result = NULL,
-               .lid = NVME_LOG_LID_DISCOVER,
-               .log = log,
-               .len = len,
-               .csi = NVME_CSI_NVM,
-               .rae = rae,
-               .ot = false,
-       };
-
-       return nvme_get_log_page(fd, 4096, &args);
-}
-
-int nvmf_get_discovery_log(nvme_ctrl_t c, struct nvmf_discovery_log **logp,
-                          int max_retries)
+static struct nvmf_discovery_log *nvme_discovery_log(nvme_ctrl_t c,
+                                                    struct nvme_get_log_args *args,
+                                                    int max_retries)
 {
        nvme_root_t r = c->s && c->s->h ? c->s->h->r : NULL;
        struct nvmf_discovery_log *log = NULL;
@@ -811,6 +790,9 @@ int nvmf_get_discovery_log(nvme_ctrl_t c, struct nvmf_discovery_log **logp,
        const char *name = nvme_ctrl_get_name(c);
        uint64_t genctr, numrec;
        unsigned int size;
+       int fd = nvme_ctrl_get_fd(c);
+
+       args->fd = fd;
 
        do {
                size = sizeof(struct nvmf_discovery_log);
@@ -821,12 +803,15 @@ int nvmf_get_discovery_log(nvme_ctrl_t c, struct nvmf_discovery_log **logp,
                        nvme_msg(r, LOG_ERR,
                                 "could not allocate memory for discovery log header\n");
                        errno = ENOMEM;
-                       return -1;
+                       return NULL;
                }
 
                nvme_msg(r, LOG_DEBUG, "%s: get header (try %d/%d)\n",
                        name, retries, max_retries);
-               ret = nvme_discovery_log(nvme_ctrl_get_fd(c), size, log, true);
+               args->rae = true;
+               args->len = size;
+               args->log = log;
+               ret = nvme_get_log_page(fd, 4096, args);
                if (ret) {
                        nvme_msg(r, LOG_INFO,
                                 "%s: discover try %d/%d failed, error %d\n",
@@ -849,14 +834,19 @@ int nvmf_get_discovery_log(nvme_ctrl_t c, struct nvmf_discovery_log **logp,
                        nvme_msg(r, LOG_ERR,
                                 "could not alloc memory for discovery log page\n");
                        errno = ENOMEM;
-                       return -1;
+                       return NULL;
                }
 
                nvme_msg(r, LOG_DEBUG,
                         "%s: get header and %" PRIu64
                         " records (length %d genctr %" PRIu64 ")\n",
                         name, numrec, size, genctr);
-               ret = nvme_discovery_log(nvme_ctrl_get_fd(c), size, log, false);
+
+               args->rae = false;
+               args->len = size;
+               args->log = log;
+               ret = nvme_get_log_page(fd, 4096, args);
+
                if (ret) {
                        nvme_msg(r, LOG_INFO,
                                 "%s: discover try %d/%d failed, error %d\n",
@@ -869,21 +859,63 @@ int nvmf_get_discovery_log(nvme_ctrl_t c, struct nvmf_discovery_log **logp,
        if (genctr != le64_to_cpu(log->genctr)) {
                nvme_msg(r, LOG_INFO, "%s: discover genctr mismatch\n", name);
                errno = EAGAIN;
-               ret = -1;
        } else if (numrec != le64_to_cpu(log->numrec)) {
                nvme_msg(r, LOG_INFO,
                         "%s: could only fetch %" PRIu64 " of %" PRIu64 " records\n",
                         name, numrec, le64_to_cpu(log->numrec));
                errno = EBADSLT;
-               ret = -1;
        } else {
-               *logp = log;
-               return 0;
+               return log;
        }
 
 out_free_log:
        free(log);
-       return ret;
+       return NULL;
+}
+
+int nvmf_get_discovery_log(nvme_ctrl_t c, struct nvmf_discovery_log **logp,
+                          int max_retries)
+{
+       struct nvme_get_log_args args = {
+               .args_size = sizeof(args),
+               .fd = nvme_ctrl_get_fd(c),
+               .nsid = NVME_NSID_NONE,
+               .lsp = NVMF_LOG_DISC_LSP_NONE,
+               .lsi = NVME_LOG_LSI_NONE,
+               .uuidx = NVME_UUID_NONE,
+               .timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
+               .result = NULL,
+               .lid = NVME_LOG_LID_DISCOVER,
+               .log = NULL,
+               .len = 0,
+               .csi = NVME_CSI_NVM,
+               .rae = false,
+               .ot = false,
+       };
+       *logp = nvme_discovery_log(c, &args, max_retries);
+       return logp ? 0 : -1;
+}
+
+struct nvmf_discovery_log *nvmf_get_discovery_wargs(struct nvme_get_discovery_args *args)
+{
+       struct nvme_get_log_args _args = {
+               .args_size = sizeof(_args),
+               .fd = nvme_ctrl_get_fd(args->c),
+               .nsid = NVME_NSID_NONE,
+               .lsp = args->lsp,
+               .lsi = NVME_LOG_LSI_NONE,
+               .uuidx = NVME_UUID_NONE,
+               .timeout = args->timeout,
+               .result = args->result,
+               .lid = NVME_LOG_LID_DISCOVER,
+               .log = NULL,
+               .len = 0,
+               .csi = NVME_CSI_NVM,
+               .rae = false,
+               .ot = false,
+       };
+
+       return nvme_discovery_log(args->c, &_args, args->max_retries);
 }
 
 #define PATH_UUID_IBM  "/proc/device-tree/ibm,partition-uuid"
index 9e099feeeb08be8d595ba6b5a83f71a723075334..272bb40815627243f642e4575d5da6eef5731c66 100644 (file)
@@ -195,15 +195,55 @@ int nvmf_add_ctrl(nvme_host_t h, nvme_ctrl_t c,
 
 /**
  * nvmf_get_discovery_log() - Return the discovery log page
- * @c:                 Discover controller to use
+ * @c:                 Discovery controller to use
  * @logp:              Pointer to the log page to be returned
- * @max_retries:       maximum number of log page entries to be returned
+ * @max_retries:       Number of retries in case of failure
+ *
+ * The memory allocated for the log page and returned in @logp
+ * must be freed by the caller using free().
+ *
+ * Note: Consider using nvmf_get_discovery_wargs() instead.
  *
  * Return: 0 on success; on failure -1 is returned and errno is set
  */
 int nvmf_get_discovery_log(nvme_ctrl_t c, struct nvmf_discovery_log **logp,
                           int max_retries);
 
+/**
+ * struct nvme_get_discovery_args - Arguments for nvmf_get_discovery_wargs()
+ * @c:                 Discovery controller
+ * @args_size:         Length of the structure
+ * @max_retries:       Number of retries in case of failure
+ * @result:            The command completion result from CQE dword0
+ * @timeout:           Timeout in ms (default: NVME_DEFAULT_IOCTL_TIMEOUT)
+ * @lsp:               Log specific field (See enum nvmf_log_discovery_lsp)
+ */
+struct nvme_get_discovery_args {
+       nvme_ctrl_t c;
+       int args_size;
+       int max_retries;
+       __u32 *result;
+       __u32 timeout;
+       __u8 lsp;
+};
+
+/**
+ * nvmf_get_discovery_wargs() - Get the discovery log page with args
+ * @args:      Argument structure
+ *
+ * This function is similar to nvmf_get_discovery_log(), but
+ * takes an extensible @args parameter. @args provides more
+ * options than nvmf_get_discovery_log().
+ *
+ * This function performs a get discovery log page (DLP) command
+ * and returns the DLP. The memory allocated for the returned
+ * DLP must be freed by the caller using free().
+ *
+ * Return: Pointer to the discovery log page (to be freed). NULL
+ * on failure and errno is set.
+ */
+struct nvmf_discovery_log *nvmf_get_discovery_wargs(struct nvme_get_discovery_args *args);
+
 /**
  * nvmf_hostnqn_generate() - Generate a machine specific host nqn
  * Returns: An nvm namespace qualified name string based on the machine