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

Commit bfa1af2

Browse files
committed
Merge pull request #33 from gao-feng/tty
some update
2 parents f49d124 + a866e25 commit bfa1af2

File tree

7 files changed

+55
-91
lines changed

7 files changed

+55
-91
lines changed

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Process this file with autoconf to produce a configure script.
33

44
AC_PREREQ([2.69])
5-
AC_INIT([hyperstart], [0.2], [www.hyper.sh])
5+
AC_INIT([hyperstart], [0.3], [www.hyper.sh])
66
AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects])
77
AM_EXTRA_RECURSIVE_TARGETS([initrd cbfs])
88
AC_CONFIG_SRCDIR([src/init.c])

src/exec.c

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,29 @@ int hyper_exec_cmd(char *json, int length)
524524
goto out;
525525
}
526526

527+
static int hyper_send_pod_finished(struct hyper_pod *pod)
528+
{
529+
int ret = -1;
530+
struct hyper_container *c;
531+
uint8_t *data = NULL, *new;
532+
int c_num = 0;
533+
534+
list_for_each_entry(c, &pod->containers, list) {
535+
c_num++;
536+
new = realloc(data, c_num * 4);
537+
if (new == NULL)
538+
goto out;
539+
540+
hyper_set_be32(new + ((c_num - 1) * 4), c->exec.code);
541+
data = new;
542+
}
543+
544+
ret = hyper_send_msg_block(ctl.chan.fd, PODFINISHED, c_num * 4, data);
545+
out:
546+
free(data);
547+
return ret;
548+
}
549+
527550
int hyper_release_exec(struct hyper_exec *exec,
528551
struct hyper_pod *pod)
529552
{
@@ -550,9 +573,11 @@ int hyper_release_exec(struct hyper_exec *exec,
550573
return 0;
551574

552575
if (pod->type == STOPPOD) {
553-
/* stop pod manually */
554-
hyper_send_type(ctl.chan.fd, ACK);
555-
576+
/* stop pod manually, hyper doesn't care the pod finished codes */
577+
hyper_send_msg_block(ctl.chan.fd, ACK, 0, NULL);
578+
} else if (pod->type == DESTROYPOD) {
579+
/* shutdown vm manually, hyper doesn't care the pod finished codes */
580+
hyper_shutdown();
556581
} else {
557582
/* send out pod finish message, hyper will decide if restart pod or not */
558583
hyper_send_pod_finished(pod);
@@ -563,7 +588,6 @@ int hyper_release_exec(struct hyper_exec *exec,
563588
}
564589

565590
hyper_free_exec(exec);
566-
567591
return 0;
568592
}
569593

src/init.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ static int hyper_setup_container(struct hyper_pod *pod)
516516
fprintf(stdout, "pod init pid %d\n", pod->init_pid);
517517

518518
/* Wait for container start */
519-
if (hyper_get_type_block(arg.ctl_pipe[0], &type) < 0) {
519+
if (hyper_get_type(arg.ctl_pipe[0], &type) < 0) {
520520
perror("get container init ready message failed");
521521
goto out;
522522
}
@@ -669,6 +669,18 @@ static void hyper_print_uptime(void)
669669
close(fd);
670670
}
671671

672+
static int hyper_destroy_pod(struct hyper_pod *pod)
673+
{
674+
if (pod->init_pid == 0) {
675+
/* Pod stopped, just shutdown */
676+
hyper_shutdown();
677+
} else {
678+
/* Kill pod */
679+
hyper_term_all(pod);
680+
}
681+
return 0;
682+
}
683+
672684
static int hyper_start_pod(char *json, int length)
673685
{
674686
struct hyper_pod *pod = &global_pod;
@@ -684,7 +696,7 @@ static int hyper_start_pod(char *json, int length)
684696
}
685697

686698
if (hyper_setup_pod(pod) < 0) {
687-
hyper_shutdown(pod);
699+
hyper_destroy_pod(pod);
688700
return -1;
689701
}
690702

@@ -1151,7 +1163,7 @@ static int hyper_channel_handle(struct hyper_event *de, uint32_t len)
11511163
//break;
11521164
case DESTROYPOD:
11531165
fprintf(stdout, "get DESTROYPOD message\n");
1154-
hyper_shutdown(pod);
1166+
hyper_destroy_pod(pod);
11551167
return 0;
11561168
case EXECCMD:
11571169
ret = hyper_exec_cmd((char *)buf->data + 8, len - 8);
@@ -1183,9 +1195,9 @@ static int hyper_channel_handle(struct hyper_event *de, uint32_t len)
11831195
}
11841196

11851197
if (ret < 0)
1186-
hyper_send_type(de->fd, ERROR);
1198+
hyper_send_msg_block(de->fd, ERROR, 0, NULL);
11871199
else
1188-
hyper_send_msg(de->fd, ACK, datalen, data);
1200+
hyper_send_msg_block(de->fd, ACK, datalen, data);
11891201

11901202
free(data);
11911203
return 0;

src/net.c

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -112,58 +112,18 @@ int hyper_get_type(int fd, uint32_t *type)
112112
return 0;
113113
}
114114

