Skip to content

[sled agent] Compare dladm results with datalink mgmt cache file #1685

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

Closed
wants to merge 2 commits into from
Closed
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
1 change: 1 addition & 0 deletions sled-agent/src/opte/illumos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ mod port_manager;
pub use port::Port;
pub use port_manager::PortManager;
pub use port_manager::PortTicket;
pub use port_manager::XDE_LINK_PREFIX;

#[derive(thiserror::Error, Debug)]
pub enum Error {
Expand Down
15 changes: 12 additions & 3 deletions sled-agent/src/opte/illumos/port_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use std::sync::MutexGuard;
use uuid::Uuid;

// Prefix used to identify xde data links.
const XDE_LINK_PREFIX: &str = "opte";
pub const XDE_LINK_PREFIX: &str = "opte";

#[derive(Debug)]
struct PortManagerInner {
Expand Down Expand Up @@ -281,8 +281,17 @@ impl PortManager {
snat,
external_ip,
/* passthru = */ false,
)?;
debug!(
)
.map_err(|e| {
warn!(
self.inner.log,
"Failed to create xde device";
"port_name" => &port_name,
"error" => e.to_string(),
);
e
})?;
info!(
self.inner.log,
"Created xde device for guest port";
"port_name" => &port_name,
Expand Down
1 change: 1 addition & 0 deletions sled-agent/src/opte/non_illumos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mod port_manager;
pub use port::Port;
pub use port_manager::PortManager;
pub use port_manager::PortTicket;
pub use port_manager::XDE_LINK_PREFIX;

#[derive(Debug, Clone, Copy)]
pub struct Vni(u32);
Expand Down
2 changes: 1 addition & 1 deletion sled-agent/src/opte/non_illumos/port_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use std::sync::Mutex;
use uuid::Uuid;

// Prefix used to identify xde data links.
const XDE_LINK_PREFIX: &str = "opte";
pub const XDE_LINK_PREFIX: &str = "opte";

#[derive(Debug)]
#[allow(dead_code)]
Expand Down
52 changes: 52 additions & 0 deletions sled-agent/src/sled_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use crate::bootstrap::params::SledAgentRequest;
use crate::config::Config;
use crate::illumos::dladm::VNIC_PREFIX_GUEST;
use crate::illumos::vnic::VnicKind;
use crate::illumos::zfs::{
Mountpoint, ZONE_ZFS_DATASET, ZONE_ZFS_DATASET_MOUNTPOINT,
Expand All @@ -14,6 +15,7 @@ use crate::illumos::zone::IPADM;
use crate::illumos::{execute, PFEXEC};
use crate::instance_manager::InstanceManager;
use crate::nexus::LazyNexusClient;
use crate::opte::XDE_LINK_PREFIX;
use crate::params::{
DatasetKind, DiskStateRequested, InstanceHardware, InstanceMigrateParams,
InstanceRuntimeStateRequested, InstanceSerialConsoleData,
Expand All @@ -29,6 +31,7 @@ use omicron_common::api::{
};
use slog::Logger;
use std::net::SocketAddrV6;
use std::path::PathBuf;
use std::process::Command;
use uuid::Uuid;

Expand Down Expand Up @@ -94,6 +97,18 @@ pub enum Error {

#[error("Error resolving DNS name: {0}")]
ResolveError(#[from] internal_dns_client::multiclient::ResolveError),

#[error("I/O Error accessing file {path}: {err}")]
Io { path: PathBuf, err: std::io::Error },

#[error(
"Unexpected object in dladm cache file which cannot be deleted automatically
This is related to https://github.com/oxidecomputer/omicron/issues/1679 .
To fix:
- Delete the line \"{line}\" in {DATALINK_CACHE_FILE}.
- Run `svcadm restart svc:/network/datalink-management:default`"
)]
DladmBug { line: String, prefix: String },
}

impl From<Error> for omicron_common::api::external::Error {
Expand Down Expand Up @@ -252,6 +267,7 @@ impl SledAgent {
// order. That should be OK, since we're definitely deleting the guest
// VNICs before the xde devices, which is the main constraint.
delete_omicron_vnics(&log).await?;
verify_datalink_cache_does_not_contain(&log, VNIC_PREFIX_GUEST).await?;

// Also delete any extant xde devices. These should also eventually be
// recovered / tracked, to avoid interruption of any guests that are
Expand All @@ -261,6 +277,7 @@ impl SledAgent {
// This is also tracked by
// https://github.com/oxidecomputer/omicron/issues/725.
crate::opte::delete_all_xde_devices(&log)?;
verify_datalink_cache_does_not_contain(&log, XDE_LINK_PREFIX).await?;

// Ipv6 forwarding must be enabled to route traffic between zones.
//
Expand Down Expand Up @@ -497,6 +514,41 @@ async fn delete_omicron_vnics(log: &Logger) -> Result<(), Error> {
Ok(())
}

const DATALINK_CACHE_FILE: &str =
"/etc/svc/volatile/dladm/network-datalink-management:default.cache";

// Verifies that the datalink cache file does not contain a particular prefix.
//
// This is used for detecting cases where data links are not visible through
// dladm, but "exist" according to the datalink management service.
//
// Typically, this indicates a failed delete or bad state, so we propagate an
// error upward to make these cases more obvious.
//
// See https://github.com/oxidecomputer/omicron/issues/1679 for more context.
async fn verify_datalink_cache_does_not_contain(
log: &Logger,
prefix: &str,
) -> Result<(), Error> {
use tokio::io::AsyncBufReadExt;
let file =
tokio::fs::File::open(DATALINK_CACHE_FILE).await.map_err(|err| {
Error::Io { path: PathBuf::from(DATALINK_CACHE_FILE), err }
})?;
let reader = tokio::io::BufReader::new(file);
let mut lines = reader.lines();
while let Some(line) = lines.next_line().await.map_err(|err| Error::Io {
path: PathBuf::from(DATALINK_CACHE_FILE),
err,
})? {
if line.starts_with(prefix) {
warn!(log, "Found unexpected line {line} with prefix {prefix}");
return Err(Error::DladmBug { line, prefix: prefix.to_string() });
}
}
Ok(())
}

// Delete the etherstub and underlay VNIC used for interzone communication
fn delete_etherstub(log: &Logger) -> Result<(), Error> {
use crate::illumos::dladm::ETHERSTUB_NAME;
Expand Down