Re: [Xen-devel] [PATCH RFC V2 4/5] xl: add pvusb commands

2015-03-20 Thread Chun Yan Liu


 On 3/7/2015 at 01:25 AM, in message
caflbxzb1n3_9pvvg-yc8dyvaiyszvra3h2e8496vhnefvrm...@mail.gmail.com, George
Dunlap george.dun...@eu.citrix.com wrote: 
 On Mon, Jan 19, 2015 at 8:28 AM, Chunyan Liu cy...@suse.com wrote: 
  Add pvusb commands. 
  
  To attach a usb device to guest through pvusb, one could follow 
  following example: 
  
   #xl usb-ctrl-attach test_vm version=1 num_ports=8 
  
 This doesn't allow you to specify controller name or devid. 
  
 I was looking at the other device-attach code, and they all seem to 
 have a devicespec-style specification.  Would it make sense to do 
 something similar? 
  
 For example: 
  
 xl usb-ctrl-attach test_vm name=pv-1,type=pv,version=1,ports=8 
  
 Then we could re-use this for the config file as well. 
  
   #xl usb-list test_vm 
   will show the usb controllers and port usage under the domain. 
  
   #xl usb-assignable-list 
   will list all assignable usb devices now in host, with their 
   sysfs interface. (This is very useful since later we will use 
   sysfs interface to attach a usb devie to guest) 
  
   #xl usb-attach test_vm 2-1.1 
   will find the first usable controller:port, and attach usb 
   device with sysfs interface 2-1.1 (sys/bus/usb/devices/2-1.1) 
   to it. One could also specify which controller and which port 
  
   #xl usb-detach test_vm 2-1.1 
  
 Long-term we want to be able to attach and detach more kinds of 
 devices than just host devices; for example for HVM guests we want to 
 be able to attach mice, keyboards, tablets, c. 
  
 What if we continued with the devicespec idea above, it might make 
 more sense to say something like 
  
 xl usb-attach test_vm type=hostdev,hostbus=X,hostaddr=Y,ctrl=pv-1 
  
 (Assuming you had a controller named pv-1, for example.) 
  
 And then maybe in the future we could have something like 
  
 xl usb-attach test_vm type=tablet 
  
 Thoughts? 

This could be. I can update.

  
  -George 
  
  



___
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH RFC V2 4/5] xl: add pvusb commands

2015-03-06 Thread George Dunlap
On Mon, Jan 19, 2015 at 8:28 AM, Chunyan Liu cy...@suse.com wrote:
 Add pvusb commands.

 To attach a usb device to guest through pvusb, one could follow
 following example:

  #xl usb-ctrl-attach test_vm version=1 num_ports=8

This doesn't allow you to specify controller name or devid.

I was looking at the other device-attach code, and they all seem to
have a devicespec-style specification.  Would it make sense to do
something similar?

For example:

xl usb-ctrl-attach test_vm name=pv-1,type=pv,version=1,ports=8

Then we could re-use this for the config file as well.

  #xl usb-list test_vm
  will show the usb controllers and port usage under the domain.

  #xl usb-assignable-list
  will list all assignable usb devices now in host, with their
  sysfs interface. (This is very useful since later we will use
  sysfs interface to attach a usb devie to guest)

  #xl usb-attach test_vm 2-1.1
  will find the first usable controller:port, and attach usb
  device with sysfs interface 2-1.1 (sys/bus/usb/devices/2-1.1)
  to it. One could also specify which controller and which port

  #xl usb-detach test_vm 2-1.1

Long-term we want to be able to attach and detach more kinds of
devices than just host devices; for example for HVM guests we want to
be able to attach mice, keyboards, tablets, c.

What if we continued with the devicespec idea above, it might make
more sense to say something like

xl usb-attach test_vm type=hostdev,hostbus=X,hostaddr=Y,ctrl=pv-1

(Assuming you had a controller named pv-1, for example.)

And then maybe in the future we could have something like

xl usb-attach test_vm type=tablet

Thoughts?

 -George

