The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/2529

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
In case netlink does not give us the cheap way of retrieving the usb device path
let's fallback to using the busnum and devnum as before. In other news, I'm less
optimistic about netlink infos then before. :)

Signed-off-by: Christian Brauner <[email protected]>
From e4eead7963ced7ec165e70474c444fe48ac645a0 Mon Sep 17 00:00:00 2001
From: Christian Brauner <[email protected]>
Date: Wed, 19 Oct 2016 11:15:10 +0200
Subject: [PATCH] lxd/devices: be less optimistic about netlink info

In case netlink does not give us the cheap way of retrieving the usb device path
let's fallback to using the busnum and devnum as before. In other news, I'm less
optimistic about netlink infos then before. :)

Signed-off-by: Christian Brauner <[email protected]>
---
 lxd/devices.go | 32 +++++++++++++++++++++++++++++---
 1 file changed, 29 insertions(+), 3 deletions(-)

diff --git a/lxd/devices.go b/lxd/devices.go
index 2e21bcb..6a30a0f 100644
--- a/lxd/devices.go
+++ b/lxd/devices.go
@@ -55,7 +55,7 @@ type usbDevice struct {
        minor int
 }
 
-func createUSBDevice(action string, vendor string, product string, major 
string, minor string, devname string) (usbDevice, error) {
+func createUSBDevice(action string, vendor string, product string, major 
string, minor string, busnum string, devnum string, devname string) (usbDevice, 
error) {
        majorInt, err := strconv.Atoi(major)
        if err != nil {
                return usbDevice{}, err
@@ -67,8 +67,21 @@ func createUSBDevice(action string, vendor string, product 
string, major string,
        }
 
        path := devname
-       if !filepath.IsAbs(devname) {
-               path = fmt.Sprintf("/dev/%s", devname)
+       if devname == "" {
+               busnumInt, err := strconv.Atoi(busnum)
+               if err != nil {
+                       return usbDevice{}, err
+               }
+
+               devnumInt, err := strconv.Atoi(devnum)
+               if err != nil {
+                       return usbDevice{}, err
+               }
+               path = fmt.Sprintf("/dev/bus/usb/%03d/%03d", busnumInt, 
devnumInt)
+       } else {
+               if !filepath.IsAbs(devname) {
+                       path = fmt.Sprintf("/dev/%s", devname)
+               }
        }
 
        return usbDevice{
@@ -180,11 +193,20 @@ func deviceNetlinkListener() (chan []string, chan 
[]string, chan usbDevice, erro
                                if !ok {
                                        continue
                                }
+
                                minor, ok := props["MINOR"]
                                if !ok {
                                        continue
                                }
+
                                devname, ok := props["DEVNAME"]
+
+                               busnum, ok := props["BUSNUM"]
+                               if !ok {
+                                       continue
+                               }
+
+                               devnum, ok := props["DEVNUM"]
                                if !ok {
                                        continue
                                }
@@ -203,6 +225,8 @@ func deviceNetlinkListener() (chan []string, chan []string, 
chan usbDevice, erro
                                        zeroPad(parts[1], 4),
                                        major,
                                        minor,
+                                       busnum,
+                                       devnum,
                                        devname,
                                )
                                if err != nil {
@@ -1025,6 +1049,8 @@ func deviceLoadUsb() ([]usbDevice, error) {
                        values["idProduct"],
                        parts[0],
                        parts[1],
+                       values["busnum"],
+                       values["devnum"],
                        values["devname"],
                )
                if err != nil {
_______________________________________________
lxc-devel mailing list
[email protected]
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to