diff --git a/alioth-cli/src/main.rs b/alioth-cli/src/main.rs index ebf84bf..0a5945a 100644 --- a/alioth-cli/src/main.rs +++ b/alioth-cli/src/main.rs @@ -354,7 +354,7 @@ fn main_run(args: RunArgs) -> Result<(), Error> { }; if args.entropy { - vm.add_virtio_dev("virtio-entropy".to_owned(), EntropyParam) + vm.add_virtio_dev("virtio-entropy", EntropyParam) .context(error::CreateDevice)?; } #[cfg(target_os = "linux")] @@ -396,7 +396,7 @@ fn main_run(args: RunArgs) -> Result<(), Error> { serde_aco::from_args(&vsock, &objects).context(error::ParseArg { arg: vsock })?; match param { VsockParam::Vhost(p) => vm - .add_virtio_dev("vhost-vsock".to_owned(), p) + .add_virtio_dev("vhost-vsock", p) .context(error::CreateDevice)?, }; } diff --git a/alioth/src/device/console.rs b/alioth/src/device/console.rs index 3408732..7845113 100644 --- a/alioth/src/device/console.rs +++ b/alioth/src/device/console.rs @@ -71,7 +71,7 @@ pub trait UartRecv: Send + 'static { } struct ConsoleWorker { - name: Arc, + name: Arc, uart: U, poll: Poll, } @@ -139,7 +139,7 @@ impl ConsoleWorker { #[derive(Debug)] pub struct Console { - pub name: Arc, + pub name: Arc, worker_thread: Option>, exit_waker: Waker, } @@ -148,7 +148,8 @@ const TOKEN_SHUTDOWN: Token = Token(1); const TOKEN_STDIN: Token = Token(0); impl Console { - pub fn new(name: Arc, uart: impl UartRecv) -> Result { + pub fn new(name: impl Into>, uart: impl UartRecv) -> Result { + let name = name.into(); let poll = Poll::new()?; let waker = Waker::new(poll.registry(), TOKEN_SHUTDOWN)?; let mut worker = ConsoleWorker { diff --git a/alioth/src/device/pl011.rs b/alioth/src/device/pl011.rs index 5bd7a74..90837f7 100644 --- a/alioth/src/device/pl011.rs +++ b/alioth/src/device/pl011.rs @@ -143,7 +143,7 @@ struct Pl011Reg { /// https://developer.arm.com/documentation/ddi0183/g #[derive(Debug)] pub struct Pl011 { - name: Arc, + name: Arc, irq_line: Arc, reg: Arc>, console: Console, @@ -156,7 +156,7 @@ where pub fn new(base_addr: u64, irq_line: I) -> io::Result { let irq_line = Arc::new(irq_line); let reg = Arc::new(Mutex::new(Pl011Reg::default())); - let name = Arc::new(format!("pl011@{base_addr:#x}")); + let name: Arc = Arc::from(format!("pl011@{base_addr:#x}")); let pl011_recv = Pl011Recv { irq_line: irq_line.clone(), reg: reg.clone(), diff --git a/alioth/src/device/serial.rs b/alioth/src/device/serial.rs index a6e17b0..ce34318 100644 --- a/alioth/src/device/serial.rs +++ b/alioth/src/device/serial.rs @@ -183,7 +183,7 @@ struct SerialReg { #[derive(Debug)] pub struct Serial { - name: Arc, + name: Arc, irq_sender: Arc, reg: Arc>, console: Console, @@ -283,7 +283,7 @@ where } struct SerialRecv { - pub name: Arc, + pub name: Arc, pub irq_sender: Arc, pub reg: Arc>, } @@ -312,7 +312,7 @@ where pub fn new(base_port: u16, irq_sender: I) -> io::Result { let irq_sender = Arc::new(irq_sender); let reg = Arc::new(Mutex::new(SerialReg::default())); - let name = Arc::new(format!("serial_{:#x}", base_port)); + let name: Arc = Arc::from(format!("serial_{:#x}", base_port)); let uart_recv = SerialRecv { irq_sender: irq_sender.clone(), name: name.clone(), diff --git a/alioth/src/pci/bus.rs b/alioth/src/pci/bus.rs index d79d665..dac1631 100644 --- a/alioth/src/pci/bus.rs +++ b/alioth/src/pci/bus.rs @@ -97,10 +97,7 @@ pub struct PciBus { impl PciBus { pub fn new() -> Self { let devices = if cfg!(target_arch = "x86_64") { - let bridge = PciDevice::new( - Arc::new("host_bridge".to_owned()), - Arc::new(HostBridge::new()), - ); + let bridge = PciDevice::new("host_bridge", Arc::new(HostBridge::new())); HashMap::from([(Bdf(0), bridge)]) } else { HashMap::new() @@ -122,7 +119,7 @@ impl PciBus { } } - pub fn reserve(&self, bdf: Option, name: Arc) -> Option { + pub fn reserve(&self, bdf: Option, name: Arc) -> Option { self.segment.reserve(bdf, name) } diff --git a/alioth/src/pci/pci.rs b/alioth/src/pci/pci.rs index d926a04..7a15457 100644 --- a/alioth/src/pci/pci.rs +++ b/alioth/src/pci/pci.rs @@ -92,12 +92,12 @@ impl MemRegionCallback for BarCallback { #[derive(Debug)] pub struct PciDevice { - pub name: Arc, + pub name: Arc, pub dev: Arc, } impl PciDevice { - pub fn new(name: Arc, dev: Arc) -> PciDevice { + pub fn new(name: impl Into>, dev: Arc) -> PciDevice { let config = dev.config(); let dev_bars = &config.get_header().bars; for (index, dev_bar) in dev_bars.iter().enumerate() { @@ -114,6 +114,9 @@ impl PciDevice { })), } } - PciDevice { name, dev } + PciDevice { + name: name.into(), + dev, + } } } diff --git a/alioth/src/pci/segment.rs b/alioth/src/pci/segment.rs index c650494..5a80f0d 100644 --- a/alioth/src/pci/segment.rs +++ b/alioth/src/pci/segment.rs @@ -59,7 +59,7 @@ impl PciSegment { } } - pub fn reserve(&self, bdf: Option, name: Arc) -> Option { + pub fn reserve(&self, bdf: Option, name: Arc) -> Option { let mut empty_dev = PciDevice { name: name.clone(), dev: Arc::new(EmptyDevice), diff --git a/alioth/src/vfio/pci.rs b/alioth/src/vfio/pci.rs index add8f61..c18978c 100644 --- a/alioth/src/vfio/pci.rs +++ b/alioth/src/vfio/pci.rs @@ -210,7 +210,7 @@ impl SlotBackend for MaskedCap { #[derive(Debug)] struct VfioCdev { - name: Arc, + name: Arc, dev: Cdev, } @@ -397,14 +397,17 @@ where M: MsiSender, { pub fn new( - name: Arc, + name: impl Into>, param: &VfioParam, ioas: Arc, msi_sender: M, ) -> Result> { let mut dev = Cdev::new(¶m.cdev)?; dev.attach_iommu_ioas(ioas)?; - let cdev = Arc::new(VfioCdev { dev, name }); + let cdev = Arc::new(VfioCdev { + dev, + name: name.into(), + }); let region_config = cdev.dev.get_region_info(VfioPciRegion::CONFIG.raw())?; diff --git a/alioth/src/virtio/dev/blk.rs b/alioth/src/virtio/dev/blk.rs index 32f3f09..9bdc457 100644 --- a/alioth/src/virtio/dev/blk.rs +++ b/alioth/src/virtio/dev/blk.rs @@ -136,21 +136,21 @@ pub struct BlockParam { impl DevParam for BlockParam { type Device = Block; - fn build(self, name: Arc) -> Result { + fn build(self, name: impl Into>) -> Result { Block::new(self, name) } } #[derive(Debug)] pub struct Block { - name: Arc, + name: Arc, config: Arc, disk: File, feature: BlockFeature, } impl Block { - pub fn new(param: BlockParam, name: Arc) -> Result { + pub fn new(param: BlockParam, name: impl Into>) -> Result { let access_disk = error::AccessFile { path: param.path.as_path(), }; @@ -171,7 +171,7 @@ impl Block { feature |= BlockFeature::RO; } Ok(Block { - name, + name: name.into(), disk, config, feature, diff --git a/alioth/src/virtio/dev/dev.rs b/alioth/src/virtio/dev/dev.rs index 74080a5..845a85e 100644 --- a/alioth/src/virtio/dev/dev.rs +++ b/alioth/src/virtio/dev/dev.rs @@ -146,7 +146,7 @@ struct DeviceWorker where S: IrqSender, { - name: Arc, + name: Arc, dev: D, poll: Poll, memory: Arc, @@ -162,7 +162,7 @@ where S: IrqSender, E: IoeventFd, { - pub name: Arc, + pub name: Arc, pub device_config: Arc, pub reg: Arc, pub queue_regs: Arc>, @@ -192,7 +192,7 @@ where } pub fn new( - name: Arc, + name: impl Into>, dev: D, memory: Arc, registry: &R, @@ -201,6 +201,7 @@ where where R: IoeventFdRegistry, { + let name = name.into(); let poll = Poll::new().context(error::CreatePoll)?; let device_config = dev.config(); let mut dev_feat = dev.feature(); @@ -250,7 +251,7 @@ where state: WorkerState::Pending, }; let handle = std::thread::Builder::new() - .name(name.as_ref().to_owned()) + .name(name.to_string()) .spawn(move || { let r = device_worker.do_work(); if let Err(e) = r { @@ -419,7 +420,7 @@ where pub trait DevParam { type Device; - fn build(self, name: Arc) -> Result; + fn build(self, name: impl Into>) -> Result; fn needs_mem_shared_fd(&self) -> bool { false } diff --git a/alioth/src/virtio/dev/entropy.rs b/alioth/src/virtio/dev/entropy.rs index de2a6d4..94851d8 100644 --- a/alioth/src/virtio/dev/entropy.rs +++ b/alioth/src/virtio/dev/entropy.rs @@ -55,19 +55,19 @@ bitflags! { #[derive(Debug)] pub struct Entropy { - name: Arc, + name: Arc, source: File, config: Arc, } impl Entropy { - pub fn new(name: Arc) -> Result { + pub fn new(name: impl Into>) -> Result { let mut options = OpenOptions::new(); options.custom_flags(O_NONBLOCK).read(true); let path = "/dev/urandom"; let file = options.open(path).context(error::AccessFile { path })?; Ok(Entropy { - name, + name: name.into(), source: file, config: Arc::new(EntropyConfig), }) @@ -140,7 +140,7 @@ pub struct EntropyParam; impl DevParam for EntropyParam { type Device = Entropy; - fn build(self, name: Arc) -> Result { + fn build(self, name: impl Into>) -> Result { Entropy::new(name) } } diff --git a/alioth/src/virtio/dev/fs.rs b/alioth/src/virtio/dev/fs.rs index d70ad75..02bb14d 100644 --- a/alioth/src/virtio/dev/fs.rs +++ b/alioth/src/virtio/dev/fs.rs @@ -74,7 +74,7 @@ const VHOST_USER_BACKEND_FS_UNMAP: u32 = 7; #[derive(Debug)] pub struct VuFs { - name: Arc, + name: Arc, vu_dev: Arc, config: Arc, feature: u64, @@ -84,7 +84,8 @@ pub struct VuFs { } impl VuFs { - pub fn new(param: VuFsParam, name: Arc) -> Result { + pub fn new(param: VuFsParam, name: impl Into>) -> Result { + let name = name.into(); let mut vu_dev = VuDev::new(param.socket)?; let dev_feat = vu_dev.get_features()?; let virtio_feat = VirtioFeature::from_bits_retain(dev_feat); @@ -167,7 +168,7 @@ pub struct VuFsParam { impl DevParam for VuFsParam { type Device = VuFs; - fn build(self, name: Arc) -> Result { + fn build(self, name: impl Into>) -> Result { VuFs::new(self, name) } diff --git a/alioth/src/virtio/dev/net/net.rs b/alioth/src/virtio/dev/net/net.rs index dd77ea0..e9f4100 100644 --- a/alioth/src/virtio/dev/net/net.rs +++ b/alioth/src/virtio/dev/net/net.rs @@ -135,7 +135,7 @@ bitflags! { #[derive(Debug)] pub struct Net { - name: Arc, + name: Arc, config: Arc, tap_sockets: Vec, feature: NetFeature, @@ -168,7 +168,7 @@ pub struct NetParam { impl DevParam for NetParam { type Device = Net; - fn build(self, name: Arc) -> Result { + fn build(self, name: impl Into>) -> Result { Net::new(self, name) } } @@ -184,7 +184,7 @@ fn new_socket(dev_tap: Option<&Path>) -> Result { } impl Net { - pub fn new(param: NetParam, name: Arc) -> Result { + pub fn new(param: NetParam, name: impl Into>) -> Result { let mut socket = new_socket(param.tap.as_deref())?; let max_queue_pairs = param.queue_pairs.map(From::from).unwrap_or(1); setup_socket(&mut socket, param.if_name.as_deref(), max_queue_pairs > 1)?; @@ -202,7 +202,7 @@ impl Net { dev_feat |= NetFeature::MQ; } let net = Net { - name, + name: name.into(), config: Arc::new(NetConfig { mac: param.mac, max_queue_pairs, diff --git a/alioth/src/virtio/dev/vsock/vhost_vsock.rs b/alioth/src/virtio/dev/vsock/vhost_vsock.rs index d695b19..729037e 100644 --- a/alioth/src/virtio/dev/vsock/vhost_vsock.rs +++ b/alioth/src/virtio/dev/vsock/vhost_vsock.rs @@ -45,14 +45,14 @@ pub struct VhostVsockParam { impl DevParam for VhostVsockParam { type Device = VhostVsock; - fn build(self, name: Arc) -> Result { + fn build(self, name: impl Into>) -> Result { VhostVsock::new(self, name) } } #[derive(Debug)] pub struct VhostVsock { - name: Arc, + name: Arc, vhost_dev: Arc, config: VsockConfig, features: u64, @@ -60,7 +60,8 @@ pub struct VhostVsock { } impl VhostVsock { - pub fn new(param: VhostVsockParam, name: Arc) -> Result { + pub fn new(param: VhostVsockParam, name: impl Into>) -> Result { + let name = name.into(); let vhost_dev = match param.dev { Some(dev) => VhostDev::new(dev), None => VhostDev::new("/dev/vhost-vsock"), diff --git a/alioth/src/virtio/pci.rs b/alioth/src/virtio/pci.rs index a86d5a9..568f875 100644 --- a/alioth/src/virtio/pci.rs +++ b/alioth/src/virtio/pci.rs @@ -184,7 +184,7 @@ pub struct VirtioPciRegisterMmio where M: MsiSender, { - name: Arc, + name: Arc, reg: Arc, queues: Arc>, irq_sender: Arc>, diff --git a/alioth/src/vm.rs b/alioth/src/vm.rs index fccbad1..11c6722 100644 --- a/alioth/src/vm.rs +++ b/alioth/src/vm.rs @@ -202,7 +202,7 @@ where pub fn add_pvpanic(&mut self) -> Result<(), Error> { let dev = PvPanic::new(); - let pci_dev = PciDevice::new("pvpanic".to_owned().into(), Arc::new(dev)); + let pci_dev = PciDevice::new("pvpanic", Arc::new(dev)); self.add_pci_dev(None, pci_dev) } @@ -226,7 +226,7 @@ where pub fn add_virtio_dev( &mut self, - name: String, + name: impl Into>, param: P, ) -> Result>, Error> where @@ -236,7 +236,7 @@ where if param.needs_mem_shared_fd() && !self.board.config.mem.has_shared_fd() { return error::MemNotSharedFd.fail(); } - let name = Arc::new(name); + let name = name.into(); let bdf = self.board.pci_bus.reserve(None, name.clone()).unwrap(); let dev = param.build(name.clone())?; if let Some(callback) = dev.mem_update_callback() { @@ -301,8 +301,12 @@ where #[cfg(target_os = "linux")] impl Machine { - pub fn add_vfio_dev(&mut self, name: String, param: VfioParam) -> Result<(), Error> { - let name = Arc::new(name); + pub fn add_vfio_dev( + &mut self, + name: impl Into>, + param: VfioParam, + ) -> Result<(), Error> { + let name = name.into(); let iommu = if let Some(iommu) = &self.iommu { iommu.clone() } else {