Commit Graph

24 Commits

Author SHA1 Message Date
Wyatt Hepler
289046011c pw_kvs: AlignedWriter read-and-write function
Define AlignedWriter::Write overload that reads into the internal buffer
from an Input and writes it aligned to the output.

Change-Id: I72c1dead8cdcb912bf44fd1e36940cdb741f92df
2020-03-10 20:34:40 +00:00
Wyatt Hepler
f707880fbe pw_status: StatusWithSize constants
- Provide StatusWithSize constants that can be used similarly to
  Status::Codes. For example, StatusWithSize::DATA_LOSS constructs a
  StatusWithSize with status DATA_LOSS and size 0.
- Remove the default constructor argument for the size. Use the
  constants instead.
- Update uses of StatusWithSize(Status::X) to use StatusWithSize::X.

Change-Id: I901b7bb0bbbb4fde52f6b3acc3047f366b250515
2020-02-25 13:50:41 -08:00
Wyatt Hepler
118fc3c5f0 pw_kvs: Expand tests for error handling
- Add error injection features to InMemoryFakeFlash. Reads or Writes can
  be programmed to fail.
- Introduce key_value_store_error_handling_test.cc, which focuses on
  corruption and read/write failure cases.
- Add functions for creating binary KVS entries at compile time.

Change-Id: Ie52ba5eb13eb60244835ef43314282beacc3a659
2020-02-24 10:08:27 -08:00
Wyatt Hepler
bdd8e5a77b pw_kvs: Move entry.h to public/pw_kvs/internal
Move entry.h so that the KeyValueStore class can reference it in the
header.

Change-Id: Ib5a7f194db8dd9af1e8f3d8c9c7c25b8409acfe0
2020-02-20 19:30:47 -08:00
Wyatt Hepler
1fc1104cb5 pw_kvs: Transcation ID and key descriptor refactor
- Switch from per-key versions to a monotonically increasing KVS-global
  transcation ID.
- Move KeyDescriptor and the hash function to their own files.

Change-Id: I05287137579d4fe2d72c6e176969d46006c2aae6
2020-02-20 16:26:27 -08:00
Wyatt Hepler
5f6efc0fed pw_kvs: Allow specifying an offset in Get
Change-Id: Id0b27a3b7cf3d7fe53e934e2a4822f00f21cb517
2020-02-19 15:40:04 -08:00
Wyatt Hepler
5406a67a3b pw_kvs: Check for values that are too large
- Reject values that are too large to fit in one sector.
- Clean up KeyDescriptor usage.

Change-Id: I8575bd0f3b7e9c6c2a5c5e9ef5ba1bc0dd81da7b
2020-02-19 11:12:01 -08:00
Wyatt Hepler
a00d1ef82c pw_kvs: Expand Entry tests; fix issues
- Expand the tests for the KVS entry class.
- Fix a few minor issues found by the tests.

Change-Id: I92b5dd614d2a726c912b7b1bf1f9ebd47a702be4
2020-02-19 11:12:01 -08:00
Wyatt Hepler
cdd6dfcfc6 pw_kvs: FlashMemory updates; test utilities
- Update comments for FlashMemory class.
- Split InMemoryFakeFlash to move the fixed-size buffer into the
  derived FakeFlashBuffer class.
- Support initializing FakeFlashBuffer to data provided at construction.
- Allow direct access to the underlying fake flash buffer for testing.
- Create utilities for working with byte arrays in byte_utils.h.

Change-Id: I90d33621cb91da079d7213fe7d33823494120e48
2020-02-19 19:10:32 +00:00
Wyatt Hepler
e541e075d4 pw_kvs: Move reading and writing to Entry class
- Add the FlashPartition and address to the Entry class.
- Move functions for reading or writing the entry header, key, and value
  to the Entry class.

Change-Id: I0af3c140a519c8b050fcef81eca4f3b45560f75c
2020-02-14 16:21:29 -08:00
Wyatt Hepler
d31d97070f pw_kvs: Rename format.h to entry.h
Change-Id: Iad7148cad736d57a9ff5d23772a002c40508b6d4
2020-02-14 18:08:50 +00:00
Wyatt Hepler
50f70779c8 Remove StatusWithSize implicit conversions
- Disallow implicit conversions between Status and StatusWithSize, which
  can be problematic.
- Add TRY_WITH_SIZE to pw_kvs to handle returning StatusWithSize from
  functions.
- Make zero the default size argument for StatusWithSize.
- Expand tests for StatusWithSize.

Change-Id: Ia1c36e5a39402a50138d93e89afbaa5e772adb8a
2020-02-14 17:59:00 +00:00
Wyatt Hepler
38cfa98998 pw_kvs: Checksum whole entry, including padding
- Always pad entries to their alignment instead of the flash's
  alignment, which may be smaller.
