12a457
From ceaff3dc28477da45127a015a77f4c7cd163633d Mon Sep 17 00:00:00 2001
12a457
From: Krutika Dhananjay <kdhananj@redhat.com>
12a457
Date: Thu, 2 Jun 2016 19:45:03 +0530
12a457
Subject: [PATCH 188/192] posix, shard: Use page-aligned buffer for o-direct reads
12a457
12a457
        Backport of: http://review.gluster.org/14639
12a457
        3.7 backport: http://review.gluster.org/#/c/14650/
12a457
12a457
and also make shard_readv_do() pass the correct flags when
12a457
the original fd is opened with O_DIRECT.
12a457
12a457
Change-Id: I948e2040520562ca53380db0a16699c21c8ade66
12a457
BUG: 1339136
12a457
Signed-off-by: Krutika Dhananjay <kdhananj@redhat.com>
12a457
Reviewed-on: https://code.engineering.redhat.com/gerrit/76039
12a457
Reviewed-by: Pranith Kumar Karampuri <pkarampu@redhat.com>
12a457
Tested-by: Pranith Kumar Karampuri <pkarampu@redhat.com>
12a457
---
12a457
 xlators/features/shard/src/shard.c |    3 ++
12a457
 xlators/storage/posix/src/posix.c  |   40 ++++++++++++++++++++++++++++-------
12a457
 2 files changed, 35 insertions(+), 8 deletions(-)
12a457
12a457
diff --git a/xlators/features/shard/src/shard.c b/xlators/features/shard/src/shard.c
12a457
index d9a61c1..1139194 100644
12a457
--- a/xlators/features/shard/src/shard.c
12a457
+++ b/xlators/features/shard/src/shard.c
12a457
@@ -3013,6 +3013,9 @@ shard_readv_do (call_frame_t *frame, xlator_t *this)
12a457
 
12a457
         SHARD_SET_ROOT_FS_ID (frame, local);
12a457
 
12a457
+        if (fd->flags & O_DIRECT)
12a457
+                local->flags = O_DIRECT;
12a457
+
12a457
         while (cur_block <= last_block) {
12a457
                 if (wind_failed) {
12a457
                         shard_readv_do_cbk (frame, (void *) (long) 0,  this, -1,
12a457
diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c
12a457
index e19da1a..eebf22f 100644
12a457
--- a/xlators/storage/posix/src/posix.c
12a457
+++ b/xlators/storage/posix/src/posix.c
12a457
@@ -2985,6 +2985,8 @@ posix_readv (call_frame_t *frame, xlator_t *this,
12a457
         int32_t                op_ret     = -1;
12a457
         int32_t                op_errno   = 0;
12a457
         int                    _fd        = -1;
12a457
+        char                 *buf         = NULL;
12a457
+        char                 *alloc_buf   = NULL;
12a457
         struct posix_private * priv       = NULL;
12a457
         struct iobuf         * iobuf      = NULL;
12a457
         struct iobref        * iobref     = NULL;
12a457
@@ -3023,14 +3025,35 @@ posix_readv (call_frame_t *frame, xlator_t *this,
12a457
         }
12a457
 
12a457
         _fd = pfd->fd;
12a457
-        op_ret = pread (_fd, iobuf->ptr, size, offset);
12a457
-        if (op_ret == -1) {
12a457
-                op_errno = errno;
12a457
-                gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_READ_FAILED,
12a457
-                        "read failed on gfid=%s, fd=%p, offset=%"PRIu64" "
12a457
-                        "size=%"GF_PRI_SIZET"", uuid_utoa (fd->inode->gfid), fd,
12a457
-                        offset, size);
12a457
-                goto out;
12a457
+        if (pfd->flags & O_DIRECT) {
12a457
+                alloc_buf = _page_aligned_alloc (size, &buf;;
12a457
+                if (!alloc_buf) {
12a457
+                        op_ret = -1;
12a457
+                        op_errno = errno;
12a457
+                        goto out;
12a457
+                }
12a457
+
12a457
+                op_ret = pread (_fd, buf, size, offset);
12a457
+                if (op_ret == -1) {
12a457
+                        op_errno = errno;
12a457
+                        gf_msg (this->name, GF_LOG_ERROR, errno,
12a457
+                                P_MSG_READ_FAILED, "read failed on gfid=%s, "
12a457
+                                "fd=%p, offset=%"PRIu64" size=%"GF_PRI_SIZET", "
12a457
+                                "buf=%p", uuid_utoa (fd->inode->gfid), fd,
12a457
+                                offset, size, buf);
12a457
+                        goto out;
12a457
+                }
12a457
+                memcpy(iobuf->ptr, buf, size);
12a457
+        } else {
12a457
+                op_ret = pread (_fd, iobuf->ptr, size, offset);
12a457
+                if (op_ret == -1) {
12a457
+                        op_errno = errno;
12a457
+                        gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_READ_FAILED,
12a457
+                                "read failed on gfid=%s, fd=%p, offset=%"PRIu64" "
12a457
+                                "size=%"GF_PRI_SIZET"", uuid_utoa (fd->inode->gfid), fd,
12a457
+                                offset, size);
12a457
+                        goto out;
12a457
+                }
12a457
         }
12a457
 
12a457
         LOCK (&priv->lock);
12a457
@@ -3073,6 +3096,7 @@ out:
12a457
                 iobref_unref (iobref);
12a457
         if (iobuf)
12a457
                 iobuf_unref (iobuf);
12a457
+        GF_FREE (alloc_buf);
12a457
 
12a457
         return 0;
12a457
 }
12a457
-- 
12a457
1.7.1
12a457