LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Virtualization and Cloud
User Name
Password
Linux - Virtualization and Cloud This forum is for the discussion of all topics relating to Linux Virtualization and Linux Cloud platforms. Xen, KVM, OpenVZ, VirtualBox, VMware, Linux-VServer and all other Linux Virtualization platforms are welcome. OpenStack, CloudStack, ownCloud, Cloud Foundry, Eucalyptus, Nimbus, OpenNebula and all other Linux Cloud platforms are welcome. Note that questions relating solely to non-Linux OS's should be asked in the General forum.

Notices


Reply
  Search this Thread
Old 09-04-2018, 02:37 PM   #1
kp^
LQ Newbie
 
Registered: Sep 2018
Location: United States
Distribution: All
Posts: 3

Rep: Reputation: Disabled
Question KVM: Find already attached/consumed VFs by a VM?


Using virt-manager in RHEL/SLES...

Is there a way to find out if a VF (virtual function) is already attached/consumed by a VM without powering it on?

Does the driver and or kernel report this somewhere?

The only mechanism I found was to dump and parse the xml of each VM. I'm still in the process of writing this code. This is a pita and imho think there might be a better way...

Code:
 virsh dumpxml rhel7.4
or for a quick view I can dump the xml and use xmllint to check:

Code:
virsh dumpxml rhel7.4 | xmllint --xpath '//hostdev' -
If you do a 'lspci -ks 0000:6d:01.1' for example the 'Kernel driver in use' is the driver that is installed on the host. The second you power on the VM this get switched to 'vfio-pci'. This tells me this VF is in use, but I dont think I should be forced to power on my VM until I'm ready.

Context: I created a bash script to add X number of VFs to a VM (vfs must already be spawned). The issue is that the same VF gets added to multiple VM's. I don't know there is an issue until I power on the VM.

Thanks!

*Not sure if this should be here or in the programming section, please forgive.
 
Old 09-04-2018, 07:26 PM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by kp^ View Post
Using virt-manager in RHEL/SLES...

Is there a way to find out if a VF (virtual function) is already attached/consumed by a VM without powering it on?
Does the driver and or kernel report this somewhere?
Even if virt-manager told you whether an interface is based on a VF, how would you do this check in a shell script? The XML definition of your VM is an infinitely better solution. XML can be parsed, GUIs can't.

AFAIK libvirt, and all the tools that build on libvirt including virsh and the virtual machine manager GUI, don't know and don't care what kind of network device they are connected to anyway. You give them a device and that's it. It can be a physical or a virtual function, or a bridge or something else.

For example:
Code:
<interface type='hostdev' managed='yes'>
  <source>
    <address type='pci' domain='0x0' bus='4' slot='9' function='6' />
  </source>
  <mac address='aa:be:ef:23:23:01' />
</interface>
So, it depends on how exactly you specify interfaces. If it is via PCI address like in the above example (I don't know if there are other ways to map a VM interface to its host's VF), you just use lspci to check whether 4:9.6 is a virtual function or not. I don't think this is very hard to do in a shell script, with some awk and sed magic, or an XML parser.
 
Old 09-06-2018, 01:47 PM   #3
kp^
LQ Newbie
 
Registered: Sep 2018
Location: United States
Distribution: All
Posts: 3

Original Poster
Rep: Reputation: Disabled
Thanks for the feedback berndbausch!

I do alot of testing/validation on network devices so I have various scripts that show me this type of info. I know if an interface is a PF or vf based on the driver. I also know the domain:bus:slot.function of each device etc... Dig into "/sys/class/net/<interface>" for example....

Yes, so the VF is added by a PCI address like you've shown below. Below is an example of two vfs that are attached to a VM..

I will prolly have to create a thread in the programming section!

Code:
<hostdev mode='subsystem' type='pci' managed='yes'>
      <source>
        <address domain='0x0000' bus='0x44' slot='0x01' function='0x4'/>
      </source>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
    </hostdev>
    <hostdev mode='subsystem' type='pci' managed='yes'>
      <source>
        <address domain='0x0000' bus='0x44' slot='0x01' function='0x0'/>
      </source>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x1a' function='0x0'/>
    </hostdev>
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to find how much memory consumed by Linux Kernel in my system kspradhan Linux - Kernel 3 11-17-2008 11:12 PM
Find out which Interface an IP address is attached to helptonewbie Linux - Networking 6 11-08-2007 11:30 AM
how can i find space consumed by this user izrafel Linux - General 3 06-15-2007 04:21 AM
hfs: unable to find HFS+ superblock VFS: Can't find ext3 filesystem on dev sdb. macroron Linux - Hardware 3 11-20-2006 09:50 PM
Debian with 2.6.8 kernel won't boot with IOGear USB KVM attached HaganeRei Linux - Hardware 1 04-24-2005 07:10 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Virtualization and Cloud

All times are GMT -5. The time now is 11:03 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration