summaryrefslogtreecommitdiff
path: root/usr.sbin/ldomctl
diff options
context:
space:
mode:
authorMark Kettenis <kettenis@cvs.openbsd.org>2012-11-04 23:30:39 +0000
committerMark Kettenis <kettenis@cvs.openbsd.org>2012-11-04 23:30:39 +0000
commitd827be73e2505b9ee7c11f25456b19acba978385 (patch)
tree7e1c749ec8ec31bd601c53e5dbe88e403caa3c62 /usr.sbin/ldomctl
parenta68d5602e99d4903429a6884e88a76d12860c55c (diff)
A bit more SP configuration code.
Diffstat (limited to 'usr.sbin/ldomctl')
-rw-r--r--usr.sbin/ldomctl/ldomctl.c40
-rw-r--r--usr.sbin/ldomctl/mdstore.c183
-rw-r--r--usr.sbin/ldomctl/mdstore.h4
3 files changed, 217 insertions, 10 deletions
diff --git a/usr.sbin/ldomctl/ldomctl.c b/usr.sbin/ldomctl/ldomctl.c
index a4c7b23f1c8..ca52335ae86 100644
--- a/usr.sbin/ldomctl/ldomctl.c
+++ b/usr.sbin/ldomctl/ldomctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ldomctl.c,v 1.13 2012/11/04 21:44:20 kettenis Exp $ */
+/* $OpenBSD: ldomctl.c,v 1.14 2012/11/04 23:30:38 kettenis Exp $ */
/*
* Copyright (c) 2012 Mark Kettenis
@@ -57,17 +57,21 @@ uint64_t find_guest(const char *);
void fetch_pri(void);
+void download(int argc, char **argv);
void dump(int argc, char **argv);
void list(int argc, char **argv);
void xselect(int argc, char **argv);
+void delete(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[] = {
+ { "download", download },
{ "dump", dump },
{ "list", list },
{ "select", xselect },
+ { "delete", delete },
{ "start", guest_start },
{ "stop", guest_stop },
{ "status", guest_status },
@@ -302,6 +306,40 @@ xselect(int argc, char **argv)
}
void
+delete(int argc, char **argv)
+{
+ struct ds_conn *dc;
+
+ if (argc < 2)
+ usage();
+
+ dc = ds_conn_open("/dev/spds", NULL);
+ ds_conn_register_service(dc, &mdstore_service);
+ while (TAILQ_EMPTY(&mdstore_sets))
+ ds_conn_handle(dc);
+
+ mdstore_delete(dc, argv[1]);
+}
+
+void
+download(int argc, char **argv)
+{
+ struct ds_conn *dc;
+
+ debug = 1;
+
+ if (argc < 2)
+ usage();
+
+ dc = ds_conn_open("/dev/spds", NULL);
+ ds_conn_register_service(dc, &mdstore_service);
+ while (TAILQ_EMPTY(&mdstore_sets))
+ ds_conn_handle(dc);
+
+ mdstore_download(dc, argv[1]);
+}
+
+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
index 877665b7e40..14f2d426ac0 100644
--- a/usr.sbin/ldomctl/mdstore.c
+++ b/usr.sbin/ldomctl/mdstore.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mdstore.c,v 1.2 2012/11/04 21:44:20 kettenis Exp $ */
+/* $OpenBSD: mdstore.c,v 1.3 2012/11/04 23:30:38 kettenis Exp $ */
/*
* Copyright (c) 2012 Mark Kettenis
@@ -17,6 +17,7 @@
*/
#include <assert.h>
+#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -32,6 +33,9 @@ struct ds_service mdstore_service = {
"mdstore", 1, 0, mdstore_start, mdstore_rx_data
};
+#define MDSET_BEGIN_REQUEST 0x0001
+#define MDSET_END_REQUEST 0x0002
+#define MD_TRANSFER_REQUEST 0x0003
#define MDSET_LIST_REQUEST 0x0004
#define MDSET_SELECT_REQUEST 0x0005
#define MDSET_DELETE_REQUEST 0x0006
@@ -45,6 +49,34 @@ struct mdstore_msg {
uint16_t command;
} __packed;
+struct mdstore_begin_end_req {
+ uint32_t msg_type;
+ uint32_t payload_len;
+ uint64_t svc_handle;
+ uint64_t reqnum;
+ uint16_t command;
+ uint16_t nmds;
+ uint32_t namelen;
+ char name[1];
+} __packed;
+
+struct mdstore_transfer_req {
+ uint32_t msg_type;
+ uint32_t payload_len;
+ uint64_t svc_handle;
+ uint64_t reqnum;
+ uint16_t command;
+ uint16_t type;
+ uint32_t size;
+ uint64_t offset;
+ char md[];
+} __packed;
+
+#define MDSTORE_PRI_TYPE 0x01
+#define MDSTORE_HV_MD_TYPE 0x02
+#define MDSTORE_CTL_DOM_MD_TYPE 0x04
+#define MDSTORE_SVC_DOM_MD_TYPE 0x08
+
struct mdstore_sel_del_req {
uint32_t msg_type;
uint32_t payload_len;
@@ -124,10 +156,94 @@ mdstore_rx_data(struct ldc_conn *lc, uint64_t svc_handle, void *data,
len += strlen(&mr->sets[len]) + 1;
}
break;
- case MDSET_SELECT_REQUEST:
- mdstore_command = 0;
- break;
}
+
+ mdstore_command = 0;
+}
+
+void
+mdstore_begin(struct ds_conn *dc, uint64_t svc_handle, const char *name)
+{
+ struct mdstore_begin_end_req *mr;
+ size_t len = sizeof(*mr) + strlen(name);
+
+ mr = xzalloc(len);
+ mr->msg_type = DS_DATA;
+ mr->payload_len = len - 8;
+ mr->svc_handle = svc_handle;
+ mr->reqnum = mdstore_reqnum++;
+ mr->command = mdstore_command = MDSET_BEGIN_REQUEST;
+ mr->nmds = 3; /* XXX */
+ mr->namelen = strlen(name);
+ memcpy(mr->name, name, strlen(name));
+
+ ds_send_msg(&dc->lc, mr, len);
+ free(mr);
+
+ while (mdstore_command == MDSET_BEGIN_REQUEST)
+ ds_conn_handle(dc);
+}
+
+void
+mdstore_transfer(struct ds_conn *dc, uint64_t svc_handle, const char *path,
+ uint16_t type, uint64_t offset)
+{
+ struct mdstore_transfer_req *mr;
+ uint32_t size;
+ size_t len;
+ FILE *fp;
+
+ fp = fopen(path, "r");
+ if (fp == NULL)
+ err(1, "fopen");
+
+ fseek(fp, 0, SEEK_END);
+ size = ftell(fp);
+ fseek(fp, 0, SEEK_SET);
+
+ len = sizeof(*mr) + size;
+ mr = xzalloc(len);
+
+ mr->msg_type = DS_DATA;
+ mr->payload_len = len - 8;
+ mr->svc_handle = svc_handle;
+ mr->reqnum = mdstore_reqnum++;
+ mr->command = mdstore_command = MD_TRANSFER_REQUEST;
+ mr->type = type;
+ mr->size = size;
+ mr->offset = offset;
+ if (fread(&mr->md, size, 1, fp) != 1)
+ err(1, "fread");
+ ds_send_msg(&dc->lc, mr, len);
+ free(mr);
+
+ fclose(fp);
+
+ while (mdstore_command == MD_TRANSFER_REQUEST)
+ ds_conn_handle(dc);
+}
+
+void
+mdstore_end(struct ds_conn *dc, uint64_t svc_handle, const char *name)
+{
+ struct mdstore_begin_end_req *mr;
+ size_t len = sizeof(*mr) + strlen(name);
+
+ mr = xzalloc(len);
+ mr->msg_type = DS_DATA;
+ mr->payload_len = len - 8;
+ mr->svc_handle = svc_handle;
+ mr->reqnum = mdstore_reqnum++;
+ mr->command = mdstore_command = MDSET_END_REQUEST;
+ mr->nmds = 3;
+ mr->namelen = strlen(name);
+ memcpy(mr->name, name, strlen(name));
+
+ ds_send_msg(&dc->lc, mr, len);
+ free(mr);
+
+ while (mdstore_command == MDSET_END_REQUEST)
+ ds_conn_handle(dc);
}
void
@@ -135,17 +251,14 @@ mdstore_select(struct ds_conn *dc, const char *name)
{
struct ds_conn_svc *dcs;
struct mdstore_sel_del_req *mr;
- struct mdstore_set *set;
- size_t len;
+ size_t len = sizeof(*mr) + strlen(name);
TAILQ_FOREACH(dcs, &dc->services, link)
if (strcmp(dcs->service->ds_svc_id, "mdstore") == 0)
break;
assert(dcs != TAILQ_END(&dc->services));
- len = sizeof(*set) + strlen(name);
mr = xzalloc(len);
-
mr->msg_type = DS_DATA;
mr->payload_len = len - 8;
mr->svc_handle = dcs->svc_handle;
@@ -160,3 +273,57 @@ mdstore_select(struct ds_conn *dc, const char *name)
while (mdstore_command == MDSET_SELECT_REQUEST)
ds_conn_handle(dc);
}
+
+void
+mdstore_delete(struct ds_conn *dc, const char *name)
+{
+ struct ds_conn_svc *dcs;
+ struct mdstore_sel_del_req *mr;
+ size_t len = sizeof(*mr) + strlen(name);
+
+ TAILQ_FOREACH(dcs, &dc->services, link)
+ if (strcmp(dcs->service->ds_svc_id, "mdstore") == 0)
+ break;
+ assert(dcs != TAILQ_END(&dc->services));
+
+ mr = xzalloc(len);
+ mr->msg_type = DS_DATA;
+ mr->payload_len = len - 8;
+ mr->svc_handle = dcs->svc_handle;
+ mr->reqnum = mdstore_reqnum++;
+ mr->command = mdstore_command = MDSET_DELETE_REQUEST;
+ mr->namelen = strlen(name);
+ memcpy(mr->name, name, strlen(name));
+
+ ds_send_msg(&dc->lc, mr, len);
+ free(mr);
+
+ while (mdstore_command == MDSET_DELETE_REQUEST)
+ ds_conn_handle(dc);
+}
+
+void
+mdstore_download(struct ds_conn *dc, const char *name)
+{
+ struct ds_conn_svc *dcs;
+
+ TAILQ_FOREACH(dcs, &dc->services, link)
+ if (strcmp(dcs->service->ds_svc_id, "mdstore") == 0)
+ break;
+ assert(dcs != TAILQ_END(&dc->services));
+
+ printf("begin\n");
+ mdstore_begin(dc, dcs->svc_handle, name);
+ printf("transfer 0\n");
+ mdstore_transfer(dc, dcs->svc_handle, "primary.md",
+ MDSTORE_CTL_DOM_MD_TYPE, 0x100000);
+ printf("transfer 1\n");
+ mdstore_transfer(dc, dcs->svc_handle, "hv.md",
+ MDSTORE_HV_MD_TYPE, 0x80000);
+ printf("transfer 2\n");
+ mdstore_transfer(dc, dcs->svc_handle, "pri",
+ MDSTORE_PRI_TYPE, 0);
+ printf("end\n");
+ mdstore_end(dc, dcs->svc_handle, name);
+ printf("done\n");
+}
diff --git a/usr.sbin/ldomctl/mdstore.h b/usr.sbin/ldomctl/mdstore.h
index 8edccd62624..db8916dff1a 100644
--- a/usr.sbin/ldomctl/mdstore.h
+++ b/usr.sbin/ldomctl/mdstore.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: mdstore.h,v 1.2 2012/11/04 21:44:20 kettenis Exp $ */
+/* $OpenBSD: mdstore.h,v 1.3 2012/11/04 23:30:38 kettenis Exp $ */
/*
* Copyright (c) 2012 Mark Kettenis
@@ -31,4 +31,6 @@ struct mdstore_set {
extern TAILQ_HEAD(mdstore_set_head, mdstore_set) mdstore_sets;
+void mdstore_download(struct ds_conn *, const char *);
void mdstore_select(struct ds_conn *, const char *);
+void mdstore_delete(struct ds_conn *, const char *);