Skip to contentSkip to conversation

pvusb fixes

PATCH In review Chunyan Liu 3 participants 13 messages Apr 7, 2016 – Apr 8, 2016

lore
Share & tools
lore
#0 lore raw

cover pvusb fixes

Patch series of pvusb fixes.

Chunyan Liu (4):
a fix in libxl_device_usbdev_list
correct libxl_write_exactly sizeof
cleanup redundant lstat in libxl_pvusb.c
fix a pvusb type check

 tools/libxl/libxl_pvusb.c | 38 +++++++++++++++++---------------------
 1 file changed, 17 insertions(+), 21 deletions(-)
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#1 lore raw

PATCH 1/4 a fix in libxl_device_usbdev_list

In testing with libvirt pvusb functionality, found a rc check error in libxl_device_usbdev_list. Correct it. This function is not used by xl.

CC Simon Cao <[email protected]>
CC George Dunlap <[email protected]>
CC Ian Jackson <[email protected]>
---
 tools/libxl/libxl_pvusb.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tools/libxl/libxl_pvusb.c +3 -3
index 5f92628..04e41b4 100644
@@ -701,13 +701,13 @@ libxl_device_usbdev_list(libxl_ctx *ctx, uint32_t domid, int *num)
     usbctrls = libxl__xs_directory(gc, XBT_NULL, path, &nc);
 
     for (i = 0; i < nc; i++) {
-        int r, nd = 0;
+        int rc, nd = 0;
         libxl_device_usbdev *tmp = NULL;
 
-        r = libxl__device_usbdev_list_for_usbctrl(gc, domid,
+        rc = libxl__device_usbdev_list_for_usbctrl(gc, domid,
                                                   atoi(usbctrls[i]),
                                                   &tmp, &nd);
-        if (!r || !nd) continue;
+        if (rc || !nd) continue;
 
         usbdevs = libxl__realloc(NOGC, usbdevs,
                                  sizeof(*usbdevs) * (*num + nd));
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#2 lore raw

Re: [PATCH 1/4] a fix in libxl_device_usbdev_list

Chunyan Liu writes ("[PATCH 1/4] a fix in libxl_device_usbdev_list"):

Quoted 2 lines

In testing with libvirt pvusb functionality, found a rc check error in libxl_device_usbdev_list. Correct it.

Thanks. But now that I look at this code I'm not sure your fix is complete.

Quoted 8 lines
tools/libxl/libxl_pvusb.c +0 -0
index 5f92628..04e41b4 100644
@@ -701,13 +701,13 @@ libxl_device_usbdev_list(libxl_ctx *ctx, uint32_t domid, int *num)
     usbctrls = libxl__xs_directory(gc, XBT_NULL, path, &nc);
 
     for (i = 0; i < nc; i++) {

tools/libxl/libxl_pvusb.c libxl_device_usbdev_list(libxl_ctx *ctx, uint32_t domid, int *num) · line 710

Quoted 10 lines
tools/libxl/libxl_pvusb.c +3 -3
-        int r, nd = 0;
+        int rc, nd = 0;
         libxl_device_usbdev *tmp = NULL;
 
-        r = libxl__device_usbdev_list_for_usbctrl(gc, domid,
+        rc = libxl__device_usbdev_list_for_usbctrl(gc, domid,
                                                   atoi(usbctrls[i]),
                                                   &tmp, &nd);
-        if (!r || !nd) continue;
+        if (rc || !nd) continue;

If libxl__device_usbdev_list_for_usbctrl fails, shouldn't libxl_device_usbdev_list fail too ?

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#3 lore raw

Re: [PATCH 1/4] a fix in libxl_device_usbdev_list

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

On 4/8/2016 at 12:45 AM, in message

<[email protected]>, Ian Jackson

Quoted 27 lines · <[email protected]> wrote:

Chunyan Liu writes ("[PATCH 1/4] a fix in libxl_device_usbdev_list"):

Quoted 2 lines

In testing with libvirt pvusb functionality, found a rc check error in libxl_device_usbdev_list. Correct it.

Thanks. But now that I look at this code I'm not sure your fix is complete.

tools/libxl/libxl_pvusb.c libxl_device_usbdev_list(libxl_ctx *ctx, uint32_t

Quoted 5 lines
tools/libxl/libxl_pvusb.c +0 -0
index 5f92628..04e41b4 100644 
@@ -701,13 +701,13 @@ libxl_device_usbdev_list(libxl_ctx *ctx, uint32_t  

domid, int *num)

tools/libxl/libxl_pvusb.c libxl_device_usbdev_list(libxl_ctx *ctx, uint32_t domid, int *num) · line 710

Quoted 13 lines
tools/libxl/libxl_pvusb.c +3 -3
     usbctrls = libxl__xs_directory(gc, XBT_NULL, path, &nc); 
 
     for (i = 0; i < nc; i++) { 
-        int r, nd = 0; 
+        int rc, nd = 0; 
         libxl_device_usbdev *tmp = NULL; 
 
-        r = libxl__device_usbdev_list_for_usbctrl(gc, domid, 
+        rc = libxl__device_usbdev_list_for_usbctrl(gc, domid, 
                                                   atoi(usbctrls[i]), 
                                                   &tmp, &nd); 
-        if (!r || !nd) continue; 
+        if (rc || !nd) continue; 
Quoted 2 lines

If libxl__device_usbdev_list_for_usbctrl fails, shouldn't libxl_device_usbdev_list fail too ?

Following the similar definitions of other device types, the return value of this function is "libxl_device_usbdev *", to treat the above case as failure, it cannot be reflected through return value, we can only set return value to NULL, but that will be confusing with a real no-device case.

- Chunyan

Quoted 4 lines

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

Acked-by
#4 lore raw

Re: [PATCH 1/4] a fix in libxl_device_usbdev_list

Chun Yan Liu writes ("Re: [PATCH 1/4] a fix in libxl_device_usbdev_list"):

Quoted 10 lines
Quoted 2 lines · Ian Jackson

If libxl__device_usbdev_list_for_usbctrl fails, shouldn't libxl_device_usbdev_list fail too ?

Following the similar definitions of other device types, the return value of this function is "libxl_device_usbdev *", to treat the above case as failure, it cannot be reflected through return value, we can only set return value to NULL, but that will be confusing with a real no-device case.

Urk. Yes, you're right. *sigh*

We won't fix that bad API pattern for 4.7. So

Thanks,
Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#6 lore raw

Re: [PATCH 1/4] a fix in libxl_device_usbdev_list

In reply to Chunyan Liu

Chunyan Liu writes ("[PATCH 1/4] a fix in libxl_device_usbdev_list"):

Quoted 3 lines

In testing with libvirt pvusb functionality, found a rc check error in libxl_device_usbdev_list. Correct it. This function is not used by xl.

Thanks for these. I have applied 2,3, and 4. But not 1, as I had comments on it.

Regards,
Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#7 lore raw

PATCH 2/4 correct libxl_write_exactly sizeof

In reply to Chunyan Liu

sizeof is wrongly used in libxl_write_exactly function, using strlen instead.

CID: 1358110
CID: 1358109

CC Simon Cao <[email protected]>
CC George Dunlap <[email protected]>
CC Ian Jackson <[email protected]>
---
 tools/libxl/libxl_pvusb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/libxl/libxl_pvusb.c +2 -2
index 04e41b4..45117cf 100644
@@ -1025,7 +1025,7 @@ static int unbind_usbintf(libxl__gc *gc, const char *intf)
         goto out;
     }
 
-    if (libxl_write_exactly(CTX, fd, intf, sizeof(intf), path, intf)) {
+    if (libxl_write_exactly(CTX, fd, intf, strlen(intf), path, intf)) {
         rc = ERROR_FAIL;
         goto out;
     }
@@ -1065,7 +1065,7 @@ static int bind_usbintf(libxl__gc *gc, const char *intf, const char *drvpath)
         goto out;
     }
 
-    if (libxl_write_exactly(CTX, fd, intf, sizeof(intf), path, intf)) {
+    if (libxl_write_exactly(CTX, fd, intf, strlen(intf), path, intf)) {
         rc = ERROR_FAIL;
         goto out;
     }
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#9 lore raw

PATCH 3/4 cleanup redundant lstat in libxl_pvusb.c

In reply to Chunyan Liu

CID: 1358112

CC Simon Cao <[email protected]>
CC George Dunlap <[email protected]>
CC Ian Jackson <[email protected]>
---
 tools/libxl/libxl_pvusb.c | 21 +++++----------------
 1 file changed, 5 insertions(+), 16 deletions(-)
tools/libxl/libxl_pvusb.c +5 -16
index 45117cf..02d3e55 100644
@@ -983,25 +983,14 @@ static char *usbdev_busid_from_ctrlport(libxl__gc *gc, uint32_t domid,
 static int usbintf_get_drvpath(libxl__gc *gc, const char *intf, char **drvpath)
 {
     char *spath, *dp = NULL;
-    struct stat st;
-    int r;
 
     spath = GCSPRINTF(SYSFS_USB_DEV "/%s/driver", intf);
 
-    r = lstat(spath, &st);
-    if (r == 0) {
-        /* Find the canonical path to the driver. */
-        dp = libxl__zalloc(gc, PATH_MAX);
-        dp = realpath(spath, dp);
-        if (!dp) {
-            LOGE(ERROR, "get realpath failed: '%s'", spath);
-            return ERROR_FAIL;
-        }
-    } else if (errno == ENOENT) {
-        /* driver path doesn't exist */
-        dp = NULL;
-    } else {
-        LOGE(ERROR, "lstat failed: '%s'", spath);
+    /* Find the canonical path to the driver. */
+    dp = libxl__zalloc(gc, PATH_MAX);
+    dp = realpath(spath, dp);
+    if (!dp && errno != ENOENT) {
+        LOGE(ERROR, "get realpath failed: '%s'", spath);
         return ERROR_FAIL;
     }
 
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Acked-by on v1 3/4
#10 lore raw

Re: [PATCH 3/4] cleanup redundant lstat in libxl_pvusb.c

Chunyan Liu writes ("[PATCH 3/4] cleanup redundant lstat in libxl_pvusb.c"):

Quoted 6 lines

CID: 1358112

CC Simon Cao <[email protected]>
CC George Dunlap <[email protected]>
CC Ian Jackson <[email protected]>

Although for this and the previous patch, it would have been better to add "libxl:" to the start of the Subject.

I will fix that up as I commit.

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#11 lore raw

PATCH 4/4 fix a pvusb type check

In reply to Chunyan Liu

Missing a check of controller type.

CC Simon Cao <[email protected]>
CC George Dunlap <[email protected]>
CC Ian Jackson <[email protected]>
CC Juergen Gross <[email protected]>

---
This affects Juergen's qusb patch too. Fix that together. This patch could be applied on top of Juergen's qusb backend patch.

 tools/libxl/libxl_pvusb.c | 7 +++++++
 1 file changed, 7 insertions(+)
tools/libxl/libxl_pvusb.c +7 -0
index 02d3e55..6447639 100644
@@ -811,6 +811,13 @@ static int libxl__device_usbdev_setdefault(libxl__gc *gc,
                 }
             }
 
+            if (usbctrl->type != LIBXL_USBCTRL_TYPE_PV &&
+                usbctrl->type != LIBXL_USBCTRL_TYPE_QUSB) {
+                LOG(ERROR, "Unsupported USB controller type");
+                rc = ERROR_FAIL;
+                goto out;
+            }
+
             rc = libxl__device_usbctrl_add_xenstore(gc, domid, usbctrl,
                                                     update_json);
             if (rc) goto out;
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Reviewed-by on v1 4/4
#12 lore raw

Re: [PATCH 4/4] fix a pvusb type check

Quoted 7 lines · Chunyan Liu

Missing a check of controller type.

CC Simon Cao <[email protected]>
CC George Dunlap <[email protected]>
CC Ian Jackson <[email protected]>
CC Juergen Gross <[email protected]>
Quoted 16 lines

---
This affects Juergen's qusb patch too. Fix that together. This patch could be applied on top of Juergen's qusb backend patch.

 tools/libxl/libxl_pvusb.c | 7 +++++++
 1 file changed, 7 insertions(+)
tools/libxl/libxl_pvusb.c +0 -0
index 02d3e55..6447639 100644
@@ -811,6 +811,13 @@ static int libxl__device_usbdev_setdefault(libxl__gc *gc,
                 }
             }
 

tools/libxl/libxl_pvusb.c static int libxl__device_usbdev_setdefault(libxl__gc *gc, · line 823

Quoted 10 lines
tools/libxl/libxl_pvusb.c +7 -0
+            if (usbctrl->type != LIBXL_USBCTRL_TYPE_PV &&
+                usbctrl->type != LIBXL_USBCTRL_TYPE_QUSB) {
+                LOG(ERROR, "Unsupported USB controller type");
+                rc = ERROR_FAIL;
+                goto out;
+            }
+
             rc = libxl__device_usbctrl_add_xenstore(gc, domid, usbctrl,
                                                     update_json);
             if (rc) goto out;

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel