Hi Eric,
On 05/13/2010 09:24 PM, Eric Chanudet (Intern) wrote:
> On 05/13/2010 01:45 AM, Yang Hongyang wrote:
>> On 05/13/2010 01:32 AM, Eric Chanudet wrote:
>>> + { "network-attach",
>>> + &main_networkattach,
>>> + "Create a new virtual network device"
>>
>> You forgot to add usage and options here:)
>>
>>> + },
>
> Sorry about this omission. Here is the refreshed patch, with usage, for
> network-attach command :
I saw that Keir has already fix that when applying your patch on staging tree.:)
>
> 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,14 @@ 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",
> + "<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);
>
--
Regards
Yang Hongyang
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
|