]> www.infradead.org Git - users/sagi/libnvme.git/commitdiff
add lba status log helper
authorKeith Busch <kbusch@kernel.org>
Tue, 23 Feb 2021 22:54:12 +0000 (07:54 +0900)
committerKeith Busch <kbusch@kernel.org>
Tue, 23 Feb 2021 22:54:12 +0000 (07:54 +0900)
This log requires a more complex multi-sequence to successfully get, so
add a helper.

Signed-off-by: Keith Busch <kbusch@kernel.org>
src/nvme/util.c
src/nvme/util.h

index 175714e423e1b52874b8f662cba1fd89d526bd8a..7d044bf563ae455f8dc89194b492e3b6d57d1177 100644 (file)
@@ -339,11 +339,49 @@ int nvme_get_host_telemetry(int fd,  struct nvme_telemetry_log **log)
        return nvme_get_telemetry_log(fd, false, false, false, log);
 }
 
-int nvme_get_new_host_telemetry(int fd,  struct nvme_telemetry_log  **log)
+int nvme_get_new_host_telemetry(int fd,  struct nvme_telemetry_log **log)
 {
        return nvme_get_telemetry_log(fd, true, false, false, log);
 }
 
+int nvme_get_lba_status_log(int fd, bool rae, struct nvme_lba_status_log **log)
+{
+       __u32 size = sizeof(struct nvme_lba_status_log);
+       void *buf, *tmp;
+       int err;
+
+       buf = malloc(size);
+       if (!buf)
+               return -1;
+
+       *log = buf;
+       err = nvme_get_log_lba_status(fd, true, 0, size, buf);
+       if (err)
+               goto free;
+
+       size = le32_to_cpu((*log)->lslplen);
+       if (!size)
+               return 0;
+
+       tmp = realloc(buf, size);
+       if (!tmp) {
+               err = -1;
+               goto free;
+       }
+       buf = tmp;
+       *log = buf;
+
+       err = nvme_get_log_page(fd, NVME_NSID_NONE, NVME_LOG_LID_LBA_STATUS,
+                               rae, size, buf);
+       if (!err)
+               return 0;
+
+free:
+       *log = NULL;
+       free(buf);
+       return err;
+}
+
 void nvme_init_dsm_range(struct nvme_dsm_range *dsm, __u32 *ctx_attrs,
                         __u32 *llbas, __u64 *slbas, __u16 nr_ranges)
 {
index 6534f631eacf5bf9de44fae61f26312ae288af5d..a3541ab66d3f83d5a356e23190d05854c2e32b64 100644 (file)
@@ -165,6 +165,14 @@ int nvme_get_log_page(int fd, __u32 nsid, __u8 log_id, bool rae,
  */
 int nvme_get_ana_log_len(int fd, size_t *analen);
 
+/**
+ * nvme_get_lba_status_log() - Retreive the LBA Status log page
+ * @fd:           File descriptor of the nvme device
+ * @rae:   Retain asynchronous events
+ * @log:   On success, set to the value of the allocated and retreived log.
+ */
+int nvme_get_lba_status_log(int fd, bool rae, struct nvme_lba_status_log **log);
+
 /**
  * nvme_namespace_attach_ctrls() - Attach namespace to controller(s)
  * @fd:                File descriptor of nvme device