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

[nexus] Add Physical Disk Policy, State #5335

Merged
merged 93 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from 80 commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
a0e89db
[sled-agent] Plumb physical disk info through inventory
smklein Feb 24, 2024
b962606
Plumb disks into inventory
smklein Feb 27, 2024
f3bfadd
Schema
smklein Feb 27, 2024
228bcdf
Fix tests
smklein Feb 28, 2024
0d93a86
You can't run memetendo swatch games on your macrohard box
smklein Feb 28, 2024
7be0e1e
Primary key order matters
smklein Feb 28, 2024
470be89
stop ignoring test, it's only flaky locally
smklein Feb 28, 2024
50d4415
Merge branch 'main' into disk-in-inventory
smklein Mar 12, 2024
ad6bf23
John's feedback
smklein Mar 12, 2024
72ac9b5
Slot plumbing
smklein Mar 12, 2024
58e3e03
Use slots for synthetic disks
smklein Mar 12, 2024
cdab967
fmt
smklein Mar 12, 2024
6d0dc3e
Fix illumos tests
smklein Mar 12, 2024
1d1f2c3
Fix test_complex
smklein Mar 12, 2024
8cad2c5
Not using new service plan yet
smklein Mar 12, 2024
6f97ab2
Merge branch 'main' into disk-in-inventory
smklein Mar 12, 2024
8983eaa
Zpools in inventory
smklein Mar 13, 2024
296ed1e
Merge branch 'main' into disk-in-inventory
smklein Mar 13, 2024
e034542
Merge branch 'disk-in-inventory' into zpool-in-inventory
smklein Mar 13, 2024
63d3c4a
Build background task to periodically update zpools with inventory info
smklein Mar 13, 2024
4d6d4dc
Working through FULL SCANs
smklein Mar 14, 2024
8a0dc14
Fix full table scan, add test
smklein Mar 14, 2024
9acc543
Merge branch 'main' into disk-in-inventory
smklein Mar 14, 2024
966109e
Merge branch 'disk-in-inventory' into zpool-in-inventory
smklein Mar 14, 2024
19a8685
Sled API for managing disks explicitly
smklein Mar 14, 2024
8882145
automated tests
smklein Mar 14, 2024
446a2bf
Cope with ledger-less systems
smklein Mar 14, 2024
0890e75
fix merge of slots, fmt
smklein Mar 14, 2024
f316c5c
Merge branch 'main' into zpool-in-inventory
smklein Mar 14, 2024
1cd159e
review feedback
smklein Mar 14, 2024
979e246
Merge branch 'zpool-in-inventory' into sled-agent-api-to-manage-phys-…
smklein Mar 14, 2024
6025e11
Patch some physical disk tests
smklein Mar 14, 2024
0121395
wip
smklein Mar 15, 2024
b9b4bf1
Merge branch 'main' into zpool-in-inventory
smklein Mar 15, 2024
295cae3
Merge branch 'zpool-in-inventory' into sled-agent-api-to-manage-phys-…
smklein Mar 15, 2024
0c19485
ledgerless tests is at least waiting long enough now
smklein Mar 15, 2024
b88838f
ledger transition test good to go
smklein Mar 15, 2024
a668637
Fix zone bundle tests
smklein Mar 16, 2024
058fb7c
Better errors
smklein Mar 16, 2024
67aa750
Merge branch 'main' into zpool-in-inventory
smklein Mar 16, 2024
7a2f9f0
Merge branch 'zpool-in-inventory' into sled-agent-api-to-manage-phys-…
smklein Mar 16, 2024
1d6fcf0
fmt
smklein Mar 16, 2024
84f3b54
Add schema
smklein Mar 18, 2024
dc16729
Merge branch 'main' into zpool-in-inventory
smklein Mar 18, 2024
b342912
Merge branch 'zpool-in-inventory' into sled-agent-api-to-manage-phys-…
smklein Mar 18, 2024
6f1597d
Improve ZoneBundle tests, tweak vdev default sizes (smaller)
smklein Mar 18, 2024
2d55e8e
async locks
smklein Mar 18, 2024
5d35227
Fix environment variable for deploy job
smklein Mar 18, 2024
2c06900
Merge branch 'main' into zpool-in-inventory
smklein Mar 19, 2024
a6ca038
Merge branch 'zpool-in-inventory' into sled-agent-api-to-manage-phys-…
smklein Mar 19, 2024
303a4d8
less stuttering on .vdev suffix
smklein Mar 19, 2024
860a7db
Absolute path to synthetic disks
smklein Mar 19, 2024
6ee3ea2
/tmp -> /var/tmp
smklein Mar 19, 2024
db34b59
Clone the vdev a4x2 branch
smklein Mar 20, 2024
613df7b
Restore instance tests to #5172
andrewjstone Mar 19, 2024
67bd1fc
remove stale comment
andrewjstone Mar 20, 2024
b7c1d67
make tests illumos only
andrewjstone Mar 20, 2024
c51bf3e
fix unused test functions
andrewjstone Mar 20, 2024
3c203c5
Merge branch 'main' into zpool-in-inventory
smklein Mar 21, 2024
c213293
Merge branch 'zpool-in-inventory' into sled-agent-api-to-manage-phys-…
smklein Mar 21, 2024
20c9e69
review feedback
smklein Mar 21, 2024
c399dcb
slog import path
smklein Mar 21, 2024
f129287
Merge branch 'ajs/sled-agent-api-to-manage-phys-disks/instance-tests'…
smklein Mar 21, 2024
5f3bd6c
openapi specs
smklein Mar 21, 2024
228fd9d
Merge branch 'main' into zpool-in-inventory
smklein Mar 25, 2024
655976b
Merge branch 'zpool-in-inventory' into sled-agent-api-to-manage-phys-…
smklein Mar 25, 2024
b65b4c1
Refactor to use /var/tmp, avoid race conditions, advance time
smklein Mar 25, 2024
fc5acf1
Pick the zpool UUID, not the disk UUID in RSS
smklein Mar 26, 2024
f78b5f5
Merge branch 'main' into zpool-in-inventory
smklein Mar 26, 2024
c62cbc3
Merge branch 'zpool-in-inventory' into sled-agent-api-to-manage-phys-…
smklein Mar 26, 2024
35c0020
Merge branch 'main' into sled-agent-api-to-manage-phys-disks
smklein Mar 26, 2024
6d5459f
Point to sled agent config
smklein Mar 26, 2024
37693a7
[nexus] Add Physical Disk Policy, State
smklein Mar 26, 2024
940ba5b
fix schema update
smklein Mar 27, 2024
d8cb14c
Columns go to the end
smklein Mar 27, 2024
10fb9dc
Test coverage for endpoints
smklein Mar 27, 2024
b1a8bb7
Better buildomat output
smklein Mar 27, 2024
0a27b38
Merge branch 'main' into sled-agent-api-to-manage-phys-disks
smklein Mar 27, 2024
a5ac505
Merge branch 'sled-agent-api-to-manage-phys-disks' into disk-state-po…
smklein Mar 27, 2024
f3e85c5
review feedback, check for policy/state during region allocation
smklein Mar 27, 2024
77b4273
CLIIIIIIIPPPPPYYYYYY
smklein Mar 27, 2024
80931b6
Make disks more legally distinct
smklein Mar 27, 2024
65ac86b
Unauthorized test, tweak DiskTest to supply custom UUIDs
smklein Mar 27, 2024
6460fcf
Merge branch 'main' into sled-agent-api-to-manage-phys-disks
smklein Mar 27, 2024
40a561e
regex crimes
smklein Mar 27, 2024
93a9474
Merge branch 'sled-agent-api-to-manage-phys-disks' into disk-state-po…
smklein Mar 27, 2024
f32ff9d
longer handoff
smklein Mar 28, 2024
7bd3cac
Use txn connection for RSS
smklein Mar 28, 2024
5dd232a
Merge branch 'main' into sled-agent-api-to-manage-phys-disks
smklein Mar 28, 2024
2dd2e08
Point to testbed main
smklein Mar 29, 2024
75652e2
Merge branch 'sled-agent-api-to-manage-phys-disks' into disk-state-po…
smklein Mar 29, 2024
8fdf165
Merge branch 'main' into sled-agent-api-to-manage-phys-disks
smklein Mar 29, 2024
46cd079
Merge branch 'sled-agent-api-to-manage-phys-disks' into disk-state-po…
smklein Mar 29, 2024
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
2 changes: 1 addition & 1 deletion .github/buildomat/jobs/a4x2-prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ cp target/release/dhcp-server /out/
banner "testbed"
cd /work/oxidecomputer
rm -rf testbed
git clone https://github.com/oxidecomputer/testbed
git clone -b vdev https://github.com/oxidecomputer/testbed
cd testbed/a4x2