___
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH RFC V2 4/5] xl: add pvusb commands

2015-03-03 Thread Chun Yan Liu


 On 3/3/2015 at 07:43 PM, in message 1425382984.24959.115.ca...@citrix.com,
Ian Campbell ian.campb...@citrix.com wrote: 
 On Mon, 2015-01-19 at 16:28 +0800, Chunyan Liu wrote: 
  Add pvusb commands. 
   
  To attach a usb device to guest through pvusb, one could follow 
  following example: 
   
   #xl usb-ctrl-attach test_vm version=1 num_ports=8 
   
   #xl usb-list test_vm 
   will show the usb controllers and port usage under the domain. 
   
   #xl usb-assignable-list 
   will list all assignable usb devices now in host, with their 
   sysfs interface. (This is very useful since later we will use 
   sysfs interface to attach a usb devie to guest) 
   
   #xl usb-attach test_vm 2-1.1 
   will find the first usable controller:port, and attach usb 
   device with sysfs interface 2-1.1 (sys/bus/usb/devices/2-1.1) 
   to it. One could also specify which controller and which port 
   
   #xl usb-detach test_vm 2-1.1 
   
   #xl usb-ctrl-detach test_vm dev_id 
   will destroy the controller with dev_id as specified. Dev_id 
   can be traced in usb-list info 
   
  Signed-off-by: Chunyan Liu cy...@suse.com 
  Signed-off-by: Simon Cao caobosi...@gmail.com 
  --- 
   tools/libxl/xl.h  |   6 ++ 
   tools/libxl/xl_cmdimpl.c  | 256  
 ++ 
   tools/libxl/xl_cmdtable.c |  30 ++ 
  
 This patch should also touch docs/man/xl*.pod I think. 

Right. Will update it.

  
  +int main_usbassignable_list(int argc, char **argv) 
  +{ 
  +int opt; 
  + 
  +SWITCH_FOREACH_OPT(opt, , NULL, usb-assignable-list, 0) { 
  +/* No options */ 
  +} 
  + 
  +usb_assignable_list(); 
  
 Unless there are other callers or a good reason to factor it out (e.g. 
 complexity) you can just do the operation inline here if you like. 

Got it.

  
 The rest of it seems pretty straightforward and looked ok to me. 
  
 Ian. 
  
  
  



___
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH RFC V2 4/5] xl: add pvusb commands

2015-03-03 Thread Ian Campbell
On Mon, 2015-01-19 at 16:28 +0800, Chunyan Liu wrote:
 Add pvusb commands.
 
 To attach a usb device to guest through pvusb, one could follow
 following example:
 
  #xl usb-ctrl-attach test_vm version=1 num_ports=8
 
  #xl usb-list test_vm
  will show the usb controllers and port usage under the domain.
 
  #xl usb-assignable-list
  will list all assignable usb devices now in host, with their
  sysfs interface. (This is very useful since later we will use
  sysfs interface to attach a usb devie to guest)
 
  #xl usb-attach test_vm 2-1.1
  will find the first usable controller:port, and attach usb
  device with sysfs interface 2-1.1 (sys/bus/usb/devices/2-1.1)
  to it. One could also specify which controller and which port
 
  #xl usb-detach test_vm 2-1.1
 
  #xl usb-ctrl-detach test_vm dev_id
  will destroy the controller with dev_id as specified. Dev_id
  can be traced in usb-list info
 
 Signed-off-by: Chunyan Liu cy...@suse.com
 Signed-off-by: Simon Cao caobosi...@gmail.com
 ---
  tools/libxl/xl.h  |   6 ++
  tools/libxl/xl_cmdimpl.c  | 256 
 ++
  tools/libxl/xl_cmdtable.c |  30 ++

