Chun Yan Liu
2010-Aug-06 10:46 UTC
[Xen-devel][PATCH]add usb-ver format check to avoid usb-list error and incorrect usb-ver saved into config file
Add usb-ver format check to "usb-hc-create". In original file, "usb-hc-create" allows usb-ver parameter as "2/2.0/2.0aaa". In low level hc create, it only uses the integer part (that is "2"), so there is no problem. But 2/2.0/2.0aaa will be saved into VM config. After that, while doing "usb-list", it cannot handle "2.0/2.0aaa" and will cause error like this:. Idx BE state usb-ver BE-path Error: Invalid argument. Usage: xm usb-list <Domain> To avoid this, we need either change "usb-list" code or "usb-hc-create" code. This patch adds usb-ver format check to "usb-hc-create", do not allow 2.0/2.0aaa format. And add description in its HELP. diff -r 8992134dcfd0 tools/python/xen/xm/main.py --- a/tools/python/xen/xm/main.py Wed Aug 04 19:24:17 2010 +0100 +++ b/tools/python/xen/xm/main.py Fri Aug 06 18:02:33 2010 +0800 @@ -225,8 +225,8 @@ ''usb-list'' : (''<Domain>'', ''List domain\''s attachment state of all virtual port .''), ''usb-list-assignable-devices'' : ('''', ''List all the assignable usb devices''), - ''usb-hc-create'' : (''<Domain> <USBSpecVer> <NumberOfPorts>'', - ''Create a domain\''s new virtual USB host controller.''), + ''usb-hc-create'' : (''<Domain> <USBSpecVer> <NumberOfPorts>\n ## <USBSpecVer>: 2 (for USB2.0), 1 (for USB1.1)'', + ''Create a domain\''s new virtual USB host controller.''), ''usb-hc-destroy'' : (''<Domain> <DevId>'', ''Destroy a domain\''s virtual USB host controller.''), @@ -3064,6 +3064,8 @@ ver = args[1] num = args[2] vusb_config = [''vusb''] + if not re.match(''^\d{1}$'', ver): + print "Invalid usb-ver format ''%s''" % ver vusb_config.append([''usb-ver'', str(ver)]) vusb_config.append([''num-ports'', str(num)]) port_config = [''port''] _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Chun Yan Liu
2010-Aug-09 02:08 UTC
答复: [Xen-devel][PATCH]add usb-ver format check to avoid usb-list error and incorrect usb-ver saved into config file
oh, sorry, I''ve posted the wrong patch. Make an update here. Add usb-ver format check to "usb-hc-create" to fix the bug that incorrect usb-ver saved into config file and usb-list error. diff -r 8992134dcfd0 tools/python/xen/xm/main.py --- a/tools/python/xen/xm/main.py Wed Aug 04 19:24:17 2010 +0100 +++ b/tools/python/xen/xm/main.py Mon Aug 09 09:57:54 2010 +0800 @@ -225,8 +225,8 @@ ''usb-list'' : (''<Domain>'', ''List domain\''s attachment state of all virtual port .''), ''usb-list-assignable-devices'' : ('''', ''List all the assignable usb devices''), - ''usb-hc-create'' : (''<Domain> <USBSpecVer> <NumberOfPorts>'', - ''Create a domain\''s new virtual USB host controller.''), + ''usb-hc-create'' : (''<Domain> <USBSpecVer> <NumberOfPorts>\n ## <USBSpecVer>: 2 (for USB2.0), 1 (for USB1.1)'', + ''Create a domain\''s new virtual USB host controller.''), ''usb-hc-destroy'' : (''<Domain> <DevId>'', ''Destroy a domain\''s virtual USB host controller.''), @@ -3064,6 +3064,9 @@ ver = args[1] num = args[2] vusb_config = [''vusb''] + if not re.match(''^\d{1}$'', ver): + err("Invalid usb-ver format ''%s''" % ver) + usage(''usb-hc-create'') vusb_config.append([''usb-ver'', str(ver)]) vusb_config.append([''num-ports'', str(num)]) port_config = [''port'']>>> "Chun Yan Liu" <cyliu@novell.com> 2010/8/6 18:46 >>>Add usb-ver format check to "usb-hc-create". In original file, "usb-hc-create" allows usb-ver parameter as "2/2.0/2.0aaa". In low level hc create, it only uses the integer part (that is "2"), so there is no problem. But 2/2.0/2.0aaa will be saved into VM config. After that, while doing "usb-list", it cannot handle "2.0/2.0aaa" and will cause error like this:. Idx BE state usb-ver BE-path Error: Invalid argument. Usage: xm usb-list <Domain> To avoid this, we need either change "usb-list" code or "usb-hc-create" code. This patch adds usb-ver format check to "usb-hc-create", do not allow 2.0/2.0aaa format. And add description in its HELP. diff -r 8992134dcfd0 tools/python/xen/xm/main.py --- a/tools/python/xen/xm/main.py Wed Aug 04 19:24:17 2010 +0100 +++ b/tools/python/xen/xm/main.py Fri Aug 06 18:02:33 2010 +0800 @@ -225,8 +225,8 @@ ''usb-list'' : (''<Domain>'', ''List domain\''s attachment state of all virtual port .''), ''usb-list-assignable-devices'' : ('''', ''List all the assignable usb devices''), - ''usb-hc-create'' : (''<Domain> <USBSpecVer> <NumberOfPorts>'', - ''Create a domain\''s new virtual USB host controller.''), + ''usb-hc-create'' : (''<Domain> <USBSpecVer> <NumberOfPorts>\n ## <USBSpecVer>: 2 (for USB2.0), 1 (for USB1.1)'', + ''Create a domain\''s new virtual USB host controller.''), ''usb-hc-destroy'' : (''<Domain> <DevId>'', ''Destroy a domain\''s virtual USB host controller.''), @@ -3064,6 +3064,8 @@ ver = args[1] num = args[2] vusb_config = [''vusb''] + if not re.match(''^\d{1}$'', ver): + print "Invalid usb-ver format ''%s''" % ver vusb_config.append([''usb-ver'', str(ver)]) vusb_config.append([''num-ports'', str(num)]) port_config = [''port''] _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel