Skip to content

Conversation

@MirkoCovizzi
Copy link
Contributor

@MirkoCovizzi MirkoCovizzi commented Nov 17, 2025

Removes global callbacks array and replaces with callback
member inside struct bm_zms_fs.
This fixes a bug where registering multiple callbacks on
the same struct bm_zms_fs would update the user reference
number incrementally and saturate the global callbacks array.
When calling bm_zms_clear, this would only reset to NULL
the last callback set, leaving the rest still set.
This update makes it so that there can only be one callback
per each struct bm_zms_fs instance, mirroring the behavior
of other libraries.
Due to this change, also removes the BM_ZMS_MAX_USERS
Kconfig option.

@MirkoCovizzi MirkoCovizzi self-assigned this Nov 17, 2025
@MirkoCovizzi MirkoCovizzi requested review from a team and rghaddab as code owners November 17, 2025 14:07
@github-actions github-actions bot added the changelog-entry-required Update changelog before merge. Remove label if entry is not needed or already added. label Nov 17, 2025
@MirkoCovizzi MirkoCovizzi added changelog-entry-required Update changelog before merge. Remove label if entry is not needed or already added. and removed changelog-entry-required Update changelog before merge. Remove label if entry is not needed or already added. labels Nov 17, 2025
@github-actions
Copy link

You can find the documentation preview for this PR here.

@MirkoCovizzi MirkoCovizzi force-pushed the zms-register-refactor branch 3 times, most recently from 27aa479 to 564795f Compare November 17, 2025 14:14
@MirkoCovizzi MirkoCovizzi requested a review from a team as a code owner November 17, 2025 14:14
@github-actions github-actions bot added doc-required PR must not be merged without tech writer approval. and removed changelog-entry-required Update changelog before merge. Remove label if entry is not needed or already added. labels Nov 17, 2025
@MirkoCovizzi MirkoCovizzi force-pushed the zms-register-refactor branch 2 times, most recently from aa2458f to 67d1e18 Compare November 18, 2025 09:13
@rghaddab
Copy link
Contributor

@MirkoCovizzi I do not understand this bug.
The current bm_zms behavior should be that only one callback is registered for a bm_zms_fs structure.
The caller will get its user_num which indicates its order in the callback register.
No other bm_zms_register should be called on the same structure before clearing the previous one.
Can you detail the usecases where this could happen ?

@lemrey
Copy link
Contributor

lemrey commented Nov 18, 2025

I suppose that's one way to fix it. It does however add one limitation, which is that only the owner of an instance can receive callbacks from it, thus forcing a single owner for each instance. In practice, it is no longer possible to share a partition, every instance would need its own.

But it may be fine, first, because there a no events that are relevant for the whole application (like GC was). And second, because the application could still be designed in a way that allows to share a partition, by wrapping NVM operations.

@MirkoCovizzi
Copy link
Contributor Author

MirkoCovizzi commented Nov 19, 2025

@MirkoCovizzi I do not understand this bug. The current bm_zms behavior should be that only one callback is registered for a bm_zms_fs structure. The caller will get its user_num which indicates its order in the callback register. No other bm_zms_register should be called on the same structure before clearing the previous one. Can you detail the usecases where this could happen ?

It is not a use case. The current implementation makes it possible for a user to call the register function on the same instance multiple times, each time incrementing the user_num. When clearing, only the last registration is reset. If this behavior is not expected and should not be happening, then it's a bug.
This can be solved in multiple ways, however, since as you also say the user is expected to call register on an instance at most once, then it stands to reason that there can be a member inside the structure that holds the function pointer, the same way we do in the storage subsystem.

@MirkoCovizzi
Copy link
Contributor Author

I suppose that's one way to fix it. It does however add one limitation, which is that only the owner of an instance can receive callbacks from it, thus forcing a single owner for each instance. In practice, it is no longer possible to share a partition, every instance would need its own.

But it may be fine, first, because there a no events that are relevant for the whole application (like GC was). And second, because the application could still be designed in a way that allows to share a partition, by wrapping NVM operations.

What are some examples of situations where an application might want to share a single partition between different instances of a file system (or storage)?

@eivindj-nordic eivindj-nordic added this to the v1.0.0 milestone Nov 19, 2025
zms_cb_table[i] = cb;
fs->user_num = i;
fs->user_cb = cb;
fs->init_flags.cb_registred = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see the cb_registered flag used for anything. Remove it?

/**
* @brief Bare Metal ZMS event handler function prototype.
*
* @param p_evt The event.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* @param p_evt The event.
* @param evt The event.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will be addressed separately

*
* @param p_evt The event.
*/
typedef void (*bm_zms_cb_t)(bm_zms_evt_t const *p_evt);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
typedef void (*bm_zms_cb_t)(bm_zms_evt_t const *p_evt);
typedef void (*bm_zms_cb_t)(bm_zms_evt_t const *evt);

