diff options
| author | Jiffin Tony Thottan <jthottan@redhat.com> | 2015-03-11 14:20:48 +0530 | 
|---|---|---|
| committer | Kaleb KEITHLEY <kkeithle@redhat.com> | 2015-05-05 18:05:24 -0700 | 
| commit | fa0ad231745846918b2625d0e1a89c0a5c3c24dc (patch) | |
| tree | 35ff8022e965847d19198277414636f785172e61 /api | |
| parent | a5fc34604aef973606431bf7d873abb91ee03d5a (diff) | |
libgfapi : anonymous fd support
Anonymous fd's are floating fd assigned to a glusterfs client
without a explicit file open. Here either it will create a new
anonymous fd or existing anonymous fd in the client stack for
requested file.The anonymous fd's are mainly used for IO's.
This patch introduces two api's glfs_h_anonymous_read and
glfs_h_anonymous_write which performs read and write respectively
Change-Id: Id646f2220e8387b2f8bb244c848dc1db6761444f
BUG: 1204651
Signed-off-by: Jiffin Tony Thottan <jthottan@redhat.com>
Reviewed-by: Niels de Vos <ndevos@redhat.com>
Reviewed-on: http://review.gluster.org/9971
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Diffstat (limited to 'api')
| -rw-r--r-- | api/src/gfapi.aliases | 3 | ||||
| -rw-r--r-- | api/src/gfapi.map | 2 | ||||
| -rw-r--r-- | api/src/glfs-fops.c | 155 | ||||
| -rw-r--r-- | api/src/glfs-handleops.c | 48 | ||||
| -rw-r--r-- | api/src/glfs-handles.h | 10 | ||||
| -rw-r--r-- | api/src/glfs-internal.h | 8 | 
6 files changed, 226 insertions, 0 deletions
diff --git a/api/src/gfapi.aliases b/api/src/gfapi.aliases index 6d48ecdf2c9..9776c87fdcb 100644 --- a/api/src/gfapi.aliases +++ b/api/src/gfapi.aliases @@ -131,6 +131,9 @@ _pub_glfs_h_acl_set _glfs_h_acl_set$GFAPI_3.7.0  _pub_glfs_h_acl_get _glfs_h_acl_get$GFAPI_3.7.0  _pub_glfs_h_statfs _glfs_h_statfs$GFAPI_3.7.0 +_pub_glfs_h_anonymous_read _glfs_h_anonymous_read$GFAPI_3.7.0 +_pub_glfs_h_anonymous_write _glfs_h_anonymous_write$GFAPI_3.7.0 +  _priv_glfs_free_from_ctx _glfs_free_from_ctx$GFAPI_PRIVATE_3.7.0  _priv_glfs_new_from_ctx _glfs_new_from_ctx$GFAPI_PRIVATE_3.7.0  _priv_glfs_resolve _glfs_resolve$GFAPI_PRIVATE_3.7.0 diff --git a/api/src/gfapi.map b/api/src/gfapi.map index 24209d666dc..48863985135 100644 --- a/api/src/gfapi.map +++ b/api/src/gfapi.map @@ -152,6 +152,8 @@ GFAPI_3.7.0 {  		glfs_h_acl_set;  		glfs_h_acl_get;  		glfs_h_statfs; +		glfs_h_anonymous_read; +		glfs_h_anonymous_write;  } GFAPI_3.6.0;  GFAPI_PRIVATE_3.7.0 { diff --git a/api/src/glfs-fops.c b/api/src/glfs-fops.c index 4aad28005f2..08f0884c7ee 100644 --- a/api/src/glfs-fops.c +++ b/api/src/glfs-fops.c @@ -3625,3 +3625,158 @@ out:  }  GFAPI_SYMVER_PRIVATE_DEFAULT(glfs_process_upcall_event, 3.7.0); + +ssize_t +glfs_anonymous_pwritev (struct glfs *fs, struct glfs_object *object, +                        const struct iovec *iovec, int iovcnt, +                        off_t offset, int flags) +{ +        xlator_t        *subvol = NULL; +        struct iobref   *iobref = NULL; +        struct iobuf    *iobuf  = NULL; +        struct iovec    iov     = {0, }; +        inode_t         *inode  = NULL; +        fd_t            *fd     = NULL; +        int             ret     = -1; +        size_t          size    = -1; + +        __glfs_entry_fs (fs); + +        subvol = glfs_active_subvol (fs); +        if (!subvol) { +                ret = -1; +                errno = EIO; +                goto out; +        } + +        /* get/refresh the in arg objects inode in correlation to the xlator */ +        inode = glfs_resolve_inode (fs, subvol, object); +        if (!inode) { +                ret = -1; +                errno = ESTALE; +                goto out; +        } + +        fd = fd_anonymous (inode); +        if (!fd) { +                ret = -1; +                gf_msg ("gfapi", GF_LOG_ERROR, ENOMEM, API_MSG_FDCREATE_FAILED, +                        "Allocating anonymous fd failed"); +                errno = ENOMEM; +                goto out; +        } + +        size = iov_length (iovec, iovcnt); + +        iobuf = iobuf_get2 (subvol->ctx->iobuf_pool, size); +        if (!iobuf) { +                ret = -1; +                errno = ENOMEM; +                goto out; +        } + +        iobref = iobref_new (); +        if (!iobref) { +                iobuf_unref (iobuf); +                errno = ENOMEM; +                ret = -1; +                goto out; +        } + +        ret = iobref_add (iobref, iobuf); +        if (ret) { +                iobuf_unref (iobuf); +                iobref_unref (iobref); +                errno = ENOMEM; +                ret = -1; +                goto out; +        } + +        iov_unload (iobuf_ptr (iobuf), iovec, iovcnt); + +        iov.iov_base = iobuf_ptr (iobuf); +        iov.iov_len = size; + +        ret = syncop_writev (subvol, fd, &iov, 1, offset, iobref, flags, +                             NULL, NULL); +        DECODE_SYNCOP_ERR (ret); + +        iobuf_unref (iobuf); +        iobref_unref (iobref); + +        if (ret <= 0) +                goto out; + +out: + +        if (fd) +                fd_unref(fd); + +        glfs_subvol_done (fs, subvol); + +        return ret; +} + +ssize_t +glfs_anonymous_preadv (struct glfs *fs,  struct glfs_object *object, +                       const struct iovec *iovec, int iovcnt, +                       off_t offset, int flags) +{ +        xlator_t        *subvol = NULL; +        struct iovec    *iov    = NULL; +        struct iobref   *iobref = NULL; +        inode_t         *inode  = NULL; +        fd_t            *fd     = NULL; +        int             cnt     = 0; +        ssize_t         ret     = -1; +        ssize_t         size    = -1; + +        __glfs_entry_fs (fs); + +        subvol = glfs_active_subvol (fs); +        if (!subvol) { +                ret = -1; +                errno = EIO; +                goto out; +        } + +        /* get/refresh the in arg objects inode in correlation to the xlator */ +        inode = glfs_resolve_inode (fs, subvol, object); +        if (!inode) { +                ret = -1; +                errno = ESTALE; +                goto out; +        } + +        fd = fd_anonymous (inode); +        if (!fd) { +                ret = -1; +                gf_msg ("gfapi", GF_LOG_ERROR, ENOMEM, API_MSG_FDCREATE_FAILED, +                        "Allocating anonymous fd failed"); +                errno = ENOMEM; +                goto out; +        } + +        size = iov_length (iovec, iovcnt); + +	ret = syncop_readv (subvol, fd, size, offset, flags, &iov, &cnt, +                            &iobref, NULL, NULL); +        DECODE_SYNCOP_ERR (ret); +        if (ret <= 0) +                goto out; + +        size = iov_copy (iovec, iovcnt, iov, cnt); + +        ret = size; +out: +        if (iov) +                GF_FREE (iov); +        if (iobref) +                iobref_unref (iobref); +        if (fd) +                fd_unref(fd); + +        glfs_subvol_done (fs, subvol); + +        return ret; +} diff --git a/api/src/glfs-handleops.c b/api/src/glfs-handleops.c index 4a544f7c905..2793e1cb118 100644 --- a/api/src/glfs-handleops.c +++ b/api/src/glfs-handleops.c @@ -1962,3 +1962,51 @@ pub_glfs_h_acl_set (struct glfs *fs, struct glfs_object *object,  #endif  GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_acl_set, 3.7.0);  GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_acl_get, 3.7.0); + +/* The API to perform read using anonymous fd */ +ssize_t +pub_glfs_h_anonymous_read (struct glfs *fs, struct glfs_object *object, +                           const void *buf, size_t count, off_t offset) +{ +        struct iovec    iov     = {0, }; +        ssize_t         ret     = 0; + +        /* validate in args */ +        if ((fs == NULL) || (object == NULL)) { +                errno = EINVAL; +                return -1; +        } + +        iov.iov_base = (void *) buf; +        iov.iov_len = count; + +        ret = glfs_anonymous_preadv (fs, object, &iov, 1, offset, 0); + +        return ret; +} + +GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_anonymous_read, 3.7.0); + +/* The API to perform write using anonymous fd */ +ssize_t +pub_glfs_h_anonymous_write (struct glfs *fs, struct glfs_object *object, +                            const void *buf, size_t count, off_t offset) +{ +        struct iovec iov        = {0, }; +        ssize_t      ret        = 0; + +        /* validate in args */ +        if ((fs == NULL) || (object == NULL)) { +                errno = EINVAL; +                return -1; +        } + +        iov.iov_base = (void *) buf; +        iov.iov_len = count; + +        ret = glfs_anonymous_pwritev (fs, object, &iov, 1, offset, 0); + +        return ret; +} + +GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_anonymous_write, 3.7.0); diff --git a/api/src/glfs-handles.h b/api/src/glfs-handles.h index 28e9e79b9a3..19c4e8f7a62 100644 --- a/api/src/glfs-handles.h +++ b/api/src/glfs-handles.h @@ -310,6 +310,16 @@ glfs_h_acl_get (struct glfs *fs, struct glfs_object *object,                  const acl_type_t type) __THROW;          GFAPI_PUBLIC(glfs_h_acl_get, 3.7.0); +size_t +glfs_h_anonymous_write (struct glfs *fs, struct glfs_object *object, +                        const void *buf, size_t count, off_t offset) __THROW +        GFAPI_PUBLIC(glfs_h_anonymous_write, 3.7.0); + +ssize_t +glfs_h_anonymous_read (struct glfs *fs, struct glfs_object *object, +                      const void *buf, size_t count, off_t offset) __THROW +        GFAPI_PUBLIC(glfs_h_anonymous_read, 3.7.0); +  __END_DECLS  #endif /* !_GLFS_HANDLES_H */ diff --git a/api/src/glfs-internal.h b/api/src/glfs-internal.h index 972f2e4cf49..275f8d1534b 100644 --- a/api/src/glfs-internal.h +++ b/api/src/glfs-internal.h @@ -342,4 +342,12 @@ glfs_h_poll_cache_invalidation (struct glfs *fs,                                  struct callback_arg *up_arg,                                  struct gf_upcall *upcall_data); +ssize_t +glfs_anonymous_preadv (struct glfs *fs, struct glfs_object *object, +                       const struct iovec *iovec, int iovcnt, +                       off_t offset, int flags); +ssize_t +glfs_anonymous_pwritev (struct glfs *fs, struct glfs_object *object, +                        const struct iovec *iovec, int iovcnt, +                        off_t offset, int flags);  #endif /* !_GLFS_INTERNAL_H */  | 
