Skip to content

NVStore: add the allocate_key API (instead of set_alloc_key) #6480

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

Merged
merged 1 commit into from
May 21, 2018

Conversation

davidsaada
Copy link
Contributor

@davidsaada davidsaada commented Mar 27, 2018

Description

Add the allocate_key API. This replaces the previously added set_alloc_key API (which allocates a key and sets the value at the same time).
Reason for the change: Key allocation will typically be used by other storage features (like StorageLite), keeping the allocated keys in another location. Previous API created problems in the case key allocation and value setting couldn't be done at the same time (for instance, if the set value was derived from the allocated key, such as hash or CMAC).

Pull request type

[ ] Fix
[ ] Refactor
[ ] New target
[ ] Feature
[x] Breaking change

* NVSTORE_NO_FREE_KEY Couldn't allocate a key for this call.
*
*/
int set_alloc_key(uint16_t &key, uint16_t buf_size, const void *buf);
int allocate_key(uint16_t &key);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a breaking change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is indeed, but the replaced function (set_alloc_key) is a new one that was implemented after the 5.8 release. It's still not even documented. Figured that the API we had defined was wrong in that case, hence the change. Can add the "old" API back, but that that would be just dead code.

Copy link
Contributor

Choose a reason for hiding this comment

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

This PR contains a breaking change, so marked for 5.9.0.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's OK. It is mainly used for StorageLite feature, which should be out in 5.9.0.

* @param[in] buf_size Buffer size (bytes).
* @param[in] buf Input Buffer.
* @param[in] flags Record flags.
*
* @returns 0 for success, nonzero for failure.
*/
int do_set(uint16_t &key, uint16_t buf_size, const void *buf, uint16_t flags);
int do_set(uint16_t key, uint16_t buf_size, const void *buf, uint16_t flags);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is also a breaking change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's not a breaking change, as the function is private (maybe the doxy comments are confusing to think it is not).

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I missed the private at the top. Thanks.

@davidsaada
Copy link
Contributor Author

Anything missing in order for this PR to move forward (not that I'm trying to push anyone)?

@davidsaada
Copy link
Contributor Author

davidsaada commented Apr 3, 2018

@cmonr @marcuschangarm I said i didn't have a problem to have this fix on a temporary basis, and try resolving that when I'm back. However, until seeing @cmonr's comment, didn't notice the fact that this was on master, while other changes were on the feature branch. This will prevent me from testing any fix properly, as much of the memory consumption based fixes are based on trial and error (to make sure they work on all boards). Maybe it would be better to move this change to the feature branch as well?
EDIT: sorry - commented on the wrong PR...

@0xc0170 0xc0170 requested a review from sg- April 3, 2018 10:26
@0xc0170
Copy link
Contributor

0xc0170 commented Apr 3, 2018

It is a breaking change, that is correct, but what we missed , @davidsaada to confirm - as this functionality that is changing here was just on master (added after 5.8, only available on master). Therefore the reasoning:

Reason for the change: Key allocation will typically be used by other storage features (like StorageLite), keeping the allocated keys in another location. Previous API created problems in the case key allocation and value setting couldn't be done at the same time (for instance, if the set value was derived from the allocated key, such as hash or CMAC).

This PR should be considered and reviewed.

@davidsaada
Copy link
Contributor Author

Confirmed - the modified API isn't there even on 5.8.1. It was added to master after the 5.8 release, then when found my mistake, fixed it quickly.

Copy link
Contributor

@0xc0170 0xc0170 left a comment

Choose a reason for hiding this comment

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

LGTM, just one small change

@@ -597,16 +599,16 @@ int NVStore::do_get(uint16_t key, uint16_t buf_size, void *buf, uint16_t &actual
}

_mutex->lock();
record_offset = _offset_by_key[key];

record_offset = _offset_by_key[key];
Copy link
Contributor

Choose a reason for hiding this comment

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

misaligned- tabs here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Strange, my editor is setup to insert spaces only. Anyway, fixed it.

@davidsaada davidsaada force-pushed the david_nvstore_alloc_key branch from 2155e86 to f0c9f19 Compare April 4, 2018 21:16
0xc0170
0xc0170 previously approved these changes Apr 5, 2018
@davidsaada davidsaada force-pushed the david_nvstore_alloc_key branch 2 times, most recently from 49cab79 to c6d2bdd Compare April 8, 2018 11:14
0xc0170
0xc0170 previously approved these changes Apr 10, 2018
@0xc0170
Copy link
Contributor

0xc0170 commented Apr 10, 2018

/morph build

@mbed-ci
Copy link

mbed-ci commented Apr 10, 2018

Build : SUCCESS

Build number : 1705
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/6480/

Triggering tests

/morph test
/morph uvisor-test
/morph export-build
/morph mbed2-build

@mbed-ci
Copy link

mbed-ci commented Apr 10, 2018

@mbed-ci
Copy link

mbed-ci commented Apr 11, 2018

@0xc0170
Copy link
Contributor

0xc0170 commented Apr 11, 2018

/morph test

@mbed-ci
Copy link

mbed-ci commented Apr 12, 2018

@cmonr
Copy link
Contributor

cmonr commented Apr 12, 2018

Waiting on @sg- and @SenRamakri for review.

@cmonr
Copy link
Contributor

cmonr commented Apr 12, 2018

@davidsaada Also, this looks like it'll need to go through a rebase.

Add the allocate_key API. This replaces the previously added set_alloc_key API
(which allocates a key and sets the value at the same time).
Reason for the change: Key allocation will typically be used by other storage
features (like StorageLite), keeping the allocated keys in another location.
Previous API created problems in the case key allocation and value setting
couldn't be done at the same time (for instance, if the set value was
derived from the allocated key, such as hash or CMAC).
@davidsaada davidsaada force-pushed the david_nvstore_alloc_key branch from ead4901 to c90182a Compare May 14, 2018 16:01
@davidsaada
Copy link
Contributor Author

Rebased following merge of PR #6864. No longer depending on that PR.

@cmonr
Copy link
Contributor

cmonr commented May 15, 2018

/morph build

@mbed-ci
Copy link

mbed-ci commented May 15, 2018

Build : SUCCESS

Build number : 2029
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/6480/

Triggering tests

/morph test
/morph uvisor-test
/morph export-build
/morph mbed2-build

@mbed-ci
Copy link

mbed-ci commented May 16, 2018

@mbed-ci
Copy link

mbed-ci commented May 16, 2018

@cmonr
Copy link
Contributor

cmonr commented May 16, 2018

/morph test

@cmonr
Copy link
Contributor

cmonr commented May 16, 2018

/morph export-build

@cmonr
Copy link
Contributor

cmonr commented May 16, 2018

/morph test

1 similar comment
@cmonr
Copy link
Contributor

cmonr commented May 16, 2018

/morph test

@mbed-ci
Copy link

mbed-ci commented May 17, 2018

@mbed-ci
Copy link

mbed-ci commented May 17, 2018

@mbed-ci
Copy link

mbed-ci commented May 17, 2018

@adbridge
Copy link
Contributor

@SenRamakri @0xc0170 Are you happy with the updates ?

@cmonr
Copy link
Contributor

cmonr commented May 21, 2018

Looks like @0xc0170 was already good with the changes.

@cmonr cmonr merged commit db73ed0 into ARMmbed:master May 21, 2018
@davidsaada davidsaada deleted the david_nvstore_alloc_key branch July 9, 2018 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants