xl: network2 commands, hap parameter and block commands fixes
PATCH 1/1 xl: network2 commands, hap parameter and block commands fixes
This patch serie adds network2-{attach,list,detach} commands to xl and libxenlight, adds hap parameter parsing from configuration file and fixes some issues with block-{attach,list,detach} commands (argv/argc offset mismatch).
Signature · 1 line
Eric Chanudet
PATCH 1/1 xl: network2-attach command
This patch adds network2-attach command to xl.
Usage: xl network2-attach <Domain> [front_mac=<mac>] [back_mac=<mac>] [backend=<BackDomain>] [trusted=<0|1>] [back_trusted=<0|1>] [bridge=<bridge>] [filter_mac=<0|1>] [front_filter_mac=<0|1>] [pdev=<PDEV>] [max_bypasses=n]
tools/libxl/libxl.c +103 -0
@@ -1582,6 +1582,109 @@ libxl_nicinfo *libxl_list_nics(struct lireturn res; } +/******************************************************************************/ +int libxl_device_net2_add (struct libxl_ctx *ctx,uint32_t domid,libxl_device_net2 *net2) +{ +flexarray_t *front, *back; +unsigned int boffset =0 , foffset =0 ; +libxl_device device; +char *dompath, *dom, **l; +unsigned int nb; + + front =flexarray_make (16 ,1 ); +if (!front) +return ERROR_NOMEM ; + back =flexarray_make (16 ,1 ); +if (!back) +return ERROR_NOMEM ; + +if (!(dompath =libxl_xs_get_dompath (ctx, domid))) { +return ERROR_FAIL ; + } + dom =libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/name" , dompath)); + +if (net2->devid ==-1 ) { +if (!(l =libxl_xs_directory (ctx,XBT_NULL , +libxl_sprintf (ctx,"%s/device/vif2" , dompath), &nb))) { + net2->devid =0 ; + }else { + net2->devid =strtoul (l[nb -1 ],NULL ,10 ) +1 ; +libxl_free (ctx, l); + } + } + + device.backend_devid = net2->devid; + device.backend_domid = net2->backend_domid; + device.backend_kind =DEVICE_VIF2 ; + device.devid = net2->devid; + device.domid = net2->domid; + device.kind =DEVICE_VIF2 ; + +flexarray_set (back, boffset++,"domain" ); +flexarray_set (back, boffset++, dom); +flexarray_set (back, boffset++,"frontend-id" ); +flexarray_set (back, boffset++,libxl_sprintf (ctx,"%d" , net2->domid)); + +flexarray_set (back, boffset++,"local-trusted" ); +flexarray_set (back, boffset++,libxl_sprintf (ctx,"%d" , net2->back_trusted)); +flexarray_set (back, boffset++,"mac" ); +flexarray_set (back, boffset++,libxl_sprintf (ctx,"%02x:%02x:%02x:%02x:%02x:%02x" , + net2->back_mac[0 ], net2->back_mac[1 ], + net2->back_mac[2 ], net2->back_mac[3 ], + net2->back_mac[4 ], net2->back_mac[5 ])); + +flexarray_set (back, boffset++,"remote-trusted" ); +flexarray_set (back, boffset++,libxl_sprintf (ctx,"%d" , net2->trusted)); +flexarray_set (back, boffset++,"remote-mac" ); +flexarray_set (back, boffset++,libxl_sprintf (ctx,"%02x:%02x:%02x:%02x:%02x:%02x" , + net2->front_mac[0 ], net2->front_mac[1 ], + net2->front_mac[2 ], net2->front_mac[3 ], + net2->front_mac[4 ], net2->front_mac[5 ])); + +flexarray_set (back, boffset++,"max-bypasses" ); +flexarray_set (back, boffset++,libxl_sprintf (ctx,"%d" , net2->max_bypasses)); +flexarray_set (back, boffset++,"filter-mac" ); +flexarray_set (back, boffset++,libxl_sprintf (ctx,"%d" , !!(net2->filter_mac))); +flexarray_set (back, boffset++,"handle" ); +flexarray_set (back, boffset++,libxl_sprintf (ctx,"%d" , net2->devid)); +flexarray_set (back, boffset++,"online" ); +flexarray_set (back, boffset++,"1" ); +flexarray_set (back, boffset++,"state" ); +flexarray_set (back, boffset++,"1" ); + +flexarray_set (front, foffset++,"backend-id" ); +flexarray_set (front, foffset++,libxl_sprintf (ctx,"%d" , net2->backend_domid)); + +flexarray_set (front, foffset++,"local-trusted" ); +flexarray_set (front, foffset++,libxl_sprintf (ctx,"%d" , net2->trusted)); +flexarray_set (front, foffset++,"mac" ); +flexarray_set (front, foffset++,libxl_sprintf (ctx,"%02x:%02x:%02x:%02x:%02x:%02x" , + net2->front_mac[0 ], net2->front_mac[1 ], + net2->front_mac[2 ], net2->front_mac[3 ], + net2->front_mac[4 ], net2->front_mac[5 ])); + +flexarray_set (front, foffset++,"remote-trusted" ); +flexarray_set (front, foffset++,libxl_sprintf (ctx,"%d" , net2->back_trusted)); +flexarray_set (front, foffset++,"remote-mac" ); +flexarray_set (front, foffset++,libxl_sprintf (ctx,"%02x:%02x:%02x:%02x:%02x:%02x" , + net2->back_mac[0 ], net2->back_mac[1 ], + net2->back_mac[2 ], net2->back_mac[3 ], + net2->back_mac[4 ], net2->back_mac[5 ])); + +flexarray_set (front, foffset++,"filter-mac" ); +flexarray_set (front, foffset++,libxl_sprintf (ctx,"%d" , !!(net2->filter_mac))); +flexarray_set (front, foffset++,"state" ); +flexarray_set (front, foffset++,"1" ); + +libxl_device_generic_add (ctx, &device, +libxl_xs_kvs_of_flexarray (ctx, back, boffset), +libxl_xs_kvs_of_flexarray (ctx, front, foffset)); + +/* FIXME: wait for plug */ +flexarray_free (back); +flexarray_free (front); +return 0 ; +}/******************************************************************************/ int libxl_device_console_add (struct libxl_ctx *ctx,uint32_t domid,libxl_device_console *console)
tools/libxl/libxl.h +18 -0
@@ -240,6 +240,21 @@ typedef struct {libxl_nic_type nictype; } libxl_device_nic; +typedef struct { +int devid; +uint8_t front_mac[6 ]; +uint8_t back_mac[6 ]; +uint32_t backend_domid; +uint32_t domid; +uint32_t trusted:1 ; +uint32_t back_trusted:1 ; +uint32_t filter_mac:1 ; +uint32_t front_filter_mac:1 ; +uint32_t pdev; +uint32_t max_bypasses; +char *bridge; +}libxl_device_net2 ; + typedef struct { union { unsigned int value;
@@ -536,5 +551,8 @@ int libxl_tmem_set(struct libxl_ctx *ctx uint32_t set);int libxl_tmem_shared_auth (struct libxl_ctx *ctx,uint32_t domid,char * uuid,int auth); + +int libxl_device_net2_add (struct libxl_ctx *ctx,uint32_t domid,libxl_device_net2 *net2); +#endif /* LIBXL_H */
tools/libxl/libxl_device.c +1 -0
@@ -28,6 +28,7 @@static const char *string_of_kinds[] = { [DEVICE_VIF ] ="vif" , + [DEVICE_VIF2 ] ="vif2" , [DEVICE_VBD ] ="vbd" , [DEVICE_TAP ] ="tap" , [DEVICE_PCI ] ="pci" ,
tools/libxl/libxl_internal.h +1 -0
@@ -68,6 +68,7 @@ void xl_log(struct libxl_ctx *ctx, xento typedef enum { DEVICE_VIF = 1, + DEVICE_VIF2, DEVICE_VBD, DEVICE_TAP, DEVICE_PCI,
tools/libxl/libxl_utils.c +15 -0
@@ -467,3 +467,18 @@ int libxl_devid_to_device_disk(struct lireturn 0 ; } + +int libxl_strtomac (const char *mac_s,uint8_t *mac) +{ +const char *end = mac_s +17 ; +char val, *endptr; + +for (; mac_s < end; mac_s +=3 , ++mac) { + val =strtoul (mac_s, &endptr,16 ); +if (endptr != (mac_s +2 )) { +return ERROR_INVAL ; + } + *mac = val; + } +return 0 ; +}
tools/libxl/libxl_utils.h +1 -0
@@ -63,6 +63,7 @@ int libxl_devid_to_device_nic(struct libint libxl_devid_to_device_disk (struct libxl_ctx *ctx,uint32_t domid,const char *devid,libxl_device_disk *disk); +int libxl_strtomac (const char *mac_s,uint8_t *mac);#endif
tools/libxl/xl.h +1 -0
@@ -72,6 +72,7 @@ int main_tmem_destroy(int argc, char **aint main_tmem_thaw (int argc,char **argv);int main_tmem_set (int argc,char **argv);int main_tmem_shared_auth (int argc,char **argv); +int main_network2attach (int argc,char **argv);void help (char *command);
tools/libxl/xl_cmdimpl.c +176 -3
233 lines not on this page · raw message
tools/libxl/xl_cmdtable.c +8 -0
@@ -287,6 +287,14 @@ struct cmd_spec cmd_table[] = { " (abcdef01-2345-6789-1234-567890abcdef)\n" " -A AUTH 0=auth,1=deauth", }, + {"network2-attach" , + &main_network2attach, +"Create a new version 2 virtual network device" , +"<Domain> [front_mac=<mac>] [back_mac=<mac>] [backend=<BackDomain>]" +" [trusted=<0|1>] [back_trusted=<0|1>] [bridge=<bridge>]" +" [filter_mac=<0|1>] [front_filter_mac=<0|1>] [pdev=<PDEV>]" + " [max_bypasses=n]", + }, };int cmdtable_len =sizeof (cmd_table)/sizeof (struct cmd_spec );
PATCH 1/1 xl: network2-list command
In reply to Eric ChanudetThis patch adds network2-list command to xl.
Usage: xl network2-list <Domains>
tools/libxl/libxl.c +63 -0
@@ -1686,6 +1686,69 @@ int libxl_device_net2_add(struct libxl_creturn 0 ; } +libxl_net2info *libxl_device_net2_list (struct libxl_ctx *ctx,uint32_t domid,unsigned int *nb) +{ +char *dompath, *net2_path_fe; +char **l; +char *val, *tok; +unsigned int nb_net2s, i; +libxl_net2info *res, *net2s; + + dompath =libxl_xs_get_dompath (ctx, domid); +if (!dompath) { +return NULL ; + } + l =libxl_xs_directory (ctx,XBT_NULL , +libxl_sprintf (ctx,"%s/device/vif2" , dompath), &nb_net2s); +if (!l) { +return NULL ; + } + res =libxl_calloc (ctx, nb_net2s,sizeof (libxl_net2info)); +if (!res) { +libxl_free (ctx, l); +return NULL ; + } + net2s = res; +for (*nb = nb_net2s; nb_net2s >0 ; --nb_net2s, ++l, ++net2s) { + net2_path_fe =libxl_sprintf (ctx,"%s/device/vif2/%s" , dompath, *l); + + net2s->backend =libxl_xs_read (ctx,XBT_NULL , +libxl_sprintf (ctx,"%s/backend" , net2_path_fe)); + val =libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/backend-id" , net2_path_fe)); + net2s->backend_id = val ?strtoul (val,NULL ,10 ) :-1 ; + + net2s->devid =strtoul (*l,NULL ,10 ); + val =libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/state" , net2_path_fe)); + net2s->state = val ?strtoul (val,NULL ,10 ) :-1 ; + + val =libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/mac" , net2_path_fe)); +for (i =0 , tok =strtok (val,":" ); tok && (i <6 ); + ++i, tok =strtok (NULL ,":" )) { + net2s->mac[i] =strtoul (tok,NULL ,16 ); + } + val =libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/remote-trusted" , net2_path_fe)); + net2s->trusted = val ?strtoul (val,NULL ,10 ) :-1 ; + + val =libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/remote-mac" , net2_path_fe)); +for (i =0 , tok =strtok (val,":" ); tok && (i <6 ); + ++i, tok =strtok (NULL ,":" )) { + net2s->back_mac[i] =strtoul (tok,NULL ,16 ); + } + val =libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/filter-mac" , net2_path_fe)); + net2s->filter_mac = val ?strtoul (val,NULL ,10 ) :-1 ; + + net2s->frontend =libxl_xs_read (ctx,XBT_NULL , +libxl_sprintf (ctx,"%s/frontend" , net2s->backend)); + val =libxl_xs_read (ctx,XBT_NULL ,libxl_sprintf (ctx,"%s/frontend-id" , net2s->backend)); + net2s->frontend_id = val ?strtoul (val,NULL ,10 ) :-1 ; +libxl_free (ctx, net2_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 +14 -0
@@ -552,7 +552,21 @@ int libxl_tmem_set(struct libxl_ctx *ctxint libxl_tmem_shared_auth (struct libxl_ctx *ctx,uint32_t domid,char * uuid,int auth); +typedef struct { +char *backend; +uint32_t backend_id; +char *frontend; +uint32_t frontend_id; +int devid; +int state; +uint8_t mac[6 ]; +int trusted; +uint8_t back_mac[6 ]; +int filter_mac; +}libxl_net2info ; +int libxl_device_net2_add (struct libxl_ctx *ctx,uint32_t domid,libxl_device_net2 *net2); +libxl_net2info *libxl_device_net2_list (struct libxl_ctx *ctx,uint32_t domid,unsigned int *nb);#endif /* LIBXL_H */
tools/libxl/xl.h +1 -0
@@ -73,6 +73,7 @@ int main_tmem_thaw(int argc, char **argvint main_tmem_set (int argc,char **argv);int main_tmem_shared_auth (int argc,char **argv);int main_network2attach (int argc,char **argv); +int main_network2list (int argc,char **argv);void help (char *command);
tools/libxl/xl_cmdimpl.c +45 -0
51 lines not on this page · raw message
tools/libxl/xl_cmdtable.c +5 -0
@@ -295,6 +295,11 @@ struct cmd_spec cmd_table[] = { " [filter_mac=<0|1>] [front_filter_mac=<0|1>] [pdev=<PDEV>]" " [max_bypasses=n]", }, + {"network2-list" , + &main_network2list, +"list version 2 virtual network interfaces for a domain" , + "<Domain(s)>", + }, };int cmdtable_len =sizeof (cmd_table)/sizeof (struct cmd_spec );
PATCH 1/1 xl: network2-detach command
In reply to Eric ChanudetThis patch adds netowkr2-detach command to xl.
Usage: xl network2-detach <Domain> <DevId>
tools/libxl/libxl.c +14 -0
@@ -1748,6 +1748,20 @@ libxl_net2info *libxl_device_net2_list(sreturn res; } +int libxl_device_net2_del (struct libxl_ctx *ctx,libxl_device_net2 *net2,int wait) +{ +libxl_device device; + + device.backend_devid = net2->devid; + device.backend_domid = net2->backend_domid; + device.backend_kind =DEVICE_VIF2 ; + device.devid = net2->devid; + device.domid = net2->domid; + device.kind =DEVICE_VIF2 ; + +return libxl_device_del (ctx, &device, wait); +} +/******************************************************************************/ int libxl_device_console_add (struct libxl_ctx *ctx,uint32_t domid,libxl_device_console *console)
tools/libxl/libxl.h +1 -0
@@ -567,6 +567,7 @@ typedef struct {int libxl_device_net2_add (struct libxl_ctx *ctx,uint32_t domid,libxl_device_net2 *net2);libxl_net2info *libxl_device_net2_list (struct libxl_ctx *ctx,uint32_t domid,unsigned int *nb); +int libxl_device_net2_del (struct libxl_ctx *ctx,libxl_device_net2 *net2,int wait);#endif /* LIBXL_H */
tools/libxl/libxl_utils.c +48 -0
54 lines not on this page · raw message
tools/libxl/libxl_utils.h +3 -0
@@ -65,5 +65,8 @@ int libxl_devid_to_device_disk(struct liint libxl_strtomac (const char *mac_s,uint8_t *mac); +int libxl_devid_to_device_net2 (struct libxl_ctx *ctx,uint32_t domid, +const char *devid,libxl_device_net2 *net2); +#endif
tools/libxl/xl.h +1 -0
@@ -74,6 +74,7 @@ int main_tmem_set(int argc, char **argv)int main_tmem_shared_auth (int argc,char **argv);int main_network2attach (int argc,char **argv);int main_network2list (int argc,char **argv); +int main_network2detach (int argc,char **argv);void help (char *command);
tools/libxl/xl_cmdimpl.c +35 -0
@@ -3914,6 +3914,41 @@ int main_network2list(int argc, char **aexit (0 ); } +int main_network2detach (int argc,char **argv) +{ +int opt; +libxl_device_net2 net2; + +if (argc !=4 ) { +help ("network2-detach" ); +exit (0 ); + } +while ((opt =getopt (argc, argv,"h" )) !=-1 ) { +switch (opt) { +case 'h' : +help ("network2-detach" ); +exit (0 ); +default : +fprintf (stderr,"option `%c' not supported.\n" , opt); +break ; + } + } + +if (domain_qualifier_to_domid (argv[2 ], &domid,0 ) <0 ) { +fprintf (stderr,"%s is an invalid domain identifier\n" , argv[2 ]); +exit (1 ); + } +if (libxl_devid_to_device_net2 (&ctx, domid, argv[3 ], &net2)) { +fprintf (stderr,"Error: Device %s not connected.\n" , argv[3 ]); +exit (1 ); + } +if (libxl_device_net2_del (&ctx, &net2,1 )) { +fprintf (stderr,"libxl_device_net2_del failed.\n" ); +exit (1 ); + } +exit (0 ); +} +static char *uptime_to_string (unsigned long time,int short_mode) {int sec, min, hour, day;
tools/libxl/xl_cmdtable.c +5 -0
@@ -300,6 +300,11 @@ struct cmd_spec cmd_table[] = { "list version 2 virtual network interfaces for a domain", "<Domain(s)>", }, + { "network2-detach", + &main_network2detach, + "destroy a domain's version 2 virtual network device", + "<Domain> <DevId>", + }, };int cmdtable_len =sizeof (cmd_table)/sizeof (struct cmd_spec );
PATCH 1/1 xl: block-attach command line parsing
In reply to Eric ChanudetCommand line arguments start at argv[2].
tools/libxl/xl_cmdimpl.c +10 -10
@@ -3629,7 +3629,7 @@ int main_blockattach(int argc, char **aruint32_t fe_domid, be_domid =0 ;libxl_device_disk disk = {0 }; -if ((argc <4 ) || (argc >6 )) { +if ((argc <5 ) || (argc >7 )) {help ("block-attach" );exit (0 ); }
@@ -3644,7 +3644,7 @@ int main_blockattach(int argc, char **ar } } - tok =strtok (argv[2 ],":" ); + tok =strtok (argv[3 ],":" );if (!strcmp (tok,"phy" )) { disk.phystype =PHYSTYPE_PHY ; }else if (!strcmp (tok,"file" )) {
@@ -3672,17 +3672,17 @@ int main_blockattach(int argc, char **arfprintf (stderr,"Error: missing path to disk image.\n" );exit (1 ); } - disk.virtpath = argv[3 ]; + disk.virtpath = argv[4 ]; disk.unpluggable =1 ; - disk.readwrite = (argc <=4 || 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 ]); + disk.readwrite = ((argc <=4 ) || (argv[5 ][0 ] =='w' )); + +if (domain_qualifier_to_domid (argv[2 ], &fe_domid,0 ) <0 ) { +fprintf (stderr,"%s is an invalid domain identifier\n" , argv[2 ]);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 ]); +if (argc ==7 ) { +if (domain_qualifier_to_domid (argv[6 ], &be_domid,0 ) <0 ) { +fprintf (stderr,"%s is an invalid domain identifier\n" , argv[6 ]);exit (1 ); } }
PATCH 1/1 xl: block-list command line parsing
In reply to Eric ChanudetCommand line arguments start at argv[2].
tools/libxl/xl_cmdimpl.c +2 -2
@@ -3701,7 +3701,7 @@ int main_blocklist(int argc, char **argvlibxl_device_disk *disks;libxl_diskinfo diskinfo; -if (argc <2 ) { +if (argc <3 ) {help ("block-list" );exit (0 ); }
@@ -3718,7 +3718,7 @@ int main_blocklist(int argc, char **argvprintf ("%-5s %-3s %-6s %-5s %-6s %-8s %-30s\n" ,"Vdev" ,"BE" ,"handle" ,"state" ,"evt-ch" ,"ring-ref" ,"BE-path" ); -for (++argv, --argc; argc >0 ; --argc, ++argv) { +for (argv +=2 , argc -=2 ; argc >0 ; --argc, ++argv) {if (domain_qualifier_to_domid (*argv, &domid,0 ) <0 ) {fprintf (stderr,"%s is an invalid domain identifier\n" , *argv);continue ;
PATCH 1/1 xl: block-detach command line parsing
In reply to Eric ChanudetCommand line arguments start at argv[2].
tools/libxl/xl_cmdimpl.c +5 -5
@@ -3744,7 +3744,7 @@ int main_blockdetach(int argc, char **arint opt;libxl_device_disk disk; -if (argc !=3 ) { +if (argc !=4 ) {help ("block-detach" );exit (0 ); }
@@ -3759,12 +3759,12 @@ int main_blockdetach(int argc, char **ar } } -if (domain_qualifier_to_domid (argv[1 ], &domid,0 ) <0 ) { -fprintf (stderr,"%s is an invalid domain identifier\n" , argv[1 ]); +if (domain_qualifier_to_domid (argv[2 ], &domid,0 ) <0 ) { +fprintf (stderr,"%s is an invalid domain identifier\n" , argv[2 ]);exit (1 ); } -if (libxl_devid_to_device_disk (&ctx, domid, argv[2 ], &disk)) { -fprintf (stderr,"Error: Device %s not connected.\n" , argv[2 ]); +if (libxl_devid_to_device_disk (&ctx, domid, argv[3 ], &disk)) { +fprintf (stderr,"Error: Device %s not connected.\n" , argv[3 ]);exit (1 ); }if (libxl_device_disk_del (&ctx, &disk,1 )) {
PATCH 1/1 xl: hap parameter handling in configuration file
In reply to Eric ChanudetGet hap parameter from configuration file.
hap parameter can be set to 1 or 0 (default).
tools/libxl/xl_cmdimpl.c +4 -1
@@ -466,7 +466,10 @@ static void parse_config_data(const char !strncmp(buf, "hvm", strlen(buf))) c_info->hvm =1 ; -/* hap is missing */ + c_info->hap =0 ; +if (!xlu_cfg_get_string (config,"hap" , &buf)) + c_info->hap = (buf[0 ] =='1' ); +if (!xlu_cfg_get_string (config,"name" , &buf)) c_info->name =strdup (buf);else