From b4f0985266f5fba817602e8af9ad900425c5a853 Mon Sep 17 00:00:00 2001
From: Saggi Mizrahi <smizrahi@redhat.com>
Date: Mon, 24 Sep 2012 01:28:38 +0200
Subject: [PATCH] Use the recommended alignment instead of using pagesize
Page size is the usual recommended alignment but when it isn't using it
can cause memory corruption.
Change-Id: If9da41a2f74d3cea7300df9606c78eebcc9927a9
Signed-off-by: Saggi Mizrahi <smizrahi@redhat.com>
Reviewed-on: http://gerrit.ovirt.org/8143
Tested-by: Noam Slomianko <nslomian@redhat.com>
Reviewed-by: Dan Kenigsberg <danken@redhat.com>
Reviewed-on: http://gerrit.ovirt.org/8174
Reviewed-by: Federico Simoncelli <fsimonce@redhat.com>
Tested-by: Federico Simoncelli <fsimonce@redhat.com>
---
vdsm/storage/fileUtils.py | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/vdsm/storage/fileUtils.py b/vdsm/storage/fileUtils.py
index 020f16d..511dff9 100644
--- a/vdsm/storage/fileUtils.py
+++ b/vdsm/storage/fileUtils.py
@@ -45,9 +45,10 @@ NFS_OPTIONS = "".join(config.get('irs', 'nfs_mount_options').split())
log = logging.getLogger('fileUtils')
-PAGESIZE = libc.getpagesize()
CharPointer = ctypes.POINTER(ctypes.c_char)
+_PC_REC_XFER_ALIGN = 17
+
class TarCopyFailed(RuntimeError): pass
def tarCopy(src, dst, exclude=[]):
@@ -71,7 +72,8 @@ def isStaleHandle(path):
os.listdir(path)
except OSError as ex:
if ex.errno in (errno.EIO, errno.ESTALE):
- return True
+ return True
+
# We could get contradictory results because of
# soft mounts
if (exists or st) and ex.errno == errno.ENOENT:
@@ -262,7 +264,8 @@ class DirectFile(object):
ppbuff = ctypes.pointer(pbuff)
# Because we usually have fixed sizes for our reads, caching
# buffers might give a slight performance boost.
- rc = libc.posix_memalign(ppbuff, PAGESIZE, size)
+ alignment = libc.fpathconf(self.fileno(), _PC_REC_XFER_ALIGN)
+ rc = libc.posix_memalign(ppbuff, alignment, size)
if rc:
raise OSError(rc, "Could not allocate aligned buffer")
try:
--
1.7.11.4