WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

Re: [Xen-devel] [PATCH 1 of 6] xl: network-attach command

To: Eric Chanudet <eric.chanudet@xxxxxxxxxx>
Subject: Re: [Xen-devel] [PATCH 1 of 6] xl: network-attach command
From: Yang Hongyang <yanghy@xxxxxxxxxxxxxx>
Date: Thu, 13 May 2010 08:45:28 +0800
Cc: xen-devel@xxxxxxxxxxxxxxxxxxx
Delivery-date: Wed, 12 May 2010 17:46:19 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <da5000ae5fe9d10f901a.1273685529@xxxxxxxxxxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <patchbomb.1273685528@xxxxxxxxxxxxxxxxxxxxx> <da5000ae5fe9d10f901a.1273685529@xxxxxxxxxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100415 Thunderbird/3.0.4
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@xxxxxxxxxxxxxxxxxxx
> http://lists.xensource.com/xen-devel
> 
> 


-- 
Regards
Yang Hongyang

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel