3604df
From 985ad852813b548d517d86c465ce743e40085ebc Mon Sep 17 00:00:00 2001
3604df
From: Krutika Dhananjay <kdhananj@redhat.com>
3604df
Date: Tue, 20 Sep 2016 12:05:23 +0530
3604df
Subject: [PATCH 097/141] performance/open-behind: Pass O_DIRECT flags for anon fd reads when required
3604df
3604df
        Backport of: http://review.gluster.org/15537
3604df
        cherry-picked from a412a4f50d8ca2ae68dbfa93b80757889150ce99
3604df
3604df
Writes are already passing the correct flags at the time of open().
3604df
3604df
Also, make io-cache honor direct-io for anon-fds with
3604df
O_DIRECT flag during reads.
3604df
3604df
Change-Id: Ib777d3df8f3dca7bfa57edbd9a34a329699ff56a
3604df
BUG: 1380638
3604df
Signed-off-by: Krutika Dhananjay <kdhananj@redhat.com>
3604df
Reviewed-on: https://code.engineering.redhat.com/gerrit/87139
3604df
Reviewed-by: Pranith Kumar Karampuri <pkarampu@redhat.com>
3604df
Tested-by: Pranith Kumar Karampuri <pkarampu@redhat.com>
3604df
---
3604df
 xlators/performance/io-cache/src/io-cache.c       |   45 ++++++--------------
3604df
 xlators/performance/open-behind/src/open-behind.c |   22 ++++++----
3604df
 2 files changed, 28 insertions(+), 39 deletions(-)
3604df
3604df
diff --git a/xlators/performance/io-cache/src/io-cache.c b/xlators/performance/io-cache/src/io-cache.c
3604df
index 46e26bc..98c3774 100644
3604df
--- a/xlators/performance/io-cache/src/io-cache.c
3604df
+++ b/xlators/performance/io-cache/src/io-cache.c
3604df
@@ -893,29 +893,6 @@ ioc_release (xlator_t *this, fd_t *fd)
3604df
         return 0;
3604df
 }
3604df
 
3604df
-/*
3604df
- * ioc_readv_disabled_cbk
3604df
- * @frame:
3604df
- * @cookie:
3604df
- * @this:
3604df
- * @op_ret:
3604df
- * @op_errno:
3604df
- * @vector:
3604df
- * @count:
3604df
- *
3604df
- */
3604df
-int32_t
3604df
-ioc_readv_disabled_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
3604df
-                        int32_t op_ret,	int32_t op_errno, struct iovec *vector,
3604df
-                        int32_t count, struct iatt *stbuf,
3604df
-                        struct iobref *iobref, dict_t *xdata)
3604df
-{
3604df
-        STACK_UNWIND_STRICT (readv, frame, op_ret, op_errno, vector, count,
3604df
-                             stbuf, iobref, xdata);
3604df
-        return 0;
3604df
-}
3604df
-
3604df
-
3604df
 int32_t
3604df
 ioc_need_prune (ioc_table_t *table)
