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

Many protocol adjustments #1522

Merged
merged 8 commits into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
22 changes: 22 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
markdown_changed: ${{ steps.changed-markdown.outputs.any_changed }}
vscode_changed: ${{ steps.changed-vscode.outputs.any_changed }}
ci_changed: ${{ steps.changed-ci.outputs.any_changed }}
protocol_changed: ${{ steps.changed-protocol.outputs.any_changed }}
steps:
- uses: actions/checkout@v3
with:
Expand Down Expand Up @@ -80,6 +81,24 @@ jobs:
with:
files: |
README.md
- name: get protocol changes
id: changed-protocol
uses: tj-actions/changed-files@v36
with:
files: |
mirrord/protocol/**
- name: get protocol changes
aviramha marked this conversation as resolved.
Show resolved Hide resolved
id: changed-protocol-toml
uses: tj-actions/changed-files@v36
with:
files: |
mirrord/protocol/Cargo.toml
- name: verify protocol bump
run: |
if [ "${{ steps.changed-protocol.outputs.any_changed }}" == "true" ] && [ "${{ steps.changed-protocol-toml.outputs.any_changed }}" != "true" ]; then
echo "Error: Protocol has changed but Cargo.toml has not. Please update Cargo.toml."
exit 1
fi
- name: output test
run: |
echo ${{ steps.changed-rs.outputs.any_changed }};
Expand All @@ -92,6 +111,8 @@ jobs:
echo ${{ steps.changed-markdown.outputs.all_changed_files }};
echo ${{ steps.changed-ci.outputs.any_changed }};
echo ${{ steps.changed-ci.outputs.all_changed_files }};
echo ${{ steps.changed-protocol.outputs.any_changed }};
echo ${{ steps.changed-protocol-toml.outputs.any_changed }};
lint:
runs-on: ubuntu-latest
needs: changed_files
Expand Down Expand Up @@ -579,6 +600,7 @@ jobs:
with:
config: "markdownlint-config.json"
args: "README.md"

# We need some "accummulation" job here because bors fails (timeouts) to
# listen on matrix builds.
# Hence, we have some kind of dummy here that bors can listen on
Expand Down
14 changes: 13 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions changelog.d/1355.internal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
change `mirrord-protocol` to have its own versioning. add `mirrord-macros` and `protocol_break` attribute to mark places we want to break on major updates.
Add CI to verify that if protocol is changed, `Cargo.toml` is changed as well (to force bumps)
Fix some of the structs being `OS` controlled, potentially breaking the protocol between different OS's. (`GetDEnts64(RemoteResult<GetDEnts64Response>),`)
7 changes: 7 additions & 0 deletions mirrord/layer/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,13 @@ impl FileHandler {
trace!("DaemonMessage::GetDEnts64Response {getdents64:#?}!");
pop_send(&mut self.getdents64_queue, getdents64)
}
#[cfg(not(target_os = "linux"))]
GetDEnts64(_) => {
error!(
"Received GetDEnts64Response on non-linux platform! Please report this to us!"
);
Ok(())
}
}
}

Expand Down
24 changes: 24 additions & 0 deletions mirrord/macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
name = "mirrord-macros"
version.workspace = true
authors.workspace = true
description.workspace = true
documentation.workspace = true
readme.workspace = true
homepage.workspace = true
repository.workspace = true
license.workspace = true
keywords.workspace = true
categories.workspace = true
publish.workspace = true
edition.workspace = true


[lib]
proc-macro = true

[dependencies]
proc-macro2 = "1"
proc-macro2-diagnostics = "0.10"
syn = { version = "1", features = ["full", "extra-traits"] }
semver.workspace = true
37 changes: 37 additions & 0 deletions mirrord/macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
extern crate proc_macro;

use proc_macro::TokenStream;
use proc_macro2::TokenStream as TokenStream2;
use proc_macro2_diagnostics::SpanDiagnosticExt;
use semver::Version;
use syn::{parse_macro_input, spanned::Spanned};

/// Use [`protocol_break`] to mark code that should be revised when the major version is bumped.
/// For example:
/// #[derive(Encode, Decode, Debug, PartialEq, Eq, Clone)]
/// pub enum StealType {
/// All(Port),
/// FilteredHttp(Port, Filter),
/// #[protocol_break(2)] // We want that when we bump major into 2, we can remove this variant
/// or merge it with the above. FilteredHttpPath(Port, Filter),
/// }
#[proc_macro_attribute]
pub fn protocol_break(attr: TokenStream, input: TokenStream) -> TokenStream {
// Get the version to break on
let break_on_str = parse_macro_input!(attr as syn::LitInt);
let break_on_value = break_on_str.base10_parse::<u64>().unwrap();
let input: TokenStream2 = input.into();
if Version::parse(&std::env::var("CARGO_PKG_VERSION").unwrap())
.unwrap()
.major
>= break_on_value
{
input
.span()
.error("This code should be revised when the major version is bumped.")
.emit_as_expr_tokens()
.into()
} else {
input.into()
}
}
5 changes: 4 additions & 1 deletion mirrord/protocol/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mirrord-protocol"
version.workspace = true
version = "1.0.0"
authors.workspace = true
description.workspace = true
documentation.workspace = true
Expand All @@ -27,6 +27,9 @@ http-body-util = { workspace = true }
fancy-regex = { workspace = true }
libc.workspace = true
socket2.workspace = true
semver.workspace = true

mirrord-macros = { path = "../macros" }

[target.'cfg(target_os = "linux")'.dependencies]
nix.workspace = true
16 changes: 8 additions & 8 deletions mirrord/protocol/src/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ use std::{
use actix_codec::{Decoder, Encoder};
use bincode::{error::DecodeError, Decode, Encode};
use bytes::{Buf, BufMut, BytesMut};
use mirrord_macros::protocol_break;

#[cfg(target_os = "linux")]
use crate::file::{GetDEnts64Request, GetDEnts64Response};
use crate::{
dns::{GetAddrInfoRequest, GetAddrInfoResponse},
file::{
AccessFileRequest, AccessFileResponse, CloseDirRequest, CloseFileRequest, FdOpenDirRequest,
OpenDirResponse, OpenFileRequest, OpenFileResponse, OpenRelativeFileRequest,
ReadDirRequest, ReadDirResponse, ReadFileRequest, ReadFileResponse, ReadLimitedFileRequest,
SeekFileRequest, SeekFileResponse, WriteFileRequest, WriteFileResponse,
WriteLimitedFileRequest, XstatFsRequest, XstatFsResponse, XstatRequest, XstatResponse,
GetDEnts64Request, GetDEnts64Response, OpenDirResponse, OpenFileRequest, OpenFileResponse,
OpenRelativeFileRequest, ReadDirRequest, ReadDirResponse, ReadFileRequest,
ReadFileResponse, ReadLimitedFileRequest, SeekFileRequest, SeekFileResponse,
WriteFileRequest, WriteFileResponse, WriteLimitedFileRequest, XstatFsRequest,
XstatFsResponse, XstatRequest, XstatResponse,
},
outgoing::{
tcp::{DaemonTcpOutgoing, LayerTcpOutgoing},
Expand Down Expand Up @@ -77,7 +77,6 @@ pub enum FileRequest {
FdOpenDir(FdOpenDirRequest),
ReadDir(ReadDirRequest),
CloseDir(CloseDirRequest),
#[cfg(target_os = "linux")]
GetDEnts64(GetDEnts64Request),
}

Expand Down Expand Up @@ -113,11 +112,12 @@ pub enum FileResponse {
XstatFs(RemoteResult<XstatFsResponse>),
ReadDir(RemoteResult<ReadDirResponse>),
OpenDir(RemoteResult<OpenDirResponse>),
#[cfg(target_os = "linux")]
GetDEnts64(RemoteResult<GetDEnts64Response>),
}

/// `-agent` --> `-layer` messages.
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone)]
#[protocol_break(2)]
pub enum DaemonMessage {
Close(String),
Tcp(DaemonTcp),
Expand Down
2 changes: 0 additions & 2 deletions mirrord/protocol/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,14 +383,12 @@ pub struct CloseDirRequest {
pub remote_fd: u64,
}

#[cfg(target_os = "linux")]
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone)]
pub struct GetDEnts64Request {
pub remote_fd: u64,
pub buffer_size: u64,
}

#[cfg(target_os = "linux")]
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone)]
pub struct GetDEnts64Response {
pub fd: u64,
Expand Down