From: "Chun Yan Liu" Subject: Re: [PATCH v10 3/5] libxl: add pvusb API Date: Mon, 14 Dec 2015 00:25:04 -0700 Message-ID: <566EDF50020000660008FC65@relay2.provo.novell.com> References: <1449749113-1243-1-git-send-email-george.dunlap@eu.citrix.com> <1449749113-1243-4-git-send-email-george.dunlap@eu.citrix.com> <56696B4B.7060801@citrix.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartFEC9CBC0.3__=" Return-path: In-Reply-To: <56696B4B.7060801@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: George Dunlap , George Dunlap , xen-devel@lists.xen.org Cc: Ian Jackson , Simon Cao , Wei Liu , IanCampbell List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__PartFEC9CBC0.3__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline >>> On 12/10/2015 at 08:08 PM, in message <56696B4B.7060801@citrix.com>, = George Dunlap wrote:=20 > On 10/12/15 12:05, George Dunlap wrote:=20 > > From: Chunyan Liu =20 > > =20 > > Add pvusb APIs, including:=20 > > - attach/detach (create/destroy) virtual usb controller.=20 > > - attach/detach usb device=20 > > - list usb controller and usb devices=20 > > - some other helper functions=20 > > =20 > > Signed-off-by: Chunyan Liu =20 > > Signed-off-by: Simon Cao =20 > > Signed-off-by: George Dunlap =20 > =20 > Attached is a diff of v9 -> v10 for convenience.=20 Thanks very much, George! I've applied your new patch and tested, there are a couple of changes = needed to get tests PASSED. A small extra patch is written on top of your new patch, = as in attachment, please have a look. Otherwise, I agreed with all your other changes. It's great improvement. Thanks a lot! =20 > =20 > One remaining question I had regarding this patch...=20 For the question, see below. > =20 > > +static int usbdev_get_all_interfaces(libxl__gc *gc, const char = *busid,=20 > > + char ***intfs, int *num)=20 > > +{=20 > > + DIR *dir;=20 > > + char *buf;=20 > > + int rc;=20 > > +=20 > > + *intfs =3D NULL;=20 > > + *num =3D 0;=20 > > +=20 > > + buf =3D GCSPRINTF("%s:", busid);=20 > > +=20 > > + dir =3D opendir(SYSFS_USB_DEV);=20 > > + if (!dir) {=20 > > + LOGE(ERROR, "opendir failed: '%s'", SYSFS_USB_DEV);=20 > > + return ERROR_FAIL;=20 > > + }=20 > > +=20 > > + size_t need =3D offsetof(struct dirent, d_name) +=20 > > + pathconf(SYSFS_USB_DEV, _PC_NAME_MAX) + 1;=20 > > + struct dirent *de_buf =3D libxl__zalloc(gc, need);=20 > =20 > Is this thing with manually calculating the size of the structure = really=20 > necessary? Could we not just declare "struct dirent de_buf" on the = stack? Calculating in above way is to allocate enough space for d_name, whereas "struct dirent de_buf" won't allocate space for d_name (which is char *). Codes for calling read_dir_r are often done like above. - Chunyan > =20 > If it is necessary, it would be better to have it inside a function = or=20 > macro called "alloc_dirent" or something like that.=20 > =20 > -George=20 > =20 > =20 --=__PartFEC9CBC0.3__= Content-Type: text/plain; name="0004-libxl-pvusb-API-changes.PATCH" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="0004-libxl-pvusb-API-changes.PATCH" >From 771c99218a4704eb6a4850dfafb1cafad0798b9d Mon Sep 17 00:00:00 = 2001=0AFrom: Chunyan Liu =0ADate: Mon, 14 Dec 2015 = 15:00:50 +0800=0ASubject: [PATCH 4/6] libxl pvusb API changes=0A=0A* = format fix: extra white space, line > 80, etc.=0A* return ERROR_FAILED = instead of errno (>0) in sysfs_write_intf=0A* fix an error in libxl_ctrlpor= t_to_device_usbdev=0A=0ASigned-off-by: Chunyan Liu =0A---= =0A tools/libxl/libxl_pvusb.c | 34 +++++++++++++++++-----------------=0A 1 = file changed, 17 insertions(+), 17 deletions(-)=0A=0Adiff --git a/tools/lib= xl/libxl_pvusb.c b/tools/libxl/libxl_pvusb.c=0Aindex cb25fa8..5f189d6 = 100644=0A--- a/tools/libxl/libxl_pvusb.c=0A+++ b/tools/libxl/libxl_pvusb.c= =0A@@ -287,14 +287,15 @@ out:=0A return;=0A }=0A =0A-static const char = * vusb_be_from_xs_fe(libxl__gc *gc, const char *fe_path,=0A- = uint32_t tgt_domid) {=0A+static const char = *vusb_be_from_xs_fe(libxl__gc *gc, const char *fe_path,=0A+ = uint32_t tgt_domid)=0A+{=0A const char = *be_path;=0A int r;=0A uint32_t be_domid, fe_domid;=0A- =0A+=0A = r =3D libxl__xs_read_checked(gc, XBT_NULL, GCSPRINTF("%s/backend", = fe_path),=0A- &be_path);=0A+ = &be_path);=0A if (r || !be_path) return NULL;=0A =0A = /* Check to see that it has the proper form, and that fe_domid =3D=3D=0A@= @ -302,11 +303,11 @@ static const char * vusb_be_from_xs_fe(libxl__gc *gc, = const char *fe_path,=0A r =3D sscanf(be_path, "/local/domain/%d/backend= /vusb/%d",=0A &be_domid, &fe_domid);=0A =0A- if ( r !=3D = 2 || fe_domid !=3D tgt_domid ) {=0A+ if (r !=3D 2 || fe_domid !=3D = tgt_domid) {=0A LOG(ERROR, "Malformed backend, refusing to = use");=0A return NULL;=0A }=0A- =0A+=0A return = be_path;=0A }=0A =0A@@ -810,7 +811,7 @@ static int libxl__device_usbdev_set= default(libxl__gc *gc,=0A } else {=0A /* A controller was = specified; look it up */=0A const char *fe_path, *be_path, = *tmp;=0A- =0A+=0A fe_path =3D GCSPRINTF("%s/device/vusb/%d",= =0A libxl__xs_get_dompath(gc, domid),=0A = usbdev->ctrl);=0A@@ -828,7 +829,7 @@ static int = libxl__device_usbdev_setdefault(libxl__gc *gc,=0A = be_path, usbdev->port),=0A = &tmp);=0A if (rc) goto out;=0A- = =0A+=0A if (tmp && strcmp(tmp, "")) {=0A = LOG(ERROR, "The controller port isn't available");=0A rc = =3D ERROR_FAIL;=0A@@ -837,7 +838,7 @@ static int libxl__device_usbdev_setde= fault(libxl__gc *gc,=0A } else {=0A /* No port was = requested. Choose free port. */=0A int i, ports;=0A- = =0A+=0A rc =3D libxl__xs_read_checked(gc, XBT_NULL,=0A = GCSPRINTF("%s/num-ports", be_path), = &tmp);=0A if (rc) goto out;=0A@@ -849,7 +850,7 @@ static int = libxl__device_usbdev_setdefault(libxl__gc *gc,=0A = GCSPRINTF("%s/port/%d", be_path, i + 1),=0A = &tmp);=0A if (rc) goto = out;=0A- =0A+=0A if (tmp && !strcmp(tmp, = "")) {=0A usbdev->port =3D i + 1;=0A = break;=0A@@ -863,7 +864,7 @@ static int libxl__device_usbdev_setdefault(l= ibxl__gc *gc,=0A }=0A }=0A }=0A- =0A+=0A rc = =3D 0;=0A =0A out:=0A@@ -1006,7 +1007,7 @@ static int sysfs_write_intf(libx= l__gc *gc, const char *intf, const char *path)=0A close(fd);=0A if = (rc < 0) {=0A LOGE(ERROR, "write '%s' to '%s' failed", intf, = path);=0A- return errno;=0A+ return ERROR_FAIL;=0A }=0A = if (rc !=3D strlen(intf)) {=0A LOG(ERROR, "write '%s' to '%s' = failed: incorrect write count",=0A@@ -1498,15 +1499,14 @@ int libxl_ctrlpor= t_to_device_usbdev(libxl_ctx *ctx,=0A = libxl_device_usbdev *usbdev)=0A {=0A GC_INIT(ctx);=0A- const char = *dompath, *be_path, *busid;=0A+ const char *dompath, *fe_path, = *be_path, *busid;=0A int rc;=0A =0A dompath =3D libxl__xs_get_dompa= th(gc, domid);=0A =0A- be_path =3D vusb_be_from_xs_fe(gc,=0A- = GCSPRINTF("%s/device/vusb/%d/backend",=0A- = dompath, ctrl),=0A- = domid);=0A+ fe_path =3D GCSPRINTF("%s/device/vusb/%d", = dompath, ctrl);=0A+=0A+ be_path =3D vusb_be_from_xs_fe(gc, fe_path, = domid);=0A if (!be_path) {=0A rc =3D ERROR_FAIL;=0A = goto out;=0A-- =0A2.1.4=0A=0A --=__PartFEC9CBC0.3__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__PartFEC9CBC0.3__=--