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

Drop support for forward compatibility #4194

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
Refactored error propagation to avoid logging and printing an error on
exits with a zero exit code. Now, on successful exit
"Firecracker exited successfully" is logged.
- [#4194](https://github.com/firecracker-microvm/firecracker/pull/4194):
Removed support for creating Firecracker snapshots targeting older versions
of Firecracker. With this change, running 'firecracker --version' will not
print the supported snapshot versions.

### Deprecated

Expand Down
2 changes: 0 additions & 2 deletions src/api_server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,6 @@ mod tests {
snapshot_type: SnapshotType::Diff,
snapshot_path: PathBuf::new(),
mem_file_path: PathBuf::new(),
version: None,
})),
start_time_us,
);
Expand All @@ -295,7 +294,6 @@ mod tests {
snapshot_type: SnapshotType::Diff,
snapshot_path: PathBuf::new(),
mem_file_path: PathBuf::new(),
version: None,
})),
start_time_us,
);
Expand Down
3 changes: 1 addition & 2 deletions src/api_server/src/parsed_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -846,8 +846,7 @@ pub mod tests {
fn test_try_from_put_snapshot() {
let (mut sender, receiver) = UnixStream::pair().unwrap();
let mut connection = HttpConnection::new(receiver);
let body =
"{ \"snapshot_path\": \"foo\", \"mem_file_path\": \"bar\", \"version\": \"0.23.0\" }";
let body = "{ \"snapshot_path\": \"foo\", \"mem_file_path\": \"bar\" }";
sender
.write_all(http_request("PUT", "/snapshot/create", Some(body)).as_bytes())
.unwrap();
Expand Down
32 changes: 6 additions & 26 deletions src/api_server/src/request/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ use crate::request::{Body, Method, StatusCode};

/// Deprecation message for the `mem_file_path` field.
const LOAD_DEPRECATION_MESSAGE: &str = "PUT /snapshot/load: mem_file_path field is deprecated.";
/// Deprecation message for the `version` field.
const CREATE_WITH_VERSION_DEPRECATION_MESSAGE: &str =
"PUT /snapshot/create: 'version' field is deprecated.";
/// None of the `mem_backend` or `mem_file_path` fields has been specified.
pub const MISSING_FIELD: &str =
"missing field: either `mem_backend` or `mem_file_path` is required";
Expand Down Expand Up @@ -56,19 +53,9 @@ pub(crate) fn parse_patch_vm_state(body: &Body) -> Result<ParsedRequest, Error>

fn parse_put_snapshot_create(body: &Body) -> Result<ParsedRequest, Error> {
let snapshot_config = serde_json::from_slice::<CreateSnapshotParams>(body.raw())?;
let uses_deprecated_version_field = snapshot_config.version.is_some();

let mut parsed_req = ParsedRequest::new_sync(VmmAction::CreateSnapshot(snapshot_config));
// `version` field is deprecated as a parameter for `CreateSnapshotParams`.
// Add a deprecation message if the request includes the parameter.
if uses_deprecated_version_field {
METRICS.deprecated_api.deprecated_http_api_calls.inc();
parsed_req
.parsing_info()
.append_deprecation_message(CREATE_WITH_VERSION_DEPRECATION_MESSAGE);
}

Ok(parsed_req)
Ok(ParsedRequest::new_sync(VmmAction::CreateSnapshot(
snapshot_config,
)))
}

fn parse_put_snapshot_load(body: &Body) -> Result<ParsedRequest, Error> {
Expand Down Expand Up @@ -127,7 +114,7 @@ fn parse_put_snapshot_load(body: &Body) -> Result<ParsedRequest, Error> {

#[cfg(test)]
mod tests {
use vmm::vmm_config::snapshot::{MemBackendConfig, MemBackendType, Version};
use vmm::vmm_config::snapshot::{MemBackendConfig, MemBackendType};

use super::*;
use crate::parsed_request::tests::{depr_action_from_req, vmm_action_from_request};
Expand All @@ -141,21 +128,15 @@ mod tests {
let body = r#"{
"snapshot_type": "Diff",
"snapshot_path": "foo",
"mem_file_path": "bar",
"version": "0.23.0"
"mem_file_path": "bar"
}"#;
let expected_config = CreateSnapshotParams {
snapshot_type: SnapshotType::Diff,
snapshot_path: PathBuf::from("foo"),
mem_file_path: PathBuf::from("bar"),
version: Some(Version::new(0, 23, 0)),
};
let parsed_request = parse_put_snapshot(&Body::new(body), Some("create")).unwrap();
assert_eq!(
depr_action_from_req(
parsed_request,
Some(CREATE_WITH_VERSION_DEPRECATION_MESSAGE.to_string())
),
vmm_action_from_request(parse_put_snapshot(&Body::new(body), Some("create")).unwrap()),
VmmAction::CreateSnapshot(expected_config)
);

Expand All @@ -167,7 +148,6 @@ mod tests {
snapshot_type: SnapshotType::Full,
snapshot_path: PathBuf::from("foo"),
mem_file_path: PathBuf::from("bar"),
version: None,
};
assert_eq!(
vmm_action_from_request(parse_put_snapshot(&Body::new(body), Some("create")).unwrap()),
Expand Down
6 changes: 0 additions & 6 deletions src/api_server/swagger/firecracker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1177,12 +1177,6 @@ definitions:
description:
Type of snapshot to create. It is optional and by default, a full
snapshot is created.
version:
type: string
description:
The microVM version for which we want to create the snapshot.
It is optional and it defaults to the current version. This parameter
has been deprecated and it will be removed in future Firecracker release.

SnapshotLoadParams:
type: object
Expand Down
15 changes: 0 additions & 15 deletions src/firecracker/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ fn main_exec() -> Result<(), MainError> {

if arguments.flag_present("version") {
println!("Firecracker v{}\n", FIRECRACKER_VERSION);
print_supported_snapshot_versions();
return Ok(());
}

Expand Down Expand Up @@ -509,20 +508,6 @@ pub fn enable_ssbd_mitigation() {
#[allow(unused)]
fn warn_deprecated_parameters() {}

// Print supported snapshot data format versions.
fn print_supported_snapshot_versions() {
let mut versions: Vec<_> = FC_VERSION_TO_SNAP_VERSION
.iter()
.map(|(key, _)| key.clone())
.collect();
versions.sort();

println!("Supported snapshot data format versions:");
for v in versions.iter() {
println!("{v}");
}
}

#[derive(Debug, thiserror::Error, displaydoc::Display)]
enum SnapshotVersionError {
/// Unable to open snapshot state file: {0}
Expand Down
20 changes: 10 additions & 10 deletions src/vmm/src/device_manager/mmio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,16 +294,6 @@ impl MMIODeviceManager {
&self.id_to_dev_info
}

#[cfg(target_arch = "x86_64")]
/// Gets the number of interrupts used by the devices registered.
pub fn used_irqs_count(&self) -> usize {
let mut irq_number = 0;
self.get_device_info()
.iter()
.for_each(|(_, device_info)| irq_number += device_info.irqs.len());
irq_number
}

/// Gets the specified device.
pub fn get_device(
&self,
Expand Down Expand Up @@ -488,6 +478,16 @@ mod tests {
self.register_mmio_virtio_for_boot(vm, dev_id.to_string(), mmio_device, cmdline)?;
Ok(device_info.addr)
}

#[cfg(target_arch = "x86_64")]
/// Gets the number of interrupts used by the devices registered.
pub fn used_irqs_count(&self) -> usize {
let mut irq_number = 0;
self.get_device_info()
.iter()
.for_each(|(_, device_info)| irq_number += device_info.irqs.len());
irq_number
}
}

#[allow(dead_code)]
Expand Down
60 changes: 4 additions & 56 deletions src/vmm/src/device_manager/persist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::sync::{Arc, Mutex};

use event_manager::{MutEventSubscriber, SubscriberOps};
use kvm_ioctls::VmFd;
use log::{error, warn};
use log::error;
use snapshot::Persist;
use versionize::{VersionMap, Versionize, VersionizeError, VersionizeResult};
use versionize_derive::Versionize;
Expand Down Expand Up @@ -181,13 +181,13 @@ pub struct DeviceStates {
/// Vsock device state.
pub vsock_device: Option<ConnectedVsockState>,
/// Balloon device state.
#[version(start = 2, ser_fn = "balloon_serialize")]
#[version(start = 2)]
pub balloon_device: Option<ConnectedBalloonState>,
/// Mmds version.
#[version(start = 3, ser_fn = "mmds_version_serialize")]
#[version(start = 3)]
pub mmds_version: Option<MmdsVersionState>,
/// Entropy device state.
#[version(start = 4, ser_fn = "entropy_serialize")]
#[version(start = 4)]
pub entropy_device: Option<ConnectedEntropyState>,
}

Expand All @@ -202,39 +202,6 @@ pub enum SharedDeviceType {
Entropy(Arc<Mutex<Entropy>>),
}

impl DeviceStates {
fn balloon_serialize(&mut self, target_version: u16) -> VersionizeResult<()> {
if target_version < 2 && self.balloon_device.is_some() {
return Err(VersionizeError::Semantic(
"Target version does not implement the virtio-balloon device.".to_owned(),
));
}

Ok(())
}

fn mmds_version_serialize(&mut self, target_version: u16) -> VersionizeResult<()> {
if target_version < 3 && self.mmds_version.is_some() {
warn!(
"Target version does not support persisting the MMDS version. The default will be \
used when restoring."
);
}

Ok(())
}

fn entropy_serialize(&mut self, target_version: u16) -> VersionizeResult<()> {
if target_version < 4 && self.entropy_device.is_some() {
return Err(VersionizeError::Semantic(
"Target version does not support persisting the virtio-rng device.".to_owned(),
));
}

Ok(())
}
}

pub struct MMIODevManagerConstructorArgs<'a> {
pub mem: GuestMemoryMmap,
pub vm: &'a VmFd,
Expand Down Expand Up @@ -769,15 +736,6 @@ mod tests {
};
insert_vsock_device(&mut vmm, &mut cmdline, &mut event_manager, vsock_config);

assert_eq!(
vmm.mmio_device_manager
.save()
.serialize(&mut buf.as_mut_slice(), &version_map, 1),
Err(VersionizeError::Semantic(
"Target version does not implement the virtio-balloon device.".to_string()
))
);

version_map
.new_version()
.set_type_version(DeviceStates::type_id(), 2);
Expand Down Expand Up @@ -815,16 +773,6 @@ mod tests {
.new_version()
.set_type_version(DeviceStates::type_id(), 4);

// Entropy device not supported in version < 4
assert_eq!(
vmm.mmio_device_manager
.save()
.serialize(&mut buf.as_mut_slice(), &version_map, 3),
Err(VersionizeError::Semantic(
"Target version does not support persisting the virtio-rng device.".to_string()
))
);

version_map
.new_version()
.set_type_version(DeviceStates::type_id(), 4)
Expand Down
20 changes: 1 addition & 19 deletions src/vmm/src/devices/virtio/block/persist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,35 +88,17 @@ impl From<FileEngineTypeState> for FileEngineType {
pub struct BlockState {
id: String,
partuuid: Option<String>,
#[version(
start = 2,
ser_fn = "block_cache_type_ser",
default_fn = "default_cache_type_flush"
)]
#[version(start = 2, default_fn = "default_cache_type_flush")]
cache_type: CacheTypeState,
root_device: bool,
disk_path: String,
virtio_state: VirtioDeviceState,
rate_limiter_state: RateLimiterState,
#[version(start = 3)]
// We don't need to specify a `ser_fn` for the `file_engine_type` since snapshots created in
// v1.0 are incompatible with older FC versions (due to incompatible notification suppression
// feature).
file_engine_type: FileEngineTypeState,
}

impl BlockState {
fn block_cache_type_ser(&mut self, target_version: u16) -> VersionizeResult<()> {
if target_version < 3 && self.cache_type != CacheTypeState::Unsafe {
warn!(
"Target version does not implement the current cache type. Defaulting to \
\"unsafe\" mode."
);
}

Ok(())
}

fn default_cache_type_flush(_source_version: u16) -> CacheTypeState {
CacheTypeState::Unsafe
}
Expand Down
12 changes: 1 addition & 11 deletions src/vmm/src/devices/virtio/net/persist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use crate::vstate::memory::GuestMemoryMmap;
pub struct NetConfigSpaceState {
#[version(end = 2, default_fn = "def_guest_mac_old")]
guest_mac: [u8; MAC_ADDR_LEN as usize],
#[version(start = 2, de_fn = "de_guest_mac_v2", ser_fn = "ser_guest_mac_v2")]
#[version(start = 2, de_fn = "de_guest_mac_v2")]
guest_mac_v2: Option<MacAddr>,
}

Expand All @@ -45,16 +45,6 @@ impl NetConfigSpaceState {
Ok(())
}

fn ser_guest_mac_v2(&mut self, _target_version: u16) -> VersionizeResult<()> {
// v1.1 and older versions do not have optional MAC address.
warn!("Saving to older snapshot version, optional MAC address will not be saved.");
match self.guest_mac_v2 {
Some(mac) => self.guest_mac = mac.into(),
None => self.guest_mac = Default::default(),
}
Ok(())
}

fn def_guest_mac_old(_: u16) -> [u8; MAC_ADDR_LEN as usize] {
// v1.2 and newer don't use this field anyway
Default::default()
Expand Down
12 changes: 1 addition & 11 deletions src/vmm/src/devices/virtio/persist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,7 @@ pub struct VirtioDeviceState {
/// List of queues.
pub queues: Vec<QueueState>,
/// The MMIO interrupt status.
#[version(
start = 2,
de_fn = "de_interrupt_status",
ser_fn = "ser_interrupt_status"
)]
#[version(start = 2, de_fn = "de_interrupt_status")]
pub interrupt_status: u32,
/// The MMIO interrupt status as a usize.
#[version(end = 2)]
Expand Down Expand Up @@ -188,12 +184,6 @@ impl VirtioDeviceState {
}
Ok(())
}

fn ser_interrupt_status(&mut self, _target_version: u16) -> VersionizeResult<()> {
// v1 uses a usize type for interrupt status.
self.interrupt_status_old = self.interrupt_status as usize;
Ok(())
}
}

/// Transport information saved in snapshot.
Expand Down
Loading