Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit ef7010a

Browse files
committed
support kvmtool
for x86_64 ./configure for aarch64 ./configure --with-aarch64 Signed-off-by: Gao feng <omarapazanadi@gmail.com>
1 parent 9693004 commit ef7010a

File tree

4 files changed

+58
-34
lines changed

4 files changed

+58
-34
lines changed

src/api.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,8 @@ enum {
6464
#define HYPER_VSOCK_CTL_PORT 2718
6565
#define HYPER_VSOCK_MSG_PORT 2719
6666

67+
/*
68+
* use serial as channel passed through kernel cmdline
69+
*/
70+
#define HYPER_USE_SERAIL "hyper_use_serial"
6771
#endif /* _HYPERSTART_API_H_ */

src/init.c

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -924,13 +924,12 @@ static int hyper_ctl_send_ready(int fd)
924924
return 0;
925925
}
926926

927-
static int hyper_setup_ctl_channel(char *name)
927+
static int hyper_setup_ctl_channel(char *name, bool is_serial)
928928
{
929-
int fd;
930-
931-
fd = hyper_open_channel(name, 0);
929+
int fd = hyper_open_channel(name, 0, is_serial);
932930
if (fd < 0)
933931
return fd;
932+
934933
if (hyper_ctl_send_ready(fd) < 0) {
935934
close(fd);
936935
return -1;
@@ -939,9 +938,9 @@ static int hyper_setup_ctl_channel(char *name)
939938
return fd;
940939
}
941940

942-
static int hyper_setup_tty_channel(char *name)
941+
static int hyper_setup_tty_channel(char *name, bool is_serial)
943942
{
944-
int ret = hyper_open_channel(name, O_NONBLOCK);
943+
int ret = hyper_open_channel(name, O_NONBLOCK, is_serial);
945944
if (ret < 0)
946945
return -1;
947946

@@ -1061,8 +1060,7 @@ static int hyper_ttyfd_read(struct hyper_event *he, int efd, int events)
10611060
{
10621061
struct hyper_buf *buf = &he->rbuf;
10631062
uint32_t len;
1064-
int size;
1065-
int ret;
1063+
int size, ret;
10661064

10671065
if (buf->get < STREAM_HEADER_SIZE) {
10681066
size = hyper_channel_read(he, efd, STREAM_HEADER_SIZE - buf->get, events);
@@ -1524,10 +1522,34 @@ static int hyper_setup_init_process(void)
15241522
return 0;
15251523
}
15261524

1525+
void read_cmdline(bool *use_serial)
1526+
{
1527+
char buf[512];
1528+
int size;
1529+
1530+
int fd = open("/proc/cmdline", O_RDONLY| O_CLOEXEC);
1531+
if (fd < 0) {
1532+
perror("fail to open /proc/cmdline");
1533+
return;
1534+
}
1535+
size = read(fd, buf, sizeof(buf));
1536+
if (size < 0) {
1537+
perror("fail to read /proc/cmdline");
1538+
goto out;
1539+
}
1540+
1541+
if (strstr(buf, HYPER_USE_SERAIL))
1542+
*use_serial= true;
1543+
1544+
out:
1545+
close(fd);
1546+
return;
1547+
}
1548+
15271549
int main(int argc, char *argv[])
15281550
{
1529-
char *binary_name, *cmdline, *ctl_serial, *tty_serial;
1530-
bool is_init, has_vsock = false;
1551+
char *binary_name, *ctl_serial = NULL, *tty_serial = NULL;
1552+
bool is_init, has_vsock = false, is_serial = false;
15311553

15321554
binary_name = basename(argv[0]);
15331555
is_init = strncmp(binary_name, "init", 5) == 0;
@@ -1536,20 +1558,26 @@ int main(int argc, char *argv[])
15361558
return -1;
15371559
}
15381560

1539-
cmdline = read_cmdline();
1540-
1561+
read_cmdline(&is_serial);
15411562
#ifdef WITH_VBOX
15421563
ctl_serial = "/dev/ttyS0";
15431564
tty_serial = "/dev/ttyS1";
1565+
is_serial = true;
15441566

15451567
if (hyper_insmod("/vboxguest.ko") < 0 ||
15461568
hyper_insmod("/vboxsf.ko") < 0) {
15471569
fprintf(stderr, "fail to load modules\n");
15481570
return -1;
15491571
}
15501572
#else
1551-
ctl_serial = "sh.hyper.channel.0";
1552-
tty_serial = "sh.hyper.channel.1";
1573+
if (is_serial) {
1574+
ctl_serial = "/dev/ttyS1";
1575+
tty_serial = "/dev/ttyS2";
1576+
} else {
1577+
ctl_serial = strdup("sh.hyper.channel.0");
1578+
tty_serial = strdup("sh.hyper.channel.1");
1579+
}
1580+
15531581
if (probe_vsock_device() <= 0) {
15541582
fprintf(stderr, "cannot find vsock device\n");
15551583
} else if (hyper_cmd("modprobe vmw_vsock_virtio_transport") < 0) {
@@ -1558,20 +1586,19 @@ int main(int argc, char *argv[])
15581586
has_vsock = true;
15591587
}
15601588
#endif
1561-
15621589
if (has_vsock) {
15631590
if (hyper_setup_vsock_channel() < 0) {
15641591
fprintf(stderr, "fail to setup hyper vsock listener\n");
15651592
goto out;
15661593
}
15671594
} else {
1568-
hyper_epoll.ctl.fd = hyper_setup_ctl_channel(ctl_serial);
1595+
hyper_epoll.ctl.fd = hyper_setup_ctl_channel(ctl_serial, is_serial);
15691596
if (hyper_epoll.ctl.fd < 0) {
15701597
fprintf(stderr, "fail to setup hyper control serial port\n");
15711598
goto out;
15721599
}
15731600

1574-
hyper_epoll.tty.fd = hyper_setup_tty_channel(tty_serial);
1601+
hyper_epoll.tty.fd = hyper_setup_tty_channel(tty_serial, is_serial);
15751602
if (hyper_epoll.tty.fd < 0) {
15761603
fprintf(stderr, "fail to setup hyper tty serial port\n");
15771604
goto out;
@@ -1589,7 +1616,6 @@ int main(int argc, char *argv[])
15891616
close(hyper_epoll.tty.fd);
15901617
if (hyper_epoll.ctl.fd > 0)
15911618
close(hyper_epoll.ctl.fd);
1592-
free(cmdline);
15931619

15941620
return 0;
15951621
}

src/util.c

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,13 @@
1919
#include <grp.h>
2020
#include <pwd.h>
2121
#include <libgen.h>
22+
#include <termios.h>
2223

2324
#include "util.h"
2425
#include "hyper.h"
2526
#include "container.h"
2627
#include "../config.h"
2728

28-
char *read_cmdline(void)
29-
{
30-
return NULL;
31-
}
32-
3329
int hyper_setup_env(struct env *envs, int num, bool setPATH)
3430
{
3531
int i, ret = 0;
@@ -554,10 +550,7 @@ void online_memory(void)
554550
closedir(dir);
555551
}
556552

557-
#if WITH_VBOX
558-
559-
#include <termios.h>
560-
int hyper_open_channel(char *channel, int mode)
553+
static int hyper_open_serial(char *channel, int mode)
561554
{
562555
struct termios term;
563556
int fd = open(channel, O_RDWR | O_CLOEXEC | mode);
@@ -647,8 +640,8 @@ int hyper_insmod(char *module)
647640
ret = -1;
648641
goto out;
649642
}
650-
#else
651-
int hyper_open_channel(char *channel, int mode)
643+
644+
static int hyper_open_virtio_port(char *channel, int mode)
652645
{
653646
struct dirent **list;
654647
struct dirent *dir;
@@ -707,11 +700,13 @@ int hyper_open_channel(char *channel, int mode)
707700
return fd;
708701
}
709702

710-
int hyper_insmod(char *module)
703+
int hyper_open_channel(char *channel, int mode, bool is_serial)
711704
{
712-
return 0;
705+
if (is_serial)
706+
return hyper_open_serial(channel, mode);
707+
708+
return hyper_open_virtio_port(channel, mode);
713709
}
714-
#endif
715710

716711
int hyper_setfd_cloexec(int fd)
717712
{

src/util.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ struct env;
2121
#define dbg_pr(fd, fmt, ...) do { } while (0)
2222
#endif
2323

24-
char *read_cmdline(void);
2524
int hyper_setup_env(struct env *envs, int num, bool setPATH);
2625
int hyper_find_sd(char *addr, char **dev);
2726
int hyper_list_dir(char *path);
@@ -35,7 +34,7 @@ void hyper_filize(char *hyper_path);
3534
int hyper_mkdir(char *path, mode_t mode);
3635
int hyper_mkdir_at(const char *root, char *path, int size);
3736
int hyper_write_file(const char *path, const char *value, size_t len);
38-
int hyper_open_channel(char *channel, int mode);
37+
int hyper_open_channel(char *channel, int mode, bool is_serail);
3938
int hyper_setfd_cloexec(int fd);
4039
int hyper_setfd_block(int fd);
4140
int hyper_setfd_nonblock(int fd);

0 commit comments

Comments
 (0)