Skip to content

Commit

Permalink
Allow non fs stores as lower layer of overlay stores.
Browse files Browse the repository at this point in the history
The local-overlay:// documentation states that any store can be
specified as lower, e.g. another daemon store, but the code currently
downcasts the store to LocalFSStore unconditionally, which makes it
impossible to use any other store as lower.

The only reason I found to do the downcast is to perform an optional
check-mount action, which checks if the lower and upper stores are
indeed overlayed correctly.

This change relaxes that undocumented constraint and unlocks non-trivial
store compositions.
  • Loading branch information
vkryachko committed Nov 7, 2024
1 parent 0ed5af1 commit 8840a5c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/libstore/local-overlay-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ LocalOverlayStore::LocalOverlayStore(std::string_view scheme, PathView path, con
, Store(params)
, LocalFSStore(params)
, LocalStore(params)
, lowerStore(openStore(percentDecode(lowerStoreUri.get())).dynamic_pointer_cast<LocalFSStore>())
, lowerStore(openStore(percentDecode(lowerStoreUri.get())))
{
auto fsStore = lowerStore.dynamic_pointer_cast<LocalFSStore>();
if (checkMount.get()) {
if (!fsStore) {
throw Error("check-mount is only supported for local filesystem stores, but '%s' store is specified", lowerStore->getUri());
}
std::smatch match;
std::string mountInfo;
auto mounts = readFile(std::filesystem::path{"/proc/self/mounts"});
Expand All @@ -45,7 +49,7 @@ LocalOverlayStore::LocalOverlayStore(std::string_view scheme, PathView path, con
return std::regex_search(mountInfo, std::regex("\\b" + option + "=" + value + "( |,)"));
};

auto expectedLowerDir = lowerStore->realStoreDir.get();
auto expectedLowerDir = fsStore->realStoreDir.get();
if (!checkOption("lowerdir", expectedLowerDir) || !checkOption("upperdir", upperLayer)) {
debug("expected lowerdir: %s", expectedLowerDir);
debug("expected upperdir: %s", upperLayer);
Expand Down
2 changes: 1 addition & 1 deletion src/libstore/local-overlay-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class LocalOverlayStore : public virtual LocalOverlayStoreConfig, public virtual
* is that store's store dir, and the upper layer is some
* scratch storage just for us.
*/
ref<LocalFSStore> lowerStore;
ref<Store> lowerStore;

public:
LocalOverlayStore(const Params & params)
Expand Down

0 comments on commit 8840a5c

Please sign in to comment.