diff options
author | Mark Kettenis <kettenis@cvs.openbsd.org> | 2012-10-27 20:53:16 +0000 |
---|---|---|
committer | Mark Kettenis <kettenis@cvs.openbsd.org> | 2012-10-27 20:53:16 +0000 |
commit | d09d187d51d0197e2b98225668516006f7ab4597 (patch) | |
tree | 0fb2c248fc762b58aab58b26780b06d3b290ae59 | |
parent | 00f4465064be6530f7c9b3fa3cf7c6767ee5c1dc (diff) |
Close hvctl channel after initial setup and reopen it whenever we need to
reconfigure. Makes it possible to use ldomctl(8) when ldomd(8) is running.
-rw-r--r-- | usr.sbin/ldomd/ldomd.c | 102 |
1 files changed, 63 insertions, 39 deletions
diff --git a/usr.sbin/ldomd/ldomd.c b/usr.sbin/ldomd/ldomd.c index 3ae8d1bf1fb..47d8f8b7637 100644 --- a/usr.sbin/ldomd/ldomd.c +++ b/usr.sbin/ldomd/ldomd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ldomd.c,v 1.3 2012/10/27 20:03:24 kettenis Exp $ */ +/* $OpenBSD: ldomd.c,v 1.4 2012/10/27 20:53:15 kettenis Exp $ */ /* * Copyright (c) 2012 Mark Kettenis @@ -156,6 +156,8 @@ void delete_frag(uint64_t); uint64_t alloc_frag(void); void hv_update_md(struct guest *guest); +void hv_open(void); +void hv_close(void); void hv_read(uint64_t, void *, size_t); void hv_write(uint64_t, void *, size_t); @@ -229,7 +231,6 @@ main(int argc, char **argv) { struct hvctl_msg msg; ssize_t nbytes; - uint64_t code; struct md_header hdr; struct md_node *node; struct md_prop *prop; @@ -261,43 +262,7 @@ main(int argc, char **argv) log_init(debug); - hvctl_fd = open("/dev/hvctl", O_RDWR, 0); - if (hvctl_fd == -1) - fatal("cannot open /dev/hvctl"); - - /* - * Say "Hello". - */ - bzero(&msg, sizeof(msg)); - msg.hdr.op = HVCTL_OP_HELLO; - msg.hdr.seq = hvctl_seq++; - msg.msg.hello.major = 1; - nbytes = write(hvctl_fd, &msg, sizeof(msg)); - if (nbytes != sizeof(msg)) - fatal("write"); - - bzero(&msg, sizeof(msg)); - nbytes = read(hvctl_fd, &msg, sizeof(msg)); - if (nbytes != sizeof(msg)) - fatal("read"); - - code = msg.msg.clnge.code ^ 0xbadbeef20; - - /* - * Respond to challenge. - */ - bzero(&msg, sizeof(msg)); - msg.hdr.op = HVCTL_OP_RESPONSE; - msg.hdr.seq = hvctl_seq++; - msg.msg.clnge.code = code ^ 0x12cafe42a; - nbytes = write(hvctl_fd, &msg, sizeof(msg)); - if (nbytes != sizeof(msg)) - fatal("write"); - - bzero(&msg, sizeof(msg)); - nbytes = read(hvctl_fd, &msg, sizeof(msg)); - if (nbytes != sizeof(msg)) - fatal("read"); + hv_open(); /* * Request config. @@ -344,6 +309,8 @@ main(int argc, char **argv) ds_conn_register_service(dc, &var_config_service); } + hv_close(); + ds_conn_serve(); exit(EXIT_SUCCESS); @@ -514,6 +481,8 @@ hv_update_md(struct guest *guest) size_t size; uint64_t mdpa; + hv_open(); + mdpa = alloc_frag(); size = md_exhume(guest->md, &buf); hv_write(mdpa, buf, size); @@ -545,11 +514,66 @@ hv_update_md(struct guest *guest) if (nbytes != sizeof(msg)) fatal("read"); + hv_close(); + if (msg.hdr.status != HVCTL_ST_OK) logit(LOG_CRIT, "reconfigure failed: %d", msg.hdr.status); } void +hv_open(void) +{ + struct hvctl_msg msg; + ssize_t nbytes; + uint64_t code; + + hvctl_fd = open("/dev/hvctl", O_RDWR, 0); + if (hvctl_fd == -1) + fatal("cannot open /dev/hvctl"); + + /* + * Say "Hello". + */ + bzero(&msg, sizeof(msg)); + msg.hdr.op = HVCTL_OP_HELLO; + msg.hdr.seq = hvctl_seq++; + msg.msg.hello.major = 1; + nbytes = write(hvctl_fd, &msg, sizeof(msg)); + if (nbytes != sizeof(msg)) + fatal("write"); + + bzero(&msg, sizeof(msg)); + nbytes = read(hvctl_fd, &msg, sizeof(msg)); + if (nbytes != sizeof(msg)) + fatal("read"); + + code = msg.msg.clnge.code ^ 0xbadbeef20; + + /* + * Respond to challenge. + */ + bzero(&msg, sizeof(msg)); + msg.hdr.op = HVCTL_OP_RESPONSE; + msg.hdr.seq = hvctl_seq++; + msg.msg.clnge.code = code ^ 0x12cafe42a; + nbytes = write(hvctl_fd, &msg, sizeof(msg)); + if (nbytes != sizeof(msg)) + fatal("write"); + + bzero(&msg, sizeof(msg)); + nbytes = read(hvctl_fd, &msg, sizeof(msg)); + if (nbytes != sizeof(msg)) + fatal("read"); +} + +void +hv_close(void) +{ + close(hvctl_fd); + hvctl_fd = -1; +} + +void hv_read(uint64_t addr, void *buf, size_t len) { struct hv_io hi; |