0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-12-22 09:41:54 +00:00

Flock: containers are actually created

This commit is contained in:
Maria Matejka 2024-09-24 13:09:41 +02:00
parent 60a2c4e921
commit ac66a8dc00

View File

@ -30,6 +30,11 @@ struct container_runtime {
uint hash; uint hash;
pid_t pid; pid_t pid;
sock *s; sock *s;
struct container_created_callback {
callback cb;
sock *s;
void *data;
} *ccc;
char data[]; char data[];
}; };
@ -44,10 +49,12 @@ static void
container_mainloop(int fd) container_mainloop(int fd)
{ {
log(L_INFO "container mainloop with fd %d", fd); log(L_INFO "container mainloop with fd %d", fd);
/* TODO unshare, fork and send info */
/* TODO: mount overlayfs and chroot */
while (1) while (1)
{ {
pause(); pause();
/* TODO: check for telnet socket */
log(L_INFO "woken up!"); log(L_INFO "woken up!");
} }
} }
@ -198,7 +205,6 @@ hypervisor_container_forker_rx(sock *sk, uint _sz UNUSED)
log(L_INFO "Machine started with PID %d", pid); log(L_INFO "Machine started with PID %d", pid);
sock *skl = sk_new(sk->pool); sock *skl = sk_new(sk->pool);
log(L_INFO "skl is %p", skl);
skl->type = SK_MAGIC; skl->type = SK_MAGIC;
skl->rx_hook = hypervisor_container_rx; skl->rx_hook = hypervisor_container_rx;
skl->fd = sfd; skl->fd = sfd;
@ -208,23 +214,12 @@ hypervisor_container_forker_rx(sock *sk, uint _sz UNUSED)
ASSERT_DIE(birdloop_inside(hcf.loop)); ASSERT_DIE(birdloop_inside(hcf.loop));
ASSERT_DIE(hcf.cur_crt); ASSERT_DIE(hcf.cur_crt);
sock *sr = hcf.cur_crt->s;
log(L_INFO "sr is %p", sr);
hcf.cur_crt->pid = pid; hcf.cur_crt->pid = pid;
hcf.cur_crt->s = skl; hcf.cur_crt->s = skl;
if (hcf.cur_crt->ccc)
linpool *lp = lp_new(hcf.p); callback_activate(&hcf.cur_crt->ccc->cb);
struct cbor_writer *cw = cbor_init(sr->tbuf, sr->tbsize, lp); hcf.cur_crt->ccc = NULL;
cbor_open_block_with_length(cw, 1);
cbor_add_int(cw, -1);
cbor_add_string(cw, "OK");
sk_send(sr, cw->pt);
rfree(lp);
hcf.cur_crt = NULL; hcf.cur_crt = NULL;
return 0; return 0;
} }
@ -236,6 +231,36 @@ hypervisor_container_forker_err(sock *sk, int e UNUSED)
/* The child */ /* The child */
static void
crt_err(sock *s, int err UNUSED)
{
struct container_runtime *crt = s->data;
s->data = crt->ccc->data;
callback_cancel(&crt->ccc->cb);
mb_free(crt->ccc);
crt->ccc = NULL;
}
static void
container_created(callback *cb)
{
SKIP_BACK_DECLARE(struct container_created_callback, ccc, cb, cb);
sock *s = ccc->s;
linpool *lp = lp_new(s->pool);
struct cbor_writer *cw = cbor_init(s->tbuf, s->tbsize, lp);
cbor_open_block_with_length(cw, 1);
cbor_add_int(cw, -1);
cbor_add_string(cw, "OK");
sk_send(s, cw->pt);
rfree(lp);
s->data = ccc->data;
sk_resume_rx(s->loop, s);
mb_free(ccc);
}
void void
hypervisor_container_request(sock *s, const char *name, const char *basedir, const char *workdir) hypervisor_container_request(sock *s, const char *name, const char *basedir, const char *workdir)
{ {
@ -254,6 +279,7 @@ hypervisor_container_request(sock *s, const char *name, const char *basedir, con
sk_send(s, cw->pt); sk_send(s, cw->pt);
birdloop_leave(hcf.loop); birdloop_leave(hcf.loop);
return;
} }
uint nlen = strlen(name), uint nlen = strlen(name),
@ -277,7 +303,14 @@ hypervisor_container_request(sock *s, const char *name, const char *basedir, con
pos += blen + 1; pos += blen + 1;
crt->hash = h; crt->hash = h;
crt->s = s;
struct container_created_callback *ccc = mb_alloc(s->pool, sizeof *ccc);
*ccc = (struct container_created_callback) {
.s = s,
.data = s->data,
};
callback_init(&ccc->cb, container_created, s->loop);
crt->ccc = ccc;
HASH_INSERT(hcf.hash, CRT, crt); HASH_INSERT(hcf.hash, CRT, crt);
@ -298,6 +331,10 @@ hypervisor_container_request(sock *s, const char *name, const char *basedir, con
sk_send(hcf.s, cw->pt); sk_send(hcf.s, cw->pt);
rfree(lp); rfree(lp);
s->err_paused = crt_err;
s->data = crt;
sk_pause_rx(s->loop, s);
birdloop_leave(hcf.loop); birdloop_leave(hcf.loop);
} }