Eduardo has uploaded a new change for review.
Change subject: Marking del/zero volumes in blockSD class.
......................................................................
Marking del/zero volumes in blockSD class.
Related to: BZ#905938, BZ#910013, BZ#875708
Change-Id: I747bc2218e0b2cc256dd352ad890143c7d354bd8
Signed-off-by: Eduardo <ewarszaw(a)redhat.com>
---
M vdsm/storage/blockSD.py
M vdsm/storage/sd.py
2 files changed, 24 insertions(+), 11 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/45/12545/1
diff --git a/vdsm/storage/blockSD.py b/vdsm/storage/blockSD.py
index 9809bf4..35282e5 100644
--- a/vdsm/storage/blockSD.py
+++ b/vdsm/storage/blockSD.py
@@ -210,17 +210,6 @@
# spent time.
ZEROING_TIMEOUT = 60000 # [miliseconds]
log.debug("sd: %s, LVs: %s, img: %s", sdUUID, volUUIDs, imgUUID)
- # Prepare for zeroing
- try:
- lvm.changelv(sdUUID, volUUIDs, (("-a", "y"),
- ("--deltag", blockVolume.TAG_PREFIX_IMAGE + imgUUID),
- ("--addtag", blockVolume.TAG_PREFIX_IMAGE +
- sd.REMOVED_IMAGE_PREFIX + imgUUID)))
- except se.StorageException as e:
- log.error("Can't activate or change LV tags in SD %s. "
- "failing Image %s pre zeroing operation for vols: %s. %s",
- sdUUID, imgUUID, volUUIDs, e)
- raise
# Following call to changelv is separate since setting rw permission on an
# LV fails if the LV is already set to the same value, hence we would not
# be able to differentiate between a real failure of deltag/addtag and one
@@ -981,13 +970,36 @@
if v.imgs[0] == imgUUID)
return exclusives
+ def __markForDelVols(self, sdUUID, imgUUID, volUUIDs, opTag):
+ """
+ Mark volumes that will be zeroed or removed.
+
+ Mark for delete just in case that lvremove [lvs] success partialy.
+ Mark for zero just in case that zero process is interrupted.
+
+ Tagging is preferably than rename since is can be done in one lvm
+ operation and is resilent to open LV's, etc.
+ """
+ try:
+ lvm.changelv(sdUUID, volUUIDs, (("-a", "y"),
+ ("--deltag", blockVolume.TAG_PREFIX_IMAGE + imgUUID),
+ ("--addtag", blockVolume.TAG_PREFIX_IMAGE +
+ opTag + imgUUID)))
+ except se.StorageException as e:
+ log.error("Can't activate or change LV tags in SD %s. "
+ "failing Image %s %s operation for vols: %s. %s",
+ sdUUID, imgUUID, opTag, volUUIDs, e)
+ raise
+
def deleteImage(self, sdUUID, imgUUID, volsImgs):
toDel = self._getImgExclusiveVols(imgUUID, volsImgs)
+ self.__markForDelVols(sdUUID, imgUUID, toDel, sd.REMOVED_IMAGE_PREFIX)
deleteVolumes(sdUUID, toDel)
self.rmDCImgDir(imgUUID, volsImgs)
def zeroImage(self, sdUUID, imgUUID, volsImgs):
toZero = self._getImgExclusiveVols(imgUUID, volsImgs)
+ self.__markForDelVols(sdUUID, imgUUID, toZero, sd.ZEROED_IMAGE_PREFIX)
zeroImgVolumes(sdUUID, imgUUID, toZero)
self.rmDCImgDir(imgUUID, volsImgs)
diff --git a/vdsm/storage/sd.py b/vdsm/storage/sd.py
index 9ce836b..cc06ce5 100644
--- a/vdsm/storage/sd.py
+++ b/vdsm/storage/sd.py
@@ -135,6 +135,7 @@
ISO_IMAGE_UUID = '11111111-1111-1111-1111-111111111111'
BLANK_UUID = '00000000-0000-0000-0000-000000000000'
REMOVED_IMAGE_PREFIX = "_remove_me_"
+ZEROED_IMAGE_PREFIX = REMOVED_IMAGE_PREFIX + "ZERO_"
# Blocks used for each lease (valid on all domain types)
LEASE_BLOCKS = 2048
--
To view, visit http://gerrit.ovirt.org/12545
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I747bc2218e0b2cc256dd352ad890143c7d354bd8
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Eduardo <ewarszaw(a)redhat.com>
Federico Simoncelli has uploaded a new change for review.
Change subject: libvirtvm: fix xml generation for all the devices
......................................................................
libvirtvm: fix xml generation for all the devices
In one of the patches of the before_device_create series has been
removed the XML generation for the regular devices.
This patch fixes the behavior reintroducing the missing XML.
Change-Id: Ifb4f9eb32bc58371cec66301275689660193447b
Signed-off-by: Federico Simoncelli <fsimonce(a)redhat.com>
---
M vdsm/libvirtvm.py
1 file changed, 15 insertions(+), 13 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/37/13637/1
diff --git a/vdsm/libvirtvm.py b/vdsm/libvirtvm.py
index 607dedb..6f45226 100644
--- a/vdsm/libvirtvm.py
+++ b/vdsm/libvirtvm.py
@@ -1304,25 +1304,24 @@
for devType in self._devices:
for dev in self._devices[devType]:
- if not getattr(dev, 'custom', {}):
- continue
+ if hasattr(dev, 'custom'):
+ yield
- yield dev
-
- def _beforeDeviceCreateHooks(self, domxml):
+ def _beforeDeviceCreateHooks(self, dev):
"""
Run before_device_create hook script for devices with custom properties
The resulting device xml is cached in dev._deviceXML.
"""
+ deviceXML = dev.getXML()
- for dev in self._customDevices():
- deviceXML = dev.getXML().toxml(encoding='utf-8')
- deviceXML = hooks.before_device_create(
- deviceXML, self.conf, dev.custom)
- dev._deviceXML = deviceXML
- domxml._devices.appendChild(
- xml.dom.minidom.parseString(deviceXML).firstChild)
+ if not hasattr(dev, 'custom'):
+ return deviceXML
+
+ dev._deviceXML = hooks.before_device_create(
+ deviceXML.toxml(encoding='utf-8'), self.conf, dev.custom)
+
+ return xml.dom.minidom.parseString(dev._deviceXML).firstChild
def _buildCmdLine(self):
domxml = _DomXML(self.conf, self.log)
@@ -1347,7 +1346,10 @@
domxml.appendInput()
domxml.appendGraphics()
- self._beforeDeviceCreateHooks(domxml)
+ for devType in self._devices:
+ for dev in self._devices[devType]:
+ deviceXML = self._beforeDeviceCreateHooks(dev)
+ domxml._devices.appendChild(deviceXML)
for drive in self._devices[vm.DISK_DEVICES][:]:
if not hasattr(drive, 'volumeChain'):
--
To view, visit http://gerrit.ovirt.org/13637
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifb4f9eb32bc58371cec66301275689660193447b
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Federico Simoncelli <fsimonce(a)redhat.com>
Antoni Segura Puimedon has uploaded a new change for review.
Change subject: sriov: Make the hook safe for concurrency
......................................................................
sriov: Make the hook safe for concurrency
The current model uses a cache that is not locked and could
be overwritten by a second VM creation effectively preventing
the return of the chown to root:root.
This patch solves that by creating with exclusivity a file for
each virtual function that is attached (thus avoiding locking)
but having concurrency safety due to the OS guarantee that the
not more than a single processes can perform an open when the
flags O_CREAT | O_EXCL are set.
Change-Id: I2c6ad7f2ee53911312700396000e0aca07a917e9
Signed-off-by: Antoni S. Puimedon <asegurap(a)redhat.com>
---
M vdsm_hooks/sriov/after_vm_destroy.py
M vdsm_hooks/sriov/before_vm_start.py
2 files changed, 40 insertions(+), 46 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/41/13641/1
diff --git a/vdsm_hooks/sriov/after_vm_destroy.py b/vdsm_hooks/sriov/after_vm_destroy.py
index a5e25b5..e82dab0 100755
--- a/vdsm_hooks/sriov/after_vm_destroy.py
+++ b/vdsm_hooks/sriov/after_vm_destroy.py
@@ -6,15 +6,13 @@
import hooking
-SYS_NIC_PATH = '/sys/class/net/%s'
-VDSM_VAR_HOOKS_DIR = '/var/run/vdsm/hooks'
-SRIOV_CACHE_FILENAME = 'sriov.cache'
+VDSM_VAR_HOOKS_DIR = '/var/run/vdsm/hooks/sriov'
-def restoreDevicePermissions(addr, devpath):
+def restoreDevicePermissions(devpath):
owner = 'root:root'
for f in os.listdir(devpath):
- if f.startswith('resource') or f == 'rom' or f == 'reset':
+ if f.startswith('resource') or f in ('rom', 'reset'):
dev = os.path.join(devpath, f)
command = ['/bin/chown', owner, dev]
retcode, out, err = hooking.execCmd(command, sudo=True, raw=True)
@@ -26,24 +24,16 @@
if 'sriov' in os.environ:
try:
lines = ''
- nics = os.environ['sriov'].split(',')
- path = VDSM_VAR_HOOKS_DIR + '/' + SRIOV_CACHE_FILENAME
-
- if os.path.exists(path):
- with open(path, 'r') as f:
- for line in f:
- nicAddr = line.split('=')
- if nicAddr[0] in nics:
- restoreDevicePermissions(nicAddr[1],
- nicAddr[2].strip('\n'))
- else:
- lines += line
-
- 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)
+ for nic in os.environ['sriov'].split(','):
+ vfFilePath = os.path.join(VDSM_VAR_HOOKS_DIR, nic)
+ if os.path.exists(vfFilePath):
+ with open(vfFilePath, 'r') as vfFile:
+ restoreDevicePermissions(vfFile.read())
+ os.unlink(vfFilePath)
+ else:
+ sys.stderr.write('sriov after_vm_destroy: cannot find the '
+ 'virtual function reservation file of %s'
+ 'that should be at %s\n' % (nic, vfFilePath))
except:
sys.stderr.write('sriov after_vm_destroy: [unexpected error]: %s\n' %
diff --git a/vdsm_hooks/sriov/before_vm_start.py b/vdsm_hooks/sriov/before_vm_start.py
index 42b79e9..c23797b 100755
--- a/vdsm_hooks/sriov/before_vm_start.py
+++ b/vdsm_hooks/sriov/before_vm_start.py
@@ -1,5 +1,6 @@
#!/usr/bin/python
+import errno
import os
import sys
import grp
@@ -11,8 +12,7 @@
from vdsm import libvirtconnection
SYS_NIC_PATH = '/sys/class/net/%s'
-VDSM_VAR_HOOKS_DIR = '/var/run/vdsm/hooks'
-SRIOV_CACHE_FILENAME = 'sriov.cache'
+VDSM_VAR_HOOKS_DIR = '/var/run/vdsm/hooks/sriov'
'''
sriov vdsm hook
@@ -93,32 +93,36 @@
return 'pci_%s_%s_%s' % (tokens[0], tokens[1], tokens[2].replace('.', '_'))
-def writeSriovCache(name, addr, devpath):
+def writeVFReservationFile(nic, devpath):
if not os.path.exists(VDSM_VAR_HOOKS_DIR):
os.makedirs(VDSM_VAR_HOOKS_DIR)
-
- f = open(VDSM_VAR_HOOKS_DIR + '/' + SRIOV_CACHE_FILENAME, 'a')
- f.write(name + '=' + addr + '=' + devpath + '\n')
- f.close()
+ try:
+ fd = os.open(os.path.join(VDSM_VAR_HOOKS_DIR, nic),
+ os.O_WRONLY | os.O_CREAT | os.O_EXCL)
+ with os.fdopen(fd, 'w') as f:
+ f.write(devpath)
+ except OSError as e:
+ if e.errno == errno.EEXIST:
+ sys.stderr.write('sriov: Error. The device %s is already attached '
+ 'or in the process of attaching to a VM. Aborting'
+ '.\n' % nic)
+ sys.stderr.write('sriov: Unexpected error creating virtual function '
+ 'reservation file for nic %s. Aborting.\n%s\n' %
+ (nic, traceback.format_exc()))
+ sys.exit(2)
-def chown(devpath):
- group = grp.getgrnam('qemu')
- gid = group.gr_gid
- user = pwd.getpwnam('qemu')
- uid = user.pw_uid
-
+def chown(nic, devpath):
+ '''Uses sudo and chown to change the sriov ownership.'''
+ owner = ''.join([str(pwd.getpwnam('qemu').pw_uid), ':',
+ str(grp.getgrnam('qemu').gr_gid)])
for f in os.listdir(devpath):
- if f.startswith('resource') or f == 'rom' or f == 'reset':
- dev = os.path.join(devpath, f)
-
- # we don't use os.chown because we need sudo
- owner = str(uid) + ':' + str(gid)
- command = ['/bin/chown', owner, dev]
+ if f.startswith('resource') or f in ('rom', 'reset'):
+ command = ['/bin/chown', owner, os.path.join(devpath, f)]
retcode, out, err = hooking.execCmd(command, sudo=True, raw=True)
if retcode != 0:
- sys.stderr.write('sriov: error chown %s to %s, err = %s\n' %
- (dev, owner, err))
+ sys.stderr.write('sriov: Error %s changing ownership of %s to'
+ 'owner %s. Aborting.\n' % (err, nic, owner))
sys.exit(2)
@@ -141,9 +145,9 @@
sys.stderr.write('sriov: VF %s xml: %s\n' %
(nic, interface.toxml()))
- chown(devpath)
+ writeVFReservationFile(nic, devpath)
+ chown(nic, devpath)
devices.appendChild(interface)
- writeSriovCache(nic, addr, devpath)
else:
sys.stderr.write('sriov: cannot find nic "%s", aborting\n' %
nic)
--
To view, visit http://gerrit.ovirt.org/13641
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I2c6ad7f2ee53911312700396000e0aca07a917e9
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Antoni Segura Puimedon <asegurap(a)redhat.com>
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(a)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(a)redhat.com>