Skip to content
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
17 changes: 9 additions & 8 deletions src/initrd/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
/// Agent logic running at early boot.
///
/// This is run early-on in initrd, possibly before networking and other
/// services are configured, so it may not be able to use all usual metadata
/// fetcher.
use crate::errors::*;
//! Agent logic running at early boot.
//!
//! This is run early-on in initrd, possibly before networking and other
//! services are configured, so it may not be able to use all usual metadata
//! fetcher.

use crate::errors::*;
use crate::providers::vmware::VmwareProvider;
use crate::providers::MetadataProvider;
use std::fs::File;
use std::io::Write;

Expand All @@ -14,8 +16,7 @@ static KARGS_PATH: &str = "/etc/cmdline.d/50-afterburn-network-kargs.conf";
/// Fetch network kargs for the given provider.
pub(crate) fn fetch_network_kargs(provider: &str) -> Result<Option<String>> {
match provider {
// TODO(lucab): wire-in vmware guestinfo logic.
"vmware" => Ok(None),
"vmware" => VmwareProvider::try_new()?.rd_network_kargs(),
_ => Ok(None),
}
}
Expand Down
21 changes: 15 additions & 6 deletions src/providers/vmware/amd64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,38 @@
//!
//! This uses the guest->host backdoor protocol for introspection.

use error_chain::bail;

use super::VmwareProvider;
use crate::errors::*;
use error_chain::bail;

/// Guestinfo key for network kargs.
static INITRD_NET_KARGS: &str = "guestinfo.afterburn.initrd.network-kargs";

impl VmwareProvider {
/// Build the VMware provider, fetching and caching guestinfo entries.
pub fn try_new() -> Result<Self> {
if !vmw_backdoor::is_vmware_cpu() {
bail!("not running on VMWare CPU");
}

let mut backdoor = vmw_backdoor::probe_backdoor()?;
let mut erpc = backdoor.open_enhanced_chan()?;
let guestinfo_net_kargs = Self::get_net_kargs(&mut erpc)?;
let guestinfo_net_kargs = Self::fetch_guestinfo(&mut erpc, INITRD_NET_KARGS)?;

let provider = Self {
guestinfo_net_kargs,
};

slog_scope::trace!("cached vmware provider: {:?}", provider);
Ok(provider)
}

fn get_net_kargs(_erpc: &mut vmw_backdoor::EnhancedChan) -> Result<Option<String>> {
// TODO(lucab): pick a stable key name and implement this logic.
Ok(None)
/// Retrieve the value of a guestinfo string property, by key.
fn fetch_guestinfo(erpc: &mut vmw_backdoor::EnhancedChan, key: &str) -> Result<Option<String>> {
let guestinfo = erpc
.get_guestinfo(key.as_bytes())
.chain_err(|| "failed to retrieve network kargs")?
.map(|bytes| String::from_utf8_lossy(&bytes).into_owned());
Ok(guestinfo)
}
}