Skip to content

Commit c742637

Browse files
committed
refactor(balloon): remove unused restored_from_file
This flag was used for determining how to discard memory, but we previously changed that logic to look at the region mmap and perform the right action depending on that. This commit removes all references to this flag. Signed-off-by: Riccardo Mancini <mancio@amazon.com>
1 parent dbcc9a6 commit c742637

File tree

9 files changed

+20
-52
lines changed

9 files changed

+20
-52
lines changed

src/vmm/src/builder.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,6 @@ pub fn build_microvm_from_snapshot(
462462
event_manager,
463463
vm_resources,
464464
instance_id: &instance_info.id,
465-
restored_from_file: uffd.is_none(),
466465
vcpus_exit_evt: &vcpus_exit_evt,
467466
};
468467
#[allow(unused_mut)]

src/vmm/src/device_manager/mod.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,6 @@ pub struct DeviceRestoreArgs<'a> {
439439
pub vcpus_exit_evt: &'a EventFd,
440440
pub vm_resources: &'a mut VmResources,
441441
pub instance_id: &'a str,
442-
pub restored_from_file: bool,
443442
}
444443

445444
impl std::fmt::Debug for DeviceRestoreArgs<'_> {
@@ -449,7 +448,6 @@ impl std::fmt::Debug for DeviceRestoreArgs<'_> {
449448
.field("vm", &self.vm)
450449
.field("vm_resources", &self.vm_resources)
451450
.field("instance_id", &self.instance_id)
452-
.field("restored_from_file", &self.restored_from_file)
453451
.finish()
454452
}
455453
}
@@ -487,7 +485,6 @@ impl<'a> Persist<'a> for DeviceManager {
487485
event_manager: constructor_args.event_manager,
488486
vm_resources: constructor_args.vm_resources,
489487
instance_id: constructor_args.instance_id,
490-
restored_from_file: constructor_args.restored_from_file,
491488
};
492489
let mmio_devices = MMIODeviceManager::restore(mmio_ctor_args, &state.mmio_state)?;
493490

@@ -505,7 +502,6 @@ impl<'a> Persist<'a> for DeviceManager {
505502
mem: constructor_args.mem,
506503
vm_resources: constructor_args.vm_resources,
507504
instance_id: constructor_args.instance_id,
508-
restored_from_file: constructor_args.restored_from_file,
509505
event_manager: constructor_args.event_manager,
510506
};
511507
let pci_devices = PciDevices::restore(pci_ctor_args, &state.pci_state)?;

src/vmm/src/device_manager/pci_mngr.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,6 @@ pub struct PciDevicesConstructorArgs<'a> {
247247
pub mem: &'a GuestMemoryMmap,
248248
pub vm_resources: &'a mut VmResources,
249249
pub instance_id: &'a str,
250-
pub restored_from_file: bool,
251250
pub event_manager: &'a mut EventManager,
252251
}
253252

