Change in vdsm[master]: utils: Add changehash function for change detection

nsoffer at redhat.com nsoffer at redhat.com
Thu Sep 18 12:39:38 UTC 2014


Nir Soffer has uploaded a new change for review.

Change subject: utils: Add changehash function for change detection
......................................................................

utils: Add changehash function for change detection

We use Python built-in hash to detect changes in vm state without sending
the state in each response. This function is not suitable for this
usage. Now we use generic utils.changehash(), implemented using md5
hexdigest.

Change-Id: I2242a594383e2d2fe64e3a581f18b8ac662648b0
Signed-off-by: Nir Soffer <nsoffer at redhat.com>
---
M lib/vdsm/utils.py
M vdsm/virt/vm.py
2 files changed, 13 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/45/33045/1

diff --git a/lib/vdsm/utils.py b/lib/vdsm/utils.py
index 23c63e8..1b4a9d5 100644
--- a/lib/vdsm/utils.py
+++ b/lib/vdsm/utils.py
@@ -37,6 +37,7 @@
 import glob
 import io
 import itertools
+import hashlib
 import logging
 import re
 import sys
@@ -1133,3 +1134,13 @@
     flags = fcntl.fcntl(fd, fcntl.F_GETFL)
     flags |= os.O_NONBLOCK
     fcntl.fcntl(fd, fcntl.F_SETFL, flags)
+
+
+def changehash(s):
+    """
+    Returns a hash of string s, suitable for change detection.
+
+    Tipically changehash(s) is sent to client frequently. When a client detect
+    that changehash(s) changed, it ask for s itself, which may be much bigger.
+    """
+    return hashlib.md5(s).hexdigest()
diff --git a/vdsm/virt/vm.py b/vdsm/virt/vm.py
index 941f283..b1567f9 100644
--- a/vdsm/virt/vm.py
+++ b/vdsm/virt/vm.py
@@ -1500,7 +1500,7 @@
         self.guestAgent = guestagent.GuestAgent(
             self._guestSocketFile, self.cif.channelListener, self.log)
         self._lastXMLDesc = '<domain><uuid>%s</uuid></domain>' % self.id
-        self._devXmlHash = '0'
+        self._devXmlHash = utils.changehash('')
         self._released = False
         self._releaseLock = threading.Lock()
         self.saveState()
@@ -4495,7 +4495,7 @@
         self._lastXMLDesc = self._dom.XMLDesc(0)
         devxml = _domParseStr(self._lastXMLDesc).childNodes[0]. \
             getElementsByTagName('devices')[0]
-        self._devXmlHash = str(hash(devxml.toxml()))
+        self._devXmlHash = utils.changehash(devxml.toxml())
 
         return self._lastXMLDesc
 


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2242a594383e2d2fe64e3a581f18b8ac662648b0
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <nsoffer at redhat.com>


More information about the vdsm-patches mailing list