Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions fabrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "fabrics.h"
#include "util/cleanup.h"
#include "util/logging.h"
#include "util/sighdl.h"

#define PATH_NVMF_DISC SYSCONFDIR "/nvme/discovery.conf"
#define PATH_NVMF_CONFIG SYSCONFDIR "/nvme/config.json"
Expand Down Expand Up @@ -170,6 +171,22 @@ static int set_discovery_kato(struct nvme_fabrics_config *cfg)
return tmo;
}


static int nvme_add_ctrl(nvme_host_t h, nvme_ctrl_t c,
struct nvme_fabrics_config *cfg)
{
int ret;

retry:
ret = nvmf_add_ctrl(h, c, cfg);
if (ret == EAGAIN || (ret == EINTR && !nvme_sigint_received)) {
printf("nvmf_add_ctrl returned '%s'\n", strerror(ret));
goto retry;
}

return ret;
}

static nvme_ctrl_t __create_discover_ctrl(nvme_root_t r, nvme_host_t h,
struct nvme_fabrics_config *cfg,
struct tr_config *trcfg)
Expand All @@ -189,7 +206,7 @@ static nvme_ctrl_t __create_discover_ctrl(nvme_root_t r, nvme_host_t h,
tmo = set_discovery_kato(cfg);

errno = 0;
ret = nvmf_add_ctrl(h, c, cfg);
ret = nvme_add_ctrl(h, c, cfg);

cfg->keep_alive_tmo = tmo;
if (ret) {
Expand Down Expand Up @@ -1103,7 +1120,7 @@ int nvmf_connect(const char *desc, int argc, char **argv)
nvme_parse_tls_args(keyring, tls_key, tls_key_identity, &cfg, c);

errno = 0;
ret = nvmf_add_ctrl(h, c, &cfg);
ret = nvme_add_ctrl(h, c, &cfg);
if (ret)
fprintf(stderr, "could not add new controller: %s\n",
nvme_strerror(errno));
Expand Down
22 changes: 10 additions & 12 deletions nvme.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#include "util/argconfig.h"
#include "util/suffix.h"
#include "util/logging.h"
#include "util/sighdl.h"
#include "fabrics.h"
#define CREATE_CMD
#include "nvme-builtin.h"
Expand Down Expand Up @@ -4437,21 +4438,16 @@ static int list_secondary_ctrl(int argc, char **argv, struct command *cmd, struc
return err;
}

static void intr_self_test(int signum)
{
printf("\nInterrupted device self-test operation by %s\n", strsignal(signum));

errno = EINTR;
}

static int sleep_self_test(unsigned int seconds)
{
errno = 0;
nvme_sigint_received = false;

sleep(seconds);

if (errno)
return -errno;
if (nvme_sigint_received) {
printf("\nInterrupted device self-test operation by SIGINT\n");
return -SIGINT;
}

return 0;
}
Expand All @@ -4464,8 +4460,6 @@ static int wait_self_test(struct nvme_dev *dev)
int err, i = 0, p = 0, cnt = 0;
int wthr;

signal(SIGINT, intr_self_test);

ctrl = nvme_alloc(sizeof(*ctrl));
if (!ctrl)
return -ENOMEM;
Expand Down Expand Up @@ -10935,6 +10929,10 @@ int main(int argc, char **argv)
}
setlocale(LC_ALL, "");

err = nvme_install_sigint_handler();
if (err)
return err;

err = handle_plugin(argc - 1, &argv[1], nvme.extensions);
if (err == -ENOTTY)
general_help(&builtin, NULL);
Expand Down
2 changes: 1 addition & 1 deletion subprojects/libnvme.wrap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[wrap-git]
url = https://github.com/linux-nvme/libnvme.git
revision = 81bd404245823763121278fdd5f01c8177e81218
revision = 9851832179b622019c90b5b1fa243ccbec2d7477

[provide]
libnvme = libnvme_dep
Expand Down
29 changes: 26 additions & 3 deletions util/logging.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// SPDX-License-Identifier: GPL-2.0-or-later

#include <inttypes.h>

#include <signal.h>
#include <stdint.h>
#include <string.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <sys/syslog.h>
#include <sys/time.h>
Expand All @@ -11,6 +13,7 @@
#include <libnvme.h>

#include "logging.h"
#include "sighdl.h"

int log_level;
static bool dry_run;
Expand Down Expand Up @@ -92,6 +95,14 @@ static void nvme_show_latency(struct timeval start, struct timeval end)
(end.tv_usec - start.tv_usec)));
}

static void nvme_log_retry(int errnum)
{
if (log_level < LOG_DEBUG)
return;

printf("passthru command returned '%s'\n", strerror(errnum));
}

int nvme_submit_passthru(int fd, unsigned long ioctl_cmd,
struct nvme_passthru_cmd *cmd, __u32 *result)
{
Expand All @@ -102,8 +113,14 @@ int nvme_submit_passthru(int fd, unsigned long ioctl_cmd,
if (log_level >= LOG_DEBUG)
gettimeofday(&start, NULL);

if (!dry_run)
if (!dry_run) {
retry:
err = ioctl(fd, ioctl_cmd, cmd);
if (err == EAGAIN || (err == EINTR && !nvme_sigint_received)) {
nvme_log_retry(err);
goto retry;
}
}

if (log_level >= LOG_DEBUG) {
gettimeofday(&end, NULL);
Expand All @@ -128,8 +145,14 @@ int nvme_submit_passthru64(int fd, unsigned long ioctl_cmd,
if (log_level >= LOG_DEBUG)
gettimeofday(&start, NULL);

if (!dry_run)
if (!dry_run) {
retry:
err = ioctl(fd, ioctl_cmd, cmd);
if (err == EAGAIN || (err == EINTR && !nvme_sigint_received)) {
nvme_log_retry(err);
goto retry;
}
}

if (log_level >= LOG_DEBUG) {
gettimeofday(&end, NULL);
Expand Down
1 change: 1 addition & 0 deletions util/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ sources += [
'util/crc32.c',
'util/logging.c',
'util/mem.c',
'util/sighdl.c',
'util/suffix.c',
'util/types.c',
'util/utils.c'
Expand Down
27 changes: 27 additions & 0 deletions util/sighdl.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-License-Identifier: GPL-2.0-only
#include <signal.h>
#include <errno.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 changes: 11 additions & 0 deletions util/sighdl.h
Original file line number Diff line number Diff line change
@@ -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