This patch should also touch docs/man/xl*.pod I think.

 +int main_usbassignable_list(int argc, char **argv)
 +{
 +int opt;
 +
 +SWITCH_FOREACH_OPT(opt, , NULL, usb-assignable-list, 0) {
 +/* No options */
 +}
 +
 +usb_assignable_list();

Unless there are other callers or a good reason to factor it out (e.g.
complexity) you can just do the operation inline here if you like.

The rest of it seems pretty straightforward and looked ok to me.

Ian.


___
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH RFC V2 4/5] xl: add pvusb commands

2015-02-09 Thread Jürgen Groß

On 01/19/2015 09:28 AM, Chunyan Liu wrote:

Add pvusb commands.

To attach a usb device to guest through pvusb, one could follow
following example:

  #xl usb-ctrl-attach test_vm version=1 num_ports=8

  #xl usb-list test_vm
  will show the usb controllers and port usage under the domain.

  #xl usb-assignable-list
  will list all assignable usb devices now in host, with their
  sysfs interface. (This is very useful since later we will use
  sysfs interface to attach a usb devie to guest)

  #xl usb-attach test_vm 2-1.1
  will find the first usable controller:port, and attach usb
  device with sysfs interface 2-1.1 (sys/bus/usb/devices/2-1.1)
  to it. One could also specify which controller and which port

  #xl usb-detach test_vm 2-1.1

  #xl usb-ctrl-detach test_vm dev_id
  will destroy the controller with dev_id as specified. Dev_id
  can be traced in usb-list info


Sorry for late review.

Some comments inline.



Signed-off-by: Chunyan Liu cy...@suse.com
Signed-off-by: Simon Cao caobosi...@gmail.com
---
  tools/libxl/xl.h  |   6 ++
  tools/libxl/xl_cmdimpl.c  | 256 ++
  tools/libxl/xl_cmdtable.c |  30 ++
  3 files changed, 292 insertions(+)

diff --git a/tools/libxl/xl.h b/tools/libxl/xl.h
index 5bc138c..f37a99f 100644
--- a/tools/libxl/xl.h
+++ b/tools/libxl/xl.h
@@ -86,6 +86,12 @@ int main_blockdetach(int argc, char **argv);
  int main_vtpmattach(int argc, char **argv);
  int main_vtpmlist(int argc, char **argv);
  int main_vtpmdetach(int argc, char **argv);
+int main_usbassignable_list(int argc, char **argv);
+int main_usbctrl_attach(int argc, char **argv);
+int main_usbctrl_detach(int argc, char **argv);
+int main_usbattach(int argc, char **argv);
+int main_usbdetach(int argc, char **argv);
+int main_usblist(int argc, char **argv);
  int main_uptime(int argc, char **argv);
  int main_claims(int argc, char **argv);
  int main_tmem_list(int argc, char **argv);
diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index 0b02a6c..a28f460 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -3000,6 +3000,262 @@ int main_cd_insert(int argc, char **argv)
  return 0;
  }

