From: Keith Busch Date: Tue, 23 Feb 2021 22:54:12 +0000 (+0900) Subject: add lba status log helper X-Git-Tag: v1.0-rc0~138 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=76ba7703e7f84764f315af006430cd8f43e8eb14;p=users%2Fsagi%2Flibnvme.git add lba status log helper This log requires a more complex multi-sequence to successfully get, so add a helper. Signed-off-by: Keith Busch --- diff --git a/src/nvme/util.c b/src/nvme/util.c index 175714e4..7d044bf5 100644 --- a/src/nvme/util.c +++ b/src/nvme/util.c @@ -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) { diff --git a/src/nvme/util.h b/src/nvme/util.h index 6534f631..a3541ab6 100644 --- a/src/nvme/util.h +++ b/src/nvme/util.h @@ -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