115-
int hyper_get_type_block(int fd, uint32_t *type)
115+
int hyper_send_msg_block(int fd, uint32_t type, uint32_t len, uint8_t *data)
116116
{
117-
int ret = 0, flags;
117+
int ret, flags;
118118

119119
flags = hyper_setfd_block(fd);
120120
if (flags < 0) {
121121
fprintf(stderr, "%s fail to set fd block\n", __func__);
122122
return -1;
123123
}
124124

125-
ret = hyper_get_type(fd, type);
126-
if (ret < 0) {
127-
fprintf(stderr, "%s can not get type\n", __func__);
128-
}
129-
130-
if (fcntl(fd, F_SETFL, flags) < 0) {
131-
perror("restore fd flag failed");
132-
return -1;
133-
}
134-
135-
return ret;
136-
}
137-
138-
int hyper_send_type_block(int fd, uint32_t type, int need_ack)
139-
{
140-
int ret = 0, flags;
141-
uint32_t t;
142-
143-
flags = hyper_setfd_block(fd);
144-
if (flags < 0) {
145-
fprintf(stderr, "%s fail to set fd block\n", __func__);
146-
return -1;
147-
}
148-
149-
ret = hyper_send_msg(fd, type, 0, NULL);
150-
if (ret < 0)
151-
goto out;
152-
153-
if (need_ack == 0)
154-
goto out;
125+
ret = hyper_send_msg(fd, type, len, data);
155126

156-
ret = hyper_get_type(fd, &t);
157-
if (ret < 0) {
158-
fprintf(stderr, "can not get type\n");
159-
goto out;
160-
}
161-
162-
fprintf(stdout, "get type %" PRIu32"\n", type);
163-
164-
if (t != ACK)
165-
ret = -1;
166-
out:
167127
if (fcntl(fd, F_SETFL, flags) < 0) {
168128
perror("restore fd flag failed");
169129
return -1;

src/net.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,9 @@ void hyper_cleanup_network(struct hyper_pod *pod);
5151
int hyper_setup_dns(struct hyper_pod *pod);
5252
void hyper_cleanup_dns(struct hyper_pod *pod);
5353
int hyper_get_type(int fd, uint32_t *type);
54-
int hyper_get_type_block(int fd, uint32_t *type);
5554
int hyper_send_type(int fd, uint32_t type);
5655
int hyper_send_type_block(int fd, uint32_t type, int need_ack);
57-
int hyper_send_msg(int fd, uint32_t type, uint32_t len,
58-
uint8_t *message);
56+
int hyper_send_msg(int fd, uint32_t type, uint32_t len, uint8_t *data);
57+
int hyper_send_msg_block(int fd, uint32_t type, uint32_t len, uint8_t *data);
5958
int hyper_send_data(int fd, uint8_t *data, uint32_t len);
6059
#endif

src/util.c

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ int hyper_socketpair(int domain, int type, int protocol, int sv[2])
339339
return 0;
340340
}
341341

342-
void hyper_unmount_all(void)
342+
static void hyper_unmount_all(void)
343343
{
344344
FILE *mtab;
345345
struct mntent *mnt;
@@ -384,38 +384,9 @@ void hyper_unmount_all(void)
384384
sync();
385385
}
386386

387-
int hyper_send_pod_finished(struct hyper_pod *pod)
387+
void hyper_shutdown()
388388
{
389-
int ret = -1;
390-
struct hyper_container *c;
391-
uint8_t *data = NULL, *new;
392-
int c_num = 0;
393-
394-
list_for_each_entry(c, &pod->containers, list) {
395-
c_num++;
396-
new = realloc(data, c_num * 4);
397-
if (new == NULL)
398-
goto out;
399-
400-
hyper_set_be32(new + ((c_num - 1) * 4), c->exec.code);
401-
data = new;
402-
}
403-
404-
ret = hyper_send_msg(ctl.chan.fd, PODFINISHED, c_num * 4, data);
405-
out:
406-
free(data);
407-
return ret;
408-
}
409-
410-
void hyper_shutdown(struct hyper_pod *pod)
411-
{
412-
hyper_send_pod_finished(pod);
413-
/* vm will shutdown immediately after we call reboot,
414-
* no chance to send out eof message in release exec.
415-
* send it out by ourself */
416-
hyper_cleanup_exec(pod);
417-
389+
hyper_send_msg_block(ctl.chan.fd, ACK, 0, NULL);
418390
hyper_unmount_all();
419-
420391
reboot(LINUX_REBOOT_CMD_POWER_OFF);
421392
}

src/util.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ int hyper_setfd_cloexec(int fd);
2424
int hyper_setfd_block(int fd);
2525
int hyper_setfd_nonblock(int fd);
2626
int hyper_socketpair(int domain, int type, int protocol, int sv[2]);
27-
void hyper_shutdown(struct hyper_pod *pod);
28-
int hyper_send_pod_finished(struct hyper_pod *pod);
29-
void hyper_unmount_all(void);
27+
void hyper_shutdown(void);
3028
int hyper_insmod(char *module);
3129
#endif

0 commit comments

Comments
 (0)