Federico Simoncelli has uploaded a new change for review.

Change subject: image: unify the prezeroing optimizations
......................................................................

image: unify the prezeroing optimizations

The same prezeroing optimization logic was used in multiple places, this
patch unifies it in __optimizedCreateVolume.

Change-Id: I0fd90f85e9debf98bcac07d1b8d4b38c319c33f2
Signed-off-by: Federico Simoncelli <[email protected]>
---
M vdsm/storage/image.py
1 file changed, 43 insertions(+), 45 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/04/8504/1

diff --git a/vdsm/storage/image.py b/vdsm/storage/image.py
index e86d94c..19ab078 100644
--- a/vdsm/storage/image.py
+++ b/vdsm/storage/image.py
@@ -454,6 +454,37 @@
         except Exception:
             self.log.error("Unexpected error", exc_info=True)
 
+    def __optimizedCreateVolume(self, domain, imgUUID, size, apparentSize,
+                volFormat, preallocate, diskType, volUUID, desc, srcImgUUID,
+                srcVolUUID):
+        # To avoid 'prezeroing' preallocated volume on NFS domain,
+        # we create the target volume with minimal size and after
+        # that we'll change its metadata back to the original size.
+        if (volFormat == volume.COW_FORMAT
+                or preallocate == volume.SPARSE_VOL):
+            volTmpSize = size
+        else:
+            volTmpSize = TEMPORARY_VOLUME_SIZE
+
+        domain.createVolume(imgUUID, volTmpSize, volFormat, preallocate,
+                            diskType, volUUID, desc, srcImgUUID, srcVolUUID)
+        newVolume = domain.produceVolume(imgUUID, volUUID)
+
+        if volFormat == volume.RAW_FORMAT:
+            extendSize = size
+        else:
+            extendSize = apparentSize
+
+        # Extend volume (for LV only) size to the actual size
+        newVolume.extend((extendSize + 511) / 512)
+
+        # Change destination volume metadata back to the original
+        # size. Heavy operation, do it only if necessary.
+        if volTmpSize != size:
+            newVolume.setSize(size)
+
+        return newVolume
+
     def _createTargetImage(self, destDom, srcSdUUID, imgUUID):
         # Before actual data copying we need perform several operation
         # such as: create all volumes, create fake template if needed, ...
@@ -500,34 +531,12 @@
                     # find out src volume parameters
                     volParams = srcVol.getVolumeParams(bs=1)
 
-                    # To avoid 'prezeroing' preallocated volume on NFS domain,
-                    # we create the target volume with minimal size and after
-                    # that w'll change its metadata back to the original size.
-                    if (volParams['volFormat'] == volume.COW_FORMAT
-                            or volParams['prealloc'] == volume.SPARSE_VOL):
-                        volTmpSize = volParams['size']
-                    else:
-                        volTmpSize = TEMPORARY_VOLUME_SIZE  # in sectors (10M)
-
-                    destDom.createVolume(imgUUID=imgUUID, size=volTmpSize,
-                                         volFormat=volParams['volFormat'],
-                                         preallocate=volParams['prealloc'],
-                                         diskType=volParams['disktype'],
-                                         volUUID=srcVol.volUUID,
-                                         desc=volParams['descr'],
-                                         srcImgUUID=pimg,
-                                         srcVolUUID=volParams['parent'])
-
-                    dstVol = destDom.produceVolume(imgUUID=imgUUID,
-                                                   volUUID=srcVol.volUUID)
-
-                    # Extend volume (for LV only) size to the actual size
-                    dstVol.extend((volParams['apparentsize'] + 511) / 512)
-
-                    # Change destination volume metadata back to the original
-                    # size.
-                    if volTmpSize != volParams['size']:
-                        dstVol.setSize(volParams['size'])
+                    dstVol = self.__optimizedCreateVolume(
+                        destDom, imgUUID, volParams['size'],
+                        volParams['apparentsize'], volParams['volFormat'],
+                        volParams['prealloc'], volParams['disktype'],
+                        srcVol.volUUID, volParams['descr'], srcImgUUID=pimg,
+                        srcVolUUID=volParams['parent'])
 
                     dstChain.append(dstVol)
                 except se.StorageException:
@@ -760,25 +769,14 @@
                     self.log.info("delete image %s on domain %s before 
overwriting", dstImgUUID, dstSdUUID)
                     self.delete(dstSdUUID, dstImgUUID, postZero, force=True)
 
-                # To avoid 'prezeroing' preallocated volume on NFS domain,
-                # we create the target volume with minimal size and after that 
w'll change
-                # its metadata back to the original size.
-                tmpSize = TEMPORARY_VOLUME_SIZE  # in sectors (10M)
-                destDom.createVolume(imgUUID=dstImgUUID, size=tmpSize,
-                                      volFormat=dstVolFormat, 
preallocate=volParams['prealloc'],
-                                      diskType=volParams['disktype'], 
volUUID=dstVolUUID, desc=descr,
-                                      srcImgUUID=volume.BLANK_UUID, 
srcVolUUID=volume.BLANK_UUID)
+                dstVol = self.__optimizedCreateVolume(
+                            destDom, dstImgUUID, volParams['size'],
+                            volParams['apparentsize'], dstVolFormat,
+                            volParams['prealloc'], volParams['disktype'],
+                            dstVolUUID, descr, volume.BLANK_UUID,
+                            volume.BLANK_UUID)
 
-                dstVol = 
sdCache.produce(dstSdUUID).produceVolume(imgUUID=dstImgUUID, volUUID=dstVolUUID)
-                # For convert to 'raw' we need use the virtual disk size 
instead of apparent size
-                if dstVolFormat == volume.RAW_FORMAT:
-                    newsize = volParams['size']
-                else:
-                    newsize = volParams['apparentsize']
-                dstVol.extend(newsize)
                 dstPath = dstVol.getVolumePath()
-                # Change destination volume metadata back to the original size.
-                dstVol.setSize(volParams['size'])
             except se.StorageException, e:
                 self.log.error("Unexpected error", exc_info=True)
                 raise


--
To view, visit http://gerrit.ovirt.org/8504
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0fd90f85e9debf98bcac07d1b8d4b38c319c33f2
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Federico Simoncelli <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to