Adding upstream version 2.12.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
65508f0a28
commit
c0fbec1eb4
571 changed files with 10718 additions and 2738 deletions
|
@ -96,6 +96,12 @@ enum argconfig_types {
|
|||
#define OPT_LIST(l, s, v, d, ...) OPT_STRING(l, s, "LIST", v, d, __VA_ARGS__)
|
||||
#define OPT_STR(l, s, v, d, ...) OPT_STRING(l, s, "STRING", v, d, __VA_ARGS__)
|
||||
|
||||
#ifdef CONFIG_JSONC
|
||||
#define OPT_FLAG_JSON(l, s, v, d, ...) OPT_FLAG(l, s, v, d, __VA_ARGS__)
|
||||
#else /* CONFIG_JSONC */
|
||||
#define OPT_FLAG_JSON(l, s, v, d, ...) OPT_END()
|
||||
#endif /* CONFIG_JSONC */
|
||||
|
||||
#define OPT_VALS(n) \
|
||||
struct argconfig_opt_val n[]
|
||||
|
||||
|
|
63
util/json.c
63
util/json.c
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include "json.h"
|
||||
#include "types.h"
|
||||
#include "cleanup.h"
|
||||
|
||||
struct json_object *util_json_object_new_double(long double d)
|
||||
{
|
||||
|
@ -72,3 +73,65 @@ uint64_t util_json_object_get_uint64(struct json_object *obj)
|
|||
|
||||
return val;
|
||||
}
|
||||
|
||||
void json_object_add_uint_02x(struct json_object *o, const char *k, __u32 v)
|
||||
{
|
||||
json_object_add_uint_0nx(o, k, v, 2);
|
||||
}
|
||||
|
||||
void json_object_add_uint_0x(struct json_object *o, const char *k, __u32 v)
|
||||
{
|
||||
char str[STR_LEN];
|
||||
|
||||
sprintf(str, "0x%x", v);
|
||||
json_object_add_value_string(o, k, str);
|
||||
}
|
||||
|
||||
void json_object_add_byte_array(struct json_object *o, const char *k, unsigned char *buf, int len)
|
||||
{
|
||||
int i;
|
||||
|
||||
_cleanup_free_ char *value = NULL;
|
||||
|
||||
if (!buf || !len) {
|
||||
json_object_add_value_string(o, k, "No information provided");
|
||||
return;
|
||||
}
|
||||
|
||||
value = calloc(1, (len + 1) * 2 + 1);
|
||||
|
||||
if (!value) {
|
||||
json_object_add_value_string(o, k, "Could not allocate string");
|
||||
return;
|
||||
}
|
||||
|
||||
sprintf(value, "0x");
|
||||
for (i = 1; i <= len; i++)
|
||||
sprintf(&value[i * 2], "%02x", buf[len - i]);
|
||||
|
||||
json_object_add_value_string(o, k, value);
|
||||
}
|
||||
|
||||
void json_object_add_nprix64(struct json_object *o, const char *k, uint64_t v)
|
||||
{
|
||||
char str[STR_LEN];
|
||||
|
||||
sprintf(str, "%#"PRIx64"", v);
|
||||
json_object_add_value_string(o, k, str);
|
||||
}
|
||||
|
||||
void json_object_add_uint_0nx(struct json_object *o, const char *k, __u32 v, int width)
|
||||
{
|
||||
char str[STR_LEN];
|
||||
|
||||
sprintf(str, "0x%0*x", width, v);
|
||||
json_object_add_value_string(o, k, str);
|
||||
}
|
||||
|
||||
void json_object_add_0nprix64(struct json_object *o, const char *k, uint64_t v, int width)
|
||||
{
|
||||
char str[STR_LEN];
|
||||
|
||||
sprintf(str, "0x%0*"PRIx64"", width, v);
|
||||
json_object_add_value_string(o, k, str);
|
||||
}
|
||||
|
|
61
util/json.h
61
util/json.h
|
@ -9,37 +9,34 @@
|
|||
/* Wrappers around json-c's API */
|
||||
|
||||
#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))
|
||||
#define json_object_add_value_int(o, k, v) \
|
||||
json_object_object_add(o, k, json_object_new_int(v))
|
||||
#define json_object_add_value_uint(o, k, v) json_object_object_add(o, k, json_object_new_uint64(v))
|
||||
#define json_object_add_value_int(o, k, v) json_object_object_add(o, k, json_object_new_int(v))
|
||||
#ifndef CONFIG_JSONC_14
|
||||
#define json_object_new_uint64(v) util_json_object_new_uint64(v)
|
||||
#define json_object_get_uint64(v) util_json_object_get_uint64(v)
|
||||
#endif
|
||||
#endif /* CONFIG_JSONC_14 */
|
||||
#define json_object_add_value_uint64(o, k, v) \
|
||||
json_object_object_add(o, k, json_object_new_uint64(v))
|
||||
#define json_object_add_value_uint128(o, k, v) \
|
||||
json_object_object_add(o, k, util_json_object_new_uint128(v))
|
||||
#define json_object_add_value_double(o, k, v) \
|
||||
json_object_object_add(o, k, util_json_object_new_double(v))
|
||||
#define json_object_add_value_float(o, k, v) \
|
||||
json_object_object_add(o, k, json_object_new_double(v))
|
||||
static inline int json_object_add_value_string(struct json_object *o, const char *k, const char *v) {
|
||||
#define json_object_add_value_float(o, k, v) json_object_object_add(o, k, json_object_new_double(v))
|
||||
|
||||
static inline int json_object_add_value_string(struct json_object *o, const char *k, const char *v)
|
||||
{
|
||||
return json_object_object_add(o, k, v ? json_object_new_string(v) : NULL);
|
||||
}
|
||||
#define json_object_add_value_array(o, k, v) \
|
||||
json_object_object_add(o, k, v)
|
||||
#define json_object_add_value_object(o, k, v) \
|
||||
json_object_object_add(o, k, v)
|
||||
#define json_array_add_value_object(o, k) \
|
||||
json_object_array_add(o, k)
|
||||
static inline int json_array_add_value_string(struct json_object *o, const char *v) {
|
||||
|
||||
#define json_array_add_value_object(o, k) json_object_array_add(o, k)
|
||||
|
||||
static inline int json_array_add_value_string(struct json_object *o, const char *v)
|
||||
{
|
||||
return json_object_array_add(o, v ? json_object_new_string(v) : NULL);
|
||||
}
|
||||
|
||||
#define json_print_object(o, u) \
|
||||
printf("%s", json_object_to_json_string_ext(o, \
|
||||
JSON_C_TO_STRING_PRETTY | \
|
||||
|
@ -51,13 +48,35 @@ struct json_object *util_json_object_new_uint128(nvme_uint128_t val);
|
|||
struct json_object *util_json_object_new_uint128(nvme_uint128_t val);
|
||||
|
||||
uint64_t util_json_object_get_uint64(struct json_object *obj);
|
||||
|
||||
#else /* !CONFIG_JSONC */
|
||||
|
||||
#else /* CONFIG_JSONC */
|
||||
struct json_object;
|
||||
|
||||
#define json_object_add_value_string(o, k, v)
|
||||
#define json_create_object(o) NULL
|
||||
#define json_free_object(o) ((void)(o))
|
||||
#define json_object_add_value_uint(o, k, v) ((void)(v))
|
||||
#define json_object_add_value_int(o, k, v) ((void)(v))
|
||||
#define json_object_add_value_uint64(o, k, v) ((void)(v))
|
||||
#define json_object_add_value_uint128(o, k, v)
|
||||
#define json_object_add_value_double(o, k, v)
|
||||
#define json_object_add_value_float(o, k, v)
|
||||
#define json_array_add_value_object(o, k) ((void)(k))
|
||||
#define json_print_object(o, u) ((void)(o))
|
||||
#define json_object_object_add(o, k, v) ((void)(v))
|
||||
#define json_object_new_int(v)
|
||||
#define json_object_new_array(a) NULL
|
||||
#define json_object_array_add(o, k) ((void)(k))
|
||||
#endif /* CONFIG_JSONC */
|
||||
|
||||
#endif
|
||||
#define json_create_array(a) json_object_new_array(a)
|
||||
#define json_object_add_value_array(o, k, v) json_object_object_add(o, k, v)
|
||||
#define json_object_add_value_object(o, k, v) json_object_object_add(o, k, v)
|
||||
|
||||
#endif
|
||||
void json_object_add_uint_02x(struct json_object *o, const char *k, __u32 v);
|
||||
void json_object_add_uint_0x(struct json_object *o, const char *k, __u32 v);
|
||||
void json_object_add_byte_array(struct json_object *o, const char *k, unsigned char *buf, int len);
|
||||
void json_object_add_nprix64(struct json_object *o, const char *k, uint64_t v);
|
||||
void json_object_add_uint_0nx(struct json_object *o, const char *k, __u32 v, int width);
|
||||
void json_object_add_0nprix64(struct json_object *o, const char *k, uint64_t v, int width);
|
||||
|
||||
#endif /* __JSON__H */
|
||||
|
|
|
@ -81,8 +81,9 @@ static void nvme_show_command64(struct nvme_passthru_cmd64 *cmd, int err)
|
|||
|
||||
static void nvme_show_latency(struct timeval start, struct timeval end)
|
||||
{
|
||||
printf("latency : %lu us\n",
|
||||
(end.tv_sec - start.tv_sec) * 1000000 + (end.tv_usec - start.tv_usec));
|
||||
printf("latency : %llu us\n",
|
||||
(unsigned long long)((end.tv_sec - start.tv_sec) * 1000000 +
|
||||
(end.tv_usec - start.tv_usec)));
|
||||
}
|
||||
|
||||
int nvme_submit_passthru(int fd, unsigned long ioctl_cmd,
|
||||
|
|
|
@ -5,10 +5,16 @@
|
|||
|
||||
#include <stdbool.h>
|
||||
|
||||
#define print_info(...) \
|
||||
do { \
|
||||
if (log_level >= LOG_INFO) \
|
||||
printf(__VA_ARGS__); \
|
||||
#define print_info(...) \
|
||||
do { \
|
||||
if (log_level >= LOG_INFO) \
|
||||
printf(__VA_ARGS__); \
|
||||
} while (false)
|
||||
|
||||
#define print_debug(...) \
|
||||
do { \
|
||||
if (log_level >= LOG_DEBUG) \
|
||||
printf(__VA_ARGS__); \
|
||||
} while (false)
|
||||
|
||||
extern int log_level;
|
||||
|
|
23
util/types.c
23
util/types.c
|
@ -5,6 +5,7 @@
|
|||
#include <string.h>
|
||||
#include <locale.h>
|
||||
#include <time.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include <ccan/endian/endian.h>
|
||||
|
||||
|
@ -36,18 +37,30 @@ long double int128_to_double(__u8 *data)
|
|||
return result;
|
||||
}
|
||||
|
||||
uint64_t int48_to_long(__u8 *data)
|
||||
static uint64_t int_to_long(int bits, const __u8 *data)
|
||||
{
|
||||
int i;
|
||||
uint64_t result = 0;
|
||||
int bytes = (bits + CHAR_BIT - 1) / CHAR_BIT;
|
||||
|
||||
for (i = 0; i < 6; i++) {
|
||||
result *= 256;
|
||||
result += data[5 - i];
|
||||
for (i = 0; i < bytes; i++) {
|
||||
result <<= CHAR_BIT;
|
||||
result += data[bytes - 1 - i];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
uint64_t int48_to_long(const __u8 *data)
|
||||
{
|
||||
return int_to_long(48, data);
|
||||
}
|
||||
|
||||
uint64_t int56_to_long(const __u8 *data)
|
||||
{
|
||||
return int_to_long(56, data);
|
||||
}
|
||||
|
||||
long double uint128_t_to_double(nvme_uint128_t data)
|
||||
{
|
||||
long double result = 0;
|
||||
|
@ -166,7 +179,7 @@ int convert_ts(time_t time, char *ts_buf)
|
|||
gmtime_r((const time_t *)&time_human, &time_info);
|
||||
|
||||
strftime(buf, sizeof(buf), "%Y-%m-%dD|%H:%M:%S", &time_info);
|
||||
sprintf(ts_buf, "%s:%03ld", buf, time_ms);
|
||||
sprintf(ts_buf, "%s:%03llu", buf, (unsigned long long)time_ms);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
|
||||
#define ABSOLUTE_ZERO_CELSIUS -273
|
||||
|
||||
#define STR_LEN 100
|
||||
|
||||
static inline long kelvin_to_celsius(long t)
|
||||
{
|
||||
return t + ABSOLUTE_ZERO_CELSIUS;
|
||||
|
@ -36,7 +38,8 @@ typedef union nvme_uint128 nvme_uint128_t;
|
|||
|
||||
nvme_uint128_t le128_to_cpu(__u8 *data);
|
||||
long double int128_to_double(__u8 *data);
|
||||
uint64_t int48_to_long(__u8 *data);
|
||||
uint64_t int48_to_long(const __u8 *data);
|
||||
uint64_t int56_to_long(const __u8 *data);
|
||||
|
||||
char *uint128_t_to_string(nvme_uint128_t val);
|
||||
char *uint128_t_to_l10n_string(nvme_uint128_t val);
|
||||
|
|
10
util/utils.c
10
util/utils.c
|
@ -138,7 +138,7 @@ unsigned char *read_binary_file(char *data_dir_path, const char *bin_path,
|
|||
|
||||
void print_formatted_var_size_str(const char *msg, const __u8 *pdata, size_t data_size, FILE *fp)
|
||||
{
|
||||
char description_str[256] = "";
|
||||
char description_str[1024] = "";
|
||||
char temp_buffer[3] = { 0 };
|
||||
|
||||
for (size_t i = 0; i < data_size; ++i) {
|
||||
|
@ -146,10 +146,10 @@ void print_formatted_var_size_str(const char *msg, const __u8 *pdata, size_t dat
|
|||
strcat(description_str, temp_buffer);
|
||||
}
|
||||
|
||||
if (fp)
|
||||
fprintf(fp, "%s: %s\n", msg, description_str);
|
||||
else
|
||||
printf("%s: %s\n", msg, description_str);
|
||||
if (!fp)
|
||||
fp = stdout;
|
||||
|
||||
fprintf(fp, "%s: %s\n", msg, description_str);
|
||||
}
|
||||
|
||||
void process_field_size_16(int offset, char *sfield, __u8 *buf, char *datastr)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue