# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1273736817 -3600
# Node ID faf4c485827fd07fdeb500b918a254cce8c73e6d
# Parent fa94385978e6317732e2c12000923ca6a5e0d2ed
xl: Implement network-attach
Signed-off-by: Eric Chanudet <eric.chanudet@xxxxxxxxxx>
---
tools/libxl/libxl.c | 15 ++++++++
tools/libxl/xl_cmdimpl.c | 85 +++++++++++++++++++++++++++++++++++++++++++++-
tools/libxl/xl_cmdimpl.h | 1
tools/libxl/xl_cmdtable.c | 7 +++
4 files changed, 107 insertions(+), 1 deletion(-)
diff -r fa94385978e6 -r faf4c485827f tools/libxl/libxl.c
--- a/tools/libxl/libxl.c Wed May 12 09:09:40 2010 +0100
+++ b/tools/libxl/libxl.c Thu May 13 08:46:57 2010 +0100
@@ -1420,6 +1420,8 @@ int libxl_device_nic_add(struct libxl_ct
unsigned int boffset = 0;
unsigned int foffset = 0;
libxl_device device;
+ char *dompath, **l;
+ unsigned int nb;
front = flexarray_make(16, 1);
if (!front)
@@ -1427,6 +1429,19 @@ int libxl_device_nic_add(struct libxl_ct
back = flexarray_make(16, 1);
if (!back)
return ERROR_NOMEM;
+
+ if (nic->devid == -1) {
+ if (!(dompath = libxl_xs_get_dompath(ctx, domid))) {
+ return ERROR_FAIL;
+ }
+ if (!(l = libxl_xs_directory(ctx, XBT_NULL,
+ libxl_sprintf(ctx, "%s/device/vif",
dompath), &nb))) {
+ nic->devid = 0;
+ } else {
+ nic->devid = strtoul(l[nb - 1], NULL, 10) + 1;
+ libxl_free(ctx, l);
+ }
+ }
device.backend_devid = nic->devid;
device.backend_domid = nic->backend_domid;
diff -r fa94385978e6 -r faf4c485827f tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c Wed May 12 09:09:40 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.c Thu May 13 08:46:57 2010 +0100
@@ -573,7 +573,7 @@ static void parse_config_data(const char
char *buf2 = strdup(buf);
char *p, *p2;
*vifs = (libxl_device_nic *) realloc(*vifs, sizeof
(libxl_device_nic) * ((*num_vifs) + 1));
- init_nic_info((*vifs) + (*num_vifs), (*num_vifs));
+ init_nic_info((*vifs) + (*num_vifs), (*num_vifs) + 1);
p = strtok(buf2, ",");
if (!p)
goto skip;
@@ -3171,3 +3171,86 @@ int main_top(int argc, char **argv)
exit(0);
}
+
+int main_networkattach(int argc, char **argv)
+{
+ int opt;
+ libxl_device_nic nic;
+ char *endptr, *tok;
+ int i;
+ unsigned int val;
+
+ if ((argc < 2) || (argc > 11)) {
+ help("network-attach");
+ exit(0);
+ }
+ while ((opt = getopt(argc, argv, "hl")) != -1) {
+ switch (opt) {
+ case 'h':
+ help("network-attach");
+ exit(0);
+ default:
+ fprintf(stderr, "option `%c' not supported.\n", opt);
+ break;
+ }
+ }
+
+ if (domain_qualifier_to_domid(argv[1], &domid, 0) < 0) {
+ fprintf(stderr, "%s is an invalid domain identifier\n", argv[1]);
+ exit(1);
+ }
+ init_nic_info(&nic, -1);
+ for (argv += 2, argc -= 2; argc > 0; ++argv, --argc) {
+ if (!strncmp("type=", *argv, 5)) {
+ if (!strncmp("vif", (*argv) + 5, 4)) {
+ nic.nictype = NICTYPE_VIF;
+ } else if (!strncmp("ioemu", (*argv) + 5, 5)) {
+ nic.nictype = NICTYPE_IOEMU;
+ } else {
+ fprintf(stderr, "Invalid parameter `type'.\n");
+ exit(1);
+ }
+ } else if (!strncmp("mac=", *argv, 4)) {
+ tok = strtok((*argv) + 4, ":");
+ for (i = 0; tok && i < 6; tok = strtok(NULL, ":"), ++i) {
+ val = strtoul(tok, &endptr, 16);
+ if ((tok == endptr) || (val > 255)) {
+ fprintf(stderr, "Invalid parameter `mac'.\n");
+ exit(1);
+ }
+ nic.mac[i] = val;
+ }
+ } else if (!strncmp("bridge=", *argv, 7)) {
+ nic.bridge = (*argv) + 7;
+ } else if (!strncmp("ip=", *argv, 3)) {
+ if (!inet_aton((*argv) + 3, &(nic.ip))) {
+ fprintf(stderr, "Invalid parameter `ip'.\n");
+ exit(1);
+ }
+ } else if (!strncmp("script=", *argv, 6)) {
+ nic.script = (*argv) + 6;
+ } else if (!strncmp("backend=", *argv, 8)) {
+ val = strtoul((*argv) + 8, &endptr, 10);
+ if (((*argv) + 8) == endptr) {
+ fprintf(stderr, "Invalid parameter `backend'.\n");
+ exit(1);
+ }
+ nic.backend_domid = val;
+ } else if (!strncmp("vifname=", *argv, 8)) {
+ nic.ifname = (*argv) + 8;
+ } else if (!strncmp("model=", *argv, 6)) {
+ nic.model = (*argv) + 6;
+ } else if (!strncmp("rate=", *argv, 5)) {
+ } else if (!strncmp("accel=", *argv, 6)) {
+ } else {
+ fprintf(stderr, "unrecognized argument `%s'\n", *argv);
+ exit(1);
+ }
+ }
+ nic.domid = domid;
+ if (libxl_device_nic_add(&ctx, domid, &nic)) {
+ fprintf(stderr, "libxl_device_nic_add failed.\n");
+ exit(1);
+ }
+ exit(0);
+}
diff -r fa94385978e6 -r faf4c485827f tools/libxl/xl_cmdimpl.h
--- a/tools/libxl/xl_cmdimpl.h Wed May 12 09:09:40 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.h Thu May 13 08:46:57 2010 +0100
@@ -42,5 +42,6 @@ int main_trigger(int argc, char **argv);
int main_trigger(int argc, char **argv);
int main_sysrq(int argc, char **argv);
int main_top(int argc, char **argv);
+int main_networkattach(int argc, char **argv);
void help(char *command);
diff -r fa94385978e6 -r faf4c485827f tools/libxl/xl_cmdtable.c
--- a/tools/libxl/xl_cmdtable.c Wed May 12 09:09:40 2010 +0100
+++ b/tools/libxl/xl_cmdtable.c Thu May 13 08:46:57 2010 +0100
@@ -187,6 +187,13 @@ struct cmd_spec cmd_table[] = {
"Monitor a host and the domains in real time",
"",
},
+ { "network-attach",
+ &main_networkattach,
+ "Create a new virtual network device",
+ "<Domain> [type=<type>] [mac=<mac>] [bridge=<bridge>] "
+ "[ip=<ip>] [script=<script>] [backend=<BackDomain>] [vifname=<name>] "
+ "[rate=<rate>] [model=<model>][accel=<accel>]",
+ },
};
int cmdtable_len = sizeof(cmd_table)/sizeof(struct cmd_spec);
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|