[NEW PATCH] BZ#732416 Introduce deleteMultipleVolumes (via gerrit-bot)
Dan Kenigsberg
danken at redhat.com
Sun Sep 11 09:43:52 UTC 2011
New patch submitted by Dan Kenigsberg (danken at redhat.com)
You can review this change at: http://gerrit.usersys.redhat.com/881
commit 3b180b6c87de2c7ae9077cf3353997777a826d80
Author: Eduardo Warszawski <ewarszaw at redhat.com>
Date: Mon Aug 29 18:59:01 2011 +0300
BZ#732416 Introduce deleteMultipleVolumes
Change-Id: I0d8bbff8d364ef85d62237dd13caede1e60f3449
diff --git a/vdsm/storage/blockVolume.py b/vdsm/storage/blockVolume.py
index 9d2e0d7..9b51d99 100644
--- a/vdsm/storage/blockVolume.py
+++ b/vdsm/storage/blockVolume.py
@@ -648,3 +648,33 @@ def _getVolumeTag(sdUUID, volUUID, tagPrefix):
return tag[len(tagPrefix):]
raise se.MissingTagOnLogicalVolume(volUUID, tagPrefix)
+
+def _postZero(sdUUID, volumes):
+ #Assumed here that the volume is active.
+ #To activate all the volumes of an image at once get its resource.
+ #See http://gerrit.usersys.redhat.com/771
+ #Assert volumes are writable. (Don't do this at home.)
+ lvNames = (vol.volUUID for vol in volumes)
+ try:
+ lvm._lvminfo._changelv(sdUUID, lvNames, "--permission", "rw")
+ except se.StorageException, e:
+ #Hope this only means that some volumes were already writable
+ pass
+ for lv in lvm.getLV(sdUUID):
+ if lv.name in lvNames:
+ # wipe out the whole volume
+ try:
+ misc.ddWatchCopy("/dev/zero", lvm.lvPath(sdUUID, lv.name), vars.task.aborting, int(lv.size),
+ recoveryCallback=volume.baseAsyncTasksRollback)
+ except se.ActionStopped, e:
+ raise e
+ except Exception, e:
+ raise se.VolumesZeroingError(lv.name)
+
+def deleteMultipleVolumes(sdUUID, volumes, postZero):
+ "Delete multiple volumes (LVs) in the same domain (VG)."""
+ if postZero:
+ _postZero(sdUUID, volumes)
+ lvNames = (vol.volUUID for vol in volumes)
+ lvm.removeLVs(sdUUID, lvNames)
+
diff --git a/vdsm/storage/fileVolume.py b/vdsm/storage/fileVolume.py
index f6aae79..c16d68c 100644
--- a/vdsm/storage/fileVolume.py
+++ b/vdsm/storage/fileVolume.py
@@ -23,6 +23,7 @@ import uuid
import storage_exception as se
from sdf import StorageDomainFactory as SDF
+import outOfProcess as oop
import volume
import image
import sd
@@ -31,12 +32,25 @@ import misc
import task
from threadLocal import vars
-
def getDomUuidFromVolumePath(volPath):
# Volume path has pattern:
# /rhev/data-center/spUUID/sdUUID/images/imgUUID/volUUID
return volPath.split('/')[4]
+
+def deleteMultipleVolumes(sdUUID, volumes, postZero):
+ #Posix asserts that the blocks will be zeroed before reuse
+ volPaths = []
+ for vol in volumes:
+ vol.setLegality(volume.ILLEGAL_VOL)
+ volPaths.append(vol.getVolumePath())
+ try:
+ oop.fileUtils.cleanupfiles(volPaths)
+ except OSError:
+ volume.log.error("cannot delete some volumes at paths: %s",
+ volPaths, exc_info=True)
+
+
class FileVolume(volume.Volume):
""" Actually represents a single volume (i.e. part of virtual disk).
"""
diff --git a/vdsm/storage/image.py b/vdsm/storage/image.py
index b97c69f..a68f168 100644
--- a/vdsm/storage/image.py
+++ b/vdsm/storage/image.py
@@ -207,12 +207,13 @@ class Image:
volumes = [volclass(self.repoPath, sdUUID, imgUUID, volUUID) for volUUID in uuidlist]
# If we got here than go ahead and remove all of them without mercy
- for vol in volumes:
+ if volumes:
try:
- vol.delete(postZero=postZero, force=True)
- except Exception, ex:
- # Volume deletion failed, but we don't really care at this point
- self.log.warn("Problems during image %s deletion (%s). Continue...", imgUUID, str(ex))
+ #No, this is not a classmethod! No validations here
+ volclass.__module__.deleteMultipleVolumes(sdUUID, volumes, postZero)
+ except (se.CannotRemoveLogicalVolume, se.VolumeAccessError):
+ #Any volume deletion failed, but we don't really care at this point
+ self.log.warn("Problems during image %s deletion (%s). Continue...", exc_info=True)
# Now clean the image directory
removedImage = imageDir = self.getImageDir(sdUUID, imgUUID)
diff --git a/vdsm/storage/spm.py b/vdsm/storage/spm.py
index 8a2b249..76002e0 100644
--- a/vdsm/storage/spm.py
+++ b/vdsm/storage/spm.py
@@ -1525,6 +1525,12 @@ class SPM:
hsm.HSM.getPool(spUUID) #Validates that the pool is connected. WHY?
hsm.HSM.validateSdUUID(sdUUID)
+ #Need this resource to induce all the LVs in the image to be active
+ #at once if zeroed.
+ #See http://gerrit.usersys.redhat.com/771
+ if postZero:
+ vars.task.getSharedLock(STORAGE, imgUUID)
+
vars.task.getSharedLock(STORAGE, sdUUID)
# Do not validate if forced.
repoPath = os.path.join(self.storage_repository, spUUID)
More information about the vdsm-patches
mailing list