diff options
| author | Krutika Dhananjay <kdhananj@redhat.com> | 2016-06-07 16:27:34 +0530 | 
|---|---|---|
| committer | Pranith Kumar Karampuri <pkarampu@redhat.com> | 2016-06-29 02:53:40 -0700 | 
| commit | 82f77991679c05d93c01888bb79c571c7fa9142f (patch) | |
| tree | b94c99c61f7cea2d336e07450a7599da585c4ef4 /xlators/storage/posix/src/posix.c | |
| parent | 2fe7b9ddefd33d64e601254bbf740b24e2b85469 (diff) | |
libglusterfs: Implement API that provides page-aligned iobufs
        Backport of: http://review.gluster.org/14672
One of the consumers of a page aligned buffer would be posix's
readv fop on O_DIRECT fds. Today the way it works is by getting
a page-aligned buffer through calloc, pread()ing into this buffer
and then copying its contents into a newly created iobuf's ptr.
This results in an extra memcpy() which can be avoided if we could
implement an api that would return an iobuf whose ptr is
page-aligned. That way the iobuf->ptr can be directly passed to
sys_pread() as a parameter by posix translator.
Change-Id: I7f64419461db387e4ab6b0e03c90471744aa56e1
BUG: 1351025
Signed-off-by: Krutika Dhananjay <kdhananj@redhat.com>
Reviewed-on: http://review.gluster.org/14825
Smoke: Gluster Build System <jenkins@build.gluster.org>
NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
Reviewed-by: Pranith Kumar Karampuri <pkarampu@redhat.com>
Diffstat (limited to 'xlators/storage/posix/src/posix.c')
| -rw-r--r-- | xlators/storage/posix/src/posix.c | 44 | 
1 files changed, 11 insertions, 33 deletions
diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c index 2320bf13449..8784571470f 100644 --- a/xlators/storage/posix/src/posix.c +++ b/xlators/storage/posix/src/posix.c @@ -3042,8 +3042,6 @@ posix_readv (call_frame_t *frame, xlator_t *this,          int32_t                op_ret     = -1;          int32_t                op_errno   = 0;          int                    _fd        = -1; -        char                 *buf         = NULL; -        char                 *alloc_buf   = NULL;          struct posix_private * priv       = NULL;          struct iobuf         * iobuf      = NULL;          struct iobref        * iobref     = NULL; @@ -3075,42 +3073,23 @@ posix_readv (call_frame_t *frame, xlator_t *this,                  goto out;          } -        iobuf = iobuf_get2 (this->ctx->iobuf_pool, size); +        iobuf = iobuf_get_page_aligned (this->ctx->iobuf_pool, size, +                                        ALIGN_SIZE);          if (!iobuf) {                  op_errno = ENOMEM;                  goto out;          }          _fd = pfd->fd; -        if (pfd->flags & O_DIRECT) { -                alloc_buf = _page_aligned_alloc (size, &buf); -                if (!alloc_buf) { -                        op_ret = -1; -                        op_errno = errno; -                        goto out; -                } - -                op_ret = sys_pread (_fd, buf, size, offset); -                if (op_ret == -1) { -                        op_errno = errno; -                        gf_msg (this->name, GF_LOG_ERROR, errno, -                                P_MSG_READ_FAILED, "read failed on gfid=%s, " -                                "fd=%p, offset=%"PRIu64" size=%"GF_PRI_SIZET", " -                                "buf=%p", uuid_utoa (fd->inode->gfid), fd, -                                offset, size, buf); -                        goto out; -                } -                memcpy(iobuf->ptr, buf, size); -        } else { -                op_ret = sys_pread (_fd, iobuf->ptr, size, offset); -                if (op_ret == -1) { -                        op_errno = errno; -                        gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_READ_FAILED, -                                "read failed on gfid=%s, fd=%p, offset=%"PRIu64" " -                                "size=%"GF_PRI_SIZET"", uuid_utoa (fd->inode->gfid), fd, -                                offset, size); -                        goto out; -                } +        op_ret = sys_pread (_fd, iobuf->ptr, size, offset); +        if (op_ret == -1) { +                op_errno = errno; +                gf_msg (this->name, GF_LOG_ERROR, errno, +                        P_MSG_READ_FAILED, "read failed on gfid=%s, " +                        "fd=%p, offset=%"PRIu64" size=%"GF_PRI_SIZET", " +                        "buf=%p", uuid_utoa (fd->inode->gfid), fd, +                        offset, size, iobuf->ptr); +                goto out;          }          LOCK (&priv->lock); @@ -3153,7 +3132,6 @@ out:                  iobref_unref (iobref);          if (iobuf)                  iobuf_unref (iobuf); -        GF_FREE (alloc_buf);          return 0;  }  | 
