-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request NixOS#8 from NixLayeredStore/overlayfs-store-more-…
…tests Implement deduplication and add more test cases
- Loading branch information
Showing
15 changed files
with
213 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eu -o pipefail | ||
|
||
set -x | ||
|
||
source common.sh | ||
|
||
# Avoid store dir being inside sandbox build-dir | ||
unset NIX_STORE_DIR | ||
unset NIX_STATE_DIR | ||
|
||
storeDirs | ||
|
||
initLowerStore | ||
|
||
mountOverlayfs | ||
|
||
# Add something to the overlay store | ||
overlayPath=$(addTextToStore "$storeB" "overlay-file" "Add to overlay store") | ||
stat "$storeBRoot/$overlayPath" | ||
|
||
# Now add something to the lower store | ||
lowerPath=$(addTextToStore "$storeA" "lower-file" "Add to lower store") | ||
stat "$storeVolume/store-a/$lowerPath" | ||
|
||
# Remount overlayfs to ensure synchronization | ||
remountOverlayfs | ||
|
||
# Path should be accessible via overlay store | ||
stat "$storeBRoot/$lowerPath" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
source common.sh | ||
|
||
requireEnvironment | ||
setupConfig | ||
execUnshare ./add-lower-inner.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eu -o pipefail | ||
|
||
set -x | ||
|
||
source common.sh | ||
|
||
# Avoid store dir being inside sandbox build-dir | ||
unset NIX_STORE_DIR | ||
unset NIX_STATE_DIR | ||
|
||
storeDirs | ||
|
||
initLowerStore | ||
|
||
mountOverlayfs | ||
|
||
# Create a file to add to store | ||
dupFilePath="$TEST_ROOT/dup-file" | ||
echo Duplicate > "$dupFilePath" | ||
|
||
# Add it to the overlay store (it will be written to the upper layer) | ||
dupFileStorePath=$(nix-store --store "$storeB" --add "$dupFilePath") | ||
|
||
# Now add it to the lower store so the store path is duplicated | ||
nix-store --store "$storeA" --add "$dupFilePath" | ||
|
||
# Ensure overlayfs and layers and synchronised | ||
remountOverlayfs | ||
|
||
dupFilename="${dupFileStorePath#/nix/store}" | ||
lowerPath="$storeA/$dupFileStorePath" | ||
upperPath="$storeBTop/$dupFilename" | ||
overlayPath="$storeBRoot/nix/store/$dupFilename" | ||
|
||
# Check store path exists in both layers and overlay | ||
lowerInode=$(stat -c %i "$lowerPath") | ||
upperInode=$(stat -c %i "$upperPath") | ||
overlayInode=$(stat -c %i "$overlayPath") | ||
[[ $upperInode == $overlayInode ]] | ||
[[ $upperInode != $lowerInode ]] | ||
|
||
# Run optimise to deduplicate store paths | ||
nix-store --store "$storeB" --optimise | ||
remountOverlayfs | ||
|
||
# Check path only exists in lower store | ||
stat "$lowerPath" | ||
stat "$overlayPath" | ||
expect 1 stat "$upperPath" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
source common.sh | ||
|
||
requireEnvironment | ||
setupConfig | ||
execUnshare ./optimise-inner.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eu -o pipefail | ||
|
||
set -x | ||
|
||
source common.sh | ||
|
||
# Avoid store dir being inside sandbox build-dir | ||
unset NIX_STORE_DIR | ||
unset NIX_STATE_DIR | ||
|
||
storeDirs | ||
|
||
initLowerStore | ||
|
||
mountOverlayfs | ||
|
||
# Realise a derivation from the lower store to propagate paths to overlay DB | ||
nix-store --store "$storeB" --realise $drvPath | ||
|
||
# Also ensure dummy file exists in overlay DB | ||
dummyPath=$(nix-store --store "$storeB" --add ../dummy) | ||
|
||
# Verify should be successful at this point | ||
nix-store --store "$storeB" --verify --check-contents | ||
|
||
# Now delete one of the derivation inputs in the lower store | ||
inputDrvFullPath=$(find "$storeA" -name "*-hermetic-input-1.drv") | ||
inputDrvPath=${inputDrvFullPath/*\/nix\/store\///nix/store/} | ||
rm -v "$inputDrvFullPath" | ||
|
||
# And truncate the contents of dummy file in lower store | ||
find "$storeA" -name "*-dummy" -exec truncate -s 0 {} \; | ||
|
||
# Verify should fail with the messages about missing input and modified dummy file | ||
verifyOutput=$(expectStderr 1 nix-store --store "$storeB" --verify --check-contents --repair) | ||
<<<"$verifyOutput" grepQuiet "path '$inputDrvPath' disappeared, but it still has valid referrers!" | ||
<<<"$verifyOutput" grepQuiet "path '$dummyPath' was modified! expected hash" | ||
<<<"$verifyOutput" grepQuiet "store does not support --verify --repair" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
source common.sh | ||
|
||
requireEnvironment | ||
setupConfig | ||
execUnshare ./verify-inner.sh |