From: Yang Hongyang <yanghy@cn.fujitsu.com>
To: Eric Chanudet <eric.chanudet@citrix.com>
Cc: xen-devel@lists.xensource.com
Subject: Re: [PATCH 1 of 6] xl: network-attach command
Date: Thu, 13 May 2010 08:45:28 +0800 [thread overview]
Message-ID: <4BEB4BA8.6050909@cn.fujitsu.com> (raw)
In-Reply-To: <da5000ae5fe9d10f901a.1273685529@eric.cam.xci-test.com>
Hi Eric,
On 05/13/2010 01:32 AM, Eric Chanudet wrote:
> This patch adds network-attach command to xl.
>
> Usage: xl network-attach <Domain> [type=<type>] [mac=<mac>] [bridge=<bridge>]
> [ip=<ip>] [script=<script>] [backend=<BackDomain>] [vifname=<name>]
> [rate=<rate>] [model=<model>][accel=<accel>]
>
> rate and accel parameters are not handled for now.
>
> diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
> --- a/tools/libxl/libxl.c
> +++ b/tools/libxl/libxl.c
> @@ -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)
> @@ -1428,6 +1430,19 @@ int libxl_device_nic_add(struct libxl_ct
> 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;
> device.backend_kind = DEVICE_VIF;
> diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
> --- a/tools/libxl/xl_cmdimpl.c
> +++ b/tools/libxl/xl_cmdimpl.c
> @@ -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;
> @@ -3058,3 +3058,86 @@ int main_trigger(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 --git a/tools/libxl/xl_cmdimpl.h b/tools/libxl/xl_cmdimpl.h
> --- a/tools/libxl/xl_cmdimpl.h
> +++ b/tools/libxl/xl_cmdimpl.h
> @@ -39,5 +39,6 @@ int main_domid(int argc, char **argv);
> int main_domname(int argc, char **argv);
> int main_rename(int argc, char **argv);
> int main_trigger(int argc, char **argv);
> +int main_networkattach(int argc, char **argv);
>
> void help(char *command);
> diff --git a/tools/libxl/xl_cmdtable.c b/tools/libxl/xl_cmdtable.c
> --- a/tools/libxl/xl_cmdtable.c
> +++ b/tools/libxl/xl_cmdtable.c
> @@ -172,6 +172,10 @@ struct cmd_spec cmd_table[] = {
> "Send a trigger to a domain",
> "<Domain> <nmi|reset|init|power|sleep> [<VCPU>]",
> },
> + { "network-attach",
> + &main_networkattach,
> + "Create a new virtual network device"
You forgot to add usage and options here:)
> + },
> };
>
> int cmdtable_len = sizeof(cmd_table)/sizeof(struct cmd_spec);
>
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xensource.com
> http://lists.xensource.com/xen-devel
>
>
--
Regards
Yang Hongyang
next prev parent reply other threads:[~2010-05-13 0:45 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-12 17:32 [PATCH 0 of 6] xl: network and block features Eric Chanudet
2010-05-12 17:32 ` [PATCH 1 of 6] xl: network-attach command Eric Chanudet
2010-05-13 0:45 ` Yang Hongyang [this message]
2010-05-13 13:24 ` Eric Chanudet (Intern)
2010-05-14 0:40 ` Yang Hongyang
2010-05-12 17:32 ` [PATCH 2 of 6] xl: network-list command Eric Chanudet
2010-05-12 17:32 ` [PATCH 3 of 6] xl: network-detach command Eric Chanudet
2010-05-12 17:32 ` [PATCH 4 of 6] xl: block-attach command Eric Chanudet
2010-05-12 17:32 ` [PATCH 5 of 6] xl: block-list command Eric Chanudet
2010-05-12 17:32 ` [PATCH 6 of 6] xl: block-detach command Eric Chanudet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4BEB4BA8.6050909@cn.fujitsu.com \
--to=yanghy@cn.fujitsu.com \
--cc=eric.chanudet@citrix.com \
--cc=xen-devel@lists.xensource.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.