Skip to content

Commit 66b7eac

Browse files
committed
nvme: add show-topology command delay option
This is to monitor the topology information changes. Signed-off-by: Tokunori Ikegami <[email protected]>
1 parent 270e812 commit 66b7eac

8 files changed

Lines changed: 437 additions & 8 deletions

File tree

meson.build

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,21 @@ conf.set(
272272
),
273273
description: 'Does struct tm have a tm_gmtoff field?'
274274
)
275+
conf.set(
276+
'HAVE_STDOUT_TO_SET',
277+
cc.compiles(
278+
'''
279+
#include <stdio.h>
280+
int main(void) {
281+
char *buf;
282+
size_t len;
283+
stdout = open_memstream(&buf, &len);
284+
}
285+
''',
286+
name: 'stdout_to_set'
287+
),
288+
description: 'Is stdout to set a mstream available?'
289+
)
275290

276291
if cc.has_function_attribute('fallthrough')
277292
conf.set('fallthrough', '__attribute__((__fallthrough__))')

nvme.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <stdio.h>
3838
#include <stdlib.h>
3939
#include <string.h>
40+
#include <time.h>
4041
#include <unistd.h>
4142

4243
#include <linux/fs.h>
@@ -65,6 +66,7 @@
6566
#include "util/suffix.h"
6667
#include "logging.h"
6768
#include "util/sighdl.h"
69+
#include "util/delay.h"
6870
#include "fabrics.h"
6971
#define CREATE_CMD
7072
#include "nvme-builtin.h"
@@ -185,6 +187,7 @@ static struct program nvme = {
185187
};
186188

187189
const char *uuid_index = "UUID index";
190+
const char *delay = "iterative delay as SECS [.TENTHS]";
188191

189192
static const char *app_tag = "app tag for end-to-end PI";
190193
static const char *app_tag_mask = "app tag mask for end-to-end PI";
@@ -370,7 +373,7 @@ static int parse_args(int argc, char *argv[], const char *desc,
370373

371374
log_level = map_log_level(nvme_args.verbose, false);
372375

373-
return 0;
376+
return ret = delay_set_stdout_file(&nvme_args.delay);
374377
}
375378

376379
int parse_and_open(struct nvme_global_ctx **ctx,
@@ -10367,9 +10370,10 @@ static int show_topology_cmd(int argc, char **argv, struct command *acmd, struct
1036710370
};
1036810371

1036910372
NVME_ARGS(opts,
10370-
OPT_FMT("ranking", 'r', &cfg.ranking, ranking));
10373+
OPT_FMT("ranking", 'r', &cfg.ranking, ranking),
10374+
OPT_DOUBLE("delay", 'd', &nvme_args.delay.time, delay));
1037110375

10372-
err = argconfig_parse(argc, argv, desc, opts);
10376+
err = parse_args(argc, argv, desc, opts);
1037310377
if (err)
1037410378
return err;
1037510379

@@ -11300,9 +11304,11 @@ int main(int argc, char **argv)
1130011304
if (err)
1130111305
return err;
1130211306

11303-
err = handle_plugin(argc - 1, &argv[1], nvme.extensions);
11304-
if (err == -ENOTTY)
11305-
general_help(&builtin, NULL);
11307+
do {
11308+
err = handle_plugin(argc - 1, &argv[1], nvme.extensions);
11309+
if (err == -ENOTTY)
11310+
general_help(&builtin, NULL);
11311+
} while (!err && delay_handle(&nvme_args.delay));
1130611312

1130711313
return err ? 1 : 0;
1130811314
}

nvme.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "util/argconfig.h"
3434
#include "util/cleanup.h"
3535
#include "util/types.h"
36+
#include "util/delay.h"
3637

3738
enum nvme_print_flags {
3839
NORMAL = 0,
@@ -61,6 +62,7 @@ struct nvme_args {
6162
bool no_retries;
6263
bool no_ioctl_probing;
6364
unsigned int output_format_ver;
65+
struct delay_args delay;
6466
};
6567

6668
#ifdef CONFIG_JSONC
@@ -120,6 +122,7 @@ static inline DEFINE_CLEANUP_FUNC(
120122
#define _cleanup_nvme_transport_handle_ __cleanup__(cleanup_nvme_transport_handle)
121123

122124
extern const char *uuid_index;
125+
extern const char *delay;
123126
extern struct nvme_args nvme_args;
124127

125128
int validate_output_format(const char *format, nvme_print_flags_t *flags);

0 commit comments

Comments
 (0)