/// start mayastor and open the unix socket, if we are able to connect
/// we know we are up and running and ready for business.
start mayastor and open the unix socket, if we are able to connect
we know we are up and running and ready for business.
start mayastor and open the unix socket if we are able to connect we know we are up and running and ready for business .
pub fn new(args: Box<[String]>) -> Result<Self, ()> {
        let mayastor = get_path("mayastor");
        let (tx, rx) = std::sync::mpsc::channel::<MayastorProcess>();
        thread::spawn(move || {
            Mthread::unaffinitize();
            if let Err(e) = fs::create_dir(hugetlbfs_path()) {
                panic!("failed to create hugetlbfs mount path {}", e);
            }
            let output = Command::new("mount")
                .args(&[
                    "-t",
                    "hugetlbfs",
                    "nodev",
                    &hugetlbfs_path(),
                    "-o",
                    "pagesize=2048k",
                ])
                .output()
                .expect("could not exec mount");
            if !output.status.success() {
                io::stderr().write_all(&output.stderr).unwrap();
                panic!("failed to mount hugetlbfs");
            }
            let mut child = Command::new(mayastor)
                .args(&["-r", &rpc_sock_path()])
                .args(&["--huge-dir", &hugetlbfs_path()])
                .args(args.into_vec())
                .stdout(Stdio::piped())
                .stderr(Stdio::inherit())
                .spawn()
                .unwrap();
            while !MayastorProcess::ping(&rpc_sock_path()) {
                match child.try_wait() {
                    Ok(Some(_status)) => tx
                        .send(MayastorProcess {
                            child: child.id(),
                            rpc_path: rpc_sock_path(),
                            hugetlbfs: hugetlbfs_path(),
                        })
                        .unwrap(),
                    Err(_e) => tx
                        .send(MayastorProcess {
                            child: 0,
                            rpc_path: rpc_sock_path(),
                            hugetlbfs: hugetlbfs_path(),
                        })
                        .unwrap(),
                    _ => (),
                };
                std::thread::sleep(Duration::from_millis(200));
            }
            let m = MayastorProcess {
                child: child.id(),
                rpc_path: rpc_sock_path(),
                hugetlbfs: hugetlbfs_path(),
            };
            let _ = tx.send(m);
        });
        let m = rx.recv().unwrap();
        if m.child == 0 {
            panic!("Mayastor not started within deadline");
        } else {
            Ok(m)
        }
    }
pub fn new ( args : Box < [ String ] > ) -> Result < Self , ( ) > { let mayastor = get_path ( " " ) ; let ( tx , rx ) = std :: sync :: mpsc :: channel :: < MayastorProcess > ( ) ; thread :: spawn ( move | | { Mthread :: unaffinitize ( ) ; if let Err ( e ) = fs :: create_dir ( hugetlbfs_path ( ) ) { panic ! ( " " e ) ; } let output = Command :: new ( " " ) . args ( & [ " " , " " , " " , & hugetlbfs_path ( ) , " " , " " , ] ) . output ( ) . expect ( " " ) ; if ! output . status . success ( ) { io :: stderr ( ) . write_all ( & output . stderr ) . unwrap ( ) ; panic ! ( " " ) ; } let mut child = Command :: new ( mayastor ) . args ( & [ " " , & rpc_sock_path ( ) ] ) . args ( & [ " " , & hugetlbfs_path ( ) ] ) . args ( args . into_vec ( ) ) . stdout ( Stdio :: piped ( ) ) . stderr ( Stdio :: inherit ( ) ) . spawn ( ) . unwrap ( ) ; while ! MayastorProcess :: ping ( & rpc_sock_path ( ) ) { match child . try_wait ( ) { Ok ( Some ( _status ) ) => tx . send ( MayastorProcess { child : child . id ( ) , rpc_path : rpc_sock_path ( ) , hugetlbfs : hugetlbfs_path ( ) , } ) . unwrap ( ) , Err ( _e ) => tx . send ( MayastorProcess { child : 0 , rpc_path : rpc_sock_path ( ) , hugetlbfs : hugetlbfs_path ( ) , } ) . unwrap ( ) , _ => ( ) , } ; std :: thread :: sleep ( Duration :: from_millis ( 200 ) ) ; } let m = MayastorProcess { child : child . id ( ) , rpc_path : rpc_sock_path ( ) , hugetlbfs : hugetlbfs_path ( ) , } ; let _ = tx . send ( m ) ; } ) ; let m = rx . recv ( ) . unwrap ( ) ; if m . child == 0 { panic ! ( " " ) ; } else { Ok ( m ) } }
start mayastor and open the unix socket, if we are able to connect
we know we are up and running and ready for business.
start mayastor and open the unix socket if we are able to connect we know we are up and running and ready for business .
args
Box<[String]>