Skip to content
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
5 changes: 2 additions & 3 deletions Cargo.lock

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

11 changes: 7 additions & 4 deletions common/src/api/external/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,13 +578,16 @@ impl ByteCount {

impl Display for ByteCount {
fn fmt(&self, f: &mut Formatter<'_>) -> FormatResult {
if self.to_bytes() >= TiB && self.to_bytes() % TiB == 0 {
if self.to_bytes() >= TiB && self.to_bytes().is_multiple_of(TiB) {
write!(f, "{} TiB", self.to_whole_tebibytes())
} else if self.to_bytes() >= GiB && self.to_bytes() % GiB == 0 {
} else if self.to_bytes() >= GiB && self.to_bytes().is_multiple_of(GiB)
{
write!(f, "{} GiB", self.to_whole_gibibytes())
} else if self.to_bytes() >= MiB && self.to_bytes() % MiB == 0 {
} else if self.to_bytes() >= MiB && self.to_bytes().is_multiple_of(MiB)
{
write!(f, "{} MiB", self.to_whole_mebibytes())
} else if self.to_bytes() >= KiB && self.to_bytes() % KiB == 0 {
} else if self.to_bytes() >= KiB && self.to_bytes().is_multiple_of(KiB)
{
write!(f, "{} KiB", self.to_whole_kibibytes())
} else {
write!(f, "{} B", self.to_bytes())
Expand Down
2 changes: 1 addition & 1 deletion common/src/api/internal/shared/external_ip/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ impl<T: Ip> SourceNatConfig<T> {
first_port: u16,
last_port: u16,
) -> Result<Self, SourceNatConfigError> {
if first_port % NUM_SOURCE_NAT_PORTS == 0
if first_port.is_multiple_of(NUM_SOURCE_NAT_PORTS)
&& last_port
.checked_sub(first_port)
.and_then(|diff| diff.checked_add(1))
Expand Down
2 changes: 1 addition & 1 deletion common/src/api/internal/shared/external_ip/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl SourceNatConfig {
first_port: u16,
last_port: u16,
) -> Result<Self, SourceNatConfigError> {
if first_port % NUM_SOURCE_NAT_PORTS == 0
if first_port.is_multiple_of(NUM_SOURCE_NAT_PORTS)
&& last_port
.checked_sub(first_port)
.and_then(|diff| diff.checked_add(1))
Expand Down
2 changes: 1 addition & 1 deletion illumos-utils/src/vmm_reservoir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@ pub fn align_reservoir_size(size_bytes: u64) -> u64 {
}

pub fn reservoir_size_is_aligned(size_bytes: u64) -> bool {
(size_bytes % RESERVOIR_SZ_ALIGN) == 0
size_bytes.is_multiple_of(RESERVOIR_SZ_ALIGN)
}
2 changes: 1 addition & 1 deletion installinator/src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,7 @@ impl WriteTransport for BlockDeviceTransport {
// When writing to a block device, we must write a multiple of the block
// size. We can assume the image we're given should be
// appropriately-sized: return an error here if it is not.
if total_bytes % block_size != 0 {
if !total_bytes.is_multiple_of(block_size) {
return Err(WriteError::WriteError {
component,
slot,
Expand Down
20 changes: 0 additions & 20 deletions nexus/db-queries/src/db/datastore/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,9 @@ use omicron_uuid_kinds::GenericUuid as _;
use omicron_uuid_kinds::ProbeUuid;
use omicron_uuid_kinds::SledUuid;
use ref_cast::RefCast;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use sled_agent_client::types::ProbeCreate;
use uuid::Uuid;

#[derive(Debug, Clone, JsonSchema, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum IpKind {
Snat,
Floating,
Ephemeral,
}

impl From<nexus_db_model::IpKind> for IpKind {
fn from(value: nexus_db_model::IpKind) -> Self {
match value {
nexus_db_model::IpKind::SNat => Self::Snat,
nexus_db_model::IpKind::Ephemeral => Self::Ephemeral,
nexus_db_model::IpKind::Floating => Self::Floating,
}
}
}

impl super::DataStore {
/// List the probes for the given project.
pub async fn probe_list(
Expand Down
10 changes: 2 additions & 8 deletions nexus/db-queries/src/db/datastore/switch_port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use crate::db::model::{
LldpLinkConfig, Name, SwitchInterfaceConfig, SwitchLinkFec,
SwitchLinkSpeed, SwitchPort, SwitchPortAddressConfig,
SwitchPortBgpPeerConfig, SwitchPortConfig, SwitchPortLinkConfig,
SwitchPortRouteConfig, SwitchPortSettings, SwitchPortSettingsGroup,
SwitchPortSettingsGroups, SwitchVlanInterfaceConfig, TxEqConfig,
SwitchPortRouteConfig, SwitchPortSettings, SwitchPortSettingsGroups,
SwitchVlanInterfaceConfig, TxEqConfig,
};
use crate::db::pagination::paginated;
use async_bb8_diesel::{AsyncRunQueryDsl, Connection};
Expand Down Expand Up @@ -149,12 +149,6 @@ impl Into<external::SwitchPortSettings> for SwitchPortSettingsCombinedResult {
}
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct SwitchPortSettingsGroupCreateResult {
pub group: SwitchPortSettingsGroup,
pub settings: SwitchPortSettingsCombinedResult,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct LinkConfigCombinedResult {
pub port_settings_id: Uuid,
Expand Down
2 changes: 1 addition & 1 deletion nexus/db-queries/src/db/datastore/vpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ impl DataStore {
}
Err(e) => return Err(e),
Ok(None) => {
crate::probes::vni__search__range__empty!(|| (&id));
crate::probes::vni__search__range__empty!(|| &id);
debug!(
opctx.log,
"No VNIs available within current search range, retrying";
Expand Down
1 change: 0 additions & 1 deletion nexus/mgs-updates/src/common_sp_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use nexus_types::deployment::PendingMgsUpdate;
use nexus_types::deployment::PendingMgsUpdateDetails;
use nexus_types::inventory::SpType;
use omicron_common::disk::M2Slot;
use slog::error;
use std::net::SocketAddrV6;
use std::time::Duration;
use thiserror::Error;
Expand Down
8 changes: 6 additions & 2 deletions nexus/src/app/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl super::Nexus {

// Reject disks where the block size doesn't evenly divide the
// total size
if (params.size.to_bytes() % block_size) != 0 {
if !params.size.to_bytes().is_multiple_of(block_size) {
return Err(Error::invalid_value(
"size and block_size",
format!(
Expand All @@ -199,7 +199,11 @@ impl super::Nexus {

// Reject disks where the MIN_DISK_SIZE_BYTES doesn't evenly
// divide the size
if (params.size.to_bytes() % u64::from(MIN_DISK_SIZE_BYTES)) != 0 {
if !params
.size
.to_bytes()
.is_multiple_of(u64::from(MIN_DISK_SIZE_BYTES))
{
return Err(Error::invalid_value(
"size",
format!(
Expand Down
5 changes: 4 additions & 1 deletion nexus/src/app/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2559,7 +2559,10 @@ fn check_instance_cpu_memory_sizes(

// Reject instances where the memory is not divisible by
// MIN_MEMORY_BYTES_PER_INSTANCE
if (memory.to_bytes() % u64::from(MIN_MEMORY_BYTES_PER_INSTANCE)) != 0 {
if !memory
.to_bytes()
.is_multiple_of(u64::from(MIN_MEMORY_BYTES_PER_INSTANCE))
{
return Err(Error::invalid_value(
"size",
format!(
Expand Down
5 changes: 2 additions & 3 deletions nexus/src/app/sagas/disk_create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,15 +603,14 @@ async fn sdc_regions_ensure(

// Each ID should be unique to this disk
if let Some(read_only_parent) = &mut read_only_parent {
*read_only_parent = Box::new(
**read_only_parent =
randomize_volume_construction_request_ids(&read_only_parent)
.map_err(|e| {
ActionError::action_failed(Error::internal_error(&format!(
"failed to randomize ids: {}",
e,
)))
})?,
);
})?;
}

// Create volume construction request for this disk
Expand Down
18 changes: 1 addition & 17 deletions nexus/src/app/sagas/instance_create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ use omicron_common::api::external::NameOrId;
use omicron_common::api::external::{Error, InternalContext};
use omicron_common::api::internal::shared::SwitchLocation;
use omicron_uuid_kinds::{
AffinityGroupUuid, AntiAffinityGroupUuid, GenericUuid, InstanceUuid,
MulticastGroupUuid,
AntiAffinityGroupUuid, GenericUuid, InstanceUuid, MulticastGroupUuid,
};
use ref_cast::RefCast;
use serde::Deserialize;
Expand Down Expand Up @@ -61,28 +60,13 @@ struct NetParams {
new_id: Uuid,
}

#[derive(Debug, Deserialize, Serialize)]
struct AffinityParams {
serialized_authn: authn::saga::Serialized,
instance_id: InstanceUuid,
group: AffinityGroupUuid,
}

#[derive(Debug, Deserialize, Serialize)]
struct AntiAffinityParams {
serialized_authn: authn::saga::Serialized,
instance_id: InstanceUuid,
group: AntiAffinityGroupUuid,
}

#[derive(Debug, Deserialize, Serialize)]
struct NetworkConfigParams {
saga_params: Params,
instance_id: InstanceUuid,
which: usize,
switch_location: SwitchLocation,
}

#[derive(Debug, Deserialize, Serialize)]
struct DiskAttachParams {
serialized_authn: authn::saga::Serialized,
Expand Down
4 changes: 2 additions & 2 deletions nexus/src/app/sagas/region_replacement_start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ pub(crate) mod test {
async fn test_find_only_new_region(cptestctx: &ControlPlaneTestContext) {
let log = &cptestctx.logctx.log;

let datasets = vec![
let datasets = [
CrucibleDataset::new(
DatasetUuid::new_v4(),
ZpoolUuid::new_v4(),
Expand All @@ -921,7 +921,7 @@ pub(crate) mod test {
),
];

let regions = vec![
let regions = [
Region::new(
datasets[0].id(),
VolumeUuid::new_v4(),
Expand Down
2 changes: 1 addition & 1 deletion nexus/test-utils/src/starter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1978,7 +1978,7 @@ impl oximeter::Producer for IntegrationProducer {
fn produce(
&mut self,
) -> Result<
Box<(dyn Iterator<Item = oximeter::types::Sample> + 'static)>,
Box<dyn Iterator<Item = oximeter::types::Sample> + 'static>,
oximeter::MetricsError,
> {
use oximeter::Metric;
Expand Down
4 changes: 2 additions & 2 deletions nexus/tests/integration_tests/instances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3095,7 +3095,7 @@ async fn test_instance_create_delete_network_interface(
);

// Parameters for the interfaces to create/attach
let if_params = vec![
let if_params = [
params::InstanceNetworkInterfaceCreate {
identity: IdentityMetadataCreateParams {
name: "if0".parse().unwrap(),
Expand Down Expand Up @@ -3340,7 +3340,7 @@ async fn test_instance_update_network_interfaces(
);

// Parameters for each interface to try to modify.
let if_params = vec![
let if_params = [
params::InstanceNetworkInterfaceCreate {
identity: IdentityMetadataCreateParams {
name: "if0".parse().unwrap(),
Expand Down
2 changes: 1 addition & 1 deletion nexus/tests/integration_tests/multicast/instances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ async fn test_multicast_lifecycle(cptestctx: &ControlPlaneTestContext) {
wait_for_groups_active(client, &group_names).await;

// Create multiple instances in parallel - test various attachment scenarios
let instances = vec![
let instances = [
// Instance with group attached at creation
instance_for_multicast_groups(
cptestctx,
Expand Down
8 changes: 2 additions & 6 deletions nexus/types/src/external_api/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1147,6 +1147,7 @@ pub struct FloatingIpAttach {
// in the path of endpoints handling instance operations.
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
#[serde(tag = "type", content = "params", rename_all = "snake_case")]
#[derive(Default)]
pub enum InstanceNetworkInterfaceAttachment {
/// Create one or more `InstanceNetworkInterface`s for the `Instance`.
///
Expand All @@ -1157,18 +1158,13 @@ pub enum InstanceNetworkInterfaceAttachment {
/// The default networking configuration for an instance is to create a
/// single primary interface with an automatically-assigned IP address. The
/// IP will be pulled from the Project's default VPC / VPC Subnet.
#[default]
Default,

/// No network interfaces at all will be created for the instance.
None,
}

impl Default for InstanceNetworkInterfaceAttachment {
fn default() -> Self {
Self::Default
}
}

/// Describe the instance's disks at creation time
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
#[serde(tag = "type", rename_all = "snake_case")]
Expand Down
8 changes: 2 additions & 6 deletions nexus/types/src/external_api/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -753,17 +753,13 @@ impl RelayState {
/// Type of IP pool.
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema, PartialEq)]
#[serde(rename_all = "snake_case")]
#[derive(Default)]
pub enum IpPoolType {
/// Unicast IP pool for standard IP allocations.
#[default]
Unicast,
/// Multicast IP pool for multicast group allocations.
///
/// All ranges in a multicast pool must be either ASM or SSM (not mixed).
Multicast,
}

impl Default for IpPoolType {
fn default() -> Self {
Self::Unicast
}
}
4 changes: 2 additions & 2 deletions nexus/types/src/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use uuid::Uuid;
/// For durable objects which do not require soft-deletion or descriptions,
/// consider the [`Asset`] trait instead.
///
/// May be derived from [`macro@db-macros::Resource`].
/// May be derived from `db-macros::Resource`.
pub trait Resource {
type IdType: GenericUuid;

Expand Down Expand Up @@ -61,7 +61,7 @@ pub struct AssetIdentityMetadata {
/// These are objects similar to [`Resource`], but without
/// names, descriptions, or soft deletions.
///
/// May be derived from [`macro@db-macros::Asset`].
/// May be derived from `db-macros::Asset`.
pub trait Asset {
type IdType: GenericUuid;

Expand Down
2 changes: 1 addition & 1 deletion nexus/types/src/inventory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ impl Collection {
self.clickhouse_keeper_cluster_membership
.iter()
.max_by_key(|membership| membership.leader_committed_log_index)
.map(|membership| (membership.clone()))
.map(|membership| membership.clone())
}

/// Return a type which can be used to display a collection in a
Expand Down
1 change: 0 additions & 1 deletion ntp-admin/src/http_entrypoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use dropshot::HttpResponseOk;
use dropshot::RequestContext;
use ntp_admin_api::*;
use ntp_admin_types::TimeSync;
use slog::error;
use slog::info;
use slog_error_chain::InlineErrorChain;
use std::net::IpAddr;
Expand Down
2 changes: 1 addition & 1 deletion oximeter/db/src/oxql/ast/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ fn duration_to_db_interval(dur: &Duration) -> (u64, &'static str) {
fn as_whole_multiple(dur: &Duration, base: &Duration) -> Option<u64> {
let d = dur.as_nanos();
let base = base.as_nanos();
if d % base == 0 {
if d.is_multiple_of(base) {
Some(u64::try_from(d / base).unwrap())
} else {
None
Expand Down
3 changes: 1 addition & 2 deletions oximeter/instruments/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,7 @@ impl LatencyTracker {
impl Producer for LatencyTracker {
fn produce(
&mut self,
) -> Result<Box<(dyn Iterator<Item = Sample> + 'static)>, MetricsError>
{
) -> Result<Box<dyn Iterator<Item = Sample> + 'static>, MetricsError> {
// Clippy isn't correct here. It recommends using the iterator
// over the latencies directly, but there is a lifetime mismatch
// in that case: '_ would have to be 'static. The point is that
Expand Down
2 changes: 1 addition & 1 deletion oximeter/instruments/src/kstat/sampler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1377,7 +1377,7 @@ impl KstatSampler {
impl oximeter::Producer for KstatSampler {
fn produce(
&mut self,
) -> Result<Box<(dyn Iterator<Item = Sample>)>, MetricsError> {
) -> Result<Box<dyn Iterator<Item = Sample>>, MetricsError> {
// Swap the _entries_ of all the existing per-target sample queues, but
// we need to leave empty queues in their place. I.e., we can't remove
// keys.
Expand Down
Loading
Loading