Skip to content

WIP: make rasdaemon more modular and add support to use other databases - #258

Draft
mchehab wants to merge 86 commits into
masterfrom
next
Draft

WIP: make rasdaemon more modular and add support to use other databases#258
mchehab wants to merge 86 commits into
masterfrom
next

Conversation

@mchehab

@mchehab mchehab commented Aug 8, 2026

Copy link
Copy Markdown
Owner

In preparation for rasdaemon version 1.0.0, improve its internal architecture.

Goals:

  • make rasdaemon modular;
  • allow using more databases;
  • add unit tests

Updates:

  • mysql support added;
  • postgresql support added;
  • sqlite3, mysql and postgresql unit tests passed;
  • converted to use meson instead of auto-tools;
  • CI jobs adjusted to use meson and all off them passes;
  • Improved README.md file content.

I appreciate feedbacks and PRs against the next branch to help with the redesign.

mchehab added 10 commits August 8, 2026 13:36
Right now, the DB logic was written to support only sqlite3.
As we're aiming to add support for other databases, use a more
generic way to describe DB fields.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Convert sqlite3-specific bindings into a generic one inside
ras-record, to allow adding support later for other databases.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
In preparation for adding support to other databases, don't
keep any sqlite3 stuff outside ras-record.

For now, we'll keep HAVE_SQLITE3 as an intermediate step,
as right now the only SQL supported database is sqlite3.

In the future, this will be broken on two separate fields,
and the checks inside each rasdaemon file will disapear, as
the SQL backend core will take care of it.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Those should be 644, not 755.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Right now, rasdaemon is only partially modular: at build time,
each individual feature can be selected and added, but the code
requires lots of ifdefs.

This worked fine at the beginning when there weren't much options,
but now the code has lots of optional features. Use a more modular
design by adding a module register logic.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
As the project grew, there are now too much files at the
core directory, making harder to maintain.

Move them to subdirs.

No functional changes.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Make it more generic, aiming to allow automatic module load
via __attribute__((constructor)).

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
As we're aiming to let module registration to happen in any
order, make the logic deterministic by inserting modules in
alphabetic order.

This makes insert being O(n) instead of O(1), but performance
here is not a problem.

While here, fix a bug when checking if allocation succeded.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
While the code compiles, it fails at the test cases.

Fix the issues.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Add unit tests to check if modules logic works.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
mchehab added 4 commits August 9, 2026 11:57
Allow modules to optionally set a private data and ensure that
cleanup will receive enough context.

This is needed to check modules functionality via unit tests,
and could help to ensure that cleanup will do the right thing.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Ensure that init and cleanup logic will work as expected.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Instead of relying on manual conference, check programaticly
if module cleanups will happen at the expected way.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
When doing unit tests, it doesn't make any sense to write at
syslog. Also, on success, the normal behavior is to just mask
the error output.

Implement support for it and modify tests/test-modules to
use such feature.

After such change, a successful run will be cleaner:

	Testing modules functionality:
	01/06:   Running NULL entry
	02/06:   Running single module
	03/06:   Running modules in order
	04/06:   Running modules out of order
	05/06:   Running multiple levels
	06/06:   Running init/cleanup
	All module registration tests passed.

And if the logs are always shown, there will be a tab on
each new line, which will produce a better visual output
as well:

	Testing modules functionality:
	01/06:   Running NULL entry
        module entry is missing!
	02/06:   Running single module
	03/06:   Running modules in order
	04/06:   Running modules out of order
	05/06:   Running multiple levels
	06/06:   Running init/cleanup
	        module alpha enabled
	        module charlie enabled
	        module foxtrot enabled
	        module delta enabled
	        module echo enabled
	        module beta enabled
	All module registration tests passed.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Move all sqlite3-specific logit to db/ras-db, preparing the code
to support other databases in the future.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
change the namespace for all database-related ops.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Use kernel-doc style markups to document the database
generic interface.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
The code there contains only sqlite3 specifics. Rename it to
better reflect its content.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
In preparation to support other database types, add an
abstraction layer.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
As the idea is to make the logic more modular to give more
flexibility and remove ifdef code from rasdaemon, move
the DB backend initialization to be done via module register.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Forgot to add ras-db code on a previous commit.

While here, update .gitignore.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
This is useful for unit tests.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
@mchehab
mchehab force-pushed the next branch 2 times, most recently from 45e9484 to 38bf93a Compare August 11, 2026 12:01
Add a way to check if db-sqlite3 implementation is working.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
The logic inside ras-db to pick the next backend is moving the
pointer twice, producing sigfaults.

While here, do a couple of cleanups.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
@mchehab
mchehab force-pushed the next branch 9 times, most recently from b15e0ba to 110ef8b Compare August 18, 2026 08:08
Ensure that the build and SRPMS/ directories will be removed.
While here, also remove m4/ directory.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Use a more canonical identation format, as given by yamlfmt.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Now that we have a generic interface, add PostgreSQL support.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
let CI do unit tests for PostgreSQL as well.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Database setup is somewhat complex. Add a set of instructions about
it.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
There are some code there which should be compiled only if
a database backend is selected.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
As there are now multiple database backends, use the generic
HAVE_DB to ensure that the code will work with any backend.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
mchehab added 10 commits August 18, 2026 17:10
Until this change, rasdaemon had an env file stored under:
	/etc/sysconfig/rasdaemon.env

However, the content of this file was never read. Also, it
doesn't follow the way other files are stored there: without
a .env suffix.

Change the logic to make rasdaemon to automatically load its
configuration if the file is present.

If there's no /etc/sysconfig/rasdaemon, a warning will be
issued but the logic will proceed.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Add support to configure a database via env parameters.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Allow rasdaemon to select the right SQL backend.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Allow overriding the default using a --config (-c) option
to optionally select a different config file.

This can be very helpful when testing rasdaemon with different
DB backends.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Make the empty stub static inline, as otherwise some setups
may end declaring it multiple times.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Remove some logs that were useful while changing rasdaemon
architecture.

While here, replace the meaningless error message:

	rasdaemon: Failed to open directory

to one that actually makes sense:

	rasdaemon: Failed to open /sys/fs/pstore/erst directory

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Rasdaemon produces lots of logs. Make it clearer to identify
potential problems by adding colors to the messages.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
This reverts commit 4b29f86.
We want to allow installing inside a directory with:

meson build --reconfigure  -Dprefix=`pwd`/instal

but, at the same time, we need to support "make mock"
target.

The first one works, but `make mock` is adding /usr
twice:

	./BUILDROOT/usr/usr/lib/systemd/system/ras-mc-ctl.service
	./BUILDROOT/usr/usr/lib/systemd/system/rasdaemon.service

Add an extra check to prevent that.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
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.

1 participant