diff options
-rwxr-xr-x | libglusterfsclient/src/libglusterfsclient.c | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/libglusterfsclient/src/libglusterfsclient.c b/libglusterfsclient/src/libglusterfsclient.c index de26203e6..9a97b6d61 100755 --- a/libglusterfsclient/src/libglusterfsclient.c +++ b/libglusterfsclient/src/libglusterfsclient.c @@ -3778,6 +3778,83 @@ out: return op_ret; } +int +libgf_client_ftruncate_cbk (call_frame_t *frame, void *cookie, xlator_t *xlator + ,int32_t op_ret, int32_t op_errno, + struct stat *buf) +{ + libgf_client_local_t *local = frame->local; + + local->reply_stub = fop_ftruncate_cbk_stub (frame, NULL, op_ret, + op_errno, buf); + + LIBGF_REPLY_NOTIFY (local); + + return 0; +} + +int +libgf_client_ftruncate (libglusterfs_client_ctx_t *ctx, fd_t *fd, + off_t length) +{ + libgf_client_local_t *local = NULL; + call_stub_t *stub = NULL; + int op_ret = -1; + libglusterfs_client_fd_ctx_t *fdctx = NULL; + + if (!(fd->flags & O_RDWR) && (!(fd->flags & O_WRONLY))) { + errno = EBADF; + goto out; + } + + LIBGF_CLIENT_FOP (ctx, stub, ftruncate, local, fd, length); + + op_ret = stub->args.ftruncate_cbk.op_ret; + errno = stub->args.ftruncate_cbk.op_errno; + + if (op_ret == -1) + goto out; + libgf_update_iattr_cache (fd->inode, LIBGF_UPDATE_STAT, + &stub->args.ftruncate_cbk.buf); + + fdctx = libgf_get_fd_ctx (fd); + if (!fd) { + errno = EINVAL; + op_ret = -1; + goto out; + } + + pthread_mutex_lock (&fdctx->lock); + { + fdctx->offset = stub->args.ftruncate_cbk.buf.st_size; + } + pthread_mutex_lock (&fdctx->lock); + +out: + call_stub_destroy (stub); + return op_ret; +} + +int +glusterfs_ftruncate (glusterfs_file_t fd, off_t length) +{ + libglusterfs_client_fd_ctx_t *fdctx = NULL; + int op_ret = -1; + + GF_VALIDATE_OR_GOTO (LIBGF_XL_NAME, fd, out); + + fdctx = libgf_get_fd_ctx (fd); + if (!fdctx) { + errno = EBADF; + goto out; + } + + op_ret = libgf_client_ftruncate (fdctx->ctx, fd, length); + +out: + return op_ret; +} + static struct xlator_fops libgf_client_fops = { }; |