8
8
#[ macro_use]
9
9
extern crate log;
10
10
11
+ use std:: borrow:: Cow ;
11
12
use std:: fmt:: { Display , Formatter } ;
12
13
use std:: path:: Path ;
13
14
use std:: sync:: { Arc , Mutex } ;
@@ -81,7 +82,7 @@ pub type Result<T> = std::result::Result<T, Error>;
81
82
/// This structure is the public API the backend is allowed to interact with in order to run
82
83
/// a fully functional vhost-user daemon.
83
84
pub struct VhostUserDaemon < T : VhostUserBackend > {
84
- name : String ,
85
+ name : Cow < ' static , str > ,
85
86
handler : Arc < Mutex < VhostUserHandler < T > > > ,
86
87
main_thread : Option < thread:: JoinHandle < Result < ( ) > > > ,
87
88
}
98
99
/// registered event. Those events can be vring events or custom events from the backend,
99
100
/// but they get to be registered later during the sequence.
100
101
pub fn new (
101
- name : String ,
102
+ name : Cow < ' static , str > ,
102
103
backend : T ,
103
104
atomic_mem : GuestMemoryAtomic < GuestMemoryMmap < T :: Bitmap > > ,
104
105
) -> Result < Self > {
@@ -124,7 +125,7 @@ where
124
125
mut handler : BackendReqHandler < Mutex < VhostUserHandler < T > > > ,
125
126
) -> Result < ( ) > {
126
127
let handle = thread:: Builder :: new ( )
127
- . name ( self . name . clone ( ) )
128
+ . name ( self . name . to_string ( ) )
128
129
. spawn ( move || loop {
129
130
handler. handle_request ( ) . map_err ( Error :: HandleRequest ) ?;
130
131
} )
@@ -253,7 +254,7 @@ mod tests {
253
254
GuestMemoryMmap :: < ( ) > :: from_ranges ( & [ ( GuestAddress ( 0x100000 ) , 0x10000 ) ] ) . unwrap ( ) ,
254
255
) ;
255
256
let backend = Arc :: new ( Mutex :: new ( MockVhostBackend :: new ( ) ) ) ;
256
- let mut daemon = VhostUserDaemon :: new ( "test" . to_owned ( ) , backend, mem) . unwrap ( ) ;
257
+ let mut daemon = VhostUserDaemon :: new ( "test" . into ( ) , backend, mem) . unwrap ( ) ;
257
258
258
259
let handlers = daemon. get_epoll_handlers ( ) ;
259
260
assert_eq ! ( handlers. len( ) , 2 ) ;
@@ -286,7 +287,7 @@ mod tests {
286
287
GuestMemoryMmap :: < ( ) > :: from_ranges ( & [ ( GuestAddress ( 0x100000 ) , 0x10000 ) ] ) . unwrap ( ) ,
287
288
) ;
288
289
let backend = Arc :: new ( Mutex :: new ( MockVhostBackend :: new ( ) ) ) ;
289
- let mut daemon = VhostUserDaemon :: new ( "test" . to_owned ( ) , backend, mem) . unwrap ( ) ;
290
+ let mut daemon = VhostUserDaemon :: new ( "test" . into ( ) , backend, mem) . unwrap ( ) ;
290
291
291
292
let handlers = daemon. get_epoll_handlers ( ) ;
292
293
assert_eq ! ( handlers. len( ) , 2 ) ;
@@ -321,7 +322,7 @@ mod tests {
321
322
GuestMemoryMmap :: < ( ) > :: from_ranges ( & [ ( GuestAddress ( 0x100000 ) , 0x10000 ) ] ) . unwrap ( ) ,
322
323
) ;
323
324
let backend = Arc :: new ( Mutex :: new ( MockVhostBackend :: new ( ) ) ) ;
324
- let mut daemon = VhostUserDaemon :: new ( "test" . to_owned ( ) , backend. clone ( ) , mem) . unwrap ( ) ;
325
+ let mut daemon = VhostUserDaemon :: new ( "test" . into ( ) , backend. clone ( ) , mem) . unwrap ( ) ;
325
326
let tmpdir = tempfile:: tempdir ( ) . unwrap ( ) ;
326
327
let socket_path = tmpdir. path ( ) . join ( "socket" ) ;
327
328
0 commit comments