Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nbft: Refactor use of nvme_msg in nbft.c #669

Merged
merged 1 commit into from
Sep 20, 2023
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
5 changes: 3 additions & 2 deletions src/libnvme.map
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ LIBNVME_1_6 {
nvme_ctrl_find;
nvme_ctrl_get_src_addr;
nvme_ctrl_release_fd;
nvme_get_debug;
nvme_get_features_err_recovery2;
nvme_get_features_host_mem_buf2;
nvme_get_features_iocs_profile;
Expand All @@ -14,14 +15,14 @@ LIBNVME_1_6 {
nvme_host_release_fds;
nvme_ns_release_fd;
nvme_root_release_fds;
nvme_set_debug;
nvme_set_features_iocs_profile;
nvme_set_features_resv_mask2;
nvme_set_features_resv_persist2;
nvme_set_features_write_protect2;
nvme_set_root;
nvme_subsystem_get_iopolicy;
nvme_subsystem_release_fds;
nvme_set_debug;
nvme_get_debug;
};

LIBNVME_1_5 {
Expand Down
15 changes: 14 additions & 1 deletion src/nvme/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@
#define LOG_CLOCK CLOCK_MONOTONIC
#endif

static nvme_root_t root;

void __attribute__((format(printf, 4, 5)))
__nvme_msg(nvme_root_t r, int lvl,
const char *func, const char *format, ...)
{
FILE *fp = r ? r->fp : stderr;
FILE *fp = stderr;
va_list ap;
char pidbuf[16];
char timebuf[32];
Expand All @@ -48,6 +50,12 @@ __nvme_msg(nvme_root_t r, int lvl,
char *message __cleanup__(cleanup_charp) = NULL;
int idx = 0;

if (!r)
r = root;

if (r)
fp = r->fp;

if (r && lvl > r->log_level)
return;

Expand Down Expand Up @@ -90,3 +98,8 @@ void nvme_init_logging(nvme_root_t r, int lvl, bool log_pid, bool log_tstamp)
r->log_pid = log_pid;
r->log_timestamp = log_tstamp;
}

void nvme_set_root(nvme_root_t r)
{
root = r;
}
13 changes: 13 additions & 0 deletions src/nvme/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,17 @@
*/
void nvme_init_logging(nvme_root_t r, int lvl, bool log_pid, bool log_tstamp);

/**
* nvme_set_root() - Set nvme_root_t context
* @r: nvme_root_t context
*
* In order to be able to log from code paths where no root object is passed in
* via the arguments use the the default one which can be set via this call.
* When creating a new root object with @nvme_create_root the global root object
* will be set as well. This means the global root object is always pointing to
* the latest created root object. Note the first @nvme_free_tree call will reset
* the global root object.
*/
void nvme_set_root(nvme_root_t r);

#endif /* _LOG_H */
2 changes: 2 additions & 0 deletions src/nvme/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ nvme_root_t nvme_create_root(FILE *fp, int log_level)
r->fp = fp;
list_head_init(&r->hosts);
list_head_init(&r->endpoints);
nvme_set_root(r);
return r;
}

Expand Down Expand Up @@ -364,6 +365,7 @@ void nvme_free_tree(nvme_root_t r)
free(r->config_file);
if (r->application)
free(r->application);
nvme_set_root(NULL);
free(r);
}

Expand Down