WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] add the two command to add or delete the usb device instead

To: <xen-devel@xxxxxxxxxxxxxxxxxxx>
Subject: [Xen-devel] add the two command to add or delete the usb device instead of do it in QEMU console
From: "James Song" <jsong@xxxxxxxxxx>
Date: Thu, 15 Oct 2009 02:12:49 -0600
Delivery-date: Thu, 15 Oct 2009 01:13:19 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
Add the two commands( "xm usb-add" and "xm usb-del") to add or delete the usb device instead of do it in QEMU console.
 
Signed-off-by: James Song Wei <jsong@xxxxxxxxxx>
diff -r 41dbce3c96ea tools/ioemu-remote/xenstore.c
--- a/tools/ioemu-remote/xenstore.c     Tue Oct 13 14:23:10 2009 +0800
+++ b/tools/ioemu-remote/xenstore.c     Wed Oct 14 15:10:24 2009 +0800
@@ -908,6 +908,7 @@
     char *path = NULL, *command = NULL, *par = NULL;
     unsigned int len;
     extern char* snapshot_name;
+    extern void do_usb_add(const char *devname);
 
     if (pasprintf(&path,
                   "/local/domain/0/device-model/%u/command", domid) == -1) {
@@ -932,6 +933,34 @@
         }
 
         snapshot_name = xs_read(xsh, XBT_NULL, path, &len);
+    } else if (!strncmp(command, "usb-add", len)) {
+        fprintf(logfile, "dm-command: usb-add a usb device\n");
+        if (pasprintf(&path,
+                "/local/domain/0/device-model/%u/parameter", domid) == -1) {
+            fprintf(logfile, "out of memory reading dm command parameter\n");
+            goto out;
+        }
+        par = xs_read(xsh, XBT_NULL, path, &len);
+        fprintf(logfile, "dm-command: usb-add a usb device: %s \n", par);
+        if (!par)
+            goto out;
+        do_usb_add(par);
+        xenstore_record_dm_state("usb-added");
+        fprintf(logfile, "dm-command: finish usb-add a usb device:%s\n",par);
+    } else if (!strncmp(command, "usb-del", len)) {
+        fprintf(logfile, "dm-command: usb-del a usb device\n");
+        if (pasprintf(&path,
+                "/local/domain/0/device-model/%u/parameter", domid) == -1) {
+            fprintf(logfile, "out of memory reading dm command parameter\n");
+            goto out;
+        }
+        par = xs_read(xsh, XBT_NULL, path, &len);
+        fprintf(logfile, "dm-command: usb-del a usb device: %s \n", par);
+        if (!par)
+            goto out;
+        do_usb_del(par);
+        xenstore_record_dm_state("usb-deleted");
+        fprintf(logfile, "dm-command: finish usb-del a usb device:%s\n",par);
     } else if (!strncmp(command, "snapshot-delete", len)) {
         if (pasprintf(&path,
                 "/local/domain/0/device-model/%u/parameter", domid) == -1) {
diff -r 41dbce3c96ea tools/python/xen/xend/XendDomain.py
--- a/tools/python/xen/xend/XendDomain.py       Tue Oct 13 14:23:10 2009 +0800
+++ b/tools/python/xen/xend/XendDomain.py       Wed Oct 14 15:10:24 2009 +0800
@@ -1561,6 +1561,28 @@
             raise XendError("Unable to read snapshot file file %s: %s" %
                             (snap_file, ex[1]))
 
+    def domain_usb_add(self, domid, dev_id):
+        dominfo = self.domain_lookup_nr(domid)
+        if not dominfo:
+            raise XendInvalidDomain(str(domid))
+
+        if dominfo._stateGet() != DOM_STATE_HALTED:
+            dominfo.image.signalDeviceModel("usb-add",
+                "usb-added", dev_id)
+        else:
+            log.debug("error: Domain is not running!")
+
+    def domain_usb_del(self, domid, dev_id):
+        dominfo = self.domain_lookup_nr(domid)
+        if not dominfo:
+            raise XendInvalidDomain(str(domid))
+
+        if dominfo._stateGet() != DOM_STATE_HALTED:
+            dominfo.image.signalDeviceModel("usb-del",
+                "usb-deleted", dev_id)
+        else:
+            log.debug("error: Domain is not running!")
+
     def domain_snapshot_delete(self, domid, name):
         """Delete domain snapshot
 
diff -r 41dbce3c96ea tools/python/xen/xend/server/SrvDomain.py
--- a/tools/python/xen/xend/server/SrvDomain.py Tue Oct 13 14:23:10 2009 +0800
+++ b/tools/python/xen/xend/server/SrvDomain.py Wed Oct 14 15:10:24 2009 +0800
@@ -120,6 +120,20 @@
     def do_snapshot_delete(self, _, req):
         return self.xd.domain_snapshot_delete(self.dom.getName(), req.args['name'][0])
 
+    def op_usb_add(self, op, req):
+        self.acceptCommand(req)
+        return req.threadRequest(self.do_usb_add, op, req)
+
+    def do_usb_add(self, _, req):
+        return self.xd.domain_usb_add(self.dom.getName(), req)
+
+    def op_usb_del(self, op, req):
+        self.acceptCommand(req)
+        return req.threadRequest(self.do_usb_add, op, req)
+
+    def do_usb_del(self, _, req):
+        return self.xd.domain_usb_add(self.dom.getName(), req)
+
     def op_dump(self, op, req):
         self.acceptCommand(req)
         return req.threadRequest(self.do_dump, op, req)
diff -r 41dbce3c96ea tools/python/xen/xm/main.py
--- a/tools/python/xen/xm/main.py       Tue Oct 13 14:23:10 2009 +0800
+++ b/tools/python/xen/xm/main.py       Wed Oct 14 15:10:24 2009 +0800
@@ -168,6 +168,9 @@
     'vcpu-set'    : ('<Domain> <vCPUs>',
                      'Set the number of active VCPUs for allowed for the'
                      ' domain.'),
+    #usb
+    'usb-add'     : ('<domain> <[host:bus.addr] [host:vendor_id:product_id]>','Add the usb device to FV VM.'),
+    'usb-del'     : ('<domain> <[host:bus.addr] [host:vendor_id:product_id]>','Delete the usb device to FV VM.'),
 
     # device commands
 
@@ -325,6 +328,8 @@
     "top",
     "unpause",
     "uptime",
+    "usb-add",
+    "usb-del",
     "vcpu-set",
     ]
 
@@ -361,6 +366,8 @@
     "top",
     "unpause",
     "uptime",
+    "usb-add",
+    "usb-del",
     "vcpu-list",
     "vcpu-pin",
     "vcpu-set",
@@ -1500,6 +1507,14 @@
         mem_target = int_unit(args[1], 'm')
         server.xend.domain.setMemoryTarget(dom, mem_target)
 
+def xm_usb_add(args):
+    arg_check(args, "usb-add", 2)
+    server.xend.domain.usb_add(args[0],args[1])
+
+def xm_usb_del(args):
+    arg_check(args, "usb-del", 2)
+    server.xend.domain.usb_del(args[0],args[1])
+
 def xm_vcpu_set(args):
     arg_check(args, "vcpu-set", 2)
 
@@ -2990,6 +3005,9 @@
     "scsi-attach": xm_scsi_attach,
     "scsi-detach": xm_scsi_detach,
     "scsi-list": xm_scsi_list,
+    #usb
+    "usb-add": xm_usb_add,
+    "usb-del": xm_usb_del,
     }
 
 ## The commands supported by a separate argument parser in xend.xm.
 
 
 
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel