Change in vdsm[master]: Make sr-iov hook use interface instead of hostdev
asegurap at redhat.com
asegurap at redhat.com
Wed Apr 3 01:57:21 UTC 2013
Antoni Segura Puimedon has uploaded a new change for review.
Change subject: Make sr-iov hook use interface instead of hostdev
......................................................................
Make sr-iov hook use interface instead of hostdev
According to libvirt documentation, for the sr-iov virtual function
"nics" to have permanent and unique MAC addresses, the passthrough
should be done using <interface type='hostdev'> instead of
<hostdev>.
This change modifies the hook to take advantage of this libvirt
definition for stable sr-iovs and allows profiles to be defined
for the virtualports when used in conjunction with 802.11Qgh.
NOTE:
There are stil a couple of TODO in this patch that I have to solve
before the patch can be considered for merging.
Change-Id: Ib2f88a8400fe4d230c0877428afef62df8e397db
Signed-off-by: Antoni S. Puimedon <asegurap at redhat.com>
---
M vdsm_hooks/sriov/README
M vdsm_hooks/sriov/after_vm_destroy.py
M vdsm_hooks/sriov/before_vm_start.py
3 files changed, 47 insertions(+), 31 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/41/13541/1
diff --git a/vdsm_hooks/sriov/README b/vdsm_hooks/sriov/README
index 713aa6a..d8af84b 100644
--- a/vdsm_hooks/sriov/README
+++ b/vdsm_hooks/sriov/README
@@ -6,7 +6,7 @@
it to the guest xml
syntax:
-sr-iov: sriov=eth10,eth11
+sr-iov: sriov=eth10:profileA,eth11:profileB
attach 2 sr-iov VF to vm
notes at sr-iov/README
diff --git a/vdsm_hooks/sriov/after_vm_destroy.py b/vdsm_hooks/sriov/after_vm_destroy.py
index ab81e90..4b66cac 100755
--- a/vdsm_hooks/sriov/after_vm_destroy.py
+++ b/vdsm_hooks/sriov/after_vm_destroy.py
@@ -36,26 +36,21 @@
if 'sriov' in os.environ:
try:
lines = ''
- nics = os.environ['sriov']
+ nicsProfiles = os.environ['sriov'].split(',')
path = VDSM_VAR_HOOKS_DIR + '/' + SRIOV_CACHE_FILENAME
+ nics = (nicProfile.split(':')[0] for nicProfile in nicsProfiles)
if os.path.exists(path):
- f = open(path, 'r')
- while 1:
- line = f.readline()
- if not line:
- break
- pass # do something
- nicAddr = line.split('=')
- if nicAddr[0] in nics:
- returnDeviceToHost(nicAddr[1], nicAddr[2].strip('\n'))
- else:
- lines += line
- f.close()
+ with open(path, 'r') as f:
+ for line in f:
+ nicAddr = line.split('=')
+ if nicAddr[0] in nics:
+ returnDeviceToHost(nicAddr[1], nicAddr[2].strip('\n'))
+ else:
+ lines += line
- f = open(path, 'w')
- f.writelines(lines)
- f.close()
+ with open(path, 'w') as f:
+ f.writelines(lines)
else:
sys.stderr.write('sriov after_vm_destroy: cannot find sriov cache '
'file %s\n' % path)
diff --git a/vdsm_hooks/sriov/before_vm_start.py b/vdsm_hooks/sriov/before_vm_start.py
index fd9168f..e7281c4 100755
--- a/vdsm_hooks/sriov/before_vm_start.py
+++ b/vdsm_hooks/sriov/before_vm_start.py
@@ -60,31 +60,50 @@
sys.stderr.write('sriov: cannot detach device: %s\n' % addr)
-def createSriovElement(domxml, bus, slot, function):
+def createSriovElement(domxml, bus, slot, function, profile):
'''
create host device element for libvirt domain xml:
- <hostdev mode='subsystem' type='pci'>
+ <interface type='hostdev'>
<source>
- <address bus='0x1a' slot='0x10' function='0x06'/>
+ <address type='pci' domain='0x0' bus='0x1a' slot='0x10' slot='0x07'
+ function='0x06'/>
</source>
- </hostdev>
+ # TODO: Check if we omit the mac address to have libvirt auto-generate
+ # it
+ <mac address='4:54:00:6d:90:02'/>
+ # TODO: This should be set only if connected to this kind of switch.
+ <virtualport type='802.10bh'>
+ <parameters proileid='foobar'/>
+ </virtualport>
+ </interface>
'''
- hostdev = domxml.createElement('hostdev')
- hostdev.setAttribute('mode', 'subsystem')
- hostdev.setAttribute('type', 'pci')
+ interface = domxml.createElement('interface')
+ interface.setAttribute('type', 'hostdev')
+ interface.setAttribute('managed', 'yes')
source = domxml.createElement('source')
- hostdev.appendChild(source)
+ interface.appendChild(source)
address = domxml.createElement('address')
+ address.setAttribute('type', 'pci')
+ # The domain is not currently used by Qemu
+ #address.setAttribute('domain', '0')
address.setAttribute('bus', bus)
address.setAttribute('slot', slot)
address.setAttribute('function', function)
source.appendChild(address)
- return hostdev
+
+ virtualport = domxml.createElement('virtualport')
+ virtualport.setAttribute('type', '802.1Qbh')
+ interface.appendChild(virtualport)
+
+ parameters = domxml.createElement('parameters')
+ parameters.setAttribute('profileid', profile)
+ virtualport.appendChild(parameters)
+ return interface
def deviceExists(devName):
@@ -133,12 +152,13 @@
if 'sriov' in os.environ:
try:
- nics = os.environ['sriov']
+ nicsProfiles = os.environ['sriov'].split(',')
domxml = hooking.read_domxml()
devices = domxml.getElementsByTagName('devices')[0]
- for nic in nics.split(','):
+ for nicProfile in nicsProfiles:
+ nic, profile = nicProfile.split(':')
if deviceExists(nic):
sys.stderr.write('sriov: adding VF %s\n' % nic)
@@ -147,11 +167,12 @@
detachDevice(addr)
bus, slot, function = getDeviceDetails(addr)
- hostdev = createSriovElement(domxml, bus, slot, function)
+ interface = createSriovElement(domxml, bus, slot, function,
+ profile)
sys.stderr.write('sriov: VF %s xml: %s\n' %
- (nic, hostdev.toxml()))
- devices.appendChild(hostdev)
+ (nic, interface.toxml()))
+ devices.appendChild(interface)
chown(devpath)
writeSriovCache(nic, addr, devpath)
else:
--
To view, visit http://gerrit.ovirt.org/13541
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib2f88a8400fe4d230c0877428afef62df8e397db
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Antoni Segura Puimedon <asegurap at redhat.com>
More information about the vdsm-patches
mailing list