diff options
author | ShyamsundarR <srangana@redhat.com> | 2018-12-20 15:28:37 -0500 |
---|---|---|
committer | Amar Tumballi <amarts@redhat.com> | 2019-01-07 14:43:27 +0000 |
commit | 1a3c2a48e7cd44f2cc8b7b5384321d289aedab8e (patch) | |
tree | f4e38a878c80581d6e6af22e796fb88eb49ea80a /api | |
parent | c31f1c232a6673c4e3fc3188e15ae0e708a54613 (diff) |
gfapi: update returned/callback pre/post attributes to glfs_stat
Change-Id: Ie0fe971e694101aa011d66aa496d0644669c2c5a
Updates: #389
Signed-off-by: Kinglong Mee <mijinlong@open-fs.com>
Signed-off-by: ShyamsundarR <srangana@redhat.com>
Diffstat (limited to 'api')
-rw-r--r-- | api/src/gfapi.aliases | 1 | ||||
-rw-r--r-- | api/src/gfapi.map | 1 | ||||
-rw-r--r-- | api/src/glfs-fops.c | 158 | ||||
-rw-r--r-- | api/src/glfs-internal.h | 4 | ||||
-rw-r--r-- | api/src/glfs.h | 45 |
5 files changed, 159 insertions, 50 deletions
diff --git a/api/src/gfapi.aliases b/api/src/gfapi.aliases index 73b0bb67bcf..4cafd1f0174 100644 --- a/api/src/gfapi.aliases +++ b/api/src/gfapi.aliases @@ -171,6 +171,7 @@ _pub_glfs_upcall_lease_get_object _glfs_upcall_lease_get_object$GFAPI_4.1.6 _pub_glfs_upcall_lease_get_lease_type _glfs_upcall_lease_get_lease_type$GFAPI_4.1.6 _priv_glfs_statx _glfs_statx$GFAPI_future +_priv_glfs_iatt_from_statx _glfs_iatt_from_statx$GFAPI_future _pub_glfs_read_async _glfs_read_async$GFAPI_future _pub_glfs_write_async _glfs_write_async$GFAPI_future diff --git a/api/src/gfapi.map b/api/src/gfapi.map index b7f0dab2340..332af129d99 100644 --- a/api/src/gfapi.map +++ b/api/src/gfapi.map @@ -238,6 +238,7 @@ GFAPI_4.1.6 { GFAPI_PRIVATE_future { global: glfs_statx; + glfs_iatt_from_statx; } GFAPI_4.1.6; GFAPI_future { diff --git a/api/src/glfs-fops.c b/api/src/glfs-fops.c index d3255d18c0f..6d81bd85498 100644 --- a/api/src/glfs-fops.c +++ b/api/src/glfs-fops.c @@ -208,7 +208,8 @@ glfs_iatt_to_stat(struct glfs *fs, struct iatt *iatt, struct stat *stat) } void -glfs_iatt_to_statx(struct glfs *fs, struct iatt *iatt, struct glfs_stat *statx) +glfs_iatt_to_statx(struct glfs *fs, const struct iatt *iatt, + struct glfs_stat *statx) { statx->glfs_st_mask = 0; @@ -291,6 +292,87 @@ glfs_iatt_to_statx(struct glfs *fs, struct iatt *iatt, struct glfs_stat *statx) statx->glfs_st_attributes_mask = 0; } +void +priv_glfs_iatt_from_statx(struct iatt *iatt, const struct glfs_stat *statx) +{ + /* Most code in xlators are not checking validity flags before accessing + the items. Hence zero everything before setting valid items */ + memset(iatt, 0, sizeof(struct iatt)); + + if (GLFS_STAT_TYPE_VALID(statx->glfs_st_mask)) { + iatt->ia_type = ia_type_from_st_mode(statx->glfs_st_mode); + iatt->ia_flags |= IATT_TYPE; + } + + if (GLFS_STAT_MODE_VALID(statx->glfs_st_mask)) { + iatt->ia_prot = ia_prot_from_st_mode(statx->glfs_st_mode); + iatt->ia_flags |= IATT_MODE; + } + + if (GLFS_STAT_NLINK_VALID(statx->glfs_st_mask)) { + iatt->ia_nlink = statx->glfs_st_nlink; + iatt->ia_flags |= IATT_NLINK; + } + + if (GLFS_STAT_UID_VALID(statx->glfs_st_mask)) { + iatt->ia_uid = statx->glfs_st_uid; + iatt->ia_flags |= IATT_UID; + } + + if (GLFS_STAT_GID_VALID(statx->glfs_st_mask)) { + iatt->ia_gid = statx->glfs_st_gid; + iatt->ia_flags |= IATT_GID; + } + + if (GLFS_STAT_ATIME_VALID(statx->glfs_st_mask)) { + iatt->ia_atime = statx->glfs_st_atime.tv_sec; + iatt->ia_atime_nsec = statx->glfs_st_atime.tv_nsec; + iatt->ia_flags |= IATT_ATIME; + } + + if (GLFS_STAT_MTIME_VALID(statx->glfs_st_mask)) { + iatt->ia_mtime = statx->glfs_st_mtime.tv_sec; + iatt->ia_mtime_nsec = statx->glfs_st_mtime.tv_nsec; + iatt->ia_flags |= IATT_MTIME; + } + + if (GLFS_STAT_CTIME_VALID(statx->glfs_st_mask)) { + iatt->ia_ctime = statx->glfs_st_ctime.tv_sec; + iatt->ia_ctime_nsec = statx->glfs_st_ctime.tv_nsec; + iatt->ia_flags |= IATT_CTIME; + } + + if (GLFS_STAT_BTIME_VALID(statx->glfs_st_mask)) { + iatt->ia_btime = statx->glfs_st_btime.tv_sec; + iatt->ia_btime_nsec = statx->glfs_st_btime.tv_nsec; + iatt->ia_flags |= IATT_BTIME; + } + + if (GLFS_STAT_INO_VALID(statx->glfs_st_mask)) { + iatt->ia_ino = statx->glfs_st_ino; + iatt->ia_flags |= IATT_INO; + } + + if (GLFS_STAT_SIZE_VALID(statx->glfs_st_mask)) { + iatt->ia_size = statx->glfs_st_size; + iatt->ia_flags |= IATT_SIZE; + } + + if (GLFS_STAT_BLOCKS_VALID(statx->glfs_st_mask)) { + iatt->ia_blocks = statx->glfs_st_blocks; + iatt->ia_flags |= IATT_BLOCKS; + } + + /* unconditionally present, encode as is */ + iatt->ia_blksize = statx->glfs_st_blksize; + iatt->ia_rdev = makedev(statx->glfs_st_rdev_major, + statx->glfs_st_rdev_minor); + iatt->ia_dev = makedev(statx->glfs_st_dev_major, statx->glfs_st_dev_minor); + iatt->ia_attributes = statx->glfs_st_attributes; + iatt->ia_attributes_mask = statx->glfs_st_attributes_mask; +} +GFAPI_SYMVER_PRIVATE_DEFAULT(glfs_iatt_from_statx, future); + int glfs_loc_unlink(loc_t *loc) { @@ -541,7 +623,7 @@ invalid_fs: GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_stat, 3.4.0); int -priv_glfs_statx(struct glfs *fs, const char *path, unsigned int mask, +priv_glfs_statx(struct glfs *fs, const char *path, const unsigned int mask, struct glfs_stat *statxbuf) { int ret = -1; @@ -905,7 +987,7 @@ GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_lseek, 3.4.0); static ssize_t glfs_preadv_common(struct glfs_fd *glfd, const struct iovec *iovec, int iovcnt, - off_t offset, int flags, struct stat *poststat) + off_t offset, int flags, struct glfs_stat *poststat) { xlator_t *subvol = NULL; ssize_t ret = -1; @@ -949,7 +1031,7 @@ glfs_preadv_common(struct glfs_fd *glfd, const struct iovec *iovec, int iovcnt, DECODE_SYNCOP_ERR(ret); if (ret >= 0 && poststat) - glfs_iatt_to_stat(glfd->fs, &iatt, poststat); + glfs_iatt_to_statx(glfd->fs, &iatt, poststat); if (ret <= 0) goto out; @@ -1028,7 +1110,7 @@ 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) + int flags, struct glfs_stat *poststat) { struct iovec iov = { 0, @@ -1083,8 +1165,8 @@ glfs_io_async_cbk(int op_ret, int op_errno, call_frame_t *frame, void *cookie, struct glfs *fs = NULL; struct glfs_fd *glfd = NULL; int ret = -1; - struct stat prestat = {}, *prestatp = NULL; - struct stat poststat = {}, *poststatp = NULL; + struct glfs_stat prestat = {}, *prestatp = NULL; + struct glfs_stat poststat = {}, *poststatp = NULL; GF_VALIDATE_OR_GOTO("gfapi", frame, inval); GF_VALIDATE_OR_GOTO("gfapi", cookie, inval); @@ -1120,12 +1202,12 @@ out: } else { if (prebuf) { prestatp = &prestat; - glfs_iatt_to_stat(fs, prebuf, prestatp); + glfs_iatt_to_statx(fs, prebuf, prestatp); } if (postbuf) { poststatp = &poststat; - glfs_iatt_to_stat(fs, postbuf, poststatp); + glfs_iatt_to_statx(fs, postbuf, poststatp); } gio->fn(gio->glfd, op_ret, prestatp, poststatp, gio->data); @@ -1389,8 +1471,8 @@ GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_readv_async, future); 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) + off_t offset, int flags, struct glfs_stat *prestat, + struct glfs_stat *poststat) { xlator_t *subvol = NULL; int ret = -1; @@ -1443,9 +1525,9 @@ glfs_pwritev_common(struct glfs_fd *glfd, const struct iovec *iovec, int iovcnt, if (ret >= 0) { if (prestat) - glfs_iatt_to_stat(glfd->fs, &preiatt, prestat); + glfs_iatt_to_statx(glfd->fs, &preiatt, prestat); if (poststat) - glfs_iatt_to_stat(glfd->fs, &postiatt, poststat); + glfs_iatt_to_statx(glfd->fs, &postiatt, poststat); } if (ret <= 0) @@ -1475,8 +1557,8 @@ invalid_fs: ssize_t pub_glfs_copy_file_range(struct glfs_fd *glfd_in, off64_t *off_in, struct glfs_fd *glfd_out, off64_t *off_out, size_t len, - unsigned int flags, struct stat *statbuf, - struct stat *prestat, struct stat *poststat) + unsigned int flags, struct glfs_stat *statbuf, + struct glfs_stat *prestat, struct glfs_stat *poststat) { xlator_t *subvol = NULL; int ret = -1; @@ -1572,11 +1654,11 @@ pub_glfs_copy_file_range(struct glfs_fd *glfd_in, off64_t *off_in, *off_out = pos_out; if (statbuf) - glfs_iatt_to_stat(glfd_in->fs, &iattbuf, statbuf); + glfs_iatt_to_statx(glfd_in->fs, &iattbuf, statbuf); if (prestat) - glfs_iatt_to_stat(glfd_in->fs, &preiatt, prestat); + glfs_iatt_to_statx(glfd_in->fs, &preiatt, prestat); if (poststat) - glfs_iatt_to_stat(glfd_in->fs, &postiatt, poststat); + glfs_iatt_to_statx(glfd_in->fs, &postiatt, poststat); } if (ret <= 0) @@ -1688,8 +1770,8 @@ 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) + off_t offset, int flags, struct glfs_stat *prestat, + struct glfs_stat *poststat) { struct iovec iov = { 0, @@ -1953,8 +2035,8 @@ pub_glfs_writev_async(struct glfs_fd *glfd, const struct iovec *iov, int count, GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_writev_async, future); static int -glfs_fsync_common(struct glfs_fd *glfd, struct stat *prestat, - struct stat *poststat) +glfs_fsync_common(struct glfs_fd *glfd, struct glfs_stat *prestat, + struct glfs_stat *poststat) { int ret = -1; xlator_t *subvol = NULL; @@ -1996,9 +2078,9 @@ glfs_fsync_common(struct glfs_fd *glfd, struct stat *prestat, if (ret >= 0) { if (prestat) - glfs_iatt_to_stat(glfd->fs, &preiatt, prestat); + glfs_iatt_to_statx(glfd->fs, &preiatt, prestat); if (poststat) - glfs_iatt_to_stat(glfd->fs, &postiatt, poststat); + glfs_iatt_to_statx(glfd->fs, &postiatt, poststat); } out: if (fd) @@ -2025,8 +2107,8 @@ pub_glfs_fsync34(struct glfs_fd *glfd) GFAPI_SYMVER_PUBLIC(glfs_fsync34, glfs_fsync, 3.4.0); int -pub_glfs_fsync(struct glfs_fd *glfd, struct stat *prestat, - struct stat *poststat) +pub_glfs_fsync(struct glfs_fd *glfd, struct glfs_stat *prestat, + struct glfs_stat *poststat) { return glfs_fsync_common(glfd, prestat, poststat); } @@ -2150,8 +2232,8 @@ invalid_fs: GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fsync_async, future); static int -glfs_fdatasync_common(struct glfs_fd *glfd, struct stat *prestat, - struct stat *poststat) +glfs_fdatasync_common(struct glfs_fd *glfd, struct glfs_stat *prestat, + struct glfs_stat *poststat) { int ret = -1; xlator_t *subvol = NULL; @@ -2193,9 +2275,9 @@ glfs_fdatasync_common(struct glfs_fd *glfd, struct stat *prestat, if (ret >= 0) { if (prestat) - glfs_iatt_to_stat(glfd->fs, &preiatt, prestat); + glfs_iatt_to_statx(glfd->fs, &preiatt, prestat); if (poststat) - glfs_iatt_to_stat(glfd->fs, &postiatt, poststat); + glfs_iatt_to_statx(glfd->fs, &postiatt, poststat); } out: if (fd) @@ -2222,8 +2304,8 @@ pub_glfs_fdatasync34(struct glfs_fd *glfd) GFAPI_SYMVER_PUBLIC(glfs_fdatasync34, glfs_fdatasync, 3.4.0); int -pub_glfs_fdatasync(struct glfs_fd *glfd, struct stat *prestat, - struct stat *poststat) +pub_glfs_fdatasync(struct glfs_fd *glfd, struct glfs_stat *prestat, + struct glfs_stat *poststat) { return glfs_fdatasync_common(glfd, prestat, poststat); } @@ -2267,8 +2349,8 @@ invalid_fs: GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fdatasync_async, future); static int -glfs_ftruncate_common(struct glfs_fd *glfd, off_t offset, struct stat *prestat, - struct stat *poststat) +glfs_ftruncate_common(struct glfs_fd *glfd, off_t offset, + struct glfs_stat *prestat, struct glfs_stat *poststat) { int ret = -1; xlator_t *subvol = NULL; @@ -2311,9 +2393,9 @@ glfs_ftruncate_common(struct glfs_fd *glfd, off_t offset, struct stat *prestat, if (ret >= 0) { if (prestat) - glfs_iatt_to_stat(glfd->fs, &preiatt, prestat); + glfs_iatt_to_statx(glfd->fs, &preiatt, prestat); if (poststat) - glfs_iatt_to_stat(glfd->fs, &postiatt, poststat); + glfs_iatt_to_statx(glfd->fs, &postiatt, poststat); } out: if (fd) @@ -2340,8 +2422,8 @@ pub_glfs_ftruncate34(struct glfs_fd *glfd, off_t offset) GFAPI_SYMVER_PUBLIC(glfs_ftruncate34, glfs_ftruncate, 3.4.0); int -pub_glfs_ftruncate(struct glfs_fd *glfd, off_t offset, struct stat *prestat, - struct stat *poststat) +pub_glfs_ftruncate(struct glfs_fd *glfd, off_t offset, + struct glfs_stat *prestat, struct glfs_stat *poststat) { return glfs_ftruncate_common(glfd, offset, prestat, poststat); } diff --git a/api/src/glfs-internal.h b/api/src/glfs-internal.h index d372413fd56..c7fbdeb6560 100644 --- a/api/src/glfs-internal.h +++ b/api/src/glfs-internal.h @@ -695,4 +695,8 @@ int glfs_statx(struct glfs *fs, const char *path, unsigned int mask, struct glfs_stat *statxbuf) GFAPI_PRIVATE(glfs_statx, future); +void +glfs_iatt_from_statx(struct iatt *, const struct glfs_stat *) + GFAPI_PRIVATE(glfs_iatt_from_statx, future); + #endif /* !_GLFS_INTERNAL_H */ diff --git a/api/src/glfs.h b/api/src/glfs.h index 7f0a34ae9e7..fe305e8e167 100644 --- a/api/src/glfs.h +++ b/api/src/glfs.h @@ -435,6 +435,21 @@ typedef struct glfs_fd glfs_fd_t; #define GLFS_STAT_RESERVED \ 0x8000000000000000U /* Reserved to denote future expansion */ +/* Macros for checking validity of struct glfs_stat members.*/ +#define GLFS_STAT_TYPE_VALID(stmask) (stmask & GLFS_STAT_TYPE) +#define GLFS_STAT_MODE_VALID(stmask) (stmask & GLFS_STAT_MODE) +#define GLFS_STAT_NLINK_VALID(stmask) (stmask & GLFS_STAT_NLINK) +#define GLFS_STAT_UID_VALID(stmask) (stmask & GLFS_STAT_UID) +#define GLFS_STAT_GID_VALID(stmask) (stmask & GLFS_STAT_GID) +#define GLFS_STAT_ATIME_VALID(stmask) (stmask & GLFS_STAT_ATIME) +#define GLFS_STAT_MTIME_VALID(stmask) (stmask & GLFS_STAT_MTIME) +#define GLFS_STAT_CTIME_VALID(stmask) (stmask & GLFS_STAT_CTIME) +#define GLFS_STAT_INO_VALID(stmask) (stmask & GLFS_STAT_INO) +#define GLFS_STAT_SIZE_VALID(stmask) (stmask & GLFS_STAT_SIZE) +#define GLFS_STAT_BLOCKS_VALID(stmask) (stmask & GLFS_STAT_BLOCKS) +#define GLFS_STAT_BTIME_VALID(stmask) (stmask & GLFS_STAT_BTIME) +#define GLFS_STAT_GFID_VALID(stmask) (stmask & GLFS_STAT_GFID) + /* * Attributes to be found in glfs_st_attributes and masked in * glfs_st_attributes_mask. @@ -632,10 +647,14 @@ glfs_set_xlator_option(glfs_t *fs, const char *xlator, const char *key, time of issuing the async IO call. This can be used by the caller to differentiate different instances of the async requests in a common callback function. + + @prestat and @poststat are allocated on the stack, that are auto destroyed + post the callback function returns. */ -typedef void (*glfs_io_cbk)(glfs_fd_t *fd, ssize_t ret, struct stat *prestat, - struct stat *poststat, void *data); +typedef void (*glfs_io_cbk)(glfs_fd_t *fd, ssize_t ret, + struct glfs_stat *prestat, + struct glfs_stat *poststat, void *data); // glfs_{read,write}[_async] @@ -681,11 +700,12 @@ glfs_writev_async(glfs_fd_t *fd, const struct iovec *iov, int count, int flags, ssize_t glfs_pread(glfs_fd_t *fd, void *buf, size_t count, off_t offset, int flags, - struct stat *poststat) __THROW GFAPI_PUBLIC(glfs_pread, future); + struct glfs_stat *poststat) __THROW GFAPI_PUBLIC(glfs_pread, future); ssize_t glfs_pwrite(glfs_fd_t *fd, const void *buf, size_t count, off_t offset, - int flags, struct stat *prestat, struct stat *poststat) __THROW + int flags, struct glfs_stat *prestat, + struct glfs_stat *poststat) __THROW GFAPI_PUBLIC(glfs_pwrite, future); int @@ -725,8 +745,9 @@ glfs_lseek(glfs_fd_t *fd, off_t offset, int whence) __THROW ssize_t glfs_copy_file_range(struct glfs_fd *glfd_in, off64_t *off_in, struct glfs_fd *glfd_out, off64_t *off_out, size_t len, - unsigned int flags, struct stat *statbuf, - struct stat *prestat, struct stat *poststat) __THROW + unsigned int flags, struct glfs_stat *statbuf, + struct glfs_stat *prestat, + struct glfs_stat *poststat) __THROW GFAPI_PUBLIC(glfs_copy_file_range, future); int @@ -734,8 +755,8 @@ glfs_truncate(glfs_t *fs, const char *path, off_t length) __THROW GFAPI_PUBLIC(glfs_truncate, 3.7.15); int -glfs_ftruncate(glfs_fd_t *fd, off_t length, struct stat *prestat, - struct stat *poststat) __THROW +glfs_ftruncate(glfs_fd_t *fd, off_t length, struct glfs_stat *prestat, + struct glfs_stat *poststat) __THROW GFAPI_PUBLIC(glfs_ftruncate, future); int @@ -756,16 +777,16 @@ glfs_fstat(glfs_fd_t *fd, struct stat *buf) __THROW GFAPI_PUBLIC(glfs_fstat, 3.4.0); int -glfs_fsync(glfs_fd_t *fd, struct stat *prestat, struct stat *poststat) __THROW - GFAPI_PUBLIC(glfs_fsync, future); +glfs_fsync(glfs_fd_t *fd, struct glfs_stat *prestat, + struct glfs_stat *poststat) __THROW GFAPI_PUBLIC(glfs_fsync, future); int glfs_fsync_async(glfs_fd_t *fd, glfs_io_cbk fn, void *data) __THROW GFAPI_PUBLIC(glfs_fsync_async, future); int -glfs_fdatasync(glfs_fd_t *fd, struct stat *prestat, - struct stat *poststat) __THROW +glfs_fdatasync(glfs_fd_t *fd, struct glfs_stat *prestat, + struct glfs_stat *poststat) __THROW GFAPI_PUBLIC(glfs_fdatasync, future); int |