- Checksum entire entries, including padding. The checksum is calculated
  with the checksum field set to 0.

Change-Id: Ie354bf3fb93f23354d2278e5b16bd7d448728d95
2020-02-13 10:43:32 -08:00
Wyatt Hepler
30a5215045 pw_kvs: Rename EntryHeader to Entry
- Rename EntryHeader to Entry, since it is more than just the
  EntryHeader.
- Introduce POD EntryHeader struct that represents the on-disk entry
  format.
- Remove unused set functions.

Change-Id: I407d615e559ad77824fbd6c6db66aa2c666c1c1e
2020-02-13 10:43:32 -08:00
Wyatt Hepler
c656af2f12 pw_kvs: Implement AlignedChecksum
- Provide AlignedChecksum class that uses AlignedWriter to ensure that
  checksum updates are aligned as required.
- Make Finish() non-virtual and call an optional Finalize() operation
  instead.

Change-Id: I5b16468b6a55c0c2c9f2c06e37988970af147a11
2020-02-13 10:43:23 -08:00
Wyatt Hepler
1927c2868b pw_kvs: Split out aligned write functionality
- Define the Output interface.
- Create AlignedWriter class, which handles writing aligned and padded
  data to a buffer.
- Define AlignedWriterBuffer, which provides a buffer to an
  AlignedWriter.

Change-Id: I791c5fc2d47617b0866fa779a506cb977905f245
2020-02-12 17:00:09 -08:00
Wyatt Hepler
97fc794536 pw_kvs: Introduce alignment to the entry header
- Add an 8-bit alignment field to the entry header. This makes the
  entry header a complete description of the entry's representation in
  flash (assuming the checksum algorithm is implied by the magic).
- Write basic tests for the EntryHeader class.

Change-Id: I7e48d5c16451ceb81f7c191d2f261e0a9bef14b7
2020-02-07 00:34:58 +00:00
Wyatt Hepler
6c24c0638b pw_kvs: Implement Delete; add tests
- Implement Delete function.
- Add new tests and enable a few that pass now.
- Have out-of-bounds flash reads return OUT_OF_RANGE to differentiate
  from INVALID_ARGUMENT.

Change-Id: I5d65ad36913b30f2554bd12eaba26127ae0ec8f2
2020-02-05 18:00:56 -08:00
Wyatt Hepler
93b889d7cb pw_kvs: Move EntrySize to the EntryHeader class
Change-Id: I4b2dd6d6e9e632df9d39bcfad1c2a6ac321ab317
2020-02-05 09:08:58 -08:00
David Rogers
f0a354490c pw_kvs: Add implementation for RelocateEntry()
Add implementation for RelocateEntry().
Add 4K buffer member to the KeyValueStore class for use with relocation
and general use.

Change-Id: I29d30fe539959464be8ac624454ff4c94c3cc54f
2020-02-04 23:20:04 -08:00
Wyatt Hepler
0a22358554 pw_kvs: Verify checksum on write
- Replace placeholder VerifyEntry function with the real verification
  function, VerifyChecksumInFlash.
- Have VerifyChecksumInFlash read everything from flash, not just the
  value.
- Fix missing bytes_to_read updates.

Change-Id: If856c60dee710bea128684fd1bb22d3e7fc62793
2020-02-05 06:35:08 +00:00
Wyatt Hepler
6e3a83b61f pw_kvs: Get checksums working; enable test
- Allow checksums to verify data larger than their internal state. This
  facilitates using a CRC16 in a uint32_t.
- Move checksum functions to the EntryHeader class, since it ultimately
  stores the checksums and is included with it.
- Enable one checksum test. Further tests are needed.
- Make some tweaks to the Get overload for objects.

Change-Id: I989b72905e140794f75c8f8619aaab1623f6f195
2020-02-04 16:35:40 -08:00
Keir Mierle
8c352dc5dd pw_kvs: Implement KVS load from flash
This starts the implementation of loading the KVS from flash. Much
remains to do before this is done. This patch also includes some
extensions to how the tests are handled, to make it easier to
instantiate multiple KVS and flash backends for testing.

Changes is this CL to potentially split out:
- KVS dump command to log contents
- Re-enabling function and file display in log (useful!)
- Hex dumping to log

Change-Id: Ib1b25a01aa29eec3d3acd09e40205c23ded7bf6a
2020-02-03 23:21:15 +00:00
Wyatt Hepler
4da1fcb4b2 pw_kvs: Initial commit of new KVS design
Builds, but lots more work needed.

Fun fact: this code was written collaboratively in a Google Doc.

Change-Id: I8a89c5d0fdc71ec28cf432350e65d17e24a6f25c
2020-01-31 14:38:37 -08:00