Blob Blame History Raw
From c219c4455bb93d9f136849b58ceb0255e407fdbe Mon Sep 17 00:00:00 2001
From: Saggi Mizrahi <smizrahi@redhat.com>
Date: Thu, 4 Oct 2012 13:14:21 +0200
Subject: [PATCH] Use buffer size in multiplies of the recommended transfer
 size

Using the recommended transfer size fixes the memory corruption for NFS.

Bug-Id: http://bugzilla.redhat.com/845660
Change-Id: Iadea310039b30073197b7ad90afb930c460bda17
Signed-off-by: Saggi Mizrahi <smizrahi@redhat.com>
Reviewed-on: http://gerrit.ovirt.org/8356
Reviewed-by: Dan Kenigsberg <danken@redhat.com>
Tested-by: Jason Brooks <jbrooks@redhat.com>
Reviewed-on: http://gerrit.ovirt.org/8369
Reviewed-by: Federico Simoncelli <fsimonce@redhat.com>
Tested-by: Federico Simoncelli <fsimonce@redhat.com>
---
 vdsm/storage/fileUtils.py | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/vdsm/storage/fileUtils.py b/vdsm/storage/fileUtils.py
index 511dff9..ccc2bfe 100644
--- a/vdsm/storage/fileUtils.py
+++ b/vdsm/storage/fileUtils.py
@@ -48,6 +48,7 @@ log = logging.getLogger('fileUtils')
 CharPointer = ctypes.POINTER(ctypes.c_char)
 
 _PC_REC_XFER_ALIGN = 17
+_PC_REC_MIN_XFER_SIZE = 16
 
 class TarCopyFailed(RuntimeError): pass
 
@@ -265,6 +266,13 @@ class DirectFile(object):
         # Because we usually have fixed sizes for our reads, caching
         # buffers might give a slight performance boost.
         alignment = libc.fpathconf(self.fileno(), _PC_REC_XFER_ALIGN)
+        minXferSize = libc.fpathconf(self.fileno(), _PC_REC_MIN_XFER_SIZE)
+        chunks, remainder = divmod(size, minXferSize)
+        if remainder > 0:
+            chunks += 1
+
+        size = chunks * minXferSize
+
         rc = libc.posix_memalign(ppbuff, alignment, size)
         if rc:
             raise OSError(rc, "Could not allocate aligned buffer")
-- 
1.7.11.4