@@ -427,6 +427,9 @@ static int hyper_setup_shm(struct hyper_pod *pod)
427427 return 0 ;
428428}
429429
430+ static bool is_serial = false;
431+ static bool is_xen = false;
432+
430433#ifdef WITH_VBOX
431434
432435#define MAX_HOST_NAME 256
@@ -489,6 +492,8 @@ static int hyper_setup_shared(struct hyper_pod *pod)
489492#else
490493static int hyper_setup_shared (struct hyper_pod * pod )
491494{
495+ int ret ;
496+
492497 if (pod -> share_tag == NULL ) {
493498 fprintf (stdout , "no shared directory\n" );
494499 return 0 ;
@@ -499,11 +504,14 @@ static int hyper_setup_shared(struct hyper_pod *pod)
499504 return -1 ;
500505 }
501506
502- if (mount (pod -> share_tag , SHARED_DIR , "9p" ,
503- MS_MGC_VAL | MS_NODEV , "trans=virtio" ) < 0 ) {
507+ if (is_xen )
508+ ret = mount (pod -> share_tag , SHARED_DIR , "9p" , MS_NODEV , "trans=xen" );
509+ else
510+ ret = mount (pod -> share_tag , SHARED_DIR , "9p" , MS_MGC_VAL | MS_NODEV , "trans=virtio" );
504511
512+ if (ret < 0 ) {
505513 perror ("fail to mount shared dir" );
506- return -1 ;
514+ return ret ;
507515 }
508516
509517 return 0 ;
@@ -953,7 +961,7 @@ static int hyper_ctl_send_ready(int fd)
953961 return 0 ;
954962}
955963
956- static int hyper_setup_ctl_channel (char * name , bool is_serial )
964+ static int hyper_setup_ctl_channel (char * name )
957965{
958966 int fd = hyper_open_channel (name , 0 , is_serial );
959967 if (fd < 0 )
@@ -967,7 +975,7 @@ static int hyper_setup_ctl_channel(char *name, bool is_serial)
967975 return fd ;
968976}
969977
970- static int hyper_setup_tty_channel (char * name , bool is_serial )
978+ static int hyper_setup_tty_channel (char * name )
971979{
972980 int ret = hyper_open_channel (name , O_NONBLOCK , is_serial );
973981 if (ret < 0 )
@@ -980,13 +988,75 @@ static int hyper_setup_vsock_channel(void)
980988{
981989 hyper_epoll .vsock_ctl_listener .fd = hyper_create_vsock_listener (HYPER_VSOCK_CTL_PORT );
982990 if (hyper_epoll .vsock_ctl_listener .fd < 0 )
983- return -1 ;
991+ goto out ;
984992
985993 hyper_epoll .vsock_msg_listener .fd = hyper_create_vsock_listener (HYPER_VSOCK_MSG_PORT );
986994 if (hyper_epoll .vsock_msg_listener .fd < 0 )
995+ goto out ;
996+
997+ return 0 ;
998+ out :
999+ close (hyper_epoll .vsock_ctl_listener .fd );
1000+ close (hyper_epoll .vsock_msg_listener .fd );
1001+ return -1 ;
1002+ }
1003+
1004+ static int hyper_setup_normal_channel (void )
1005+ {
1006+ char * ctl_serial = NULL , * tty_serial = NULL ;
1007+
1008+ #ifdef WITH_VBOX
1009+ ctl_serial = strdup ("/dev/ttyS0" );
1010+ tty_serial = strdup ("/dev/ttyS1" );
1011+ is_serial = true;
1012+
1013+ if (hyper_insmod ("/vboxguest.ko" ) < 0 ||
1014+ hyper_insmod ("/vboxsf.ko" ) < 0 ) {
1015+ fprintf (stderr , "fail to load modules\n" );
9871016 return -1 ;
1017+ }
1018+ #else
1019+ if (is_serial ) {
1020+ ctl_serial = strdup ("/dev/ttyS1" );
1021+ tty_serial = strdup ("/dev/ttyS2" );
1022+ } else if (is_xen ) {
1023+ ctl_serial = strdup ("/dev/hvc1" );
1024+ tty_serial = strdup ("/dev/hvc2" );
1025+ is_serial = true;
1026+ } else {
1027+ ctl_serial = hyper_find_virtio_port ("sh.hyper.channel.0" );
1028+ if (ctl_serial == NULL ) {
1029+ fprintf (stderr , "cannot find ctl channel\n" );
1030+ goto out ;
1031+ }
1032+ tty_serial = hyper_find_virtio_port ("sh.hyper.channel.1" );
1033+ if (tty_serial == NULL ) {
1034+ fprintf (stderr , "cannot find tty channel\n" );
1035+ goto out ;
1036+ }
1037+ }
1038+ #endif
1039+ fprintf (stdout , "ctl: %s, tty: %s\n" , ctl_serial , tty_serial );
1040+ hyper_epoll .ctl .fd = hyper_setup_ctl_channel (ctl_serial );
1041+ if (hyper_epoll .ctl .fd < 0 ) {
1042+ fprintf (stderr , "fail to setup hyper control serial port\n" );
1043+ goto out ;
1044+ }
9881045
1046+ hyper_epoll .tty .fd = hyper_setup_tty_channel (tty_serial );
1047+ if (hyper_epoll .tty .fd < 0 ) {
1048+ fprintf (stderr , "fail to setup hyper tty serial port\n" );
1049+ goto out ;
1050+ }
1051+ free (ctl_serial );
1052+ free (tty_serial );
9891053 return 0 ;
1054+ out :
1055+ free (ctl_serial );
1056+ free (tty_serial );
1057+ close (hyper_epoll .ctl .fd );
1058+ close (hyper_epoll .tty .fd );
1059+ return -1 ;
9901060}
9911061
9921062static int hyper_ttyfd_handle (struct hyper_event * de , uint32_t len )
@@ -1561,7 +1631,7 @@ static int hyper_setup_init_process(void)
15611631 return 0 ;
15621632}
15631633
1564- void read_cmdline (bool * use_serial )
1634+ void read_cmdline ()
15651635{
15661636 char buf [512 ];
15671637 int size ;
@@ -1578,17 +1648,19 @@ void read_cmdline(bool *use_serial)
15781648 }
15791649
15801650 if (strstr (buf , HYPER_USE_SERAIL ))
1581- * use_serial = true;
1651+ is_serial = true;
15821652
1653+ if (strstr (buf , HYPER_P9_USE_XEN ))
1654+ is_xen = true;
15831655out :
15841656 close (fd );
15851657 return ;
15861658}
15871659
15881660int main (int argc , char * argv [])
15891661{
1590- char * binary_name , * ctl_serial = NULL , * tty_serial = NULL ;
1591- bool is_init , has_vsock = false, is_serial = false ;
1662+ char * binary_name = NULL ;
1663+ bool is_init , has_vsock = false;
15921664
15931665 binary_name = basename (argv [0 ]);
15941666 is_init = strncmp (binary_name , "init" , 5 ) == 0 ;
@@ -1597,25 +1669,7 @@ int main(int argc, char *argv[])
15971669 return -1 ;
15981670 }
15991671
1600- read_cmdline (& is_serial );
1601- #ifdef WITH_VBOX
1602- ctl_serial = "/dev/ttyS0" ;
1603- tty_serial = "/dev/ttyS1" ;
1604- is_serial = true;
1605-
1606- if (hyper_insmod ("/vboxguest.ko" ) < 0 ||
1607- hyper_insmod ("/vboxsf.ko" ) < 0 ) {
1608- fprintf (stderr , "fail to load modules\n" );
1609- return -1 ;
1610- }
1611- #else
1612- if (is_serial ) {
1613- ctl_serial = "/dev/ttyS1" ;
1614- tty_serial = "/dev/ttyS2" ;
1615- } else {
1616- ctl_serial = strdup ("sh.hyper.channel.0" );
1617- tty_serial = strdup ("sh.hyper.channel.1" );
1618- }
1672+ read_cmdline ();
16191673
16201674 if (probe_vsock_device () <= 0 ) {
16211675 fprintf (stderr , "cannot find vsock device\n" );
@@ -1624,37 +1678,20 @@ int main(int argc, char *argv[])
16241678 } else {
16251679 has_vsock = true;
16261680 }
1627- #endif
1681+
16281682 if (has_vsock ) {
16291683 if (hyper_setup_vsock_channel () < 0 ) {
16301684 fprintf (stderr , "fail to setup hyper vsock listener\n" );
1631- goto out ;
1685+ return -1 ;
16321686 }
16331687 } else {
1634- hyper_epoll .ctl .fd = hyper_setup_ctl_channel (ctl_serial , is_serial );
1635- if (hyper_epoll .ctl .fd < 0 ) {
1636- fprintf (stderr , "fail to setup hyper control serial port\n" );
1637- goto out ;
1638- }
1639-
1640- hyper_epoll .tty .fd = hyper_setup_tty_channel (tty_serial , is_serial );
1641- if (hyper_epoll .tty .fd < 0 ) {
1642- fprintf (stderr , "fail to setup hyper tty serial port\n" );
1643- goto out ;
1688+ if (hyper_setup_normal_channel () < 0 ) {
1689+ fprintf (stderr , "fail to setup hyper serial channel\n" );
1690+ return -1 ;
16441691 }
16451692 }
16461693
16471694 hyper_loop ();
16481695
1649- out :
1650- if (hyper_epoll .vsock_ctl_listener .fd > 0 )
1651- close (hyper_epoll .vsock_ctl_listener .fd );
1652- if (hyper_epoll .vsock_msg_listener .fd > 0 )
1653- close (hyper_epoll .vsock_msg_listener .fd );
1654- if (hyper_epoll .tty .fd > 0 )
1655- close (hyper_epoll .tty .fd );
1656- if (hyper_epoll .ctl .fd > 0 )
1657- close (hyper_epoll .ctl .fd );
1658-
16591696 return 0 ;
16601697}
0 commit comments