NvmfStagingBufferCache: fix allocation

Fix allocation of Crail buffers to slice correct amount
of buffers for staging.

Signed-off-by: Jonas Pfefferle <peppe...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/incubator-crail/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-crail/commit/3845c273
Tree: http://git-wip-us.apache.org/repos/asf/incubator-crail/tree/3845c273
Diff: http://git-wip-us.apache.org/repos/asf/incubator-crail/diff/3845c273

Branch: refs/heads/master
Commit: 3845c273be15ef7405132d71dad8e3faee9f5590
Parents: b54e114
Author: Jonas Pfefferle <peppe...@apache.org>
Authored: Mon Apr 9 15:13:57 2018 +0200
Committer: Jonas Pfefferle <peppe...@apache.org>
Committed: Tue Apr 10 13:19:02 2018 +0200

----------------------------------------------------------------------
 .../apache/crail/storage/nvmf/client/NvmfStagingBufferCache.java  | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-crail/blob/3845c273/storage-nvmf/src/main/java/org/apache/crail/storage/nvmf/client/NvmfStagingBufferCache.java
----------------------------------------------------------------------
diff --git 
a/storage-nvmf/src/main/java/org/apache/crail/storage/nvmf/client/NvmfStagingBufferCache.java
 
b/storage-nvmf/src/main/java/org/apache/crail/storage/nvmf/client/NvmfStagingBufferCache.java
index b4f4dc3..dcfc411 100644
--- 
a/storage-nvmf/src/main/java/org/apache/crail/storage/nvmf/client/NvmfStagingBufferCache.java
+++ 
b/storage-nvmf/src/main/java/org/apache/crail/storage/nvmf/client/NvmfStagingBufferCache.java
@@ -80,7 +80,8 @@ public class NvmfStagingBufferCache {
                if (buffer.capacity() < lbaDataSize) {
                        throw new IllegalArgumentException("Slice size smaller 
LBA data size");
                }
-               while (buffer.remaining() >= lbaDataSize && buffersLeft > 0) {
+               int numStagingBuffers = buffer.remaining() / lbaDataSize;
+               while (numStagingBuffers-- > 0 && buffersLeft > 0) {
                        buffer.limit(buffer.position() + lbaDataSize);
                        freeBuffers.add(buffer.slice());
                        buffer.position(buffer.limit());

Reply via email to