summaryrefslogtreecommitdiffhomepage
path: root/pkg/state/statefile/statefile.go
diff options
context:
space:
mode:
authorZhaozhong Ni <nzz@google.com>2018-08-24 14:52:23 -0700
committerShentubot <shentubot@google.com>2018-08-24 14:53:31 -0700
commita6b00502b04ced2f12cfcf35c6f276cff349737b (patch)
treed443ea0679091b193bcc5568f0aa5aff3ba1a0f3 /pkg/state/statefile/statefile.go
parent02dfceab6d4c4a2a3342ef69be0265b7ab03e5d7 (diff)
compressio: support optional hashing and eliminate hashio.
Compared to previous compressio / hashio nesting, there is up to 100% speedup. PiperOrigin-RevId: 210161269 Change-Id: I481aa9fe980bb817fe465fe34d32ea33fc8abf1c
Diffstat (limited to 'pkg/state/statefile/statefile.go')
-rw-r--r--pkg/state/statefile/statefile.go11
1 files changed, 3 insertions, 8 deletions
diff --git a/pkg/state/statefile/statefile.go b/pkg/state/statefile/statefile.go
index 0b4eff8fa..9c86c1934 100644
--- a/pkg/state/statefile/statefile.go
+++ b/pkg/state/statefile/statefile.go
@@ -57,7 +57,6 @@ import (
"crypto/sha256"
"gvisor.googlesource.com/gvisor/pkg/binary"
"gvisor.googlesource.com/gvisor/pkg/compressio"
- "gvisor.googlesource.com/gvisor/pkg/hashio"
)
// keySize is the AES-256 key length.
@@ -139,13 +138,11 @@ func NewWriter(w io.Writer, key []byte, metadata map[string]string) (io.WriteClo
}
}
- w = hashio.NewWriter(w, h)
-
// Wrap in compression. We always use "best speed" mode here. When using
// "best compression" mode, there is usually only a little gain in file
// size reduction, which translate to even smaller gain in restore
// latency reduction, while inccuring much more CPU usage at save time.
- return compressio.NewWriter(w, compressionChunkSize, flate.BestSpeed)
+ return compressio.NewWriter(w, key, compressionChunkSize, flate.BestSpeed)
}
// MetadataUnsafe reads out the metadata from a state file without verifying any
@@ -204,7 +201,7 @@ func metadata(r io.Reader, h hash.Hash) (map[string]string, error) {
return nil, err
}
if !hmac.Equal(cur, buf) {
- return nil, hashio.ErrHashMismatch
+ return nil, compressio.ErrHashMismatch
}
}
@@ -226,10 +223,8 @@ func NewReader(r io.Reader, key []byte) (io.Reader, map[string]string, error) {
return nil, nil, err
}
- r = hashio.NewReader(r, h)
-
// Wrap in compression.
- rc, err := compressio.NewReader(r)
+ rc, err := compressio.NewReader(r, key)
if err != nil {
return nil, nil, err
}