I made this patch according to Zheng Sheng's advice that we provide more specific information of PCI device of "interface" and "storage", which more types of devices can be added. By hanging the mouse on top of the name, possible information will be shown if there is any description available.



Recently we have host device passthrough feature merged into master. If
you have ever tried it, you may find that it's not very easy to
determine which device is suitable to passthrough. For example, in
Kimchi web interface we have list of host PCI devices as follow.

pci_0000_00_19_0 82579LM Gigabit Network Connection
pci_0000_00_1f_2 6 Series/C200 Series Chipset Family 6 port SATA AHCI
Controller
pci_0000_03_00_0 Centrino Advanced-N 6205 [Taylor Peak]
pci_0000_0d_00_0 MMC/SD Host Controller

If there are multiple NIC or HBA cards on the host, the user will see
more similar entries like this. However the user is unclear of the
relationship between a "82579LM Gigabit Network Connection" and "eth0",
or the relationship between "SATA AHCI Controller" and "sda". It'll be
better if we can provide the related devices information when the user
click one of the PCI device.

The back-end has already provided a API to query the passthrough
affected device.

Just GET /host/devices?_passthrough_affected_by=pci_0000_00_19_0
where "pci_0000_00_19_0" is the device name of "82579LM Gigabit Network
Connection". The back-end returns the following information.
[
   {
     "parent":"pci_0000_00_19_0",
     "name":"net_em1_00_21_cc_c2_6d_a6",
     "device_type":"net",
     "address":"00:21:cc:c2:6d:a6",
     "interface":"em1",
     "path":"/sys/devices/pci0000:00/0000:00:19.0/net/em1",
     "link_type":"IEEE 802.3"
   }
]
So in the "interface" field indicates that the related Linux network
interface device is "em1", and "address" provides the MAC address.

GET /host/devices?_passthrough_affected_by=pci_0000_03_00_0
returns
[
   {
     "parent":"pci_0000_03_00_0",
     "name":"net_wlp3s0_8c_70_5a_5d_5e_90",
     "device_type":"net",
     "address":"8c:70:5a:5d:5e:90",
     "interface":"wlp3s0",
    
"path":"/sys/devices/pci0000:00/0000:00:1c.1/0000:03:00.0/net/wlp3s0",
     "link_type":"IEEE 802.11"
   }
]
"Centrino Advanced-N 6205 [Taylor Peak]" is a WLAN NIC, because
"link_type" is "IEEE 802.11". The Linux network interface device
"wlp3s0" is related to it, the MAC address is "8c:70:5a:5d:5e:90".

As regard to storage device,
GET /host/devices?_passthrough_affected_by=pci_0000_00_1f_2
returns
[
   {
     "num_blocks":976773168,
     "vendor":"ATA",
     "name":"block_sda_HITACHI_HTS727550A9E364_J3320082GMK10A",
     "parent":"scsi_0_0_0_0",
     "bus":"ata",
     "drive_type":"disk",
     "device_type":"storage",
     "logical_block_size":512,

"path":"/sys/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda",

     "model":"HITACHI HTS72755",
     "serial":"HITACHI_HTS727550A9E364_J3320082GMK10A",
     "block":"/dev/sda",
     "size":500107862016
   },
   {
     "vendor":"HL-DT-ST",
     "name":"block_sr0_HL_DT_ST_DVDRAM_GT50N_M3MC3C81854",
     "parent":"scsi_1_0_0_0",
     "bus":"ata",
     "drive_type":"cdrom",
     "device_type":"storage",
     "media":{
       "available":false,
       "media_size":0,
       "type":"removable"
     },

"path":"/sys/devices/pci0000:00/0000:00:1f.2/ata2/host1/target1:0:0/1:0:0:0/block/sr0",

     "model":"DVDRAM GT50N",
     "serial":"HL-DT-ST_DVDRAM_GT50N_M3MC3C81854",
     "block":"/dev/sr0"
   },
...]
Indicate that "/dev/sda" and "/dev/sr0" are related to HBA card "6
Series/C200 Series Chipset Family 6 port SATA AHCI Controller". "sda" is
a disk, and the size is 500107862016, "sr0" is a cdrom and it's emtpy.

