Skip to content

Commit 87feebd

Browse files
committed
log: remove deprecated default global context functions
The global context has been introduced throughout the library thus we don't need the fallback default global context anymore. Signed-off-by: Daniel Wagner <wagi@kernel.org>
1 parent 2c7174f commit 87feebd

File tree

5 files changed

+14
-96
lines changed

5 files changed

+14
-96
lines changed

libnvme/src/libnvme.ld

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,10 @@ LIBNVME_2_0 {
8181
nvme_get_attr;
8282
nvme_get_ctrl_attr;
8383
nvme_get_ctrl_telemetry;
84-
nvme_get_debug;
8584
nvme_get_directive_receive_length;
8685
nvme_get_feature_length;
8786
nvme_get_host_telemetry;
8887
nvme_get_log;
89-
nvme_get_logging_level;
9088
nvme_get_logical_block_size;
9189
nvme_get_new_host_telemetry;
9290
nvme_get_ns_attr;
@@ -118,7 +116,6 @@ LIBNVME_2_0 {
118116
nvme_init_copy_range_f3;
119117
nvme_init_ctrl;
120118
nvme_init_ctrl_list;
121-
nvme_init_default_logging;
122119
nvme_init_dsm_range;
123120
nvme_init_logging;
124121
nvme_insert_tls_key;
@@ -230,7 +227,6 @@ LIBNVME_2_0 {
230227
nvme_scan_tls_keys;
231228
nvme_scan_topology;
232229
nvme_set_application;
233-
nvme_set_debug;
234230
nvme_set_dry_run;
235231
nvme_set_etdas;
236232
nvme_set_keyring;

libnvme/src/nvme/log.c

Lines changed: 8 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@
1010

1111
#include <sys/types.h>
1212
#include <stdio.h>
13-
#include <stdlib.h>
1413
#include <stdarg.h>
1514
#include <stdbool.h>
1615
#include <syslog.h>
1716
#include <unistd.h>
1817
#include <time.h>
19-
#include <string.h>
2018
#define LOG_FUNCNAME 1
2119
#include "private.h"
2220
#include "log.h"
@@ -26,18 +24,11 @@
2624
#define LOG_CLOCK CLOCK_MONOTONIC
2725
#endif
2826

29-
static struct nvme_log def_log = {
30-
.fd = STDERR_FILENO,
31-
.level = DEFAULT_LOGLEVEL,
32-
.pid = false,
33-
.timestamp = false,
34-
};
35-
3627
void __attribute__((format(printf, 4, 5)))
3728
__nvme_msg(struct nvme_global_ctx *ctx, int level,
3829
const char *func, const char *format, ...)
3930
{
40-
struct nvme_log *l;
31+
struct nvme_log *l = &ctx->log;
4132
va_list ap;
4233
char pidbuf[16];
4334
char timebuf[32];
@@ -55,11 +46,6 @@ __nvme_msg(struct nvme_global_ctx *ctx, int level,
5546
_cleanup_free_ char *message = NULL;
5647
int idx = 0;
5748

58-
if (ctx)
59-
l = &ctx->log;
60-
else
61-
l = &def_log;
62-
6349
if (level > l->level)
6450
return;
6551

@@ -96,51 +82,20 @@ __nvme_msg(struct nvme_global_ctx *ctx, int level,
9682
message ? message : "<error>");
9783
}
9884

99-
void nvme_init_logging(struct nvme_global_ctx *ctx, int lvl, bool log_pid, bool log_tstamp)
85+
void nvme_init_logging(struct nvme_global_ctx *ctx, int lvl,
86+
bool log_pid, bool log_tstamp)
10087
{
10188
ctx->log.level = lvl;
10289
ctx->log.pid = log_pid;
10390
ctx->log.timestamp = log_tstamp;
10491
}
10592

106-
int nvme_get_logging_level(struct nvme_global_ctx *ctx, bool *log_pid, bool *log_tstamp)
93+
int nvme_get_logging_level(struct nvme_global_ctx *ctx,
94+
bool *log_pid, bool *log_tstamp)
10795
{
108-
struct nvme_log *l;
109-
110-
if (ctx)
111-
l = &ctx->log;
112-
else
113-
l = &def_log;
114-
11596
if (log_pid)
116-
*log_pid = l->pid;
97+
*log_pid = ctx->log.pid;
11798
if (log_tstamp)
118-
*log_tstamp = l->timestamp;
119-
return l->level;
120-
}
121-
122-
void nvme_init_default_logging(FILE *fp, int level, bool log_pid, bool log_tstamp)
123-
{
124-
def_log.fd = fileno(fp);
125-
def_log.level = level;
126-
def_log.pid = log_pid;
127-
def_log.timestamp = log_tstamp;
128-
}
129-
130-
void nvme_set_global_ctx(struct nvme_global_ctx *ctx)
131-
{
132-
def_log.fd = ctx->log.fd;
133-
def_log.level = ctx->log.level;
134-
def_log.pid = ctx->log.pid;
135-
def_log.timestamp = ctx->log.timestamp;
136-
}
137-
138-
void nvme_set_debug(bool debug)
139-
{
140-
def_log.level = debug ? LOG_DEBUG : DEFAULT_LOGLEVEL;
141-
}
142-
143-
bool nvme_get_debug(void)
144-
{
145-
return def_log.level == LOG_DEBUG;
99+
*log_tstamp = ctx->log.timestamp;
100+
return ctx->log.level;
146101
}

libnvme/src/nvme/log.h

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
*
3434
* Sets the default logging variables for the library.
3535
*/
36-
void nvme_init_logging(struct nvme_global_ctx *ctx, int lvl, bool log_pid, bool log_tstamp);
36+
void nvme_init_logging(struct nvme_global_ctx *ctx, int lvl,
37+
bool log_pid, bool log_tstamp);
3738

3839
/**
3940
* nvme_init_default_logging() - Initialize default (fallback) logging
@@ -45,7 +46,8 @@ void nvme_init_logging(struct nvme_global_ctx *ctx, int lvl, bool log_pid, bool
4546
* Sets the default logging settings for the library in case the root object
4647
* is absent.
4748
*/
48-
void nvme_init_default_logging(FILE *fp, int lvl, bool log_pid, bool log_tstamp);
49+
void nvme_init_default_logging(FILE *fp, int lvl, bool log_pid,
50+
bool log_tstamp);
4951

5052
/**
5153
* nvme_get_logging_level() - Get current logging level
@@ -59,40 +61,7 @@ void nvme_init_default_logging(FILE *fp, int lvl, bool log_pid, bool log_tstamp)
5961
*
6062
* Return: current log level value or DEFAULT_LOGLEVEL if not initialized.
6163
*/
62-
int nvme_get_logging_level(struct nvme_global_ctx *ctx, bool *log_pid, bool *log_tstamp);
63-
64-
/**
65-
* nvme_set_global_ctx() - Set global context
66-
* @ctx: struct nvme_global_ctx object
67-
*
68-
* In order to be able to log from code paths where no global context
69-
* object is passed in via the arguments use the the default one which
70-
* can be set via this call. When creating a new global context object
71-
* with @nvme_create_global_ctx the global context object will be set as
72-
* well. This means the global context object is always pointing to the
73-
* latest created global context object. Note the first
74-
* @nvme_free_global_ctx call will reset the global context object.
75-
*
76-
* This function is deprecated. Use nvme_init_default_logging or/and
77-
* nvme_init_logging instead.
78-
*/
79-
void nvme_set_global_ctx(struct nvme_global_ctx *ctx) __attribute__((deprecated));
80-
81-
/**
82-
* nvme_set_debug - Set NVMe command debugging output
83-
* @debug: true to enable or false to disable
84-
*
85-
* This function is deprecated. Use nvme_init_default_logging instead.
86-
*/
87-
void nvme_set_debug(bool debug) __attribute__((deprecated));
88-
89-
/**
90-
* nvme_get_debug - Get NVMe command debugging output
91-
*
92-
* This function is deprecated. Use nvme_get_logging_level instead.
93-
*
94-
* Return: false if disabled or true if enabled.
95-
*/
96-
bool nvme_get_debug(void) __attribute__((deprecated));
64+
int nvme_get_logging_level(struct nvme_global_ctx *ctx, bool *log_pid,
65+
bool *log_tstamp);
9766

9867
#endif /* _LOG_H */

nvme.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,6 @@ static int parse_args(int argc, char *argv[], const char *desc,
372372
return ret;
373373

374374
log_level = map_log_level(nvme_cfg.verbose, false);
375-
nvme_init_default_logging(stderr, log_level, false, false);
376375

377376
return 0;
378377
}

plugins/nbft/nbft-plugin.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,6 @@ int show_nbft(int argc, char **argv, struct command *acmd, struct plugin *plugin
559559
return ret;
560560

561561
log_level = map_log_level(verbose, false /* quiet */);
562-
nvme_init_default_logging(stderr, log_level, false, false);
563562

564563
ret = validate_output_format(format, &flags);
565564
if (ret < 0)

0 commit comments

Comments
 (0)