Skip to content

Conversation

@MirkoCovizzi
Copy link
Contributor

The bm_zms_clear function executes write operations under the hood that can be asynchronous.
The condition of termination for the operation is when the file system is set to uninitialized.
Adds a check for this condition before terminating the sample.

@MirkoCovizzi MirkoCovizzi self-assigned this Nov 18, 2025
@MirkoCovizzi MirkoCovizzi requested a review from a team as a code owner November 18, 2025 12:44
@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 18, 2025
@MirkoCovizzi MirkoCovizzi removed the changelog-entry-required Update changelog before merge. Remove label if entry is not needed or already added. label Nov 18, 2025
@github-actions
Copy link

You can find the documentation preview for this PR here.

@MirkoCovizzi MirkoCovizzi requested a review from a team as a code owner November 18, 2025 12:53
@github-actions github-actions bot added changelog-entry-required Update changelog before merge. Remove label if entry is not needed or already added. doc-required PR must not be merged without tech writer approval. labels Nov 18, 2025
@MirkoCovizzi MirkoCovizzi removed the changelog-entry-required Update changelog before merge. Remove label if entry is not needed or already added. label Nov 18, 2025
@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 18, 2025
@MirkoCovizzi MirkoCovizzi removed the changelog-entry-required Update changelog before merge. Remove label if entry is not needed or already added. label Nov 18, 2025
@eivindj-nordic eivindj-nordic added this to the v1.0.0 milestone Nov 19, 2025
@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 19, 2025
@MirkoCovizzi MirkoCovizzi changed the title samples: peripherals: bm_zms: add wait after clear samples: subsys: fs: bm_zms: add wait after clear Nov 19, 2025
Clearing the storage system
===========================

The :c:func:`bm_zms_clear` function must be called to clear the storage.
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
The :c:func:`bm_zms_clear` function must be called to clear the storage.
Call the :c:func:`bm_zms_clear` function to clear the storage.

The :c:func:`bm_zms_clear` function must be called to clear the storage.

When this uninitialization is successful, the library sets the flag :c:member:`bm_zms_fs.init_flags.initialized` to false.
For asynchronous storage backends, you must wait for the uninitialization to finish before re-initializing the storage system.
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
For asynchronous storage backends, you must wait for the uninitialization to finish before re-initializing the storage system.
For asynchronous storage backends, you must wait for the uninitialization to finish before reinitializing the storage system.

Clearing the storage system
===========================

Call the :c:func:`bm_zms_clear` function to clear the storage.
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps state explicitly here that it uinintializes the zms instance.

Suggested change
Call the :c:func:`bm_zms_clear` function to clear the storage.
Call the :c:func:`bm_zms_clear` function to clear the storage and uninitialize the ZMS instance.

@sonarqubecloud
Copy link

The `bm_zms_clear` function executes write operations
under the hood that can be asynchronous.
The condition of termination for the operation is when
the file system is set to uninitialized.
Adds a check for this condition before terminating
the sample.

Signed-off-by: Mirko Covizzi <mirko.covizzi@nordicsemi.no>
Adds section that explains how to handle the storage system
clear.

Signed-off-by: Mirko Covizzi <mirko.covizzi@nordicsemi.no>
@MirkoCovizzi MirkoCovizzi removed the changelog-entry-required Update changelog before merge. Remove label if entry is not needed or already added. label Nov 21, 2025
Copy link
Contributor

@lemrey lemrey left a comment

Choose a reason for hiding this comment

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

Something's wrong here; it cannot be that un-initialization should be checked by the application by polling an internal flag in the instance structure-- this whole library has an asynchronous interface and the uninitialization should be signalled by an event. If un-initialization hasn't completed at the time the event is sent, then it's a bug but clearly we can't solve it like this.

@MirkoCovizzi
Copy link
Contributor Author

MirkoCovizzi commented Nov 24, 2025

Something's wrong here; it cannot be that un-initialization should be checked by the application by polling an internal flag in the instance structure-- this whole library has an asynchronous interface and the uninitialization should be signalled by an event. If un-initialization hasn't completed at the time the event is sent, then it's a bug but clearly we can't solve it like this.

I agree, that requires a bit of a redesign of the ZMS API and logic. Currently, the subsystem is operating on flags when it comes to specific actions. My contribution is simply addressing the current existing implementation and how it lacks adequate documentation for its behavior.

@rghaddab Any opinions on this topic?

@lemrey
Copy link
Contributor

lemrey commented Nov 24, 2025

Can you try to explain exactly what the problem is?

@MirkoCovizzi
Copy link
Contributor Author

MirkoCovizzi commented Nov 24, 2025

Can you try to explain exactly what the problem is?

Currently the problem is that we are not documenting to the user how to make sure that a clear has completed. I'm currently looking into the event system, and while there is an event for CLEAR, it is never propagated because as I just discovered, we are effectively resetting the handlers to NULL on CLEAR, before sending the event. That, instead, is a bug.

@lemrey
Copy link
Contributor

lemrey commented Nov 24, 2025

there is an event for CLEAR, it is never propagated because as I just discovered, we are effectively resetting the handlers to NULL on CLEAR, before sending the event. That, instead, is a bug.

Yes, I fully agree with that. It's a bug, the _CLEAR event should be sent just like the other events. Would it be sufficient to never unset the handler? Once the library is uninitialized, API calls other than _mount() would return an error, so there would not be any other events dispatched to the handler. The only API call allowed, _mount() would overwrite it, so is there any need to set it to NULL?

@MirkoCovizzi
Copy link
Contributor Author

there is an event for CLEAR, it is never propagated because as I just discovered, we are effectively resetting the handlers to NULL on CLEAR, before sending the event. That, instead, is a bug.

Yes, I fully agree with that. It's a bug, the _CLEAR event should be sent just like the other events. Would it be sufficient to never unset the handler? Once the library is uninitialized, API calls other than _mount() would return an error, so there would not be any other events dispatched to the handler. The only API call allowed, _mount() would overwrite it, so is there any need to set it to NULL?

Yes, that's what I planned to do too. I'm working on a PR that addresses this behavior.

@MirkoCovizzi MirkoCovizzi removed this from the v1.0.0 milestone Nov 25, 2025
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.

4 participants