-
Notifications
You must be signed in to change notification settings - Fork 5
Support using the filesystem as backend for settings subsystem #121
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
Open
medarion
wants to merge
3
commits into
edgehog-device-manager:master
Choose a base branch
from
medarion:support-settings-file-backend
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,8 @@ | |
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #include <zephyr/fs/fs.h> | ||
|
|
||
| #include "storage_usage.h" | ||
|
|
||
| #include "edgehog_private.h" | ||
|
|
@@ -19,23 +21,41 @@ EDGEHOG_LOG_MODULE_REGISTER(storage_usage, CONFIG_EDGEHOG_DEVICE_STORAGE_USAGE_L | |
|
|
||
| void publish_storage_usage(edgehog_device_handle_t edgehog_device) | ||
| { | ||
|
|
||
| #if defined(CONFIG_SETTINGS_NVS) | ||
| const char *path = "/" NVS_PARTITION_LABEL; | ||
| size_t total_space = NVS_PARTITION_SIZE; | ||
| size_t free_space = 0; | ||
| edgehog_result_t res = edgehog_nvs_get_free_space(&free_space); | ||
|
|
||
| if (res == EDGEHOG_RESULT_OK) { | ||
| astarte_object_entry_t object_entries[] | ||
| = { { .path = "totalBytes", .data = astarte_data_from_longinteger(NVS_PARTITION_SIZE) }, | ||
| { .path = "freeBytes", .data = astarte_data_from_longinteger(free_space) } }; | ||
|
|
||
| int64_t timestamp_ms = 0; | ||
| system_time_current_ms(×tamp_ms); | ||
|
|
||
| astarte_result_t res = astarte_device_send_object(edgehog_device->astarte_device, | ||
| io_edgehog_devicemanager_StorageUsage.name, "/" NVS_PARTITION_LABEL, object_entries, | ||
| ARRAY_SIZE(object_entries), ×tamp_ms); | ||
| if (res != ASTARTE_RESULT_OK) { | ||
| EDGEHOG_LOG_ERR("Unable to send syste_status"); // NOLINT | ||
| } | ||
| if (edgehog_nvs_get_free_space(&free_space) != EDGEHOG_RESULT_OK) { | ||
| return; | ||
| } | ||
| #elif defined(CONFIG_SETTINGS_FILE) | ||
| struct fs_file_t f; | ||
| fs_file_t_init(&f); | ||
| if (fs_open(&f, CONFIG_SETTINGS_FILE_PATH, 0) != 0) { | ||
| return; | ||
| } | ||
| const char *path = f.mp->mnt_point; | ||
| fs_close(&f); | ||
|
|
||
| struct fs_statvfs s; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do not use single-character variables. Minimum is three chars according to our clang-tidy configuration. |
||
| if (fs_statvfs(path, &s) != 0) { | ||
| return; | ||
| } | ||
| size_t total_space = (size_t) s.f_frsize * s.f_blocks; | ||
| size_t free_space = (size_t) s.f_frsize * s.f_bfree; | ||
| #endif | ||
|
|
||
| astarte_object_entry_t object_entries[] | ||
| = { { .path = "totalBytes", .data = astarte_data_from_longinteger(total_space) }, | ||
| { .path = "freeBytes", .data = astarte_data_from_longinteger(free_space) } }; | ||
|
|
||
| int64_t timestamp_ms = 0; | ||
| system_time_current_ms(×tamp_ms); | ||
|
|
||
| astarte_result_t res = astarte_device_send_object(edgehog_device->astarte_device, | ||
| io_edgehog_devicemanager_StorageUsage.name, path, object_entries, | ||
| ARRAY_SIZE(object_entries), ×tamp_ms); | ||
| if (res != ASTARTE_RESULT_OK) { | ||
| EDGEHOG_LOG_ERR("Unable to send syste_status"); // NOLINT | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
In general, this whole open close cycle intended to find the partition mount point should not be required.
Passing
CONFIG_SETTINGS_FILE_PATHdirectly tofs_statvfsshould work fine. I have not tested this myself, but looking at the codebase of Zephyr it seems to be used this way in multiple spots.See, for example, the test
test_file_statvfs.