Blame 0043-Use-the-recommended-alignment-instead-of-using-pages.patch

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