#
Expand Down
13 changes: 9 additions & 4 deletions .github/buildomat/jobs/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ PXA_END="$EXTRA_IP_END"
export GATEWAY_IP GATEWAY_MAC PXA_START PXA_END

pfexec zpool create -f scratch c1t1d0 c2t1d0
ZPOOL_VDEV_DIR=/scratch ptime -m pfexec ./tools/create_virtual_hardware.sh
VDEV_DIR=/scratch ptime -m pfexec ./tools/create_virtual_hardware.sh

#
# Generate a self-signed certificate to use as the initial TLS certificate for
Expand All @@ -214,7 +214,12 @@ ZPOOL_VDEV_DIR=/scratch ptime -m pfexec ./tools/create_virtual_hardware.sh
# real system, the certificate would come from the customer during initial rack
# setup on the technician port.
#
tar xf out/omicron-sled-agent.tar pkg/config-rss.toml
tar xf out/omicron-sled-agent.tar pkg/config-rss.toml pkg/config.toml

# Update the vdevs to point to where we've created them
sed -i~ "s/\(m2\|u2\)\(.*\.vdev\)/\/scratch\/\1\2/g" pkg/config.toml
diff -u pkg/config.toml{~,} || true

SILO_NAME="$(sed -n 's/silo_name = "\(.*\)"/\1/p' pkg/config-rss.toml)"
EXTERNAL_DNS_DOMAIN="$(sed -n 's/external_dns_zone_name = "\(.*\)"/\1/p' pkg/config-rss.toml)"