All the above example mean that if the user passthrough a PCI device to
the guest, the related "em1" or "sda" "sr0" will also be affected.

I think in UI we can make of this
"/host/devices?_passthrough_affected_by" API. When the user selects a
PCI device, the front-end GETs this URI and parses the result, and then
pops a tool tip or something to show the related devices. This would be
very helpful for a user to estimate the impact of passing through a
device.

-- Zhou Zheng Sheng / ÖÜÕ÷êÉ E-mail: zhshzhou@linux.vnet.ibm.com
Telephone: 86-10-82454397
ÔÚ 10/24/14 6:16 PM, Wen Wang дµÀ:
From: Wen Wang <wenwang@linux.vnet.ibm.com>

This patch provide the way that shows more specific PCI device
information by hanging the mouse on top of device name.

Signed-off-by: Wen Wang <wenwang@linux.vnet.ibm.com>
---
 ui/js/src/kimchi.api.js             |   14 ++++++++++++++
 ui/js/src/kimchi.guest_edit_main.js |   25 +++++++++++++++++++++++++
 2 files changed, 39 insertions(+), 0 deletions(-)

diff --git a/ui/js/src/kimchi.api.js b/ui/js/src/kimchi.api.js
index 8a6e416..aebac56 100644
--- a/ui/js/src/kimchi.api.js
+++ b/ui/js/src/kimchi.api.js
@@ -1129,6 +1129,20 @@ var kimchi = {
         });
     },

+    getPCIDeviceDescriptions : function(pcidev, suc, err) {
+        kimchi.requestJSON({
+            url : kimchi.url + 'host/devices?_passthrough_affected_by=' + pcidev,
+            type : 'GET',
+            contentType : 'application/json',
+            dataType : 'json',
+            resend : true,
+            success : suc,
+            error : err ? err : function(data) {
+                kimchi.message.error(data.responseJSON.reason);
+            }
+        });
+    },
+
     getISCSITargets : function(server, port, suc, err) {
         server = encodeURIComponent(server);
         port = port ? '&_server_port='+encodeURIComponent(port) : '';
diff --git a/ui/js/src/kimchi.guest_edit_main.js b/ui/js/src/kimchi.guest_edit_main.js
index 030e112..580f648 100644
--- a/ui/js/src/kimchi.guest_edit_main.js
+++ b/ui/js/src/kimchi.guest_edit_main.js
@@ -365,6 +365,9 @@ kimchi.guest_edit_main = function() {
                 kimchi.getCapabilities(function(result) {
                     var pciEnabled = result.kernel_vfio;
                     for(var i=0; i<hostPCIs.length; i++){
+
+
+
                         var itemNode = $.parseHTML(kimchi.substitute($('#pci-tmpl').html(),{
                             name: hostPCIs[i].name,
                             product: hostPCIs[i].product.description,
@@ -407,6 +410,28 @@ kimchi.guest_edit_main = function() {
                                 });
                             }
                         });
+                        kimchi.getPCIDeviceDescriptions(hostPCIs[i].name, function(infoData) {
+                            var pciTitle = "";
+                            if(infoData.length>0) {
+                                for(var p=0; p<infoData.length; p++) {
+                                    if(infoData[p].interface) {
+                                        pciTitle += "interface: " + infoData[p].interface;
+                                        pciTitle += ", address: " + infoData[p].address;
+                                        pciTitle += ", link_type: " + infoData[p].link_type;
+                                        pciTitle += " ";
+                                    } else if(infoData[p].block) {
+                                        pciTitle += "block: " + infoData[p].block;
+                                        pciTitle += ", drive_type: " + infoData[p].drive_type;
+                                        pciTitle += ", model: " + infoData[p].model;
+                                        pciTitle += " ";
+                                    }
+                                    
+                                }
+                                for(var q=0; q<infoData.length; q++) {
+                                    pciTitle === "" || $(".name", "#" + infoData[q].parent).attr("title", pciTitle);
+                                }
+                            }
+                        });
                     }
                 });
             });
-- 1.7.1