+static void usbinfo_print(libxl_device_usb *usbs, int num) {
+int i;
+if ( usbs == NULL )
+ return;
+libxl_usbinfo usbinfo;
+for (i = 0; i  num; i++) {
+/* TO BE Improved */
+if (usbs[i].port )
+printf(Port %d:, usbs[i].port);
+printf(Interface %8s , usbs[i].intf);
+if (!libxl_device_usb_getinfo(ctx, usbs[i].intf, usbinfo)) {
+printf(Bus %03d Dev %03d: %04d:%04d %s %s\n,
+usbinfo.bus, usbinfo.devnum, usbinfo.idVendor,
+usbinfo.idProduct, usbinfo.manuf, usbinfo.prod);
+}
+libxl_usbinfo_dispose(usbinfo);
+}
+}
+
+
+static void usb_assignable_list(void)
+{
+libxl_device_usb *usbs;
+int num;
+
+usbs = libxl_device_usb_assignable_list(ctx, num);
+
+usbinfo_print(usbs, num);
+
+free(usbs);
+}
+
+int main_usbassignable_list(int argc, char **argv)
+{
+int opt;
+
+SWITCH_FOREACH_OPT(opt, , NULL, usb-assignable-list, 0) {
+/* No options */
+}
+
+usb_assignable_list();
+return 0;
+}
+
+int main_usbctrl_attach(int argc, char **argv)
+{
+uint32_t domid;
+int opt;
+char *oparg;
+libxl_device_usbctrl usbctrl;
+
+SWITCH_FOREACH_OPT(opt, , NULL, usb-controller-attach, 1) {


Should be usb-ctrl-attach.


+/* No options */
+}
+
+domid = find_domain(argv[optind++]);
+
+libxl_device_usbctrl_init(usbctrl);
+
+while (argc = optind) {


argc  optind?


+if (MATCH_OPTION(type,  argv[optind], oparg)) {
+if (!strcmp(pv, oparg)) {
+usbctrl.type = LIBXL_USBCTRL_TYPE_PV;
+} else if(!strcmp(ioemu, oparg)) {
+usbctrl.type = LIBXL_USBCTRL_TYPE_DEVICEMODEL;
+} else {
+fprintf(stderr, Invalid parameter `type'.\n);
+exit(-1);
+}
+} else if (MATCH_OPTION(version, argv[optind], oparg)) {
+usbctrl.usb_version = atoi(oparg);
+} else if (MATCH_OPTION(num_ports, argv[optind], oparg)) {
+usbctrl.num_ports = atoi(oparg);
+}  else {
+fprintf(stderr, unrecognized argument `%s'\n, argv[optind]);
+exit(-1);
+}
+optind++;
+}
+
+if (dryrun_only) {
+   char* json = libxl_device_usbctrl_to_json(ctx, usbctrl);
+   printf(usb controller: %s\n, json);
+   free(json);
+   libxl_device_usbctrl_dispose(usbctrl);
+   if (ferror(stdout) || fflush(stdout)) {
+   perror(stdout);
+   exit(-1);
+   }
+   return 0;
+}
+
+if (libxl_device_usbctrl_add(ctx, domid, usbctrl, 0)) {
+fprintf(stderr, libxl_device_usbctrl_add failed.\n);
+exit(-1);
+}
+libxl_device_usbctrl_dispose(usbctrl);
+return 0;

[Xen-devel] [PATCH RFC V2 4/5] xl: add pvusb commands

2015-01-19 Thread Chunyan Liu
Add pvusb commands.

To attach a usb device to guest through pvusb, one could follow
following example:

 #xl usb-ctrl-attach test_vm version=1 num_ports=8

 #xl usb-list test_vm
 will show the usb controllers and port usage under the domain.

 #xl usb-assignable-list
 will list all assignable usb devices now in host, with their
 sysfs interface. (This is very useful since later we will use
 sysfs interface to attach a usb devie to guest)

 #xl usb-attach test_vm 2-1.1
 will find the first usable controller:port, and attach usb
 device with sysfs interface 2-1.1 (sys/bus/usb/devices/2-1.1)
 to it. One could also specify which controller and which port

 #xl usb-detach test_vm 2-1.1

 #xl usb-ctrl-detach test_vm dev_id
 will destroy the controller with dev_id as specified. Dev_id
 can be traced in usb-list info

Signed-off-by: Chunyan Liu cy...@suse.com
Signed-off-by: Simon Cao caobosi...@gmail.com
---
 tools/libxl/xl.h  |   6 ++
 tools/libxl/xl_cmdimpl.c  | 256 ++
 tools/libxl/xl_cmdtable.c |  30 ++
 3 files changed, 292 insertions(+)

diff --git a/tools/libxl/xl.h b/tools/libxl/xl.h
index 5bc138c..f37a99f 100644
--- a/tools/libxl/xl.h
+++ b/tools/libxl/xl.h
@@ -86,6 +86,12 @@ int main_blockdetach(int argc, char **argv);
 int main_vtpmattach(int argc, char **argv);
 int main_vtpmlist(int argc, char **argv);
 int main_vtpmdetach(int argc, char **argv);
+int main_usbassignable_list(int argc, char **argv);
+int main_usbctrl_attach(int argc, char **argv);
+int main_usbctrl_detach(int argc, char **argv);
+int main_usbattach(int argc, char **argv);
+int main_usbdetach(int argc, char **argv);
+int main_usblist(int argc, char **argv);
 int main_uptime(int argc, char **argv);
 int main_claims(int argc, char **argv);
 int main_tmem_list(int argc, char **argv);
diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index 0b02a6c..a28f460 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -3000,6 +3000,262 @@ int main_cd_insert(int argc, char **argv)
 return 0;
 }
 
+static void usbinfo_print(libxl_device_usb *usbs, int num) {
+int i;
+if ( usbs == NULL )
+ return;
+libxl_usbinfo usbinfo;
+for (i = 0; i  num; i++) {
+/* TO BE Improved */
+if (usbs[i].port )
+printf(Port %d:, usbs[i].port);
+printf(Interface %8s , usbs[i].intf);
+if (!libxl_device_usb_getinfo(ctx, usbs[i].intf, usbinfo)) {
+printf(Bus %03d Dev %03d: %04d:%04d %s %s\n,
+usbinfo.bus, usbinfo.devnum, usbinfo.idVendor,
+usbinfo.idProduct, usbinfo.manuf, usbinfo.prod);
+}
+libxl_usbinfo_dispose(usbinfo);
+}
+}
+
+
+static void usb_assignable_list(void)
+{
+libxl_device_usb *usbs;
+int num;
+
+usbs = libxl_device_usb_assignable_list(ctx, num);
+
+usbinfo_print(usbs, num);
+
+free(usbs);
+}
+
+int main_usbassignable_list(int argc, char **argv)
+{
+int opt;
+
+SWITCH_FOREACH_OPT(opt, , NULL, usb-assignable-list, 0) {
+/* No options */
+}
+
+usb_assignable_list();
+return 0;
+}
+
+int main_usbctrl_attach(int argc, char **argv)
+{
+uint32_t domid;
+int opt;
+char *oparg;
+libxl_device_usbctrl usbctrl;
+
+SWITCH_FOREACH_OPT(opt, , NULL, usb-controller-attach, 1) {
+/* No options */
+}
+
+domid = find_domain(argv[optind++]);
+
+libxl_device_usbctrl_init(usbctrl);
+
+while (argc = optind) {
+if (MATCH_OPTION(type,  argv[optind], oparg)) {
+if (!strcmp(pv, oparg)) {
+usbctrl.type = LIBXL_USBCTRL_TYPE_PV;
+} else if(!strcmp(ioemu, oparg)) {
+usbctrl.type = LIBXL_USBCTRL_TYPE_DEVICEMODEL;
+} else {
+fprintf(stderr, Invalid parameter `type'.\n);
+exit(-1);
+}
+} else if (MATCH_OPTION(version, argv[optind], oparg)) {
+usbctrl.usb_version = atoi(oparg);
+} else if (MATCH_OPTION(num_ports, argv[optind], oparg)) {
+usbctrl.num_ports = atoi(oparg);
+}  else {
+fprintf(stderr, unrecognized argument `%s'\n, argv[optind]);
+exit(-1);
+}
+optind++;
+}
+
+if (dryrun_only) {
+   char* json = libxl_device_usbctrl_to_json(ctx, usbctrl);
+   printf(usb controller: %s\n, json);
+   free(json);
+   libxl_device_usbctrl_dispose(usbctrl);
+   if (ferror(stdout) || fflush(stdout)) {
+   perror(stdout);
+   exit(-1);
+   }
+   return 0;
+}
+
+if (libxl_device_usbctrl_add(ctx, domid, usbctrl, 0)) {
+fprintf(stderr, libxl_device_usbctrl_add failed.\n);
+exit(-1);
+}
+libxl_device_usbctrl_dispose(usbctrl);
+return 0;
+}
+
+int main_usbctrl_detach(int argc, char **argv)
+{
+uint32_t domid;
+int devid;
+int opt;
+libxl_device_usbctrl usbctrl;
+
+