POC: Add logging function callback#189
Conversation
|
Could resolve: #187 |
Add a logging function callback which is stored in nvme_root_t so that we don't have to have any global data. This is incomplete, do not merge! Signed-off-by: Tony Asleson <tasleson@redhat.com>
And the symbols: __nvme_get_log_page, __nvme_msg Signed-off-by: Tony Asleson <tasleson@redhat.com>
| char *tmp = strdup(src); | ||
| if (!tmp) | ||
| nvme_msg(LOG_ERR, "cannot copy: %s\n", src); | ||
| return -ENOMEM; // Just logging here looks like a bug |
There was a problem hiding this comment.
Yes, this should just return the error code.
| break; | ||
| default: | ||
| nvme_msg(LOG_ERR, "unexpected address family %d\n", af); | ||
| ret = -EINVAL; |
There was a problem hiding this comment.
I don't mind these error handling cleanups in inet*(). But it would be better to go into a separate patch.
| ret = -1; | ||
| } else { | ||
| nvme_msg(LOG_INFO, "nvme%d: ctrl connected\n", ret); | ||
| nvme_msg_n(c->s->h->r, LOG_INFO, "nvme%d: ctrl connected\n", ret); |
There was a problem hiding this comment.
Indeed, looks a bit ugly. Though I don't have a good idea how to do it differently.
| @@ -1,7 +1,5 @@ | |||
| LIBNVME_1_0 { | |||
| global: | |||
| __nvme_get_log_page; | |||
There was a problem hiding this comment.
You can't remove this one. This is a public function (even documented) see
Line 83 in 5aea021
Bad name. We should rename it. Though I don't have a better name yet.
|
Interesting concept, however to be really useful I would need a context passed to |
Your original comment on this #160 (comment) didn't have user supplied data. We could add a user supplied data pointer when registering the callback and store it in the |
|
Yes, my original proposal was about general logging function with no context as everything was on a global level. But now since you would be operating on a local
Not necessarily but I understood it should be a good practice. However heavy async app may create |
I believe we are in agreement that a single If/when I update this PR I'll include a user supplied data pointer. I can see how that would be beneficial in a multi-threaded app. |
|
Can you check PR #202 ? That does most what you want; if needed we could even add a logging function callback to nvme_root_t, but I guess with being able to redirect the message logging to a different filedescriptor we should be mostly there. |
|
Let's close this PR as we have some good progress in #202. |
I spent some time today exploring if have a call back function which was embedded in the
nvme_root_tto prevent global data would be possible. This is rough, and incomplete, and not even run once for testing.I created a macro
nvme_msg_nwhich takes an additional argument which is thenvme_root_tpointer. In some cases its use is pretty clean:In other cases, kind of ugly and I'm not even sure if all the embedded pointers are correctly setup for the context.
In some other cases we have nothing existing to get a handle to the
nvme_root_t, so I added an argument to the function. In other cases I just removed the logging and returned an error code.At the moment I'm not sure how to make this cleaner. Thoughts, suggestions?