@@ -258,7 +257,6 @@ impl<'a> Debug for PciDevicesConstructorArgs<'a> {
258257
.field("mem", &self.mem)
259258
.field("vm_resources", &self.vm_resources)
260259
.field("instance_id", &self.instance_id)
261-
.field("restored_from_file", &self.restored_from_file)
262260
.finish()
263261
}
264262
}
@@ -410,10 +408,7 @@ impl<'a> Persist<'a> for PciDevices {
410408
if let Some(balloon_state) = &state.balloon_device {
411409
let device = Arc::new(Mutex::new(
412410
Balloon::restore(
413-
BalloonConstructorArgs {
414-
mem: mem.clone(),
415-
restored_from_file: constructor_args.restored_from_file,
416-
},
411+
BalloonConstructorArgs { mem: mem.clone() },
417412
&balloon_state.device_state,
418413
)
419414
.unwrap(),
@@ -668,7 +663,6 @@ mod tests {
668663
mem: vmm.vm.guest_memory(),
669664
vm_resources,
670665
instance_id: "microvm-id",
671-
restored_from_file: true,
672666
event_manager: &mut event_manager,
673667
};
674668
let _restored_dev_manager =

src/vmm/src/device_manager/persist.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ pub struct MMIODevManagerConstructorArgs<'a> {
144144
pub event_manager: &'a mut EventManager,
145145
pub vm_resources: &'a mut VmResources,
146146
pub instance_id: &'a str,
147-
pub restored_from_file: bool,
148147
}
149148
impl fmt::Debug for MMIODevManagerConstructorArgs<'_> {
150149
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@@ -412,10 +411,7 @@ impl<'a> Persist<'a> for MMIODeviceManager {
412411

413412
if let Some(balloon_state) = &state.balloon_device {
414413
let device = Arc::new(Mutex::new(Balloon::restore(
415-
BalloonConstructorArgs {
416-
mem: mem.clone(),
417-
restored_from_file: constructor_args.restored_from_file,
418-
},
414+
BalloonConstructorArgs { mem: mem.clone() },
419415
&balloon_state.device_state,
420416
)?));
421417

@@ -686,7 +682,6 @@ mod tests {
686682
event_manager: &mut event_manager,
687683
vm_resources,
688684
instance_id: "microvm-id",
689-
restored_from_file: true,
690685
};
691686
let _restored_dev_manager =
692687
MMIODeviceManager::restore(restore_args, &device_manager_state.mmio_state).unwrap();

src/vmm/src/devices/virtio/balloon/device.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ pub struct Balloon {
173173
pub(crate) device_state: DeviceState,
174174

175175
// Implementation specific fields.
176-
pub(crate) restored_from_file: bool,
177176
pub(crate) stats_polling_interval_s: u16,
178177
pub(crate) stats_timer: TimerFd,
179178
// The index of the previous stats descriptor is saved because
@@ -190,7 +189,6 @@ impl Balloon {
190189
amount_mib: u32,
191190
deflate_on_oom: bool,
192191
stats_polling_interval_s: u16,
193-
restored_from_file: bool,
194192
) -> Result<Balloon, BalloonError> {
195193
let mut avail_features = 1u64 << VIRTIO_F_VERSION_1;
196194

@@ -230,7 +228,6 @@ impl Balloon {
230228
queues,
231229
device_state: DeviceState::Inactive,
232230
activate_evt: EventFd::new(libc::EFD_NONBLOCK).map_err(BalloonError::EventFd)?,
233-
restored_from_file,
234231
stats_polling_interval_s,
235232
stats_timer,
236233
stats_desc_index: None,
@@ -740,7 +737,7 @@ pub(crate) mod tests {
740737
// Test all feature combinations.
741738
for deflate_on_oom in [true, false].iter() {
742739
for stats_interval in [0, 1].iter() {
743-
let mut balloon = Balloon::new(0, *deflate_on_oom, *stats_interval, false).unwrap();
740+
let mut balloon = Balloon::new(0, *deflate_on_oom, *stats_interval).unwrap();
744741
assert_eq!(balloon.device_type(), VIRTIO_ID_BALLOON);
745742

746743
let features: u64 = (1u64 << VIRTIO_F_VERSION_1)
@@ -767,7 +764,7 @@ pub(crate) mod tests {
767764

768765
#[test]
769766
fn test_virtio_read_config() {
770-
let balloon = Balloon::new(0x10, true, 0, false).unwrap();
767+
let balloon = Balloon::new(0x10, true, 0).unwrap();
771768

772769
let cfg = BalloonConfig {
773770
amount_mib: 16,
@@ -801,7 +798,7 @@ pub(crate) mod tests {
801798

802799
#[test]
803800
fn test_virtio_write_config() {
804-
let mut balloon = Balloon::new(0, true, 0, false).unwrap();
801+
let mut balloon = Balloon::new(0, true, 0).unwrap();
805802

806803
let expected_config_space: [u8; BALLOON_CONFIG_SPACE_SIZE] =
807804
[0x00, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
@@ -827,7 +824,7 @@ pub(crate) mod tests {
827824

828825
#[test]
829826
fn test_invalid_request() {
830-
let mut balloon = Balloon::new(0, true, 0, false).unwrap();
827+
let mut balloon = Balloon::new(0, true, 0).unwrap();
831828
let mem = default_mem();
832829
let interrupt = default_interrupt();
833830
// Only initialize the inflate queue to demonstrate invalid request handling.
@@ -888,7 +885,7 @@ pub(crate) mod tests {
888885

889886
#[test]
890887
fn test_inflate() {
891-
let mut balloon = Balloon::new(0, true, 0, false).unwrap();
888+
let mut balloon = Balloon::new(0, true, 0).unwrap();
892889
let mem = default_mem();
893890
let interrupt = default_interrupt();
894891
let infq = VirtQueue::new(GuestAddress(0), &mem, 16);
@@ -960,7 +957,7 @@ pub(crate) mod tests {
960957

961958
#[test]
962959
fn test_deflate() {
963-
let mut balloon = Balloon::new(0, true, 0, false).unwrap();
960+
let mut balloon = Balloon::new(0, true, 0).unwrap();
964961
let mem = default_mem();
965962
let interrupt = default_interrupt();
966963
let defq = VirtQueue::new(GuestAddress(0), &mem, 16);
@@ -1010,7 +1007,7 @@ pub(crate) mod tests {
10101007

10111008
#[test]
10121009
fn test_stats() {
1013-
let mut balloon = Balloon::new(0, true, 1, false).unwrap();
1010+
let mut balloon = Balloon::new(0, true, 1).unwrap();
10141011
let mem = default_mem();
10151012
let interrupt = default_interrupt();
10161013
let statsq = VirtQueue::new(GuestAddress(0), &mem, 16);
@@ -1102,7 +1099,7 @@ pub(crate) mod tests {
11021099

11031100
#[test]
11041101
fn test_process_balloon_queues() {
1105-
let mut balloon = Balloon::new(0x10, true, 0, false).unwrap();
1102+
let mut balloon = Balloon::new(0x10, true, 0).unwrap();
11061103
let mem = default_mem();
11071104
let interrupt = default_interrupt();
11081105
let infq = VirtQueue::new(GuestAddress(0), &mem, 16);
@@ -1117,7 +1114,7 @@ pub(crate) mod tests {
11171114

11181115
#[test]
11191116
fn test_update_stats_interval() {
1120-
let mut balloon = Balloon::new(0, true, 0, false).unwrap();
1117+
let mut balloon = Balloon::new(0, true, 0).unwrap();
11211118
let mem = default_mem();
11221119
let q = VirtQueue::new(GuestAddress(0), &mem, 16);
11231120
balloon.set_queue(INFLATE_INDEX, q.create_queue());
@@ -1130,7 +1127,7 @@ pub(crate) mod tests {
11301127
);
11311128
balloon.update_stats_polling_interval(0).unwrap();
11321129

1133-
let mut balloon = Balloon::new(0, true, 1, false).unwrap();
1130+
let mut balloon = Balloon::new(0, true, 1).unwrap();
11341131
let mem = default_mem();
11351132
let q = VirtQueue::new(GuestAddress(0), &mem, 16);
11361133
balloon.set_queue(INFLATE_INDEX, q.create_queue());
@@ -1148,14 +1145,14 @@ pub(crate) mod tests {
11481145

11491146
#[test]
11501147
fn test_cannot_update_inactive_device() {
1151-
let mut balloon = Balloon::new(0, true, 0, false).unwrap();
1148+
let mut balloon = Balloon::new(0, true, 0).unwrap();
11521149
// Assert that we can't update an inactive device.
11531150
balloon.update_size(1).unwrap_err();
11541151
}
11551152

11561153
#[test]
11571154
fn test_num_pages() {
1158-
let mut balloon = Balloon::new(0, true, 0, false).unwrap();
1155+
let mut balloon = Balloon::new(0, true, 0).unwrap();
11591156
// Switch the state to active.
11601157
balloon.device_state = DeviceState::Activated(ActiveState {
11611158
mem: single_region_mem(32 << 20),

src/vmm/src/devices/virtio/balloon/event_handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ pub mod tests {
142142
#[test]
143143
fn test_event_handler() {
144144
let mut event_manager = EventManager::new().unwrap();
145-
let mut balloon = Balloon::new(0, true, 10, false).unwrap();
145+
let mut balloon = Balloon::new(0, true, 10).unwrap();
146146
let mem = default_mem();
147147
let interrupt = default_interrupt();
148148
let infq = VirtQueue::new(GuestAddress(0), &mem, 16);

src/vmm/src/devices/virtio/balloon/persist.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ pub struct BalloonState {
9595
pub struct BalloonConstructorArgs {
9696
/// Pointer to guest memory.
9797
pub mem: GuestMemoryMmap,
98-
pub restored_from_file: bool,
9998
}
10099

101100
impl Persist<'_> for Balloon {
@@ -122,12 +121,7 @@ impl Persist<'_> for Balloon {
122121
) -> Result<Self, Self::Error> {
123122
// We can safely create the balloon with arbitrary flags and
124123
// num_pages because we will overwrite them after.
125-
let mut balloon = Balloon::new(
126-
0,
127-
false,
128-
state.stats_polling_interval_s,
129-
constructor_args.restored_from_file,
130-
)?;
124+
let mut balloon = Balloon::new(0, false, state.stats_polling_interval_s)?;
131125

132126
let mut num_queues = BALLOON_NUM_QUEUES;
133127
// As per the virtio 1.1 specification, the statistics queue
@@ -184,26 +178,22 @@ mod tests {
184178
let mut mem = vec![0; 4096];
185179

186180
// Create and save the balloon device.
187-
let balloon = Balloon::new(0x42, false, 2, false).unwrap();
181+
let balloon = Balloon::new(0x42, false, 2).unwrap();
188182

189183
Snapshot::new(balloon.save())
190184
.save(&mut mem.as_mut_slice())
191185
.unwrap();
192186

193187
// Deserialize and restore the balloon device.
194188
let restored_balloon = Balloon::restore(
195-
BalloonConstructorArgs {
196-
mem: guest_mem,
197-
restored_from_file: true,
198-
},
189+
BalloonConstructorArgs { mem: guest_mem },
199190
&Snapshot::load_without_crc_check(mem.as_slice())
200191
.unwrap()
201192
.data,
202193
)
203194
.unwrap();
204195

205196
assert_eq!(restored_balloon.device_type(), VIRTIO_ID_BALLOON);
206-
assert!(restored_balloon.restored_from_file);
207197

208198
assert_eq!(restored_balloon.acked_features, balloon.acked_features);
209199
assert_eq!(restored_balloon.avail_features, balloon.avail_features);

src/vmm/src/resources.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1520,7 +1520,7 @@ mod tests {
15201520
.unwrap();
15211521
let err = vm_resources
15221522
.update_from_restored_device(SharedDeviceType::Balloon(Arc::new(Mutex::new(
1523-
Balloon::new(128, false, 0, true).unwrap(),
1523+
Balloon::new(128, false, 0).unwrap(),
15241524
))))
15251525
.unwrap_err();
15261526
assert!(

src/vmm/src/vmm_config/balloon.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,6 @@ impl BalloonBuilder {
8888
cfg.amount_mib,
8989
cfg.deflate_on_oom,
9090
cfg.stats_polling_interval_s,
91-
// `restored` flag is false because this code path
92-
// is never called by snapshot restore functionality.
93-
false,
9491
)?)));
9592

9693
Ok(())
@@ -178,7 +175,7 @@ pub(crate) mod tests {
178175
#[test]
179176
fn test_set_device() {
180177
let mut builder = BalloonBuilder::new();
181-
let balloon = Balloon::new(0, true, 0, true).unwrap();
178+
let balloon = Balloon::new(0, true, 0).unwrap();
182179
builder.set_device(Arc::new(Mutex::new(balloon)));
183180
assert!(builder.inner.is_some());
184181
}

0 commit comments

Comments
 (0)