diff --git a/Cargo.lock b/Cargo.lock index 5ef5a78..b6511e3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1198,28 +1198,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "num_enum" -version = "0.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1207a7e20ad57b847bbddc6776b968420d38292bbfe2089accff5e19e82454c" -dependencies = [ - "num_enum_derive", - "rustversion", -] - -[[package]] -name = "num_enum_derive" -version = "0.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff32365de1b6743cb203b710788263c44a03de03802daf96092f2da4fe6ba4d7" -dependencies = [ - "proc-macro-crate", - "proc-macro2", - "quote", - "syn 2.0.106", -] - [[package]] name = "once_cell" version = "1.21.3" @@ -2192,7 +2170,6 @@ dependencies = [ "env_logger", "epoll", "log", - "num_enum", "tempfile", "thiserror 2.0.17", "vhost", diff --git a/vhost-device-scsi/Cargo.toml b/vhost-device-scsi/Cargo.toml index 564274d..bb5abea 100644 --- a/vhost-device-scsi/Cargo.toml +++ b/vhost-device-scsi/Cargo.toml @@ -19,7 +19,6 @@ clap = { version = "4.5", features = ["derive"] } env_logger = "0.11" epoll = "4.4" log = "0.4" -num_enum = "0.7" thiserror = "2.0" vhost = { version = "0.14", features = ["vhost-user-backend"] } vhost-user-backend = "0.20" diff --git a/vhost-device-scsi/src/scsi/emulation/command.rs b/vhost-device-scsi/src/scsi/emulation/command.rs index e5e1ee2..ce2b307 100644 --- a/vhost-device-scsi/src/scsi/emulation/command.rs +++ b/vhost-device-scsi/src/scsi/emulation/command.rs @@ -13,12 +13,11 @@ use std::convert::{TryFrom, TryInto}; use log::warn; -use num_enum::TryFromPrimitive; use crate::scsi::emulation::mode_page::ModePage; /// One of the modes supported by SCSI's REPORT LUNS command. -#[derive(PartialEq, Eq, TryFromPrimitive, Debug, Copy, Clone)] +#[derive(PartialEq, Eq, Debug, Copy, Clone)] #[repr(u8)] pub(crate) enum ReportLunsSelectReport { NoWellKnown = 0x0, @@ -29,6 +28,22 @@ pub(crate) enum ReportLunsSelectReport { SameConglomerate = 0x12, } +impl TryFrom for ReportLunsSelectReport { + type Error = (); + + fn try_from(val: u8) -> Result { + match val { + 0x0 => Ok(Self::NoWellKnown), + 0x1 => Ok(Self::WellKnownOnly), + 0x2 => Ok(Self::All), + 0x10 => Ok(Self::Administrative), + 0x11 => Ok(Self::TopLevel), + 0x12 => Ok(Self::SameConglomerate), + _ => Err(()), + } + } +} + /// A type of "vital product data" page returned by SCSI's INQUIRY command. #[derive(PartialEq, Eq, Debug, Copy, Clone)] pub(crate) enum VpdPage { @@ -61,7 +76,7 @@ pub(crate) enum VpdPage { } // starred ones are ones Linux will use if available -#[derive(PartialEq, Eq, TryFromPrimitive, Debug, Copy, Clone)] +#[derive(PartialEq, Eq, Debug, Copy, Clone)] #[repr(u8)] pub(crate) enum ModeSensePageControl { Current = 0b00, @@ -70,6 +85,20 @@ pub(crate) enum ModeSensePageControl { Saved = 0b11, } +impl TryFrom for ModeSensePageControl { + type Error = (); + + fn try_from(val: u8) -> Result { + match val { + 0b00 => Ok(Self::Current), + 0b01 => Ok(Self::Changeable), + 0b10 => Ok(Self::Default), + 0b11 => Ok(Self::Saved), + _ => Err(()), + } + } +} + impl TryFrom for VpdPage { type Error = ();