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

Commit 2b1edec

Browse files
committed
introduce hyper_send_msg_block
the control serial port is opened as unblock fd, set is as block fd to make sure sending successfully. Signed-off-by: Gao feng <omarapazanadi@gmail.com>
1 parent f49d124 commit 2b1edec

File tree

5 files changed

+10
-52
lines changed

5 files changed

+10
-52
lines changed

src/exec.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -551,8 +551,7 @@ int hyper_release_exec(struct hyper_exec *exec,
551551

552552
if (pod->type == STOPPOD) {
553553
/* stop pod manually */
554-
hyper_send_type(ctl.chan.fd, ACK);
555-
554+
hyper_send_msg_block(ctl.chan.fd, ACK, 0, NULL);
556555
} else {
557556
/* send out pod finish message, hyper will decide if restart pod or not */
558557
hyper_send_pod_finished(pod);

src/init.c

Lines changed: 3 additions & 3 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
}
@@ -1183,9 +1183,9 @@ static int hyper_channel_handle(struct hyper_event *de, uint32_t len)
11831183
}
11841184

11851185
if (ret < 0)
1186-
hyper_send_type(de->fd, ERROR);
1186+
hyper_send_msg_block(de->fd, ERROR, 0, NULL);
11871187
else
1188-
hyper_send_msg(de->fd, ACK, datalen, data);
1188+
hyper_send_msg_block(de->fd, ACK, datalen, data);
11891189

11901190
free(data);
11911191
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ int hyper_send_pod_finished(struct hyper_pod *pod)
401401
data = new;
402402
}
403403

404-
ret = hyper_send_msg(ctl.chan.fd, PODFINISHED, c_num * 4, data);
404+
ret = hyper_send_msg_block(ctl.chan.fd, PODFINISHED, c_num * 4, data);
405405
out:
406406
free(data);
407407
return ret;

0 commit comments

Comments
 (0)