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;
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);
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",
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",
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"
/**
* 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