Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify block context for reads #1391

Merged
merged 3 commits into from
Jul 31, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Return MissingBlockContext on encryption mismatch
mkeeter committed Jul 24, 2024
commit 410a8743309510e907b9b4e2e1fa1014cdc581f7
50 changes: 28 additions & 22 deletions upstairs/src/deferred.rs
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ use crate::{
BlockRes, ClientId, ImpactedBlocks, Message, RawWrite, Validation,
};
use bytes::BytesMut;
use crucible_common::{integrity_hash, RegionDefinition};
use crucible_common::{integrity_hash, CrucibleError, RegionDefinition};
use crucible_protocol::ReadBlockContext;
use futures::{
future::{ready, Either, Ready},
@@ -234,42 +234,48 @@ impl DeferredRead {
let block_size = data.len() / rs.len();
for (i, r) in rs.iter_mut().enumerate() {
let v = if let Some(ctx) = &self.cfg.encryption_context {
let r = match r {
ReadBlockContext::Empty => None,
match r {
ReadBlockContext::Empty => Ok(None),
ReadBlockContext::Encrypted { ctx } => Ok(Some(*ctx)),
ReadBlockContext::Unencrypted { .. } => {
error!(
self.log,
"expected encrypted but got unencrypted \
block context"
);
None
Err(CrucibleError::MissingBlockContext)
}
ReadBlockContext::Encrypted { ctx } => Some(*ctx),
};
validate_encrypted_read_response(
r,
&mut data[i * block_size..][..block_size],
ctx,
&self.log,
)
}
.and_then(|r| {
validate_encrypted_read_response(
r,
&mut data[i * block_size..][..block_size],
ctx,
&self.log,
)
})
} else {
let r = match r {
ReadBlockContext::Empty => None,
match r {
ReadBlockContext::Empty => Ok(None),
ReadBlockContext::Unencrypted { hash } => {
Ok(Some(*hash))
}
ReadBlockContext::Encrypted { .. } => {
error!(
self.log,
"expected unencrypted but got encrypted \
block context"
);
None
Err(CrucibleError::MissingBlockContext)
}
ReadBlockContext::Unencrypted { hash } => Some(*hash),
};
validate_unencrypted_read_response(
r,
&mut data[i * block_size..][..block_size],
&self.log,
)
}
.and_then(|r| {
validate_unencrypted_read_response(
r,
&mut data[i * block_size..][..block_size],
&self.log,
)
})
};
match v {
Ok(hash) => hashes.push(hash),