Initializes the IO task for sampling the VMClock shared memory file. A VMClock object will not be created if the daemon is running on a unsupported instance type, the shared memory file is not found or if IMDS fails to provide instance metadata. # Panics - When the vmclock device can not be constructed using the provided shared memory path.
(&mut self, vmclock_shm_path: &str)
| 205 | /// # Panics |
| 206 | /// - When the vmclock device can not be constructed using the provided shared memory path. |
| 207 | pub async fn create_vmclock(&mut self, vmclock_shm_path: &str) { |
| 208 | info!("Creating link local source."); |
| 209 | |
| 210 | info!(?self.vmclock, "Current source entry status."); |
| 211 | if self.vmclock.is_none() { |
| 212 | self.vmclock = { |
| 213 | let (ctrl_sender, ctrl_receiver) = mpsc::channel::<ControlRequest>(1); |
| 214 | // Not all instance types are able to use vmclock. Before attempting to create the |
| 215 | // vmclock object the instance is first determined to be viable. |
| 216 | |
| 217 | // NOTE: There are scenarios when the vmclock should be created, but |
| 218 | // is not -- IMDS timeouts, droplet live updates and IMDS queries too close instance |
| 219 | // launch will result in no vmclock runner, even when the user might expect |
| 220 | // it to. |
| 221 | // |
| 222 | // Future work is required to disambiguate and handle these failure modes as well as identify |
| 223 | // and handle vmclock runner creation on non EC2 instances. |
| 224 | let instance_type = match InstanceType::get_from_imds().await { |
| 225 | Ok(it) => it, |
| 226 | Err(e) => { |
| 227 | warn!(?e, "EC2 instance type not determined. VMClock not enabled."); |
| 228 | return; |
| 229 | } |
| 230 | }; |
| 231 | |
| 232 | // Metal instances do not benefit from the vmclock and the vmclock will not be |
| 233 | // enabled on this instance types. |
| 234 | if instance_type.is_metal() { |
| 235 | info!("EC2 metal instance type determined. Not enabling VMClock"); |
| 236 | return; |
| 237 | } |
| 238 | |
| 239 | info!("EC2 non-metal instance type determined. Enabling VMClock."); |
| 240 | let vmclock = VMClock::construct( |
| 241 | vmclock_shm_path, |
| 242 | ctrl_receiver, |
| 243 | self.clock_disruption_channels.sender.clone(), |
| 244 | ) |
| 245 | .await |
| 246 | .unwrap_or_else(|_| panic!("vmclock device not found {vmclock_shm_path}")); |
| 247 | |
| 248 | let source = Source { |
| 249 | state: SourceState::Initialized(vmclock), |
| 250 | ctrl_sender, |
| 251 | }; |
| 252 | Some(source) |
| 253 | }; |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | /// Returns `VMCLock` if it has been initialized |
| 258 | pub fn vmclock(&self) -> Option<&VMClock> { |
no test coverage detected