3604df
 {
3604df
@@ -1128,10 +1105,17 @@ ioc_readv (call_frame_t *frame, xlator_t *this, fd_t *fd,
3604df
         ioc_inode = (ioc_inode_t *)(long)tmp_ioc_inode;
3604df
         if (!ioc_inode) {
3604df
                 /* caching disabled, go ahead with normal readv */
3604df
-                STACK_WIND (frame, ioc_readv_disabled_cbk,
3604df
-                            FIRST_CHILD (frame->this),
3604df
-                            FIRST_CHILD (frame->this)->fops->readv, fd, size,
3604df
-                            offset, flags, xdata);
3604df
+                STACK_WIND_TAIL (frame, FIRST_CHILD (frame->this),
3604df
+                                 FIRST_CHILD (frame->this)->fops->readv, fd,
3604df
+                                 size, offset, flags, xdata);
3604df
+                return 0;
3604df
+        }
3604df
+
3604df
+        if (flags & O_DIRECT) {
3604df
+                /* disable caching for this fd, if O_DIRECT is used */
3604df
+                STACK_WIND_TAIL (frame, FIRST_CHILD (frame->this),
3604df
+                                 FIRST_CHILD (frame->this)->fops->readv, fd,
3604df
+                                 size, offset, flags, xdata);
3604df
                 return 0;
3604df
         }
3604df
 
3604df
@@ -1165,10 +1149,9 @@ ioc_readv (call_frame_t *frame, xlator_t *this, fd_t *fd,
3604df
 
3604df
         if (!fd_ctx_get (fd, this, NULL)) {
3604df
                 /* disable caching for this fd, go ahead with normal readv */
3604df
-                STACK_WIND (frame, ioc_readv_disabled_cbk,
3604df
-                            FIRST_CHILD (frame->this),
3604df
-                            FIRST_CHILD (frame->this)->fops->readv, fd, size,
3604df
-                            offset, flags, xdata);
3604df
+                STACK_WIND_TAIL (frame, FIRST_CHILD (frame->this),
3604df
+                                 FIRST_CHILD (frame->this)->fops->readv, fd,
3604df
+                                 size, offset, flags, xdata);
3604df
                 return 0;
3604df
         }
3604df
 
3604df
diff --git a/xlators/performance/open-behind/src/open-behind.c b/xlators/performance/open-behind/src/open-behind.c
3604df
index efab885..00e8906 100644
3604df
--- a/xlators/performance/open-behind/src/open-behind.c
3604df
+++ b/xlators/performance/open-behind/src/open-behind.c
3604df
@@ -351,19 +351,25 @@ err:
3604df
 
3604df
 
3604df
 fd_t *
3604df
-ob_get_wind_fd (xlator_t *this, fd_t *fd)
3604df
+ob_get_wind_fd (xlator_t *this, fd_t *fd, uint32_t *flag)
3604df
 {
3604df
-	ob_conf_t  *conf = NULL;
3604df
-	ob_fd_t    *ob_fd = NULL;
3604df
+        fd_t       *wind_fd = NULL;
3604df
+	ob_fd_t    *ob_fd   = NULL;
3604df
+	ob_conf_t  *conf    = NULL;
3604df
 
3604df
 	conf = this->private;
3604df
 
3604df
 	ob_fd = ob_fd_ctx_get (this, fd);
3604df
 
3604df
-	if (ob_fd && conf->use_anonymous_fd)
3604df
-		return fd_anonymous (fd->inode);
3604df
+	if (ob_fd && conf->use_anonymous_fd) {
3604df
+                wind_fd = fd_anonymous (fd->inode);
3604df
+                if ((ob_fd->flags & O_DIRECT) && (flag))
3604df
+                        *flag = *flag | O_DIRECT;
3604df
+        } else {
3604df
+                wind_fd = fd_ref (fd);
3604df
+        }
3604df
 
3604df
-	return fd_ref (fd);
3604df
+	return wind_fd;
3604df
 }
3604df
 
3604df
 
3604df
@@ -378,7 +384,7 @@ ob_readv (call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size,
3604df
         conf = this->private;
3604df
 
3604df
         if (!conf->read_after_open)
3604df
-                wind_fd = ob_get_wind_fd (this, fd);
3604df
+                wind_fd = ob_get_wind_fd (this, fd, &flags);
3604df
         else
3604df
                 wind_fd = fd_ref (fd);
3604df
 
3604df
@@ -427,7 +433,7 @@ ob_fstat (call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *xdata)
3604df
 	call_stub_t  *stub = NULL;
3604df
 	fd_t         *wind_fd = NULL;
3604df
 
3604df
-	wind_fd = ob_get_wind_fd (this, fd);
3604df
+	wind_fd = ob_get_wind_fd (this, fd, NULL);
3604df
 
3604df
 	stub = fop_fstat_stub (frame, default_fstat_resume, wind_fd, xdata);
3604df
 
3604df
-- 
3604df
1.7.1
3604df