pw_kvs: Add KVS options for GC and recovery

Add KVS configuration options for
- Type of automatic garbage collection on write
- When/how to handle KVS self-healing recovery

Change-Id: I8f6fdfc05ca1491a3b0e3a699060018637bd967b
diff --git a/pw_kvs/key_value_store.cc b/pw_kvs/key_value_store.cc
index 9aed5fe..df125d0 100644
--- a/pw_kvs/key_value_store.cc
+++ b/pw_kvs/key_value_store.cc
@@ -754,7 +754,8 @@
 Status KeyValueStore::FindOrRecoverSectorWithSpace(SectorDescriptor** sector,
                                                    size_t size) {
   Status result = FindSectorWithSpace(sector, size, kAppendEntry);
-  if (result == Status::RESOURCE_EXHAUSTED && options_.partial_gc_on_write) {
+  if (result == Status::RESOURCE_EXHAUSTED &&
+      options_.gc_on_write != GargbageCollectOnWrite::kDisabled) {
     // Garbage collect and then try again to find the best sector.
     TRY(GarbageCollectPartial());
     return FindSectorWithSpace(sector, size, kAppendEntry);
diff --git a/pw_kvs/key_value_store_error_handling_test.cc b/pw_kvs/key_value_store_error_handling_test.cc
index a13010d..fb04bdc 100644
--- a/pw_kvs/key_value_store_error_handling_test.cc
+++ b/pw_kvs/key_value_store_error_handling_test.cc
@@ -93,7 +93,7 @@
 constexpr uint32_t kMagic = 0xc001beef;
 constexpr EntryFormat kFormat{.magic = kMagic, .checksum = &checksum};
 constexpr Options kNoGcOptions{
-    .partial_gc_on_write = false,
+    .gc_on_write = GargbageCollectOnWrite::kDisabled,
     .verify_on_read = true,
     .verify_on_write = true,
 };
diff --git a/pw_kvs/public/pw_kvs/key_value_store.h b/pw_kvs/public/pw_kvs/key_value_store.h
index 5e64146..cb76aa9 100644
--- a/pw_kvs/public/pw_kvs/key_value_store.h
+++ b/pw_kvs/public/pw_kvs/key_value_store.h
@@ -33,12 +33,38 @@
 
 namespace pw::kvs {
 
+enum class GargbageCollectOnWrite {
+  // Disable all automatic garbage collection on write.
+  kDisabled,
+
+  // Allow up to a single sector, if needed, to be garbage collected on write.
+  kOneSector,
+
+  // Allow as many sectors as needed be garbage collected on write.
+  kAsManySectorsNeeded,
+};
+
+enum class ErrorRecovery {
+  // Immediately do full recovery of any errors that are detected.
+  kImmediate,
+
+  // Recover from errors, but do some time consuming steps at a later time. Such
+  // as waiting to garbage collect sectors with corrupt entries until the next
+  // garbage collection.
+  kLazy,
+};
+
 struct Options {
-  // Perform garbage collection if necessary when writing. If true, garbage
-  // collection is attempted if space for an entry cannot be found. This is a
-  // relatively lengthy operation. If false, Put calls that would require
-  // garbage collection fail with RESOURCE_EXHAUSTED.
-  bool partial_gc_on_write = true;
+  // Perform garbage collection if necessary when writing. If not kDisabled,
+  // garbage collection is attempted if space for an entry cannot be found. This
+  // is a relatively lengthy operation. If kDisabled, Put calls that would
+  // require garbage collection fail with RESOURCE_EXHAUSTED.
+  GargbageCollectOnWrite gc_on_write =
+      GargbageCollectOnWrite::kAsManySectorsNeeded;
+
+  // When the KVS handles errors that are discovered, such as corrupt entries,
+  // not enough redundant copys of an entry, etc.
+  ErrorRecovery recovery = ErrorRecovery::kLazy;
 
   // Verify an entry's checksum after reading it from flash.
   bool verify_on_read = true;