Change in vdsm[master]: Add wipeVolume API

alitke at redhat.com alitke at redhat.com
Wed May 6 20:26:03 UTC 2015


Adam Litke has uploaded a new change for review.

Change subject: Add wipeVolume API
......................................................................

Add wipeVolume API

Change-Id: I572099e1fee4ae847de95e27973405ba90b56a9b
Signed-off-by: Adam Litke <alitke at redhat.com>
---
M client/vdsClient.py
M vdsm/API.py
M vdsm/rpc/BindingXMLRPC.py
M vdsm/rpc/vdsmapi-schema.json
M vdsm/storage/hsm.py
M vdsm/storage/sdm/__init__.py
6 files changed, 70 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/28/40628/1

diff --git a/client/vdsClient.py b/client/vdsClient.py
index bac146e..c267b75 100755
--- a/client/vdsClient.py
+++ b/client/vdsClient.py
@@ -1973,6 +1973,16 @@
         else:
             return status['status']['code'], status['status']['message']
 
+    def wipeVolume(self, args):
+        if len(args) != 3:
+            raise ValueError('Wrong number of arguments')
+        sdUUID, imgUUID, volUUID = args
+        status = self.s.wipeVolume(sdUUID, imgUUID, volUUID)
+        if status['status']['code'] == 0:
+            return 0, ''
+        else:
+            return status['status']['code'], status['status']['message']
+
 
 if __name__ == '__main__':
     if _glusterEnabled:
diff --git a/vdsm/API.py b/vdsm/API.py
index 6adefa8..a49448b 100644
--- a/vdsm/API.py
+++ b/vdsm/API.py
@@ -840,6 +840,9 @@
         return self._irs.setVolumeLegality(self._sdUUID, self._spUUID,
                                            self._imgUUID, self._UUID, legality)
 
+    def wipe(self):
+        return self._irs.wipeVolume(self._sdUUID, self._imgUUID, self._UUID)
+
 
 class Image(APIBase):
     ctorArgs = ['imageID', 'storagepoolID', 'storagedomainID']
diff --git a/vdsm/rpc/BindingXMLRPC.py b/vdsm/rpc/BindingXMLRPC.py
index f110468..270f7a1 100644
--- a/vdsm/rpc/BindingXMLRPC.py
+++ b/vdsm/rpc/BindingXMLRPC.py
@@ -1004,6 +1004,10 @@
         api = API.StorageDomain(sdUUID)
         return api.isolateVolume(srcImgUUID, dstImgUUID, volumeID)
 
+    def wipeVolume(self, sdUUID, imgUUID, volUUID):
+        volume = API.Volume(volUUID, None, sdUUID, imgUUID)
+        return volume.wipe()
+
     def getGlobalMethods(self):
         return ((self.vmDestroy, 'destroy'),
                 (self.vmCreate, 'create'),
@@ -1156,7 +1160,8 @@
                 (self.volumeCreateContainer, 'createVolumeContainer'),
                 (self.copyData, 'copyData'),
                 (self.extendVolumeContainer, 'extendVolumeContainer'),
-                (self.isolateVolume, 'isolateVolume'))
+                (self.isolateVolume, 'isolateVolume'),
+                (self.wipeVolume, 'wipeVolume'))
 
 
 def wrapApiMethod(f):
diff --git a/vdsm/rpc/vdsmapi-schema.json b/vdsm/rpc/vdsmapi-schema.json
index a76db8d..80b1968 100644
--- a/vdsm/rpc/vdsmapi-schema.json
+++ b/vdsm/rpc/vdsmapi-schema.json
@@ -8312,6 +8312,22 @@
           'legality': 'VolumeLegality'}}
 
 ##
+# @Volume.wipe:
+#
+# Wipe a volume to ensure previous data is erased.
+#
+# @volumeID:         The UUID of the Volume
+#
+# @storagedomainID:  The Storage Domain associated with the Volume
+#
+# @imageID:          The Image associated with the Volume
+#
+# Since: 4.18.0
+##
+{'command': {'class': 'Volume', 'name': 'wipe'},
+ 'data': {'volumeID': 'UUID', 'storagedomainID': 'UUID', 'imageID': 'UUID'}}
+
+##
 # @VM.setNumberOfCpus:
 #
 # Set the number CPUs for a VM
diff --git a/vdsm/storage/hsm.py b/vdsm/storage/hsm.py
index 432c8f9..cb51cd1 100644
--- a/vdsm/storage/hsm.py
+++ b/vdsm/storage/hsm.py
@@ -3776,3 +3776,16 @@
         misc.validateUUID(dstImgUUID, 'dstImgUUID')
         vars.task.getSharedLock(STORAGE, sdUUID)
         return sdm.isolateVolume(dom, srcImgUUID, dstImgUUID, volumeID)
+
+    @public
+    def wipeVolume(self, sdUUID, imgUUID, volUUID):
+        argsStr = ("sdUUID=%s, imgUUID=%s, volUUID=%s" %
+                   (sdUUID, imgUUID, volUUID))
+        vars.task.setDefaultException(se.VolumesZeroingError(argsStr))
+        misc.validateUUID(imgUUID, 'imgUUID')
+        misc.validateUUID(volUUID, 'volUUID')
+        vars.task.getSharedLock(STORAGE, sdUUID)
+        imageSpec = {'sdUUID': sdUUID, 'imgUUID': imgUUID, 'volUUID': volUUID}
+        with sdm.prepareCopy(imageSpec, False, 0, True):
+            self._sdmSchedule('wipeVolume', sdm.wipeVolume, sdUUID, imgUUID,
+                              volUUID)
diff --git a/vdsm/storage/sdm/__init__.py b/vdsm/storage/sdm/__init__.py
index 4738813..2113d26 100644
--- a/vdsm/storage/sdm/__init__.py
+++ b/vdsm/storage/sdm/__init__.py
@@ -22,6 +22,7 @@
 from contextlib import contextmanager, nested
 
 from .. import image
+from .. import misc
 from .. import resourceManager as rm
 from .. import sd
 from .. import storage_exception as se
@@ -234,6 +235,27 @@
         domain.releaseClusterLock()
 
 
+def wipeVolume(sdUUID, imgUUID, volUUID):
+    dom = sdCache.produce(sdUUID)
+    imageResourcesNamespace = sd.getNamespace(sdUUID, IMAGE_NAMESPACE)
+    try:
+        with rmanager.acquireResource(imageResourcesNamespace,
+                                      imgUUID, rm.LockType.exclusive):
+            vol = dom.produceVolume(imgUUID, volUUID)
+            size = vol.getVolumeSize(bs=1)
+            vol_path = vol.getVolumePath()
+            vol.prepare(rw=True, justme=True)
+            try:
+                vol.setLegality(volume.ILLEGAL_VOL)
+                misc.ddWatchCopy(
+                    "/dev/zero", vol_path, vars.task.aborting, int(size))
+            finally:
+                vol.tearDown(imgUUID, volUUID)
+            vol.setLegality(volume.LEGAL_VOL)
+    finally:
+        dom.releaseVolumeLease(imgUUID, volUUID)
+
+
 def garbageCollectStorageDomain(domain):
     if domain.isISO():
         return


-- 
To view, visit https://gerrit.ovirt.org/40628
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I572099e1fee4ae847de95e27973405ba90b56a9b
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Adam Litke <alitke at redhat.com>


More information about the vdsm-patches mailing list