Skip to content

Trigger block device rescan via PUT /actions #430

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

Merged
merged 4 commits into from
Aug 3, 2018
Merged

Trigger block device rescan via PUT /actions #430

merged 4 commits into from
Aug 3, 2018

Conversation

alxiord
Copy link

@alxiord alxiord commented Jul 31, 2018

Changes

  • renamed AsyncRequest to Request and refactored *Request structs accordingly to facilitate sync requests to /actions as well as async ones. PUT /actions used to create an async request that had to be queried with GET.
  • maded the action IDs optional as sync ones don't need and ID.
  • added an optional payload field to the /actions resource. Future actions should use this to encapsulate the necessary information. For block device rescan, payload contains the block device's ID.
  • added another action type to trigger block device rescan. This is a sync request that replaces the PUT /drives.
  • PUT /drives now returns 403 after guest boot.
  • added unit tests and integration tests verifying that PUT /drives is not allowed anymore and that the rescan works properly.

Fixes #280.
Partially addresses #409 as it cleans up the logic for updating drive resources.

Testing

  • Style, build and unit testing covered by pytest.
  • Coverage = 64.4%
  • Added integration tests for the rescan scenario.

Copy link
Member

@andreeaflorescu andreeaflorescu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code is much improved now <3 I like the general direction, but there are some nits here and there.

vmm/Cargo.toml Outdated
@@ -7,6 +7,7 @@ authors = ["Amazon firecracker team <[email protected]>"]
libc = ">=0.2.39"
epoll = "=2.1.0"
scopeguard = "=0.3.3"
serde_json = "=1.0.9"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use >=1.0.9

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

device_type: DeviceType,
device_resource_id: String,
force: bool,
pub device_type: DeviceType,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need the fields to be public?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For easy instantiation and comparison (inside tests). It would be cumbersome to add getters, setters and builders in the test section.

vmm/src/lib.rs Outdated
@@ -618,6 +615,16 @@ impl Vmm {
self.network_interface_configs.put(body)
}

fn rescan_device(&mut self, body: RequestBody) -> result::Result<SyncOkStatus, SyncError> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is more of a nit, but I don't think you still need both the rescan and rescan_device functions. It adds a bit of confusion because it is not very clear what is the difference between them. For clarity, I would only keep handle_rescan_block_device, which would be the function handling the communication with the API thread and a function rescan_block_device that actually implements the VMM logic.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Only handle_rescan_block_device and rescan_block_device are left.

}
}

#[test]
fn test_to_parsed_request() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this test gone?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's moved to actions.rs -> test_into_parsed_request because RequestBody no longer has a to_parsed_request method, but implements the IntoParsedRequest trait instead. Since actions::IntoParsedRequest can return either a SyncRequest or an AsyncRequest, it didn't make sense for the test to stay in the async module.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I totally missed that, sorry.

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
pub struct RequestBody {
pub action_id: String,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The action_id can be optional as it will only be used for Async requests. When we change InstanceStart & InstanceHalt to also be sync requests, we can remove it altogether.
Making the action_id optional would require changes in into_parsed_request. We should unwrap the action_id only when parsing InstanceStart and the InstanceHalt.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

// json body into this.
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
pub struct RequestBody {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ActionBody seems like a better name for this struct.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

PUT Requests to /actions don't necessarily need to be async. Renaming to
avoid confusion when the need for sync PUT /actions requests arises
(soon). Moving structs related to /actions to a separate file. Preparing
the code for the addition of sync requests to /actions.

Signed-off-by: Alexandra Iordache <[email protected]>
andreeaflorescu
andreeaflorescu previously approved these changes Aug 2, 2018
Alexandra Iordache added 3 commits August 2, 2018 14:35
Made action_id optional in the request body, as sync actions don't
need an ID.
Added a new action that triggers block device rescan. PUT /drives is no
longer allowed after the guest boots.

Signed-off-by: Alexandra Iordache <[email protected]>
Signed-off-by: Alexandra Iordache <[email protected]>
@alxiord alxiord merged commit 9c26e78 into firecracker-microvm:master Aug 3, 2018
@alxiord alxiord deleted the updatedrive branch August 3, 2018 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants