When starting an LXC container, the /dev entries are created
under temp root (/var/run/libvirt/lxc/$name.dev), relabelled and
then the root is pivoted. However, when it comes to USB devices
which keep path to the device in the structure we need a way to
override the default /dev/usb/... path because we want to work
with the one under temp root. That's what @vroot argument is for
in virUSBDeviceNew. However, what is being passed there is:
vroot = /var/run/libvirt/lxc/lxc_0.dev/bus/usb
Therefore, constructed path is wrong:
dev->path = //var/run/libvirt/lxc/lxc_0.dev/bus/usb//dev/bus/usb/002/002
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
src/util/virusb.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/src/util/virusb.c b/src/util/virusb.c
index 6359235ff..f06639eec 100644
--- a/src/util/virusb.c
+++ b/src/util/virusb.c
@@ -343,9 +343,13 @@ virUSBDeviceNew(unsigned int bus,
virUSBDeviceFree(dev);
return NULL;
}
- if (virAsprintf(&dev->path, "%s" USB_DEVFS "%03d/%03d",
- vroot ? vroot : "",
- dev->bus, dev->dev) < 0) {
+
+ if ((vroot &&
+ virAsprintf(&dev->path, "%s/%03d/%03d",
+ vroot, dev->bus, dev->dev) < 0) ||
+ (!vroot &&
+ virAsprintf(&dev->path, USB_DEVFS "%03d/%03d",
+ dev->bus, dev->dev) < 0)) {
virUSBDeviceFree(dev);
return NULL;
}
--
2.13.6
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
On 01/24/2018 04:37 AM, Michal Privoznik wrote: > When starting an LXC container, the /dev entries are created > under temp root (/var/run/libvirt/lxc/$name.dev), relabelled and > then the root is pivoted. However, when it comes to USB devices > which keep path to the device in the structure we need a way to > override the default /dev/usb/... path because we want to work > with the one under temp root. That's what @vroot argument is for > in virUSBDeviceNew. However, what is being passed there is: > > vroot = /var/run/libvirt/lxc/lxc_0.dev/bus/usb > > Therefore, constructed path is wrong: > > dev->path = //var/run/libvirt/lxc/lxc_0.dev/bus/usb//dev/bus/usb/002/002 > > Signed-off-by: Michal Privoznik <mprivozn@redhat.com> > --- > src/util/virusb.c | 10 +++++++--- > 1 file changed, 7 insertions(+), 3 deletions(-) > Reviewed-by: John Ferlan <jferlan@redhat.com> > diff --git a/src/util/virusb.c b/src/util/virusb.c > index 6359235ff..f06639eec 100644 > --- a/src/util/virusb.c > +++ b/src/util/virusb.c > @@ -343,9 +343,13 @@ virUSBDeviceNew(unsigned int bus, > virUSBDeviceFree(dev); > return NULL; > } > - if (virAsprintf(&dev->path, "%s" USB_DEVFS "%03d/%03d", > - vroot ? vroot : "", > - dev->bus, dev->dev) < 0) { > + > + if ((vroot && > + virAsprintf(&dev->path, "%s/%03d/%03d", > + vroot, dev->bus, dev->dev) < 0) || > + (!vroot && > + virAsprintf(&dev->path, USB_DEVFS "%03d/%03d", > + dev->bus, dev->dev) < 0)) { This I think is of those cases where something like: if (vroot) rc = virAsprintf() else rc = virAsprintf() if (rc < 0) just is easier to read. Your call - the code works, just causes personal eye irritation ;-) John > virUSBDeviceFree(dev); > return NULL; > } > -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
© 2016 - 2025 Red Hat, Inc.