-
Notifications
You must be signed in to change notification settings - Fork 8.4k
Settings stream codec #9521
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
Settings stream codec #9521
Conversation
|
For sure the code still need some clean-up - so pleas comment on general conception and so one (no coding standard session for now). |
Codecov Report
@@ Coverage Diff @@
## master #9521 +/- ##
==========================================
+ Coverage 48.13% 48.19% +0.06%
==========================================
Files 281 280 -1
Lines 43425 43259 -166
Branches 10406 10364 -42
==========================================
- Hits 20902 20850 -52
+ Misses 18368 18255 -113
+ Partials 4155 4154 -1
Continue to review full report at Codecov.
|
|
@jhedberg @Laczen @carlescufi @lemrey Pleas review in yours convenience. |
|
Hi @nvlsianpu, sorry I did not respond any faster. I am tied up in other work. This is a great improvement to the settings module. Maybe there is still an opening for a big simplification of the settings module. As I mentioned before the encoding could be removed. The encoding was imo needed for:
In fcb you could just store the items as "variable_name=" concatenated with the binary data. As you know the total length of an item in fcb getting the length of the binary data is the difference between the length and the location of the first "=". No need for encoding or streamed encoding. The advantage is of course the reduction in data size and the simplicity. For nffs it might also be possible to do something like this (I have never used nffs). In the worst case nffs would still require encoding but the settings module would be a lot simpler for fcb. |
|
@Laczen Thanks for comments - I received similar comments off-channel from my colleges. I will differentiate algorithm between FCB and FS.
What do you mean, what a serial monitor? |
|
Hi @nvlsianpu, what I meant by serial monitor was newt_mgr. The implementation in mynewt has the possibility to export to newt_mgr, this would require encoding to be able to do this. |
|
@Laczen Sure - the idea is not to keep things like in the MyNewt it used to be. So zephyr-mcumgr-go-app will suport this (remote provisioning) in the appropriate shape. |
rakons
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a change in good direction. If the whole module is going to be rewriten it may be good moment to start using doxygen tags to describe structures here in correct way.
aebee6e to
753f97a
Compare
7e4d791 to
9a8f0a0
Compare
41c46ef to
e86c420
Compare
|
All checks are passing now. Review history of this comment for details about previous failed status. |
a5f55ab to
85f9ea5
Compare
This Patch add tests for API in nffs and fcb back-ends. Signed-off-by: Andrzej Puzdrowski <[email protected]>
So far to deleting av existing key-value pair it was required to storing NULL value using setting_save_one(). This patch introduce more intuitive API which takes only the name key string. Signed-off-by: Andrzej Puzdrowski <[email protected]>
Added BT alisa for dumping binary data to the logg. The macro will be useful for BT as reworked settings supports r/w of raw data - which will be widely leveraged in bluetooth storage alignment to reworked settings. Signed-off-by: Andrzej Puzdrowski <[email protected]>
The Code need to be align after introduction of stream codec to setting serialization subsystem. Signed-off-by: Andrzej Puzdrowski <[email protected]>
9152902 to
056c030
Compare
|
@jhedberg updated |
jhedberg
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks generally good now, thanks! Mostly logging related comments still.
The code need to be align after introduction of stream codec to setting serialization subsystem. Signed-off-by: Andrzej Puzdrowski <[email protected]>
The Code need to be align after introduction of stream codec to setting serialization subsystem. Signed-off-by: Andrzej Puzdrowski <[email protected]>
056c030 to
8b37f23
Compare
|
@jhedberg I hope I solved all problems you had found. |
Laczen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @nvlsianpu, very nice work, congrats.
Once this gets merged I will start working on adding a nvs backend. I would like to keep it as simple as possible, but with minimal flash wear:
- Names are stored in id's
0x8001...0xBFFF - Corresponding values are stored in id's
0xC001..0xFFFF - id
0x8000keeps track of the last name id in use.
This way:
a. Flash wear is minimal (only value updates are stored)
b. NVS direct use is possible for id's below 8000.
Settings_NVS would only need to keep track of:
a. settings_nvs_write_id (what id to use next, reusing deleted id's when possible),
b. settings_nvs_last_id (last id to use when reading at start).
|
@rakons could you please re-review? |
rakons
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not like the doxygen style used here to document structure - it might be corrected. But technically it is not an error. Some misssing return value documentation and also the parameters constantness requires thought. I am approving as any of the error here technically is not a something that would make the library unusable.
| */ | ||
| struct settings_handler { | ||
| sys_snode_t node; | ||
| /**< Linked list node info for module internal usage. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would not it be better to document it on top? Without < in the doxygen comment? This kind of comment is rather designed to be used in single name:
int val; /**< Super duper value field */
This looks ok.
int val;
/**< Super duper value field */
Looks odd. Much better is:
/** Super duper value field */
int val;
| int (*h_get)(int argc, char **argv, char *val, int val_len_max); | ||
| /**< Get values handler of settings items identified by keyword names. | ||
| * | ||
| * Parameters: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use @param.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return value documentation missing.
| int (*h_set)(int argc, char **argv, void *value_ctx); | ||
| /**< Set value handler of settings items identified by keyword names. | ||
| * | ||
| * Parameters: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use @param. Return value documentation missing.
| int (*h_commit)(void); | ||
| int (*h_export)(int (*export_func)(const char *name, char *val), | ||
| enum settings_export_tgt tgt); | ||
| /**< This handler gets called after settings has been loaded in full. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return value documentation.
| /**< This gets called to dump all current settings items. | ||
| * | ||
| * This happens when @ref settings_save tries to save the settings. | ||
| * Parameters: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use @param. Document return value.
| * @return 0 on success, non-zero on failure. | ||
| */ | ||
| int settings_set_value(char *name, char *val_str); | ||
| int settings_set_value(char *name, void *value, size_t len); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the value can be const here.
| * | ||
| * @return 0 on success, non-zero on failure. | ||
| */ | ||
| int settings_commit(char *name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const
|
|
||
| #define SETTINGS_VALUE_SET(str, type, val) \ | ||
| settings_value_from_str((str), (type), &(val), sizeof(val)) | ||
| size_t settings_val_get_len_cb(void *value_ctx); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const ?
| } | ||
|
|
||
| static int ps_set(int argc, char **argv, char *val) | ||
| static int ps_set(int argc, char **argv, void *val_ctx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For me it seems that we can have const char *const *argv here.
| } | ||
|
|
||
| static int ccc_set(int argc, char **argv, char *val) | ||
| static int ccc_set(int argc, char **argv, void *val_ctx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
char const * const *argv ?
carlescufi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job @nvlsianpu
Whenever a new key-value is about to be stored, the settings perform check whether the value really changes. This check after zephyrproject-rtos#9521 patch should work differently as `\0` is not the value terminator anymore. Because of above any value which starts from \0 will be treated mistakenly as a NULL. This patch uses check-length callback instead read-callback which fix the issue and simplify the code a little. Signed-off-by: Andrzej Puzdrowski <[email protected]>
Whenever a new key-value is about to be stored, the settings perform check whether the value really changes. This check after #9521 patch should work differently as `\0` is not the value terminator anymore. Because of above any value which starts from \0 will be treated mistakenly as a NULL. This patch uses check-length callback instead read-callback which fix the issue and simplify the code a little. Signed-off-by: Andrzej Puzdrowski <[email protected]>
Patch removes dead, replaced code which was accidentally not removed within the stream-codec PR zephyrproject-rtos#9521. Signed-off-by: Andrzej Puzdrowski <[email protected]>
Patch removes dead, replaced code which was accidentally not removed within the stream-codec PR #9521. Signed-off-by: Andrzej Puzdrowski <[email protected]>
This patch reworks routines used to store and read the settings data.
Provide stream-style encoding and decoding to/from flash, so the the
API only requires a pointer to binary data, and the settings
implementation takes care of encoding/decoding to/from base64 and
writing/reading to/from flash on the fly. This would eliminate the
need of a separate base64 value buffer on the application-side, thereby
further contributing to the stack footprint reduction.
Above changes allows to remove:
256-byte value length limitation.
removing enum settings_type usage so all settings data are treated
now as a byte array (i.e. what's previously SETTINGS_BYTES)
Introduced routine settings_val_read_cb for read and decode the
settings data from storage inside h_set handler implementations.
h_set settings handler now provide persistent value's context
used along with read routine instead of immediately value.
Also the user code in higher modules will be aligned then.
For this patch all tests from path teste/subsys/settings/fcb pass.
Any new back-end need to implement two I/O handlers:
and register it using f.
settings_line_io_init.Above handler need only to provide RAW access to the back-end storage.
The Introduced codec take ceare about I/O access alignment.
remove Remove the tgt parameter to the export callback
The tgt parameter is unneeded and only complicates the API.
Signed-off-by: Andrzej Puzdrowski [email protected]