diff options
author | 2012-11-04 20:09:02 +0000 | |
---|---|---|
committer | 2012-11-04 20:09:02 +0000 | |
commit | cceaa36bc1babc4238243fc5ea2473ec6c63dd5d (patch) | |
tree | 642d219dcbe4cc92f000a10742ea56cfd9969dc1 | |
parent | Switch over to using the ds.[ch] from ldomd(8). (diff) | |
download | wireguard-openbsd-cceaa36bc1babc4238243fc5ea2473ec6c63dd5d.tar.xz wireguard-openbsd-cceaa36bc1babc4238243fc5ea2473ec6c63dd5d.zip |
Support for listing configurations store on the SP.
-rw-r--r-- | usr.sbin/ldomctl/Makefile | 4 | ||||
-rw-r--r-- | usr.sbin/ldomctl/ldomctl.c | 26 | ||||
-rw-r--r-- | usr.sbin/ldomctl/mdstore.c | 107 | ||||
-rw-r--r-- | usr.sbin/ldomctl/mdstore.h | 32 |
4 files changed, 166 insertions, 3 deletions
diff --git a/usr.sbin/ldomctl/Makefile b/usr.sbin/ldomctl/Makefile index d06e1433c42..f852f4a3b1b 100644 --- a/usr.sbin/ldomctl/Makefile +++ b/usr.sbin/ldomctl/Makefile @@ -1,11 +1,11 @@ -# $OpenBSD: Makefile,v 1.6 2012/11/04 18:59:02 kettenis Exp $ +# $OpenBSD: Makefile,v 1.7 2012/11/04 20:09:02 kettenis Exp $ .if ${MACHINE} == "sparc64" .PATH: ${.CURDIR}/../ldomd PROG= ldomctl -SRCS= ldomctl.c ds.c mdesc.c util.c pri.c +SRCS= ldomctl.c ds.c mdesc.c util.c mdstore.c pri.c CFLAGS+=-Wall CFLAGS+=-I${.CURDIR}/../ldomd -I${.CURDIR} DEBUG= -g diff --git a/usr.sbin/ldomctl/ldomctl.c b/usr.sbin/ldomctl/ldomctl.c index 9ea5340a315..73ab89a32b9 100644 --- a/usr.sbin/ldomctl/ldomctl.c +++ b/usr.sbin/ldomctl/ldomctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ldomctl.c,v 1.11 2012/11/04 18:59:02 kettenis Exp $ */ +/* $OpenBSD: ldomctl.c,v 1.12 2012/11/04 20:09:02 kettenis Exp $ */ /* * Copyright (c) 2012 Mark Kettenis @@ -27,6 +27,7 @@ #include "ds.h" #include "hvctl.h" +#include "mdstore.h" #include "mdesc.h" #include "util.h" @@ -57,12 +58,14 @@ uint64_t find_guest(const char *); void fetch_pri(void); void dump(int argc, char **argv); +void list(int argc, char **argv); void guest_start(int argc, char **argv); void guest_stop(int argc, char **argv); void guest_status(int argc, char **argv); struct command commands[] = { { "dump", dump }, + { "list", list }, { "start", guest_start }, { "stop", guest_stop }, { "status", guest_status }, @@ -260,6 +263,27 @@ dump(int argc, char **argv) } void +list(int argc, char **argv) +{ + struct ds_conn *dc; + struct mdstore_set *set; + + dc = ds_conn_open("/dev/spds", NULL); + ds_conn_register_service(dc, &mdstore_service); + while (TAILQ_EMPTY(&mdstore_sets)) + ds_conn_handle(dc); + + TAILQ_FOREACH(set, &mdstore_sets, link) { + printf("%s", set->name); + if (set->booted_set) + printf(" [current]"); + else if (set->boot_set) + printf(" [next]"); + printf("\n"); + } +} + +void guest_start(int argc, char **argv) { struct hvctl_msg msg; diff --git a/usr.sbin/ldomctl/mdstore.c b/usr.sbin/ldomctl/mdstore.c new file mode 100644 index 00000000000..fbc036e09a3 --- /dev/null +++ b/usr.sbin/ldomctl/mdstore.c @@ -0,0 +1,107 @@ +/* $OpenBSD: mdstore.c,v 1.1 2012/11/04 20:09:02 kettenis Exp $ */ + +/* + * Copyright (c) 2012 Mark Kettenis + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <stdio.h> +#include <string.h> + +#include "ds.h" +#include "mdstore.h" +#include "util.h" + +void mdstore_start(struct ldc_conn *, uint64_t); +void mdstore_rx_data(struct ldc_conn *, uint64_t, void *, size_t); + +struct ds_service mdstore_service = { + "mdstore", 1, 0, mdstore_start, mdstore_rx_data +}; + +#define MDSET_LIST_REQUEST 0x0004 + +struct mdstore_msg { + uint32_t msg_type; + uint32_t payload_len; + uint64_t svc_handle; + uint64_t reqnum; + uint16_t command; +} __packed; + +#define MDSET_LIST_REPLY 0x0104 + +struct mdstore_list_resp { + uint32_t msg_type; + uint32_t payload_len; + uint64_t svc_handle; + uint64_t reqnum; + uint32_t result; + uint16_t booted_set; + uint16_t boot_set; + char sets[1]; +} __packed; + +#define MDST_SUCCESS 0x0 +#define MDST_FAILURE 0x1 +#define MDST_INVALID_MSG 0x2 +#define MDST_MAX_MDS_ERR 0x3 +#define MDST_BAD_NAME_ERR 0x4 +#define MDST_SET_EXISTS_ERR 0x5 +#define MDST_ALLOC_SET_ERR 0x6 +#define MDST_ALLOC_MD_ERR 0x7 +#define MDST_MD_COUNT_ERR 0x8 +#define MDST_MD_SIZE_ERR 0x9 +#define MDST_MD_TYPE_ERR 0xa +#define MDST_NOT_EXIST_ERR 0xb + +struct mdstore_set_head mdstore_sets = TAILQ_HEAD_INITIALIZER(mdstore_sets); + +void +mdstore_start(struct ldc_conn *lc, uint64_t svc_handle) +{ + struct mdstore_msg mm; + + bzero(&mm, sizeof(mm)); + mm.msg_type = DS_DATA; + mm.payload_len = sizeof(mm) - 8; + mm.svc_handle = svc_handle; + mm.reqnum = 0; + mm.command = MDSET_LIST_REQUEST; + ds_send_msg(lc, &mm, sizeof(mm)); +} + +void +mdstore_rx_data(struct ldc_conn *lc, uint64_t svc_handle, void *data, + size_t len) +{ + struct mdstore_list_resp *mr = data; + struct mdstore_set *set; + int idx; + + if (mr->result != MDST_SUCCESS) { + DPRINTF(("Unexpected result 0x%x\n", mr->result)); + return; + } + + len = 0; + for (idx = 0; len < mr->payload_len - 24; idx++) { + set = xmalloc(sizeof(*set)); + set->name = xstrdup(&mr->sets[len]); + set->booted_set = (idx == mr->booted_set); + set->boot_set = (idx == mr->boot_set); + TAILQ_INSERT_TAIL(&mdstore_sets, set, link); + len += strlen(&mr->sets[len]) + 1; + } +} diff --git a/usr.sbin/ldomctl/mdstore.h b/usr.sbin/ldomctl/mdstore.h new file mode 100644 index 00000000000..665ef8f95f1 --- /dev/null +++ b/usr.sbin/ldomctl/mdstore.h @@ -0,0 +1,32 @@ +/* $OpenBSD: mdstore.h,v 1.1 2012/11/04 20:09:02 kettenis Exp $ */ + +/* + * Copyright (c) 2012 Mark Kettenis + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/queue.h> +#include <stdbool.h> + +extern struct ds_service mdstore_service; + +struct mdstore_set { + const char *name; + bool booted_set; + bool boot_set; + + TAILQ_ENTRY(mdstore_set) link; +}; + +extern TAILQ_HEAD(mdstore_set_head, mdstore_set) mdstore_sets; |