1
0
Fork 0

Merging upstream version 2.14.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-05-22 13:00:36 +02:00
parent 0d9181726f
commit f268303a51
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
572 changed files with 4636 additions and 1730 deletions

View file

@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include <stdio.h>
#include <errno.h>
#include <stdarg.h>
#include "json.h"
#include "types.h"
@ -135,3 +136,18 @@ void json_object_add_0nprix64(struct json_object *o, const char *k, uint64_t v,
sprintf(str, "0x%0*"PRIx64"", width, v);
json_object_add_value_string(o, k, str);
}
void json_object_add_string(struct json_object *o, const char *k, const char *format, ...)
{
_cleanup_free_ char *value = NULL;
va_list ap;
va_start(ap, format);
if (vasprintf(&value, format, ap) < 0)
value = NULL;
json_object_add_value_string(o, k, value ? value : "Could not allocate string");
va_end(ap);
}

View file

@ -78,5 +78,6 @@ void json_object_add_byte_array(struct json_object *o, const char *k, unsigned c
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);
void json_object_add_string(struct json_object *o, const char *k, const char *format, ...);
#endif /* __JSON__H */

View file

@ -1,137 +0,0 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include <inttypes.h>
#include <stdint.h>
#include <sys/ioctl.h>
#include <sys/syslog.h>
#include <sys/time.h>
#include <linux/types.h>
#include <libnvme.h>
#include "logging.h"
int log_level;
int map_log_level(int verbose, bool quiet)
{
int log_level;
/*
* LOG_NOTICE is unused thus the user has to provide two 'v' for getting
* any feedback at all. Thus skip this level
*/
verbose++;
switch (verbose) {
case 0:
log_level = LOG_WARNING;
break;
case 1:
log_level = LOG_NOTICE;
break;
case 2:
log_level = LOG_INFO;
break;
default:
log_level = LOG_DEBUG;
break;
}
if (quiet)
log_level = LOG_ERR;
return log_level;
}
static void nvme_show_common(struct nvme_passthru_cmd *cmd)
{
printf("opcode : %02x\n", cmd->opcode);
printf("flags : %02x\n", cmd->flags);
printf("rsvd1 : %04x\n", cmd->rsvd1);
printf("nsid : %08x\n", cmd->nsid);
printf("cdw2 : %08x\n", cmd->cdw2);
printf("cdw3 : %08x\n", cmd->cdw3);
printf("data_len : %08x\n", cmd->data_len);
printf("metadata_len : %08x\n", cmd->metadata_len);
printf("addr : %"PRIx64"\n", (uint64_t)(uintptr_t)cmd->addr);
printf("metadata : %"PRIx64"\n", (uint64_t)(uintptr_t)cmd->metadata);
printf("cdw10 : %08x\n", cmd->cdw10);
printf("cdw11 : %08x\n", cmd->cdw11);
printf("cdw12 : %08x\n", cmd->cdw12);
printf("cdw13 : %08x\n", cmd->cdw13);
printf("cdw14 : %08x\n", cmd->cdw14);
printf("cdw15 : %08x\n", cmd->cdw15);
printf("timeout_ms : %08x\n", cmd->timeout_ms);
}
static void nvme_show_command(struct nvme_passthru_cmd *cmd, int err)
{
nvme_show_common(cmd);
printf("result : %08x\n", cmd->result);
printf("err : %d\n", err);
}
static void nvme_show_command64(struct nvme_passthru_cmd64 *cmd, int err)
{
nvme_show_common((struct nvme_passthru_cmd *)cmd);
printf("result : %"PRIx64"\n", (uint64_t)(uintptr_t)cmd->result);
printf("err : %d\n", err);
}
static void nvme_show_latency(struct timeval start, struct timeval end)
{
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,
struct nvme_passthru_cmd *cmd, __u32 *result)
{
struct timeval start;
struct timeval end;
int err;
if (log_level >= LOG_DEBUG)
gettimeofday(&start, NULL);
err = ioctl(fd, ioctl_cmd, cmd);
if (log_level >= LOG_DEBUG) {
gettimeofday(&end, NULL);
nvme_show_command(cmd, err);
nvme_show_latency(start, end);
}
if (err >= 0 && result)
*result = cmd->result;
return err;
}
int nvme_submit_passthru64(int fd, unsigned long ioctl_cmd,
struct nvme_passthru_cmd64 *cmd,
__u64 *result)
{
struct timeval start;
struct timeval end;
int err;
if (log_level >= LOG_DEBUG)
gettimeofday(&start, NULL);
err = ioctl(fd, ioctl_cmd, cmd);
if (log_level >= LOG_DEBUG) {
gettimeofday(&end, NULL);
nvme_show_command64(cmd, err);
nvme_show_latency(start, end);
}
if (err >= 0 && result)
*result = cmd->result;
return err;
}

View file

@ -1,24 +0,0 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
#ifndef DEBUG_H_
#define DEBUG_H_
#include <stdbool.h>
#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;
int map_log_level(int verbose, bool quiet);
#endif // DEBUG_H_

View file

@ -4,8 +4,8 @@ sources += [
'util/argconfig.c',
'util/base64.c',
'util/crc32.c',
'util/logging.c',
'util/mem.c',
'util/sighdl.c',
'util/suffix.c',
'util/types.c',
'util/utils.c'

28
util/sighdl.c Normal file
View file

@ -0,0 +1,28 @@
// SPDX-License-Identifier: GPL-2.0-only
#include <signal.h>
#include <errno.h>
#include <stddef.h>
#include "sighdl.h"
bool nvme_sigint_received;
static void nvme_sigint_handler(int signum)
{
nvme_sigint_received = true;
}
int nvme_install_sigint_handler(void)
{
struct sigaction act;
sigemptyset(&act.sa_mask);
act.sa_handler = nvme_sigint_handler;
act.sa_flags = 0;
nvme_sigint_received = false;
if (sigaction(SIGINT, &act, NULL) == -1)
return -errno;
return 0;
}

11
util/sighdl.h Normal file
View file

@ -0,0 +1,11 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
#ifndef __NVME_SIGHDL
#define __NVME_SIGHDL
#include <stdbool.h>
extern bool nvme_sigint_received;
int nvme_install_sigint_handler(void);
#endif // __NVME_SIGHDL