Invoke remount-hook program when necessary.

This commit is contained in:
Ben Radford 2023-07-26 14:05:54 +01:00 committed by Ben Radford
parent 33ebae75ca
commit ed14286924
4 changed files with 29 additions and 2 deletions

View file

@ -176,6 +176,14 @@ void LocalOverlayStore::registerValidPaths(const ValidPathInfos & infos)
} }
void LocalOverlayStore::collectGarbage(const GCOptions & options, GCResults & results)
{
LocalStore::collectGarbage(options, results);
remountIfNecessary();
}
void LocalOverlayStore::deleteStorePath(const Path & path, uint64_t & bytesFreed) void LocalOverlayStore::deleteStorePath(const Path & path, uint64_t & bytesFreed)
{ {
auto mergedDir = realStoreDir.get() + "/"; auto mergedDir = realStoreDir.get() + "/";
@ -224,6 +232,8 @@ void LocalOverlayStore::optimiseStore()
done++; done++;
act.progress(done, paths.size()); act.progress(done, paths.size());
} }
remountIfNecessary();
} }
@ -235,6 +245,18 @@ Path LocalOverlayStore::toRealPathForHardLink(const StorePath & path)
} }
void LocalOverlayStore::remountIfNecessary()
{
if (remountHook.get().empty()) {
warn("'%s' needs remounting, set remount-hook to do this automatically", realStoreDir.get());
} else {
runProgram(remountHook, false, {realStoreDir});
}
_remountRequired = false;
}
static RegisterStoreImplementation<LocalOverlayStore, LocalOverlayStoreConfig> regLocalOverlayStore; static RegisterStoreImplementation<LocalOverlayStore, LocalOverlayStoreConfig> regLocalOverlayStore;
} }

View file

@ -118,12 +118,16 @@ private:
void queryRealisationUncached(const DrvOutput&, void queryRealisationUncached(const DrvOutput&,
Callback<std::shared_ptr<const Realisation>> callback) noexcept override; Callback<std::shared_ptr<const Realisation>> callback) noexcept override;
void collectGarbage(const GCOptions & options, GCResults & results) override;
void deleteStorePath(const Path & path, uint64_t & bytesFreed) override; void deleteStorePath(const Path & path, uint64_t & bytesFreed) override;
void optimiseStore() override; void optimiseStore() override;
Path toRealPathForHardLink(const StorePath & storePath) override; Path toRealPathForHardLink(const StorePath & storePath) override;
void remountIfNecessary();
bool _remountRequired = false; bool _remountRequired = false;
}; };

View file

@ -27,8 +27,7 @@ lowerInode=$(stat -c %i "$storeA/$lowerPath")
[[ "$upperInode" != "$lowerInode" ]] [[ "$upperInode" != "$lowerInode" ]]
# Now delete file via the overlay store # Now delete file via the overlay store
nix-store --store "$storeB" --delete "$upperPath" nix-store --store "$storeB&remount-hook=$PWD/remount.sh" --delete "$upperPath"
remountOverlayfs
# Check there is no longer a file in upper layer # Check there is no longer a file in upper layer
expect 1 stat "$storeBTop/${upperPath##/nix/store/}" expect 1 stat "$storeBTop/${upperPath##/nix/store/}"

View file

@ -0,0 +1,2 @@
#!/usr/bin/env bash
mount -o remount "$1"