Change in vdsm[ovirt-3.6]: hsm: Remove support for size in sectors as int

frolland at redhat.com frolland at redhat.com
Sat Oct 17 18:39:49 UTC 2015


Hello Adam Litke,

I'd like you to do a code review.  Please visit

    https://gerrit.ovirt.org/47418

to review the following change.

Change subject: hsm: Remove support for size in sectors as int
......................................................................

hsm: Remove support for size in sectors as int

We used to support volume size either as number of sectors using int, or
as number of bytes using a string. Engine is using size in bytes since
first git commit. Hosted engine setup is also using size in bytes.  We
don't know about old code using number of sectors.

This patch removes the support for size in sectors.  To prevent
incorrect usage we raise InvalidParameterException if called with an
integer.

Change-Id: I52957eec163973fd60a95a9bf523131f3c83a9da
Bug-Url: https://bugzilla.redhat.com/1221603
Signed-off-by: Nir Soffer <nsoffer at redhat.com>
Reviewed-on: https://gerrit.ovirt.org/47381
Reviewed-by: Adam Litke <alitke at redhat.com>
Continuous-Integration: Jenkins CI
---
M client/vdsClient.py
M lib/vdsm/constants.py.in
M vdsm/rpc/vdsmapi-schema.json
M vdsm/storage/hsm.py
4 files changed, 12 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/18/47418/1

diff --git a/client/vdsClient.py b/client/vdsClient.py
index 71b559a..b9a977e 100755
--- a/client/vdsClient.py
+++ b/client/vdsClient.py
@@ -29,7 +29,7 @@
 import socket
 import pprint as pp
 
-from vdsm import utils, vdscli
+from vdsm import utils, vdscli, constants
 from vdsm.compat import json
 
 try:
@@ -1063,9 +1063,8 @@
         sdUUID = args[0]
         spUUID = args[1]
         imgUUID = args[2]
-        diskSize = int(args[3])
-        convertFactor = 2097152
-        size = diskSize * convertFactor
+        sizeGIB = int(args[3])
+        size = str(sizeGIB * constants.GIB)
         volFormat = int(args[4])
         preallocate = int(args[5])
         diskType = int(args[6])
diff --git a/lib/vdsm/constants.py.in b/lib/vdsm/constants.py.in
index e5cff54..704c3f9 100644
--- a/lib/vdsm/constants.py.in
+++ b/lib/vdsm/constants.py.in
@@ -68,6 +68,7 @@
 UUID_GLOB_PATTERN = '*-*-*-*-*'
 
 MEGAB = 2 ** 20  # = 1024 ** 2 = 1 MiB
+GIB = 1024 * MEGAB
 
 #
 # Path definitions
diff --git a/vdsm/rpc/vdsmapi-schema.json b/vdsm/rpc/vdsmapi-schema.json
index 07fc8a4..1ff0caa 100644
--- a/vdsm/rpc/vdsmapi-schema.json
+++ b/vdsm/rpc/vdsmapi-schema.json
@@ -8267,7 +8267,7 @@
 #
 # @imageID:          The Image associated with the Volume
 #
-# @size:             The Volume size in sectors
+# @size:             The Volume size in bytes (as string)
 #
 # @volFormat:        The data format to use for the destination Volume
 #
@@ -8290,7 +8290,7 @@
 {'command': {'class': 'Volume', 'name': 'create'},
  'data': {'volumeID': 'UUID', 'storagepoolID': 'UUID',
           'storagedomainID': 'UUID', 'imageID': 'UUID',
-          'size': 'int', 'volFormat': 'VolumeFormat',
+          'size': 'str', 'volFormat': 'VolumeFormat',
           'preallocate': 'VolumeAllocation', 'diskType': 'DiskType',
           'desc': 'str', 'srcImgUUID': 'UUID', 'srcVolUUID': 'UUID'},
  'returns': 'UUID'}
diff --git a/vdsm/storage/hsm.py b/vdsm/storage/hsm.py
index 02eaf4f..ac0f434 100644
--- a/vdsm/storage/hsm.py
+++ b/vdsm/storage/hsm.py
@@ -33,7 +33,6 @@
 import errno
 import time
 import signal
-import types
 import math
 import numbers
 import stat
@@ -1451,12 +1450,12 @@
         dom = sdCache.produce(sdUUID=sdUUID)
         misc.validateUUID(imgUUID, 'imgUUID')
         misc.validateUUID(volUUID, 'volUUID')
-        # TODO: For backwards compatibility, we need to support accepting
-        # number of sectors as int type Updated interface is accepting string
-        # type in bytes (ugly, get rid of this when possible)
-        if not isinstance(size, types.IntType):
-            size = misc.validateN(size, "size")
-            size = (size + SECTOR_SIZE - 1) / SECTOR_SIZE
+        if not isinstance(size, basestring):
+            self.log.error("Number of sectors as int is not supported, use "
+                           "size in bytes as string")
+            raise se.InvalidParameterException("size", size)
+        size = misc.validateN(size, "size")
+        size = (size + SECTOR_SIZE - 1) / SECTOR_SIZE
 
         if srcImgUUID:
             misc.validateUUID(srcImgUUID, 'srcImgUUID')


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I52957eec163973fd60a95a9bf523131f3c83a9da
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: ovirt-3.6
Gerrit-Owner: Freddy Rolland <frolland at redhat.com>
Gerrit-Reviewer: Adam Litke <alitke at redhat.com>


More information about the vdsm-patches mailing list