| 229 | |
| 230 | namespace { |
| 231 | UnitResult initConfig( |
| 232 | navy::BlockCache::Config& config, |
| 233 | navy::Device* device, |
| 234 | const FlashCacheComponent::PersistenceConfig& persistenceConfig) { |
| 235 | constexpr auto expireCheck = [](navy::BufferView v) -> bool { |
| 236 | return util::isExpired(FlashCacheItem::getExpiryTime(v)); |
| 237 | }; |
| 238 | |
| 239 | if (config.checkExpired) { |
| 240 | return makeError(Error::Code::INVALID_CONFIG, |
| 241 | "expiration callback set in BlockCache::Config but " |
| 242 | "component is going to set it"); |
| 243 | } else if (!device) { |
| 244 | return makeError(Error::Code::INVALID_CONFIG, |
| 245 | "need to supply a device to create()"); |
| 246 | } else if (config.device && config.device != device) { |
| 247 | return makeError(Error::Code::INVALID_CONFIG, |
| 248 | "device set in BlockCache::Config is not the same as " |
| 249 | "the device passed to create()"); |
| 250 | } else if (config.cacheBaseOffset != 0 && |
| 251 | config.cacheBaseOffset != |
| 252 | device->getIOAlignedSize(persistenceConfig.metadataSize())) { |
| 253 | return makeError(Error::Code::INVALID_CONFIG, |
| 254 | "cacheBaseOffset set in BlockCache::Config but " |
| 255 | "component is going to set it"); |
| 256 | } |
| 257 | |
| 258 | config.device = device; |
| 259 | config.checkExpired = expireCheck; |
| 260 | // TODO for now we're assuming we're the only cache on this flash device |
| 261 | config.cacheBaseOffset = |
| 262 | device->getIOAlignedSize(persistenceConfig.metadataSize()); |
| 263 | return folly::unit; |
| 264 | } |
| 265 | } // namespace |
| 266 | |
| 267 | // ============================================================================ |
no test coverage detected