diff options
Diffstat (limited to 'nvme.h')
-rw-r--r-- | nvme.h | 105 |
1 files changed, 29 insertions, 76 deletions
@@ -22,17 +22,28 @@ #include <sys/time.h> #include "plugin.h" -#ifdef LIBJSONC -#include <json-c/json.h> +#ifdef CONFIG_JSONC +#include <json.h> #define json_create_object(o) json_object_new_object(o) #define json_create_array(a) json_object_new_array(a) #define json_free_object(o) json_object_put(o) #define json_free_array(a) json_object_put(a) #define json_object_add_value_uint(o, k, v) \ - json_object_object_add(o, k, json_object_new_uint64(v)) + json_object_object_add(o, k, json_object_new_int(v)) #define json_object_add_value_int(o, k, v) \ - json_object_object_add(o, k, json_object_new_int64(v)) + json_object_object_add(o, k, json_object_new_int(v)) +#ifdef CONFIG_JSONC_14 +#define json_object_add_value_uint64(o, k, v) \ + json_object_object_add(o, k, json_object_new_uint64(v)) +#else +#define json_object_add_value_uint64(o, k, v) \ + if ((v) > UINT_MAX) { \ + fprintf(stderr, "Value overflow in %s", k); \ + json_object_object_add(o, k, json_object_new_int(-1)); \ + } else \ + json_object_object_add(o, k, json_object_new_int(v)) +#endif #define json_object_add_value_float(o, k, v) \ json_object_object_add(o, k, json_object_new_double(v)) #define json_object_add_value_string(o, k, v) \ @@ -46,12 +57,13 @@ #define json_array_add_value_string(o, v) \ json_object_array_add(o, json_object_new_string(v)) #define json_print_object(o, u) \ - printf("%s", json_object_to_json_string_ext(o, JSON_C_TO_STRING_PRETTY)) + printf("%s", json_object_to_json_string_ext(o, \ + JSON_C_TO_STRING_PRETTY | \ + JSON_C_TO_STRING_NOSLASHESCAPE)) #else #include "util/json.h" #endif #include "util/argconfig.h" -#include "linux/nvme.h" enum nvme_print_flags { NORMAL = 0, @@ -61,55 +73,6 @@ enum nvme_print_flags { BINARY = 1 << 3, /* binary dump raw bytes */ }; -struct nvme_subsystem; -struct nvme_ctrl; - -struct nvme_namespace { - char *name; - struct nvme_ctrl *ctrl; - - unsigned nsid; - struct nvme_id_ns ns; -}; - -struct nvme_ctrl { - char *name; - char *path; - struct nvme_subsystem *subsys; - - char *address; - char *transport; - char *state; - char *ana_state; - char *traddr; - char *trsvcid; - char *host_traddr; - char *host_iface; - char *hostnqn; - char *hostid; - - struct nvme_id_ctrl id; - - int nr_namespaces; - struct nvme_namespace *namespaces; -}; - -struct nvme_subsystem { - char *name; - char *subsysnqn; - - int nr_ctrls; - struct nvme_ctrl *ctrls; - - int nr_namespaces; - struct nvme_namespace *namespaces; -}; - -struct nvme_topology { - int nr_subsystems; - struct nvme_subsystem *subsystems; -}; - #define SYS_NVME "/sys/class/nvme" void register_extension(struct plugin *plugin); @@ -121,30 +84,12 @@ extern const char *output_format; enum nvme_print_flags validate_output_format(const char *format); int __id_ctrl(int argc, char **argv, struct command *cmd, - struct plugin *plugin, void (*vs)(__u8 *vs, struct json_object *root)); -char *nvme_char_from_block(char *block); -int nvme_logical_block_size_from_ns_char(const char *dev); -void *mmap_registers(const char *dev); + struct plugin *plugin, void (*vs)(uint8_t *vs, struct json_object *root)); extern int current_index; -int scan_ctrl_namespace_filter(const struct dirent *d); -int scan_namespace_filter(const struct dirent *d); -int scan_ctrl_paths_filter(const struct dirent *d); -int scan_ctrls_filter(const struct dirent *d); -int scan_subsys_filter(const struct dirent *d); -int scan_dev_filter(const struct dirent *d); - -int scan_subsystems(struct nvme_topology *t, const char *subsysnqn, - __u32 ns_instance, int nsid, char *dev_dir); -void free_topology(struct nvme_topology *t); -char *get_nvme_subsnqn(char *path); -char *nvme_get_ctrl_attr(const char *path, const char *attr); - void *nvme_alloc(size_t len, bool *huge); void nvme_free(void *p, bool huge); - -int uuid_from_dmi(char *uuid); -int uuid_from_systemd(char *uuid); +const char *nvme_strerror(int errnum); unsigned long long elapsed_utime(struct timeval start_time, struct timeval end_time); @@ -154,5 +99,13 @@ static inline void nvme_strip_spaces(char *s, int l) while (l && (s[l] == '\0' || s[l] == ' ')) s[l--] = '\0'; } -__u16 get_feat_buf_len(unsigned short feature); + +/* nvme-print.c */ +const char *nvme_select_to_string(int sel); + +void d(unsigned char *buf, int len, int width, int group); +void d_raw(unsigned char *buf, unsigned len); +uint64_t int48_to_long(uint8_t *data); + +int map_log_level(int verbose, bool quiet); #endif /* _NVME_H */ |