diff options
-rw-r--r-- | api/src/gfapi.aliases | 3 | ||||
-rw-r--r-- | api/src/gfapi.map | 2 | ||||
-rw-r--r-- | api/src/glfs-fops.c | 35 | ||||
-rw-r--r-- | api/src/glfs.h | 5 | ||||
-rwxr-xr-x | libglusterfs/src/generator.py | 2 | ||||
-rw-r--r-- | libglusterfs/src/syncop.c | 15 | ||||
-rw-r--r-- | libglusterfs/src/syncop.h | 1 | ||||
-rw-r--r-- | tests/basic/gfapi/mandatory-lock-optimal.c | 2 | ||||
-rw-r--r-- | xlators/cluster/dht/src/dht-rebalance.c | 11 |
9 files changed, 61 insertions, 15 deletions
diff --git a/api/src/gfapi.aliases b/api/src/gfapi.aliases index 16777fa417c..0445c0ac640 100644 --- a/api/src/gfapi.aliases +++ b/api/src/gfapi.aliases @@ -34,7 +34,7 @@ _pub_glfs_preadv_async _glfs_preadv_async$GFAPI_3.4.0 _pub_glfs_pwritev_async _glfs_pwritev_async$GFAPI_3.4.0 _pub_glfs_lseek _glfs_lseek$GFAPI_3.4.0 _pub_glfs_truncate _glfs_truncate$GFAPI_3.7.15 -_pub_glfs_ftruncate _glfs_ftruncate$GFAPI_3.4.0 +_pub_glfs_ftruncate34 _glfs_ftruncate34$GFAPI_3.4.0 _pub_glfs_ftruncate_async _glfs_ftruncate_async$GFAPI_3.4.0 _pub_glfs_lstat _glfs_lstat$GFAPI_3.4.0 _pub_glfs_stat _glfs_stat$GFAPI_3.4.0 @@ -176,3 +176,4 @@ _pub_glfs_pread _glfs_pread$GFAPI_4.0.0 _pub_glfs_pwrite _glfs_pwrite$GFAPI_4.0.0 _pub_glfs_fsync _glfs_fsync$GFAPI_4.0.0 _pub_glfs_fdatasync _glfs_fdatasync$GFAPI_4.0.0 +_pub_glfs_ftruncate _glfs_ftruncate$GFAPI_4.0.0 diff --git a/api/src/gfapi.map b/api/src/gfapi.map index fec0f4ff807..fbf0985d990 100644 --- a/api/src/gfapi.map +++ b/api/src/gfapi.map @@ -37,7 +37,6 @@ GFAPI_3.4.0 { glfs_preadv_async; glfs_pwritev_async; glfs_lseek; - glfs_ftruncate; glfs_ftruncate_async; glfs_lstat; glfs_stat; @@ -227,4 +226,5 @@ GFAPI_4.0.0 { glfs_pwrite; glfs_fsync; glfs_fdatasync; + glfs_ftruncate; } GFAPI_3.13.0; diff --git a/api/src/glfs-fops.c b/api/src/glfs-fops.c index a63c175d052..1cd7669438f 100644 --- a/api/src/glfs-fops.c +++ b/api/src/glfs-fops.c @@ -1678,12 +1678,14 @@ invalid_fs: GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fdatasync_async, 3.4.0); -int -pub_glfs_ftruncate (struct glfs_fd *glfd, off_t offset) +static int +glfs_ftruncate_common (struct glfs_fd *glfd, off_t offset, + struct stat *prestat, struct stat *poststat) { int ret = -1; xlator_t *subvol = NULL; fd_t *fd = NULL; + struct iatt preiatt = {0, }, postiatt = {0, }; DECLARE_OLD_THIS; __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); @@ -1704,8 +1706,16 @@ pub_glfs_ftruncate (struct glfs_fd *glfd, off_t offset) goto out; } - ret = syncop_ftruncate (subvol, fd, offset, NULL, NULL); + ret = syncop_ftruncate (subvol, fd, offset, &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); + } out: if (fd) fd_unref (fd); @@ -1720,7 +1730,24 @@ invalid_fs: return ret; } -GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_ftruncate, 3.4.0); +int +pub_glfs_ftruncate34 (struct glfs_fd *glfd, off_t offset) +{ + return glfs_ftruncate_common (glfd, offset, NULL, NULL); +} + +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) +{ + return glfs_ftruncate_common (glfd, offset, prestat, poststat); +} + +GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_ftruncate, 4.0.0); + int pub_glfs_truncate (struct glfs *fs, const char *path, off_t length) diff --git a/api/src/glfs.h b/api/src/glfs.h index 2addacb7ecf..e2f2a2c1804 100644 --- a/api/src/glfs.h +++ b/api/src/glfs.h @@ -571,8 +571,9 @@ off_t glfs_lseek (glfs_fd_t *fd, off_t offset, int whence) __THROW int 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) __THROW - GFAPI_PUBLIC(glfs_ftruncate, 3.4.0); +int glfs_ftruncate (glfs_fd_t *fd, off_t length, struct stat *prestat, + struct stat *poststat) __THROW + GFAPI_PUBLIC(glfs_ftruncate, 4.0.0); int glfs_ftruncate_async (glfs_fd_t *fd, off_t length, glfs_io_cbk fn, void *data) __THROW GFAPI_PUBLIC(glfs_ftruncate_async, 3.4.0); diff --git a/libglusterfs/src/generator.py b/libglusterfs/src/generator.py index e565438bfeb..c9311ea3856 100755 --- a/libglusterfs/src/generator.py +++ b/libglusterfs/src/generator.py @@ -303,6 +303,8 @@ ops['access'] = ( ops['ftruncate'] = ( ('fop-arg', 'fd', 'fd_t *', 'fd'), ('fop-arg', 'offset', 'off_t', 'offset'), + ('extra', 'preop', 'struct iatt', '&preop'), + ('extra', 'postop', 'struct iatt', '&postop'), ('fop-arg', 'xdata', 'dict_t *', 'xdata'), ('cbk-arg', 'prebuf', 'struct iatt *'), ('cbk-arg', 'postbuf', 'struct iatt *'), diff --git a/libglusterfs/src/syncop.c b/libglusterfs/src/syncop.c index 76e1a5e9116..202b3aba4ab 100644 --- a/libglusterfs/src/syncop.c +++ b/libglusterfs/src/syncop.c @@ -2326,20 +2326,31 @@ syncop_ftruncate_cbk (call_frame_t *frame, void *cookie, xlator_t *this, if (xdata) args->xdata = dict_ref (xdata); + if (op_ret >= 0) { + args->iatt1 = *prebuf; + args->iatt2 = *postbuf; + } + __wake (args); return 0; } int -syncop_ftruncate (xlator_t *subvol, fd_t *fd, off_t offset, dict_t *xdata_in, - dict_t **xdata_out) +syncop_ftruncate (xlator_t *subvol, fd_t *fd, off_t offset, + struct iatt *preiatt, struct iatt *postiatt, + dict_t *xdata_in, dict_t **xdata_out) { struct syncargs args = {0, }; SYNCOP (subvol, (&args), syncop_ftruncate_cbk, subvol->fops->ftruncate, fd, offset, xdata_in); + if (preiatt) + *preiatt = args.iatt1; + if (postiatt) + *postiatt = args.iatt2; + if (xdata_out) *xdata_out = args.xdata; else if (args.xdata) diff --git a/libglusterfs/src/syncop.h b/libglusterfs/src/syncop.h index b0052b368b7..7d3afa823e3 100644 --- a/libglusterfs/src/syncop.h +++ b/libglusterfs/src/syncop.h @@ -470,6 +470,7 @@ int syncop_readv (xlator_t *subvol, fd_t *fd, size_t size, off_t off, struct iatt *iatt, dict_t *xdata_in, dict_t **xdata_out); int syncop_ftruncate (xlator_t *subvol, fd_t *fd, off_t offset, + struct iatt *preiatt, struct iatt *postiatt, dict_t *xdata_in, dict_t **xdata_out); int syncop_truncate (xlator_t *subvol, loc_t *loc, off_t offset, diff --git a/tests/basic/gfapi/mandatory-lock-optimal.c b/tests/basic/gfapi/mandatory-lock-optimal.c index 6c62f437a0f..9fb5ad657b0 100644 --- a/tests/basic/gfapi/mandatory-lock-optimal.c +++ b/tests/basic/gfapi/mandatory-lock-optimal.c @@ -366,7 +366,7 @@ void run_test_7 (int i) { if (!fd2) LOG_ERR ("glfs_open", errno); - ret = glfs_ftruncate (fd2, 4); + ret = glfs_ftruncate (fd2, 4, NULL, NULL); if (ret == 0 || errno != EAGAIN) LOG_ERR ("glfs_ftruncate", errno); diff --git a/xlators/cluster/dht/src/dht-rebalance.c b/xlators/cluster/dht/src/dht-rebalance.c index 5bd81244b74..901575563f8 100644 --- a/xlators/cluster/dht/src/dht-rebalance.c +++ b/xlators/cluster/dht/src/dht-rebalance.c @@ -876,6 +876,7 @@ __dht_rebalance_create_dst_file (xlator_t *this, xlator_t *to, xlator_t *from, * in some cases */ ret2 = syncop_ftruncate (to, fd, 0, + NULL, NULL, NULL, NULL); if (ret2 < 0) { gf_msg (this->name, @@ -891,7 +892,8 @@ __dht_rebalance_create_dst_file (xlator_t *this, xlator_t *to, xlator_t *from, } if (!conf->use_fallocate) { - ret = syncop_ftruncate (to, fd, stbuf->ia_size, NULL, NULL); + ret = syncop_ftruncate (to, fd, stbuf->ia_size, NULL, + NULL, NULL, NULL); if (ret < 0) { *fop_errno = -ret; gf_msg (this->name, GF_LOG_WARNING, -ret, @@ -1767,7 +1769,7 @@ dht_migrate_file (xlator_t *this, loc_t *loc, xlator_t *from, xlator_t *to, } - ret = syncop_ftruncate (to, dst_fd, 0, NULL, NULL); + ret = syncop_ftruncate (to, dst_fd, 0, NULL, NULL, NULL, NULL); if (ret) { gf_log (this->name, GF_LOG_WARNING, "%s: failed to perform truncate on %s (%s)", @@ -2199,7 +2201,7 @@ dht_migrate_file (xlator_t *this, loc_t *loc, xlator_t *from, xlator_t *to, /* Free up the data blocks on the source node, as the whole file is migrated */ - ret = syncop_ftruncate (from, src_fd, 0, NULL, NULL); + ret = syncop_ftruncate (from, src_fd, 0, NULL, NULL, NULL, NULL); if (ret) { gf_log (this->name, GF_LOG_WARNING, "%s: failed to perform truncate on %s (%s)", @@ -2332,7 +2334,8 @@ out: /* reset the destination back to 0 */ if (clean_dst) { - lk_ret = syncop_ftruncate (to, dst_fd, 0, NULL, NULL); + lk_ret = syncop_ftruncate (to, dst_fd, 0, NULL, NULL, + NULL, NULL); if (lk_ret) { gf_msg (this->name, GF_LOG_ERROR, -lk_ret, DHT_MSG_MIGRATE_FILE_FAILED, |