xl: network and block features
PATCH 1/1 xl: network and block features
This patch series adds the following features to xl and libxenlight:
- network-{attach,list,detach}
- block-{attach,list,detach}
Some details :
- network-attach accel and rate parameters are not handled yet (they are not in xm neither).
- devid attribution for PV nics now starts from 0 for nics described in configuration file (used to start at 1, which made xm freeze when attaching more than one PV nic, probably because of nextDeviceID xenstore entry).
- devid attribution do not rely on nextDeviceID xenstore entry in libxl (comments, in python code, suggest this entry to be optional).
Signature · 1 line
Eric Chanudet
PATCH 1/1 xl: network-attach command
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.
tools/libxl/libxl.c +15 -0
@@ -1420,6 +1420,8 @@ int libxl_device_nic_add(struct libxl_ctunsigned 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_ctif (!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 ;
tools/libxl/xl_cmdimpl.c +84 -1
94 lines not on this page · raw message
tools/libxl/xl_cmdimpl.h +1 -0
@@ -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);
tools/libxl/xl_cmdtable.c +4 -0
@@ -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" + }, };int cmdtable_len =sizeof (cmd_table)/sizeof (struct cmd_spec );
Re: [PATCH 1 of 6] xl: network-attach command
Hi Eric,
Quoted 153 lines · Eric Chanudet
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.
tools/libxl/libxl.c +15
-0@@ -1420,6 +1420,8 @@ int libxl_device_nic_add(struct libxl_ctunsigned 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_ctif (!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 ;tools/libxl/xl_cmdimpl.c +84
-1@@ -573,7 +573,7 @@ static void parse_config_data(const charchar *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 ); +}tools/libxl/xl_cmdimpl.h +1
-0@@ -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);
tools/libxl/xl_cmdtable.c struct cmd_spec cmd_table[] = { · line 177
Quoted 6 lines
tools/libxl/xl_cmdtable.c +3
-0@@ -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:)
Quoted 11 lines
tools/libxl/xl_cmdtable.c +1
-0+ }, };int cmdtable_len =sizeof (cmd_table)/sizeof (struct cmd_spec );_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Signature · 2 lines
Regards Yang Hongyang
RE: [PATCH 1 of 6] xl: network-attach command
Quoted 8 lines · Yang Hongyang
Review
Quoted 3 lines · Eric Chanudet
(quoted diff) +3
-0+ { "network-attach", + &main_networkattach, + "Create a new virtual network device"You forgot to add usage and options here:)
Quoted 1 line
+ },
Sorry about this omission. Here is the refreshed patch, with usage, for network-attach command :
tools/libxl/libxl.c +15 -0
@@ -1420,6 +1420,8 @@ int libxl_device_nic_add(struct libxl_ctunsigned 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_ctif (!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 ;
tools/libxl/xl_cmdimpl.c +84 -1
94 lines not on this page · raw message
tools/libxl/xl_cmdimpl.h +1 -0
@@ -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);
tools/libxl/xl_cmdtable.c +8 -0
@@ -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 );
Signature · 1 line
Eric Chanudet
Re: [PATCH 1 of 6] xl: network-attach command
Hi Eric,
Quoted 11 lines · Eric Chanudet (Intern)
Quoted 8 lines · Yang Hongyang
tools/libxl/xl_cmdtable.c struct cmd_spec cmd_table[] = {
Quoted 3 lines · Eric Chanudet
tools/libxl/xl_cmdtable.c +3
-0+ {"network-attach" , + &main_networkattach, +"Create a new virtual network device" You forgot to add usage and options here:)
Quoted 1 line
+ },
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.:)
Quoted 161 lines
tools/libxl/libxl.c +15
-0@@ -1420,6 +1420,8 @@ int libxl_device_nic_add(struct libxl_ctunsigned 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_ctif (!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 ;tools/libxl/xl_cmdimpl.c +84
-1@@ -573,7 +573,7 @@ static void parse_config_data(const charchar *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 ); +}tools/libxl/xl_cmdimpl.h +1
-0@@ -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);tools/libxl/xl_cmdtable.c +8
-0@@ -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 );
Signature · 2 lines
Regards Yang Hongyang
PATCH 1/1 xl: network-list command
In reply to Eric ChanudetThis patch adds network-list command to xl.
Usage: xl network-list <Domain(s)>
tools/libxl/libxl.c +60 -0
@@ -1505,6 +1505,66 @@ int libxl_device_nic_del(struct libxl_ctreturn libxl_device_del (ctx, &device, wait); } +libxl_nicinfo *libxl_list_nics (struct libxl_ctx *ctx,uint32_t domid,unsigned int *nb) +{ +char *dompath, *nic_path_fe; +char **l; +char *val, *tok; +unsigned int nb_nics, i; +libxl_nicinfo *res, *nics; + + dompath =libxl_xs_get_dompath (ctx, domid); +if (!dompath) { +return NULL ; + } + l =libxl_xs_directory (ctx,XBT_NULL , +libxl_sprintf (ctx,"%s/device/vif" , dompath), &nb_nics); +if (!l) { +return NULL ; + } + res =libxl_calloc (ctx, nb_nics,sizeof (libxl_device_nic)); +if (!res) { +libxl_free (ctx, l); +return NULL ; + } + nics = res; +for (*nb = nb_nics; nb_nics >0 ; --nb_nics, ++l, ++nics) { + nic_path_fe =libxl_sprintf (ctx,"%s/device/vif/%s" , dompath, *l); + + nics->backend =libxl_xs_read (ctx,XBT_NULL , +libxl_sprintf (ctx,"%s/backend" , nic_path_fe)); + val =libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/backend-id" , nic_path_fe)); + nics->backend_id = val ?strtoul (val,NULL ,10 ) :-1 ; + + nics->devid =strtoul (*l,NULL ,10 ); + val =libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/state" , nic_path_fe)); + nics->state = val ?strtoul (val,NULL ,10 ) :-1 ; + val =libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/mac" , nic_path_fe)); +for (i =0 , tok =strtok (val,":" ); tok && (i <6 ); + ++i, tok =strtok (NULL ,":" )) { + nics->mac[i] =strtoul (tok,NULL ,16 ); + } + val =libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/event-channel" , nic_path_fe)); + nics->evtch = val ?strtol (val,NULL ,10 ) :-1 ; + val =libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/tx-ring-ref" , nic_path_fe)); + nics->rref_tx = val ?strtol (val,NULL ,10 ) :-1 ; + val =libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/rx-ring-ref" , nic_path_fe)); + nics->rref_rx = val ?strtol (val,NULL ,10 ) :-1 ; + nics->frontend =libxl_xs_read (ctx,XBT_NULL , +libxl_sprintf (ctx,"%s/frontend" , nics->backend)); + val =libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/frontend-id" , nics->backend)); + nics->frontend_id = val ?strtoul (val,NULL ,10 ) :-1 ; + nics->script =libxl_xs_read (ctx,XBT_NULL , +libxl_sprintf (ctx,"%s/script" , nics->backend)); + +libxl_free (ctx, nic_path_fe); + } + +libxl_free (ctx, l); +return res; +} + +/******************************************************************************/ int libxl_device_console_add (struct libxl_ctx *ctx,uint32_t domid,libxl_device_console *console) {
tools/libxl/libxl.h +15 -0
@@ -372,8 +372,23 @@ int libxl_device_disk_del(struct libxl_clibxl_device_disk *libxl_device_disk_list (struct libxl_ctx *ctx,uint32_t domid,int *num);int libxl_cdrom_insert (struct libxl_ctx *ctx,uint32_t domid,libxl_device_disk *disk); +typedef struct { +char *backend; +uint32_t backend_id; +char *frontend; +uint32_t frontend_id; +int devid; +int state; +char *script; +uint8_t mac[6 ]; +int evtch; +int rref_tx; +int rref_rx; +}libxl_nicinfo ; +int libxl_device_nic_add (struct libxl_ctx *ctx,uint32_t domid,libxl_device_nic *nic);int libxl_device_nic_del (struct libxl_ctx *ctx,libxl_device_nic *nic,int wait); +libxl_nicinfo *libxl_list_nics (struct libxl_ctx *ctx,uint32_t domid,unsigned int *nb);int libxl_device_console_add (struct libxl_ctx *ctx,uint32_t domid,libxl_device_console *console);
tools/libxl/xl_cmdimpl.c +48 -0
51 lines not on this page · raw message
tools/libxl/xl_cmdimpl.h +1 -0
@@ -40,5 +40,6 @@ 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); +int main_networklist (int argc,char **argv);void help (char *command);
tools/libxl/xl_cmdtable.c +4 -0
@@ -176,6 +176,10 @@ struct cmd_spec cmd_table[] = { &main_networkattach, "Create a new virtual network device" }, + {"network-list" , + &main_networklist, +"List virtual network interfaces for a domain" + }, };int cmdtable_len =sizeof (cmd_table)/sizeof (struct cmd_spec );
PATCH 1/1 xl: network-detach command
In reply to Eric ChanudetThis patch adds network-detach command to xl.
Usage: xl network-detach <Domain> <DevId|mac>
tools/libxl/libxl_utils.c +74 -0
@@ -356,3 +356,77 @@ int libxl_pipe(struct libxl_ctx *ctx, in }return 0 ; } + +int libxl_mac_to_device_nic (struct libxl_ctx *ctx,uint32_t domid, +const char *mac,libxl_device_nic *nic) +{ +libxl_nicinfo *nics; +unsigned int nb, i; +uint8_t mac_n[6 ]; +uint8_t *a, *b; +const char *tok; +char *endptr; + + nics =libxl_list_nics (ctx, domid, &nb); +if (!nics) { +return ERROR_FAIL ; + } + +for (i =0 , tok = mac; *tok && (i <6 ); ++i, tok +=3 ) { + mac_n[i] =strtol (tok, &endptr,16 ); +if (endptr != (tok +2 )) { +return ERROR_INVAL ; + } + } +memset (nic,0 ,sizeof (libxl_device_nic)); +for (; nb; --nb, ++nics) { +for (i =0 , a = nics->mac, b = mac_n; + (b < mac_n +6 ) && (*a == *b); ++a, ++b) + ; +if ((b >= mac_n +6 ) && (*a == *b)) { + nic->backend_domid = nics->backend_id; + nic->domid = nics->frontend_id; + nic->devid = nics->devid; +memcpy (nic->mac, nics->mac,sizeof (nic->mac)); + nic->script = nics->script; +libxl_free (ctx, nics); +return 0 ; + } + } + +libxl_free (ctx, nics); +return 0 ; +} + +int libxl_devid_to_device_nic (struct libxl_ctx *ctx,uint32_t domid, +const char *devid,libxl_device_nic *nic) +{ +char *tok, *val; +char *dompath, *nic_path_fe, *nic_path_be; +unsigned int i; + +memset (nic,0 ,sizeof (libxl_device_nic)); + dompath =libxl_xs_get_dompath (ctx, domid); +if (!dompath) { +return ERROR_FAIL ; + } + nic_path_fe =libxl_sprintf (ctx,"%s/device/vif/%s" , dompath, devid); + nic_path_be =libxl_xs_read (ctx,XBT_NULL , +libxl_sprintf (ctx,"%s/backend" , nic_path_fe)); + val =libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/backend-id" , nic_path_fe)); + nic->backend_domid =strtoul (val,NULL ,10 ); + nic->devid =strtoul (devid,NULL ,10 ); +libxl_free (ctx, val); + + val =libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/mac" , nic_path_fe)); +for (i =0 , tok =strtok (val,":" ); tok && (i <6 ); + ++i, tok =strtok (NULL ,":" )) { + nic->mac[i] =strtoul (tok,NULL ,16 ); + } +libxl_free (ctx, val); + nic->script =libxl_xs_read (ctx,XBT_NULL , +libxl_sprintf (ctx,"%s/script" , nic_path_be)); +libxl_free (ctx, nic_path_fe); +libxl_free (ctx, nic_path_be); +return 0 ; +}
tools/libxl/libxl_utils.h +6 -0
@@ -55,6 +55,12 @@ void libxl_report_child_exitstatus(struc/* treats all exit statuses as errors; if that's not what you want, * check status yourself first */ + +int libxl_mac_to_device_nic (struct libxl_ctx *ctx,uint32_t domid, +const char *mac,libxl_device_nic *nic); +int libxl_devid_to_device_nic (struct libxl_ctx *ctx,uint32_t domid, +const char *devid,libxl_device_nic *nic); +/* log levels: */ #define XL_LOG_DEBUG 3#define XL_LOG_INFO 2
tools/libxl/xl_cmdimpl.c +42 -0
45 lines not on this page · raw message
tools/libxl/xl_cmdimpl.h +1 -0
@@ -41,5 +41,6 @@ int main_rename(int argc, char **argv);int main_trigger (int argc,char **argv);int main_networkattach (int argc,char **argv);int main_networklist (int argc,char **argv); +int main_networkdetach (int argc,char **argv);void help (char *command);
tools/libxl/xl_cmdtable.c +4 -0
@@ -180,6 +180,10 @@ struct cmd_spec cmd_table[] = { &main_networklist, "List virtual network interfaces for a domain" }, + {"network-detach" , + &main_networkdetach, +"Destroy a domain's virtual network device" + }, };int cmdtable_len =sizeof (cmd_table)/sizeof (struct cmd_spec );
PATCH 1/1 xl: block-attach command
In reply to Eric ChanudetThis patch adds block-attach command to xl.
Usage: xl block-attach <Domain> <BackDev> <FrontDev> <Mode> [BackDomain]
tools/libxl/xl_cmdimpl.c +72 -0
@@ -3231,3 +3231,75 @@ int main_networkdetach(int argc, char ** }exit (0 ); } + +int main_blockattach (int argc,char **argv) +{ +int opt; +char *tok; +uint32_t fe_domid, be_domid =0 ; +libxl_device_disk disk = {0 }; + +if ((argc <3 ) || (argc >6 )) { +help ("block-attach" ); +exit (0 ); + } +while ((opt =getopt (argc, argv,"h" )) !=-1 ) { +switch (opt) { +case 'h' : +help ("block-attach" ); +exit (0 ); +default : +fprintf (stderr,"option `%c' not supported.\n" , opt); +break ; + } + } + + tok =strtok (argv[2 ],":" ); +if (!strcmp (tok,"phy" )) { + disk.phystype =PHYSTYPE_PHY ; + }else if (!strcmp (tok,"file" )) { + disk.phystype =PHYSTYPE_FILE ; + }else if (!strcmp (tok,"tap" )) { + tok =strtok (NULL ,":" ); +if (!strcmp (tok,"aio" )) { + disk.phystype =PHYSTYPE_AIO ; + }else if (!strcmp (tok,"vhd" )) { + disk.phystype =PHYSTYPE_VHD ; + }else if (!strcmp (tok,"qcow" )) { + disk.phystype =PHYSTYPE_QCOW ; + }else if (!strcmp (tok,"qcow2" )) { + disk.phystype =PHYSTYPE_QCOW2 ; + }else { +fprintf (stderr,"Error: `%s' is not a valid disk image.\n" , tok); +exit (1 ); + } + }else { +fprintf (stderr,"Error: `%s' is not a valid block device.\n" , tok); +exit (1 ); + } + disk.physpath =strtok (NULL ,"\0" ); +if (!disk.physpath) { +fprintf (stderr,"Error: missing path to disk image.\n" ); +exit (1 ); + } + disk.virtpath = argv[3 ]; + disk.unpluggable =1 ; + disk.readwrite = (argv[4 ][0 ] =='w' ) ?1 :0 ; + +if (domain_qualifier_to_domid (argv[1 ], &fe_domid,0 ) <0 ) { +fprintf (stderr,"%s is an invalid domain identifier\n" , argv[1 ]); +exit (1 ); + } +if (argc ==6 ) { +if (domain_qualifier_to_domid (argv[5 ], &be_domid,0 ) <0 ) { +fprintf (stderr,"%s is an invalid domain identifier\n" , argv[5 ]); +exit (1 ); + } + } + disk.domid = fe_domid; + disk.backend_domid = be_domid; +if (libxl_device_disk_add (&ctx, fe_domid, &disk)) { +fprintf (stderr,"libxl_device_disk_add failed.\n" ); + } +exit (0 ); +}
tools/libxl/xl_cmdimpl.h +1 -0
@@ -42,5 +42,6 @@ int main_trigger(int argc, char **argv);int main_networkattach (int argc,char **argv);int main_networklist (int argc,char **argv);int main_networkdetach (int argc,char **argv); +int main_blockattach (int argc,char **argv);void help (char *command);
tools/libxl/xl_cmdtable.c +4 -0
@@ -184,6 +184,10 @@ struct cmd_spec cmd_table[] = { &main_networkdetach, "Destroy a domain's virtual network device" }, + {"block-attach" , + &main_blockattach, +"Create a new virtual block device" + }, };int cmdtable_len =sizeof (cmd_table)/sizeof (struct cmd_spec );
PATCH 1/1 xl: block-list command
In reply to Eric ChanudetThis patch adds block-list command to xl.
Usage: xl block-list <Domain(s)>
tools/libxl/libxl.c +70 -37
@@ -1703,57 +1703,90 @@ int libxl_device_vkb_hard_shutdown(struclibxl_device_disk *libxl_device_disk_list (struct libxl_ctx *ctx,uint32_t domid,int *num) {char *be_path_tap, *be_path_vbd; -libxl_device_disk *disks =NULL ; -char **l =NULL ; +libxl_device_disk *dend, *disks, *ret =NULL ; +char **b, **l =NULL ;unsigned int numl; -int num_disks =0 , i;char *type; be_path_vbd =libxl_sprintf (ctx,"%s/backend/vbd/%d" ,libxl_xs_get_dompath (ctx,0 ), domid); be_path_tap =libxl_sprintf (ctx,"%s/backend/tap/%d" ,libxl_xs_get_dompath (ctx,0 ), domid); - l =libxl_xs_directory (ctx,XBT_NULL , be_path_vbd, &numl); + b = l =libxl_xs_directory (ctx,XBT_NULL , be_path_vbd, &numl);if (l) { - num_disks += numl; - disks =realloc (disks,sizeof (libxl_device_disk) * num_disks); -for (i =0 ; i < numl; i++) { - disks[i].backend_domid =0 ; - disks[i].domid = domid; - disks[i].physpath =libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/%s/params" , be_path_vbd, l[i])); -libxl_string_to_phystype (ctx,libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/%s/type" , be_path_vbd, l[i])), &(disks[i].phystype)); - disks[i].virtpath =libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/%s/dev" , be_path_vbd, l[i])); - disks[i].unpluggable =atoi (libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/%s/removable" , be_path_vbd, l[i]))); -if (!strcmp (libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/%s/mode" , be_path_vbd, l[i])),"w" )) - disks[i].readwrite =1 ; + ret =realloc (ret,sizeof (libxl_device_disk) * numl); + disks = ret; + *num = numl; + dend = ret + *num; +for (; disks < dend; ++disks, ++l) { + disks->backend_domid =0 ; + disks->domid = domid; + disks->physpath =libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/%s/params" , be_path_vbd, *l)); +libxl_string_to_phystype (ctx,libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/%s/type" , be_path_vbd, *l)), &(disks->phystype)); + disks->virtpath =libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/%s/dev" , be_path_vbd, *l)); + disks->unpluggable =atoi (libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/%s/removable" , be_path_vbd, *l))); +if (!strcmp (libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/%s/mode" , be_path_vbd, *l)),"w" )) + disks->readwrite =1 ;else - disks[i].readwrite =0 ; - type =libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/device-type" ,libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/%s/frontend" , be_path_vbd, l[i])))); - disks[i].is_cdrom = !strcmp (type,"cdrom" ); + disks->readwrite =0 ; + type =libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/device-type" ,libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/%s/frontend" , be_path_vbd, *l)))); + disks->is_cdrom = !strcmp (type,"cdrom" ); } -free (l); +libxl_free (ctx, b); } - l =libxl_xs_directory (ctx,XBT_NULL , be_path_tap, &numl); + b = l =libxl_xs_directory (ctx,XBT_NULL , be_path_tap, &numl);if (l) { - num_disks += numl; - disks =realloc (disks,sizeof (libxl_device_disk) * num_disks); -for (i =0 ; i < numl; i++) { - disks[i].backend_domid =0 ; - disks[i].domid = domid; - disks[i].physpath =libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/%s/params" , be_path_tap, l[i])); -libxl_string_to_phystype (ctx,libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/%s/type" , be_path_tap, l[i])), &(disks[i].phystype)); - disks[i].virtpath =libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/%s/dev" , be_path_tap, l[i])); - disks[i].unpluggable =atoi (libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/%s/removable" , be_path_tap, l[i]))); -if (!strcmp (libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/%s/mode" , be_path_tap, l[i])),"w" )) - disks[i].readwrite =1 ; + ret =realloc (ret,sizeof (libxl_device_disk) * (*num + numl)); + disks = ret + *num; + *num += numl; +for (dend = ret + *num; disks < dend; ++disks, ++l) { + disks->backend_domid =0 ; + disks->domid = domid; + disks->physpath =libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/%s/params" , be_path_tap, *l)); +libxl_string_to_phystype (ctx,libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/%s/type" , be_path_tap, *l)), &(disks->phystype)); + disks->virtpath =libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/%s/dev" , be_path_tap, *l)); + disks->unpluggable =atoi (libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/%s/removable" , be_path_tap, *l))); +if (!strcmp (libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/%s/mode" , be_path_tap, *l)),"w" )) + disks->readwrite =1 ;else - disks[i].readwrite =0 ; - type =libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/device-type" ,libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/%s/frontend" , be_path_vbd, l[i])))); - disks[i].is_cdrom = !strcmp (type,"cdrom" ); + disks->readwrite =0 ; + type =libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/device-type" ,libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/%s/frontend" , be_path_tap, *l)))); + disks->is_cdrom = !strcmp (type,"cdrom" ); } -free (l); +libxl_free (ctx, b); } - *num = num_disks; -return disks; +return ret; +} + +int libxl_device_disk_getinfo (struct libxl_ctx *ctx,uint32_t domid, +libxl_device_disk *disk,libxl_diskinfo *diskinfo) +{ +char *dompath, *diskpath; +char *val; + + dompath =libxl_xs_get_dompath (ctx, domid); + diskinfo->devid =device_disk_dev_number (disk->virtpath); + +/* tap devices entries in xenstore are written as vbd devices. */ + diskpath =libxl_sprintf (ctx,"%s/device/vbd/%d" , dompath, diskinfo->devid); + diskinfo->backend =libxl_xs_read (ctx,XBT_NULL , +libxl_sprintf (ctx,"%s/backend" , diskpath)); +if (!diskinfo->backend) { +return ERROR_FAIL ; + } + val =libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/backend-id" , diskpath)); + diskinfo->backend_id = val ?strtoul (val,NULL ,10 ) :-1 ; + val =libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/state" , diskpath)); + diskinfo->state = val ?strtoul (val,NULL ,10 ) :-1 ; + val =libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/event-channel" , diskpath)); + diskinfo->evtch = val ?strtoul (val,NULL ,10 ) :-1 ; + val =libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/ring-ref" , diskpath)); + diskinfo->rref = val ?strtoul (val,NULL ,10 ) :-1 ; + diskinfo->frontend =libxl_xs_read (ctx,XBT_NULL , +libxl_sprintf (ctx,"%s/frontend" , diskinfo->backend)); + val =libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/frontend-id" , diskinfo->backend)); + diskinfo->frontend_id = val ?strtoul (val,NULL ,10 ) :-1 ; + +return 0 ; }int libxl_cdrom_insert (struct libxl_ctx *ctx,uint32_t domid,libxl_device_disk *disk)
tools/libxl/libxl.h +13 -0
@@ -367,9 +367,22 @@ int libxl_detach_device_model(struct lib libxl_device_model_starting *starting);/* DM is detached even if error is returned */ +typedef struct { +char *backend; +uint32_t backend_id; +char *frontend; +uint32_t frontend_id; +int devid; +int state; +int evtch; +int rref; +}libxl_diskinfo ; +int libxl_device_disk_add (struct libxl_ctx *ctx,uint32_t domid,libxl_device_disk *disk);int libxl_device_disk_del (struct libxl_ctx *ctx,libxl_device_disk *disk,int wait);libxl_device_disk *libxl_device_disk_list (struct libxl_ctx *ctx,uint32_t domid,int *num); +int libxl_device_disk_getinfo (struct libxl_ctx *ctx,uint32_t domid, +libxl_device_disk *disk,libxl_diskinfo *diskinfo);int libxl_cdrom_insert (struct libxl_ctx *ctx,uint32_t domid,libxl_device_disk *disk); typedef struct {
tools/libxl/xl_cmdimpl.c +45 -0
48 lines not on this page · raw message
tools/libxl/xl_cmdimpl.h +1 -0
@@ -43,5 +43,6 @@ int main_networkattach(int argc, char **int main_networklist (int argc,char **argv);int main_networkdetach (int argc,char **argv);int main_blockattach (int argc,char **argv); +int main_blocklist (int argc,char **argv);void help (char *command);
tools/libxl/xl_cmdtable.c +4 -0
@@ -188,6 +188,10 @@ struct cmd_spec cmd_table[] = { &main_blockattach, "Create a new virtual block device" }, + {"block-list" , + &main_blocklist, +"List virtual block devices for a domain" + }, };int cmdtable_len =sizeof (cmd_table)/sizeof (struct cmd_spec );
PATCH 1/1 xl: block-detach command
In reply to Eric ChanudetThis patch adds block-detach command to xl.
Usage: xl block-detach <Domain> <DevId>
tools/libxl/libxl_utils.c +35 -0
@@ -430,3 +430,38 @@ int libxl_devid_to_device_nic(struct liblibxl_free (ctx, nic_path_be);return 0 ; } + +int libxl_devid_to_device_disk (struct libxl_ctx *ctx,uint32_t domid, +const char *devid,libxl_device_disk *disk) +{ +char *endptr, *val; +char *dompath, *diskpath, *be_path; +unsigned int devid_n; + + devid_n =strtoul (devid, &endptr,10 ); +if (devid == endptr) { +return ERROR_INVAL ; + } + dompath =libxl_xs_get_dompath (ctx, domid); + diskpath =libxl_sprintf (ctx,"%s/device/vbd/%s" , dompath, devid); +if (!diskpath) { +return ERROR_FAIL ; + } + + val =libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/backend-id" , diskpath)); + disk->backend_domid =strtoul (val,NULL ,10 ); + disk->domid = domid; + be_path =libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/backend" , diskpath)); + disk->physpath =libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/params" , be_path)); + val =libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/type" , be_path)); +libxl_string_to_phystype (ctx, val, &(disk->phystype)); + disk->virtpath =libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/dev" , be_path)); + val =libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/removable" , be_path)); + disk->unpluggable = !strcmp (val,"1" ); + val =libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/mode" , be_path)); + disk->readwrite = !!strcmp (val,"w" ); + val =libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/device-type" , diskpath)); + disk->is_cdrom = !strcmp (val,"cdrom" ); + +return 0 ; +}
tools/libxl/libxl_utils.h +3 -0
@@ -61,6 +61,9 @@ int libxl_mac_to_device_nic(struct libxlint libxl_devid_to_device_nic (struct libxl_ctx *ctx,uint32_t domid,const char *devid,libxl_device_nic *nic); +int libxl_devid_to_device_disk (struct libxl_ctx *ctx,uint32_t domid, +const char *devid,libxl_device_disk *disk); +/* log levels: */ #define XL_LOG_DEBUG 3#define XL_LOG_INFO 2
tools/libxl/xl_cmdimpl.c +34 -0
@@ -3348,3 +3348,37 @@ int main_blocklist(int argc, char **argv }exit (0 ); } + +int main_blockdetach (int argc,char **argv) +{ +int opt; +libxl_device_disk disk; + +if (argc !=3 ) { +help ("block-detach" ); +exit (0 ); + } +while ((opt =getopt (argc, argv,"h" )) !=-1 ) { +switch (opt) { +case 'h' : +help ("block-detach" ); +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 ); + } +if (libxl_devid_to_device_disk (&ctx, domid, argv[2 ], &disk)) { +fprintf (stderr,"Error: Device %s not connected.\n" , argv[2 ]); +exit (1 ); + } +if (libxl_device_disk_del (&ctx, &disk,1 )) { +fprintf (stderr,"libxl_device_del failed.\n" ); + } +exit (0 ); +}
tools/libxl/xl_cmdimpl.h +1 -0
@@ -44,5 +44,6 @@ int main_networklist(int argc, char **arint main_networkdetach (int argc,char **argv);int main_blockattach (int argc,char **argv);int main_blocklist (int argc,char **argv); +int main_blockdetach (int argc,char **argv);void help (char *command);
tools/libxl/xl_cmdtable.c +4 -0
@@ -192,6 +192,10 @@ struct cmd_spec cmd_table[] = { &main_blocklist, "List virtual block devices for a domain" }, + {"block-detach" , + &main_blockdetach, +"Destroy a domain's virtual block device" + }, };int cmdtable_len =sizeof (cmd_table)/sizeof (struct cmd_spec );