diff options
author | Kinglong Mee <kinglongmee@gmail.com> | 2018-02-12 15:13:49 +0800 |
---|---|---|
committer | Amar Tumballi <amarts@redhat.com> | 2018-02-12 21:34:46 +0000 |
commit | d01f7244e9d9f7e3ef84e0ba7b48ef1b1b09d809 (patch) | |
tree | 1a95023e8a4097e9a07ded99642228894876d8b5 /api | |
parent | bfb66cc535ce473afa7e330800d2d2c38afe42c9 (diff) |
gfapi: return pre/post attributes from glfs_pread/pwrite
As nfs-ganesha, a wcc data contains pre/post attributes is return
in read/write rpc reply. nfs-ganesha get those attributes by
two getattr between the real read/write right now.
But, gluster has return pre/post attributes from glusterfsd,
those attributes are skipped in syncop/gfapi, if gfapi return them,
the upper user (nfs-ganesha) can use them directly without any
duplicate getattr.
Updates: #389
Change-Id: I7b643ae4241cfe2aeb17063de00192d81674024a
Signed-off-by: Kinglong Mee <mijinlong@open-fs.com>
Diffstat (limited to 'api')
-rw-r--r-- | api/src/gfapi.aliases | 6 | ||||
-rw-r--r-- | api/src/gfapi.map | 4 | ||||
-rw-r--r-- | api/src/glfs-fops.c | 100 | ||||
-rw-r--r-- | api/src/glfs.h | 9 |
4 files changed, 93 insertions, 26 deletions
diff --git a/api/src/gfapi.aliases b/api/src/gfapi.aliases index 0cb2e5c1baf..d8c5162e684 100644 --- a/api/src/gfapi.aliases +++ b/api/src/gfapi.aliases @@ -24,8 +24,8 @@ _pub_glfs_readv _glfs_readv$GFAPI_3.4.0 _pub_glfs_writev _glfs_writev$GFAPI_3.4.0 _pub_glfs_readv_async _glfs_readv_async$GFAPI_3.4.0 _pub_glfs_writev_async _glfs_writev_async$GFAPI_3.4.0 -_pub_glfs_pread _glfs_pread$GFAPI_3.4.0 -_pub_glfs_pwrite _glfs_pwrite$GFAPI_3.4.0 +_pub_glfs_pread34 _glfs_pread$GFAPI_3.4.0 +_pub_glfs_pwrite34 _glfs_pwrite$GFAPI_3.4.0 _pub_glfs_pread_async _glfs_pread_async$GFAPI_3.4.0 _pub_glfs_pwrite_async _glfs_pwrite_async$GFAPI_3.4.0 _pub_glfs_preadv _glfs_preadv$GFAPI_3.4.0 @@ -172,3 +172,5 @@ _pub_glfs_setfsleaseid _glfs_setfsleaseid$GFAPI_4.0.0 _pub_glfs_file_lock _glfs_file_lock$GFAPI_4.0.0 _pub_glfs_lease _glfs_lease$GFAPI_4.0.0 _pub_glfs_h_lease _glfs_h_lease$GFAPI_4.0.0 +_pub_glfs_pread _glfs_pread$GFAPI_4.0.0 +_pub_glfs_pwrite _glfs_pwrite$GFAPI_4.0.0 diff --git a/api/src/gfapi.map b/api/src/gfapi.map index 4dc20e33f4d..c122023e7f5 100644 --- a/api/src/gfapi.map +++ b/api/src/gfapi.map @@ -30,8 +30,6 @@ GFAPI_3.4.0 { glfs_writev; glfs_readv_async; glfs_writev_async; - glfs_pread; - glfs_pwrite; glfs_pread_async; glfs_pwrite_async; glfs_preadv; @@ -227,4 +225,6 @@ GFAPI_4.0.0 { glfs_file_lock; glfs_lease; glfs_h_lease; + glfs_pread; + glfs_pwrite; } GFAPI_3.13.0; diff --git a/api/src/glfs-fops.c b/api/src/glfs-fops.c index d3deb746406..98ffa5ea68d 100644 --- a/api/src/glfs-fops.c +++ b/api/src/glfs-fops.c @@ -694,9 +694,9 @@ invalid_fs: GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_lseek, 3.4.0); -ssize_t -pub_glfs_preadv (struct glfs_fd *glfd, const struct iovec *iovec, int iovcnt, - off_t offset, int flags) +static ssize_t +glfs_preadv_common (struct glfs_fd *glfd, const struct iovec *iovec, + int iovcnt, off_t offset, int flags, struct stat *poststat) { xlator_t *subvol = NULL; ssize_t ret = -1; @@ -705,6 +705,7 @@ pub_glfs_preadv (struct glfs_fd *glfd, const struct iovec *iovec, int iovcnt, int cnt = 0; struct iobref *iobref = NULL; fd_t *fd = NULL; + struct iatt iatt = {0, }; DECLARE_OLD_THIS; __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); @@ -728,8 +729,12 @@ pub_glfs_preadv (struct glfs_fd *glfd, const struct iovec *iovec, int iovcnt, size = iov_length (iovec, iovcnt); ret = syncop_readv (subvol, fd, size, offset, 0, &iov, &cnt, &iobref, - NULL, NULL); + &iatt, NULL, NULL); DECODE_SYNCOP_ERR (ret); + + if (ret >= 0 && poststat) + glfs_iatt_to_stat (glfd->fs, &iatt, poststat); + if (ret <= 0) goto out; @@ -757,6 +762,13 @@ invalid_fs: return ret; } +ssize_t +pub_glfs_preadv (struct glfs_fd *glfd, const struct iovec *iovec, int iovcnt, + off_t offset, int flags) +{ + return glfs_preadv_common (glfd, iovec, iovcnt, offset, flags, NULL); +} + GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_preadv, 3.4.0); @@ -778,8 +790,8 @@ GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_read, 3.4.0); ssize_t -pub_glfs_pread (struct glfs_fd *glfd, void *buf, size_t count, off_t offset, - int flags) +pub_glfs_pread34 (struct glfs_fd *glfd, void *buf, size_t count, off_t offset, + int flags) { struct iovec iov = {0, }; ssize_t ret = 0; @@ -792,7 +804,25 @@ pub_glfs_pread (struct glfs_fd *glfd, void *buf, size_t count, off_t offset, return ret; } -GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_pread, 3.4.0); +GFAPI_SYMVER_PUBLIC(glfs_pread34, glfs_pread, 3.4.0); + + +ssize_t +pub_glfs_pread (struct glfs_fd *glfd, void *buf, size_t count, off_t offset, + int flags, struct stat *poststat) +{ + struct iovec iov = {0, }; + ssize_t ret = 0; + + iov.iov_base = buf; + iov.iov_len = count; + + ret = glfs_preadv_common (glfd, &iov, 1, offset, flags, poststat); + + return ret; +} + +GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_pread, 4.0.0); ssize_t @@ -1081,9 +1111,10 @@ out: } -ssize_t -pub_glfs_pwritev (struct glfs_fd *glfd, const struct iovec *iovec, int iovcnt, - off_t offset, int flags) +static ssize_t +glfs_pwritev_common (struct glfs_fd *glfd, const struct iovec *iovec, + int iovcnt, off_t offset, int flags, + struct stat *prestat, struct stat *poststat) { xlator_t *subvol = NULL; int ret = -1; @@ -1091,6 +1122,7 @@ pub_glfs_pwritev (struct glfs_fd *glfd, const struct iovec *iovec, int iovcnt, struct iobuf *iobuf = NULL; struct iovec iov = {0, }; fd_t *fd = NULL; + struct iatt preiatt = {0, }, postiatt = {0, }; DECLARE_OLD_THIS; __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); @@ -1115,15 +1147,21 @@ pub_glfs_pwritev (struct glfs_fd *glfd, const struct iovec *iovec, int iovcnt, if (ret) goto out; - ret = syncop_writev (subvol, fd, &iov, 1, offset, iobref, flags, NULL, - NULL); + ret = syncop_writev (subvol, fd, &iov, 1, offset, iobref, flags, + &preiatt, &postiatt, NULL, NULL); DECODE_SYNCOP_ERR (ret); + if (ret >= 0) { + if (prestat) + glfs_iatt_to_stat (glfd->fs, &preiatt, prestat); + if (poststat) + glfs_iatt_to_stat (glfd->fs, &postiatt, poststat); + } + if (ret <= 0) goto out; glfd->offset = (offset + iov.iov_len); - out: if (iobuf) iobuf_unref (iobuf); @@ -1142,6 +1180,14 @@ invalid_fs: return ret; } +ssize_t +pub_glfs_pwritev (struct glfs_fd *glfd, const struct iovec *iovec, int iovcnt, + off_t offset, int flags) +{ + return glfs_pwritev_common (glfd, iovec, iovcnt, offset, flags, + NULL, NULL); +} + GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_pwritev, 3.4.0); @@ -1177,8 +1223,8 @@ GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_writev, 3.4.0); ssize_t -pub_glfs_pwrite (struct glfs_fd *glfd, const void *buf, size_t count, - off_t offset, int flags) +pub_glfs_pwrite34 (struct glfs_fd *glfd, const void *buf, size_t count, + off_t offset, int flags) { struct iovec iov = {0, }; ssize_t ret = 0; @@ -1191,8 +1237,26 @@ pub_glfs_pwrite (struct glfs_fd *glfd, const void *buf, size_t count, return ret; } -GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_pwrite, 3.4.0); +GFAPI_SYMVER_PUBLIC(glfs_pwrite34, glfs_pwrite, 3.4.0); + +ssize_t +pub_glfs_pwrite (struct glfs_fd *glfd, const void *buf, size_t count, + off_t offset, int flags, struct stat *prestat, + struct stat *poststat) +{ + struct iovec iov = {0, }; + ssize_t ret = 0; + + iov.iov_base = (void *) buf; + iov.iov_len = count; + + ret = glfs_pwritev_common (glfd, &iov, 1, offset, flags, + prestat, poststat); + + return ret; +} +GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_pwrite, 4.0.0); extern glfs_t *pub_glfs_from_glfd (glfs_fd_t *); @@ -4746,7 +4810,7 @@ glfs_anonymous_pwritev (struct glfs *fs, struct glfs_object *object, iov.iov_len = size; ret = syncop_writev (subvol, fd, &iov, 1, offset, iobref, flags, - NULL, NULL); + NULL, NULL, NULL, NULL); DECODE_SYNCOP_ERR (ret); iobuf_unref (iobuf); @@ -4815,7 +4879,7 @@ glfs_anonymous_preadv (struct glfs *fs, struct glfs_object *object, size = iov_length (iovec, iovcnt); ret = syncop_readv (subvol, fd, size, offset, flags, &iov, &cnt, - &iobref, NULL, NULL); + &iobref, NULL, NULL, NULL); DECODE_SYNCOP_ERR (ret); if (ret <= 0) goto out; diff --git a/api/src/glfs.h b/api/src/glfs.h index 4613cd193ea..39caf3efc3f 100644 --- a/api/src/glfs.h +++ b/api/src/glfs.h @@ -534,11 +534,12 @@ int glfs_writev_async (glfs_fd_t *fd, const struct iovec *iov, int count, // glfs_p{read,write}[_async] ssize_t glfs_pread (glfs_fd_t *fd, void *buf, size_t count, off_t offset, - int flags) __THROW - GFAPI_PUBLIC(glfs_pread, 3.4.0); + int flags, struct stat *poststat) __THROW + GFAPI_PUBLIC(glfs_pread, 4.0.0); ssize_t glfs_pwrite (glfs_fd_t *fd, const void *buf, size_t count, - off_t offset, int flags) __THROW - GFAPI_PUBLIC(glfs_pwrite, 3.4.0); + off_t offset, int flags, struct stat *prestat, + struct stat *poststat) __THROW + GFAPI_PUBLIC(glfs_pwrite, 4.0.0); int glfs_pread_async (glfs_fd_t *fd, void *buf, size_t count, off_t offset, int flags, glfs_io_cbk fn, void *data) __THROW GFAPI_PUBLIC(glfs_pread_async, 3.4.0); |