From 771c99218a4704eb6a4850dfafb1cafad0798b9d Mon Sep 17 00:00:00 2001 From: Chunyan Liu Date: Mon, 14 Dec 2015 15:00:50 +0800 Subject: [PATCH 4/6] libxl pvusb API changes * format fix: extra white space, line > 80, etc. * return ERROR_FAILED instead of errno (>0) in sysfs_write_intf * fix an error in libxl_ctrlport_to_device_usbdev Signed-off-by: Chunyan Liu --- tools/libxl/libxl_pvusb.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/tools/libxl/libxl_pvusb.c b/tools/libxl/libxl_pvusb.c index cb25fa8..5f189d6 100644 --- a/tools/libxl/libxl_pvusb.c +++ b/tools/libxl/libxl_pvusb.c @@ -287,14 +287,15 @@ out: return; } -static const char * vusb_be_from_xs_fe(libxl__gc *gc, const char *fe_path, - uint32_t tgt_domid) { +static const char *vusb_be_from_xs_fe(libxl__gc *gc, const char *fe_path, + uint32_t tgt_domid) +{ const char *be_path; int r; uint32_t be_domid, fe_domid; - + r = libxl__xs_read_checked(gc, XBT_NULL, GCSPRINTF("%s/backend", fe_path), - &be_path); + &be_path); if (r || !be_path) return NULL; /* Check to see that it has the proper form, and that fe_domid == @@ -302,11 +303,11 @@ static const char * vusb_be_from_xs_fe(libxl__gc *gc, const char *fe_path, r = sscanf(be_path, "/local/domain/%d/backend/vusb/%d", &be_domid, &fe_domid); - if ( r != 2 || fe_domid != tgt_domid ) { + if (r != 2 || fe_domid != tgt_domid) { LOG(ERROR, "Malformed backend, refusing to use"); return NULL; } - + return be_path; } @@ -810,7 +811,7 @@ static int libxl__device_usbdev_setdefault(libxl__gc *gc, } else { /* A controller was specified; look it up */ const char *fe_path, *be_path, *tmp; - + fe_path = GCSPRINTF("%s/device/vusb/%d", libxl__xs_get_dompath(gc, domid), usbdev->ctrl); @@ -828,7 +829,7 @@ static int libxl__device_usbdev_setdefault(libxl__gc *gc, be_path, usbdev->port), &tmp); if (rc) goto out; - + if (tmp && strcmp(tmp, "")) { LOG(ERROR, "The controller port isn't available"); rc = ERROR_FAIL; @@ -837,7 +838,7 @@ static int libxl__device_usbdev_setdefault(libxl__gc *gc, } else { /* No port was requested. Choose free port. */ int i, ports; - + rc = libxl__xs_read_checked(gc, XBT_NULL, GCSPRINTF("%s/num-ports", be_path), &tmp); if (rc) goto out; @@ -849,7 +850,7 @@ static int libxl__device_usbdev_setdefault(libxl__gc *gc, GCSPRINTF("%s/port/%d", be_path, i + 1), &tmp); if (rc) goto out; - + if (tmp && !strcmp(tmp, "")) { usbdev->port = i + 1; break; @@ -863,7 +864,7 @@ static int libxl__device_usbdev_setdefault(libxl__gc *gc, } } } - + rc = 0; out: @@ -1006,7 +1007,7 @@ static int sysfs_write_intf(libxl__gc *gc, const char *intf, const char *path) close(fd); if (rc < 0) { LOGE(ERROR, "write '%s' to '%s' failed", intf, path); - return errno; + return ERROR_FAIL; } if (rc != strlen(intf)) { LOG(ERROR, "write '%s' to '%s' failed: incorrect write count", @@ -1498,15 +1499,14 @@ int libxl_ctrlport_to_device_usbdev(libxl_ctx *ctx, libxl_device_usbdev *usbdev) { GC_INIT(ctx); - const char *dompath, *be_path, *busid; + const char *dompath, *fe_path, *be_path, *busid; int rc; dompath = libxl__xs_get_dompath(gc, domid); - be_path = vusb_be_from_xs_fe(gc, - GCSPRINTF("%s/device/vusb/%d/backend", - dompath, ctrl), - domid); + fe_path = GCSPRINTF("%s/device/vusb/%d", dompath, ctrl); + + be_path = vusb_be_from_xs_fe(gc, fe_path, domid); if (!be_path) { rc = ERROR_FAIL; goto out; -- 2.1.4