Blob Blame History Raw
From 466aaa3977c8cd9728a9f53a457de385c49d4e37 Mon Sep 17 00:00:00 2001
From: Dan Callaghan <dcallagh@redhat.com>
Date: Wed, 29 Jul 2015 18:09:49 +1000
Subject: [PATCH 26/26] sysfs: businfo for USB devices (#692)

This matches the behaviour of guessBusInfo() for USB device names of the
form host-port:config.interface.

This patch allows SCSI devices where the host is a USB device to be
parented correctly.
---
 src/core/sysfs.cc | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/src/core/sysfs.cc b/src/core/sysfs.cc
index d17d33d..4f6a51f 100644
--- a/src/core/sysfs.cc
+++ b/src/core/sysfs.cc
@@ -137,6 +137,17 @@ static string sysfstobusinfo(const string & path)
   if (bustype == "ide")
     return sysfstoide(path);
 
+  if (bustype == "usb")
+  {
+    string name = basename(path.c_str());
+    if (matches(name, "^[0-9]+-[0-9]+(\\.[0-9]+)*:[0-9]+\\.[0-9]+$"))
+    {
+      size_t colon = name.rfind(":");
+      size_t dash = name.find("-");
+      return "usb@" + name.substr(0, dash) + ":" + name.substr(dash+1, colon-dash-1);
+    }
+  }
+
   if (bustype == "virtio")
   {
     string name = basename(path.c_str());
-- 
2.10.2