Comment on lines 135 to 136
* Removed the :kconfig:option:`CONFIG_BM_ZMS_MAX_USERS` Kconfig option. Now the library expects at most one callback for each instance of the struct :c:struct:`bm_zms_fs`.
* Removed the :c:member:`bm_zms_init_flags.cb_registred` member since it was not used anymore.
Copy link

Choose a reason for hiding this comment

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

Suggested change
* Removed the :kconfig:option:`CONFIG_BM_ZMS_MAX_USERS` Kconfig option. Now the library expects at most one callback for each instance of the struct :c:struct:`bm_zms_fs`.
* Removed the :c:member:`bm_zms_init_flags.cb_registred` member since it was not used anymore.
* Removed:
* The :kconfig:option:`CONFIG_BM_ZMS_MAX_USERS` Kconfig option.
Now, the library expects at most one callback for each instance of the :c:struct:`bm_zms_fs` structure.
* The :c:member:`bm_zms_init_flags.cb_registred` member as it was not used anymore.

@MirkoCovizzi MirkoCovizzi force-pushed the zms-register-refactor branch 2 times, most recently from 31a4e76 to e4a83c9 Compare November 24, 2025 13:05
@MirkoCovizzi MirkoCovizzi requested a review from peknis November 24, 2025 13:06

* Removed:

* The :kconfig:option:`CONFIG_BM_ZMS_MAX_USERS` Kconfig option. Now the library expects at most one callback for each instance of the struct :c:struct:`bm_zms_fs`.
Copy link

Choose a reason for hiding this comment

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

Suggested change
* The :kconfig:option:`CONFIG_BM_ZMS_MAX_USERS` Kconfig option. Now the library expects at most one callback for each instance of the struct :c:struct:`bm_zms_fs`.
* The :kconfig:option:`CONFIG_BM_ZMS_MAX_USERS` Kconfig option.
Now, the library expects at most one callback for each instance of the struct :c:struct:`bm_zms_fs`.

Remember, every sentence on its own line. Do we need "at most"?

Copy link
Contributor Author

@MirkoCovizzi MirkoCovizzi Nov 24, 2025

Choose a reason for hiding this comment

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

"At most" clarifies that the callback is optional. Without it, it would seem that there has to be one callback. It also clarifies the difference compared to before, where it would seem that a user can set multiple callbacks on an instance.

* Removed:

* The :kconfig:option:`CONFIG_BM_ZMS_MAX_USERS` Kconfig option. Now the library expects at most one callback for each instance of the struct :c:struct:`bm_zms_fs`.
* The :c:member:`bm_zms_init_flags.cb_registred` member since it was not used anymore.
Copy link

Choose a reason for hiding this comment

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

Suggested change
* The :c:member:`bm_zms_init_flags.cb_registred` member since it was not used anymore.
* The :c:member:`bm_zms_init_flags.cb_registred` member as it was not used anymore.

Removes global callbacks array and replaces with callback
member inside `struct bm_zms_fs`.
This fixes a bug where registering multiple callbacks on
the same `struct bm_zms_fs` would update the user reference
number incrementally and saturate the global callbacks array.
When calling `bm_zms_clear`, this would only reset to NULL
the last callback set, leaving the rest still set.
This update makes it so that there can only be one callback
per each `struct bm_zms_fs` instance, mirroring the behavior
of other libraries.
Due to this change, also removes the `BM_ZMS_MAX_USERS`
Kconfig option.
Also removes the member `cb_registred` in the struct
`bm_zms_init_flags` since it is not used anymore.

Signed-off-by: Mirko Covizzi <mirko.covizzi@nordicsemi.no>
Cleans up Doxygen.

Signed-off-by: Mirko Covizzi <mirko.covizzi@nordicsemi.no>
Copy link

@peknis peknis left a comment

Choose a reason for hiding this comment

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

Approved with a couple of further suggestions.


* Removed:

* The :kconfig:option:`CONFIG_BM_ZMS_MAX_USERS` Kconfig option.
Copy link

Choose a reason for hiding this comment

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

Suggested change
* The :kconfig:option:`CONFIG_BM_ZMS_MAX_USERS` Kconfig option.
* The ``CONFIG_BM_ZMS_MAX_USERS`` Kconfig option.

Sorry, my bad. The :kconfig:option: would not work anymore as the option is removed, thus double back-ticks.


* The :kconfig:option:`CONFIG_BM_ZMS_MAX_USERS` Kconfig option.
Now the library expects at most one callback for each instance of the struct :c:struct:`bm_zms_fs`.
* The :c:member:`bm_zms_init_flags.cb_registred` member as it was not used anymore.
Copy link

Choose a reason for hiding this comment

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

Suggested change
* The :c:member:`bm_zms_init_flags.cb_registred` member as it was not used anymore.
* The ``bm_zms_init_flags.cb_registred`` member as it was not used anymore.

Same here, the directive :c:member: would not work as it is removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc-required PR must not be merged without tech writer approval.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants