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

Use strum crate for enum-related utilities #532

Merged
merged 1 commit into from
Sep 27, 2023
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
36 changes: 7 additions & 29 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ crucible = { git = "https://github.com/oxidecomputer/crucible", rev = "aeb69dda2
crucible-client-types = { git = "https://github.com/oxidecomputer/crucible", rev = "aeb69dda26c7e1a8b6eada425670cd4b83f91c07" }
ctrlc = "3.2"
dropshot = { git = "https://github.com/oxidecomputer/dropshot", branch = "main" }
enum-iterator = "1.4.1"
erased-serde = "0.3"
errno = "0.2.8"
expectorate = "1.0.5"
Expand All @@ -113,7 +112,7 @@ inventory = "0.3.0"
lazy_static = "1.4"
libc = "0.2"
mockall = "0.11"
num_enum = "0.5"
num_enum = "0.5.11"
proc-macro2 = "1.0"
progenitor = { git = "https://github.com/oxidecomputer/progenitor", branch = "main" }
quote = "1.0"
Expand All @@ -133,6 +132,7 @@ slog-async = "2.8"
slog-bunyan = "2.4.0"
slog-dtrace = "0.2.3"
slog-term = "2.8"
strum = "0.25"
syn = "1.0"
tempfile = "3.2"
thiserror = "1.0"
Expand Down
3 changes: 1 addition & 2 deletions bin/propolis-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,13 @@ clap = { workspace = true, features = ["derive"] }
const_format.workspace = true
crucible-client-types.workspace = true
dropshot = { workspace = true, features = ["usdt-probes"] }
enum-iterator.workspace = true
erased-serde.workspace = true
futures.workspace = true
http.workspace = true
hyper.workspace = true
internal-dns.workspace = true
lazy_static.workspace = true
nexus-client.workspace = true
num_enum.workspace = true
omicron-common.workspace = true
oximeter-producer.workspace = true
oximeter.workspace = true
Expand All @@ -55,6 +53,7 @@ slog-async.workspace = true
slog-bunyan.workspace = true
slog-dtrace.workspace = true
slog-term.workspace = true
strum = { workspace = true, features = ["derive"] }
propolis = { workspace = true, features = ["crucible-full", "oximeter"] }
propolis-client = { workspace = true, features = ["generated"] }
propolis-server-config.workspace = true
Expand Down
10 changes: 5 additions & 5 deletions bin/propolis-server/src/lib/migrate/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
//! for that.

use super::MigrateError;

use bytes::{Buf, BufMut, Bytes};
use num_enum::{IntoPrimitive, TryFromPrimitive};
use slog::error;
use std::convert::TryFrom;
use strum::FromRepr;
use thiserror::Error;
use tokio_tungstenite::tungstenite;

Expand Down Expand Up @@ -90,7 +90,7 @@ pub(crate) enum Message {
/// identifying frame types. They are an implementation detail of
/// the wire format, and not used elsewhere. However, they must be
/// kept in bijection with Message, above.
#[derive(Debug, PartialEq, IntoPrimitive, TryFromPrimitive)]
#[derive(Debug, PartialEq, FromRepr)]
#[repr(u8)]
enum MessageType {
Okay,
Expand Down Expand Up @@ -179,8 +179,8 @@ impl std::convert::TryInto<Message> for tungstenite::Message {
tungstenite::Message::Binary(mut v) => {
// If the tag byte is absent or invalid, don't bother looking at the message.
let tag_byte = v.pop().ok_or(ProtocolError::EmptyMessage)?;
let tag = MessageType::try_from(tag_byte)
.map_err(|_| ProtocolError::InvalidMessageType(tag_byte))?;
let tag = MessageType::from_repr(tag_byte)
.ok_or(ProtocolError::InvalidMessageType(tag_byte))?;
let mut src = Bytes::from(v);
// At this point, we have a valid message of a known type, and
// the remaining bytes are the message contents.
Expand Down
8 changes: 4 additions & 4 deletions bin/propolis-server/src/lib/migrate/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@

use std::{fmt::Display, iter::Peekable, num::ParseIntError, str::FromStr};

use enum_iterator::Sequence;
use lazy_static::lazy_static;
use serde::{Deserialize, Serialize};
use strum::{EnumIter, IntoEnumIterator};
use thiserror::Error;

/// The complete set of protocols supported by this version of the migration
/// library.
#[derive(Debug, Clone, Copy, Sequence)]
#[derive(Debug, Clone, Copy, EnumIter)]
pub enum Protocol {
RonV0,
}
Expand Down Expand Up @@ -171,7 +171,7 @@ impl FromStr for ProtocolParts {

lazy_static! {
static ref PROTOCOL_PARTS: Vec<ProtocolParts> =
enum_iterator::all::<Protocol>().map(ProtocolParts::from).collect();
Protocol::iter().map(ProtocolParts::from).collect();
}

/// Constructs a protocol offer string from a peekable protocol iterator.
Expand All @@ -194,7 +194,7 @@ fn make_protocol_offers_from_parts<
/// Constructs a protocol offer string from the static supported protocol set.
pub(super) fn make_protocol_offer() -> String {
make_protocol_offers_from_parts(
enum_iterator::all::<Protocol>().map(ProtocolParts::from).peekable(),
Protocol::iter().map(ProtocolParts::from).peekable(),
)
}

Expand Down
2 changes: 1 addition & 1 deletion bin/propolis-standalone/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ slog-async.workspace = true
slog-dtrace.workspace = true
slog-bunyan.workspace = true
slog-term.workspace = true
num_enum.workspace = true
strum = { workspace = true, features = ["derive"] }
uuid.workspace = true

[features]
Expand Down
12 changes: 6 additions & 6 deletions bin/propolis-standalone/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ use std::time::{SystemTime, UNIX_EPOCH};
use anyhow::Context;
use clap::Parser;
use futures::future::BoxFuture;
use slog::{o, Drain};
use strum::IntoEnumIterator;
use tokio::runtime;

use propolis::chardev::{BlockingSource, Sink, Source, UDSock};
use propolis::hw::chipset::{i440fx, Chipset};
use propolis::hw::ibmpc;
use propolis::hw::ps2::ctrl::PS2Ctrl;
use propolis::hw::uart::LpcUart;
use propolis::intr_pins::FuncPin;
use propolis::usdt::register_probes;
use propolis::vcpu::Vcpu;
use propolis::vmm::{Builder, Machine};
use propolis::*;
use tokio::runtime;

use propolis::usdt::register_probes;

use slog::{o, Drain};

mod config;
mod snapshot;
Expand Down Expand Up @@ -934,7 +934,7 @@ fn setup_instance(
)
.with_vcpuid(vcpu.id)
.with_cache_topo()
.clear_cpu_topo(cpuid::TopoKind::all())
.clear_cpu_topo(cpuid::TopoKind::iter())
.execute(profile.clone())
.context("failed to specialize cpuid profile")?
} else {
Expand Down
Loading