libxl, Handle the command line options of qemu 0.12.
cover libxl, Handle the command line options of qemu 0.12.
From: Anthony PERARD <[email protected]>
This patch gives the ability to the libxl to handle the command line argument of the last qemu version. I begin by checking the version of the device model with '-h' options, '--version' is not handled in qemu-xen. If I found a version upper than 0.12, I use the new command line argument, or else I use the old functions to build args.
The second patch introduces a udev rule to handle tap devices and add them to the bridge instead of using a script called by qemu.
Anthony
Anthony PERARD (2):
libxl, Introduce the command line handler for the new qemu. tools/hotplug, Use udev rules instead of qemu script to setup the
bridge.
tools/hotplug/Linux/vif-bridge | 42 +++++++-- tools/hotplug/Linux/vif-common.sh | 12 ++- tools/hotplug/Linux/xen-backend.rules | 5 +- tools/libxl/libxl.c | 163 ++++++++++++++++++++++++++++++++- tools/libxl/libxl_utils.c | 73 +++++++++++++++ tools/libxl/libxl_utils.h | 5 + 6 files changed, 286 insertions(+), 14 deletions(-)
PATCH 1/2 libxl, Introduce the command line handler for the new qemu.
From: Anthony PERARD <[email protected]>
This patch adds a function to check the version of the device model. Depending on the version of the DM, the command line arguments will be built differently.
--- tools/libxl/libxl.c | 163 ++++++++++++++++++++++++++++++++++++++++++++- tools/libxl/libxl_utils.c | 73 ++++++++++++++++++++ tools/libxl/libxl_utils.h | 5 ++ 3 files changed, 240 insertions(+), 1 deletions(-)
tools/libxl/libxl.c +162 -1
@@ -964,7 +964,7 @@ skip_autopass:return 0 ; } -static char **libxl_build_device_model_args (libxl_ctx *ctx, +static char **libxl_build_device_model_args_old (libxl_ctx *ctx,libxl_device_model_info *info,libxl_device_nic *vifs,int num_vifs)
@@ -1098,10 +1098,171 @@ static char ** libxl_build_device_model_args(libxl_ctx *ctx,else flexarray_set (dm_args, num++,"xenfv" );flexarray_set (dm_args, num++,NULL ); +return (char **)flexarray_contents (dm_args); +} + +static char **libxl_build_device_model_args_new (libxl_ctx *ctx, +libxl_device_model_info *info, +libxl_device_nic *vifs, +int num_vifs) +{ +int num =0 , i; +int new_qemu =0 ; +flexarray_t *dm_args; +int nb; +libxl_device_disk *disks; + + dm_args =flexarray_make (16 ,1 ); +if (!dm_args) +return NULL ; + + new_qemu =libxl_check_device_model_version (ctx, info->device_model); + +flexarray_set (dm_args, num++,"qemu-system-xen" ); +flexarray_set (dm_args, num++,"-xen-domid" ); + +flexarray_set (dm_args, num++,libxl_sprintf (ctx,"%d" , info->domid)); + +if (info->dom_name) { +flexarray_set (dm_args, num++,"-name" ); +flexarray_set (dm_args, num++, info->dom_name); + } +if (info->vnc || info->vncdisplay || info->vnclisten || info->vncunused) { +int display =0 ; +const char *listen ="127.0.0.1" ; + +flexarray_set (dm_args, num++,"-vnc" ); + +if (info->vncdisplay) { + display = info->vncdisplay; +if (info->vnclisten &&strchr (info->vnclisten,':' ) ==NULL ) { + listen = info->vnclisten; + } + }else if (info->vnclisten) { + listen = info->vnclisten; + } + +if (strchr (listen,':' ) !=NULL ) +flexarray_set (dm_args, num++, +libxl_sprintf (ctx,"%s%s" , listen, + info->vncunused ?",to=99" :"" )); +else +flexarray_set (dm_args, num++, +libxl_sprintf (ctx,"%s:%d%s" , listen, display, + info->vncunused ?",to=99" :"" )); + } +if (info->sdl) { +flexarray_set (dm_args, num++,"-sdl" ); + } +if (info->keymap) { +flexarray_set (dm_args, num++,"-k" ); +flexarray_set (dm_args, num++, info->keymap); + } +if (info->nographic && (!info->sdl && !info->vnc)) { +flexarray_set (dm_args, num++,"-nographic" ); + } +if (info->serial) { +flexarray_set (dm_args, num++,"-serial" ); +flexarray_set (dm_args, num++, info->serial); + } +if (info->type ==XENFV ) { +int ioemu_vifs =0 ; +if (info->stdvga) { +flexarray_set (dm_args, num++,"-vga" ); +flexarray_set (dm_args, num++,"std" ); + } + +if (info->boot) { +flexarray_set (dm_args, num++,"-boot" ); +flexarray_set (dm_args, num++,libxl_sprintf (ctx,"order=%s" , info->boot)); + } +if (info->usb || info->usbdevice) { +flexarray_set (dm_args, num++,"-usb" ); +if (info->usbdevice) { +flexarray_set (dm_args, num++,"-usbdevice" ); +flexarray_set (dm_args, num++, info->usbdevice); + } + } +if (info->soundhw) { +flexarray_set (dm_args, num++,"-soundhw" ); +flexarray_set (dm_args, num++, info->soundhw); + } +if (!info->apic) { +flexarray_set (dm_args, num++,"-no-acpi" ); + } +if (info->vcpus >1 ) { +flexarray_set (dm_args, num++,"-smp" ); +if (info->vcpu_avail) +flexarray_set (dm_args, num++,libxl_sprintf (ctx,"%d,maxcpus=%d" , info->vcpus, info->vcpu_avail)); +else +flexarray_set (dm_args, num++,libxl_sprintf (ctx,"%d" , info->vcpus)); + } +for (i =0 ; i < num_vifs; i++) { +if (vifs[i].nictype ==NICTYPE_IOEMU ) { +char *smac =libxl_sprintf (ctx,"%02x:%02x:%02x:%02x:%02x:%02x" , + vifs[i].mac[0 ], vifs[i].mac[1 ], vifs[i].mac[2 ], + vifs[i].mac[3 ], vifs[i].mac[4 ], vifs[i].mac[5 ]); +if (!vifs[i].ifname) + vifs[i].ifname =libxl_sprintf (ctx,"tap%d.%d" , info->domid, vifs[i].devid -1 ); +flexarray_set (dm_args, num++,"-net" ); +flexarray_set (dm_args, num++,libxl_sprintf (ctx,"nic,vlan=%d,macaddr=%s,model=%s" , + vifs[i].devid, smac, vifs[i].model)); +flexarray_set (dm_args, num++,"-net" ); +flexarray_set (dm_args, num++,libxl_sprintf (ctx,"tap,vlan=%d,ifname=%s,script=%s" , + vifs[i].devid, vifs[i].ifname,"/etc/xen/scripts/qemu-ifup" )); + ioemu_vifs++; + } + } +/* If we have no emulated nics, tell qemu not to create any */ +if ( ioemu_vifs ==0 ) { +flexarray_set (dm_args, num++,"-net" ); +flexarray_set (dm_args, num++,"none" ); + } + } +if (info->saved_state) { +flexarray_set (dm_args, num++,"-loadvm" ); +flexarray_set (dm_args, num++, info->saved_state); + } +for (i =0 ; info->extra && info->extra[i] !=NULL ; i++) +flexarray_set (dm_args, num++, info->extra[i]); +flexarray_set (dm_args, num++,"-M" ); +if (info->type ==XENPV ) +flexarray_set (dm_args, num++,"xenpv" ); +else +flexarray_set (dm_args, num++,"xenfv" ); + + disks =libxl_device_disk_list (ctx, info->domid, &nb); +for (; nb >0 ; --nb, ++disks) { +if ( disks->is_cdrom ) { +flexarray_set (dm_args, num++,"-cdrom" ); +flexarray_set (dm_args, num++, disks->physpath); + }else { +flexarray_set (dm_args, num++,libxl_sprintf (ctx,"-%s" , disks->virtpath)); +flexarray_set (dm_args, num++, disks->physpath); + } + } + +flexarray_set (dm_args, num++,NULL );return (char **)flexarray_contents (dm_args); } +static char **libxl_build_device_model_args (libxl_ctx *ctx, +libxl_device_model_info *info, +libxl_device_nic *vifs, +int num_vifs) +{ +int new_qemu; + + new_qemu =libxl_check_device_model_version (ctx, info->device_model); + +if (new_qemu) { +return libxl_build_device_model_args_new (ctx, info, vifs, num_vifs); + }else { +return libxl_build_device_model_args_old (ctx, info, vifs, num_vifs); + } +} +void dm_xenstore_record_pid (void *for_spawn,pid_t innerchild) {libxl_device_model_starting *starting = for_spawn;
tools/libxl/libxl_utils.c +73 -0
76 lines not on this page · raw message
tools/libxl/libxl_utils.h +5 -0
@@ -68,5 +68,10 @@ int libxl_strtomac(const char *mac_s, uint8_t *mac);int libxl_devid_to_device_net2 (libxl_ctx *ctx,uint32_t domid,const char *devid,libxl_device_net2 *net2); +/* check the version of qemu +* return 1 if is the new one +* return 0 if is the old one or if there are an error */ +int libxl_check_device_model_version (libxl_ctx *ctx,char *path); +#endif
Signature · 1 line
1.6.5
Re: [PATCH 1/2] libxl, Introduce the command line handler for the new qemu.
Quoted 12 lines · On Wed, 2010-08-04 at 17:11 +0100, [email protected] wrote:
tools/libxl/libxl_utils.c +12
-0+// Search for the new version or the old version: +// QEMU emulator version 0.12.50, ... +// QEMU PC emulator version 0.10.2, ... +if (strncmp ("QEMU" , buf,4 ) ==0 ) { +char *v =strstr (buf,"version " ); +if (v) { +int major, minor; +char *endptr =NULL ; + + v +=strlen ("version " ); + major =strtol (v, &endptr,10 ); +if (major ==0 && endptr && *endptr =='.' ) {
tools/libxl/libxl_utils.c int libxl_strtomac(const char *mac_s, uint8_t *mac) · line 607
Quoted 10 lines
tools/libxl/libxl_utils.c +10
-0+ v = endptr +1 ; + minor =strtol (v, &endptr,10 ); +if (minor >=12 ) +return 1 ; + } +return 0 ; + } + } +return 0 ; +}
I don't like it. The version number is not a clear indication of parameters especially of patched versions. If you are going to do anything like this then qemu-dm ought to print out QEMU-DM and handle it like that.
As for mainstream qemu, I hear that a future version will contain some capability querying functionality.
Gianni
Re: [PATCH 1/2] libxl, Introduce the command line handler for the new qemu.
In reply to [email protected]Quoted 40 lines · On Wed, 4 Aug 2010, [email protected] wrote:
From: Anthony PERARD <[email protected]>
This patch adds a function to check the version of the device model. Depending on the version of the DM, the command line arguments will be built differently.
Signed-off-by Anthony PERARD <[email protected]>--- tools/libxl/libxl.c | 163 ++++++++++++++++++++++++++++++++++++++++++++- tools/libxl/libxl_utils.c | 73 ++++++++++++++++++++ tools/libxl/libxl_utils.h | 5 ++ 3 files changed, 240 insertions(+), 1 deletions(-)tools/libxl/libxl.c +11
-1@@ -964,7 +964,7 @@ skip_autopass:return 0 ; } -static char **libxl_build_device_model_args (libxl_ctx *ctx, +static char **libxl_build_device_model_args_old (libxl_ctx *ctx,libxl_device_model_info *info,libxl_device_nic *vifs,int num_vifs)@@ -1098,10 +1098,171 @@ static char ** libxl_build_device_model_args(libxl_ctx *ctx,else flexarray_set (dm_args, num++,"xenfv" );flexarray_set (dm_args, num++,NULL ); +return (char **)flexarray_contents (dm_args); +} + +static char **libxl_build_device_model_args_new (libxl_ctx *ctx, +libxl_device_model_info *info, +libxl_device_nic *vifs, +int num_vifs) +{ +int num =0 , i; +int new_qemu =0 ;
tools/libxl/libxl.c static char ** libxl_build_device_model_args(libxl_ctx *ctx, · line 1120
Quoted 10 lines
tools/libxl/libxl.c +10
-0+flexarray_t *dm_args; +int nb; +libxl_device_disk *disks; + + dm_args =flexarray_make (16 ,1 ); +if (!dm_args) +return NULL ; + + new_qemu =libxl_check_device_model_version (ctx, info->device_model); +
do we actually need to call libxl_check_device_model_version again here?
Quoted 219 lines
tools/libxl/libxl.c +141
-0+flexarray_set (dm_args, num++,"qemu-system-xen" ); +flexarray_set (dm_args, num++,"-xen-domid" ); + +flexarray_set (dm_args, num++,libxl_sprintf (ctx,"%d" , info->domid)); + +if (info->dom_name) { +flexarray_set (dm_args, num++,"-name" ); +flexarray_set (dm_args, num++, info->dom_name); + } +if (info->vnc || info->vncdisplay || info->vnclisten || info->vncunused) { +int display =0 ; +const char *listen ="127.0.0.1" ; + +flexarray_set (dm_args, num++,"-vnc" ); + +if (info->vncdisplay) { + display = info->vncdisplay; +if (info->vnclisten &&strchr (info->vnclisten,':' ) ==NULL ) { + listen = info->vnclisten; + } + }else if (info->vnclisten) { + listen = info->vnclisten; + } + +if (strchr (listen,':' ) !=NULL ) +flexarray_set (dm_args, num++, +libxl_sprintf (ctx,"%s%s" , listen, + info->vncunused ?",to=99" :"" )); +else +flexarray_set (dm_args, num++, +libxl_sprintf (ctx,"%s:%d%s" , listen, display, + info->vncunused ?",to=99" :"" )); + } +if (info->sdl) { +flexarray_set (dm_args, num++,"-sdl" ); + } +if (info->keymap) { +flexarray_set (dm_args, num++,"-k" ); +flexarray_set (dm_args, num++, info->keymap); + } +if (info->nographic && (!info->sdl && !info->vnc)) { +flexarray_set (dm_args, num++,"-nographic" ); + } +if (info->serial) { +flexarray_set (dm_args, num++,"-serial" ); +flexarray_set (dm_args, num++, info->serial); + } +if (info->type ==XENFV ) { +int ioemu_vifs =0 ; +if (info->stdvga) { +flexarray_set (dm_args, num++,"-vga" ); +flexarray_set (dm_args, num++,"std" ); + } + +if (info->boot) { +flexarray_set (dm_args, num++,"-boot" ); +flexarray_set (dm_args, num++,libxl_sprintf (ctx,"order=%s" , info->boot)); + } +if (info->usb || info->usbdevice) { +flexarray_set (dm_args, num++,"-usb" ); +if (info->usbdevice) { +flexarray_set (dm_args, num++,"-usbdevice" ); +flexarray_set (dm_args, num++, info->usbdevice); + } + } +if (info->soundhw) { +flexarray_set (dm_args, num++,"-soundhw" ); +flexarray_set (dm_args, num++, info->soundhw); + } +if (!info->apic) { +flexarray_set (dm_args, num++,"-no-acpi" ); + } +if (info->vcpus >1 ) { +flexarray_set (dm_args, num++,"-smp" ); +if (info->vcpu_avail) +flexarray_set (dm_args, num++,libxl_sprintf (ctx,"%d,maxcpus=%d" , info->vcpus, info->vcpu_avail)); +else +flexarray_set (dm_args, num++,libxl_sprintf (ctx,"%d" , info->vcpus)); + } +for (i =0 ; i < num_vifs; i++) { +if (vifs[i].nictype ==NICTYPE_IOEMU ) { +char *smac =libxl_sprintf (ctx,"%02x:%02x:%02x:%02x:%02x:%02x" , + vifs[i].mac[0 ], vifs[i].mac[1 ], vifs[i].mac[2 ], + vifs[i].mac[3 ], vifs[i].mac[4 ], vifs[i].mac[5 ]); +if (!vifs[i].ifname) + vifs[i].ifname =libxl_sprintf (ctx,"tap%d.%d" , info->domid, vifs[i].devid -1 ); +flexarray_set (dm_args, num++,"-net" ); +flexarray_set (dm_args, num++,libxl_sprintf (ctx,"nic,vlan=%d,macaddr=%s,model=%s" , + vifs[i].devid, smac, vifs[i].model)); +flexarray_set (dm_args, num++,"-net" ); +flexarray_set (dm_args, num++,libxl_sprintf (ctx,"tap,vlan=%d,ifname=%s,script=%s" , + vifs[i].devid, vifs[i].ifname,"/etc/xen/scripts/qemu-ifup" )); + ioemu_vifs++; + } + } +/* If we have no emulated nics, tell qemu not to create any */ +if ( ioemu_vifs ==0 ) { +flexarray_set (dm_args, num++,"-net" ); +flexarray_set (dm_args, num++,"none" ); + } + } +if (info->saved_state) { +flexarray_set (dm_args, num++,"-loadvm" ); +flexarray_set (dm_args, num++, info->saved_state); + } +for (i =0 ; info->extra && info->extra[i] !=NULL ; i++) +flexarray_set (dm_args, num++, info->extra[i]); +flexarray_set (dm_args, num++,"-M" ); +if (info->type ==XENPV ) +flexarray_set (dm_args, num++,"xenpv" ); +else +flexarray_set (dm_args, num++,"xenfv" ); + + disks =libxl_device_disk_list (ctx, info->domid, &nb); +for (; nb >0 ; --nb, ++disks) { +if ( disks->is_cdrom ) { +flexarray_set (dm_args, num++,"-cdrom" ); +flexarray_set (dm_args, num++, disks->physpath); + }else { +flexarray_set (dm_args, num++,libxl_sprintf (ctx,"-%s" , disks->virtpath)); +flexarray_set (dm_args, num++, disks->physpath); + } + } + +flexarray_set (dm_args, num++,NULL );return (char **)flexarray_contents (dm_args); } +static char **libxl_build_device_model_args (libxl_ctx *ctx, +libxl_device_model_info *info, +libxl_device_nic *vifs, +int num_vifs) +{ +int new_qemu; + + new_qemu =libxl_check_device_model_version (ctx, info->device_model); + +if (new_qemu) { +return libxl_build_device_model_args_new (ctx, info, vifs, num_vifs); + }else { +return libxl_build_device_model_args_old (ctx, info, vifs, num_vifs); + } +} +void dm_xenstore_record_pid (void *for_spawn,pid_t innerchild) {libxl_device_model_starting *starting = for_spawn;tools/libxl/libxl_utils.c +63
-0@@ -532,3 +532,76 @@ int libxl_strtomac(const char *mac_s, uint8_t *mac) }return 0 ; } + +int libxl_check_device_model_version (libxl_ctx *ctx,char *path) +{ +pid_t pid =-1 ; +int pipefd[2 ]; +char buf[100 ]; +ssize_t i, count =0 ; +int status; +char *abs_path =NULL ; + + abs_path =libxl_abs_path (ctx, path,libxl_private_bindir_path ()); + +if (pipe (pipefd)) +return 0 ; + + pid =fork (); +if (pid ==-1 ) { +return 0 ; + } + +if (!pid) { +close (pipefd[0 ]); +if (dup2 (pipefd[1 ],STDOUT_FILENO ) ==-1 ) +exit (1 ); +execlp (abs_path, abs_path,"-h" ,NULL ); + +close (pipefd[1 ]); +exit (127 ); + } + +close (pipefd[1 ]); +if (abs_path != path) +libxl_free (ctx, abs_path); + +// attempt to get the first line of `qemu -h` +while ((i =read (pipefd[0 ], buf + count,99 - count)) >0 ) { +if (i + count >90 ) +break ; +for (int j =0 ; j < i; j++) { +if (buf[j + count] =='\n' ) +break ; + } + count += i; + } + count += i; +close (pipefd[0 ]); +waitpid (pid, &status,0 ); +if (!WIFEXITED (status) ||WEXITSTATUS (status) !=0 ) { +return 0 ; + } + +// Search for the new version or the old version: +// QEMU emulator version 0.12.50, ... +// QEMU PC emulator version 0.10.2, ... +if (strncmp ("QEMU" , buf,4 ) ==0 ) { +char *v =strstr (buf,"version " ); +if (v) { +int major, minor; +char *endptr =NULL ; + + v +=strlen ("version " ); + major =strtol (v, &endptr,10 ); +if (major ==0 && endptr && *endptr =='.' ) {
tools/libxl/libxl_utils.c int libxl_strtomac(const char *mac_s, uint8_t *mac) · line 607
Quoted 10 lines
tools/libxl/libxl_utils.c +10
-0+ v = endptr +1 ; + minor =strtol (v, &endptr,10 ); +if (minor >=12 ) +return 1 ; + } +return 0 ; + } + } +return 0 ; +}
Please use C style comments.
I think Gianni is right about the string to search: it is probably better to add a Xen specific string to qemu-dm, like "QEMU-DM", and rely on that and the version (0.10.2 or older) to distinguish between the two.
Quoted 24 lines
tools/libxl/libxl_utils.h +5
-1@@ -68,5 +68,10 @@ int libxl_strtomac(const char *mac_s, uint8_t *mac);int libxl_devid_to_device_net2 (libxl_ctx *ctx,uint32_t domid,const char *devid,libxl_device_net2 *net2); +/* check the version of qemu +* return 1 if is the new one +* return 0 if is the old one or if there are an error */ +int libxl_check_device_model_version (libxl_ctx *ctx,char *path); +#endif --1.6.5
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Re: [PATCH 1/2] libxl, Introduce the command line handler for the new qemu.
Quoted 35 lines · Stefano Stabellini
Quoted 34 lines · On Wed, 4 Aug 2010, [email protected] wrote:
From: Anthony PERARD <[email protected]>
This patch adds a function to check the version of the device model. Depending on the version of the DM, the command line arguments will be built differently.
Signed-off-by Anthony PERARD <[email protected]>--- tools/libxl/libxl.c | 163 ++++++++++++++++++++++++++++++++++++++++++++- tools/libxl/libxl_utils.c | 73 ++++++++++++++++++++ tools/libxl/libxl_utils.h | 5 ++ 3 files changed, 240 insertions(+), 1 deletions(-)[...]
tools/libxl/libxl_utils.c +19
-0+// Search for the new version or the old version: +// QEMU emulator version 0.12.50, ... +// QEMU PC emulator version 0.10.2, ... +if (strncmp ("QEMU" , buf,4 ) ==0 ) { +char *v =strstr (buf,"version " ); +if (v) { +int major, minor; +char *endptr =NULL ; + + v +=strlen ("version " ); + major =strtol (v, &endptr,10 ); +if (major ==0 && endptr && *endptr =='.' ) { + v = endptr +1 ; + minor =strtol (v, &endptr,10 ); +if (minor >=12 ) +return 1 ; + } +return 0 ; + }
Quoted 8 lines
tools/libxl/libxl_utils.c int libxl_strtomac(const char *mac_s, uint8_t *mac) · line 584
Quoted 3 lines
tools/libxl/libxl_utils.c +3
-0+ } +return 0 ; +}I think Gianni is right about the string to search: it is probably better to add a Xen specific string to qemu-dm, like "QEMU-DM", and rely on that and the version (0.10.2 or older) to distinguish between the two.
I can do something better by run "qemu -M ?" and check if "xenfv" machine is supported. This work with both versions.
Signature · 1 line
Anthony PERARD
Re: [PATCH 1/2] libxl, Introduce the command line handler for the new qemu.
Quoted 45 lines · Anthony Perard
Quoted 35 lines · Stefano Stabellini
Quoted 34 lines · On Wed, 4 Aug 2010, [email protected] wrote:
From: Anthony PERARD <[email protected]>
This patch adds a function to check the version of the device model. Depending on the version of the DM, the command line arguments will be built differently.
Signed-off-by Anthony PERARD <[email protected]>--- tools/libxl/libxl.c | 163 ++++++++++++++++++++++++++++++++++++++++++++- tools/libxl/libxl_utils.c | 73 ++++++++++++++++++++ tools/libxl/libxl_utils.h | 5 ++ 3 files changed, 240 insertions(+), 1 deletions(-)[...]
tools/libxl/libxl_utils.c +19
-0+// Search for the new version or the old version: +// QEMU emulator version 0.12.50, ... +// QEMU PC emulator version 0.10.2, ... +if (strncmp ("QEMU" , buf,4 ) ==0 ) { +char *v =strstr (buf,"version " ); +if (v) { +int major, minor; +char *endptr =NULL ; + + v +=strlen ("version " ); + major =strtol (v, &endptr,10 ); +if (major ==0 && endptr && *endptr =='.' ) { + v = endptr +1 ; + minor =strtol (v, &endptr,10 ); +if (minor >=12 ) +return 1 ; + } +return 0 ; + }Quoted 8 lines
tools/libxl/libxl_utils.c int libxl_strtomac(const char *mac_s, uint8_t *mac) · line 584
Quoted 3 lines
tools/libxl/libxl_utils.c +3
-0+ } +return 0 ; +}I think Gianni is right about the string to search: it is probably better to add a Xen specific string to qemu-dm, like "QEMU-DM", and rely on that and the version (0.10.2 or older) to distinguish between the two.
Quoted 2 lines
I can do something better by run "qemu -M ?" and check if "xenfv" machine is supported. This work with both versions.
Yes but this is the problem exactly. The output of this does not correlate to which set of command-line options are supported.
We cannot predict the future as to precisely what form any merge to qemu upstream will take. Our only reliable choice is to add something new and deliberately non-standardized to existing qemu-xen fork and detect that.
Gianni
Re: [PATCH 1/2] libxl, Introduce the command line handler for the new qemu.
Quoted 7 lines · On Thu, 5 Aug 2010, Gianni Tedesco (3P) wrote:
Yes but this is the problem exactly. The output of this does not correlate to which set of command-line options are supported.
We cannot predict the future as to precisely what form any merge to qemu upstream will take. Our only reliable choice is to add something new and deliberately non-standardized to existing qemu-xen fork and detect that.
That and also hope that if in the future qemu changes command line options it will bump version number.
Re: [PATCH 1/2] libxl, Introduce the command line handler for the new qemu.
Quoted 11 lines · Stefano Stabellini
Quoted 7 lines · On Thu, 5 Aug 2010, Gianni Tedesco (3P) wrote:
Yes but this is the problem exactly. The output of this does not correlate to which set of command-line options are supported.
We cannot predict the future as to precisely what form any merge to qemu upstream will take. Our only reliable choice is to add something new and deliberately non-standardized to existing qemu-xen fork and detect that.
That and also hope that if in the future qemu changes command line options it will bump version number.
Indeed, but this is apparently also a problem for libvirt which qemu maintainers care deeply about so I think there will be a solution for that more along the lines of capability querying returning JSON data objects but that is just speculation at this point AFAIK.
PATCH 1/1 Change the first line of help to add 'QEMU-DM'.
In reply to Gianni TedescoFrom: Anthony PERARD <[email protected]>
Add QEMU-DM at the beginning of the help message. With that, xl can detect the forked version of qemu and build the correct command line.
--- vl.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
vl.c +1 -1
@@ -3990,7 +3990,7 @@ static void help(int exitcode) {/* Please keep in synch with QEMU_OPTION_ enums, qemu_options[] and qemu-doc.texi */ -printf ("QEMU PC emulator version " QEMU_VERSION ", Copyright (c) 2003-2008 Fabrice Bellard\n" +printf ("QEMU-DM emulator version " QEMU_VERSION ", Copyright (c) 2003-2008 Fabrice Bellard\n" "usage: %s [options] [disk_image]\n" "\n" "'disk_image' is a raw hard image image for IDE hard disk 0\n"
Signature · 1 line
1.6.5
PATCH v2 1/2 tools/hotplug, Use udev rules instead of qemu script to setup the bridge.
In reply to Gianni TedescoFrom: Anthony PERARD <[email protected]>
This patch adds a second argument to vif-bridge script. It can be "vif" or "tap". "vif" give the default behavior and "tap" just add the interface to the found bridge when the action is "add".
--- tools/hotplug/Linux/vif-bridge | 42 +++++++++++++++++++++++++++----- tools/hotplug/Linux/vif-common.sh | 12 ++++++--- tools/hotplug/Linux/xen-backend.rules | 5 ++- tools/libxl/libxl.c | 4 +- 4 files changed, 48 insertions(+), 15 deletions(-)
tools/hotplug/Linux/vif-bridge +35 -7
@@ -29,6 +29,13 @@ # rules for its ip addresses (if any). #============================================================================ +# Older versions of Xen do not pass in the type as an argument +if [ $# -lt 2 ]; then + type_if=vif +else + type_if=$2 +fi + dir=$(dirname "$0") . "$dir/vif-common.sh"
@@ -79,22 +86,43 @@ then fatal "Could not find bridge device $bridge" fi +case "$type_if" in + vif) + dev=$vif + ;; + tap) + dev=$INTERFACE + ;; +esac + case "$command" in online) - setup_bridge_port "$vif" - add_to_bridge "$bridge" "$vif" + if [ "$type_if" = vif ]; then + setup_bridge_port "$vif" + add_to_bridge "$bridge" "$vif" + fi ;; offline) - do_without_error brctl delif "$bridge" "$vif" - do_without_error ifconfig "$vif" down + if [ "$type_if" = vif ]; then + do_without_error brctl delif "$bridge" "$vif" + do_without_error ifconfig "$vif" down + fi + ;; + + add) + if [ "$type_if" = tap ]; then + add_to_bridge "$bridge" "$dev" + fi ;; esac -handle_iptable +if [ "$type_if" = vif ]; then + handle_iptable +fi -log debug "Successful vif-bridge $command for $vif, bridge $bridge." -if [ "$command" == "online" ] +log debug "Successful vif-bridge $command for $dev, bridge $bridge." +if [ "$type_if" = vif -a "$command" = "online" ] then success fi
tools/hotplug/Linux/vif-common.sh +8 -4
@@ -33,7 +33,9 @@ fi case "$command" in add | remove) - exit 0 + if [ "$type_if" != tap ]; then + exit 0 + fi ;; esac
@@ -48,9 +50,11 @@ evalVariables "$@" ip=${ip:-} ip=$(xenstore_read_default "$XENBUS_PATH/ip" "$ip") -# Check presence of compulsory args. -XENBUS_PATH="${XENBUS_PATH:?}" -vif="${vif:?}" +if [ "$type_if" != tap ]; then + # Check presence of compulsory args. + XENBUS_PATH="${XENBUS_PATH:?}" + vif="${vif:?}" +fi vifname=$(xenstore_read_default "$XENBUS_PATH/vifname" "")
tools/hotplug/Linux/xen-backend.rules +3 -2
@@ -2,10 +2,11 @@ SUBSYSTEM=="xen-backend", KERNEL=="tap*", RUN+="/etc/xen/scripts/blktap $env{ACT SUBSYSTEM=="xen-backend", KERNEL=="vbd*", RUN+="/etc/xen/scripts/block $env{ACTION}" SUBSYSTEM=="xen-backend", KERNEL=="vtpm*", RUN+="/etc/xen/scripts/vtpm $env{ACTION}" SUBSYSTEM=="xen-backend", KERNEL=="vif2-*", RUN+="/etc/xen/scripts/vif2 $env{ACTION}" -SUBSYSTEM=="xen-backend", KERNEL=="vif-*", ACTION=="online", RUN+="/etc/xen/scripts/vif-setup online" -SUBSYSTEM=="xen-backend", KERNEL=="vif-*", ACTION=="offline", RUN+="/etc/xen/scripts/vif-setup offline" +SUBSYSTEM=="xen-backend", KERNEL=="vif-*", ACTION=="online", RUN+="/etc/xen/scripts/vif-setup online vif" +SUBSYSTEM=="xen-backend", KERNEL=="vif-*", ACTION=="offline", RUN+="/etc/xen/scripts/vif-setup offline vif" SUBSYSTEM=="xen-backend", KERNEL=="vscsi*", RUN+="/etc/xen/scripts/vscsi $env{ACTION}" SUBSYSTEM=="xen-backend", ACTION=="remove", RUN+="/etc/xen/scripts/xen-hotplug-cleanup" KERNEL=="evtchn", NAME="xen/%k" KERNEL=="blktap[0-9]*", NAME="xen/%k" KERNEL=="pci_iomul", NAME="xen/%k" +SUBSYSTEM=="net", KERNEL=="tap*", ACTION=="add", RUN+="/etc/xen/scripts/vif-setup $env{ACTION} tap"
tools/libxl/libxl.c +2 -2
@@ -1206,8 +1206,8 @@ static char ** libxl_build_device_model_args_new(libxl_ctx *ctx,flexarray_set (dm_args, num++,libxl_sprintf (ctx,"nic,vlan=%d,macaddr=%s,model=%s" , vifs[i].devid, smac, vifs[i].model));flexarray_set (dm_args, num++,"-net" ); -flexarray_set (dm_args, num++,libxl_sprintf (ctx,"tap,vlan=%d,ifname=%s,script=%s" , - vifs[i].devid, vifs[i].ifname,"/etc/xen/scripts/qemu-ifup" )); +flexarray_set (dm_args, num++,libxl_sprintf (ctx,"tap,vlan=%d,ifname=%s,script=no" , + vifs[i].devid, vifs[i].ifname)); ioemu_vifs++; } }
Signature · 1 line
1.6.5
Re: [PATCH v2 1/2] tools/hotplug, Use udev rules instead of qemu script to setup the bridge.
Quoted 6 lines · Anthony Perard
From: Anthony PERARD <[email protected]>
This patch adds a second argument to vif-bridge script. It can be "vif" or "tap". "vif" give the default behavior and "tap" just add the interface to the found bridge when the action is "add".
Quoted 7 lines
Signed-off-by Anthony PERARD <[email protected]>--- tools/hotplug/Linux/vif-bridge | 42 +++++++++++++++++++++++++++----- tools/hotplug/Linux/vif-common.sh | 12 ++++++--- tools/hotplug/Linux/xen-backend.rules | 5 ++- tools/libxl/libxl.c | 4 +- 4 files changed, 48 insertions(+), 15 deletions(-)
Sorry, wrong patch, this one is not updated...
Signature · 1 line
Anthony PERARD
PATCH v2 1/2 libxl, Introduce the command line handler for the new qemu.
In reply to Gianni TedescoFrom: Anthony PERARD <[email protected]>
This patch adds a function to check the version of the device model. Depending on the version of the DM, the command line arguments will be built differently.
--- tools/libxl/libxl.c | 160 ++++++++++++++++++++++++++++++++++++++++++++- tools/libxl/libxl_utils.c | 78 ++++++++++++++++++++++ tools/libxl/libxl_utils.h | 6 ++ 3 files changed, 243 insertions(+), 1 deletions(-)
tools/libxl/libxl.c +159 -1
@@ -964,7 +964,7 @@ skip_autopass:return 0 ; } -static char **libxl_build_device_model_args (libxl_ctx *ctx, +static char **libxl_build_device_model_args_old (libxl_ctx *ctx,libxl_device_model_info *info,libxl_device_nic *vifs,int num_vifs)
@@ -1098,10 +1098,168 @@ static char ** libxl_build_device_model_args(libxl_ctx *ctx,else flexarray_set (dm_args, num++,"xenfv" );flexarray_set (dm_args, num++,NULL ); +return (char **)flexarray_contents (dm_args); +} + +static char **libxl_build_device_model_args_new (libxl_ctx *ctx, +libxl_device_model_info *info, +libxl_device_nic *vifs, +int num_vifs) +{ +int num =0 , i; +flexarray_t *dm_args; +int nb; +libxl_device_disk *disks; + + dm_args =flexarray_make (16 ,1 ); +if (!dm_args) +return NULL ; + +flexarray_set (dm_args, num++,"qemu-system-xen" ); +flexarray_set (dm_args, num++,"-xen-domid" ); + +flexarray_set (dm_args, num++,libxl_sprintf (ctx,"%d" , info->domid)); + +if (info->dom_name) { +flexarray_set (dm_args, num++,"-name" ); +flexarray_set (dm_args, num++, info->dom_name); + } +if (info->vnc || info->vncdisplay || info->vnclisten || info->vncunused) { +int display =0 ; +const char *listen ="127.0.0.1" ; + +flexarray_set (dm_args, num++,"-vnc" ); + +if (info->vncdisplay) { + display = info->vncdisplay; +if (info->vnclisten &&strchr (info->vnclisten,':' ) ==NULL ) { + listen = info->vnclisten; + } + }else if (info->vnclisten) { + listen = info->vnclisten; + } + +if (strchr (listen,':' ) !=NULL ) +flexarray_set (dm_args, num++, +libxl_sprintf (ctx,"%s%s" , listen, + info->vncunused ?",to=99" :"" )); +else +flexarray_set (dm_args, num++, +libxl_sprintf (ctx,"%s:%d%s" , listen, display, + info->vncunused ?",to=99" :"" )); + } +if (info->sdl) { +flexarray_set (dm_args, num++,"-sdl" ); + } +if (info->keymap) { +flexarray_set (dm_args, num++,"-k" ); +flexarray_set (dm_args, num++, info->keymap); + } +if (info->nographic && (!info->sdl && !info->vnc)) { +flexarray_set (dm_args, num++,"-nographic" ); + } +if (info->serial) { +flexarray_set (dm_args, num++,"-serial" ); +flexarray_set (dm_args, num++, info->serial); + } +if (info->type ==XENFV ) { +int ioemu_vifs =0 ; + +if (info->stdvga) { +flexarray_set (dm_args, num++,"-vga" ); +flexarray_set (dm_args, num++,"std" ); + } + +if (info->boot) { +flexarray_set (dm_args, num++,"-boot" ); +flexarray_set (dm_args, num++,libxl_sprintf (ctx,"order=%s" , info->boot)); + } +if (info->usb || info->usbdevice) { +flexarray_set (dm_args, num++,"-usb" ); +if (info->usbdevice) { +flexarray_set (dm_args, num++,"-usbdevice" ); +flexarray_set (dm_args, num++, info->usbdevice); + } + } +if (info->soundhw) { +flexarray_set (dm_args, num++,"-soundhw" ); +flexarray_set (dm_args, num++, info->soundhw); + } +if (!info->apic) { +flexarray_set (dm_args, num++,"-no-acpi" ); + } +if (info->vcpus >1 ) { +flexarray_set (dm_args, num++,"-smp" ); +if (info->vcpu_avail) +flexarray_set (dm_args, num++,libxl_sprintf (ctx,"%d,maxcpus=%d" , info->vcpus, info->vcpu_avail)); +else +flexarray_set (dm_args, num++,libxl_sprintf (ctx,"%d" , info->vcpus)); + } +for (i =0 ; i < num_vifs; i++) { +if (vifs[i].nictype ==NICTYPE_IOEMU ) { +char *smac =libxl_sprintf (ctx,"%02x:%02x:%02x:%02x:%02x:%02x" , + vifs[i].mac[0 ], vifs[i].mac[1 ], vifs[i].mac[2 ], + vifs[i].mac[3 ], vifs[i].mac[4 ], vifs[i].mac[5 ]); +if (!vifs[i].ifname) + vifs[i].ifname =libxl_sprintf (ctx,"tap%d.%d" , info->domid, vifs[i].devid -1 ); +flexarray_set (dm_args, num++,"-net" ); +flexarray_set (dm_args, num++,libxl_sprintf (ctx,"nic,vlan=%d,macaddr=%s,model=%s" , + vifs[i].devid, smac, vifs[i].model)); +flexarray_set (dm_args, num++,"-net" ); +flexarray_set (dm_args, num++,libxl_sprintf (ctx,"tap,vlan=%d,ifname=%s,script=%s" , + vifs[i].devid, vifs[i].ifname,"/etc/xen/scripts/qemu-ifup" )); + ioemu_vifs++; + } + } +/* If we have no emulated nics, tell qemu not to create any */ +if ( ioemu_vifs ==0 ) { +flexarray_set (dm_args, num++,"-net" ); +flexarray_set (dm_args, num++,"none" ); + } + } +if (info->saved_state) { +flexarray_set (dm_args, num++,"-loadvm" ); +flexarray_set (dm_args, num++, info->saved_state); + } +for (i =0 ; info->extra && info->extra[i] !=NULL ; i++) +flexarray_set (dm_args, num++, info->extra[i]); +flexarray_set (dm_args, num++,"-M" ); +if (info->type ==XENPV ) +flexarray_set (dm_args, num++,"xenpv" ); +else +flexarray_set (dm_args, num++,"xenfv" ); + disks =libxl_device_disk_list (ctx, info->domid, &nb); +for (; nb >0 ; --nb, ++disks) { +if ( disks->is_cdrom ) { +flexarray_set (dm_args, num++,"-cdrom" ); +flexarray_set (dm_args, num++, disks->physpath); + }else { +flexarray_set (dm_args, num++,libxl_sprintf (ctx,"-%s" , disks->virtpath)); +flexarray_set (dm_args, num++, disks->physpath); + } + } + +flexarray_set (dm_args, num++,NULL );return (char **)flexarray_contents (dm_args); } +static char **libxl_build_device_model_args (libxl_ctx *ctx, +libxl_device_model_info *info, +libxl_device_nic *vifs, +int num_vifs) +{ +int new_qemu; + + new_qemu =libxl_check_device_model_version (ctx, info->device_model); + +if (new_qemu ==1 ) { +return libxl_build_device_model_args_new (ctx, info, vifs, num_vifs); + }else { +return libxl_build_device_model_args_old (ctx, info, vifs, num_vifs); + } +} +void dm_xenstore_record_pid (void *for_spawn,pid_t innerchild) {libxl_device_model_starting *starting = for_spawn;
tools/libxl/libxl_utils.c +78 -0
81 lines not on this page · raw message
tools/libxl/libxl_utils.h +6 -0
@@ -68,5 +68,11 @@ int libxl_strtomac(const char *mac_s, uint8_t *mac);int libxl_devid_to_device_net2 (libxl_ctx *ctx,uint32_t domid,const char *devid,libxl_device_net2 *net2); +/* check the version of qemu +* return 1 if is the new one +* return 0 if is the old one +* return -1 if there are an error */ +int libxl_check_device_model_version (libxl_ctx *ctx,char *path); +#endif
Signature · 1 line
1.6.5
PATCH 2/2 tools/hotplug, Use udev rules instead of qemu script to setup the bridge.
In reply to [email protected]From: Anthony PERARD <[email protected]>
This patch adds a second argument to vif-bridge script. It can be "vif" or "tap". "vif" give the default behavior and "tap" just add the interface to the found bridge when the action is "add".
--- tools/hotplug/Linux/vif-bridge | 42 +++++++++++++++++++++++++++----- tools/hotplug/Linux/vif-common.sh | 12 ++++++--- tools/hotplug/Linux/xen-backend.rules | 5 ++- tools/libxl/libxl.c | 4 +- 4 files changed, 48 insertions(+), 15 deletions(-)
tools/hotplug/Linux/vif-bridge +35 -7
@@ -29,6 +29,13 @@ # rules for its ip addresses (if any). #============================================================================ +# Older versions of Xen do not pass in the type as an argument +if [ $# -lt 2 ]; then + type_if=vif +else + type_if=$2 +fi + dir=$(dirname "$0") . "$dir/vif-common.sh"
@@ -79,22 +86,43 @@ then fatal "Could not find bridge device $bridge" fi +case "$type_if" in + vif) + dev=$vif + ;; + tap) + dev=$INTERFACE + ;; +esac + case "$command" in online) - setup_bridge_port "$vif" - add_to_bridge "$bridge" "$vif" + if [ "$type_if" = vif ]; then + setup_bridge_port "$vif" + add_to_bridge "$bridge" "$vif" + fi ;; offline) - do_without_error brctl delif "$bridge" "$vif" - do_without_error ifconfig "$vif" down + if [ "$type_if" = vif ]; then + do_without_error brctl delif "$bridge" "$vif" + do_without_error ifconfig "$vif" down + fi + ;; + + add) + if [ "$type_if" = tap ]; then + add_to_bridge "$bridge" "$dev" + fi ;; esac -handle_iptable +if [ "$type_if" = vif ]; then + handle_iptable +fi -log debug "Successful vif-bridge $command for $vif, bridge $bridge." -if [ "$command" == "online" ] +log debug "Successful vif-bridge $command for $dev, bridge $bridge." +if [ "$type_if" = vif -a "$command" = "online" ] then success fi
tools/hotplug/Linux/vif-common.sh +8 -4
@@ -33,7 +33,9 @@ fi case "$command" in add | remove) - exit 0 + if [ "$type_if" != tap ]; then + exit 0 + fi ;; esac
@@ -48,9 +50,11 @@ evalVariables "$@" ip=${ip:-} ip=$(xenstore_read_default "$XENBUS_PATH/ip" "$ip") -# Check presence of compulsory args. -XENBUS_PATH="${XENBUS_PATH:?}" -vif="${vif:?}" +if [ "$type_if" != tap ]; then + # Check presence of compulsory args. + XENBUS_PATH="${XENBUS_PATH:?}" + vif="${vif:?}" +fi vifname=$(xenstore_read_default "$XENBUS_PATH/vifname" "")
tools/hotplug/Linux/xen-backend.rules +3 -2
@@ -2,10 +2,11 @@ SUBSYSTEM=="xen-backend", KERNEL=="tap*", RUN+="/etc/xen/scripts/blktap $env{ACT SUBSYSTEM=="xen-backend", KERNEL=="vbd*", RUN+="/etc/xen/scripts/block $env{ACTION}" SUBSYSTEM=="xen-backend", KERNEL=="vtpm*", RUN+="/etc/xen/scripts/vtpm $env{ACTION}" SUBSYSTEM=="xen-backend", KERNEL=="vif2-*", RUN+="/etc/xen/scripts/vif2 $env{ACTION}" -SUBSYSTEM=="xen-backend", KERNEL=="vif-*", ACTION=="online", RUN+="/etc/xen/scripts/vif-setup online" -SUBSYSTEM=="xen-backend", KERNEL=="vif-*", ACTION=="offline", RUN+="/etc/xen/scripts/vif-setup offline" +SUBSYSTEM=="xen-backend", KERNEL=="vif-*", ACTION=="online", RUN+="/etc/xen/scripts/vif-setup online vif" +SUBSYSTEM=="xen-backend", KERNEL=="vif-*", ACTION=="offline", RUN+="/etc/xen/scripts/vif-setup offline vif" SUBSYSTEM=="xen-backend", KERNEL=="vscsi*", RUN+="/etc/xen/scripts/vscsi $env{ACTION}" SUBSYSTEM=="xen-backend", ACTION=="remove", RUN+="/etc/xen/scripts/xen-hotplug-cleanup" KERNEL=="evtchn", NAME="xen/%k" KERNEL=="blktap[0-9]*", NAME="xen/%k" KERNEL=="pci_iomul", NAME="xen/%k" +SUBSYSTEM=="net", KERNEL=="tap*", ACTION=="add", RUN+="/etc/xen/scripts/vif-setup $env{ACTION} tap"
tools/libxl/libxl.c +2 -2
@@ -1209,8 +1209,8 @@ static char ** libxl_build_device_model_args_new(libxl_ctx *ctx,flexarray_set (dm_args, num++,libxl_sprintf (ctx,"nic,vlan=%d,macaddr=%s,model=%s" , vifs[i].devid, smac, vifs[i].model));flexarray_set (dm_args, num++,"-net" ); -flexarray_set (dm_args, num++,libxl_sprintf (ctx,"tap,vlan=%d,ifname=%s,script=%s" , - vifs[i].devid, vifs[i].ifname,"/etc/xen/scripts/qemu-ifup" )); +flexarray_set (dm_args, num++,libxl_sprintf (ctx,"tap,vlan=%d,ifname=%s,script=no" , + vifs[i].devid, vifs[i].ifname)); ioemu_vifs++; } }
Signature · 1 line
1.6.5
Re: [PATCH 2/2] tools/hotplug, Use udev rules instead of qemu script to setup the bridge.
Quoted 60 lines · On Wed, 4 Aug 2010, [email protected] wrote:
From: Anthony PERARD <[email protected]>
This patch adds a second argument to vif-bridge script. It can be "vif" or "tap". "vif" give the default behavior and "tap" just add the interface to the found bridge when the action is "add".
Signed-off-by Anthony PERARD <[email protected]>--- tools/hotplug/Linux/vif-bridge | 42 +++++++++++++++++++++++++++----- tools/hotplug/Linux/vif-common.sh | 12 ++++++--- tools/hotplug/Linux/xen-backend.rules | 5 ++- tools/libxl/libxl.c | 4 +- 4 files changed, 48 insertions(+), 15 deletions(-)tools/hotplug/Linux/vif-bridge +22
-4@@ -29,6 +29,13 @@ # rules for its ip addresses (if any). #============================================================================ +# Older versions of Xen do not pass in the type as an argument +if [ $# -lt 2 ]; then + type_if=vif +else + type_if=$2 +fi + dir=$(dirname "$0") . "$dir/vif-common.sh"@@ -79,22 +86,43 @@ then fatal "Could not find bridge device $bridge" fi +case "$type_if" in + vif) + dev=$vif + ;; + tap) + dev=$INTERFACE + ;; +esac + case "$command" in online) - setup_bridge_port "$vif" - add_to_bridge "$bridge" "$vif" + if [ "$type_if" = vif ]; then + setup_bridge_port "$vif" + add_to_bridge "$bridge" "$vif" + fi ;; offline) - do_without_error brctl delif "$bridge" "$vif" - do_without_error ifconfig "$vif" down + if [ "$type_if" = vif ]; then + do_without_error brctl delif "$bridge" "$vif"
tools/hotplug/Linux/vif-bridge then · line 118
Quoted 10 lines
tools/hotplug/Linux/vif-bridge +8
-0+ do_without_error ifconfig "$vif" down + fi + ;; + + add) + if [ "$type_if" = tap ]; then + add_to_bridge "$bridge" "$dev" + fi ;; esac
Can we limit the amount of "if" introduced by this patch somehow? If we use a different command (add instead of online), why do we need the "if" under the online and offline cases?
If add is only used with tap devices, why do we need an if under add?
tools/hotplug/Linux/vif-bridge then · line 123
Quoted 6 lines
tools/hotplug/Linux/vif-bridge +3
-1-handle_iptable +if [ "$type_if" = vif ]; then + handle_iptable +fi
why is handle_iptable only called with vifs?
Quoted 24 lines
tools/hotplug/Linux/vif-bridge +2
-2-log debug "Successful vif-bridge $command for $vif, bridge $bridge." -if [ "$command" == "online" ] +log debug "Successful vif-bridge $command for $dev, bridge $bridge." +if [ "$type_if" = vif -a "$command" = "online" ] then success fitools/hotplug/Linux/vif-common.sh +3
-1@@ -33,7 +33,9 @@ fi case "$command" in add | remove) - exit 0 + if [ "$type_if" != tap ]; then + exit 0 + fi ;; esac@@ -48,9 +50,11 @@ evalVariables "$@" ip=${ip:-}
tools/hotplug/Linux/vif-common.sh evalVariables "$@" · line 57
Quoted 10 lines
tools/hotplug/Linux/vif-common.sh +5
-3ip=$(xenstore_read_default "$XENBUS_PATH/ip" "$ip") -# Check presence of compulsory args. -XENBUS_PATH="${XENBUS_PATH:?}" -vif="${vif:?}" +if [ "$type_if" != tap ]; then + # Check presence of compulsory args. + XENBUS_PATH="${XENBUS_PATH:?}" + vif="${vif:?}" +fi
vifs get the parameter from xenstore, how do tap devices get the parameter?
Re: [PATCH 2/2] tools/hotplug, Use udev rules instead of qemu script to setup the bridge.
Quoted 68 lines · Stefano Stabellini
Quoted 67 lines · On Wed, 4 Aug 2010, [email protected] wrote:
From: Anthony PERARD <[email protected]>
This patch adds a second argument to vif-bridge script. It can be "vif" or "tap". "vif" give the default behavior and "tap" just add the interface to the found bridge when the action is "add".
Signed-off-by Anthony PERARD <[email protected]>--- tools/hotplug/Linux/vif-bridge | 42 +++++++++++++++++++++++++++----- tools/hotplug/Linux/vif-common.sh | 12 ++++++--- tools/hotplug/Linux/xen-backend.rules | 5 ++- tools/libxl/libxl.c | 4 +- 4 files changed, 48 insertions(+), 15 deletions(-)tools/hotplug/Linux/vif-bridge +29
-4@@ -29,6 +29,13 @@ # rules for its ip addresses (if any). #============================================================================ +# Older versions of Xen do not pass in the type as an argument +if [ $# -lt 2 ]; then + type_if=vif +else + type_if=$2 +fi + dir=$(dirname "$0") . "$dir/vif-common.sh"@@ -79,22 +86,43 @@ then fatal "Could not find bridge device $bridge" fi +case "$type_if" in + vif) + dev=$vif + ;; + tap) + dev=$INTERFACE + ;; +esac + case "$command" in online) - setup_bridge_port "$vif" - add_to_bridge "$bridge" "$vif" + if [ "$type_if" = vif ]; then + setup_bridge_port "$vif" + add_to_bridge "$bridge" "$vif" + fi ;; offline) - do_without_error brctl delif "$bridge" "$vif" - do_without_error ifconfig "$vif" down + if [ "$type_if" = vif ]; then + do_without_error brctl delif "$bridge" "$vif" + do_without_error ifconfig "$vif" down + fi + ;; + + add) + if [ "$type_if" = tap ]; then + add_to_bridge "$bridge" "$dev"
Quoted 8 lines
tools/hotplug/Linux/vif-bridge then · line 118
Quoted 3 lines
tools/hotplug/Linux/vif-bridge +1
-0+ fi ;; esacCan we limit the amount of "if" introduced by this patch somehow? If we use a different command (add instead of online), why do we need the "if" under the online and offline cases?
If add is only used with tap devices, why do we need an if under add?
The command come directly from the $ACTION in udev, and for some reason, this event is different in both cases. Here, I just check if we really want to setup a vif or a tap. This is too much? I can check the argument before that, in vif-common.sh, like is already done for a vif.
Quoted 8 lines
tools/hotplug/Linux/vif-bridge then · line 123
Quoted 6 lines
tools/hotplug/Linux/vif-bridge +3
-1-handle_iptable +if [ "$type_if" = vif ]; then + handle_iptable +fiwhy is
handle_iptableonly called with vifs?
Because iptable wasn't handled before with the qemu script and it doesn't seem to be necessary to handle iptable for a tap device.
Quoted 26 lines
Quoted 26 lines
tools/hotplug/Linux/vif-bridge +2
-2-log debug "Successful vif-bridge $command for $vif, bridge $bridge." -if [ "$command" == "online" ] +log debug "Successful vif-bridge $command for $dev, bridge $bridge." +if [ "$type_if" = vif -a "$command" = "online" ] then success fitools/hotplug/Linux/vif-common.sh +3
-1@@ -33,7 +33,9 @@ fi case "$command" in add | remove) - exit 0 + if [ "$type_if" != tap ]; then + exit 0 + fi ;; esac@@ -48,9 +50,11 @@ evalVariables "$@" ip=${ip:-} ip=$(xenstore_read_default "$XENBUS_PATH/ip" "$ip")
Quoted 11 lines
tools/hotplug/Linux/vif-common.sh evalVariables "$@" · line 57
Quoted 8 lines
tools/hotplug/Linux/vif-common.sh +5
-3-# Check presence of compulsory args. -XENBUS_PATH="${XENBUS_PATH:?}" -vif="${vif:?}" +if [ "$type_if" != tap ]; then + # Check presence of compulsory args. + XENBUS_PATH="${XENBUS_PATH:?}" + vif="${vif:?}" +fivifs get the parameter from xenstore, how do tap devices get the parameter?
The interface name is get from $INTERFACE, and the bridge is found automatically by the script. But there must be a way to take the bridge from xenstore, by using the name of the device (tap32.0) to have the path.
Signature · 1 line
Anthony PERARD
Re: [PATCH 2/2] tools/hotplug, Use udev rules instead of qemu script to setup the bridge.
Quoted 11 lines · Anthony PERARD
Quoted 3 lines
Can we limit the amount of "if" introduced by this patch somehow? If we use a different command (add instead of online), why do we
need
Quoted 2 lines
the "if" under the online and offline cases?
If add is only used with tap devices, why do we need an if underadd?
The command come directly from the $ACTION in udev, and for some reason, this event is different in both cases. Here, I just check if we really want to setup a vif or a tap. This is too much?
It could be that just handling one of online or add would be sufficient. I don't really remember but when I made the patch for XCP which you are basing this patch on I may just have been trying to avoid a large change in behaviour and/or other knockon effects. It's equally possible that one or the other type of device actually generates both types of event or that I was being overly/unnecessarily conservative.
I think I'd recommend confirming the actual behaviour WRT event names of both vif and tap devices on a few "important/interesting" kernel versions before removing the extra if statements.
I wonder if we should be looking to begin transitioning the hotplug events generated by netback to be consistent with those generated by other network devices? (assuming there is consistency in general and the the tun/tap driver is the correct one in this case)
Ian
v2 cover libxl, Handle the command line options of qemu 0.12.
In reply to [email protected]From: Anthony PERARD <[email protected]>
This patch gives the ability to the libxl to handle the command line argument of the last qemu version. I begin by checking the version of the device model with '-h' options, '--version' is not handled in qemu-xen. If I found a version upper than 0.12, I use the new command line argument, or else I use the old functions to build args.
The second patch introduces a udev rule to handle tap devices and add them to the bridge instead of using a script called by qemu.
Anthony PERARD (3):
libxl, Fix name of tap device.
libxl, Introduce the command line handler for the new qemu. tools/hotplug, Use udev rules instead of qemu script to setup the
bridge.
tools/hotplug/Linux/vif-bridge | 20 +++-- tools/hotplug/Linux/vif-common.sh | 70 ++++++++++---- tools/hotplug/Linux/xen-backend.rules | 5 +- tools/libxl/libxl.c | 164 ++++++++++++++++++++++++++++++++- tools/libxl/libxl_utils.c | 78 ++++++++++++++++ tools/libxl/libxl_utils.h | 6 + 6 files changed, 312 insertions(+), 31 deletions(-)
PATCH v2 1/3 libxl, Fix name of tap device.
From: Anthony PERARD <[email protected]>
Currently, tap device names for a domain begin at tap42.-1, but it must be tap42.0.
--- tools/libxl/libxl.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
tools/libxl/libxl.c +1 -1
@@ -1070,7 +1070,7 @@ static char ** libxl_build_device_model_args(libxl_ctx *ctx, vifs[i].mac[0 ], vifs[i].mac[1 ], vifs[i].mac[2 ], vifs[i].mac[3], vifs[i].mac[4], vifs[i].mac[5]);if (!vifs[i].ifname) - vifs[i].ifname =libxl_sprintf (ctx,"tap%d.%d" , info->domid, vifs[i].devid -1 ); + vifs[i].ifname =libxl_sprintf (ctx,"tap%d.%d" , info->domid, vifs[i].devid);flexarray_set (dm_args, num++,"-net" );flexarray_set (dm_args, num++,libxl_sprintf (ctx,"nic,vlan=%d,macaddr=%s,model=%s" , vifs[i].devid, smac, vifs[i].model));
Signature · 1 line
1.6.5
PATCH v2 2/3 libxl, Introduce the command line handler for the new qemu.
From: Anthony PERARD <[email protected]>
This patch adds a function to check the version of the device model. Depending on the version of the DM, the command line arguments will be built differently.
--- tools/libxl/libxl.c | 160 ++++++++++++++++++++++++++++++++++++++++++++- tools/libxl/libxl_utils.c | 78 ++++++++++++++++++++++ tools/libxl/libxl_utils.h | 6 ++ 3 files changed, 243 insertions(+), 1 deletions(-)
tools/libxl/libxl.c +159 -1
@@ -964,7 +964,7 @@ skip_autopass:return 0 ; } -static char **libxl_build_device_model_args (libxl_ctx *ctx, +static char **libxl_build_device_model_args_old (libxl_ctx *ctx,libxl_device_model_info *info,libxl_device_nic *vifs,int num_vifs)
@@ -1098,10 +1098,168 @@ static char ** libxl_build_device_model_args(libxl_ctx *ctx,else flexarray_set (dm_args, num++,"xenfv" );flexarray_set (dm_args, num++,NULL ); +return (char **)flexarray_contents (dm_args); +} + +static char **libxl_build_device_model_args_new (libxl_ctx *ctx, +libxl_device_model_info *info, +libxl_device_nic *vifs, +int num_vifs) +{ +int num =0 , i; +flexarray_t *dm_args; +int nb; +libxl_device_disk *disks; + + dm_args =flexarray_make (16 ,1 ); +if (!dm_args) +return NULL ; + +flexarray_set (dm_args, num++,"qemu-system-xen" ); +flexarray_set (dm_args, num++,"-xen-domid" ); + +flexarray_set (dm_args, num++,libxl_sprintf (ctx,"%d" , info->domid)); + +if (info->dom_name) { +flexarray_set (dm_args, num++,"-name" ); +flexarray_set (dm_args, num++, info->dom_name); + } +if (info->vnc || info->vncdisplay || info->vnclisten || info->vncunused) { +int display =0 ; +const char *listen ="127.0.0.1" ; + +flexarray_set (dm_args, num++,"-vnc" ); + +if (info->vncdisplay) { + display = info->vncdisplay; +if (info->vnclisten &&strchr (info->vnclisten,':' ) ==NULL ) { + listen = info->vnclisten; + } + }else if (info->vnclisten) { + listen = info->vnclisten; + } + +if (strchr (listen,':' ) !=NULL ) +flexarray_set (dm_args, num++, +libxl_sprintf (ctx,"%s%s" , listen, + info->vncunused ?",to=99" :"" )); +else +flexarray_set (dm_args, num++, +libxl_sprintf (ctx,"%s:%d%s" , listen, display, + info->vncunused ?",to=99" :"" )); + } +if (info->sdl) { +flexarray_set (dm_args, num++,"-sdl" ); + } +if (info->keymap) { +flexarray_set (dm_args, num++,"-k" ); +flexarray_set (dm_args, num++, info->keymap); + } +if (info->nographic && (!info->sdl && !info->vnc)) { +flexarray_set (dm_args, num++,"-nographic" ); + } +if (info->serial) { +flexarray_set (dm_args, num++,"-serial" ); +flexarray_set (dm_args, num++, info->serial); + } +if (info->type ==XENFV ) { +int ioemu_vifs =0 ; + +if (info->stdvga) { +flexarray_set (dm_args, num++,"-vga" ); +flexarray_set (dm_args, num++,"std" ); + } + +if (info->boot) { +flexarray_set (dm_args, num++,"-boot" ); +flexarray_set (dm_args, num++,libxl_sprintf (ctx,"order=%s" , info->boot)); + } +if (info->usb || info->usbdevice) { +flexarray_set (dm_args, num++,"-usb" ); +if (info->usbdevice) { +flexarray_set (dm_args, num++,"-usbdevice" ); +flexarray_set (dm_args, num++, info->usbdevice); + } + } +if (info->soundhw) { +flexarray_set (dm_args, num++,"-soundhw" ); +flexarray_set (dm_args, num++, info->soundhw); + } +if (!info->apic) { +flexarray_set (dm_args, num++,"-no-acpi" ); + } +if (info->vcpus >1 ) { +flexarray_set (dm_args, num++,"-smp" ); +if (info->vcpu_avail) +flexarray_set (dm_args, num++,libxl_sprintf (ctx,"%d,maxcpus=%d" , info->vcpus, info->vcpu_avail)); +else +flexarray_set (dm_args, num++,libxl_sprintf (ctx,"%d" , info->vcpus)); + } +for (i =0 ; i < num_vifs; i++) { +if (vifs[i].nictype ==NICTYPE_IOEMU ) { +char *smac =libxl_sprintf (ctx,"%02x:%02x:%02x:%02x:%02x:%02x" , + vifs[i].mac[0 ], vifs[i].mac[1 ], vifs[i].mac[2 ], + vifs[i].mac[3 ], vifs[i].mac[4 ], vifs[i].mac[5 ]); +if (!vifs[i].ifname) + vifs[i].ifname =libxl_sprintf (ctx,"tap%d.%d" , info->domid, vifs[i].devid); +flexarray_set (dm_args, num++,"-net" ); +flexarray_set (dm_args, num++,libxl_sprintf (ctx,"nic,vlan=%d,macaddr=%s,model=%s" , + vifs[i].devid, smac, vifs[i].model)); +flexarray_set (dm_args, num++,"-net" ); +flexarray_set (dm_args, num++,libxl_sprintf (ctx,"tap,vlan=%d,ifname=%s,script=%s" , + vifs[i].devid, vifs[i].ifname,"/etc/xen/scripts/qemu-ifup" )); + ioemu_vifs++; + } + } +/* If we have no emulated nics, tell qemu not to create any */ +if ( ioemu_vifs ==0 ) { +flexarray_set (dm_args, num++,"-net" ); +flexarray_set (dm_args, num++,"none" ); + } + } +if (info->saved_state) { +flexarray_set (dm_args, num++,"-loadvm" ); +flexarray_set (dm_args, num++, info->saved_state); + } +for (i =0 ; info->extra && info->extra[i] !=NULL ; i++) +flexarray_set (dm_args, num++, info->extra[i]); +flexarray_set (dm_args, num++,"-M" ); +if (info->type ==XENPV ) +flexarray_set (dm_args, num++,"xenpv" ); +else +flexarray_set (dm_args, num++,"xenfv" ); + disks =libxl_device_disk_list (ctx, info->domid, &nb); +for (; nb >0 ; --nb, ++disks) { +if ( disks->is_cdrom ) { +flexarray_set (dm_args, num++,"-cdrom" ); +flexarray_set (dm_args, num++, disks->physpath); + }else { +flexarray_set (dm_args, num++,libxl_sprintf (ctx,"-%s" , disks->virtpath)); +flexarray_set (dm_args, num++, disks->physpath); + } + } + +flexarray_set (dm_args, num++,NULL );return (char **)flexarray_contents (dm_args); } +static char **libxl_build_device_model_args (libxl_ctx *ctx, +libxl_device_model_info *info, +libxl_device_nic *vifs, +int num_vifs) +{ +int new_qemu; + + new_qemu =libxl_check_device_model_version (ctx, info->device_model); + +if (new_qemu ==1 ) { +return libxl_build_device_model_args_new (ctx, info, vifs, num_vifs); + }else { +return libxl_build_device_model_args_old (ctx, info, vifs, num_vifs); + } +} +void dm_xenstore_record_pid (void *for_spawn,pid_t innerchild) {libxl_device_model_starting *starting = for_spawn;
tools/libxl/libxl_utils.c +78 -0
81 lines not on this page · raw message
tools/libxl/libxl_utils.h +6 -0
@@ -68,5 +68,11 @@ int libxl_strtomac(const char *mac_s, uint8_t *mac);int libxl_devid_to_device_net2 (libxl_ctx *ctx,uint32_t domid,const char *devid,libxl_device_net2 *net2); +/* check the version of qemu +* return 1 if is the new one +* return 0 if is the old one +* return -1 if there are an error */ +int libxl_check_device_model_version (libxl_ctx *ctx,char *path); +#endif
Signature · 1 line
1.6.5
PATCH v2 3/3 tools/hotplug, Use udev rules instead of qemu script to setup the bridge.
From: Anthony PERARD <[email protected]>
This patch adds a second argument to vif-bridge script. It can be "vif" or "tap". "vif" give the default behavior and "tap" just add the interface to the found bridge when the action is "add".
--- tools/hotplug/Linux/vif-bridge | 20 ++++++--- tools/hotplug/Linux/vif-common.sh | 70 ++++++++++++++++++++++++--------- tools/hotplug/Linux/xen-backend.rules | 5 +- tools/libxl/libxl.c | 6 +- 4 files changed, 70 insertions(+), 31 deletions(-)
tools/hotplug/Linux/vif-bridge +13 -7
@@ -81,20 +81,26 @@ fi case "$command" in online) - setup_bridge_port "$vif" - add_to_bridge "$bridge" "$vif" + setup_bridge_port "$dev" + add_to_bridge "$bridge" "$dev" ;; offline) - do_without_error brctl delif "$bridge" "$vif" - do_without_error ifconfig "$vif" down + do_without_error brctl delif "$bridge" "$dev" + do_without_error ifconfig "$dev" down + ;; + + add) + add_to_bridge "$bridge" "$dev" ;; esac -handle_iptable +if [ "$type_if" = vif ]; then + handle_iptable +fi -log debug "Successful vif-bridge $command for $vif, bridge $bridge." -if [ "$command" == "online" ] +log debug "Successful vif-bridge $command for $dev, bridge $bridge." +if [ "$type_if" = vif -a "$command" = "online" ] then success fi
tools/hotplug/Linux/vif-common.sh +51 -19
87 lines not on this page · raw message
tools/hotplug/Linux/xen-backend.rules +3 -2
@@ -2,10 +2,11 @@ SUBSYSTEM=="xen-backend", KERNEL=="tap*", RUN+="/etc/xen/scripts/blktap $env{ACT SUBSYSTEM=="xen-backend", KERNEL=="vbd*", RUN+="/etc/xen/scripts/block $env{ACTION}" SUBSYSTEM=="xen-backend", KERNEL=="vtpm*", RUN+="/etc/xen/scripts/vtpm $env{ACTION}" SUBSYSTEM=="xen-backend", KERNEL=="vif2-*", RUN+="/etc/xen/scripts/vif2 $env{ACTION}" -SUBSYSTEM=="xen-backend", KERNEL=="vif-*", ACTION=="online", RUN+="/etc/xen/scripts/vif-setup online" -SUBSYSTEM=="xen-backend", KERNEL=="vif-*", ACTION=="offline", RUN+="/etc/xen/scripts/vif-setup offline" +SUBSYSTEM=="xen-backend", KERNEL=="vif-*", ACTION=="online", RUN+="/etc/xen/scripts/vif-setup online type_if=vif" +SUBSYSTEM=="xen-backend", KERNEL=="vif-*", ACTION=="offline", RUN+="/etc/xen/scripts/vif-setup offline type_if=vif" SUBSYSTEM=="xen-backend", KERNEL=="vscsi*", RUN+="/etc/xen/scripts/vscsi $env{ACTION}" SUBSYSTEM=="xen-backend", ACTION=="remove", RUN+="/etc/xen/scripts/xen-hotplug-cleanup" KERNEL=="evtchn", NAME="xen/%k" KERNEL=="blktap[0-9]*", NAME="xen/%k" KERNEL=="pci_iomul", NAME="xen/%k" +SUBSYSTEM=="net", KERNEL=="tap*", ACTION=="add", RUN+="/etc/xen/scripts/vif-setup $env{ACTION} type_if=tap"
tools/libxl/libxl.c +3 -3
@@ -1075,7 +1075,7 @@ static char ** libxl_build_device_model_args_old(libxl_ctx *ctx,flexarray_set (dm_args, num++,libxl_sprintf (ctx,"nic,vlan=%d,macaddr=%s,model=%s" , vifs[i].devid, smac, vifs[i].model));flexarray_set (dm_args, num++,"-net" ); -flexarray_set (dm_args, num++,libxl_sprintf (ctx,"tap,vlan=%d,ifname=%s,bridge=%s" , +flexarray_set (dm_args, num++,libxl_sprintf (ctx,"tap,vlan=%d,ifname=%s,bridge=%s,script=no" , vifs[i].devid, vifs[i].ifname, vifs[i].bridge)); ioemu_vifs++; }
@@ -1206,8 +1206,8 @@ static char ** libxl_build_device_model_args_new(libxl_ctx *ctx,flexarray_set (dm_args, num++,libxl_sprintf (ctx,"nic,vlan=%d,macaddr=%s,model=%s" , vifs[i].devid, smac, vifs[i].model));flexarray_set (dm_args, num++,"-net" ); -flexarray_set (dm_args, num++,libxl_sprintf (ctx,"tap,vlan=%d,ifname=%s,script=%s" , - vifs[i].devid, vifs[i].ifname,"/etc/xen/scripts/qemu-ifup" )); +flexarray_set (dm_args, num++,libxl_sprintf (ctx,"tap,vlan=%d,ifname=%s,script=no" , + vifs[i].devid, vifs[i].ifname)); ioemu_vifs++; } }
Signature · 1 line
1.6.5
Stefano Stabellini
AppliedQuoted 8 lines · Anthony Perard
From: Anthony PERARD <[email protected]>
This patch gives the ability to the libxl to handle the command line argument of the last qemu version. I begin by checking the version of the device model with '-h' options, '--version' is not handled in qemu-xen. If I found a version upper than 0.12, I use the new command line argument, or else I use the old functions to build args.
Quoted 9 lines
The second patch introduces a udev rule to handle tap devices and add them to the bridge instead of using a script called by qemu.
Anthony PERARD (3):
libxl, Fix name of tap device.
libxl, Introduce the command line handler for the new qemu.tools/hotplug, Use udev rules instead of qemu script to setup the
bridge.
applied, thanks
[email protected] writes ("[Xen-devel] [PATCH v2 0/3] libxl, Handle the command line options of qemu 0.12."):
Quoted 6 lines
This patch gives the ability to the libxl to handle the command line argument of the last qemu version. I begin by checking the version of the device model with '-h' options, '--version' is not handled in qemu-xen. If I found a version upper than 0.12, I use the new command line argument, or else I use the old functions to build args.
I see I'm too late with this but I agree with the comments that checking the version number is not the right approach.
The right approach, it seems to me, is to call strstr() on a copy of the qemu-dm -h output to try to see whether it supports each particular variant.
Ian.