Expand All @@ -241,8 +246,8 @@ addresses = \\[\"$UPLINK_IP/24\"\\]
" pkg/config-rss.toml
diff -u pkg/config-rss.toml{~,} || true

tar rvf out/omicron-sled-agent.tar pkg/config-rss.toml
rm -f pkg/config-rss.toml*
tar rvf out/omicron-sled-agent.tar pkg/config-rss.toml pkg/config.toml
rm -f pkg/config-rss.toml* pkg/config.toml*

#
# By default, OpenSSL creates self-signed certificates with "CA:true". The TLS
Expand Down
5 changes: 5 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ update-engine = { path = "update-engine" }
usdt = "0.5.0"
uuid = { version = "1.7.0", features = ["serde", "v4"] }
walkdir = "2.4"
whoami = "1.5"
wicket = { path = "wicket" }
wicket-common = { path = "wicket-common" }
wicketd-client = { path = "clients/wicketd-client" }
Expand Down
11 changes: 1 addition & 10 deletions clients/sled-agent-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ progenitor::generate_api!(
// replace directives below?
replace = {
ByteCount = omicron_common::api::external::ByteCount,
DiskIdentity = omicron_common::disk::DiskIdentity,
Generation = omicron_common::api::external::Generation,
MacAddr = omicron_common::api::external::MacAddr,
Name = omicron_common::api::external::Name,
Expand Down Expand Up @@ -189,16 +190,6 @@ impl omicron_common::api::external::ClientError for types::Error {
}
}

impl From<types::DiskIdentity> for omicron_common::disk::DiskIdentity {
fn from(identity: types::DiskIdentity) -> Self {
Self {
vendor: identity.vendor,
serial: identity.serial,
model: identity.model,
}
}
}

impl From<omicron_common::api::internal::nexus::InstanceRuntimeState>
for types::InstanceRuntimeState
{
Expand Down
1 change: 1 addition & 0 deletions common/src/api/external/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,7 @@ pub enum ResourceType {
ServiceNetworkInterface,
Sled,
SledInstance,
SledLedger,
Switch,
SagaDbg,
Snapshot,
Expand Down
5 changes: 3 additions & 2 deletions common/src/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use async_trait::async_trait;
use camino::{Utf8Path, Utf8PathBuf};
use serde::{de::DeserializeOwned, Serialize};
use slog::{debug, info, warn, Logger};
use slog::{debug, error, info, warn, Logger};

#[derive(thiserror::Error, Debug)]
pub enum Error {
Expand Down Expand Up @@ -127,14 +127,15 @@ impl<T: Ledgerable> Ledger<T> {
let mut one_successful_write = false;
for path in self.paths.iter() {
if let Err(e) = self.atomic_write(&path).await {
warn!(self.log, "Failed to write to {}: {e}", path);
warn!(self.log, "Failed to write ledger"; "path" => ?path, "err" => ?e);
failed_paths.push((path.to_path_buf(), e));
} else {
one_successful_write = true;
}
}

if !one_successful_write {
error!(self.log, "No successful writes to ledger");
return Err(Error::FailedToWrite { failed_paths });
}
Ok(())
Expand Down
4 changes: 1 addition & 3 deletions illumos-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ smf.workspace = true
thiserror.workspace = true
tokio.workspace = true
uuid.workspace = true
whoami.workspace = true
zone.workspace = true

# only enabled via the `testing` feature
Expand All @@ -46,6 +47,3 @@ toml.workspace = true
[features]
# Enable to generate MockZones
testing = ["mockall"]
# Useful for tests that want real functionality and ability to run without
# pfexec
tmp_keypath = []
61 changes: 40 additions & 21 deletions illumos-utils/src/zfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//! Utilities for poking at ZFS.

use crate::{execute, PFEXEC};
use camino::Utf8PathBuf;
use camino::{Utf8Path, Utf8PathBuf};
use omicron_common::disk::DiskIdentity;
use std::fmt;

Expand All @@ -28,8 +28,6 @@ pub const ZFS: &str = "/usr/sbin/zfs";
/// the keys and recreate the files on demand when creating and mounting
/// encrypted filesystems. We then zero them and unlink them.
pub const KEYPATH_ROOT: &str = "/var/run/oxide/";
// Use /tmp so we don't have to worry about running tests with pfexec
pub const TEST_KEYPATH_ROOT: &str = "/tmp";

/// Error returned by [`Zfs::list_datasets`].
#[derive(thiserror::Error, Debug)]
Expand Down Expand Up @@ -168,27 +166,34 @@ impl fmt::Display for Keypath {
}
}

#[cfg(not(feature = "tmp_keypath"))]
impl From<&DiskIdentity> for Keypath {
fn from(id: &DiskIdentity) -> Self {
build_keypath(id, KEYPATH_ROOT)
}
}

#[cfg(feature = "tmp_keypath")]
impl From<&DiskIdentity> for Keypath {
fn from(id: &DiskIdentity) -> Self {
build_keypath(id, TEST_KEYPATH_ROOT)
impl Keypath {
/// Constructs a Keypath for the specified disk within the supplied root
/// directory.
///
/// By supplying "root", tests can override the location where these paths
/// are stored to non-global locations.
pub fn new<P: AsRef<Utf8Path>>(id: &DiskIdentity, root: &P) -> Keypath {
let keypath_root = Utf8PathBuf::from(KEYPATH_ROOT);
let mut keypath = keypath_root.as_path();
let keypath_directory = loop {
match keypath.strip_prefix("/") {
Ok(stripped) => keypath = stripped,
Err(_) => break root.as_ref().join(keypath),
}
};
std::fs::create_dir_all(&keypath_directory)
.expect("Cannot ensure directory for keys");

let filename = format!(
"{}-{}-{}-zfs-aes-256-gcm.key",
id.vendor, id.serial, id.model
);
let path: Utf8PathBuf =
[keypath_directory.as_str(), &filename].iter().collect();
Keypath(path)
}
}

fn build_keypath(id: &DiskIdentity, root: &str) -> Keypath {
let filename =
format!("{}-{}-{}-zfs-aes-256-gcm.key", id.vendor, id.serial, id.model);
let path: Utf8PathBuf = [root, &filename].iter().collect();
Keypath(path)
}

#[derive(Debug)]
pub struct EncryptionDetails {
pub keypath: Keypath,
Expand Down Expand Up @@ -332,6 +337,20 @@ impl Zfs {
err: err.into(),
})?;

// We ensure that the currently running process has the ability to
// act on the underlying mountpoint.
if !zoned {
let mut command = std::process::Command::new(PFEXEC);
let user = whoami::username();
let mount = format!("{mountpoint}");
let cmd = command.args(["chown", "-R", &user, &mount]);
execute(cmd).map_err(|err| EnsureFilesystemError {
name: name.to_string(),
mountpoint: mountpoint.clone(),
err: err.into(),
})?;
}

if let Some(SizeDetails { quota, compression }) = size_details {
// Apply any quota and compression mode.
Self::apply_properties(name, &mountpoint, quota, compression)?;
Expand Down
17 changes: 12 additions & 5 deletions illumos-utils/src/zpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ use std::fmt;
use std::str::FromStr;
use uuid::Uuid;

const ZPOOL_EXTERNAL_PREFIX: &str = "oxp_";
const ZPOOL_INTERNAL_PREFIX: &str = "oxi_";
pub const ZPOOL_EXTERNAL_PREFIX: &str = "oxp_";
pub const ZPOOL_INTERNAL_PREFIX: &str = "oxi_";
const ZPOOL: &str = "/usr/sbin/zpool";

pub const ZPOOL_MOUNTPOINT_ROOT: &str = "/";

#[derive(thiserror::Error, Debug, PartialEq, Eq)]
#[error("Failed to parse output: {0}")]
pub struct ParseError(String);
Expand Down Expand Up @@ -192,7 +194,7 @@ impl Zpool {
let mut cmd = std::process::Command::new(PFEXEC);
cmd.env_clear();
cmd.env("LC_ALL", "C.UTF-8");
cmd.arg(ZPOOL).arg("create");
cmd.arg(ZPOOL).args(["create", "-o", "ashift=12"]);
cmd.arg(&name.to_string());
cmd.arg(vdev);
execute(&mut cmd).map_err(Error::from)?;
Expand Down Expand Up @@ -374,9 +376,14 @@ impl ZpoolName {
/// Returns a path to a dataset's mountpoint within the zpool.
///
/// For example: oxp_(UUID) -> /pool/ext/(UUID)/(dataset)
pub fn dataset_mountpoint(&self, dataset: &str) -> Utf8PathBuf {
pub fn dataset_mountpoint(
&self,
root: &Utf8Path,
dataset: &str,
) -> Utf8PathBuf {
let mut path = Utf8PathBuf::new();
path.push("/pool");
path.push(root);
path.push("pool");
match self.kind {
ZpoolKind::External => path.push("ext"),
ZpoolKind::Internal => path.push("int"),
Expand Down
13 changes: 10 additions & 3 deletions installinator/src/hardware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use anyhow::Result;
use sled_hardware::DiskVariant;
use sled_hardware::HardwareManager;
use sled_hardware::SledMode;
use sled_storage::config::MountConfig;
use sled_storage::disk::Disk;
use sled_storage::disk::RawDisk;
use slog::info;
Expand Down Expand Up @@ -49,9 +50,15 @@ impl Hardware {
);
}
DiskVariant::M2 => {
let disk = Disk::new(log, disk, None)
.await
.context("failed to instantiate Disk handle for M.2")?;
let disk = Disk::new(
log,
&MountConfig::default(),
disk,
None,
None,
)
.await
.context("failed to instantiate Disk handle for M.2")?;
m2_disks.push(disk);
}
}
Expand Down
1 change: 1 addition & 0 deletions installinator/src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ impl WriteDestination {

let zpool_name = disk.zpool_name().clone();
let control_plane_dir = zpool_name.dataset_mountpoint(
illumos_utils::zpool::ZPOOL_MOUNTPOINT_ROOT.into(),
sled_storage::dataset::INSTALL_DATASET,
);

Expand Down
2 changes: 1 addition & 1 deletion key-manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ enum StorageKeyRequest {
/// the sled-agent starts. The `HardwareMonitor` gets the StorageKeyRequester
/// from the bootstrap agent. If this changes, we should remove the `Clone` to
/// limit who has access to the storage keys.
#[derive(Clone)]
#[derive(Debug, Clone)]
pub struct StorageKeyRequester {
tx: mpsc::Sender<StorageKeyRequest>,
}
Expand Down
4 changes: 4 additions & 0 deletions nexus/db-model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ mod network_interface;
mod oximeter_info;
mod physical_disk;
mod physical_disk_kind;
mod physical_disk_policy;
mod physical_disk_state;
mod probe;
mod producer_endpoint;
mod project;
Expand Down Expand Up @@ -150,6 +152,8 @@ pub use network_interface::*;
pub use oximeter_info::*;
pub use physical_disk::*;
pub use physical_disk_kind::*;
pub use physical_disk_policy::*;
pub use physical_disk_state::*;
pub use probe::*;
pub use producer_endpoint::*;
pub use project::*;
Expand Down
Loading
Loading