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

split logging from root object #824

Merged
merged 3 commits into from
May 10, 2024
Merged

split logging from root object #824

merged 3 commits into from
May 10, 2024

Conversation

igaw
Copy link
Collaborator

@igaw igaw commented Apr 26, 2024

Let's refactor the logging out from the root object and accept the full defeat against no global variables fight.

src/nvme/mi.c Outdated Show resolved Hide resolved
src/nvme/tree.c Outdated Show resolved Hide resolved
Copy link
Contributor

@tbzatek tbzatek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I like it. It always puzzled me to have a global root object with dubious memory ownership, though the code appeared safe.

Don't worry too much about global variables, I have a similar mental block for goto... 😳

src/nvme/log.h Outdated Show resolved Hide resolved
src/nvme/log.h Outdated Show resolved Hide resolved
src/nvme/mi.c Outdated Show resolved Hide resolved
src/nvme/private.h Show resolved Hide resolved
src/nvme/tree.c Outdated Show resolved Hide resolved
@igaw
Copy link
Collaborator Author

igaw commented Apr 29, 2024

We do create multiple root objects in libblockdev since it's often used in threads and need separate memory objects. While not currently used, it might be useful to grab the log for certain operations and present it as a buffer back to the user (e.g. via D-Bus).

If I got you right, the idea is to introduce a global log buffer with multiple readers. This indeed would also solve the issue.

Besides, as backwards compatibility is concerned, I would keep it there. Reconsider later for libnvme 2.0?

Yeah, let's start with the default global logging fix here and see if anyone is really unhappy with it. We can discuss/play with the two idea (either introducing a library handle or your idea with a log buffer) for libnvme 2.0.

@tbzatek
Copy link
Contributor

tbzatek commented May 2, 2024

We do create multiple root objects in libblockdev since it's often used in threads and need separate memory objects. While not currently used, it might be useful to grab the log for certain operations and present it as a buffer back to the user (e.g. via D-Bus).

If I got you right, the idea is to introduce a global log buffer with multiple readers. This indeed would also solve the issue.

It was more an idea than any proposal and we don't plan to make use of anything like this in the near term.

To be precise, we need multiple root objects to be supported, due to threading. However logging is a different affair, at the moment we basically silence/disable libnvme logging in libblockdev and rely solely on error codes.

My only concern is that whenever a root object takes fp or log_level args via e.g. nvme_mi_create_root() or nvme_create_root() and global logging has been initialized already, it should not get overridden. I.e. either use the global logging only or keep it separate for each root object. Theoretically, in a process that pulls multiple libraries in that use libnvme for something, we don't want our global logging settings to be reset by a foreign library. No big deal though, just customers are sometimes picky with any single message on stderr. 😑

@martin-belanger
Copy link
Contributor

To be precise, we need multiple root objects to be supported, due to threading.

Just thought I'd chime in to say that threading is precisely why nvme-stas also requires multiple root objects.

Sort the entries alphabetically.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
Do not distribute the filtering over several places.

While at it also make it the arguments a bit more readable.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
src/nvme/log.c Outdated Show resolved Hide resolved
The original plan was to avoid any global variables in the library. Thus
the logging variables were tied to the root object which is available
via the fabric API.

The default NVME API doesn't have the root object thus we had to add a
global variable to set log level etc. But the API to set these variables
is done via the root object.

This approach enforces the caller side to create an default root object
to initialize the default logging level. This introduces unnecessary
complexity on the caller side and wastes resources.

Let's split the default logging setting from the root object.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
@igaw igaw merged commit bec7a98 into linux-nvme:master May 10, 2024
13 of 14 checks passed
@igaw igaw deleted the logging branch May 10, 2024 07:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants